diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2007-09-17 14:56:21 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:49:10 -0400 |
commit | 881d966b48b035ab3f3aeaae0f3d3f9b584f45b2 (patch) | |
tree | c579d59a4107cbbe9e2b85939bc0d496b815c887 /drivers/net | |
parent | b4b510290b056b86611757ce1175a230f1080f53 (diff) |
[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 <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/bonding/bond_main.c | 2 | ||||
-rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 3 | ||||
-rw-r--r-- | drivers/net/eql.c | 9 | ||||
-rw-r--r-- | drivers/net/ifb.c | 3 | ||||
-rw-r--r-- | drivers/net/macvlan.c | 2 | ||||
-rw-r--r-- | drivers/net/pppoe.c | 4 | ||||
-rw-r--r-- | drivers/net/shaper.c | 3 | ||||
-rw-r--r-- | drivers/net/tun.c | 3 | ||||
-rw-r--r-- | drivers/net/veth.c | 2 | ||||
-rw-r--r-- | drivers/net/wan/dlci.c | 4 | ||||
-rw-r--r-- | drivers/net/wan/sbni.c | 3 | ||||
-rw-r--r-- | drivers/net/wireless/strip.c | 2 |
12 files changed, 23 insertions, 17 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index cf97d8a6326e..559fe9437e0b 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -3719,7 +3719,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd | |||
3719 | } | 3719 | } |
3720 | 3720 | ||
3721 | down_write(&(bonding_rwsem)); | 3721 | 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); |
3723 | 3723 | ||
3724 | dprintk("slave_dev=%p: \n", slave_dev); | 3724 | dprintk("slave_dev=%p: \n", slave_dev); |
3725 | 3725 | ||
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index 60cccf2aa959..8289e27a360a 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/ctype.h> | 35 | #include <linux/ctype.h> |
36 | #include <linux/inet.h> | 36 | #include <linux/inet.h> |
37 | #include <linux/rtnetlink.h> | 37 | #include <linux/rtnetlink.h> |
38 | #include <net/net_namespace.h> | ||
38 | 39 | ||
39 | /* #define BONDING_DEBUG 1 */ | 40 | /* #define BONDING_DEBUG 1 */ |
40 | #include "bonding.h" | 41 | #include "bonding.h" |
@@ -299,7 +300,7 @@ static ssize_t bonding_store_slaves(struct device *d, | |||
299 | read_unlock_bh(&bond->lock); | 300 | read_unlock_bh(&bond->lock); |
300 | printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n", | 301 | printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n", |
301 | bond->dev->name, ifname); | 302 | bond->dev->name, ifname); |
302 | dev = dev_get_by_name(ifname); | 303 | dev = dev_get_by_name(&init_net, ifname); |
303 | if (!dev) { | 304 | if (!dev) { |
304 | printk(KERN_INFO DRV_NAME | 305 | printk(KERN_INFO DRV_NAME |
305 | ": %s: Interface %s does not exist!\n", | 306 | ": %s: Interface %s does not exist!\n", |
diff --git a/drivers/net/eql.c b/drivers/net/eql.c index 102218c4a907..f1cc66dcbdfd 100644 --- a/drivers/net/eql.c +++ b/drivers/net/eql.c | |||
@@ -116,6 +116,7 @@ | |||
116 | #include <linux/init.h> | 116 | #include <linux/init.h> |
117 | #include <linux/timer.h> | 117 | #include <linux/timer.h> |
118 | #include <linux/netdevice.h> | 118 | #include <linux/netdevice.h> |
119 | #include <net/net_namespace.h> | ||
119 | 120 | ||
120 | #include <linux/if.h> | 121 | #include <linux/if.h> |
121 | #include <linux/if_arp.h> | 122 | #include <linux/if_arp.h> |
@@ -412,7 +413,7 @@ static int eql_enslave(struct net_device *master_dev, slaving_request_t __user * | |||
412 | if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) | 413 | if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) |
413 | return -EFAULT; | 414 | return -EFAULT; |
414 | 415 | ||
415 | slave_dev = dev_get_by_name(srq.slave_name); | 416 | slave_dev = dev_get_by_name(&init_net, srq.slave_name); |
416 | if (slave_dev) { | 417 | if (slave_dev) { |
417 | if ((master_dev->flags & IFF_UP) == IFF_UP) { | 418 | if ((master_dev->flags & IFF_UP) == IFF_UP) { |
418 | /* slave is not a master & not already a slave: */ | 419 | /* 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 | |||
460 | if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) | 461 | if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) |
461 | return -EFAULT; | 462 | return -EFAULT; |
462 | 463 | ||
463 | slave_dev = dev_get_by_name(srq.slave_name); | 464 | slave_dev = dev_get_by_name(&init_net, srq.slave_name); |
464 | ret = -EINVAL; | 465 | ret = -EINVAL; |
465 | if (slave_dev) { | 466 | if (slave_dev) { |
466 | spin_lock_bh(&eql->queue.lock); | 467 | 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) | |||
493 | if (copy_from_user(&sc, scp, sizeof (slave_config_t))) | 494 | if (copy_from_user(&sc, scp, sizeof (slave_config_t))) |
494 | return -EFAULT; | 495 | return -EFAULT; |
495 | 496 | ||
496 | slave_dev = dev_get_by_name(sc.slave_name); | 497 | slave_dev = dev_get_by_name(&init_net, sc.slave_name); |
497 | if (!slave_dev) | 498 | if (!slave_dev) |
498 | return -ENODEV; | 499 | return -ENODEV; |
499 | 500 | ||
@@ -528,7 +529,7 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp) | |||
528 | if (copy_from_user(&sc, scp, sizeof (slave_config_t))) | 529 | if (copy_from_user(&sc, scp, sizeof (slave_config_t))) |
529 | return -EFAULT; | 530 | return -EFAULT; |
530 | 531 | ||
531 | slave_dev = dev_get_by_name(sc.slave_name); | 532 | slave_dev = dev_get_by_name(&init_net, sc.slave_name); |
532 | if (!slave_dev) | 533 | if (!slave_dev) |
533 | return -ENODEV; | 534 | return -ENODEV; |
534 | 535 | ||
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c index f5c3598e59af..b06c6db4383a 100644 --- a/drivers/net/ifb.c +++ b/drivers/net/ifb.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/moduleparam.h> | 35 | #include <linux/moduleparam.h> |
36 | #include <net/pkt_sched.h> | 36 | #include <net/pkt_sched.h> |
37 | #include <net/net_namespace.h> | ||
37 | 38 | ||
38 | #define TX_TIMEOUT (2*HZ) | 39 | #define TX_TIMEOUT (2*HZ) |
39 | 40 | ||
@@ -97,7 +98,7 @@ static void ri_tasklet(unsigned long dev) | |||
97 | stats->tx_packets++; | 98 | stats->tx_packets++; |
98 | stats->tx_bytes +=skb->len; | 99 | stats->tx_bytes +=skb->len; |
99 | 100 | ||
100 | skb->dev = __dev_get_by_index(skb->iif); | 101 | skb->dev = __dev_get_by_index(&init_net, skb->iif); |
101 | if (!skb->dev) { | 102 | if (!skb->dev) { |
102 | dev_kfree_skb(skb); | 103 | dev_kfree_skb(skb); |
103 | stats->tx_dropped++; | 104 | stats->tx_dropped++; |
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index dc74d006e01f..2de073da182c 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c | |||
@@ -376,7 +376,7 @@ static int macvlan_newlink(struct net_device *dev, | |||
376 | if (!tb[IFLA_LINK]) | 376 | if (!tb[IFLA_LINK]) |
377 | return -EINVAL; | 377 | return -EINVAL; |
378 | 378 | ||
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])); |
380 | if (lowerdev == NULL) | 380 | if (lowerdev == NULL) |
381 | return -ENODEV; | 381 | return -ENODEV; |
382 | 382 | ||
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c index c5c70e4b1d36..2f130e06b6dc 100644 --- a/drivers/net/pppoe.c +++ b/drivers/net/pppoe.c | |||
@@ -216,7 +216,7 @@ static inline struct pppox_sock *get_item_by_addr(struct sockaddr_pppox *sp) | |||
216 | struct net_device *dev; | 216 | struct net_device *dev; |
217 | int ifindex; | 217 | int ifindex; |
218 | 218 | ||
219 | dev = dev_get_by_name(sp->sa_addr.pppoe.dev); | 219 | dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev); |
220 | if(!dev) | 220 | if(!dev) |
221 | return NULL; | 221 | return NULL; |
222 | ifindex = dev->ifindex; | 222 | ifindex = dev->ifindex; |
@@ -603,7 +603,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr, | |||
603 | 603 | ||
604 | /* Don't re-bind if sid==0 */ | 604 | /* Don't re-bind if sid==0 */ |
605 | if (sp->sa_addr.pppoe.sid != 0) { | 605 | if (sp->sa_addr.pppoe.sid != 0) { |
606 | dev = dev_get_by_name(sp->sa_addr.pppoe.dev); | 606 | dev = dev_get_by_name(&init_net, sp->sa_addr.pppoe.dev); |
607 | 607 | ||
608 | error = -ENODEV; | 608 | error = -ENODEV; |
609 | if (!dev) | 609 | if (!dev) |
diff --git a/drivers/net/shaper.c b/drivers/net/shaper.c index 4c3d98ff4cd4..3773b3858bd4 100644 --- a/drivers/net/shaper.c +++ b/drivers/net/shaper.c | |||
@@ -86,6 +86,7 @@ | |||
86 | 86 | ||
87 | #include <net/dst.h> | 87 | #include <net/dst.h> |
88 | #include <net/arp.h> | 88 | #include <net/arp.h> |
89 | #include <net/net_namespace.h> | ||
89 | 90 | ||
90 | struct shaper_cb { | 91 | struct shaper_cb { |
91 | unsigned long shapeclock; /* Time it should go out */ | 92 | unsigned long shapeclock; /* Time it should go out */ |
@@ -488,7 +489,7 @@ static int shaper_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |||
488 | { | 489 | { |
489 | case SHAPER_SET_DEV: | 490 | case SHAPER_SET_DEV: |
490 | { | 491 | { |
491 | struct net_device *them=__dev_get_by_name(ss->ss_name); | 492 | struct net_device *them=__dev_get_by_name(&init_net, ss->ss_name); |
492 | if(them==NULL) | 493 | if(them==NULL) |
493 | return -ENODEV; | 494 | return -ENODEV; |
494 | if(sh->dev) | 495 | if(sh->dev) |
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 62b2b3005019..691d264fbb6f 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #include <linux/if_ether.h> | 62 | #include <linux/if_ether.h> |
63 | #include <linux/if_tun.h> | 63 | #include <linux/if_tun.h> |
64 | #include <linux/crc32.h> | 64 | #include <linux/crc32.h> |
65 | #include <net/net_namespace.h> | ||
65 | 66 | ||
66 | #include <asm/system.h> | 67 | #include <asm/system.h> |
67 | #include <asm/uaccess.h> | 68 | #include <asm/uaccess.h> |
@@ -475,7 +476,7 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr) | |||
475 | !capable(CAP_NET_ADMIN)) | 476 | !capable(CAP_NET_ADMIN)) |
476 | return -EPERM; | 477 | return -EPERM; |
477 | } | 478 | } |
478 | else if (__dev_get_by_name(ifr->ifr_name)) | 479 | else if (__dev_get_by_name(&init_net, ifr->ifr_name)) |
479 | return -EINVAL; | 480 | return -EINVAL; |
480 | else { | 481 | else { |
481 | char *name; | 482 | char *name; |
diff --git a/drivers/net/veth.c b/drivers/net/veth.c index ca1c6893b809..2c86a4459d8a 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c | |||
@@ -345,7 +345,7 @@ static int veth_newlink(struct net_device *dev, | |||
345 | else | 345 | else |
346 | snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d"); | 346 | snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d"); |
347 | 347 | ||
348 | peer = rtnl_create_link(ifname, &veth_link_ops, tbp); | 348 | peer = rtnl_create_link(dev->nd_net, ifname, &veth_link_ops, tbp); |
349 | if (IS_ERR(peer)) | 349 | if (IS_ERR(peer)) |
350 | return PTR_ERR(peer); | 350 | return PTR_ERR(peer); |
351 | 351 | ||
diff --git a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c index 61041d5186ac..bc12810157e0 100644 --- a/drivers/net/wan/dlci.c +++ b/drivers/net/wan/dlci.c | |||
@@ -361,7 +361,7 @@ static int dlci_add(struct dlci_add *dlci) | |||
361 | 361 | ||
362 | 362 | ||
363 | /* validate slave device */ | 363 | /* validate slave device */ |
364 | slave = dev_get_by_name(dlci->devname); | 364 | slave = dev_get_by_name(&init_net, dlci->devname); |
365 | if (!slave) | 365 | if (!slave) |
366 | return -ENODEV; | 366 | return -ENODEV; |
367 | 367 | ||
@@ -427,7 +427,7 @@ static int dlci_del(struct dlci_add *dlci) | |||
427 | int err; | 427 | int err; |
428 | 428 | ||
429 | /* validate slave device */ | 429 | /* validate slave device */ |
430 | master = __dev_get_by_name(dlci->devname); | 430 | master = __dev_get_by_name(&init_net, dlci->devname); |
431 | if (!master) | 431 | if (!master) |
432 | return(-ENODEV); | 432 | return(-ENODEV); |
433 | 433 | ||
diff --git a/drivers/net/wan/sbni.c b/drivers/net/wan/sbni.c index 1cc18e787a65..8d7e01e8f56f 100644 --- a/drivers/net/wan/sbni.c +++ b/drivers/net/wan/sbni.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include <linux/init.h> | 54 | #include <linux/init.h> |
55 | #include <linux/delay.h> | 55 | #include <linux/delay.h> |
56 | 56 | ||
57 | #include <net/net_namespace.h> | ||
57 | #include <net/arp.h> | 58 | #include <net/arp.h> |
58 | 59 | ||
59 | #include <asm/io.h> | 60 | #include <asm/io.h> |
@@ -1361,7 +1362,7 @@ sbni_ioctl( struct net_device *dev, struct ifreq *ifr, int cmd ) | |||
1361 | 1362 | ||
1362 | if (copy_from_user( slave_name, ifr->ifr_data, sizeof slave_name )) | 1363 | if (copy_from_user( slave_name, ifr->ifr_data, sizeof slave_name )) |
1363 | return -EFAULT; | 1364 | return -EFAULT; |
1364 | slave_dev = dev_get_by_name( slave_name ); | 1365 | slave_dev = dev_get_by_name(&init_net, slave_name ); |
1365 | if( !slave_dev || !(slave_dev->flags & IFF_UP) ) { | 1366 | if( !slave_dev || !(slave_dev->flags & IFF_UP) ) { |
1366 | printk( KERN_ERR "%s: trying to enslave non-active " | 1367 | printk( KERN_ERR "%s: trying to enslave non-active " |
1367 | "device %s\n", dev->name, slave_name ); | 1368 | "device %s\n", dev->name, slave_name ); |
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c index edb214e8c744..904e548e6795 100644 --- a/drivers/net/wireless/strip.c +++ b/drivers/net/wireless/strip.c | |||
@@ -1972,7 +1972,7 @@ static struct net_device *get_strip_dev(struct strip *strip_info) | |||
1972 | sizeof(zero_address))) { | 1972 | sizeof(zero_address))) { |
1973 | struct net_device *dev; | 1973 | struct net_device *dev; |
1974 | read_lock_bh(&dev_base_lock); | 1974 | read_lock_bh(&dev_base_lock); |
1975 | for_each_netdev(dev) { | 1975 | for_each_netdev(&init_net, dev) { |
1976 | if (dev->type == strip_info->dev->type && | 1976 | if (dev->type == strip_info->dev->type && |
1977 | !memcmp(dev->dev_addr, | 1977 | !memcmp(dev->dev_addr, |
1978 | &strip_info->true_dev_addr, | 1978 | &strip_info->true_dev_addr, |