Add m_clrprotoflags() to clear protocol specific mbuf flags at up and

downwards layer crossings.

Consistently use it within IP, IPv6 and ethernet protocols.

Discussed with:	trociny, glebius
This commit is contained in:
Andre Oppermann 2013-08-19 13:27:32 +00:00
parent 88169e0388
commit 86bd049144
15 changed files with 37 additions and 12 deletions

View File

@ -774,7 +774,7 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
* Strip off Ethernet header. * Strip off Ethernet header.
*/ */
m->m_flags &= ~M_VLANTAG; m->m_flags &= ~M_VLANTAG;
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
m_adj(m, ETHER_HDR_LEN); m_adj(m, ETHER_HDR_LEN);
/* /*

View File

@ -355,7 +355,8 @@ hostap_deliver_data(struct ieee80211vap *vap,
struct ifnet *ifp = vap->iv_ifp; struct ifnet *ifp = vap->iv_ifp;
/* clear driver/net80211 flags before passing up */ /* clear driver/net80211 flags before passing up */
m->m_flags &= ~(M_80211_RX | M_MCAST | M_BCAST); m->m_flags &= ~(M_MCAST | M_BCAST);
m_clrprotoflags(m);
KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP, KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP,
("gack, opmode %d", vap->iv_opmode)); ("gack, opmode %d", vap->iv_opmode));

View File

@ -250,7 +250,8 @@ ieee80211_deliver_data(struct ieee80211vap *vap,
struct ifnet *ifp = vap->iv_ifp; struct ifnet *ifp = vap->iv_ifp;
/* clear driver/net80211 flags before passing up */ /* clear driver/net80211 flags before passing up */
m->m_flags &= ~(M_80211_RX | M_MCAST | M_BCAST); m->m_flags &= ~(M_MCAST | M_BCAST);
m_clrprotoflags(m);
/* NB: see hostap_deliver_data, this path doesn't handle hostap */ /* NB: see hostap_deliver_data, this path doesn't handle hostap */
KASSERT(vap->iv_opmode != IEEE80211_M_HOSTAP, ("gack, hostap")); KASSERT(vap->iv_opmode != IEEE80211_M_HOSTAP, ("gack, hostap"));

View File

@ -281,6 +281,7 @@ arprequest(struct ifnet *ifp, const struct in_addr *sip,
sa.sa_family = AF_ARP; sa.sa_family = AF_ARP;
sa.sa_len = 2; sa.sa_len = 2;
m->m_flags |= M_BCAST; m->m_flags |= M_BCAST;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
(*ifp->if_output)(ifp, m, &sa, NULL); (*ifp->if_output)(ifp, m, &sa, NULL);
ARPSTAT_INC(txrequests); ARPSTAT_INC(txrequests);
} }
@ -784,6 +785,8 @@ in_arpinput(struct mbuf *m)
for (; m_hold != NULL; m_hold = m_hold_next) { for (; m_hold != NULL; m_hold = m_hold_next) {
m_hold_next = m_hold->m_nextpkt; m_hold_next = m_hold->m_nextpkt;
m_hold->m_nextpkt = NULL; m_hold->m_nextpkt = NULL;
/* Avoid confusing lower layers. */
m_clrprotoflags(m_hold);
(*ifp->if_output)(ifp, m_hold, &sa, NULL); (*ifp->if_output)(ifp, m_hold, &sa, NULL);
} }
} else } else
@ -888,6 +891,7 @@ in_arpinput(struct mbuf *m)
m->m_pkthdr.rcvif = NULL; m->m_pkthdr.rcvif = NULL;
sa.sa_family = AF_ARP; sa.sa_family = AF_ARP;
sa.sa_len = 2; sa.sa_len = 2;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
(*ifp->if_output)(ifp, m, &sa, NULL); (*ifp->if_output)(ifp, m, &sa, NULL);
ARPSTAT_INC(txreplies); ARPSTAT_INC(txreplies);
return; return;

View File

@ -3450,7 +3450,7 @@ igmp_intr(struct mbuf *m)
} }
igmp_scrub_context(m0); igmp_scrub_context(m0);
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
m0->m_pkthdr.rcvif = V_loif; m0->m_pkthdr.rcvif = V_loif;
#ifdef MAC #ifdef MAC
mac_netinet_igmp_send(ifp, m0); mac_netinet_igmp_send(ifp, m0);

View File

@ -524,6 +524,10 @@ ip_fastforward(struct mbuf *m)
if (ip_len <= mtu || if (ip_len <= mtu ||
(ifp->if_hwassist & CSUM_FRAGMENT && (ip_off & IP_DF) == 0)) { (ifp->if_hwassist & CSUM_FRAGMENT && (ip_off & IP_DF) == 0)) {
/*
* Avoid confusing lower layers.
*/
m_clrprotoflags(m);
/* /*
* Send off the packet via outgoing interface * Send off the packet via outgoing interface
*/ */
@ -553,6 +557,10 @@ ip_fastforward(struct mbuf *m)
do { do {
m0 = m->m_nextpkt; m0 = m->m_nextpkt;
m->m_nextpkt = NULL; m->m_nextpkt = NULL;
/*
* Avoid confusing lower layers.
*/
m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m, error = (*ifp->if_output)(ifp, m,
(struct sockaddr *)dst, &ro); (struct sockaddr *)dst, &ro);

View File

@ -621,7 +621,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
* Reset layer specific mbuf flags * Reset layer specific mbuf flags
* to avoid confusing lower layers. * to avoid confusing lower layers.
*/ */
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m, error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro); (const struct sockaddr *)gw, ro);
goto done; goto done;
@ -654,7 +654,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
* Reset layer specific mbuf flags * Reset layer specific mbuf flags
* to avoid confusing upper layers. * to avoid confusing upper layers.
*/ */
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m, error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro); (const struct sockaddr *)gw, ro);

