-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathazure-iptables-monitor.sh
More file actions
75 lines (61 loc) · 2.29 KB
/
azure-iptables-monitor.sh
File metadata and controls
75 lines (61 loc) · 2.29 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
#!/bin/bash
set -eux
[[ $OS =~ windows ]] && { echo "azure-iptables-monitor is not supported on Windows"; exit 1; }
FILE_EXT=''
export CGO_ENABLED=0
# Go 1.26 Linux-only: use nocgo OpenSSL backend (systemcrypto default requires CGO)
export GOEXPERIMENT=ms_nocgo_opensslcrypto
export C_INCLUDE_PATH=/usr/include/bpf
mkdir -p "$OUT_DIR"/bin
mkdir -p "$OUT_DIR"/files
pushd "$REPO_ROOT"/azure-iptables-monitor
GOOS="$OS" go build -v -a -trimpath \
-o "$OUT_DIR"/bin/azure-iptables-monitor"$FILE_EXT" \
-ldflags "-s -w -X github.com/Azure/azure-container-networking/azure-iptables-monitor/internal/buildinfo.Version=$AZURE_IPTABLES_MONITOR_VERSION -X main.version=$AZURE_IPTABLES_MONITOR_VERSION" \
-gcflags="-dwarflocationlists=true" \
.
popd
echo "Building azure-block-iptables binary..."
# Debian/Ubuntu
if [[ -f /etc/debian_version ]]; then
apt-get update -y
apt-get install -y --no-install-recommends llvm clang linux-libc-dev libbpf-dev libc6-dev nftables iproute2
if [[ $ARCH =~ amd64 ]]; then
apt-get install -y --no-install-recommends gcc-multilib
ARCH_GNU=x86_64-linux-gnu
elif [[ $ARCH =~ arm64 ]]; then
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu
ARCH_GNU=aarch64-linux-gnu
fi
# Create symlinks for architecture-specific includes
for dir in /usr/include/"$ARCH_GNU"/*; do
if [[ -d "$dir" || -f "$dir" ]]; then
ln -sfn "$dir" /usr/include/$(basename "$dir")
fi
done
# Mariner
else
tdnf install -y llvm clang libbpf-devel nftables gcc binutils iproute glibc
if [[ $ARCH =~ amd64 ]]; then
ARCH_GNU=x86_64-linux-gnu
elif [[ $ARCH =~ arm64 ]]; then
ARCH_GNU=aarch64-linux-gnu
fi
# Create symlinks for architecture-specific includes
for dir in /usr/include/"$ARCH_GNU"/*; do
if [[ -d "$dir" || -f "$dir" ]]; then
ln -sfn "$dir" /usr/include/$(basename "$dir")
fi
done
fi
pushd "$REPO_ROOT"
# Generate BPF objects
GOOS="$OS" CGO_ENABLED=0 go generate ./bpf-prog/azure-block-iptables/...
# Build the binary
GOOS="$OS" CGO_ENABLED=0 go build -a \
-o "$OUT_DIR"/bin/azure-block-iptables"$FILE_EXT" \
-trimpath \
-ldflags "-s -w -X main.version=$AZURE_BLOCK_IPTABLES_VERSION" \
-gcflags="-dwarflocationlists=true" \
./bpf-prog/azure-block-iptables/cmd/azure-block-iptables
popd