Skip to content

Commit d131249

Browse files
committed
introduce compile argument COMPAT_MODE for low version kernel
Rename 'MAP_CONFIG' with 'COMPAT_MODE' and use compatibility mode for 4.X kernel. Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent 5b360f3 commit d131249

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

shared/bpf/skb_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct {
4141
#define _C(src, a, ...) BPF_CORE_READ(src, a, ##__VA_ARGS__)
4242
#endif
4343

44-
#ifdef MAP_CONFIG
44+
#ifdef COMPAT_MODE
4545
struct {
4646
__uint(type, BPF_MAP_TYPE_ARRAY);
4747
__uint(key_size, sizeof(int));

shared/bpf_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct {
1818

1919
extern long int syscall (long int __sysno, ...);
2020

21-
#ifdef MAP_CONFIG
21+
#ifdef COMPAT_MODE
2222
#define bpf_set_config(skel, sec, value) do { \
2323
int fd = bpf_map__fd(skel->maps.m_config); \
2424
u8 buf[CONFIG_MAP_SIZE] = {}; \

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ COMPAT ?= $(if $(KERNEL),$(shell cat $(HEADERS)/Makefile | grep \
1818
'VERSION = 4'),$(shell uname -r | grep ^4))
1919

2020
ifneq ($(strip $(COMPAT)),)
21-
CFLAGS += -DMAP_CONFIG
21+
CFLAGS += -DCOMPAT_MODE
2222
endif
2323

2424
NFT_HEADER := $(HEADERS)/include/net/netfilter/nf_tables.h

src/gen_trace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ def gen_group(group, is_root=False):
121121
else:
122122
trace_type = 'TRACE_FUNCTION'
123123
if 'skb' in child:
124-
skb_str = '\n\t.skb = {},'.format(child["skb"])
124+
skb_index = int(child["skb"]) + 1
125+
skb_str = '\n\t.skb = {},'.format(skb_index)
125126
probe_str += '\tFN({}, {})\t\\\n'.format(name,
126-
int(child["skb"]) + 1)
127+
skb_index)
127128
if 'analyzer' in child:
128129
analyzer = '\n\t.analyzer = &ANALYZER({}),'.format(
129130
child["analyzer"])

0 commit comments

Comments
 (0)