diff options
author | sashan <sashan@openbsd.org> | 2018-09-10 16:18:34 +0000 |
---|---|---|
committer | sashan <sashan@openbsd.org> | 2018-09-10 16:18:34 +0000 |
commit | 872527097680c6cf1b32ba9c5f884d29604e6659 (patch) | |
tree | 5fb6e1b963d2c04d8bb9031bb9f2096e479721ed /sys/net/if.c | |
parent | Introduce copy_satopfaddr() (diff) | |
download | wireguard-openbsd-872527097680c6cf1b32ba9c5f884d29604e6659.tar.xz wireguard-openbsd-872527097680c6cf1b32ba9c5f884d29604e6659.zip |
- if_cloners list populated at boot time only then becomes immutable,
so we can let go if_cloners_lock.
OK tb@, claudio@, bluhm@, kn@, henning@
Diffstat (limited to 'sys/net/if.c')
-rw-r--r-- | sys/net/if.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index f4978c1112d..0e0c767cc3b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.562 2018/09/10 16:07:20 henning Exp $ */ +/* $OpenBSD: if.c,v 1.563 2018/09/10 16:18:34 sashan Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -129,6 +129,8 @@ #include <net/pfvar.h> #endif +#include <sys/device.h> + void if_attachsetup(struct ifnet *); void if_attachdomain(struct ifnet *); void if_attach_common(struct ifnet *); @@ -220,8 +222,6 @@ void if_idxmap_remove(struct ifnet *); TAILQ_HEAD(, ifg_group) ifg_head = TAILQ_HEAD_INITIALIZER(ifg_head); -/* Serialize access to &if_cloners and if_cloners_count */ -struct rwlock if_cloners_lock = RWLOCK_INITIALIZER("ifclonerslk"); LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners); int if_cloners_count; @@ -1253,13 +1253,11 @@ if_clone_lookup(const char *name, int *unitp) if (cp - name < IFNAMSIZ-1 && *cp == '0' && cp[1] != '\0') return (NULL); /* unit number 0 padded */ - rw_enter_read(&if_cloners_lock); LIST_FOREACH(ifc, &if_cloners, ifc_list) { if (strlen(ifc->ifc_name) == cp - name && !strncmp(name, ifc->ifc_name, cp - name)) break; } - rw_exit_read(&if_cloners_lock); if (ifc == NULL) return (NULL); @@ -1285,22 +1283,15 @@ if_clone_lookup(const char *name, int *unitp) void if_clone_attach(struct if_clone *ifc) { - rw_enter_write(&if_cloners_lock); + /* + * we are called at kernel boot by main(), when pseudo devices are + * being attached. The main() is the only guy which may alter the + * if_cloners. While system is running and main() is done with + * initialization, the if_cloners becomes immutable. + */ + KASSERT(pdevinit_done == 0); LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); if_cloners_count++; - rw_exit_write(&if_cloners_lock); -} - -/* - * Unregister a network interface cloner. - */ -void -if_clone_detach(struct if_clone *ifc) -{ - rw_enter_write(&if_cloners_lock); - LIST_REMOVE(ifc, ifc_list); - if_cloners_count--; - rw_exit_write(&if_cloners_lock); } /* @@ -1315,17 +1306,13 @@ if_clone_list(struct if_clonereq *ifcr) if ((dst = ifcr->ifcr_buffer) == NULL) { /* Just asking how many there are. */ - rw_enter_read(&if_cloners_lock); ifcr->ifcr_total = if_cloners_count; - rw_exit_read(&if_cloners_lock); return (0); } if (ifcr->ifcr_count < 0) return (EINVAL); - rw_enter_read(&if_cloners_lock); - ifcr->ifcr_total = if_cloners_count; count = MIN(if_cloners_count, ifcr->ifcr_count); @@ -1341,7 +1328,6 @@ if_clone_list(struct if_clonereq *ifcr) dst += IFNAMSIZ; } - rw_exit_read(&if_cloners_lock); return (error); } |