Commit aa79e66e authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller

net: Make ifindex generation per-net namespace

Strictly speaking this is only _really_ required for checkpoint-restore to
make loopback device always have the same index.

This change appears to be safe wrt "ifindex should be unique per-system"
concept, as all the ifindex usage is either already made per net namespace
of is explicitly limited with init_net only.

There are two cool side effects of this. The first one -- ifindices of
devices in container are always small, regardless of how many containers
we've started (and re-started) so far. The second one is -- we can speed
up the loopback ifidex access as shown in the next patch.

v2: Place ifindex right after dev_base_seq : avoid two holes and use the
    same cache line, dirtied in list_netdevice()/unlist_netdevice()
Signed-off-by: default avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e6f8f1a7
...@@ -66,6 +66,7 @@ struct net { ...@@ -66,6 +66,7 @@ struct net {
struct hlist_head *dev_name_head; struct hlist_head *dev_name_head;
struct hlist_head *dev_index_head; struct hlist_head *dev_index_head;
unsigned int dev_base_seq; /* protected by rtnl_mutex */ unsigned int dev_base_seq; /* protected by rtnl_mutex */
int ifindex;
/* core fib_rules */ /* core fib_rules */
struct list_head rules_ops; struct list_head rules_ops;
......
...@@ -5221,12 +5221,12 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg) ...@@ -5221,12 +5221,12 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
*/ */
static int dev_new_index(struct net *net) static int dev_new_index(struct net *net)
{ {
static int ifindex; int ifindex = net->ifindex;
for (;;) { for (;;) {
if (++ifindex <= 0) if (++ifindex <= 0)
ifindex = 1; ifindex = 1;
if (!__dev_get_by_index(net, ifindex)) if (!__dev_get_by_index(net, ifindex))
return ifindex; return net->ifindex = ifindex;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment