Skip to content

Commit 8cf0e71

Browse files
committed
nettrace: auto detect 4.X kernel and use COMPAT for it
Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent b37fbf7 commit 8cf0e71

5 files changed

Lines changed: 25 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ GPATH
1010
GTAGS
1111
GRTAGS
1212
kheaders.h
13+
build.sh

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ pack:
5858

5959
rpm:
6060
@make clean
61+
@make man
6162
@rm -rf ${SOURCE_DIR} && mkdir -p ${SOURCE_DIR}
6263
@cp -r * ${SOURCE_DIR}/
64+
@sed -i 's/%{VERSION}/$(VERSION)/' ${SOURCE_DIR}/script/nettrace.spec
6365
@cd ~/rpmbuild/SOURCES/ && tar -czf nettrace-${VERSION}.tar.gz \
6466
nettrace-${VERSION}
65-
@rpmbuild -ba $(SCRIPT)/nettrace.spec
67+
@rpmbuild -D 'dist $(RELEASE)' -ba ${SOURCE_DIR}/script/nettrace.spec
6668

6769
.PHONY: $(targets)

common.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ COMMON_SHARED := $(ROOT)/shared/pkt_utils.c $(COMPONENT)/net_utils.c \
44
$(COMPONENT)/arg_parse.c $(COMPONENT)/sys_utils.c
55

66
CFLAGS += -I./ -I$(ROOT)/shared/bpf/
7-
BPF_CFLAGS := $(CFLAGS) -I$(LIBBPF) -Wno-unused-function
8-
HOST_CFLAGS := \
7+
BPF_CFLAGS = $(CFLAGS) -I$(LIBBPF) -Wno-unused-function
8+
HOST_CFLAGS = \
99
-lbpf -lelf -lz -g -O2 -static $(CFLAGS) \
1010
-Wno-deprecated-declarations \
1111
-I$(ROOT)/shared/ -I$(ROOT)/component

script/nettrace.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Summary: A skb (network package) trace tool for kernel
22

33
Name: nettrace
44

5-
Version: %{getenv:VERSION}
5+
Version: %{VERSION}
66

7-
Release: %{getenv:RELEASE}
7+
Release: %{?dist}
88

99
License: GPL
1010

src/Makefile

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
ROOT ?= $(abspath ../)
2-
bpf_progs := progs/kprobe progs/tracing
3-
progs := nettrace
4-
prog-nettrace-origin = trace.c $(COMMON_SHARED) \
5-
trace_probe.c trace_tracing.c analysis.c \
6-
$(COMPONENT)/parse_sym.c trace_group.c \
7-
drop_reason.h
8-
9-
prog-nettrace = $(prog-nettrace-origin) nettrace.c
10-
11-
ifdef COMPAT
12-
CFLAGS += -DMAP_CONFIG
13-
endif
1+
ROOT ?= $(abspath ../)
2+
bpf_progs := progs/kprobe progs/tracing
3+
progs := nettrace
4+
prog-nettrace-origin = \
5+
trace.c $(COMMON_SHARED) trace_probe.c trace_tracing.c \
6+
analysis.c $(COMPONENT)/parse_sym.c trace_group.c \
7+
drop_reason.h
8+
prog-nettrace = $(prog-nettrace-origin) nettrace.c
149

1510
ifdef KERN_VER
16-
CFLAGS += -DKERN_VER=$(KERN_VER)
11+
CFLAGS += -DKERN_VER=$(KERN_VER)
1712
endif
1813

1914
include ../common.mk
2015

16+
# check if current kernel version is 4.X
17+
COMPAT ?= $(if $(KERNEL),$(shell cat $(HEADERS)/Makefile | grep \
18+
'VERSION = 4'),$(shell uname -r | grep ^4))
19+
20+
ifneq ($(strip $(COMPAT)),)
21+
CFLAGS += -DMAP_CONFIG
22+
endif
23+
2124
NFT_HEADER := $(HEADERS)/include/net/netfilter/nf_tables.h
2225
ifeq ($(shell cat $(NFT_HEADER) 2>&1 | grep xt_action_param),)
2326
BPF_CFLAGS += -DNFT_HIGH_VERSION

0 commit comments

Comments
 (0)