net: sk_drops consolidation
authorEric Dumazet <eric.dumazet@gmail.com>
Thu, 15 Oct 2009 03:40:11 +0000 (20:40 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 15 Oct 2009 03:40:11 +0000 (20:40 -0700)
sock_queue_rcv_skb() can update sk_drops itself, removing need for
callers to take care of it. This is more consistent since
sock_queue_rcv_skb() also reads sk_drops when queueing a skb.

This adds sk_drops managment to many protocols that not cared yet.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/sock.c
net/ieee802154/dgram.c
net/ieee802154/raw.c
net/ipv4/raw.c
net/ipv4/udp.c
net/ipv6/raw.c
net/ipv6/udp.c
net/phonet/datagram.c
net/phonet/pep.c

index 43ca2c99539330fb68753c63d92939796db36cca..38713aa3faf2a383e6e608f8815e6dd6aa18d868 100644 (file)
@@ -274,7 +274,7 @@ static void sock_disable_timestamp(struct sock *sk, int flag)
 
 int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 {
-       int err = 0;
+       int err;
        int skb_len;
        unsigned long flags;
        struct sk_buff_head *list = &sk->sk_receive_queue;
@@ -284,17 +284,17 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
         */
        if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
            (unsigned)sk->sk_rcvbuf) {
-               err = -ENOMEM;
-               goto out;
+               atomic_inc(&sk->sk_drops);
+               return -ENOMEM;
        }
 
        err = sk_filter(sk, skb);
        if (err)
-               goto out;
+               return err;
 
        if (!sk_rmem_schedule(sk, skb->truesize)) {
-               err = -ENOBUFS;
-               goto out;
+               atomic_inc(&sk->sk_drops);
+               return -ENOBUFS;
        }
 
        skb->dev = NULL;
@@ -314,8 +314,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
        if (!sock_flag(sk, SOCK_DEAD))
                sk->sk_data_ready(sk, skb_len);
-out:
-       return err;
+       return 0;
 }
 EXPORT_SYMBOL(sock_queue_rcv_skb);
 
index 25ad956a39d8a2b4ffafb4baeb5d29ba9964f72f..9aac5aee157548d663114661d945a3188611f0d4 100644 (file)
@@ -318,7 +318,6 @@ out:
 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
 {
        if (sock_queue_rcv_skb(sk, skb) < 0) {
-               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index 769c8d138fc3a8bf4911064d205a38ad212768e6..9c9b85c00033718a5a4f7bf8e879869631f2b08b 100644 (file)
@@ -206,7 +206,6 @@ out:
 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
 {
        if (sock_queue_rcv_skb(sk, skb) < 0) {
-               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index f18172b07611235736f3def254a12a0591c8a790..39e2a6b8752c3b25887683b94b7f342264ae97c7 100644 (file)
@@ -292,7 +292,6 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
        /* Charge it to the socket. */
 
        if (sock_queue_rcv_skb(sk, skb) < 0) {
-               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index ee61b3fc4cae1139668689e2e5f3142a61d78c66..45a8a7e374d872864bb996bdb78cf38fa2d3d2b7 100644 (file)
@@ -1063,25 +1063,22 @@ EXPORT_SYMBOL(udp_lib_unhash);
 
 static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 {
-       int is_udplite = IS_UDPLITE(sk);
-       int rc;
+       int rc = sock_queue_rcv_skb(sk, skb);
+
+       if (rc < 0) {
+               int is_udplite = IS_UDPLITE(sk);
 
-       if ((rc = sock_queue_rcv_skb(sk, skb)) < 0) {
                /* Note that an ENOMEM error is charged twice */
-               if (rc == -ENOMEM) {
+               if (rc == -ENOMEM)
                        UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
                                         is_udplite);
-                       atomic_inc(&sk->sk_drops);
-               }
-               goto drop;
+               UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
+               kfree_skb(skb);
+               return -1;
        }
 
        return 0;
 
-drop:
-       UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
-       kfree_skb(skb);
-       return -1;
 }
 
 /* returns:
index d8375bc7f2d5530d4748be73193b12166d37c705..fd737efed96c4ea0418a95a37e753904c7192255 100644 (file)
@@ -381,8 +381,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
        }
 
        /* Charge it to the socket. */
-       if (sock_queue_rcv_skb(sk,skb)<0) {
-               atomic_inc(&sk->sk_drops);
+       if (sock_queue_rcv_skb(sk, skb) < 0) {
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index 1f8e2afa449019ef902914aca2baa130ae6fec70..b86425b7ea2204c8c7646443f618fdc60e13329b 100644 (file)
@@ -385,13 +385,11 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
                        goto drop;
        }
 
-       if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) {
+       if ((rc = sock_queue_rcv_skb(sk, skb)) < 0) {
                /* Note that an ENOMEM error is charged twice */
-               if (rc == -ENOMEM) {
+               if (rc == -ENOMEM)
                        UDP6_INC_STATS_BH(sock_net(sk),
                                        UDP_MIB_RCVBUFERRORS, is_udplite);
-                       atomic_inc(&sk->sk_drops);
-               }
                goto drop;
        }
 
index ef5c75c372e41701965737ae04ed88c0f805c9f2..67f072e94d00f78394af72f2ad53014ad6e2b235 100644 (file)
@@ -159,11 +159,9 @@ out_nofree:
 static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 {
        int err = sock_queue_rcv_skb(sk, skb);
-       if (err < 0) {
+
+       if (err < 0)
                kfree_skb(skb);
-               if (err == -ENOMEM)
-                       atomic_inc(&sk->sk_drops);
-       }
        return err ? NET_RX_DROP : NET_RX_SUCCESS;
 }
 
index 5f32d217535b4695667dc3e75ea3e0bcaab9a15e..cbaa1d67d77b17ac37dd0ce58a91a2a959365ed8 100644 (file)
@@ -360,8 +360,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
                        err = sock_queue_rcv_skb(sk, skb);
                        if (!err)
                                return 0;
-                       if (err == -ENOMEM)
-                               atomic_inc(&sk->sk_drops);
                        break;
                }