]> Pileus Git - ~andy/linux/blobdiff - net/ipv4/udp.c
[SK_BUFF]: Introduce skb_transport_offset()
[~andy/linux] / net / ipv4 / udp.c
index 86368832d4812e739d83c8106c01ee1448e1cdba..13875e8419a7467360490fc8915fdf1ad669e84b 100644 (file)
@@ -175,7 +175,8 @@ int __udp_lib_get_port(struct sock *sk, unsigned short snum,
                        ;
                }
                result = best;
-               for(i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++, result += UDP_HTABLE_SIZE) {
+               for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE;
+                    i++, result += UDP_HTABLE_SIZE) {
                        if (result > sysctl_local_port_range[1])
                                result = sysctl_local_port_range[0]
                                        + ((result - sysctl_local_port_range[0]) &
@@ -212,13 +213,13 @@ fail:
        return error;
 }
 
-__inline__ int udp_get_port(struct sock *sk, unsigned short snum,
+int udp_get_port(struct sock *sk, unsigned short snum,
                        int (*scmp)(const struct sock *, const struct sock *))
 {
        return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
 }
 
-inline int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
+int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
 {
        struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
 
@@ -270,10 +271,10 @@ static struct sock *__udp4_lib_lookup(__be32 saddr, __be16 sport,
                                        continue;
                                score+=2;
                        }
-                       if(score == 9) {
+                       if (score == 9) {
                                result = sk;
                                break;
-                       } else if(score > badness) {
+                       } else if (score > badness) {
                                result = sk;
                                badness = score;
                        }
@@ -390,7 +391,7 @@ out:
        sock_put(sk);
 }
 
-__inline__ void udp_err(struct sk_buff *skb, u32 info)
+void udp_err(struct sk_buff *skb, u32 info)
 {
        return __udp4_lib_err(skb, info, udp_hash);
 }
@@ -434,7 +435,7 @@ static void udp4_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb,
                 * fragments on the socket so that all csums of sk_buffs
                 * should be together
                 */
-               offset = skb->h.raw - skb->data;
+               offset = skb_transport_offset(skb);
                skb->csum = skb_checksum(skb, offset, skb->len - offset, 0);
 
                skb->ip_summed = CHECKSUM_NONE;
@@ -765,38 +766,38 @@ out:
 
 int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
 {
-       switch(cmd)
+       switch (cmd) {
+       case SIOCOUTQ:
        {
-               case SIOCOUTQ:
-               {
-                       int amount = atomic_read(&sk->sk_wmem_alloc);
-                       return put_user(amount, (int __user *)arg);
-               }
+               int amount = atomic_read(&sk->sk_wmem_alloc);
+               return put_user(amount, (int __user *)arg);
+       }
 
-               case SIOCINQ:
-               {
-                       struct sk_buff *skb;
-                       unsigned long amount;
-
-                       amount = 0;
-                       spin_lock_bh(&sk->sk_receive_queue.lock);
-                       skb = skb_peek(&sk->sk_receive_queue);
-                       if (skb != NULL) {
-                               /*
-                                * We will only return the amount
-                                * of this packet since that is all
-                                * that will be read.
-                                */
-                               amount = skb->len - sizeof(struct udphdr);
-                       }
-                       spin_unlock_bh(&sk->sk_receive_queue.lock);
-                       return put_user(amount, (int __user *)arg);
+       case SIOCINQ:
+       {
+               struct sk_buff *skb;
+               unsigned long amount;
+
+               amount = 0;
+               spin_lock_bh(&sk->sk_receive_queue.lock);
+               skb = skb_peek(&sk->sk_receive_queue);
+               if (skb != NULL) {
+                       /*
+                        * We will only return the amount
+                        * of this packet since that is all
+                        * that will be read.
+                        */
+                       amount = skb->len - sizeof(struct udphdr);
                }
+               spin_unlock_bh(&sk->sk_receive_queue.lock);
+               return put_user(amount, (int __user *)arg);
+       }
 
-               default:
-                       return -ENOIOCTLCMD;
+       default:
+               return -ENOIOCTLCMD;
        }
-       return(0);
+
+       return 0;
 }
 
 /*
@@ -866,7 +867,7 @@ try_again:
        {
                sin->sin_family = AF_INET;
                sin->sin_port = skb->h.uh->source;
-               sin->sin_addr.s_addr = skb->nh.iph->saddr;
+               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
                memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
        }
        if (inet->cmsg_flags)
@@ -958,7 +959,7 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
                /* Check if this is a keepalive packet.  If so, eat it. */
                if (len == 1 && udpdata[0] == 0xff) {
                        return 0;
-               } else if (len > sizeof(struct ip_esp_hdr) && udpdata32[0] != 0 ) {
+               } else if (len > sizeof(struct ip_esp_hdr) && udpdata32[0] != 0) {
                        /* ESP Packet without Non-ESP header */
                        len = sizeof(struct udphdr);
                } else
@@ -989,7 +990,7 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
                return 0;
 
        /* Now we can update and verify the packet length... */
-       iph = skb->nh.iph;
+       iph = ip_hdr(skb);
        iphlen = iph->ihl << 2;
        iph->tot_len = htons(ntohs(iph->tot_len) - len);
        if (skb->len < iphlen + len) {
@@ -1001,7 +1002,8 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
         * transport header to point to ESP.  Keep UDP on the stack
         * for later.
         */
-       skb->h.raw = skb_pull(skb, len);
+       __skb_pull(skb, len);
+       skb_reset_transport_header(skb);
 
        /* modify the protocol (it's ESP!) */
        iph->protocol = IPPROTO_ESP;
@@ -1141,10 +1143,10 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
 
                        sknext = udp_v4_mcast_next(sk_next(sk), uh->dest, daddr,
                                                   uh->source, saddr, dif);
-                       if(sknext)
+                       if (sknext)
                                skb1 = skb_clone(skb, GFP_ATOMIC);
 
-                       if(skb1) {
+                       if (skb1) {
                                int ret = udp_queue_rcv_skb(sk, skb1);
                                if (ret > 0)
                                        /* we should probably re-process instead
@@ -1152,7 +1154,7 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
                                        kfree_skb(skb1);
                        }
                        sk = sknext;
-               } while(sknext);
+               } while (sknext);
        } else
                kfree_skb(skb);
        read_unlock(&udp_hash_lock);
@@ -1167,6 +1169,7 @@ static int __udp4_lib_mcast_deliver(struct sk_buff *skb,
 static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
                                 int proto)
 {
+       const struct iphdr *iph;
        int err;
 
        UDP_SKB_CB(skb)->partial_cov = 0;
@@ -1178,16 +1181,16 @@ static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
                        return err;
        }
 
+       iph = ip_hdr(skb);
        if (uh->check == 0) {
                skb->ip_summed = CHECKSUM_UNNECESSARY;
        } else if (skb->ip_summed == CHECKSUM_COMPLETE) {
-              if (!csum_tcpudp_magic(skb->nh.iph->saddr, skb->nh.iph->daddr,
-                                     skb->len, proto, skb->csum))
+              if (!csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len,
+                                     proto, skb->csum))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
        }
        if (skb->ip_summed != CHECKSUM_UNNECESSARY)
-               skb->csum = csum_tcpudp_nofold(skb->nh.iph->saddr,
-                                              skb->nh.iph->daddr,
+               skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
                                               skb->len, proto, 0);
        /* Probably, we should checksum udp header (it should be in cache
         * in any case) and data in tiny packets (< rx copybreak).
@@ -1207,8 +1210,8 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
        struct udphdr *uh = skb->h.uh;
        unsigned short ulen;
        struct rtable *rt = (struct rtable*)skb->dst;
-       __be32 saddr = skb->nh.iph->saddr;
-       __be32 daddr = skb->nh.iph->daddr;
+       __be32 saddr = ip_hdr(skb)->saddr;
+       __be32 daddr = ip_hdr(skb)->daddr;
 
        /*
         *  Validate the packet.
@@ -1230,7 +1233,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
        if (udp4_csum_init(skb, uh, proto))
                goto csum_error;
 
-       if(rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST))
+       if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST))
                return __udp4_lib_mcast_deliver(skb, uh, saddr, daddr, udptable);
 
        sk = __udp4_lib_lookup(saddr, uh->source, daddr, uh->dest,
@@ -1264,7 +1267,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
         * don't wanna listen.  Ignore it.
         */
        kfree_skb(skb);
-       return(0);
+       return 0;
 
 short_packet:
        LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: short packet: From %u.%u.%u.%u:%u %d/%d to %u.%u.%u.%u:%u\n",
@@ -1292,10 +1295,10 @@ csum_error:
 drop:
        UDP_INC_STATS_BH(UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
        kfree_skb(skb);
-       return(0);
+       return 0;
 }
 
-__inline__ int udp_rcv(struct sk_buff *skb)
+int udp_rcv(struct sk_buff *skb)
 {
        return __udp4_lib_rcv(skb, udp_hash, IPPROTO_UDP);
 }
@@ -1319,13 +1322,13 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
        int val;
        int err = 0;
 
-       if(optlen<sizeof(int))
+       if (optlen<sizeof(int))
                return -EINVAL;
 
        if (get_user(val, (int __user *)optval))
                return -EFAULT;
 
-       switch(optname) {
+       switch (optname) {
        case UDP_CORK:
                if (val != 0) {
                        up->corkflag = 1;
@@ -1379,7 +1382,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
        default:
                err = -ENOPROTOOPT;
                break;
-       };
+       }
 
        return err;
 }
@@ -1410,15 +1413,15 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
        struct udp_sock *up = udp_sk(sk);
        int val, len;
 
-       if(get_user(len,optlen))
+       if (get_user(len,optlen))
                return -EFAULT;
 
        len = min_t(unsigned int, len, sizeof(int));
 
-       if(len < 0)
+       if (len < 0)
                return -EINVAL;
 
-       switch(optname) {
+       switch (optname) {
        case UDP_CORK:
                val = up->corkflag;
                break;
@@ -1439,11 +1442,11 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
 
        default:
                return -ENOPROTOOPT;
-       };
+       }
 
-       if(put_user(len, optlen))
+       if (put_user(len, optlen))
                return -EFAULT;
-       if(copy_to_user(optval, &val,len))
+       if (copy_to_user(optval, &val,len))
                return -EFAULT;
        return 0;
 }
@@ -1575,7 +1578,7 @@ static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
        struct sock *sk = udp_get_first(seq);
 
        if (sk)
-               while(pos && (sk = udp_get_next(seq, sk)) != NULL)
+               while (pos && (sk = udp_get_next(seq, sk)) != NULL)
                        --pos;
        return pos ? NULL : sk;
 }