diff options
author | dlg <dlg@openbsd.org> | 2019-11-06 03:51:26 +0000 |
---|---|---|
committer | dlg <dlg@openbsd.org> | 2019-11-06 03:51:26 +0000 |
commit | 3fe9d1bd1154bd2f33ea9eb9c49bd45b08486a1a (patch) | |
tree | 14de69a116793ce1ffa47b2521e1bdbbd05e9e09 /sys/net/if_tpmr.c | |
parent | sync (diff) | |
download | wireguard-openbsd-3fe9d1bd1154bd2f33ea9eb9c49bd45b08486a1a.tar.xz wireguard-openbsd-3fe9d1bd1154bd2f33ea9eb9c49bd45b08486a1a.zip |
replace the hooks used with if_detachhooks with a task list.
the main semantic change is that things registering detach hooks
have to allocate and set a task structure that then gets added to
the list. this means if the task is allocated up front (eg, as part
of carps softc or bridges port structure), it avoids the possibility
that adding a hook can fail. a lot of drivers weren't checking for
failure, and unwinding state in the event of failure in other parts
was error prone.
while doing this i discovered that the list operations have to be
in a particular order, but drivers weren't doing that consistently
either. this diff wraps the list ops up so you have to seriously
go out of your way to screw them up.
ive also sprinkled some NET_ASSERT_LOCKED around the list operations
so we can make sure there's no potential for the list to be corrupted,
especially while it's being run.
hrvoje popovski has tested this a bit, and some issues he discovered
have been fixed.
ok sashan@
Diffstat (limited to 'sys/net/if_tpmr.c')
-rw-r--r-- | sys/net/if_tpmr.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sys/net/if_tpmr.c b/sys/net/if_tpmr.c index 6af11933c40..231e2e1968b 100644 --- a/sys/net/if_tpmr.c +++ b/sys/net/if_tpmr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tpmr.c,v 1.4 2019/09/12 02:02:54 dlg Exp $ */ +/* $OpenBSD: if_tpmr.c,v 1.5 2019/11/06 03:51:26 dlg Exp $ */ /* * Copyright (c) 2019 The University of Queensland @@ -87,7 +87,7 @@ struct tpmr_port { struct rtentry *); void *p_lcookie; - void *p_dcookie; + struct task p_dtask; struct tpmr_softc *p_tpmr; unsigned int p_slot; @@ -197,9 +197,6 @@ tpmr_clone_destroy(struct ifnet *ifp) if (ISSET(ifp->if_flags, IFF_RUNNING)) tpmr_down(sc); - NET_UNLOCK(); - - if_detach(ifp); for (i = 0; i < nitems(sc->sc_ports); i++) { struct tpmr_port *p = SMR_PTR_GET_LOCKED(&sc->sc_ports[i]); @@ -207,6 +204,9 @@ tpmr_clone_destroy(struct ifnet *ifp) continue; tpmr_p_dtor(sc, p, "destroy"); } + NET_UNLOCK(); + + if_detach(ifp); free(sc, M_DEVBUF, sizeof(*sc)); @@ -565,8 +565,8 @@ tpmr_add_port(struct tpmr_softc *sc, const struct trunk_reqport *rp) p->p_lcookie = hook_establish(ifp0->if_linkstatehooks, 1, tpmr_p_linkch, p); - p->p_dcookie = hook_establish(ifp0->if_detachhooks, 0, - tpmr_p_detach, p); + task_set(&p->p_dtask, tpmr_p_detach, p); + if_detachhook_add(ifp0, &p->p_dtask); /* commit */ DPRINTF(sc, "%s %s trunkport: creating port\n", @@ -724,7 +724,7 @@ tpmr_p_dtor(struct tpmr_softc *sc, struct tpmr_port *p, const char *op) ifp->if_xname, ifp0->if_xname); } - hook_disestablish(ifp0->if_detachhooks, p->p_dcookie); + if_detachhook_del(ifp0, &p->p_dtask); hook_disestablish(ifp0->if_linkstatehooks, p->p_lcookie); smr_barrier(); |