Module Name:    src
Committed By:   ozaki-r
Date:           Thu Jun 16 03:03:33 UTC 2016

Modified Files:
        src/sys/net: if.c if_ethersubr.c if_llatbl.c
        src/sys/net/npf: npf_ext_log.c
        src/sys/netinet6: mld6.c

Log Message:
Use if_get_byindex instead of if_byindex for MP-safe


To generate a diff of this commit:
cvs rdiff -u -r1.339 -r1.340 src/sys/net/if.c
cvs rdiff -u -r1.222 -r1.223 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/if_llatbl.c
cvs rdiff -u -r1.8 -r1.9 src/sys/net/npf/npf_ext_log.c
cvs rdiff -u -r1.66 -r1.67 src/sys/netinet6/mld6.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.339 src/sys/net/if.c:1.340
--- src/sys/net/if.c:1.339	Thu Jun 16 02:38:40 2016
+++ src/sys/net/if.c	Thu Jun 16 03:03:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.339 2016/06/16 02:38:40 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.340 2016/06/16 03:03:33 ozaki-r 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.339 2016/06/16 02:38:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.340 2016/06/16 03:03:33 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3097,28 +3097,38 @@ if_sdl_sysctl(SYSCTLFN_ARGS)
 {
 	struct ifnet *ifp;
 	const struct sockaddr_dl *sdl;
+	struct psref psref;
+	int error = 0;
+	int bound;
 
 	if (namelen != 1)
 		return EINVAL;
 
-	ifp = if_byindex(name[0]);
-	if (ifp == NULL)
-		return ENODEV;
+	bound = curlwp_bind();
+	ifp = if_get_byindex(name[0], &psref);
+	if (ifp == NULL) {
+		error = ENODEV;
+		goto out;
+	}
 
 	sdl = ifp->if_sadl;
 	if (sdl == NULL) {
 		*oldlenp = 0;
-		return 0;
+		goto out;
 	}
 
 	if (oldp == NULL) {
 		*oldlenp = sdl->sdl_alen;
-		return 0;
+		goto out;
 	}
 
 	if (*oldlenp >= sdl->sdl_alen)
 		*oldlenp = sdl->sdl_alen;
-	return sysctl_copyout(l, &sdl->sdl_data[sdl->sdl_nlen], oldp, *oldlenp);
+	error = sysctl_copyout(l, &sdl->sdl_data[sdl->sdl_nlen], oldp, *oldlenp);
+out:
+	if_put(ifp, &psref);
+	curlwp_bindx(bound);
+	return error;
 }
 
 SYSCTL_SETUP(sysctl_net_sdl_setup, "sysctl net.sdl subtree setup")

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.222 src/sys/net/if_ethersubr.c:1.223
--- src/sys/net/if_ethersubr.c:1.222	Thu Apr 28 00:16:56 2016
+++ src/sys/net/if_ethersubr.c	Thu Jun 16 03:03:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.222 2016/04/28 00:16:56 ozaki-r Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.223 2016/06/16 03:03:33 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.222 2016/04/28 00:16:56 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.223 2016/06/16 03:03:33 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1475,24 +1475,31 @@ ether_multicast_sysctl(SYSCTLFN_ARGS)
 	struct ether_multi_sysctl addr;
 	struct ifnet *ifp;
 	struct ethercom *ec;
-	int error;
+	int error = 0;
 	size_t written;
+	struct psref psref;
+	int bound;
 
 	if (namelen != 1)
 		return EINVAL;
 
-	ifp = if_byindex(name[0]);
-	if (ifp == NULL)
-		return ENODEV;
+	bound = curlwp_bind();
+	ifp = if_get_byindex(name[0], &psref);
+	if (ifp == NULL) {
+		error = ENODEV;
+		goto out;
+	}
 	if (ifp->if_type != IFT_ETHER) {
+		if_put(ifp, &psref);
 		*oldlenp = 0;
-		return 0;
+		goto out;
 	}
 	ec = (struct ethercom *)ifp;
 
 	if (oldp == NULL) {
+		if_put(ifp, &psref);
 		*oldlenp = ec->ec_multicnt * sizeof(addr);
-		return 0;
+		goto out;
 	}
 
 	memset(&addr, 0, sizeof(addr));
@@ -1511,8 +1518,11 @@ ether_multicast_sysctl(SYSCTLFN_ARGS)
 		written += sizeof(addr);
 		oldp = (char *)oldp + sizeof(addr);
 	}
+	if_put(ifp, &psref);
 
 	*oldlenp = written;
+out:
+	curlwp_bindx(bound);
 	return error;
 }
 

