Module Name:    src
Committed By:   ozaki-r
Date:           Thu Feb 25 03:23:15 UTC 2016

Modified Files:
        src/tests/net/arp: t_arp.sh

Log Message:
Add basic tests for Proxy ARP

The tests don't much enough and need more realitic tests, for example
tests for a setup using ppp found in PR 44032.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/net/arp/t_arp.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/arp/t_arp.sh
diff -u src/tests/net/arp/t_arp.sh:1.10 src/tests/net/arp/t_arp.sh:1.11
--- src/tests/net/arp/t_arp.sh:1.10	Wed Dec  2 06:05:14 2015
+++ src/tests/net/arp/t_arp.sh	Thu Feb 25 03:23:15 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_arp.sh,v 1.10 2015/12/02 06:05:14 ozaki-r Exp $
+#	$NetBSD: t_arp.sh,v 1.11 2016/02/25 03:23:15 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -32,6 +32,10 @@ SOCKSRC=unix://commsock1
 SOCKDST=unix://commsock2
 IP4SRC=10.0.1.1
 IP4DST=10.0.1.2
+IP4DST_PUB=10.0.1.3
+MACDST_PUB=b2:a1:00:00:00:01
+IP4DST_PUBPROXY=10.0.1.4
+MACDST_PUBPROXY=b2:a1:00:00:00:02
 
 DEBUG=false
 TIMEOUT=1
@@ -41,6 +45,7 @@ atf_test_case cache_expiration_10s clean
 atf_test_case command cleanup
 atf_test_case garp cleanup
 atf_test_case cache_overwriting cleanup
+atf_test_case pubproxy_arp cleanup
 
 cache_expiration_5s_head()
 {
@@ -72,6 +77,12 @@ cache_overwriting_head()
 	atf_set "require.progs" "rump_server"
 }
 
+pubproxy_arp_head()
+{
+	atf_set "descr" "Tests for Proxy ARP"
+	atf_set "require.progs" "rump_server"
+}
+
 setup_dst_server()
 {
 	export RUMP_SERVER=$SOCKDST
@@ -225,7 +236,7 @@ command_body()
 	return 0
 }
 
-make_pkt_str()
+make_pkt_str_arpreq()
 {
 	local target=$1
 	local sender=$2
@@ -253,10 +264,10 @@ garp_body()
 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
 
 	# A GARP packet is sent for the primary address
-	pkt=$(make_pkt_str 10.0.0.1 10.0.0.1)
+	pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
 	# No GARP packet is sent for the alias address
-	pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
+	pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
 
 	atf_check -s exit:0 rump.ifconfig -w 10
@@ -265,9 +276,9 @@ garp_body()
 
 	# No GARP packets are sent during IFF_UP
 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
-	pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
+	pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
-	pkt=$(make_pkt_str 10.0.0.4 10.0.0.4)
+	pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
 }
 
@@ -309,6 +320,94 @@ cache_overwriting_body()
 	return 0
 }
 
+make_pkt_str_arprep()
+{
+	local ip=$1
+	local mac=$2
+	pkt="ethertype ARP (0x0806), length 42: "
+	pkt="Reply $ip is-at $mac, length 28"
+	echo $pkt
+}
+
+extract_new_packets()
+{
+	local old=./old
+
+	if [ ! -f $old ]; then
+		old=/dev/null
+	fi
+
+	shmif_dumpbus -p - bus1 2>/dev/null| \
+	    tcpdump -n -e -r - 2>/dev/null > ./new
+	diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
+	mv -f ./new ./old
+	cat ./diff
+}
+
+check_entry_flags()
+{
+	local ip=$(echo $1 |sed 's/\./\\./g')
+	local flags=$2
+
+	atf_check -s exit:0 -o match:" $flags " -e ignore -x \
+	    "rump.netstat -rn -f inet | grep ^'$ip'"
+}
+
+pubproxy_arp_body()
+{
+	local arp_keep=5
+
+	atf_check -s exit:0 ${inetserver} $SOCKSRC
+	atf_check -s exit:0 ${inetserver} $SOCKDST
+
+	setup_dst_server
+	setup_src_server $arp_keep
+
+	export RUMP_SERVER=$SOCKDST
+
+	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST_PUB \
+	    $MACDST_PUB pub
+	atf_check -s exit:0 -o match:'permanent published' \
+	    rump.arp -n $IP4DST_PUB
+	check_entry_flags $IP4DST_PUB ULSp
+
+	$DEBUG && rump.arp -n -a
+	$DEBUG && rump.netstat -nr -f inet
+
+	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST_PUBPROXY \
+	    $MACDST_PUBPROXY pub proxy
+	atf_check -s exit:0 -o match:'permanent published \(proxy only\)' \
+	    rump.arp -n $IP4DST_PUBPROXY
+	check_entry_flags $IP4DST_PUBPROXY UHLSp
+
+	$DEBUG && rump.arp -n -a
+	$DEBUG && rump.netstat -nr -f inet
+
+	export RUMP_SERVER=$SOCKSRC
+
+	atf_check -s not-exit:0 -o ignore -e ignore \
+	    rump.ping -n -w 1 -c 1 $IP4DST_PUB
+
+	atf_check -s exit:0 sleep 1
+	extract_new_packets > ./out
+	$DEBUG && cat ./out
+
+	pkt=$(make_pkt_str_arprep $IP4DST_PUB $MACDST_PUB)
+	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
+
+	atf_check -s not-exit:0 -o ignore -e ignore \
+	    rump.ping -n -w 1 -c 1 $IP4DST_PUBPROXY
+
+	atf_check -s exit:0 sleep 1
+	extract_new_packets > ./out
+	$DEBUG && cat ./out
+
+	pkt=$(make_pkt_str_arprep $IP4DST_PUBPROXY $MACDST_PUBPROXY)
+	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
+
+	return 0
+}
+
 cleanup()
 {
 	env RUMP_SERVER=$SOCKSRC rump.halt
@@ -371,6 +470,12 @@ cache_overwriting_cleanup()
 	cleanup
 }
 
+pubproxy_arp_cleanup()
+{
+	$DEBUG && dump
+	cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case cache_expiration_5s
@@ -378,4 +483,5 @@ atf_init_test_cases()
 	atf_add_test_case command
 	atf_add_test_case garp
 	atf_add_test_case cache_overwriting
+	atf_add_test_case pubproxy_arp
 }

Reply via email to