From nobody@FreeBSD.org  Fri Apr  2 16:52:56 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 04E62106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Apr 2010 16:52:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id E7BDC8FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Apr 2010 16:52:55 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o32GqtVV046705
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Apr 2010 16:52:55 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o32GqtK6046704;
	Fri, 2 Apr 2010 16:52:55 GMT
	(envelope-from nobody)
Message-Id: <201004021652.o32GqtK6046704@www.freebsd.org>
Date: Fri, 2 Apr 2010 16:52:55 GMT
From: Boris Astardzhiev <boris_astardzhiev@smartcom.bg>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ARP table mapping is not refreshed on a MAC address change
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145300
>Category:       kern
>Synopsis:       [arp] ARP table mapping is not refreshed on a MAC address change
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    qingli
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 02 17:00:13 UTC 2010
>Closed-Date:    
>Last-Modified:  Sat Jul 24 12:10:00 UTC 2010
>Originator:     Boris Astardzhiev
>Release:        FreeBSD 8.0
>Organization:
Smartcom Bulgaria AD
>Environment:
FreeBSD boris-fbsd.smartcom.bg 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #3: Tue Mar 30 18:58:50 EEST 2010     root@boris-fbsd.smartcom.bg:/usr/src/sys/i386/compile/KGDB  i386

>Description:
On changing a link layer (MAC) address of a network interface that has an AF_INET address family applied to it the ARP table remains untouched reporting that the AF_INET address family is still mapped to the previous MAC address. An ARP table flush does not solve the problem.
>How-To-Repeat:
Here's a walk-through regarding the specified problem.

boris-fbsd# ifconfig em1
em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
	ether 08:00:27:07:bb:b7
	inet 192.168.56.2 netmask 0xffffff00 broadcast 192.168.56.255
	media: Ethernet autoselect (1000baseT <full-duplex>)
	status: active

boris-fbsd# arp -a -n
? (192.168.56.2) at 08:00:27:07:bb:b7 on em1 permanent [ethernet]

boris-fbsd# ifconfig em1 ether 11:22:33:44:55:66

boris-fbsd# ifconfig em1
em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
	ether 11:22:33:44:55:66
	inet 192.168.56.2 netmask 0xffffff00 broadcast 192.168.56.255
	media: Ethernet autoselect (1000baseT <full-duplex>)
	status: active

boris-fbsd# arp -a -n
? (192.168.56.2) at 08:00:27:07:bb:b7 on em1 permanent [ethernet]

boris-fbsd# arp -a -d
192.168.56.2 (192.168.56.2) deleted

boris-fbsd# arp -a -n
? (192.168.56.2) at 08:00:27:07:bb:b7 on em1 permanent [ethernet]

boris-fbsd# 

As you may have noticed the MAC address reported in the ARP table remains the old one though it's been changed.
>Fix:
A patch is applied.

Patch attached with submission follows:

--- usr/src/sys/net/if.c	2010-04-02 19:15:39.000000000 +0300
+++ /usr/src/sys/net/if.c	2010-04-02 19:16:57.000000000 +0300
@@ -142,6 +142,11 @@
 static void	if_attach_internal(struct ifnet *, int);
 static void	if_detach_internal(struct ifnet *, int);
 
+#ifdef INET
+/* XXX: better way to grab access to this function? */
+extern void arp_ifscrub(struct ifnet *ifp, uint32_t addr);
+#endif /* INET */
+
 #ifdef INET6
 /*
  * XXX: declare here to avoid to include many inet6 related files..
@@ -3197,8 +3202,14 @@
 		 * the address change.
 		 */
 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
-			if (ifa->ifa_addr->sa_family == AF_INET)
+			if (ifa->ifa_addr->sa_family == AF_INET) {
+				struct in_ifaddr *ia = (struct in_ifaddr *)ifa;
+
+				/* Delete previous mappings in the ARP table 
+				 * first then send a gratuitous ARP */
+				arp_ifscrub(ifp, (uint32_t)(IA_SIN(ia)->sin_addr.s_addr));
 				arp_ifinit(ifp, ifa);
+			}
 		}
 #endif
 	}


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->qingli 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sat Apr 3 09:06:11 UTC 2010 
Responsible-Changed-Why:  
Qing, you worked on the l2/l3 rewrite, can this be part of that? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145300 

From: boris astardzhiev <boris.astardzhiev@gmail.com>
To: bug-followup@FreeBSD.org, boris_astardzhiev@smartcom.bg
Cc:  
Subject: Re: kern/145300: [arp] ARP table mapping is not refreshed on a MAC
 address change
Date: Sat, 24 Jul 2010 14:39:21 +0300

 This bug also applies to a freshly installed FreeBSD 8.1-RELEASE:
 
 boris-fbsd81# uname -a
 FreeBSD boris-fbsd81.smartcom.bg 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon 
 Jul 19 02:55:53 UTC 2010 
 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
 boris-fbsd81#
>Unformatted:
