summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2006-05-16 20:23:11 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2006-05-16 20:23:11 +0000
commit70e152fda5425c460811ab2bdc909d8b157858d8 (patch)
tree1c3f6e95d0a741e89e70cfd7a4124e87abeb139a /sys
parentf029b18f4a0920d3d7f0f9dfbdd86bb219fd6718 (diff)
the ifp->if_linkstatehooks may be NULL, add an extra check to avoid
possible kernel panic. this happened to me by using tun(4) in layer 2 mode (link0 flag) as a trunk port for testing.
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_trunk.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c
index 3b6c97e6106..a5e4f27e463 100644
--- a/sys/net/if_trunk.c
+++ b/sys/net/if_trunk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_trunk.c,v 1.23 2006/03/25 22:41:47 djm Exp $ */
+/* $OpenBSD: if_trunk.c,v 1.24 2006/05/16 20:23:10 reyk Exp $ */
/*
* Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org>
@@ -346,8 +346,9 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp)
trunk_ether_cmdmulti(tp, SIOCADDMULTI);
/* Register callback for physical link state changes */
- tp->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
- trunk_port_state, tp);
+ if (ifp->if_linkstatehooks != NULL)
+ tp->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
+ trunk_port_state, tp);
if (tr->tr_port_create != NULL)
error = (*tr->tr_port_create)(tp);
@@ -397,7 +398,8 @@ trunk_port_destroy(struct trunk_port *tp)
ifp->if_ioctl = tp->tp_ioctl;
ifp->if_tp = NULL;
- hook_disestablish(ifp->if_linkstatehooks, tp->lh_cookie);
+ if (ifp->if_linkstatehooks != NULL)
+ hook_disestablish(ifp->if_linkstatehooks, tp->lh_cookie);
/* Finally, remove the port from the trunk */
SLIST_REMOVE(&tr->tr_ports, tp, trunk_port, tp_entries);