1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4source lib.sh 5TESTS=" 6 basic_tx_ipv4 7 basic_tx_ipv6 8 learning 9 proxy_ipv4 10 proxy_ipv6 11" 12VERBOSE=0 13 14################################################################################ 15# Utilities 16 17run_cmd() 18{ 19 local cmd="$1" 20 local out 21 local stderr="2>/dev/null" 22 23 if [ "$VERBOSE" = "1" ]; then 24 echo "COMMAND: $cmd" 25 stderr= 26 fi 27 28 out=$(eval "$cmd" "$stderr") 29 rc=$? 30 if [ "$VERBOSE" -eq 1 ] && [ -n "$out" ]; then 31 echo " $out" 32 fi 33 34 return $rc 35} 36 37################################################################################ 38# Cleanup 39 40exit_cleanup_all() 41{ 42 cleanup_all_ns 43 exit "${EXIT_STATUS}" 44} 45 46################################################################################ 47# Tests 48 49nh_stats_get() 50{ 51 ip -n "$ns1" -s -j nexthop show id 10 | jq ".[][\"group_stats\"][][\"packets\"]" 52} 53 54tc_stats_get() 55{ 56 tc_rule_handle_stats_get "dev dummy1 egress" 101 ".packets" "-n $ns1" 57} 58 59nh_stats_get_port() 60{ 61 ip -n "$ns1" -s -j nexthop show id 20 | \ 62 jq ".[][\"group_stats\"][][\"packets\"]" 63} 64 65tc_stats_get_port() 66{ 67 tc_rule_handle_stats_get "dev dummy1 egress" 102 ".packets" "-n $ns1" 68} 69 70basic_tx_common() 71{ 72 local af_str=$1; shift 73 local proto=$1; shift 74 local local_addr=$1; shift 75 local plen=$1; shift 76 local remote_addr=$1; shift 77 78 RET=0 79 80 # Test basic Tx functionality. Check that stats are incremented on 81 # both the FDB nexthop group and the egress device. 82 83 run_cmd "ip -n $ns1 link add name dummy1 up type dummy" 84 run_cmd "ip -n $ns1 route add $remote_addr/$plen dev dummy1" 85 run_cmd "tc -n $ns1 qdisc add dev dummy1 clsact" 86 run_cmd "tc -n $ns1 filter add dev dummy1 egress proto $proto pref 1 handle 101 flower ip_proto udp dst_ip $remote_addr dst_port 4789 action pass" 87 88 run_cmd "ip -n $ns1 address add $local_addr/$plen dev lo" 89 90 run_cmd "ip -n $ns1 nexthop add id 1 via $remote_addr fdb" 91 run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 92 93 run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local $local_addr dstport 4789" 94 run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static nhid 10" 95 96 run_cmd "ip netns exec $ns1 mausezahn vx0 -a own -b 00:11:22:33:44:55 -c 1 -q" 97 98 busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" nh_stats_get > /dev/null 99 check_err $? "FDB nexthop group stats did not increase" 100 101 busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" tc_stats_get > /dev/null 102 check_err $? "tc filter stats did not increase" 103 104 # Add a second FDB nexthop group whose nexthop carries a per-nexthop 105 # destination port (NHA_DST_PORT) that differs from the VXLAN device 106 # default. Matching outer traffic must egress with that port, so a 107 # separate flower filter keyed on the new port catches it. 108 run_cmd "tc -n $ns1 filter add dev dummy1 egress proto $proto \ 109 pref 1 handle 102 flower ip_proto udp dst_ip $remote_addr \ 110 dst_port 4790 action pass" 111 112 run_cmd "ip -n $ns1 nexthop add id 2 via $remote_addr fdb dst_port 4790" 113 run_cmd "ip -n $ns1 nexthop add id 20 group 2 fdb" 114 115 run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:66 dev vx0 \ 116 self static nhid 20" 117 118 run_cmd "ip netns exec $ns1 mausezahn vx0 -a own \ 119 -b 00:11:22:33:44:66 -c 1 -q" 120 121 busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" \ 122 nh_stats_get_port > /dev/null 123 check_err $? "FDB nexthop group stats did not increase (with port)" 124 125 busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" \ 126 tc_stats_get_port > /dev/null 127 check_err $? "tc filter stats did not increase (with port)" 128 129 log_test "VXLAN FDB nexthop: $af_str basic Tx" 130} 131 132basic_tx_ipv4() 133{ 134 basic_tx_common "IPv4" ipv4 192.0.2.1 32 192.0.2.2 135} 136 137basic_tx_ipv6() 138{ 139 basic_tx_common "IPv6" ipv6 2001:db8:1::1 128 2001:db8:1::2 140} 141 142learning() 143{ 144 RET=0 145 146 # When learning is enabled on the VXLAN device, an incoming packet 147 # might try to refresh an FDB entry that points to an FDB nexthop group 148 # instead of an ordinary remote destination. Check that the kernel does 149 # not crash in this situation. 150 151 run_cmd "ip -n $ns1 address add 192.0.2.1/32 dev lo" 152 run_cmd "ip -n $ns1 address add 192.0.2.2/32 dev lo" 153 154 run_cmd "ip -n $ns1 nexthop add id 1 via 192.0.2.3 fdb" 155 run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 156 157 run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local 192.0.2.1 dstport 12345 localbypass" 158 run_cmd "ip -n $ns1 link add name vx1 up type vxlan id 10020 local 192.0.2.2 dstport 54321 learning" 159 160 run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static dst 192.0.2.2 port 54321 vni 10020" 161 run_cmd "bridge -n $ns1 fdb add 00:aa:bb:cc:dd:ee dev vx1 self static nhid 10" 162 163 run_cmd "ip netns exec $ns1 mausezahn vx0 -a 00:aa:bb:cc:dd:ee -b 00:11:22:33:44:55 -c 1 -q" 164 165 log_test "VXLAN FDB nexthop: learning" 166} 167 168proxy_common() 169{ 170 local af_str=$1; shift 171 local local_addr=$1; shift 172 local plen=$1; shift 173 local remote_addr=$1; shift 174 local neigh_addr=$1; shift 175 local ping_cmd=$1; shift 176 177 RET=0 178 179 # When the "proxy" option is enabled on the VXLAN device, the device 180 # will suppress ARP requests and IPv6 Neighbor Solicitation messages if 181 # it is able to reply on behalf of the remote host. That is, if a 182 # matching and valid neighbor entry is configured on the VXLAN device 183 # whose MAC address is not behind the "any" remote (0.0.0.0 / ::). The 184 # FDB entry for the neighbor's MAC address might point to an FDB 185 # nexthop group instead of an ordinary remote destination. Check that 186 # the kernel does not crash in this situation. 187 188 run_cmd "ip -n $ns1 address add $local_addr/$plen dev lo" 189 190 run_cmd "ip -n $ns1 nexthop add id 1 via $remote_addr fdb" 191 run_cmd "ip -n $ns1 nexthop add id 10 group 1 fdb" 192 193 run_cmd "ip -n $ns1 link add name vx0 up type vxlan id 10010 local $local_addr dstport 4789 proxy" 194 195 run_cmd "ip -n $ns1 neigh add $neigh_addr lladdr 00:11:22:33:44:55 nud perm dev vx0" 196 197 run_cmd "bridge -n $ns1 fdb add 00:11:22:33:44:55 dev vx0 self static nhid 10" 198 199 run_cmd "ip netns exec $ns1 $ping_cmd" 200 201 log_test "VXLAN FDB nexthop: $af_str proxy" 202} 203 204proxy_ipv4() 205{ 206 proxy_common "IPv4" 192.0.2.1 32 192.0.2.2 192.0.2.3 \ 207 "arping -b -c 1 -s 192.0.2.1 -I vx0 192.0.2.3" 208} 209 210proxy_ipv6() 211{ 212 proxy_common "IPv6" 2001:db8:1::1 128 2001:db8:1::2 2001:db8:1::3 \ 213 "ndisc6 -r 1 -s 2001:db8:1::1 -w 1 2001:db8:1::3 vx0" 214} 215 216################################################################################ 217# Usage 218 219usage() 220{ 221 cat <<EOF 222usage: ${0##*/} OPTS 223 224 -t <test> Test(s) to run (default: all) 225 (options: $TESTS) 226 -p Pause on fail 227 -v Verbose mode (show commands and output) 228EOF 229} 230 231################################################################################ 232# Main 233 234while getopts ":t:pvh" opt; do 235 case $opt in 236 t) TESTS=$OPTARG;; 237 p) PAUSE_ON_FAIL=yes;; 238 v) VERBOSE=$((VERBOSE + 1));; 239 h) usage; exit 0;; 240 *) usage; exit 1;; 241 esac 242done 243 244require_command mausezahn 245require_command arping 246require_command ndisc6 247require_command jq 248 249if ! ip nexthop help 2>&1 | grep -q "dst_port"; then 250 echo "SKIP: iproute2 ip too old, missing nexthop dst_port support" 251 exit "$ksft_skip" 252fi 253 254trap exit_cleanup_all EXIT 255 256for t in $TESTS 257do 258 setup_ns ns1; $t; cleanup_all_ns; 259done 260