xref: /linux/tools/testing/selftests/net/forwarding/tc_shblocks.sh (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="shared_block_test"
5NUM_NETIFS=4
6source tc_common.sh
7source lib.sh
8
9tcflags="skip_hw"
10
11h1_create()
12{
13	simple_if_init $h1 192.0.2.1/24
14}
15
16h1_destroy()
17{
18	simple_if_fini $h1 192.0.2.1/24
19}
20
21h2_create()
22{
23	simple_if_init $h2 192.0.2.1/24
24}
25
26h2_destroy()
27{
28	simple_if_fini $h2 192.0.2.1/24
29}
30
31switch_create()
32{
33	simple_if_init $swp1 192.0.2.2/24
34	tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
35
36	simple_if_init $swp2 192.0.2.2/24
37	tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
38}
39
40switch_destroy()
41{
42	tc qdisc del dev $swp2 clsact
43	simple_if_fini $swp2 192.0.2.2/24
44
45	tc qdisc del dev $swp1 clsact
46	simple_if_fini $swp1 192.0.2.2/24
47}
48
49shared_block_test()
50{
51	RET=0
52
53	tc filter add block 22 protocol ip pref 1 handle 101 flower \
54		$tcflags dst_ip 192.0.2.2 action drop
55
56	$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
57		-t ip -q
58
59	tc_check_packets "block 22" 101 1
60	check_err $? "Did not match first incoming packet on a block"
61
62	$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
63		-t ip -q
64
65	tc_check_packets "block 22" 101 2
66	check_err $? "Did not match second incoming packet on a block"
67
68	tc filter del block 22 protocol ip pref 1 handle 101 flower
69
70	log_test "shared block ($tcflags)"
71}
72
73setup_prepare()
74{
75	h1=${NETIFS[p1]}
76	swp1=${NETIFS[p2]}
77
78	swp2=${NETIFS[p3]}
79	h2=${NETIFS[p4]}
80
81	h1mac=$(mac_get $h1)
82	h2mac=$(mac_get $h2)
83
84	swmac=$(mac_get $swp1)
85	swp2origmac=$(mac_get $swp2)
86	ip link set $swp2 address $swmac
87
88	vrf_prepare
89
90	h1_create
91	h2_create
92	switch_create
93}
94
95cleanup()
96{
97	pre_cleanup
98
99	switch_destroy
100	h2_destroy
101	h1_destroy
102
103	vrf_cleanup
104
105	ip link set $swp2 address $swp2origmac
106}
107
108check_tc_shblock_support
109
110trap cleanup EXIT
111
112setup_prepare
113setup_wait
114
115tests_run
116
117tc_offload_check
118if [[ $? -ne 0 ]]; then
119	log_info "Could not test offloaded functionality"
120else
121	tcflags="skip_sw"
122	tests_run
123fi
124
125exit $EXIT_STATUS
126