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 2015-07-16 11:50:22 +02:00
parent a6896b6149
commit 197de6e66b
2 changed files with 12 additions and 2 deletions

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.
charon.plugins.kernel-netlink.fwmark =

View 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");