1#- 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2019 Netflix, Inc. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27 28. $(atf_get_srcdir)/frag6.subr 29 30frag6_20_check_stats() { 31 32 local jname ifname 33 jname=$1 34 ifname=$2 35 36 case "${jname}" in 37 "") echo "ERROR: jname is empty"; return ;; 38 esac 39 case "${ifname}" in 40 "") echo "ERROR: ifname is empty"; return ;; 41 esac 42 43 # Defaults are: IPV6_FRAGTTL 120 slowtimo ticks. 44 # pfslowtimo() is run at hz/2. So this takes 60s. 45 # This is awefully long for a test case. 46 # The Python script has to wait for this already to get the ICMPv6 47 # hence we do not sleep here anymore. 48 49 nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets` 50 case ${nf} in 51 0) break ;; 52 *) atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;; 53 esac 54 nf=`sysctl -n net.inet6.ip6.frag6_nfrags` 55 case ${nf} in 56 0) break ;; 57 *) atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;; 58 esac 59 60 # 61 # Check selection of global UDP stats. 62 # 63 cat <<EOF > ${HOME}/filter-${jname}.txt 64 <received-datagrams>0</received-datagrams> 65 <dropped-incomplete-headers>0</dropped-incomplete-headers> 66 <dropped-bad-data-length>0</dropped-bad-data-length> 67 <dropped-bad-checksum>0</dropped-bad-checksum> 68 <dropped-no-checksum>0</dropped-no-checksum> 69 <dropped-no-socket>0</dropped-no-socket> 70 <dropped-broadcast-multicast>0</dropped-broadcast-multicast> 71 <dropped-full-socket-buffer>0</dropped-full-socket-buffer> 72 <not-for-hashed-pcb>0</not-for-hashed-pcb> 73EOF 74 count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` 75 rm -f ${HOME}/filter-${jname}.txt 76 case ${count} in 77 9) ;; 78 *) jexec ${jname} netstat -s -p udp --libxo xml,pretty 79 atf_fail "Global UDP statistics do not match: ${count} != 9" ;; 80 esac 81 82 83 # 84 # Check selection of global IPv6 stats. 85 # 86 cat <<EOF > ${HOME}/filter-${jname}.txt 87 <dropped-below-minimum-size>0</dropped-below-minimum-size> 88 <dropped-short-packets>0</dropped-short-packets> 89 <dropped-bad-options>0</dropped-bad-options> 90 <dropped-bad-version>0</dropped-bad-version> 91 <received-fragments>3</received-fragments> 92 <dropped-fragment>1</dropped-fragment> 93 <dropped-fragment-after-timeout>2</dropped-fragment-after-timeout> 94 <dropped-fragments-overflow>0</dropped-fragments-overflow> 95 <atomic-fragments>0</atomic-fragments> 96 <reassembled-packets>0</reassembled-packets> 97 <forwarded-packets>0</forwarded-packets> 98 <packets-not-forwardable>0</packets-not-forwardable> 99 <sent-redirects>0</sent-redirects> 100 <send-packets-fabricated-header>0</send-packets-fabricated-header> 101 <discard-no-mbufs>0</discard-no-mbufs> 102 <discard-no-route>0</discard-no-route> 103 <sent-fragments>0</sent-fragments> 104 <fragments-created>0</fragments-created> 105 <discard-cannot-fragment>0</discard-cannot-fragment> 106 <discard-scope-violations>0</discard-scope-violations> 107EOF 108 count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` 109 rm -f ${HOME}/filter-${jname}.txt 110 case ${count} in 111 20) ;; 112 *) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty 113 atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;; 114 esac 115 116 # 117 # Check selection of global ICMPv6 stats. 118 # XXX-TODO check output histogram (just too hard to parse [no multi-line-grep]) 119 # 120 cat <<EOF > ${HOME}/filter-${jname}.txt 121 <icmp6-calls>1</icmp6-calls> 122 <no-route>0</no-route> 123 <admin-prohibited>0</admin-prohibited> 124 <beyond-scope>0</beyond-scope> 125 <address-unreachable>0</address-unreachable> 126 <port-unreachable>0</port-unreachable> 127 <packet-too-big>0</packet-too-big> 128 <time-exceed-transmit>0</time-exceed-transmit> 129 <time-exceed-reassembly>1</time-exceed-reassembly> 130 <bad-header>0</bad-header> 131 <bad-next-header>0</bad-next-header> 132 <bad-option>0</bad-option> 133 <redirects>0</redirects> 134 <unknown>0</unknown> 135 <reflect>0</reflect> 136 <too-many-nd-options>0</too-many-nd-options> 137 <bad-nd-options>0</bad-nd-options> 138 <bad-neighbor-solicitation>0</bad-neighbor-solicitation> 139 <bad-neighbor-advertisement>0</bad-neighbor-advertisement> 140 <bad-router-solicitation>0</bad-router-solicitation> 141 <bad-router-advertisement>0</bad-router-advertisement> 142 <bad-redirect>0</bad-redirect> 143EOF 144 count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` 145 rm -f ${HOME}/filter-${jname}.txt 146 case ${count} in 147 22) ;; 148 *) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty 149 atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;; 150 esac 151 152 # 153 # Check selection of interface IPv6 stats. 154 # 155 cat <<EOF > ${HOME}/filter-${jname}.txt 156 <dropped-invalid-header>0</dropped-invalid-header> 157 <dropped-mtu-exceeded>0</dropped-mtu-exceeded> 158 <dropped-no-route>0</dropped-no-route> 159 <dropped-invalid-destination>0</dropped-invalid-destination> 160 <dropped-unknown-protocol>0</dropped-unknown-protocol> 161 <dropped-truncated>0</dropped-truncated> 162 <sent-forwarded>0</sent-forwarded> 163 <discard-packets>0</discard-packets> 164 <discard-fragments>0</discard-fragments> 165 <fragments-failed>0</fragments-failed> 166 <fragments-created>0</fragments-created> 167 <reassembly-required>3</reassembly-required> 168 <reassembled-packets>0</reassembled-packets> 169 <reassembly-failed>1</reassembly-failed> 170EOF 171 count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` 172 rm -f ${HOME}/filter-${jname}.txt 173 case ${count} in 174 14) ;; 175 *) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty 176 atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;; 177 esac 178 179 # 180 # Check selection of interface ICMPv6 stats. 181 # 182 cat <<EOF > ${HOME}/filter-${jname}.txt 183 <received-errors>0</received-errors> 184 <received-destination-unreachable>0</received-destination-unreachable> 185 <received-admin-prohibited>0</received-admin-prohibited> 186 <received-time-exceeded>0</received-time-exceeded> 187 <received-bad-parameter>0</received-bad-parameter> 188 <received-packet-too-big>0</received-packet-too-big> 189 <received-echo-requests>0</received-echo-requests> 190 <received-echo-replies>0</received-echo-replies> 191 <received-router-solicitation>0</received-router-solicitation> 192 <received-router-advertisement>0</received-router-advertisement> 193 <sent-errors>1</sent-errors> 194 <sent-destination-unreachable>0</sent-destination-unreachable> 195 <sent-admin-prohibited>0</sent-admin-prohibited> 196 <sent-time-exceeded>1</sent-time-exceeded> 197 <sent-bad-parameter>0</sent-bad-parameter> 198 <sent-packet-too-big>0</sent-packet-too-big> 199 <sent-echo-requests>0</sent-echo-requests> 200 <sent-echo-replies>0</sent-echo-replies> 201 <sent-router-solicitation>0</sent-router-solicitation> 202 <sent-router-advertisement>0</sent-router-advertisement> 203 <sent-redirects>0</sent-redirects> 204EOF 205 count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` 206 rm -f ${HOME}/filter-${jname}.txt 207 case ${count} in 208 21) ;; 209 *) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty 210 atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;; 211 esac 212} 213 214atf_test_case "frag6_20" "cleanup" 215frag6_20_head() { 216 frag6_head 20 217} 218 219frag6_20_body() { 220 frag6_body 20 frag6_20_check_stats 221} 222 223frag6_20_cleanup() { 224 frag6_cleanup 20 225} 226 227atf_init_test_cases() 228{ 229 atf_add_test_case "frag6_20" 230} 231