From nobody Wed Sep 28 10:20:20 2022 X-Original-To: dev-commits-src-main@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 4Mcsv84hMjz4dWc6; Wed, 28 Sep 2022 10:20:20 +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 4Mcsv83rZcz3GNq; Wed, 28 Sep 2022 10:20:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664360420; 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=z+gyc/gYgNHR/hzThubNJLc0Vzbg1dCFyrctT7AsHK8=; b=kwzXKwPC65LkkZYZ1QrzO6HpnGzvWRKK9fIAKlcozlgSRtYJbdHqfzxZEJ5+fuJ7GbLwij chQFgYGWkoXvGC0EI1pL1tZml4nPrhgVfxtiFwilMKtpGhIEG84wILByQMOkuHHNCGNq60 4Lap6YlU/txiAFnQfxHXzYJFZT6QDFFmnscCC/vGANwtsdUNA5IUtdJoPqXYTCTMb7cp4J ToR6kAzJJJN1keKTnctJ7qy0oKeeEtfwFB+83s1xsB+LXM+aUIVY9vv22vMZAerRAW2hG6 b8A+iuTWWs/3iuqTnKS+D2rMiybAyFyoOXbDtPcyZz3I7G2EoE26RF5v4NXOBA== 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 4Mcsv82p7yzRFM; Wed, 28 Sep 2022 10:20:20 +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 28SAKKlu036939; Wed, 28 Sep 2022 10:20:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28SAKKFZ036933; Wed, 28 Sep 2022 10:20:20 GMT (envelope-from git) Date: Wed, 28 Sep 2022 10:20:20 GMT Message-Id: <202209281020.28SAKKFZ036933@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: f66968564dd7 - main - protocols: make socket buffers ioctl handler changeable List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f66968564dd7e87a02f3a4d4bfa5e73c84e5e772 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664360420; 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=z+gyc/gYgNHR/hzThubNJLc0Vzbg1dCFyrctT7AsHK8=; b=UcoHxNsXDcgosPo/ctDHtS/H1doqIctGhlbQzWl0YyUOUEcYbYII/OWR7y26zpOwh1vYE+ OaXfnNUTV0GB5sXmys4EunaC59s6wCsL+g+yZ8K77ZGyjEIonmQb4HEFCi0NC2pqtvY7ry 3ml99KZlIPw5RcW9ao6j4zi571F4UTuQEpRsMrkUPfJ7zb2kjlkox0ay8XITBIz1af2/Am laTj5l9Ig9Ds+ZyVtLXOhokGpwUPeTH9PEBJ829ZcJBdlEvO6FpthFVr1Wy+CxZtm4IDsG PQXSdxi+nTMi1d71NcR+HMtqQmTMWrvPmsLrR/YyheZijpJ3jBO+avbxvHk1rw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664360420; a=rsa-sha256; cv=none; b=AcLkxaPVHnrGKut4EgHXpaAxgntUmy6NUp7iqnruuxg1CK30vqjtPCR+atyVWVWbtLiGHv SVzyw+m3ncS7OlfjAlADx5v4oBLjCIxsFNqv6i5WBU/7Vp88OGNc0CuAGlO4xKs5ITzS1E HAxk3WGZPq7nkDcbcWCTY9Vf3RiruMptIdZ95rgUY6nU28idPRk3VrmcFfOhLhnlcrmQu7 vKGj53wtzKvxttTeKIqZ65+o+kkKH/dLgUjhH/FmjDc7I1afXOzSMgWLI9pVWQGZ0nbHet S9scsNsHdV4I93HEzFBab4XtX6H1kghtTaOrPU3BpSavkQEQDwva04giskZUvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=f66968564dd7e87a02f3a4d4bfa5e73c84e5e772 commit f66968564dd7e87a02f3a4d4bfa5e73c84e5e772 Author: Alexander V. Chernikov AuthorDate: 2022-09-27 13:39:34 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-09-28 10:20:09 +0000 protocols: make socket buffers ioctl handler changeable Allow to set custom per-protocol handlers for the socket buffers ioctls by introducing pr_setsbopt callback with the default value set to the currently-used sbsetopt(). Reviewed by: glebius Differential Revision: https://reviews.freebsd.org/D36746 --- sys/kern/uipc_domain.c | 1 + sys/kern/uipc_sockbuf.c | 24 ++++++++++++++++++------ sys/kern/uipc_socket.c | 14 +------------- sys/sys/protosw.h | 2 ++ sys/sys/sockbuf.h | 3 ++- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index f1b2c616c662..0c92ff699171 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -201,6 +201,7 @@ pr_init(struct domain *dom, struct protosw *pr) DEFAULT(pr_sosend, sosend_generic); DEFAULT(pr_soreceive, soreceive_generic); DEFAULT(pr_sopoll, sopoll_generic); + DEFAULT(pr_setsbopt, sbsetopt); #define NOTSUPP(foo) if (pr->foo == NULL) pr->foo = foo ## _notsupp NOTSUPP(pr_accept); diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index da02de3e3301..a2d3fc28bbec 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -651,18 +651,30 @@ sbreserve_locked(struct socket *so, sb_which which, u_long cc, } int -sbsetopt(struct socket *so, int cmd, u_long cc) +sbsetopt(struct socket *so, struct sockopt *sopt) { struct sockbuf *sb; sb_which wh; short *flags; - u_int *hiwat, *lowat; - int error; + u_int cc, *hiwat, *lowat; + int error, optval; + + error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval); + if (error != 0) + return (error); + + /* + * Values < 1 make no sense for any of these options, + * so disallow them. + */ + if (optval < 1) + return (EINVAL); + cc = optval; sb = NULL; SOCK_LOCK(so); if (SOLISTENING(so)) { - switch (cmd) { + switch (sopt->sopt_name) { case SO_SNDLOWAT: case SO_SNDBUF: lowat = &so->sol_sbsnd_lowat; @@ -677,7 +689,7 @@ sbsetopt(struct socket *so, int cmd, u_long cc) break; } } else { - switch (cmd) { + switch (sopt->sopt_name) { case SO_SNDLOWAT: case SO_SNDBUF: sb = &so->so_snd; @@ -696,7 +708,7 @@ sbsetopt(struct socket *so, int cmd, u_long cc) } error = 0; - switch (cmd) { + switch (sopt->sopt_name) { case SO_SNDBUF: case SO_RCVBUF: if (SOLISTENING(so)) { diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 7f5e70d14e91..7e1d2c910dbd 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -3109,21 +3109,9 @@ sosetopt(struct socket *so, struct sockopt *sopt) case SO_RCVBUF: case SO_SNDLOWAT: case SO_RCVLOWAT: - error = sooptcopyin(sopt, &optval, sizeof optval, - sizeof optval); + error = so->so_proto->pr_setsbopt(so, sopt); if (error) goto bad; - - /* - * Values < 1 make no sense for any of these options, - * so disallow them. - */ - if (optval < 1) { - error = EINVAL; - goto bad; - } - - error = sbsetopt(so, sopt->sopt_name, optval); break; case SO_SNDTIMEO: diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 3b89c6f78caf..c0d1ae3761d8 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -62,6 +62,7 @@ struct uio; /* USE THESE FOR YOUR PROTOTYPES ! */ typedef int pr_ctloutput_t(struct socket *, struct sockopt *); +typedef int pr_setsbopt_t(struct socket *, struct sockopt *); typedef void pr_abort_t(struct socket *); typedef int pr_accept_t(struct socket *, struct sockaddr **); typedef int pr_attach_t(struct socket *, int, struct thread *); @@ -143,6 +144,7 @@ struct protosw { pr_sense_t *pr_sense; /* stat(2) */ pr_flush_t *pr_flush; /* XXXGL: merge with pr_shutdown_t! */ pr_sosetlabel_t *pr_sosetlabel; /* MAC, XXXGL: remove */ + pr_setsbopt_t *pr_setsbopt; /* Socket buffer ioctls */ }; /*#endif*/ diff --git a/sys/sys/sockbuf.h b/sys/sys/sockbuf.h index 7075cab650da..a0c6fd10116a 100644 --- a/sys/sys/sockbuf.h +++ b/sys/sys/sockbuf.h @@ -71,6 +71,7 @@ struct ktls_session; struct mbuf; struct sockaddr; struct socket; +struct sockopt; struct thread; struct selinfo; @@ -227,7 +228,7 @@ void sbflush(struct sockbuf *sb); void sbflush_locked(struct sockbuf *sb); void sbrelease(struct socket *, sb_which); void sbrelease_locked(struct socket *, sb_which); -int sbsetopt(struct socket *so, int cmd, u_long cc); +int sbsetopt(struct socket *so, struct sockopt *); bool sbreserve_locked(struct socket *so, sb_which which, u_long cc, struct thread *td); void sbsndptr_adv(struct sockbuf *sb, struct mbuf *mb, u_int len);