From 7e40d9705de5e94ff64684573c573deb97950b5e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 16 Jul 2015 11:50:22 +0200 Subject: [PATCH] kernel-netlink: Use the PAGE_SIZE as default for the netlink receive buffer 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 | 2 +- src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/conf/plugins/kernel-netlink.opt b/conf/plugins/kernel-netlink.opt index 4338a5f..6adefd8 100644 --- a/conf/plugins/kernel-netlink.opt +++ b/conf/plugins/kernel-netlink.opt @@ -1,4 +1,4 @@ -charon.plugins.kernel-netlink.buflen = 4096 +charon.plugins.kernel-netlink.buflen = Buffer size for received Netlink messages. charon.plugins.kernel-netlink.fwmark = diff --git a/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c b/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c index 809d0f4..ddb2254 100644 --- a/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c +++ b/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c @@ -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"); -- 2.4.6