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