From 64cd4fca52d5b65f6e68b7b2b4e1b628f096b9bf Mon Sep 17 00:00:00 2001 From: fruffy Date: Thu, 19 Dec 2024 16:10:52 +0100 Subject: [PATCH] Use BTF maps if BPF_ANNOTATE_KV_PAIR is defined. Signed-off-by: fruffy --- backends/ebpf/runtime/ebpf_kernel.h | 6 ++++-- testdata/extern_modules/extern-conntrack-ebpf.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/ebpf/runtime/ebpf_kernel.h b/backends/ebpf/runtime/ebpf_kernel.h index 6813c0affca..f63a17db24f 100644 --- a/backends/ebpf/runtime/ebpf_kernel.h +++ b/backends/ebpf/runtime/ebpf_kernel.h @@ -23,6 +23,7 @@ limitations under the License. #include "ebpf_common.h" +#include // Exports BPF_ANNOTATE_KV_PAIR in newer versions. #include // definitions for bpf_ntohs etc... #undef htonl @@ -79,6 +80,9 @@ struct bpf_elf_map { /// Simple descriptor which replaces the kernel sk_buff structure. #define SK_BUFF struct __sk_buff + +#define REGISTER_START() +#ifndef BPF_ANNOTATE_KV_PAIR /// From iproute2, annotate table with BTF which allows to read types at runtime. #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \ struct ____btf_map_##name { \ @@ -89,8 +93,6 @@ struct bpf_elf_map { __attribute__ ((section(".maps." #name), used)) \ ____btf_map_##name = {}; -#define REGISTER_START() -#ifndef BTF /// Note: pinning exports the table name globally, do not remove. #define REGISTER_TABLE(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES) \ struct bpf_elf_map SEC("maps") NAME = { \ diff --git a/testdata/extern_modules/extern-conntrack-ebpf.c b/testdata/extern_modules/extern-conntrack-ebpf.c index 2b90d0a3b7e..f5046fd6b85 100644 --- a/testdata/extern_modules/extern-conntrack-ebpf.c +++ b/testdata/extern_modules/extern-conntrack-ebpf.c @@ -29,7 +29,7 @@ struct connInfo { }; REGISTER_START() -REGISTER_TABLE(tcp_reg, BPF_MAP_TYPE_HASH, sizeof(u32), sizeof(struct connInfo), MAX_ENTRIES) +REGISTER_TABLE(tcp_reg, BPF_MAP_TYPE_HASH, u32, struct connInfo, MAX_ENTRIES) REGISTER_END() static inline u8 tcp_conntrack(struct Headers_t hdrs)