Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Use if_get_byindex instead of if_byindex for MP-safe
details: https://anonhg.NetBSD.org/src/rev/0d22a767c67c
branches: trunk
changeset: 345934:0d22a767c67c
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Thu Jun 16 03:03:33 2016 +0000
description:
Use if_get_byindex instead of if_byindex for MP-safe
diffstat:
sys/net/if.c | 26 ++++++++++++++++++--------
sys/net/if_ethersubr.c | 26 ++++++++++++++++++--------
sys/net/if_llatbl.c | 22 ++++++++++++++++------
sys/net/npf/npf_ext_log.c | 8 +++++---
sys/netinet6/mld6.c | 17 +++++++++++++----
5 files changed, 70 insertions(+), 29 deletions(-)
diffs (299 lines):
diff -r e5c6f2bf75bb -r 0d22a767c67c sys/net/if.c
--- a/sys/net/if.c Thu Jun 16 02:54:41 2016 +0000
+++ b/sys/net/if.c Thu Jun 16 03:03:33 2016 +0000
@@ -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 @@
{
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")
diff -r e5c6f2bf75bb -r 0d22a767c67c sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c Thu Jun 16 02:54:41 2016 +0000
+++ b/sys/net/if_ethersubr.c Thu Jun 16 03:03:33 2016 +0000
@@ -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 @@
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 @@
written += sizeof(addr);
oldp = (char *)oldp + sizeof(addr);
}
+ if_put(ifp, &psref);
*oldlenp = written;
+out:
+ curlwp_bindx(bound);
return error;
}
diff -r e5c6f2bf75bb -r 0d22a767c67c sys/net/if_llatbl.c
--- a/sys/net/if_llatbl.c Thu Jun 16 02:54:41 2016 +0000
+++ b/sys/net/if_llatbl.c Thu Jun 16 03:03:33 2016 +0000
@@ -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 @@
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 @@
(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 @@
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 @@
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);
}
diff -r e5c6f2bf75bb -r 0d22a767c67c sys/net/npf/npf_ext_log.c
--- a/sys/net/npf/npf_ext_log.c Thu Jun 16 02:54:41 2016 +0000
+++ b/sys/net/npf/npf_ext_log.c Thu Jun 16 03:03:33 2016 +0000
@@ -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 @@
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 @@
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 @@
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;
diff -r e5c6f2bf75bb -r 0d22a767c67c sys/netinet6/mld6.c
--- a/sys/netinet6/mld6.c Thu Jun 16 02:54:41 2016 +0000
+++ b/sys/netinet6/mld6.c Thu Jun 16 03:03:33 2016 +0000
@@ -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 @@
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 @@
sizeof(uint32_t);
}
}
+ if_put(ifp, &psref);
+ curlwp_bindx(bound);
return 0;
}
@@ -1039,6 +1046,8 @@
}
}
done:
+ if_put(ifp, &psref);
+ curlwp_bindx(bound);
*oldlenp = written;
return error;
}
Home |
Main Index |
Thread Index |
Old Index