Skip to content

Commit bbae4f7

Browse files
xdp-forward: Add selftest for flowtable mode
Signed-off-by: Lorenzo Bianconi <[email protected]>
1 parent 1a738f9 commit bbae4f7

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

lib/testing/test_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ALL_TESTS=""
2525
VERBOSE_TESTS=${V:-0}
2626
NUM_NS=2
2727

28-
NEEDED_TOOLS="capinfos ethtool ip ping sed tc tcpdump timeout nc tshark"
28+
NEEDED_TOOLS="capinfos ethtool ip ping sed tc tcpdump timeout nc tshark nft"
2929

3030
if [ -f "$TEST_CONFIG" ]; then
3131
source "$TEST_CONFIG"

xdp-forward/tests/test-xdp-forward.sh

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
XDP_LOADER=${XDP_LOADER:-./xdp-loader}
22
XDP_FORWARD=${XDP_FORWARD:-./xdp-forward}
3-
ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct"
3+
ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct test_flowtable"
44

55

66
test_ping()
@@ -52,6 +52,61 @@ test_fwd_direct()
5252
check_run $XDP_FORWARD unload ${NS_NAMES[@]}
5353
}
5454

55+
test_flowtable()
56+
{
57+
# veth NAPI GRO support added this symbol; forwarding won't work without it
58+
skip_if_missing_kernel_symbol veth_set_features
59+
# check if bpf flowtable lookup is available
60+
skip_if_missing_kernel_symbol bpf_xdp_flow_lookup
61+
62+
# disable {tx,rx} checksum offload since it is not currently suported
63+
# by XDP_REDIRECT
64+
for n in ${NS_NAMES[@]}; do
65+
ip netns exec $n ethtool -K veth0 tx-checksumming off rx-checksumming off
66+
ethtool -K $n tx-checksumming off rx-checksumming off
67+
done
68+
69+
# create data to send via tcp
70+
local infile="$(mktemp)"
71+
dd if=/dev/urandom of="${infile}" bs=8192 count=32 status=none
72+
73+
# create flowtable configuration
74+
check_run nft -f /dev/stdin <<EOF
75+
table inet filter {
76+
flowtable ft {
77+
hook ingress priority filter
78+
devices = { ${NS_NAMES[0]}, ${NS_NAMES[-1]} }
79+
}
80+
chain forward {
81+
type filter hook forward priority filter
82+
meta l4proto { tcp } flow add @ft
83+
}
84+
}
85+
EOF
86+
# wait a bit to configure nft
87+
sleep 2
88+
89+
check_run $XDP_FORWARD load -f flowtable ${NS_NAMES[0]}
90+
91+
PID=$(start_background_ns_devnull "nc -4 -l --no-shutdown 10000")
92+
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -4 ${ALL_INSIDE_IP4[-1]} 10000 < ${infile}
93+
stop_background $PID
94+
95+
PID=$(start_background_ns_devnull "nc -6 -l --no-shutdown 10000")
96+
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -6 ${ALL_INSIDE_IP6[-1]} 10000 < ${infile}
97+
stop_background $PID
98+
99+
check_run $XDP_FORWARD unload ${NS_NAMES[0]}
100+
check_run nft flush ruleset
101+
# enable {tx,rx} checksum offload
102+
for n in ${NS_NAMES[@]}; do
103+
ip netns exec $n ethtool -K veth0 tx-checksumming on rx-checksumming on
104+
ethtool -K $n tx-checksumming on rx-checksumming on
105+
done
106+
107+
rm -f ${infile}
108+
}
109+
55110
cleanup_tests()
56111
{
57112
$XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1

0 commit comments

Comments
 (0)