|
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" |
5 | 4 |
|
6 | 5 | test_ping()
|
7 | 6 | {
|
@@ -52,8 +51,89 @@ test_fwd_direct()
|
52 | 51 | check_run $XDP_FORWARD unload ${NS_NAMES[@]}
|
53 | 52 | }
|
54 | 53 |
|
| 54 | +test_flowtable() |
| 55 | +{ |
| 56 | + local INPUT_FILE="${STATEDIR}/in_$$_$RANDOM" |
| 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 | + |
| 61 | + # disable {tx,rx} checksum offload since it is not currently suported |
| 62 | + # by XDP_REDIRECT |
| 63 | + for n in ${NS_NAMES[@]}; do |
| 64 | + ip netns exec $n ethtool -K veth0 tx-checksumming off rx-checksumming off |
| 65 | + ethtool -K $n tx-checksumming off rx-checksumming off |
| 66 | + done |
| 67 | + |
| 68 | + # create data to send via tcp |
| 69 | + dd if=/dev/urandom of="${INPUT_FILE}" bs=8192 count=32 status=none |
| 70 | + |
| 71 | + # create flowtable configuration in the main namespace |
| 72 | + check_run nft -f /dev/stdin <<EOF |
| 73 | +table inet nat { |
| 74 | + # enable DNAT to server <ip:port> in pre-routing chain |
| 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 | + # enable SNAT of the client ip via masquerading in post-routing chain |
| 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 | + |
| 98 | + # check if bpf flowtable lookup is available |
| 99 | + skip_if_missing_kernel_symbol bpf_xdp_flow_lookup |
| 100 | + |
| 101 | + # Add some nft rules to check {dnat/snat} is done properly in |
| 102 | + # the main namespace |
| 103 | + check_run ip netns exec ${NS_NAMES[-1]} nft -f /dev/stdin <<EOF |
| 104 | +table inet filter { |
| 105 | + chain input { |
| 106 | + type filter hook input priority 0; policy drop |
| 107 | + ip saddr $OUTSIDE_IP4 ip daddr ${ALL_INSIDE_IP4[-1]} tcp dport 10000 accept |
| 108 | + ip6 saddr $OUTSIDE_IP6 ip6 daddr ${ALL_INSIDE_IP6[-1]} tcp dport 10000 accept |
| 109 | + } |
| 110 | +} |
| 111 | +EOF |
| 112 | + # wait a bit to configure nft |
| 113 | + sleep 2 |
| 114 | + |
| 115 | + check_run $XDP_FORWARD load -f flowtable ${NS_NAMES[@]} |
| 116 | + |
| 117 | + PID=$(start_background_ns_devnull "socat -4 TCP-LISTEN:10000,reuseaddr,fork -") |
| 118 | + check_run ip netns exec ${NS_NAMES[0]} socat ${INPUT_FILE} TCP4:${OUTSIDE_IP4}:12345 |
| 119 | + stop_background $PID |
| 120 | + |
| 121 | + PID=$(start_background_ns_devnull "socat -6 TCP-LISTEN:10000,reuseaddr,fork -") |
| 122 | + check_run ip netns exec ${NS_NAMES[0]} socat ${INPUT_FILE} TCP6:[${OUTSIDE_IP6}]:12345 |
| 123 | + stop_background $PID |
| 124 | +} |
| 125 | + |
55 | 126 | cleanup_tests()
|
56 | 127 | {
|
57 |
| - $XDP_FORWARD unload ${NS_NAMES[@]} >/dev/null 2>&1 |
58 |
| - $XDP_LOADER unload $NS --all >/dev/null 2>&1 |
| 128 | + # enable {tx,rx} checksum offload |
| 129 | + for n in ${NS_NAMES[@]}; do |
| 130 | + ip netns exec $n ethtool -K veth0 tx-checksumming on rx-checksumming on |
| 131 | + ethtool -K $n tx-checksumming on rx-checksumming on |
| 132 | + done >/dev/null 2>&1 |
| 133 | + { |
| 134 | + $XDP_FORWARD unload ${NS_NAMES[@]} |
| 135 | + $XDP_LOADER unload $NS --all |
| 136 | + check_run ip netns exec ${NS_NAMES[-1]} nft flush ruleset |
| 137 | + check_run nft flush ruleset |
| 138 | + } >/dev/null 2>&1 |
59 | 139 | }
|
0 commit comments