mac80211: remove trivial rx_data->fc users
[safe/jmp/linux-2.6] / net / core / dev.c
index 29cf00c..7593393 100644 (file)
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
+#include <linux/ethtool.h>
 #include <linux/notifier.h>
 #include <linux/skbuff.h>
+#include <net/net_namespace.h>
 #include <net/sock.h>
 #include <linux/rtnetlink.h>
 #include <linux/proc_fs.h>
 #include <linux/err.h>
 #include <linux/ctype.h>
 #include <linux/if_arp.h>
+#include <linux/if_vlan.h>
+
+#include "net-sysfs.h"
 
 /*
  *     The list of packet types we will receive (as opposed to discard)
  *             86DD    IPv6
  */
 
+#define PTYPE_HASH_SIZE        (16)
+#define PTYPE_HASH_MASK        (PTYPE_HASH_SIZE - 1)
+
 static DEFINE_SPINLOCK(ptype_lock);
-static struct list_head ptype_base[16] __read_mostly;  /* 16 way hashed list */
+static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
 static struct list_head ptype_all __read_mostly;       /* Taps */
 
 #ifdef CONFIG_NET_DMA
@@ -156,7 +164,7 @@ struct net_dma {
        struct dma_client client;
        spinlock_t lock;
        cpumask_t channel_mask;
-       struct dma_chan *channels[NR_CPUS];
+       struct dma_chan **channels;
 };
 
 static enum dma_state_client
@@ -189,25 +197,50 @@ static struct net_dma net_dma = {
  * unregister_netdevice(), which must be called with the rtnl
  * semaphore held.
  */
-LIST_HEAD(dev_base_head);
 DEFINE_RWLOCK(dev_base_lock);
 
-EXPORT_SYMBOL(dev_base_head);
 EXPORT_SYMBOL(dev_base_lock);
 
 #define NETDEV_HASHBITS        8
-static struct hlist_head dev_name_head[1<<NETDEV_HASHBITS];
-static struct hlist_head dev_index_head[1<<NETDEV_HASHBITS];
+#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
 
-static inline struct hlist_head *dev_name_hash(const char *name)
+static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
 {
        unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
-       return &dev_name_head[hash & ((1<<NETDEV_HASHBITS)-1)];
+       return &net->dev_name_head[hash & ((1 << NETDEV_HASHBITS) - 1)];
+}
+
+static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex)
+{
+       return &net->dev_index_head[ifindex & ((1 << NETDEV_HASHBITS) - 1)];
+}
+
+/* Device list insertion */
+static int list_netdevice(struct net_device *dev)
+{
+       struct net *net = dev_net(dev);
+
+       ASSERT_RTNL();
+
+       write_lock_bh(&dev_base_lock);
+       list_add_tail(&dev->dev_list, &net->dev_base_head);
+       hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
+       hlist_add_head(&dev->index_hlist, dev_index_hash(net, dev->ifindex));
+       write_unlock_bh(&dev_base_lock);
+       return 0;
 }
 
-static inline struct hlist_head *dev_index_hash(int ifindex)
+/* Device list removal */
+static void unlist_netdevice(struct net_device *dev)
 {
-       return &dev_index_head[ifindex & ((1<<NETDEV_HASHBITS)-1)];
+       ASSERT_RTNL();
+
+       /* Unlink dev from the device chain */
+       write_lock_bh(&dev_base_lock);
+       list_del(&dev->dev_list);
+       hlist_del(&dev->name_hlist);
+       hlist_del(&dev->index_hlist);
+       write_unlock_bh(&dev_base_lock);
 }
 
 /*
@@ -223,16 +256,6 @@ static RAW_NOTIFIER_HEAD(netdev_chain);
 
 DEFINE_PER_CPU(struct softnet_data, softnet_data);
 
-#ifdef CONFIG_SYSFS
-extern int netdev_sysfs_init(void);
-extern int netdev_register_sysfs(struct net_device *);
-extern void netdev_unregister_sysfs(struct net_device *);
-#else
-#define netdev_sysfs_init()            (0)
-#define netdev_register_sysfs(dev)     (0)
-#define        netdev_unregister_sysfs(dev)    do { } while(0)
-#endif
-
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 /*
  * register_netdevice() inits dev->_xmit_lock and sets lockdep class
@@ -344,7 +367,7 @@ void dev_add_pack(struct packet_type *pt)
        if (pt->type == htons(ETH_P_ALL))
                list_add_rcu(&pt->list, &ptype_all);
        else {
-               hash = ntohs(pt->type) & 15;
+               hash = ntohs(pt->type) & PTYPE_HASH_MASK;
                list_add_rcu(&pt->list, &ptype_base[hash]);
        }
        spin_unlock_bh(&ptype_lock);
@@ -373,7 +396,7 @@ void __dev_remove_pack(struct packet_type *pt)
        if (pt->type == htons(ETH_P_ALL))
                head = &ptype_all;
        else
-               head = &ptype_base[ntohs(pt->type) & 15];
+               head = &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK];
 
        list_for_each_entry(pt1, head, list) {
                if (pt == pt1) {
@@ -432,7 +455,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
        for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
                if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
                        memset(s[i].name, 0, sizeof(s[i].name));
-                       strcpy(s[i].name, name);
+                       strlcpy(s[i].name, name, IFNAMSIZ);
                        memcpy(&s[i].map, map, sizeof(s[i].map));
                        break;
                }
@@ -457,7 +480,7 @@ int netdev_boot_setup_check(struct net_device *dev)
 
        for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
                if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
-                   !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
+                   !strcmp(dev->name, s[i].name)) {
                        dev->irq        = s[i].map.irq;
                        dev->base_addr  = s[i].map.base_addr;
                        dev->mem_start  = s[i].map.mem_start;
@@ -491,7 +514,7 @@ unsigned long netdev_boot_base(const char *prefix, int unit)
         * If device already registered then return base of 1
         * to indicate not to probe for this interface
         */
-       if (__dev_get_by_name(name))
+       if (__dev_get_by_name(&init_net, name))
                return 1;
 
        for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
@@ -537,6 +560,7 @@ __setup("netdev=", netdev_boot_setup);
 
 /**
  *     __dev_get_by_name       - find a device by its name
+ *     @net: the applicable net namespace
  *     @name: name to find
  *
  *     Find an interface by name. Must be called under RTNL semaphore
@@ -546,11 +570,11 @@ __setup("netdev=", netdev_boot_setup);
  *     careful with locks.
  */
 
