Module Name:    src
Committed By:   ozaki-r
Date:           Fri Dec 25 08:22:28 UTC 2015

Modified Files:
        src/tests/net/icmp: t_icmp_redirect.sh
        src/tests/net/net: t_forwarding.sh

Log Message:
Add some tests for sysctl net.inet.ip.*

- net.inet.ip.redirect
- net.inet.ip.directed-broadcast (and net.inet.icmp.bmcastecho)
- net.inet.ip.ttl

>From suzu-ken@IIJ (with tweaks by me)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/icmp/t_icmp_redirect.sh
cvs rdiff -u -r1.10 -r1.11 src/tests/net/net/t_forwarding.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/icmp/t_icmp_redirect.sh
diff -u src/tests/net/icmp/t_icmp_redirect.sh:1.1 src/tests/net/icmp/t_icmp_redirect.sh:1.2
--- src/tests/net/icmp/t_icmp_redirect.sh:1.1	Mon Aug 31 06:16:08 2015
+++ src/tests/net/icmp/t_icmp_redirect.sh	Fri Dec 25 08:22:28 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: t_icmp_redirect.sh,v 1.1 2015/08/31 06:16:08 ozaki-r Exp $
+#	$NetBSD: t_icmp_redirect.sh,v 1.2 2015/12/25 08:22:28 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -209,8 +209,131 @@ icmp_redirect_timeout_cleanup()
 	cleanup
 }
 
+atf_test_case icmp_redirect cleanup
+
+icmp_redirect_head()
+{
+
+	atf_set "descr" "Tests for icmp redirect";
+	atf_set "require.progs" "rump_server";
+}
+
+setup_redirect()
+{
+	atf_check -s exit:0 -o ignore rump.sysctl -w \
+	    net.inet.ip.redirect=1
+}
+
+teardown_redirect()
+{
+	atf_check -s exit:0 -o ignore rump.sysctl -w \
+	    net.inet.ip.redirect=0
+}
+
+icmp_redirect_body()
+{
+
+	$DEBUG && ulimit -c unlimited
+
+	setup_local
+	setup_peer
+
+	#
+	# Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
+	#
+	setup_gw
+
+	#
+	# Teach the peer that 10.0.2.* is behind 10.0.0.254
+	#
+	export RUMP_SERVER=$SOCK_PEER
+	atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
+	# Up, Gateway, Static
+	check_entry_flags 10.0.2/24 UGS
+
+	#
+	# Setup the default gateway to the peer, 10.0.0.1
+	#
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
+	# Up, Gateway, Static
+	check_entry_flags default UGS
+
+
+	### ICMP redirects are NOT sent by the peer ###
+
+	#
+	# Disable net.inet.ip.redirect
+	#
+	export RUMP_SERVER=$SOCK_PEER
+	teardown_redirect
+
+	# Try ping 10.0.2.1
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
+	$DEBUG && rump.netstat -rn -f inet
+
+	# A direct route shouldn't be created
+	check_entry_fail 10.0.2.1
+
+
+	### ICMP redirects are sent by the peer ###
+
+	#
+	# Enable net.inet.ip.redirect
+	#
+	export RUMP_SERVER=$SOCK_PEER
+	setup_redirect
+
+	# Try ping 10.0.2.1
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
+	$DEBUG && rump.netstat -rn -f inet
+
+	# Up, Gateway, Host, Dynamic
+	check_entry_flags 10.0.2.1 UGHD
+	check_entry_gw 10.0.2.1 10.0.0.254
+
+	export RUMP_SERVER=$SOCK_PEER
+	$DEBUG && rump.netstat -rn -f inet
+
+
+	# cleanup
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 -o ignore rump.route delete 10.0.2.1
+	check_entry_fail 10.0.2.1
+
+
+	### ICMP redirects are NOT sent by the peer (again) ###
+
+	#
+	# Disable net.inet.ip.redirect
+	#
+	export RUMP_SERVER=$SOCK_PEER
+	teardown_redirect
+
+	# Try ping 10.0.2.1
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
+	$DEBUG && rump.netstat -rn -f inet
+
+	# A direct route shouldn't be created
+	check_entry_fail 10.0.2.1
+
+
+	teardown_gw
+}
+
+icmp_redirect_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
 atf_init_test_cases()
 {
 
+	atf_add_test_case icmp_redirect
 	atf_add_test_case icmp_redirect_timeout
 }

