Skip to content

Commit 8e15aee

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: move altnames together with the netdevice
The altname nodes are currently not moved to the new netns when netdevice itself moves: [ ~]# ip netns add test [ ~]# ip -netns test link add name eth0 type dummy [ ~]# ip -netns test link property add dev eth0 altname some-name [ ~]# ip -netns test link show dev some-name 2: eth0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 1e:67:ed:19:3d:24 brd ff:ff:ff:ff:ff:ff altname some-name [ ~]# ip -netns test link set dev eth0 netns 1 [ ~]# ip link ... 3: eth0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 02:40:88:62:ec:b8 brd ff:ff:ff:ff:ff:ff altname some-name [ ~]# ip li show dev some-name Device "some-name" does not exist. Remove them from the hash table when device is unlisted and add back when listed again. Fixes: 36fbf1e ("net: rtnetlink: add linkprop commands to add and delete alternative ifnames") Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 1a83f4a commit 8e15aee

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/core/dev.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ static void netdev_name_node_alt_flush(struct net_device *dev)
381381
/* Device list insertion */
382382
static void list_netdevice(struct net_device *dev)
383383
{
384+
struct netdev_name_node *name_node;
384385
struct net *net = dev_net(dev);
385386

386387
ASSERT_RTNL();
@@ -391,6 +392,10 @@ static void list_netdevice(struct net_device *dev)
391392
hlist_add_head_rcu(&dev->index_hlist,
392393
dev_index_hash(net, dev->ifindex));
393394
write_unlock(&dev_base_lock);
395+
396+
netdev_for_each_altname(dev, name_node)
397+
netdev_name_node_add(net, name_node);
398+
394399
/* We reserved the ifindex, this can't fail */
395400
WARN_ON(xa_store(&net->dev_by_index, dev->ifindex, dev, GFP_KERNEL));
396401

@@ -402,12 +407,16 @@ static void list_netdevice(struct net_device *dev)
402407
*/
403408
static void unlist_netdevice(struct net_device *dev, bool lock)
404409
{
410+
struct netdev_name_node *name_node;
405411
struct net *net = dev_net(dev);
406412

407413
ASSERT_RTNL();
408414

409415
xa_erase(&net->dev_by_index, dev->ifindex);
410416

417+
netdev_for_each_altname(dev, name_node)
418+
netdev_name_node_del(name_node);
419+
411420
/* Unlink dev from the device chain */
412421
if (lock)
413422
write_lock(&dev_base_lock);
@@ -10942,7 +10951,6 @@ void unregister_netdevice_many_notify(struct list_head *head,
1094210951
synchronize_net();
1094310952

1094410953
list_for_each_entry(dev, head, unreg_list) {
10945-
struct netdev_name_node *name_node;
1094610954
struct sk_buff *skb = NULL;
1094710955

1094810956
/* Shutdown queueing discipline. */
@@ -10970,9 +10978,6 @@ void unregister_netdevice_many_notify(struct list_head *head,
1097010978
dev_uc_flush(dev);
1097110979
dev_mc_flush(dev);
1097210980

10973-
netdev_for_each_altname(dev, name_node)
10974-
netdev_name_node_del(name_node);
10975-
synchronize_rcu();
1097610981
netdev_name_node_alt_flush(dev);
1097710982
netdev_name_node_free(dev->name_node);
1097810983

0 commit comments

Comments
 (0)