2 # SPDX-License-Identifier: GPL-2.0
4 # Test a "one-armed router" [1] scenario. Packets forwarded between H1 and H2
5 # should be forwarded by the ASIC, but also trapped so that ICMP redirect
6 # packets could be potentially generated.
8 # 1. https://en.wikipedia.org/wiki/One-armed_router
10 # +---------------------------------+
14 # | | 2001:db8:1::1/64 |
16 # | | default via 192.0.2.2 |
17 # | | default via 2001:db8:1::2 |
18 # +----|----------------------------+
20 # +----|----------------------------------------------------------------------+
22 # | +--|--------------------------------------------------------------------+ |
23 # | | + $swp1 BR0 (802.1d) | |
25 # | | 192.0.2.2/24 | |
26 # | | 2001:db8:1::2/64 | |
27 # | | 198.51.100.2/24 | |
28 # | | 2001:db8:2::2/64 | |
31 # | +--|--------------------------------------------------------------------+ |
33 # +----|----------------------------------------------------------------------+
35 # +----|----------------------------+
36 # | | default via 198.51.100.2 |
37 # | | default via 2001:db8:2::2 |
39 # | | 2001:db8:2::1/64 |
40 # | | 198.51.100.1/24 |
43 # +---------------------------------+
45 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
47 ALL_TESTS
="ping_ipv4 ping_ipv6 fwd_mark_ipv4 fwd_mark_ipv6"
49 source $lib_dir/tc_common.sh
50 source $lib_dir/lib.sh
54 simple_if_init
$h1 192.0.2.1/24 2001:db8
:1::1/64
56 ip
-4 route add default vrf v
$h1 nexthop via
192.0.2.2
57 ip
-6 route add default vrf v
$h1 nexthop via
2001:db8
:1::2
62 ip
-6 route del default vrf v
$h1 nexthop via
2001:db8
:1::2
63 ip
-4 route del default vrf v
$h1 nexthop via
192.0.2.2
65 simple_if_fini
$h1 192.0.2.1/24 2001:db8
:1::1/64
70 simple_if_init
$h2 198.51.100.1/24 2001:db8
:2::1/64
72 ip
-4 route add default vrf v
$h2 nexthop via
198.51.100.2
73 ip
-6 route add default vrf v
$h2 nexthop via
2001:db8
:2::2
78 ip
-6 route del default vrf v
$h2 nexthop via
2001:db8
:2::2
79 ip
-4 route del default vrf v
$h2 nexthop via
198.51.100.2
81 simple_if_fini
$h2 198.51.100.1/24 2001:db8
:2::1/64
86 ip link add name br0
type bridge mcast_snooping
0
87 ip link
set dev br0 up
89 ip link
set dev
$swp1 master br0
90 ip link
set dev
$swp1 up
91 ip link
set dev
$swp2 master br0
92 ip link
set dev
$swp2 up
94 tc qdisc add dev
$swp1 clsact
95 tc qdisc add dev
$swp2 clsact
97 __addr_add_del br0 add
192.0.2.2/24 2001:db8
:1::2/64
98 __addr_add_del br0 add
198.51.100.2/24 2001:db8
:2::2/64
103 __addr_add_del br0 del
198.51.100.2/24 2001:db8
:2::2/64
104 __addr_add_del br0 del
192.0.2.2/24 2001:db8
:1::2/64
106 tc qdisc del dev
$swp2 clsact
107 tc qdisc del dev
$swp1 clsact
109 ip link
set dev
$swp2 down
110 ip link
set dev
$swp2 nomaster
111 ip link
set dev
$swp1 down
112 ip link
set dev
$swp1 nomaster
114 ip link
set dev br0 down
120 ping_test
$h1 198.51.100.1 ": h1->h2"
125 ping6_test
$h1 2001:db8
:2::1 ": h1->h2"
130 # Transmit packets from H1 to H2 and make sure they are trapped at
131 # swp1 due to loopback error, but only forwarded by the ASIC through
134 tc filter add dev
$swp1 ingress protocol ip pref
1 handle
101 flower \
135 skip_hw dst_ip
198.51.100.1 ip_proto udp dst_port
52768 \
138 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 flower \
139 skip_hw dst_ip
198.51.100.1 ip_proto udp dst_port
52768 \
142 tc filter add dev
$swp2 egress protocol ip pref
2 handle
102 flower \
143 skip_sw dst_ip
198.51.100.1 ip_proto udp dst_port
52768 \
146 ip vrf
exec v
$h1 $MZ $h1 -c 10 -d 100msec
-p 64 -A 192.0.2.1 \
147 -B 198.51.100.1 -t udp dp
=52768,sp
=42768 -q
151 tc_check_packets
"dev $swp1 ingress" 101 10
154 log_test
"fwd mark: trapping IPv4 packets due to LBERROR"
158 tc_check_packets
"dev $swp2 egress" 101 0
161 log_test
"fwd mark: forwarding IPv4 packets in software"
165 tc_check_packets
"dev $swp2 egress" 102 10
168 log_test
"fwd mark: forwarding IPv4 packets in hardware"
170 tc filter del dev
$swp2 egress protocol ip pref
2 handle
102 flower
171 tc filter del dev
$swp2 egress protocol ip pref
1 handle
101 flower
172 tc filter del dev
$swp1 ingress protocol ip pref
1 handle
101 flower
177 tc filter add dev
$swp1 ingress protocol ipv6 pref
1 handle
101 flower \
178 skip_hw dst_ip
2001:db8
:2::1 ip_proto udp dst_port
52768 \
181 tc filter add dev
$swp2 egress protocol ipv6 pref
1 handle
101 flower \
182 skip_hw dst_ip
2001:db8
:2::1 ip_proto udp dst_port
52768 \
185 tc filter add dev
$swp2 egress protocol ipv6 pref
2 handle
102 flower \
186 skip_sw dst_ip
2001:db8
:2::1 ip_proto udp dst_port
52768 \
189 ip vrf
exec v
$h1 $MZ $h1 -6 -c 10 -d 100msec
-p 64 -A 2001:db8
:1::1 \
190 -B 2001:db8
:2::1 -t udp dp
=52768,sp
=42768 -q
194 tc_check_packets
"dev $swp1 ingress" 101 10
197 log_test
"fwd mark: trapping IPv6 packets due to LBERROR"
201 tc_check_packets
"dev $swp2 egress" 101 0
204 log_test
"fwd mark: forwarding IPv6 packets in software"
208 tc_check_packets
"dev $swp2 egress" 102 10
211 log_test
"fwd mark: forwarding IPv6 packets in hardware"
213 tc filter del dev
$swp2 egress protocol ipv6 pref
2 handle
102 flower
214 tc filter del dev
$swp2 egress protocol ipv6 pref
1 handle
101 flower
215 tc filter del dev
$swp1 ingress protocol ipv6 pref
1 handle
101 flower
229 sysctl_set net.ipv4.conf.all.accept_redirects
0
230 sysctl_set net.ipv6.conf.all.accept_redirects
0
245 sysctl_restore net.ipv6.conf.all.accept_redirects
246 sysctl_restore net.ipv4.conf.all.accept_redirects