From e6ccd70936186495ada83c2ee0e4cf74efa19811 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Sat, 21 Aug 2004 16:14:04 +0000 Subject: [PATCH] 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. --- sys/netinet/udp_usrreq.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 5f1a1bb24aa..81ab6e1a16f 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -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