|
1 | 1 | XDP_LOADER=${XDP_LOADER:-./xdp-loader}
|
2 | 2 | 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" |
4 | 4 |
|
| 5 | +infile="$(mktemp)" |
5 | 6 |
|
6 | 7 | test_ping()
|
7 | 8 | {
|
@@ -52,8 +53,70 @@ test_fwd_direct()
|
52 | 53 | check_run $XDP_FORWARD unload ${NS_NAMES[@]}
|
53 | 54 | }
|
54 | 55 |
|
| 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 | + |
55 | 111 | cleanup_tests()
|
56 | 112 | {
|
| 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 |
57 | 118 | $XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1
|
58 | 119 | $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} |
59 | 122 | }
|
0 commit comments