Skip to contentSkip to conversation

flowtable: device array dynamic allocation

PATCH Superseded Pablo Neira Ayuso 1 participant 2 messages Oct 18, 2019 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 flowtable: device array dynamic allocation

Remove artificial upper limit of 8 devices per flowtable.

---
 src/flowtable.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
src/flowtable.c +15 -14
index 1f7ba3052d4f..54e1bea25775 100644
@@ -358,30 +358,31 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data)
 static int nftnl_flowtable_parse_devs(struct nlattr *nest,
 				      struct nftnl_flowtable *c)
 {
+	const char **dev_array;
+	int len = 0, size = 8;
 	struct nlattr *attr;
-	char *dev_array[8];
-	int len = 0, i;
+
+	dev_array = calloc(8, sizeof(char *));
+	if (!dev_array)
+		return -1;
 
 	mnl_attr_for_each_nested(attr, nest) {
 		if (mnl_attr_get_type(attr) != NFTA_DEVICE_NAME)
 			goto err;
 		dev_array[len++] = strdup(mnl_attr_get_str(attr));
-		if (len >= 8)
-			break;
-	}
+		if (len >= size) {
+			dev_array = realloc(dev_array, size * 2);
+			if (!dev_array)
+				goto err;
 
-	if (!len)
-		return -1;
-
-	c->dev_array = calloc(len + 1, sizeof(char *));
-	if (!c->dev_array)
-		goto err;
+			size *= 2;
+			memset(&dev_array[len], 0, size - len);
+		}
+	}
 
+	c->dev_array = dev_array;
 	c->dev_array_len = len;
 
-	for (i = 0; i < len; i++)
-		c->dev_array[i] = dev_array[i];
-
 	return 0;
 err:
 	while (len--)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 2/2 chain: multi-device support

Add support for NFTA_HOOK_DEVS.

---
 include/libnftnl/chain.h            |   1 +
 include/linux/netfilter/nf_tables.h |   2 +
 src/chain.c                         | 107 +++++++++++++++++++++++++++++++++++-
 3 files changed, 109 insertions(+), 1 deletion(-)
include/libnftnl/chain.h +1 -0
index 31b48cf32bed..f84a2a3a20f2 100644
@@ -31,6 +31,7 @@ enum nftnl_chain_attr {
 	NFTNL_CHAIN_HANDLE,
 	NFTNL_CHAIN_TYPE,
 	NFTNL_CHAIN_DEV,
+	NFTNL_CHAIN_DEVICES,
 	__NFTNL_CHAIN_MAX
 };
 #define NFTNL_CHAIN_MAX (__NFTNL_CHAIN_MAX - 1)
include/linux/netfilter/nf_tables.h +2 -0
index 2e49bc6541a4..81c27d3c9ffd 100644
@@ -144,12 +144,14 @@ enum nft_list_attributes {
  * @NFTA_HOOK_HOOKNUM: netfilter hook number (NLA_U32)
  * @NFTA_HOOK_PRIORITY: netfilter hook priority (NLA_U32)
  * @NFTA_HOOK_DEV: netdevice name (NLA_STRING)
+ * @NFTA_HOOK_DEVS: list of netdevices (NLA_NESTED)
  */
 enum nft_hook_attributes {
 	NFTA_HOOK_UNSPEC,
 	NFTA_HOOK_HOOKNUM,
 	NFTA_HOOK_PRIORITY,
 	NFTA_HOOK_DEV,
+	NFTA_HOOK_DEVS,
 	__NFTA_HOOK_MAX
 };
 #define NFTA_HOOK_MAX		(__NFTA_HOOK_MAX - 1)
src/chain.c +106 -1

194 lines not on this page · raw message

Signature · 1 line
2.11.0