Commit 127c4962 authored by Davide Caratti's avatar Davide Caratti Committed by Marc Kleine-Budde
Browse files

can: add drop reasons in the receive path of AF_CAN



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: default avatarDavide Caratti <dcaratti@redhat.com>
Link: https://patch.msgid.link/20250604160605.1005704-2-dcaratti@redhat.com


Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 9e97db3c
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -121,6 +121,9 @@
	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
+3 −3
Original line number Diff line number Diff line
@@ -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;
	}