From: wenxu <wenxu@ucloud.cn>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next v2 3/3] netfilter: nf_tables_offload: clean offload things when the device unregister
Date: Thu, 5 Sep 2019 11:26:46 +0800 [thread overview]
Message-ID: <466178d0-3f97-e474-467d-df732b867daa@ucloud.cn> (raw)
In-Reply-To: <20190904194024.q2rxmdpnthgkono4@salvia>
On 9/5/2019 3:40 AM, Pablo Neira Ayuso wrote:
> Thanks for working on this.
>
> On Wed, Sep 04, 2019 at 03:07:31PM +0800, wenxu@ucloud.cn wrote:
>> diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
>> index 9657001..9fa3bdb 100644
>> --- a/net/netfilter/nf_tables_offload.c
>> +++ b/net/netfilter/nf_tables_offload.c
>> @@ -396,17 +396,78 @@ static void nft_indr_block_cb(struct net_device *dev,
>> mutex_unlock(&net->nft.commit_mutex);
>> }
>>
>> +static void nft_offload_chain_clean(struct nft_chain *chain)
>> +{
>> + struct nft_rule *rule;
>> +
>> + list_for_each_entry(rule, &chain->rules, list) {
>> + nft_flow_offload_rule(chain, rule,
>> + NULL, FLOW_CLS_DESTROY);
>> + }
>> +
>> + nft_flow_offload_chain(chain, FLOW_BLOCK_UNBIND);
>> +}
>> +
>> +static int nft_offload_netdev_event(struct notifier_block *this,
>> + unsigned long event, void *ptr)
>> +{
>> + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
>> + struct nft_base_chain *basechain;
>> + struct net *net = dev_net(dev);
>> + struct nft_table *table;
>> + struct nft_chain *chain;
>> +
>> + if (event != NETDEV_UNREGISTER)
>> + return NOTIFY_DONE;
>> +
>> + mutex_lock(&net->nft.commit_mutex);
>> + list_for_each_entry(table, &net->nft.tables, list) {
>> + if (table->family != NFPROTO_NETDEV)
>> + continue;
>> +
>> + list_for_each_entry(chain, &table->chains, list) {
>> + if (!nft_is_base_chain(chain) ||
>> + !(chain->flags & NFT_CHAIN_HW_OFFLOAD))
>> + continue;
>> +
>> + basechain = nft_base_chain(chain);
>> + if (strncmp(basechain->dev_name, dev->name, IFNAMSIZ))
>> + continue;
>> +
>> + nft_offload_chain_clean(chain);
>> + mutex_unlock(&net->nft.commit_mutex);
>> + return NOTIFY_DONE;
>> + }
>> + }
>> + mutex_unlock(&net->nft.commit_mutex);
> This code around the mutex look very similar to nft_block_indr_cb(),
> could you consolidate this? Probably something like
> nft_offload_netdev_iterate() and add a callback.
nft_offload_netdev_iterate is a good idear, But maybe it can't provide
a common callback. The nft_offload_netdev_iterate(without mutex) can return the chain
amke each function(with mutex) use it
>
>> + return NOTIFY_DONE;
>> +}
>> +
>> static struct flow_indr_block_ing_entry block_ing_entry = {
>> .cb = nft_indr_block_cb,
>> .list = LIST_HEAD_INIT(block_ing_entry.list),
>> };
>>
>> -void nft_offload_init(void)
>> +static struct notifier_block nft_offload_netdev_notifier = {
>> + .notifier_call = nft_offload_netdev_event,
> No need for priority because of registration order, right?
yes, nft_offload_init will early than nft_chain_filter mod init
>
prev parent reply other threads:[~2019-09-05 3:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-04 7:07 [PATCH nf-next v2 0/3] netfilter: nf_tables_offload: clean offload things when the device unregister wenxu
2019-09-04 7:07 ` [PATCH nf-next v2 1/3] netfilter: nf_offload: refactor the nft_flow_offload_chain function wenxu
2019-09-04 7:07 ` [PATCH nf-next v2 2/3] netfilter: nf_offload: refactor the nft_flow_offload_rule function wenxu
2019-09-04 7:07 ` [PATCH nf-next v2 3/3] netfilter: nf_tables_offload: clean offload things when the device unregister wenxu
2019-09-04 19:40 ` Pablo Neira Ayuso
2019-09-05 3:26 ` wenxu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=466178d0-3f97-e474-467d-df732b867daa@ucloud.cn \
--to=wenxu@ucloud.cn \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).