Network Drop Monitor: Adding kfree_skb_clean for non-drops and modifying end-of-line...
authorNeil Horman <nhorman@tuxdriver.com>
Wed, 11 Mar 2009 09:49:55 +0000 (09:49 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 Mar 2009 19:09:28 +0000 (12:09 -0700)
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
 include/linux/skbuff.h |    4 +++-
 net/core/datagram.c    |    2 +-
 net/core/skbuff.c      |   22 ++++++++++++++++++++++
 net/ipv4/arp.c         |    2 +-
 net/ipv4/udp.c         |    2 +-
 net/packet/af_packet.c |    2 +-
 6 files changed, 29 insertions(+), 5 deletions(-)
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/skbuff.h
net/core/datagram.c
net/core/skbuff.c
net/ipv4/arp.c
net/ipv4/udp.c
net/packet/af_packet.c

index 1f659e8c2b888677f8a92dc2c0e2d1562ae856f1..1fbab2ae613c6338939d8921803889d54987314e 100644 (file)
@@ -421,6 +421,7 @@ extern void skb_dma_unmap(struct device *dev, struct sk_buff *skb,
 #endif
 
 extern void kfree_skb(struct sk_buff *skb);
+extern void consume_skb(struct sk_buff *skb);
 extern void           __kfree_skb(struct sk_buff *skb);
 extern struct sk_buff *__alloc_skb(unsigned int size,
                                   gfp_t priority, int fclone, int node);
@@ -459,7 +460,8 @@ extern int         skb_to_sgvec(struct sk_buff *skb,
 extern int            skb_cow_data(struct sk_buff *skb, int tailbits,
                                    struct sk_buff **trailer);
 extern int            skb_pad(struct sk_buff *skb, int pad);
-#define dev_kfree_skb(a)       kfree_skb(a)
+#define dev_kfree_skb(a)       consume_skb(a)
+#define dev_consume_skb(a)     kfree_skb_clean(a)
 extern void          skb_over_panic(struct sk_buff *skb, int len,
                                     void *here);
 extern void          skb_under_panic(struct sk_buff *skb, int len,
index 5e2ac0c4b07cfdab7b2a5a2c74e2c2ddcd337328..d0de644b378d5a71e161a905c85d847622df49d2 100644 (file)
@@ -208,7 +208,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
 
 void skb_free_datagram(struct sock *sk, struct sk_buff *skb)
 {
-       kfree_skb(skb);
+       consume_skb(skb);
        sk_mem_reclaim_partial(sk);
 }
 
index e5e2111a397d1d0559ab171c663b5f50c457a2ce..6acbf9e79eb1dc2076bc192f774c8b5591566c42 100644 (file)
@@ -65,6 +65,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
+#include <trace/skb.h>
 
 #include "kmap_skb.h"
 
@@ -442,10 +443,31 @@ void kfree_skb(struct sk_buff *skb)
                smp_rmb();
        else if (likely(!atomic_dec_and_test(&skb->users)))
                return;
+       trace_kfree_skb(skb, __builtin_return_address(0));
        __kfree_skb(skb);
 }
 EXPORT_SYMBOL(kfree_skb);
 
+/**
+ *     consume_skb - free an skbuff
+ *     @skb: buffer to free
+ *
+ *     Drop a ref to the buffer and free it if the usage count has hit zero
+ *     Functions identically to kfree_skb, but kfree_skb assumes that the frame
+ *     is being dropped after a failure and notes that
+ */
+void consume_skb(struct sk_buff *skb)
+{
+       if (unlikely(!skb))
+               return;
+       if (likely(atomic_read(&skb->users) == 1))
+               smp_rmb();
+       else if (likely(!atomic_dec_and_test(&skb->users)))
+               return;
+       __kfree_skb(skb);
+}
+EXPORT_SYMBOL(consume_skb);
+
 /**
  *     skb_recycle_check - check if skb can be reused for receive
  *     @skb: buffer
index 3d67d1ffed7715f2a90aaf50307bab8a9f078b1c..9c220323f3534b0e6dd4397a547cb3040f11ba0b 100644 (file)
@@ -892,7 +892,7 @@ static int arp_process(struct sk_buff *skb)
 out:
        if (in_dev)
                in_dev_put(in_dev);
-       kfree_skb(skb);
+       consume_skb(skb);
        return 0;
 }
 
index 4bd178a111d567a81a1219fdcd28ce0e10712b14..05b7abb99f699378674eb107db0f0eedc61bf2e3 100644 (file)
@@ -1184,7 +1184,7 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
                        sk = sknext;
                } while (sknext);
        } else
-               kfree_skb(skb);
+               consume_skb(skb);
        spin_unlock(&hslot->lock);
        return 0;
 }
index d8cc006fac455cce40956330d561573174b62ca1..74776de523ec52239627bf54ca7c50f546d01627 100644 (file)
@@ -584,7 +584,7 @@ drop_n_restore:
                skb->len = skb_len;
        }
 drop:
-       kfree_skb(skb);
+       consume_skb(skb);
        return 0;
 }