diff options
Diffstat (limited to 'sys')
56 files changed, 324 insertions, 209 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index a230b8e3bcc..507ec6b2fe5 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.204 2015/05/31 20:10:44 bluhm Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.205 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -1206,8 +1206,8 @@ m_print(void *v, (*pr)("m_data: %p\tm_len: %u\n", m->m_data, m->m_len); (*pr)("m_dat: %p\tm_pktdat: %p\n", m->m_dat, m->m_pktdat); if (m->m_flags & M_PKTHDR) { - (*pr)("m_ptkhdr.rcvif: %p\tm_pkthdr.len: %i\n", - m->m_pkthdr.rcvif, m->m_pkthdr.len); + (*pr)("m_ptkhdr.ph_ifidx: %u\tm_pkthdr.len: %i\n", + m->m_pkthdr.ph_ifidx, m->m_pkthdr.len); (*pr)("m_ptkhdr.tags: %p\tm_pkthdr.tagsset: %b\n", SLIST_FIRST(&m->m_pkthdr.tags), m->m_pkthdr.tagsset, MTAG_BITS); diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index b37d55d8f34..808653cb06b 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.138 2015/05/06 08:52:17 mpi Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.139 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -486,7 +486,7 @@ restart: MGETHDR(m, M_WAIT, MT_DATA); mlen = MHLEN; m->m_pkthdr.len = 0; - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.ph_ifidx = 0; } else { MGET(m, M_WAIT, MT_DATA); mlen = MLEN; diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 5626c73fef0..ecf59a8f0af 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.119 2015/05/13 10:42:46 jsg Exp $ */ +/* $OpenBSD: bpf.c,v 1.120 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -180,7 +180,7 @@ bpf_movein(struct uio *uio, u_int linktype, struct mbuf **mp, len = uio->uio_resid; MGETHDR(m, M_WAIT, MT_DATA); - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.len = len - hlen; if (len > MHLEN) { diff --git a/sys/net/bpf.h b/sys/net/bpf.h index 188bb79e4e1..0be8dab461e 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.h,v 1.48 2015/02/10 00:53:55 pelikan Exp $ */ +/* $OpenBSD: bpf.h,v 1.49 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: bpf.h,v 1.15 1996/12/13 07:57:33 mikel Exp $ */ /* @@ -271,6 +271,8 @@ struct bpf_dltlist { #define BPF_JUMP(code, k, jt, jf) { (u_int16_t)(code), jt, jf, k } #ifdef _KERNEL +struct ifnet; + int bpf_validate(struct bpf_insn *, int); int bpf_tap(caddr_t, u_char *, u_int, u_int); void bpf_mtap(caddr_t, struct mbuf *, u_int); diff --git a/sys/net/bridgestp.c b/sys/net/bridgestp.c index 74504acd6ba..0318144d0a2 100644 --- a/sys/net/bridgestp.c +++ b/sys/net/bridgestp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bridgestp.c,v 1.55 2015/05/15 10:15:13 mpi Exp $ */ +/* $OpenBSD: bridgestp.c,v 1.56 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2000 Jason L. Wright (jason@thought.net) @@ -360,7 +360,7 @@ bstp_transmit_tcn(struct bstp_state *bs, struct bstp_port *bp) MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == NULL) return; - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; m->m_pkthdr.len = sizeof(*eh) + sizeof(bpdu); m->m_pkthdr.pf.prio = BSTP_IFQ_PRIO; m->m_len = m->m_pkthdr.len; @@ -503,7 +503,7 @@ bstp_send_bpdu(struct bstp_state *bs, struct bstp_port *bp, default: panic("not implemented"); } - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; m->m_len = m->m_pkthdr.len; m->m_pkthdr.pf.prio = BSTP_IFQ_PRIO; diff --git a/sys/net/if.c b/sys/net/if.c index 21031279f00..a9180400ba3 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.339 2015/06/09 14:57:30 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.340 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -486,7 +486,7 @@ if_input(struct ifnet *ifp, struct mbuf_list *ml) splassert(IPL_NET); MBUF_LIST_FOREACH(ml, m) { - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; } @@ -524,11 +524,16 @@ if_input_process(void *xmq) while ((m = ml_dequeue(&ml)) != NULL) { sched_pause(); + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + continue; + } + /* * Pass this mbuf to all input handlers of its * interface until it is consumed. */ - ifp = m->m_pkthdr.rcvif; SLIST_FOREACH(ifih, &ifp->if_inputs, ifih_next) { if ((*ifih->ifih_input)(m)) break; @@ -699,7 +704,7 @@ if_detach_filter(void *ctx, const struct mbuf *m) return (0); #endif - return (m->m_pkthdr.rcvif == ifp); + return (m->m_pkthdr.ph_ifidx == ifp->if_index); } void diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 8f66923843e..15d77b216cc 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.243 2015/06/12 15:40:06 mpi Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.244 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -1143,7 +1143,11 @@ bridgeintr_frame(struct bridge_softc *sc, struct mbuf *m) return; } - src_if = m->m_pkthdr.rcvif; + src_if = if_get(m->m_pkthdr.ph_ifidx); + if (src_if == NULL) { + m_freem(m); + return; + } sc->sc_if.if_ipackets++; sc->sc_if.if_ibytes += m->m_pkthdr.len; @@ -2464,8 +2468,11 @@ bridge_ip(struct bridge_softc *sc, int dir, struct ifnet *ifp, ip6 = mtod(m, struct ip6_hdr *); if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { + struct ifnet *ifp; ip6stat.ip6s_badvers++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp != NULL) + in6_ifstat_inc(ifp, ifs6_in_hdrerr); goto dropit; } diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 61b303b3ea5..c6ae0229045 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.204 2015/06/08 13:44:08 mpi Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.205 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -344,7 +344,8 @@ ether_input(struct mbuf *m) struct ether_header *eh_tmp; #endif - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); if ((ifp->if_flags & IFF_UP) == 0) { m_freem(m); return (1); @@ -393,7 +394,8 @@ ether_input(struct mbuf *m) if (m == NULL) return (1); /* The bridge has determined it's for us. */ - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); m_adj(m, ETHER_HDR_LEN); } } diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 356d353df2e..d7cd01898f8 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_loop.c,v 1.65 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: if_loop.c,v 1.66 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $ */ /* @@ -216,7 +216,7 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, if (ifp->if_bpf && (ifp->if_flags & IFF_LOOPBACK)) bpf_mtap_af(ifp->if_bpf, dst->sa_family, m, BPF_DIRECTION_OUT); #endif - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { m_freem(m); diff --git a/sys/net/if_mpe.c b/sys/net/if_mpe.c index f2a7bde7d6d..9565273ba3e 100644 --- a/sys/net/if_mpe.c +++ b/sys/net/if_mpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_mpe.c,v 1.44 2015/05/15 10:15:13 mpi Exp $ */ +/* $OpenBSD: if_mpe.c,v 1.45 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -214,7 +214,7 @@ mpeoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, ifp->if_rdomain, rtable_l2(m->m_pkthdr.ph_rtableid)); } #endif - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; /* XXX assumes MPLS is always in rdomain 0 */ m->m_pkthdr.ph_rtableid = 0; @@ -391,7 +391,7 @@ mpe_input(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls, } /* new receive if and move into correct rtable */ - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; #if NBPFILTER > 0 @@ -423,7 +423,7 @@ mpe_input6(struct mbuf *m, struct ifnet *ifp, struct sockaddr_mpls *smpls, } /* new receive if and move into correct rtable */ - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; #if NBPFILTER > 0 diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c index 6ff2adebd00..322c5b2d47c 100644 --- a/sys/net/if_pflow.c +++ b/sys/net/if_pflow.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.c,v 1.50 2015/06/07 12:02:28 jsg Exp $ */ +/* $OpenBSD: if_pflow.c,v 1.51 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2011 Florian Obser <florian@narrans.de> @@ -506,7 +506,7 @@ pflow_get_mbuf(struct pflow_softc *sc, u_int16_t set_id) } m->m_len = m->m_pkthdr.len = 0; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; if (sc == NULL) /* get only a new empty mbuf */ return (m); diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c index 77c63ce0d74..998a7dfff4f 100644 --- a/sys/net/if_pfsync.c +++ b/sys/net/if_pfsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pfsync.c,v 1.218 2015/03/14 03:38:51 jsg Exp $ */ +/* $OpenBSD: if_pfsync.c,v 1.219 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff @@ -672,7 +672,7 @@ pfsync_input(struct mbuf *m, ...) goto done; /* verify that the packet came in on the right interface */ - if (sc->sc_sync_if != m->m_pkthdr.rcvif) { + if (sc->sc_sync_if->if_index != m->m_pkthdr.ph_ifidx) { pfsyncstats.pfsyncs_badif++; goto done; } diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c index 89f4482c177..2dcc8c096bc 100644 --- a/sys/net/if_ppp.c +++ b/sys/net/if_ppp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ppp.c,v 1.84 2015/06/03 00:50:09 dlg Exp $ */ +/* $OpenBSD: if_ppp.c,v 1.85 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */ /* @@ -1372,7 +1372,7 @@ ppp_inproc(struct ppp_softc *sc, struct mbuf *m) #endif /* VJC */ m->m_pkthdr.len = ilen; - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; /* mark incoming routing table */ m->m_pkthdr.ph_rtableid = ifp->if_rdomain; diff --git a/sys/net/if_pppoe.c b/sys/net/if_pppoe.c index ebfe565b31c..ed492b0e80e 100644 --- a/sys/net/if_pppoe.c +++ b/sys/net/if_pppoe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppoe.c,v 1.45 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: if_pppoe.c,v 1.46 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if_pppoe.c,v 1.51 2003/11/28 08:56:48 keihan Exp $ */ /* @@ -181,8 +181,8 @@ static int pppoe_send_padt(struct ifnet *, u_int, const u_int8_t *); static int pppoe_output(struct pppoe_softc *, struct mbuf *); /* internal helper functions */ -static struct pppoe_softc *pppoe_find_softc_by_session(u_int, struct ifnet *); -static struct pppoe_softc *pppoe_find_softc_by_hunique(u_int8_t *, size_t, struct ifnet *); +static struct pppoe_softc *pppoe_find_softc_by_session(u_int, u_int); +static struct pppoe_softc *pppoe_find_softc_by_hunique(u_int8_t *, size_t, u_int); static struct mbuf *pppoe_get_mbuf(size_t len); LIST_HEAD(pppoe_softc_head, pppoe_softc) pppoe_softc_list; @@ -295,7 +295,7 @@ pppoe_clone_destroy(struct ifnet *ifp) * be 1. */ static struct pppoe_softc * -pppoe_find_softc_by_session(u_int session, struct ifnet *rcvif) +pppoe_find_softc_by_session(u_int session, u_int ifidx) { struct pppoe_softc *sc; @@ -305,7 +305,7 @@ pppoe_find_softc_by_session(u_int session, struct ifnet *rcvif) LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { if (sc->sc_state == PPPOE_STATE_SESSION && sc->sc_session == session - && sc->sc_eth_if == rcvif) { + && sc->sc_eth_if->if_index == ifidx) { return (sc); } } @@ -317,7 +317,7 @@ pppoe_find_softc_by_session(u_int session, struct ifnet *rcvif) * or NULL if token is bogus. */ static struct pppoe_softc * -pppoe_find_softc_by_hunique(u_int8_t *token, size_t len, struct ifnet *rcvif) +pppoe_find_softc_by_hunique(u_int8_t *token, size_t len, u_int ifidx) { struct pppoe_softc *sc; u_int32_t hunique; @@ -344,7 +344,7 @@ pppoe_find_softc_by_hunique(u_int8_t *token, size_t len, struct ifnet *rcvif) sc->sc_sppp.pp_if.if_xname, sc->sc_state); return (NULL); } - if (sc->sc_eth_if != rcvif) { + if (sc->sc_eth_if->if_index != ifidx) { printf("%s: wrong interface, not accepting host unique\n", sc->sc_sppp.pp_if.if_xname); return (NULL); @@ -484,7 +484,7 @@ static void pppoe_dispatch_disc_pkt(struct mbuf *m, int off) hunique_len = len; #endif sc = pppoe_find_softc_by_hunique(mtod(n, caddr_t) + noff, - len, m->m_pkthdr.rcvif); + len, m->m_pkthdr.ph_ifidx); if (sc != NULL) devname = sc->sc_sppp.pp_if.if_xname; break; @@ -610,7 +610,7 @@ breakbreak: sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, - m->m_pkthdr.rcvif); + m->m_pkthdr.ph_ifidx); if (sc == NULL) { /* be quiet if there is not a single pppoe instance */ if (!LIST_EMPTY(&pppoe_softc_list)) @@ -798,7 +798,7 @@ pppoe_data_input(struct mbuf *m) goto drop; session = ntohs(ph->session); - sc = pppoe_find_softc_by_session(session, m->m_pkthdr.rcvif); + sc = pppoe_find_softc_by_session(session, m->m_pkthdr.ph_ifidx); if (sc == NULL) { #ifdef PPPOE_TERM_UNKNOWN_SESSIONS printf("pppoe (data): input for unknown session 0x%x, sending PADT\n", @@ -837,7 +837,7 @@ pppoe_data_input(struct mbuf *m) goto drop; /* fix incoming interface pointer (not the raw ethernet interface anymore) */ - m->m_pkthdr.rcvif = &sc->sc_sppp.pp_if; + m->m_pkthdr.ph_ifidx = sc->sc_sppp.pp_if.if_index; /* pass packet up and account for it */ sc->sc_sppp.pp_if.if_ipackets++; @@ -1043,7 +1043,7 @@ pppoe_get_mbuf(size_t len) m->m_data += sizeof(struct ether_header); m->m_len = len; m->m_pkthdr.len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; return (m); } diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index ea4cf3a9106..145805319ff 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_spppsubr.c,v 1.133 2015/05/15 10:15:13 mpi Exp $ */ +/* $OpenBSD: if_spppsubr.c,v 1.134 2015/06/16 11:09:39 mpi Exp $ */ /* * Synchronous PPP/Cisco link level subroutines. * Keepalive protocol implemented in both Cisco and PPP modes. @@ -1155,7 +1155,7 @@ sppp_cisco_send(struct sppp *sp, u_int32_t type, u_int32_t par1, u_int32_t par2) if (! m) return; m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.ph_ifidx = 0; h = mtod (m, struct ppp_header*); h->address = CISCO_MULTICAST; @@ -1214,7 +1214,7 @@ sppp_cp_send(struct sppp *sp, u_short proto, u_char type, if (! m) return; m->m_pkthdr.len = m->m_len = pkthdrlen + LCP_HEADER_LEN + len; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.ph_ifidx = 0; if (sp->pp_flags & PP_NOFRAMING) { *mtod(m, u_int16_t *) = htons(proto); @@ -4317,7 +4317,7 @@ sppp_auth_send(const struct cp *cp, struct sppp *sp, MGETHDR (m, M_DONTWAIT, MT_DATA); if (! m) return; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.ph_ifidx = 0; if (sp->pp_flags & PP_NOFRAMING) { *mtod(m, u_int16_t *) = htons(cp->proto); diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c index 5de66dd6e3e..ba3887168db 100644 --- a/sys/net/if_trunk.c +++ b/sys/net/if_trunk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_trunk.c,v 1.102 2015/06/15 15:55:08 mpi Exp $ */ +/* $OpenBSD: if_trunk.c,v 1.103 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -1090,9 +1090,14 @@ trunk_input(struct mbuf *m) struct mbuf_list ml = MBUF_LIST_INITIALIZER(); int error; - ifp = m->m_pkthdr.rcvif; - eh = mtod(m, struct ether_header *); + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); + if ((ifp->if_flags & IFF_UP) == 0) { + m_freem(m); + return (1); + } + eh = mtod(m, struct ether_header *); if (ETHER_IS_MULTICAST(eh->ether_dhost)) ifp->if_imcasts++; diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 4600a8cfa6c..41ef1053770 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.145 2015/06/01 07:48:04 mpi Exp $ */ +/* $OpenBSD: if_tun.c,v 1.146 2015/06/16 11:09:39 mpi Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -898,7 +898,7 @@ tunwrite(dev_t dev, struct uio *uio, int ioflag) top->m_len -= sizeof(*th); top->m_pkthdr.len -= sizeof(*th); top->m_pkthdr.ph_rtableid = ifp->if_rdomain; - top->m_pkthdr.rcvif = ifp; + top->m_pkthdr.ph_ifidx = ifp->if_index; switch (ntohl(*th)) { case AF_INET: diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 632ace29c6d..6371b96536b 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vlan.c,v 1.128 2015/06/08 13:44:08 mpi Exp $ */ +/* $OpenBSD: if_vlan.c,v 1.129 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright 1998 Massachusetts Institute of Technology @@ -259,9 +259,14 @@ vlan_input(struct mbuf *m) struct mbuf_list ml = MBUF_LIST_INITIALIZER(); u_int16_t etype; - ifp = m->m_pkthdr.rcvif; - eh = mtod(m, struct ether_header *); + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); + if ((ifp->if_flags & IFF_UP) == 0) { + m_freem(m); + return (1); + } + eh = mtod(m, struct ether_header *); etype = ntohs(eh->ether_type); if (m->m_flags & M_VLANTAG) { diff --git a/sys/net/pf.c b/sys/net/pf.c index 0fcbd5f4289..1069f647888 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.918 2015/06/07 12:02:28 jsg Exp $ */ +/* $OpenBSD: pf.c,v 1.919 2015/06/16 11:09:39 mpi Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -2350,7 +2350,7 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, m->m_pkthdr.pf.qid = r->qid; m->m_data += max_linkhdr; m->m_pkthdr.len = m->m_len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.csum_flags |= M_TCP_CSUM_OUT; bzero(m->m_data, len); switch (af) { @@ -2605,9 +2605,10 @@ pf_match_tag(struct mbuf *m, struct pf_rule *r, int *tag) int pf_match_rcvif(struct mbuf *m, struct pf_rule *r) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct pfi_kif *kif; + ifp = if_get(m->m_pkthdr.ph_ifidx); if (ifp == NULL) return (0); diff --git a/sys/net/pipex.c b/sys/net/pipex.c index 7c93ab6fbdc..5c52cbfbbfa 100644 --- a/sys/net/pipex.c +++ b/sys/net/pipex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pipex.c,v 1.69 2015/04/23 09:45:24 dlg Exp $ */ +/* $OpenBSD: pipex.c,v 1.70 2015/06/16 11:09:40 mpi Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. @@ -1095,8 +1095,8 @@ pipex_ip_input(struct mbuf *m0, struct pipex_session *session) int is_idle; /* change recvif */ - m0->m_pkthdr.rcvif = session->pipex_iface->ifnet_this; - ifp = m0->m_pkthdr.rcvif; + ifp = session->pipex_iface->ifnet_this; + m0->m_pkthdr.ph_ifidx = ifp->if_index; PIPEX_PULLUP(m0, sizeof(struct ip)); if (m0 == NULL) @@ -1180,8 +1180,8 @@ pipex_ip6_input(struct mbuf *m0, struct pipex_session *session) int len; /* change recvif */ - m0->m_pkthdr.rcvif = session->pipex_iface->ifnet_this; - ifp = m0->m_pkthdr.rcvif; + ifp = session->pipex_iface->ifnet_this; + m0->m_pkthdr.ph_ifidx = ifp->if_index; #if 0 /* XXX: alignment */ PIPEX_PULLUP(m0, sizeof(struct ip6_hdr)); @@ -1431,7 +1431,7 @@ pipex_pppoe_output(struct mbuf *m0, struct pipex_session *session) pppoe->session_id = htons(session->session_id); pppoe->length = htons(len); - m0->m_pkthdr.rcvif = ifp; + m0->m_pkthdr.ph_ifidx = ifp->if_index; m0->m_flags &= ~(M_BCAST|M_MCAST); session->stat.opackets++; @@ -1516,7 +1516,7 @@ pipex_pptp_output(struct mbuf *m0, struct pipex_session *session, } gre->flags = htons(gre->flags); - m0->m_pkthdr.rcvif = session->pipex_iface->ifnet_this; + m0->m_pkthdr.ph_ifidx = session->pipex_iface->ifnet_this->if_index; if (ip_output(m0, NULL, NULL, 0, NULL, NULL, 0) != 0) { PIPEX_DBG((session, LOG_DEBUG, "ip_output failed.")); goto drop; @@ -1948,7 +1948,7 @@ pipex_l2tp_output(struct mbuf *m0, struct pipex_session *session) udp->uh_sum = 0; m0->m_pkthdr.csum_flags |= M_UDP_CSUM_OUT; - m0->m_pkthdr.rcvif = session->pipex_iface->ifnet_this; + m0->m_pkthdr.ph_ifidx = session->pipex_iface->ifnet_this->if_index; #if NPF > 0 pf_pkt_addr_changed(m0); #endif diff --git a/sys/net/ppp_tty.c b/sys/net/ppp_tty.c index 590b531e372..24af0237be4 100644 --- a/sys/net/ppp_tty.c +++ b/sys/net/ppp_tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ppp_tty.c,v 1.33 2015/06/03 00:50:09 dlg Exp $ */ +/* $OpenBSD: ppp_tty.c,v 1.34 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: ppp_tty.c,v 1.12 1997/03/24 21:23:10 christos Exp $ */ /* @@ -362,7 +362,7 @@ pppwrite(struct tty *tp, struct uio *uio, int flag) if (mp == &m0) { MGETHDR(m, M_WAIT, MT_DATA); m->m_pkthdr.len = uio->uio_resid - PPP_HDRLEN; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; } else MGET(m, M_WAIT, MT_DATA); *mp = m; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index eb221a75b6b..48e5ae4d7f6 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.159 2015/05/13 10:42:46 jsg Exp $ */ +/* $OpenBSD: rtsock.c,v 1.160 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -981,7 +981,7 @@ rt_msg1(int type, struct rt_addrinfo *rtinfo) if (m == NULL) return (m); m->m_pkthdr.len = m->m_len = hlen = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; rtm = mtod(m, struct rt_msghdr *); bzero(rtm, len); for (i = 0; i < RTAX_MAX; i++) { diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 8b7c5b7e011..9209706131d 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ether.c,v 1.154 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: if_ether.c,v 1.155 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */ /* @@ -522,8 +522,8 @@ void in_arpinput(struct mbuf *m) { struct ether_arp *ea; - struct ifnet *ifp = m->m_pkthdr.rcvif; - struct arpcom *ac = (struct arpcom *)ifp; + struct ifnet *ifp; + struct arpcom *ac; struct ether_header *eh; struct llinfo_arp *la = 0; struct rtentry *rt; @@ -540,6 +540,11 @@ in_arpinput(struct mbuf *m) int op, changed = 0; unsigned int len; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto out; + ac = (struct arpcom *)ifp; + ea = mtod(m, struct ether_arp *); op = ntohs(ea->arp_op); if ((op != ARPOP_REQUEST) && (op != ARPOP_REPLY)) @@ -921,7 +926,7 @@ in_revarpinput(struct mbuf *m) #ifdef NFSCLIENT if (!revarp_in_progress) goto out; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); if (ifp != revarp_ifp) /* !same interface */ goto out; if (revarp_finished) diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index f4c4bf03a9a..3a486107f76 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: igmp.c,v 1.48 2014/12/17 09:57:13 mpi Exp $ */ +/* $OpenBSD: igmp.c,v 1.49 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: igmp.c,v 1.15 1996/02/13 23:41:25 christos Exp $ */ /* @@ -209,7 +209,7 @@ void igmp_input(struct mbuf *m, ...) { int iphlen; - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct ip *ip = mtod(m, struct ip *); struct igmp *igmp; int igmplen; @@ -229,6 +229,12 @@ igmp_input(struct mbuf *m, ...) igmplen = ntohs(ip->ip_len) - iphlen; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return; + } + /* * Validate lengths */ diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index 59a6cff70fb..46de6b73859 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_gif.c,v 1.44 2015/05/12 12:27:17 mpi Exp $ */ +/* $OpenBSD: in_gif.c,v 1.45 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: in_gif.c,v 1.50 2001/01/22 07:27:16 itojun Exp $ */ /* @@ -190,7 +190,7 @@ in_gif_input(struct mbuf *m, ...) } if (gifp) { - m->m_pkthdr.rcvif = gifp; + m->m_pkthdr.ph_ifidx = gifp->if_index; m->m_pkthdr.ph_rtableid = gifp->if_rdomain; gifp->if_ipackets++; gifp->if_ibytes += m->m_pkthdr.len; diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 5c42326d870..76bd3a3367d 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.259 2015/06/08 13:40:48 mpi Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.260 2015/06/16 11:09:40 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -399,7 +399,7 @@ void carp_proto_input(struct mbuf *m, ...) { struct ip *ip = mtod(m, struct ip *); - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct carp_softc *sc = NULL; struct carp_header *ch; int iplen, len, hlen, ismulti; @@ -409,6 +409,12 @@ carp_proto_input(struct mbuf *m, ...) hlen = va_arg(ap, int); va_end(ap); + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return; + } + carpstats.carps_ipackets++; if (!carp_opts[CARPCTL_ALLOW]) { @@ -478,12 +484,18 @@ int carp6_proto_input(struct mbuf **mp, int *offp, int proto) { struct mbuf *m = *mp; - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct carp_softc *sc = NULL; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct carp_header *ch; u_int len; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return (IPPROTO_DONE); + } + carpstats.carps_ipackets6++; if (!carp_opts[CARPCTL_ALLOW]) { @@ -538,12 +550,15 @@ void carp_proto_input_c(struct mbuf *m, struct carp_header *ch, int ismulti, sa_family_t af) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct carp_softc *sc; struct carp_vhost_entry *vhe; struct timeval sc_tv, ch_tv; struct carp_if *cif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); + if (ifp->if_type == IFT_CARP) cif = (struct carp_if *)ifp->if_carpdev->if_carp; else @@ -1012,7 +1027,7 @@ carp_send_ad(void *v) } len = sizeof(*ip) + sizeof(ch); m->m_pkthdr.len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.ph_rtableid = sc->sc_if.if_rdomain; m->m_pkthdr.pf.prio = CARP_IFQ_PRIO; m->m_len = len; @@ -1102,7 +1117,7 @@ carp_send_ad(void *v) } len = sizeof(*ip6) + sizeof(ch); m->m_pkthdr.len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.pf.prio = CARP_IFQ_PRIO; m->m_pkthdr.ph_rtableid = sc->sc_if.if_rdomain; m->m_len = len; @@ -1408,7 +1423,13 @@ carp_input(struct mbuf *m) struct carp_if *cif; struct ifnet *ifp0, *ifp; - ifp0 = m->m_pkthdr.rcvif; + ifp0 = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp0 != NULL); + if ((ifp0->if_flags & IFF_UP) == 0) { + m_freem(m); + return (1); + } + eh = mtod(m, struct ether_header *); cif = (struct carp_if *)ifp0->if_carp; @@ -1462,10 +1483,15 @@ carp_input(struct mbuf *m) int carp_lsdrop(struct mbuf *m, sa_family_t af, u_int32_t *src, u_int32_t *dst) { - struct carp_softc *sc = m->m_pkthdr.rcvif->if_softc; + struct ifnet *ifp; + struct carp_softc *sc; int match; u_int32_t fold; + ifp = if_get(m->m_pkthdr.ph_ifidx); + KASSERT(ifp != NULL); + + sc = ifp->if_softc; if (sc->sc_balancing < CARP_BAL_IP) return (0); /* diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 1b36f12dcd6..3ce58c662ca 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.33 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.34 2015/06/16 11:09:40 mpi Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -89,7 +89,7 @@ divert_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, struct ip *ip; u_int16_t off; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_nextpkt = NULL; m->m_pkthdr.ph_rtableid = inp->inp_rtableid; @@ -146,7 +146,7 @@ divert_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, error = EADDRNOTAVAIL; goto fail; } - m->m_pkthdr.rcvif = ifa->ifa_ifp; + m->m_pkthdr.ph_ifidx = ifa->ifa_ifp->if_index; /* * Recalculate IP and protocol checksums for the inbound packet @@ -210,7 +210,11 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port) struct ifaddr *ifa; struct ifnet *ifp; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return (0); + } TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET) continue; diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c index 1633b5cd696..f581082c6a1 100644 --- a/sys/netinet/ip_ether.c +++ b/sys/netinet/ip_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ether.c,v 1.71 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: ip_ether.c,v 1.72 2015/06/16 11:09:40 mpi Exp $ */ /* * The author of this code is Angelos D. Keromytis (kermit@adk.gr) * @@ -258,7 +258,7 @@ etherip_decap(struct mbuf *m, int iphlen) #if NPF > 0 pf_pkt_addr_changed(m); #endif - m->m_pkthdr.rcvif = &sc->gif_if; + m->m_pkthdr.ph_ifidx = sc->gif_if.if_index; m->m_pkthdr.ph_rtableid = sc->gif_if.if_rdomain; if (m->m_flags & (M_BCAST|M_MCAST)) sc->gif_if.if_imcasts++; @@ -322,7 +322,7 @@ mplsip_decap(struct mbuf *m, int iphlen) bpf_mtap_af(sc->gif_if.if_bpf, AF_MPLS, m, BPF_DIRECTION_IN); #endif - m->m_pkthdr.rcvif = &sc->gif_if; + m->m_pkthdr.ph_ifidx = sc->gif_if.if_index; m->m_pkthdr.ph_rtableid = sc->gif_if.if_rdomain; #if NPF > 0 pf_pkt_addr_changed(m); diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index c2038ccaa26..e8ead454a10 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.54 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.55 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -110,7 +110,7 @@ gre_input2(struct mbuf *m, int hlen, u_char proto) } gip = mtod(m, struct greip *); - m->m_pkthdr.rcvif = &sc->sc_if; + m->m_pkthdr.ph_ifidx = sc->sc_if.if_index; m->m_pkthdr.ph_rtableid = sc->sc_if.if_rdomain; sc->sc_if.if_ipackets++; @@ -295,7 +295,7 @@ gre_mobile_input(struct mbuf *m, ...) ip = mtod(m, struct ip *); mip = mtod(m, struct mobip_h *); - m->m_pkthdr.rcvif = &sc->sc_if; + m->m_pkthdr.ph_ifidx = sc->sc_if.if_index; sc->sc_if.if_ipackets++; sc->sc_if.if_ibytes += m->m_pkthdr.len; diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 6ea790f0183..cf60775c5eb 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.135 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.136 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -257,7 +257,7 @@ icmp_do_error(struct mbuf *n, int type, int code, u_int32_t dest, int destmtu) m->m_data -= sizeof(struct ip); m->m_len += sizeof(struct ip); m->m_pkthdr.len = m->m_len; - m->m_pkthdr.rcvif = n->m_pkthdr.rcvif; + m->m_pkthdr.ph_ifidx = n->m_pkthdr.ph_ifidx; nip = mtod(m, struct ip *); /* ip_v set in ip_output */ nip->ip_hl = sizeof(struct ip) >> 2; @@ -319,7 +319,9 @@ icmp_input(struct mbuf *m, ...) hlen = va_arg(ap, int); va_end(ap); - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; /* * Locate icmp structure in mbuf, and check diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 8fc560dd999..70670c0ab1c 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.250 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: ip_input.c,v 1.251 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -225,7 +225,9 @@ ipv4_input(struct mbuf *m) struct m_tag *mtag; #endif /* IPSEC */ - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto bad; ipstat.ips_total++; if (m->m_len < sizeof (struct ip) && @@ -1687,7 +1689,7 @@ ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip, struct sockaddr_dl sdl; struct ifnet *ifp; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); if (ifp == NULL || ifp->if_sadl == NULL) { memset(&sdl, 0, sizeof(sdl)); sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data[0]); diff --git a/sys/netinet/ip_ipip.c b/sys/netinet/ip_ipip.c index 77756748da2..b3cadd21b0f 100644 --- a/sys/netinet/ip_ipip.c +++ b/sys/netinet/ip_ipip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipip.c,v 1.59 2015/05/13 10:42:46 jsg Exp $ */ +/* $OpenBSD: ip_ipip.c,v 1.60 2015/06/16 11:09:40 mpi Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -136,8 +136,9 @@ ip4_input(struct mbuf *m, ...) /* * ipip_input gets called when we receive an IP{46} encapsulated packet, * either because we got it at a real interface, or because AH or ESP - * were being used in tunnel mode (in which case the rcvif element will - * contain the address of the encX interface associated with the tunnel. + * were being used in tunnel mode (in which case the ph_ifidx element + * will contain the index of the encX interface associated with the + * tunnel. */ void @@ -294,9 +295,8 @@ ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp, int proto) } /* Check for local address spoofing. */ - if ((m->m_pkthdr.rcvif == NULL || - !(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK)) && - ipip_allow != 2) { + if (((ifp = if_get(m->m_pkthdr.ph_ifidx)) == NULL || + !(ifp->if_flags & IFF_LOOPBACK)) && ipip_allow != 2) { rdomain = rtable_l2(m->m_pkthdr.ph_rtableid); TAILQ_FOREACH(ifp, &ifnet, if_list) { if (ifp->if_rdomain != rdomain) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 960fc284624..b3d15f5973f 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.282 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: ip_output.c,v 1.283 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -769,7 +769,7 @@ ip_fragment(struct mbuf *m, struct ifnet *ifp, u_long mtu) goto sendorfree; } m->m_pkthdr.len = mhlen + len; - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.ph_ifidx = 0; mhip->ip_off = htons((u_int16_t)mhip->ip_off); mhip->ip_sum = 0; if ((ifp != NULL) && diff --git a/sys/netinet/ipsec_input.c b/sys/netinet/ipsec_input.c index a95dbda1a6d..013672e123f 100644 --- a/sys/netinet/ipsec_input.c +++ b/sys/netinet/ipsec_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipsec_input.c,v 1.132 2015/06/11 15:59:17 mikeb Exp $ */ +/* $OpenBSD: ipsec_input.c,v 1.133 2015/06/16 11:09:40 mpi Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -290,7 +290,7 @@ ipsec_common_input(struct mbuf *m, int skip, int protoff, int af, int sproto, } /* XXX This conflicts with the scoped nature of IPv6 */ - m->m_pkthdr.rcvif = encif; + m->m_pkthdr.ph_ifidx = encif->if_index; } /* Register first use, setup expiration timer. */ @@ -1019,8 +1019,12 @@ ah6_input_cb(struct mbuf *m, int off, int protoff) * more sanity checks in header chain processing. */ if (m->m_pkthdr.len < off) { + struct ifnet *ifp; + ip6stat.ip6s_tooshort++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp != NULL) + in6_ifstat_inc(ifp, ifs6_in_truncated); goto bad; } nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt); diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 15e69aead3a..dd4eca286ae 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_input.c,v 1.292 2015/06/07 12:02:28 jsg Exp $ */ +/* $OpenBSD: tcp_input.c,v 1.293 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */ /* @@ -177,8 +177,8 @@ do { \ do { \ if ((tp)->t_flags & TF_DELACK || \ (tcp_ack_on_push && (tiflags) & TH_PUSH) || \ - (m && (m->m_flags & M_PKTHDR) && m->m_pkthdr.rcvif && \ - (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK))) \ + (m && (m->m_flags & M_PKTHDR) && if_get(m->m_pkthdr.ph_ifidx) && \ + (if_get(m->m_pkthdr.ph_ifidx)->if_flags & IFF_LOOPBACK))) \ tp->t_flags |= TF_ACKNOW; \ else \ TCP_SET_DELACK(tp); \ @@ -813,7 +813,8 @@ findpcb: if (ip6 && !ip6_use_deprecated) { struct in6_ifaddr *ia6; - if ((ia6 = in6ifa_ifpwithaddr(m->m_pkthdr.rcvif, + if ((ia6 = in6ifa_ifpwithaddr( + if_get(m->m_pkthdr.ph_ifidx), &ip6->ip6_dst)) && (ia6->ia6_flags & IN6_IFF_DEPRECATED)) { tp = NULL; @@ -4039,7 +4040,7 @@ syn_cache_add(struct sockaddr *src, struct sockaddr *dst, struct tcphdr *th, sc->sc_iss = issp ? *issp : arc4random(); sc->sc_peermaxseg = oi->maxseg; sc->sc_ourmaxseg = tcp_mss_adv(m->m_flags & M_PKTHDR ? - m->m_pkthdr.rcvif : NULL, sc->sc_src.sa.sa_family); + if_get(m->m_pkthdr.ph_ifidx) : NULL, sc->sc_src.sa.sa_family); sc->sc_win = win; sc->sc_timestamp = tb.ts_recent; if ((tb.t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == @@ -4178,7 +4179,7 @@ syn_cache_respond(struct syn_cache *sc, struct mbuf *m) /* Fixup the mbuf. */ m->m_data += max_linkhdr; m->m_len = m->m_pkthdr.len = tlen; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.ph_rtableid = sc->sc_rtableid; memset(mtod(m, u_char *), 0, tlen); diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 2fd005582e8..0c46215d7bd 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_output.c,v 1.110 2015/06/07 01:25:27 krw Exp $ */ +/* $OpenBSD: tcp_output.c,v 1.111 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */ /* @@ -765,7 +765,7 @@ send: m->m_data += max_linkhdr; m->m_len = hdrlen; } - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.len = hdrlen + len; if (!tp->t_template) diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 3637eefcadb..12788eb3246 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.142 2015/05/13 10:42:46 jsg Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.143 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -394,7 +394,7 @@ tcp_respond(struct tcpcb *tp, caddr_t template, struct tcphdr *th0, m->m_len = tlen; m->m_pkthdr.len = tlen; - m->m_pkthdr.rcvif = (struct ifnet *) 0; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.csum_flags |= M_TCP_CSUM_OUT; /* force routing table */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 76048a45115..9dcff8aca59 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.200 2015/06/05 21:41:43 krw Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.201 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -756,8 +756,8 @@ udp6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d) sa6.sin6_len = sizeof(sa6); sa6.sin6_addr = *ip6cp->ip6c_finaldst; /* XXX: assuming M is valid in this case */ - sa6.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif, - ip6cp->ip6c_finaldst); + sa6.sin6_scope_id = in6_addr2scopeid( + if_get(m->m_pkthdr.ph_ifidx), ip6cp->ip6c_finaldst); if (in6_embedscope(ip6cp->ip6c_finaldst, &sa6, NULL, NULL)) { /* should be impossible */ return; @@ -789,8 +789,8 @@ udp6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d) sa6_src.sin6_family = AF_INET6; sa6_src.sin6_len = sizeof(sa6_src); sa6_src.sin6_addr = ip6->ip6_src; - sa6_src.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif, - &ip6->ip6_src); + sa6_src.sin6_scope_id = in6_addr2scopeid( + if_get(m->m_pkthdr.ph_ifidx), &ip6->ip6_src); if (in6_embedscope(&sa6_src.sin6_addr, &sa6_src, NULL, NULL)) { /* should be impossible */ return; diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c index bff3dc8da94..1d43f3f2aea 100644 --- a/sys/netinet6/frag6.c +++ b/sys/netinet6/frag6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frag6.c,v 1.59 2014/12/08 10:51:00 mpi Exp $ */ +/* $OpenBSD: frag6.c,v 1.60 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */ /* @@ -203,7 +203,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto) #else /* we are violating the spec, this is not the destination interface */ if ((m->m_flags & M_PKTHDR) != 0) - dstifp = m->m_pkthdr.rcvif; + dstifp = if_get(m->m_pkthdr.ph_ifidx); #endif /* jumbo payload can't contain a fragment header */ diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index bf1c2124db1..cfc8ff6b041 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.158 2015/06/08 22:19:27 krw Exp $ */ +/* $OpenBSD: icmp6.c,v 1.159 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -354,10 +354,10 @@ icmp6_error(struct mbuf *m, int type, int code, int param) * icmp6_reflect() is designed to be in the input path. * icmp6_error() can be called from both input and outut path, * and if we are in output path rcvif could contain bogus value. - * clear m->m_pkthdr.rcvif for safety, we should have enough scope - * information in ip header (nip6). + * clear m->m_pkthdr.ph_ifidx for safety, we should have enough + * scope information in ip header (nip6). */ - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; icmp6stat.icp6s_outhist[type]++; icmp6_reflect(m, sizeof(struct ip6_hdr)); /* header order: IPv6 - ICMPv6 */ @@ -386,7 +386,9 @@ icmp6_input(struct mbuf **mp, int *offp, int proto) int code, sum, noff; char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN]; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; icmp6_ifstat_inc(ifp, ifs6_in_msg); @@ -926,8 +928,8 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code) icmp6dst.sin6_addr = eip6->ip6_dst; else icmp6dst.sin6_addr = *finaldst; - icmp6dst.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif, - &icmp6dst.sin6_addr); + icmp6dst.sin6_scope_id = in6_addr2scopeid( + if_get(m->m_pkthdr.ph_ifidx), &icmp6dst.sin6_addr); if (in6_embedscope(&icmp6dst.sin6_addr, &icmp6dst, NULL, NULL)) { /* should be impossbile */ @@ -944,8 +946,8 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code) icmp6src.sin6_len = sizeof(struct sockaddr_in6); icmp6src.sin6_family = AF_INET6; icmp6src.sin6_addr = eip6->ip6_src; - icmp6src.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif, - &icmp6src.sin6_addr); + icmp6src.sin6_scope_id = in6_addr2scopeid( + if_get(m->m_pkthdr.ph_ifidx), &icmp6src.sin6_addr); if (in6_embedscope(&icmp6src.sin6_addr, &icmp6src, NULL, NULL)) { /* should be impossbile */ @@ -1030,10 +1032,9 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) sin6.sin6_addr = *dst; /* XXX normally, this won't happen */ if (IN6_IS_ADDR_LINKLOCAL(dst)) { - sin6.sin6_addr.s6_addr16[1] = - htons(m->m_pkthdr.rcvif->if_index); + sin6.sin6_addr.s6_addr16[1] = htons(m->m_pkthdr.ph_ifidx); } - sin6.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif, + sin6.sin6_scope_id = in6_addr2scopeid(if_get(m->m_pkthdr.ph_ifidx), &sin6.sin6_addr); rt = icmp6_mtudisc_clone(sin6tosa(&sin6), m->m_pkthdr.ph_rtableid); @@ -1237,13 +1238,13 @@ icmp6_reflect(struct mbuf *m, size_t off) sa6_src.sin6_family = AF_INET6; sa6_src.sin6_len = sizeof(sa6_src); sa6_src.sin6_addr = ip6->ip6_dst; - in6_recoverscope(&sa6_src, &ip6->ip6_dst, m->m_pkthdr.rcvif); + in6_recoverscope(&sa6_src, &ip6->ip6_dst, if_get(m->m_pkthdr.ph_ifidx)); in6_embedscope(&ip6->ip6_dst, &sa6_src, NULL, NULL); bzero(&sa6_dst, sizeof(sa6_dst)); sa6_dst.sin6_family = AF_INET6; sa6_dst.sin6_len = sizeof(sa6_dst); sa6_dst.sin6_addr = t; - in6_recoverscope(&sa6_dst, &t, m->m_pkthdr.rcvif); + in6_recoverscope(&sa6_dst, &t, if_get(m->m_pkthdr.ph_ifidx)); in6_embedscope(&t, &sa6_dst, NULL, NULL); /* @@ -1299,9 +1300,9 @@ icmp6_reflect(struct mbuf *m, size_t off) ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; ip6->ip6_nxt = IPPROTO_ICMPV6; - if (m->m_pkthdr.rcvif) { + if (if_get(m->m_pkthdr.ph_ifidx) != NULL) { /* XXX: This may not be the outgoing interface */ - ip6->ip6_hlim = ND_IFINFO(m->m_pkthdr.rcvif)->chlim; + ip6->ip6_hlim = ND_IFINFO(if_get(m->m_pkthdr.ph_ifidx))->chlim; } else ip6->ip6_hlim = ip6_defhlim; @@ -1363,7 +1364,7 @@ icmp6_redirect_diag(struct in6_addr *src6, struct in6_addr *dst6, void icmp6_redirect_input(struct mbuf *m, int off) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_redirect *nd_rd; int icmp6len = ntohs(ip6->ip6_plen); @@ -1378,7 +1379,8 @@ icmp6_redirect_input(struct mbuf *m, int off) union nd_opts ndopts; char addr[INET6_ADDRSTRLEN]; - if (!ifp) + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) return; /* XXX if we are router, we don't update route by icmp6 redirect */ @@ -1631,7 +1633,7 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt) MCLGET(m, M_DONTWAIT); if (!m) goto fail; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_len = 0; maxlen = M_TRAILINGSPACE(m); maxlen = min(IPV6_MMTU, maxlen); diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index c7230c70d17..20f810ac128 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_gif.c,v 1.39 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: in6_gif.c,v 1.40 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: in6_gif.c,v 1.43 2001/01/22 07:27:17 itojun Exp $ */ /* @@ -179,7 +179,7 @@ int in6_gif_input(struct mbuf **mp, int *offp, int proto) } if (gifp) { - m->m_pkthdr.rcvif = gifp; + m->m_pkthdr.ph_ifidx = gifp->if_index; gifp->if_ipackets++; gifp->if_ibytes += m->m_pkthdr.len; ipip_input(m, *offp, gifp, proto); diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 4512dbe0ab9..3cc2224f01d 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.34 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.35 2015/06/16 11:09:40 mpi Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -92,7 +92,7 @@ divert6_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, int error = 0, min_hdrlen = 0, nxt = 0, off, dir; struct ip6_hdr *ip6; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_nextpkt = NULL; m->m_pkthdr.ph_rtableid = inp->inp_rtableid; @@ -156,7 +156,7 @@ divert6_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, error = EADDRNOTAVAIL; goto fail; } - m->m_pkthdr.rcvif = ifa->ifa_ifp; + m->m_pkthdr.ph_ifidx = ifa->ifa_ifp->if_index; /* * Recalculate the protocol checksum for the inbound packet @@ -216,7 +216,11 @@ divert6_packet(struct mbuf *m, int dir, u_int16_t divert_port) struct ifaddr *ifa; struct ifnet *ifp; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return (0); + } TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index cd69125c163..fe8863d2dcf 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_forward.c,v 1.75 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: ip6_forward.c,v 1.76 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $ */ /* @@ -122,10 +122,10 @@ ip6_forward(struct mbuf *m, int srcrt) inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6)); log(LOG_DEBUG, "cannot forward " - "from %s to %s nxt %d received on %s\n", + "from %s to %s nxt %d received on inteface %u\n", src6, dst6, ip6->ip6_nxt, - m->m_pkthdr.rcvif->if_xname); + m->m_pkthdr.ph_ifidx); } m_freem(m); return; @@ -287,7 +287,7 @@ reroute: * unreachable error with Code 2 (beyond scope of source address). * [draft-ietf-ipngwg-icmp-v3-00.txt, Section 3.1] */ - if (in6_addr2scopeid(m->m_pkthdr.rcvif, &ip6->ip6_src) != + if (in6_addr2scopeid(if_get(m->m_pkthdr.ph_ifidx), &ip6->ip6_src) != in6_addr2scopeid(rt->rt_ifp, &ip6->ip6_src)) { ip6stat.ip6s_cantforward++; ip6stat.ip6s_badscope++; @@ -299,10 +299,10 @@ reroute: inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6)); log(LOG_DEBUG, "cannot forward " - "src %s, dst %s, nxt %d, rcvif %s, outif %s\n", + "src %s, dst %s, nxt %d, rcvif %u, outif %u\n", src6, dst6, ip6->ip6_nxt, - m->m_pkthdr.rcvif->if_xname, rt->rt_ifp->if_xname); + m->m_pkthdr.ph_ifidx, rt->rt_ifp->if_index); } if (mcopy) icmp6_error(mcopy, ICMP6_DST_UNREACH, @@ -369,7 +369,8 @@ reroute: * Also, don't send redirect if forwarding using a route * modified by a redirect. */ - if (rt->rt_ifp == m->m_pkthdr.rcvif && !srcrt && ip6_sendredirects && + if (rt->rt_ifp->if_index == m->m_pkthdr.ph_ifidx && !srcrt && + ip6_sendredirects && (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0) { if ((rt->rt_ifp->if_flags & IFF_POINTOPOINT) && nd6_is_addr_neighbor(&ip6_forward_rt.ro_dst, rt->rt_ifp)) { diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 8d24ad2087a..feb188e235f 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.142 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.143 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -191,7 +191,9 @@ ip6_input(struct mbuf *m) int srcrt = 0, isanycast = 0; u_int rtableid = 0; - ifp = m->m_pkthdr.rcvif; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto bad; if (m->m_flags & M_EXT) { if (m->m_next) @@ -987,8 +989,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp) bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr)); if (IN6_IS_SCOPE_EMBED(&pi6.ipi6_addr)) pi6.ipi6_addr.s6_addr16[1] = 0; - pi6.ipi6_ifindex = - (m && m->m_pkthdr.rcvif) ? m->m_pkthdr.rcvif->if_index : 0; + pi6.ipi6_ifindex = m ? m->m_pkthdr.ph_ifidx : 0; *mp = sbcreatecontrol((caddr_t) &pi6, sizeof(struct in6_pktinfo), IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6); diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index b1a37e6bf26..a031115d2e1 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1078,10 +1078,10 @@ ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m) ip6_log_time = time_second; log(LOG_DEBUG, "cannot forward " - "from %s to %s nxt %d received on %s\n", + "from %s to %s nxt %d received on interface %u\n", src, dst, ip6->ip6_nxt, - m->m_pkthdr.rcvif->if_xname); + m->m_pkthdr.ph_ifidx); } return 0; } @@ -1445,8 +1445,8 @@ ip6_mdq(struct mbuf *m, struct ifnet *ifp, struct mf6c *rt) } /* if wrong iif */ /* If I sourced this packet, it counts as output, else it was input. */ - if (m->m_pkthdr.rcvif == NULL) { - /* XXX: is rcvif really NULL when output?? */ + if (m->m_pkthdr.ph_ifidx == 0) { + /* XXX: is ph_ifidx really 0 when output?? */ mif6table[mifi].m6_pkt_out++; mif6table[mifi].m6_bytes_out += plen; } else { @@ -1526,7 +1526,7 @@ phyint_send6(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m) * Otherwise, we can simply send the packet to the interface * sending queue. */ - if (m->m_pkthdr.rcvif == NULL) { + if (m->m_pkthdr.ph_ifidx == 0) { struct ip6_moptions im6o; im6o.im6o_ifidx = ifp->if_index; diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index e467ccdb871..e85aa0fb8d3 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_output.c,v 1.173 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: ip6_output.c,v 1.174 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -713,7 +713,7 @@ reroute: * continuous unless the flag is set. */ m->m_flags |= M_LOOP; - m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.ph_ifidx = ifp->if_index; if (ip6_process_hopopts(m, (u_int8_t *)(hbh + 1), ((hbh->ip6h_len + 1) << 3) - sizeof(struct ip6_hbh), &dummy1, &dummy2) < 0) { @@ -722,7 +722,7 @@ reroute: goto done; } m->m_flags &= ~M_LOOP; /* XXX */ - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; } #if NPF > 0 diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c index f864299c290..d449c31a45f 100644 --- a/sys/netinet6/mld6.c +++ b/sys/netinet6/mld6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mld6.c,v 1.41 2014/12/17 09:57:13 mpi Exp $ */ +/* $OpenBSD: mld6.c,v 1.42 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: mld6.c,v 1.26 2001/02/16 14:50:35 itojun Exp $ */ /* @@ -164,11 +164,17 @@ mld6_input(struct mbuf *m, int off) { struct ip6_hdr *ip6; struct mld_hdr *mldh; - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct in6_multi *in6m; struct ifmaddr *ifma; int timer; /* timer value in the MLD query header */ + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) { + m_freem(m); + return; + } + IP6_EXTHDR_GET(mldh, struct mld_hdr *, m, off, sizeof(*mldh)); if (mldh == NULL) { icmp6stat.icp6s_tooshort++; @@ -405,7 +411,7 @@ mld6_sendpkt(struct in6_multi *in6m, int type, const struct in6_addr *dst) } mh->m_next = md; - mh->m_pkthdr.rcvif = NULL; + mh->m_pkthdr.ph_ifidx = 0; mh->m_pkthdr.ph_rtableid = ifp->if_rdomain; mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld_hdr); mh->m_len = sizeof(struct ip6_hdr); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 7936cad3c97..65e9bc3b845 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.138 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: nd6.c,v 1.139 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -430,7 +430,7 @@ nd6_llinfo_timer(void *arg) * XXX: should we consider * older rcvif? */ - m->m_pkthdr.rcvif = rt->rt_ifp; + m->m_pkthdr.ph_ifidx = rt->rt_ifp->if_index; icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, 0); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 43cad6b5bce..a6b28034486 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_nbr.c,v 1.89 2015/03/14 03:38:52 jsg Exp $ */ +/* $OpenBSD: nd6_nbr.c,v 1.90 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ /* @@ -95,7 +95,7 @@ static int dad_maxtry = 15; /* max # of *tries* to transmit DAD packet */ void nd6_ns_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_neighbor_solicit *nd_ns; struct in6_addr saddr6 = ip6->ip6_src; @@ -112,6 +112,10 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) struct sockaddr_dl *proxydl = NULL; char addr[INET6_ADDRSTRLEN], addr0[INET6_ADDRSTRLEN]; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; + IP6_EXTHDR_GET(nd_ns, struct nd_neighbor_solicit *, m, off, icmp6len); if (nd_ns == NULL) { icmp6stat.icp6s_tooshort++; @@ -392,7 +396,7 @@ nd6_ns_output(struct ifnet *ifp, struct in6_addr *daddr6, } if (m == NULL) return; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; if (daddr6 == NULL || IN6_IS_ADDR_MULTICAST(daddr6)) { @@ -562,7 +566,7 @@ nd6_ns_output(struct ifnet *ifp, struct in6_addr *daddr6, void nd6_na_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_neighbor_advert *nd_na; struct in6_addr saddr6 = ip6->ip6_src; @@ -581,6 +585,10 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) union nd_opts ndopts; char addr[INET6_ADDRSTRLEN], addr0[INET6_ADDRSTRLEN]; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; + if (ip6->ip6_hlim != 255) { nd6log((LOG_ERR, "nd6_na_input: invalid hlim (%d) from %s to %s on %s\n", @@ -943,7 +951,7 @@ nd6_na_output(struct ifnet *ifp, struct in6_addr *daddr6, } if (m == NULL) return; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; if (IN6_IS_ADDR_MULTICAST(daddr6)) { diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 8e6ecb03818..9acef421b86 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.106 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.107 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -88,7 +88,7 @@ extern int nd6_recalc_reachtm_interval; void nd6_rs_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_router_solicit *nd_rs; struct in6_addr saddr6 = ip6->ip6_src; @@ -106,6 +106,10 @@ nd6_rs_input(struct mbuf *m, int off, int icmp6len) union nd_opts ndopts; char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN]; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; + /* If I'm not a router, ignore it. XXX - too restrictive? */ if (!ip6_forwarding) goto freeit; @@ -197,7 +201,7 @@ nd6_rs_output(struct ifnet* ifp, struct in6_ifaddr *ia6) if (m == NULL) return; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; m->m_pkthdr.ph_rtableid = ifp->if_rdomain; m->m_flags |= M_MCAST; m->m_pkthdr.csum_flags |= M_ICMP_CSUM_OUT; @@ -278,8 +282,8 @@ nd6_rs_dev_state(void *arg) void nd6_ra_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; - struct nd_ifinfo *ndi = ND_IFINFO(ifp); + struct ifnet *ifp; + struct nd_ifinfo *ndi; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_router_advert *nd_ra; struct in6_addr saddr6 = ip6->ip6_src; @@ -293,9 +297,15 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len) struct nd_defrouter *dr; char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN]; + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL) + goto freeit; + /* We accept RAs only if inet6 autoconf is enabled */ if (!(ifp->if_xflags & IFXF_AUTOCONF6)) goto freeit; + + ndi = ND_IFINFO(ifp); if (!(ndi->flags & ND6_IFF_ACCEPT_RTADV)) goto freeit; @@ -420,7 +430,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len) pr.ndpr_prefix.sin6_family = AF_INET6; pr.ndpr_prefix.sin6_len = sizeof(pr.ndpr_prefix); pr.ndpr_prefix.sin6_addr = pi->nd_opt_pi_prefix; - pr.ndpr_ifp = (struct ifnet *)m->m_pkthdr.rcvif; + pr.ndpr_ifp = ifp; pr.ndpr_raf_onlink = (pi->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) ? 1 : 0; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 83a8d75c14a..0003bd65627 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.74 2015/06/08 22:19:28 krw Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.75 2015/06/16 11:09:40 mpi Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -223,10 +223,15 @@ rip6_input(struct mbuf **mp, int *offp, int proto) m_freem(m); else { u_int8_t *prvnxtp = ip6_get_prevhdr(m, *offp); /* XXX */ - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_protounknown); - icmp6_error(m, ICMP6_PARAM_PROB, - ICMP6_PARAMPROB_NEXTHEADER, - prvnxtp - mtod(m, u_int8_t *)); + struct ifnet *ifp; + + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp != NULL) { + in6_ifstat_inc(ifp, ifs6_in_protounknown); + icmp6_error(m, ICMP6_PARAM_PROB, + ICMP6_PARAMPROB_NEXTHEADER, + prvnxtp - mtod(m, u_int8_t *)); + } } ip6stat.ip6s_delivered--; } diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 1929786cbdc..622442a79b4 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.43 2015/04/10 13:58:20 dlg Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.44 2015/06/16 11:09:40 mpi Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -77,7 +77,7 @@ mplsintr(void) void mpls_input(struct mbuf *m) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp; struct sockaddr_mpls *smpls; struct sockaddr_mpls sa_mpls; struct shim_hdr *shim; @@ -86,7 +86,8 @@ mpls_input(struct mbuf *m) u_int8_t ttl; int i, hasbos; - if (!ISSET(ifp->if_xflags, IFXF_MPLS)) { + ifp = if_get(m->m_pkthdr.ph_ifidx); + if (ifp == NULL || !ISSET(ifp->if_xflags, IFXF_MPLS)) { m_freem(m); return; } diff --git a/sys/nfs/krpc_subr.c b/sys/nfs/krpc_subr.c index e40c006217c..c65d012b8f0 100644 --- a/sys/nfs/krpc_subr.c +++ b/sys/nfs/krpc_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: krpc_subr.c,v 1.26 2015/03/14 03:38:52 jsg Exp $ */ +/* $OpenBSD: krpc_subr.c,v 1.27 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: krpc_subr.c,v 1.12.4.1 1996/06/07 00:52:26 cgd Exp $ */ /* @@ -329,7 +329,7 @@ krpc_call(struct sockaddr_in *sa, u_int prog, u_int vers, u_int func, m = m->m_next; } mhead->m_pkthdr.len = len; - mhead->m_pkthdr.rcvif = NULL; + mhead->m_pkthdr.ph_ifidx = 0; /* * Send it, repeatedly, until a reply is received, diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index 7fb7eb5d560..59ecd4acee4 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_subs.c,v 1.127 2015/04/17 04:43:21 guenther Exp $ */ +/* $OpenBSD: nfs_subs.c,v 1.128 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: nfs_subs.c,v 1.27.4.3 1996/07/08 20:34:24 jtc Exp $ */ /* @@ -626,7 +626,7 @@ nfsm_rpchead(struct nfsreq *req, struct ucred *cr, int auth_type) } mb->m_pkthdr.len += authsiz + 10 * NFSX_UNSIGNED; - mb->m_pkthdr.rcvif = NULL; + mb->m_pkthdr.ph_ifidx = 0; } /* diff --git a/sys/nfs/nfs_syscalls.c b/sys/nfs/nfs_syscalls.c index 26db90feed0..c5a5478e525 100644 --- a/sys/nfs/nfs_syscalls.c +++ b/sys/nfs/nfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_syscalls.c,v 1.100 2015/05/06 08:52:17 mpi Exp $ */ +/* $OpenBSD: nfs_syscalls.c,v 1.101 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: nfs_syscalls.c,v 1.19 1996/02/18 11:53:52 fvdl Exp $ */ /* @@ -401,7 +401,7 @@ loop: m = mreq; m->m_pkthdr.len = siz; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.ph_ifidx = 0; /* For stream protocols, prepend a Sun RPC Record Mark. */ if (sotype == SOCK_STREAM) { diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 64d1321320a..af6054af78d 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.191 2015/05/23 12:52:59 markus Exp $ */ +/* $OpenBSD: mbuf.h,v 1.192 2015/06/16 11:09:40 mpi Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -121,7 +121,7 @@ struct pkthdr_pf { /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */ struct pkthdr { - struct ifnet *rcvif; /* rcv interface */ + void *ph_cookie; /* additional data */ SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ int len; /* total packet length */ u_int16_t tagsset; /* mtags attached */ @@ -129,7 +129,7 @@ struct pkthdr { u_int16_t csum_flags; /* checksum flags */ u_int16_t ether_vtag; /* Ethernet 802.1p+Q vlan tag */ u_int ph_rtableid; /* routing table id */ - void *ph_cookie; /* additional data */ + u_int ph_ifidx; /* rcv interface index */ struct pkthdr_pf pf; }; |