[PATCH V2] Increase the size of the netlink recvmsg buffer
dwilder <[email protected]>
| Newsgroups | gmane.linux.keepalived.devel |
|---|---|
| Message-ID | <[email protected]> |
On systems with a page size larger than 4096 keepalived may report: "Netlink: error: message truncated messages" This error was reported on a ppc64le in an OpenStack/Nutron environment. Ppc64le is using a 64k pages size. I found that keepalived's netlink recvmsg buffer was too small causing messages to be truncated. The size of the read buffer for the netlink socket should be based on page size however, it should not exceed 8192. See the comment in the patch. I tested the fix by creating 100 veth interfaces and verifying the errors did not return. Version 2 patch adds the check for page size and adjusts the buffer size accordingly. Signed-off-by: David Wilder <[email protected]> --- keepalived/vrrp/vrrp_netlink.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/keepalived/vrrp/vrrp_netlink.c b/keepalived/vrrp/vrrp_netlink.c index 3fe5f53..6a8c324 100644 --- a/keepalived/vrrp/vrrp_netlink.c +++ b/keepalived/vrrp/vrrp_netlink.c @@ -514,8 +514,19 @@ netlink_parse_info(int (*filter) (struct sockaddr_nl *, struct nlmsghdr *), int ret = 0; int error; + /* The size of the read buffer for the NL socket is based on page + * size however, it should not exceed 8192. See the comment in: + * linux/include/linux/netlink.h (copied below): + * skb should fit one page. This choice is good for headerless malloc. + * But we should limit to 8K so that userspace does not have to + * use enormous buffer sizes on recvmsg() calls just to avoid + * MSG_TRUNC when PAGE_SIZE is very large. + */ + size_t nlmsg_buf_size = getpagesize(); + if (nlmsg_buf_size > 8192) nlmsg_buf_size = 8192; + while (1) { - char buf[4096]; + char buf[nlmsg_buf_size]; struct iovec iov = { .iov_base = buf, .iov_len = sizeof buf -- 2.7.4 ------------------------------------------------------------------------------