Skip to content

Commit 3e52fba

Browse files
Jiri Pirkokuba-moo
authored andcommitted
net: introduce a helper to move notifier block to different namespace
Currently, net_dev() netdev notifier variant follows the netdev with per-net notifier from namespace to namespace. This is implemented by move_netdevice_notifiers_dev_net() helper. For devlink it is needed to re-register per-net notifier during devlink reload. Introduce a new helper called move_netdevice_notifier_net() and share the unregister/register code with existing move_netdevice_notifiers_dev_net() helper. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 154ba79 commit 3e52fba

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

include/linux/netdevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,8 @@ int unregister_netdevice_notifier(struct notifier_block *nb);
28262826
int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
28272827
int unregister_netdevice_notifier_net(struct net *net,
28282828
struct notifier_block *nb);
2829+
void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
2830+
struct notifier_block *nb);
28292831
int register_netdevice_notifier_dev_net(struct net_device *dev,
28302832
struct notifier_block *nb,
28312833
struct netdev_net_notifier *nn);

net/core/dev.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,22 @@ int unregister_netdevice_notifier_net(struct net *net,
18611861
}
18621862
EXPORT_SYMBOL(unregister_netdevice_notifier_net);
18631863

1864+
static void __move_netdevice_notifier_net(struct net *src_net,
1865+
struct net *dst_net,
1866+
struct notifier_block *nb)
1867+
{
1868+
__unregister_netdevice_notifier_net(src_net, nb);
1869+
__register_netdevice_notifier_net(dst_net, nb, true);
1870+
}
1871+
1872+
void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
1873+
struct notifier_block *nb)
1874+
{
1875+
rtnl_lock();
1876+
__move_netdevice_notifier_net(src_net, dst_net, nb);
1877+
rtnl_unlock();
1878+
}
1879+
18641880
int register_netdevice_notifier_dev_net(struct net_device *dev,
18651881
struct notifier_block *nb,
18661882
struct netdev_net_notifier *nn)
@@ -1897,10 +1913,8 @@ static void move_netdevice_notifiers_dev_net(struct net_device *dev,
18971913
{
18981914
struct netdev_net_notifier *nn;
18991915

1900-
list_for_each_entry(nn, &dev->net_notifier_list, list) {
1901-
__unregister_netdevice_notifier_net(dev_net(dev), nn->nb);
1902-
__register_netdevice_notifier_net(net, nn->nb, true);
1903-
}
1916+
list_for_each_entry(nn, &dev->net_notifier_list, list)
1917+
__move_netdevice_notifier_net(dev_net(dev), net, nn->nb);
19041918
}
19051919

19061920
/**

0 commit comments

Comments
 (0)