Skip to content

Commit f112a0e

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

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-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: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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

5+
infile="$(mktemp)"
56

67
test_ping()
78
{
@@ -52,8 +53,70 @@ test_fwd_direct()
5253
check_run $XDP_FORWARD unload ${NS_NAMES[@]}
5354
}
5455

56+
test_flowtable()
57+
{
58+
# veth NAPI GRO support added this symbol; forwarding won't work without it
59+
skip_if_missing_kernel_symbol veth_set_features
60+
# check if bpf flowtable lookup is available
61+
skip_if_missing_kernel_symbol bpf_xdp_flow_lookup
62+
63+
# disable {tx,rx} checksum offload since it is not currently suported
64+
# by XDP_REDIRECT
65+
for n in ${NS_NAMES[@]}; do
66+
ip netns exec $n ethtool -K veth0 tx-checksumming off rx-checksumming off
67+
ethtool -K $n tx-checksumming off rx-checksumming off
68+
done
69+
70+
# create data to send via tcp
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 nat {
76+
chain prerouting {
77+
type nat hook prerouting priority filter; policy accept;
78+
iifname == "${NS_NAMES[0]}" meta nfproto ipv4 tcp dport 12345 dnat ip to ${ALL_INSIDE_IP4[-1]}:10000
79+
iifname == "${NS_NAMES[0]}" meta nfproto ipv6 tcp dport 12345 dnat ip6 to [${ALL_INSIDE_IP6[-1]}]:10000
80+
}
81+
chain postrouting {
82+
type nat hook postrouting priority filter; policy accept;
83+
oifname "${NS_NAMES[-1]}" masquerade
84+
}
85+
}
86+
table inet filter {
87+
flowtable ft {
88+
hook ingress priority filter
89+
devices = { ${NS_NAMES[0]}, ${NS_NAMES[-1]} }
90+
}
91+
chain forward {
92+
type filter hook forward priority filter
93+
meta l4proto { tcp } flow add @ft
94+
}
95+
}
96+
EOF
97+
# wait a bit to configure nft
98+
sleep 2
99+
100+
check_run $XDP_FORWARD load -f flowtable ${NS_NAMES[0]}
101+
102+
PID=$(start_background_ns_devnull "nc -4 -l --no-shutdown 10000")
103+
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -4 ${OUTSIDE_IP4} 12345 < ${infile}
104+
stop_background $PID
105+
106+
PID=$(start_background_ns_devnull "nc -6 -l --no-shutdown 10000")
107+
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -6 ${OUTSIDE_IP6} 12345 < ${infile}
108+
stop_background $PID
109+
}
110+
55111
cleanup_tests()
56112
{
113+
# enable {tx,rx} checksum offload
114+
for n in ${NS_NAMES[@]}; do
115+
ip netns exec $n ethtool -K veth0 tx-checksumming on rx-checksumming on
116+
ethtool -K $n tx-checksumming on rx-checksumming on
117+
done >/dev/null 2>&1
57118
$XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1
58119
$XDP_LOADER unload $NS --all >/dev/null 2>&1
120+
check_run nft flush ruleset >/dev/null 2>&1
121+
[ -f ${infile} ] && rm -f ${infile}
59122
}

0 commit comments

Comments
 (0)