netfilter: nf_tables: make move set_update_list to nftables per-netns
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: nf_tables: make move set_update_list to nftables per-netns
This list is used to invoke the set .commit and .abort ops for the rbtree and pipapo to run GC on expired elements and replace the current datastructure view by the clone. For the rbtree, this also rebuild the datapath b-search array.
From abort path, remove the set from the update_list if it is already bound to rule, then the rule itself takes care of releasing the set and its elements, otherwise, memleak is possible because set ops .abort only deals with removing the set data structure, not the elements.
This is a preparation patch to call set .commit before processing the transaction list for the rbtree, no functional changes are intended.
--- include/net/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 49 ++++++++++--------------------- 2 files changed, 16 insertions(+), 34 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -1949,6 +1949,7 @@ struct nftables_pernet {struct list_head binding_list;struct list_head module_list;struct list_head notify_list; +struct list_head set_update_list;struct mutex commit_mutex;u64 table_handle;u64 tstamp;
net/netfilter/nf_tables_api.c +15 -34
140 lines not on this page · raw message
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nf_tables: call set ops .commit when building new ruleset
The rbtree set only builds the b-search array after the new ruleset has been exposed through set ops .commit.
This is currently needed by pipapo because it purges the elements from the clone after the transactions are handled, therefore, pipapo still needs the delayed set ops .commit call after the transaction handling.
Allow the rbtree to call .commit before the transaction handling which purges the stale elements from the frontend rbtree datastructure.
Update rbtree .commit to skip deactivated and expired elements when building the new b-search array.
--- net/netfilter/nf_tables_api.c | 9 ++++++-- net/netfilter/nft_set_rbtree.c | 41 +++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-)
net/netfilter/nf_tables_api.c +7 -2
@@ -10853,11 +10853,14 @@ static void nf_tables_commit_audit_log(struct list_head *adl, u32 generation) } } -static void nft_set_commit_update (struct nftables_pernet *nft_net) +static void nft_set_commit_update (struct nftables_pernet *nft_net,bool early_commit) {struct nft_set *set, *next;list_for_each_entry_safe (set, next, &nft_net->set_update_list, pending_update) { +if (set->ops->abort_skip_removal && early_commit) +continue ; +list_del_init (&set->pending_update);if (!set->ops->commit || set->dead)
@@ -10964,6 +10967,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) }/* step 2. Make rules_gen_X visible to packet path */ +nft_set_commit_update (nft_net, true); +list_for_each_entry (table, &nft_net->tables, list) {list_for_each_entry (chain, &table->chains, list)nf_tables_commit_chain (net, chain);
@@ -11170,7 +11175,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) } } -nft_set_commit_update (nft_net); +nft_set_commit_update (nft_net, false);nft_commit_notify (net,NETLINK_CB (skb).portid);nf_tables_gen_notify (net, skb,NFT_MSG_NEWGEN );
net/netfilter/nft_set_rbtree.c +35 -6
76 lines not on this page · raw message
Signature · 1 line
2.47.3