Skip to contentSkip to conversation

conntrack: Allow setting of netlink buffer size

PATCH In review William Blough 2 participants 3 messages Jan 6, 2023 – Jan 11, 2023 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 conntrack: Allow setting of netlink buffer size

ENOBUFS is returned in the case that the nfnetlink socket buffer is exhausted. The function nfnl_rcvbufsize is provided by libnfnetlink to set the buffer size in order to handle this error, however libnetfilter_conntrack does not expose this function for the underlying netlink socket.

Add nfct_rcvbufsiz function to allow setting of buffer size for netlink socket.

---
 .../libnetfilter_conntrack.h                   |  3 +++
 src/conntrack/api.c                            | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
include/libnetfilter_conntrack/libnetfilter_conntrack.h +3 -0
index e229472..d496307 100644
@@ -591,6 +591,9 @@ extern int nfct_nlmsg_build_filter(struct nlmsghdr *nlh, const struct nfct_filte
 extern int nfct_nlmsg_parse(const struct nlmsghdr *nlh, struct nf_conntrack *ct);
 extern int nfct_payload_parse(const void *payload, size_t payload_len, uint16_t l3num, struct nf_conntrack *ct);
 
+/* set size of netlink socket buffer */
+unsigned int nfct_rcvbufsize(struct nfct_handle *h, unsigned int size);
+
 /*
  * NEW expectation API
  */
src/conntrack/api.c +18 -0
index 7f72d07..699f560 100644
@@ -350,6 +350,24 @@ void nfct_callback_unregister2(struct nfct_handle *h)
 	h->nfnl_cb_ct.attr_count = 0;
 }
 
+/**
+ * nfct_rcvbufsiz - set size of netlink socket buffer
+ * \param h library handler
+ * \param size size of the buffer we want to set
+ *
+ * This function sets the new size of the the netlink socket buffer.  Use this
+ * setting to increase the socket buffer size if your system is reporting
+ * ENOBUFS errors.
+ *
+ * This function returns the new size of the netlink socket buffer.
+ */
+unsigned int nfct_rcvbufsiz(struct nfct_handle *h, unsigned int size)
+{
+	assert(h != NULL);
+
+	return nfnl_rcvbufsiz(h->nfnlh, size);
+}
+
 /**
  * @}
  */
Signature · 1 line
2.30.2
#1 lore raw
Quoted 8 lines · William Blough

ENOBUFS is returned in the case that the nfnetlink socket buffer is exhausted. The function nfnl_rcvbufsize is provided by libnfnetlink to set the buffer size in order to handle this error, however libnetfilter_conntrack does not expose this function for the underlying netlink socket.

Add nfct_rcvbufsiz function to allow setting of buffer size for netlink socket.

Thanks for your patch.

There is already nfct_fd() and you can use setsockopt() on it.

#2 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · William Blough

Add nfct_rcvbufsiz function to allow setting of buffer size for netlink socket.

Thanks for your patch.

There is already nfct_fd() and you can use setsockopt() on it.

Ah, apparently I overlooked that. Thanks.

Best regards,
Bill