netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 2/3 netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase
Publish new hooks in the list into the basechain/flowtable using splice_list_rcu() to ensure netlink dump list traversal via rcu is safe while concurrent ruleset update is going on.
---
v2: no changes, requires list_splice_rcu() in v2
net/netfilter/nf_tables_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +4 -4
@@ -10912,8 +10912,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_chain_commit_update (nft_trans_container_chain (trans));nf_tables_chain_notify (&ctx,NFT_MSG_NEWCHAIN , &nft_trans_chain_hooks (trans)); -list_splice (&nft_trans_chain_hooks (trans), - &nft_trans_basechain (trans)->hook_list); +list_splice_rcu (&nft_trans_chain_hooks (trans), + &nft_trans_basechain (trans)->hook_list);/* trans destroyed after rcu grace period */ }else {nft_chain_commit_drop_policy (nft_trans_container_chain (trans));
@@ -11042,8 +11042,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_trans_flowtable (trans), &nft_trans_flowtable_hooks (trans), NFT_MSG_NEWFLOWTABLE); -list_splice (&nft_trans_flowtable_hooks (trans), - &nft_trans_flowtable (trans)->hook_list); +list_splice_rcu (&nft_trans_flowtable_hooks (trans), + &nft_trans_flowtable (trans)->hook_list); }else {nft_clear (net,nft_trans_flowtable (trans)); nf_tables_flowtable_notify(&ctx,
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v2 3/3 netfilter: nf_tables: add hook transactions for device deletions
Restore the flag that indicates that the hook is going away, ie. NFT_HOOK_REMOVE, but add a new transaction object to track deletion of hooks without altering the basechain/flowtable hook_list during the preparation phase.
The existing approach that moves the hook from the basechain/flowtable hook_list to transaction hook_list breaks netlink dump path readers of this RCU-protected list.
It should be possible use an array for nft_trans_hook to store the deleted hooks to compact the representation but I am not expecting many hook object, specially now that wildcard support for devices is in place.
Note that the nft_trans_chain_hooks() list contains a list of struct nft_trans_hook objects for DELCHAIN and DELFLOWTABLE commands, while this list stores struct nft_hook objects for NEWCHAIN and NEWFLOWTABLE. Note that new commands can be updated to use nft_trans_hook for consistency.
---
v2: no changes.
include/net/netfilter/nf_tables.h | 13 ++++ net/netfilter/nf_tables_api.c | 124 ++++++++++++++++++++++++++---- 2 files changed, 120 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +13 -0
@@ -1216,12 +1216,15 @@ struct nft_stats {struct u64_stats_sync syncp; }; +#define NFT_HOOK_REMOVE (1 << 0) +struct nft_hook {struct list_head list;struct list_head ops_list;struct rcu_head rcu;char ifname[IFNAMSIZ ];u8 ifnamelen; +u8 flags; }; struct nf_hook_ops *nft_hook_find_ops(const struct nft_hook *hook,
@@ -1676,6 +1679,16 @@ struct nft_trans { u8 put_net:1; }; +/** +* struct nft_trans_hook - nf_tables hook update in transaction +* @list: used internally +* @hook: struct nft_hook with the device hook +*/ +struct nft_trans_hook { +struct list_head list; +struct nft_hook *hook; +}; +/** * struct nft_trans_binding - nf_tables object with binding support in transaction * @nft_trans: base structure, MUST be first member
net/netfilter/nf_tables_api.c +107 -17
227 lines not on this page · raw message
Signature · 1 line
2.47.3
Florian Westphal
maintainerRe: [PATCH nf,v2 3/3] netfilter: nf_tables: add hook transactions for device deletions
Quoted 53 lines · Pablo Neira Ayuso
Restore the flag that indicates that the hook is going away, ie.
NFT_HOOK_REMOVE, but add a new transaction object to track deletion of hooks without altering the basechain/flowtablehook_listduring the preparation phase.The existing approach that moves the hook from the basechain/flowtable
hook_listto transactionhook_listbreaks netlink dump path readers of this RCU-protected list.It should be possible use an array for
nft_trans_hookto store the deleted hooks to compact the representation but I am not expecting many hook object, specially now that wildcard support for devices is in place.Note that the
nft_trans_chain_hooks()list contains a list of structnft_trans_hookobjects for DELCHAIN and DELFLOWTABLE commands, while this list stores structnft_hookobjects for NEWCHAIN and NEWFLOWTABLE. Note that new commands can be updated to usenft_trans_hookfor consistency.Fixes 7d937b107108 ("netfilter: nf_tables: support for deleting devices in an existing netdev chain")Fixes b6d9014a3335 ("netfilter: nf_tables: delete flowtable hooks via transaction list")Signed-off-by Pablo Neira Ayuso <[email protected]>---
v2: no changes.include/net/netfilter/nf_tables.h | 13 ++++ net/netfilter/nf_tables_api.c | 124 ++++++++++++++++++++++++++---- 2 files changed, 120 insertions(+), 17 deletions(-)include/net/netfilter/nf_tables.h +3
-0@@ -1216,12 +1216,15 @@ struct nft_stats {struct u64_stats_sync syncp; }; +#define NFT_HOOK_REMOVE (1 << 0) +struct nft_hook {struct list_head list;struct list_head ops_list;struct rcu_head rcu;char ifname[IFNAMSIZ ];u8 ifnamelen; +u8 flags; }; struct nf_hook_ops *nft_hook_find_ops(const struct nft_hook *hook,@@ -1676,6 +1679,16 @@ struct nft_trans { u8 put_net:1; };
include/net/netfilter/nf_tables.h struct nft_trans { · line 1690
Quoted 10 lines
include/net/netfilter/nf_tables.h +9
-0+/** +* struct nft_trans_hook - nf_tables hook update in transaction +* @list: used internally +* @hook: struct nft_hook with the device hook +*/ +struct nft_trans_hook { +struct list_head list; +struct nft_hook *hook; +};
Do I get this correctly?
nft_trans_container_flowtable(trans)->hook_list
and
nft_trans_container_chain(trans)->hook_list
Either hold 'struct nft_hook' objects or nft_trans_hook objects? Former when adding, latter when removing from existing base hook?
include/net/netfilter/nf_tables.h struct nft_trans { · line 1691
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+ trans_hook =kmalloc (sizeof (*trans_hook),GFP_KERNEL );
Note that 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types") transformed such allocation requests to use "kmalloc_obj(*trans_hook, GFP_KERNEL);" instead.
Pablo Neira Ayuso
maintainerRe: [PATCH nf,v2 3/3] netfilter: nf_tables: add hook transactions for device deletions
Quoted 67 lines · Florian Westphal
Quoted 53 lines · Pablo Neira Ayuso
Restore the flag that indicates that the hook is going away, ie.
NFT_HOOK_REMOVE, but add a new transaction object to track deletion of hooks without altering the basechain/flowtablehook_listduring the preparation phase.The existing approach that moves the hook from the basechain/flowtable
hook_listto transactionhook_listbreaks netlink dump path readers of this RCU-protected list.It should be possible use an array for
nft_trans_hookto store the deleted hooks to compact the representation but I am not expecting many hook object, specially now that wildcard support for devices is in place.Note that the
nft_trans_chain_hooks()list contains a list of structnft_trans_hookobjects for DELCHAIN and DELFLOWTABLE commands, while this list stores structnft_hookobjects for NEWCHAIN and NEWFLOWTABLE. Note that new commands can be updated to usenft_trans_hookfor consistency.Fixes 7d937b107108 ("netfilter: nf_tables: support for deleting devices in an existing netdev chain")Fixes b6d9014a3335 ("netfilter: nf_tables: delete flowtable hooks via transaction list")Signed-off-by Pablo Neira Ayuso <[email protected]>---
v2: no changes.include/net/netfilter/nf_tables.h | 13 ++++ net/netfilter/nf_tables_api.c | 124 ++++++++++++++++++++++++++---- 2 files changed, 120 insertions(+), 17 deletions(-)include/net/netfilter/nf_tables.h +3
-0@@ -1216,12 +1216,15 @@ struct nft_stats {struct u64_stats_sync syncp; }; +#define NFT_HOOK_REMOVE (1 << 0) +struct nft_hook {struct list_head list;struct list_head ops_list;struct rcu_head rcu;char ifname[IFNAMSIZ ];u8 ifnamelen; +u8 flags; }; struct nf_hook_ops *nft_hook_find_ops(const struct nft_hook *hook,@@ -1676,6 +1679,16 @@ struct nft_trans { u8 put_net:1; };include/net/netfilter/nf_tables.h struct nft_trans { · line 1690
Quoted 10 lines
include/net/netfilter/nf_tables.h +9
-0+/** +* struct nft_trans_hook - nf_tables hook update in transaction +* @list: used internally +* @hook: struct nft_hook with the device hook +*/ +struct nft_trans_hook { +struct list_head list; +struct nft_hook *hook; +};Do I get this correctly?
Quoted 6 lines
nft_trans_container_flowtable(trans)->hook_list
and
nft_trans_container_chain(trans)->hook_listEither hold 'struct
nft_hook' objects ornft_trans_hookobjects? Former when adding, latter when removing from existing base hook?
Add, update -> struct nft_hook
Delete -> struct nft_trans_hook
Yes. I could add a separated list, but this list is exclusive for the transaction object. Another option is a union to highlight how it is used, but it is not better than the current mixed semantics, which are not ideal.
As a follow up, it should be possible to use nft_trans_hook for updates too in nf-next for consistency.
Quoted 5 lines
include/net/netfilter/nf_tables.h struct nft_trans { · line 1691
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+ trans_hook =kmalloc (sizeof (*trans_hook),GFP_KERNEL );Note that
69050f8d6d07("treewide: Replace kmalloc withkmalloc_objfor non-scalar types") transformed such allocation requests to use "kmalloc_obj(*trans_hook, GFP_KERNEL);" instead.
I will replace it to use the new kmalloc_obj().