File Index
Files and directories
Sign in
FILE

ip6_forward_instats_vrf.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/net/forwarding/ip6_forward_instats_vrf.sh BASH
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3
  4# Test ipv6 stats on the incoming if when forwarding with VRF
  5
  6ALL_TESTS="
  7	ipv6_ping
  8	ipv6_in_too_big_err
  9	ipv6_in_hdr_err
 10	ipv6_in_addr_err
 11	ipv6_in_discard
 12"
 13
 14NUM_NETIFS=4
 15source lib.sh
 16
 17require_command $TROUTE6
 18
 19h1_create()
 20{
 21	simple_if_init $h1 2001:1:1::2/64
 22	ip -6 route add vrf v$h1 2001:1:2::/64 via 2001:1:1::1
 23}
 24
 25h1_destroy()
 26{
 27	ip -6 route del vrf v$h1 2001:1:2::/64 via 2001:1:1::1
 28	simple_if_fini $h1 2001:1:1::2/64
 29}
 30
 31router_create()
 32{
 33	vrf_create router
 34	__simple_if_init $rtr1 router 2001:1:1::1/64
 35	__simple_if_init $rtr2 router 2001:1:2::1/64
 36	mtu_set $rtr2 1280
 37}
 38
 39router_destroy()
 40{
 41	mtu_restore $rtr2
 42	__simple_if_fini $rtr2 2001:1:2::1/64
 43	__simple_if_fini $rtr1 2001:1:1::1/64
 44	vrf_destroy router
 45}
 46
 47h2_create()
 48{
 49	simple_if_init $h2 2001:1:2::2/64
 50	ip -6 route add vrf v$h2 2001:1:1::/64 via 2001:1:2::1
 51	mtu_set $h2 1280
 52}
 53
 54h2_destroy()
 55{
 56	mtu_restore $h2
 57	ip -6 route del vrf v$h2 2001:1:1::/64 via 2001:1:2::1
 58	simple_if_fini $h2 2001:1:2::2/64
 59}
 60
 61setup_prepare()
 62{
 63	h1=${NETIFS[p1]}
 64	rtr1=${NETIFS[p2]}
 65
 66	rtr2=${NETIFS[p3]}
 67	h2=${NETIFS[p4]}
 68
 69	vrf_prepare
 70	h1_create
 71	router_create
 72	h2_create
 73
 74	forwarding_enable
 75}
 76
 77cleanup()
 78{
 79	pre_cleanup
 80
 81	forwarding_restore
 82
 83	h2_destroy
 84	router_destroy
 85	h1_destroy
 86	vrf_cleanup
 87}
 88
 89ipv6_in_too_big_err()
 90{
 91	RET=0
 92
 93	local t0=$(ipv6_stats_get $rtr1 Ip6InTooBigErrors)
 94	local vrf_name=$(master_name_get $h1)
 95
 96	# Send too big packets
 97	ip vrf exec $vrf_name \
 98		$PING6 -s 1300 -c 1 -w $PING_TIMEOUT 2001:1:2::2 &> /dev/null
 99
100	local t1=$(ipv6_stats_get $rtr1 Ip6InTooBigErrors)
101	test "$((t1 - t0))" -ne 0
102	check_err $?
103	log_test "Ip6InTooBigErrors"
104}
105
106ipv6_in_hdr_err()
107{
108	RET=0
109
110	local t0=$(ipv6_stats_get $rtr1 Ip6InHdrErrors)
111	local vrf_name=$(master_name_get $h1)
112
113	# Send packets with hop limit 1, easiest with traceroute6 as some ping6
114	# doesn't allow hop limit to be specified
115	ip vrf exec $vrf_name \
116		$TROUTE6 2001:1:2::2 &> /dev/null
117
118	local t1=$(ipv6_stats_get $rtr1 Ip6InHdrErrors)
119	test "$((t1 - t0))" -ne 0
120	check_err $?
121	log_test "Ip6InHdrErrors"
122}
123
124ipv6_in_addr_err()
125{
126	RET=0
127
128	local t0=$(ipv6_stats_get $rtr1 Ip6InAddrErrors)
129	local vrf_name=$(master_name_get $h1)
130
131	# Disable forwarding temporary while sending the packet
132	sysctl -qw net.ipv6.conf.all.forwarding=0
133	ip vrf exec $vrf_name \
134		$PING6 -c 1 -w $PING_TIMEOUT 2001:1:2::2 &> /dev/null
135	sysctl -qw net.ipv6.conf.all.forwarding=1
136
137	local t1=$(ipv6_stats_get $rtr1 Ip6InAddrErrors)
138	test "$((t1 - t0))" -ne 0
139	check_err $?
140	log_test "Ip6InAddrErrors"
141}
142
143ipv6_in_discard()
144{
145	RET=0
146
147	local t0=$(ipv6_stats_get $rtr1 Ip6InDiscards)
148	local vrf_name=$(master_name_get $h1)
149
150	# Add a policy to discard
151	ip xfrm policy add dst 2001:1:2::2/128 dir fwd action block
152	ip vrf exec $vrf_name \
153		$PING6 -c 1 -w $PING_TIMEOUT 2001:1:2::2 &> /dev/null
154	ip xfrm policy del dst 2001:1:2::2/128 dir fwd
155
156	local t1=$(ipv6_stats_get $rtr1 Ip6InDiscards)
157	test "$((t1 - t0))" -ne 0
158	check_err $?
159	log_test "Ip6InDiscards"
160}
161ipv6_ping()
162{
163	RET=0
164
165	ping6_test $h1 2001:1:2::2
166}
167
168trap cleanup EXIT
169
170setup_prepare
171setup_wait
172tests_run
173
174exit $EXIT_STATUS
~/ Read-only file preview.