Skip to contentSkip to conversation

flowtable updates

PATCH New Pablo Neira Ayuso 1 participant 5 messages Oct 16, 2019

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover flowtable updates

Hi,

The following patchset update the flowtable control plane for nf_tables:

1) Move the priority field to nf_flowtable.

2) Dynamically allocate hooks per net_device.

3) Return EEXIST if a netdevice is twice or more from the same flowtable.

4) Rise limit from 8 to 256 netdevices per flowtable.

Pablo Neira Ayuso (4):
netfilter: nf_flow_table: move priority to struct nf_flowtable
netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables
netfilter: nf_tables: allow only one netdev per flowtable
netfilter: nf_tables: increase maximum devices number per flowtable

 include/net/netfilter/nf_flow_table.h |   1 +
 include/net/netfilter/nf_tables.h     |  12 +-
 net/netfilter/nf_tables_api.c         | 276 +++++++++++++++++++++-------------
 3 files changed, 180 insertions(+), 109 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/4 netfilter: nf_flow_table: move priority to struct nf_flowtable

Hardware offload needs access to the priority field, store this field in the nf_flowtable object.

---
 include/net/netfilter/nf_flow_table.h |  1 +
 include/net/netfilter/nf_tables.h     |  2 --
 net/netfilter/nf_tables_api.c         | 10 +++++-----
 3 files changed, 6 insertions(+), 7 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -0
index b37a7d608134..158514281a75 100644
@@ -24,6 +24,7 @@ struct nf_flowtable_type {
 struct nf_flowtable {
 	struct list_head		list;
 	struct rhashtable		rhashtable;
+	int				priority;
 	const struct nf_flowtable_type	*type;
 	struct delayed_work		gc_work;
 };
include/net/netfilter/nf_tables.h +0 -2
index 001d294edf57..d529dfb5aa64 100644
@@ -1155,7 +1155,6 @@ void nft_unregister_obj(struct nft_object_type *obj_type);
  * 	@table: the table the flow table is contained in
  *	@name: name of this flow table
  *	@hooknum: hook number
- *	@priority: hook priority
  *	@ops_len: number of hooks in array
  *	@genmask: generation mask
  *	@use: number of references to this flow table
@@ -1169,7 +1168,6 @@ struct nft_flowtable {
 	struct nft_table		*table;
 	char				*name;
 	int				hooknum;
-	int				priority;
 	int				ops_len;
 	u32				genmask:2,
 					use:30;
net/netfilter/nf_tables_api.c +5 -5
index d481f9baca2f..bfea0d6effc5 100644
@@ -5706,10 +5706,10 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
 	if (!ops)
 		return -ENOMEM;
 
-	flowtable->hooknum	= hooknum;
-	flowtable->priority	= priority;
-	flowtable->ops		= ops;
-	flowtable->ops_len	= n;
+	flowtable->hooknum		= hooknum;
+	flowtable->data.priority	= priority;
+	flowtable->ops			= ops;
+	flowtable->ops_len		= n;
 
 	for (i = 0; i < n; i++) {
 		flowtable->ops[i].pf		= NFPROTO_NETDEV;
@@ -5969,7 +5969,7 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,
 	if (!nest)
 		goto nla_put_failure;
 	if (nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_NUM, htonl(flowtable->hooknum)) ||
-	    nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_PRIORITY, htonl(flowtable->priority)))
+	    nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_PRIORITY, htonl(flowtable->data.priority)))
 		goto nla_put_failure;
 
 	nest_devs = nla_nest_start_noflag(skb, NFTA_FLOWTABLE_HOOK_DEVS);
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/4 netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables

In reply to Pablo Neira Ayuso

Use a list of hooks per device instead an array.

---
 include/net/netfilter/nf_tables.h |   8 +-
 net/netfilter/nf_tables_api.c     | 253 +++++++++++++++++++++++---------------
 2 files changed, 158 insertions(+), 103 deletions(-)
include/net/netfilter/nf_tables.h +7 -1
index d529dfb5aa64..7a2ac82ee0ad 100644
@@ -963,6 +963,12 @@ struct nft_stats {
 	struct u64_stats_sync	syncp;
 };
 
+struct nft_hook {
+	struct list_head	list;
+	struct nf_hook_ops	ops;
+	struct rcu_head		rcu;
+};
+
 /**
  *	struct nft_base_chain - nf_tables base chain
  *
@@ -1173,7 +1179,7 @@ struct nft_flowtable {
 					use:30;
 	u64				handle;
 	/* runtime data below here */
-	struct nf_hook_ops		*ops ____cacheline_aligned;
+	struct list_head		hook_list ____cacheline_aligned;
 	struct nf_flowtable		data;
 };
 
net/netfilter/nf_tables_api.c +151 -102

353 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/4 netfilter: nf_tables: allow only one netdev per flowtable

In reply to Pablo Neira Ayuso

Allow netdevice only once per flowtable, otherwise hit EEXIST.

---
 net/netfilter/nf_tables_api.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
net/netfilter/nf_tables_api.c +17 -0
index 0e0e35876b53..80ded807d529 100644
@@ -1538,6 +1538,19 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net,
 	return ERR_PTR(err);
 }
 
+static bool nft_hook_list_find(struct list_head *hook_list,
+			       const struct nft_hook *this)
+{
+	struct nft_hook *hook;
+
+	list_for_each_entry(hook, hook_list, list) {
+		if (this->ops.dev == hook->ops.dev)
+			return true;
+	}
+
+	return false;
+}
+
 static int nf_tables_parse_netdev_hooks(struct net *net,
 					const struct nlattr *attr,
 					struct list_head *hook_list)
@@ -1557,6 +1570,10 @@ static int nf_tables_parse_netdev_hooks(struct net *net,
 			err = PTR_ERR(hook);
 			goto err_hook;
 		}
+		if (nft_hook_list_find(hook_list, hook)) {
+			err = -EEXIST;
+			goto err_hook;
+		}
 		list_add_tail(&hook->list, hook_list);
 		n++;
 
Signature · 1 line
2.11.0
author maintainer
#4 lore raw

PATCH 4/4 netfilter: nf_tables: increase maximum devices number per flowtable

In reply to Pablo Neira Ayuso

Rise the maximum limit of devices per flowtable up to 256. Rename NFT_FLOWTABLE_DEVICE_MAX to NFT_NETDEVICE_MAX in preparation to reuse the netdev hook parser for ingress basechain.

---
 include/net/netfilter/nf_tables.h | 2 +-
 net/netfilter/nf_tables_api.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
index 7a2ac82ee0ad..3d71070e747a 100644
@@ -1152,7 +1152,7 @@ struct nft_object_ops {
 int nft_register_obj(struct nft_object_type *obj_type);
 void nft_unregister_obj(struct nft_object_type *obj_type);
 
-#define NFT_FLOWTABLE_DEVICE_MAX	8
+#define NFT_NETDEVICE_MAX	256
 
 /**
  *	struct nft_flowtable - nf_tables flow table
net/netfilter/nf_tables_api.c +1 -1
index 80ded807d529..d736a0cd056c 100644
@@ -1577,7 +1577,7 @@ static int nf_tables_parse_netdev_hooks(struct net *net,
 		list_add_tail(&hook->list, hook_list);
 		n++;
 
-		if (n == NFT_FLOWTABLE_DEVICE_MAX) {
+		if (n == NFT_NETDEVICE_MAX) {
 			err = -EFBIG;
 			goto err_hook;
 		}
Signature · 1 line
2.11.0