From 6f8aee22681c9a4b16edbcdb4411e35b59a3a27a Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Fri, 14 May 2004 03:57:17 +0000 Subject: [PATCH] Fix a bug which I discovered recently while doing IPv6 testing at Wind River. In the IPv4 output path, one of the tests in ip_output() checks how many slots are actually available in the interface output queue before attempting to send a packet. If, for example, we need to transmit a packet of 32K bytes over an interface with an MTU of 1500, we know it's going to take about 21 fragments to do it. If there's less than 21 slots left in the output queue, there's no point in transmitting anything at all: IP does not do retransmission, so sending only some of the fragments would just be a waste of bandwidth. (In an extreme case, if you're sending a heavy stream of fragmented packets, you might find yourself sending nothing by the first fragment of all your packets.) So if ip_output() notices there's not enough room in the output queue to send the frame, it just dumps the packet and returns ENOBUFS to the app. It turns out ip6_output() lacks this code. Consequently, this caused the netperf UDPIPV6_STREAM test to produce very poor results with large write sizes. This commit adds code to check the remaining space in the output queue and junk fragmented packets if they're too big to be sent, just like with IPv4. (I can't imagine anyone's running an NFS server using UDP over IPv6, but if they are, this will likely make them a lot happier. :) --- sys/netinet6/ip6_output.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 5e0105cba63b..b955f40e2805 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1044,6 +1044,7 @@ skip_ipsec2:; u_char nextproto; struct ip6ctlparam ip6cp; u_int32_t mtu32; + int qslots = ifp->if_snd.ifq_maxlen - ifp->if_snd.ifq_len; /* * Too large for the destination or interface; @@ -1068,6 +1069,17 @@ skip_ipsec2:; goto bad; } + /* + * Verify that we have any chance at all of being able to queue + * the packet or packet fragments + */ + if (qslots <= 0 || ((u_int)qslots * (mtu - hlen) + < tlen /* - hlen */)) { + error = ENOBUFS; + ip6stat.ip6s_odropped++; + goto bad; + } + mnext = &m->m_nextpkt; /*