diff options
author | 2005-04-20 23:00:40 +0000 | |
---|---|---|
committer | 2005-04-20 23:00:40 +0000 | |
commit | f67c2b7131eea7164a7eea33b01ffe6155c10695 (patch) | |
tree | dc16f690a301232e270e01a550d60edbdb65edd2 | |
parent | fix buffer overrun introduced with my previous commit. Found and fixed by (diff) | |
download | wireguard-openbsd-f67c2b7131eea7164a7eea33b01ffe6155c10695.tar.xz wireguard-openbsd-f67c2b7131eea7164a7eea33b01ffe6155c10695.zip |
Introduce if_linkstatehooks.
This converts if_link_state_change() to a generic usable
callback with dohooks().
OK henning@, camield@
Tested by camield@ and Alexey E. Suslikov
-rw-r--r-- | sys/net/if.c | 19 | ||||
-rw-r--r-- | sys/net/if.h | 3 | ||||
-rw-r--r-- | sys/netinet/ip_carp.c | 11 | ||||
-rw-r--r-- | sys/netinet/ip_carp.h | 4 |
4 files changed, 25 insertions, 12 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index d2b0eb1bed7..ffaed85044a 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.106 2005/04/05 12:19:37 claudio Exp $ */ +/* $OpenBSD: if.c,v 1.107 2005/04/20 23:00:41 mpf Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -400,6 +400,11 @@ if_attachhead(ifp) if (ifp->if_addrhooks == NULL) panic("if_attachhead: malloc"); TAILQ_INIT(ifp->if_addrhooks); + ifp->if_linkstatehooks = malloc(sizeof(*ifp->if_linkstatehooks), + M_TEMP, M_NOWAIT); + if (ifp->if_linkstatehooks == NULL) + panic("if_attachhead: malloc"); + TAILQ_INIT(ifp->if_linkstatehooks); TAILQ_INSERT_HEAD(&ifnet, ifp, if_list); if_attachsetup(ifp); } @@ -422,6 +427,11 @@ if_attach(ifp) if (ifp->if_addrhooks == NULL) panic("if_attach: malloc"); TAILQ_INIT(ifp->if_addrhooks); + ifp->if_linkstatehooks = malloc(sizeof(*ifp->if_linkstatehooks), + M_TEMP, M_NOWAIT); + if (ifp->if_linkstatehooks == NULL) + panic("if_attach: malloc"); + TAILQ_INIT(ifp->if_linkstatehooks); #if NCARP > 0 if (ifp->if_type != IFT_CARP) @@ -625,6 +635,7 @@ do { \ ifnet_addrs[ifp->if_index] = NULL; free(ifp->if_addrhooks, M_TEMP); + free(ifp->if_linkstatehooks, M_TEMP); for (dp = domains; dp; dp = dp->dom_next) { if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family]) @@ -1107,16 +1118,12 @@ if_up(struct ifnet *ifp) /* * Process a link state change. * NOTE: must be called at splsoftnet or equivalent. - * XXX Should be converted to dohooks(). */ void if_link_state_change(struct ifnet *ifp) { rt_ifmsg(ifp); -#if NCARP > 0 - if (ifp->if_carp) - carp_carpdev_state(ifp); -#endif + dohooks(ifp->if_linkstatehooks, 0); } /* diff --git a/sys/net/if.h b/sys/net/if.h index 31df9263080..ef402f7a1fb 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if.h,v 1.64 2005/02/07 15:00:17 mcbride Exp $ */ +/* $OpenBSD: if.h,v 1.65 2005/04/20 23:00:40 mpf Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -176,6 +176,7 @@ struct ifnet { /* and the entries */ TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */ TAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if */ struct hook_desc_head *if_addrhooks; /* address change callbacks */ + struct hook_desc_head *if_linkstatehooks; /* link change callbacks */ char if_xname[IFNAMSIZ]; /* external name (name + unit) */ int if_pcount; /* number of promiscuous listeners */ caddr_t if_bpf; /* packet filter structure */ diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index e58d8b9793a..5690fc2e8ae 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.104 2005/03/15 15:51:27 mcbride Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.105 2005/04/20 23:00:41 mpf Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -106,6 +106,7 @@ struct carp_softc { #define sc_if sc_ac.ac_if #define sc_carpdev sc_ac.ac_if.if_carpdev void *ah_cookie; + void *lh_cookie; struct ip_moptions sc_imo; #ifdef INET6 struct ip6_moptions sc_im6o; @@ -774,6 +775,8 @@ carpdetach(struct carp_softc *sc) carp_multicast_cleanup(sc); if (sc->sc_carpdev != NULL) { + hook_disestablish(sc->sc_carpdev->if_linkstatehooks, + sc->lh_cookie); cif = (struct carp_if *)sc->sc_carpdev->if_carp; TAILQ_REMOVE(&cif->vhif_vrs, sc, sc_list); if (!--cif->vhif_nvrs) { @@ -1482,13 +1485,14 @@ carp_set_ifp(struct carp_softc *sc, struct ifnet *ifp) if (sc->sc_naddrs || sc->sc_naddrs6) sc->sc_if.if_flags |= IFF_UP; carp_set_enaddr(sc); + sc->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1, + carp_carpdev_state, ifp); carp_carpdev_state(ifp); } else { carpdetach(sc); sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING); } return (0); - } void @@ -1986,10 +1990,11 @@ carp_set_state(struct carp_softc *sc, int state) } void -carp_carpdev_state(struct ifnet *ifp) +carp_carpdev_state(void *v) { struct carp_if *cif; struct carp_softc *sc; + struct ifnet *ifp = v; if (ifp->if_type == IFT_CARP) return; diff --git a/sys/netinet/ip_carp.h b/sys/netinet/ip_carp.h index 8bd44c73d27..a16981fec41 100644 --- a/sys/netinet/ip_carp.h +++ b/sys/netinet/ip_carp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.h,v 1.17 2005/03/01 19:04:56 mcbride Exp $ */ +/* $OpenBSD: ip_carp.h,v 1.18 2005/04/20 23:00:41 mpf Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -154,7 +154,7 @@ struct carpreq { #ifdef _KERNEL void carp_ifdetach (struct ifnet *); void carp_proto_input (struct mbuf *, ...); -void carp_carpdev_state(struct ifnet *); +void carp_carpdev_state(void *); int carp6_proto_input(struct mbuf **, int *, int); int carp_iamatch(struct in_ifaddr *, u_char *, u_int32_t *, u_int32_t); |