Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / pedit_l4port.sh
blob10e594c551175b5b7ade331b9d5f345bb1b25d08
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test sends traffic from H1 to H2. Either on ingress of $swp1, or on egress of $swp2, the
5 # traffic is acted upon by a pedit action. An ingress filter installed on $h2 verifies that the
6 # packet looks like expected.
8 # +----------------------+ +----------------------+
9 # | H1 | | H2 |
10 # | + $h1 | | $h2 + |
11 # | | 192.0.2.1/28 | | 192.0.2.2/28 | |
12 # +----|-----------------+ +----------------|-----+
13 # | |
14 # +----|----------------------------------------------------------------|-----+
15 # | SW | | |
16 # | +-|----------------------------------------------------------------|-+ |
17 # | | + $swp1 BR $swp2 + | |
18 # | +--------------------------------------------------------------------+ |
19 # +---------------------------------------------------------------------------+
21 ALL_TESTS="
22 ping_ipv4
23 test_udp_sport
24 test_udp_dport
25 test_tcp_sport
26 test_tcp_dport
29 NUM_NETIFS=4
30 source lib.sh
31 source tc_common.sh
33 : ${HIT_TIMEOUT:=2000} # ms
35 h1_create()
37 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
40 h1_destroy()
42 simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
45 h2_create()
47 simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
48 tc qdisc add dev $h2 clsact
51 h2_destroy()
53 tc qdisc del dev $h2 clsact
54 simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
57 switch_create()
59 ip link add name br1 up type bridge vlan_filtering 1
60 ip link set dev $swp1 master br1
61 ip link set dev $swp1 up
62 ip link set dev $swp2 master br1
63 ip link set dev $swp2 up
65 tc qdisc add dev $swp1 clsact
66 tc qdisc add dev $swp2 clsact
69 switch_destroy()
71 tc qdisc del dev $swp2 clsact
72 tc qdisc del dev $swp1 clsact
74 ip link set dev $swp2 down
75 ip link set dev $swp2 nomaster
76 ip link set dev $swp1 down
77 ip link set dev $swp1 nomaster
78 ip link del dev br1
81 setup_prepare()
83 h1=${NETIFS[p1]}
84 swp1=${NETIFS[p2]}
86 swp2=${NETIFS[p3]}
87 h2=${NETIFS[p4]}
89 h2mac=$(mac_get $h2)
91 vrf_prepare
92 h1_create
93 h2_create
94 switch_create
97 cleanup()
99 pre_cleanup
101 switch_destroy
102 h2_destroy
103 h1_destroy
104 vrf_cleanup
107 ping_ipv4()
109 ping_test $h1 192.0.2.2
112 ping_ipv6()
114 ping6_test $h1 2001:db8:1::2
117 do_test_pedit_l4port_one()
119 local pedit_locus=$1; shift
120 local pedit_prot=$1; shift
121 local pedit_action=$1; shift
122 local match_prot=$1; shift
123 local match_flower=$1; shift
124 local mz_flags=$1; shift
125 local saddr=$1; shift
126 local daddr=$1; shift
128 tc filter add $pedit_locus handle 101 pref 1 \
129 flower action pedit ex munge $pedit_action
130 tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \
131 flower skip_hw $match_flower action pass
133 RET=0
135 $MZ $mz_flags $h1 -c 10 -d 20msec -p 100 \
136 -a own -b $h2mac -q -t $pedit_prot sp=54321,dp=12345
138 local pkts
139 pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \
140 tc_rule_handle_stats_get "dev $h2 ingress" 101)
141 check_err $? "Expected to get 10 packets, but got $pkts."
143 pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)
144 ((pkts >= 10))
145 check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."
147 log_test "$pedit_locus pedit $pedit_action"
149 tc filter del dev $h2 ingress pref 1
150 tc filter del $pedit_locus pref 1
153 do_test_pedit_l4port()
155 local locus=$1; shift
156 local prot=$1; shift
157 local pedit_port=$1; shift
158 local flower_port=$1; shift
159 local port
161 for port in 1 11111 65535; do
162 do_test_pedit_l4port_one "$locus" "$prot" \
163 "$prot $pedit_port set $port" \
164 ip "ip_proto $prot $flower_port $port" \
165 "-A 192.0.2.1 -B 192.0.2.2"
166 done
169 test_udp_sport()
171 do_test_pedit_l4port "dev $swp1 ingress" udp sport src_port
172 do_test_pedit_l4port "dev $swp2 egress" udp sport src_port
175 test_udp_dport()
177 do_test_pedit_l4port "dev $swp1 ingress" udp dport dst_port
178 do_test_pedit_l4port "dev $swp2 egress" udp dport dst_port
181 test_tcp_sport()
183 do_test_pedit_l4port "dev $swp1 ingress" tcp sport src_port
184 do_test_pedit_l4port "dev $swp2 egress" tcp sport src_port
187 test_tcp_dport()
189 do_test_pedit_l4port "dev $swp1 ingress" tcp dport dst_port
190 do_test_pedit_l4port "dev $swp2 egress" tcp dport dst_port
193 trap cleanup EXIT
195 setup_prepare
196 setup_wait
198 tests_run
200 exit $EXIT_STATUS