[WEXT]: Move to net/wireless
[deliverable/linux.git] / net / core / dev.c
index f7f7e5687e462a459a8395d2ed5f273aa0eaee74..700e4b5081b6ee6da6fe1f49b53bc57dfd0f8f63 100644 (file)
@@ -225,12 +225,6 @@ extern void netdev_unregister_sysfs(struct net_device *);
 
 *******************************************************************************/
 
-/*
- *     For efficiency
- */
-
-static int netdev_nit;
-
 /*
  *     Add a protocol ID to the list. Now that the input handler is
  *     smarter we can dispense with all the messy stuff that used to be
@@ -265,10 +259,9 @@ void dev_add_pack(struct packet_type *pt)
        int hash;
 
        spin_lock_bh(&ptype_lock);
-       if (pt->type == htons(ETH_P_ALL)) {
-               netdev_nit++;
+       if (pt->type == htons(ETH_P_ALL))
                list_add_rcu(&pt->list, &ptype_all);
-       else {
+       else {
                hash = ntohs(pt->type) & 15;
                list_add_rcu(&pt->list, &ptype_base[hash]);
        }
@@ -295,10 +288,9 @@ void __dev_remove_pack(struct packet_type *pt)
 
        spin_lock_bh(&ptype_lock);
 
-       if (pt->type == htons(ETH_P_ALL)) {
-               netdev_nit--;
+       if (pt->type == htons(ETH_P_ALL))
                head = &ptype_all;
-       else
+       else
                head = &ptype_base[ntohs(pt->type) & 15];
 
        list_for_each_entry(pt1, head, list) {
@@ -817,7 +809,6 @@ static int default_rebuild_header(struct sk_buff *skb)
        return 1;
 }
 
-
 /**
  *     dev_open        - prepare an interface for use.
  *     @dev:   device to open
@@ -1069,7 +1060,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
                        skb_reset_mac_header(skb2);
 
                        if (skb_network_header(skb2) < skb2->data ||
-                           skb_network_header(skb2) > skb2->tail) {
+                           skb2->network_header > skb2->tail) {
                                if (net_ratelimit())
                                        printk(KERN_CRIT "protocol %04x is "
                                               "buggy, dev %s\n",
@@ -1077,7 +1068,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
                                skb_reset_network_header(skb2);
                        }
 
-                       skb2->h.raw = skb2->nh.raw;
+                       skb2->transport_header = skb2->network_header;
                        skb2->pkt_type = PACKET_OUTGOING;
                        ptype->func(skb2, skb->dev, ptype, skb->dev);
                }
@@ -1156,7 +1147,7 @@ EXPORT_SYMBOL(netif_device_attach);
 int skb_checksum_help(struct sk_buff *skb)
 {
        __wsum csum;
-       int ret = 0, offset = skb_transport_offset(skb);
+       int ret = 0, offset;
 
        if (skb->ip_summed == CHECKSUM_COMPLETE)
                goto out_set_summed;
@@ -1172,15 +1163,16 @@ int skb_checksum_help(struct sk_buff *skb)
                        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->tail - skb->h.raw;
+       offset = skb_headlen(skb) - offset;
        BUG_ON(offset <= 0);
        BUG_ON(skb->csum_offset + 2 > offset);
 
-       *(__sum16*)(skb->h.raw + skb->csum_offset) = csum_fold(csum);
-
+       *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) =
+               csum_fold(csum);
 out_set_summed:
        skb->ip_summed = CHECKSUM_NONE;
 out:
@@ -1207,10 +1199,10 @@ struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
        BUG_ON(skb_shinfo(skb)->frag_list);
 
        skb_reset_mac_header(skb);
-       skb->mac_len = skb->nh.raw - skb->mac.raw;
+       skb->mac_len = skb->network_header - skb->mac_header;
        __skb_pull(skb, skb->mac_len);
 
-       if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
+       if (WARN_ON(skb->ip_summed != CHECKSUM_PARTIAL)) {
                if (skb_header_cloned(skb) &&
                    (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
                        return ERR_PTR(err);
@@ -1330,7 +1322,7 @@ static int dev_gso_segment(struct sk_buff *skb)
 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        if (likely(!skb->next)) {
-               if (netdev_nit)
+               if (!list_empty(&ptype_all))
                        dev_queue_xmit_nit(skb, dev);
 
                if (netif_needs_gso(dev, skb)) {
@@ -1432,12 +1424,16 @@ int dev_queue_xmit(struct sk_buff *skb)
        /* If packet is not checksummed and device does not support
         * checksumming for this protocol, complete checksumming here.
         */
-       if (skb->ip_summed == CHECKSUM_PARTIAL &&
-           (!(dev->features & NETIF_F_GEN_CSUM) &&
-            (!(dev->features & NETIF_F_IP_CSUM) ||
-             skb->protocol != htons(ETH_P_IP))))
-               if (skb_checksum_help(skb))
-                       goto out_kfree_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)))
+                       if (skb_checksum_help(skb))
+                               goto out_kfree_skb;
+       }
 
 gso:
        spin_lock_prefetch(&dev->queue_lock);
@@ -1683,31 +1679,37 @@ static inline int deliver_skb(struct sk_buff *skb,
 }
 
 #if defined(CONFIG_BRIDGE) || defined (CONFIG_BRIDGE_MODULE)
