Skip to content

Commit

Permalink
xdp-forward: Add selftest for flowtable mode
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
  • Loading branch information
LorenzoBianconi committed Sep 25, 2024
1 parent 042d4c2 commit 004e068
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/testing/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ALL_TESTS=""
VERBOSE_TESTS=${V:-0}
NUM_NS=2

NEEDED_TOOLS="capinfos ethtool ip ping sed tc tcpdump timeout nc tshark"
NEEDED_TOOLS="capinfos ethtool ip ping sed tc tcpdump timeout nc tshark nft"

if [ -f "$TEST_CONFIG" ]; then
source "$TEST_CONFIG"
Expand Down
57 changes: 56 additions & 1 deletion xdp-forward/tests/test-xdp-forward.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XDP_LOADER=${XDP_LOADER:-./xdp-loader}
XDP_FORWARD=${XDP_FORWARD:-./xdp-forward}
ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct"
ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct test_flowtable"


test_ping()
Expand Down Expand Up @@ -52,6 +52,61 @@ test_fwd_direct()
check_run $XDP_FORWARD unload ${NS_NAMES[@]}
}

test_flowtable()
{
# veth NAPI GRO support added this symbol; forwarding won't work without it
skip_if_missing_kernel_symbol veth_set_features
# check if bpf flowtable lookup is available
skip_if_missing_kernel_symbol bpf_xdp_flow_lookup

# disable {tx,rx} checksum offload since it is not currently suported
# by XDP_REDIRECT
for n in ${NS_NAMES[@]}; do
ip netns exec $n ethtool -K veth0 tx-checksumming off rx-checksumming off
ethtool -K $n tx-checksumming off rx-checksumming off
done

# create data to send via tcp
local infile="$(mktemp)"
dd if=/dev/urandom of="${infile}" bs=8192 count=32 status=none

# create flowtable configuration
check_run nft -f /dev/stdin <<EOF
table inet filter {
flowtable ft {
hook ingress priority filter
devices = { ${NS_NAMES[0]}, ${NS_NAMES[-1]} }
}
chain forward {
type filter hook forward priority filter
meta l4proto { tcp } flow add @ft
}
}
EOF
# wait a bit to configure nft
sleep 2

check_run $XDP_FORWARD load -f flowtable ${NS_NAMES[0]}

PID=$(start_background_ns_devnull "nc -4 -l --no-shutdown 10000")
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -4 ${ALL_INSIDE_IP4[-1]} 10000 < ${infile}
stop_background $PID

PID=$(start_background_ns_devnull "nc -6 -l --no-shutdown 10000")
check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -6 ${ALL_INSIDE_IP6[-1]} 10000 < ${infile}
stop_background $PID

check_run $XDP_FORWARD unload ${NS_NAMES[0]}
check_run nft flush ruleset
# enable {tx,rx} checksum offload
for n in ${NS_NAMES[@]}; do
ip netns exec $n ethtool -K veth0 tx-checksumming on rx-checksumming on
ethtool -K $n tx-checksumming on rx-checksumming on
done

rm -f ${infile}
}

cleanup_tests()
{
$XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1
Expand Down

0 comments on commit 004e068

Please sign in to comment.