|
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" |
4 |
| - |
| 3 | +ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct test_flowtable" |
| 4 | +INFILE="$(mktemp)" |
5 | 5 |
|
6 | 6 | test_ping()
|
7 | 7 | {
|
@@ -52,8 +52,85 @@ test_fwd_direct()
|
52 | 52 | check_run $XDP_FORWARD unload ${NS_NAMES[@]}
|
53 | 53 | }
|
54 | 54 |
|
| 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 | + dd if=/dev/urandom of="${INFILE}" bs=8192 count=32 status=none |
| 71 | + |
| 72 | + # create flowtable configuration in the main namespace |
| 73 | + check_run nft -f /dev/stdin <<EOF |
| 74 | +table inet nat { |
| 75 | + chain prerouting { |
| 76 | + type nat hook prerouting priority filter; policy accept; |
| 77 | + iifname == "${NS_NAMES[0]}" meta nfproto ipv4 tcp dport 12345 dnat ip to ${ALL_INSIDE_IP4[-1]}:10000 |
| 78 | + iifname == "${NS_NAMES[0]}" meta nfproto ipv6 tcp dport 12345 dnat ip6 to [${ALL_INSIDE_IP6[-1]}]:10000 |
| 79 | + } |
| 80 | + chain postrouting { |
| 81 | + type nat hook postrouting priority filter; policy accept; |
| 82 | + oifname "${NS_NAMES[-1]}" masquerade |
| 83 | + } |
| 84 | +} |
| 85 | +table inet filter { |
| 86 | + flowtable ft { |
| 87 | + hook ingress priority filter |
| 88 | + devices = { ${NS_NAMES[0]}, ${NS_NAMES[-1]} } |
| 89 | + } |
| 90 | + chain forward { |
| 91 | + type filter hook forward priority filter |
| 92 | + meta l4proto { tcp } flow add @ft |
| 93 | + } |
| 94 | +} |
| 95 | +EOF |
| 96 | + |
| 97 | + # Add sone nft rules to check natting is done properly in |
| 98 | + # the main namespace |
| 99 | + check_run ip netns exec ${NS_NAMES[-1]} nft -f /dev/stdin <<EOF |
| 100 | +table inet filter { |
| 101 | + chain input { |
| 102 | + type filter hook input priority 0; policy drop |
| 103 | + ip saddr $OUTSIDE_IP4 ip daddr ${ALL_INSIDE_IP4[-1]} tcp dport 10000 accept |
| 104 | + ip6 saddr $OUTSIDE_IP6 ip6 daddr ${ALL_INSIDE_IP6[-1]} tcp dport 10000 accept |
| 105 | + } |
| 106 | +} |
| 107 | +EOF |
| 108 | + # wait a bit to configure nft |
| 109 | + sleep 2 |
| 110 | + |
| 111 | + check_run $XDP_FORWARD load -f flowtable ${NS_NAMES[0]} |
| 112 | + |
| 113 | + PID=$(start_background_ns_devnull "nc -4 -l --no-shutdown 10000") |
| 114 | + check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -4 ${OUTSIDE_IP4} 12345 < ${INFILE} |
| 115 | + stop_background $PID |
| 116 | + |
| 117 | + PID=$(start_background_ns_devnull "nc -6 -l --no-shutdown 10000") |
| 118 | + check_run ip netns exec ${NS_NAMES[0]} nc -w 1 -6 ${OUTSIDE_IP6} 12345 < ${INFILE} |
| 119 | + stop_background $PID |
| 120 | +} |
| 121 | + |
55 | 122 | cleanup_tests()
|
56 | 123 | {
|
57 |
| - $XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1 |
58 |
| - $XDP_LOADER unload $NS --all >/dev/null 2>&1 |
| 124 | + # enable {tx,rx} checksum offload |
| 125 | + for n in ${NS_NAMES[@]}; do |
| 126 | + ip netns exec $n ethtool -K veth0 tx-checksumming on rx-checksumming on |
| 127 | + ethtool -K $n tx-checksumming on rx-checksumming on |
| 128 | + done >/dev/null 2>&1 |
| 129 | + { |
| 130 | + $XDP_FORWARD unload ${NS_NAMES[@]} |
| 131 | + $XDP_LOADER unload $NS --all |
| 132 | + check_run ip netns exec ${NS_NAMES[-1]} nft flush ruleset |
| 133 | + check_run nft flush ruleset |
| 134 | + rm -f ${INFILE} |
| 135 | + } >/dev/null 2>&1 |
59 | 136 | }
|
0 commit comments