From 7b9489fb84bd4542b5996fc3c37e6b21515dcda1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 2 Jun 2020 00:07:39 +0200 Subject: [PATCH] the buffer passed to mnl_nlmsg_batch_start() must be double of MNL_SOCKET_BUFFER_SIZE see https://www.netfilter.org/projects/libmnl/doxygen/html/group__batch.html http://www.lt.netfilter.org/projects/libmnl/doxygen/group__batch.html#ga28488fc4dee4c3e9eda5918f049db2af --- miniupnpd/netfilter_nft/nftnlrdr_misc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/miniupnpd/netfilter_nft/nftnlrdr_misc.c b/miniupnpd/netfilter_nft/nftnlrdr_misc.c index 9c3c677..37bdcbf 100644 --- a/miniupnpd/netfilter_nft/nftnlrdr_misc.c +++ b/miniupnpd/netfilter_nft/nftnlrdr_misc.c @@ -1133,10 +1133,9 @@ nft_send_rule(struct nftnl_rule * rule, uint16_t cmd, enum rule_chain_type chain int result = -1; struct nlmsghdr *nlh; struct mnl_nlmsg_batch *batch; - char buf[MNL_SOCKET_BUFFER_SIZE]; + char buf[MNL_SOCKET_BUFFER_SIZE*2]; - - batch = start_batch(buf, sizeof(buf)); + batch = start_batch(buf, MNL_SOCKET_BUFFER_SIZE); if (batch != NULL) { switch (chain_type) { @@ -1171,7 +1170,7 @@ table_op( enum nf_tables_msg_types op, uint16_t family, const char * name) int result; struct nlmsghdr *nlh; struct mnl_nlmsg_batch *batch; - char buf[MNL_SOCKET_BUFFER_SIZE]; + char buf[MNL_SOCKET_BUFFER_SIZE*2]; struct nftnl_table *table; @@ -1185,7 +1184,7 @@ table_op( enum nf_tables_msg_types op, uint16_t family, const char * name) nftnl_table_set_u32(table, NFTNL_TABLE_FAMILY, family); nftnl_table_set_str(table, NFTNL_TABLE_NAME, name); - batch = start_batch( buf, sizeof(buf)); + batch = start_batch(buf, MNL_SOCKET_BUFFER_SIZE); if (batch == NULL) { log_error("out of memory: %m"); result = -2; @@ -1210,7 +1209,7 @@ chain_op(enum nf_tables_msg_types op, uint16_t family, const char * table, int result = -1; struct nlmsghdr *nlh; struct mnl_nlmsg_batch *batch; - char buf[MNL_SOCKET_BUFFER_SIZE]; + char buf[MNL_SOCKET_BUFFER_SIZE*2]; struct nftnl_chain *chain; @@ -1230,7 +1229,7 @@ chain_op(enum nf_tables_msg_types op, uint16_t family, const char * table, nftnl_chain_set_s32(chain, NFTNL_CHAIN_PRIO, priority); } - batch = start_batch(buf, sizeof(buf)); + batch = start_batch(buf, MNL_SOCKET_BUFFER_SIZE); if (batch == NULL) { log_error("out of memory: %m"); result = -3; @@ -1254,9 +1253,13 @@ chain_op(enum nf_tables_msg_types op, uint16_t family, const char * table, return result; } - +/** + * the buffer that you have to use to store the batch must be double + * of MNL_SOCKET_BUFFER_SIZE + * @see https://www.netfilter.org/projects/libmnl/doxygen/html/group__batch.html + */ struct mnl_nlmsg_batch * -start_batch( char *buf, size_t buf_size) +start_batch(char *buf, size_t buf_size) { struct mnl_nlmsg_batch *result; mnl_seq = time(NULL);