summaryrefslogtreecommitdiffstats
path: root/sys/net/if.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2019-11-07 07:36:31 +0000
committerdlg <dlg@openbsd.org>2019-11-07 07:36:31 +0000
commit4f5e51a4e9a138283295ab8b7f236f90bf0f58ce (patch)
treee8f67f65e4d04bf88cb83ad12c28409ae28f84d8 /sys/net/if.c
parentAdd -F flag to send-keys to expand formats in search-backward and (diff)
downloadwireguard-openbsd-4f5e51a4e9a138283295ab8b7f236f90bf0f58ce.tar.xz
wireguard-openbsd-4f5e51a4e9a138283295ab8b7f236f90bf0f58ce.zip
turn the linkstate hooks into a task list, like the detach hooks.
this is largely mechanical, except for carp. this moves the addition of the carp link state hook after we're committed to using the new interface as a carpdev. because the add can't fail, we avoid a complicated unwind dance. also, this tweaks the carp linkstate hook so it only updates the relevant carp interface, not all of the carpdevs on the parent. hrvoje popovski has tested an early version of this diff and it's generally ok, but there's some splasserts that this diff fires that i'll fix in an upcoming diff. ok claudio@
Diffstat (limited to 'sys/net/if.c')
-rw-r--r--sys/net/if.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 0f3e07a53d8..0c96e305224 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.589 2019/11/06 03:51:26 dlg Exp $ */
+/* $OpenBSD: if.c,v 1.590 2019/11/07 07:36:31 dlg Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -629,9 +629,7 @@ if_attach_common(struct ifnet *ifp)
ifp->if_addrhooks = malloc(sizeof(*ifp->if_addrhooks),
M_TEMP, M_WAITOK);
TAILQ_INIT(ifp->if_addrhooks);
- ifp->if_linkstatehooks = malloc(sizeof(*ifp->if_linkstatehooks),
- M_TEMP, M_WAITOK);
- TAILQ_INIT(ifp->if_linkstatehooks);
+ TAILQ_INIT(&ifp->if_linkstatehooks);
TAILQ_INIT(&ifp->if_detachhooks);
if (ifp->if_rtrequest == NULL)
@@ -1055,8 +1053,6 @@ if_deactivate(struct ifnet *ifp)
NET_LOCK();
TAILQ_FOREACH_SAFE(t, &ifp->if_detachhooks, t_entry, nt)
(*t->t_func)(t->t_arg);
-
- KASSERT(TAILQ_EMPTY(&ifp->if_detachhooks));
NET_UNLOCK();
}
@@ -1148,7 +1144,8 @@ if_detach(struct ifnet *ifp)
}
free(ifp->if_addrhooks, M_TEMP, sizeof(*ifp->if_addrhooks));
- free(ifp->if_linkstatehooks, M_TEMP, sizeof(*ifp->if_linkstatehooks));
+ KASSERT(TAILQ_EMPTY(&ifp->if_linkstatehooks));
+ KASSERT(TAILQ_EMPTY(&ifp->if_detachhooks));
for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
@@ -1646,11 +1643,29 @@ if_linkstate_task(void *xifidx)
void
if_linkstate(struct ifnet *ifp)
{
+ struct task *t, *nt;
+
NET_ASSERT_LOCKED();
rtm_ifchg(ifp);
rt_if_track(ifp);
- dohooks(ifp->if_linkstatehooks, 0);
+
+ TAILQ_FOREACH_SAFE(t, &ifp->if_linkstatehooks, t_entry, nt)
+ (*t->t_func)(t->t_arg);
+}
+
+void
+if_linkstatehook_add(struct ifnet *ifp, struct task *t)
+{
+ NET_ASSERT_LOCKED();
+ TAILQ_INSERT_TAIL(&ifp->if_linkstatehooks, t, t_entry);
+}
+
+void
+if_linkstatehook_del(struct ifnet *ifp, struct task *t)
+{
+ NET_ASSERT_LOCKED();
+ TAILQ_REMOVE(&ifp->if_linkstatehooks, t, t_entry);
}
/*