[CRIU] [PATCH kernel] net: Virtualize netdev ifindex

Pavel Emelyanov xemul at parallels.com
Thu Aug 2 00:42:29 EDT 2012


This is required to make the --namespaces net option pushed recently
work. This is for debugging only, I'm currently working on having
similar stuff upstream.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

commit 30ef146da688d1786f1f98c51268c408ef6cb6bb
Author: Pavel Emelyanov <xemul at parallels.com>
Date:   Wed Aug 1 09:45:02 2012 +0400

    own devifindex dances

diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 32eb94e..5f896a8 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -192,6 +192,7 @@ static __net_init int loopback_net_init(struct net *net)
 	if (!dev)
 		goto out;
 
+	dev->ifindex = 1; /* FIXME */
 	dev_net_set(dev, net);
 	err = register_netdev(dev);
 	if (err)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 5852361..496c026 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -348,6 +348,9 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
 	if (tbp[IFLA_ADDRESS] == NULL)
 		eth_hw_addr_random(peer);
 
+	if (ifmp)
+		peer->ifindex = ifmp->ifi_index;
+
 	err = register_netdevice(peer);
 	put_net(net);
 	net = NULL;
diff --git a/net/core/dev.c b/net/core/dev.c
index 1cb0d8a..8107451 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5499,7 +5499,12 @@ int register_netdevice(struct net_device *dev)
 		}
 	}
 
-	dev->ifindex = dev_new_index(net);
+	ret = -EBUSY;
+	if (!dev->ifindex)
+		dev->ifindex = dev_new_index(net);
+	else if (__dev_get_by_index(net, dev->ifindex))
+		goto err_uninit;
+
 	if (dev->iflink == -1)
 		dev->iflink = dev->ifindex;
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 21318d1..9cc68b5 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1803,8 +1803,6 @@ replay:
 			return -ENODEV;
 		}
 
-		if (ifm->ifi_index)
-			return -EOPNOTSUPP;
 		if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
 			return -EOPNOTSUPP;
 
@@ -1830,10 +1828,14 @@ replay:
 			return PTR_ERR(dest_net);
 
 		dev = rtnl_create_link(net, dest_net, ifname, ops, tb);
-
-		if (IS_ERR(dev))
+		if (IS_ERR(dev)) {
 			err = PTR_ERR(dev);
-		else if (ops->newlink)
+			goto out;
+		}
+
+		dev->ifindex = ifm->ifi_index;
+
+		if (ops->newlink)
 			err = ops->newlink(net, dev, tb, data);
 		else
 			err = register_netdevice(dev);


More information about the CRIU mailing list