Path: blob/main/tests/sys/netinet6/frag6/frag6_05.sh
39482 views
#-1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2019 Netflix, Inc.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.25#2627. $(atf_get_srcdir)/frag6.subr2829frag6_05_check_stats_0() {3031local jname ifname32jname=$133ifname=$23435case "${jname}" in36"") echo "ERROR: jname is empty"; return ;;37esac38case "${ifname}" in39"") echo "ERROR: ifname is empty"; return ;;40esac4142# Defaults are: IPV6_FRAGTTL 120 slowtimo ticks.43# pfslowtimo() is run at hz/2. So this takes 60s.44# This is awefully long for a test case.45# The Python script has to wait for this already to get the ICMPv646# hence we do not sleep here anymore.4748nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets`49case ${nf} in500) break ;;51*) atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;;52esac53nf=`sysctl -n net.inet6.ip6.frag6_nfrags`54case ${nf} in550) break ;;56*) atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;;57esac5859#60# Check that the sysctl is set to what we expect.61#62sn=`sysctl -n net.inet6.ip6.maxfrags`63case "${sn}" in640) ;;65*) atf_fail "Sysctl net.inet6.ip6.maxfrags is ${sn} and not 0" ;;66esac6768#69# Check selection of global UDP stats.70#71cat <<EOF > ${HOME}/filter-${jname}.txt72<received-datagrams>0</received-datagrams>73<dropped-incomplete-headers>0</dropped-incomplete-headers>74<dropped-bad-data-length>0</dropped-bad-data-length>75<dropped-bad-checksum>0</dropped-bad-checksum>76<dropped-no-checksum>0</dropped-no-checksum>77<dropped-no-socket>0</dropped-no-socket>78<dropped-broadcast-multicast>0</dropped-broadcast-multicast>79<dropped-full-socket-buffer>0</dropped-full-socket-buffer>80<not-for-hashed-pcb>0</not-for-hashed-pcb>81EOF82count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`83rm -f ${HOME}/filter-${jname}.txt84case ${count} in859) ;;86*) jexec ${jname} netstat -s -p udp --libxo xml,pretty87atf_fail "Global UDP statistics do not match: ${count} != 9" ;;88esac899091#92# Check selection of global IPv6 stats.93#94cat <<EOF > ${HOME}/filter-${jname}.txt95<dropped-below-minimum-size>0</dropped-below-minimum-size>96<dropped-short-packets>0</dropped-short-packets>97<dropped-bad-options>0</dropped-bad-options>98<dropped-bad-version>0</dropped-bad-version>99<received-fragments>20</received-fragments>100<dropped-fragment>20</dropped-fragment>101<dropped-fragment-after-timeout>0</dropped-fragment-after-timeout>102<dropped-fragments-overflow>0</dropped-fragments-overflow>103<atomic-fragments>0</atomic-fragments>104<reassembled-packets>0</reassembled-packets>105<forwarded-packets>0</forwarded-packets>106<packets-not-forwardable>0</packets-not-forwardable>107<sent-redirects>0</sent-redirects>108<send-packets-fabricated-header>0</send-packets-fabricated-header>109<discard-no-mbufs>0</discard-no-mbufs>110<discard-no-route>0</discard-no-route>111<sent-fragments>0</sent-fragments>112<fragments-created>0</fragments-created>113<discard-cannot-fragment>0</discard-cannot-fragment>114<discard-scope-violations>0</discard-scope-violations>115EOF116count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`117rm -f ${HOME}/filter-${jname}.txt118case ${count} in11920) ;;120*) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty121atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;122esac123124#125# Check selection of global ICMPv6 stats.126# XXX-TODO check output histogram (just too hard to parse [no multi-line-grep])127#128cat <<EOF > ${HOME}/filter-${jname}.txt129<icmp6-calls>0</icmp6-calls>130<no-route>0</no-route>131<admin-prohibited>0</admin-prohibited>132<beyond-scope>0</beyond-scope>133<address-unreachable>0</address-unreachable>134<port-unreachable>0</port-unreachable>135<packet-too-big>0</packet-too-big>136<time-exceed-transmit>0</time-exceed-transmit>137<time-exceed-reassembly>0</time-exceed-reassembly>138<bad-header>0</bad-header>139<bad-next-header>0</bad-next-header>140<bad-option>0</bad-option>141<redirects>0</redirects>142<unknown>0</unknown>143<reflect>0</reflect>144<too-many-nd-options>0</too-many-nd-options>145<bad-nd-options>0</bad-nd-options>146<bad-neighbor-solicitation>0</bad-neighbor-solicitation>147<bad-neighbor-advertisement>0</bad-neighbor-advertisement>148<bad-router-solicitation>0</bad-router-solicitation>149<bad-router-advertisement>0</bad-router-advertisement>150<bad-redirect>0</bad-redirect>151EOF152count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`153rm -f ${HOME}/filter-${jname}.txt154case ${count} in15522) ;;156*) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty157atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;158esac159160#161# Check selection of interface IPv6 stats.162#163cat <<EOF > ${HOME}/filter-${jname}.txt164<dropped-invalid-header>0</dropped-invalid-header>165<dropped-mtu-exceeded>0</dropped-mtu-exceeded>166<dropped-no-route>0</dropped-no-route>167<dropped-invalid-destination>0</dropped-invalid-destination>168<dropped-unknown-protocol>0</dropped-unknown-protocol>169<dropped-truncated>0</dropped-truncated>170<sent-forwarded>0</sent-forwarded>171<discard-packets>0</discard-packets>172<discard-fragments>0</discard-fragments>173<fragments-failed>0</fragments-failed>174<fragments-created>0</fragments-created>175<reassembly-required>20</reassembly-required>176<reassembled-packets>0</reassembled-packets>177<reassembly-failed>20</reassembly-failed>178EOF179count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`180rm -f ${HOME}/filter-${jname}.txt181case ${count} in18214) ;;183*) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty184atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;185esac186187#188# Check selection of interface ICMPv6 stats.189#190cat <<EOF > ${HOME}/filter-${jname}.txt191<received-errors>0</received-errors>192<received-destination-unreachable>0</received-destination-unreachable>193<received-admin-prohibited>0</received-admin-prohibited>194<received-time-exceeded>0</received-time-exceeded>195<received-bad-parameter>0</received-bad-parameter>196<received-packet-too-big>0</received-packet-too-big>197<received-echo-requests>0</received-echo-requests>198<received-echo-replies>0</received-echo-replies>199<received-router-solicitation>0</received-router-solicitation>200<received-router-advertisement>0</received-router-advertisement>201<sent-errors>0</sent-errors>202<sent-destination-unreachable>0</sent-destination-unreachable>203<sent-admin-prohibited>0</sent-admin-prohibited>204<sent-time-exceeded>0</sent-time-exceeded>205<sent-bad-parameter>0</sent-bad-parameter>206<sent-packet-too-big>0</sent-packet-too-big>207<sent-echo-requests>0</sent-echo-requests>208<sent-echo-replies>0</sent-echo-replies>209<sent-router-solicitation>0</sent-router-solicitation>210<sent-router-advertisement>0</sent-router-advertisement>211<sent-redirects>0</sent-redirects>212EOF213count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`214rm -f ${HOME}/filter-${jname}.txt215case ${count} in21621) ;;217*) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty218atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;219esac220}221222frag6_05_check_stats_1() {223224local jname ifname225jname=$1226ifname=$2227228case "${jname}" in229"") echo "ERROR: jname is empty"; return ;;230esac231case "${ifname}" in232"") echo "ERROR: ifname is empty"; return ;;233esac234235# Defaults are: IPV6_FRAGTTL 120 slowtimo ticks.236# pfslowtimo() is run at hz/2. So this takes 60s.237# This is awefully long for a test case.238# The Python script has to wait for this already to get the ICMPv6239# hence we do not sleep here anymore.240241nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets`242case ${nf} in2430) break ;;244*) atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;;245esac246nf=`sysctl -n net.inet6.ip6.frag6_nfrags`247case ${nf} in2480) break ;;249*) atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;;250esac251252#253# Check that the sysctl is set to what we expect.254#255sn=`sysctl -n net.inet6.ip6.maxfrags`256case "${sn}" in25710) ;;258*) atf_fail "Sysctl net.inet6.ip6.maxfrags is ${sn} and not 10" ;;259esac260261#262# Check selection of global UDP stats.263#264cat <<EOF > ${HOME}/filter-${jname}.txt265<received-datagrams>0</received-datagrams>266<dropped-incomplete-headers>0</dropped-incomplete-headers>267<dropped-bad-data-length>0</dropped-bad-data-length>268<dropped-bad-checksum>0</dropped-bad-checksum>269<dropped-no-checksum>0</dropped-no-checksum>270<dropped-no-socket>0</dropped-no-socket>271<dropped-broadcast-multicast>0</dropped-broadcast-multicast>272<dropped-full-socket-buffer>0</dropped-full-socket-buffer>273<not-for-hashed-pcb>0</not-for-hashed-pcb>274EOF275count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`276rm -f ${HOME}/filter-${jname}.txt277case ${count} in2789) ;;279*) jexec ${jname} netstat -s -p udp --libxo xml,pretty280atf_fail "Global UDP statistics do not match: ${count} != 9" ;;281esac282283284#285# Check selection of global IPv6 stats.286#287cat <<EOF > ${HOME}/filter-${jname}.txt288<dropped-below-minimum-size>0</dropped-below-minimum-size>289<dropped-short-packets>0</dropped-short-packets>290<dropped-bad-options>0</dropped-bad-options>291<dropped-bad-version>0</dropped-bad-version>292<received-fragments>20</received-fragments>293<dropped-fragment>10</dropped-fragment>294<dropped-fragment-after-timeout>10</dropped-fragment-after-timeout>295<dropped-fragments-overflow>0</dropped-fragments-overflow>296<atomic-fragments>0</atomic-fragments>297<reassembled-packets>0</reassembled-packets>298<forwarded-packets>0</forwarded-packets>299<packets-not-forwardable>0</packets-not-forwardable>300<sent-redirects>0</sent-redirects>301<send-packets-fabricated-header>0</send-packets-fabricated-header>302<discard-no-mbufs>0</discard-no-mbufs>303<discard-no-route>0</discard-no-route>304<sent-fragments>0</sent-fragments>305<fragments-created>0</fragments-created>306<discard-cannot-fragment>0</discard-cannot-fragment>307<discard-scope-violations>0</discard-scope-violations>308EOF309count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`310rm -f ${HOME}/filter-${jname}.txt311case ${count} in31220) ;;313*) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty314atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;315esac316317#318# Check selection of global ICMPv6 stats.319# XXX-TODO check output histogram (just too hard to parse [no multi-line-grep])320#321cat <<EOF > ${HOME}/filter-${jname}.txt322<icmp6-calls>10</icmp6-calls>323<no-route>0</no-route>324<admin-prohibited>0</admin-prohibited>325<beyond-scope>0</beyond-scope>326<address-unreachable>0</address-unreachable>327<port-unreachable>0</port-unreachable>328<packet-too-big>0</packet-too-big>329<time-exceed-transmit>0</time-exceed-transmit>330<time-exceed-reassembly>10</time-exceed-reassembly>331<bad-header>0</bad-header>332<bad-next-header>0</bad-next-header>333<bad-option>0</bad-option>334<redirects>0</redirects>335<unknown>0</unknown>336<reflect>0</reflect>337<too-many-nd-options>0</too-many-nd-options>338<bad-nd-options>0</bad-nd-options>339<bad-neighbor-solicitation>0</bad-neighbor-solicitation>340<bad-neighbor-advertisement>0</bad-neighbor-advertisement>341<bad-router-solicitation>0</bad-router-solicitation>342<bad-router-advertisement>0</bad-router-advertisement>343<bad-redirect>0</bad-redirect>344EOF345count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`346rm -f ${HOME}/filter-${jname}.txt347case ${count} in34822) ;;349*) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty350atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;351esac352353#354# Check selection of interface IPv6 stats.355#356cat <<EOF > ${HOME}/filter-${jname}.txt357<dropped-invalid-header>0</dropped-invalid-header>358<dropped-mtu-exceeded>0</dropped-mtu-exceeded>359<dropped-no-route>0</dropped-no-route>360<dropped-invalid-destination>0</dropped-invalid-destination>361<dropped-unknown-protocol>0</dropped-unknown-protocol>362<dropped-truncated>0</dropped-truncated>363<sent-forwarded>0</sent-forwarded>364<discard-packets>0</discard-packets>365<discard-fragments>0</discard-fragments>366<fragments-failed>0</fragments-failed>367<fragments-created>0</fragments-created>368<reassembly-required>20</reassembly-required>369<reassembled-packets>0</reassembled-packets>370<reassembly-failed>10</reassembly-failed>371EOF372count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`373rm -f ${HOME}/filter-${jname}.txt374case ${count} in37514) ;;376*) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty377atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;378esac379380#381# Check selection of interface ICMPv6 stats.382#383cat <<EOF > ${HOME}/filter-${jname}.txt384<received-errors>0</received-errors>385<received-destination-unreachable>0</received-destination-unreachable>386<received-admin-prohibited>0</received-admin-prohibited>387<received-time-exceeded>0</received-time-exceeded>388<received-bad-parameter>0</received-bad-parameter>389<received-packet-too-big>0</received-packet-too-big>390<received-echo-requests>0</received-echo-requests>391<received-echo-replies>0</received-echo-replies>392<received-router-solicitation>0</received-router-solicitation>393<received-router-advertisement>0</received-router-advertisement>394<sent-errors>10</sent-errors>395<sent-destination-unreachable>0</sent-destination-unreachable>396<sent-admin-prohibited>0</sent-admin-prohibited>397<sent-time-exceeded>10</sent-time-exceeded>398<sent-bad-parameter>0</sent-bad-parameter>399<sent-packet-too-big>0</sent-packet-too-big>400<sent-echo-requests>0</sent-echo-requests>401<sent-echo-replies>0</sent-echo-replies>402<sent-router-solicitation>0</sent-router-solicitation>403<sent-router-advertisement>0</sent-router-advertisement>404<sent-redirects>0</sent-redirects>405EOF406count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`407rm -f ${HOME}/filter-${jname}.txt408case ${count} in40921) ;;410*) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty411atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;412esac413}414415atf_test_case "frag6_05_0" "cleanup"416frag6_05_0_head() {417frag6_head 5_0418}419420frag6_05_0_body() {421422# Save current sysctl value.423ov=`sysctl -n net.inet6.ip6.maxfrags`424echo "${ov}" > ${HOME}/sysctl-$(atf_get ident).txt425426# Never accept fragments.427sysctl net.inet6.ip6.maxfrags=0428429frag6_body 5 frag6_05_check_stats_0430}431432frag6_05_0_cleanup() {433frag6_cleanup 5_0434435# Restore sysctl back to default.436ov=`cat ${HOME}/sysctl-$(atf_get ident).txt`437rm -f ${HOME}/sysctl-$(atf_get ident).txt438sysctl net.inet6.ip6.maxfrags=${ov}439}440441442atf_test_case "frag6_05_1" "cleanup"443frag6_05_1_head() {444frag6_head 5_1445}446447frag6_05_1_body() {448449# Save current sysctl value.450ov=`sysctl -n net.inet6.ip6.maxfrags`451echo "${ov}" > ${HOME}/sysctl-$(atf_get ident).txt452453# Maximum of 10 global system-wide fragments.454sysctl net.inet6.ip6.maxfrags=10455456frag6_body 5 frag6_05_check_stats_1457}458459frag6_05_1_cleanup() {460frag6_cleanup 5_1461462# Restore sysctl back to default.463ov=`cat ${HOME}/sysctl-$(atf_get ident).txt`464rm -f ${HOME}/sysctl-$(atf_get ident).txt465sysctl net.inet6.ip6.maxfrags=${ov}466}467468469atf_init_test_cases()470{471atf_add_test_case "frag6_05_0"472atf_add_test_case "frag6_05_1"473}474475476