From nobody Wed Aug 10 18:10:27 2022 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 4M2yfC6kHsz4YlxM; Wed, 10 Aug 2022 18:10:27 +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 4M2yfC6BkZz3Mf7; Wed, 10 Aug 2022 18:10:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660155027; 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=mZqpa5RDNVjgzIvD3IOQ+Kc3mfr9xtyIghqP5Q/5D10=; b=RkHf29sHg14uW6QiGYEdiWd4YDrc+W1qPOhzl//j5OUQWR28hJbMZo2pX/UwtrEaKNIpuv su0VZiLVMt3Rqy4Y3APpnFz+6NU7AxMXotCLbI+V7bGcOH8/3NlNmQZBN5p6WJUDbUM+HX 6dXePgx4l0XqSgq8LtG8g9kWzviJR4LckfeCJ+7CDGUsaozQglJC2YziCFF/GTV6LqvJii /eP9rzDvakaPMchxOrit5h7C0gGfqvnLRe8UDgpGsi773dOqHHYPeIuSNmwF+Vz+O8yQiC mqyvL4S8jCTTuv/7lHp+q3o3TJgzoNpD1Fjfjz0l0n8qIcwj0vsstW9TmVt1Dg== 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 4M2yfC5J1gzLVZ; Wed, 10 Aug 2022 18:10:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27AIARO9044005; Wed, 10 Aug 2022 18:10:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27AIARKE044004; Wed, 10 Aug 2022 18:10:27 GMT (envelope-from git) Date: Wed, 10 Aug 2022 18:10:27 GMT Message-Id: <202208101810.27AIARKE044004@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: 8f5a0a2e4f31 - main - sockets: provide solisten_clone(), solisten_enqueue() 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: 8f5a0a2e4f315a03caaa2d51efdcf837e303e510 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660155027; 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=mZqpa5RDNVjgzIvD3IOQ+Kc3mfr9xtyIghqP5Q/5D10=; b=hzZNJL3T0z0NSNZ4J3AeG8b8k+y2ssNkLchwJ65GJizZbRhO+QN87NgutCPRA6ToiwZf6O oegLE384ZhJyaUpgaVSWY/4NcFe96lyG1tFP4EzhWBkFKjPRPjRBK2wbJ6yO6WyIg5c2oP zK6qQQbWSHk+el+oiu0yXg5PimcxtkNlZJ6S6weYUlW3z3iu26ebwKxj9f0ZmUSrOQGRFN FOjQStGzl11QzkJ2Bl4xJ+t2uDLI7RcuDr5gsBBCoN/x1LCNQQee6TC3jofUa1LoC/Kl5P ZZvzXf1VWsyAGSgLYLgGKINBPblIqWB3CA5vboKNEKm8eBWC8bv7YEFJh/sY2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660155027; a=rsa-sha256; cv=none; b=vk/yKU6BWwJl39KDmE+/Aa+h6xBMD83pruAolMH4+6V7omDr5fIfAR5KLs1sLZK6I5/Y6J vcI0ze06w/02qrBScMjCxow/ei4QgxMBgjH/i9WP7HRM8vY6ovRiu/6I9JqG78OoiOXynF 4iK7HoZUChZFEWRSfu68Iq9F92kq9dZekV6kjxj3WOvfoZI9s9V4hFxUZcQRzjUaZjw+fT w1/kq/ouc3cso7mkddOhITjg3Pb3F0eyQCx3XGfwZCLZyWsKBYhKAKrE2fNVryrLUwFfnJ TR3AHE05/AqNJ6wFyU65DvueHhMTzIBmE30a+waO1grUy1kHtxO35jE0pPy8Xg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=8f5a0a2e4f315a03caaa2d51efdcf837e303e510 commit 8f5a0a2e4f315a03caaa2d51efdcf837e303e510 Author: Gleb Smirnoff AuthorDate: 2022-08-10 18:09:34 +0000 Commit: Gleb Smirnoff CommitDate: 2022-08-10 18:09:34 +0000 sockets: provide solisten_clone(), solisten_enqueue() as alternative KPI to sonewconn(). The latter has three stages: - check the listening socket queue limits - allocate a new socket - call into protocol attach method - link the new socket into the listen queue of the listening socket The attach method, originally designed for a creation of socket by the socket(2) syscall has slightly different semantics than attach of a socket cloned by listener. Make it possible for protocols to call into the first stage, then perform a different attach, and then call into the final stage. The first stage, that checks limits and clones a socket is called solisten_clone(), and the function that enqueues the socket is solisten_enqueue(). Reviewed by: tuexen Differential revision: https://reviews.freebsd.org/D36063 --- sys/kern/uipc_socket.c | 86 +++++++++++++++++++++++++++++++++++--------------- sys/sys/socketvar.h | 3 ++ 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 8ecf83d30e28..73725efceb2d 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -587,16 +587,17 @@ SYSCTL_TIMEVAL_SEC(_kern_ipc, OID_AUTO, sooverinterval, CTLFLAG_RW, "Delay in seconds between warnings for listen socket overflows"); /* - * When an attempt at a new connection is noted on a socket which accepts - * connections, sonewconn is called. If the connection is possible (subject - * to space constraints, etc.) then we allocate a new structure, properly - * linked into the data structure of the original socket, and return this. - * Connstatus may be 0, or SS_ISCONFIRMING, or SS_ISCONNECTED. + * When an attempt at a new connection is noted on a socket which supports + * accept(2), the protocol has two options: + * 1) Call legacy sonewconn() function, which would call protocol attach + * method, same as used for socket(2). + * 2) Call solisten_clone(), do attach that is specific to a cloned connection, + * and then call solisten_enqueue(). * * Note: the ref count on the socket is 0 on return. */ struct socket * -sonewconn(struct socket *head, int connstatus) +solisten_clone(struct socket *head) { struct sbuf descrsb; struct socket *so; @@ -701,20 +702,27 @@ sonewconn(struct socket *head, int connstatus) } KASSERT(sbuf_len(&descrsb) > 0, ("%s: sbuf creation failed", __func__)); + /* + * Preserve the historic listen queue overflow log + * message, that starts with "sonewconn:". It has + * been known to sysadmins for years and also test + * sys/kern/sonewconn_overflow checks for it. + */ if (head->so_cred == 0) { - log(LOG_DEBUG, - "%s: pcb %p (%s): Listen queue overflow: " - "%i already in queue awaiting acceptance " - "(%d occurrences)\n", - __func__, head->so_pcb, sbuf_data(&descrsb), + log(LOG_DEBUG, "sonewconn: pcb %p (%s): " + "Listen queue overflow: %i already in " + "queue awaiting acceptance (%d " + "occurrences)\n", head->so_pcb, + sbuf_data(&descrsb), qlen, overcount); } else { - log(LOG_DEBUG, "%s: pcb %p (%s): Listen queue overflow: " + log(LOG_DEBUG, "sonewconn: pcb %p (%s): " + "Listen queue overflow: " "%i already in queue awaiting acceptance " "(%d occurrences), euid %d, rgid %d, jail %s\n", - __func__, head->so_pcb, sbuf_data(&descrsb), - qlen, overcount, - head->so_cred->cr_uid, head->so_cred->cr_rgid, + head->so_pcb, sbuf_data(&descrsb), qlen, + overcount, head->so_cred->cr_uid, + head->so_cred->cr_rgid, head->so_cred->cr_prison ? head->so_cred->cr_prison->pr_name : "not_jailed"); @@ -758,25 +766,52 @@ sonewconn(struct socket *head, int connstatus) __func__, head->so_pcb); return (NULL); } + so->so_rcv.sb_lowat = head->sol_sbrcv_lowat; + so->so_snd.sb_lowat = head->sol_sbsnd_lowat; + so->so_rcv.sb_timeo = head->sol_sbrcv_timeo; + so->so_snd.sb_timeo = head->sol_sbsnd_timeo; + so->so_rcv.sb_flags = head->sol_sbrcv_flags & SB_AUTOSIZE; + so->so_snd.sb_flags = head->sol_sbsnd_flags & SB_AUTOSIZE; if ((so->so_proto->pr_flags & PR_SOCKBUF) == 0) { so->so_snd.sb_mtx = &so->so_snd_mtx; so->so_rcv.sb_mtx = &so->so_rcv_mtx; } - /* Socket starts with a reference from the listen queue. */ - refcount_init(&so->so_count, 1); + + return (so); +} + +/* Connstatus may be 0, or SS_ISCONFIRMING, or SS_ISCONNECTED. */ +struct socket * +sonewconn(struct socket *head, int connstatus) +{ + struct socket *so; + + if ((so = solisten_clone(head)) == NULL) + return (NULL); + if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { - MPASS(refcount_release(&so->so_count)); sodealloc(so); log(LOG_DEBUG, "%s: pcb %p: pru_attach() failed\n", __func__, head->so_pcb); return (NULL); } - so->so_rcv.sb_lowat = head->sol_sbrcv_lowat; - so->so_snd.sb_lowat = head->sol_sbsnd_lowat; - so->so_rcv.sb_timeo = head->sol_sbrcv_timeo; - so->so_snd.sb_timeo = head->sol_sbsnd_timeo; - so->so_rcv.sb_flags |= head->sol_sbrcv_flags & SB_AUTOSIZE; - so->so_snd.sb_flags |= head->sol_sbsnd_flags & SB_AUTOSIZE; + + solisten_enqueue(so, connstatus); + + return (so); +} + +/* + * Enqueue socket cloned by solisten_clone() to the listen queue of the + * listener it has been cloned from. + */ +void +solisten_enqueue(struct socket *so, int connstatus) +{ + struct socket *head = so->so_listen; + + MPASS(refcount_load(&so->so_count) == 0); + refcount_init(&so->so_count, 1); SOLISTEN_LOCK(head); if (head->sol_accept_filter != NULL) @@ -815,13 +850,14 @@ sonewconn(struct socket *head, int connstatus) head->sol_incqlen++; SOLISTEN_UNLOCK(head); } - return (so); } #if defined(SCTP) || defined(SCTP_SUPPORT) /* * Socket part of sctp_peeloff(). Detach a new socket from an * association. The new socket is returned with a reference. + * + * XXXGL: reduce copy-paste with solisten_clone(). */ struct socket * sopeeloff(struct socket *head) diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index c496239f92bc..ed797c6d6239 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -474,7 +474,10 @@ int solisten(struct socket *so, int backlog, struct thread *td); void solisten_proto(struct socket *so, int backlog); void solisten_proto_abort(struct socket *so); int solisten_proto_check(struct socket *so); +void solisten_enqueue(struct socket *, int); int solisten_dequeue(struct socket *, struct socket **, int); +struct socket * + solisten_clone(struct socket *); struct socket * sonewconn(struct socket *head, int connstatus); struct socket *