The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.2
------>
commit e48918b1779fb4a942d347447c2d237aa4fe50e6
Author: Menglong Dong <imaged...@tencent.com>
Date:   Tue Jan 3 17:38:58 2023 +0200

    net: ipv4: use kfree_skb_reason() in ip_rcv_core()
    
    Replace kfree_skb() with kfree_skb_reason() in ip_rcv_core(). Three new
    drop reasons are introduced:
    
    SKB_DROP_REASON_OTHERHOST
    SKB_DROP_REASON_IP_CSUM
    SKB_DROP_REASON_IP_INHDR
    
    Signed-off-by: Menglong Dong <imaged...@tencent.com>
    Reviewed-by: David Ahern <dsah...@kernel.org>
    Signed-off-by: David S. Miller <da...@davemloft.net>
    Acked-by: Nikolay Borisov <nbori...@suse.com>
    Signed-off-by: Nikolay Borisov <nikolay.bori...@virtuozzo.com>
    
    ======
    Patchset description:
    ms/net: Annotate skb free sites with reason
    
    This series backports most of the patches that add a reason to skb free 
sites.
    
    https://jira.sw.ru/browse/PSBM-143302
    
    Feature: net: improve verbosity of dropped packets reporting
---
 include/linux/skbuff.h     | 10 ++++++++++
 include/trace/events/skb.h |  3 +++
 net/ipv4/ip_input.c        | 12 ++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 629296082a9b..3a6bc3932a70 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -319,6 +319,16 @@ enum skb_drop_reason {
        SKB_DROP_REASON_TCP_FILTER,
        SKB_DROP_REASON_UDP_CSUM,
        SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */
+       SKB_DROP_REASON_OTHERHOST,      /* packet don't belong to current
+                                        * host (interface is in promisc
+                                        * mode)
+                                        */
+       SKB_DROP_REASON_IP_CSUM,        /* IP checksum error */
+       SKB_DROP_REASON_IP_INHDR,       /* there is something wrong with
+                                        * IP header (see
+                                        * IPSTATS_MIB_INHDRERRORS)
+                                        */
+
        SKB_DROP_REASON_MAX,
 };
 
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index beed7bb2bc0e..c11dfc26bf14 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -17,6 +17,9 @@
        EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER)              \
        EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM)                  \
        EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP)      \
+       EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST)                \
+       EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM)                    \
+       EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR)                  \
        EMe(SKB_DROP_REASON_MAX, MAX)
 
 #undef EM
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 3a025c011971..7be18de32e16 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -436,13 +436,16 @@ static int ip_rcv_finish(struct net *net, struct sock 
*sk, struct sk_buff *skb)
 static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
 {
        const struct iphdr *iph;
+       int drop_reason;
        u32 len;
 
        /* When the interface is in promisc. mode, drop all the crap
         * that it receives, do not try to analyse it.
         */
-       if (skb->pkt_type == PACKET_OTHERHOST)
+       if (skb->pkt_type == PACKET_OTHERHOST) {
+               drop_reason = SKB_DROP_REASON_OTHERHOST;
                goto drop;
+       }
 
        __IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len);
 
@@ -452,6 +455,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, 
struct net *net)
                goto out;
        }
 
+       drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
        if (!pskb_may_pull(skb, sizeof(struct iphdr)))
                goto inhdr_error;
 
@@ -488,6 +492,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, 
struct net *net)
 
        len = ntohs(iph->tot_len);
        if (skb->len < len) {
+               drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL;
                __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS);
                goto drop;
        } else if (len < (iph->ihl*4))
@@ -516,11 +521,14 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, 
struct net *net)
        return skb;
 
 csum_error:
+       drop_reason = SKB_DROP_REASON_IP_CSUM;
        __IP_INC_STATS(net, IPSTATS_MIB_CSUMERRORS);
 inhdr_error:
+       if (drop_reason == SKB_DROP_REASON_NOT_SPECIFIED)
+               drop_reason = SKB_DROP_REASON_IP_INHDR;
        __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS);
 drop:
-       kfree_skb(skb);
+       kfree_skb_reason(skb, drop_reason);
 out:
        return NULL;
 }
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to