summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2013-03-15 12:50:29 +0000
committerglebius <glebius@FreeBSD.org>2013-03-15 12:50:29 +0000
commit79cb402edbb474fc00a40f3fc46c9b5c2304d461 (patch)
tree619169508217237c17f20f5bebb987eddbdfb894 /sys
parentace684a13202a960c7f5a15ff9d3604793bced5f (diff)
downloadFreeBSD-src-79cb402edbb474fc00a40f3fc46c9b5c2304d461.zip
FreeBSD-src-79cb402edbb474fc00a40f3fc46c9b5c2304d461.tar.gz
- Use m_getcl() instead of hand allocating.
- Use m_get()/m_gethdr() instead of macros. - Remove superfluous cleaning of mbuf fields after allocation. Sponsored by: Nginx, Inc.
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet6/icmp6.c33
-rw-r--r--sys/netinet6/ip6_mroute.c5
-rw-r--r--sys/netinet6/ip6_output.c11
-rw-r--r--sys/netinet6/mld6.c6
4 files changed, 22 insertions, 33 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index 0cd6e5a..089dabe 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -581,7 +581,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
const int maxlen = sizeof(*nip6) + sizeof(*nicmp6);
int n0len;
- MGETHDR(n, M_NOWAIT, n0->m_type);
+ n = m_gethdr(M_NOWAIT, n0->m_type);
n0len = n0->m_pkthdr.len; /* save for use below */
if (n)
M_MOVE_PKTHDR(n, n0); /* FIB copied. */
@@ -699,7 +699,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
/* Give up remote */
break;
}
- MGETHDR(n, M_NOWAIT, m->m_type);
+ n = m_gethdr(M_NOWAIT, m->m_type);
if (n && maxlen > MHLEN) {
MCLGET(n, M_NOWAIT);
if ((n->m_flags & M_EXT) == 0) {
@@ -1495,7 +1495,7 @@ ni6_input(struct mbuf *m, int off)
}
/* allocate an mbuf to reply. */
- MGETHDR(n, M_NOWAIT, m->m_type);
+ n = m_gethdr(M_NOWAIT, m->m_type);
if (n == NULL) {
m_freem(m);
return (NULL);
@@ -1608,16 +1608,13 @@ ni6_nametodns(const char *name, int namelen, int old)
else
len = MCLBYTES;
- /* because MAXHOSTNAMELEN is usually 256, we use cluster mbuf */
- MGET(m, M_NOWAIT, MT_DATA);
- if (m && len > MLEN) {
- MCLGET(m, M_NOWAIT);
- if ((m->m_flags & M_EXT) == 0)
- goto fail;
- }
- if (!m)
+ /* Because MAXHOSTNAMELEN is usually 256, we use cluster mbuf. */
+ if (len > MLEN)
+ m = m_getcl(M_NOWAIT, MT_DATA, 0);
+ else
+ m = m_get(M_NOWAIT, MT_DATA);
+ if (m == NULL)
goto fail;
- m->m_next = NULL;
if (old) {
m->m_len = len;
@@ -2063,7 +2060,7 @@ icmp6_rip6_input(struct mbuf **mp, int off)
*/
if ((m->m_flags & M_EXT) && m->m_next == NULL &&
m->m_len <= MHLEN) {
- MGET(n, M_NOWAIT, m->m_type);
+ n = m_get(M_NOWAIT, m->m_type);
if (n != NULL) {
if (m_dup_pkthdr(n, m, M_NOWAIT)) {
bcopy(m->m_data, n->m_data,
@@ -2113,7 +2110,7 @@ icmp6_rip6_input(struct mbuf **mp, int off)
m->m_len <= MHLEN) {
struct mbuf *n;
- MGET(n, M_NOWAIT, m->m_type);
+ n = m_get(M_NOWAIT, m->m_type);
if (n != NULL) {
if (m_dup_pkthdr(n, m, M_NOWAIT)) {
bcopy(m->m_data, n->m_data, m->m_len);
@@ -2592,14 +2589,10 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
#if IPV6_MMTU >= MCLBYTES
# error assumption failed about IPV6_MMTU and MCLBYTES
#endif
- MGETHDR(m, M_NOWAIT, MT_HEADER);
- if (m && IPV6_MMTU >= MHLEN)
- MCLGET(m, M_NOWAIT);
- if (!m)
+ m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+ if (m == NULL)
goto fail;
M_SETFIB(m, rt->rt_fibnum);
- m->m_pkthdr.rcvif = NULL;
- m->m_len = 0;
maxlen = M_TRAILINGSPACE(m);
maxlen = min(IPV6_MMTU, maxlen);
/* just for safety */
diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c
index a221110..aeeb644 100644
--- a/sys/netinet6/ip6_mroute.c
+++ b/sys/netinet6/ip6_mroute.c
@@ -1698,11 +1698,10 @@ register_send(struct ip6_hdr *ip6, struct mif6 *mif, struct mbuf *m)
#endif
++pim6stat.pim6s_snd_registers;
- /* Make a copy of the packet to send to the user level process */
- MGETHDR(mm, M_NOWAIT, MT_HEADER);
+ /* Make a copy of the packet to send to the user level process. */
+ mm = m_gethdr(M_NOWAIT, MT_DATA);
if (mm == NULL)
return (ENOBUFS);
- mm->m_pkthdr.rcvif = NULL;
mm->m_data += max_linkhdr;
mm->m_len = sizeof(struct ip6_hdr);
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index 5e8c11f..cb1feab 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -774,9 +774,7 @@ again:
/*
* XXX: ip6_mforward expects that rcvif is NULL
* when it is called from the originating path.
- * However, it is not always the case, since
- * some versions of MGETHDR() does not
- * initialize the field.
+ * However, it may not always be the case.
*/
m->m_pkthdr.rcvif = NULL;
if (ip6_mforward(ip6, ifp, m) != 0) {
@@ -1122,13 +1120,12 @@ passout:
*/
m0 = m;
for (off = hlen; off < tlen; off += len) {
- MGETHDR(m, M_NOWAIT, MT_HEADER);
+ m = m_gethdr(M_NOWAIT, MT_DATA);
if (!m) {
error = ENOBUFS;
V_ip6stat.ip6s_odropped++;
goto sendorfree;
}
- m->m_pkthdr.rcvif = NULL;
m->m_flags = m0->m_flags & M_COPYFLAGS; /* incl. FIB */
*mnext = m;
mnext = &m->m_nextpkt;
@@ -3045,8 +3042,8 @@ ip6_splithdr(struct mbuf *m, struct ip6_exthdrs *exthdrs)
ip6 = mtod(m, struct ip6_hdr *);
if (m->m_len > sizeof(*ip6)) {
- MGETHDR(mh, M_NOWAIT, MT_HEADER);
- if (mh == 0) {
+ mh = m_gethdr(M_NOWAIT, MT_DATA);
+ if (mh == NULL) {
m_freem(m);
return ENOBUFS;
}
diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c
index 0d9e300..560e8d6 100644
--- a/sys/netinet6/mld6.c
+++ b/sys/netinet6/mld6.c
@@ -1799,13 +1799,13 @@ mld_v1_transmit_report(struct in6_multi *in6m, const int type)
ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST);
/* ia may be NULL if link-local address is tentative. */
- MGETHDR(mh, M_NOWAIT, MT_HEADER);
+ mh = m_gethdr(M_NOWAIT, MT_DATA);
if (mh == NULL) {
if (ia != NULL)
ifa_free(&ia->ia_ifa);
return (ENOMEM);
}
- MGET(md, M_NOWAIT, MT_DATA);
+ md = m_get(M_NOWAIT, MT_DATA);
if (md == NULL) {
m_free(mh);
if (ia != NULL)
@@ -3173,7 +3173,7 @@ mld_v2_encap_report(struct ifnet *ifp, struct mbuf *m)
if (ia == NULL)
CTR1(KTR_MLD, "%s: warning: ia is NULL", __func__);
- MGETHDR(mh, M_NOWAIT, MT_HEADER);
+ mh = m_gethdr(M_NOWAIT, MT_DATA);
if (mh == NULL) {
if (ia != NULL)
ifa_free(&ia->ia_ifa);
OpenPOWER on IntegriCloud