]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/udp.c
[UDP]: Only increment counter on first peek/recv
[net-next-2.6.git] / net / ipv6 / udp.c
index c347f3e30e2e5ef1ccd3469f6f2ab804649402c4..fa640765385e995350a4dc2a1fe9b4c19552ea3b 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/ipv6.h>
 #include <linux/icmpv6.h>
 #include <linux/init.h>
+#include <linux/module.h>
 #include <linux/skbuff.h>
 #include <asm/uaccess.h>
 
@@ -51,6 +52,7 @@
 #include "udp_impl.h"
 
 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
+EXPORT_SYMBOL(udp_stats_in6);
 
 static inline int udp_v6_get_port(struct sock *sk, unsigned short snum)
 {
@@ -121,6 +123,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
        struct inet_sock *inet = inet_sk(sk);
        struct sk_buff *skb;
        unsigned int ulen, copied;
+       int peeked;
        int err;
        int is_udplite = IS_UDPLITE(sk);
 
@@ -131,7 +134,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
                return ipv6_recv_error(sk, msg, len);
 
 try_again:
-       skb = skb_recv_datagram(sk, flags, noblock, &err);
+       skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
+                                 &peeked, &err);
        if (!skb)
                goto out;
 
@@ -164,6 +168,9 @@ try_again:
        if (err)
                goto out_free;
 
+       if (!peeked)
+               UDP6_INC_STATS_USER(UDP_MIB_INDATAGRAMS, is_udplite);
+
        sock_recv_timestamp(msg, sk, skb);
 
        /* Copy the address. */
@@ -205,12 +212,11 @@ out:
        return err;
 
 csum_copy_err:
-       skb_kill_datagram(sk, skb, flags);
-
-       if (flags & MSG_DONTWAIT) {
+       if (!skb_kill_datagram(sk, skb, flags))
                UDP6_INC_STATS_USER(UDP_MIB_INERRORS, is_udplite);
+
+       if (flags & MSG_DONTWAIT)
                return -EAGAIN;
-       }
        goto try_again;
 }
 
@@ -259,6 +265,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
 {
        struct udp_sock *up = udp_sk(sk);
        int rc;
+       int is_udplite = IS_UDPLITE(sk);
 
        if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
                goto drop;
@@ -266,7 +273,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
        /*
         * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
         */
-       if ((up->pcflag & UDPLITE_RECV_CC)  &&  UDP_SKB_CB(skb)->partial_cov) {
+       if ((is_udplite & UDPLITE_RECV_CC)  &&  UDP_SKB_CB(skb)->partial_cov) {
 
                if (up->pcrlen == 0) {          /* full coverage was set  */
                        LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: partial coverage"
@@ -290,13 +297,13 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
        if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) {
                /* Note that an ENOMEM error is charged twice */
                if (rc == -ENOMEM)
-                       UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS, up->pcflag);
+                       UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS, is_udplite);
                goto drop;
        }
-       UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
+
        return 0;
 drop:
-       UDP6_INC_STATS_BH(UDP_MIB_INERRORS, up->pcflag);
+       UDP6_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite);
        kfree_skb(skb);
        return -1;
 }
@@ -405,10 +412,9 @@ static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh,
        return 0;
 }
 
-int __udp6_lib_rcv(struct sk_buff **pskb, struct hlist_head udptable[],
+int __udp6_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
                   int proto)
 {
-       struct sk_buff *skb = *pskb;
        struct sock *sk;
        struct udphdr *uh;
        struct net_device *dev = skb->dev;
@@ -494,9 +500,9 @@ discard:
        return 0;
 }
 
-static __inline__ int udpv6_rcv(struct sk_buff **pskb)
+static __inline__ int udpv6_rcv(struct sk_buff *skb)
 {
-       return __udp6_lib_rcv(pskb, udp_hash, IPPROTO_UDP);
+       return __udp6_lib_rcv(skb, udp_hash, IPPROTO_UDP);
 }
 
 /*
@@ -525,6 +531,7 @@ static int udp_v6_push_pending_frames(struct sock *sk)
        struct inet_sock *inet = inet_sk(sk);
        struct flowi *fl = &inet->cork.fl;
        int err = 0;
+       int is_udplite = IS_UDPLITE(sk);
        __wsum csum = 0;
 
        /* Grab the skbuff where UDP header space exists. */
@@ -540,7 +547,7 @@ static int udp_v6_push_pending_frames(struct sock *sk)
        uh->len = htons(up->len);
        uh->check = 0;
 
-       if (up->pcflag)
+       if (is_udplite)
                csum = udplite_csum_outgoing(sk, skb);
         else
                csum = udp_csum_outgoing(sk, skb);
@@ -556,7 +563,7 @@ out:
        up->len = 0;
        up->pending = 0;
        if (!err)
-               UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS, up->pcflag);
+               UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS, is_udplite);
        return err;
 }
 
@@ -580,7 +587,7 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
        int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
        int err;
        int connected = 0;
-       int is_udplite = up->pcflag;
+       int is_udplite = IS_UDPLITE(sk);
        int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
 
        /* destination address check */
@@ -612,7 +619,7 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
                daddr = NULL;
 
        if (daddr) {
-               if (ipv6_addr_type(daddr) == IPV6_ADDR_MAPPED) {
+               if (ipv6_addr_v4mapped(daddr)) {
                        struct sockaddr_in sin;
                        sin.sin_family = AF_INET;
                        sin.sin_port = sin6 ? sin6->sin6_port : inet->dport;
@@ -972,6 +979,8 @@ void udp6_proc_exit(void) {
 
 /* ------------------------------------------------------------------------ */
 
+DEFINE_PROTO_INUSE(udpv6)
+
 struct proto udpv6_prot = {
        .name              = "UDPv6",
        .owner             = THIS_MODULE,
@@ -993,6 +1002,7 @@ struct proto udpv6_prot = {
        .compat_setsockopt = compat_udpv6_setsockopt,
        .compat_getsockopt = compat_udpv6_getsockopt,
 #endif
+       REF_PROTO_INUSE(udpv6)
 };
 
 static struct inet_protosw udpv6_protosw = {