receiving interface in the packet header of every mbuf.
The interface pointer should now be retrieved when necessary with
if_get(). If a NULL pointer is returned by if_get(), the interface
has probably been destroy/removed and the mbuf should be freed.
Such mechanism will simplify garbage collection of mbufs and limit
problems with dangling ifp pointers.
Tested by jmatthew@ and krw@, discussed with many.
ok mikeb@, bluhm@, dlg@
-/* $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 $ */
/*
(*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);
-/* $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 $ */
/*
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;
-/* $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 $ */
/*
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) {
-/* $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 $ */
/*
#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);
-/* $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)
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;
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;
-/* $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 $ */
/*
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;
}
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;
return (0);
#endif
- return (m->m_pkthdr.rcvif == ifp);
+ return (m->m_pkthdr.ph_ifidx == ifp->if_index);
}
void
-/* $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)
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;
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;
}
-/* $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 $ */
/*
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);
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);
}
}
-/* $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 $ */
/*
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);
-/* $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>
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;
}
/* 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
}
/* 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
-/* $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>
}
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);
-/* $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
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;
}
-/* $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 $ */
/*
#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;
-/* $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 $ */
/*
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;
* 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;
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);
}
}
* 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;
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);
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;
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))
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",
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++;
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);
}
-/* $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.
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;
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);
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);
-/* $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>
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++;
-/* $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 $ */
/*
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:
-/* $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
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) {
-/* $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
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) {
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);
-/* $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.
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)
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));
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++;
}
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;
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
-/* $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 $ */
/*
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;
-/* $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 $ */
/*
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++) {
-/* $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 $ */
/*
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;
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))
#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)
-/* $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 $ */
/*
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;
igmplen = ntohs(ip->ip_len) - iphlen;
+ ifp = if_get(m->m_pkthdr.ph_ifidx);
+ if (ifp == NULL) {
+ m_freem(m);
+ return;
+ }
+
/*
* Validate lengths
*/
-/* $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 $ */
/*
}
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;
-/* $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.
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;
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]) {
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]) {
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
}
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;
}
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;
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;
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);
/*
-/* $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>
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;
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
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;
-/* $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)
*
#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++;
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);
-/* $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 $ */
/*
}
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++;
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;
-/* $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 $ */
/*
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;
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
-/* $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 $ */
/*
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) &&
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]);
-/* $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
/*
* 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
}
/* 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)
-/* $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 $ */
/*
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) &&
-/* $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
}
/* 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. */
* 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);
-/* $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 $ */
/*
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); \
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;
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)) ==
/* 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);
-/* $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 $ */
/*
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)
-/* $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 $ */
/*
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 */
-/* $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 $ */
/*
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;
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;
-/* $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 $ */
/*
#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 */
-/* $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 $ */
/*
* 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 */
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);
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 */
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 */
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);
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);
/*
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;
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);
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 */
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);
-/* $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 $ */
/*
}
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);
-/* $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>
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;
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
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;
-/* $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 $ */
/*
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;
* 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++;
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,
* 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)) {
-/* $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 $ */
/*
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)
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);
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;
}
} /* 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 {
* 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;
-/* $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 $ */
/*
* 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) {
goto done;
}
m->m_flags &= ~M_LOOP; /* XXX */
- m->m_pkthdr.rcvif = NULL;
+ m->m_pkthdr.ph_ifidx = 0;
}
#if NPF > 0
-/* $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 $ */
/*
{
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++;
}
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);
-/* $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 $ */
/*
* 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);
-/* $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 $ */
/*
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;
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++;
}
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)) {
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;
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",
}
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)) {
-/* $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 $ */
/*
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;
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;
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;
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;
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;
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;
-/* $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 $ */
/*
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--;
}
-/* $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>
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;
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;
}
-/* $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 $ */
/*
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,
-/* $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 $ */
/*
}
mb->m_pkthdr.len += authsiz + 10 * NFSX_UNSIGNED;
- mb->m_pkthdr.rcvif = NULL;
+ mb->m_pkthdr.ph_ifidx = 0;
}
/*
-/* $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 $ */
/*
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) {
-/* $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 $ */
/*
/* 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 */
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;
};