libnetlink: fix netlink buffer space handling
authorFelix Fietkau <nbd@nbd.name>
Wed, 25 Aug 2021 11:29:45 +0000 (13:29 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 25 Aug 2021 11:29:47 +0000 (13:29 +0200)
Significantly increaese buffer size in order to avoid missing events
Do not stop polling socket after running out of buffer space

Signed-off-by: Felix Fietkau <nbd@nbd.name>
libnetlink.c

index 477e1a25126ee423bd0736cb64a79f8316ef7c50..5c5523da2613a80712b19a6e4321a06732c0f2fd 100644 (file)
@@ -27,7 +27,7 @@
 #include "libnetlink.h"
 
 #ifndef DEFAULT_RTNL_BUFSIZE
-#define DEFAULT_RTNL_BUFSIZE   256 * 1024
+#define DEFAULT_RTNL_BUFSIZE   4 * 1024 * 1024
 #endif
 
 #ifndef RTNL_SND_BUFSIZE
@@ -48,6 +48,7 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
        socklen_t addr_len;
        int sndbuf = RTNL_SND_BUFSIZE;
        int rcvbuf = RTNL_RCV_BUFSIZE;
+       int yes = 1;
 
        memset(rth, 0, sizeof(*rth));
 
@@ -69,6 +70,9 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
                return -1;
        }
 
+       if (setsockopt(rth->fd, SOL_NETLINK, NETLINK_NO_ENOBUFS, &yes, sizeof(yes)) < 0)
+               ERROR("NETLINK_NO_EBUFS");
+
        memset(&rth->local, 0, sizeof(rth->local));
        rth->local.nl_family = AF_NETLINK;
        rth->local.nl_groups = subscriptions;