]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/appletalk/ddp.c
[NET]: Make the device list and device lookups per namespace.
[linux-2.6-omap-h63xx.git] / net / appletalk / ddp.c
index 16eda21fb38ce2c9ebeb6f33dfdf47ebe2721f43..7c0b5151d5265408614fda8c25e489aff50c5b41 100644 (file)
@@ -647,9 +647,14 @@ static inline void atalk_dev_down(struct net_device *dev)
 static int ddp_device_event(struct notifier_block *this, unsigned long event,
                            void *ptr)
 {
+       struct net_device *dev = ptr;
+
+       if (dev->nd_net != &init_net)
+               return NOTIFY_DONE;
+
        if (event == NETDEV_DOWN)
                /* Discard any use of this */
-               atalk_dev_down(ptr);
+               atalk_dev_down(dev);
 
        return NOTIFY_DONE;
 }
@@ -672,7 +677,7 @@ static int atif_ioctl(int cmd, void __user *arg)
        if (copy_from_user(&atreq, arg, sizeof(atreq)))
                return -EFAULT;
 
-       dev = __dev_get_by_name(atreq.ifr_name);
+       dev = __dev_get_by_name(&init_net, atreq.ifr_name);
        if (!dev)
                return -ENODEV;
 
@@ -896,7 +901,7 @@ static int atrtr_ioctl(unsigned int cmd, void __user *arg)
                                if (copy_from_user(name, rt.rt_dev, IFNAMSIZ-1))
                                        return -EFAULT;
                                name[IFNAMSIZ-1] = '\0';
-                               dev = __dev_get_by_name(name);
+                               dev = __dev_get_by_name(&init_net, name);
                                if (!dev)
                                        return -ENODEV;
                        }
@@ -937,11 +942,11 @@ static unsigned long atalk_sum_partial(const unsigned char *data,
 static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
                                   int len, unsigned long sum)
 {
-       int end = skb_headlen(skb);
+       int start = skb_headlen(skb);
        int i, copy;
 
        /* checksum stuff in header space */
-       if ((copy = end - offset) > 0) {
+       if ( (copy = start - offset) > 0) {
                if (copy > len)
                        copy = len;
                sum = atalk_sum_partial(skb->data + offset, copy, sum);
@@ -953,9 +958,11 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
 
        /* checksum stuff in frags */
        for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
-               BUG_TRAP(len >= 0);
+               int end;
+
+               BUG_TRAP(start <= offset + len);
 
-               end = offset + skb_shinfo(skb)->frags[i].size;
+               end = start + skb_shinfo(skb)->frags[i].size;
                if ((copy = end - offset) > 0) {
                        u8 *vaddr;
                        skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -963,31 +970,36 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
                        if (copy > len)
                                copy = len;
                        vaddr = kmap_skb_frag(frag);
-                       sum = atalk_sum_partial(vaddr + frag->page_offset,
-                                               copy, sum);
+                       sum = atalk_sum_partial(vaddr + frag->page_offset +
+                                                 offset - start, copy, sum);
                        kunmap_skb_frag(vaddr);
 
                        if (!(len -= copy))
                                return sum;
                        offset += copy;
                }
+               start = end;
        }
 
        if (skb_shinfo(skb)->frag_list) {
                struct sk_buff *list = skb_shinfo(skb)->frag_list;
 
                for (; list; list = list->next) {
-                       BUG_TRAP(len >= 0);
+                       int end;
 
-                       end = offset + list->len;
+                       BUG_TRAP(start <= offset + len);
+
+                       end = start + list->len;
                        if ((copy = end - offset) > 0) {
                                if (copy > len)
                                        copy = len;
-                               sum = atalk_sum_skb(list, 0, copy, sum);
+                               sum = atalk_sum_skb(list, offset - start,
+                                                   copy, sum);
                                if ((len -= copy) == 0)
                                        return sum;
                                offset += copy;
                        }
+                       start = end;
                }
        }
 
@@ -1017,11 +1029,14 @@ static struct proto ddp_proto = {
  * Create a socket. Initialise the socket, blank the addresses
  * set the state.
  */
-static int atalk_create(struct socket *sock, int protocol)
+static int atalk_create(struct net *net, struct socket *sock, int protocol)
 {
        struct sock *sk;
        int rc = -ESOCKTNOSUPPORT;
 
+       if (net != &init_net)
+               return -EAFNOSUPPORT;
+
        /*
         * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
         * and gives you the full ELAP frame. Should be handy for CAP 8)
@@ -1029,7 +1044,7 @@ static int atalk_create(struct socket *sock, int protocol)
        if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
                goto out;
        rc = -ENOMEM;
-       sk = sk_alloc(PF_APPLETALK, GFP_KERNEL, &ddp_proto, 1);
+       sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto, 1);
        if (!sk)
                goto out;
        rc = 0;
@@ -1258,7 +1273,7 @@ static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
 
 static int handle_ip_over_ddp(struct sk_buff *skb)
 {
-       struct net_device *dev = __dev_get_by_name("ipddp0");
+       struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
        struct net_device_stats *stats;
 
        /* This needs to be able to handle ipddp"N" devices */
@@ -1391,6 +1406,9 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
        int origlen;
        __u16 len_hops;
 
+       if (dev->nd_net != &init_net)
+               goto freeit;
+
        /* Don't mangle buffer if shared */
        if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
                goto out;
@@ -1476,6 +1494,9 @@ freeit:
 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
                     struct packet_type *pt, struct net_device *orig_dev)
 {
+       if (dev->nd_net != &init_net)
+               goto freeit;
+
        /* Expand any short form frames */
        if (skb_mac_header(skb)[2] == 1) {
                struct ddpehdr *ddp;
@@ -1837,7 +1858,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
        .sendpage       = sock_no_sendpage,
 };
 
-#include <linux/smp_lock.h>
 SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
 
 static struct notifier_block ddp_notifier = {