61 lines
1.7 KiB
Diff
61 lines
1.7 KiB
Diff
|
From e98f08306dd0dc854d93339730a8603638173e23 Mon Sep 17 00:00:00 2001
|
||
|
From: Tom Goff <thomas.goff@boeing.com>
|
||
|
Date: Fri, 27 Jul 2012 00:02:50 -0700
|
||
|
Subject: [PATCH] Make network device ifindex sequential per network
|
||
|
namespace.
|
||
|
|
||
|
Signed-off-by: Tom Goff <thomas.goff@boeing.com>
|
||
|
---
|
||
|
include/net/net_namespace.h | 2 ++
|
||
|
net/core/dev.c | 13 ++++++-------
|
||
|
2 files changed, 8 insertions(+), 7 deletions(-)
|
||
|
|
||
|
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
|
||
|
index ac9195e..1b9c99a 100644
|
||
|
--- a/include/net/net_namespace.h
|
||
|
+++ b/include/net/net_namespace.h
|
||
|
@@ -62,6 +62,8 @@ struct net {
|
||
|
struct sock *rtnl; /* rtnetlink socket */
|
||
|
struct sock *genl_sock;
|
||
|
|
||
|
+ int ifindex;
|
||
|
+
|
||
|
struct list_head dev_base_head;
|
||
|
struct hlist_head *dev_name_head;
|
||
|
struct hlist_head *dev_index_head;
|
||
|
diff --git a/net/core/dev.c b/net/core/dev.c
|
||
|
index 3ad746b..7bec156 100644
|
||
|
--- a/net/core/dev.c
|
||
|
+++ b/net/core/dev.c
|
||
|
@@ -5168,12 +5168,11 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
|
||
|
*/
|
||
|
static int dev_new_index(struct net *net)
|
||
|
{
|
||
|
- static int ifindex;
|
||
|
for (;;) {
|
||
|
- if (++ifindex <= 0)
|
||
|
- ifindex = 1;
|
||
|
- if (!__dev_get_by_index(net, ifindex))
|
||
|
- return ifindex;
|
||
|
+ if (++net->ifindex <= 0)
|
||
|
+ net->ifindex = 1;
|
||
|
+ if (!__dev_get_by_index(net, net->ifindex))
|
||
|
+ return net->ifindex;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@@ -6182,8 +6181,8 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
|
||
|
/* Actually switch the network namespace */
|
||
|
dev_net_set(dev, net);
|
||
|
|
||
|
- /* If there is an ifindex conflict assign a new one */
|
||
|
- if (__dev_get_by_index(net, dev->ifindex)) {
|
||
|
+ /* Assign a new ifindex */
|
||
|
+ {
|
||
|
int iflink = (dev->iflink == dev->ifindex);
|
||
|
dev->ifindex = dev_new_index(net);
|
||
|
if (iflink)
|
||
|
--
|
||
|
1.7.10.4
|
||
|
|