net: skb->dst accessors
[safe/jmp/linux-2.6] / net / decnet / dn_nsp_in.c
index 39a6cf7..932408d 100644 (file)
@@ -33,7 +33,7 @@
 
 /******************************************************************************
     (c) 1995-1998 E.M. Serrat          emserrat@geocities.com
-    
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
@@ -50,7 +50,6 @@
 #include <linux/socket.h>
 #include <linux/in.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/string.h>
 #include <linux/sockios.h>
@@ -63,7 +62,7 @@
 #include <asm/system.h>
 #include <linux/fcntl.h>
 #include <linux/mm.h>
-#include <linux/termios.h>      
+#include <linux/termios.h>
 #include <linux/interrupt.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
@@ -84,7 +83,9 @@ static void dn_log_martian(struct sk_buff *skb, const char *msg)
        if (decnet_log_martians && net_ratelimit()) {
                char *devname = skb->dev ? skb->dev->name : "???";
                struct dn_skb_cb *cb = DN_SKB_CB(skb);
-               printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n", msg, devname, dn_ntohs(cb->src), dn_ntohs(cb->dst), dn_ntohs(cb->src_port), dn_ntohs(cb->dst_port));
+               printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
+                      msg, devname, le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
+                      le16_to_cpu(cb->src_port), le16_to_cpu(cb->dst_port));
        }
 }
 
@@ -134,12 +135,12 @@ static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
        if (skb->len < 2)
                return len;
 
-       if ((ack = dn_ntohs(*ptr)) & 0x8000) {
+       if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
                skb_pull(skb, 2);
                ptr++;
                len += 2;
                if ((ack & 0x4000) == 0) {
-                       if (oth) 
+                       if (oth)
                                ack ^= 0x2000;
                        dn_ack(sk, skb, ack);
                }
@@ -148,11 +149,11 @@ static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
        if (skb->len < 2)
                return len;
 
-       if ((ack = dn_ntohs(*ptr)) & 0x8000) {
+       if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
                skb_pull(skb, 2);
                len += 2;
                if ((ack & 0x4000) == 0) {
-                       if (oth) 
+                       if (oth)
                                ack ^= 0x2000;
                        dn_ack(sk, skb, ack);
                }
@@ -238,7 +239,7 @@ static struct sock *dn_find_listener(struct sk_buff *skb, unsigned short *reason
        cb->dst_port = msg->dstaddr;
        cb->services = msg->services;
        cb->info     = msg->info;
-       cb->segsize  = dn_ntohs(msg->segsize);
+       cb->segsize  = le16_to_cpu(msg->segsize);
 
        if (!pskb_may_pull(skb, sizeof(*msg)))
                goto err_out;
@@ -345,13 +346,13 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
        ptr = skb->data;
        cb->services = *ptr++;
        cb->info = *ptr++;
-       cb->segsize = dn_ntohs(*(__le16 *)ptr);
+       cb->segsize = le16_to_cpu(*(__le16 *)ptr);
 
        if ((scp->state == DN_CI) || (scp->state == DN_CD)) {
                scp->persist = 0;
-                scp->addrrem = cb->src_port;
-                sk->sk_state = TCP_ESTABLISHED;
-                scp->state = DN_RUN;
+               scp->addrrem = cb->src_port;
+               sk->sk_state = TCP_ESTABLISHED;
+               scp->state = DN_RUN;
                scp->services_rem = cb->services;
                scp->info_rem = cb->info;
                scp->segsize_rem = cb->segsize;
@@ -362,17 +363,18 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
                if (skb->len > 0) {
                        u16 dlen = *skb->data;
                        if ((dlen <= 16) && (dlen <= skb->len)) {
-                               scp->conndata_in.opt_optl = dn_htons(dlen);
-                               memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen);
+                               scp->conndata_in.opt_optl = cpu_to_le16(dlen);
+                               skb_copy_from_linear_data_offset(skb, 1,
+                                             scp->conndata_in.opt_data, dlen);
                        }
                }
-                dn_nsp_send_link(sk, DN_NOCHANGE, 0);
-                if (!sock_flag(sk, SOCK_DEAD))
-                       sk->sk_state_change(sk);
-        }
+               dn_nsp_send_link(sk, DN_NOCHANGE, 0);
+               if (!sock_flag(sk, SOCK_DEAD))
+                       sk->sk_state_change(sk);
+       }
 
 out:
-        kfree_skb(skb);
+       kfree_skb(skb);
 }
 
 static void dn_nsp_conn_ack(struct sock *sk, struct sk_buff *skb)
@@ -396,18 +398,18 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
        if (skb->len < 2)
                goto out;
 
-       reason = dn_ntohs(*(__le16 *)skb->data);
+       reason = le16_to_cpu(*(__le16 *)skb->data);
        skb_pull(skb, 2);
 
-       scp->discdata_in.opt_status = dn_htons(reason);
+       scp->discdata_in.opt_status = cpu_to_le16(reason);
        scp->discdata_in.opt_optl   = 0;
        memset(scp->discdata_in.opt_data, 0, 16);
 
        if (skb->len > 0) {
                u16 dlen = *skb->data;
                if ((dlen <= 16) && (dlen <= skb->len)) {
-                       scp->discdata_in.opt_optl = dn_htons(dlen);
-                       memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen);
+                       scp->discdata_in.opt_optl = cpu_to_le16(dlen);
+                       skb_copy_from_linear_data_offset(skb, 1, scp->discdata_in.opt_data, dlen);
                }
        }
 
@@ -435,7 +437,7 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
                sk->sk_state_change(sk);
        }
 
-       /* 
+       /*
         * It appears that its possible for remote machines to send disc
         * init messages with no port identifier if we are in the CI and
         * possibly also the CD state. Obviously we shouldn't reply with
@@ -463,7 +465,7 @@ static void dn_nsp_disc_conf(struct sock *sk, struct sk_buff *skb)
        if (skb->len != 2)
                goto out;
 
-       reason = dn_ntohs(*(__le16 *)skb->data);
+       reason = le16_to_cpu(*(__le16 *)skb->data);
 
        sk->sk_state = TCP_CLOSE;
 
@@ -512,14 +514,14 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
        if (skb->len != 4)
                goto out;
 
-       segnum = dn_ntohs(*(__le16 *)ptr);
+       segnum = le16_to_cpu(*(__le16 *)ptr);
        ptr += 2;
        lsflags = *(unsigned char *)ptr++;
        fcval = *ptr;
 
        /*
         * Here we ignore erronous packets which should really
-        * should cause a connection abort. It is not critical 
+        * should cause a connection abort. It is not critical
         * for now though.
         */
        if (lsflags & 0xf8)
