Module Name:    src
Committed By:   ozaki-r
Date:           Mon Nov  7 04:43:14 UTC 2016

Modified Files:
        src/tests/net/net: t_ping6_opts.sh

Log Message:
Add tests of ping6 hops optional argument (Type 0 Routing Headers)

Note that ping6 with the argument can send packets with routing headers
but the kernel doesn't support receiving the packets so that ping6 fails.
Nevertheless, we can test whether sent packets are correct or not.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ping6_opts.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/net/t_ping6_opts.sh
diff -u src/tests/net/net/t_ping6_opts.sh:1.1 src/tests/net/net/t_ping6_opts.sh:1.2
--- src/tests/net/net/t_ping6_opts.sh:1.1	Mon Oct 31 10:38:25 2016
+++ src/tests/net/net/t_ping6_opts.sh	Mon Nov  7 04:43:14 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping6_opts.sh,v 1.1 2016/10/31 10:38:25 ozaki-r Exp $
+#	$NetBSD: t_ping6_opts.sh,v 1.2 2016/11/07 04:43:14 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -160,6 +160,20 @@ check_echo_request_pkt_with_macaddr()
 	atf_check -s exit:0 -o match:"$pkt" cat ./out
 }
 
+check_echo_request_pkt_with_macaddr_and_rthdr0()
+{
+	local pkt=
+
+	pkt="$1 > $2, .+ $3 > $4:"
+	pkt="$pkt srcrt \\(len=2, type=0, segleft=1, \\[0\\]$5\\)"
+	pkt="$pkt .+ echo request"
+
+	extract_new_packets $BUS_SRCGW > ./out
+	$DEBUG && echo $pkt
+	$DEBUG && cat ./out
+	atf_check -s exit:0 -o match:"$pkt" cat ./out
+}
+
 dump()
 {
 
@@ -333,10 +347,71 @@ ping6_opts_gateway_cleanup()
 	cleanup
 }
 
+atf_test_case ping6_opts_hops cleanup
+ping6_opts_hops_head()
+{
+
+	atf_set "descr" "tests of ping6 hops (Type 0 Routing Header)"
+	atf_set "require.progs" "rump_server"
+}
+
+ping6_opts_hops_body()
+{
+	local my_macaddr=
+	local gw_shmif0_macaddr=
+	local gw_shmif2_macaddr=
+
+	setup6
+	setup_forwarding6
+
+	my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
+	gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
+
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
+	check_echo_request_pkt_with_macaddr \
+	    $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
+
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.ifconfig shmif2 create
+	atf_check -s exit:0 rump.ifconfig shmif2 linkstr $BUS_SRCGW
+	atf_check -s exit:0 rump.ifconfig shmif2 inet6 $IP6SRCGW2
+	atf_check -s exit:0 rump.ifconfig -w 10
+	gw_shmif2_macaddr=$(get_macaddr ${SOCKFWD} shmif2)
+
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
+	check_echo_request_pkt_with_macaddr \
+	    $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
+
+	# ping6 hops
+
+	# ping6 fails expectedly because the kernel doesn't support
+	# to receive packets with type 0 routing headers, but we can
+	# check whether a sent packet is correct.
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	    $IP6SRCGW $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	    $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
+
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	    $IP6SRCGW2 $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	    $my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
+}
+
+ping6_opts_hops_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
 atf_init_test_cases()
 {
 
 	atf_add_test_case ping6_opts_sourceaddr
 	atf_add_test_case ping6_opts_interface
 	atf_add_test_case ping6_opts_gateway
+	atf_add_test_case ping6_opts_hops
 }

Reply via email to