Commit 5a9229db authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by Paolo Abeni
Browse files

can: move ifindex to CAN skb extensions



When routing CAN frames over different CAN interfaces the interface index
skb->iif is overwritten with every single hop. To prevent sending a CAN
frame back to its originating (first) incoming CAN interface another
ifindex variable is needed, which was stored in can_skb_priv::ifindex.

Move the can_skb_priv::ifindex content to can_skb_ext::can_iif.

Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260201-can_skb_ext-v8-3-3635d790fe8b@hartkopp.net


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 96ea3a1e
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)

	skb->protocol = htons(ETH_P_CAN);
	init_can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	*cf = skb_put_zero(skb, sizeof(struct can_frame));

@@ -255,7 +255,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,

	skb->protocol = htons(ETH_P_CANFD);
	init_can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	*cfd = skb_put_zero(skb, sizeof(struct canfd_frame));

@@ -294,7 +294,7 @@ struct sk_buff *alloc_canxl_skb(struct net_device *dev,

	skb->protocol = htons(ETH_P_CANXL);
	init_can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	*cxl = skb_put_zero(skb, CANXL_HDR_SIZE + data_len);

@@ -344,8 +344,7 @@ static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb)
				return false;
		}

		can_skb_prv(skb)->ifindex = dev->ifindex;

		csx->can_iif = dev->ifindex;
		skb->ip_summed = CHECKSUM_UNNECESSARY;

		/* perform proper loopback on capable devices */
+2 −2
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ static void bcm_can_tx(struct bcm_op *op)
	}

	can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	skb_put_data(skb, cf, op->cfsiz);

@@ -1357,7 +1357,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk,
		return -ENODEV;
	}

	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;
	skb->dev = dev;
	can_skb_set_owner(skb, sk);
	err = can_send(skb, 1); /* send with loopback */
+1 −1
Original line number Diff line number Diff line
@@ -505,7 +505,7 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)

	/* is sending the skb back to the incoming interface not allowed? */
	if (!(gwj->flags & CGW_FLAGS_CAN_IIF_TX_OK) &&
	    can_skb_prv(skb)->ifindex == gwj->dst.dev->ifindex)
	    csx->can_iif == gwj->dst.dev->ifindex)
		return;

	/* clone the given skb, which has not been done in can_rcv()
+3 −3
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
	}

	can_skb_reserve(nskb);
	can_skb_prv(nskb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	nskb->dev = dev;
	can_skb_set_owner(nskb, sk);
@@ -794,7 +794,7 @@ static void isotp_send_cframe(struct isotp_sock *so)
	}

	can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	cf = (struct canfd_frame *)skb->data;
	skb_put_zero(skb, so->ll.mtu);
@@ -1031,7 +1031,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
	}

	can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = dev->ifindex;
	csx->can_iif = dev->ifindex;

	so->tx.len = size;
	so->tx.idx = 0;
+1 −1
Original line number Diff line number Diff line
@@ -905,7 +905,7 @@ static struct sk_buff *j1939_sk_alloc_skb(struct net_device *ndev,
	}

	can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = ndev->ifindex;
	csx->can_iif = ndev->ifindex;
	skb_reserve(skb, offsetof(struct can_frame, data));

	ret = memcpy_from_msg(skb_put(skb, size), msg, size);
Loading