WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_tcp_check_syncookie.sh
blob9b3617d770a525875bf6a0d6d6d2f27553267029
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook
4 # Copyright (c) 2019 Cloudflare
6 set -eu
8 wait_for_ip()
10 local _i
11 printf "Wait for IP %s to become available " "$1"
12 for _i in $(seq ${MAX_PING_TRIES}); do
13 printf "."
14 if ns1_exec ping -c 1 -W 1 "$1" >/dev/null 2>&1; then
15 echo " OK"
16 return
18 sleep 1
19 done
20 echo 1>&2 "ERROR: Timeout waiting for test IP to become available."
21 exit 1
24 get_prog_id()
26 awk '/ id / {sub(/.* id /, "", $0); print($1)}'
29 ns1_exec()
31 ip netns exec ns1 "$@"
34 setup()
36 ip netns add ns1
37 ns1_exec ip link set lo up
39 ns1_exec sysctl -w net.ipv4.tcp_syncookies=2
40 ns1_exec sysctl -w net.ipv4.tcp_window_scaling=0
41 ns1_exec sysctl -w net.ipv4.tcp_timestamps=0
42 ns1_exec sysctl -w net.ipv4.tcp_sack=0
44 wait_for_ip 127.0.0.1
45 wait_for_ip ::1
48 cleanup()
50 ip netns del ns1 2>/dev/null || :
53 main()
55 trap cleanup EXIT 2 3 6 15
56 setup
58 printf "Testing clsact..."
59 ns1_exec tc qdisc add dev "${TEST_IF}" clsact
60 ns1_exec tc filter add dev "${TEST_IF}" ingress \
61 bpf obj "${BPF_PROG_OBJ}" sec "${CLSACT_SECTION}" da
63 BPF_PROG_ID=$(ns1_exec tc filter show dev "${TEST_IF}" ingress | \
64 get_prog_id)
65 ns1_exec "${PROG}" "${BPF_PROG_ID}"
66 ns1_exec tc qdisc del dev "${TEST_IF}" clsact
68 printf "Testing XDP..."
69 ns1_exec ip link set "${TEST_IF}" xdp \
70 object "${BPF_PROG_OBJ}" section "${XDP_SECTION}"
71 BPF_PROG_ID=$(ns1_exec ip link show "${TEST_IF}" | get_prog_id)
72 ns1_exec "${PROG}" "${BPF_PROG_ID}"
75 DIR=$(dirname $0)
76 TEST_IF=lo
77 MAX_PING_TRIES=5
78 BPF_PROG_OBJ="${DIR}/test_tcp_check_syncookie_kern.o"
79 CLSACT_SECTION="clsact/check_syncookie"
80 XDP_SECTION="xdp/check_syncookie"
81 BPF_PROG_ID=0
82 PROG="${DIR}/test_tcp_check_syncookie_user"
84 main