]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-netlink: Also set the receive buffer size on event sockets
authorTobias Brunner <tobias@strongswan.org>
Fri, 21 Jul 2023 07:39:09 +0000 (09:39 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 26 Jul 2023 13:14:50 +0000 (15:14 +0200)
This was weirdly overlooked and could cause issues e.g. on hosts with
lots of route changes.

src/libcharon/plugins/kernel_netlink/kernel_netlink_shared.c

index eb20a8515b569e67693cd40b7170b9d45be077c0..72c13a69787da8aeeac2fb23b29a08d995c9c01b 100644 (file)
@@ -653,6 +653,29 @@ u_int netlink_get_buflen()
        return buflen;
 }
 
+/**
+ * Set the configured receive buffer size on the given socket.
+ */
+static void set_rcvbuf_size(int socket)
+{
+       int rcvbuf_size = 0;
+
+       rcvbuf_size = lib->settings->get_int(lib->settings,
+                                               "%s.plugins.kernel-netlink.receive_buffer_size",
+                                               NETLINK_RCVBUF_DEFAULT, lib->ns);
+       if (rcvbuf_size)
+       {
+               if (setsockopt(socket, SOL_SOCKET, SO_RCVBUFFORCE, &rcvbuf_size,
+                                          sizeof(rcvbuf_size)) == -1 &&
+                       setsockopt(socket, SOL_SOCKET, SO_RCVBUF, &rcvbuf_size,
+                                          sizeof(rcvbuf_size)) == -1)
+               {
+                       DBG1(DBG_KNL, "failed to set receive buffer size to %d: %s",
+                                rcvbuf_size, strerror(errno));
+               }
+       }
+}
+
 /*
  * Described in header
  */
@@ -663,7 +686,7 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
        struct sockaddr_nl addr = {
                .nl_family = AF_NETLINK,
        };
-       int on = 1, rcvbuf_size = 0;
+       int on = 1;
 
        INIT(this,
                .public = {
@@ -711,20 +734,8 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
        ignore_result(setsockopt(this->socket, SOL_NETLINK, NETLINK_EXT_ACK, &on,
                                                         sizeof(on)));
 
-       rcvbuf_size = lib->settings->get_int(lib->settings,
-                                               "%s.plugins.kernel-netlink.receive_buffer_size",
-                                               NETLINK_RCVBUF_DEFAULT, lib->ns);
-       if (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 set receive buffer size to %d: %s",
-                                rcvbuf_size, strerror(errno));
-               }
-       }
+       set_rcvbuf_size(this->socket);
+
        if (this->parallel)
        {
                lib->watcher->add(lib->watcher, this->socket, WATCHER_READ, watch, this);
@@ -806,6 +817,8 @@ netlink_event_socket_t *netlink_event_socket_create(int protocol, uint32_t group
                return NULL;
        }
 
+       set_rcvbuf_size(this->socket);
+
        if (bind(this->socket, (struct sockaddr*)&addr, sizeof(addr)))
        {
                DBG1(DBG_KNL, "unable to bind netlink event socket: %s (%d)",