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.
*/
m->m_flags &= ~M_VLANTAG;
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m);
m_adj(m, ETHER_HDR_LEN);
/*

View File

@ -355,7 +355,8 @@ hostap_deliver_data(struct ieee80211vap *vap,
struct ifnet *ifp = vap->iv_ifp;
/* 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,
("gack, opmode %d", vap->iv_opmode));

View File

@ -250,7 +250,8 @@ ieee80211_deliver_data(struct ieee80211vap *vap,
struct ifnet *ifp = vap->iv_ifp;
/* 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 */
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_len = 2;
m->m_flags |= M_BCAST;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
(*ifp->if_output)(ifp, m, &sa, NULL);
ARPSTAT_INC(txrequests);
}
@ -784,6 +785,8 @@ in_arpinput(struct mbuf *m)
for (; m_hold != NULL; m_hold = m_hold_next) {
m_hold_next = m_hold->m_nextpkt;
m_hold->m_nextpkt = NULL;
/* Avoid confusing lower layers. */
m_clrprotoflags(m_hold);
(*ifp->if_output)(ifp, m_hold, &sa, NULL);
}
} else
@ -888,6 +891,7 @@ in_arpinput(struct mbuf *m)
m->m_pkthdr.rcvif = NULL;
sa.sa_family = AF_ARP;
sa.sa_len = 2;
m_clrprotoflags(m); /* Avoid confusing lower layers. */
(*ifp->if_output)(ifp, m, &sa, NULL);
ARPSTAT_INC(txreplies);
return;

View File

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

View File

@ -524,6 +524,10 @@ ip_fastforward(struct mbuf *m)
if (ip_len <= mtu ||
(ifp->if_hwassist & CSUM_FRAGMENT && (ip_off & IP_DF) == 0)) {
/*
* Avoid confusing lower layers.
*/
m_clrprotoflags(m);
/*
* Send off the packet via outgoing interface
*/
@ -553,6 +557,10 @@ ip_fastforward(struct mbuf *m)
do {
m0 = m->m_nextpkt;
m->m_nextpkt = NULL;
/*
* Avoid confusing lower layers.
*/
m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m,
(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
* to avoid confusing lower layers.
*/
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m,
(const struct sockaddr *)gw, ro);
goto done;
@ -654,7 +654,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
* Reset layer specific mbuf flags
* to avoid confusing upper layers.
*/
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m);
error = (*ifp->if_output)(ifp, m,
(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->sctp_socket) \
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); \
}
#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \
{ \
struct sctp_tcb *local_stcb = stcb; \
m_clrprotoflags(o_pak); \
if (local_stcb && local_stcb->sctp_ep) \
result = ip6_output(o_pak, \
((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 need no ND for a multicast forwarded packet...right?
*/
m_clrprotoflags(m); /* Avoid confusing lower layers. */
error = (*ifp->if_output)(ifp, mb_copy,
(struct sockaddr *)&dst6, NULL);
#ifdef MRT6DEBUG

View File

@ -3098,7 +3098,7 @@ mld_dispatch_packet(struct mbuf *m)
}
mld_scrub_context(m0);
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m);
m0->m_pkthdr.rcvif = V_loif;
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);
}
/* Reset layer specific mbuf flags to avoid confusing lower layers. */
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m); /* Avoid confusing lower layers. */
if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
return ((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
NULL));

View File

@ -180,6 +180,8 @@ send_output(struct mbuf *m, struct ifnet *ifp, int direction)
dst.sin6_len = sizeof(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.
* 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);
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);
goto done;
}
@ -5335,7 +5335,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
m1 = m0->m_nextpkt;
m0->m_nextpkt = NULL;
if (error == 0) {
m0->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m0);
error = (*ifp->if_output)(ifp, m0, sintosa(&dst), NULL);
} else
m_freem(m0);

View File

@ -1442,7 +1442,7 @@ ipoib_input(struct ifnet *ifp, struct mbuf *m)
* Strip off Infiniband header.
*/
m->m_flags &= ~M_VLANTAG;
m->m_flags &= ~(M_PROTOFLAGS);
m_clrprotoflags(m);
m_adj(m, IPOIB_HEADER_LEN);
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;
}
static __inline void
m_clrprotoflags(struct mbuf *m)
{
m->m_flags &= ~M_PROTOFLAGS;
}
static __inline struct mbuf *
m_last(struct mbuf *m)
{