diff options
author | 2015-09-10 16:41:30 +0000 | |
---|---|---|
committer | 2015-09-10 16:41:30 +0000 | |
commit | 651987cba2f5dacbfe3b4fe61bbfb9cbe9fd08cb (patch) | |
tree | 9569df38d4383b64e624d7f8063069709cacc8fe | |
parent | Kill in6_ifstat_inc() and associated per-ifp storage. (diff) | |
download | wireguard-openbsd-651987cba2f5dacbfe3b4fe61bbfb9cbe9fd08cb.tar.xz wireguard-openbsd-651987cba2f5dacbfe3b4fe61bbfb9cbe9fd08cb.zip |
pass a cookie argument to interface input handlers that can be used
to pass additional context or transient data with the similar life
time.
ok mpi, suggestions, hand holding and ok from dlg
-rw-r--r-- | sys/net/if.c | 19 | ||||
-rw-r--r-- | sys/net/if_bridge.c | 6 | ||||
-rw-r--r-- | sys/net/if_ethersubr.c | 8 | ||||
-rw-r--r-- | sys/net/if_mpw.c | 10 | ||||
-rw-r--r-- | sys/net/if_trunk.c | 10 | ||||
-rw-r--r-- | sys/net/if_var.h | 10 | ||||
-rw-r--r-- | sys/net/if_vlan.c | 12 | ||||
-rw-r--r-- | sys/netinet/ip_carp.c | 10 |
8 files changed, 46 insertions, 39 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index a295811fc33..9ca0a6fc8cb 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.367 2015/09/10 14:06:43 dlg Exp $ */ +/* $OpenBSD: if.c,v 1.368 2015/09/10 16:41:30 mikeb Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -488,7 +488,9 @@ if_input(struct ifnet *ifp, struct mbuf_list *ml) struct ifih { struct srpl_entry ifih_next; - int (*ifih_input)(struct ifnet *, struct mbuf *); + int (*ifih_input)(struct ifnet *, struct mbuf *, + void *); + void *ifih_cookie; int ifih_refcnt; int ifih_srpcnt; }; @@ -499,7 +501,8 @@ void if_ih_unref(void *, void *); struct srpl_rc ifih_rc = SRPL_RC_INITIALIZER(if_ih_ref, if_ih_unref, NULL); void -if_ih_insert(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *)) +if_ih_insert(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *, + void *), void *cookie) { struct ifih *ifih; @@ -507,7 +510,7 @@ if_ih_insert(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *)) KERNEL_ASSERT_LOCKED(); SRPL_FOREACH_LOCKED(ifih, &ifp->if_inputs, ifih_next) { - if (ifih->ifih_input == input) { + if (ifih->ifih_input == input && ifih->ifih_cookie == cookie) { ifih->ifih_refcnt++; break; } @@ -517,6 +520,7 @@ if_ih_insert(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *)) ifih = malloc(sizeof(*ifih), M_DEVBUF, M_WAITOK); ifih->ifih_input = input; + ifih->ifih_cookie = cookie; ifih->ifih_refcnt = 1; ifih->ifih_srpcnt = 0; SRPL_INSERT_HEAD_LOCKED(&ifih_rc, &ifp->if_inputs, @@ -542,7 +546,8 @@ if_ih_unref(void *null, void *i) } void -if_ih_remove(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *)) +if_ih_remove(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *, + void *), void *cookie) { struct sleep_state sls; struct ifih *ifih; @@ -552,7 +557,7 @@ if_ih_remove(struct ifnet *ifp, int (*input)(struct ifnet *, struct mbuf *)) KERNEL_ASSERT_LOCKED(); SRPL_FOREACH_LOCKED(ifih, &ifp->if_inputs, ifih_next) { - if (ifih->ifih_input == input) + if (ifih->ifih_input == input && ifih->ifih_cookie == cookie) break; } @@ -617,7 +622,7 @@ if_input_process(void *xmq) * interface until it is consumed. */ SRPL_FOREACH(ifih, &ifp->if_inputs, &i, ifih_next) { - if ((*ifih->ifih_input)(ifp, m)) + if ((*ifih->ifih_input)(ifp, m, ifih->ifih_cookie)) break; } SRPL_LEAVE(&i, ifih); diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 2937b027c28..b97b8de197b 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.263 2015/09/10 15:27:00 mpi Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.264 2015/09/10 16:41:30 mikeb Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -223,7 +223,7 @@ bridge_clone_create(struct if_clone *ifc, int unit) DLT_EN10MB, ETHER_HDR_LEN); #endif - if_ih_insert(ifp, ether_input); + if_ih_insert(ifp, ether_input, NULL); return (0); } @@ -248,7 +248,7 @@ bridge_clone_destroy(struct ifnet *ifp) /* Undo pseudo-driver changes. */ if_deactivate(ifp); - if_ih_remove(ifp, ether_input); + if_ih_remove(ifp, ether_input, NULL); KASSERT(SRPL_EMPTY_LOCKED(&ifp->if_inputs)); diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index eee6da9a2af..d824a7cf706 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.222 2015/09/10 13:32:19 dlg Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.223 2015/09/10 16:41:30 mikeb Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -284,7 +284,7 @@ bad: * the ether header, which is provided separately. */ int -ether_input(struct ifnet *ifp, struct mbuf *m) +ether_input(struct ifnet *ifp, struct mbuf *m, void *cookie) { struct ether_header *eh; struct niqueue *inq; @@ -506,7 +506,7 @@ ether_ifattach(struct ifnet *ifp) ifp->if_mtu = ETHERMTU; ifp->if_output = ether_output; - if_ih_insert(ifp, ether_input); + if_ih_insert(ifp, ether_input, NULL); if (ifp->if_hardmtu == 0) ifp->if_hardmtu = ETHERMTU; @@ -528,7 +528,7 @@ ether_ifdetach(struct ifnet *ifp) /* Undo pseudo-driver changes. */ if_deactivate(ifp); - if_ih_remove(ifp, ether_input); + if_ih_remove(ifp, ether_input, NULL); KASSERT(SRPL_EMPTY_LOCKED(&ifp->if_inputs)); diff --git a/sys/net/if_mpw.c b/sys/net/if_mpw.c index b6fe8e6b9cc..d8c5e1b4004 100644 --- a/sys/net/if_mpw.c +++ b/sys/net/if_mpw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_mpw.c,v 1.4 2015/09/10 13:32:19 dlg Exp $ */ +/* $OpenBSD: if_mpw.c,v 1.5 2015/09/10 16:41:30 mikeb Exp $ */ /* * Copyright (c) 2015 Rafael Zalamena <rzalamena@openbsd.org> @@ -62,7 +62,7 @@ int mpw_ioctl(struct ifnet *, u_long, caddr_t); int mpw_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); void mpw_start(struct ifnet *); -int mpw_input(struct ifnet *, struct mbuf *); +int mpw_input(struct ifnet *, struct mbuf *, void *); #if NVLAN > 0 struct mbuf *mpw_vlan_handle(struct mbuf *, struct mpw_softc *); #endif /* NVLAN */ @@ -109,7 +109,7 @@ mpw_clone_create(struct if_clone *ifc, int unit) sc->sc_smpls.smpls_len = sizeof(sc->sc_smpls); sc->sc_smpls.smpls_family = AF_MPLS; - if_ih_insert(ifp, mpw_input); + if_ih_insert(ifp, mpw_input, NULL); #if NBPFILTER > 0 bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, ETHER_HDR_LEN); @@ -133,7 +133,7 @@ mpw_clone_destroy(struct ifnet *ifp) splx(s); } - if_ih_remove(ifp, mpw_input); + if_ih_remove(ifp, mpw_input, NULL); if_detach(ifp); free(sc, M_DEVBUF, sizeof(*sc)); @@ -142,7 +142,7 @@ mpw_clone_destroy(struct ifnet *ifp) } int -mpw_input(struct ifnet *ifp, struct mbuf *m) +mpw_input(struct ifnet *ifp, struct mbuf *m, void *cookie) { /* Don't have local broadcast. */ m_freem(m); diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c index b55843328d8..c5f981599b7 100644 --- a/sys/net/if_trunk.c +++ b/sys/net/if_trunk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_trunk.c,v 1.110 2015/09/10 13:32:19 dlg Exp $ */ +/* $OpenBSD: if_trunk.c,v 1.111 2015/09/10 16:41:30 mikeb Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -75,7 +75,7 @@ int trunk_ether_delmulti(struct trunk_softc *, struct ifreq *); void trunk_ether_purgemulti(struct trunk_softc *); int trunk_ether_cmdmulti(struct trunk_port *, u_long); int trunk_ioctl_allports(struct trunk_softc *, u_long, caddr_t); -int trunk_input(struct ifnet *, struct mbuf *); +int trunk_input(struct ifnet *, struct mbuf *, void *); void trunk_start(struct ifnet *); void trunk_init(struct ifnet *); void trunk_stop(struct ifnet *); @@ -344,7 +344,7 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp) ifp->if_type = IFT_IEEE8023ADLAG; /* Change input handler of the physical interface. */ - if_ih_insert(ifp, trunk_input); + if_ih_insert(ifp, trunk_input, NULL); ifp->if_tp = (caddr_t)tp; tp->tp_ioctl = ifp->if_ioctl; @@ -437,7 +437,7 @@ trunk_port_destroy(struct trunk_port *tp) ifp->if_type = tp->tp_iftype; /* Restore previous input handler. */ - if_ih_remove(ifp, trunk_input); + if_ih_remove(ifp, trunk_input, NULL); ifp->if_watchdog = tp->tp_watchdog; ifp->if_ioctl = tp->tp_ioctl; @@ -1079,7 +1079,7 @@ trunk_watchdog(struct ifnet *ifp) } int -trunk_input(struct ifnet *ifp, struct mbuf *m) +trunk_input(struct ifnet *ifp, struct mbuf *m, void *cookie) { struct trunk_softc *tr; struct trunk_port *tp; diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 3ff0a9012fd..f2e10d6f050 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.37 2015/09/10 14:56:41 dlg Exp $ */ +/* $OpenBSD: if_var.h,v 1.38 2015/09/10 16:41:30 mikeb Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -409,7 +409,7 @@ void if_input(struct ifnet *, struct mbuf_list *); void ether_ifattach(struct ifnet *); void ether_ifdetach(struct ifnet *); int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t); -int ether_input(struct ifnet *, struct mbuf *); +int ether_input(struct ifnet *, struct mbuf *, void *); int ether_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); char *ether_sprintf(u_char *); @@ -441,8 +441,10 @@ void ifa_del(struct ifnet *, struct ifaddr *); void ifa_update_broadaddr(struct ifnet *, struct ifaddr *, struct sockaddr *); -void if_ih_insert(struct ifnet *, int (*)(struct ifnet *, struct mbuf *)); -void if_ih_remove(struct ifnet *, int (*)(struct ifnet *, struct mbuf *)); +void if_ih_insert(struct ifnet *, int (*)(struct ifnet *, struct mbuf *, + void *), void *); +void if_ih_remove(struct ifnet *, int (*)(struct ifnet *, struct mbuf *, + void *), void *); void if_rxr_init(struct if_rxring *, u_int, u_int); u_int if_rxr_get(struct if_rxring *, u_int); diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 4329bf0c0f6..b83c14f85c1 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vlan.c,v 1.136 2015/09/10 13:32:19 dlg Exp $ */ +/* $OpenBSD: if_vlan.c,v 1.137 2015/09/10 16:41:30 mikeb Exp $ */ /* * Copyright 1998 Massachusetts Institute of Technology @@ -79,7 +79,7 @@ u_long vlan_tagmask, svlan_tagmask; LIST_HEAD(vlan_taghash, ifvlan) *vlan_tagh, *svlan_tagh; -int vlan_input(struct ifnet *, struct mbuf *); +int vlan_input(struct ifnet *, struct mbuf *, void *); void vlan_start(struct ifnet *ifp); int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr); int vlan_unconfig(struct ifnet *ifp, struct ifnet *newp); @@ -255,7 +255,7 @@ vlan_start(struct ifnet *ifp) * vlan_input() returns 1 if it has consumed the packet, 0 otherwise. */ int -vlan_input(struct ifnet *ifp, struct mbuf *m) +vlan_input(struct ifnet *ifp, struct mbuf *m, void *cookie) { struct ifvlan *ifv; struct ether_vlan_header *evl; @@ -429,7 +429,7 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag) splx(s); /* Change input handler of the physical interface. */ - if_ih_insert(p, vlan_input); + if_ih_insert(p, vlan_input, NULL); return (0); } @@ -455,9 +455,9 @@ vlan_unconfig(struct ifnet *ifp, struct ifnet *newp) s = splnet(); LIST_REMOVE(ifv, ifv_list); splx(s); - + /* Restore previous input handler. */ - if_ih_remove(p, vlan_input); + if_ih_remove(p, vlan_input, NULL); hook_disestablish(p->if_linkstatehooks, ifv->lh_cookie); hook_disestablish(p->if_detachhooks, ifv->dh_cookie); diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 142d41f7661..96b44ff497d 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.266 2015/09/10 15:09:16 dlg Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.267 2015/09/10 16:41:30 mikeb Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -193,7 +193,7 @@ void carp_hmac_generate(struct carp_vhost_entry *, u_int32_t *, unsigned char *, u_int8_t); int carp_hmac_verify(struct carp_vhost_entry *, u_int32_t *, unsigned char *); -int carp_input(struct ifnet *ifp, struct mbuf *); +int carp_input(struct ifnet *ifp, struct mbuf *, void *); void carp_proto_input_c(struct ifnet *ifp, struct mbuf *, struct carp_header *, int, sa_family_t); void carp_proto_input_if(struct ifnet *, struct mbuf *, int); @@ -883,7 +883,7 @@ carpdetach(struct carp_softc *sc) return; /* Restore previous input handler. */ - if_ih_remove(ifp, carp_input); + if_ih_remove(ifp, carp_input, NULL); s = splnet(); if (sc->lh_cookie != NULL) @@ -1430,7 +1430,7 @@ carp_ourether(void *v, u_int8_t *ena) } int -carp_input(struct ifnet *ifp0, struct mbuf *m) +carp_input(struct ifnet *ifp0, struct mbuf *m, void *cookie) { struct carp_softc *sc; struct ether_header *eh; @@ -1741,7 +1741,7 @@ carp_set_ifp(struct carp_softc *sc, struct ifnet *ifp) carp_carpdev_state, ifp); /* Change input handler of the physical interface. */ - if_ih_insert(ifp, carp_input); + if_ih_insert(ifp, carp_input, NULL); s = splnet(); carp_carpdev_state(ifp); |