]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-netlink: Make buffer size for received Netlink messages configurable
authorTobias Brunner <tobias@strongswan.org>
Tue, 14 Apr 2015 07:56:10 +0000 (09:56 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 21 May 2015 08:19:08 +0000 (10:19 +0200)
conf/plugins/kernel-netlink.opt
src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c

index 800ba20c0e899e4269729d7a17ba4a0be5da9a66..4338a5fbde732a3d0e33f59ab2662bd5bb3ecc2a 100644 (file)
@@ -1,3 +1,6 @@
+charon.plugins.kernel-netlink.buflen = 4096
+       Buffer size for received Netlink messages.
+
 charon.plugins.kernel-netlink.fwmark =
        Firewall mark to set on the routing rule that directs traffic to our routing
        table.
index a9adfe09128da225e63bd3972701111ca05b9e2c..b0e3103d327f3c94b95ee183e8b78c46c8d7e5ff 100644 (file)
@@ -82,6 +82,11 @@ struct private_netlink_socket_t {
         */
        u_int retries;
 
+       /**
+        * Buffer size for received Netlink messages
+        */
+       u_int buflen;
+
        /**
         * Use parallel netlink queries
         */
@@ -161,7 +166,7 @@ static bool write_msg(private_netlink_socket_t *this, struct nlmsghdr *msg)
  * Read a single Netlink message from socket, return 0 on error, -1 on timeout
  */
 static ssize_t read_msg(private_netlink_socket_t *this,
-                                               char buf[4096], size_t buflen, bool block)
+                                               char *buf, size_t buflen, bool block)
 {
        ssize_t len;
 
@@ -236,20 +241,17 @@ static bool queue(private_netlink_socket_t *this, struct nlmsghdr *buf)
 static bool read_and_queue(private_netlink_socket_t *this, bool block)
 {
        struct nlmsghdr *hdr;
-       union {
-               struct nlmsghdr hdr;
-               char bytes[4096];
-       } buf;
+       char buf[this->buflen];
        ssize_t len;
 
-       len = read_msg(this, buf.bytes, sizeof(buf.bytes), block);
+       len = read_msg(this, buf, sizeof(buf), block);
        if (len == -1)
        {
                return TRUE;
        }
        if (len)
        {
-               hdr = &buf.hdr;
+               hdr = (struct nlmsghdr*)buf;
                while (NLMSG_OK(hdr, len))
                {
                        if (!queue(this, hdr))
@@ -568,6 +570,8 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
                .entries = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 4),
                .protocol = protocol,
                .names = names,
+               .buflen = lib->settings->get_int(lib->settings,
+                                                       "%s.plugins.kernel-netlink.buflen", 4096, lib->ns),
                .timeout = lib->settings->get_int(lib->settings,
                                                        "%s.plugins.kernel-netlink.timeout", 0, lib->ns),
                .retries = lib->settings->get_int(lib->settings,