Skip to content

Commit

Permalink
Retire MT_HEADER mbuf type and change its users to use MT_DATA.
Browse files Browse the repository at this point in the history
Having an additional MT_HEADER mbuf type is superfluous and redundant
as nothing depends on it.  It only adds a layer of confusion.  The
distinction between header mbuf's and data mbuf's is solely done
through the m->m_flags M_PKTHDR flag.

Non-native code is not changed in this commit.  For compatibility
MT_HEADER is mapped to MT_DATA.

Sponsored by:	TCP/IP Optimization Fundraise 2005
  • Loading branch information
andreoppermann committed Nov 2, 2005
1 parent 728b935 commit 0df84f5
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 41 deletions.
2 changes: 1 addition & 1 deletion sys/compat/ndis/kern_ndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ ndis_ptom(m0, p)

for (buf = priv->npp_head; buf != NULL; buf = buf->mdl_next) {
if (buf == priv->npp_head)
MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
else
MGET(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
Expand Down
6 changes: 2 additions & 4 deletions sys/kern/uipc_sockbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,7 @@ sbcompress(sb, m, n)
(unsigned)m->m_len);
n->m_len += m->m_len;
sb->sb_cc += m->m_len;
if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
m->m_type != MT_OOBDATA)
if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
/* XXX: Probably don't need.*/
sb->sb_ctl += m->m_len;
m = m_free(m);
Expand Down Expand Up @@ -1163,8 +1162,7 @@ sbdrop_locked(sb, len)
m->m_len -= len;
m->m_data += len;
sb->sb_cc -= len;
if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
m->m_type != MT_OOBDATA)
if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
sb->sb_ctl -= len;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/uipc_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
} else if (type == MT_OOBDATA)
break;
else
KASSERT(m->m_type == MT_DATA || m->m_type == MT_HEADER,
KASSERT(m->m_type == MT_DATA,
("m->m_type == %d", m->m_type));
so->so_rcv.sb_state &= ~SBS_RCVATMARK;
len = uio->uio_resid;
Expand Down
6 changes: 2 additions & 4 deletions sys/kern/uipc_socket2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,7 @@ sbcompress(sb, m, n)
(unsigned)m->m_len);
n->m_len += m->m_len;
sb->sb_cc += m->m_len;
if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
m->m_type != MT_OOBDATA)
if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
/* XXX: Probably don't need.*/
sb->sb_ctl += m->m_len;
m = m_free(m);
Expand Down Expand Up @@ -1163,8 +1162,7 @@ sbdrop_locked(sb, len)
m->m_len -= len;
m->m_data += len;
sb->sb_cc -= len;
if (m->m_type != MT_DATA && m->m_type != MT_HEADER &&
m->m_type != MT_OOBDATA)
if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
sb->sb_ctl -= len;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/if_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,