Index: src/tests/net/net/t_forwarding.sh
diff -u src/tests/net/net/t_forwarding.sh:1.10 src/tests/net/net/t_forwarding.sh:1.11
--- src/tests/net/net/t_forwarding.sh:1.10	Tue Nov 24 02:37:33 2015
+++ src/tests/net/net/t_forwarding.sh	Fri Dec 25 08:22:28 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: t_forwarding.sh,v 1.10 2015/11/24 02:37:33 ozaki-r Exp $
+#	$NetBSD: t_forwarding.sh,v 1.11 2015/12/25 08:22:28 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -35,6 +35,7 @@ IP4SRC=10.0.1.2
 IP4SRCGW=10.0.1.1
 IP4DSTGW=10.0.2.1
 IP4DST=10.0.2.2
+IP4DST_BCAST=10.0.2.255
 IP6SRC=fc00:0:0:1::2
 IP6SRCGW=fc00:0:0:1::1
 IP6DSTGW=fc00:0:0:2::1
@@ -49,6 +50,7 @@ atf_test_case basic cleanup
 atf_test_case basic6 cleanup
 atf_test_case fastforward cleanup
 atf_test_case fastforward6 cleanup
+atf_test_case misc cleanup
 
 basic_head()
 {
@@ -62,6 +64,12 @@ basic6_head()
 	atf_set "require.progs" "rump_server"
 }
 
+misc_head()
+{
+	atf_set "descr" "Does IPv4 forwarding tests"
+	atf_set "require.progs" "rump_server"
+}
+
 setup_endpoint()
 {
 	sock=${1}
@@ -224,6 +232,18 @@ setup_forwarding6()
 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
 }
 
+setup_directed_broadcast()
+{
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=1
+}
+
+setup_icmp_bmcastecho()
+{
+	export RUMP_SERVER=$SOCKDST
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=1
+}
+
 teardown_forwarding()
 {
 	export RUMP_SERVER=$SOCKFWD
@@ -236,6 +256,18 @@ teardown_forwarding6()
 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=0
 }
 
+teardown_directed_broadcast()
+{
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=0
+}
+
+teardown_icmp_bmcastecho()
+{
+	export RUMP_SERVER=$SOCKDST
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=0
+}
+
 test_setup_forwarding()
 {
 	export RUMP_SERVER=$SOCKFWD
@@ -321,7 +353,7 @@ test_ping_success()
 	$DEBUG && rump.netstat -nr
 }
 
-test_ttl()
+test_ping_ttl()
 {
 	export RUMP_SERVER=$SOCKSRC
 	$DEBUG && rump.ifconfig -v shmif0
@@ -332,6 +364,44 @@ test_ttl()
 	$DEBUG && rump.ifconfig -v shmif0
 }
 
+test_sysctl_ttl()
+{
+	local ip=$1
+
+	export RUMP_SERVER=$SOCKSRC
+	$DEBUG && rump.ifconfig -v shmif0
+
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=1
+	# get the webpage
+	atf_check -s not-exit:0 -e match:'timed out' \
+		env LD_PRELOAD=/usr/lib/librumphijack.so	\
+		ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
+
+
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=2
+	# get the webpage
+	atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so 	\
+		ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
+
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=64
+	$DEBUG && rump.ifconfig -v shmif0
+}
+
+test_directed_broadcast()
+{
+	setup_icmp_bmcastecho
+
+	setup_directed_broadcast
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
+
+	teardown_directed_broadcast
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
+
+	teardown_icmp_bmcastecho
+}
+
 test_ping6_failure()
 {
 	export RUMP_SERVER=$SOCKSRC
@@ -383,7 +453,6 @@ basic_body()
 	setup_forwarding
 	test_setup_forwarding
 	test_ping_success
-	test_ttl
 
 	teardown_forwarding
 	test_teardown_forwarding
@@ -429,6 +498,24 @@ fastforward6_body()
 	test_http_get "[$IP6DST]"
 }
 
+misc_body()
+{
+	setup
+	test_setup
+
+	setup_forwarding
+	test_setup_forwarding
+
+	test_ping_ttl
+
+	test_directed_broadcast
+
+	setup_bozo $IP4DST
+	test_sysctl_ttl $IP4DST
+
+	return 0
+}
+
 basic_cleanup()
 {
 	dump
@@ -455,10 +542,18 @@ fastforward6_cleanup()
 	cleanup
 }
 
+misc_cleanup()
+{
+	dump
+	cleanup_bozo
+	cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case basic
 	atf_add_test_case basic6
 	atf_add_test_case fastforward
 	atf_add_test_case fastforward6
+	atf_add_test_case misc
 }

Reply via email to