mac80211: fix sign error in pid controller
[safe/jmp/linux-2.6] / net / core / dev.c
index c3e0578..c36a17a 100644 (file)
 #include <net/dst.h>
 #include <net/pkt_sched.h>
 #include <net/checksum.h>
+#include <net/xfrm.h>
 #include <linux/highmem.h>
 #include <linux/init.h>
 #include <linux/kmod.h>
@@ -893,7 +894,8 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
                free_page((unsigned long) inuse);
        }
 
-       snprintf(buf, IFNAMSIZ, name, i);
+       if (buf != name)
+               snprintf(buf, IFNAMSIZ, name, i);
        if (!__dev_get_by_name(net, buf))
                return i;
 
@@ -933,6 +935,21 @@ int dev_alloc_name(struct net_device *dev, const char *name)
 }
 EXPORT_SYMBOL(dev_alloc_name);
 
+static int dev_get_valid_name(struct net *net, const char *name, char *buf,
+                             bool fmt)
+{
+       if (!dev_valid_name(name))
+               return -EINVAL;
+
+       if (fmt && strchr(name, '%'))
+               return __dev_alloc_name(net, name, buf);
+       else if (__dev_get_by_name(net, name))
+               return -EEXIST;
+       else if (buf != name)
+               strlcpy(buf, name, IFNAMSIZ);
+
+       return 0;
+}
 
 /**
  *     dev_change_name - change name of a device
@@ -956,28 +973,20 @@ int dev_change_name(struct net_device *dev, const char *newname)
        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, '%')) {
-               err = dev_alloc_name(dev, newname);
-               if (err < 0)
-                       return err;
-       } else if (__dev_get_by_name(net, newname))
-               return -EEXIST;
-       else
-               strlcpy(dev->name, newname, IFNAMSIZ);
+       err = dev_get_valid_name(net, newname, dev->name, 1);
+       if (err < 0)
+               return err;
 
 rollback:
        /* For now only devices in the initial network namespace
         * are in sysfs.
         */
-       if (net == &init_net) {
+       if (net_eq(net, &init_net)) {
                ret = device_rename(&dev->dev, dev->name);
                if (ret) {
                        memcpy(dev->name, oldname, IFNAMSIZ);
@@ -1344,6 +1353,7 @@ rollback:
                                nb->notifier_call(nb, NETDEV_DOWN, dev);
                        }
                        nb->notifier_call(nb, NETDEV_UNREGISTER, dev);
+                       nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev);
                }
        }
 
@@ -1410,6 +1420,45 @@ static inline void net_timestamp(struct sk_buff *skb)
                skb->tstamp.tv64 = 0;
 }
 
+/**
+ * dev_forward_skb - loopback an skb to another netif
+ *
+ * @dev: destination network device
+ * @skb: buffer to forward
+ *
+ * return values:
+ *     NET_RX_SUCCESS  (no congestion)
+ *     NET_RX_DROP     (packet was dropped)
+ *
+ * dev_forward_skb can be used for injecting an skb from the
+ * start_xmit function of one device into the receive queue
+ * of another device.
+ *
+ * The receiving device may be in another namespace, so
+ * we have to clear all information in the skb that could
+ * impact namespace isolation.
+ */
+int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
+{
+       skb_orphan(skb);
+
+       if (!(dev->flags & IFF_UP))
+               return NET_RX_DROP;
+
+       if (skb->len > (dev->mtu + dev->hard_header_len))
+               return NET_RX_DROP;
+
+       skb_dst_drop(skb);
+       skb->tstamp.tv64 = 0;
+       skb->pkt_type = PACKET_HOST;
+       skb->protocol = eth_type_trans(skb, dev);
+       skb->mark = 0;
+       secpath_reset(skb);
+       nf_reset(skb);
+       return netif_rx(skb);
+}
+EXPORT_SYMBOL_GPL(dev_forward_skb);
+
 /*
  *     Support routine. Sends outgoing frames to any network
  *     taps currently in use.
@@ -2278,7 +2327,7 @@ static int ing_filter(struct sk_buff *skb)
        if (MAX_RED_LOOP < ttl++) {
                printk(KERN_WARNING
                       "Redir loop detected Dropping packet (%d->%d)\n",
-                      skb->iif, dev->ifindex);
+                      skb->skb_iif, dev->ifindex);
                return TC_ACT_SHOT;
        }
 
@@ -2386,8 +2435,8 @@ int netif_receive_skb(struct sk_buff *skb)
        if (netpoll_receive_skb(skb))
                return NET_RX_DROP;
 
-       if (!skb->iif)
-               skb->iif = skb->dev->ifindex;
+       if (!skb->skb_iif)
+               skb->skb_iif = skb->dev->ifindex;
 
        null_or_orig = NULL;
        orig_dev = skb->dev;
@@ -2628,9 +2677,10 @@ __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
                return GRO_NORMAL;
 
        for (p = napi->gro_list; p; p = p->next) {
-               NAPI_GRO_CB(p)->same_flow = (p->dev == skb->dev)
-                       && !compare_ether_header(skb_mac_header(p),
-                                                skb_gro_mac_header(skb));
+               NAPI_GRO_CB(p)->same_flow =
+                       (p->dev == skb->dev) &&
+                       !compare_ether_header(skb_mac_header(p),
+                                             skb_gro_mac_header(skb));
                NAPI_GRO_CB(p)->flush = 0;
        }
 
@@ -4777,6 +4827,10 @@ static void rollback_registered_many(struct list_head *head)
                netdev_unregister_kobject(dev);
        }
 
+       /* Process any work delayed until the end of the batch */
+       dev = list_entry(head->next, struct net_device, unreg_list);
+       call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
+
        synchronize_net();
 
        list_for_each_entry(dev, head, unreg_list)
