kernel-netlink: Use PAGE_SIZE as default size 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.
This commit is contained in:
Tobias Brunner committed 2015-08-04 14:15:19 +02:00
1 parent a6896b6149
commit 197de6e66b
2 files changed
+12 -2

No files matched your search

+1 -1
View 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. Buffer size for received Netlink messages.
charon.plugins.kernel-netlink.fwmark = charon.plugins.kernel-netlink.fwmark =
@@ -571,7 +571,7 @@ netlink_socket_t *netlink_socket_create(int protocol, enum_name_t *names,
.protocol = protocol, .protocol = protocol,
.names = names, .names = names,
.buflen = lib->settings->get_int(lib->settings, .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, .timeout = lib->settings->get_int(lib->settings,
"%s.plugins.kernel-netlink.timeout", 0, lib->ns), "%s.plugins.kernel-netlink.timeout", 0, lib->ns),
.retries = lib->settings->get_int(lib->settings, .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, .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) if (this->socket == -1)
{ {
DBG1(DBG_KNL, "unable to create netlink socket"); DBG1(DBG_KNL, "unable to create netlink socket");