-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathMakefile
100 lines (79 loc) · 2.41 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
ROOT ?= $(abspath ../)
bpf_progs := progs/kprobe
progs := nettrace
prog-nettrace-origin = \
trace.c $(COMMON_SHARED) trace_probe.c trace_tracing.c \
analysis.c $(COMPONENT)/parse_sym.c trace_group.c \
dropreason.c
prog-nettrace = $(prog-nettrace-origin) nettrace.c
ifdef COMPAT
NO_GLOBAL_DATA := 1
NO_BTF := 1
INLINE := 1
endif
ifndef NO_BTF
bpf_progs += progs/tracing progs/feat_args_ext
endif
BPF_EXTRA_DEP := kheaders.h progs/core.c progs/core.h
include ../common.mk
cmd_kversion := awk -F '=' 'NR>10{exit;} \
$$1~/^VERSION/{ \
sub(/ /, "", $$2); a=$$2; \
} \
$$1~/^PATCHLEVEL/{ \
sub(/ /, "", $$2); b=$$2 \
} \
$$1~/^SUBLEVEL/{ \
sub(/ /, "", $$2); c=$$2 \
} \
END{printf "%s.%s.%s\n", a, b, c}' \
$(HEADERS)/Makefile
str_count = $(shell grep -c $2 $(HEADERS)/$1 2>/dev/null)
struct_field = $(shell awk 'BEGIN{start=0}/struct $2 {/{start=1} \
/$3/{if (start==1) print 1} \
/}/{start=0}' $(HEADERS)/$1 2>/dev/null)
ifdef NO_BTF
ifeq ($(call str_count,include/uapi/linux/bpf.h,BPF_PROG_TYPE_TRACEPOINT),0)
$(error BPF_PROG_TYPE_TRACEPOINT not supported by your kernel!)
endif
ifneq ($(call str_count,include/uapi/linux/bpf.h,get_stackid),0)
CFLAGS += -D__F_STACK_TRACE
endif
ifneq ($(call str_count,include/net/sock.h,sk_protocol.*8),0)
BPF_CFLAGS += -D__F_SK_PRPTOCOL_LEGACY
endif
ifeq ($(call str_count,include/net/sock.h,__sk_flags_offset),0)
BPF_CFLAGS += -D__F_NO_SK_FLAGS_OFFSET
endif
ifeq ($(call str_count,include/linux/netfilter.h,nf_hook_entries),0)
BPF_CFLAGS += -D__F_NO_NF_HOOK_ENTRIES
endif
ifeq ($(call str_count,include/uapi/linux/bpf.h,bpf_probe_read_str),0)
BPF_CFLAGS += -D__F_NO_PROBE_READ_STR
endif
ifeq ($(call struct_field,include/net/netfilter/nf_tables.h,nft_chain,\*name),)
CFLAGS += -D__F_NFT_NAME_ARRAY
endif
__KERN_VER := $(shell $(cmd_kversion))
CFLAGS += -D__KERN_VER=$(__KERN_VER)
CFLAGS += -D__KERN_MAJOR=$(shell echo $(__KERN_VER) | cut -c 1)
else
CFLAGS += -D__F_STACK_TRACE
endif
progs/kprobe_trace.h:
python3 gen_trace.py probe > progs/kprobe_trace.h
trace_group.c: trace.yaml
python3 gen_trace.py > trace_group.c
progs/*.c: progs/kprobe_trace.h
@:
nettrace.c: $(prog-nettrace-origin)
all: $(progs)
install: all
@mkdir -p ${PREFIX}/usr/bin/
@cp nettrace ${PREFIX}/usr/bin/
pack: all
@cp nettrace ${PREFIX}/
clean:
rm -rf $(progs) trace_group.c progs/kprobe_trace.h \
$(bpf_progs) progs/*.o progs/*.skel.h \
kheaders.h