linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [RFC PATCH] vxcan: remove sk reference in peer skb
Date: Sat, 19 Jun 2021 14:11:59 +0200	[thread overview]
Message-ID: <20210619121159.1805-1-socketcan@hartkopp.net> (raw)

With can_create_echo_skb() the skb which is forwarded to the peer CAN
interface shares the sk pointer from the originating socket.
This makes the CAN frame show up in the peer namespace as a TX packet.

With the use of skb_clone() analogue to the handling in gw.c the peer
skb gets a new start in the peer namespace and correctly appears as
a RX packet.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/vxcan.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
index be5566168d0f..e5fd8b9bfca5 100644
--- a/drivers/net/can/vxcan.c
+++ b/drivers/net/can/vxcan.c
@@ -35,10 +35,11 @@ struct vxcan_priv {
 
 static netdev_tx_t vxcan_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct vxcan_priv *priv = netdev_priv(dev);
 	struct net_device *peer;
+	struct sk_buff *nskb;
 	struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 	struct net_device_stats *peerstats, *srcstats = &dev->stats;
 	u8 len;
 
 	if (can_dropped_invalid_skb(dev, skb))
@@ -50,22 +51,26 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *skb, struct net_device *dev)
 		kfree_skb(skb);
 		dev->stats.tx_dropped++;
 		goto out_unlock;
 	}
 
-	skb = can_create_echo_skb(skb);
-	if (!skb)
+	nskb = skb_clone(skb, GFP_ATOMIC);
+	if (nskb)
+		consume_skb(skb);
+	else {
+		kfree_skb(skb);
 		goto out_unlock;
+	}
 
 	/* reset CAN GW hop counter */
-	skb->csum_start = 0;
-	skb->pkt_type   = PACKET_BROADCAST;
-	skb->dev        = peer;
-	skb->ip_summed  = CHECKSUM_UNNECESSARY;
+	nskb->csum_start = 0;
+	nskb->pkt_type   = PACKET_BROADCAST;
+	nskb->dev        = peer;
+	nskb->ip_summed  = CHECKSUM_UNNECESSARY;
 
 	len = cfd->len;
-	if (netif_rx_ni(skb) == NET_RX_SUCCESS) {
+	if (netif_rx_ni(nskb) == NET_RX_SUCCESS) {
 		srcstats->tx_packets++;
 		srcstats->tx_bytes += len;
 		peerstats = &peer->stats;
 		peerstats->rx_packets++;
 		peerstats->rx_bytes += len;
-- 
2.30.2


                 reply	other threads:[~2021-06-19 12:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210619121159.1805-1-socketcan@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).