]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-netlink: Increase the default receive buffer size
authorTobias Brunner <tobias@strongswan.org>
Fri, 21 Jul 2023 07:34:22 +0000 (09:34 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 26 Jul 2023 13:14:50 +0000 (15:14 +0200)
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.

conf/plugins/kernel-netlink.opt
src/libcharon/plugins/kernel_netlink/kernel_netlink_shared.c

index 39fdf5b997a1add315a37678666a2af3ae0825e8..9310a302299e47c7930ccc63355dd104a3e5e234 100644 (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.
index cb09446409ad48a809d66702afdfbb15025fc159..eb20a8515b569e67693cd40b7170b9d45be077c0 100644 (file)
 #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)