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