Skip to content

Commit 9c7dafb

Browse files
xemuldavem330
authored andcommitted
net: Allow to create links with given ifindex
Currently the RTM_NEWLINK results in -EOPNOTSUPP if the ifinfomsg->ifi_index is not zero. I propose to allow requesting ifindices on link creation. This is required by the checkpoint-restore to correctly restore a net namespace (i.e. -- a container). Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b14f243 commit 9c7dafb

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

net/core/dev.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5579,7 +5579,12 @@ int register_netdevice(struct net_device *dev)
55795579
}
55805580
}
55815581

5582-
dev->ifindex = dev_new_index(net);
5582+
ret = -EBUSY;
5583+
if (!dev->ifindex)
5584+
dev->ifindex = dev_new_index(net);
5585+
else if (__dev_get_by_index(net, dev->ifindex))
5586+
goto err_uninit;
5587+
55835588
if (dev->iflink == -1)
55845589
dev->iflink = dev->ifindex;
55855590

net/core/rtnetlink.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,8 +1812,6 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
18121812
return -ENODEV;
18131813
}
18141814

1815-
if (ifm->ifi_index)
1816-
return -EOPNOTSUPP;
18171815
if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
18181816
return -EOPNOTSUPP;
18191817

@@ -1839,10 +1837,14 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
18391837
return PTR_ERR(dest_net);
18401838

18411839
dev = rtnl_create_link(net, dest_net, ifname, ops, tb);
1842-
1843-
if (IS_ERR(dev))
1840+
if (IS_ERR(dev)) {
18441841
err = PTR_ERR(dev);
1845-
else if (ops->newlink)
1842+
goto out;
1843+
}
1844+
1845+
dev->ifindex = ifm->ifi_index;
1846+
1847+
if (ops->newlink)
18461848
err = ops->newlink(net, dev, tb, data);
18471849
else
18481850
err = register_netdevice(dev);

0 commit comments

Comments
 (0)