From 511e01e2d678c362d84700678c2b0da517c37b82 Mon Sep 17 00:00:00 2001 From: Maxime Henrion Date: Tue, 25 Mar 2003 23:49:14 +0000 Subject: [PATCH] Try to make the MBUF_FRAG_TEST code work better. - Don't try to fragment the packet if it's smaller than mbuf_frag_size. - Preserve the size of the mbuf chain which is modified by m_split(). - Check that m_split() didn't return NULL. - Make it so we don't end up with two M_PKTHDR mbuf in the chain. - Use m->m_pkthdr.len instead of m->m_len so that we fragment the whole chain and not just the first mbuf. - Fix a nearby style bug and rework the logic of the loops so that it's more clear. This is still not quite right, because we're clearly abusing m_split() to do something it was not designed for, but at least it works now. We should probably move this code into a m_fragment() function when it's correct. --- sys/netinet/ip_output.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 02fb2d31452..c00ac4cd512 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1021,25 +1021,23 @@ ip_output(m0, opt, ro, flags, imo, inp) #endif #ifdef MBUF_FRAG_TEST - if (mbuf_frag_size) { + if (mbuf_frag_size && m->m_pkthdr.len > mbuf_frag_size) { struct mbuf *m1, *m2; - int length; + int length, tmp; - length = m->m_len; + tmp = length = m->m_pkthdr.len; - while (1) { - length -= mbuf_frag_size; - if (length < 1) - break; + while ((length -= mbuf_frag_size) >= 1) { m1 = m_split(m, length, M_DONTWAIT); + if (m1 == NULL) + break; + m1->m_flags &= ~M_PKTHDR; m2 = m; - while (1) { - if (m2->m_next == NULL) - break; + while (m2->m_next != NULL) m2 = m2->m_next; - } - m2->m_next = m1; + m2->m_next = m1; } + m->m_pkthdr.len = tmp; } #endif error = (*ifp->if_output)(ifp, m, -- 2.45.2