diff --git a/Makefile b/Makefile index 2b386d589c8..d5653bd1fc4 100644 --- a/Makefile +++ b/Makefile @@ -105,8 +105,8 @@ clean: cli-clean tarball-clean ##@ Build and install -pkg/errmetrics/fileids.json: bpf/lib/fileids.h - go run ./cmd/bpf-fileids bpf/lib/fileids.h pkg/errmetrics/fileids.json +pkg/errmetrics/fileids.json: bpf/tetragon/fileids.h + go run ./cmd/bpf-fileids bpf/tetragon/fileids.h pkg/errmetrics/fileids.json .PHONY: fileids fileids: pkg/errmetrics/fileids.json diff --git a/bpf/Makefile.defs b/bpf/Makefile.defs index 8618687c74a..7237ee086f2 100644 --- a/bpf/Makefile.defs +++ b/bpf/Makefile.defs @@ -19,6 +19,7 @@ ROOT_DIR := $(dir $(lastword $(MAKEFILE_LIST))) IDIR = $(ROOT_DIR)include/ LIBBPF = $(ROOT_DIR)libbpf/ LDIR = $(ROOT_DIR)lib +TETRAGONDIR = $(ROOT_DIR)tetragon/ DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) FLAGS := -I$(ROOT_DIR) \ @@ -31,4 +32,4 @@ ifeq ($(DEBUG),1) __DEBUG_FLAGS = -DTETRAGON_BPF_DEBUG endif -CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -target bpf -mcpu=v2 -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 $(__DEBUG_FLAGS) +CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -I $(TETRAGONDIR) -target bpf -mcpu=v2 -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 $(__DEBUG_FLAGS) diff --git a/bpf/lib/bpf_errmetrics.h b/bpf/lib/bpf_errmetrics.h index f6c65af81c3..258f5ae643e 100644 --- a/bpf/lib/bpf_errmetrics.h +++ b/bpf/lib/bpf_errmetrics.h @@ -4,6 +4,7 @@ #define BPF_ERRMETRICS_H__ #include "compiler.h" +#include "get_fileid.h" // should match: pkg/errmetrics/map.go:MapKey struct errmetrics_key { @@ -14,18 +15,6 @@ struct errmetrics_key { __u16 pad2; } __attribute__((packed)); -FUNC_INLINE __u16 -get_fileid__(const char *const fname) -{ -#define fileid__(f, id) \ - if (!__builtin_strcmp(f, fname)) \ - return id; -#include "fileids.h" -#undef fileid__ - - return 0; -} - struct { __uint(type, BPF_MAP_TYPE_LRU_PERCPU_HASH); __uint(max_entries, 1024); diff --git a/bpf/lib/fileids.h b/bpf/tetragon/fileids.h similarity index 100% rename from bpf/lib/fileids.h rename to bpf/tetragon/fileids.h diff --git a/bpf/tetragon/get_fileid.h b/bpf/tetragon/get_fileid.h new file mode 100644 index 00000000000..41a2f4f6d5b --- /dev/null +++ b/bpf/tetragon/get_fileid.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Copyright Authors of Tetragon */ + +#ifndef GET_FILEID_H__ +#define GET_FILEID_H__ + +FUNC_INLINE __u16 +get_fileid__(const char *const fname) +{ +#define fileid__(f, id) \ + if (!__builtin_strcmp(f, fname)) \ + return id; +#include "fileids.h" +#undef fileid__ + + return 0; +} + +#endif /* GET_FILEID_H__ */