-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake.sh
105 lines (72 loc) · 2.51 KB
/
make.sh
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
#!/bin/bash
CLANG="$(which clang)";
GO="$(which go)";
LLC="$(which llc)";
ROOT="$(pwd)";
build_ebpf() {
cd "${ROOT}/ebpf";
# TODO: Add -DENABLE_DNSFILTER once it's ready
${CLANG} -S -I"${ROOT}/ebpf/headers" -target bpf -O2 -Wall -Wno-unused-value -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Werror -emit-llvm -g -c -o "${ROOT}/ebpf/module/module.ll" "${ROOT}/ebpf/module/module.c"
if [[ "$?" == "0" ]]; then
echo -e "- Generate eBPF LLVM code: ${os} [\e[32mok\e[0m]";
else
echo -e "- Generate eBPF LLVM code: ${os} [\e[31mfail\e[0m]";
fi;
${LLC} -march=bpfeb -mcpu=v1 -filetype=obj -o "${ROOT}/source/adapters/mitigations/ebpf/module/module.bpfeb" "${ROOT}/ebpf/module/module.ll";
if [[ "$?" == "0" ]]; then
echo -e "- Generate eBPF big-endian module: ${os} [\e[32mok\e[0m]";
else
echo -e "- Generate eBPF big-endian module: ${os} [\e[31mfail\e[0m]";
fi;
${LLC} -march=bpfel -mcpu=v1 -filetype=obj -o "${ROOT}/source/adapters/mitigations/ebpf/module/module.bpfel" "${ROOT}/ebpf/module/module.ll";
if [[ "$?" == "0" ]]; then
echo -e "- Generate eBPF little-endian module: ${os} [\e[32mok\e[0m]";
else
echo -e "- Generate eBPF little-endian module: ${os} [\e[31mfail\e[0m]";
fi;
}
build_source() {
#
# Available build tags to reduce file size
#
# guard:
# - includes source/adapters/mitigations/ebpf Kernel Modules
# - includes source/insights
#
# guard_openwrt:
# - includes source/adapters/mitigations/ebpf Kernel Modules
#
local os="$1";
local arch="$2";
local variant="$3";
local folder="${ROOT}/build/${os}";
mkdir -p "${folder}";
cd "${ROOT}/source";
env CGO_ENABLED=0 GOOS="${os}" GOARCH="${arch}" ${GO} build -tags "${variant}" -o "${folder}/tholian-firewall-${variant}-${arch}" "${ROOT}/source/cmds/tholian-firewall/main.go";
if [[ "$?" == "0" ]]; then
echo -e "- Build source: ${os} / ${arch} [\e[32mok\e[0m]";
else
echo -e "- Build source: ${os} / ${arch} [\e[31mfail\e[0m]";
fi;
}
if [[ "${GO}" != "" ]] && [[ "${CLANG}" != "" ]] && [[ "${LLC}" != "" ]]; then
if [[ "$1" == "ebpf" ]]; then
build_ebpf;
elif [[ "$1" == "source" ]]; then
build_ebpf;
build_source linux amd64 guard;
build_source linux arm64 guard;
build_source linux amd64 guard_openwrt;
build_source linux arm64 guard_openwrt;
else
echo -e "Build Script Usage:";
echo -e "";
echo -e " bash ./make.sh ebpf;";
echo -e " bash ./make.sh source;";
echo -e "";
exit 1;
fi;
else
echo -e "Please install go(lang) and LLVM/clang compilers. [\e[31mfail\e[0m]";
exit 1;
fi;