Skip to content

Commit aa79e66

Browse files
xemuldavem330
authored andcommitted
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: Pavel Emelyanov <xemul@parallels.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e6f8f1a commit aa79e66

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct net {
6666
struct hlist_head *dev_name_head;
6767
struct hlist_head *dev_index_head;
6868
unsigned int dev_base_seq; /* protected by rtnl_mutex */
69+
int ifindex;
6970

7071
/* core fib_rules */
7172
struct list_head rules_ops;

‎net/core/dev.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5221,12 +5221,12 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
52215221
*/
52225222
static int dev_new_index(struct net *net)
52235223
{
5224-
static int ifindex;
5224+
int ifindex = net->ifindex;
52255225
for (;;) {
52265226
if (++ifindex <= 0)
52275227
ifindex = 1;
52285228
if (!__dev_get_by_index(net, ifindex))
5229-
return ifindex;
5229+
return net->ifindex = ifindex;
52305230
}
52315231
}
52325232

0 commit comments

Comments
 (0)