kernel-netlink: Increase the default receive buffer size

Also simplify how we try to exceed the system-wide maximum.  We basically
just try to force the value and simply fall back to the regular call.
The kernel actually won't let the latter fail if the value is too big,
it just caps it at the internal maximum.
This commit is contained in:
Tobias Brunner
2023-07-26 15:14:50 +02:00
parent 0b47357091
commit 714c939018
2 changed files with 20 additions and 25 deletions
+7 -13
View File
@@ -1,14 +1,6 @@
charon.plugins.kernel-netlink.buflen = <min(PAGE_SIZE, 8192)>
Buffer size for received Netlink messages.
charon.plugins.kernel-netlink.force_receive_buffer_size = no
Force maximum Netlink receive buffer on Netlink socket.
If the maximum Netlink socket receive buffer in bytes set by
_receive_buffer_size_ exceeds the system-wide maximum from
/proc/sys/net/core/rmem_max, this option can be used to override the limit.
Enabling this option requires special privileges (CAP_NET_ADMIN).
charon.plugins.kernel-netlink.fwmark =
Firewall mark to set on the routing rule that directs traffic to our routing
table.
@@ -74,14 +66,16 @@ charon.plugins.kernel-netlink.process_rules = no
currently only useful if the kernel based route lookup is used (i.e. if
route installation is disabled or an inverted fwmark match is configured).
charon.plugins.kernel-netlink.receive_buffer_size = 0
charon.plugins.kernel-netlink.receive_buffer_size = 8388608
Maximum Netlink socket receive buffer in bytes.
Maximum Netlink socket receive buffer in bytes. This value controls how many
bytes of Netlink messages can be received on a Netlink socket. The default
value is set by /proc/sys/net/core/rmem_default. The specified value cannot
exceed the system-wide maximum from /proc/sys/net/core/rmem_max, unless
_force_receive_buffer_size_ is enabled.
bytes of Netlink messages can be queued to a Netlink socket. If set to 0,
the default from /proc/sys/net/core/rmem_default will apply. Note that the
kernel doubles the configured value to account for overhead. To exceed the
system-wide maximum from /proc/sys/net/core/rmem_max, special privileges
(CAP_NET_ADMIN) are necessary, otherwise, the kernel silently caps the
value.
charon.plugins.kernel-netlink.roam_events = yes
Whether to trigger roam events when interfaces, addresses or routes change.
@@ -57,6 +57,13 @@
#define SOL_NETLINK 270
#endif
/**
* Default receive buffer size
*/
#ifndef NETLINK_RCVBUF_DEFAULT
#define NETLINK_RCVBUF_DEFAULT (8 * 1024 * 1024)
#endif
typedef struct private_netlink_socket_t private_netlink_socket_t;
typedef struct private_netlink_event_socket_t private_netlink_event_socket_t;
@@ -656,7 +663,6 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
struct sockaddr_nl addr = {
.nl_family = AF_NETLINK,
};
bool force_buf = FALSE;
int on = 1, rcvbuf_size = 0;
INIT(this,
@@ -707,21 +713,16 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
rcvbuf_size = lib->settings->get_int(lib->settings,
"%s.plugins.kernel-netlink.receive_buffer_size",
rcvbuf_size, lib->ns);
NETLINK_RCVBUF_DEFAULT, lib->ns);
if (rcvbuf_size)
{
int optname;
force_buf = lib->settings->get_bool(lib->settings,
"%s.plugins.kernel-netlink.force_receive_buffer_size",
force_buf, lib->ns);
optname = force_buf ? SO_RCVBUFFORCE : SO_RCVBUF;
if (setsockopt(this->socket, SOL_SOCKET, optname, &rcvbuf_size,
if (setsockopt(this->socket, SOL_SOCKET, SO_RCVBUFFORCE, &rcvbuf_size,
sizeof(rcvbuf_size)) == -1 &&
setsockopt(this->socket, SOL_SOCKET, SO_RCVBUF, &rcvbuf_size,
sizeof(rcvbuf_size)) == -1)
{
DBG1(DBG_KNL, "failed to %supdate receive buffer size to %d: %s",
force_buf ? "forcibly " : "", rcvbuf_size, strerror(errno));
DBG1(DBG_KNL, "failed to set receive buffer size to %d: %s",
rcvbuf_size, strerror(errno));
}
}
if (this->parallel)