Stop dumping match count before update, users can get it if they want
[flowspec-xdp] / install.sh
1 #!/bin/bash
2 set -e
3
4 CLANG_ARGS=""
5 XDP_SECTION="xdp_drop"
6 if [ "$2" != "" ]; then
7         CLANG_ARGS="-DHAVE_WRAPPER"
8         XDP_SECTION="$3"
9         if [ ! -f "$2" -o "$3" = "" ]; then
10                 echo "To use a wrapper C file, call as $0 interface path/to/wrapper.c xdp_section wrapper-clang-args"
11                 exit 1
12         fi
13 fi
14
15 RULES="$(birdc show route table flowspec4 primary all)
16 $(birdc show route table flowspec6 primary all)"
17
18 echo "const uint8_t COMPILE_TIME_RAND[] = { $(dd if=/dev/urandom of=/dev/stdout bs=1 count=8 2>/dev/null | hexdump -e '4/1 "0x%02x, "') };" > rand.h
19
20 STATS_RULES="$(echo "$RULES" | ./genrules.py --8021q=drop-vlan --v6frag=ignore-parse-if-rule --ihl=parse-options)"
21 clang $CLANG_ARGS -g -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -Wno-unused-function -O3 -emit-llvm -c xdp.c -o xdp.bc
22 if [ "$2" != "" ]; then
23         clang $4 -g -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -O3 -emit-llvm -c "$2" -o wrapper.bc
24         llvm-link xdp.bc wrapper.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp
25 else
26         cat xdp.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp
27 fi
28
29 # Note that sometimes the automated fallback does not work properly so we have to || generic here
30 ip -force link set "$1" xdpoffload obj xdp sec $XDP_SECTION || (
31         echo "Failed to install in NIC, testing in driver..." && ip -force link set "$1" xdpdrv obj xdp sec $XDP_SECTION || (
32                 echo "Failed to install in driver, using generic..." && ip -force link set "$1" xdpgeneric obj xdp sec $XDP_SECTION
33         )
34 )
35 echo "$STATS_RULES" > installed-rules.txt