netfilter: nf_tables: rename function to destroy hook list
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 1/4 netfilter: nf_tables: rename function to destroy hook list
Rename nft_flowtable_hooks_destroy() by nft_hooks_destroy() to prepare for netdev chain device updates.
---
v2: no changes.
net/netfilter/nf_tables_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +4 -4
@@ -7608,7 +7608,7 @@ static int nft_register_flowtable_net_hooks(struct net *net,return err; } -static void nft_flowtable_hooks_destroy (struct list_head *hook_list) +static void nft_hooks_destroy (struct list_head *hook_list) {struct nft_hook *hook, *next;
@@ -7788,7 +7788,7 @@ static int nf_tables_newflowtable(struct sk_buff *skb, &flowtable->hook_list, flowtable);if (err <0 ) { -nft_flowtable_hooks_destroy (&flowtable->hook_list); +nft_hooks_destroy (&flowtable->hook_list); goto err4; }
@@ -8568,7 +8568,7 @@ static void nft_commit_release(struct nft_trans *trans)break ;case NFT_MSG_DELFLOWTABLE :if (nft_trans_flowtable_update (trans)) -nft_flowtable_hooks_destroy (&nft_trans_flowtable_hooks (trans)); +nft_hooks_destroy (&nft_trans_flowtable_hooks (trans));else nf_tables_flowtable_destroy (nft_trans_flowtable (trans));break ;
@@ -9208,7 +9208,7 @@ static void nf_tables_abort_release(struct nft_trans *trans)break ;case NFT_MSG_NEWFLOWTABLE :if (nft_trans_flowtable_update (trans)) -nft_flowtable_hooks_destroy (&nft_trans_flowtable_hooks (trans)); +nft_hooks_destroy (&nft_trans_flowtable_hooks (trans));else nf_tables_flowtable_destroy (nft_trans_flowtable (trans));break ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 3/4 netfilter: nf_tables: support for deleting devices in an existing netdev chain
This patch allows for deleting devices in an existing netdev chain.
---
v2: disallow device update if NFT_CHAIN_HW_OFFLOAD is set.
net/netfilter/nf_tables_api.c | 103 ++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 12 deletions(-)
net/netfilter/nf_tables_api.c +91 -12
@@ -1631,7 +1631,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net, NFTA_CHAIN_PAD)) goto nla_put_failure; -if (event ==NFT_MSG_DELCHAIN ) { +if (event ==NFT_MSG_DELCHAIN && !hook_list) {nlmsg_end (skb, nlh);return 0 ; }
@@ -2642,6 +2642,60 @@ static int nf_tables_newchain(struct sk_buff *skb, const struct nfnl_info *info,return nf_tables_addchain (&ctx, family, genmask, policy, flags, extack); } +static int nft_delchain_hook (struct nft_ctx *ctx,struct nft_chain *chain, +struct netlink_ext_ack *extack) +{ +const struct nlattr *const *nla = ctx->nla; +struct nft_chain_hook chain_hook = {}; +struct nft_base_chain *basechain; +struct nft_hook *this, *hook; +LIST_HEAD (chain_del_list); +struct nft_trans *trans; +int err; + +if (!nft_is_base_chain (chain)) +return -EOPNOTSUPP ; + + err =nft_chain_parse_hook (ctx->net, nla, &chain_hook, ctx->family, + extack, false); +if (err <0 ) +return err; + + basechain =nft_base_chain (chain); + +list_for_each_entry (this, &chain_hook.list, list) { + hook =nft_hook_list_find (&basechain->hook_list, this); +if (!hook) { + err = -ENOENT ; + goto err_chain_del_hook; + } +list_move (&hook->list, &chain_del_list); + } + + trans =nft_trans_alloc (ctx,NFT_MSG_DELCHAIN , +sizeof (struct nft_trans_chain )); +if (!trans) { + err = -ENOMEM ; + goto err_chain_del_hook; + } + +nft_trans_basechain (trans) = basechain; +nft_trans_chain_update (trans) = true; +INIT_LIST_HEAD (&nft_trans_chain_hooks (trans)); +list_splice (&chain_del_list, &nft_trans_chain_hooks (trans)); +nft_chain_release_hook (&chain_hook); + +nft_trans_commit_list_add_tail (ctx->net, trans); + +return 0 ; + +err_chain_del_hook: +list_splice (&chain_del_list, &basechain->hook_list); +nft_chain_release_hook (&chain_hook); + +return err; +} +static int nf_tables_delchain (struct sk_buff *skb,const struct nfnl_info *info,const struct nlattr *const nla[]) {
@@ -2678,12 +2732,19 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,return PTR_ERR (chain); } +nft_ctx_init (&ctx, net, skb, info->nlh, family, table, chain, nla); + +if (nla[NFTA_CHAIN_HOOK ]) { +if (chain->flags &NFT_CHAIN_HW_OFFLOAD ) +return -EOPNOTSUPP ; + +return nft_delchain_hook (&ctx, chain, extack); + } +if (info->nlh->nlmsg_flags &NLM_F_NONREC && chain->use >0 )return -EBUSY ; -nft_ctx_init (&ctx, net, skb, info->nlh, family, table, chain, nla); - use = chain->use;list_for_each_entry (rule, &chain->rules, list) {if (!nft_is_active_next (net, rule))
@@ -8586,7 +8647,10 @@ static void nft_commit_release(struct nft_trans *trans)kfree (nft_trans_chain_name (trans));break ;case NFT_MSG_DELCHAIN : -nf_tables_chain_destroy (&trans->ctx); +if (nft_trans_chain_update (trans)) +nft_hooks_destroy (&nft_trans_chain_hooks (trans)); +else +nf_tables_chain_destroy (&trans->ctx);break ;case NFT_MSG_DELRULE :nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans));
@@ -9068,16 +9132,26 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) }else {nft_chain_commit_drop_policy (trans);nft_clear (net, trans->ctx.chain); -nf_tables_chain_notify (&trans->ctx,NFT_MSG_NEWCHAIN ,NULL ); +nf_tables_chain_notify (&trans->ctx,NFT_MSG_NEWCHAIN , +NULL );nft_trans_destroy (trans); }break ;case NFT_MSG_DELCHAIN : -nft_chain_del (trans->ctx.chain); -nf_tables_chain_notify (&trans->ctx,NFT_MSG_DELCHAIN ,NULL ); -nf_tables_unregister_hook (trans->ctx.net, - trans->ctx.table, - trans->ctx.chain); +if (nft_trans_chain_update (trans)) { +nf_tables_chain_notify (&trans->ctx,NFT_MSG_DELCHAIN , + &nft_trans_chain_hooks (trans)); +nft_netdev_unregister_hooks (net, + &nft_trans_chain_hooks (trans), + true); + }else { +nft_chain_del (trans->ctx.chain); +nf_tables_chain_notify (&trans->ctx,NFT_MSG_DELCHAIN , +NULL ); +nf_tables_unregister_hook (trans->ctx.net, + trans->ctx.table, + trans->ctx.chain); + }break ;case NFT_MSG_NEWRULE :nft_clear (trans->ctx.net,nft_trans_rule (trans));
@@ -9314,8 +9388,13 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) }break ;case NFT_MSG_DELCHAIN : - trans->ctx.table->use++; -nft_clear (trans->ctx.net, trans->ctx.chain); +if (nft_trans_chain_update (trans)) { +list_splice (&nft_trans_chain_hooks (trans), + &nft_trans_basechain (trans)->hook_list); + }else { + trans->ctx.table->use++; +nft_clear (trans->ctx.net, trans->ctx.chain); + }nft_trans_destroy (trans);break ;case NFT_MSG_NEWRULE :
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 4/4 netfilter: nf_tables: allow to create netdev chain without device
In reply to Pablo Neira AyusoRelax netdev chain creation to allow for loading the ruleset, then adding/deleting devices at a later stage. Hardware offload does not support for this feature yet.
---
v2: new in this series.
net/netfilter/nf_tables_api.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
net/netfilter/nf_tables_api.c +13 -13
@@ -2005,9 +2005,8 @@ struct nft_chain_hook {struct list_head list; }; -static int nft_chain_parse_netdev (struct net *net, -struct nlattr *tb[], -struct list_head *hook_list) +static int nft_chain_parse_netdev (struct net *net,struct nlattr *tb[], +struct list_head *hook_list,u32 flags) {struct nft_hook *hook;int err;
@@ -2024,19 +2023,20 @@ static int nft_chain_parse_netdev(struct net *net,if (err <0 )return err; -if (list_empty (hook_list)) -return -EINVAL ; - }else { -return -EINVAL ; } +if (flags &NFT_CHAIN_HW_OFFLOAD && +list_empty (hook_list)) +return -EINVAL ; +return 0 ; }static int nft_chain_parse_hook (struct net *net,const struct nlattr *const nla[],struct nft_chain_hook *hook,u8 family, -struct netlink_ext_ack *extack,bool add) +u32 flags,struct netlink_ext_ack *extack, +bool add) {struct nftables_pernet *nft_net =nft_pernet (net);struct nlattr *ha[NFTA_HOOK_MAX +1 ];
@@ -2095,7 +2095,7 @@ static int nft_chain_parse_hook(struct net *net,INIT_LIST_HEAD (&hook->list);if (nft_base_chain_netdev (family, hook->num)) { - err =nft_chain_parse_netdev (net, ha, &hook->list); + err =nft_chain_parse_netdev (net, ha, &hook->list, flags);if (err <0 ) {module_put (type->owner);return err;
@@ -2238,8 +2238,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,if (flags &NFT_CHAIN_BINDING )return -EOPNOTSUPP ; - err =nft_chain_parse_hook (net, nla, &hook, family, extack, - true); + err =nft_chain_parse_hook (net, nla, &hook, family, flags, + extack, true);if (err <0 )return err;
@@ -2381,7 +2381,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,return -EEXIST ; } err =nft_chain_parse_hook (ctx->net, nla, &hook, ctx->family, - extack, false); + flags, extack, false);if (err <0 )return err;
@@ -2657,7 +2657,7 @@ static int nft_delchain_hook(struct nft_ctx *ctx, struct nft_chain *chain,return -EOPNOTSUPP ; err =nft_chain_parse_hook (ctx->net, nla, &chain_hook, ctx->family, - extack, false); + chain->flags, extack, false);if (err <0 )return err;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 2/4 netfilter: nf_tables: support for adding new devices to an existing netdev chain
In reply to Pablo Neira AyusoThis patch allows users to add devices to an existing netdev chain.
---
v2: - notify device updates.
- fix error path in nf_tables_updchain()
- initialize nft_chain_hook object to fix spurious hooknum / priority mismatch.
include/net/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 169 +++++++++++++++++++----------- 2 files changed, 113 insertions(+), 62 deletions(-)
include/net/netfilter/nf_tables.h +6 -0
@@ -1574,6 +1574,8 @@ struct nft_trans_chain {struct nft_stats __percpu *stats;u8 policy;u32 chain_id; +struct nft_base_chain *basechain; +struct list_head hook_list; };#define nft_trans_chain_update (trans) \
@@ -1586,6 +1588,10 @@ struct nft_trans_chain { (((struct nft_trans_chain *)trans->data)->policy)#define nft_trans_chain_id (trans) \ (((struct nft_trans_chain *)trans->data)->chain_id) +#define nft_trans_basechain (trans) \ + (((struct nft_trans_chain *)trans->data)->basechain) +#define nft_trans_chain_hooks (trans) \ + (((struct nft_trans_chain *)trans->data)->hook_list)struct nft_trans_table {bool update;
net/netfilter/nf_tables_api.c +107 -62
349 lines not on this page · raw message
Signature · 1 line
2.30.2