From nobody Wed Sep 04 16:08:18 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 4WzS8M0xmSz5V9VS; Wed, 04 Sep 2024 16:08:19 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WzS8L6zNLz4ctq; Wed, 4 Sep 2024 16:08:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725466099; 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=kNIBCDRWwnIHp31x3Z92MxzGtdNXWZ65fWlXodoJW78=; b=G2DyGMjugfIlRXgaFQ3PkhOVeBwvVUjsSH7LbcHqfhfY5cP2cWgZYDkybIQC3yIn6yf+An AafBb3STbH1LYhUKGSbNRav8gfYwm/9x66yklG9MTZlj6dSDrfK4Jx3LbmLmArZ7TSu3AA J0y2WZxJJgPdD1WfsS6DZbF1ZGMvH7e6HSwUl7YqGwU02eDe14QCUeu0VjNaOWgjuCzR9E 3H/XAwDjchmi3xsKzv3yRlKgmj6iq9DbvCzhjuSJUxFUbs42PXm4vH1bFmPIQmQWZhdlWe sEqyKEm+758CqQE5RqwcWNjZDxOUYjuSmoc6lk/nmYeYmEj6TP+XuQZLrTS+yQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725466099; a=rsa-sha256; cv=none; b=kEU3xA7orFHpoXKICDDW9A/q+Cy2CRQbrrhr8beUkGcKS1q5ev6B4BfKLjt90CQfBPyNk1 IqqvFyyj+DAI24MllriWHbsVUQu9dW5epGc9frTXxHEOQpmDFpo8SFhRpGJjZsl9mspGHy ULTuxHobP7fGaMCDlL/dGWYd7eL0eqb3Kd6lMX28IXJmJpdT9olkeekGjdmYD4k+JqEkXT Q3iMEEAW5Y0xS0KCrv/VI9p2FW8oQ9dvIMMhnF3b4hvtrq+b23v4XR9jXRNBVbVuH2S6gK 0Vp1BVQSBZ9fX8ouNJik0pg5uI7fCBv7BfkRXhsn7Y7kcWnbvTjWVOSUNem0yg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725466099; 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=kNIBCDRWwnIHp31x3Z92MxzGtdNXWZ65fWlXodoJW78=; b=gzfD27McO0ZUcwDBbAANdFw+IOvgouB/RcCLNn73R9dAUerOCcyVcn0fqyppyfy2CrzJ/C TGROhYNKM8S24RKrtVjqQwBJK9OJZFlQqnlMNDxscnGg6cViWDt1H7vW96bEWdxcrVLZcF 3d/rUfPRl4YOy0wmaSfY7cwX+Ot1Ys6pBFLdhLf7srt1blRjz/bX5saEmGsMq4PX69HWH6 zjB1asxx5p1/PKXn6kUROtZWh8N8tPOhRUXHkpLB7PY1B6Ke9m5TG8FLy9SrsgeX6DDCtJ 9+C+l88ifLxPM2dTSNSFzGUeXgSeBnMMbbvqTS9a31PYicsxiucc2ynxV1JA+Q== 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 4WzS8L6Zs5zWm9; Wed, 4 Sep 2024 16:08:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 484G8Ifo040203; Wed, 4 Sep 2024 16:08:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 484G8IW6040200; Wed, 4 Sep 2024 16:08:18 GMT (envelope-from git) Date: Wed, 4 Sep 2024 16:08:18 GMT Message-Id: <202409041608.484G8IW6040200@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: 881886673a34 - stable/13 - MFC: ng_ksocket: fix accept(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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 881886673a3423926c8b5f0955c4b966317f8ae8 Auto-Submitted: auto-generated The branch stable/13 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=881886673a3423926c8b5f0955c4b966317f8ae8 commit 881886673a3423926c8b5f0955c4b966317f8ae8 Author: Gleb Smirnoff AuthorDate: 2023-11-17 17:24:30 +0000 Commit: Eugene Grosbein CommitDate: 2024-09-04 16:07:52 +0000 MFC: ng_ksocket: fix accept(2) - Provide listen upcall and set it on NGM_KSOCKET_LISTEN - Mask EWOULDBLOCK on NGM_KSOCKET_ACCEPT Reviewed by: afedorov Differential Revision: https://reviews.freebsd.org/D42637 PR: 272319 PR: 275106 Fixes: 779f106aa169256b7010a1d8f963ff656b881e92 (cherry picked from commit 43f7e21668105cc5a3c66eae5ecef0203c2df62f) --- sys/netgraph/ng_ksocket.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/sys/netgraph/ng_ksocket.c b/sys/netgraph/ng_ksocket.c index 027aaae4e607..6e12415e449a 100644 --- a/sys/netgraph/ng_ksocket.c +++ b/sys/netgraph/ng_ksocket.c @@ -152,6 +152,10 @@ static const struct ng_ksocket_alias ng_ksocket_protos[] = { /* Helper functions */ static int ng_ksocket_accept(priv_p); +static int ng_ksocket_listen_upcall(struct socket *so, void *arg, + int waitflag); +static void ng_ksocket_listen_upcall2(node_p node, hook_p hook, + void *arg1, int arg2); static int ng_ksocket_incoming(struct socket *so, void *arg, int waitflag); static int ng_ksocket_parse(const struct ng_ksocket_alias *aliases, const char *s, int family); @@ -696,6 +700,12 @@ ng_ksocket_rcvmsg(node_p node, item_p item, hook_p lasthook) /* Listen */ so->so_state |= SS_NBIO; error = solisten(so, *((int32_t *)msg->data), td); + if (error == 0) { + SOLISTEN_LOCK(so); + solisten_upcall_set(so, + ng_ksocket_listen_upcall, priv); + SOLISTEN_UNLOCK(so); + } break; } @@ -716,11 +726,15 @@ ng_ksocket_rcvmsg(node_p node, item_p item, hook_p lasthook) /* * If a connection is already complete, take it. * Otherwise let the upcall function deal with - * the connection when it comes in. + * the connection when it comes in. Don't return + * EWOULDBLOCK, per ng_ksocket(4) documentation. */ error = ng_ksocket_accept(priv); - if (error != 0 && error != EWOULDBLOCK) + if (error == EWOULDBLOCK) + error = 0; + if (error != 0) ERROUT(error); + priv->response_token = msg->header.token; raddr = priv->response_addr = NGI_RETADDR(item); break; @@ -1058,10 +1072,6 @@ ng_ksocket_incoming2(node_p node, hook_p hook, void *arg1, int arg2) } } - /* Check whether a pending accept operation has completed */ - if (priv->flags & KSF_ACCEPTING) - (void )ng_ksocket_accept(priv); - /* * If we don't have a hook, we must handle data events later. When * the hook gets created and is connected, this upcall function @@ -1244,6 +1254,25 @@ out: return (0); } +static int +ng_ksocket_listen_upcall(struct socket *so, void *arg, int waitflag) +{ + priv_p priv = arg; + int wait = ((waitflag & M_WAITOK) ? NG_WAITOK : 0) | NG_QUEUE; + + ng_send_fn1(priv->node, NULL, &ng_ksocket_listen_upcall2, priv, 0, + wait); + return (SU_OK); +} + +static void +ng_ksocket_listen_upcall2(node_p node, hook_p hook, void *arg1, int arg2) +{ + const priv_p priv = NG_NODE_PRIVATE(node); + + (void )ng_ksocket_accept(priv); +} + /* * Parse out either an integer value or an alias. */