Index: kern/kern_mbuf.c =================================================================== --- kern/kern_mbuf.c (revision 223932) +++ kern/kern_mbuf.c (working copy) @@ -399,7 +399,8 @@ m->m_type = type; if (flags & M_PKTHDR) { m->m_data = m->m_pktdat; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; + m->m_pkthdr.rcvif_unique = 0; m->m_pkthdr.header = NULL; m->m_pkthdr.len = 0; m->m_pkthdr.csum_flags = 0; @@ -624,7 +625,8 @@ m->m_type = type; if (flags & M_PKTHDR) { - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; + m->m_pkthdr.rcvif_unique = 0; m->m_pkthdr.len = 0; m->m_pkthdr.header = NULL; m->m_pkthdr.csum_flags = 0; @@ -653,7 +655,8 @@ #endif m->m_data = m->m_pktdat; SLIST_INIT(&m->m_pkthdr.tags); - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; + m->m_pkthdr.rcvif_unique = 0; m->m_pkthdr.header = NULL; m->m_pkthdr.len = 0; m->m_pkthdr.flowid = 0; Index: kern/uipc_mbuf.c =================================================================== --- kern/uipc_mbuf.c (revision 223932) +++ kern/uipc_mbuf.c (working copy) @@ -1135,7 +1135,8 @@ MGETHDR(n, wait, m0->m_type); if (n == NULL) return (NULL); - n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif; + n->m_pkthdr.rcvif_idx = m0->m_pkthdr.rcvif_idx; + n->m_pkthdr.rcvif_unique = m0->m_pkthdr.rcvif_unique; n->m_pkthdr.len = m0->m_pkthdr.len - len0; m0->m_pkthdr.len = len0; if (m->m_flags & M_EXT) @@ -1182,7 +1183,7 @@ * which to begin copying the data to. */ struct mbuf * -m_devget(char *buf, int totlen, int off, struct ifnet *ifp, +m_devget(char *buf, int totlen, int off, void (*copy)(char *from, caddr_t to, u_int len)) { struct mbuf *m; @@ -1209,7 +1210,6 @@ } if (m == NULL) return NULL; - m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = totlen; } else { if (totlen + off >= MINCLSIZE) { Index: netinet/tcp_input.c =================================================================== --- netinet/tcp_input.c (revision 223932) +++ netinet/tcp_input.c (working copy) @@ -817,7 +817,7 @@ inp = in6_pcblookup_mbuf(&V_tcbinfo, &ip6->ip6_src, th->th_sport, &ip6->ip6_dst, th->th_dport, INPLOOKUP_WILDCARD | INPLOOKUP_WLOCKPCB, - m->m_pkthdr.rcvif, m); + mbuf_rcvif(m), m); #endif #if defined(INET) && defined(INET6) else @@ -826,7 +826,7 @@ inp = in_pcblookup_mbuf(&V_tcbinfo, ip->ip_src, th->th_sport, ip->ip_dst, th->th_dport, INPLOOKUP_WILDCARD | INPLOOKUP_WLOCKPCB, - m->m_pkthdr.rcvif, m); + mbuf_rcvif(m), m); #endif } @@ -1304,7 +1304,7 @@ if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || IN_MULTICAST(ntohl(ip->ip_src.s_addr)) || ip->ip_src.s_addr == htonl(INADDR_BROADCAST) || - in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) { + in_broadcast(ip->ip_dst, mbuf_rcvif(m))) { if ((s = tcp_log_addrs(&inc, th, NULL, NULL))) log(LOG_DEBUG, "%s; %s: Listen socket: " "Connection attempt from/to broad- " @@ -3060,7 +3060,7 @@ if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || IN_MULTICAST(ntohl(ip->ip_src.s_addr)) || ip->ip_src.s_addr == htonl(INADDR_BROADCAST) || - in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) + in_broadcast(ip->ip_dst, mbuf_rcvif(m))) goto drop; } #endif Index: netinet/tcp_subr.c =================================================================== --- netinet/tcp_subr.c (revision 223932) +++ netinet/tcp_subr.c (working copy) @@ -589,7 +589,7 @@ #endif m->m_len = tlen; m->m_pkthdr.len = tlen; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; #ifdef MAC if (inp != NULL) { /* Index: netinet/tcp_output.c =================================================================== --- netinet/tcp_output.c (revision 223932) +++ netinet/tcp_output.c (working copy) @@ -891,7 +891,7 @@ m->m_len = hdrlen; } SOCKBUF_UNLOCK_ASSERT(&so->so_snd); - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.rcvif_idx = 0; #ifdef MAC mac_inpcb_create_mbuf(tp->t_inpcb, m); #endif Index: netinet/tcp_syncache.c =================================================================== --- netinet/tcp_syncache.c (revision 223932) +++ netinet/tcp_syncache.c (working copy) @@ -1356,7 +1356,6 @@ m->m_data += max_linkhdr; m->m_len = tlen; m->m_pkthdr.len = tlen; - m->m_pkthdr.rcvif = NULL; #ifdef INET6 if (sc->sc_inc.inc_flags & INC_ISIPV6) { Index: netinet/ip_input.c =================================================================== --- netinet/ip_input.c (revision 223932) +++ netinet/ip_input.c (working copy) @@ -429,7 +429,7 @@ } /* 127/8 must not appear on wire - RFC1122 */ - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { if ((ifp->if_flags & IFF_LOOPBACK) == 0) { @@ -514,7 +514,7 @@ ip = mtod(m, struct ip *); dchg = (odst.s_addr != ip->ip_dst.s_addr); - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); #ifdef IPFIREWALL_FORWARD if (m->m_flags & M_FASTFWD_OURS) { @@ -1457,7 +1457,7 @@ */ dest.s_addr = 0; if (!srcrt && V_ipsendredirects && - ia != NULL && ia->ia_ifp == m->m_pkthdr.rcvif) { + ia != NULL && ia->ia_ifp == mbuf_rcvif(m)) { struct sockaddr_in *sin; struct rtentry *rt; @@ -1665,8 +1665,8 @@ struct sockaddr_dl *sdp; struct sockaddr_dl *sdl2 = &sdlbuf.sdl; - if (((ifp = m->m_pkthdr.rcvif)) - && ( ifp->if_index && (ifp->if_index <= V_if_index))) { + ifp = mbuf_rcvif(m); + if (ifp && (ifp->if_index && (ifp->if_index <= V_if_index))) { sdp = (struct sockaddr_dl *)ifp->if_addr->ifa_addr; /* * Change our mind and don't try copy. Index: netinet/ip6.h =================================================================== --- netinet/ip6.h (revision 223932) +++ netinet/ip6.h (working copy) @@ -293,7 +293,7 @@ } else { \ if ((m)->m_len < (off) + (hlen)) { \ V_ip6stat.ip6s_tooshort++; \ - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \ + in6_ifstat_inc(mbuf_rcvif(m), ifs6_in_truncated); \ m_freem(m); \ return ret; \ } \ Index: netinet/ip_icmp.c =================================================================== --- netinet/ip_icmp.c (revision 223932) +++ netinet/ip_icmp.c (working copy) @@ -306,7 +306,8 @@ 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.rcvif_idx = n->m_pkthdr.rcvif_idx; + m->m_pkthdr.rcvif_unique = n->m_pkthdr.rcvif_unique; nip = mtod(m, struct ip *); bcopy((caddr_t)oip, (caddr_t)nip, sizeof(struct ip)); nip->ip_len = m->m_len; @@ -327,6 +328,7 @@ icmp_input(struct mbuf *m, int off) { struct icmp *icp; + struct ifnet *ifp; struct in_ifaddr *ia; struct ip *ip = mtod(m, struct ip *); struct sockaddr_in icmpsrc, icmpdst, icmpgw; @@ -368,7 +370,7 @@ m->m_len += hlen; m->m_data -= hlen; - if (m->m_pkthdr.rcvif && m->m_pkthdr.rcvif->if_type == IFT_FAITH) { + if ((ifp = mbuf_rcvif(m)) != NULL && ifp->if_type == IFT_FAITH) { /* * Deliver very specific ICMP type only. */ @@ -545,7 +547,7 @@ icmpdst.sin_addr = ip->ip_dst; } ia = (struct in_ifaddr *)ifaof_ifpforaddr( - (struct sockaddr *)&icmpdst, m->m_pkthdr.rcvif); + (struct sockaddr *)&icmpdst, mbuf_rcvif(m)); if (ia == NULL) break; if (ia->ia_ifp == NULL) { @@ -701,7 +703,7 @@ * addresses, use the first non-broadcast address which corresponds * to the incoming interface. */ - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); if (ifp != NULL && ifp->if_flags & IFF_BROADCAST) { IF_ADDR_LOCK(ifp); TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { @@ -874,7 +876,7 @@ icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen); m->m_data -= hlen; m->m_len += hlen; - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.rcvif_idx = 0; #ifdef ICMPPRINTFS if (icmpprintfs) { char buf[4 * sizeof "123"]; Index: netinet/if_ether.c =================================================================== --- netinet/if_ether.c (revision 223932) +++ netinet/if_ether.c (working copy) @@ -503,7 +503,7 @@ in_arpinput(struct mbuf *m) { struct arphdr *ah; - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); struct llentry *la = NULL; struct rtentry *rt; struct ifaddr *ifa; @@ -859,7 +859,7 @@ ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */ m->m_len = sizeof(*ah) + (2 * ah->ar_pln) + (2 * ah->ar_hln); m->m_pkthdr.len = m->m_len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; sa.sa_family = AF_ARP; sa.sa_len = 2; (*ifp->if_output)(ifp, m, &sa, NULL); Index: netinet/udp_usrreq.c =================================================================== --- netinet/udp_usrreq.c (revision 223932) +++ netinet/udp_usrreq.c (working copy) @@ -345,7 +345,7 @@ struct m_tag *fwd_tag; #endif - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); UDPSTAT_INC(udps_ipackets); /* Index: netinet/raw_ip.c =================================================================== --- netinet/raw_ip.c (revision 223932) +++ netinet/raw_ip.c (working copy) @@ -288,7 +288,7 @@ ripsrc.sin_addr = ip->ip_src; last = NULL; - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); hash = INP_PCBHASH_RAW(proto, ip->ip_src.s_addr, ip->ip_dst.s_addr, V_ripcbinfo.ipi_hashmask); Index: netinet/ip_output.c =================================================================== --- netinet/ip_output.c (revision 223932) +++ netinet/ip_output.c (working copy) @@ -517,8 +517,8 @@ /* If destination is now ourself drop to ip_input(). */ if (in_localip(ip->ip_dst)) { m->m_flags |= M_FASTFWD_OURS; - if (m->m_pkthdr.rcvif == NULL) - m->m_pkthdr.rcvif = V_loif; + if (mbuf_rcvif(m) == NULL) + m_set_rcvif(m, V_loif); if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; @@ -821,7 +821,7 @@ goto done; } m->m_pkthdr.len = mhlen + len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; #ifdef MAC mac_netinet_fragment(m0, m); #endif Index: netinet/ip_options.c =================================================================== --- netinet/ip_options.c (revision 223932) +++ netinet/ip_options.c (working copy) @@ -323,7 +323,7 @@ } ipaddr.sin_addr = dst; ia = (INA)ifaof_ifpforaddr((SA)&ipaddr, - m->m_pkthdr.rcvif); + mbuf_rcvif(m)); if (ia == NULL) continue; (void)memcpy(sin, &IA_SIN(ia)->sin_addr, @@ -507,7 +507,7 @@ return (m); } M_MOVE_PKTHDR(n, m); - n->m_pkthdr.rcvif = NULL; + n->m_pkthdr.rcvif_idx = 0; n->m_pkthdr.len += optlen; m->m_len -= sizeof(struct ip); m->m_data += sizeof(struct ip); Index: netinet/ip_fastfwd.c =================================================================== --- netinet/ip_fastfwd.c (revision 223932) +++ netinet/ip_fastfwd.c (working copy) @@ -316,8 +316,9 @@ * let ip_input handle it. We play safe here and let ip_input * deal with it until it is proven that we can directly drop it. */ + ifp = mbuf_rcvif(m); if ((m->m_flags & (M_BCAST|M_MCAST)) || - (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) || + (ifp->if_flags & IFF_LOOPBACK) || ntohl(ip->ip_src.s_addr) == (u_long)INADDR_BROADCAST || ntohl(ip->ip_dst.s_addr) == (u_long)INADDR_BROADCAST || IN_MULTICAST(ntohl(ip->ip_src.s_addr)) || @@ -354,8 +355,7 @@ if (!PFIL_HOOKED(&V_inet_pfil_hook)) goto passin; - if (pfil_run_hooks( - &V_inet_pfil_hook, &m, m->m_pkthdr.rcvif, PFIL_IN, NULL) || + if (pfil_run_hooks(&V_inet_pfil_hook, &m, ifp, PFIL_IN, NULL) || m == NULL) goto drop; Index: netinet/igmp.c =================================================================== --- netinet/igmp.c (revision 223932) +++ netinet/igmp.c (working copy) @@ -1435,7 +1435,7 @@ CTR3(KTR_IGMPV3, "%s: called w/mbuf (%p,%d)", __func__, m, off); - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); IGMPSTAT_INC(igps_rcv_total); @@ -3454,7 +3454,7 @@ igmp_scrub_context(m0); m->m_flags &= ~(M_PROTOFLAGS); - m0->m_pkthdr.rcvif = V_loif; + m_set_rcvif(m0, V_loif); #ifdef MAC mac_netinet_igmp_send(ifp, m0); #endif Index: netgraph/ng_eiface.c =================================================================== --- netgraph/ng_eiface.c (revision 223932) +++ netgraph/ng_eiface.c (working copy) @@ -596,7 +596,7 @@ } /* Note receiving interface */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* Update interface stats */ ifp->if_ipackets++; Index: netgraph/ng_tty.c =================================================================== --- netgraph/ng_tty.c (revision 223932) +++ netgraph/ng_tty.c (working copy) @@ -425,7 +425,6 @@ "%s: can't get mbuf\n", NG_NODE_NAME(node)); return (0); } - m->m_pkthdr.rcvif = NULL; for (mb = m; mb != NULL; mb = mb->m_next) { length = min(M_TRAILINGSPACE(mb), len - total); @@ -484,7 +483,6 @@ return (ENOBUFS); } m->m_len = m->m_pkthdr.len = 0; - m->m_pkthdr.rcvif = NULL; sc->m = m; } Index: netgraph/ng_sppp.c =================================================================== --- netgraph/ng_sppp.c (revision 223932) +++ netgraph/ng_sppp.c (working copy) @@ -366,7 +366,7 @@ SP2IFP(pp)->if_ipackets++; /* Note receiving interface */ - m->m_pkthdr.rcvif = SP2IFP(pp); + m_set_rcvif(m, SP2IFP(pp)); /* Berkeley packet filter */ BPF_MTAP (SP2IFP(pp), m); Index: netgraph/ng_socket.c =================================================================== --- netgraph/ng_socket.c (revision 223932) +++ netgraph/ng_socket.c (working copy) @@ -934,7 +934,7 @@ /* Copy the message itself into an mbuf chain. */ m = m_devget((caddr_t)msg, sizeof(struct ng_mesg) + msg->header.arglen, - 0, NULL, NULL); + 0, NULL); /* * Here we free the message. We need to do that Index: netgraph/ng_bridge.c =================================================================== --- netgraph/ng_bridge.c (revision 223932) +++ netgraph/ng_bridge.c (working copy) @@ -599,7 +599,7 @@ /* Log the problem */ if (priv->conf.debugLevel >= 2) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); char suffix[32]; if (ifp != NULL) Index: netgraph/ng_ether.c =================================================================== --- netgraph/ng_ether.c (revision 223932) +++ netgraph/ng_ether.c (working copy) @@ -679,7 +679,7 @@ (m = m_pullup(m, sizeof(struct ether_header))) == NULL) return (ENOBUFS); - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* Pass the packet to the bridge, it may come back to us */ if (ifp->if_bridge) { Index: netgraph/ng_async.c =================================================================== --- netgraph/ng_async.c (revision 223932) +++ netgraph/ng_async.c (working copy) @@ -417,7 +417,7 @@ } NGI_GET_M(item, m); - rcvif = m->m_pkthdr.rcvif; + rcvif = mbuf_rcvif(m); /* Get ACCM; special case LCP frames, which use full ACCM */ accm = sc->cfg.accm; @@ -475,10 +475,11 @@ sc->abuf[alen++] = PPP_FLAG; /* Put frame in an mbuf and ship it off */ - if (!(m = m_devget(sc->abuf, alen, 0, rcvif, NULL))) { + if (!(m = m_devget(sc->abuf, alen, 0, NULL))) { NG_FREE_ITEM(item); error = ENOBUFS; } else { + m_set_rcvif(m, rcvif); NG_FWD_NEW_DATA(error, item, sc->async, m); } return (error); @@ -501,7 +502,7 @@ return (error); } NGI_GET_M(item, m); - rcvif = m->m_pkthdr.rcvif; + rcvif = mbuf_rcvif(m); while (m) { struct mbuf *n; @@ -540,7 +541,8 @@ /* OK, ship it out */ if ((n = m_devget(sc->sbuf + skip, - sc->slen - skip, 0, rcvif, NULL))) { + sc->slen - skip, 0, NULL))) { + m_set_rcvif(n, rcvif); if (item) { /* sets NULL -> item */ NG_FWD_NEW_DATA(error, item, sc->sync, n); Index: netgraph/ng_vjc.c =================================================================== --- netgraph/ng_vjc.c (revision 223932) +++ netgraph/ng_vjc.c (working copy) @@ -482,7 +482,6 @@ return (ENOBUFS); } hm->m_len = 0; - hm->m_pkthdr.rcvif = NULL; if (hlen > MHLEN) { /* unlikely, but can happen */ MCLGET(hm, M_DONTWAIT); if ((hm->m_flags & M_EXT) == 0) { Index: netgraph/ng_fec.c =================================================================== --- netgraph/ng_fec.c (revision 223932) +++ netgraph/ng_fec.c (working copy) @@ -864,7 +864,7 @@ struct ng_node *node; struct ng_fec_private *priv; struct ng_fec_bundle *b; - struct ifnet *bifp; + struct ifnet *mifp, *bifp; struct ng_fec_portlist *p; /* Sanity check */ @@ -880,9 +880,10 @@ priv = NG_NODE_PRIVATE(node); b = &priv->fec_bundle; bifp = priv->ifp; + mifp = mbuf_rcvif(m0); TAILQ_FOREACH(p, &b->ng_fec_ports, fec_list) { - if (p->fec_if == m0->m_pkthdr.rcvif) + if (p->fec_if == mifp) break; } @@ -897,10 +898,10 @@ * otherwise would not. BPF tapping of our own aggregate * interface will occur once we call ether_input(). */ - BPF_MTAP(m0->m_pkthdr.rcvif, m0); + BPF_MTAP(mifp, m0); /* Convince the system that this is our frame. */ - m0->m_pkthdr.rcvif = bifp; + m_set_rcvif(m0, bifp); /* * Count bytes on an individual interface in a bundle. Index: netgraph/ng_cisco.c =================================================================== --- netgraph/ng_cisco.c (revision 223932) +++ netgraph/ng_cisco.c (working copy) @@ -613,7 +613,6 @@ t = time.tv_sec * 1000 + time.tv_usec / 1000; m->m_pkthdr.len = m->m_len = CISCO_HEADER_LEN + CISCO_PACKET_LEN; - m->m_pkthdr.rcvif = 0; h = mtod(m, struct cisco_header *); h->address = CISCO_MULTICAST; Index: netgraph/ng_iface.c =================================================================== --- netgraph/ng_iface.c (revision 223932) +++ netgraph/ng_iface.c (working copy) @@ -743,7 +743,7 @@ ifp->if_ibytes += m->m_pkthdr.len; /* Note receiving interface */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* Berkeley packet filter */ ng_iface_bpftap(ifp, m, iffam->family); Index: netgraph/netflow/ng_netflow.c =================================================================== --- netgraph/netflow/ng_netflow.c (revision 223932) +++ netgraph/netflow/ng_netflow.c (working copy) @@ -894,8 +894,8 @@ /* Determine packet input interface. Prefer configured. */ src_if_index = 0; if (hook == iface->out || iface->info.ifinfo_index == 0) { - if (m->m_pkthdr.rcvif != NULL) - src_if_index = m->m_pkthdr.rcvif->if_index; + if (m->m_pkthdr.rcvif_idx != 0) + src_if_index = m->m_pkthdr.rcvif_idx; } else src_if_index = iface->info.ifinfo_index; Index: netgraph/ng_lmi.c =================================================================== --- netgraph/ng_lmi.c (revision 223932) +++ netgraph/ng_lmi.c (working copy) @@ -322,7 +322,6 @@ log(LOG_ERR, "nglmi: unable to start up LMI processing\n"); return; } - m->m_pkthdr.rcvif = NULL; /* Attach a tag to packet, marking it of link level state priority, so * that device driver would put it in the beginning of queue */ Index: netgraph/ng_l2tp.c =================================================================== --- netgraph/ng_l2tp.c (revision 223932) +++ netgraph/ng_l2tp.c (working copy) @@ -1527,7 +1527,6 @@ return (ENOBUFS); } m->m_len = m->m_pkthdr.len = 12; - m->m_pkthdr.rcvif = NULL; priv->stats.xmitZLBs++; } else { Index: netgraph/ng_pptpgre.c =================================================================== --- netgraph/ng_pptpgre.c (revision 223932) +++ netgraph/ng_pptpgre.c (working copy) @@ -604,7 +604,6 @@ ERROUT(ENOBUFS); } m->m_len = m->m_pkthdr.len = grelen; - m->m_pkthdr.rcvif = NULL; } else { M_PREPEND(m, grelen, M_DONTWAIT); if (m == NULL || (m->m_len < grelen Index: netgraph/ng_pppoe.c =================================================================== --- netgraph/ng_pppoe.c (revision 223932) +++ netgraph/ng_pppoe.c (working copy) @@ -806,7 +806,6 @@ free(neg, M_NETGRAPH_PPPOE); LEAVE(ENOBUFS); } - neg->m->m_pkthdr.rcvif = NULL; sp->neg = neg; ng_callout_init(&neg->handle); neg->m->m_len = sizeof(struct pppoe_full_hdr); @@ -1746,7 +1745,6 @@ int msglen = strlen(SIGNOFF); int error = 0; - m->m_pkthdr.rcvif = NULL; m->m_pkthdr.len = m->m_len = sizeof(*wh); wh = mtod(m, struct pppoe_full_hdr *); bcopy(&sp->pkt_hdr, wh, sizeof(*wh)); Index: dev/e1000/if_igb.c =================================================================== --- dev/e1000/if_igb.c (revision 223932) +++ dev/e1000/if_igb.c (working copy) @@ -4542,7 +4542,7 @@ } if (eop) { - rxr->fmp->m_pkthdr.rcvif = ifp; + m_set_rcvif(rxr->fmp, ifp); ifp->if_ipackets++; rxr->rx_packets++; /* capture data for AIM */ Index: dev/e1000/if_lem.c =================================================================== --- dev/e1000/if_lem.c (revision 223932) +++ dev/e1000/if_lem.c (working copy) @@ -3497,7 +3497,7 @@ } if (eop) { - adapter->fmp->m_pkthdr.rcvif = ifp; + m_set_rcvif(adapter->fmp, ifp); ifp->if_ipackets++; lem_receive_checksum(adapter, current_desc, adapter->fmp); Index: dev/e1000/if_em.c =================================================================== --- dev/e1000/if_em.c (revision 223932) +++ dev/e1000/if_em.c (working copy) @@ -4299,7 +4299,7 @@ if (eop) { --count; sendmp = rxr->fmp; - sendmp->m_pkthdr.rcvif = ifp; + m_set_rcvif(sendmp, ifp); ifp->if_ipackets++; em_receive_checksum(cur, sendmp); #ifndef __NO_STRICT_ALIGNMENT Index: dev/age/if_age.c =================================================================== --- dev/age/if_age.c (revision 223932) +++ dev/age/if_age.c (working copy) @@ -2347,7 +2347,7 @@ m = sc->age_cdata.age_rxhead; m->m_flags |= M_PKTHDR; - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); m->m_pkthdr.len = sc->age_cdata.age_rxlen; /* Set the first mbuf length. */ m->m_len = sc->age_cdata.age_rxlen - pktlen; Index: dev/ae/if_ae.c =================================================================== --- dev/ae/if_ae.c (revision 223932) +++ dev/ae/if_ae.c (working copy) @@ -1897,9 +1897,10 @@ return (EIO); } - m = m_devget(&rxd->data[0], size, ETHER_ALIGN, ifp, NULL); + m = m_devget(&rxd->data[0], size, ETHER_ALIGN, NULL); if (m == NULL) return (ENOBUFS); + m_set_rcvif(m, ifp); if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 && (flags & AE_RXD_HAS_VLAN) != 0) { Index: dev/an/if_an.c =================================================================== --- dev/an/if_an.c (revision 223932) +++ dev/an/if_an.c (working copy) @@ -957,7 +957,7 @@ ifp->if_ierrors++; return; } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* Read Ethernet encapsulated packet */ #ifdef ANCACHE @@ -1048,7 +1048,7 @@ ifp->if_ierrors++; return; } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* Read Ethernet encapsulated packet */ /* Index: dev/alc/if_alc.c =================================================================== --- dev/alc/if_alc.c (revision 223932) +++ dev/alc/if_alc.c (working copy) @@ -3020,7 +3020,7 @@ } } else m->m_len = m->m_pkthdr.len; - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* * Due to hardware bugs, Rx checksum offloading * was intentionally disabled. Index: dev/ale/if_ale.c =================================================================== --- dev/ale/if_ale.c (revision 223932) +++ dev/ale/if_ale.c (working copy) @@ -2566,12 +2566,13 @@ * on these low-end consumer ethernet controller. */ m = m_devget((char *)(rs + 1), length - ETHER_CRC_LEN, - ETHER_ALIGN, ifp, NULL); + ETHER_ALIGN, NULL); if (m == NULL) { ifp->if_iqdrops++; ale_rx_update_page(sc, &rx_page, length, &prod); continue; } + m_set_rcvif(m, ifp); if ((ifp->if_capenable & IFCAP_RXCSUM) != 0 && (status & ALE_RD_IPV4) != 0) ale_rxcsum(sc, m, status); Index: dev/ath/if_ath.c =================================================================== --- dev/ath/if_ath.c (revision 223932) +++ dev/ath/if_ath.c (working copy) @@ -3588,7 +3588,7 @@ sc->sc_stats.ast_rx_toobig++; m_freem(sc->sc_rxpending); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); m->m_pkthdr.len = len; sc->sc_rxpending = m; goto rx_next; @@ -3607,7 +3607,7 @@ * Normal single-descriptor receive; setup * the rcvif and packet length. */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); m->m_pkthdr.len = len; } Index: net/if.c =================================================================== --- net/if.c (revision 223932) +++ net/if.c (working copy) @@ -186,12 +186,14 @@ VNET_DEFINE(struct ifgrouphead, ifg_head); static VNET_DEFINE(int, if_indexlim) = 8; +static VNET_DEFINE(u_int, if_unique) = 1; /* Table of ifnet by index. */ VNET_DEFINE(struct ifindex_entry *, ifindex_table); #define V_if_indexlim VNET(if_indexlim) #define V_ifindex_table VNET(ifindex_table) +#define V_if_unique VNET(if_unique) /* * The global network interface list (V_ifnet) and related state (such as @@ -257,6 +259,58 @@ return (ifp); } +struct ifnet * +mbuf_rcvif(struct mbuf *m) +{ + struct ifnet *ifp; + + M_ASSERTPKTHDR(m); + + if (m->m_pkthdr.rcvif_idx == 0) + return (NULL); + + /* + * XXXGL: since we do not put a ref on ifnet, there + * is no reason to use locking. + */ + ifp = ifnet_byindex_locked(m->m_pkthdr.rcvif_idx); + if (ifp == NULL) + return (NULL); + if (ifp->if_unique != m->m_pkthdr.rcvif_unique) + return (NULL); + + return (ifp); +} + +struct ifnet * +mbuf_rcvif_ref(struct mbuf *m) +{ + struct ifnet *ifp; + + M_ASSERTPKTHDR(m); + + if (m->m_pkthdr.rcvif_idx == 0) + return (NULL); + + ifp = ifnet_byindex_ref(m->m_pkthdr.rcvif_idx); + if (ifp == NULL) + return (NULL); + if (ifp->if_unique != m->m_pkthdr.rcvif_unique) { + if_rele(ifp); + return (NULL); + } + + return (ifp); +} + +void +m_set_rcvif(struct mbuf *m, struct ifnet *ifp) +{ + + m->m_pkthdr.rcvif_idx = ifp->if_index; + m->m_pkthdr.rcvif_unique = ifp->if_unique; +} + /* * Allocate an ifindex array entry; return 0 on success or an error on * failure. @@ -435,6 +489,7 @@ return (NULL); } ifnet_setbyindex_locked(idx, IFNET_HOLD); + ifp->if_unique = V_if_unique++; IFNET_WUNLOCK(); ifp->if_index = idx; ifp->if_type = type; Index: net/if_disc.c =================================================================== --- net/if_disc.c (revision 223932) +++ net/if_disc.c (working copy) @@ -172,7 +172,7 @@ u_int af = dst->sa_family; bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); ifp->if_opackets++; ifp->if_obytes += m->m_pkthdr.len; Index: net/netisr.c =================================================================== --- net/netisr.c (revision 223932) +++ net/netisr.c (working copy) @@ -744,7 +744,7 @@ ("%s: invalid policy %u for %s", __func__, npp->np_policy, npp->np_name)); - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); if (ifp != NULL) *cpuidp = nws_array[(ifp->if_index + source) % nws_count]; else @@ -795,14 +795,17 @@ nwsp->nws_pendingbits &= ~(1 << proto); NWS_UNLOCK(nwsp); while ((m = local_npw.nw_head) != NULL) { + struct ifnet *ifp; + local_npw.nw_head = m->m_nextpkt; m->m_nextpkt = NULL; if (local_npw.nw_head == NULL) local_npw.nw_tail = NULL; local_npw.nw_len--; - VNET_ASSERT(m->m_pkthdr.rcvif != NULL, - ("%s:%d rcvif == NULL: m=%p", __func__, __LINE__, m)); - CURVNET_SET(m->m_pkthdr.rcvif->if_vnet); + ifp = mbuf_rcvif(m); + VNET_ASSERT(ifp != NULL, + ("%s:%d no rcvif: m=%p", __func__, __LINE__, m)); + CURVNET_SET(ifp->if_vnet); netisr_proto[proto].np_handler(m); CURVNET_RESTORE(); } Index: net/bpf.c =================================================================== --- net/bpf.c (revision 223932) +++ net/bpf.c (working copy) @@ -500,7 +500,7 @@ #endif (len <= MJUM9BYTES ? MJUM9BYTES : MJUM16BYTES)); m->m_pkthdr.len = m->m_len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; *mp = m; if (m->m_len < hlen) { @@ -924,7 +924,7 @@ if (d->bd_feedback) { mc = m_dup(m, M_DONTWAIT); if (mc != NULL) - mc->m_pkthdr.rcvif = ifp; + m_set_rcvif(mc, ifp); /* Set M_PROMISC for outgoing packets to be discarded. */ if (d->bd_direction == BPF_D_INOUT) m->m_flags |= M_PROMISC; @@ -1870,7 +1870,7 @@ int gottime; /* Skip outgoing duplicate packets. */ - if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) { + if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif_idx == 0) { m->m_flags &= ~M_PROMISC; return; } @@ -1880,7 +1880,8 @@ gottime = BPF_TSTAMP_NONE; BPFIF_LOCK(bp); LIST_FOREACH(d, &bp->bif_dlist, bd_next) { - if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp)) + if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif_idx, + bp->bif_ifp->if_index)) continue; BPFD_LOCK(d); ++d->bd_rcount; @@ -1921,7 +1922,7 @@ int gottime; /* Skip outgoing duplicate packets. */ - if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) { + if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif_idx == 0) { m->m_flags &= ~M_PROMISC; return; } @@ -1940,7 +1941,8 @@ gottime = BPF_TSTAMP_NONE; BPFIF_LOCK(bp); LIST_FOREACH(d, &bp->bif_dlist, bd_next) { - if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp)) + if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif_idx, + bp->bif_ifp->if_index)) continue; BPFD_LOCK(d); ++d->bd_rcount; Index: net/if_stf.c =================================================================== --- net/if_stf.c (revision 223932) +++ net/if_stf.c (working copy) @@ -726,7 +726,7 @@ * for source, perform ingress filter as well. */ if (stf_checkaddr4(sc, &ip->ip_dst, NULL) < 0 || - stf_checkaddr4(sc, &ip->ip_src, m->m_pkthdr.rcvif) < 0) { + stf_checkaddr4(sc, &ip->ip_src, mbuf_rcvif(m)) < 0) { m_freem(m); return; } @@ -746,7 +746,7 @@ * for source, perform ingress filter as well. */ if (stf_checkaddr6(sc, &ip6->ip6_dst, NULL) < 0 || - stf_checkaddr6(sc, &ip6->ip6_src, m->m_pkthdr.rcvif) < 0) { + stf_checkaddr6(sc, &ip6->ip6_src, mbuf_rcvif(m)) < 0) { m_freem(m); return; } @@ -759,7 +759,7 @@ ip6->ip6_flow &= ~htonl(0xff << 20); ip6->ip6_flow |= htonl((u_int32_t)itos << 20); - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); if (bpf_peers_present(ifp->if_bpf)) { /* Index: net/if_atmsubr.c =================================================================== --- net/if_atmsubr.c (revision 223932) +++ net/if_atmsubr.c (working copy) @@ -279,7 +279,7 @@ npcb = rxhand; npcb->npcb_inq++; /* count # in queue */ isr = NETISR_NATM; - m->m_pkthdr.rcvif = rxhand; /* XXX: overload */ + m_set_rcvif(m, rxhand); /* XXX: overload */ NATM_UNLOCK(); #else printf("atm_input: NATM detected but not " Index: net/if_ef.c =================================================================== --- net/if_ef.c (revision 223932) +++ net/if_ef.c (working copy) @@ -364,7 +364,7 @@ if ((eifp->if_flags & IFF_UP) == 0) return EPROTONOSUPPORT; eifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); - m->m_pkthdr.rcvif = eifp; + m_set_rcvif(m, eifp); BPF_MTAP2(eifp, eh, ETHER_HDR_LEN, m); /* Index: net/if_bridge.c =================================================================== --- net/if_bridge.c (revision 223932) +++ net/if_bridge.c (working copy) @@ -2009,7 +2009,7 @@ uint8_t *dst; int error; - src_if = m->m_pkthdr.rcvif; + src_if = mbuf_rcvif(m); ifp = sc->sc_ifp; ifp->if_ipackets++; @@ -2171,7 +2171,7 @@ * packet counters associated with this interface. */ if ((bifp->if_flags & IFF_MONITOR) != 0) { - m->m_pkthdr.rcvif = bifp; + m_set_rcvif(m, bifp); ETHER_BPF_MTAP(bifp, m); bifp->if_ipackets++; bifp->if_ibytes += m->m_pkthdr.len; @@ -2235,7 +2235,7 @@ mc2 = m_copyup(mc2, i, ETHER_ALIGN); } if (mc2 != NULL) { - mc2->m_pkthdr.rcvif = bifp; + m_set_rcvif(mc2, bifp); (*bifp->if_input)(bifp, mc2); } @@ -2298,7 +2298,7 @@ return (NULL); \ } \ } \ - m->m_pkthdr.rcvif = iface; \ + m_set_rcvif(m, iface); \ BRIDGE_UNLOCK(sc); \ return (m); \ } \ @@ -3356,7 +3356,10 @@ { struct mbuf *m = *mp; struct ip6_hdr *ip6; + struct ifnet *inifp; + inifp = mbuf_rcvif(m); + /* * If the IPv6 header is not aligned, slurp it up into a new * mbuf with space for link headers, in the event we forward @@ -3364,7 +3367,6 @@ * IPv6 header is in the first mbuf of the chain. */ if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) { - struct ifnet *inifp = m->m_pkthdr.rcvif; if ((m = m_copyup(m, sizeof(struct ip6_hdr), (max_linkhdr + 3) & ~3)) == NULL) { /* XXXJRT new stat, please */ @@ -3373,7 +3375,6 @@ goto bad; } } else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) { - struct ifnet *inifp = m->m_pkthdr.rcvif; if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) { V_ip6stat.ip6s_toosmall++; in6_ifstat_inc(inifp, ifs6_in_hdrerr); @@ -3385,7 +3386,7 @@ if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { V_ip6stat.ip6s_badvers++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); + in6_ifstat_inc(inifp, ifs6_in_hdrerr); goto bad; } Index: net/bridgestp.c =================================================================== --- net/bridgestp.c (revision 223932) +++ net/bridgestp.c (working copy) @@ -238,7 +238,7 @@ if (m == NULL) return; - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); m->m_pkthdr.len = sizeof(*eh) + sizeof(bpdu); m->m_len = m->m_pkthdr.len; @@ -382,7 +382,7 @@ default: panic("not implemented"); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); m->m_len = m->m_pkthdr.len; bp->bp_txcount++; Index: net/if_fwsubr.c =================================================================== --- net/if_fwsubr.c (revision 223932) +++ net/if_fwsubr.c (working copy) @@ -534,16 +534,16 @@ m_adj(m, sizeof(uint32_t)); } - if (m->m_pkthdr.rcvif == NULL) { + if (mbuf_rcvif(m) == NULL) { if_printf(ifp, "discard frame w/o interface pointer\n"); ifp->if_ierrors++; m_freem(m); return; } #ifdef DIAGNOSTIC - if (m->m_pkthdr.rcvif != ifp) { - if_printf(ifp, "Warning, frame marked as received on %s\n", - m->m_pkthdr.rcvif->if_xname); + if (mbuf_rcvif(m) != ifp) { + if_printf(ifp, "Warning, frame marked as received on %u\n", + m->m_pkthdr.rcvif_idx); } #endif Index: net/if_vlan.c =================================================================== --- net/if_vlan.c (revision 223932) +++ net/if_vlan.c (working copy) @@ -1162,7 +1162,7 @@ } TRUNK_RUNLOCK(trunk); - m->m_pkthdr.rcvif = ifv->ifv_ifp; + m_set_rcvif(m, ifv->ifv_ifp); ifv->ifv_ifp->if_ipackets++; /* Pass it back through the parent's input routine. */ Index: net/if_ethersubr.c =================================================================== --- net/if_ethersubr.c (revision 223932) +++ net/if_ethersubr.c (working copy) @@ -598,16 +598,16 @@ } eh = mtod(m, struct ether_header *); etype = ntohs(eh->ether_type); - if (m->m_pkthdr.rcvif == NULL) { - if_printf(ifp, "discard frame w/o interface pointer\n"); + if (m->m_pkthdr.rcvif_idx == 0) { + if_printf(ifp, "discard frame w/o interface index\n"); ifp->if_ierrors++; m_freem(m); return; } #ifdef DIAGNOSTIC - if (m->m_pkthdr.rcvif != ifp) { - if_printf(ifp, "Warning, frame marked as received on %s\n", - m->m_pkthdr.rcvif->if_xname); + if (mbuf_rcvif(m) != ifp) { + if_printf(ifp, "Warning, frame marked as received on %u\n", + m->m_pkthdr.rcvif_idx); } #endif @@ -659,7 +659,7 @@ ("%s: if_lagg not loaded!", __func__)); m = (*lagg_input_p)(ifp, m); if (m != NULL) - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); else return; } @@ -764,7 +764,7 @@ ether_nh_input(struct mbuf *m) { - ether_input_internal(m->m_pkthdr.rcvif, m); + ether_input_internal(mbuf_rcvif(m), m); } static struct netisr_handler ether_nh = { @@ -791,7 +791,7 @@ * We will rely on rcvif being set properly in the deferred context, * so assert it is correct here. */ - KASSERT(m->m_pkthdr.rcvif == ifp, ("%s: ifnet mismatch", __func__)); + KASSERT(mbuf_rcvif(m) == ifp, ("%s: ifnet mismatch", __func__)); netisr_dispatch(NETISR_ETHER, m); } Index: net/if_gif.c =================================================================== --- net/if_gif.c (revision 223932) +++ net/if_gif.c (working copy) @@ -499,7 +499,7 @@ return; } sc = ifp->if_softc; - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); #ifdef MAC mac_ifnet_create_mbuf(ifp, m); @@ -572,7 +572,7 @@ m_adj(m, sizeof(struct etherip_header)); m->m_flags &= ~(M_BCAST|M_MCAST); - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); if (ifp->if_bridge) { oldifp = ifp; Index: net/if_loop.c =================================================================== --- net/if_loop.c (revision 223932) +++ net/if_loop.c (working copy) @@ -282,7 +282,7 @@ M_ASSERTPKTHDR(m); m_tag_delete_nonpersistent(m); - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); #ifdef MAC mac_ifnet_create_mbuf(ifp, m); Index: net/if_tap.c =================================================================== --- net/if_tap.c (revision 223932) +++ net/if_tap.c (working copy) @@ -924,7 +924,7 @@ return (ENOBUFS); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); /* * Only pass a unicast frame to ether_input(), if it would actually Index: net/rtsock.c =================================================================== --- net/rtsock.c (revision 223932) +++ net/rtsock.c (working copy) @@ -1020,7 +1020,7 @@ if (m == NULL) return (m); m->m_pkthdr.len = m->m_len = len; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; rtm = mtod(m, struct rt_msghdr *); bzero((caddr_t)rtm, len); for (i = 0; i < RTAX_MAX; i++) { @@ -1374,7 +1374,7 @@ } #ifdef VIMAGE if (V_loif) - m->m_pkthdr.rcvif = V_loif; + m_set_rcvif(m, V_loif); else { m_freem(m); return; Index: net/if_faith.c =================================================================== --- net/if_faith.c (revision 223932) +++ net/if_faith.c (working copy) @@ -237,7 +237,7 @@ /* XXX do we need more sanity checks? */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); ifp->if_ipackets++; ifp->if_ibytes += m->m_pkthdr.len; netisr_dispatch(isr, m); Index: net/if_iso88025subr.c =================================================================== --- net/if_iso88025subr.c (revision 223932) +++ net/if_iso88025subr.c (working copy) @@ -467,7 +467,7 @@ m_freem(m); return; } - if (m->m_pkthdr.rcvif == NULL) { + if (mbuf_rcvif(m) == NULL) { if_printf(ifp, "discard frame w/o interface pointer\n"); ifp->if_ierrors++; m_freem(m); Index: net/if_var.h =================================================================== --- net/if_var.h (revision 223932) +++ net/if_var.h (working copy) @@ -142,6 +142,7 @@ struct bpf_if *if_bpf; /* packet filter structure */ u_short if_index; /* numeric abbreviation for this if */ short if_index_reserved; /* spare space to grow if_index */ + u_int if_unique; /* unique id */ struct ifvlantrunk *if_vlantrunk; /* pointer to 802.1q data */ int if_flags; /* up/down, broadcast, etc. */ int if_capabilities; /* interface features & capabilities */ @@ -206,7 +207,7 @@ char if_cspare[3]; char *if_description; /* interface description */ void *if_pspare[7]; - int if_ispare[4]; + int if_ispare[3]; }; typedef void if_init_f_t(void *); Index: net/if_epair.c =================================================================== --- net/if_epair.c (revision 223932) +++ net/if_epair.c (working copy) @@ -250,7 +250,7 @@ struct ifnet *ifp; struct epair_softc *sc; - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); (*ifp->if_input)(ifp, m); sc = ifp->if_softc; EPAIR_REFCOUNT_RELEASE(&sc->refcount); @@ -264,7 +264,7 @@ epair_nh_m2cpuid(struct mbuf *m, uintptr_t source, u_int *cpuid) { - *cpuid = cpuid_from_ifp(m->m_pkthdr.rcvif); + *cpuid = cpuid_from_ifp(mbuf_rcvif(m)); return (m); } @@ -430,7 +430,7 @@ * packet is in transit as we rely on rcvif to stay valid. */ EPAIR_REFCOUNT_AQUIRE(&sc->refcount); - m->m_pkthdr.rcvif = oifp; + m_set_rcvif(m, oifp); CURVNET_SET_QUIET(oifp->if_vnet); error = netisr_queue(NETISR_EPAIR, m); CURVNET_RESTORE(); @@ -552,7 +552,7 @@ * packet is in transit as we rely on rcvif to stay valid. */ EPAIR_REFCOUNT_AQUIRE(&sc->refcount); - m->m_pkthdr.rcvif = oifp; + m_set_rcvif(m, oifp); CURVNET_SET_QUIET(oifp->if_vnet); error = netisr_queue(NETISR_EPAIR, m); CURVNET_RESTORE(); Index: net/if_fddisubr.c =================================================================== --- net/if_fddisubr.c (revision 223932) +++ net/if_fddisubr.c (working copy) @@ -378,7 +378,7 @@ m_freem(m); return; } - if (m->m_pkthdr.rcvif == NULL) { + if (mbuf_rcvif(m) == NULL) { if_printf(ifp, "discard frame w/o interface pointer\n"); ifp->if_ierrors++; m_freem(m); Index: net/if_tun.c =================================================================== --- net/if_tun.c (revision 223932) +++ net/if_tun.c (working copy) @@ -877,7 +877,7 @@ return (ENOBUFS); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); #ifdef MAC mac_ifnet_create_mbuf(ifp, m); #endif Index: net/if_spppfr.c =================================================================== --- net/if_spppfr.c (revision 223932) +++ net/if_spppfr.c (working copy) @@ -384,7 +384,7 @@ MGETHDR (m, M_DONTWAIT, MT_DATA); if (! m) return; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.rcvif_idx = 0; h = mtod (m, u_char*); p = h; @@ -505,7 +505,7 @@ if (! m) return; m->m_pkthdr.len = m->m_len = 10 + sizeof (*reply); - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.rcvif_idx = 0; h = mtod (m, u_char*); reply = (struct arp_req*) (h + 10); Index: net/if_lagg.c =================================================================== --- net/if_lagg.c (revision 223932) +++ net/if_lagg.c (working copy) @@ -1524,7 +1524,7 @@ struct ifnet *ifp = sc->sc_ifp; /* Just pass in the packet to our lagg device */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); return (m); } @@ -1573,7 +1573,7 @@ struct lagg_port *tmp_tp; if (lp == sc->sc_primary || lagg_failover_rx_all) { - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); return (m); } @@ -1584,7 +1584,7 @@ * our links are down. Weird, but process it anyways. */ if ((tmp_tp == NULL || tmp_tp == lp)) { - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); return (m); } } @@ -1701,7 +1701,7 @@ struct ifnet *ifp = sc->sc_ifp; /* Just pass in the packet to our lagg device */ - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); return (m); } @@ -1810,6 +1810,6 @@ return (NULL); } - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); return (m); } Index: net/if_bridgevar.h =================================================================== --- net/if_bridgevar.h (revision 223932) +++ net/if_bridgevar.h (working copy) @@ -311,7 +311,7 @@ ("%s: if_bridge not loaded!", __func__)); \ _m = (*bridge_input_p)(_ifp, _m); \ if (_m != NULL) \ - _ifp = _m->m_pkthdr.rcvif; \ + _ifp = mbuf_rcvif(_m); \ } while (0) #define BRIDGE_OUTPUT(_ifp, _m, _err) do { \ Index: net/if_spppsubr.c =================================================================== --- net/if_spppsubr.c (revision 223932) +++ net/if_spppsubr.c (working copy) @@ -1416,7 +1416,7 @@ if (! m) return; m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.rcvif_idx = 0; h = mtod (m, struct ppp_header*); h->address = CISCO_MULTICAST; @@ -1464,7 +1464,7 @@ if (! m) return; m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.rcvif_idx = 0; h = mtod (m, struct ppp_header*); h->address = PPP_ALLSTATIONS; /* broadcast address */ @@ -4767,7 +4767,7 @@ MGETHDR (m, M_DONTWAIT, MT_DATA); if (! m) return; - m->m_pkthdr.rcvif = 0; + m->m_pkthdr.rcvif_idx = 0; h = mtod (m, struct ppp_header*); h->address = PPP_ALLSTATIONS; /* broadcast address */ Index: netinet6/raw_ip6.c =================================================================== --- netinet6/raw_ip6.c (revision 223932) +++ netinet6/raw_ip6.c (working copy) @@ -170,7 +170,7 @@ init_sin6(&fromsa, m); /* general init */ - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); INP_INFO_RLOCK(&V_ripcbinfo); LIST_FOREACH(in6p, &V_ripcb, inp_list) { Index: netinet6/ip6_output.c =================================================================== --- netinet6/ip6_output.c (revision 223932) +++ netinet6/ip6_output.c (working copy) @@ -737,7 +737,7 @@ * some versions of MGETHDR() does not * initialize the field. */ - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; if (ip6_mforward(ip6, ifp, m) != 0) { m_freem(m); goto done; @@ -823,7 +823,7 @@ * contiguous unless the flag is set. */ m->m_flags |= M_LOOP; - m->m_pkthdr.rcvif = ifp; + m_set_rcvif(m, ifp); if (ip6_process_hopopts(m, (u_int8_t *)(hbh + 1), ((hbh->ip6h_len + 1) << 3) - sizeof(struct ip6_hbh), &dummy, &plen) < 0) { @@ -832,7 +832,7 @@ goto done; } m->m_flags &= ~M_LOOP; /* XXX */ - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; } /* Jump over all PFIL processing if hooks are not active. */ @@ -851,8 +851,8 @@ m->m_flags |= M_SKIP_FIREWALL; /* If destination is now ourself drop to ip6_input(). */ if (in6_localaddr(&ip6->ip6_dst)) { - if (m->m_pkthdr.rcvif == NULL) - m->m_pkthdr.rcvif = V_loif; + if (mbuf_rcvif(m) == NULL) + m_set_rcvif(m, V_loif); if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; @@ -1031,7 +1031,7 @@ V_ip6stat.ip6s_odropped++; goto sendorfree; } - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; m->m_flags = m0->m_flags & M_COPYFLAGS; *mnext = m; mnext = &m->m_nextpkt; @@ -1058,7 +1058,7 @@ } m_cat(m, m_frgpart); m->m_pkthdr.len = len + hlen + sizeof(*ip6f); - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; ip6f->ip6f_reserved = 0; ip6f->ip6f_ident = id; ip6f->ip6f_nxt = nextproto; Index: netinet6/icmp6.c =================================================================== --- netinet6/icmp6.c (revision 223932) +++ netinet6/icmp6.c (working copy) @@ -384,10 +384,10 @@ * icmp6_reflect() is designed to be in the input path. * icmp6_error() can be called from both input and output 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 + * clear m->m_pkthdr.rcvif_idx for safety, we should have enough scope * information in ip header (nip6). */ - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; ICMP6STAT_INC(icp6s_outhist[type]); icmp6_reflect(m, sizeof(struct ip6_hdr)); /* header order: IPv6 - ICMPv6 */ @@ -417,7 +417,7 @@ char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN]; int ip6len, error; - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); #ifndef PULLDOWN_TEST IP6_EXTHDR_CHECK(m, off, sizeof(struct icmp6_hdr), IPPROTO_DONE); @@ -446,7 +446,7 @@ inm = in6m_lookup(ifp, &ip6->ip6_dst); if (inm == NULL) { IP6STAT_INC(ip6s_notmember); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); + in6_ifstat_inc(mbuf_rcvif(m), ifs6_in_discard); goto freeit; } } @@ -722,7 +722,7 @@ /* Give up remote */ break; } - n->m_pkthdr.rcvif = NULL; + n->m_pkthdr.rcvif_idx = 0; n->m_len = 0; maxhlen = M_TRAILINGSPACE(n) - maxlen; pr = curthread->td_ucred->cr_prison; @@ -1006,6 +1006,7 @@ struct ip6_frag *fh; struct ip6_rthdr *rth; struct ip6_rthdr0 *rth0; + struct ifnet *ifp; int rthlen; while (1) { /* XXX: should avoid infinite loop explicitly? */ @@ -1156,13 +1157,14 @@ icmp6dst.sin6_addr = eip6->ip6_dst; else icmp6dst.sin6_addr = *finaldst; - if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL)) + ifp = mbuf_rcvif(m); + if (in6_setscope(&icmp6dst.sin6_addr, ifp, NULL)) goto freeit; bzero(&icmp6src, sizeof(icmp6src)); icmp6src.sin6_len = sizeof(struct sockaddr_in6); icmp6src.sin6_family = AF_INET6; icmp6src.sin6_addr = eip6->ip6_src; - if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL)) + if (in6_setscope(&icmp6src.sin6_addr, ifp, NULL)) goto freeit; icmp6src.sin6_flowinfo = (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); @@ -1244,7 +1246,7 @@ bzero(&inc, sizeof(inc)); inc.inc_flags |= INC_ISIPV6; inc.inc6_faddr = *dst; - if (in6_setscope(&inc.inc6_faddr, m->m_pkthdr.rcvif, NULL)) + if (in6_setscope(&inc.inc6_faddr, mbuf_rcvif(m), NULL)) return; if (mtu < tcp_maxmtu6(&inc, NULL)) { @@ -1390,7 +1392,7 @@ /* m_pulldown instead of copy? */ m_copydata(m, off + sizeof(struct icmp6_nodeinfo), subjlen, (caddr_t)&in6_subj); - if (in6_setscope(&in6_subj, m->m_pkthdr.rcvif, NULL)) + if (in6_setscope(&in6_subj, mbuf_rcvif(m), NULL)) goto bad; subj = (char *)&in6_subj; @@ -2157,7 +2159,7 @@ struct in6_ifaddr *ia = NULL; int plen; int type, code; - struct ifnet *outif = NULL; + struct ifnet *ifp, *outif = NULL; struct in6_addr origdst, src, *srcp = NULL; /* too short to reflect */ @@ -2285,9 +2287,9 @@ ip6->ip6_nxt = IPPROTO_ICMPV6; if (outif) ip6->ip6_hlim = ND_IFINFO(outif)->chlim; - else if (m->m_pkthdr.rcvif) { + else if ((ifp = mbuf_rcvif(m)) != NULL) { /* XXX: This may not be the outgoing interface */ - ip6->ip6_hlim = ND_IFINFO(m->m_pkthdr.rcvif)->chlim; + ip6->ip6_hlim = ND_IFINFO(ifp)->chlim; } else ip6->ip6_hlim = V_ip6_defhlim; @@ -2369,7 +2371,7 @@ if (!m) return; - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); if (!ifp) return; @@ -2393,8 +2395,8 @@ redtgt6 = nd_rd->nd_rd_target; reddst6 = nd_rd->nd_rd_dst; - if (in6_setscope(&redtgt6, m->m_pkthdr.rcvif, NULL) || - in6_setscope(&reddst6, m->m_pkthdr.rcvif, NULL)) { + if (in6_setscope(&redtgt6, ifp, NULL) || + in6_setscope(&reddst6, ifp, NULL)) { goto freeit; } @@ -2613,7 +2615,6 @@ MCLGET(m, M_DONTWAIT); if (!m) goto fail; - m->m_pkthdr.rcvif = NULL; m->m_len = 0; maxlen = M_TRAILINGSPACE(m); maxlen = min(IPV6_MMTU, maxlen); Index: netinet6/udp6_usrreq.c =================================================================== --- netinet6/udp6_usrreq.c (revision 223932) +++ netinet6/udp6_usrreq.c (working copy) @@ -182,7 +182,7 @@ int plen, ulen; struct sockaddr_in6 fromsa; - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); ip6 = mtod(m, struct ip6_hdr *); if (faithprefix_p != NULL && (*faithprefix_p)(&ip6->ip6_dst)) { @@ -379,7 +379,7 @@ */ inp = in6_pcblookup_mbuf(&V_udbinfo, &ip6->ip6_src, uh->uh_sport, &ip6->ip6_dst, uh->uh_dport, INPLOOKUP_WILDCARD | - INPLOOKUP_RLOCKPCB, m->m_pkthdr.rcvif, m); + INPLOOKUP_RLOCKPCB, mbuf_rcvif(m), m); if (inp == NULL) { if (udp_log_in_vain) { char ip6bufs[INET6_ADDRSTRLEN]; Index: netinet6/ip6_forward.c =================================================================== --- netinet6/ip6_forward.c (revision 223932) +++ netinet6/ip6_forward.c (working copy) @@ -139,7 +139,7 @@ ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst), ip6->ip6_nxt, - if_name(m->m_pkthdr.rcvif)); + if_name(mbuf_rcvif(m))); } m_freem(m); return; @@ -357,7 +357,7 @@ RT_UNLOCK(rin6.ro_rt); else { V_ip6stat.ip6s_noroute++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_noroute); + in6_ifstat_inc(mbuf_rcvif(m), ifs6_in_noroute); if (mcopy) { icmp6_error(mcopy, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE, 0); @@ -385,7 +385,7 @@ V_ip6stat.ip6s_badscope++; goto bad; } - if (in6_setscope(&src_in6, m->m_pkthdr.rcvif, &inzone)) { + if (in6_setscope(&src_in6, mbuf_rcvif(m), &inzone)) { V_ip6stat.ip6s_cantforward++; V_ip6stat.ip6s_badscope++; goto bad; @@ -407,7 +407,7 @@ ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst), ip6->ip6_nxt, - if_name(m->m_pkthdr.rcvif), if_name(rt->rt_ifp)); + if_name(mbuf_rcvif(m)), if_name(rt->rt_ifp)); } if (mcopy) icmp6_error(mcopy, ICMP6_DST_UNREACH, @@ -423,7 +423,7 @@ * packet to a different zone by (e.g.) a default route. */ dst_in6 = ip6->ip6_dst; - if (in6_setscope(&dst_in6, m->m_pkthdr.rcvif, &inzone) != 0 || + if (in6_setscope(&dst_in6, mbuf_rcvif(m), &inzone) != 0 || in6_setscope(&dst_in6, rt->rt_ifp, &outzone) != 0 || inzone != outzone) { V_ip6stat.ip6s_cantforward++; @@ -483,7 +483,7 @@ * Also, don't send redirect if forwarding using a route * modified by a redirect. */ - if (V_ip6_sendredirects && rt->rt_ifp == m->m_pkthdr.rcvif && !srcrt && + if (V_ip6_sendredirects && rt->rt_ifp == mbuf_rcvif(m) && !srcrt && #ifdef IPSEC !ipsecrt && #endif /* IPSEC */ @@ -530,16 +530,16 @@ if ((rt->rt_flags & (RTF_BLACKHOLE|RTF_REJECT)) == 0) #endif { - printf("ip6_forward: outgoing interface is loopback. " + log(LOG_DEBUG, "ip6_forward: outgoing interface is loopback. " "src %s, dst %s, nxt %d, rcvif %s, outif %s\n", ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst), - ip6->ip6_nxt, if_name(m->m_pkthdr.rcvif), + ip6->ip6_nxt, if_name(mbuf_rcvif(m)), if_name(rt->rt_ifp)); } /* we can just use rcvif in forwarding. */ - origifp = m->m_pkthdr.rcvif; + origifp = mbuf_rcvif(m); } else origifp = rt->rt_ifp; Index: netinet6/nd6_nbr.c =================================================================== --- netinet6/nd6_nbr.c (revision 223932) +++ netinet6/nd6_nbr.c (working copy) @@ -100,7 +100,7 @@ void nd6_ns_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_neighbor_solicit *nd_ns; struct in6_addr saddr6 = ip6->ip6_src; @@ -423,7 +423,7 @@ } if (m == NULL) return; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; bzero(&ro, sizeof(ro)); @@ -613,7 +613,7 @@ void nd6_na_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_neighbor_advert *nd_na; struct in6_addr daddr6 = ip6->ip6_dst; @@ -988,7 +988,7 @@ } if (m == NULL) return; - m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.rcvif_idx = 0; if (IN6_IS_ADDR_MULTICAST(&daddr6)) { m->m_flags |= M_MCAST; Index: netinet6/mld6.c =================================================================== --- netinet6/mld6.c (revision 223932) +++ netinet6/mld6.c (working copy) @@ -1250,7 +1250,7 @@ CTR3(KTR_MLD, "%s: called w/mbuf (%p,%d)", __func__, m, off); - ifp = m->m_pkthdr.rcvif; + ifp = mbuf_rcvif(m); ip6 = mtod(m, struct ip6_hdr *); @@ -3094,7 +3094,7 @@ mld_scrub_context(m0); m->m_flags &= ~(M_PROTOFLAGS); - m0->m_pkthdr.rcvif = V_loif; + m_set_rcvif(m0, V_loif); ip6 = mtod(m0, struct ip6_hdr *); #if 0 Index: netinet6/ip6_input.c =================================================================== --- netinet6/ip6_input.c (revision 223932) +++ netinet6/ip6_input.c (working copy) @@ -332,7 +332,7 @@ u_int32_t plen; u_int32_t rtalert = ~0; int nxt, ours = 0; - struct ifnet *deliverifp = NULL, *ifp = NULL; + struct ifnet *deliverifp = NULL, *ifp; struct in6_addr odst; struct route_in6 rin6; int srcrt = 0; @@ -357,6 +357,8 @@ */ ip6_delaux(m); + ifp = mbuf_rcvif(m); + /* * mbuf statistics */ @@ -370,8 +372,8 @@ if (m->m_next) { if (m->m_flags & M_LOOP) { V_ip6stat.ip6s_m2m[V_loif->if_index]++; - } else if (m->m_pkthdr.rcvif->if_index < M2MMAX) - V_ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++; + } else if (ifp->if_index < M2MMAX) + V_ip6stat.ip6s_m2m[ifp->if_index]++; else V_ip6stat.ip6s_m2m[0]++; } else @@ -380,12 +382,12 @@ } /* drop the packet if IPv6 operation is disabled on the IF */ - if ((ND_IFINFO(m->m_pkthdr.rcvif)->flags & ND6_IFF_IFDISABLED)) { + if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED)) { m_freem(m); return; } - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive); + in6_ifstat_inc(ifp, ifs6_in_receive); V_ip6stat.ip6s_total++; #ifndef PULLDOWN_TEST @@ -421,11 +423,9 @@ #endif if (m->m_len < sizeof(struct ip6_hdr)) { - struct ifnet *inifp; - inifp = m->m_pkthdr.rcvif; if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) { V_ip6stat.ip6s_toosmall++; - in6_ifstat_inc(inifp, ifs6_in_hdrerr); + in6_ifstat_inc(ifp, ifs6_in_hdrerr); return; } } @@ -434,7 +434,7 @@ if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { V_ip6stat.ip6s_badvers++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); + in6_ifstat_inc(ifp, ifs6_in_hdrerr); goto bad; } @@ -449,7 +449,7 @@ * XXX: "badscope" is not very suitable for a multicast source. */ V_ip6stat.ip6s_badscope++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(ifp, ifs6_in_addrerr); goto bad; } if (IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) && @@ -461,7 +461,7 @@ * as the outgoing/incoming interface. */ V_ip6stat.ip6s_badscope++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(ifp, ifs6_in_addrerr); goto bad; } @@ -486,7 +486,7 @@ if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { V_ip6stat.ip6s_badscope++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(ifp, ifs6_in_addrerr); goto bad; } #if 0 @@ -500,7 +500,7 @@ if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) || IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) { V_ip6stat.ip6s_badscope++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(ifp, ifs6_in_addrerr); goto bad; } #endif @@ -525,12 +525,13 @@ if (!PFIL_HOOKED(&V_inet6_pfil_hook)) goto passin; - if (pfil_run_hooks(&V_inet6_pfil_hook, &m, - m->m_pkthdr.rcvif, PFIL_IN, NULL)) + if (pfil_run_hooks(&V_inet6_pfil_hook, &m, ifp, PFIL_IN, NULL)) return; if (m == NULL) /* consumed by filter */ return; + ip6 = mtod(m, struct ip6_hdr *); + ifp = mbuf_rcvif(m); /* could pfilters change it? */ srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst); passin: @@ -548,8 +549,8 @@ V_ip6stat.ip6s_badscope++; /* XXX */ goto bad; } - if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) || - in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) { + if (in6_setscope(&ip6->ip6_src, ifp, NULL) || + in6_setscope(&ip6->ip6_dst, ifp, NULL)) { V_ip6stat.ip6s_badscope++; goto bad; } @@ -560,8 +561,8 @@ */ if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { ours = 1; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast); - deliverifp = m->m_pkthdr.rcvif; + in6_ifstat_inc(ifp, ifs6_in_mcast); + deliverifp = ifp; goto hbhcheck; } @@ -573,7 +574,6 @@ dst6.sin6_family = AF_INET6; dst6.sin6_len = sizeof(struct sockaddr_in6); dst6.sin6_addr = ip6->ip6_dst; - ifp = m->m_pkthdr.rcvif; IF_AFDATA_LOCK(ifp); lle = lla_lookup(LLTABLE6(ifp), 0, (struct sockaddr *)&dst6); @@ -755,7 +755,7 @@ */ if (!V_ip6_forwarding) { V_ip6stat.ip6s_cantforward++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); + in6_ifstat_inc(ifp, ifs6_in_discard); goto bad; } @@ -793,7 +793,7 @@ if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) { #if 0 /*touches NULL pointer*/ - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); + in6_ifstat_inc(ifp, ifs6_in_discard); #endif goto out; /* m have already been freed */ } @@ -813,8 +813,8 @@ * (non-zero) payload length to the variable plen. */ V_ip6stat.ip6s_badoptions++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); + in6_ifstat_inc(ifp, ifs6_in_discard); + in6_ifstat_inc(ifp, ifs6_in_hdrerr); icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, (caddr_t)&ip6->ip6_plen - (caddr_t)ip6); @@ -865,7 +865,7 @@ */ if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { V_ip6stat.ip6s_tooshort++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); + in6_ifstat_inc(ifp, ifs6_in_truncated); goto bad; } if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { @@ -893,9 +893,9 @@ * unnecessarily calling into ip6_mforward(). */ if (ip6_mforward && - ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) { + ip6_mforward(ip6, ifp, m)) { IP6STAT_INC(ip6s_cantforward); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); + in6_ifstat_inc(ifp, ifs6_in_discard); goto bad; } } else if (!ours) { @@ -917,7 +917,7 @@ if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { V_ip6stat.ip6s_badscope++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(ifp, ifs6_in_addrerr); goto bad; } @@ -940,7 +940,7 @@ */ if (m->m_pkthdr.len < off) { V_ip6stat.ip6s_tooshort++; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); + in6_ifstat_inc(ifp, ifs6_in_truncated); goto bad; } @@ -1277,8 +1277,7 @@ bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr)); in6_clearscope(&pi6.ipi6_addr); /* XXX */ - pi6.ipi6_ifindex = - (m && m->m_pkthdr.rcvif) ? m->m_pkthdr.rcvif->if_index : 0; + pi6.ipi6_ifindex = (m) ? m->m_pkthdr.rcvif_idx : 0; *mp = sbcreatecontrol((caddr_t) &pi6, sizeof(struct in6_pktinfo), Index: netinet6/nd6_rtr.c =================================================================== --- netinet6/nd6_rtr.c (revision 223932) +++ netinet6/nd6_rtr.c (working copy) @@ -118,7 +118,7 @@ void nd6_rs_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_router_solicit *nd_rs; struct in6_addr saddr6 = ip6->ip6_src; @@ -205,7 +205,7 @@ void nd6_ra_input(struct mbuf *m, int off, int icmp6len) { - struct ifnet *ifp = m->m_pkthdr.rcvif; + struct ifnet *ifp = mbuf_rcvif(m); struct nd_ifinfo *ndi = ND_IFINFO(ifp); struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct nd_router_advert *nd_ra; @@ -342,7 +342,7 @@ 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 = mbuf_rcvif(m); pr.ndpr_raf_onlink = (pi->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) ? 1 : 0; Index: sys/mbuf.h =================================================================== --- sys/mbuf.h (revision 223932) +++ sys/mbuf.h (working copy) @@ -111,7 +111,8 @@ * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. */ struct pkthdr { - struct ifnet *rcvif; /* rcv interface */ + uint32_t rcvif_idx; /* rcv interface index */ + uint32_t rcvif_unique; /* rcv interface unique id */ /* variables for ip and tcp reassembly */ void *header; /* pointer to packet header */ int len; /* total packet length */ @@ -852,7 +853,7 @@ struct mbuf *m_copyup(struct mbuf *n, int len, int dstoff); struct mbuf *m_defrag(struct mbuf *, int); void m_demote(struct mbuf *, int); -struct mbuf *m_devget(char *, int, int, struct ifnet *, +struct mbuf *m_devget(char *, int, int, void (*)(char *, caddr_t, u_int)); struct mbuf *m_dup(struct mbuf *, int); int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); @@ -873,6 +874,13 @@ struct mbuf *m_uiotombuf(struct uio *, int, int, int, int); struct mbuf *m_unshare(struct mbuf *, int how); +/* + * Look up an ifnet using index + unique stored in mbuf header. + */ +struct ifnet *mbuf_rcvif(struct mbuf *m); +struct ifnet *mbuf_rcvif_ref(struct mbuf *m); +void m_set_rcvif(struct mbuf *m, struct ifnet *ifp); + /*- * Network packets may have annotations attached by affixing a list of * "packet tags" to the pkthdr structure. Packet tags are dynamically