ip6: leave room for link headers in UDP

UDP over IPv6 was not leaving space for link headers,
resulting in the ethernet header being placed in its own mbuf
at the front of the mbuf chain sent down to the NIC driver.
This is inefficient, in terms of allocating 2x as many
header mbufs as needed, and its also confusing for drivers
which may expect to find ether/ip/l4 headers together in the same
mbuf.

Reviewed by: glebius, rrs, tuexen
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D49840

This is a port of e6ccd70936, which was done by Robert
Watson in 2004 for IP4
This commit is contained in:
Andrew Gallatin 2025-04-15 19:37:06 -04:00
parent b7f71ffe0f
commit b836c229aa

View file

@ -860,14 +860,18 @@ udp6_send(struct socket *so, int flags_arg, struct mbuf *m,
hlen = sizeof(struct ip6_hdr);
/*
* Calculate data length and get a mbuf
* for UDP and IP6 headers.
* Calculate data length and get a mbuf for UDP, IP6, and possible
* link-layer headers. Immediate slide the data pointer back forward
* since we won't use that space at this layer.
*/
M_PREPEND(m, hlen + sizeof(struct udphdr), M_NOWAIT);
M_PREPEND(m, hlen + sizeof(struct udphdr) + max_linkhdr, M_NOWAIT);
if (m == NULL) {
error = ENOBUFS;
goto release;
}
m->m_data += max_linkhdr;
m->m_len -= max_linkhdr;
m->m_pkthdr.len -= max_linkhdr;
/*
* Stuff checksum and output datagram.