Skip to content

Commit 881d966

Browse files
ebiedermDavid S. Miller
authored andcommitted
[NET]: Make the device list and device lookups per namespace.
This patch makes most of the generic device layer network namespace safe. This patch makes dev_base_head a network namespace variable, and then it picks up a few associated variables. The functions: dev_getbyhwaddr dev_getfirsthwbytype dev_get_by_flags dev_get_by_name __dev_get_by_name dev_get_by_index __dev_get_by_index dev_ioctl dev_ethtool dev_load wireless_process_ioctl were modified to take a network namespace argument, and deal with it. vlan_ioctl_set and brioctl_set were modified so their hooks will receive a network namespace argument. So basically anthing in the core of the network stack that was affected to by the change of dev_base was modified to handle multiple network namespaces. The rest of the network stack was simply modified to explicitly use &init_net the initial network namespace. This can be fixed when those components of the network stack are modified to handle multiple network namespaces. For now the ifindex generator is left global. Fundametally ifindex numbers are per namespace, or else we will have corner case problems with migration when we get that far. At the same time there are assumptions in the network stack that the ifindex of a network device won't change. Making the ifindex number global seems a good compromise until the network stack can cope with ifindex changes when you change namespaces, and the like. Signed-off-by: Eric W. Biederman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b4b5102 commit 881d966

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+555
-362
lines changed

arch/s390/appldata/appldata_net_sum.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/errno.h>
1717
#include <linux/kernel_stat.h>
1818
#include <linux/netdevice.h>
19+
#include <net/net_namespace.h>
1920

2021
#include "appldata.h"
2122

