* [PATCH nf-next 2/3] netfilter: nf_offload: Make nft_flow_offload_rule public
2019-08-19 9:45 [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
@ 2019-08-19 9:45 ` wenxu
2019-08-19 9:45 ` [PATCH nf-next 3/3] netfilter: nf_offload: clear offload things in __nft_release_basechain wenxu
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: wenxu @ 2019-08-19 9:45 UTC (permalink / raw)
To: pablo, fw; +Cc: netfilter-devel
From: wenxu <wenxu@ucloud.cn>
Refactor nft_flow_offload_rule and make it public in header
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
include/net/netfilter/nf_tables_offload.h | 4 ++++
net/netfilter/nf_tables_offload.c | 26 ++++++++++++++++++--------
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/include/net/netfilter/nf_tables_offload.h b/include/net/netfilter/nf_tables_offload.h
index a13aab1..6946db67 100644
--- a/include/net/netfilter/nf_tables_offload.h
+++ b/include/net/netfilter/nf_tables_offload.h
@@ -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 = \
diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
index 3ffe4bb..bcaafc8 100644
--- a/net/netfilter/nf_tables_offload.c
+++ b/net/netfilter/nf_tables_offload.c
@@ -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;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH nf-next 3/3] netfilter: nf_offload: clear offload things in __nft_release_basechain
2019-08-19 9:45 [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
2019-08-19 9:45 ` [PATCH nf-next 2/3] netfilter: nf_offload: Make nft_flow_offload_rule public wenxu
@ 2019-08-19 9:45 ` wenxu
2019-09-02 6:13 ` [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
2019-09-03 17:33 ` Pablo Neira Ayuso
3 siblings, 0 replies; 5+ messages in thread
From: wenxu @ 2019-08-19 9:45 UTC (permalink / raw)
To: pablo, fw; +Cc: netfilter-devel
From: wenxu <wenxu@ucloud.cn>
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
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/netfilter/nf_tables_api.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index fe3b7b0..345df36 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public
2019-08-19 9:45 [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
2019-08-19 9:45 ` [PATCH nf-next 2/3] netfilter: nf_offload: Make nft_flow_offload_rule public wenxu
2019-08-19 9:45 ` [PATCH nf-next 3/3] netfilter: nf_offload: clear offload things in __nft_release_basechain wenxu
@ 2019-09-02 6:13 ` wenxu
2019-09-03 17:33 ` Pablo Neira Ayuso
3 siblings, 0 replies; 5+ messages in thread
From: wenxu @ 2019-09-02 6:13 UTC (permalink / raw)
To: pablo, fw; +Cc: netfilter-devel
Hi pablo,
any idea about this series?
BR
wenxu
On 8/19/2019 5:45 PM, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Refactor nft_flow_offload_chain and make it public in header
>
> Signed-off-by: wenxu <wenxu@ucloud.cn>
> ---
> include/net/netfilter/nf_tables_offload.h | 3 +++
> net/netfilter/nf_tables_offload.c | 25 ++++++++++++++++---------
> 2 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/include/net/netfilter/nf_tables_offload.h b/include/net/netfilter/nf_tables_offload.h
> index 8a5969d9..a13aab1 100644
> --- a/include/net/netfilter/nf_tables_offload.h
> +++ b/include/net/netfilter/nf_tables_offload.h
> @@ -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); \
> diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
> index fd8d3ab..3ffe4bb 100644
> --- a/net/netfilter/nf_tables_offload.c
> +++ b/net/netfilter/nf_tables_offload.c
> @@ -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))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public
2019-08-19 9:45 [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
` (2 preceding siblings ...)
2019-09-02 6:13 ` [PATCH nf-next 1/3] netfilter: nf_offload: Make nft_flow_offload_chain public wenxu
@ 2019-09-03 17:33 ` Pablo Neira Ayuso
3 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2019-09-03 17:33 UTC (permalink / raw)
To: wenxu; +Cc: fw, netfilter-devel
Could 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().
^ permalink raw reply [flat|nested] 5+ messages in thread