diff options
author | 2016-10-07 08:18:22 +0000 | |
---|---|---|
committer | 2016-10-07 08:18:22 +0000 | |
commit | be4a9ca0e76593daa1fc0d7c29e69bfb0042a3b9 (patch) | |
tree | 07678cfdea4e51a7b97bf2b5bcaba6deff7c9f78 | |
parent | Extra parentheses in conditional; no binary change. (diff) | |
download | wireguard-openbsd-be4a9ca0e76593daa1fc0d7c29e69bfb0042a3b9.tar.xz wireguard-openbsd-be4a9ca0e76593daa1fc0d7c29e69bfb0042a3b9.zip |
Use detach hook to notify switch(4) about interface removals instead of
adding code to if.c.
ok mpi@
-rw-r--r-- | sys/net/if.c | 11 | ||||
-rw-r--r-- | sys/net/if_switch.c | 22 | ||||
-rw-r--r-- | sys/net/if_switch.h | 4 |
3 files changed, 13 insertions, 24 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index af73a2ab106..cb88ef910ba 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.452 2016/10/03 12:26:13 rzalamena Exp $ */ +/* $OpenBSD: if.c,v 1.453 2016/10/07 08:18:22 rzalamena Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -130,10 +130,6 @@ #include <net/pfvar.h> #endif -#if NSWITCH > 0 -#include <net/if_switch.h> -#endif - void if_attachsetup(struct ifnet *); void if_attachdomain(struct ifnet *); void if_attach_common(struct ifnet *); @@ -895,11 +891,6 @@ if_deactivate(struct ifnet *ifp) */ dohooks(ifp->if_detachhooks, HOOK_REMOVE | HOOK_FREE); -#if NSWITCH > 0 - if (ifp->if_switchport) - switch_port_detach(ifp); -#endif - #if NCARP > 0 /* Remove the interface from any carp group it is a part of. */ if (ifp->if_carp && ifp->if_type != IFT_CARP) diff --git a/sys/net/if_switch.c b/sys/net/if_switch.c index 3b6d6907e99..7eeb4d8bff3 100644 --- a/sys/net/if_switch.c +++ b/sys/net/if_switch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_switch.c,v 1.7 2016/09/29 11:37:44 reyk Exp $ */ +/* $OpenBSD: if_switch.c,v 1.8 2016/10/07 08:18:22 rzalamena Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -74,6 +74,7 @@ int switch_port_set_local(struct switch_softc *, struct switch_port *); int switch_port_unset_local(struct switch_softc *, struct switch_port *); int switch_ioctl(struct ifnet *, unsigned long, caddr_t); int switch_port_add(struct switch_softc *, struct ifbreq *); +void switch_port_detach(void *); int switch_port_del(struct switch_softc *, struct ifbreq *); int switch_port_list(struct switch_softc *, struct ifbifconf *); int switch_output(struct ifnet *, struct mbuf *, struct sockaddr *, @@ -215,16 +216,9 @@ switch_clone_destroy(struct ifnet *ifp) struct ifnet *ifs; TAILQ_FOREACH_SAFE(swpo, &sc->sc_swpo_list, swpo_list_next, tp) { - if ((ifs = if_get(swpo->swpo_ifindex)) != NULL) { - if (swpo->swpo_flags & IFBIF_LOCAL) - switch_port_unset_local(sc, swpo); - ifs->if_switchport = NULL; - ifpromisc(ifs, 0); - if_ih_remove(ifs, switch_input, NULL); - if_put(ifs); - TAILQ_REMOVE(&sc->sc_swpo_list, swpo, swpo_list_next); - free(swpo, M_DEVBUF, sizeof(*swpo)); - } else + if ((ifs = if_get(swpo->swpo_ifindex)) != NULL) + switch_port_detach(ifs); + else log(LOG_ERR, "failed to cleanup on ifindex(%d)\n", swpo->swpo_ifindex); } @@ -576,6 +570,8 @@ switch_port_add(struct switch_softc *sc, struct ifbreq *req) ifs->if_switchport = (caddr_t)swpo; if_ih_insert(ifs, switch_input, NULL); swpo->swpo_port_no = swofp_assign_portno(sc, ifs->if_index); + swpo->swpo_dhcookie = hook_establish(ifs->if_detachhooks, 0, + switch_port_detach, ifs); nanouptime(&swpo->swpo_appended); @@ -630,8 +626,9 @@ done: } void -switch_port_detach(struct ifnet *ifp) +switch_port_detach(void *arg) { + struct ifnet *ifp = (struct ifnet *)arg; struct switch_softc *sc = ifp->if_softc; struct switch_port *swpo; @@ -640,6 +637,7 @@ switch_port_detach(struct ifnet *ifp) switch_port_unset_local(sc, swpo); ifp->if_switchport = NULL; + hook_disestablish(ifp->if_detachhooks, swpo->swpo_dhcookie); ifpromisc(ifp, 0); if_ih_remove(ifp, switch_input, NULL); TAILQ_REMOVE(&sc->sc_swpo_list, swpo, swpo_list_next); diff --git a/sys/net/if_switch.h b/sys/net/if_switch.h index cb5a9f35b09..ff50da864ca 100644 --- a/sys/net/if_switch.h +++ b/sys/net/if_switch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_switch.h,v 1.3 2016/09/28 08:31:42 rzalamena Exp $ */ +/* $OpenBSD: if_switch.h,v 1.4 2016/10/07 08:18:22 rzalamena Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -174,6 +174,7 @@ struct switch_port { struct timespec swpo_appended; struct switch_softc *swpo_switch; uint32_t swpo_flags; + void *swpo_dhcookie; void (*swop_bk_start)(struct ifnet *); }; @@ -215,7 +216,6 @@ void switch_port_egress(struct switch_softc *, struct switch_fwdp_queue *, int switch_swfcl_dup(struct switch_flow_classify *, struct switch_flow_classify *); void switch_swfcl_free(struct switch_flow_classify *); -void switch_port_detach(struct ifnet *); /* switchctl.c */ void switch_dev_destroy(struct switch_softc *); |