diff options
author | 2019-11-06 03:51:26 +0000 | |
---|---|---|
committer | 2019-11-06 03:51:26 +0000 | |
commit | 3fe9d1bd1154bd2f33ea9eb9c49bd45b08486a1a (patch) | |
tree | 14de69a116793ce1ffa47b2521e1bdbbd05e9e09 /sys/net/if_bpe.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_bpe.c')
-rw-r--r-- | sys/net/if_bpe.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/net/if_bpe.c b/sys/net/if_bpe.c index bc9553d98be..5ad9a41b684 100644 --- a/sys/net/if_bpe.c +++ b/sys/net/if_bpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bpe.c,v 1.8 2019/07/17 16:46:17 mpi Exp $ */ +/* $OpenBSD: if_bpe.c,v 1.9 2019/11/06 03:51:26 dlg Exp $ */ /* * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> * @@ -103,7 +103,7 @@ struct bpe_softc { uint8_t sc_group[ETHER_ADDR_LEN]; void * sc_lh_cookie; - void * sc_dh_cookie; + struct task sc_dtask; struct bpe_map sc_bridge_map; struct rwlock sc_bridge_lock; @@ -174,6 +174,8 @@ bpe_clone_create(struct if_clone *ifc, int unit) sc->sc_txhprio = IF_HDRPRIO_PACKET; sc->sc_rxhprio = IF_HDRPRIO_OUTER; + task_set(&sc->sc_dtask, bpe_detach_hook, sc); + rw_init(&sc->sc_bridge_lock, "bpebr"); RBT_INIT(bpe_map, &sc->sc_bridge_map); sc->sc_bridge_num = 0; @@ -636,8 +638,7 @@ bpe_up(struct bpe_softc *sc) bpe_link_hook, sc); /* Register callback if parent wants to unregister */ - sc->sc_dh_cookie = hook_establish(ifp0->if_detachhooks, 0, - bpe_detach_hook, sc); + if_detachhook_add(ifp0, &sc->sc_dtask); /* we're running now */ SET(ifp->if_flags, IFF_RUNNING); @@ -674,7 +675,7 @@ bpe_down(struct bpe_softc *sc) ifp0 = if_get(sc->sc_key.k_if); if (ifp0 != NULL) { - hook_disestablish(ifp0->if_detachhooks, sc->sc_dh_cookie); + if_detachhook_del(ifp0, &sc->sc_dtask); hook_disestablish(ifp0->if_linkstatehooks, sc->sc_lh_cookie); bpe_multi(sc, ifp0, SIOCDELMULTI); } |