From nobody Fri Feb 10 17:00:58 2023 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 4PD0P83bTdz3pKBG; Fri, 10 Feb 2023 17:01:00 +0000 (UTC) (envelope-from mike@karels.net) Received: from mail2.karels.net (mail2.karels.net [3.19.118.201]) (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 (2048 bits) client-digest SHA256) (Client CN "freebsd", Issuer "freebsd" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PD0P81ZpGz4lFt; Fri, 10 Feb 2023 17:01:00 +0000 (UTC) (envelope-from mike@karels.net) Authentication-Results: mx1.freebsd.org; none Received: from mail2.karels.net (localhost [IPv6:0:0:0:0:0:0:0:1]) by mail2.karels.net (8.16.1/8.16.1) with ESMTP id 31AH0wAA050136; Fri, 10 Feb 2023 11:00:58 -0600 (CST) (envelope-from mike@karels.net) Received: from [10.0.2.130] ([73.62.165.147]) by mail2.karels.net with ESMTPSA id 9Ss1LEp45mPWwwAAs/W3XQ (envelope-from ); Fri, 10 Feb 2023 11:00:58 -0600 From: Mike Karels To: "Alexander V. Chernikov" Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: Re: git: c3d3f3594fdf - stable/13 - netlink: allow to override sb_max for netlink sockets. Date: Fri, 10 Feb 2023 11:00:58 -0600 X-Mailer: MailMate (1.14r5937) Message-ID: <721D2CDA-6740-482D-BDC9-C5EFE56F7AE0@karels.net> In-Reply-To: <202302101619.31AGJESZ073291@gitrepo.freebsd.org> References: <202302101619.31AGJESZ073291@gitrepo.freebsd.org> 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 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4PD0P81ZpGz4lFt X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:16509, ipnet:3.16.0.0/14, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 10 Feb 2023, at 10:19, Alexander V. Chernikov wrote: > The branch stable/13 has been updated by melifaro: > > URL: https://cgit.FreeBSD.org/src/commit/?id=3Dc3d3f3594fdf653392936594= b75ec330af12d7fa > > commit c3d3f3594fdf653392936594b75ec330af12d7fa > Author: Alexander V. Chernikov > AuthorDate: 2023-02-10 16:07:17 +0000 > Commit: Alexander V. Chernikov > CommitDate: 2023-02-10 16:07:22 +0000 > > netlink: allow to override sb_max for netlink sockets. > > Netlink sockets sometimes require larger buffers than other sockets= =2E > For example, full-view IPv4 dump sent via netlink may consume 50+ m= egabytes. > The desired buffer may be bigger than the system maximum `sb_max`. > FreeBSD HEAD has a mechanism for overriding protocol `setsockopt()`= handler, > which netlink uses to permit buffer reservations beyond `sb_max`.= > This behaviour is handy as it doesn't require system administrator= to lift > the limits for other sockets. > Stable/13 lack such muchanism, so a different approach has to be us= ed. > This diff is a direct commit to stable/13 and it simply copies the = logic from > Netlink in -HEAD for checking if the larger buffer size should be = permitted. > > Differential Revision: https://reviews.freebsd.org/D38472 > --- > sys/kern/uipc_sockbuf.c | 3 ++- > sys/kern/uipc_socket.c | 10 ++++++++++ > sys/sys/sockopt.h | 1 + > 3 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c > index cbfcc0e5fe95..277965412779 100644 > --- a/sys/kern/uipc_sockbuf.c > +++ b/sys/kern/uipc_sockbuf.c > @@ -693,7 +693,8 @@ sbsetopt(struct socket *so, int cmd, u_long cc) > if (*lowat > *hiwat) > *lowat =3D *hiwat; > } else { > - if (!sbreserve_locked(sb, cc, so, curthread)) > + u_long limit =3D sogetmaxbuf(so); Spaces instead of tabs. Mike > + if (!sbreserve_locked_limit(sb, cc, so, limit, curthread)) > error =3D ENOBUFS; > } > if (error =3D=3D 0) > diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c > index f8931b653a4d..fdf718de2483 100644 > --- a/sys/kern/uipc_socket.c > +++ b/sys/kern/uipc_socket.c > @@ -128,6 +128,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > #include > #include > @@ -2975,6 +2976,15 @@ sooptcopyin(struct sockopt *sopt, void *buf, siz= e_t len, size_t minlen) > return (0); > } > > +u_long > +sogetmaxbuf(struct socket *so) > +{ > + if (so->so_proto->pr_domain->dom_family !=3D PF_NETLINK) > + return (sb_max); > + u_long nl_maxsockbuf =3D 512 * 1024 * 1024; /* 512M, XXX: init based = on physmem */ > + return ((priv_check(curthread, PRIV_NET_ROUTE) =3D=3D 0) ? nl_maxsock= buf : sb_max); > +} > + > /* > * Kernel version of setsockopt(2). > * > diff --git a/sys/sys/sockopt.h b/sys/sys/sockopt.h > index cb7fc3ffca27..d01d62f21680 100644 > --- a/sys/sys/sockopt.h > +++ b/sys/sys/sockopt.h > @@ -68,5 +68,6 @@ int accept_filt_getopt(struct socket *, struct sockop= t *); > int accept_filt_setopt(struct socket *, struct sockopt *); > int so_setsockopt(struct socket *so, int level, int optname, > void *optval, size_t optlen); > +u_long sogetmaxbuf(struct socket *so); > > #endif /* _SYS_SOCKOPT_H_ */