Index: src/sys/net/if_llatbl.c
diff -u src/sys/net/if_llatbl.c:1.13 src/sys/net/if_llatbl.c:1.14
--- src/sys/net/if_llatbl.c:1.13	Wed Apr  6 08:45:46 2016
+++ src/sys/net/if_llatbl.c	Thu Jun 16 03:03:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_llatbl.c,v 1.13 2016/04/06 08:45:46 ozaki-r Exp $	*/
+/*	$NetBSD: if_llatbl.c,v 1.14 2016/06/16 03:03:33 ozaki-r Exp $	*/
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -592,14 +592,18 @@ lla_rt_output(const u_char rtm_type, con
 	struct llentry *lle;
 	u_int laflags;
 	int error;
+	struct psref psref;
+	int bound;
 
 	KASSERTMSG(dl != NULL && dl->sdl_family == AF_LINK, "invalid dl");
 
+	bound = curlwp_bind();
 	if (sdl_index != 0)
-		ifp = if_byindex(sdl_index);
+		ifp = if_get_byindex(sdl_index, &psref);
 	else
-		ifp = if_byindex(dl->sdl_index);
+		ifp = if_get_byindex(dl->sdl_index, &psref);
 	if (ifp == NULL) {
+		curlwp_bindx(bound);
 		log(LOG_INFO, "%s: invalid ifp (sdl_index %d)\n",
 		    __func__, sdl_index != 0 ? sdl_index : dl->sdl_index);
 		return EINVAL;
@@ -628,7 +632,8 @@ lla_rt_output(const u_char rtm_type, con
 		    (lle->la_flags & LLE_STATIC || lle->la_expire == 0)) {
 			LLE_RUNLOCK(lle);
 			IF_AFDATA_WUNLOCK(ifp);
-			return EEXIST;
+			error = EEXIST;
+			goto out;
 		}
 		if (lle != NULL)
 			LLE_RUNLOCK(lle);
@@ -636,7 +641,8 @@ lla_rt_output(const u_char rtm_type, con
 		lle = lla_create(llt, 0, dst);
 		if (lle == NULL) {
 			IF_AFDATA_WUNLOCK(ifp);
-			return (ENOMEM);
+			error = ENOMEM;
+			goto out;
 		}
 
 		KASSERT(ifp->if_addrlen <= sizeof(lle->ll_addr));
@@ -680,12 +686,16 @@ lla_rt_output(const u_char rtm_type, con
 		IF_AFDATA_WLOCK(ifp);
 		error = lla_delete(llt, 0, dst);
 		IF_AFDATA_WUNLOCK(ifp);
-		return (error == 0 ? 0 : ENOENT);
+		error = (error == 0 ? 0 : ENOENT);
+		break;
 
 	default:
 		error = EINVAL;
 	}
 
+out:
+	if_put(ifp, &psref);
+	curlwp_bindx(bound);
 	return (error);
 }
 

Index: src/sys/net/npf/npf_ext_log.c
diff -u src/sys/net/npf/npf_ext_log.c:1.8 src/sys/net/npf/npf_ext_log.c:1.9
--- src/sys/net/npf/npf_ext_log.c:1.8	Sun Jul 20 00:37:41 2014
+++ src/sys/net/npf/npf_ext_log.c	Thu Jun 16 03:03:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_ext_log.c,v 1.8 2014/07/20 00:37:41 rmind Exp $	*/
+/*	$NetBSD: npf_ext_log.c,v 1.9 2016/06/16 03:03:33 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2010-2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ext_log.c,v 1.8 2014/07/20 00:37:41 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ext_log.c,v 1.9 2016/06/16 03:03:33 ozaki-r Exp $");
 
 #include <sys/types.h>
 #include <sys/module.h>
@@ -85,6 +85,7 @@ npf_log(npf_cache_t *npc, void *meta, in
 	const npf_ext_log_t *log = meta;
 	ifnet_t *ifp;
 	int family;
+	struct psref psref;
 
 	/* Set the address family. */
 	if (npf_iscached(npc, NPC_IP4)) {
@@ -98,7 +99,7 @@ npf_log(npf_cache_t *npc, void *meta, in
 	KERNEL_LOCK(1, NULL);
 
 	/* Find a pseudo-interface to log. */
-	ifp = if_byindex(log->if_idx);
+	ifp = if_get_byindex(log->if_idx, &psref);
 	if (ifp == NULL) {
 		/* No interface. */
 		KERNEL_UNLOCK_ONE(NULL);
@@ -109,6 +110,7 @@ npf_log(npf_cache_t *npc, void *meta, in
 	ifp->if_opackets++;
 	ifp->if_obytes += m->m_pkthdr.len;
 	bpf_mtap_af(ifp, family, m);
+	if_put(ifp, &psref);
 	KERNEL_UNLOCK_ONE(NULL);
 
 	return true;

Index: src/sys/netinet6/mld6.c
diff -u src/sys/netinet6/mld6.c:1.66 src/sys/netinet6/mld6.c:1.67
--- src/sys/netinet6/mld6.c:1.66	Fri Jun 10 13:31:44 2016
+++ src/sys/netinet6/mld6.c	Thu Jun 16 03:03:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.66 2016/06/10 13:31:44 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.67 2016/06/16 03:03:33 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.66 2016/06/10 13:31:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.67 2016/06/16 03:03:33 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -982,13 +982,18 @@ in6_multicast_sysctl(SYSCTLFN_ARGS)
 	uint32_t tmp;
 	int error;
 	size_t written;
+	struct psref psref;
+	int bound;
 
 	if (namelen != 1)
 		return EINVAL;
 
-	ifp = if_byindex(name[0]);
-	if (ifp == NULL)
+	bound = curlwp_bind();
+	ifp = if_get_byindex(name[0], &psref);
+	if (ifp == NULL) {
+		curlwp_bindx(bound);
 		return ENODEV;
+	}
 
 	if (oldp == NULL) {
 		*oldlenp = 0;
@@ -1003,6 +1008,8 @@ in6_multicast_sysctl(SYSCTLFN_ARGS)
 				    sizeof(uint32_t);
 			}
 		}
+		if_put(ifp, &psref);
+		curlwp_bindx(bound);
 		return 0;
 	}
 
@@ -1039,6 +1046,8 @@ in6_multicast_sysctl(SYSCTLFN_ARGS)
 		}
 	}
 done:
+	if_put(ifp, &psref);
+	curlwp_bindx(bound);
 	*oldlenp = written;
 	return error;
 }

Reply via email to