From deb499d51d32f9cec3bfdb35cc09c01a9c33681c Mon Sep 17 00:00:00 2001 From: bms Date: Wed, 16 Jun 2004 05:41:00 +0000 Subject: [PATCH] Disconnect a temporarily-connected UDP socket in out-of-mbufs case. This fixes the problem of UDP sockets getting wedged in a connected state (and bound to their destination) under heavy load. Temporary bind/connect should probably be deleted in future as an optimization, as described in "A Faster UDP" [Partridge/Pink 1993]. Notes: - INP_LOCK() is already held in udp_output(). The connection is in effect happening at a layer lower than the socket layer, therefore in theory socket locking should not be needed. - Inlining the in_pcbdisconnect() operation buys us nothing (in the case of the current state of the code), as laddr is not part of the inpcb hash or the udbinfo hash. Therefore there should be no need to rehash after restoring laddr in the error case (this was a concern of the original author of the patch). PR: kern/41765 Requested by: gnn Submitted by: Jinmei Tatuya (with cleanups) Tested by: spray(8) --- sys/netinet/udp_usrreq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 9c541dba852..47d12f852b2 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -837,7 +837,7 @@ udp_output(inp, m, addr, control, td) M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT); if (m == 0) { error = ENOBUFS; - goto release; + goto disconnect; } /* @@ -879,6 +879,12 @@ udp_output(inp, m, addr, control, td) inp->inp_moptions, inp); return (error); +disconnect: + if (addr) { + in_pcbdisconnect(inp); + inp->inp_laddr = laddr; + } + release: m_freem(m); return (error); -- 2.45.2