new transaction infrastructure for nf_tables
Subsystems (2)
Pablo Neira Ayuso
maintainercover new transaction infrastructure for nf_tables
Hi,
This patchset contains updates to the transaction infrastructure and a new batch API to userspace to update tables, chains and sets. Basically, it generalises the existing rule batching so we can also include sets, chains and tables in one single batch. This helps to speed up updates since we save many netlink messages between kernel and userspace and this also improves several batch loading error cases that resulted in inconsistent configurations.
Still, this patchset doesn't address the abortion of chain policy/counter updates and new set elements addition/removals. Basically, this means that we don't have atomic set element updates yet, but that wasn't possible with the former API either.
Pablo Neira Ayuso (7):
netfilter: nf_tables: deconstify table and chain in context structure
netfilter: nf_tables: generalise transaction infrastructure
netfilter: nf_tables: relocate commit and abort routines in the source file
netfilter: nf_tables: better encapsulation for the rule transaction code
netfilter: nf_tables: move set handling to the transaction infrastructure
netfilter: nf_tables: move chain handling to the transaction infrastructure
netfilter: nf_tables: move table handling to the transaction infrastructure
include/net/netfilter/nf_tables.h | 31 +- include/uapi/linux/netfilter/nf_tables.h | 6 + net/netfilter/nf_tables_api.c | 830 ++++++++++++++++++++++-------- net/netfilter/nft_lookup.c | 15 +- 4 files changed, 656 insertions(+), 226 deletions(-)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: nf_tables: deconstify table and chain in context structure
The new transaction infrastructure updates the family, table and chain objects in the context structure, so let's deconstify them. While at it, move the context structure initialization routine to the top of the source file as it will be also used from the table and chain routines.
--- include/net/netfilter/nf_tables.h | 6 ++-- net/netfilter/nf_tables_api.c | 58 ++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 32 deletions(-)
include/net/netfilter/nf_tables.h +3 -3
@@ -83,9 +83,9 @@ struct nft_ctx {struct net *net;const struct sk_buff *skb;const struct nlmsghdr *nlh; -const struct nft_af_info *afi; -const struct nft_table *table; -const struct nft_chain *chain; +struct nft_af_info *afi; +struct nft_table *table; +struct nft_chain *chain;const struct nlattr *const *nla; };
net/netfilter/nf_tables_api.c +29 -29
125 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 1/7] netfilter: nf_tables: deconstify table and chain in context structure
Quoted 4 lines · Pablo Neira Ayuso
The new transaction infrastructure updates the family, table and chain objects in the context structure, so let's deconstify them. While at it, move the context structure initialization routine to the top of the source file as it will be also used from the table and chain routines.
I would prefer to keep the consts for the context, but I'm fine with it if we don't find a clean other way. Basically I'd suggest to use your patch if we have functions that are called from both the transaction code and non-transaction code, IOW need the nft_ctx structure. Otherwise, if this stuff is only used by the transaction code, we could add the individual members to the transaction as non-consts.
Pablo Neira Ayuso
maintainerRe: [PATCH 1/7] netfilter: nf_tables: deconstify table and chain in context structure
Quoted 6 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso
The new transaction infrastructure updates the family, table and chain objects in the context structure, so let's deconstify them. While at it, move the context structure initialization routine to the top of the source file as it will be also used from the table and chain routines.
Quoted 6 lines
I would prefer to keep the consts for the context, but I'm fine with it if we don't find a clean other way. Basically I'd suggest to use your patch if we have functions that are called from both the transaction code and non-transaction code, IOW need the
nft_ctxstructure. Otherwise, if this stuff is only used by the transaction code, we could add the individual members to the transaction as non-consts.
This is being used from both transaction and non-transaction code. I initially casted this to non-const as a workaround to calm down gcc, but at some point I needed the list handling to add and to remove elements from the lists which was quite ugly. I liked those compile time checkings that we were getting before this.
Another possibility is to add some nft_ctx_trans which would look very similar to nft_ctx, but in some cases we would need to define both nft_ctx and nft_ctx_trans, which doesn't look very nice either. So I don't see a better way to make this at this moment.
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: nf_tables: generalise transaction infrastructure
In reply to Pablo Neira AyusoThis patch generalises the existing rule transaction infrastructure so it can be used to handle set, table and chain object transactions as well.
--- include/net/netfilter/nf_tables.h | 15 +++-- net/netfilter/nf_tables_api.c | 114 +++++++++++++++++++++---------------- 2 files changed, 75 insertions(+), 54 deletions(-)
include/net/netfilter/nf_tables.h +11 -4
@@ -340,17 +340,24 @@ struct nft_rule { __attribute__((aligned(__alignof__(struct nft_expr)))); }; +enum nft_trans_type { +NFT_TRANS_RULE , +}; +/** -* struct nft_rule_trans - nf_tables rule update in transaction +* struct nft_trans - nf_tables object update in transaction * * @list: used internally +* @type: object type * @ctx: rule context -* @rule: rule that needs to be updated */ -struct nft_rule_trans { +struct nft_trans {struct list_head list; +enum nft_trans_type type;struct nft_ctx ctx; -struct nft_rule *rule; +union { +struct nft_rule *rule; + }; };static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule)
net/netfilter/nf_tables_api.c +64 -50
202 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 2/7] netfilter: nf_tables: generalise transaction infrastructure
Quoted 3 lines · Pablo Neira Ayuso
This patch generalises the existing rule transaction infrastructure so it can be used to handle set, table and chain object transactions as well.
This looks very good to me.
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: nf_tables: relocate commit and abort routines in the source file
In reply to Pablo Neira AyusoMove the commit and abort routines to the bottom of the source code file. This change is required by the follow up patches that add the set, chain and table transaction support.
This patch is just a cleanup to access several functions without having to declare their prototypes.
--- net/netfilter/nf_tables_api.c | 164 ++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 82 deletions(-)
net/netfilter/nf_tables_api.c +82 -82
@@ -1821,88 +1821,6 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,return err; } -static int nf_tables_commit (struct sk_buff *skb) -{ -struct net *net =sock_net (skb->sk); -struct nft_trans *trans, *next; - -/* Bump generation counter, invalidate any dump in progress */ - net->nft.genctr++; - -/* A new generation has just started */ - net->nft.gencursor =gencursor_next (net); - -/* Make sure all packets have left the previous generation before -* purging old rules. -*/ -synchronize_rcu (); - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -/* This rule was inactive in the past and just became active. -* Clear the next bit of the genmask since its meaning has -* changed, now it is the future. -*/ -if (nft_rule_is_active (net, trans->rule)) { -nft_rule_clear (net, trans->rule); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, trans->ctx.chain, - trans->rule,NFT_MSG_NEWRULE ,0 , - trans->ctx.afi->family); -list_del (&trans->list); -kfree (trans); -continue ; - } - -/* This rule is in the past, get rid of it */ -list_del_rcu (&trans->rule->list); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, trans->ctx.chain, - trans->rule,NFT_MSG_DELRULE ,0 , - trans->ctx.afi->family); - } - -/* Make sure we don't see any packet traversing old rules */ -synchronize_rcu (); - -/* Now we can safely release unused old rules */ -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx, trans->rule); -list_del (&trans->list); -kfree (trans); - } - -return 0 ; -} - -static int nf_tables_abort (struct sk_buff *skb) -{ -struct net *net =sock_net (skb->sk); -struct nft_trans *trans, *next; - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -if (!nft_rule_is_active_next (net, trans->rule)) { -nft_rule_clear (net, trans->rule); -list_del (&trans->list); -kfree (trans); -continue ; - } - -/* This rule is inactive, get rid of it */ -list_del_rcu (&trans->rule->list); - } - -/* Make sure we don't see any packet accessing aborted rules */ -synchronize_rcu (); - -list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx, trans->rule); -list_del (&trans->list); -kfree (trans); - } - -return 0 ; -} -/* * Sets */
@@ -2997,6 +2915,88 @@ static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = { }, }; +static int nf_tables_commit (struct sk_buff *skb) +{ +struct net *net =sock_net (skb->sk); +struct nft_trans *trans, *next; + +/* Bump generation counter, invalidate any dump in progress */ + net->nft.genctr++; + +/* A new generation has just started */ + net->nft.gencursor =gencursor_next (net); + +/* Make sure all packets have left the previous generation before +* purging old rules. +*/ +synchronize_rcu (); + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +/* This rule was inactive in the past and just became active. +* Clear the next bit of the genmask since its meaning has +* changed, now it is the future. +*/ +if (nft_rule_is_active (net, trans->rule)) { +nft_rule_clear (net, trans->rule); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, trans->ctx.chain, + trans->rule,NFT_MSG_NEWRULE ,0 , + trans->ctx.afi->family); +list_del (&trans->list); +kfree (trans); +continue ; + } + +/* This rule is in the past, get rid of it */ +list_del_rcu (&trans->rule->list); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, trans->ctx.chain, + trans->rule,NFT_MSG_DELRULE ,0 , + trans->ctx.afi->family); + } + +/* Make sure we don't see any packet traversing old rules */ +synchronize_rcu (); + +/* Now we can safely release unused old rules */ +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +nf_tables_rule_destroy (&trans->ctx, trans->rule); +list_del (&trans->list); +kfree (trans); + } + +return 0 ; +} + +static int nf_tables_abort (struct sk_buff *skb) +{ +struct net *net =sock_net (skb->sk); +struct nft_trans *trans, *next; + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +if (!nft_rule_is_active_next (net, trans->rule)) { +nft_rule_clear (net, trans->rule); +list_del (&trans->list); +kfree (trans); +continue ; + } + +/* This rule is inactive, get rid of it */ +list_del_rcu (&trans->rule->list); + } + +/* Make sure we don't see any packet accessing aborted rules */ +synchronize_rcu (); + +list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +nf_tables_rule_destroy (&trans->ctx, trans->rule); +list_del (&trans->list); +kfree (trans); + } + +return 0 ; +} +static const struct nfnetlink_subsystem nf_tables_subsys = { .name ="nf_tables" , .subsys_id =NFNL_SUBSYS_NFTABLES ,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: nf_tables: better encapsulation for the rule transaction code
In reply to Pablo Neira AyusoAnother cleanup to accomodate set, chain and table transaction support. Move the rule transaction code to several functions to avoid too large commit and abort routines.
--- net/netfilter/nf_tables_api.c | 102 ++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 33 deletions(-)
net/netfilter/nf_tables_api.c +69 -33
@@ -2915,6 +2915,32 @@ static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = { }, }; +static void nft_rule_commit_update (struct net *net,struct sk_buff *skb, +struct nft_trans *trans) +{ +/* This rule was inactive in the past and just became active. +* Clear the next bit of the genmask since its meaning has +* changed, now it is the future. +*/ +if (nft_rule_is_active (net, trans->rule)) { +nft_rule_clear (net, trans->rule); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, trans->ctx.chain, + trans->rule,NFT_MSG_NEWRULE ,0 , + trans->ctx.afi->family); +list_del (&trans->list); +kfree (trans); +return ; + } + +/* This rule is in the past, get rid of it */ +list_del_rcu (&trans->rule->list); +nf_tables_rule_notify (skb, trans->ctx.nlh, + trans->ctx.table, trans->ctx.chain, + trans->rule,NFT_MSG_DELRULE ,0 , + trans->ctx.afi->family); +} +static int nf_tables_commit (struct sk_buff *skb) {struct net *net =sock_net (skb->sk);
@@ -2927,70 +2953,80 @@ static int nf_tables_commit(struct sk_buff *skb) net->nft.gencursor =gencursor_next (net);/* Make sure all packets have left the previous generation before -* purging old rules. +* purging old objects. */ synchronize_rcu ();list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -/* This rule was inactive in the past and just became active. -* Clear the next bit of the genmask since its meaning has -* changed, now it is the future. -*/ -if (nft_rule_is_active (net, trans->rule)) { -nft_rule_clear (net, trans->rule); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, trans->ctx.chain, - trans->rule,NFT_MSG_NEWRULE ,0 , - trans->ctx.afi->family); -list_del (&trans->list); -kfree (trans); -continue ; +switch (trans->type) { +case NFT_TRANS_RULE : +nft_rule_commit_update (net, skb, trans); +break ; } - -/* This rule is in the past, get rid of it */ -list_del_rcu (&trans->rule->list); -nf_tables_rule_notify (skb, trans->ctx.nlh, - trans->ctx.table, trans->ctx.chain, - trans->rule,NFT_MSG_DELRULE ,0 , - trans->ctx.afi->family); } -/* Make sure we don't see any packet traversing old rules */ +/* Make sure we don't see any packet traversing old objects */ synchronize_rcu (); -/* Now we can safely release unused old rules */ +/* Now we can safely release unused old objects */ list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx, trans->rule);list_del (&trans->list); +switch (trans->type) { +case NFT_TRANS_RULE : +nf_tables_rule_destroy (&trans->ctx, trans->rule); +break ; + }kfree (trans); }return 0 ; } +static void nft_rule_abort_undo (struct net *net,struct sk_buff *skb, +struct nft_trans *trans) +{ +/* This rule was scheduled for removal but this transaction has been +* aborted, clear the rule generation bitmask and leave it in place. +*/ +if (!nft_rule_is_active_next (net, trans->rule)) { +nft_rule_clear (net, trans->rule); +list_del (&trans->list); +kfree (trans); +return ; + } + +/* This rule was scheduled to be active in the next generation, but +* this transaction was aborted, remove it from the list. +*/ +list_del_rcu (&trans->rule->list); +} +static int nf_tables_abort (struct sk_buff *skb) {struct net *net =sock_net (skb->sk);struct nft_trans *trans, *next;list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -if (!nft_rule_is_active_next (net, trans->rule)) { -nft_rule_clear (net, trans->rule); -list_del (&trans->list); -kfree (trans); -continue ; +switch (trans->type) { +case NFT_TRANS_RULE : +nft_rule_abort_undo (net, skb, trans); +break ; } - -/* This rule is inactive, get rid of it */ -list_del_rcu (&trans->rule->list); }/* Make sure we don't see any packet accessing aborted rules */ synchronize_rcu ();list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { -nf_tables_rule_destroy (&trans->ctx, trans->rule);list_del (&trans->list); +switch (trans->type) { +case NFT_TRANS_RULE : +/* Release new rules, already removed from the list, +* that we couldn't activate. +*/ +nf_tables_rule_destroy (&trans->ctx, trans->rule); +break ; + }kfree (trans); }
Signature · 1 line
1.7.10.4
Re: [PATCH 4/7] netfilter: nf_tables: better encapsulation for the rule transaction code
net/netfilter/nf_tables_api.c static const struct nfnl_callback nf_tables_cb[NFT_MSG_MAX] = { · line 2919
Quoted 7 lines · Pablo Neira Ayuso
Another cleanup to accomodate set, chain and table transaction support. Move the rule transaction code to several functions to avoid too large commit and abort routines.
net/netfilter/nf_tables_api.c +2
-0+static void nft_rule_commit_update (struct net *net,struct sk_buff *skb, +struct nft_trans *trans)
Just wondering, why aren't we using the net and skb from the context?
net/netfilter/nf_tables_api.c static int nf_tables_commit(struct sk_buff *skb) · line 2986
Quoted 2 lines
net/netfilter/nf_tables_api.c +2
-0+static void nft_rule_abort_undo (struct net *net,struct sk_buff *skb, +struct nft_trans *trans)
In this case neither net nor skb are used.
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: nf_tables: move set handling to the transaction infrastructure
In reply to Pablo Neira AyusoThis patch reworks the nf_tables API so set updates are moved into the same batch that contains rule updates. This speeds up rule-set updates we skip a dialog of four messages between kernel and user-space (two on each direction).
1) create the set and send netlink message to the kernel
2) process the response from the kernel that contains the allocated name.
3) add the set elements and send netlink message to the kernel.
4) process the response from the kernel (to check for errors).
To:
1) add the set to the batch.
2) add the set elements to the batch.
3) add the rule that points to the set.
4) send batch to the kernel.
The idea is to allocate an internal set ID to the batch that can be used when adding set elements and rules that refer to the set in the batch.
Note that this patch doesn't add atomic set element updates, it just helps to leave the set configuration in consistent state in case that we fail to load the entire batch for some reason.
Backward compatibility has been only retained in userspace, this means that new nft versions can talk to the kernel both in the new and the old fashion.
--- include/net/netfilter/nf_tables.h | 7 ++ include/uapi/linux/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 130 +++++++++++++++++++++++++++--- net/netfilter/nft_lookup.c | 15 +++- 4 files changed, 141 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +7 -0
@@ -222,6 +222,8 @@ static inline void *nft_set_priv(const struct nft_set *set)struct nft_set *nf_tables_set_lookup (const struct nft_table *table,const struct nlattr *nla); +struct nft_set *nf_tables_set_lookup_byid (const struct net *net, +const struct nlattr *nla);/** * struct nft_set_binding - nf_tables set binding
@@ -342,6 +344,7 @@ struct nft_rule {enum nft_trans_type {NFT_TRANS_RULE , +NFT_TRANS_SET , };/**
@@ -357,6 +360,10 @@ struct nft_trans {struct nft_ctx ctx;union {struct nft_rule *rule; +struct { +struct nft_set *set; +u32 set_id; + }; }; };
include/uapi/linux/netfilter/nf_tables.h +6 -0
@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_set_attributes {NFTA_SET_UNSPEC ,
@@ -231,6 +232,7 @@ enum nft_set_attributes {NFTA_SET_KEY_LEN ,NFTA_SET_DATA_TYPE ,NFTA_SET_DATA_LEN , +NFTA_SET_ID , __NFTA_SET_MAX };#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -266,12 +268,14 @@ enum nft_set_elem_attributes {* @NFTA_SET_ELEM_LIST_TABLE: table of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_SET: name of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_ELEMENTS: list of set elements (NLA_NESTED: nft_set_elem_attributes) +* @NFTA_SET_ELEM_LIST_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_set_elem_list_attributes {NFTA_SET_ELEM_LIST_UNSPEC ,NFTA_SET_ELEM_LIST_TABLE ,NFTA_SET_ELEM_LIST_SET ,NFTA_SET_ELEM_LIST_ELEMENTS , +NFTA_SET_ELEM_LIST_SET_ID , __NFTA_SET_ELEM_LIST_MAX };#define NFTA_SET_ELEM_LIST_MAX (__NFTA_SET_ELEM_LIST_MAX - 1)
@@ -457,12 +461,14 @@ enum nft_cmp_attributes {* @NFTA_LOOKUP_SET: name of the set where to look for (NLA_STRING) * @NFTA_LOOKUP_SREG: source register of the data to look for (NLA_U32: nft_registers) * @NFTA_LOOKUP_DREG: destination register (NLA_U32: nft_registers) +* @NFTA_LOOKUP_SET_ID: uniquely identifies a set in a transaction (NLA_U32) */ enum nft_lookup_attributes {NFTA_LOOKUP_UNSPEC ,NFTA_LOOKUP_SET ,NFTA_LOOKUP_SREG ,NFTA_LOOKUP_DREG , +NFTA_LOOKUP_SET_ID , __NFTA_LOOKUP_MAX };#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)
net/netfilter/nf_tables_api.c +117 -13
254 lines not on this page · raw message
net/netfilter/nft_lookup.c +11 -4
@@ -51,13 +51,20 @@ static int nft_lookup_init(const struct nft_ctx *ctx,struct nft_set *set;int err; -if (tb[NFTA_LOOKUP_SET ] ==NULL || +if ((tb[NFTA_LOOKUP_SET ] ==NULL && tb[NFTA_LOOKUP_SET_ID ] ==NULL ) || tb[NFTA_LOOKUP_SREG ] ==NULL )return -EINVAL ; - set =nf_tables_set_lookup (ctx->table, tb[NFTA_LOOKUP_SET ]); -if (IS_ERR (set)) -return PTR_ERR (set); +if (tb[NFTA_LOOKUP_SET_ID ]) { + set =nf_tables_set_lookup_byid (ctx->net, + tb[NFTA_LOOKUP_SET_ID ]); +if (IS_ERR (set)) +return PTR_ERR (set); + }else { + set =nf_tables_set_lookup (ctx->table, tb[NFTA_LOOKUP_SET ]); +if (IS_ERR (set)) +return PTR_ERR (set); + } priv->sreg =ntohl (nla_get_be32 (tb[NFTA_LOOKUP_SREG ])); err =nft_validate_input_register (priv->sreg);
Signature · 1 line
1.7.10.4
Re: [PATCH 5/7] netfilter: nf_tables: move set handling to the transaction infrastructure
Quoted 17 lines · Pablo Neira Ayuso
This patch reworks the
nf_tablesAPI so set updates are moved into the same batch that contains rule updates. This speeds up rule-set updates we skip a dialog of four messages between kernel and user-space (two on each direction).1) create the set and send netlink message to the kernel
2) process the response from the kernel that contains the allocated name.
3) add the set elements and send netlink message to the kernel.
4) process the response from the kernel (to check for errors).To:
1) add the set to the batch.
2) add the set elements to the batch.
3) add the rule that points to the set.
4) send batch to the kernel.
Quoted 7 lines
The idea is to allocate an internal set ID to the batch that can be used when adding set elements and rules that refer to the set in the batch.
Note that this patch doesn't add atomic set element updates, it just helps to leave the set configuration in consistent state in case that we fail to load the entire batch for some reason.
Looks fine to me. However I'm wondering whether this couldn't be simplified. Basically all we need is a way to detect sets contained in the batch for abort/commit, which could be achieved using a single flag. The sets don't have any direct impact on runtime and they're not visible to userspace as long as we hold the nfnl. So all we need to do on abort is kill all the sets with this flag, on commit we clear the flag and send notifications.
Quoted 3 lines
Backward compatibility has been only retained in userspace, this means that new nft versions can talk to the kernel both in the new and the old fashion.
And old nftables can't talk to new kernels?
Pablo Neira Ayuso
maintainerPATCH 6/7 netfilter: nf_tables: move chain handling to the transaction infrastructure
In reply to Pablo Neira AyusoThis patch speeds up rule-set updates and it helps to leave chains in consistent state when processing a batch. Note this patch does not introduce a way to revert chain updates, eg. counter or default policy changes.
--- include/net/netfilter/nf_tables.h | 2 + net/netfilter/nf_tables_api.c | 199 ++++++++++++++++++++++++++++++------- 2 files changed, 164 insertions(+), 37 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -343,6 +343,7 @@ struct nft_rule { };enum nft_trans_type { +NFT_TRANS_CHAIN ,NFT_TRANS_RULE ,NFT_TRANS_SET , };
@@ -364,6 +365,7 @@ struct nft_trans {struct nft_set *set;u32 set_id; }; +bool update; }; };
net/netfilter/nf_tables_api.c +162 -37
321 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 6/7] netfilter: nf_tables: move chain handling to the transaction infrastructure
Quoted 4 lines · Pablo Neira Ayuso
This patch speeds up rule-set updates and it helps to leave chains in consistent state when processing a batch. Note this patch does not introduce a way to revert chain updates, eg. counter or default policy changes.
Also it doesn't seem to handle chain renames. I think this is a conceptual shortcoming, there's no way to implement updates properly by just storing the chain in the transaction, we need to store the actual actions to be performed.
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: nf_tables: move table handling to the transaction infrastructure
In reply to Pablo Neira AyusoThis patch speeds up rule-set updates and it helps to leave the table configuration in consistent state when processing a batch.
--- include/net/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 189 ++++++++++++++++++++++++++++++------- 2 files changed, 156 insertions(+), 34 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -343,6 +343,7 @@ struct nft_rule { };enum nft_trans_type { +NFT_TRANS_TABLE =0 ,NFT_TRANS_CHAIN ,NFT_TRANS_RULE ,NFT_TRANS_SET ,
net/netfilter/nf_tables_api.c +155 -34
359 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 7/7] netfilter: nf_tables: move table handling to the transaction infrastructure
Quoted 2 lines · Pablo Neira Ayuso
This patch speeds up rule-set updates and it helps to leave the table configuration in consistent state when processing a batch.
Same things as for chain updates apply to this patch. I think we should limit this to sets until the conceptual shortcomings have been resolved.