When prepending space onto outgoing UDP datagram payloads to hold the

UDP/IP header, make sure that space is also allocated for the link
layer header.  If an mbuf must be allocated to hold the UDP/IP header
(very likely), then this will avoid an additional mbuf allocation at
the link layer.  This trick is also used by TCP and other protocols to
avoid extra calls to the mbuf allocator in the ethernet (and related)
output routines.
This commit is contained in:
Robert Watson committed 2004-08-21 16:14:04 +00:00
1 parent b282bdf0ef
commit e6ccd70936
1 file changed
+7 -4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=134119
+7 -4
View File
@@ -851,15 +851,18 @@ udp_output(inp, m, addr, control, td)
goto release;
}
}
/*
* Calculate data length and get a mbuf
* for UDP and IP headers.
* Calculate data length and get a mbuf for UDP, IP, and possible
* link-layer headers.
*/
M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
if (m == 0) {
M_PREPEND(m, sizeof(struct udpiphdr) + max_linkhdr, M_DONTWAIT);
if (m == NULL) {
error = ENOBUFS;
goto release;
}
m->m_data += max_linkhdr;
m->m_len -= max_linkhdr;
/*
* Fill in mbuf with extended UDP header