kernel-netlink: Use PAGE_SIZE as default size for the netlink receive buffer
authorTobias Brunner <tobias@strongswan.org>
Thu, 16 Jul 2015 09:50:22 +0000 (11:50 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 4 Aug 2015 12:15:19 +0000 (14:15 +0200)
The kernel uses NLMSG_GOODSIZE as default buffer size, which defaults to
the PAGE_SIZE if it is lower than 8192 or to that value otherwise.

In some cases (e.g. for dump messages) the kernel might use up to 16k
for messages, which might require increasing this value.

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

index 4338a5f..6adefd8 100644 (file)
@@ -1,4 +1,4 @@
-charon.plugins.kernel-netlink.buflen = 4096
+charon.plugins.kernel-netlink.buflen = <min(PAGE_SIZE, 8192)>
        Buffer size for received Netlink messages.
 
 charon.plugins.kernel-netlink.fwmark =
index 238de82..f7ce992 100644 (file)
@@ -571,7 +571,7 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
                .protocol = protocol,
                .names = names,
                .buflen = lib->settings->get_int(lib->settings,
-                                                       "%s.plugins.kernel-netlink.buflen", 4096, lib->ns),
+                                                       "%s.plugins.kernel-netlink.buflen", 0, lib->ns),
                .timeout = lib->settings->get_int(lib->settings,
                                                        "%s.plugins.kernel-netlink.timeout", 0, lib->ns),
                .retries = lib->settings->get_int(lib->settings,
@@ -582,6 +582,16 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
                .parallel = parallel,
        );
 
+       if (!this->buflen)
+       {
+               long pagesize = sysconf(_SC_PAGESIZE);
+               if (pagesize == -1)
+               {
+                       pagesize = 4096;
+               }
+               /* base this on NLMSG_GOODSIZE */
+               this->buflen = min(pagesize, 8192);
+       }
        if (this->socket == -1)
        {
                DBG1(DBG_KNL, "unable to create netlink socket");