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) @@ -675,6 +680,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); +} + static int nl_setsbopt(struct socket *so, struct sockopt *sopt) {