Module Name:    src
Committed By:   snj
Date:           Sun Apr  8 06:09:12 UTC 2018

Modified Files:
        src/sys/netinet [netbsd-8]: in.c
        src/sys/netinet6 [netbsd-8]: in6.c
        src/tests/net/arp [netbsd-8]: t_arp.sh

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #701):
        sys/netinet/in.c: 1.227
        sys/netinet6/in6.c: 1.265
        tests/net/arp/t_arp.sh: 1.35-1.36
Make GARP work again when DAD is disabled
The change avoids setting an IP address tentative on initializing it when
the IPv4 DAD is disabled (net.inet.ip.dad_count=0), which allows a GARP packet
to be sent (see arpannounce).  This is the same behavior of NetBSD 7, i.e.,
before introducing the IPv4 DAD.
Additionally do the same change to IPv6 DAD for consistency.
The change is suggested by roy@
--
Improve packet checks and error reporting
--
Add tests for GARP without DAD
Additionally make the existing tests for GARP more explicit.


To generate a diff of this commit:
cvs rdiff -u -r1.203.2.11 -r1.203.2.12 src/sys/netinet/in.c
cvs rdiff -u -r1.245.2.9 -r1.245.2.10 src/sys/netinet6/in6.c
cvs rdiff -u -r1.22.6.1 -r1.22.6.2 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/sys/netinet/in.c
diff -u src/sys/netinet/in.c:1.203.2.11 src/sys/netinet/in.c:1.203.2.12
--- src/sys/netinet/in.c:1.203.2.11	Tue Mar 13 13:27:10 2018
+++ src/sys/netinet/in.c	Sun Apr  8 06:09:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.203.2.11 2018/03/13 13:27:10 martin Exp $	*/
+/*	$NetBSD: in.c,v 1.203.2.12 2018/04/08 06:09:12 snj Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.11 2018/03/13 13:27:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.12 2018/04/08 06:09:12 snj Exp $");
 
 #include "arp.h"
 
@@ -1150,7 +1150,7 @@ in_ifinit(struct ifnet *ifp, struct in_i
 	if (ifp->if_link_state == LINK_STATE_DOWN) {
 		ia->ia4_flags |= IN_IFF_DETACHED;
 		ia->ia4_flags &= ~IN_IFF_TENTATIVE;
-	} else if (hostIsNew && if_do_dad(ifp))
+	} else if (hostIsNew && if_do_dad(ifp) && ip_dad_count > 0)
 		ia->ia4_flags |= IN_IFF_TRYTENTATIVE;
 
 	/*

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.245.2.9 src/sys/netinet6/in6.c:1.245.2.10
--- src/sys/netinet6/in6.c:1.245.2.9	Tue Mar 13 13:27:10 2018
+++ src/sys/netinet6/in6.c	Sun Apr  8 06:09:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.245.2.9 2018/03/13 13:27:10 martin Exp $	*/
+/*	$NetBSD: in6.c,v 1.245.2.10 2018/04/08 06:09:12 snj Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.9 2018/03/13 13:27:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.10 2018/04/08 06:09:12 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1240,8 +1240,10 @@ in6_update_ifa1(struct ifnet *ifp, struc
 	if (ifp->if_link_state == LINK_STATE_DOWN) {
 		ia->ia6_flags |= IN6_IFF_DETACHED;
 		ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
-	} else if ((hostIsNew || was_tentative) && if_do_dad(ifp))
+	} else if ((hostIsNew || was_tentative) && if_do_dad(ifp) &&
+	           ip6_dad_count > 0) {
 		ia->ia6_flags |= IN6_IFF_TENTATIVE;
+	}
 
 	/*
 	 * backward compatibility - if IN6_IFF_DEPRECATED is set from the

Index: src/tests/net/arp/t_arp.sh
diff -u src/tests/net/arp/t_arp.sh:1.22.6.1 src/tests/net/arp/t_arp.sh:1.22.6.2
--- src/tests/net/arp/t_arp.sh:1.22.6.1	Fri Jul  7 13:57:26 2017
+++ src/tests/net/arp/t_arp.sh	Sun Apr  8 06:09:12 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_arp.sh,v 1.22.6.1 2017/07/07 13:57:26 martin Exp $
+#	$NetBSD: t_arp.sh,v 1.22.6.2 2018/04/08 06:09:12 snj Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -41,6 +41,7 @@ atf_test_case arp_cache_expiration_5s cl
 atf_test_case arp_cache_expiration_10s cleanup
 atf_test_case arp_command cleanup
 atf_test_case arp_garp cleanup
+atf_test_case arp_garp_without_dad cleanup
 atf_test_case arp_cache_overwriting cleanup
 atf_test_case arp_proxy_arp_pub cleanup
 atf_test_case arp_proxy_arp_pubproxy cleanup
@@ -71,6 +72,13 @@ arp_garp_head()
 	atf_set "require.progs" "rump_server"
 }
 
+arp_garp_without_dad_head()
+{
+
+	atf_set "descr" "Tests for GARP with DAD disabled"
+	atf_set "require.progs" "rump_server"
+}
+
 arp_cache_overwriting_head()
 {
 	atf_set "descr" "Tests for behavior of overwriting ARP caches"
@@ -292,50 +300,105 @@ make_pkt_str_arpreq()
 {
 	local target=$1
 	local sender=$2
-	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
+	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP \(0x0806\), length 42:"
 	pkt="$pkt Request who-has $target tell $sender, length 28"
 	echo $pkt
 }
 
-arp_garp_body()
+test_garp_common()
 {
+	local no_dad=$1
 	local pkt=
 
 	rump_server_start $SOCKSRC
 
 	export RUMP_SERVER=$SOCKSRC
 
+	if $no_dad; then
+		atf_check -s exit:0 -o match:'3 -> 0' \
+		    rump.sysctl -w net.inet.ip.dad_count=0
+	fi
+
 	# Setup an interface
 	rump_server_add_iface $SOCKSRC shmif0 bus1
 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
-	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
 	atf_check -s exit:0 rump.ifconfig shmif0 up
 	$DEBUG && rump.ifconfig shmif0
 
 	atf_check -s exit:0 sleep 1
-	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
+	extract_new_packets bus1 > ./out
 
+	#
+	# Assign an address to an interface without IFF_UP
+	#
 	# A GARP packet is sent for the primary address
 	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
+	atf_check -s exit:0 -o match:"$pkt" cat ./out
+
+	atf_check -s exit:0 rump.ifconfig shmif0 down
+	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
+
+	atf_check -s exit:0 sleep 1
+	extract_new_packets bus1 > ./out
+
+	# A GARP packet is sent for the alias address
 	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 -o match:"$pkt" cat ./out
 
-	atf_check -s exit:0 rump.ifconfig -w 10
+	# Clean up
+	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24 delete
+	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 delete
+
+	#
+	# Assign an address to an interface with IFF_UP
+	#
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+
+	# Primary address
 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
-	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
 
-	# No GARP packets are sent during IFF_UP
-	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
+	atf_check -s exit:0 sleep 1
+	extract_new_packets bus1 > ./out
+
 	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'"
+	if $no_dad; then
+		# A GARP packet is sent
+		atf_check -s exit:0 -o match:"$pkt" cat ./out
+	else
+		# No GARP packet is sent
+		atf_check -s exit:0 -o not-match:"$pkt" cat ./out
+	fi
+
+	# Alias address
+	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
+
+	atf_check -s exit:0 sleep 1
+	extract_new_packets bus1 > ./out
+
 	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'"
+	if $no_dad; then
+		# A GARP packet is sent
+		atf_check -s exit:0 -o match:"$pkt" cat ./out
+	else
+		# No GARP packet is sent
+		atf_check -s exit:0 -o not-match:"$pkt" cat ./out
+	fi
 
 	rump_server_destroy_ifaces
 }
 
+arp_garp_body()
+{
+
+	test_garp_common false
+}
+
+arp_garp_without_dad_body()
+{
+
+	test_garp_common true
+}
+
 arp_cache_overwriting_body()
 {
 	local bonus=2
@@ -519,7 +582,7 @@ arp_link_activation_body()
 	$DEBUG && cat ./out
 
 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
-	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
+	atf_check -s exit:0 -o not-match:"$pkt" cat ./out
 
 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
 	    b2:a1:00:00:00:02 active
@@ -529,8 +592,7 @@ arp_link_activation_body()
 	$DEBUG && cat ./out
 
 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
-	atf_check -s exit:0 -x \
-	    "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
+	atf_check -s exit:0 -o match:"b2:a1:00:00:00:02 $pkt" cat ./out
 
 	rump_server_destroy_ifaces
 }
@@ -584,6 +646,13 @@ arp_garp_cleanup()
 	cleanup
 }
 
+arp_garp_without_dad_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
 arp_cache_overwriting_cleanup()
 {
 	$DEBUG && dump
@@ -882,6 +951,7 @@ atf_init_test_cases()
 	atf_add_test_case arp_cache_expiration_10s
 	atf_add_test_case arp_command
 	atf_add_test_case arp_garp
+	atf_add_test_case arp_garp_without_dad
 	atf_add_test_case arp_cache_overwriting
 	atf_add_test_case arp_proxy_arp_pub
 	atf_add_test_case arp_proxy_arp_pubproxy

Reply via email to