]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
mnl: mnl_set_rcvbuffer() skips buffer size update if it is too small
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 30 May 2019 10:52:49 +0000 (12:52 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 31 May 2019 15:57:35 +0000 (17:57 +0200)
Check for existing buffer size, if this is larger than the newer buffer
size, skip this size update.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/mnl.c

index 288a887df0977673ef62abe56b09f8a8454a0f3a..859c7d77074800d7208c83d447c2c957a33facd8 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -233,10 +233,21 @@ static void mnl_set_sndbuffer(const struct mnl_socket *nl,
        nlbuffsiz = newbuffsiz;
 }
 
+static unsigned int nlsndbufsiz;
+
 static int mnl_set_rcvbuffer(const struct mnl_socket *nl, size_t bufsiz)
 {
+       socklen_t len = sizeof(nlsndbufsiz);
        int ret;
 
+       if (!nlsndbufsiz) {
+               getsockopt(mnl_socket_get_fd(nl), SOL_SOCKET, SO_RCVBUF,
+                          &nlsndbufsiz, &len);
+       }
+
+       if (nlsndbufsiz >= bufsiz)
+               return 0;
+
        ret = setsockopt(mnl_socket_get_fd(nl), SOL_SOCKET, SO_RCVBUFFORCE,
                         &bufsiz, sizeof(socklen_t));
        if (ret < 0) {