From 219503cf61ebf0aa6c01e49f6b073f0a40e0f1ec Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Tue, 22 Nov 2016 10:57:13 +0800 Subject: [PATCH] udp: Don't propagate connect error, as long as the inpcb has local port. This fixes the UDP socket disconnect->[read/write] support; before this fix, the immediate read/write after disconnect will get EAFNOTSUPPORT. --- 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 807a12c7e0..103a5f8c94 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1591,7 +1591,13 @@ out: if (msg->connect.nm_flags & PRUC_HELDTD) lwkt_rele(td); if (error && (msg->connect.nm_flags & PRUC_ASYNC)) { - so->so_error = error; + if (inp->inp_lport == 0) { + /* + * As long as we have the local port, it is fine + * for connect to fail, e.g. disconnect. + */ + so->so_error = error; + } soclrstate(so, SS_ISCONNECTED); /* * Wake up callers blocked on this socket to make sure -- 2.41.0