-struct net_device *__dev_get_by_name(const char *name)
+struct net_device *__dev_get_by_name(struct net *net, const char *name)
 {
        struct hlist_node *p;
 
-       hlist_for_each(p, dev_name_hash(name)) {
+       hlist_for_each(p, dev_name_hash(net, name)) {
                struct net_device *dev
                        = hlist_entry(p, struct net_device, name_hlist);
                if (!strncmp(dev->name, name, IFNAMSIZ))
@@ -561,6 +585,7 @@ struct net_device *__dev_get_by_name(const char *name)
 
 /**
  *     dev_get_by_name         - find a device by its name
+ *     @net: the applicable net namespace
  *     @name: name to find
  *
  *     Find an interface by name. This can be called from any
@@ -570,12 +595,12 @@ struct net_device *__dev_get_by_name(const char *name)
  *     matching device is found.
  */
 
-struct net_device *dev_get_by_name(const char *name)
+struct net_device *dev_get_by_name(struct net *net, const char *name)
 {
        struct net_device *dev;
 
        read_lock(&dev_base_lock);
-       dev = __dev_get_by_name(name);
+       dev = __dev_get_by_name(net, name);
        if (dev)
                dev_hold(dev);
        read_unlock(&dev_base_lock);
@@ -584,6 +609,7 @@ struct net_device *dev_get_by_name(const char *name)
 
 /**
  *     __dev_get_by_index - find a device by its ifindex
+ *     @net: the applicable net namespace
  *     @ifindex: index of device
  *
  *     Search for an interface by index. Returns %NULL if the device
@@ -593,11 +619,11 @@ struct net_device *dev_get_by_name(const char *name)
  *     or @dev_base_lock.
  */
 
-struct net_device *__dev_get_by_index(int ifindex)
+struct net_device *__dev_get_by_index(struct net *net, int ifindex)
 {
        struct hlist_node *p;
 
-       hlist_for_each(p, dev_index_hash(ifindex)) {
+       hlist_for_each(p, dev_index_hash(net, ifindex)) {
                struct net_device *dev
                        = hlist_entry(p, struct net_device, index_hlist);
                if (dev->ifindex == ifindex)
@@ -609,6 +635,7 @@ struct net_device *__dev_get_by_index(int ifindex)
 
 /**
  *     dev_get_by_index - find a device by its ifindex
+ *     @net: the applicable net namespace
  *     @ifindex: index of device
  *
  *     Search for an interface by index. Returns NULL if the device
@@ -617,12 +644,12 @@ struct net_device *__dev_get_by_index(int ifindex)
  *     dev_put to indicate they have finished with it.
  */
 
-struct net_device *dev_get_by_index(int ifindex)
+struct net_device *dev_get_by_index(struct net *net, int ifindex)
 {
        struct net_device *dev;
 
        read_lock(&dev_base_lock);
-       dev = __dev_get_by_index(ifindex);
+       dev = __dev_get_by_index(net, ifindex);
        if (dev)
                dev_hold(dev);
        read_unlock(&dev_base_lock);
@@ -631,6 +658,7 @@ struct net_device *dev_get_by_index(int ifindex)
 
 /**
  *     dev_getbyhwaddr - find a device by its hardware address
+ *     @net: the applicable net namespace
  *     @type: media type of device
  *     @ha: hardware address
  *
@@ -643,13 +671,13 @@ struct net_device *dev_get_by_index(int ifindex)
  *     If the API was consistent this would be __dev_get_by_hwaddr
  */
 
-struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
+struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha)
 {
        struct net_device *dev;
 
        ASSERT_RTNL();
 
-       for_each_netdev(dev)
+       for_each_netdev(net, dev)
                if (dev->type == type &&
                    !memcmp(dev->dev_addr, ha, dev->addr_len))
                        return dev;
@@ -659,12 +687,12 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
 
 EXPORT_SYMBOL(dev_getbyhwaddr);
 
-struct net_device *__dev_getfirstbyhwtype(unsigned short type)
+struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
 {
        struct net_device *dev;
 
        ASSERT_RTNL();
-       for_each_netdev(dev)
+       for_each_netdev(net, dev)
                if (dev->type == type)
                        return dev;
 
@@ -673,12 +701,12 @@ struct net_device *__dev_getfirstbyhwtype(unsigned short type)
 
 EXPORT_SYMBOL(__dev_getfirstbyhwtype);
 
-struct net_device *dev_getfirstbyhwtype(unsigned short type)
+struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
 {
        struct net_device *dev;
 
        rtnl_lock();
-       dev = __dev_getfirstbyhwtype(type);
+       dev = __dev_getfirstbyhwtype(net, type);
        if (dev)
                dev_hold(dev);
        rtnl_unlock();
@@ -689,6 +717,7 @@ EXPORT_SYMBOL(dev_getfirstbyhwtype);
 
 /**
  *     dev_get_by_flags - find any device with given flags
+ *     @net: the applicable net namespace
  *     @if_flags: IFF_* values
  *     @mask: bitmask of bits in if_flags to check
  *
@@ -698,13 +727,13 @@ EXPORT_SYMBOL(dev_getfirstbyhwtype);
  *     dev_put to indicate they have finished with it.
  */
 
-struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask)
+struct net_device * dev_get_by_flags(struct net *net, unsigned short if_flags, unsigned short mask)
 {
        struct net_device *dev, *ret;
 
        ret = NULL;
        read_lock(&dev_base_lock);
-       for_each_netdev(dev) {
+       for_each_netdev(net, dev) {
                if (((dev->flags ^ if_flags) & mask) == 0) {
                        dev_hold(dev);
                        ret = dev;
@@ -741,9 +770,10 @@ int dev_valid_name(const char *name)
 }
 
 /**
- *     dev_alloc_name - allocate a name for a device
- *     @dev: device
+ *     __dev_alloc_name - allocate a name for a device
+ *     @net: network namespace to allocate the device name in
  *     @name: name format string
+ *     @buf:  scratch buffer and result name string
  *
  *     Passed a format string - eg "lt%d" it will try and find a suitable
  *     id. It scans list of devices to build up a free map, then chooses
@@ -754,13 +784,12 @@ int dev_valid_name(const char *name)
  *     Returns the number of the unit assigned or a negative errno code.
  */
 
-int dev_alloc_name(struct net_device *dev, const char *name)
+static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 {
        int i = 0;
-       char buf[IFNAMSIZ];
        const char *p;
        const int max_netdevices = 8*PAGE_SIZE;
-       long *inuse;
+       unsigned long *inuse;
        struct net_device *d;
 
        p = strnchr(name, IFNAMSIZ-1, '%');
@@ -774,18 +803,18 @@ int dev_alloc_name(struct net_device *dev, const char *name)
                        return -EINVAL;
 
                /* Use one page as a bit array of possible slots */
-               inuse = (long *) get_zeroed_page(GFP_ATOMIC);
+               inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
                if (!inuse)
                        return -ENOMEM;
 
-               for_each_netdev(d) {
+               for_each_netdev(net, d) {
                        if (!sscanf(d->name, name, &i))
                                continue;
                        if (i < 0 || i >= max_netdevices)
                                continue;
 
                        /*  avoid cases where sscanf is not exact inverse of printf */
-                       snprintf(buf, sizeof(buf), name, i);
+                       snprintf(buf, IFNAMSIZ, name, i);
                        if (!strncmp(buf, d->name, IFNAMSIZ))
                                set_bit(i, inuse);
                }
@@ -794,11 +823,9 @@ int dev_alloc_name(struct net_device *dev, const char *name)
                free_page((unsigned long) inuse);
        }
 
-       snprintf(buf, sizeof(buf), name, i);
-       if (!__dev_get_by_name(buf)) {
-               strlcpy(dev->name, buf, IFNAMSIZ);
+       snprintf(buf, IFNAMSIZ, name, i);
+       if (!__dev_get_by_name(net, buf))
                return i;
-       }
 
        /* It is possible to run out of possible slots
         * when the name is long and there isn't enough space left
@@ -807,6 +834,34 @@ int dev_alloc_name(struct net_device *dev, const char *name)
        return -ENFILE;
 }
 
+/**
+ *     dev_alloc_name - allocate a name for a device
+ *     @dev: device
+ *     @name: name format string
+ *
+ *     Passed a format string - eg "lt%d" it will try and find a suitable
+ *     id. It scans list of devices to build up a free map, then chooses
+ *     the first empty slot. The caller must hold the dev_base or rtnl lock
+ *     while allocating the name and adding the device in order to avoid
+ *     duplicates.
+ *     Limited to bits_per_byte * page size devices (ie 32K on most platforms).
+ *     Returns the number of the unit assigned or a negative errno code.
+ */
+
+int dev_alloc_name(struct net_device *dev, const char *name)
+{
+       char buf[IFNAMSIZ];
+       struct net *net;
+       int ret;
+
+       BUG_ON(!dev_net(dev));
+       net = dev_net(dev);
+       ret = __dev_alloc_name(net, name, buf);
+       if (ret >= 0)
+               strlcpy(dev->name, buf, IFNAMSIZ);
+       return ret;
+}
+
 
 /**
  *     dev_change_name - change name of a device
@@ -821,15 +876,21 @@ int dev_change_name(struct net_device *dev, char *newname)
        char oldname[IFNAMSIZ];
        int err = 0;
        int ret;
+       struct net *net;
 
        ASSERT_RTNL();
+       BUG_ON(!dev_net(dev));
 
+       net = dev_net(dev);
        if (dev->flags & IFF_UP)
                return -EBUSY;
 
        if (!dev_valid_name(newname))
                return -EINVAL;
 
+       if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
+               return 0;
+
        memcpy(oldname, dev->name, IFNAMSIZ);
 
        if (strchr(newname, '%')) {
@@ -838,20 +899,24 @@ int dev_change_name(struct net_device *dev, char *newname)
                        return err;
                strcpy(newname, dev->name);
        }
-       else if (__dev_get_by_name(newname))
+       else if (__dev_get_by_name(net, newname))
                return -EEXIST;
        else
                strlcpy(dev->name, newname, IFNAMSIZ);
 
 rollback:
-       device_rename(&dev->dev, dev->name);
+       err = device_rename(&dev->dev, dev->name);
+       if (err) {
+               memcpy(dev->name, oldname, IFNAMSIZ);
+               return err;
+       }
 
        write_lock_bh(&dev_base_lock);
        hlist_del(&dev->name_hlist);
-       hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name));
+       hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
        write_unlock_bh(&dev_base_lock);
 
-       ret = raw_notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
+       ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev);
        ret = notifier_to_errno(ret);
 
        if (ret) {
@@ -877,7 +942,7 @@ rollback:
  */
 void netdev_features_change(struct net_device *dev)
 {
-       raw_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev);
+       call_netdevice_notifiers(NETDEV_FEAT_CHANGE, dev);
 }
 EXPORT_SYMBOL(netdev_features_change);
 
@@ -892,14 +957,20 @@ EXPORT_SYMBOL(netdev_features_change);
 void netdev_state_change(struct net_device *dev)
 {
        if (dev->flags & IFF_UP) {
-               raw_notifier_call_chain(&netdev_chain,
-                               NETDEV_CHANGE, dev);
+               call_netdevice_notifiers(NETDEV_CHANGE, dev);
                rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
        }
 }
 
+void netdev_bonding_change(struct net_device *dev)
+{
+       call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, dev);
+}
+EXPORT_SYMBOL(netdev_bonding_change);
+
 /**
  *     dev_load        - load a network module
+ *     @net: the applicable net namespace
  *     @name: name of interface
  *
  *     If a network interface is not present and the process has suitable
@@ -907,26 +978,18 @@ void netdev_state_change(struct net_device *dev)
  *     available in this kernel then it becomes a nop.
  */
 
-void dev_load(const char *name)
+void dev_load(struct net *net, const char *name)
 {
        struct net_device *dev;
 
        read_lock(&dev_base_lock);
-       dev = __dev_get_by_name(name);
+       dev = __dev_get_by_name(net, name);
        read_unlock(&dev_base_lock);
 
        if (!dev && capable(CAP_SYS_MODULE))
                request_module("%s", name);
 }
 
-static int default_rebuild_header(struct sk_buff *skb)
-{
-       printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n",
-              skb->dev ? skb->dev->name : "NULL!!!");
-       kfree_skb(skb);
-       return 1;
-}
-
 /**
  *     dev_open        - prepare an interface for use.
  *     @dev:   device to open
@@ -943,6 +1006,8 @@ int dev_open(struct net_device *dev)
 {
        int ret = 0;
 
+       ASSERT_RTNL();
+
        /*
         *      Is it already up?
         */
@@ -960,17 +1025,20 @@ int dev_open(struct net_device *dev)
         *      Call device private open method
         */
        set_bit(__LINK_STATE_START, &dev->state);
-       if (dev->open) {
+
+       if (dev->validate_addr)
+               ret = dev->validate_addr(dev);
+
+       if (!ret && dev->open)
                ret = dev->open(dev);
-               if (ret)
-                       clear_bit(__LINK_STATE_START, &dev->state);
-       }
 
        /*
         *      If it went open OK then:
         */
 
-       if (!ret) {
+       if (ret)
+               clear_bit(__LINK_STATE_START, &dev->state);
+       else {
                /*
                 *      Set the flags.
                 */
@@ -989,8 +1057,9 @@ int dev_open(struct net_device *dev)
                /*
                 *      ... and announce new interface.
                 */
-               raw_notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
+               call_netdevice_notifiers(NETDEV_UP, dev);
        }
+
        return ret;
 }
 
@@ -1005,6 +1074,10 @@ int dev_open(struct net_device *dev)
  */
 int dev_close(struct net_device *dev)
 {
+       ASSERT_RTNL();
+
+       might_sleep();
+
        if (!(dev->flags & IFF_UP))
                return 0;
 
@@ -1012,9 +1085,7 @@ int dev_close(struct net_device *dev)
         *      Tell people we are going down, so that they can
         *      prepare to death, when device is still operating.
         */
-       raw_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
-
-       dev_deactivate(dev);
+       call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);
 
        clear_bit(__LINK_STATE_START, &dev->state);
 
@@ -1026,6 +1097,8 @@ int dev_close(struct net_device *dev)
         */
        smp_mb__after_clear_bit(); /* Commit netif_running(). */
 
+       dev_deactivate(dev);
+
        /*
         *      Call the device specific close. This cannot fail.
         *      Only if device is UP
@@ -1045,12 +1118,37 @@ int dev_close(struct net_device *dev)
        /*
         * Tell people we are down
         */
-       raw_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
+       call_netdevice_notifiers(NETDEV_DOWN, dev);
 
        return 0;
 }
 
 
+/**
+ *     dev_disable_lro - disable Large Receive Offload on a device
+ *     @dev: device
+ *
+ *     Disable Large Receive Offload (LRO) on a net device.  Must be
+ *     called under RTNL.  This is needed if received packets may be
+ *     forwarded to another interface.
+ */
+void dev_disable_lro(struct net_device *dev)
+{
+       if (dev->ethtool_ops && dev->ethtool_ops->get_flags &&
+           dev->ethtool_ops->set_flags) {
+               u32 flags = dev->ethtool_ops->get_flags(dev);
+               if (flags & ETH_FLAG_LRO) {
+                       flags &= ~ETH_FLAG_LRO;
+                       dev->ethtool_ops->set_flags(dev, flags);
+               }
+       }
+       WARN_ON(dev->features & NETIF_F_LRO);
+}
+EXPORT_SYMBOL(dev_disable_lro);
+
+
+static int dev_boot_phase = 1;
+
 /*
  *     Device change register/unregister. These are not inline or static
  *     as we export them to the world.
@@ -1074,23 +1172,27 @@ int register_netdevice_notifier(struct notifier_block *nb)
 {
        struct net_device *dev;
        struct net_device *last;
+       struct net *net;
        int err;
 
        rtnl_lock();
        err = raw_notifier_chain_register(&netdev_chain, nb);
        if (err)
                goto unlock;
+       if (dev_boot_phase)
+               goto unlock;
+       for_each_net(net) {
+               for_each_netdev(net, dev) {
+                       err = nb->notifier_call(nb, NETDEV_REGISTER, dev);
+                       err = notifier_to_errno(err);
+                       if (err)
+                               goto rollback;
+
+                       if (!(dev->flags & IFF_UP))
+                               continue;
 
-       for_each_netdev(dev) {
-               err = nb->notifier_call(nb, NETDEV_REGISTER, dev);
-               err = notifier_to_errno(err);
-               if (err)
-                       goto rollback;
-
-               if (!(dev->flags & IFF_UP))
-                       continue;
-
-               nb->notifier_call(nb, NETDEV_UP, dev);
+                       nb->notifier_call(nb, NETDEV_UP, dev);
+               }
        }
 
 unlock:
@@ -1099,16 +1201,20 @@ unlock:
 
 rollback:
        last = dev;
-       for_each_netdev(dev) {
-               if (dev == last)
-                       break;
+       for_each_net(net) {
+               for_each_netdev(net, dev) {
+                       if (dev == last)
+                               break;
 
-               if (dev->flags & IFF_UP) {
-                       nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
-                       nb->notifier_call(nb, NETDEV_DOWN, dev);
+                       if (dev->flags & IFF_UP) {
+                               nb->notifier_call(nb, NETDEV_GOING_DOWN, dev);
+                               nb->notifier_call(nb, NETDEV_DOWN, dev);
+                       }
+                       nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
                }
-               nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
        }
+
+       raw_notifier_chain_unregister(&netdev_chain, nb);
        goto unlock;
 }
 
@@ -1135,15 +1241,15 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
 /**
  *     call_netdevice_notifiers - call all network notifier blocks
  *      @val: value passed unmodified to notifier function
- *      @v:   pointer passed unmodified to notifier function
+ *      @dev: net_device pointer passed unmodified to notifier function
  *
  *     Call all network notifier blocks.  Parameters and return value
  *     are as for raw_notifier_call_chain().
  */
 
-int call_netdevice_notifiers(unsigned long val, void *v)
+int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
 {
-       return raw_notifier_call_chain(&netdev_chain, val, v);
+       return raw_notifier_call_chain(&netdev_chain, val, dev);
 }
 
 /* When > 0 there are consumers of rx skb time stamps */
@@ -1287,6 +1393,29 @@ void netif_device_attach(struct net_device *dev)
 }
 EXPORT_SYMBOL(netif_device_attach);
 
+static bool can_checksum_protocol(unsigned long features, __be16 protocol)
+{
+       return ((features & NETIF_F_GEN_CSUM) ||
+               ((features & NETIF_F_IP_CSUM) &&
+                protocol == htons(ETH_P_IP)) ||
+               ((features & NETIF_F_IPV6_CSUM) &&
+                protocol == htons(ETH_P_IPV6)));
+}
+
+static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
+{
+       if (can_checksum_protocol(dev->features, skb->protocol))
+               return true;
+
+       if (skb->protocol == htons(ETH_P_8021Q)) {
+               struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
+               if (can_checksum_protocol(dev->features & dev->vlan_features,
+                                         veh->h_vlan_encapsulated_proto))
+                       return true;
+       }
+
+       return false;
+}
 
 /*
  * Invalidate hardware checksum when packet is to be mangled, and
@@ -1305,22 +1434,21 @@ int skb_checksum_help(struct sk_buff *skb)
                goto out_set_summed;
        }
 
-       if (skb_cloned(skb)) {
+       offset = skb->csum_start - skb_headroom(skb);
+       BUG_ON(offset >= skb_headlen(skb));
+       csum = skb_checksum(skb, offset, skb->len - offset, 0);
+
+       offset += skb->csum_offset;
+       BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb));
+
+       if (skb_cloned(skb) &&
+           !skb_clone_writable(skb, offset + sizeof(__sum16))) {
                ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
                if (ret)
                        goto out;
        }
 
-       offset = skb->csum_start - skb_headroom(skb);
-       BUG_ON(offset > (int)skb->len);
-       csum = skb_checksum(skb, offset, skb->len-offset, 0);
-
-       offset = skb_headlen(skb) - offset;
-       BUG_ON(offset <= 0);
-       BUG_ON(skb->csum_offset + 2 > offset);
-
-       *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) =
-               csum_fold(csum);
+       *(__sum16 *)(skb->data + offset) = csum_fold(csum);
 out_set_summed:
        skb->ip_summed = CHECKSUM_NONE;
 out:
@@ -1357,7 +1485,8 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
        }
 
        rcu_read_lock();
-       list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type) & 15], list) {
+       list_for_each_entry_rcu(ptype,
+                       &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
                if (ptype->type == type && !ptype->dev && ptype->gso_segment) {
                        if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
                                err = ptype->gso_send_check(skb);
@@ -1457,7 +1586,7 @@ static int dev_gso_segment(struct sk_buff *skb)
        if (!segs)
                return 0;
 
-       if (unlikely(IS_ERR(segs)))
+       if (IS_ERR(segs))
                return PTR_ERR(segs);
 
        skb->next = segs;
@@ -1497,7 +1626,7 @@ gso:
                        return rc;
                }
                if (unlikely((netif_queue_stopped(dev) ||
-                            netif_subqueue_stopped(dev, skb->queue_mapping)) &&
+                            netif_subqueue_stopped(dev, skb)) &&
                             skb->next))
                        return NETDEV_TX_BUSY;
        } while (skb->next);
@@ -1509,18 +1638,6 @@ out_kfree_skb:
        return 0;
 }
 
-#define HARD_TX_LOCK(dev, cpu) {                       \
-       if ((dev->features & NETIF_F_LLTX) == 0) {      \
-               netif_tx_lock(dev);                     \
-       }                                               \
-}
-
-#define HARD_TX_UNLOCK(dev) {                          \
-       if ((dev->features & NETIF_F_LLTX) == 0) {      \
-               netif_tx_unlock(dev);                   \
-       }                                               \
-}
-
 /**
  *     dev_queue_xmit - transmit a buffer
  *     @skb: buffer to transmit
@@ -1577,14 +1694,8 @@ int dev_queue_xmit(struct sk_buff *skb)
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
                skb_set_transport_header(skb, skb->csum_start -
                                              skb_headroom(skb));
-
-               if (!(dev->features & NETIF_F_GEN_CSUM) &&
-                   !((dev->features & NETIF_F_IP_CSUM) &&
-                     skb->protocol == htons(ETH_P_IP)) &&
-                   !((dev->features & NETIF_F_IPV6_CSUM) &&
-                     skb->protocol == htons(ETH_P_IPV6)))
-                       if (skb_checksum_help(skb))
-                               goto out_kfree_skb;
+               if (!dev_can_checksum(dev, skb) && skb_checksum_help(skb))
+                       goto out_kfree_skb;
        }
 
 gso:
@@ -1617,7 +1728,7 @@ gso:
                q = dev->qdisc;
                if (q->enqueue) {
                        /* reset queue_mapping to zero */
-                       skb->queue_mapping = 0;
+                       skb_set_queue_mapping(skb, 0);
                        rc = q->enqueue(skb, q);
                        qdisc_run(dev);
                        spin_unlock(&dev->queue_lock);
@@ -1648,7 +1759,7 @@ gso:
                        HARD_TX_LOCK(dev, cpu);
 
                        if (!netif_queue_stopped(dev) &&
-                           !netif_subqueue_stopped(dev, skb->queue_mapping)) {
+                           !netif_subqueue_stopped(dev, skb)) {
                                rc = 0;
                                if (!dev_hard_start_xmit(skb, dev)) {
                                        HARD_TX_UNLOCK(dev);
@@ -1702,9 +1813,6 @@ DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
  *
  *     return values:
  *     NET_RX_SUCCESS  (no congestion)
- *     NET_RX_CN_LOW   (low congestion)
- *     NET_RX_CN_MOD   (moderate congestion)
- *     NET_RX_CN_HIGH  (high congestion)
  *     NET_RX_DROP     (packet was dropped)
  *
  */
@@ -1904,30 +2012,69 @@ static int ing_filter(struct sk_buff *skb)
        struct Qdisc *q;
        struct net_device *dev = skb->dev;
        int result = TC_ACT_OK;
+       u32 ttl = G_TC_RTTL(skb->tc_verd);
 
-       if (dev->qdisc_ingress) {
-               __u32 ttl = (__u32) G_TC_RTTL(skb->tc_verd);
-               if (MAX_RED_LOOP < ttl++) {
-                       printk(KERN_WARNING "Redir loop detected Dropping packet (%d->%d)\n",
-                               skb->iif, skb->dev->ifindex);
-                       return TC_ACT_SHOT;
-               }
+       if (MAX_RED_LOOP < ttl++) {
+               printk(KERN_WARNING
+                      "Redir loop detected Dropping packet (%d->%d)\n",
+                      skb->iif, dev->ifindex);
+               return TC_ACT_SHOT;
+       }
 
-               skb->tc_verd = SET_TC_RTTL(skb->tc_verd,ttl);
+       skb->tc_verd = SET_TC_RTTL(skb->tc_verd, ttl);
+       skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS);
 
-               skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_INGRESS);
+       spin_lock(&dev->ingress_lock);
+       if ((q = dev->qdisc_ingress) != NULL)
+               result = q->enqueue(skb, q);
+       spin_unlock(&dev->ingress_lock);
 
-               spin_lock(&dev->ingress_lock);
-               if ((q = dev->qdisc_ingress) != NULL)
-                       result = q->enqueue(skb, q);
-               spin_unlock(&dev->ingress_lock);
+       return result;
+}
 
+static inline struct sk_buff *handle_ing(struct sk_buff *skb,
+                                        struct packet_type **pt_prev,
+                                        int *ret, struct net_device *orig_dev)
+{
+       if (!skb->dev->qdisc_ingress)
+               goto out;
+
+       if (*pt_prev) {
+               *ret = deliver_skb(skb, *pt_prev, orig_dev);
+               *pt_prev = NULL;
+       } else {
+               /* Huh? Why does turning on AF_PACKET affect this? */
+               skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
        }
 
-       return result;
+       switch (ing_filter(skb)) {
+       case TC_ACT_SHOT:
+       case TC_ACT_STOLEN:
+               kfree_skb(skb);
+               return NULL;
+       }
+
+out:
+       skb->tc_verd = 0;
+       return skb;
 }
 #endif
 
+/**
+ *     netif_receive_skb - process receive buffer from network
+ *     @skb: buffer to process
+ *
+ *     netif_receive_skb() is the main receive data processing function.
+ *     It always succeeds. The buffer may be dropped during processing
+ *     for congestion control or by the protocol layers.
+ *
+ *     This function may only be called from softirq context and interrupts
+ *     should be enabled.
+ *
+ *     Return values (usually ignored):
+ *     NET_RX_SUCCESS: no congestion
+ *     NET_RX_DROP: packet was dropped
+ */
 int netif_receive_skb(struct sk_buff *skb)
 {
        struct packet_type *ptype, *pt_prev;
@@ -1960,6 +2107,10 @@ int netif_receive_skb(struct sk_buff *skb)
 
        rcu_read_lock();
 
+       /* Don't receive packets in an exiting network namespace */
+       if (!net_alive(dev_net(skb->dev)))
+               goto out;
+
 #ifdef CONFIG_NET_CLS_ACT
        if (skb->tc_verd & TC_NCLS) {
                skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
@@ -1976,21 +2127,9 @@ int netif_receive_skb(struct sk_buff *skb)
        }
 
 #ifdef CONFIG_NET_CLS_ACT
-       if (pt_prev) {
-               ret = deliver_skb(skb, pt_prev, orig_dev);
-               pt_prev = NULL; /* noone else should process this after*/
-       } else {
-               skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
-       }
-
-       ret = ing_filter(skb);
-
-       if (ret == TC_ACT_SHOT || (ret == TC_ACT_STOLEN)) {
-               kfree_skb(skb);
+       skb = handle_ing(skb, &pt_prev, &ret, orig_dev);
+       if (!skb)
                goto out;
-       }
-
-       skb->tc_verd = 0;
 ncls:
 #endif
 
@@ -2002,7 +2141,8 @@ ncls:
                goto out;
 
        type = skb->protocol;
-       list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type)&15], list) {
+       list_for_each_entry_rcu(ptype,
+                       &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
                if (ptype->type == type &&
                    (!ptype->dev || ptype->dev == skb->dev)) {
                        if (pt_prev)
@@ -2059,11 +2199,11 @@ static int process_backlog(struct napi_struct *napi, int quota)
 
 /**
  * __napi_schedule - schedule for receive
- * @napi: entry to schedule
+ * @n: entry to schedule
  *
  * The entry's receive function will be scheduled to run
  */
-void fastcall __napi_schedule(struct napi_struct *n)
+void __napi_schedule(struct napi_struct *n)
 {
        unsigned long flags;
 
@@ -2111,7 +2251,15 @@ static void net_rx_action(struct softirq_action *h)
 
                weight = n->weight;
 
-               work = n->poll(n, weight);
+               /* This NAPI_STATE_SCHED test is for avoiding a race
+                * with netpoll's poll_napi().  Only the entity which
+                * obtains the lock and sees NAPI_STATE_SCHED set will
+                * actually make the ->poll() call.  Therefore we avoid
+                * accidently calling ->poll() when NAPI is not scheduled.
+                */
+               work = 0;
+               if (test_bit(NAPI_STATE_SCHED, &n->state))
+                       work = n->poll(n, weight);
 
                WARN_ON_ONCE(work > weight);
 
@@ -2124,8 +2272,12 @@ static void net_rx_action(struct softirq_action *h)
                 * still "owns" the NAPI instance and therefore can
                 * move the instance around on the list at-will.
                 */
-               if (unlikely(work == weight))
-                       list_move_tail(&n->poll_list, list);
+               if (unlikely(work == weight)) {
+                       if (unlikely(napi_disable_pending(n)))
+                               __napi_complete(n);
+                       else
+                               list_move_tail(&n->poll_list, list);
+               }
 
                netpoll_poll_unlock(have);
        }
@@ -2186,7 +2338,7 @@ int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
  *     match.  --pb
  */
 
-static int dev_ifname(struct ifreq __user *arg)
+static int dev_ifname(struct net *net, struct ifreq __user *arg)
 {
        struct net_device *dev;
        struct ifreq ifr;
@@ -2199,7 +2351,7 @@ static int dev_ifname(struct ifreq __user *arg)
                return -EFAULT;
 
        read_lock(&dev_base_lock);
-       dev = __dev_get_by_index(ifr.ifr_ifindex);
+       dev = __dev_get_by_index(net, ifr.ifr_ifindex);
        if (!dev) {
                read_unlock(&dev_base_lock);
                return -ENODEV;
@@ -2219,7 +2371,7 @@ static int dev_ifname(struct ifreq __user *arg)
  *     Thus we will need a 'compatibility mode'.
  */
 
-static int dev_ifconf(char __user *arg)
+static int dev_ifconf(struct net *net, char __user *arg)
 {
        struct ifconf ifc;
        struct net_device *dev;
@@ -2243,7 +2395,7 @@ static int dev_ifconf(char __user *arg)
         */
 
        total = 0;
-       for_each_netdev(dev) {
+       for_each_netdev(net, dev) {
                for (i = 0; i < NPROTO; i++) {
                        if (gifconf_list[i]) {
                                int done;
@@ -2276,7 +2428,9 @@ static int dev_ifconf(char __user *arg)
  *     in detail.
  */
 void *dev_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(dev_base_lock)
 {
+       struct net *net = seq_file_net(seq);
        loff_t off;
        struct net_device *dev;
 
@@ -2285,7 +2439,7 @@ void *dev_seq_start(struct seq_file *seq, loff_t *pos)
                return SEQ_START_TOKEN;
 
        off = 1;
-       for_each_netdev(dev)
+       for_each_netdev(net, dev)
                if (off++ == *pos)
                        return dev;
 
@@ -2294,12 +2448,14 @@ void *dev_seq_start(struct seq_file *seq, loff_t *pos)
 
 void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
+       struct net *net = seq_file_net(seq);
        ++*pos;
        return v == SEQ_START_TOKEN ?
-               first_net_device() : next_net_device((struct net_device *)v);
+               first_net_device(net) : next_net_device((struct net_device *)v);
 }
 
 void dev_seq_stop(struct seq_file *seq, void *v)
+       __releases(dev_base_lock)
 {
        read_unlock(&dev_base_lock);
 }
@@ -2348,7 +2504,7 @@ static struct netif_rx_stats *softnet_get_online(loff_t *pos)
 {
        struct netif_rx_stats *rc = NULL;
 
-       while (*pos < NR_CPUS)
+       while (*pos < nr_cpu_ids)
                if (cpu_online(*pos)) {
                        rc = &per_cpu(netdev_rx_stat, *pos);
                        break;
@@ -2392,7 +2548,8 @@ static const struct seq_operations dev_seq_ops = {
 
 static int dev_seq_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &dev_seq_ops);
+       return seq_open_net(inode, file, &dev_seq_ops,
+                           sizeof(struct seq_net_private));
 }
 
 static const struct file_operations dev_seq_fops = {
@@ -2400,7 +2557,7 @@ static const struct file_operations dev_seq_fops = {
        .open    = dev_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = seq_release,
+       .release = seq_release_net,
 };
 
 static const struct seq_operations softnet_seq_ops = {
@@ -2435,7 +2592,7 @@ static void *ptype_get_idx(loff_t pos)
                ++i;
        }
 
-       for (t = 0; t < 16; t++) {
+       for (t = 0; t < PTYPE_HASH_SIZE; t++) {
                list_for_each_entry_rcu(pt, &ptype_base[t], list) {
                        if (i == pos)
                                return pt;
@@ -2446,6 +2603,7 @@ static void *ptype_get_idx(loff_t pos)
 }
 
 static void *ptype_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(RCU)
 {
        rcu_read_lock();
        return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN;
@@ -2469,10 +2627,10 @@ static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos)
                hash = 0;
                nxt = ptype_base[0].next;
        } else
-               hash = ntohs(pt->type) & 15;
+               hash = ntohs(pt->type) & PTYPE_HASH_MASK;
 
        while (nxt == &ptype_base[hash]) {
-               if (++hash >= 16)
+               if (++hash >= PTYPE_HASH_SIZE)
                        return NULL;
                nxt = ptype_base[hash].next;
        }
@@ -2481,6 +2639,7 @@ found:
 }
 
 static void ptype_seq_stop(struct seq_file *seq, void *v)
+       __releases(RCU)
 {
        rcu_read_unlock();
 }
@@ -2516,7 +2675,7 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
 
        if (v == SEQ_START_TOKEN)
                seq_puts(seq, "Type Device      Function\n");
-       else {
+       else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) {
                if (pt->type == htons(ETH_P_ALL))
                        seq_puts(seq, "ALL ");
                else
@@ -2540,7 +2699,8 @@ static const struct seq_operations ptype_seq_ops = {
 
 static int ptype_seq_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &ptype_seq_ops);
+       return seq_open_net(inode, file, &ptype_seq_ops,
+                       sizeof(struct seq_net_private));
 }
 
 static const struct file_operations ptype_seq_fops = {
@@ -2548,34 +2708,53 @@ static const struct file_operations ptype_seq_fops = {
        .open    = ptype_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = seq_release,
+       .release = seq_release_net,
 };
 
 
-static int __init dev_proc_init(void)
+static int __net_init dev_proc_net_init(struct net *net)
 {
        int rc = -ENOMEM;
 
-       if (!proc_net_fops_create("dev", S_IRUGO, &dev_seq_fops))
+       if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops))
                goto out;
-       if (!proc_net_fops_create("softnet_stat", S_IRUGO, &softnet_seq_fops))
+       if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops))
                goto out_dev;
-       if (!proc_net_fops_create("ptype", S_IRUGO, &ptype_seq_fops))
-               goto out_dev2;
-
-       if (wext_proc_init())
+       if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops))
                goto out_softnet;
+
+       if (wext_proc_init(net))
+               goto out_ptype;
        rc = 0;
 out:
        return rc;
+out_ptype:
+       proc_net_remove(net, "ptype");
 out_softnet:
-       proc_net_remove("ptype");
-out_dev2:
-       proc_net_remove("softnet_stat");
+       proc_net_remove(net, "softnet_stat");
 out_dev:
-       proc_net_remove("dev");
+       proc_net_remove(net, "dev");
        goto out;
 }
+
+static void __net_exit dev_proc_net_exit(struct net *net)
+{
+       wext_proc_exit(net);
+
+       proc_net_remove(net, "ptype");
+       proc_net_remove(net, "softnet_stat");
+       proc_net_remove(net, "dev");
+}
+
+static struct pernet_operations __net_initdata dev_proc_ops = {
+       .init = dev_proc_net_init,
+       .exit = dev_proc_net_exit,
+};
+
+static int __init dev_proc_init(void)
+{
+       return register_pernet_subsys(&dev_proc_ops);
+}
 #else
 #define dev_proc_init() 0
 #endif /* CONFIG_PROC_FS */
@@ -2620,30 +2799,47 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
        return 0;
 }
 
-static void __dev_set_promiscuity(struct net_device *dev, int inc)
+static int __dev_set_promiscuity(struct net_device *dev, int inc)
 {
        unsigned short old_flags = dev->flags;
 
        ASSERT_RTNL();
 
-       if ((dev->promiscuity += inc) == 0)
-               dev->flags &= ~IFF_PROMISC;
-       else
-               dev->flags |= IFF_PROMISC;
+       dev->flags |= IFF_PROMISC;
+       dev->promiscuity += inc;
+       if (dev->promiscuity == 0) {
+               /*
+                * Avoid overflow.
+                * If inc causes overflow, untouch promisc and return error.
+                */
+               if (inc < 0)
+                       dev->flags &= ~IFF_PROMISC;
+               else {
+                       dev->promiscuity -= inc;
+                       printk(KERN_WARNING "%s: promiscuity touches roof, "
+                               "set promiscuity failed, promiscuity feature "
+                               "of device might be broken.\n", dev->name);
+                       return -EOVERFLOW;
+               }
+       }
        if (dev->flags != old_flags) {
                printk(KERN_INFO "device %s %s promiscuous mode\n",
                       dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
                                                               "left");
-               audit_log(current->audit_context, GFP_ATOMIC,
-                       AUDIT_ANOM_PROMISCUOUS,
-                       "dev=%s prom=%d old_prom=%d auid=%u",
-                       dev->name, (dev->flags & IFF_PROMISC),
-                       (old_flags & IFF_PROMISC),
-                       audit_get_loginuid(current->audit_context));
+               if (audit_enabled)
+                       audit_log(current->audit_context, GFP_ATOMIC,
+                               AUDIT_ANOM_PROMISCUOUS,
+                               "dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u",
+                               dev->name, (dev->flags & IFF_PROMISC),
+                               (old_flags & IFF_PROMISC),
+                               audit_get_loginuid(current),
+                               current->uid, current->gid,
+                               audit_get_sessionid(current));
 
                if (dev->change_rx_flags)
                        dev->change_rx_flags(dev, IFF_PROMISC);
        }
+       return 0;
 }
 
 /**
@@ -2655,14 +2851,19 @@ static void __dev_set_promiscuity(struct net_device *dev, int inc)
  *     remains above zero the interface remains promiscuous. Once it hits zero
  *     the device reverts back to normal filtering operation. A negative inc
  *     value is used to drop promiscuity on the device.
+ *     Return 0 if successful or a negative errno code on error.
  */
-void dev_set_promiscuity(struct net_device *dev, int inc)
+int dev_set_promiscuity(struct net_device *dev, int inc)
 {
        unsigned short old_flags = dev->flags;
+       int err;
 
-       __dev_set_promiscuity(dev, inc);
+       err = __dev_set_promiscuity(dev, inc);
+       if (err < 0)
+               return err;
        if (dev->flags != old_flags)
                dev_set_rx_mode(dev);
+       return err;
 }
 
 /**
@@ -2675,28 +2876,44 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
  *     to all interfaces. Once it hits zero the device reverts back to normal
  *     filtering operation. A negative @inc value is used to drop the counter
  *     when releasing a resource needing all multicasts.
+ *     Return 0 if successful or a negative errno code on error.
  */
 
-void dev_set_allmulti(struct net_device *dev, int inc)
+int dev_set_allmulti(struct net_device *dev, int inc)
 {
        unsigned short old_flags = dev->flags;
 
        ASSERT_RTNL();
 
        dev->flags |= IFF_ALLMULTI;
-       if ((dev->allmulti += inc) == 0)
-               dev->flags &= ~IFF_ALLMULTI;
+       dev->allmulti += inc;
+       if (dev->allmulti == 0) {
+               /*
+                * Avoid overflow.
+                * If inc causes overflow, untouch allmulti and return error.
+                */
+               if (inc < 0)
+                       dev->flags &= ~IFF_ALLMULTI;
+               else {
+                       dev->allmulti -= inc;
+                       printk(KERN_WARNING "%s: allmulti touches roof, "
+                               "set allmulti failed, allmulti feature of "
+                               "device might be broken.\n", dev->name);
+                       return -EOVERFLOW;
+               }
+       }
        if (dev->flags ^ old_flags) {
                if (dev->change_rx_flags)
                        dev->change_rx_flags(dev, IFF_ALLMULTI);
                dev_set_rx_mode(dev);
        }
+       return 0;
 }
 
 /*
  *     Upload unicast and multicast address lists to device and
  *     configure RX filtering. When the device doesn't support unicast
- *     filtering it is put in promiscous mode while unicast addresses
+ *     filtering it is put in promiscuous mode while unicast addresses
  *     are present.
  */
 void __dev_set_rx_mode(struct net_device *dev)
@@ -2779,7 +2996,7 @@ int __dev_addr_add(struct dev_addr_list **list, int *count,
                }
        }
 
-       da = kmalloc(sizeof(*da), GFP_ATOMIC);
+       da = kzalloc(sizeof(*da), GFP_ATOMIC);
        if (da == NULL)
                return -ENOMEM;
        memcpy(da->da_addr, addr, alen);
@@ -2821,7 +3038,7 @@ EXPORT_SYMBOL(dev_unicast_delete);
 /**
  *     dev_unicast_add         - add a secondary unicast address
  *     @dev: device
- *     @addr: address to delete
+ *     @addr: address to add
  *     @alen: length of @addr
  *
  *     Add a secondary unicast address to the device or increase
@@ -2844,6 +3061,101 @@ int dev_unicast_add(struct net_device *dev, void *addr, int alen)
 }
 EXPORT_SYMBOL(dev_unicast_add);
 
+int __dev_addr_sync(struct dev_addr_list **to, int *to_count,
+                   struct dev_addr_list **from, int *from_count)
+{
+       struct dev_addr_list *da, *next;
+       int err = 0;
+
+       da = *from;
+       while (da != NULL) {
+               next = da->next;
+               if (!da->da_synced) {
+                       err = __dev_addr_add(to, to_count,
+                                            da->da_addr, da->da_addrlen, 0);
+                       if (err < 0)
+                               break;
+                       da->da_synced = 1;
+                       da->da_users++;
+               } else if (da->da_users == 1) {
+                       __dev_addr_delete(to, to_count,
+                                         da->da_addr, da->da_addrlen, 0);
+                       __dev_addr_delete(from, from_count,
+                                         da->da_addr, da->da_addrlen, 0);
+               }
+               da = next;
+       }
+       return err;
+}
+
+void __dev_addr_unsync(struct dev_addr_list **to, int *to_count,
+                      struct dev_addr_list **from, int *from_count)
+{
+       struct dev_addr_list *da, *next;
+
+       da = *from;
+       while (da != NULL) {
+               next = da->next;
+               if (da->da_synced) {
+                       __dev_addr_delete(to, to_count,
+                                         da->da_addr, da->da_addrlen, 0);
+                       da->da_synced = 0;
+                       __dev_addr_delete(from, from_count,
+                                         da->da_addr, da->da_addrlen, 0);
+               }
+               da = next;
+       }
+}
+
+/**
+ *     dev_unicast_sync - Synchronize device's unicast list to another device
+ *     @to: destination device
+ *     @from: source device
+ *
+ *     Add newly added addresses to the destination device and release
+ *     addresses that have no users left. The source device must be
+ *     locked by netif_tx_lock_bh.
+ *
+ *     This function is intended to be called from the dev->set_rx_mode
+ *     function of layered software devices.
+ */
+int dev_unicast_sync(struct net_device *to, struct net_device *from)
+{
+       int err = 0;
+
+       netif_tx_lock_bh(to);
+       err = __dev_addr_sync(&to->uc_list, &to->uc_count,
+                             &from->uc_list, &from->uc_count);
+       if (!err)
+               __dev_set_rx_mode(to);
+       netif_tx_unlock_bh(to);
+       return err;
+}
+EXPORT_SYMBOL(dev_unicast_sync);
+
+/**
+ *     dev_unicast_unsync - Remove synchronized addresses from the destination device
+ *     @to: destination device
+ *     @from: source device
+ *
+ *     Remove all addresses that were added to the destination device by
+ *     dev_unicast_sync(). This function is intended to be called from the
+ *     dev->stop function of layered software devices.
+ */
+void dev_unicast_unsync(struct net_device *to, struct net_device *from)
+{
+       netif_tx_lock_bh(from);
+       netif_tx_lock_bh(to);
+
+       __dev_addr_unsync(&to->uc_list, &to->uc_count,
+                         &from->uc_list, &from->uc_count);
+       __dev_set_rx_mode(to);
+
+       netif_tx_unlock_bh(to);
+       netif_tx_unlock_bh(from);
+}
+EXPORT_SYMBOL(dev_unicast_unsync);
+
 static void __dev_addr_discard(struct dev_addr_list **list)
 {
        struct dev_addr_list *tmp;
@@ -2916,7 +3228,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
         *      Load in the correct multicast list now the flags have changed.
         */
 
-       if (dev->change_rx_flags && (dev->flags ^ flags) & IFF_MULTICAST)
+       if (dev->change_rx_flags && (old_flags ^ flags) & IFF_MULTICAST)
                dev->change_rx_flags(dev, IFF_MULTICAST);
 
        dev_set_rx_mode(dev);
@@ -2938,8 +3250,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
        if (dev->flags & IFF_UP &&
            ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
                                          IFF_VOLATILE)))
-               raw_notifier_call_chain(&netdev_chain,
-                               NETDEV_CHANGE, dev);
+               call_netdevice_notifiers(NETDEV_CHANGE, dev);
 
        if ((flags ^ dev->gflags) & IFF_PROMISC) {
                int inc = (flags & IFF_PROMISC) ? +1 : -1;
@@ -2985,8 +3296,7 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
        else
                dev->mtu = new_mtu;
        if (!err && dev->flags & IFF_UP)
-               raw_notifier_call_chain(&netdev_chain,
-                               NETDEV_CHANGEMTU, dev);
+               call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
        return err;
 }
 
@@ -3002,18 +3312,17 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
                return -ENODEV;
        err = dev->set_mac_address(dev, sa);
        if (!err)
-               raw_notifier_call_chain(&netdev_chain,
-                               NETDEV_CHANGEADDR, dev);
+               call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
        return err;
 }
 
 /*
- *     Perform the SIOCxIFxxx calls.
+ *     Perform the SIOCxIFxxx calls, inside read_lock(dev_base_lock)
  */
-static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
+static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd)
 {
        int err;
-       struct net_device *dev = __dev_get_by_name(ifr->ifr_name);
+       struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
 
        if (!dev)
                return -ENODEV;
@@ -3023,25 +3332,15 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                        ifr->ifr_flags = dev_get_flags(dev);
                        return 0;
 
-               case SIOCSIFFLAGS:      /* Set interface flags */
-                       return dev_change_flags(dev, ifr->ifr_flags);
-
                case SIOCGIFMETRIC:     /* Get the metric on the interface
                                           (currently unused) */
                        ifr->ifr_metric = 0;
                        return 0;
 
-               case SIOCSIFMETRIC:     /* Set the metric on the interface
-                                          (currently unused) */
-                       return -EOPNOTSUPP;
-
                case SIOCGIFMTU:        /* Get the MTU of a device */
                        ifr->ifr_mtu = dev->mtu;
                        return 0;
 
-               case SIOCSIFMTU:        /* Set the MTU of a device */
-                       return dev_set_mtu(dev, ifr->ifr_mtu);
-
                case SIOCGIFHWADDR:
                        if (!dev->addr_len)
                                memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data);
@@ -3051,17 +3350,9 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                        ifr->ifr_hwaddr.sa_family = dev->type;
                        return 0;
 
-               case SIOCSIFHWADDR:
-                       return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
-
-               case SIOCSIFHWBROADCAST:
-                       if (ifr->ifr_hwaddr.sa_family != dev->type)
-                               return -EINVAL;
-                       memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
-                              min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
-                       raw_notifier_call_chain(&netdev_chain,
-                                           NETDEV_CHANGEADDR, dev);
-                       return 0;
+               case SIOCGIFSLAVE:
+                       err = -EINVAL;
+                       break;
 
                case SIOCGIFMAP:
                        ifr->ifr_map.mem_start = dev->mem_start;
@@ -3072,6 +3363,59 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                        ifr->ifr_map.port      = dev->if_port;
                        return 0;
 
+               case SIOCGIFINDEX:
+                       ifr->ifr_ifindex = dev->ifindex;
+                       return 0;
+
+               case SIOCGIFTXQLEN:
+                       ifr->ifr_qlen = dev->tx_queue_len;
+                       return 0;
+
+               default:
+                       /* dev_ioctl() should ensure this case
+                        * is never reached
+                        */
+                       WARN_ON(1);
+                       err = -EINVAL;
+                       break;
+
+       }
+       return err;
+}
+
+/*
+ *     Perform the SIOCxIFxxx calls, inside rtnl_lock()
+ */
+static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
+{
+       int err;
+       struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
+
+       if (!dev)
+               return -ENODEV;
+
+       switch (cmd) {
+               case SIOCSIFFLAGS:      /* Set interface flags */
+                       return dev_change_flags(dev, ifr->ifr_flags);
+
+               case SIOCSIFMETRIC:     /* Set the metric on the interface
+                                          (currently unused) */
+                       return -EOPNOTSUPP;
+
+               case SIOCSIFMTU:        /* Set the MTU of a device */
+                       return dev_set_mtu(dev, ifr->ifr_mtu);
+
+               case SIOCSIFHWADDR:
+                       return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
+
+               case SIOCSIFHWBROADCAST:
+                       if (ifr->ifr_hwaddr.sa_family != dev->type)
+                               return -EINVAL;
+                       memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
+                              min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
+                       call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
+                       return 0;
+
                case SIOCSIFMAP:
                        if (dev->set_config) {
                                if (!netif_device_present(dev))
@@ -3081,7 +3425,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                        return -EOPNOTSUPP;
 
                case SIOCADDMULTI:
-                       if (!dev->set_multicast_list ||
+                       if ((!dev->set_multicast_list && !dev->set_rx_mode) ||
                            ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
                                return -EINVAL;
                        if (!netif_device_present(dev))
@@ -3090,7 +3434,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                                          dev->addr_len, 1);
 
                case SIOCDELMULTI:
-                       if (!dev->set_multicast_list ||
+                       if ((!dev->set_multicast_list && !dev->set_rx_mode) ||
                            ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
                                return -EINVAL;
                        if (!netif_device_present(dev))
@@ -3098,14 +3442,6 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
                        return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data,
                                             dev->addr_len, 1);
 
-               case SIOCGIFINDEX:
-                       ifr->ifr_ifindex = dev->ifindex;
-                       return 0;
-
-               case SIOCGIFTXQLEN:
-                       ifr->ifr_qlen = dev->tx_queue_len;
-                       return 0;
-
                case SIOCSIFTXQLEN:
                        if (ifr->ifr_qlen < 0)
                                return -EINVAL;
@@ -3157,6 +3493,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
 
 /**
  *     dev_ioctl       -       network device ioctl
+ *     @net: the applicable net namespace
  *     @cmd: command to issue
  *     @arg: pointer to a struct ifreq in user space
  *
@@ -3166,7 +3503,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
  *     positive or a negative errno code on error.
  */
 
-int dev_ioctl(unsigned int cmd, void __user *arg)
+int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
 {
        struct ifreq ifr;
        int ret;
@@ -3179,12 +3516,12 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
 
        if (cmd == SIOCGIFCONF) {
                rtnl_lock();
-               ret = dev_ifconf((char __user *) arg);
+               ret = dev_ifconf(net, (char __user *) arg);
                rtnl_unlock();
                return ret;
        }
        if (cmd == SIOCGIFNAME)
-               return dev_ifname((struct ifreq __user *)arg);
+               return dev_ifname(net, (struct ifreq __user *)arg);
 
        if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
                return -EFAULT;
@@ -3214,9 +3551,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                case SIOCGIFMAP:
                case SIOCGIFINDEX:
                case SIOCGIFTXQLEN:
-                       dev_load(ifr.ifr_name);
+                       dev_load(net, ifr.ifr_name);
                        read_lock(&dev_base_lock);
-                       ret = dev_ifsioc(&ifr, cmd);
+                       ret = dev_ifsioc_locked(net, &ifr, cmd);
                        read_unlock(&dev_base_lock);
                        if (!ret) {
                                if (colon)
@@ -3228,9 +3565,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                        return ret;
 
                case SIOCETHTOOL:
-                       dev_load(ifr.ifr_name);
+                       dev_load(net, ifr.ifr_name);
                        rtnl_lock();
-                       ret = dev_ethtool(&ifr);
+                       ret = dev_ethtool(net, &ifr);
                        rtnl_unlock();
                        if (!ret) {
                                if (colon)
@@ -3252,9 +3589,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                case SIOCSIFNAME:
                        if (!capable(CAP_NET_ADMIN))
                                return -EPERM;
-                       dev_load(ifr.ifr_name);
+                       dev_load(net, ifr.ifr_name);
                        rtnl_lock();
-                       ret = dev_ifsioc(&ifr, cmd);
+                       ret = dev_ifsioc(net, &ifr, cmd);
                        rtnl_unlock();
                        if (!ret) {
                                if (colon)
@@ -3293,9 +3630,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                        /* fall through */
                case SIOCBONDSLAVEINFOQUERY:
                case SIOCBONDINFOQUERY:
-                       dev_load(ifr.ifr_name);
+                       dev_load(net, ifr.ifr_name);
                        rtnl_lock();
-                       ret = dev_ifsioc(&ifr, cmd);
+                       ret = dev_ifsioc(net, &ifr, cmd);
                        rtnl_unlock();
                        return ret;
 
@@ -3315,9 +3652,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                        if (cmd == SIOCWANDEV ||
                            (cmd >= SIOCDEVPRIVATE &&
                             cmd <= SIOCDEVPRIVATE + 15)) {
-                               dev_load(ifr.ifr_name);
+                               dev_load(net, ifr.ifr_name);
                                rtnl_lock();
-                               ret = dev_ifsioc(&ifr, cmd);
+                               ret = dev_ifsioc(net, &ifr, cmd);
                                rtnl_unlock();
                                if (!ret && copy_to_user(arg, &ifr,
                                                         sizeof(struct ifreq)))
@@ -3326,7 +3663,7 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                        }
                        /* Take care of Wireless Extensions */
                        if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
-                               return wext_handle_ioctl(&ifr, cmd, arg);
+                               return wext_handle_ioctl(net, &ifr, cmd, arg);
                        return -EINVAL;
        }
 }
@@ -3334,27 +3671,26 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
 
 /**
  *     dev_new_index   -       allocate an ifindex
+ *     @net: the applicable net namespace
  *
  *     Returns a suitable unique value for a new device interface
  *     number.  The caller must hold the rtnl semaphore or the
  *     dev_base_lock to be sure it remains unique.
  */
-static int dev_new_index(void)
+static int dev_new_index(struct net *net)
 {
        static int ifindex;
        for (;;) {
                if (++ifindex <= 0)
                        ifindex = 1;
-               if (!__dev_get_by_index(ifindex))
+               if (!__dev_get_by_index(net, ifindex))
                        return ifindex;
        }
 }
 
-static int dev_boot_phase = 1;
-
 /* Delayed registration/unregisteration */
 static DEFINE_SPINLOCK(net_todo_list_lock);
-static struct list_head net_todo_list = LIST_HEAD_INIT(net_todo_list);
+static LIST_HEAD(net_todo_list);
 
 static void net_set_todo(struct net_device *dev)
 {
@@ -3363,6 +3699,60 @@ static void net_set_todo(struct net_device *dev)
        spin_unlock(&net_todo_list_lock);
 }
 
+static void rollback_registered(struct net_device *dev)
+{
+       BUG_ON(dev_boot_phase);
+       ASSERT_RTNL();
+
+       /* Some devices call without registering for initialization unwind. */
+       if (dev->reg_state == NETREG_UNINITIALIZED) {
+               printk(KERN_DEBUG "unregister_netdevice: device %s/%p never "
+                                 "was registered\n", dev->name, dev);
+
+               WARN_ON(1);
+               return;
+       }
+
+       BUG_ON(dev->reg_state != NETREG_REGISTERED);
+
+       /* If device is running, close it first. */
+       dev_close(dev);
+
+       /* And unlink it from device chain. */
+       unlist_netdevice(dev);
+
+       dev->reg_state = NETREG_UNREGISTERING;
+
+       synchronize_net();
+
+       /* Shutdown queueing discipline. */
+       dev_shutdown(dev);
+
+
+       /* Notify protocols, that we are about to destroy
+          this device. They should clean all the things.
+       */
+       call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
+
+       /*
+        *      Flush the unicast and multicast chains
+        */
+       dev_addr_discard(dev);
+
+       if (dev->uninit)
+               dev->uninit(dev);
+
+       /* Notifier chain MUST detach us from master device. */
+       BUG_TRAP(!dev->master);
+
+       /* Remove entries from kobject tree */
+       netdev_unregister_kobject(dev);
+
+       synchronize_net();
+
+       dev_put(dev);
+}
+
 /**
  *     register_netdevice      - register a network device
  *     @dev: device to register
@@ -3385,6 +3775,7 @@ int register_netdevice(struct net_device *dev)
        struct hlist_head *head;
        struct hlist_node *p;
        int ret;
+       struct net *net;
 
        BUG_ON(dev_boot_phase);
        ASSERT_RTNL();
@@ -3393,6 +3784,8 @@ int register_netdevice(struct net_device *dev)
 
        /* When net_device's are persistent, this will be fatal. */
        BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
+       BUG_ON(!dev_net(dev));
+       net = dev_net(dev);
 
        spin_lock_init(&dev->queue_lock);
        spin_lock_init(&dev->_xmit_lock);
@@ -3417,12 +3810,12 @@ int register_netdevice(struct net_device *dev)
                goto err_uninit;
        }
 
-       dev->ifindex = dev_new_index();
+       dev->ifindex = dev_new_index(net);
        if (dev->iflink == -1)
                dev->iflink = dev->ifindex;
 
        /* Check for existence of name */
-       head = dev_name_hash(dev->name);
+       head = dev_name_hash(net, dev->name);
        hlist_for_each(p, head) {
                struct net_device *d
                        = hlist_entry(p, struct net_device, name_hlist);
@@ -3478,15 +3871,8 @@ int register_netdevice(struct net_device *dev)
                }
        }
 
-       /*
-        *      nil rebuild_header routine,
-        *      that should be never called and used as just bug trap.
-        */
-
-       if (!dev->rebuild_header)
-               dev->rebuild_header = default_rebuild_header;
-
-       ret = netdev_register_sysfs(dev);
+       netdev_initialize_kobject(dev);
+       ret = netdev_register_kobject(dev);
        if (ret)
                goto err_uninit;
        dev->reg_state = NETREG_REGISTERED;
@@ -3499,18 +3885,16 @@ int register_netdevice(struct net_device *dev)
        set_bit(__LINK_STATE_PRESENT, &dev->state);
 
        dev_init_scheduler(dev);
-       write_lock_bh(&dev_base_lock);
-       list_add_tail(&dev->dev_list, &dev_base_head);
-       hlist_add_head(&dev->name_hlist, head);
-       hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
        dev_hold(dev);
-       write_unlock_bh(&dev_base_lock);
+       list_netdevice(dev);
 
        /* Notify protocols, that a new device appeared. */
-       ret = raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
+       ret = call_netdevice_notifiers(NETDEV_REGISTER, dev);
        ret = notifier_to_errno(ret);
-       if (ret)
-               unregister_netdevice(dev);
+       if (ret) {
+               rollback_registered(dev);
+               dev->reg_state = NETREG_UNREGISTERED;
+       }
 
 out:
        return ret;
@@ -3578,8 +3962,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
                        rtnl_lock();
 
                        /* Rebroadcast unregister notification */
-                       raw_notifier_call_chain(&netdev_chain,
-                                           NETDEV_UNREGISTER, dev);
+                       call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 
                        if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
                                     &dev->state)) {
@@ -3709,11 +4092,15 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 
        BUG_ON(strlen(name) >= sizeof(dev->name));
 
-       /* ensure 32-byte alignment of both the device and private area */
-       alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
-                    (sizeof(struct net_device_subqueue) * (queue_count - 1))) &
-                    ~NETDEV_ALIGN_CONST;
-       alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
+       alloc_size = sizeof(struct net_device) +
+                    sizeof(struct net_device_subqueue) * (queue_count - 1);
+       if (sizeof_priv) {
+               /* ensure 32-byte alignment of private area */
+               alloc_size = (alloc_size + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
+               alloc_size += sizeof_priv;
+       }
+       /* ensure 32-byte alignment of whole construct */
+       alloc_size += NETDEV_ALIGN_CONST;
 
        p = kzalloc(alloc_size, GFP_KERNEL);
        if (!p) {
@@ -3724,6 +4111,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
        dev = (struct net_device *)
                (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
        dev->padded = (char *)dev - (char *)p;
+       dev_net_set(dev, &init_net);
 
        if (sizeof_priv) {
                dev->priv = ((char *)dev +
@@ -3734,6 +4122,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
        }
 
        dev->egress_subqueue_count = queue_count;
+       dev->gso_max_size = GSO_MAX_SIZE;
 
        dev->get_stats = internal_stats;
        netpoll_netdev_init(dev);
@@ -3753,7 +4142,8 @@ EXPORT_SYMBOL(alloc_netdev_mq);
  */
 void free_netdev(struct net_device *dev)
 {
-#ifdef CONFIG_SYSFS
+       release_net(dev_net(dev));
+
        /*  Compatibility with error handling in drivers */
        if (dev->reg_state == NETREG_UNINITIALIZED) {
                kfree((char *)dev - dev->padded);
@@ -3765,9 +4155,6 @@ void free_netdev(struct net_device *dev)
 
        /* will free via device release */
        put_device(&dev->dev);
-#else
-       kfree((char *)dev - dev->padded);
-#endif
 }
 
 /* Synchronize with packet receive processing. */
@@ -3782,8 +4169,7 @@ void synchronize_net(void)
  *     @dev: device
  *
  *     This function shuts down a device interface and removes it
- *     from the kernel tables. On success 0 is returned, on a failure
- *     a negative errno code is returned.
+ *     from the kernel tables.
  *
  *     Callers must hold the rtnl semaphore.  You may want
  *     unregister_netdev() instead of this.
@@ -3791,87 +4177,149 @@ void synchronize_net(void)
 
 void unregister_netdevice(struct net_device *dev)
 {
-       BUG_ON(dev_boot_phase);
        ASSERT_RTNL();
 
-       /* Some devices call without registering for initialization unwind. */
-       if (dev->reg_state == NETREG_UNINITIALIZED) {
-               printk(KERN_DEBUG "unregister_netdevice: device %s/%p never "
-                                 "was registered\n", dev->name, dev);
+       rollback_registered(dev);
+       /* Finish processing unregister after unlock */
+       net_set_todo(dev);
+}
 
-               WARN_ON(1);
-               return;
-       }
+/**
+ *     unregister_netdev - remove device from the kernel
+ *     @dev: device
+ *
+ *     This function shuts down a device interface and removes it
+ *     from the kernel tables.
+ *
+ *     This is just a wrapper for unregister_netdevice that takes
+ *     the rtnl semaphore.  In general you want to use this and not
+ *     unregister_netdevice.
+ */
+void unregister_netdev(struct net_device *dev)
+{
+       rtnl_lock();
+       unregister_netdevice(dev);
+       rtnl_unlock();
+}
 
-       BUG_ON(dev->reg_state != NETREG_REGISTERED);
+EXPORT_SYMBOL(unregister_netdev);
 
-       /* If device is running, close it first. */
-       if (dev->flags & IFF_UP)
-               dev_close(dev);
+/**
+ *     dev_change_net_namespace - move device to different nethost namespace
+ *     @dev: device
+ *     @net: network namespace
+ *     @pat: If not NULL name pattern to try if the current device name
+ *           is already taken in the destination network namespace.
+ *
+ *     This function shuts down a device interface and moves it
+ *     to a new network namespace. On success 0 is returned, on
+ *     a failure a netagive errno code is returned.
+ *
+ *     Callers must hold the rtnl semaphore.
+ */
 
-       /* And unlink it from device chain. */
-       write_lock_bh(&dev_base_lock);
-       list_del(&dev->dev_list);
-       hlist_del(&dev->name_hlist);
-       hlist_del(&dev->index_hlist);
-       write_unlock_bh(&dev_base_lock);
+int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat)
+{
+       char buf[IFNAMSIZ];
+       const char *destname;
+       int err;
 
-       dev->reg_state = NETREG_UNREGISTERING;
+       ASSERT_RTNL();
+
+       /* Don't allow namespace local devices to be moved. */
+       err = -EINVAL;
+       if (dev->features & NETIF_F_NETNS_LOCAL)
+               goto out;
+
+       /* Ensure the device has been registrered */
+       err = -EINVAL;
+       if (dev->reg_state != NETREG_REGISTERED)
+               goto out;
+
+       /* Get out if there is nothing todo */
+       err = 0;
+       if (net_eq(dev_net(dev), net))
+               goto out;
+
+       /* Pick the destination device name, and ensure
+        * we can use it in the destination network namespace.
+        */
+       err = -EEXIST;
+       destname = dev->name;
+       if (__dev_get_by_name(net, destname)) {
+               /* We get here if we can't use the current device name */
+               if (!pat)
+                       goto out;
+               if (!dev_valid_name(pat))
+                       goto out;
+               if (strchr(pat, '%')) {
+                       if (__dev_alloc_name(net, pat, buf) < 0)
+                               goto out;
+                       destname = buf;
+               } else
+                       destname = pat;
+               if (__dev_get_by_name(net, destname))
+                       goto out;
+       }
+
+       /*
+        * And now a mini version of register_netdevice unregister_netdevice.
+        */
+
+       /* If device is running close it first. */
+       dev_close(dev);
+
+       /* And unlink it from device chain */
+       err = -ENODEV;
+       unlist_netdevice(dev);
 
        synchronize_net();
 
        /* Shutdown queueing discipline. */
        dev_shutdown(dev);
 
-
        /* Notify protocols, that we are about to destroy
           this device. They should clean all the things.
        */
-       raw_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
+       call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 
        /*
         *      Flush the unicast and multicast chains
         */
        dev_addr_discard(dev);
 
-       if (dev->uninit)
-               dev->uninit(dev);
+       /* Actually switch the network namespace */
+       dev_net_set(dev, net);
 
-       /* Notifier chain MUST detach us from master device. */
-       BUG_TRAP(!dev->master);
+       /* Assign the new device name */
+       if (destname != dev->name)
+               strcpy(dev->name, destname);
 
-       /* Remove entries from sysfs */
-       netdev_unregister_sysfs(dev);
+       /* If there is an ifindex conflict assign a new one */
+       if (__dev_get_by_index(net, dev->ifindex)) {
+               int iflink = (dev->iflink == dev->ifindex);
+               dev->ifindex = dev_new_index(net);
+               if (iflink)
+                       dev->iflink = dev->ifindex;
+       }
 
-       /* Finish processing unregister after unlock */
-       net_set_todo(dev);
+       /* Fixup kobjects */
+       netdev_unregister_kobject(dev);
+       err = netdev_register_kobject(dev);
+       WARN_ON(err);
 
-       synchronize_net();
+       /* Add the device back in the hashes */
+       list_netdevice(dev);
 
-       dev_put(dev);
-}
+       /* Notify protocols, that a new device appeared. */
+       call_netdevice_notifiers(NETDEV_REGISTER, dev);
 
-/**
- *     unregister_netdev - remove device from the kernel
- *     @dev: device
- *
- *     This function shuts down a device interface and removes it
- *     from the kernel tables. On success 0 is returned, on a failure
- *     a negative errno code is returned.
- *
- *     This is just a wrapper for unregister_netdevice that takes
- *     the rtnl semaphore.  In general you want to use this and not
- *     unregister_netdevice.
- */
-void unregister_netdev(struct net_device *dev)
-{
-       rtnl_lock();
-       unregister_netdevice(dev);
-       rtnl_unlock();
+       synchronize_net();
+       err = 0;
+out:
+       return err;
 }
 
-EXPORT_SYMBOL(unregister_netdev);
-
 static int dev_cpu_callback(struct notifier_block *nfb,
                            unsigned long action,
                            void *ocpu)
@@ -3973,7 +4421,7 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
        spin_lock(&net_dma->lock);
        switch (state) {
        case DMA_RESOURCE_AVAILABLE:
-               for (i = 0; i < NR_CPUS; i++)
+               for (i = 0; i < nr_cpu_ids; i++)
                        if (net_dma->channels[i] == chan) {
                                found = 1;
                                break;
@@ -3988,7 +4436,7 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
                }
                break;
        case DMA_RESOURCE_REMOVED:
-               for (i = 0; i < NR_CPUS; i++)
+               for (i = 0; i < nr_cpu_ids; i++)
                        if (net_dma->channels[i] == chan) {
                                found = 1;
                                pos = i;
@@ -4015,6 +4463,13 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
  */
 static int __init netdev_dma_register(void)
 {
+       net_dma.channels = kzalloc(nr_cpu_ids * sizeof(struct net_dma),
+                                                               GFP_KERNEL);
+       if (unlikely(!net_dma.channels)) {
+               printk(KERN_NOTICE
+                               "netdev_dma: no memory for net_dma.channels\n");
+               return -ENOMEM;
+       }
        spin_lock_init(&net_dma.lock);
        dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask);
        dma_async_client_register(&net_dma.client);
@@ -4065,6 +4520,83 @@ int netdev_compute_features(unsigned long all, unsigned long one)
 }
 EXPORT_SYMBOL(netdev_compute_features);
 
+static struct hlist_head *netdev_create_hash(void)
+{
+       int i;
+       struct hlist_head *hash;
+
+       hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL);
+       if (hash != NULL)
+               for (i = 0; i < NETDEV_HASHENTRIES; i++)
+                       INIT_HLIST_HEAD(&hash[i]);
+
+       return hash;
+}
+
+/* Initialize per network namespace state */
+static int __net_init netdev_init(struct net *net)
+{
+       INIT_LIST_HEAD(&net->dev_base_head);
+
+       net->dev_name_head = netdev_create_hash();
+       if (net->dev_name_head == NULL)
+               goto err_name;
+
+       net->dev_index_head = netdev_create_hash();
+       if (net->dev_index_head == NULL)
+               goto err_idx;
+
+       return 0;
+
+err_idx:
+       kfree(net->dev_name_head);
+err_name:
+       return -ENOMEM;
+}
+
+static void __net_exit netdev_exit(struct net *net)
+{
+       kfree(net->dev_name_head);
+       kfree(net->dev_index_head);
+}
+
+static struct pernet_operations __net_initdata netdev_net_ops = {
+       .init = netdev_init,
+       .exit = netdev_exit,
+};
+
+static void __net_exit default_device_exit(struct net *net)
+{
+       struct net_device *dev, *next;
+       /*
+        * Push all migratable of the network devices back to the
+        * initial network namespace
+        */
+       rtnl_lock();
+       for_each_netdev_safe(net, dev, next) {
+               int err;
+               char fb_name[IFNAMSIZ];
+
+               /* Ignore unmoveable devices (i.e. loopback) */
+               if (dev->features & NETIF_F_NETNS_LOCAL)
+                       continue;
+
+               /* Push remaing network devices to init_net */
+               snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
+               err = dev_change_net_namespace(dev, &init_net, fb_name);
+               if (err) {
+                       printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
+                               __func__, dev->name, err);
+                       BUG();
+               }
+       }
+       rtnl_unlock();
+}
+
+static struct pernet_operations __net_initdata default_device_ops = {
+       .exit = default_device_exit,
+};
+
 /*
  *     Initialize the DEV module. At boot time this walks the device list and
  *     unhooks any devices that fail to initialise (normally hardware not
@@ -4085,18 +4617,18 @@ static int __init net_dev_init(void)
        if (dev_proc_init())
                goto out;
 
-       if (netdev_sysfs_init())
+       if (netdev_kobject_init())
                goto out;
 
        INIT_LIST_HEAD(&ptype_all);
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < PTYPE_HASH_SIZE; i++)
                INIT_LIST_HEAD(&ptype_base[i]);
 
-       for (i = 0; i < ARRAY_SIZE(dev_name_head); i++)
-               INIT_HLIST_HEAD(&dev_name_head[i]);
+       if (register_pernet_subsys(&netdev_net_ops))
+               goto out;
 
-       for (i = 0; i < ARRAY_SIZE(dev_index_head); i++)
-               INIT_HLIST_HEAD(&dev_index_head[i]);
+       if (register_pernet_device(&default_device_ops))
+               goto out;
 
        /*
         *      Initialise the packet receive queues.