@@ -107,7 +108,7 @@ static void appldata_get_net_sum_data(void *data)
107108
tx_dropped = 0;
108109
collisions = 0;
109110
read_lock(&dev_base_lock);
110-
for_each_netdev(dev) {
111+
for_each_netdev(&init_net, dev) {
111112
stats = dev->get_stats(dev);
112113
rx_packets += stats->rx_packets;
113114
tx_packets += stats->tx_packets;

arch/sparc64/solaris/ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/compat.h>
2929

3030
#include <net/sock.h>
31+
#include <net/net_namespace.h>
3132

3233
#include <asm/uaccess.h>
3334
#include <asm/termios.h>
@@ -686,7 +687,7 @@ static inline int solaris_i(unsigned int fd, unsigned int cmd, u32 arg)
686687
int i = 0;
687688

688689
read_lock_bh(&dev_base_lock);
689-
for_each_netdev(d)
690+
for_each_netdev(&init_net, d)
690691
i++;
691692
read_unlock_bh(&dev_base_lock);
692693

drivers/atm/idt77252.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3576,7 +3576,7 @@ init_card(struct atm_dev *dev)
35763576
* XXX: <hack>
35773577
*/
35783578
sprintf(tname, "eth%d", card->index);
3579-
tmp = dev_get_by_name(tname); /* jhs: was "tmp = dev_get(tname);" */
3579+
tmp = dev_get_by_name(&init_net, tname); /* jhs: was "tmp = dev_get(tname);" */
35803580
if (tmp) {
35813581
memcpy(card->atmdev->esi, tmp->dev_addr, 6);
35823582

drivers/block/aoe/aoecmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/skbuff.h>
1010
#include <linux/netdevice.h>
1111
#include <linux/genhd.h>
12+
#include <net/net_namespace.h>
1213
#include <asm/unaligned.h>
1314
#include "aoe.h"
1415

@@ -194,7 +195,7 @@ aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
194195
sl = sl_tail = NULL;
195196

196197
read_lock(&dev_base_lock);
197-
for_each_netdev(ifp) {
198+
for_each_netdev(&init_net, ifp) {
198199
dev_hold(ifp);
199200
if (!is_aoe_netif(ifp))
200201
goto cont;

drivers/infiniband/hw/cxgb3/cxio_hal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/spinlock.h>
3838
#include <linux/pci.h>
3939
#include <linux/dma-mapping.h>
40+
#include <net/net_namespace.h>
4041

4142
#include "cxio_resource.h"
4243
#include "cxio_hal.h"
@@ -894,7 +895,7 @@ int cxio_rdev_open(struct cxio_rdev *rdev_p)
894895
if (cxio_hal_find_rdev_by_name(rdev_p->dev_name)) {
895896
return -EBUSY;
896897
}
897-
netdev_p = dev_get_by_name(rdev_p->dev_name);
898+
netdev_p = dev_get_by_name(&init_net, rdev_p->dev_name);
898899
if (!netdev_p) {
899900
return -EINVAL;
900901
}

drivers/net/bonding/bond_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3719,7 +3719,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
37193719
}
37203720

37213721
down_write(&(bonding_rwsem));
3722-
slave_dev = dev_get_by_name(ifr->ifr_slave);
3722+
slave_dev = dev_get_by_name(&init_net, ifr->ifr_slave);
37233723

37243724
dprintk("slave_dev=%p: \n", slave_dev);
37253725

drivers/net/bonding/bond_sysfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/ctype.h>
3636
#include <linux/inet.h>
3737
#include <linux/rtnetlink.h>
38+
#include <net/net_namespace.h>
3839

3940
/* #define BONDING_DEBUG 1 */
4041
#include "bonding.h"
@@ -299,7 +300,7 @@ static ssize_t bonding_store_slaves(struct device *d,
299300
read_unlock_bh(&bond->lock);
300301
printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
301302
bond->dev->name, ifname);
302-
dev = dev_get_by_name(ifname);
303+
dev = dev_get_by_name(&init_net, ifname);
303304
if (!dev) {
304305
printk(KERN_INFO DRV_NAME
305306
": %s: Interface %s does not exist!\n",

drivers/net/eql.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#include <linux/init.h>
117117
#include <linux/timer.h>
118118
#include <linux/netdevice.h>
119+
#include <net/net_namespace.h>
119120

120121
#include <linux/if.h>
121122
#include <linux/if_arp.h>
@@ -412,7 +413,7 @@ static int eql_enslave(struct net_device *master_dev, slaving_request_t __user *
412413
if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
413414
return -EFAULT;
414415

415-
slave_dev = dev_get_by_name(srq.slave_name);
416+
slave_dev = dev_get_by_name(&init_net, srq.slave_name);
416417
if (slave_dev) {
417418
if ((master_dev->flags & IFF_UP) == IFF_UP) {
418419
/* slave is not a master & not already a slave: */
@@ -460,7 +461,7 @@ static int eql_emancipate(struct net_device *master_dev, slaving_request_t __use
460461
if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
461462
return -EFAULT;
462463

463-
slave_dev = dev_get_by_name(srq.slave_name);
464+
slave_dev = dev_get_by_name(&init_net, srq.slave_name);
464465
ret = -EINVAL;
465466
if (slave_dev) {
466467
spin_lock_bh(&eql->queue.lock);
@@ -493,7 +494,7 @@ static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
493494
if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
494495
return -EFAULT;
495496

496-
slave_dev = dev_get_by_name(sc.slave_name);
497+
slave_dev = dev_get_by_name(&init_net, sc.slave_name);
497498
if (!slave_dev)
498499
return -ENODEV;
499500

@@ -528,7 +529,7 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
528529
if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
529530
return -EFAULT;
530531

531-
slave_dev = dev_get_by_name(sc.slave_name);
532+
slave_dev = dev_get_by_name(&init_net, sc.slave_name);
532533
if (!slave_dev)
533534
return -ENODEV;
534535

drivers/net/ifb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/init.h>
3535
#include <linux/moduleparam.h>
3636
#include <net/pkt_sched.h>
37+
#include <net/net_namespace.h>
3738

3839
#define TX_TIMEOUT (2*HZ)
3940

@@ -97,7 +98,7 @@ static void ri_tasklet(unsigned long dev)
9798
stats->tx_packets++;
9899
stats->tx_bytes +=skb->len;
99100

100-
skb->dev = __dev_get_by_index(skb->iif);
101+
skb->dev = __dev_get_by_index(&init_net, skb->iif);
101102
if (!skb->dev) {
102103
dev_kfree_skb(skb);
103104
stats->tx_dropped++;

drivers/net/macvlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static int macvlan_newlink(struct net_device *dev,
376376
if (!tb[IFLA_LINK])
377377
return -EINVAL;
378378

379-
lowerdev = __dev_get_by_index(nla_get_u32(tb[IFLA_LINK]));
379+
lowerdev = __dev_get_by_index(dev->nd_net, nla_get_u32(tb[IFLA_LINK]));
380380
if (lowerdev == NULL)
381381
return -ENODEV;
382382

0 commit comments

Comments
 (0)