Skip to content

Commit 9669c11

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Wrap netdev notifiers
Handling NETDEV_CHANGENAME events has to traverse all chains/flowtables twice, prepare for this. No functional change intended. Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a331b78 commit 9669c11

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9736,13 +9736,28 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
97369736
return 0;
97379737
}
97389738

9739+
static int __nf_tables_flowtable_event(unsigned long event,
9740+
struct net_device *dev)
9741+
{
9742+
struct nftables_pernet *nft_net = nft_pernet(dev_net(dev));
9743+
struct nft_flowtable *flowtable;
9744+
struct nft_table *table;
9745+
9746+
list_for_each_entry(table, &nft_net->tables, list) {
9747+
list_for_each_entry(flowtable, &table->flowtables, list) {
9748+
if (nft_flowtable_event(event, dev, flowtable))
9749+
return 1;
9750+
}
9751+
}
9752+
return 0;
9753+
}
9754+
97399755
static int nf_tables_flowtable_event(struct notifier_block *this,
97409756
unsigned long event, void *ptr)
97419757
{
97429758
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
9743-
struct nft_flowtable *flowtable;
97449759
struct nftables_pernet *nft_net;
9745-
struct nft_table *table;
9760+
int ret = NOTIFY_DONE;
97469761
struct net *net;
97479762

97489763
if (event != NETDEV_REGISTER &&
@@ -9752,17 +9767,12 @@ static int nf_tables_flowtable_event(struct notifier_block *this,
97529767
net = dev_net(dev);
97539768
nft_net = nft_pernet(net);
97549769
mutex_lock(&nft_net->commit_mutex);
9755-
list_for_each_entry(table, &nft_net->tables, list) {
9756-
list_for_each_entry(flowtable, &table->flowtables, list) {
9757-
if (nft_flowtable_event(event, dev, flowtable)) {
9758-
mutex_unlock(&nft_net->commit_mutex);
9759-
return NOTIFY_BAD;
9760-
}
9761-
}
9762-
}
9763-
mutex_unlock(&nft_net->commit_mutex);
97649770

9765-
return NOTIFY_DONE;
9771+
if (__nf_tables_flowtable_event(event, dev))
9772+
ret = NOTIFY_BAD;
9773+
9774+
mutex_unlock(&nft_net->commit_mutex);
9775+
return ret;
97669776
}
97679777

97689778
static struct notifier_block nf_tables_flowtable_notifier = {

net/netfilter/nft_chain_filter.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,14 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,
363363
return 0;
364364
}
365365

366-
static int nf_tables_netdev_event(struct notifier_block *this,
367-
unsigned long event, void *ptr)
366+
static int __nf_tables_netdev_event(unsigned long event, struct net_device *dev)
368367
{
369-
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
370368
struct nft_base_chain *basechain;
371369
struct nftables_pernet *nft_net;
372370
struct nft_chain *chain;
373371
struct nft_table *table;
374372

375-
if (event != NETDEV_REGISTER &&
376-
event != NETDEV_UNREGISTER)
377-
return NOTIFY_DONE;
378-
379373
nft_net = nft_pernet(dev_net(dev));
380-
mutex_lock(&nft_net->commit_mutex);
381374
list_for_each_entry(table, &nft_net->tables, list) {
382375
if (table->family != NFPROTO_NETDEV &&
383376
table->family != NFPROTO_INET)
@@ -392,15 +385,32 @@ static int nf_tables_netdev_event(struct notifier_block *this,
392385
basechain->ops.hooknum != NF_INET_INGRESS)
393386
continue;
394387

395-
if (nft_netdev_event(event, dev, basechain)) {
396-
mutex_unlock(&nft_net->commit_mutex);
397-
return NOTIFY_BAD;
398-
}
388+
if (nft_netdev_event(event, dev, basechain))
389+
return 1;
399390
}
400391
}
401-
mutex_unlock(&nft_net->commit_mutex);
392+
return 0;
393+
}
394+
395+
static int nf_tables_netdev_event(struct notifier_block *this,
396+
unsigned long event, void *ptr)
397+
{
398+
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
399+
struct nftables_pernet *nft_net;
400+
int ret = NOTIFY_DONE;
401+
402+
if (event != NETDEV_REGISTER &&
403+
event != NETDEV_UNREGISTER)
404+
return NOTIFY_DONE;
402405

403-
return NOTIFY_DONE;
406+
nft_net = nft_pernet(dev_net(dev));
407+
mutex_lock(&nft_net->commit_mutex);
408+
409+
if (__nf_tables_netdev_event(event, dev))
410+
ret = NOTIFY_BAD;
411+
412+
mutex_unlock(&nft_net->commit_mutex);
413+
return ret;
404414
}
405415

406416
static struct notifier_block nf_tables_netdev_notifier = {

0 commit comments

Comments
 (0)