netfilter: nf_offload: Make nft_flow_offload_chain public
Subsystems (2)
PATCH 1/3 netfilter: nf_offload: Make nft_flow_offload_chain public
From: wenxu <[email protected]>
Refactor nft_flow_offload_chain and make it public in header
--- include/net/netfilter/nf_tables_offload.h | 3 +++ net/netfilter/nf_tables_offload.c | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-)
include/net/netfilter/nf_tables_offload.h +3 -0
@@ -69,6 +69,9 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,void *cb_priv, enum flow_block_command command); +int nft_flow_offload_chain (struct nft_chain *chain, +enum flow_block_command cmd); +#define NFT_OFFLOAD_MATCH (__key, __base, __field, __len, __reg) \ (__reg)->base_offset = \ offsetof(struct nft_flow_key, __base); \
net/netfilter/nf_tables_offload.c +16 -9
@@ -262,10 +262,9 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain,#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK -static int nft_flow_offload_chain (struct nft_trans *trans, -enum flow_block_command cmd) +int nft_flow_offload_chain (struct nft_chain *chain, +enum flow_block_command cmd) { -struct nft_chain *chain = trans->ctx.chain;struct nft_base_chain *basechain;struct net_device *dev;
@@ -277,16 +276,24 @@ static int nft_flow_offload_chain(struct nft_trans *trans,if (!dev)return -EOPNOTSUPP ; +if (dev->netdev_ops->ndo_setup_tc) +return nft_block_offload_cmd (basechain, dev, cmd); +else +return nft_indr_block_offload_cmd (basechain, dev, cmd); +} + +static int __nft_flow_offload_chain (struct nft_trans *trans, +enum flow_block_command cmd) +{ +struct nft_chain *chain = trans->ctx.chain; +/* Only default policy to accept is supported for now. */ if (cmd ==FLOW_BLOCK_BIND &&nft_trans_chain_policy (trans) !=-1 &&nft_trans_chain_policy (trans) !=NF_ACCEPT )return -EOPNOTSUPP ; -if (dev->netdev_ops->ndo_setup_tc) -return nft_block_offload_cmd (basechain, dev, cmd); -else -return nft_indr_block_offload_cmd (basechain, dev, cmd); +return nft_flow_offload_chain (chain, cmd); }int nft_flow_rule_offload_commit (struct net *net)
@@ -303,13 +310,13 @@ int nft_flow_rule_offload_commit(struct net *net)if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))continue ; - err =nft_flow_offload_chain (trans,FLOW_BLOCK_BIND ); + err =__nft_flow_offload_chain (trans,FLOW_BLOCK_BIND );break ;case NFT_MSG_DELCHAIN :if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))continue ; - err =nft_flow_offload_chain (trans,FLOW_BLOCK_UNBIND ); + err =__nft_flow_offload_chain (trans,FLOW_BLOCK_UNBIND );break ;case NFT_MSG_NEWRULE :if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))
Signature · 1 line
1.8.3.1
PATCH 2/3 netfilter: nf_offload: Make nft_flow_offload_rule public
From: wenxu <[email protected]>
Refactor nft_flow_offload_rule and make it public in header
--- include/net/netfilter/nf_tables_offload.h | 4 ++++ net/netfilter/nf_tables_offload.c | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-)
include/net/netfilter/nf_tables_offload.h +4 -0
@@ -71,6 +71,10 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,int nft_flow_offload_chain (struct nft_chain *chain,enum flow_block_command cmd); +int nft_flow_offload_rule (struct nft_chain *chain, +struct nft_rule *rule, +struct nft_flow_rule *flow, +enum flow_cls_command command);#define NFT_OFFLOAD_MATCH (__key, __base, __field, __len, __reg) \ (__reg)->base_offset = \
net/netfilter/nf_tables_offload.c +18 -8
@@ -124,20 +124,20 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain,return 0 ; } -static int nft_flow_offload_rule (struct nft_trans *trans, -enum flow_cls_command command) +int nft_flow_offload_rule (struct nft_chain *chain, +struct nft_rule *rule, +struct nft_flow_rule *flow, +enum flow_cls_command command) { -struct nft_flow_rule *flow =nft_trans_flow_rule (trans); -struct nft_rule *rule =nft_trans_rule (trans);struct flow_cls_offload cls_flow = {};struct nft_base_chain *basechain;struct netlink_ext_ack extack;__be16 proto =ETH_P_ALL ; -if (!nft_is_base_chain (trans->ctx.chain)) +if (!nft_is_base_chain (chain))return -EOPNOTSUPP ; - basechain =nft_base_chain (trans->ctx.chain); + basechain =nft_base_chain (chain);if (flow) proto = flow->proto;
@@ -151,6 +151,16 @@ static int nft_flow_offload_rule(struct nft_trans *trans,return nft_setup_cb_call (basechain,TC_SETUP_CLSFLOWER , &cls_flow); } +static int __nft_flow_offload_rule (struct nft_trans *trans, +enum flow_cls_command command) +{ +struct nft_flow_rule *flow =nft_trans_flow_rule (trans); +struct nft_rule *rule =nft_trans_rule (trans); +struct nft_chain *chain = trans->ctx.chain; + +return nft_flow_offload_rule (chain, rule, flow, command); +} +static int nft_flow_offload_bind (struct flow_block_offload *bo,struct nft_base_chain *basechain) {
@@ -326,14 +336,14 @@ int nft_flow_rule_offload_commit(struct net *net) !(trans->ctx.flags & NLM_F_APPEND))return -EOPNOTSUPP ; - err =nft_flow_offload_rule (trans,FLOW_CLS_REPLACE ); + err =__nft_flow_offload_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 ))continue ; - err =nft_flow_offload_rule (trans,FLOW_CLS_DESTROY ); + err =__nft_flow_offload_rule (trans,FLOW_CLS_DESTROY );break ; }
Signature · 1 line
1.8.3.1
PATCH 3/3 netfilter: nf_offload: clear offload things in __nft_release_basechain
In reply to [email protected]From: wenxu <[email protected]>
When the net_device unregister, the netdevice_notifier will release the related netdev basedchain and rules in this chains. So it is also need to clear the offload things
--- net/netfilter/nf_tables_api.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/netfilter/nf_tables_api.c +9 -0
@@ -7495,16 +7495,25 @@ int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,int __nft_release_basechain (struct nft_ctx *ctx) {struct nft_rule *rule, *nr; +bool offloaded = false;if (WARN_ON (!nft_is_base_chain (ctx->chain)))return 0 ; +if (ctx->chain->flags &NFT_CHAIN_HW_OFFLOAD ) + offloaded = true; +nf_tables_unregister_hook (ctx->net, ctx->chain->table, ctx->chain);list_for_each_entry_safe (rule, nr, &ctx->chain->rules, list) { +if (offloaded) +nft_flow_offload_rule (ctx->chain, rule, +NULL ,FLOW_CLS_DESTROY );list_del (&rule->list); ctx->chain->use--;nf_tables_rule_release (ctx, rule); } +if (offloaded) +nft_flow_offload_chain (ctx->chain,FLOW_BLOCK_UNBIND );nft_chain_del (ctx->chain); ctx->table->use--;nf_tables_chain_destroy (ctx);
Signature · 1 line
1.8.3.1
Hi pablo,
any idea about this series?
BR
wenxu
Quoted 86 lines · On 8/19/2019 5:45 PM, [email protected] wrote:
From: wenxu <[email protected]>
Refactor
nft_flow_offload_chainand make it public in headerSigned-off-by wenxu <[email protected]>--- include/net/netfilter/nf_tables_offload.h | 3 +++ net/netfilter/nf_tables_offload.c | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-)include/net/netfilter/nf_tables_offload.h +3
-0@@ -69,6 +69,9 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,void *cb_priv, enum flow_block_command command); +int nft_flow_offload_chain (struct nft_chain *chain, +enum flow_block_command cmd); +#define NFT_OFFLOAD_MATCH (__key, __base, __field, __len, __reg) \ (__reg)->base_offset = \ offsetof(struct nft_flow_key, __base); \net/netfilter/nf_tables_offload.c +16
-9@@ -262,10 +262,9 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain,#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK -static int nft_flow_offload_chain (struct nft_trans *trans, -enum flow_block_command cmd) +int nft_flow_offload_chain (struct nft_chain *chain, +enum flow_block_command cmd) { -struct nft_chain *chain = trans->ctx.chain;struct nft_base_chain *basechain;struct net_device *dev;@@ -277,16 +276,24 @@ static int nft_flow_offload_chain(struct nft_trans *trans,if (!dev)return -EOPNOTSUPP ; +if (dev->netdev_ops->ndo_setup_tc) +return nft_block_offload_cmd (basechain, dev, cmd); +else +return nft_indr_block_offload_cmd (basechain, dev, cmd); +} + +static int __nft_flow_offload_chain (struct nft_trans *trans, +enum flow_block_command cmd) +{ +struct nft_chain *chain = trans->ctx.chain; +/* Only default policy to accept is supported for now. */ if (cmd ==FLOW_BLOCK_BIND &&nft_trans_chain_policy (trans) !=-1 &&nft_trans_chain_policy (trans) !=NF_ACCEPT )return -EOPNOTSUPP ; -if (dev->netdev_ops->ndo_setup_tc) -return nft_block_offload_cmd (basechain, dev, cmd); -else -return nft_indr_block_offload_cmd (basechain, dev, cmd); +return nft_flow_offload_chain (chain, cmd); }int nft_flow_rule_offload_commit (struct net *net)@@ -303,13 +310,13 @@ int nft_flow_rule_offload_commit(struct net *net)if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))continue ; - err =nft_flow_offload_chain (trans,FLOW_BLOCK_BIND ); + err =__nft_flow_offload_chain (trans,FLOW_BLOCK_BIND );break ;case NFT_MSG_DELCHAIN :if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))continue ; - err =nft_flow_offload_chain (trans,FLOW_BLOCK_UNBIND ); + err =__nft_flow_offload_chain (trans,FLOW_BLOCK_UNBIND );break ;case NFT_MSG_NEWRULE :if (!(trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ))
Pablo Neira Ayuso
maintainerCould you explore fixing up this by registering a netdev handler from nf_tables_offload.c?
Now we have a nft_offload_init() and _exit() functions, you could register this from there.
I think notifier block priority should allow for running this before __nft_release_basechain().