@@ -530,7 +532,7 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
                switch(lsflags & 0x04) { /* FCVAL INT */
                case 0x00: /* Normal Request */
                        switch(lsflags & 0x03) { /* FCVAL MOD */
-                               case 0x00: /* Request count */
+                       case 0x00: /* Request count */
                                if (fcval < 0) {
                                        unsigned char p_fcval = -fcval;
                                        if ((scp->flowrem_dat > p_fcval) &&
@@ -541,7 +543,7 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
                                        scp->flowrem_dat += fcval;
                                        wake_up = 1;
                                }
-                                       break;
+                               break;
                        case 0x01: /* Stop outgoing data */
                                scp->flowrem_sw = DN_DONTSEND;
                                break;
@@ -557,10 +559,10 @@ static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
                                wake_up = 1;
                        }
                        break;
-                }
+               }
                if (wake_up && !sock_flag(sk, SOCK_DEAD))
                        sk->sk_state_change(sk);
-        }
+       }
 
        dn_nsp_send_oth_ack(sk);
 
@@ -576,38 +578,29 @@ out:
 static __inline__ int dn_queue_skb(struct sock *sk, struct sk_buff *skb, int sig, struct sk_buff_head *queue)
 {
        int err;
-       
-        /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
-           number of warnings when compiling with -W --ANK
-         */
-        if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
+       int skb_len;
+
+       /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
+          number of warnings when compiling with -W --ANK
+        */
+       if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
            (unsigned)sk->sk_rcvbuf) {
-               err = -ENOMEM;
-               goto out;
-        }
+               err = -ENOMEM;
+               goto out;
+       }
 
        err = sk_filter(sk, skb);
        if (err)
                goto out;
 