@@ -4847,6 +4901,33 @@ unsigned long netdev_fix_features(unsigned long features, const char *name)
 EXPORT_SYMBOL(netdev_fix_features);
 
 /**
+ *     netif_stacked_transfer_operstate -      transfer operstate
+ *     @rootdev: the root or lower level device to transfer state from
+ *     @dev: the device to transfer operstate to
+ *
+ *     Transfer operational state from root to device. This is normally
+ *     called when a stacking relationship exists between the root
+ *     device and the device(a leaf device).
+ */
+void netif_stacked_transfer_operstate(const struct net_device *rootdev,
+                                       struct net_device *dev)
+{
+       if (rootdev->operstate == IF_OPER_DORMANT)
+               netif_dormant_on(dev);
+       else
+               netif_dormant_off(dev);
+
+       if (netif_carrier_ok(rootdev)) {
+               if (!netif_carrier_ok(dev))
+                       netif_carrier_on(dev);
+       } else {
+               if (netif_carrier_ok(dev))
+                       netif_carrier_off(dev);
+       }
+}
+EXPORT_SYMBOL(netif_stacked_transfer_operstate);
+
+/**
  *     register_netdevice      - register a network device
  *     @dev: device to register
  *
@@ -4865,8 +4946,6 @@ EXPORT_SYMBOL(netdev_fix_features);
 
 int register_netdevice(struct net_device *dev)
 {
-       struct hlist_head *head;
-       struct hlist_node *p;
        int ret;
        struct net *net = dev_net(dev);
 
@@ -4895,26 +4974,14 @@ int register_netdevice(struct net_device *dev)
                }
        }
 
-       if (!dev_valid_name(dev->name)) {
-               ret = -EINVAL;
+       ret = dev_get_valid_name(net, dev->name, dev->name, 0);
+       if (ret)
                goto err_uninit;
-       }
 
        dev->ifindex = dev_new_index(net);
        if (dev->iflink == -1)
                dev->iflink = dev->ifindex;
 
-       /* Check for existence of 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);
-               if (!strncmp(d->name, dev->name, IFNAMSIZ)) {
-                       ret = -EEXIST;
-                       goto err_uninit;
-               }
-       }
-
        /* Fix illegal checksum combinations */
        if ((dev->features & NETIF_F_HW_CSUM) &&
            (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
@@ -5067,6 +5134,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
 {
        unsigned long rebroadcast_time, warning_time;
 
+       linkwatch_forget_dev(dev);
+
        rebroadcast_time = warning_time = jiffies;
        while (atomic_read(&dev->refcnt) != 0) {
                if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
@@ -5074,6 +5143,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
 
                        /* Rebroadcast unregister notification */
                        call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
+                       /* don't resend NETDEV_UNREGISTER_BATCH, _BATCH users
+                        * should have already handle it the first time */
 
                        if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
                                     &dev->state)) {
@@ -5291,6 +5362,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 
        INIT_LIST_HEAD(&dev->napi_list);
        INIT_LIST_HEAD(&dev->unreg_list);
+       INIT_LIST_HEAD(&dev->link_watch_list);
        dev->priv_flags = IFF_XMIT_DST_RELEASE;
        setup(dev);
        strcpy(dev->name, name);
@@ -5358,7 +5430,7 @@ EXPORT_SYMBOL(synchronize_net);
  *     unregister_netdevice_queue - remove device from the kernel
  *     @dev: device
  *     @head: list
-
+ *
  *     This function shuts down a device interface and removes it
  *     from the kernel tables.
  *     If head not NULL, device is queued to be unregistered later.
@@ -5384,7 +5456,6 @@ EXPORT_SYMBOL(unregister_netdevice_queue);
 /**
  *     unregister_netdevice_many - unregister many devices
  *     @head: list of devices
- *
  */
 void unregister_netdevice_many(struct list_head *head)
 {
@@ -5433,8 +5504,6 @@ EXPORT_SYMBOL(unregister_netdev);
 
 int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat)
 {
-       char buf[IFNAMSIZ];
-       const char *destname;
        int err;
 
        ASSERT_RTNL();
@@ -5467,20 +5536,11 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
         * we can use it in the destination network namespace.
         */
        err = -EEXIST;
-       destname = dev->name;
-       if (__dev_get_by_name(net, destname)) {
+       if (__dev_get_by_name(net, dev->name)) {
                /* 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))
+               if (dev_get_valid_name(net, pat, dev->name, 1))
                        goto out;
        }
 
@@ -5504,6 +5564,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
           this device. They should clean all the things.
        */
        call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
+       call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
 
        /*
         *      Flush the unicast and multicast chains
@@ -5516,10 +5577,6 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
        /* Actually switch the network namespace */
        dev_net_set(dev, net);
 
-       /* Assign the new device name */
-       if (destname != dev->name)
-               strcpy(dev->name, destname);
-
        /* If there is an ifindex conflict assign a new one */
        if (__dev_get_by_index(net, dev->ifindex)) {
                int iflink = (dev->iflink == dev->ifindex);
@@ -5706,14 +5763,13 @@ static struct pernet_operations __net_initdata netdev_net_ops = {
 
 static void __net_exit default_device_exit(struct net *net)
 {
-       struct net_device *dev;
+       struct net_device *dev, *aux;
        /*
-        * Push all migratable of the network devices back to the
+        * Push all migratable network devices back to the
         * initial network namespace
         */
        rtnl_lock();
-restart:
-       for_each_netdev(net, dev) {
+       for_each_netdev_safe(net, dev, aux) {
                int err;
                char fb_name[IFNAMSIZ];
 
@@ -5721,11 +5777,9 @@ restart:
                if (dev->features & NETIF_F_NETNS_LOCAL)
                        continue;
 
-               /* Delete virtual devices */
-               if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) {
-                       dev->rtnl_link_ops->dellink(dev, NULL);
-                       goto restart;
-               }
+               /* Leave virtual devices for the generic cleanup */
+               if (dev->rtnl_link_ops)
+                       continue;
 
                /* Push remaing network devices to init_net */
                snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
@@ -5735,13 +5789,37 @@ restart:
                                __func__, dev->name, err);
                        BUG();
                }
-               goto restart;
        }
        rtnl_unlock();
 }
 
+static void __net_exit default_device_exit_batch(struct list_head *net_list)
+{
+       /* At exit all network devices most be removed from a network
+        * namespace.  Do this in the reverse order of registeration.
+        * Do this across as many network namespaces as possible to
+        * improve batching efficiency.
+        */
+       struct net_device *dev;
+       struct net *net;
+       LIST_HEAD(dev_kill_list);
+
+       rtnl_lock();
+       list_for_each_entry(net, net_list, exit_list) {
+               for_each_netdev_reverse(net, dev) {
+                       if (dev->rtnl_link_ops)
+                               dev->rtnl_link_ops->dellink(dev, &dev_kill_list);
+                       else
+                               unregister_netdevice_queue(dev, &dev_kill_list);
+               }
+       }
+       unregister_netdevice_many(&dev_kill_list);
+       rtnl_unlock();
+}
+
 static struct pernet_operations __net_initdata default_device_ops = {
        .exit = default_device_exit,
+       .exit_batch = default_device_exit_batch,
 };
 
 /*