aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
Diffstat (limited to 'net/core')
-rw-r--r--net/core/dev.c271
-rw-r--r--net/core/dev_mcast.c41
-rw-r--r--net/core/ethtool.c4
-rw-r--r--net/core/fib_rules.c4
-rw-r--r--net/core/neighbour.c6
-rw-r--r--net/core/netpoll.c2
-rw-r--r--net/core/pktgen.c2
-rw-r--r--net/core/rtnetlink.c35
-rw-r--r--net/core/sock.c3
9 files changed, 250 insertions, 118 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 40fd66fbe4e1..3a3d5ee73909 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -190,25 +190,22 @@ static struct net_dma net_dma = {
190 * unregister_netdevice(), which must be called with the rtnl 190 * unregister_netdevice(), which must be called with the rtnl
191 * semaphore held. 191 * semaphore held.
192 */ 192 */
193LIST_HEAD(dev_base_head);
194DEFINE_RWLOCK(dev_base_lock); 193DEFINE_RWLOCK(dev_base_lock);
195 194
196EXPORT_SYMBOL(dev_base_head);
197EXPORT_SYMBOL(dev_base_lock); 195EXPORT_SYMBOL(dev_base_lock);
198 196
199#define NETDEV_HASHBITS 8 197#define NETDEV_HASHBITS 8
200static struct hlist_head dev_name_head[1<<NETDEV_HASHBITS]; 198#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
201static struct hlist_head dev_index_head[1<<NETDEV_HASHBITS];
202 199
203static inline struct hlist_head *dev_name_hash(const char *name) 200static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
204{ 201{
205 unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ)); 202 unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
206 return &dev_name_head[hash & ((1<<NETDEV_HASHBITS)-1)]; 203 return &net->dev_name_head[hash & ((1 << NETDEV_HASHBITS) - 1)];
207} 204}
208 205
209static inline struct hlist_head *dev_index_hash(int ifindex) 206static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex)
210{ 207{
211 return &dev_index_head[ifindex & ((1<<NETDEV_HASHBITS)-1)]; 208 return &net->dev_index_head[ifindex & ((1 << NETDEV_HASHBITS) - 1)];
212} 209}
213 210
214/* 211/*
@@ -492,7 +489,7 @@ unsigned long netdev_boot_base(const char *prefix, int unit)
492 * If device already registered then return base of 1 489 * If device already registered then return base of 1
493 * to indicate not to probe for this interface 490 * to indicate not to probe for this interface
494 */ 491 */
495 if (__dev_get_by_name(name)) 492 if (__dev_get_by_name(&init_net, name))
496 return 1; 493 return 1;
497 494
498 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) 495 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
@@ -547,11 +544,11 @@ __setup("netdev=", netdev_boot_setup);
547 * careful with locks. 544 * careful with locks.
548 */ 545 */
549 546
550struct net_device *__dev_get_by_name(const char *name) 547struct net_device *__dev_get_by_name(struct net *net, const char *name)
551{ 548{
552 struct hlist_node *p; 549 struct hlist_node *p;
553 550
554 hlist_for_each(p, dev_name_hash(name)) { 551 hlist_for_each(p, dev_name_hash(net, name)) {
555 struct net_device *dev 552 struct net_device *dev
556 = hlist_entry(p, struct net_device, name_hlist); 553 = hlist_entry(p, struct net_device, name_hlist);
557 if (!strncmp(dev->name, name, IFNAMSIZ)) 554 if (!strncmp(dev->name, name, IFNAMSIZ))
@@ -571,12 +568,12 @@ struct net_device *__dev_get_by_name(const char *name)
571 * matching device is found. 568 * matching device is found.
572 */ 569 */
573 570
574struct net_device *dev_get_by_name(const char *name) 571struct net_device *dev_get_by_name(struct net *net, const char *name)
575{ 572{
576 struct net_device *dev; 573 struct net_device *dev;
577 574
578 read_lock(&dev_base_lock); 575 read_lock(&dev_base_lock);
579 dev = __dev_get_by_name(name); 576 dev = __dev_get_by_name(net, name);
580 if (dev) 577 if (dev)
581 dev_hold(dev); 578 dev_hold(dev);
582 read_unlock(&dev_base_lock); 579 read_unlock(&dev_base_lock);
@@ -594,11 +591,11 @@ struct net_device *dev_get_by_name(const char *name)
594 * or @dev_base_lock. 591 * or @dev_base_lock.
595 */ 592 */
596 593
597struct net_device *__dev_get_by_index(int ifindex) 594struct net_device *__dev_get_by_index(struct net *net, int ifindex)
598{ 595{
599 struct hlist_node *p; 596 struct hlist_node *p;
600 597
601 hlist_for_each(p, dev_index_hash(ifindex)) { 598 hlist_for_each(p, dev_index_hash(net, ifindex)) {
602 struct net_device *dev 599 struct net_device *dev
603 = hlist_entry(p, struct net_device, index_hlist); 600 = hlist_entry(p, struct net_device, index_hlist);
604 if (dev->ifindex == ifindex) 601 if (dev->ifindex == ifindex)
@@ -618,12 +615,12 @@ struct net_device *__dev_get_by_index(int ifindex)
618 * dev_put to indicate they have finished with it. 615 * dev_put to indicate they have finished with it.
619 */ 616 */
620 617
621struct net_device *dev_get_by_index(int ifindex) 618struct net_device *dev_get_by_index(struct net *net, int ifindex)
622{ 619{
623 struct net_device *dev; 620 struct net_device *dev;
624 621
625 read_lock(&dev_base_lock); 622 read_lock(&dev_base_lock);
626 dev = __dev_get_by_index(ifindex); 623 dev = __dev_get_by_index(net, ifindex);
627 if (dev) 624 if (dev)
628 dev_hold(dev); 625 dev_hold(dev);
629 read_unlock(&dev_base_lock); 626 read_unlock(&dev_base_lock);
@@ -644,13 +641,13 @@ struct net_device *dev_get_by_index(int ifindex)
644 * If the API was consistent this would be __dev_get_by_hwaddr 641 * If the API was consistent this would be __dev_get_by_hwaddr
645 */ 642 */
646 643
647struct net_device *dev_getbyhwaddr(unsigned short type, char *ha) 644struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha)
648{ 645{
649 struct net_device *dev; 646 struct net_device *dev;
650 647
651 ASSERT_RTNL(); 648 ASSERT_RTNL();
652 649
653 for_each_netdev(dev) 650 for_each_netdev(&init_net, dev)
654 if (dev->type == type && 651 if (dev->type == type &&
655 !memcmp(dev->dev_addr, ha, dev->addr_len)) 652 !memcmp(dev->dev_addr, ha, dev->addr_len))
656 return dev; 653 return dev;
@@ -660,12 +657,12 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
660 657
661EXPORT_SYMBOL(dev_getbyhwaddr); 658EXPORT_SYMBOL(dev_getbyhwaddr);
662 659
663struct net_device *__dev_getfirstbyhwtype(unsigned short type) 660struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
664{ 661{
665 struct net_device *dev; 662 struct net_device *dev;
666 663
667 ASSERT_RTNL(); 664 ASSERT_RTNL();
668 for_each_netdev(dev) 665 for_each_netdev(net, dev)
669 if (dev->type == type) 666 if (dev->type == type)
670 return dev; 667 return dev;
671 668
@@ -674,12 +671,12 @@ struct net_device *__dev_getfirstbyhwtype(unsigned short type)
674 671
675EXPORT_SYMBOL(__dev_getfirstbyhwtype); 672EXPORT_SYMBOL(__dev_getfirstbyhwtype);
676 673
677struct net_device *dev_getfirstbyhwtype(unsigned short type) 674struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
678{ 675{
679 struct net_device *dev; 676 struct net_device *dev;
680 677
681 rtnl_lock(); 678 rtnl_lock();
682 dev = __dev_getfirstbyhwtype(type); 679 dev = __dev_getfirstbyhwtype(net, type);
683 if (dev) 680 if (dev)
684 dev_hold(dev); 681 dev_hold(dev);
685 rtnl_unlock(); 682 rtnl_unlock();
@@ -699,13 +696,13 @@ EXPORT_SYMBOL(dev_getfirstbyhwtype);
699 * dev_put to indicate they have finished with it. 696 * dev_put to indicate they have finished with it.
700 */ 697 */
701 698
702struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask) 699struct net_device * dev_get_by_flags(struct net *net, unsigned short if_flags, unsigned short mask)
703{ 700{
704 struct net_device *dev, *ret; 701 struct net_device *dev, *ret;
705 702
706 ret = NULL; 703 ret = NULL;
707 read_lock(&dev_base_lock); 704 read_lock(&dev_base_lock);
708 for_each_netdev(dev) { 705 for_each_netdev(net, dev) {
709 if (((dev->flags ^ if_flags) & mask) == 0) { 706 if (((dev->flags ^ if_flags) & mask) == 0) {
710 dev_hold(dev); 707 dev_hold(dev);
711 ret = dev; 708 ret = dev;
@@ -763,6 +760,10 @@ int dev_alloc_name(struct net_device *dev, const char *name)
763 const int max_netdevices = 8*PAGE_SIZE; 760 const int max_netdevices = 8*PAGE_SIZE;
764 long *inuse; 761 long *inuse;
765 struct net_device *d; 762 struct net_device *d;
763 struct net *net;
764
765 BUG_ON(!dev->nd_net);
766 net = dev->nd_net;
766 767
767 p = strnchr(name, IFNAMSIZ-1, '%'); 768 p = strnchr(name, IFNAMSIZ-1, '%');
768 if (p) { 769 if (p) {
@@ -779,7 +780,7 @@ int dev_alloc_name(struct net_device *dev, const char *name)
779 if (!inuse) 780 if (!inuse)
780 return -ENOMEM; 781 return -ENOMEM;
781 782
782 for_each_netdev(d) { 783 for_each_netdev(net, d) {
783 if (!sscanf(d->name, name, &i)) 784 if (!sscanf(d->name, name, &i))
784 continue; 785 continue;
785 if (i < 0 || i >= max_netdevices) 786 if (i < 0 || i >= max_netdevices)
@@ -796,7 +797,7 @@ int dev_alloc_name(struct net_device *dev, const char *name)
796 } 797 }
797 798
798 snprintf(buf, sizeof(buf), name, i); 799 snprintf(buf, sizeof(buf), name, i);
799 if (!__dev_get_by_name(buf)) { 800 if (!__dev_get_by_name(net, buf)) {
800 strlcpy(dev->name, buf, IFNAMSIZ); 801 strlcpy(dev->name, buf, IFNAMSIZ);
801 return i; 802 return i;
802 } 803 }
@@ -822,9 +823,12 @@ int dev_change_name(struct net_device *dev, char *newname)
822 char oldname[IFNAMSIZ]; 823 char oldname[IFNAMSIZ];
823 int err = 0; 824 int err = 0;
824 int ret; 825 int ret;
826 struct net *net;
825 827
826 ASSERT_RTNL(); 828 ASSERT_RTNL();
829 BUG_ON(!dev->nd_net);
827 830
831 net = dev->nd_net;
828 if (dev->flags & IFF_UP) 832 if (dev->flags & IFF_UP)
829 return -EBUSY; 833 return -EBUSY;
830 834
@@ -839,7 +843,7 @@ int dev_change_name(struct net_device *dev, char *newname)
839 return err; 843 return err;
840 strcpy(newname, dev->name); 844 strcpy(newname, dev->name);
841 } 845 }
842 else if (__dev_get_by_name(newname)) 846 else if (__dev_get_by_name(net, newname))
843 return -EEXIST; 847 return -EEXIST;
844 else 848 else
845 strlcpy(dev->name, newname, IFNAMSIZ); 849 strlcpy(dev->name, newname, IFNAMSIZ);
@@ -849,7 +853,7 @@ rollback:
849 853
850 write_lock_bh(&dev_base_lock); 854 write_lock_bh(&dev_base_lock);
851 hlist_del(&dev->name_hlist); 855 hlist_del(&dev->name_hlist);
852 hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name)); 856 hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
853 write_unlock_bh(&dev_base_lock); 857 write_unlock_bh(&dev_base_lock);
854 858
855 ret = raw_notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev); 859 ret = raw_notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
@@ -908,12 +912,12 @@ void netdev_state_change(struct net_device *dev)
908 * available in this kernel then it becomes a nop. 912 * available in this kernel then it becomes a nop.
909 */ 913 */
910 914
911void dev_load(const char *name) 915void dev_load(struct net *net, const char *name)
912{ 916{
913 struct net_device *dev; 917 struct net_device *dev;
914 918
915 read_lock(&dev_base_lock); 919 read_lock(&dev_base_lock);
916 dev = __dev_get_by_name(name); 920 dev = __dev_get_by_name(net, name);
917 read_unlock(&dev_base_lock); 921 read_unlock(&dev_base_lock);
918 922
919 if (!dev && capable(CAP_SYS_MODULE)) 923 if (!dev && capable(CAP_SYS_MODULE))
@@ -1052,6 +1056,8 @@ int dev_close(struct net_device *dev)
1052} 1056}
1053 1057
1054 1058
1059static int dev_boot_phase = 1;
1060
1055/* 1061/*
1056 * Device change register/unregister. These are not inline or static 1062 * Device change register/unregister. These are not inline or static
1057 * as we export them to the world. 1063 * as we export them to the world.
@@ -1075,23 +1081,27 @@ int register_netdevice_notifier(struct notifier_block *nb)
1075{ 1081{
1076 struct net_device *dev; 1082 struct net_device *dev;
1077 struct net_device *last; 1083 struct net_device *last;
1084 struct net *net;
1078 int err; 1085 int err;
1079 1086
1080 rtnl_lock(); 1087 rtnl_lock();
1081 err = raw_notifier_chain_register(&netdev_chain, nb); 1088 err = raw_notifier_chain_register(&netdev_chain, nb);
1082 if (err) 1089 if (err)
1083 goto unlock; 1090 goto unlock;
1091 if (dev_boot_phase)
1092 goto unlock;
1093 for_each_net(net) {
1094 for_each_netdev(net, dev) {
1095 err = nb->notifier_call(nb, NETDEV_REGISTER, dev);
1096 err = notifier_to_errno(err);
1097 if (err)
1098 goto rollback;
1099
1100 if (!(dev->flags & IFF_UP))
1101 continue;
1084 1102
1085 for_each_netdev(dev) { 1103 nb->notifier_call(nb, NETDEV_UP, dev);
1086 err = nb->notifier_call(nb, NETDEV_REGISTER, dev); 1104 }
1087 err = notifier_to_errno(err);
1088 if (err)
1089 goto rollback;
1090
1091 if (!(dev->flags & IFF_UP))
1092 continue;
1093
1094 nb->notifier_call(nb, NETDEV_UP, dev);
1095 } 1105 }
1096 1106
1097unlock: 1107unlock:
@@ -1100,15 +1110,17 @@ unlock:
1100 1110
1101rollback: 1111rollback:
1102 last = dev; 1112 last = dev;
1103 for_each_netdev(dev) { 1113 for_each_net(net) {
1104 if (dev == last) 1114 for_each_netdev(net, dev) {
1105 break; 1115 if (dev == last)
1116 break;
1106 1117
1107 if (dev->flags & IFF_UP) { 1118 if (dev->flags & IFF_UP) {
1108 nb->notifier_call(nb, NETDEV_GOING_DOWN, dev); 1119 nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
1109 nb->notifier_call(nb, NETDEV_DOWN, dev); 1120 nb->notifier_call(nb, NETDEV_DOWN, dev);
1121 }
1122 nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
1110 } 1123 }
1111 nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
1112 } 1124 }
1113 goto unlock; 1125 goto unlock;
1114} 1126}
@@ -2187,7 +2199,7 @@ int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
2187 * match. --pb 2199 * match. --pb
2188 */ 2200 */
2189 2201
2190static int dev_ifname(struct ifreq __user *arg) 2202static int dev_ifname(struct net *net, struct ifreq __user *arg)
2191{ 2203{
2192 struct net_device *dev; 2204 struct net_device *dev;
2193 struct ifreq ifr; 2205 struct ifreq ifr;
@@ -2200,7 +2212,7 @@ static int dev_ifname(struct ifreq __user *arg)
2200 return -EFAULT; 2212 return -EFAULT;
2201 2213
2202 read_lock(&dev_base_lock); 2214 read_lock(&dev_base_lock);
2203 dev = __dev_get_by_index(ifr.ifr_ifindex); 2215 dev = __dev_get_by_index(net, ifr.ifr_ifindex);
2204 if (!dev) { 2216 if (!dev) {
2205 read_unlock(&dev_base_lock); 2217 read_unlock(&dev_base_lock);
2206 return -ENODEV; 2218 return -ENODEV;
@@ -2220,7 +2232,7 @@ static int dev_ifname(struct ifreq __user *arg)
2220 * Thus we will need a 'compatibility mode'. 2232 * Thus we will need a 'compatibility mode'.
2221 */ 2233 */
2222 2234
2223static int dev_ifconf(char __user *arg) 2235static int dev_ifconf(struct net *net, char __user *arg)
2224{ 2236{
2225 struct ifconf ifc; 2237 struct ifconf ifc;
2226 struct net_device *dev; 2238 struct net_device *dev;
@@ -2244,7 +2256,7 @@ static int dev_ifconf(char __user *arg)
2244 */ 2256 */
2245 2257
2246 total = 0; 2258 total = 0;
2247 for_each_netdev(dev) { 2259 for_each_netdev(net, dev) {
2248 for (i = 0; i < NPROTO; i++) { 2260 for (i = 0; i < NPROTO; i++) {
2249 if (gifconf_list[i]) { 2261 if (gifconf_list[i]) {
2250 int done; 2262 int done;
@@ -2278,6 +2290,7 @@ static int dev_ifconf(char __user *arg)
2278 */ 2290 */
2279void *dev_seq_start(struct seq_file *seq, loff_t *pos) 2291void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2280{ 2292{
2293 struct net *net = seq->private;
2281 loff_t off; 2294 loff_t off;
2282 struct net_device *dev; 2295 struct net_device *dev;
2283 2296
@@ -2286,7 +2299,7 @@ void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2286 return SEQ_START_TOKEN; 2299 return SEQ_START_TOKEN;
2287 2300
2288 off = 1; 2301 off = 1;
2289 for_each_netdev(dev) 2302 for_each_netdev(net, dev)
2290 if (off++ == *pos) 2303 if (off++ == *pos)
2291 return dev; 2304 return dev;
2292 2305
@@ -2295,9 +2308,10 @@ void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2295 2308
2296void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2309void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2297{ 2310{
2311 struct net *net = seq->private;
2298 ++*pos; 2312 ++*pos;
2299 return v == SEQ_START_TOKEN ? 2313 return v == SEQ_START_TOKEN ?
2300 first_net_device() : next_net_device((struct net_device *)v); 2314 first_net_device(net) : next_net_device((struct net_device *)v);
2301} 2315}
2302 2316
2303void dev_seq_stop(struct seq_file *seq, void *v) 2317void dev_seq_stop(struct seq_file *seq, void *v)
@@ -2393,7 +2407,22 @@ static const struct seq_operations dev_seq_ops = {
2393 2407
2394static int dev_seq_open(struct inode *inode, struct file *file) 2408static int dev_seq_open(struct inode *inode, struct file *file)
2395{ 2409{
2396 return seq_open(file, &dev_seq_ops); 2410 struct seq_file *seq;
2411 int res;
2412 res = seq_open(file, &dev_seq_ops);
2413 if (!res) {
2414 seq = file->private_data;
2415 seq->private = get_net(PROC_NET(inode));
2416 }
2417 return res;
2418}
2419
2420static int dev_seq_release(struct inode *inode, struct file *file)
2421{
2422 struct seq_file *seq = file->private_data;
2423 struct net *net = seq->private;
2424 put_net(net);
2425 return seq_release(inode, file);
2397} 2426}
2398 2427
2399static const struct file_operations dev_seq_fops = { 2428static const struct file_operations dev_seq_fops = {
@@ -2401,7 +2430,7 @@ static const struct file_operations dev_seq_fops = {
2401 .open = dev_seq_open, 2430 .open = dev_seq_open,
2402 .read = seq_read, 2431 .read = seq_read,
2403 .llseek = seq_lseek, 2432 .llseek = seq_lseek,
2404 .release = seq_release, 2433 .release = dev_seq_release,
2405}; 2434};
2406 2435
2407static const struct seq_operations softnet_seq_ops = { 2436static const struct seq_operations softnet_seq_ops = {
@@ -2553,30 +2582,49 @@ static const struct file_operations ptype_seq_fops = {
2553}; 2582};
2554 2583
2555 2584
2556static int __init dev_proc_init(void) 2585static int dev_proc_net_init(struct net *net)
2557{ 2586{
2558 int rc = -ENOMEM; 2587 int rc = -ENOMEM;
2559 2588
2560 if (!proc_net_fops_create(&init_net, "dev", S_IRUGO, &dev_seq_fops)) 2589 if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops))
2561 goto out; 2590 goto out;
2562 if (!proc_net_fops_create(&init_net, "softnet_stat", S_IRUGO, &softnet_seq_fops)) 2591 if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops))
2563 goto out_dev; 2592 goto out_dev;
2564 if (!proc_net_fops_create(&init_net, "ptype", S_IRUGO, &ptype_seq_fops)) 2593 if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops))
2565 goto out_softnet; 2594 goto out_softnet;
2566 2595
2567 if (wext_proc_init()) 2596 if (wext_proc_init(net))
2568 goto out_ptype; 2597 goto out_ptype;
2569 rc = 0; 2598 rc = 0;
2570out: 2599out:
2571 return rc; 2600 return rc;
2572out_ptype: 2601out_ptype:
2573 proc_net_remove(&init_net, "ptype"); 2602 proc_net_remove(net, "ptype");
2574out_softnet: 2603out_softnet:
2575 proc_net_remove(&init_net, "softnet_stat"); 2604 proc_net_remove(net, "softnet_stat");
2576out_dev: 2605out_dev:
2577 proc_net_remove(&init_net, "dev"); 2606 proc_net_remove(net, "dev");
2578 goto out; 2607 goto out;
2579} 2608}
2609
2610static void dev_proc_net_exit(struct net *net)
2611{
2612 wext_proc_exit(net);
2613
2614 proc_net_remove(net, "ptype");
2615 proc_net_remove(net, "softnet_stat");
2616 proc_net_remove(net, "dev");
2617}
2618
2619static struct pernet_operations dev_proc_ops = {
2620 .init = dev_proc_net_init,
2621 .exit = dev_proc_net_exit,
2622};
2623
2624static int __init dev_proc_init(void)
2625{
2626 return register_pernet_subsys(&dev_proc_ops);
2627}
2580#else 2628#else
2581#define dev_proc_init() 0 2629#define dev_proc_init() 0
2582#endif /* CONFIG_PROC_FS */ 2630#endif /* CONFIG_PROC_FS */
@@ -3011,10 +3059,10 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
3011/* 3059/*
3012 * Perform the SIOCxIFxxx calls. 3060 * Perform the SIOCxIFxxx calls.
3013 */ 3061 */
3014static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd) 3062static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3015{ 3063{
3016 int err; 3064 int err;
3017 struct net_device *dev = __dev_get_by_name(ifr->ifr_name); 3065 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
3018 3066
3019 if (!dev) 3067 if (!dev)
3020 return -ENODEV; 3068 return -ENODEV;
@@ -3167,7 +3215,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
3167 * positive or a negative errno code on error. 3215 * positive or a negative errno code on error.
3168 */ 3216 */
3169 3217
3170int dev_ioctl(unsigned int cmd, void __user *arg) 3218int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
3171{ 3219{
3172 struct ifreq ifr; 3220 struct ifreq ifr;
3173 int ret; 3221 int ret;
@@ -3180,12 +3228,12 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3180 3228
3181 if (cmd == SIOCGIFCONF) { 3229 if (cmd == SIOCGIFCONF) {
3182 rtnl_lock(); 3230 rtnl_lock();
3183 ret = dev_ifconf((char __user *) arg); 3231 ret = dev_ifconf(net, (char __user *) arg);
3184 rtnl_unlock(); 3232 rtnl_unlock();
3185 return ret; 3233 return ret;
3186 } 3234 }
3187 if (cmd == SIOCGIFNAME) 3235 if (cmd == SIOCGIFNAME)
3188 return dev_ifname((struct ifreq __user *)arg); 3236 return dev_ifname(net, (struct ifreq __user *)arg);
3189 3237
3190 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 3238 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
3191 return -EFAULT; 3239 return -EFAULT;
@@ -3215,9 +3263,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3215 case SIOCGIFMAP: 3263 case SIOCGIFMAP:
3216 case SIOCGIFINDEX: 3264 case SIOCGIFINDEX:
3217 case SIOCGIFTXQLEN: 3265 case SIOCGIFTXQLEN:
3218 dev_load(ifr.ifr_name); 3266 dev_load(net, ifr.ifr_name);
3219 read_lock(&dev_base_lock); 3267 read_lock(&dev_base_lock);
3220 ret = dev_ifsioc(&ifr, cmd); 3268 ret = dev_ifsioc(net, &ifr, cmd);
3221 read_unlock(&dev_base_lock); 3269 read_unlock(&dev_base_lock);
3222 if (!ret) { 3270 if (!ret) {
3223 if (colon) 3271 if (colon)
@@ -3229,9 +3277,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3229 return ret; 3277 return ret;
3230 3278
3231 case SIOCETHTOOL: 3279 case SIOCETHTOOL:
3232 dev_load(ifr.ifr_name); 3280 dev_load(net, ifr.ifr_name);
3233 rtnl_lock(); 3281 rtnl_lock();
3234 ret = dev_ethtool(&ifr); 3282 ret = dev_ethtool(net, &ifr);
3235 rtnl_unlock(); 3283 rtnl_unlock();
3236 if (!ret) { 3284 if (!ret) {
3237 if (colon) 3285 if (colon)
@@ -3253,9 +3301,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3253 case SIOCSIFNAME: 3301 case SIOCSIFNAME:
3254 if (!capable(CAP_NET_ADMIN)) 3302 if (!capable(CAP_NET_ADMIN))
3255 return -EPERM; 3303 return -EPERM;
3256 dev_load(ifr.ifr_name); 3304 dev_load(net, ifr.ifr_name);
3257 rtnl_lock(); 3305 rtnl_lock();
3258 ret = dev_ifsioc(&ifr, cmd); 3306 ret = dev_ifsioc(net, &ifr, cmd);
3259 rtnl_unlock(); 3307 rtnl_unlock();
3260 if (!ret) { 3308 if (!ret) {
3261 if (colon) 3309 if (colon)
@@ -3294,9 +3342,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3294 /* fall through */ 3342 /* fall through */
3295 case SIOCBONDSLAVEINFOQUERY: 3343 case SIOCBONDSLAVEINFOQUERY:
3296 case SIOCBONDINFOQUERY: 3344 case SIOCBONDINFOQUERY:
3297 dev_load(ifr.ifr_name); 3345 dev_load(net, ifr.ifr_name);
3298 rtnl_lock(); 3346 rtnl_lock();
3299 ret = dev_ifsioc(&ifr, cmd); 3347 ret = dev_ifsioc(net, &ifr, cmd);
3300 rtnl_unlock(); 3348 rtnl_unlock();
3301 return ret; 3349 return ret;
3302 3350
@@ -3316,9 +3364,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3316 if (cmd == SIOCWANDEV || 3364 if (cmd == SIOCWANDEV ||
3317 (cmd >= SIOCDEVPRIVATE && 3365 (cmd >= SIOCDEVPRIVATE &&
3318 cmd <= SIOCDEVPRIVATE + 15)) { 3366 cmd <= SIOCDEVPRIVATE + 15)) {
3319 dev_load(ifr.ifr_name); 3367 dev_load(net, ifr.ifr_name);
3320 rtnl_lock(); 3368 rtnl_lock();
3321 ret = dev_ifsioc(&ifr, cmd); 3369 ret = dev_ifsioc(net, &ifr, cmd);
3322 rtnl_unlock(); 3370 rtnl_unlock();
3323 if (!ret && copy_to_user(arg, &ifr, 3371 if (!ret && copy_to_user(arg, &ifr,
3324 sizeof(struct ifreq))) 3372 sizeof(struct ifreq)))
@@ -3327,7 +3375,7 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3327 } 3375 }
3328 /* Take care of Wireless Extensions */ 3376 /* Take care of Wireless Extensions */
3329 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) 3377 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
3330 return wext_handle_ioctl(&ifr, cmd, arg); 3378 return wext_handle_ioctl(net, &ifr, cmd, arg);
3331 return -EINVAL; 3379 return -EINVAL;
3332 } 3380 }
3333} 3381}
@@ -3340,19 +3388,17 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
3340 * number. The caller must hold the rtnl semaphore or the 3388 * number. The caller must hold the rtnl semaphore or the
3341 * dev_base_lock to be sure it remains unique. 3389 * dev_base_lock to be sure it remains unique.
3342 */ 3390 */
3343static int dev_new_index(void) 3391static int dev_new_index(struct net *net)
3344{ 3392{
3345 static int ifindex; 3393 static int ifindex;
3346 for (;;) { 3394 for (;;) {
3347 if (++ifindex <= 0) 3395 if (++ifindex <= 0)
3348 ifindex = 1; 3396 ifindex = 1;
3349 if (!__dev_get_by_index(ifindex)) 3397 if (!__dev_get_by_index(net, ifindex))
3350 return ifindex; 3398 return ifindex;
3351 } 3399 }
3352} 3400}
3353 3401
3354static int dev_boot_phase = 1;
3355
3356/* Delayed registration/unregisteration */ 3402/* Delayed registration/unregisteration */
3357static DEFINE_SPINLOCK(net_todo_list_lock); 3403static DEFINE_SPINLOCK(net_todo_list_lock);
3358static struct list_head net_todo_list = LIST_HEAD_INIT(net_todo_list); 3404static struct list_head net_todo_list = LIST_HEAD_INIT(net_todo_list);
@@ -3386,6 +3432,7 @@ int register_netdevice(struct net_device *dev)
3386 struct hlist_head *head; 3432 struct hlist_head *head;
3387 struct hlist_node *p; 3433 struct hlist_node *p;
3388 int ret; 3434 int ret;
3435 struct net *net;
3389 3436
3390 BUG_ON(dev_boot_phase); 3437 BUG_ON(dev_boot_phase);
3391 ASSERT_RTNL(); 3438 ASSERT_RTNL();
@@ -3394,6 +3441,8 @@ int register_netdevice(struct net_device *dev)
3394 3441
3395 /* When net_device's are persistent, this will be fatal. */ 3442 /* When net_device's are persistent, this will be fatal. */
3396 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); 3443 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
3444 BUG_ON(!dev->nd_net);
3445 net = dev->nd_net;
3397 3446
3398 spin_lock_init(&dev->queue_lock); 3447 spin_lock_init(&dev->queue_lock);
3399 spin_lock_init(&dev->_xmit_lock); 3448 spin_lock_init(&dev->_xmit_lock);
@@ -3418,12 +3467,12 @@ int register_netdevice(struct net_device *dev)
3418 goto err_uninit; 3467 goto err_uninit;
3419 } 3468 }
3420 3469
3421 dev->ifindex = dev_new_index(); 3470 dev->ifindex = dev_new_index(net);
3422 if (dev->iflink == -1) 3471 if (dev->iflink == -1)
3423 dev->iflink = dev->ifindex; 3472 dev->iflink = dev->ifindex;
3424 3473
3425 /* Check for existence of name */ 3474 /* Check for existence of name */
3426 head = dev_name_hash(dev->name); 3475 head = dev_name_hash(net, dev->name);
3427 hlist_for_each(p, head) { 3476 hlist_for_each(p, head) {
3428 struct net_device *d 3477 struct net_device *d
3429 = hlist_entry(p, struct net_device, name_hlist); 3478 = hlist_entry(p, struct net_device, name_hlist);
@@ -3501,9 +3550,9 @@ int register_netdevice(struct net_device *dev)
3501 3550
3502 dev_init_scheduler(dev); 3551 dev_init_scheduler(dev);
3503 write_lock_bh(&dev_base_lock); 3552 write_lock_bh(&dev_base_lock);
3504 list_add_tail(&dev->dev_list, &dev_base_head); 3553 list_add_tail(&dev->dev_list, &net->dev_base_head);
3505 hlist_add_head(&dev->name_hlist, head); 3554 hlist_add_head(&dev->name_hlist, head);
3506 hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); 3555 hlist_add_head(&dev->index_hlist, dev_index_hash(net, dev->ifindex));
3507 dev_hold(dev); 3556 dev_hold(dev);
3508 write_unlock_bh(&dev_base_lock); 3557 write_unlock_bh(&dev_base_lock);
3509 3558
@@ -4067,6 +4116,45 @@ int netdev_compute_features(unsigned long all, unsigned long one)
4067} 4116}
4068EXPORT_SYMBOL(netdev_compute_features); 4117EXPORT_SYMBOL(netdev_compute_features);
4069 4118
4119/* Initialize per network namespace state */
4120static int netdev_init(struct net *net)
4121{
4122 int i;
4123 INIT_LIST_HEAD(&net->dev_base_head);
4124 rwlock_init(&dev_base_lock);
4125
4126 net->dev_name_head = kmalloc(
4127 sizeof(*net->dev_name_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
4128 if (!net->dev_name_head)
4129 return -ENOMEM;
4130
4131 net->dev_index_head = kmalloc(
4132 sizeof(*net->dev_index_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
4133 if (!net->dev_index_head) {
4134 kfree(net->dev_name_head);
4135 return -ENOMEM;
4136 }
4137
4138 for (i = 0; i < NETDEV_HASHENTRIES; i++)
4139 INIT_HLIST_HEAD(&net->dev_name_head[i]);
4140
4141 for (i = 0; i < NETDEV_HASHENTRIES; i++)
4142 INIT_HLIST_HEAD(&net->dev_index_head[i]);
4143
4144 return 0;
4145}
4146
4147static void netdev_exit(struct net *net)
4148{
4149 kfree(net->dev_name_head);
4150 kfree(net->dev_index_head);
4151}
4152
4153static struct pernet_operations netdev_net_ops = {
4154 .init = netdev_init,
4155 .exit = netdev_exit,
4156};
4157
4070/* 4158/*
4071 * Initialize the DEV module. At boot time this walks the device list and 4159 * Initialize the DEV module. At boot time this walks the device list and
4072 * unhooks any devices that fail to initialise (normally hardware not 4160 * unhooks any devices that fail to initialise (normally hardware not
@@ -4094,11 +4182,8 @@ static int __init net_dev_init(void)
4094 for (i = 0; i < 16; i++) 4182 for (i = 0; i < 16; i++)
4095 INIT_LIST_HEAD(&ptype_base[i]); 4183 INIT_LIST_HEAD(&ptype_base[i]);
4096 4184
4097 for (i = 0; i < ARRAY_SIZE(dev_name_head); i++) 4185 if (register_pernet_subsys(&netdev_net_ops))
4098 INIT_HLIST_HEAD(&dev_name_head[i]); 4186 goto out;
4099
4100 for (i = 0; i < ARRAY_SIZE(dev_index_head); i++)
4101 INIT_HLIST_HEAD(&dev_index_head[i]);
4102 4187
4103 /* 4188 /*
4104 * Initialise the packet receive queues. 4189 * Initialise the packet receive queues.
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index 8e069fc207cb..1c4f6198459b 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -187,11 +187,12 @@ EXPORT_SYMBOL(dev_mc_unsync);
187#ifdef CONFIG_PROC_FS 187#ifdef CONFIG_PROC_FS
188static void *dev_mc_seq_start(struct seq_file *seq, loff_t *pos) 188static void *dev_mc_seq_start(struct seq_file *seq, loff_t *pos)
189{ 189{
190 struct net *net = seq->private;
190 struct net_device *dev; 191 struct net_device *dev;
191 loff_t off = 0; 192 loff_t off = 0;
192 193
193 read_lock(&dev_base_lock); 194 read_lock(&dev_base_lock);
194 for_each_netdev(dev) { 195 for_each_netdev(net, dev) {
195 if (off++ == *pos) 196 if (off++ == *pos)
196 return dev; 197 return dev;
197 } 198 }
@@ -240,7 +241,22 @@ static const struct seq_operations dev_mc_seq_ops = {
240 241
241static int dev_mc_seq_open(struct inode *inode, struct file *file) 242static int dev_mc_seq_open(struct inode *inode, struct file *file)
242{ 243{
243 return seq_open(file, &dev_mc_seq_ops); 244 struct seq_file *seq;
245 int res;
246 res = seq_open(file, &dev_mc_seq_ops);
247 if (!res) {
248 seq = file->private_data;
249 seq->private = get_net(PROC_NET(inode));
250 }
251 return res;
252}
253
254static int dev_mc_seq_release(struct inode *inode, struct file *file)
255{
256 struct seq_file *seq = file->private_data;
257 struct net *net = seq->private;
258 put_net(net);
259 return seq_release(inode, file);
244} 260}
245 261
246static const struct file_operations dev_mc_seq_fops = { 262static const struct file_operations dev_mc_seq_fops = {
@@ -248,14 +264,31 @@ static const struct file_operations dev_mc_seq_fops = {
248 .open = dev_mc_seq_open, 264 .open = dev_mc_seq_open,
249 .read = seq_read, 265 .read = seq_read,
250 .llseek = seq_lseek, 266 .llseek = seq_lseek,
251 .release = seq_release, 267 .release = dev_mc_seq_release,
252}; 268};
253 269
254#endif 270#endif
255 271
272static int dev_mc_net_init(struct net *net)
273{
274 if (!proc_net_fops_create(net, "dev_mcast", 0, &dev_mc_seq_fops))
275 return -ENOMEM;
276 return 0;
277}
278
279static void dev_mc_net_exit(struct net *net)
280{
281 proc_net_remove(net, "dev_mcast");
282}
283
284static struct pernet_operations dev_mc_net_ops = {
285 .init = dev_mc_net_init,
286 .exit = dev_mc_net_exit,
287};
288
256void __init dev_mcast_init(void) 289void __init dev_mcast_init(void)
257{ 290{
258 proc_net_fops_create(&init_net, "dev_mcast", 0, &dev_mc_seq_fops); 291 register_pernet_subsys(&dev_mc_net_ops);
259} 292}
260 293
261EXPORT_SYMBOL(dev_mc_add); 294EXPORT_SYMBOL(dev_mc_add);
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 7c43f032a7f9..0d0b13cc1dd3 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -779,9 +779,9 @@ static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
779 779
780/* The main entry point in this file. Called from net/core/dev.c */ 780/* The main entry point in this file. Called from net/core/dev.c */
781 781
782int dev_ethtool(struct ifreq *ifr) 782int dev_ethtool(struct net *net, struct ifreq *ifr)
783{ 783{
784 struct net_device *dev = __dev_get_by_name(ifr->ifr_name); 784 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
785 void __user *useraddr = ifr->ifr_data; 785 void __user *useraddr = ifr->ifr_data;
786 u32 ethcmd; 786 u32 ethcmd;
787 int rc; 787 int rc;
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 9eabe1ae01dc..1ba71baf87ef 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -12,6 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/list.h> 13#include <linux/list.h>
14#include <net/net_namespace.h> 14#include <net/net_namespace.h>
15#include <net/sock.h>
15#include <net/fib_rules.h> 16#include <net/fib_rules.h>
16 17
17static LIST_HEAD(rules_ops); 18static LIST_HEAD(rules_ops);
@@ -198,6 +199,7 @@ errout:
198 199
199static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 200static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
200{ 201{
202 struct net *net = skb->sk->sk_net;
201 struct fib_rule_hdr *frh = nlmsg_data(nlh); 203 struct fib_rule_hdr *frh = nlmsg_data(nlh);
202 struct fib_rules_ops *ops = NULL; 204 struct fib_rules_ops *ops = NULL;
203 struct fib_rule *rule, *r, *last = NULL; 205 struct fib_rule *rule, *r, *last = NULL;
@@ -235,7 +237,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
235 237
236 rule->ifindex = -1; 238 rule->ifindex = -1;
237 nla_strlcpy(rule->ifname, tb[FRA_IFNAME], IFNAMSIZ); 239 nla_strlcpy(rule->ifname, tb[FRA_IFNAME], IFNAMSIZ);
238 dev = __dev_get_by_name(rule->ifname); 240 dev = __dev_get_by_name(net, rule->ifname);
239 if (dev) 241 if (dev)
240 rule->ifindex = dev->ifindex; 242 rule->ifindex = dev->ifindex;
241 } 243 }
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 5f25f4f79b8c..2c6577c1eedd 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1441,6 +1441,7 @@ int neigh_table_clear(struct neigh_table *tbl)
1441 1441
1442static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1442static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1443{ 1443{
1444 struct net *net = skb->sk->sk_net;
1444 struct ndmsg *ndm; 1445 struct ndmsg *ndm;
1445 struct nlattr *dst_attr; 1446 struct nlattr *dst_attr;
1446 struct neigh_table *tbl; 1447 struct neigh_table *tbl;
@@ -1456,7 +1457,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1456 1457
1457 ndm = nlmsg_data(nlh); 1458 ndm = nlmsg_data(nlh);
1458 if (ndm->ndm_ifindex) { 1459 if (ndm->ndm_ifindex) {
1459 dev = dev_get_by_index(ndm->ndm_ifindex); 1460 dev = dev_get_by_index(net, ndm->ndm_ifindex);
1460 if (dev == NULL) { 1461 if (dev == NULL) {
1461 err = -ENODEV; 1462 err = -ENODEV;
1462 goto out; 1463 goto out;
@@ -1506,6 +1507,7 @@ out:
1506 1507
1507static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1508static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1508{ 1509{
1510 struct net *net = skb->sk->sk_net;
1509 struct ndmsg *ndm; 1511 struct ndmsg *ndm;
1510 struct nlattr *tb[NDA_MAX+1]; 1512 struct nlattr *tb[NDA_MAX+1];
1511 struct neigh_table *tbl; 1513 struct neigh_table *tbl;
@@ -1522,7 +1524,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1522 1524
1523 ndm = nlmsg_data(nlh); 1525 ndm = nlmsg_data(nlh);
1524 if (ndm->ndm_ifindex) { 1526 if (ndm->ndm_ifindex) {
1525 dev = dev_get_by_index(ndm->ndm_ifindex); 1527 dev = dev_get_by_index(net, ndm->ndm_ifindex);
1526 if (dev == NULL) { 1528 if (dev == NULL) {
1527 err = -ENODEV; 1529 err = -ENODEV;
1528 goto out; 1530 goto out;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 0952f936b292..bb7523a5b408 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -653,7 +653,7 @@ int netpoll_setup(struct netpoll *np)
653 int err; 653 int err;
654 654
655 if (np->dev_name) 655 if (np->dev_name)
656 ndev = dev_get_by_name(np->dev_name); 656 ndev = dev_get_by_name(&init_net, np->dev_name);
657 if (!ndev) { 657 if (!ndev) {
658 printk(KERN_ERR "%s: %s doesn't exist, aborting.\n", 658 printk(KERN_ERR "%s: %s doesn't exist, aborting.\n",
659 np->name, np->dev_name); 659 np->name, np->dev_name);
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index d7c30ce095a1..94e42be16daa 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2008,7 +2008,7 @@ static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname)
2008 pkt_dev->odev = NULL; 2008 pkt_dev->odev = NULL;
2009 } 2009 }
2010 2010
2011 odev = dev_get_by_name(ifname); 2011 odev = dev_get_by_name(&init_net, ifname);
2012 if (!odev) { 2012 if (!odev) {
2013 printk(KERN_ERR "pktgen: no such netdevice: \"%s\"\n", ifname); 2013 printk(KERN_ERR "pktgen: no such netdevice: \"%s\"\n", ifname);
2014 return -ENODEV; 2014 return -ENODEV;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 416768d1e0cd..44f91bb1ae8d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -306,10 +306,13 @@ EXPORT_SYMBOL_GPL(rtnl_link_register);
306void __rtnl_link_unregister(struct rtnl_link_ops *ops) 306void __rtnl_link_unregister(struct rtnl_link_ops *ops)
307{ 307{
308 struct net_device *dev, *n; 308 struct net_device *dev, *n;
309 struct net *net;
309 310
310 for_each_netdev_safe(dev, n) { 311 for_each_net(net) {
311 if (dev->rtnl_link_ops == ops) 312 for_each_netdev_safe(net, dev, n) {
312 ops->dellink(dev); 313 if (dev->rtnl_link_ops == ops)
314 ops->dellink(dev);
315 }
313 } 316 }
314 list_del(&ops->list); 317 list_del(&ops->list);
315} 318}
@@ -693,12 +696,13 @@ nla_put_failure:
693 696
694static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 697static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
695{ 698{
699 struct net *net = skb->sk->sk_net;
696 int idx; 700 int idx;
697 int s_idx = cb->args[0]; 701 int s_idx = cb->args[0];
698 struct net_device *dev; 702 struct net_device *dev;
699 703
700 idx = 0; 704 idx = 0;
701 for_each_netdev(dev) { 705 for_each_netdev(net, dev) {
702 if (idx < s_idx) 706 if (idx < s_idx)
703 goto cont; 707 goto cont;
704 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK, 708 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
@@ -858,6 +862,7 @@ errout:
858 862
859static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 863static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
860{ 864{
865 struct net *net = skb->sk->sk_net;
861 struct ifinfomsg *ifm; 866 struct ifinfomsg *ifm;
862 struct net_device *dev; 867 struct net_device *dev;
863 int err; 868 int err;
@@ -876,9 +881,9 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
876 err = -EINVAL; 881 err = -EINVAL;
877 ifm = nlmsg_data(nlh); 882 ifm = nlmsg_data(nlh);
878 if (ifm->ifi_index > 0) 883 if (ifm->ifi_index > 0)
879 dev = dev_get_by_index(ifm->ifi_index); 884 dev = dev_get_by_index(net, ifm->ifi_index);
880 else if (tb[IFLA_IFNAME]) 885 else if (tb[IFLA_IFNAME])
881 dev = dev_get_by_name(ifname); 886 dev = dev_get_by_name(net, ifname);
882 else 887 else
883 goto errout; 888 goto errout;
884 889
@@ -904,6 +909,7 @@ errout:
904 909
905static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 910static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
906{ 911{
912 struct net *net = skb->sk->sk_net;
907 const struct rtnl_link_ops *ops; 913 const struct rtnl_link_ops *ops;
908 struct net_device *dev; 914 struct net_device *dev;
909 struct ifinfomsg *ifm; 915 struct ifinfomsg *ifm;
@@ -920,9 +926,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
920 926
921 ifm = nlmsg_data(nlh); 927 ifm = nlmsg_data(nlh);
922 if (ifm->ifi_index > 0) 928 if (ifm->ifi_index > 0)
923 dev = __dev_get_by_index(ifm->ifi_index); 929 dev = __dev_get_by_index(net, ifm->ifi_index);
924 else if (tb[IFLA_IFNAME]) 930 else if (tb[IFLA_IFNAME])
925 dev = __dev_get_by_name(ifname); 931 dev = __dev_get_by_name(net, ifname);
926 else 932 else
927 return -EINVAL; 933 return -EINVAL;
928 934
@@ -937,7 +943,7 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
937 return 0; 943 return 0;
938} 944}
939 945
940struct net_device *rtnl_create_link(char *ifname, 946struct net_device *rtnl_create_link(struct net *net, char *ifname,
941 const struct rtnl_link_ops *ops, struct nlattr *tb[]) 947 const struct rtnl_link_ops *ops, struct nlattr *tb[])
942{ 948{
943 int err; 949 int err;
@@ -954,6 +960,7 @@ struct net_device *rtnl_create_link(char *ifname,
954 goto err_free; 960 goto err_free;
955 } 961 }
956 962
963 dev->nd_net = net;
957 dev->rtnl_link_ops = ops; 964 dev->rtnl_link_ops = ops;
958 965
959 if (tb[IFLA_MTU]) 966 if (tb[IFLA_MTU])
@@ -981,6 +988,7 @@ err:
981 988
982static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 989static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
983{ 990{
991 struct net *net = skb->sk->sk_net;
984 const struct rtnl_link_ops *ops; 992 const struct rtnl_link_ops *ops;
985 struct net_device *dev; 993 struct net_device *dev;
986 struct ifinfomsg *ifm; 994 struct ifinfomsg *ifm;
@@ -1004,9 +1012,9 @@ replay:
1004 1012
1005 ifm = nlmsg_data(nlh); 1013 ifm = nlmsg_data(nlh);
1006 if (ifm->ifi_index > 0) 1014 if (ifm->ifi_index > 0)
1007 dev = __dev_get_by_index(ifm->ifi_index); 1015 dev = __dev_get_by_index(net, ifm->ifi_index);
1008 else if (ifname[0]) 1016 else if (ifname[0])
1009 dev = __dev_get_by_name(ifname); 1017 dev = __dev_get_by_name(net, ifname);
1010 else 1018 else
1011 dev = NULL; 1019 dev = NULL;
1012 1020
@@ -1092,7 +1100,7 @@ replay:
1092 if (!ifname[0]) 1100 if (!ifname[0])
1093 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); 1101 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
1094 1102
1095 dev = rtnl_create_link(ifname, ops, tb); 1103 dev = rtnl_create_link(net, ifname, ops, tb);
1096 1104
1097 if (IS_ERR(dev)) 1105 if (IS_ERR(dev))
1098 err = PTR_ERR(dev); 1106 err = PTR_ERR(dev);
@@ -1109,6 +1117,7 @@ replay:
1109 1117
1110static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 1118static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1111{ 1119{
1120 struct net *net = skb->sk->sk_net;
1112 struct ifinfomsg *ifm; 1121 struct ifinfomsg *ifm;
1113 struct nlattr *tb[IFLA_MAX+1]; 1122 struct nlattr *tb[IFLA_MAX+1];
1114 struct net_device *dev = NULL; 1123 struct net_device *dev = NULL;
@@ -1121,7 +1130,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1121 1130
1122 ifm = nlmsg_data(nlh); 1131 ifm = nlmsg_data(nlh);
1123 if (ifm->ifi_index > 0) { 1132 if (ifm->ifi_index > 0) {
1124 dev = dev_get_by_index(ifm->ifi_index); 1133 dev = dev_get_by_index(net, ifm->ifi_index);
1125 if (dev == NULL) 1134 if (dev == NULL)
1126 return -ENODEV; 1135 return -ENODEV;
1127 } else 1136 } else
diff --git a/net/core/sock.c b/net/core/sock.c
index a31455dc7024..4ed9b507c1e7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -367,6 +367,7 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
367{ 367{
368 int ret = -ENOPROTOOPT; 368 int ret = -ENOPROTOOPT;
369#ifdef CONFIG_NETDEVICES 369#ifdef CONFIG_NETDEVICES
370 struct net *net = sk->sk_net;
370 char devname[IFNAMSIZ]; 371 char devname[IFNAMSIZ];
371 int index; 372 int index;
372 373
@@ -395,7 +396,7 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
395 if (devname[0] == '\0') { 396 if (devname[0] == '\0') {
396 index = 0; 397 index = 0;
397 } else { 398 } else {
398 struct net_device *dev = dev_get_by_name(devname); 399 struct net_device *dev = dev_get_by_name(net, devname);
399 400
400 ret = -ENODEV; 401 ret = -ENODEV;
401 if (!dev) 402 if (!dev)