Date: Fri, 24 Feb 2023 10:40:40 +0000 From: Alexander Chernikov <melifaro@FreeBSD.org> To: Mike Karels <mike@karels.net> Cc: "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, "dev-commits-src-branches@freebsd.org" <dev-commits-src-branches@FreeBSD.org> Subject: Re: git: c3d3f3594fdf - stable/13 - netlink: allow to override sb_max for netlink sockets. Message-ID: <2F9CFF0F-F14C-401F-97D6-E83B3842A599@FreeBSD.org> In-Reply-To: <721D2CDA-6740-482D-BDC9-C5EFE56F7AE0@karels.net> References: <202302101619.31AGJESZ073291@gitrepo.freebsd.org> <721D2CDA-6740-482D-BDC9-C5EFE56F7AE0@karels.net>
next in thread | previous in thread | raw e-mail | index | archive | help
> On 10 Feb 2023, at 17:00, Mike Karels <mike@karels.net> wrote: >=20 > On 10 Feb 2023, at 10:19, Alexander V. Chernikov wrote: >=20 >> The branch stable/13 has been updated by melifaro: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dc3d3f3594fdf653392936594b75ec330= af12d7fa >>=20 >> commit c3d3f3594fdf653392936594b75ec330af12d7fa >> Author: Alexander V. Chernikov <melifaro@FreeBSD.org> >> AuthorDate: 2023-02-10 16:07:17 +0000 >> Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> >> CommitDate: 2023-02-10 16:07:22 +0000 >>=20 >> netlink: allow to override sb_max for netlink sockets. >>=20 >> Netlink sockets sometimes require larger buffers than other = sockets. >> For example, full-view IPv4 dump sent via netlink may consume 50+ = megabytes. >> 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 = used. >> 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. >>=20 >> 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(-) >>=20 >> 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); >=20 > Spaces instead of tabs. >=20 > Mike Ups. Haven=E2=80=99t noticed that one. Fixed in f9f0d2f475e05ad88120ef1c0a645d2aa6dc3e94. Thank you! >=20 >> + 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 <sys/event.h> >> #include <sys/eventhandler.h> >> #include <sys/poll.h> >> +#include <sys/priv.h> >> #include <sys/proc.h> >> #include <sys/protosw.h> >> #include <sys/sbuf.h> >> @@ -2975,6 +2976,15 @@ sooptcopyin(struct sockopt *sopt, void *buf, = size_t len, size_t minlen) >> return (0); >> } >>=20 >> +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_maxsockbuf : 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 = sockopt *); >> 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); >>=20 >> #endif /* _SYS_SOCKOPT_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2F9CFF0F-F14C-401F-97D6-E83B3842A599>