netfilter: nf_tables_offload: remove reference to flow rule from deletion path
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nf_tables_offload: remove reference to flow rule from deletion path
The cookie is sufficient to delete the rule from the hardware.
--- net/netfilter/nf_tables_offload.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netfilter/nf_tables_offload.c +1 -2
@@ -437,8 +437,7 @@ int nft_flow_rule_offload_commit(struct net *net) err =nft_flow_offload_rule (trans->ctx.chain,nft_trans_rule (trans), -nft_trans_flow_rule (trans), -FLOW_CLS_DESTROY ); +NULL ,FLOW_CLS_DESTROY );break ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nf_tables_offload: release flow_rule on error from commit path
If hardware offload commit path fails, release all flow_rule object.
--- net/netfilter/nf_tables_offload.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_offload.c +21 -5
@@ -422,14 +422,14 @@ int nft_flow_rule_offload_commit(struct net *net)continue ;if (trans->ctx.flags &NLM_F_REPLACE || - !(trans->ctx.flags &NLM_F_APPEND )) -return -EOPNOTSUPP ; - + !(trans->ctx.flags &NLM_F_APPEND )) { + err = -EOPNOTSUPP ; +break ; + } err =nft_flow_offload_rule (trans->ctx.chain,nft_trans_rule (trans),nft_trans_flow_rule (trans),FLOW_CLS_REPLACE ); -nft_flow_rule_destroy (nft_trans_flow_rule (trans));break ;case NFT_MSG_DELRULE :if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))
@@ -442,7 +442,23 @@ int nft_flow_rule_offload_commit(struct net *net) }if (err) -return err; +break ; + } + +list_for_each_entry (trans, &net->nft.commit_list, list) { +if (trans->ctx.family !=NFPROTO_NETDEV ) +continue ; + +switch (trans->msg_type) { +case NFT_MSG_NEWRULE : +if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD )) +continue ; + +nft_flow_rule_destroy (nft_trans_flow_rule (trans)); +break ; +default : +break ; + } }return err;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nf_tables_offload: undo updates if transaction fails
In reply to Pablo Neira AyusoThe nft_flow_rule_offload_commit() might fail after several successful commands leaving the hardware filtering policy in inconsistent state. This patch adds nft_flow_rule_offload_abort() which undoes the updates that have been already processed if one command of this transaction fails. Hence, the hardware ruleset is left as is it was before the update.
Thee deletion path needs to create the flow_rule object too, in case that an existing rule needs to be re-added from the abort path.
--- net/netfilter/nf_tables_api.c | 11 ++++++++ net/netfilter/nf_tables_offload.c | 54 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +11 -0
@@ -361,6 +361,7 @@ static struct nft_trans *nft_trans_rule_add(struct nft_ctx *ctx, int msg_type,static int nft_delrule (struct nft_ctx *ctx,struct nft_rule *rule) { +struct nft_flow_rule *flow;struct nft_trans *trans;int err;
@@ -368,6 +369,16 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)if (trans ==NULL )return -ENOMEM ; +if (ctx->chain->flags &NFT_CHAIN_HW_OFFLOAD ) { + flow =nft_flow_rule_create (ctx->net, rule); +if (IS_ERR (flow)) { +nft_trans_destroy (trans); +return PTR_ERR (flow); + } + +nft_trans_flow_rule (trans) = flow; + } + err =nf_tables_delrule_deactivate (ctx, rule);if (err <0 ) {nft_trans_destroy (trans);
net/netfilter/nf_tables_offload.c +53 -1
73 lines not on this page · raw message
Signature · 1 line
2.11.0