Commit af424041 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde
Browse files

Merge patch series "can: add drop reasons in the receive path"

Davide Caratti <dcaratti@redhat.com> says:

drop reasons have been recently introduced to improve debuggability of
networking stack. This series introduces drop reasons in the RX path
of the CAN protocol stack.

Link: https://patch.msgid.link/20250604160605.1005704-1-dcaratti@redhat.com


Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents 9e97db3c 81807451
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;
	}

+3 −2
Original line number Diff line number Diff line
@@ -359,6 +359,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
	unsigned int datalen = head->nframes * op->cfsiz;
	int err;
	unsigned int *pflags;
	enum skb_drop_reason reason;

	skb = alloc_skb(sizeof(*head) + datalen, gfp_any());
	if (!skb)
@@ -413,11 +414,11 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
	addr->can_family  = AF_CAN;
	addr->can_ifindex = op->rx_ifindex;

	err = sock_queue_rcv_skb(sk, skb);
	err = sock_queue_rcv_skb_reason(sk, skb, &reason);
	if (err < 0) {
		struct bcm_sock *bo = bcm_sk(sk);

		kfree_skb(skb);
		sk_skb_reason_drop(sk, skb, reason);
		/* don't care about overflows in this statistic */
		bo->dropped_usr_msgs++;
	}
+3 −2
Original line number Diff line number Diff line
@@ -278,6 +278,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
{
	struct sockaddr_can *addr = (struct sockaddr_can *)skb->cb;
	enum skb_drop_reason reason;

	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can));

@@ -285,8 +286,8 @@ static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
	addr->can_family = AF_CAN;
	addr->can_ifindex = skb->dev->ifindex;

	if (sock_queue_rcv_skb(sk, skb) < 0)
		kfree_skb(skb);
	if (sock_queue_rcv_skb_reason(sk, skb, &reason) < 0)
		sk_skb_reason_drop(sk, skb, reason);
}

static u8 padlen(u8 datalen)
+3 −2
Original line number Diff line number Diff line
@@ -311,6 +311,7 @@ static void j1939_sk_recv_one(struct j1939_sock *jsk, struct sk_buff *oskb)
{
	const struct j1939_sk_buff_cb *oskcb = j1939_skb_to_cb(oskb);
	struct j1939_sk_buff_cb *skcb;
	enum skb_drop_reason reason;
	struct sk_buff *skb;

	if (oskb->sk == &jsk->sk)
@@ -331,8 +332,8 @@ static void j1939_sk_recv_one(struct j1939_sock *jsk, struct sk_buff *oskb)
	if (skb->sk)
		skcb->msg_flags |= MSG_DONTROUTE;

	if (sock_queue_rcv_skb(&jsk->sk, skb) < 0)
		kfree_skb(skb);
	if (sock_queue_rcv_skb_reason(&jsk->sk, skb, &reason) < 0)
		sk_skb_reason_drop(&jsk->sk, skb, reason);
}

bool j1939_sk_recv_match(struct j1939_priv *priv, struct j1939_sk_buff_cb *skcb)
Loading