- 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.
This commit is contained in:
parent
aa48181169
commit
7b07d1bed0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=248321
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -774,9 +774,7 @@ skip_ipsec2:;
|
||||
/*
|
||||
* 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 @@ skip_ipsec2:;
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user