diff options
author | Tobias Brunner <tobias@strongswan.org> | 2015-04-14 09:56:10 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2015-05-21 10:19:08 +0200 |
commit | cc902695e80c6af8ef512ce641898fefd36cb6c8 (patch) | |
tree | a9be7b0ad0144605fc4a0cc114318806119b4a27 /src | |
parent | 682aab205e39473263d4fcf15194526e5b1be490 (diff) | |
download | strongswan-cc902695e80c6af8ef512ce641898fefd36cb6c8.tar.bz2 strongswan-cc902695e80c6af8ef512ce641898fefd36cb6c8.tar.xz |
kernel-netlink: Make buffer size for received Netlink messages configurable
Diffstat (limited to 'src')
-rw-r--r-- | src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c b/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c index a9adfe091..b0e3103d3 100644 --- a/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c +++ b/src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c @@ -83,6 +83,11 @@ struct private_netlink_socket_t { u_int retries; /** + * Buffer size for received Netlink messages + */ + u_int buflen; + + /** * Use parallel netlink queries */ bool parallel; @@ -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, |