xref: /freebsd/tests/sys/netinet6/frag6/frag6_14.sh (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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
30atf_test_case "frag6_14" "cleanup"
31frag6_14_head() {
32	frag6_head 14
33}
34
35frag6_14_check_stats() {
36
37	local jname ifname
38	jname=$1
39	ifname=$2
40
41	case "${jname}" in
42	"")	echo "ERROR: jname is empty"; return ;;
43	esac
44	case "${ifname}" in
45	"")	echo "ERROR: ifname is empty"; return ;;
46	esac
47
48	# Defaults are: IPV6_FRAGTTL  120 slowtimo ticks.
49	# pfslowtimo() is run at hz/2.  So this takes 60s.
50	# This is awefully long for a test case.
51	# The Python script has to wait for this already to get the ICMPv6
52	# hence we do not sleep here anymore.
53
54	nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets`
55	case ${nf} in
56	0)	break ;;
57	*)	atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;;
58	esac
59	nf=`sysctl -n net.inet6.ip6.frag6_nfrags`
60	case ${nf} in
61	0)	break ;;
62	*)	atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;;
63	esac
64
65	#
66	# Check selection of global UDP stats.
67	#
68	cat <<EOF > ${HOME}/filter-${jname}.txt
69    <received-datagrams>0</received-datagrams>
70    <dropped-incomplete-headers>0</dropped-incomplete-headers>
71    <dropped-bad-data-length>0</dropped-bad-data-length>
72    <dropped-bad-checksum>0</dropped-bad-checksum>
73    <dropped-no-checksum>0</dropped-no-checksum>
74    <dropped-no-socket>0</dropped-no-socket>
75    <dropped-broadcast-multicast>0</dropped-broadcast-multicast>
76    <dropped-full-socket-buffer>0</dropped-full-socket-buffer>
77    <not-for-hashed-pcb>0</not-for-hashed-pcb>
78EOF
79	count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
80	rm -f ${HOME}/filter-${jname}.txt
81	case ${count} in
82	9)	;;
83	*)	jexec ${jname} netstat -s -p udp --libxo xml,pretty
84		atf_fail "Global UDP statistics do not match: ${count} != 9" ;;
85	esac
86
87	#
88	# Check selection of global IPv6 stats.
89	#
90	cat <<EOF > ${HOME}/filter-${jname}.txt
91    <dropped-below-minimum-size>0</dropped-below-minimum-size>
92    <dropped-short-packets>0</dropped-short-packets>
93    <dropped-bad-options>0</dropped-bad-options>
94    <dropped-bad-version>0</dropped-bad-version>
95    <received-fragments>6</received-fragments>
96    <dropped-fragment>2</dropped-fragment>
97    <dropped-fragment-after-timeout>3</dropped-fragment-after-timeout>
98    <dropped-fragments-overflow>0</dropped-fragments-overflow>
99    <atomic-fragments>0</atomic-fragments>
100    <reassembled-packets>0</reassembled-packets>
101    <forwarded-packets>0</forwarded-packets>
102    <packets-not-forwardable>0</packets-not-forwardable>
103    <sent-redirects>0</sent-redirects>
104    <send-packets-fabricated-header>0</send-packets-fabricated-header>
105    <discard-no-mbufs>0</discard-no-mbufs>
106    <discard-no-route>0</discard-no-route>
107    <sent-fragments>0</sent-fragments>
108    <fragments-created>0</fragments-created>
109    <discard-cannot-fragment>0</discard-cannot-fragment>
110    <discard-scope-violations>0</discard-scope-violations>
111EOF
112	count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
113	rm -f ${HOME}/filter-${jname}.txt
114	case ${count} in
115	20)	;;
116	*)	jexec ${jname} netstat -s -p ip6 --libxo xml,pretty
117		atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;
118	esac
119
120	#
121	# Check selection of global ICMPv6 stats.
122	#
123	cat <<EOF > ${HOME}/filter-${jname}.txt
124    <icmp6-calls>1</icmp6-calls>
125      <no-route>0</no-route>
126      <admin-prohibited>0</admin-prohibited>
127      <beyond-scope>0</beyond-scope>
128      <address-unreachable>0</address-unreachable>
129      <port-unreachable>0</port-unreachable>
130      <packet-too-big>0</packet-too-big>
131      <time-exceed-transmit>0</time-exceed-transmit>
132      <time-exceed-reassembly>1</time-exceed-reassembly>
133      <bad-header>0</bad-header>
134      <bad-next-header>0</bad-next-header>
135      <bad-option>0</bad-option>
136      <redirects>0</redirects>
137      <unknown>0</unknown>
138      <reflect>0</reflect>
139      <too-many-nd-options>0</too-many-nd-options>
140      <bad-nd-options>0</bad-nd-options>
141      <bad-neighbor-solicitation>0</bad-neighbor-solicitation>
142      <bad-neighbor-advertisement>0</bad-neighbor-advertisement>
143      <bad-router-solicitation>0</bad-router-solicitation>
144      <bad-router-advertisement>0</bad-router-advertisement>
145      <bad-redirect>0</bad-redirect>
146EOF
147	count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
148	rm -f ${HOME}/filter-${jname}.txt
149	case ${count} in
150	22)	;;
151	*)	jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty
152		atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;
153	esac
154
155	#
156	# Check selection of interface IPv6 stats.
157	#
158	cat <<EOF > ${HOME}/filter-${jname}.txt
159    <dropped-invalid-header>0</dropped-invalid-header>
160    <dropped-mtu-exceeded>0</dropped-mtu-exceeded>
161    <dropped-no-route>0</dropped-no-route>
162    <dropped-invalid-destination>0</dropped-invalid-destination>
163    <dropped-unknown-protocol>0</dropped-unknown-protocol>
164    <dropped-truncated>0</dropped-truncated>
165    <sent-forwarded>0</sent-forwarded>
166    <discard-packets>0</discard-packets>
167    <discard-fragments>0</discard-fragments>
168    <fragments-failed>0</fragments-failed>
169    <fragments-created>0</fragments-created>
170    <reassembly-required>6</reassembly-required>
171    <reassembled-packets>0</reassembled-packets>
172    <reassembly-failed>2</reassembly-failed>
173EOF
174	count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
175	rm -f ${HOME}/filter-${jname}.txt
176	case ${count} in
177	14)	;;
178	*)	jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty
179		atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;
180	esac
181
182	#
183	# Check selection of interface ICMPv6 stats.
184	#
185	cat <<EOF > ${HOME}/filter-${jname}.txt
186    <received-errors>0</received-errors>
187    <received-destination-unreachable>0</received-destination-unreachable>
188    <received-admin-prohibited>0</received-admin-prohibited>
189    <received-time-exceeded>0</received-time-exceeded>
190    <received-bad-parameter>0</received-bad-parameter>
191    <received-packet-too-big>0</received-packet-too-big>
192    <received-echo-requests>0</received-echo-requests>
193    <received-echo-replies>0</received-echo-replies>
194    <received-router-solicitation>0</received-router-solicitation>
195    <received-router-advertisement>0</received-router-advertisement>
196    <sent-errors>1</sent-errors>
197    <sent-destination-unreachable>0</sent-destination-unreachable>
198    <sent-admin-prohibited>0</sent-admin-prohibited>
199    <sent-time-exceeded>1</sent-time-exceeded>
200    <sent-bad-parameter>0</sent-bad-parameter>
201    <sent-packet-too-big>0</sent-packet-too-big>
202    <sent-echo-requests>0</sent-echo-requests>
203    <sent-echo-replies>0</sent-echo-replies>
204    <sent-router-solicitation>0</sent-router-solicitation>
205    <sent-router-advertisement>0</sent-router-advertisement>
206    <sent-redirects>0</sent-redirects>
207EOF
208	count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
209	rm -f ${HOME}/filter-${jname}.txt
210	case ${count} in
211	21)	;;
212	*)	jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty
213		atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;
214	esac
215}
216frag6_14_body() {
217	frag6_body 14 frag6_14_check_stats
218}
219
220frag6_14_cleanup() {
221	frag6_cleanup 14
222}
223
224atf_init_test_cases()
225{
226	atf_add_test_case "frag6_14"
227}
228