1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test is for checking the VXLAN vni filtering api and
5# datapath.
6# It simulates two hypervisors running two VMs each using four network
7# six namespaces: two for the HVs, four for the VMs. Each VM is
8# connected to a separate bridge. The VM's use overlapping vlans and
9# hence the separate bridge domain. Each vxlan device is a collect
10# metadata device with vni filtering and hence has the ability to
11# terminate configured vni's only.
12
13#  +--------------------------------+     +------------------------------------+
14#  |  vm-11 netns                   |     |  vm-21 netns                       |
15#  |                                |     |                                    |
16#  |+------------+  +-------------+ |     |+-------------+ +----------------+  |
17#  ||veth-11.10  |  |veth-11.20   | |     ||veth-21.10   | | veth-21.20     |  |
18#  ||10.0.10.11/24  |10.0.20.11/24| |     ||10.0.10.21/24| | 10.0.20.21/24  |  |
19#  |+------|-----+  +|------------+ |     |+-----------|-+ +---|------------+  |
20#  |       |         |              |     |            |       |               |
21#  |       |         |              |     |         +------------+             |
22#  |      +------------+            |     |         | veth-21    |             |
23#  |      | veth-11    |            |     |         |            |             |
24#  |      |            |            |     |         +-----|------+             |
25#  |      +-----|------+            |     |               |                    |
26#  |            |                   |     |               |                    |
27#  +------------|-------------------+     +---------------|--------------------+
28#  +------------|-----------------------------------------|-------------------+
29#  |      +-----|------+                            +-----|------+            |
30#  |      |vethhv-11   |                            |vethhv-21   |            |
31#  |      +----|-------+                            +-----|------+            |
32#  |       +---|---+                                  +---|--+                |
33#  |       |  br1  |                                  | br2  |                |
34#  |       +---|---+                                  +---|--+                |
35#  |       +---|----+                                 +---|--+                |
36#  |       |  vxlan1|                                 |vxlan2|                |
37#  |       +--|-----+                                 +--|---+                |
38#  |          |                                          |                    |
39#  |          |         +---------------------+          |                    |
40#  |          |         |veth0                |          |                    |
41#  |          +---------|172.16.0.1/24        -----------+                    |
42#  |                    |2002:fee1::1/64      |                               |
43#  | hv-1 netns         +--------|------------+                               |
44#  +-----------------------------|--------------------------------------------+
45#                                |
46#  +-----------------------------|--------------------------------------------+
47#  | hv-2 netns         +--------|-------------+                              |
48#  |                    | veth0                |                              |
49#  |             +------| 172.16.0.2/24        |---+                          |
50#  |             |      | 2002:fee1::2/64      |   |                          |
51#  |             |      |                      |   |                          |
52#  |             |      +----------------------+   |         -                |
53#  |             |                                 |                          |
54#  |           +-|-------+                +--------|-+                        |
55#  |           | vxlan1  |                |  vxlan2  |                        |
56#  |           +----|----+                +---|------+                        |
57#  |             +--|--+                    +-|---+                           |
58#  |             | br1 |                    | br2 |                           |
59#  |             +--|--+                    +--|--+                           |
60#  |          +-----|-------+             +----|-------+                      |
61#  |          | vethhv-12   |             |vethhv-22   |                      |
62#  |          +------|------+             +-------|----+                      |
63#  +-----------------|----------------------------|---------------------------+
64#                    |                            |
65#  +-----------------|-----------------+ +--------|---------------------------+
66#  |         +-------|---+             | |     +--|---------+                 |
67#  |         | veth-12   |             | |     |veth-22     |                 |
68#  |         +-|--------|+             | |     +--|--------|+                 |
69#  |           |        |              | |        |        |                  |
70#  |+----------|--+ +---|-----------+  | |+-------|-----+ +|---------------+  |
71#  ||veth-12.10   | |veth-12.20     |  | ||veth-22.10   | |veth-22.20      |  |
72#  ||10.0.10.12/24| |10.0.20.12/24  |  | ||10.0.10.22/24| |10.0.20.22/24   |  |
73#  |+-------------+ +---------------+  | |+-------------+ +----------------+  |
74#  |                                   | |                                    |
75#  |                                   | |                                    |
76#  | vm-12 netns                       | |vm-22 netns                         |
77#  +-----------------------------------+ +------------------------------------+
78#
79#
80# This test tests the new vxlan vnifiltering api
81
82ret=0
83# Kselftest framework requirement - SKIP code is 4.
84ksft_skip=4
85
86# all tests in this script. Can be overridden with -t option
87TESTS="
88	vxlan_vnifilter_api
89	vxlan_vnifilter_datapath
90	vxlan_vnifilter_datapath_pervni
91	vxlan_vnifilter_datapath_mgroup
92	vxlan_vnifilter_datapath_mgroup_pervni
93	vxlan_vnifilter_metadata_and_traditional_mix
94"
95VERBOSE=0
96PAUSE_ON_FAIL=no
97PAUSE=no
98
99which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
100
101log_test()
102{
103	local rc=$1
104	local expected=$2
105	local msg="$3"
106
107	if [ ${rc} -eq ${expected} ]; then
108		printf "    TEST: %-60s  [ OK ]\n" "${msg}"
109		nsuccess=$((nsuccess+1))
110	else
111		ret=1
112		nfail=$((nfail+1))
113		printf "    TEST: %-60s  [FAIL]\n" "${msg}"
114		if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
115		echo
116			echo "hit enter to continue, 'q' to quit"
117			read a
118			[ "$a" = "q" ] && exit 1
119		fi
120	fi
121
122	if [ "${PAUSE}" = "yes" ]; then
123		echo
124		echo "hit enter to continue, 'q' to quit"
125		read a
126		[ "$a" = "q" ] && exit 1
127	fi
128}
129
130run_cmd()
131{
132	local cmd="$1"
133	local out
134	local stderr="2>/dev/null"
135
136	if [ "$VERBOSE" = "1" ]; then
137		printf "COMMAND: $cmd\n"
138		stderr=
139	fi
140
141	out=$(eval $cmd $stderr)
142	rc=$?
143	if [ "$VERBOSE" = "1" -a -n "$out" ]; then
144		echo "    $out"
145	fi
146
147	return $rc
148}
149
150check_hv_connectivity() {
151	ip netns exec hv-1 ping -c 1 -W 1 $1 &>/dev/null
152	sleep 1
153	ip netns exec hv-1 ping -c 1 -W 1 $2 &>/dev/null
154
155	return $?
156}
157
158check_vm_connectivity() {
159	run_cmd "ip netns exec vm-11 ping -c 1 -W 1 10.0.10.12"
160	log_test $? 0 "VM connectivity over $1 (ipv4 default rdst)"
161
162	run_cmd "ip netns exec vm-21 ping -c 1 -W 1 10.0.10.22"
163	log_test $? 0 "VM connectivity over $1 (ipv6 default rdst)"
164}
165
166cleanup() {
167	ip link del veth-hv-1 2>/dev/null || true
168	ip link del vethhv-11 vethhv-12 vethhv-21 vethhv-22 2>/dev/null || true
169
170	for ns in hv-1 hv-2 vm-11 vm-21 vm-12 vm-22 vm-31 vm-32; do
171		ip netns del $ns 2>/dev/null || true
172	done
173}
174
175trap cleanup EXIT
176
177setup-hv-networking() {
178	hv=$1
179	local1=$2
180	mask1=$3
181	local2=$4
182	mask2=$5
183
184	ip netns add hv-$hv
185	ip link set veth-hv-$hv netns hv-$hv
186	ip -netns hv-$hv link set veth-hv-$hv name veth0
187	ip -netns hv-$hv addr add $local1/$mask1 dev veth0
188	ip -netns hv-$hv addr add $local2/$mask2 dev veth0
189	ip -netns hv-$hv link set veth0 up
190}
191
192# Setups a "VM" simulated by a netns an a veth pair
193# example: setup-vm <hvid> <vmid> <brid> <VATTRS> <mcast_for_bum>
194# VATTRS = comma separated "<vlan>-<v[46]>-<localip>-<remoteip>-<VTYPE>-<vxlandstport>"
195# VTYPE = vxlan device type. "default = traditional device, metadata = metadata device
196#         vnifilter = vnifiltering device,
197#         vnifilterg = vnifiltering device with per vni group/remote"
198# example:
199#     setup-vm 1 11 1 \
200#         10-v4-172.16.0.1-239.1.1.100-vnifilterg,20-v4-172.16.0.1-239.1.1.100-vnifilterg 1
201#
202setup-vm() {
203	hvid=$1
204	vmid=$2
205	brid=$3
206	vattrs=$4
207	mcast=$5
208	lastvxlandev=""
209
210	# create bridge
211	ip -netns hv-$hvid link add br$brid type bridge vlan_filtering 1 vlan_default_pvid 0 \
212		mcast_snooping 0
213	ip -netns hv-$hvid link set br$brid up
214
215	# create vm namespace and interfaces and connect to hypervisor
216	# namespace
217	ip netns add vm-$vmid
218	hvvethif="vethhv-$vmid"
219	vmvethif="veth-$vmid"
220	ip link add $hvvethif type veth peer name $vmvethif
221	ip link set $hvvethif netns hv-$hvid
222	ip link set $vmvethif netns vm-$vmid
223	ip -netns hv-$hvid link set $hvvethif up
224	ip -netns vm-$vmid link set $vmvethif up
225	ip -netns hv-$hvid link set $hvvethif master br$brid
226
227	# configure VM vlan/vni filtering on hypervisor
228	for vmap in $(echo $vattrs | cut -d "," -f1- --output-delimiter=' ')
229	do
230	local vid=$(echo $vmap | awk -F'-' '{print ($1)}')
231	local family=$(echo $vmap | awk -F'-' '{print ($2)}')
232	local localip=$(echo $vmap | awk -F'-' '{print ($3)}')
233	local group=$(echo $vmap | awk -F'-' '{print ($4)}')
234	local vtype=$(echo $vmap | awk -F'-' '{print ($5)}')
235	local port=$(echo $vmap | awk -F'-' '{print ($6)}')
236
237	ip -netns vm-$vmid link add name $vmvethif.$vid link $vmvethif type vlan id $vid
238	ip -netns vm-$vmid addr add 10.0.$vid.$vmid/24 dev $vmvethif.$vid
239	ip -netns vm-$vmid link set $vmvethif.$vid up
240
241	tid=$vid
242	vxlandev="vxlan$brid"
243	vxlandevflags=""
244
245	if [[ -n $vtype && $vtype == "metadata" ]]; then
246	   vxlandevflags="$vxlandevflags external"
247	elif [[ -n $vtype && $vtype == "vnifilter" || $vtype == "vnifilterg" ]]; then
248	   vxlandevflags="$vxlandevflags external vnifilter"
249	   tid=$((vid+brid))
250	else
251	   vxlandevflags="$vxlandevflags id $tid"
252	   vxlandev="vxlan$tid"
253	fi
254
255	if [[ -n $vtype && $vtype != "vnifilterg" ]]; then
256	   if [[ -n "$group" && "$group" != "null" ]]; then
257	      if [ $mcast -eq 1 ]; then
258		 vxlandevflags="$vxlandevflags group $group"
259	      else
260		 vxlandevflags="$vxlandevflags remote $group"
261	      fi
262	   fi
263	fi
264
265	if [[ -n "$port" && "$port" != "default" ]]; then
266	      vxlandevflags="$vxlandevflags dstport $port"
267	fi
268
269	# create vxlan device
270	if [ "$vxlandev" != "$lastvxlandev" ]; then
271	     ip -netns hv-$hvid link add $vxlandev type vxlan local $localip $vxlandevflags dev veth0 2>/dev/null
272	     ip -netns hv-$hvid link set $vxlandev master br$brid
273	     ip -netns hv-$hvid link set $vxlandev up
274	     lastvxlandev=$vxlandev
275	fi
276
277	# add vlan
278	bridge -netns hv-$hvid vlan add vid $vid dev $hvvethif
279	bridge -netns hv-$hvid vlan add vid $vid pvid dev $vxlandev
280
281	# Add bridge vni filter for tx
282	if [[ -n $vtype && $vtype == "metadata" || $vtype == "vnifilter" || $vtype == "vnifilterg" ]]; then
283	   bridge -netns hv-$hvid link set dev $vxlandev vlan_tunnel on
284	   bridge -netns hv-$hvid vlan add dev $vxlandev vid $vid tunnel_info id $tid
285	fi
286
287	if [[ -n $vtype && $vtype == "metadata" ]]; then
288	   bridge -netns hv-$hvid fdb add 00:00:00:00:00:00 dev $vxlandev \
289								src_vni $tid vni $tid dst $group self
290	elif [[ -n $vtype && $vtype == "vnifilter" ]]; then
291	   # Add per vni rx filter with 'bridge vni' api
292	   bridge -netns hv-$hvid vni add dev $vxlandev vni $tid
293	elif [[ -n $vtype && $vtype == "vnifilterg" ]]; then
294	   # Add per vni group config with 'bridge vni' api
295	   if [ -n "$group" ]; then
296		if [ $mcast -eq 1 ]; then
297			bridge -netns hv-$hvid vni add dev $vxlandev vni $tid group $group
298		else
299			bridge -netns hv-$hvid vni add dev $vxlandev vni $tid remote $group
300		fi
301	   fi
302	fi
303	done
304}
305
306setup_vnifilter_api()
307{
308	ip link add veth-host type veth peer name veth-testns
309	ip netns add testns
310	ip link set veth-testns netns testns
311}
312
313cleanup_vnifilter_api()
314{
315	ip link del veth-host 2>/dev/null || true
316	ip netns del testns 2>/dev/null || true
317}
318
319# tests vxlan filtering api
320vxlan_vnifilter_api()
321{
322	hv1addr1="172.16.0.1"
323	hv2addr1="172.16.0.2"
324	hv1addr2="2002:fee1::1"
325	hv2addr2="2002:fee1::2"
326	localip="172.16.0.1"
327	group="239.1.1.101"
328
329	cleanup_vnifilter_api &>/dev/null
330	setup_vnifilter_api
331
332	# Duplicate vni test
333	# create non-vnifiltering traditional vni device
334	run_cmd "ip -netns testns link add vxlan100 type vxlan id 100 local $localip dev veth-testns dstport 4789"
335	log_test $? 0 "Create traditional vxlan device"
336
337	# create vni filtering device
338	run_cmd "ip -netns testns link add vxlan-ext1 type vxlan vnifilter local $localip dev veth-testns dstport 4789"
339	log_test $? 1 "Cannot create vnifilter device without external flag"
340
341	run_cmd "ip -netns testns link add vxlan-ext1 type vxlan external vnifilter local $localip dev veth-testns dstport 4789"
342	log_test $? 0 "Creating external vxlan device with vnifilter flag"
343
344	run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 100"
345	log_test $? 0 "Cannot set in-use vni id on vnifiltering device"
346
347	run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 200"
348	log_test $? 0 "Set new vni id on vnifiltering device"
349
350	run_cmd "ip -netns testns link add vxlan-ext2 type vxlan external vnifilter local $localip dev veth-testns dstport 4789"
351	log_test $? 0 "Create second external vxlan device with vnifilter flag"
352
353	run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 200"
354	log_test $? 255 "Cannot set in-use vni id on vnifiltering device"
355
356	run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300"
357	log_test $? 0 "Set new vni id on vnifiltering device"
358
359	# check in bridge vni show
360	run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300"
361	log_test $? 0 "Update vni id on vnifiltering device"
362
363	run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 400"
364	log_test $? 0 "Add new vni id on vnifiltering device"
365
366	# add multicast group per vni
367	run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 200 group $group"
368	log_test $? 0 "Set multicast group on existing vni"
369
370	# add multicast group per vni
371	run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300 group $group"
372	log_test $? 0 "Set multicast group on existing vni"
373
374	# set vnifilter on an existing external vxlan device
375	run_cmd "ip -netns testns link set dev vxlan-ext1 type vxlan external vnifilter"
376	log_test $? 2 "Cannot set vnifilter flag on a device"
377
378	# change vxlan vnifilter flag
379	run_cmd "ip -netns testns link set dev vxlan-ext1 type vxlan external novnifilter"
380	log_test $? 2 "Cannot unset vnifilter flag on a device"
381}
382
383# Sanity test vnifilter datapath
384# vnifilter vnis inherit BUM group from
385# vxlan device
386vxlan_vnifilter_datapath()
387{
388	hv1addr1="172.16.0.1"
389	hv2addr1="172.16.0.2"
390	hv1addr2="2002:fee1::1"
391	hv2addr2="2002:fee1::2"
392
393	ip link add veth-hv-1 type veth peer name veth-hv-2
394	setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 $hv2addr1 $hv2addr2
395	setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 $hv1addr1 $hv1addr2
396
397        check_hv_connectivity hv2addr1 hv2addr2
398
399	setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilter,20-v4-$hv1addr1-$hv2addr1-vnifilter 0
400	setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilter,20-v6-$hv1addr2-$hv2addr2-vnifilter 0
401
402	setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilter,20-v4-$hv2addr1-$hv1addr1-vnifilter 0
403	setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilter,20-v6-$hv2addr2-$hv1addr2-vnifilter 0
404
405        check_vm_connectivity "vnifiltering vxlan"
406}
407
408# Sanity test vnifilter datapath
409# with vnifilter per vni configured BUM
410# group/remote
411vxlan_vnifilter_datapath_pervni()
412{
413	hv1addr1="172.16.0.1"
414	hv2addr1="172.16.0.2"
415	hv1addr2="2002:fee1::1"
416	hv2addr2="2002:fee1::2"
417
418	ip link add veth-hv-1 type veth peer name veth-hv-2
419	setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64
420	setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64
421
422        check_hv_connectivity hv2addr1 hv2addr2
423
424	setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilterg,20-v4-$hv1addr1-$hv2addr1-vnifilterg 0
425	setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilterg,20-v6-$hv1addr2-$hv2addr2-vnifilterg 0
426
427	setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilterg,20-v4-$hv2addr1-$hv1addr1-vnifilterg 0
428	setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilterg,20-v6-$hv2addr2-$hv1addr2-vnifilterg 0
429
430        check_vm_connectivity "vnifiltering vxlan pervni remote"
431}
432
433
434vxlan_vnifilter_datapath_mgroup()
435{
436	hv1addr1="172.16.0.1"
437	hv2addr1="172.16.0.2"
438	hv1addr2="2002:fee1::1"
439	hv2addr2="2002:fee1::2"
440        group="239.1.1.100"
441        group6="ff07::1"
442
443	ip link add veth-hv-1 type veth peer name veth-hv-2
444	setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64
445	setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64
446
447        check_hv_connectivity hv2addr1 hv2addr2
448
449	setup-vm 1 11 1 10-v4-$hv1addr1-$group-vnifilter,20-v4-$hv1addr1-$group-vnifilter 1
450	setup-vm 1 21 2 "10-v6-$hv1addr2-$group6-vnifilter,20-v6-$hv1addr2-$group6-vnifilter" 1
451
452        setup-vm 2 12 1 10-v4-$hv2addr1-$group-vnifilter,20-v4-$hv2addr1-$group-vnifilter 1
453        setup-vm 2 22 2 10-v6-$hv2addr2-$group6-vnifilter,20-v6-$hv2addr2-$group6-vnifilter 1
454
455        check_vm_connectivity "vnifiltering vxlan mgroup"
456}
457
458vxlan_vnifilter_datapath_mgroup_pervni()
459{
460	hv1addr1="172.16.0.1"
461	hv2addr1="172.16.0.2"
462	hv1addr2="2002:fee1::1"
463	hv2addr2="2002:fee1::2"
464        group="239.1.1.100"
465        group6="ff07::1"
466
467	ip link add veth-hv-1 type veth peer name veth-hv-2
468	setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64
469	setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64
470
471        check_hv_connectivity hv2addr1 hv2addr2
472
473	setup-vm 1 11 1 10-v4-$hv1addr1-$group-vnifilterg,20-v4-$hv1addr1-$group-vnifilterg 1
474	setup-vm 1 21 2 10-v6-$hv1addr2-$group6-vnifilterg,20-v6-$hv1addr2-$group6-vnifilterg 1
475
476        setup-vm 2 12 1 10-v4-$hv2addr1-$group-vnifilterg,20-v4-$hv2addr1-$group-vnifilterg 1
477        setup-vm 2 22 2 10-v6-$hv2addr2-$group6-vnifilterg,20-v6-$hv2addr2-$group6-vnifilterg 1
478
479        check_vm_connectivity "vnifiltering vxlan pervni mgroup"
480}
481
482vxlan_vnifilter_metadata_and_traditional_mix()
483{
484	hv1addr1="172.16.0.1"
485	hv2addr1="172.16.0.2"
486	hv1addr2="2002:fee1::1"
487	hv2addr2="2002:fee1::2"
488
489	ip link add veth-hv-1 type veth peer name veth-hv-2
490	setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64
491	setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64
492
493        check_hv_connectivity hv2addr1 hv2addr2
494
495	setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilter,20-v4-$hv1addr1-$hv2addr1-vnifilter 0
496	setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilter,20-v6-$hv1addr2-$hv2addr2-vnifilter 0
497	setup-vm 1 31 3 30-v4-$hv1addr1-$hv2addr1-default-4790,40-v6-$hv1addr2-$hv2addr2-default-4790,50-v4-$hv1addr1-$hv2addr1-metadata-4791 0
498
499
500	setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilter,20-v4-$hv2addr1-$hv1addr1-vnifilter 0
501	setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilter,20-v6-$hv2addr2-$hv1addr2-vnifilter 0
502	setup-vm 2 32 3 30-v4-$hv2addr1-$hv1addr1-default-4790,40-v6-$hv2addr2-$hv1addr2-default-4790,50-v4-$hv2addr1-$hv1addr1-metadata-4791 0
503
504        check_vm_connectivity "vnifiltering vxlan pervni remote mix"
505
506	# check VM connectivity over traditional/non-vxlan filtering vxlan devices
507	run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.30.32"
508        log_test $? 0 "VM connectivity over traditional vxlan (ipv4 default rdst)"
509
510	run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.40.32"
511        log_test $? 0 "VM connectivity over traditional vxlan (ipv6 default rdst)"
512
513	run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.50.32"
514        log_test $? 0 "VM connectivity over metadata nonfiltering vxlan (ipv4 default rdst)"
515}
516
517while getopts :t:pP46hv o
518do
519	case $o in
520		t) TESTS=$OPTARG;;
521		p) PAUSE_ON_FAIL=yes;;
522		P) PAUSE=yes;;
523		v) VERBOSE=$(($VERBOSE + 1));;
524		h) usage; exit 0;;
525		*) usage; exit 1;;
526	esac
527done
528
529# make sure we don't pause twice
530[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
531
532if [ "$(id -u)" -ne 0 ];then
533	echo "SKIP: Need root privileges"
534	exit $ksft_skip;
535fi
536
537if [ ! -x "$(command -v ip)" ]; then
538	echo "SKIP: Could not run test without ip tool"
539	exit $ksft_skip
540fi
541
542ip link help vxlan 2>&1 | grep -q "vnifilter"
543if [ $? -ne 0 ]; then
544   echo "SKIP: iproute2 too old, missing vxlan dev vnifilter setting"
545   sync
546   exit $ksft_skip
547fi
548
549bridge vni help 2>&1 | grep -q "Usage: bridge vni"
550if [ $? -ne 0 ]; then
551   echo "SKIP: iproute2 bridge lacks vxlan vnifiltering support"
552   exit $ksft_skip
553fi
554
555# start clean
556cleanup &> /dev/null
557
558for t in $TESTS
559do
560	case $t in
561	none) setup; exit 0;;
562	*) $t; cleanup;;
563	esac
564done
565
566if [ "$TESTS" != "none" ]; then
567	printf "\nTests passed: %3d\n" ${nsuccess}
568	printf "Tests failed: %3d\n"   ${nfail}
569fi
570
571exit $ret
572