diff options
author | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2023-02-27 10:44:54 +0000 |
---|---|---|
committer | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2023-03-01 16:53:36 +0000 |
commit | aa330214cf1daacfdf706d12c01a34dc2f862693 (patch) | |
tree | 2bcff225d6e644c77abad930937069db2269fdbf | |
parent | 3623575a8613ce4faf40e3f29e926272309e6498 (diff) | |
download | src-aa330214cf1daacfdf706d12c01a34dc2f862693.tar.gz src-aa330214cf1daacfdf706d12c01a34dc2f862693.zip |
netlink: make the maximum allowed netlink socket buffer runtime tunable.
Dumping large routng tables (>1M paths with multipath) require the socket
buffer which is larger than the currently defined limit.
Allow the limit to be set in runtime, similar to kern.ipc.maxsockbuf.
Reported by: Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after: 1 day
Approved by: re(cperciva)
(cherry picked from commit 28a5d88f7091d1fc72f4f1bd8562d3c8b15883f5)
(cherry picked from commit b656161b84dce0322ab00d7958267fa47cda6318)
-rw-r--r-- | share/man/man4/netlink.4 | 6 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 3 | ||||
-rw-r--r-- | sys/netlink/netlink_domain.c | 25 |
3 files changed, 30 insertions, 4 deletions
diff --git a/share/man/man4/netlink.4 b/share/man/man4/netlink.4 index 1894de5841fe..c0d9b5a88ade 100644 --- a/share/man/man4/netlink.4 +++ b/share/man/man4/netlink.4 @@ -276,6 +276,12 @@ Default receive buffer for the netlink socket. Note that the socket recvspace has to be least as long as the longest message that can be received from this socket. .El +.Bl -tag -width indent +.It Va net.netlink.nl_maxsockbuf +Maximum receive buffer for the netlink socket that can be set via +.Dv SO_RCVBUF +socket option. +.El .Sh DEBUGGING Netlink implements per-functional-unit debugging, with different severities controllable via the diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index fdf718de2483..5b1e572d786f 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2976,12 +2976,13 @@ sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen) return (0); } +u_long nl_maxsockbuf = 512 * 1024 * 1024; /* 512M, XXX: init based on physmem */ + u_long sogetmaxbuf(struct socket *so) { if (so->so_proto->pr_domain->dom_family != PF_NETLINK) return (sb_max); - u_long nl_maxsockbuf = 512 * 1024 * 1024; /* 512M, XXX: init based on physmem */ return ((priv_check(curthread, PRIV_NET_ROUTE) == 0) ? nl_maxsockbuf : sb_max); } diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c index c451274b1e63..348788434175 100644 --- a/sys/netlink/netlink_domain.c +++ b/sys/netlink/netlink_domain.c @@ -76,9 +76,12 @@ SYSCTL_ULONG(_net_netlink, OID_AUTO, recvspace, CTLFLAG_RW, &nl_recvspace, 0, "Default netlink socket receive space"); extern u_long sb_max_adj; -#if 0 -static u_long nl_maxsockbuf = 512 * 1024 * 1024; /* 512M, XXX: init based on physmem */ -#endif +extern u_long nl_maxsockbuf; +static int sysctl_handle_nl_maxsockbuf(SYSCTL_HANDLER_ARGS); +SYSCTL_OID(_net_netlink, OID_AUTO, nl_maxsockbuf, + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, &nl_maxsockbuf, 0, + sysctl_handle_nl_maxsockbuf, "LU", + "Maximum Netlink socket buffer size"); uint32_t nlp_get_pid(const struct nlpcb *nlp) @@ -673,6 +676,22 @@ nl_ctloutput(struct socket *so, struct sockopt *sopt) return (error); } +static int +sysctl_handle_nl_maxsockbuf(SYSCTL_HANDLER_ARGS) +{ + int error = 0; + u_long tmp_maxsockbuf = nl_maxsockbuf; + + error = sysctl_handle_long(oidp, &tmp_maxsockbuf, arg2, req); + if (error || !req->newptr) + return (error); + if (tmp_maxsockbuf < MSIZE + MCLBYTES) + return (EINVAL); + nl_maxsockbuf = tmp_maxsockbuf; + + return (0); +} + #if 0 static int nl_setsbopt(struct socket *so, struct sockopt *sopt) |