X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=flowspec-xdp;a=blobdiff_plain;f=install.sh;h=1371807cd7fdf0fffcde963e5027ee9aba792b1a;hp=d93664c4146c92015f0d6b07b40e5a6e3467fd34;hb=HEAD;hpb=fd5a4615a8c2684076a66389fc747be49f3e0b6c diff --git a/install.sh b/install.sh index d93664c..1371807 100755 --- a/install.sh +++ b/install.sh @@ -1,16 +1,35 @@ #!/bin/bash set -e -RULES="$(birdc show route table flowspec4) -$(birdc show route table flowspec6)" +CLANG_ARGS="" +XDP_SECTION="xdp_drop" +if [ "$2" != "" ]; then + CLANG_ARGS="-DHAVE_WRAPPER" + XDP_SECTION="$3" + if [ ! -f "$2" -o "$3" = "" ]; then + echo "To use a wrapper C file, call as $0 interface path/to/wrapper.c xdp_section wrapper-clang-args" + exit 1 + fi +fi -echo "$RULES" | ./genrules.py --8021q=drop-vlan --v6frag=ignore-parse-if-rule --ihl=drop-options -clang -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -Os -emit-llvm -c xdp.c -o - | llc -march=bpf -filetype=obj -o xdp +RULES="$(birdc show route table flowspec4 primary all) +$(birdc show route table flowspec6 primary all)" -echo "Before unload drop count was:" -./dropcount.sh || echo "Not loaded" +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 + +STATS_RULES="$(echo "$RULES" | ./genrules.py --8021q=drop-vlan --v6frag=ignore-parse-if-rule --ihl=parse-options)" +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 +if [ "$2" != "" ]; then + clang $4 -g -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -O3 -emit-llvm -c "$2" -o wrapper.bc + llvm-link xdp.bc wrapper.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp +else + cat xdp.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp +fi -ip link set "$1" xdp off -ip link set "$1" xdpgeneric off # Note that sometimes the automated fallback does not work properly so we have to || generic here -ip link set "$1" xdp obj xdp sec xdp_drop || ip link set "$1" xdpgeneric obj xdp sec xdp_drop +ip -force link set "$1" xdpoffload obj xdp sec $XDP_SECTION || ( + echo "Failed to install in NIC, testing in driver..." && ip -force link set "$1" xdpdrv obj xdp sec $XDP_SECTION || ( + echo "Failed to install in driver, using generic..." && ip -force link set "$1" xdpgeneric obj xdp sec $XDP_SECTION + ) +) +echo "$STATS_RULES" > installed-rules.txt