From nobody Thu Feb 15 18:49:03 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TbPH41GKxz59t9V; Thu, 15 Feb 2024 18:49:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TbPH40h5Kz4tQk; Thu, 15 Feb 2024 18:49:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708022944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j6BLEUVc3EBLL4eAqJoaB6g8EaY2MJbtWsvTHRGCHAM=; b=QfsprVFKmfwX1EsGafrJI1ah4rLOgDX5wkDhcr//Us1aDCNuJBsyZzNUnhNphJZqGDe4Fk ZxE6pnOZVTjmVozlRo6N8TIpy3IUiNngoRBQYREYrN8XcvLk2+j8VbTCvb+YcW4O4MlRnk yVW4ORUsJKuLjkjJCfb5J4tIq9WG5MurQJ36udsoq8wCHXSM+RxeNDREc2CquCxy/VD+pi az7khYgI7ggCbEikDjvZ8+6O+hWBmrDLmNZGQPfu0jSv3QYjMcg7nqIPu3ZsuXyxK64+BJ w2uqkAk3MhJgkI0OALmzggme4JFl2cD1GLzY5hrUIwaIIhvdJGrqwOamHBcj7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708022944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j6BLEUVc3EBLL4eAqJoaB6g8EaY2MJbtWsvTHRGCHAM=; b=HBoMZ9Xje8XcNzJtbGWYaik4j1qfl6GZIhUD5TMTsUcN5jbHMN/kYd5NIsEoMP8ha0DsxW xGRl249+2Xfx4FigkEJ4dKcrGBdOpOD4NrFrIWGSkxf78EMfdBIOtLmtLQm/3TEtA4IjEN gA4XwKapH9Ff2pGBwAaoHJbR5Jg0iS4flZo7Y51T81FBxAkUMVCPGRCfs8myRhvGlOXPtj vhswkiat+QIkavs4Ntfmo6eUi2hLenNlVNGj9EZ3CEdOzJ+1HBpJgkeHBtNWIyYx+i8Awm x+dA/8wAhp4E0l/0EwiCoMNNM+fGU2qKYfVHuMs0UMBiOWviWHU/bD6bqOgRUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708022944; a=rsa-sha256; cv=none; b=r83tSfnrxiYGssxLlLq45iekj7kwo+hZpCRWn8P/mKfzFZxjFIrY4Pu1i7sZm8aaGIr+nZ Tgx+RwMsWyYeuP47130uykw513vznVxvSPAaOgZfkIzTAhTtpoD4HcNk4zTjYIoasd342t oYOetStE3fLU8tkCBRFjeAzl4rpDi6pdsEEIixvW0rcPCoCYTHXVaX/SYmRwujF0uL6Jkg a4L9BLof5nkk1qsgiYrt4F++u8eNw7s5IbPuUgAkQo7FZ+vOs9D3PNkK8aVKg3+6I+BPDw CxV4zA0IjtPjbtFHgr8FtDbZqPVt7AC5ZF8o2e+S9ZpcAjXTTmvstPqBw0tpaA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TbPH36rsHzsrq; Thu, 15 Feb 2024 18:49:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41FIn3IE085008; Thu, 15 Feb 2024 18:49:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41FIn3dm085005; Thu, 15 Feb 2024 18:49:03 GMT (envelope-from git) Date: Thu, 15 Feb 2024 18:49:03 GMT Message-Id: <202402151849.41FIn3dm085005@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: abe8379b4f24 - main - sockets: repair wakeup of accept(2) by shutdown(2) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: abe8379b4f244aa12f13a603124eb6b41faabec5 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=abe8379b4f244aa12f13a603124eb6b41faabec5 commit abe8379b4f244aa12f13a603124eb6b41faabec5 Author: Gleb Smirnoff AuthorDate: 2024-02-15 18:48:44 +0000 Commit: Gleb Smirnoff CommitDate: 2024-02-15 18:48:44 +0000 sockets: repair wakeup of accept(2) by shutdown(2) That was lost in transition from one-for-all soshutdown() to protocol specific methods. Only protocols that listen(2) were affected. This is not a documented or specified feature, but some software relies on it. At least the FreeSWITCH telephony software uses this behavior on PF_INET/SOCK_STREAM. Fixes: 5bba2728079ed4da33f727dbc2b6ae1de02ba897 --- sys/kern/uipc_usrreq.c | 17 ++++++++--------- sys/netinet/sctp_usrreq.c | 11 +++++------ sys/netinet/tcp_usrreq.c | 11 +++++------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index db226a16674e..20facd9b0a44 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1669,7 +1669,14 @@ uipc_shutdown(struct socket *so, enum shutdown_how how) int error; SOCK_LOCK(so); - if ((so->so_state & + if (SOLISTENING(so)) { + if (how != SHUT_WR) { + so->so_error = ECONNABORTED; + solisten_wakeup(so); /* unlocks so */ + } else + SOCK_UNLOCK(so); + return (ENOTCONN); + } else if ((so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) { /* * POSIX mandates us to just return ENOTCONN when shutdown(2) is @@ -1691,14 +1698,6 @@ uipc_shutdown(struct socket *so, enum shutdown_how how) } } else error = 0; - if (SOLISTENING(so)) { - if (how != SHUT_WR) { - so->so_error = ECONNABORTED; - solisten_wakeup(so); /* unlocks so */ - } else - SOCK_UNLOCK(so); - return (0); - } SOCK_UNLOCK(so); switch (how) { diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index 70fe021be766..3b0da87edce3 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -794,18 +794,17 @@ sctp_shutdown(struct socket *so, enum shutdown_how how) return (EOPNOTSUPP); SOCK_LOCK(so); - if ((so->so_state & - (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) { - SOCK_UNLOCK(so); - return (ENOTCONN); - } if (SOLISTENING(so)) { if (how != SHUT_WR) { so->so_error = ECONNABORTED; solisten_wakeup(so); /* unlocks so */ } else SOCK_UNLOCK(so); - return (0); + return (ENOTCONN); + } else if ((so->so_state & + (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) { + SOCK_UNLOCK(so); + return (ENOTCONN); } SOCK_UNLOCK(so); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index a283d308801f..9bb953617d99 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -807,18 +807,17 @@ tcp_usr_shutdown(struct socket *so, enum shutdown_how how) int error = 0; SOCK_LOCK(so); - if ((so->so_state & - (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) { - SOCK_UNLOCK(so); - return (ENOTCONN); - } if (SOLISTENING(so)) { if (how != SHUT_WR) { so->so_error = ECONNABORTED; solisten_wakeup(so); /* unlocks so */ } else SOCK_UNLOCK(so); - return (0); + return (ENOTCONN); + } else if ((so->so_state & + (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) { + SOCK_UNLOCK(so); + return (ENOTCONN); } SOCK_UNLOCK(so);