-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathMakefile
More file actions
333 lines (284 loc) · 10.2 KB
/
Makefile
File metadata and controls
333 lines (284 loc) · 10.2 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
include variables.mk
include functions.mk
.PHONY: all | env nocore
# include core and non-core ebpf bytecode
all: ebpf ebpf_noncore assets build
@echo $(shell date)
# exclude core ebpf
nocore: ebpf_noncore assets_noncore build_noncore
@echo $(shell date)
noncore: nocore
ebpf_nocore: ebpf_noncore
.ONESHELL:
SHELL = /bin/bash
.PHONY: env
env:
@echo ---------------------------------------
@echo "eCapture Makefile Environment:"
@echo ---------------------------------------
@echo "PARALLEL $(PARALLEL)"
@echo ----------------[ from args ]---------------
@echo "CROSS_ARCH $(CROSS_ARCH)"
@echo "ANDROID $(ANDROID)"
@echo "DEBUG $(DEBUG)"
@echo "SNAPSHOT_VERSION $(SNAPSHOT_VERSION)"
@echo ---------------------------------------
@echo "HOST_ARCH $(HOST_ARCH)"
@echo "UNAME_R $(UNAME_R)"
@echo "CLANG_VERSION $(CLANG_VERSION)"
@echo "GO_VERSION $(GO_VERSION)"
@echo ---------------------------------------
@echo "CMD_CLANG $(CMD_CLANG)"
@echo "CMD_GIT $(CMD_GIT)"
@echo "CMD_GO $(CMD_GO)"
@echo "CMD_INSTALL $(CMD_INSTALL)"
@echo "CMD_LLC $(CMD_LLC)"
@echo "CMD_MD5 $(CMD_MD5)"
@echo "CMD_PKGCONFIG $(CMD_PKGCONFIG)"
@echo "CMD_STRIP $(CMD_STRIP)"
@echo "CMD_CC_PREFIX $(CMD_CC_PREFIX)"
@echo "CMD_TAR $(CMD_TAR)"
@echo "CMD_RPMBUILD $(CMD_RPMBUILD)"
@echo "CMD_RPM_SETUP_TREE $(CMD_RPM_SETUP_TREE)"
@echo ---------------------------------------
@echo "VERSION_NUM $(VERSION_NUM)"
@echo "LAST_GIT_TAG $(LAST_GIT_TAG)"
@echo "BPF_NOCORE_TAG $(BPF_NOCORE_TAG)"
@echo "KERN_RELEASE $(KERN_RELEASE)"
@echo "LINUX_SOURCE_PATH $(LINUX_SOURCE_PATH)"
@echo "KERN_BUILD_PATH $(KERN_BUILD_PATH)"
@echo "KERN_SRC_PATH $(KERN_SRC_PATH)"
@echo "TARGET_ARCH $(TARGET_ARCH)"
@echo "GOARCH $(GOARCH)"
@echo "LINUX_ARCH $(LINUX_ARCH)"
@echo "LIBPCAP_ARCH $(LIBPCAP_ARCH)"
@echo "AUTOGENCMD $(AUTOGENCMD)"
@echo "PACKAGE_VERSION $(PACKAGE_VERSION)"
@echo "OUT_DEB_FILE $(OUT_DEB_FILE)"
@echo ---------------------------------------
.PHONY:rpm
rpm:
@$(CMD_RPM_SETUP_TREE) || exit 1
$(CMD_SED) -i '0,/^Version:.*$$/s//Version: $(TAG)/' builder/rpmBuild.spec
$(CMD_SED) -i '0,/^Release:.*$$/s//Release: $(RPM_RELEASE)/' builder/rpmBuild.spec
$(CMD_TAR) zcvf ~/rpmbuild/SOURCES/$(RPM_SOURCE0) ./
$(CMD_RPMBUILD) -ba builder/rpmBuild.spec
#
# usage
#
.PHONY: help
help:
@echo "# environment"
@echo " $$ make env # show makefile environment/variables"
@echo ""
@echo "# build"
@echo " $$ make all # build ecapture"
@echo ""
@echo "# build rpm"
@echo " $$ make rpm VERSION=0.0.0 RELEASE=1 # build ecapture rpm"
@echo ""
@echo "# clean"
@echo " $$ make clean # wipe ./bin/ ./bytecode/ ./assets/"
@echo ""
@echo "# test"
@echo " $$ CROSS_ARCH=arm64 make ... # cross compile, build eCapture for arm64(aarch64) on amd64(x86_64) host"
@echo ""
@echo "# flags"
@echo " $$ ANDROID=1 make ... # build eCapture for Android"
.PHONY: prepare
prepare:
if [ -d "$(LINUX_SOURCE_PATH)" ]; then \
$(CMD_CD) $(LINUX_SOURCE_PATH) && $(KERNEL_HEADER_GEN) || { echo "Kernel header generation failed"; exit 1; } \
elif [ -n "$(CROSS_ARCH)" ]; then \
$(CMD_ECHO) "linux source not found with path: $(LINUX_SOURCE_PATH)" || exit 1; \
fi
.PHONY: clean assets build ebpf
.PHONY: clean
clean:
$(CMD_RM) -f bytecode/*.d
$(CMD_RM) -f bytecode/*.o
$(CMD_RM) -f assets/ebpf_probe.go
$(CMD_RM) -f bin/ecapture
$(CMD_RM) -f .check*
if test -e "./lib/libpcap/Makefile"; then $(MAKE) -C ./lib/libpcap clean; fi
.PHONY: $(KERN_OBJECTS)
$(KERN_OBJECTS): %.o: %.c \
| .checkver_$(CMD_CLANG) \
.checkver_$(CMD_GO) \
autogen
$(CMD_CLANG) -D__TARGET_ARCH_$(LINUX_ARCH) \
$(EXTRA_CFLAGS) \
$(BPFHEADER) \
-target bpfel -c $< -o $(subst kern/,bytecode/,$(subst .o,_core.o,$@)) \
-fno-ident -fdebug-compilation-dir . -g -D__BPF_TARGET_MISSING="GCC error \"The eBPF is using target specific macros, please provide -target\"" \
-MD -MP || exit 1
.PHONY: autogen
autogen: .checkver_$(CMD_BPFTOOL)
$(AUTOGENCMD)
.PHONY: ebpf
ebpf: autogen $(KERN_OBJECTS)
.PHONY: ebpf_noncore
ebpf_noncore: prepare $(KERN_OBJECTS_NOCORE)
.PHONY: $(KERN_OBJECTS_NOCORE)
$(KERN_OBJECTS_NOCORE): %.nocore: %.c \
| .checkver_$(CMD_CLANG) \
.checkver_$(CMD_GO) \
prepare
$(CMD_CLANG) \
$(EXTRA_CFLAGS_NOCORE) \
$(BPFHEADER) \
-I $(KERN_SRC_PATH)/arch/$(LINUX_ARCH)/include \
-I $(KERN_BUILD_PATH)/arch/$(LINUX_ARCH)/include/generated \
-I $(KERN_SRC_PATH)/include \
-I $(KERN_SRC_PATH)/include/linux \
-I $(KERN_SRC_PATH)/arch/$(LINUX_ARCH)/include/uapi \
-I $(KERN_BUILD_PATH)/arch/$(LINUX_ARCH)/include/generated/uapi \
-I $(KERN_SRC_PATH)/include/uapi \
-I $(KERN_BUILD_PATH)/include/generated/uapi \
-c $< \
-o - |$(CMD_LLC) \
-march=bpf \
-filetype=obj \
-o $(subst kern/,bytecode/,$(subst .c,_noncore.o,$<)) || exit 1
# Generate assets for all eBPF bytecode
.PHONY: assets
assets: .checkver_$(CMD_GO) ebpf ebpf_noncore
$(CMD_GO) run github.com/shuLhan/go-bindata/cmd/go-bindata $(IGNORE_LESS52) -pkg assets -o "assets/ebpf_probe.go" $(wildcard ./bytecode/*.o)
sed -i '1s/^\/\/ Code generated/\/\/go:build ebpfassets\n\/\/ Code generated/' assets/ebpf_probe.go
# Generate assets for non-core eBPF bytecode only
.PHONY: assets_noncore
assets_noncore: \
.checkver_$(CMD_GO) \
ebpf_noncore
$(CMD_GO) run github.com/shuLhan/go-bindata/cmd/go-bindata $(IGNORE_LESS52) -pkg assets -o "assets/ebpf_probe.go" $(wildcard ./bytecode/*.o)
sed -i '1s/^\/\/ Code generated/\/\/go:build ebpfassets\n\/\/ Code generated/' assets/ebpf_probe.go
# Build libpcap static library
.PHONY: $(TARGET_LIBPCAP)
$(TARGET_LIBPCAP):
test -f ./lib/libpcap/configure || git submodule update --init
cd lib/libpcap && \
CC=$(CMD_CC_PREFIX)$(CMD_CC) AR=$(CMD_AR_PREFIX)$(CMD_AR) CFLAGS="-O2 -g -gdwarf-4 -static -Wno-unused-result" ./configure --disable-rdma --disable-shared --disable-usb \
--disable-netmap --disable-bluetooth --disable-dbus --without-libnl \
--without-dpdk --without-dag --without-septel --without-snf \
--without-gcc --with-pcap=linux \
--without-turbocap --host=$(LIBPCAP_ARCH) && \
CC=$(CMD_CC_PREFIX)$(CMD_CC) AR=$(CMD_AR_PREFIX)$(CMD_AR) make || exit 1
# Build CO-RE eBPF bytecode and golang binary
.PHONY: build
build: .checkver_$(CMD_GO) $(TARGET_LIBPCAP) assets assets_noncore
$(call allow-override,VERSION_FLAG,$(UNAME_R))
$(call gobuild, $(ANDROID))
# Build non-core eBPF bytecode and golang binary
.PHONY: build_noncore
build_noncore: \
.checkver_$(CMD_GO) \
$(TARGET_LIBPCAP) \
assets_noncore
$(call allow-override,VERSION_FLAG,$(HOST_ARCH))
$(call allow-override,BYTECODE_FILES,noncore)
$(call gobuild, $(ANDROID))
# Format the code
.PHONY: format
format:
@echo " -> Formatting code"
@clang-format -i -style=$(STYLE) kern/*.c
@clang-format -i -style=$(STYLE) kern/common.h
@clang-format -i -style=$(STYLE) kern/openssl_masterkey.h
@clang-format -i -style=$(STYLE) kern/openssl_masterkey_3.0.h
@clang-format -i -style=$(STYLE) kern/openssl_masterkey_3.2.h
@clang-format -i -style=$(STYLE) kern/boringssl_masterkey.h
@clang-format -i -style=$(STYLE) utils/*.c
# run unit tests with race detector
.PHONY: test-race
test-race: \
.checkver_$(CMD_GO) \
$(TARGET_LIBPCAP)
CGO_ENABLED=1 \
CGO_CFLAGS='-O2 -g -I$(CURDIR)/lib/libpcap/' \
CGO_LDFLAGS='-O2 -g -L$(CURDIR)/lib/libpcap/ -lpcap' \
GOOS=linux GOARCH=$(GOARCH) CC=$(CMD_CC_PREFIX)$(CMD_CC) \
go test -v -race -tags dynamic,ebpfassets ./... -coverprofile=coverage.out
# run Bash module e2e test
.PHONY: e2e-bash
e2e-bash:
bash ./test/e2e/bash_e2e_test.sh
# run Zsh module e2e test
.PHONY: e2e-zsh
e2e-zsh:
bash ./test/e2e/zsh_e2e_test.sh
# run MySQL module e2e test
.PHONY: e2e-mysql
e2e-mysql:
bash ./test/e2e/mysql_e2e_test.sh
# run PostgreSQL module e2e test
.PHONY: e2e-postgres
e2e-postgres:
bash ./test/e2e/postgres_e2e_test.sh
# run TLS module e2e test
.PHONY: e2e-tls
e2e-tls:
bash ./test/e2e/tls_e2e_test.sh
# run GnuTLS module e2e test
.PHONY: e2e-gnutls
e2e-gnutls:
bash ./test/e2e/gnutls_e2e_test.sh
# run GoTLS module e2e test
.PHONY: e2e-gotls
e2e-gotls:
bash ./test/e2e/gotls_e2e_test.sh
# run advanced TLS text mode tests
.PHONY: e2e-tls-text-advanced
e2e-tls-text-advanced:
bash ./test/e2e/tls_text_advanced_test.sh
# run advanced TLS pcap mode tests
.PHONY: e2e-tls-pcap-advanced
e2e-tls-pcap-advanced:
bash ./test/e2e/tls_pcap_advanced_test.sh
# run advanced TLS keylog mode tests
.PHONY: e2e-tls-keylog-advanced
e2e-tls-keylog-advanced:
bash ./test/e2e/tls_keylog_advanced_test.sh
# run advanced GoTLS tests
.PHONY: e2e-gotls-advanced
e2e-gotls-advanced:
bash ./test/e2e/gotls_advanced_test.sh
# run advanced Bash tests
.PHONY: e2e-bash-advanced
e2e-bash-advanced:
bash ./test/e2e/bash_advanced_test.sh
# run advanced MySQL tests
.PHONY: e2e-mysql-advanced
e2e-mysql-advanced:
bash ./test/e2e/mysql_advanced_test.sh
# run edge cases and error handling tests
.PHONY: e2e-edge-cases
e2e-edge-cases:
bash ./test/e2e/edge_cases_test.sh
# run all basic e2e tests
.PHONY: e2e-basic
e2e-basic: e2e-bash e2e-tls e2e-gnutls e2e-gotls
@echo "All basic e2e tests completed"
# run all advanced e2e tests
.PHONY: e2e-advanced
e2e-advanced: e2e-tls-text-advanced e2e-tls-pcap-advanced e2e-tls-keylog-advanced e2e-gotls-advanced e2e-bash-advanced e2e-edge-cases
@echo "All advanced e2e tests completed"
# run all comprehensive e2e tests (basic + advanced)
.PHONY: e2e
e2e: e2e-basic e2e-advanced
@echo "All e2e tests completed"
# Android e2e tests
.PHONY: e2e-android-tls
e2e-android-tls:
bash ./test/e2e/android/android_tls_e2e_test.sh
.PHONY: e2e-android-gotls
e2e-android-gotls:
bash ./test/e2e/android/android_gotls_e2e_test.sh
.PHONY: e2e-android-all
e2e-android-all: e2e-android-tls e2e-android-gotls
@echo "All Android e2e tests completed"
.PHONY: build-android-tests
build-android-tests:
bash ./test/e2e/android/build_android_tests.sh
.PHONY: setup-android-env
setup-android-env:
bash ./test/e2e/android/setup_android_env.sh