diff options
author | Ido Schimmel <idosch@mellanox.com> | 2018-02-28 05:25:09 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-02-28 12:25:47 -0500 |
commit | 7b7bc875559c0c06406d77a7f71e3c0e289a60be (patch) | |
tree | 382458864bea6c9509855bc1bd8198b3494c8d7b /tools | |
parent | 236dd50bf67a2ab5fd39d82e712d1fafdd4c602d (diff) |
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 <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/net/forwarding/lib.sh | 15 | ||||
-rwxr-xr-x | tools/testing/selftests/net/forwarding/router.sh | 125 |
2 files changed, 140 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index e2a4ee8946ef..962153b7181b 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh | |||
@@ -267,6 +267,21 @@ bridge_ageing_time_get() | |||
267 | echo $((ageing_time / 100)) | 267 | echo $((ageing_time / 100)) |
268 | } | 268 | } |
269 | 269 | ||
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 | |||
270 | ############################################################################## | 285 | ############################################################################## |
271 | # Tests | 286 | # Tests |
272 | 287 | ||
diff --git a/tools/testing/selftests/net/forwarding/router.sh b/tools/testing/selftests/net/forwarding/router.sh new file mode 100755 index 000000000000..cc6a14abfa87 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/router.sh | |||
@@ -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 | ||