kernel-netlink: Make buffer size for received Netlink messages configurable

This commit is contained in:
Tobias Brunner
2015-05-21 10:19:08 +02:00
parent 682aab205e
commit cc902695e8
2 changed files with 14 additions and 7 deletions
+3
View File
@@ -1,3 +1,6 @@
charon.plugins.kernel-netlink.buflen = 4096
Buffer size for received Netlink messages.
charon.plugins.kernel-netlink.fwmark = charon.plugins.kernel-netlink.fwmark =
Firewall mark to set on the routing rule that directs traffic to our routing Firewall mark to set on the routing rule that directs traffic to our routing
table. table.
@@ -82,6 +82,11 @@ struct private_netlink_socket_t {
*/ */
u_int retries; u_int retries;
/**
* Buffer size for received Netlink messages
*/
u_int buflen;
/** /**
* Use parallel netlink queries * 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 * Read a single Netlink message from socket, return 0 on error, -1 on timeout
*/ */
static ssize_t read_msg(private_netlink_socket_t *this, 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; 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) static bool read_and_queue(private_netlink_socket_t *this, bool block)
{ {
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
union { char buf[this->buflen];
struct nlmsghdr hdr;
char bytes[4096];
} buf;
ssize_t len; ssize_t len;
len = read_msg(this, buf.bytes, sizeof(buf.bytes), block); len = read_msg(this, buf, sizeof(buf), block);
if (len == -1) if (len == -1)
{ {
return TRUE; return TRUE;
} }
if (len) if (len)
{ {
hdr = &buf.hdr; hdr = (struct nlmsghdr*)buf;
while (NLMSG_OK(hdr, len)) while (NLMSG_OK(hdr, len))
{ {
if (!queue(this, hdr)) 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), .entries = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 4),
.protocol = protocol, .protocol = protocol,
.names = names, .names = names,
.buflen = lib->settings->get_int(lib->settings,
"%s.plugins.kernel-netlink.buflen", 4096, 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,