Skip to content

Commit 7b7bc87

Browse files
idoschdavem330
authored andcommitted
selftests: forwarding: Add a test for basic IPv4 and IPv6 routing
Configure two hosts which are directly connected to the same router and test IPv4 and IPv6 ping. Use a large MTU and check that ping is unaffected. Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 236dd50 commit 7b7bc87

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ bridge_ageing_time_get()
267267
echo $((ageing_time / 100))
268268
}
269269

270+
forwarding_enable()
271+
{
272+
ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding)
273+
ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding)
274+
275+
sysctl -q -w net.ipv4.conf.all.forwarding=1
276+
sysctl -q -w net.ipv6.conf.all.forwarding=1
277+
}
278+
279+
forwarding_restore()
280+
{
281+
sysctl -q -w net.ipv6.conf.all.forwarding=$ipv6_fwd
282+
sysctl -q -w net.ipv4.conf.all.forwarding=$ipv4_fwd
283+
}
284+
270285
##############################################################################
271286
# Tests
272287

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NUM_NETIFS=4
5+
source lib.sh
6+
7+
h1_create()
8+
{
9+
vrf_create "vrf-h1"
10+
ip link set dev $h1 master vrf-h1
11+
12+
ip link set dev vrf-h1 up
13+
ip link set dev $h1 up
14+
15+
ip address add 192.0.2.2/24 dev $h1
16+
ip address add 2001:db8:1::2/64 dev $h1
17+
18+
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
19+
ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
20+
}
21+
22+
h1_destroy()
23+
{
24+
ip route del 2001:db8:2::/64 vrf vrf-h1
25+
ip route del 198.51.100.0/24 vrf vrf-h1
26+
27+
ip address del 2001:db8:1::2/64 dev $h1
28+
ip address del 192.0.2.2/24 dev $h1
29+
30+
ip link set dev $h1 down
31+
vrf_destroy "vrf-h1"
32+
}
33+
34+
h2_create()
35+
{
36+
vrf_create "vrf-h2"
37+
ip link set dev $h2 master vrf-h2
38+
39+
ip link set dev vrf-h2 up
40+
ip link set dev $h2 up
41+
42+
ip address add 198.51.100.2/24 dev $h2
43+
ip address add 2001:db8:2::2/64 dev $h2
44+
45+
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
46+
ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
47+
}
48+
49+
h2_destroy()
50+
{
51+
ip route del 2001:db8:1::/64 vrf vrf-h2
52+
ip route del 192.0.2.0/24 vrf vrf-h2
53+
54+
ip address del 2001:db8:2::2/64 dev $h2
55+
ip address del 198.51.100.2/24 dev $h2
56+
57+
ip link set dev $h2 down
58+
vrf_destroy "vrf-h2"
59+
}
60+
61+
router_create()
62+
{
63+
ip link set dev $rp1 up
64+
ip link set dev $rp2 up
65+
66+
ip address add 192.0.2.1/24 dev $rp1
67+
ip address add 2001:db8:1::1/64 dev $rp1
68+
69+
ip address add 198.51.100.1/24 dev $rp2
70+
ip address add 2001:db8:2::1/64 dev $rp2
71+
}
72+
73+
router_destroy()
74+
{
75+
ip address del 2001:db8:2::1/64 dev $rp2
76+
ip address del 198.51.100.1/24 dev $rp2
77+
78+
ip address del 2001:db8:1::1/64 dev $rp1
79+
ip address del 192.0.2.1/24 dev $rp1
80+
81+
ip link set dev $rp2 down
82+
ip link set dev $rp1 down
83+
}
84+
85+
setup_prepare()
86+
{
87+
h1=${NETIFS[p1]}
88+
rp1=${NETIFS[p2]}
89+
90+
rp2=${NETIFS[p3]}
91+
h2=${NETIFS[p4]}
92+
93+
vrf_prepare
94+
95+
h1_create
96+
h2_create
97+
98+
router_create
99+
100+
forwarding_enable
101+
}
102+
103+
cleanup()
104+
{
105+
pre_cleanup
106+
107+
forwarding_restore
108+
109+
router_destroy
110+
111+
h2_destroy
112+
h1_destroy
113+
114+
vrf_cleanup
115+
}
116+
117+
trap cleanup EXIT
118+
119+
setup_prepare
120+
setup_wait
121+
122+
ping_test $h1 198.51.100.2
123+
ping6_test $h1 2001:db8:2::2
124+
125+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)