Skip to content

Commit

Permalink
Use BTF maps if BPF_ANNOTATE_KV_PAIR is defined.
Browse files Browse the repository at this point in the history
Signed-off-by: fruffy <[email protected]>
  • Loading branch information
fruffy committed Dec 19, 2024
1 parent 82e200c commit 64cd4fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions backends/ebpf/runtime/ebpf_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.

#include "ebpf_common.h"

#include <iproute2/bpf_elf.h> // Exports BPF_ANNOTATE_KV_PAIR in newer versions.
#include <bpf/bpf_endian.h> // definitions for bpf_ntohs etc...

#undef htonl
Expand Down Expand Up @@ -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 { \
Expand All @@ -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 = { \
Expand Down
2 changes: 1 addition & 1 deletion testdata/extern_modules/extern-conntrack-ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64cd4fc

Please sign in to comment.