net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core()
authorMenglong Dong <imagedong@tencent.com>
Sat, 5 Feb 2022 07:47:36 +0000 (15:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Jul 2022 15:25:16 +0000 (17:25 +0200)
[ Upstream commit c1f166d1f7eef212096a98b22f5acf92f9af353d ]

Replace kfree_skb() with kfree_skb_reason() in ip_rcv_finish_core(),
following drop reasons are introduced:

SKB_DROP_REASON_IP_RPFILTER
SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/skbuff.h
include/trace/events/skb.h
net/ipv4/ip_input.c

index 514fb8074f782ee1cfe429c75ef6623a452bfafc..cbd719e5329a4d100ffb0dad302dbead605ef726 100644 (file)
@@ -327,6 +327,15 @@ enum skb_drop_reason {
                                         * IP header (see
                                         * IPSTATS_MIB_INHDRERRORS)
                                         */
+       SKB_DROP_REASON_IP_RPFILTER,    /* IP rpfilter validate failed.
+                                        * see the document for rp_filter
+                                        * in ip-sysctl.rst for more
+                                        * information
+                                        */
+       SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, /* destination address of L2
+                                                 * is multicast, but L3 is
+                                                 * unicast.
+                                                 */
        SKB_DROP_REASON_MAX,
 };
 
index f2b1778485f01b7a9d79507a486ac0aa0de18258..485a1d3034a4b2c59808b7b5b6b31e923a549333 100644 (file)
@@ -20,6 +20,9 @@
        EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST)                \
        EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM)                    \
        EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR)                  \
+       EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER)            \
+       EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,             \
+          UNICAST_IN_L2_MULTICAST)                             \
        EMe(SKB_DROP_REASON_MAX, MAX)
 
 #undef EM
index 7be18de32e16e8606e0b79efd36516ec98587aff..d5222c0fa87cb6f51a209e07eb26ccecd73319f6 100644 (file)
@@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
 {
        const struct iphdr *iph = ip_hdr(skb);
        int (*edemux)(struct sk_buff *skb);
+       int err, drop_reason;
        struct rtable *rt;
-       int err;
+
+       drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
 
        if (ip_can_use_hint(skb, iph, hint)) {
                err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos,
@@ -396,19 +398,23 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
                 * so-called "hole-196" attack) so do it for both.
                 */
                if (in_dev &&
-                   IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST))
+                   IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) {
+                       drop_reason = SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST;
                        goto drop;
+               }
        }
 
        return NET_RX_SUCCESS;
 
 drop:
-       kfree_skb(skb);
+       kfree_skb_reason(skb, drop_reason);
        return NET_RX_DROP;
 
 drop_error:
-       if (err == -EXDEV)
+       if (err == -EXDEV) {
+               drop_reason = SKB_DROP_REASON_IP_RPFILTER;
                __NET_INC_STATS(net, LINUX_MIB_IPRPFILTER);
+       }
        goto drop;
 }