appletalk: convert aarp to net_device_ops
[safe/jmp/linux-2.6] / net / appletalk / ddp.c
index 934f259..5abce07 100644 (file)
@@ -2,7 +2,7 @@
  *     DDP:    An implementation of the AppleTalk DDP protocol for
  *             Ethernet 'ELAP'.
  *
- *             Alan Cox  <Alan.Cox@linux.org>
+ *             Alan Cox  <alan@lxorguk.ukuu.org.uk>
  *
  *             With more than a little assistance from
  *
@@ -177,10 +177,9 @@ static inline void atalk_destroy_socket(struct sock *sk)
 
        if (atomic_read(&sk->sk_wmem_alloc) ||
            atomic_read(&sk->sk_rmem_alloc)) {
-               init_timer(&sk->sk_timer);
+               setup_timer(&sk->sk_timer, atalk_destroy_timer,
+                               (unsigned long)sk);
                sk->sk_timer.expires    = jiffies + SOCK_DESTROY_TIME;
-               sk->sk_timer.function   = atalk_destroy_timer;
-               sk->sk_timer.data       = (unsigned long)sk;
                add_timer(&sk->sk_timer);
        } else
                sock_put(sk);
@@ -647,9 +646,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 (!net_eq(dev_net(dev), &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 +676,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;
 
@@ -811,9 +815,6 @@ static int atif_ioctl(int cmd, void __user *arg)
                                return -EPERM;
                        if (sa->sat_family != AF_APPLETALK)
                                return -EINVAL;
-                       if (!atif)
-                               return -EADDRNOTAVAIL;
-
                        /*
                         * for now, we only support proxy AARP on ELAP;
                         * we should be able to do it for LocalTalk, too.
@@ -896,7 +897,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;
                        }
@@ -955,7 +956,7 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
        for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
                int end;
 
-               BUG_TRAP(start <= offset + len);
+               WARN_ON(start > offset + len);
 
                end = start + skb_shinfo(skb)->frags[i].size;
                if ((copy = end - offset) > 0) {
@@ -982,7 +983,7 @@ static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
                for (; list; list = list->next) {
                        int end;
 
-                       BUG_TRAP(start <= offset + len);
+                       WARN_ON(start > offset + len);
 
                        end = start + list->len;
                        if ((copy = end - offset) > 0) {
@@ -1024,11 +1025,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)
@@ -1036,7 +1040,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);
        if (!sk)
                goto out;
        rc = 0;
@@ -1265,7 +1269,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 */
@@ -1275,9 +1279,9 @@ static int handle_ip_over_ddp(struct sk_buff *skb)
        skb->protocol = htons(ETH_P_IP);
        skb_pull(skb, 13);
        skb->dev   = dev;
-       skb->h.raw = skb->data;
+       skb_reset_transport_header(skb);
 
-       stats = dev->priv;
+       stats = netdev_priv(dev);
        stats->rx_packets++;
        stats->rx_bytes += skb->len + 13;
        netif_rx(skb);  /* Send the SKB up to a higher place. */
@@ -1383,10 +1387,10 @@ free_it:
  *     @pt - packet type
  *
  *     Receive a packet (in skb) from device dev. This has come from the SNAP
- *     decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
- *     header, skb->len is the DDP length. The physical headers have been
- *     extracted. PPP should probably pass frames marked as for this layer.
- *     [ie ARPHRD_ETHERTALK]
+ *     decoder, and on entry skb->transport_header is the DDP header, skb->len
+ *     is the DDP header, skb->len is the DDP length. The physical headers
+ *     have been extracted. PPP should probably pass frames marked as for this
+ *     layer.  [ie ARPHRD_ETHERTALK]
  */
 static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
                     struct packet_type *pt, struct net_device *orig_dev)
@@ -1398,6 +1402,9 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
        int origlen;
        __u16 len_hops;
 
+       if (!net_eq(dev_net(dev), &init_net))
+               goto freeit;
+
        /* Don't mangle buffer if shared */
        if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
                goto out;
@@ -1483,6 +1490,9 @@ freeit:
 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
                     struct packet_type *pt, struct net_device *orig_dev)
 {
+       if (!net_eq(dev_net(dev), &init_net))
+               goto freeit;
+
        /* Expand any short form frames */
        if (skb_mac_header(skb)[2] == 1) {
                struct ddpehdr *ddp;
@@ -1522,7 +1532,7 @@ static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
                /* Non routable, so force a drop if we slip up later */
                ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
        }
-       skb->h.raw = skb->data;
+       skb_reset_transport_header(skb);
 
        return atalk_rcv(skb, dev, pt, orig_dev);
 freeit:
@@ -1844,7 +1854,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 = {
@@ -1922,6 +1931,6 @@ static void __exit atalk_exit(void)
 module_exit(atalk_exit);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
+MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
 MODULE_DESCRIPTION("AppleTalk 0.20\n");
 MODULE_ALIAS_NETPROTO(PF_APPLETALK);