-int (*br_handle_frame_hook)(struct net_bridge_port *p, struct sk_buff **pskb);
+/* These hooks defined here for ATM */
 struct net_bridge;
 struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
                                                unsigned char *addr);
-void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
+void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent) __read_mostly;
 
-static __inline__ int handle_bridge(struct sk_buff **pskb,
-                                   struct packet_type **pt_prev, int *ret,
-                                   struct net_device *orig_dev)
+/*
+ * If bridge module is loaded call bridging hook.
+ *  returns NULL if packet was consumed.
+ */
+struct sk_buff *(*br_handle_frame_hook)(struct net_bridge_port *p,
+                                       struct sk_buff *skb) __read_mostly;
+static inline struct sk_buff *handle_bridge(struct sk_buff *skb,
+                                           struct packet_type **pt_prev, int *ret,
+                                           struct net_device *orig_dev)
 {
        struct net_bridge_port *port;
 
-       if ((*pskb)->pkt_type == PACKET_LOOPBACK ||
-           (port = rcu_dereference((*pskb)->dev->br_port)) == NULL)
-               return 0;
+       if (skb->pkt_type == PACKET_LOOPBACK ||
+           (port = rcu_dereference(skb->dev->br_port)) == NULL)
+               return skb;
 
        if (*pt_prev) {
-               *ret = deliver_skb(*pskb, *pt_prev, orig_dev);
+               *ret = deliver_skb(skb, *pt_prev, orig_dev);
                *pt_prev = NULL;
        }
 
-       return br_handle_frame_hook(port, pskb);
+       return br_handle_frame_hook(port, skb);
 }
 #else
-#define handle_bridge(skb, pt_prev, ret, orig_dev)     (0)
+#define handle_bridge(skb, pt_prev, ret, orig_dev)     (skb)
 #endif
 
 #ifdef CONFIG_NET_CLS_ACT
@@ -1737,10 +1739,10 @@ static int ing_filter(struct sk_buff *skb)
 
                skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_INGRESS);
 
-               spin_lock(&dev->queue_lock);
+               spin_lock(&dev->ingress_lock);
                if ((q = dev->qdisc_ingress) != NULL)
                        result = q->enqueue(skb, q);
-               spin_unlock(&dev->queue_lock);
+               spin_unlock(&dev->ingress_lock);
 
        }
 
@@ -1774,7 +1776,7 @@ int netif_receive_skb(struct sk_buff *skb)
 
        skb_reset_network_header(skb);
        skb_reset_transport_header(skb);
-       skb->mac_len = skb->nh.raw - skb->mac.raw;
+       skb->mac_len = skb->network_header - skb->mac_header;
 
        pt_prev = NULL;
 
@@ -1814,7 +1816,8 @@ int netif_receive_skb(struct sk_buff *skb)
 ncls:
 #endif
 
-       if (handle_bridge(&skb, &pt_prev, &ret, orig_dev))
+       skb = handle_bridge(skb, &pt_prev, &ret, orig_dev);
+       if (!skb)
                goto out;
 
        type = skb->protocol;
@@ -2096,9 +2099,9 @@ void dev_seq_stop(struct seq_file *seq, void *v)
 
 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
 {
-       if (dev->get_stats) {
-               struct net_device_stats *stats = dev->get_stats(dev);
+       struct net_device_stats *stats = dev->get_stats(dev);
 
+       if (stats) {
                seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
                                "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
                           dev->name, stats->rx_bytes, stats->rx_packets,
@@ -2933,7 +2936,7 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
                                }
                                dev_load(ifr.ifr_name);
                                rtnl_lock();
-                               /* Follow me in net/core/wireless.c */
+                               /* Follow me in net/wireless/wext.c */
                                ret = wireless_process_ioctl(&ifr, cmd);
                                rtnl_unlock();
                                if (IW_IS_GET(cmd) &&
@@ -3013,9 +3016,7 @@ int register_netdevice(struct net_device *dev)
        spin_lock_init(&dev->queue_lock);
        spin_lock_init(&dev->_xmit_lock);
        dev->xmit_lock_owner = -1;
-#ifdef CONFIG_NET_CLS_ACT
        spin_lock_init(&dev->ingress_lock);
-#endif
 
        dev->iflink = -1;
 
@@ -3127,7 +3128,7 @@ out:
  *     chain. 0 is returned on success. A negative errno code is returned
  *     on a failure to set up the device, or if the name is a duplicate.
  *
- *     This is a wrapper around register_netdev that takes the rtnl semaphore
+ *     This is a wrapper around register_netdevice that takes the rtnl semaphore
  *     and expands the device name if you passed a format string to
  *     alloc_netdev.
  */
@@ -3282,6 +3283,13 @@ out:
        mutex_unlock(&net_todo_run_mutex);
 }
 
+static struct net_device_stats *maybe_internal_stats(struct net_device *dev)
+{
+       if (dev->features & NETIF_F_INTERNAL_STATS)
+               return &dev->stats;
+       return NULL;
+}
+
 /**
  *     alloc_netdev - allocate network device
  *     @sizeof_priv:   size of private data to allocate space for
@@ -3317,6 +3325,7 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
        if (sizeof_priv)
                dev->priv = netdev_priv(dev);
 
+       dev->get_stats = maybe_internal_stats;
        setup(dev);
        strcpy(dev->name, name);
        return dev;
This page took 0.036318 seconds and 5 git commands to generate.