View File

@ -444,12 +444,14 @@ typedef struct rtentry sctp_rtentry_t;
local_stcb->sctp_ep && \ local_stcb->sctp_ep && \
local_stcb->sctp_ep->sctp_socket) \ local_stcb->sctp_ep->sctp_socket) \
o_flgs |= local_stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE; \ o_flgs |= local_stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE; \
m_clrprotoflags(o_pak); \
result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \ result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \
} }
#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \ #define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \
{ \ { \
struct sctp_tcb *local_stcb = stcb; \ struct sctp_tcb *local_stcb = stcb; \
m_clrprotoflags(o_pak); \
if (local_stcb && local_stcb->sctp_ep) \ if (local_stcb && local_stcb->sctp_ep) \
result = ip6_output(o_pak, \ result = ip6_output(o_pak, \
((struct in6pcb *)(local_stcb->sctp_ep))->in6p_outputopts, \ ((struct in6pcb *)(local_stcb->sctp_ep))->in6p_outputopts, \

View File

@ -1648,6 +1648,7 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m)
* We just call if_output instead of nd6_output here, since * We just call if_output instead of nd6_output here, since
* we need no ND for a multicast forwarded packet...right? * we need no ND for a multicast forwarded packet...right?
*/ */
m_clrprotoflags(m); /* Avoid confusing lower layers. */
error = (*ifp->if_output)(ifp, mb_copy, error = (*ifp->if_output)(ifp, mb_copy,
(struct sockaddr *)&dst6, NULL); (struct sockaddr *)&dst6, NULL);
#ifdef MRT6DEBUG #ifdef MRT6DEBUG

View File

@ -3098,7 +3098,7 @@ mld_dispatch_packet(struct mbuf *m)
} }
mld_scrub_context(m0); mld_scrub_context(m0);
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
m0->m_pkthdr.rcvif = V_loif; m0->m_pkthdr.rcvif = V_loif;
ip6 = mtod(m0, struct ip6_hdr *); ip6 = mtod(m0, struct ip6_hdr *);

View File

@ -2082,8 +2082,7 @@ nd6_output_lle(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0,
} }
return (error); return (error);
} }
/* Reset layer specific mbuf flags to avoid confusing lower layers. */ m_clrprotoflags(m); /* Avoid confusing lower layers. */
m->m_flags &= ~(M_PROTOFLAGS);
if ((ifp->if_flags & IFF_LOOPBACK) != 0) { if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
return ((*ifp->if_output)(origifp, m, (struct sockaddr *)dst, return ((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
NULL)); NULL));

View File

@ -180,6 +180,8 @@ send_output(struct mbuf *m, struct ifnet *ifp, int direction)
dst.sin6_len = sizeof(dst); dst.sin6_len = sizeof(dst);
dst.sin6_addr = ip6->ip6_dst; dst.sin6_addr = ip6->ip6_dst;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
/* /*
* Output the packet as nd6.c:nd6_output_lle() would do. * Output the packet as nd6.c:nd6_output_lle() would do.
* The mbuf is always consumed, so we do not have to care * The mbuf is always consumed, so we do not have to care

View File

@ -5310,7 +5310,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
ip->ip_sum = in_cksum(m0, ip->ip_hl << 2); ip->ip_sum = in_cksum(m0, ip->ip_hl << 2);
m0->m_pkthdr.csum_flags &= ~CSUM_IP; m0->m_pkthdr.csum_flags &= ~CSUM_IP;
} }
m0->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m0); /* Avoid confusing lower layers. */
error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL); error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL);
goto done; goto done;
} }
@ -5335,7 +5335,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
m1 = m0->m_nextpkt; m1 = m0->m_nextpkt;
m0->m_nextpkt = NULL; m0->m_nextpkt = NULL;
if (error == 0) { if (error == 0) {
m0->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m0);
error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL); error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL);
} else } else
m_freem(m0); m_freem(m0);

View File

@ -1442,7 +1442,7 @@ ipoib_input(struct ifnet *ifp, struct mbuf *m)
* Strip off Infiniband header. * Strip off Infiniband header.
*/ */
m->m_flags &= ~M_VLANTAG; m->m_flags &= ~M_VLANTAG;
m->m_flags &= ~(M_PROTOFLAGS); m_clrprotoflags(m);
m_adj(m, IPOIB_HEADER_LEN); m_adj(m, IPOIB_HEADER_LEN);
if (IPOIB_IS_MULTICAST(eh->hwaddr)) { if (IPOIB_IS_MULTICAST(eh->hwaddr)) {

View File

@ -603,6 +603,13 @@ m_chtype(struct mbuf *m, short new_type)
m->m_type = new_type; m->m_type = new_type;
} }
static __inline void
m_clrprotoflags(struct mbuf *m)
{
m->m_flags &= ~M_PROTOFLAGS;
}
static __inline struct mbuf * static __inline struct mbuf *
m_last(struct mbuf *m) m_last(struct mbuf *m)
{ {