summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-28 09:35:14 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-28 09:35:14 +0000
commit72287614c427ec01dfccecc057a936574bb8933e (patch)
tree5311d0715e33e80e9c52cf7ce710df8d07fe2b2c
parentf7c42a4fb10d25eb74f7b8cb4ecb5fb680559931 (diff)
Protect the global array of interfaces with the NET_LOCK().
ok sashan@
-rw-r--r--sys/net/if_enc.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/sys/net/if_enc.c b/sys/net/if_enc.c
index 1f749fc3a16..a12ce47e2d1 100644
--- a/sys/net/if_enc.c
+++ b/sys/net/if_enc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_enc.c,v 1.67 2017/01/23 11:37:29 mpi Exp $ */
+/* $OpenBSD: if_enc.c,v 1.68 2017/05/28 09:35:13 mpi Exp $ */
/*
* Copyright (c) 2010 Reyk Floeter <reyk@vantronix.net>
@@ -72,7 +72,7 @@ enc_clone_create(struct if_clone *ifc, int unit)
struct ifnet *ifp;
struct ifnet **new;
size_t newlen;
- int error;
+ int s, error;
if (unit > ENC_MAX_UNITS)
return (EINVAL);
@@ -111,8 +111,10 @@ enc_clone_create(struct if_clone *ifc, int unit)
#if NBPFILTER > 0
bpfattach(&ifp->if_bpf, ifp, DLT_ENC, ENC_HDRLEN);
#endif
-
- if ((error = enc_setif(ifp, 0)) != 0) {
+ NET_LOCK(s);
+ error = enc_setif(ifp, 0);
+ if (error != 0) {
+ NET_UNLOCK(s);
if_detach(ifp);
free(sc, M_DEVBUF, 0);
return (error);
@@ -120,8 +122,10 @@ enc_clone_create(struct if_clone *ifc, int unit)
if (unit == 0 || unit > enc_max_unit) {
if ((new = mallocarray(unit + 1, sizeof(struct ifnet *),
- M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
+ M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) {
+ NET_UNLOCK(s);
return (ENOBUFS);
+ }
newlen = sizeof(struct ifnet *) * (unit + 1);
if (enc_allifps != NULL) {
@@ -133,6 +137,7 @@ enc_clone_create(struct if_clone *ifc, int unit)
enc_max_unit = unit;
}
enc_allifps[unit] = ifp;
+ NET_UNLOCK(s);
return (0);
}
@@ -147,12 +152,13 @@ enc_clone_destroy(struct ifnet *ifp)
if (sc->sc_unit == 0)
return (EPERM);
- s = splnet();
+ NET_LOCK(s);
enc_allifps[sc->sc_unit] = NULL;
enc_unsetif(ifp);
+ NET_UNLOCK(s);
+
if_detach(ifp);
free(sc, M_DEVBUF, 0);
- splx(s);
return (0);
}
@@ -229,8 +235,8 @@ enc_getif(u_int id, u_int unit)
return (enc_ifps[id]);
}
-struct ifaddr
-*enc_getifa(u_int id, u_int unit)
+struct ifaddr *
+enc_getifa(u_int id, u_int unit)
{
struct ifnet *ifp;
struct enc_softc *sc;
@@ -248,6 +254,8 @@ enc_setif(struct ifnet *ifp, u_int id)
struct ifnet **new;
size_t newlen;
+ NET_ASSERT_LOCKED();
+
enc_unsetif(ifp);
/*