netfilter: nf_tables: return immediately on empty commit
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: nf_tables: return immediately on empty commit
When running 'nft flush ruleset' while no rules exist, we will increment the generation counter and announce a new genid to userspace, yet nothing had changed in the first place.
--- net/netfilter/nf_tables_api.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_tables_api.c +5 -0
@@ -6536,6 +6536,11 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)struct nft_chain *chain;struct nft_table *table; +if (list_empty (&net->nft.commit_list)) { +mutex_unlock (&net->nft.commit_mutex); +return 0 ; + } +/* 0. Validate ruleset, otherwise roll back for error reporting. */ if (nf_tables_validate (net) <0 )return -EAGAIN ;
Signature · 1 line
2.19.2
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 14 lines · Florian Westphal
When running 'nft flush ruleset' while no rules exist, we will increment the generation counter and announce a new genid to userspace, yet nothing had changed in the first place.
Signed-off-by Florian Westphal <[email protected]>--- net/netfilter/nf_tables_api.c | 5 +++++ 1 file changed, 5 insertions(+)net/netfilter/nf_tables_api.c +0
-0
net/netfilter/nf_tables_api.c static int nf_tables_commit(struct net *net, struct sk_buff *skb) · line 6542
Quoted 7 lines
net/netfilter/nf_tables_api.c +4
-0@@ -6536,6 +6536,11 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)struct nft_chain *chain;struct nft_table *table; +if (list_empty (&net->nft.commit_list)) { +mutex_unlock (&net->nft.commit_mutex); +return 0 ; + }
This looks good to catch this case.
I think we should probably address these too:
term1# nft add table x
term1# nft add table x
term2# nft monitor
add table ip x
# new generation 1587 by process 14422 (nft) # new generation 1588 by process 14423 (nft)
So re-insertion of existing objects should not trigger unnecessary generation counter bump. We can probably count the number of events that have been sent from the commit path before we bump it.
Florian Westphal
maintainerQuoted 11 lines · Pablo Neira Ayuso
term1# nft add table x
term1# nft add table xterm2# nft monitor
add table ip x# new generation 1587 by process 14422 (nft) # new generation 1588 by process 14423 (nft)So re-insertion of existing objects should not trigger unnecessary generation counter bump. We can probably count the number of events that have been sent from the commit path before we bump it.
Thats strange. Why does the second add result in the creation of a transaction object in the first place?
2nd add should result in a call to "upd_table", and it should find that no attributes are being changed, and no transaction object should be created, i.e. the commit should end up with empty transaction list.
Quoted 3 lines · Florian Westphal
When running 'nft flush ruleset' while no rules exist, we will increment the generation counter and announce a new genid to userspace, yet nothing had changed in the first place.
Applied, thanks Florian.