Module Name:    src
Committed By:   knakahara
Date:           Thu Oct 18 11:34:54 UTC 2018

Modified Files:
        src/sys/net: if.c if.h if_vlan.c

Log Message:
fix panic when do ifconfig -vlanif and ifconfig vlanif again. advised by 
ozaki-r@.

e.g. do the following commands.
    ====================
    # ifconfig vlan0 create
    # ifconfig vlan0 vlan 100 vlanif wm0
    # ifconfig vlan0 -vlanif wm0
    # ifconfig vlan0 vlan 100 vlanif wm0
    ====================

ATF net/if_vlan do this type of test, however it cannot detect this bug.
Because the shmif(4)'s ifp->if_hwdl is always NULL as shmif(4)'s ethernet
address is set U/L bit.
See: https://nxr.netbsd.org/xref/src/sys/net/if_ethersubr.c#997


To generate a diff of this commit:
cvs rdiff -u -r1.436 -r1.437 src/sys/net/if.c
cvs rdiff -u -r1.265 -r1.266 src/sys/net/if.h
cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_vlan.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/net/if.c
diff -u src/sys/net/if.c:1.436 src/sys/net/if.c:1.437
--- src/sys/net/if.c:1.436	Fri Sep  7 13:24:14 2018
+++ src/sys/net/if.c	Thu Oct 18 11:34:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.436 2018/09/07 13:24:14 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.437 2018/10/18 11:34:54 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.436 2018/09/07 13:24:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.437 2018/10/18 11:34:54 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -201,7 +201,6 @@ static void if_detach_queues(struct ifne
 static void sysctl_sndq_setup(struct sysctllog **, const char *,
     struct ifaltq *);
 static void if_slowtimo(void *);
-static void if_free_sadl(struct ifnet *, int);
 static void if_attachdomain1(struct ifnet *);
 static int ifconf(u_long, void *);
 static int if_transmit(struct ifnet *, struct mbuf *);
@@ -573,7 +572,7 @@ if_activate_sadl(struct ifnet *ifp, stru
  * Free the link level name for the specified interface.  This is
  * a detach helper.  This is called from if_detach().
  */
-static void
+void
 if_free_sadl(struct ifnet *ifp, int factory)
 {
 	struct ifaddr *ifa;

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.265 src/sys/net/if.h:1.266
--- src/sys/net/if.h:1.265	Wed Aug 22 01:05:24 2018
+++ src/sys/net/if.h	Thu Oct 18 11:34:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.265 2018/08/22 01:05:24 msaitoh Exp $	*/
+/*	$NetBSD: if.h,v 1.266 2018/10/18 11:34:54 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1075,6 +1075,7 @@ void if_activate_sadl(struct ifnet *, st
     const struct sockaddr_dl *);
 void	if_set_sadl(struct ifnet *, const void *, u_char, bool);
 void	if_alloc_sadl(struct ifnet *);
+void	if_free_sadl(struct ifnet *, int);
 int	if_initialize(struct ifnet *);
 void	if_register(struct ifnet *);
 int	if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.131 src/sys/net/if_vlan.c:1.132
--- src/sys/net/if_vlan.c:1.131	Fri Aug  3 11:24:19 2018
+++ src/sys/net/if_vlan.c	Thu Oct 18 11:34:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.131 2018/08/03 11:24:19 jmcneill Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.132 2018/10/18 11:34:54 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.131 2018/08/03 11:24:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.132 2018/10/18 11:34:54 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -634,6 +634,9 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 		IFNET_LOCK(ifp);
 		mutex_enter(&ifv->ifv_lock);
 
+		/* if_free_sadl must be called with IFNET_LOCK */
+		if_free_sadl(ifp, 1);
+
 		/* Restore vlan_ioctl overwritten by ether_ifdetach */
 		ifp->if_ioctl = vlan_ioctl;
 		vlan_reset_linkname(ifp);

Reply via email to