-        skb_set_owner_r(skb, sk);
-        skb_queue_tail(queue, skb);
+       skb_len = skb->len;
+       skb_set_owner_r(skb, sk);
+       skb_queue_tail(queue, skb);
 
-       /* This code only runs from BH or BH protected context.
-        * Therefore the plain read_lock is ok here. -DaveM
-        */
-       read_lock(&sk->sk_callback_lock);
-        if (!sock_flag(sk, SOCK_DEAD)) {
-               struct socket *sock = sk->sk_socket;
-               wake_up_interruptible(sk->sk_sleep);
-               if (sock && sock->fasync_list &&
-                   !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
-                       __kill_fasync(sock->fasync_list, sig, 
-                                   (sig == SIGURG) ? POLL_PRI : POLL_IN);
-       }
-       read_unlock(&sk->sk_callback_lock);
+       if (!sock_flag(sk, SOCK_DEAD))
+               sk->sk_data_ready(sk, skb_len);
 out:
-        return err;
+       return err;
 }
 
 static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
@@ -620,7 +613,7 @@ static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
        if (skb->len < 2)
                goto out;
 
-       cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data);
+       cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
        skb_pull(skb, 2);
 
        if (seq_next(scp->numoth_rcv, segnum)) {
@@ -648,20 +641,20 @@ static void dn_nsp_data(struct sock *sk, struct sk_buff *skb)
        if (skb->len < 2)
                goto out;
 
-       cb->segnum = segnum = dn_ntohs(*(__le16 *)skb->data);
+       cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
        skb_pull(skb, 2);
 
        if (seq_next(scp->numdat_rcv, segnum)) {
-                if (dn_queue_skb(sk, skb, SIGIO, &sk->sk_receive_queue) == 0) {
+               if (dn_queue_skb(sk, skb, SIGIO, &sk->sk_receive_queue) == 0) {
                        seq_add(&scp->numdat_rcv, 1);
-                       queued = 1;
-                }
+                       queued = 1;
+               }
 
                if ((scp->flowloc_sw == DN_SEND) && dn_congested(sk)) {
                        scp->flowloc_sw = DN_DONTSEND;
                        dn_nsp_send_link(sk, DN_DONTSEND, 0);
                }
-        }
+       }
 
        dn_nsp_send_data_ack(sk);
 out:
@@ -726,13 +719,13 @@ static int dn_nsp_rx_packet(struct sk_buff *skb)
        if (!pskb_may_pull(skb, 2))
                goto free_out;
 
-       skb->h.raw    = skb->data;
+       skb_reset_transport_header(skb);
        cb->nsp_flags = *ptr++;
 
        if (decnet_debug_level & 2)
                printk(KERN_DEBUG "dn_nsp_rx: Message type 0x%02x\n", (int)cb->nsp_flags);
 
-       if (cb->nsp_flags & 0x83) 
+       if (cb->nsp_flags & 0x83)
                goto free_out;
 
        /*
@@ -852,7 +845,7 @@ int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
                        case 0x30:
                                dn_nsp_disc_init(sk, skb);
                                break;
-                       case 0x40:      
+                       case 0x40:
                                dn_nsp_disc_conf(sk, skb);
                                break;
                }