if ((m->m_data - msiz) < m->m_pktdat) {
/* need new mbuf */
MGETHDR(m0, M_DONTWAIT, MT_HEADER);
MGETHDR(m0, M_DONTWAIT, MT_DATA);
if (m0 == NULL) {
_IF_DROP(&ifp->if_snd);
m_freem(m);
Expand Down
4 changes: 2 additions & 2 deletions sys/net80211/ieee80211_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen)
len = roundup(sizeof(struct ieee80211_frame) + pktlen, 4);
KASSERT(len <= MCLBYTES, ("802.11 mgt frame too large: %u", len));
if (len < MINCLSIZE) {
m = m_gethdr(M_NOWAIT, MT_HEADER);
m = m_gethdr(M_NOWAIT, MT_DATA);
/*
* Align the data in case additional headers are added.
* This should only happen when a WEP header is added
Expand All @@ -180,7 +180,7 @@ ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen)
if (m != NULL)
MH_ALIGN(m, len);
} else
m = m_getcl(M_NOWAIT, MT_HEADER, M_PKTHDR);
m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
if (m != NULL) {
m->m_data += sizeof(struct ieee80211_frame);
*frm = m->m_data;
Expand Down
2 changes: 1 addition & 1 deletion sys/net80211/ieee80211_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ ieee80211_send_nulldata(struct ieee80211_node *ni)
struct mbuf *m;
struct ieee80211_frame *wh;

MGETHDR(m, M_NOWAIT, MT_HEADER);
MGETHDR(m, M_NOWAIT, MT_DATA);
if (m == NULL) {
/* XXX debug msg */
ic->ic_stats.is_tx_nobuf++;
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ igmp_sendpkt(struct in_multi *inm, int type, unsigned long addr)

IN_MULTI_LOCK_ASSERT();

MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
return;

Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/ip_fw2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ send_pkt(struct ipfw_flow_id *id, u_int32_t seq, u_int32_t ack, int flags)
struct ip *ip;
struct tcphdr *tcp;

MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == 0)
return (NULL);
m->m_pkthdr.rcvif = (struct ifnet *)0;
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/ip_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ icmp_error(n, type, code, dest, mtu)
/*
* First, formulate icmp message
*/
MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
goto freeit;
#ifdef MAC
Expand Down Expand Up @@ -719,7 +719,7 @@ icmp_reflect(m)
*/
cp = (u_char *) (ip + 1);
if ((opts = ip_srcroute(m)) == 0 &&
(opts = m_gethdr(M_DONTWAIT, MT_HEADER))) {
(opts = m_gethdr(M_DONTWAIT, MT_DATA))) {
opts->m_len = sizeof(struct in_addr);
mtod(opts, struct in_addr *)->s_addr = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions sys/netinet/ip_mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
* new mbuf so we can modify it. Try to fill the new
* mbuf since if we don't the ethernet driver will.
*/
MGETHDR(mb_copy, M_DONTWAIT, MT_HEADER);
MGETHDR(mb_copy, M_DONTWAIT, MT_DATA);
if (mb_copy == NULL)
return;
#ifdef MAC
Expand Down Expand Up @@ -2715,7 +2715,7 @@ bw_upcalls_send(void)
* Allocate a new mbuf, initialize it with the header and
* the payload for the pending calls.
*/
MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
log(LOG_WARNING, "bw_upcalls_send: cannot allocate mbuf\n");
return;
Expand Down Expand Up @@ -3055,7 +3055,7 @@ pim_register_send_upcall(struct ip *ip, struct vif *vifp,
/*
* Add a new mbuf with an upcall header
*/
MGETHDR(mb_first, M_DONTWAIT, MT_HEADER);
MGETHDR(mb_first, M_DONTWAIT, MT_DATA);
if (mb_first == NULL) {
m_freem(mb_copy);
return ENOBUFS;
Expand Down Expand Up @@ -3115,7 +3115,7 @@ pim_register_send_rp(struct ip *ip, struct vif *vifp,
/*
* Add a new mbuf with the encapsulating header
*/
MGETHDR(mb_first, M_DONTWAIT, MT_HEADER);
MGETHDR(mb_first, M_DONTWAIT, MT_DATA);
if (mb_first == NULL) {
m_freem(mb_copy);
return ENOBUFS;
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
struct mbuf *m;
int mhlen = sizeof (struct ip);

MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
error = ENOBUFS;
ipstat.ips_odropped++;
Expand Down Expand Up @@ -1067,7 +1067,7 @@ ip_insertoptions(m, opt, phlen)
if (p->ipopt_dst.s_addr)
ip->ip_dst = p->ipopt_dst;
if (m->m_flags & M_EXT || m->m_data - optlen < m->m_pktdat) {
MGETHDR(n, M_DONTWAIT, MT_HEADER);
MGETHDR(n, M_DONTWAIT, MT_DATA);
if (n == NULL) {
*phlen = 0;
return (m);
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ tcp_output(struct tcpcb *tp)
m->m_len += hdrlen;
m->m_data -= hdrlen;
#else
MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
SOCKBUF_UNLOCK(&so->so_snd);
error = ENOBUFS;
Expand Down Expand Up @@ -800,7 +800,7 @@ tcp_output(struct tcpcb *tp)
else
tcpstat.tcps_sndwinup++;

MGETHDR(m, M_DONTWAIT, MT_HEADER);
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
error = ENOBUFS;
goto out;
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/tcp_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags)
}
}
if (m == NULL) {
m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return;
tlen = 0;
Expand Down Expand Up @@ -1794,7 +1794,7 @@ tcp_twrespond(struct tcptw *tw, int flags)

INP_LOCK_ASSERT(inp);

m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return (ENOBUFS);
m->m_data += max_linkhdr;
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/tcp_syncache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ syncache_respond(sc, m)
if (m)
m_freem(m);

m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return (ENOBUFS);
m->m_data += max_linkhdr;
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/tcp_timewait.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags)
}
}
if (m == NULL) {
m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return;
tlen = 0;
Expand Down Expand Up @@ -1794,7 +1794,7 @@ tcp_twrespond(struct tcptw *tw, int flags)

INP_LOCK_ASSERT(inp);

m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return (ENOBUFS);
m->m_data += max_linkhdr;
Expand Down
2 changes: 1 addition & 1 deletion sys/netipsec/ipsec_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ ipsec6_splithdr(struct mbuf *m)
ip6 = mtod(m, struct ip6_hdr *);
hlen = sizeof(struct ip6_hdr);
if (m->m_len > hlen) {
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
MGETHDR(mh, M_DONTWAIT, MT_DATA);
if (!mh) {
m_freem(m);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion sys/netipx/ipx_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ipxipoutput(ifp, m, dst, rt)
/* following clause not necessary on vax */
if (3 & (intptr_t)m->m_data) {
/* force longword alignment of ip hdr */
struct mbuf *m0 = m_gethdr(MT_HEADER, M_DONTWAIT);
struct mbuf *m0 = m_gethdr(MT_DATA, M_DONTWAIT);
if (m0 == NULL) {
m_freem(m);
return (ENOBUFS);
Expand Down
6 changes: 3 additions & 3 deletions sys/netipx/spx_usrreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ spx_output(cb, m0)
m->m_next = m1;
}
}
m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL) {
m_freem(m0);
return (ENOBUFS);
Expand Down Expand Up @@ -1026,7 +1026,7 @@ spx_output(cb, m0)
spxstat.spxs_sndprobe++;
if (cb->s_flags & SF_ACKNOW)
spxstat.spxs_sndacks++;
m = m_gethdr(M_DONTWAIT, MT_HEADER);
m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL)
return (ENOBUFS);
/*
Expand Down Expand Up @@ -1373,7 +1373,7 @@ spx_attach(so, proto, td)
}
sb = &so->so_snd;

mm = m_getclr(M_DONTWAIT, MT_HEADER);
mm = m_getclr(M_DONTWAIT, MT_DATA);
if (mm == NULL) {
FREE(cb, M_PCB);
error = ENOBUFS;
Expand Down
2 changes: 1 addition & 1 deletion sys/sys/mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct mbuf {
*/
#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */
#define MT_DATA 1 /* dynamic (data) allocation */
#define MT_HEADER 2 /* packet header */
#define MT_HEADER MT_DATA /* packet header, use M_PKTHDR instead */
#if 0
#define MT_SOCKET 3 /* socket structure */
#define MT_PCB 4 /* protocol control block */
Expand Down
6 changes: 2 additions & 4 deletions sys/sys/socketvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ struct xsocket {
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \
(sb)->sb_cc += (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
(m)->m_type != MT_OOBDATA) \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl += (m)->m_len; \
(sb)->sb_mbcnt += MSIZE; \
if ((m)->m_flags & M_EXT) \
Expand All @@ -308,8 +307,7 @@ struct xsocket {
/* adjust counters in sb reflecting freeing of m */
#define sbfree(sb, m) { \
(sb)->sb_cc -= (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
(m)->m_type != MT_OOBDATA) \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl -= (m)->m_len; \
(sb)->sb_mbcnt -= MSIZE; \
if ((m)->m_flags & M_EXT) \
Expand Down

0 comments on commit 0df84f5

Please sign in to comment.