]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
can: add drop reasons in the receive path of AF_CAN
authorDavide Caratti <dcaratti@redhat.com>
Wed, 4 Jun 2025 16:06:04 +0000 (18:06 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 10 Jun 2025 08:23:30 +0000 (10:23 +0200)
Besides the existing pr_warn_once(), use skb drop reasons in case AF_CAN
layer drops non-conformant CAN{,FD,XL} frames, or conformant frames
received by "wrong" devices, so that it's possible to debug (and count)
such events using existing tracepoints:

| # perf record -e skb:kfree_skb -aR -- ./drv/canfdtest -v -g -l 1 vcan0
| # perf script
| [...]
| canfdtest  1123 [000]  3893.271264: skb:kfree_skb: skbaddr=0xffff975703c9f700 rx_sk=(nil) protocol=12 location=can_rcv+0x4b  reason: CAN_RX_INVALID_FRAME

Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Link: https://patch.msgid.link/20250604160605.1005704-2-dcaratti@redhat.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
include/net/dropreason-core.h
net/can/af_can.c

index bcf9d7467e1a119ddd2d4c2b99befcbc700287a0..b9e78290269e6e7d9d9155171f6b0ef03c7697c9 100644 (file)
        FN(ARP_PVLAN_DISABLE)           \
        FN(MAC_IEEE_MAC_CONTROL)        \
        FN(BRIDGE_INGRESS_STP_STATE)    \
+       FN(CAN_RX_INVALID_FRAME)        \
+       FN(CANFD_RX_INVALID_FRAME)      \
+       FN(CANXL_RX_INVALID_FRAME)      \
        FNe(MAX)
 
 /**
@@ -573,6 +576,21 @@ enum skb_drop_reason {
         * ingress bridge port does not allow frames to be forwarded.
         */
        SKB_DROP_REASON_BRIDGE_INGRESS_STP_STATE,
+       /**
+        * @SKB_DROP_REASON_CAN_RX_INVALID_FRAME: received
+        * non conform CAN frame (or device is unable to receive CAN frames)
+        */
+       SKB_DROP_REASON_CAN_RX_INVALID_FRAME,
+       /**
+        * @SKB_DROP_REASON_CANFD_RX_INVALID_FRAME: received
+        * non conform CAN-FD frame (or device is unable to receive CAN frames)
+        */
+       SKB_DROP_REASON_CANFD_RX_INVALID_FRAME,
+       /**
+        * @SKB_DROP_REASON_CANXL_RX_INVALID_FRAME: received
+        * non conform CAN-XL frame (or device is unable to receive CAN frames)
+        */
+       SKB_DROP_REASON_CANXL_RX_INVALID_FRAME,
        /**
         * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
         * shouldn't be used as a real 'reason' - only for tracing code gen
index 4aab7033c933098f115a61154047656f18dcdb25..b2387a46794a576973f3d865a5ca8e2ba696d167 100644 (file)
@@ -683,7 +683,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
                pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
                             dev->type, skb->len);
 
-               kfree_skb(skb);
+               kfree_skb_reason(skb, SKB_DROP_REASON_CAN_RX_INVALID_FRAME);
                return NET_RX_DROP;
        }
 
@@ -698,7 +698,7 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
                pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
                             dev->type, skb->len);
 
-               kfree_skb(skb);
+               kfree_skb_reason(skb, SKB_DROP_REASON_CANFD_RX_INVALID_FRAME);
                return NET_RX_DROP;
        }
 
@@ -713,7 +713,7 @@ static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
                pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n",
                             dev->type, skb->len);
 
-               kfree_skb(skb);
+               kfree_skb_reason(skb, SKB_DROP_REASON_CANXL_RX_INVALID_FRAME);
                return NET_RX_DROP;
        }