fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / atm / br2684.c
index 91a89d3..83a1c1b 100644 (file)
@@ -5,7 +5,6 @@ Author: Marcell GAL, 2000, XDSL Ltd, Hungary
 */
 
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
@@ -18,12 +17,12 @@ Author: Marcell GAL, 2000, XDSL Ltd, Hungary
 #include <net/arp.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
+#include <linux/capability.h>
 #include <linux/seq_file.h>
 
 #include <linux/atmbr2684.h>
 
 #include "common.h"
-#include "ipcommon.h"
 
 /*
  * Define this to use a version of the code which interacts with the higher
@@ -97,7 +96,7 @@ struct br2684_dev {
  * do read-locking under interrupt context, so write locking must block
  * the current CPU's interrupts
  */
-static rwlock_t devs_lock = RW_LOCK_UNLOCKED;
+static DEFINE_RWLOCK(devs_lock);
 
 static LIST_HEAD(br2684_devs);
 
@@ -190,7 +189,7 @@ static int br2684_xmit_vcc(struct sk_buff *skb, struct br2684_dev *brdev,
                dev_kfree_skb(skb);
                return 0;
                }
-       atomic_add(skb->truesize, &atmvcc->sk->sk_wmem_alloc);
+       atomic_add(skb->truesize, &sk_atm(atmvcc)->sk_wmem_alloc);
        ATM_SKB(skb)->atm_options = atmvcc->atm_options;
        brdev->stats.tx_packets++;
        brdev->stats.tx_bytes += skb->len;
@@ -220,7 +219,7 @@ static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev)
                /* netif_stop_queue(dev); */
                dev_kfree_skb(skb);
                read_unlock(&devs_lock);
-               return -EUNATCH;
+               return 0;
        }
        if (!br2684_xmit_vcc(skb, brdev, brvcc)) {
                /*
@@ -289,21 +288,20 @@ xmit will add the additional header part in that case */
  * This is similar to eth_type_trans, which cannot be used because of
  * our dev->hard_header_len
  */
-static inline unsigned short br_type_trans(struct sk_buff *skb,
-                                              struct net_device *dev)
+static inline __be16 br_type_trans(struct sk_buff *skb, struct net_device *dev)
 {
        struct ethhdr *eth;
        unsigned char *rawp;
-       eth = skb->mac.ethernet;
+       eth = eth_hdr(skb);
 
-       if (*eth->h_dest & 1) {
-               if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
+       if (is_multicast_ether_addr(eth->h_dest)) {
+               if (!compare_ether_addr(eth->h_dest, dev->broadcast))
                        skb->pkt_type = PACKET_BROADCAST;
                else
                        skb->pkt_type = PACKET_MULTICAST;
        }
 
-       else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
+       else if (compare_ether_addr(eth->h_dest, dev->dev_addr))
                skb->pkt_type = PACKET_OTHERHOST;
 
        if (ntohs(eth->h_proto) >= 1536)
@@ -373,7 +371,7 @@ static int br2684_setfilt(struct atm_vcc *atmvcc, void __user *arg)
 
 /* Returns 1 if packet should be dropped */
 static inline int
-packet_fails_filter(u16 type, struct br2684_vcc *brvcc, struct sk_buff *skb)
+packet_fails_filter(__be16 type, struct br2684_vcc *brvcc, struct sk_buff *skb)
 {
        if (brvcc->filter.netmask == 0)
                return 0;                       /* no filter in place */
@@ -501,18 +499,18 @@ Note: we do not have explicit unassign, but look at _push()
 */
        int err;
        struct br2684_vcc *brvcc;
-       struct sk_buff_head copy;
        struct sk_buff *skb;
+       struct sk_buff_head *rq;
        struct br2684_dev *brdev;
        struct net_device *net_dev;
        struct atm_backend_br2684 be;
+       unsigned long flags;
 
        if (copy_from_user(&be, arg, sizeof be))
                return -EFAULT;
-       brvcc = kmalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
+       brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
        if (!brvcc)
                return -ENOMEM;
-       memset(brvcc, 0, sizeof(struct br2684_vcc));
        write_lock_irq(&devs_lock);
        net_dev = br2684_find_dev(&be.ifspec);
        if (net_dev == NULL) {
@@ -556,14 +554,32 @@ Note: we do not have explicit unassign, but look at _push()
        brvcc->old_push = atmvcc->push;
        barrier();
        atmvcc->push = br2684_push;
-       skb_queue_head_init(&copy);
-       skb_migrate(&atmvcc->sk->sk_receive_queue, &copy);
-       while ((skb = skb_dequeue(&copy))) {
+
+       rq = &sk_atm(atmvcc)->sk_receive_queue;
+
+       spin_lock_irqsave(&rq->lock, flags);
+       if (skb_queue_empty(rq)) {
+               skb = NULL;
+       } else {
+               /* NULL terminate the list.  */
+               rq->prev->next = NULL;
+               skb = rq->next;
+       }
+       rq->prev = rq->next = (struct sk_buff *)rq;
+       rq->qlen = 0;
+       spin_unlock_irqrestore(&rq->lock, flags);
+
+       while (skb) {
+               struct sk_buff *next = skb->next;
+
+               skb->next = skb->prev = NULL;
                BRPRIV(skb->dev)->stats.rx_bytes -= skb->len;
                BRPRIV(skb->dev)->stats.rx_packets--;
                br2684_push(atmvcc, skb);
+
+               skb = next;
        }
-       (void) try_module_get(THIS_MODULE);
+       __module_get(THIS_MODULE);
        return 0;
     error:
        write_unlock_irq(&devs_lock);