summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2013-11-18 09:16:30 +0000
committermpi <mpi@openbsd.org>2013-11-18 09:16:30 +0000
commitdd83e934a89a96a35361a39d89a3a10791c1185b (patch)
tree842fa4af1db87f5d0e2c62cc9c56cfd025a99ce2
parentNormalize code sequence around dumpsys(), doshutdownhooks(), and (diff)
downloadwireguard-openbsd-dd83e934a89a96a35361a39d89a3a10791c1185b.tar.xz
wireguard-openbsd-dd83e934a89a96a35361a39d89a3a10791c1185b.zip
Convert trunk(4) to use a detachhook, discussed at b2k13 with many.
While here add a comment explaining detach hooks' order of execution when destroying/detaching an interface.
-rw-r--r--sys/net/if.c17
-rw-r--r--sys/net/if_trunk.c23
-rw-r--r--sys/net/if_trunk.h4
3 files changed, 20 insertions, 24 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 04f0b6d389d..5a4a7998733 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.275 2013/11/11 09:15:34 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.276 2013/11/18 09:16:30 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -118,10 +118,6 @@
#include <net/bpf.h>
#endif
-#if NTRUNK > 0
-#include <net/if_trunk.h>
-#endif
-
#if NBRIDGE > 0
#include <net/if_bridge.h>
#endif
@@ -511,14 +507,13 @@ if_detach(struct ifnet *ifp)
ifp->if_ioctl = if_detached_ioctl;
ifp->if_watchdog = if_detached_watchdog;
- /* Call detach hooks, ie. to remove vlan interfaces */
+ /*
+ * Call detach hooks from head to tail. To make sure detach
+ * hooks are executed in the reverse order they were added, all
+ * the hooks have to be added to the head!
+ */
dohooks(ifp->if_detachhooks, HOOK_REMOVE | HOOK_FREE);
-#if NTRUNK > 0
- if (ifp->if_type == IFT_IEEE8023ADLAG)
- trunk_port_ifdetach(ifp);
-#endif
-
#if NBRIDGE > 0
/* Remove the interface from any bridge it is part of. */
if (ifp->if_bridgeport)
diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c
index 8ef7749286b..f4bc2ccc492 100644
--- a/sys/net/if_trunk.c
+++ b/sys/net/if_trunk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_trunk.c,v 1.84 2013/06/20 12:03:40 mpi Exp $ */
+/* $OpenBSD: if_trunk.c,v 1.85 2013/11/18 09:16:30 mpi Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -70,6 +70,7 @@ int trunk_port_create(struct trunk_softc *, struct ifnet *);
int trunk_port_destroy(struct trunk_port *);
void trunk_port_watchdog(struct ifnet *);
void trunk_port_state(void *);
+void trunk_port_ifdetach(void *);
int trunk_port_ioctl(struct ifnet *, u_long, caddr_t);
struct trunk_port *trunk_port_get(struct trunk_softc *, struct ifnet *);
int trunk_port_checkstacking(struct trunk_softc *);
@@ -381,9 +382,12 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp)
trunk_ether_cmdmulti(tp, SIOCADDMULTI);
/* Register callback for physical link state changes */
- if (ifp->if_linkstatehooks != NULL)
- tp->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
- trunk_port_state, tp);
+ tp->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
+ trunk_port_state, tp);
+
+ /* Register callback if parent wants to unregister */
+ tp->dh_cookie = hook_establish(ifp->if_detachhooks, 0,
+ trunk_port_ifdetach, tp);
if (tr->tr_port_create != NULL)
error = (*tr->tr_port_create)(tp);
@@ -433,8 +437,8 @@ trunk_port_destroy(struct trunk_port *tp)
ifp->if_ioctl = tp->tp_ioctl;
ifp->if_tp = NULL;
- if (ifp->if_linkstatehooks != NULL)
- hook_disestablish(ifp->if_linkstatehooks, tp->lh_cookie);
+ hook_disestablish(ifp->if_linkstatehooks, tp->lh_cookie);
+ hook_disestablish(ifp->if_detachhooks, tp->dh_cookie);
/* Finally, remove the port from the trunk */
SLIST_REMOVE(&tr->tr_ports, tp, trunk_port, tp_entries);
@@ -544,12 +548,9 @@ trunk_port_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
void
-trunk_port_ifdetach(struct ifnet *ifp)
+trunk_port_ifdetach(void *arg)
{
- struct trunk_port *tp;
-
- if ((tp = (struct trunk_port *)ifp->if_tp) == NULL)
- return;
+ struct trunk_port *tp = (struct trunk_port *)arg;
trunk_port_destroy(tp);
}
diff --git a/sys/net/if_trunk.h b/sys/net/if_trunk.h
index 2d0763527ee..0a2a6b647a3 100644
--- a/sys/net/if_trunk.h
+++ b/sys/net/if_trunk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_trunk.h,v 1.17 2011/07/04 04:29:17 claudio Exp $ */
+/* $OpenBSD: if_trunk.h,v 1.18 2013/11/18 09:16:30 mpi Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -136,6 +136,7 @@ struct trunk_port {
u_int32_t tp_prio; /* port priority */
u_int32_t tp_flags; /* port flags */
void *lh_cookie; /* if state hook */
+ void *dh_cookie; /* if detach hook */
/* Redirected callbacks */
void (*tp_watchdog)(struct ifnet *);
@@ -219,7 +220,6 @@ struct trunk_lb {
struct trunk_port *lb_ports[TRUNK_MAX_PORTS];
};
-void trunk_port_ifdetach(struct ifnet *);
int trunk_input(struct ifnet *, struct ether_header *,
struct mbuf *);
int trunk_enqueue(struct ifnet *, struct mbuf *);