aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2023-02-27 10:44:54 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2023-02-27 10:48:31 +0000
commit28a5d88f7091d1fc72f4f1bd8562d3c8b15883f5 (patch)
tree3ef9fa733388e5f06c075acc9ba83598a5e710f6
parenta4b92fefd2507140be6b4298bc3c2ba59d7b48b2 (diff)
downloadsrc-28a5d88f7091d1fc72f4f1bd8562d3c8b15883f5.tar.gz
src-28a5d88f7091d1fc72f4f1bd8562d3c8b15883f5.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
-rw-r--r--share/man/man4/netlink.46
-rw-r--r--sys/netlink/netlink_domain.c21
2 files changed, 27 insertions, 0 deletions
diff --git a/share/man/man4/netlink.4 b/share/man/man4/netlink.4
index fdcc823b01a6..ece4892f481e 100644
--- a/share/man/man4/netlink.4
+++ b/share/man/man4/netlink.4
@@ -280,6 +280,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/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c
index 5f9120f14308..01023f7244b6 100644
--- a/sys/netlink/netlink_domain.c
+++ b/sys/netlink/netlink_domain.c
@@ -77,6 +77,11 @@ SYSCTL_ULONG(_net_netlink, OID_AUTO, recvspace, CTLFLAG_RW, &nl_recvspace, 0,
extern u_long sb_max_adj;
static u_long nl_maxsockbuf = 512 * 1024 * 1024; /* 512M, XXX: init based on physmem */
+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)
@@ -676,6 +681,22 @@ nl_ctloutput(struct socket *so, struct sockopt *sopt)
}
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);
+}
+
+static int
nl_setsbopt(struct socket *so, struct sockopt *sopt)
{
int error, optval;