Module Name:    src
Committed By:   ozaki-r
Date:           Tue Aug 20 08:21:04 UTC 2024

Modified Files:
        src/sys/netinet: if_arp.c

Log Message:
arp: fix the behavior on detecting an address duplication without IPv4 DAD

On receiving an ARP request that has the same source protocol address as
the own address, i.e., address duplication, the original behavior of
a kernel prior to supporing IPv4 DAD is to send an ARP reply.   It is
the same with a latest kernel with DAD enabled.  However, a latest
kernel without DAD sends back an GARP packet.  Restore the original
behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/sys/netinet/if_arp.c

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/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.313 src/sys/netinet/if_arp.c:1.314
--- src/sys/netinet/if_arp.c:1.313	Sat Jun 29 12:59:08 2024
+++ src/sys/netinet/if_arp.c	Tue Aug 20 08:21:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.313 2024/06/29 12:59:08 riastradh Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.314 2024/08/20 08:21:04 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.313 2024/06/29 12:59:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.314 2024/08/20 08:21:04 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -924,8 +924,20 @@ again:
 	 */
 	if (in_nullhost(isaddr))
 		ARP_STATINC(ARP_STAT_RCVZEROSPA);
-	else if (in_hosteq(isaddr, myaddr))
+	else if (in_hosteq(isaddr, myaddr)) {
 		ARP_STATINC(ARP_STAT_RCVLOCALSPA);
+		/* This is the original behavior prior to supporting IPv4 DAD */
+		if (!ip_dad_enabled()) {
+			char llabuf[LLA_ADDRSTRLEN];
+			log(LOG_ERR,
+			    "duplicate IP address %s sent from link address %s\n",
+			    IN_PRINT(ipbuf, &isaddr),
+			    lla_snprintf(llabuf, sizeof(llabuf), ar_sha(ah),
+			                 ah->ar_hln));
+			itaddr = myaddr;
+			goto reply;
+		}
+	}
 
 	if (in_nullhost(itaddr))
 		ARP_STATINC(ARP_STAT_RCVZEROTPA);
@@ -941,7 +953,7 @@ again:
 	 * AND our address is either tentative or duplicated
 	 * If it was unicast then it's a valid Unicast Poll from RFC 1122.
 	 */
-	if (do_dad &&
+	if (ip_dad_enabled() && do_dad &&
 	    (in_hosteq(isaddr, myaddr) ||
 	    (in_nullhost(isaddr) && in_hosteq(itaddr, myaddr) &&
 	     m->m_flags & M_BCAST &&

Reply via email to