Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Feb 2023 11:00:58 -0600
From:      Mike Karels <mike@karels.net>
To:        "Alexander V. Chernikov" <melifaro@FreeBSD.org>
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.
Message-ID:  <721D2CDA-6740-482D-BDC9-C5EFE56F7AE0@karels.net>
In-Reply-To: <202302101619.31AGJESZ073291@gitrepo.freebsd.org>
References:  <202302101619.31AGJESZ073291@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <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
>
>     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 <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, 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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?721D2CDA-6740-482D-BDC9-C5EFE56F7AE0>