Path: blob/main/tests/sys/netinet6/frag6/frag6_06.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_06_pre_test_0() {3031local jname ifname32jname=$13334case "${jname}" in35"") echo "ERROR: jname is empty"; return ;;36esac3738# Never accept fragments.39jexec ${jname} sysctl net.inet6.ip6.maxfragbucketsize=040}414243frag6_06_check_stats_0() {4445local jname ifname46jname=$147ifname=$24849case "${jname}" in50"") echo "ERROR: jname is empty"; return ;;51esac52case "${ifname}" in53"") echo "ERROR: ifname is empty"; return ;;54esac5556# Defaults are: IPV6_FRAGTTL 120 slowtimo ticks.57# pfslowtimo() is run at hz/2. So this takes 60s.58# This is awefully long for a test case.59# The Python script has to wait for this already to get the ICMPv660# hence we do not sleep here anymore.6162nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets`63case ${nf} in640) break ;;65*) atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;;66esac67nf=`sysctl -n net.inet6.ip6.frag6_nfrags`68case ${nf} in690) break ;;70*) atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;;71esac7273#74# Check that the sysctl is set to what we expect.75#76sn=`jexec ${jname} sysctl -n net.inet6.ip6.maxfragbucketsize`77case "${sn}" in780) ;;79*) atf_fail "Sysctl net.inet6.ip6.maxfragbucketsize is ${sn} and not 0" ;;80esac8182#83# Check selection of global UDP stats.84#85cat <<EOF > ${HOME}/filter-${jname}.txt86<received-datagrams>0</received-datagrams>87<dropped-incomplete-headers>0</dropped-incomplete-headers>88<dropped-bad-data-length>0</dropped-bad-data-length>89<dropped-bad-checksum>0</dropped-bad-checksum>90<dropped-no-checksum>0</dropped-no-checksum>91<dropped-no-socket>0</dropped-no-socket>92<dropped-broadcast-multicast>0</dropped-broadcast-multicast>93<dropped-full-socket-buffer>0</dropped-full-socket-buffer>94<not-for-hashed-pcb>0</not-for-hashed-pcb>95EOF96count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`97rm -f ${HOME}/filter-${jname}.txt98case ${count} in999) ;;100*) jexec ${jname} netstat -s -p udp --libxo xml,pretty101atf_fail "Global UDP statistics do not match: ${count} != 9" ;;102esac103104105#106# Check selection of global IPv6 stats.107#108cat <<EOF > ${HOME}/filter-${jname}.txt109<dropped-below-minimum-size>0</dropped-below-minimum-size>110<dropped-short-packets>0</dropped-short-packets>111<dropped-bad-options>0</dropped-bad-options>112<dropped-bad-version>0</dropped-bad-version>113<received-fragments>20</received-fragments>114<dropped-fragment>20</dropped-fragment>115<dropped-fragment-after-timeout>0</dropped-fragment-after-timeout>116<dropped-fragments-overflow>0</dropped-fragments-overflow>117<atomic-fragments>0</atomic-fragments>118<reassembled-packets>0</reassembled-packets>119<forwarded-packets>0</forwarded-packets>120<packets-not-forwardable>0</packets-not-forwardable>121<sent-redirects>0</sent-redirects>122<send-packets-fabricated-header>0</send-packets-fabricated-header>123<discard-no-mbufs>0</discard-no-mbufs>124<discard-no-route>0</discard-no-route>125<sent-fragments>0</sent-fragments>126<fragments-created>0</fragments-created>127<discard-cannot-fragment>0</discard-cannot-fragment>128<discard-scope-violations>0</discard-scope-violations>129EOF130count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`131rm -f ${HOME}/filter-${jname}.txt132case ${count} in13320) ;;134*) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty135atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;136esac137138#139# Check selection of global ICMPv6 stats.140# XXX-TODO check output histogram (just too hard to parse [no multi-line-grep])141#142cat <<EOF > ${HOME}/filter-${jname}.txt143<icmp6-calls>0</icmp6-calls>144<no-route>0</no-route>145<admin-prohibited>0</admin-prohibited>146<beyond-scope>0</beyond-scope>147<address-unreachable>0</address-unreachable>148<port-unreachable>0</port-unreachable>149<packet-too-big>0</packet-too-big>150<time-exceed-transmit>0</time-exceed-transmit>151<time-exceed-reassembly>0</time-exceed-reassembly>152<bad-header>0</bad-header>153<bad-next-header>0</bad-next-header>154<bad-option>0</bad-option>155<redirects>0</redirects>156<unknown>0</unknown>157<reflect>0</reflect>158<too-many-nd-options>0</too-many-nd-options>159<bad-nd-options>0</bad-nd-options>160<bad-neighbor-solicitation>0</bad-neighbor-solicitation>161<bad-neighbor-advertisement>0</bad-neighbor-advertisement>162<bad-router-solicitation>0</bad-router-solicitation>163<bad-router-advertisement>0</bad-router-advertisement>164<bad-redirect>0</bad-redirect>165EOF166count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`167rm -f ${HOME}/filter-${jname}.txt168case ${count} in16922) ;;170*) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty171atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;172esac173174#175# Check selection of interface IPv6 stats.176#177cat <<EOF > ${HOME}/filter-${jname}.txt178<dropped-invalid-header>0</dropped-invalid-header>179<dropped-mtu-exceeded>0</dropped-mtu-exceeded>180<dropped-no-route>0</dropped-no-route>181<dropped-invalid-destination>0</dropped-invalid-destination>182<dropped-unknown-protocol>0</dropped-unknown-protocol>183<dropped-truncated>0</dropped-truncated>184<sent-forwarded>0</sent-forwarded>185<discard-packets>0</discard-packets>186<discard-fragments>0</discard-fragments>187<fragments-failed>0</fragments-failed>188<fragments-created>0</fragments-created>189<reassembly-required>20</reassembly-required>190<reassembled-packets>0</reassembled-packets>191<reassembly-failed>20</reassembly-failed>192EOF193count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`194rm -f ${HOME}/filter-${jname}.txt195case ${count} in19614) ;;197*) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty198atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;199esac200201#202# Check selection of interface ICMPv6 stats.203#204cat <<EOF > ${HOME}/filter-${jname}.txt205<received-errors>0</received-errors>206<received-destination-unreachable>0</received-destination-unreachable>207<received-admin-prohibited>0</received-admin-prohibited>208<received-time-exceeded>0</received-time-exceeded>209<received-bad-parameter>0</received-bad-parameter>210<received-packet-too-big>0</received-packet-too-big>211<received-echo-requests>0</received-echo-requests>212<received-echo-replies>0</received-echo-replies>213<received-router-solicitation>0</received-router-solicitation>214<received-router-advertisement>0</received-router-advertisement>215<sent-errors>0</sent-errors>216<sent-destination-unreachable>0</sent-destination-unreachable>217<sent-admin-prohibited>0</sent-admin-prohibited>218<sent-time-exceeded>0</sent-time-exceeded>219<sent-bad-parameter>0</sent-bad-parameter>220<sent-packet-too-big>0</sent-packet-too-big>221<sent-echo-requests>0</sent-echo-requests>222<sent-echo-replies>0</sent-echo-replies>223<sent-router-solicitation>0</sent-router-solicitation>224<sent-router-advertisement>0</sent-router-advertisement>225<sent-redirects>0</sent-redirects>226EOF227count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`228rm -f ${HOME}/filter-${jname}.txt229case ${count} in23021) ;;231*) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty232atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;233esac234}235236atf_test_case "frag6_06_0" "cleanup"237frag6_06_0_head() {238frag6_head 6_0239}240241frag6_06_0_body() {242frag6_body 6 frag6_06_check_stats_0 frag6_06_pre_test_0243}244245frag6_06_0_cleanup() {246frag6_cleanup 6_0247248# No need to restore the sysctl back to default as the jail is gone.249}250251252#atf_test_case "frag6_06_1" "cleanup"253# There is no point in testing a != 0 value for net.inet6.ip6.maxfragbucketsize.254# We would have to be able to generate hash collisions to end up in the same255# bucket (or re-compile a kernel with only 1 bucket).256257258atf_init_test_cases()259{260atf_add_test_case "frag6_06_0"261}262263264