Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/net Add some tests for sysctl net.inet.ip.*



details:   https://anonhg.NetBSD.org/src/rev/82aa5a7b8982
branches:  trunk
changeset: 342503:82aa5a7b8982
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Dec 25 08:22:28 2015 +0000

description:
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)

diffstat:

 tests/net/icmp/t_icmp_redirect.sh |  125 +++++++++++++++++++++++++++++++++++++-
 tests/net/net/t_forwarding.sh     |  101 +++++++++++++++++++++++++++++-
 2 files changed, 222 insertions(+), 4 deletions(-)

diffs (truncated from 323 to 300 lines):

diff -r e0797d3e79db -r 82aa5a7b8982 tests/net/icmp/t_icmp_redirect.sh
--- a/tests/net/icmp/t_icmp_redirect.sh Fri Dec 25 06:47:56 2015 +0000
+++ b/tests/net/icmp/t_icmp_redirect.sh Fri Dec 25 08:22:28 2015 +0000
@@ -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 @@
        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
 }
diff -r e0797d3e79db -r 82aa5a7b8982 tests/net/net/t_forwarding.sh
--- a/tests/net/net/t_forwarding.sh     Fri Dec 25 06:47:56 2015 +0000
+++ b/tests/net/net/t_forwarding.sh     Fri Dec 25 08:22:28 2015 +0000
@@ -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 @@
 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 basic6 cleanup
 atf_test_case fastforward cleanup
 atf_test_case fastforward6 cleanup
+atf_test_case misc cleanup
 
 basic_head()
 {
@@ -62,6 +64,12 @@
        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 @@
        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 @@
        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 @@
        $DEBUG && rump.netstat -nr
 }
 
-test_ttl()
+test_ping_ttl()
 {
        export RUMP_SERVER=$SOCKSRC
        $DEBUG && rump.ifconfig -v shmif0
@@ -332,6 +364,44 @@
        $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 @@
        setup_forwarding
        test_setup_forwarding
        test_ping_success
-       test_ttl
 
        teardown_forwarding
        test_teardown_forwarding
@@ -429,6 +498,24 @@
        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
+}



Home | Main Index | Thread Index | Old Index