Re: [PATCH] can: bcm: add recvmsg flags for own, local and remote traffic
From: Oliver Hartkopp
Date: Mon Jan 08 2024 - 14:01:17 EST
Hi Nicolas,
thanks for the patch!
On 07.01.24 07:44, Nicolas Maier wrote:
@@ -642,7 +666,7 @@ static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer)
static void bcm_rx_handler(struct sk_buff *skb, void *data)
{
struct bcm_op *op = (struct bcm_op *)data;
- const struct canfd_frame *rxframe = (struct canfd_frame *)skb->data;
+ struct canfd_frame *rxframe = (struct canfd_frame *)skb->data;
unsigned int i;
if (op->can_id != rxframe->can_id)
@@ -657,6 +681,13 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
return;
}
+ /* add flags to distinguish between own/local/remote CAN traffic */
+ if (skb->sk) {
+ rxframe->flags |= RX_LOCAL;
+ if (skb->sk == op->sk)
+ rxframe->flags |= RX_OWN;
+ }
+
/* disable timeout */
hrtimer_cancel(&op->timer);
No. You are writing to a read-only skbuff, which is not yet cloned or
copied. The read-only handling of the skb is done in the NET_RX_SOFTIRQ
triggering can_rcv_filter() and friends.
See this note:
https://elixir.bootlin.com/linux/v6.7/source/net/can/af_can.c#L430
When you are also changing the CAN frames' content you need to
skb_copy() the provided skb, see:
https://elixir.bootlin.com/linux/v6.7/source/net/can/gw.c#L504
So if you want to pass these new flags to the user space you should
think of extending the parameter list of bcm_rx_update_and_send() and
bcm_rx_cmp_to_index().
But in the first place I'm interested to know what the use-case for this
extension is.
Best regards,
Oliver