linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* CAN_RAW_RECV_OWN_MSGS and filters
@ 2021-04-14 19:22 Erik Flodin
  2021-04-15  8:32 ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Erik Flodin @ 2021-04-14 19:22 UTC (permalink / raw)
  To: linux-can

Hi all,

I've been using a raw CAN socket with RECV_OWN_MSGS enabled to get a
transmission confirmation when a frame has been sent. Today when I
tried to enable filters to limit what I receive to only those frames
that I'm interested in I noticed that the filters also affected
reception of my own frames. So in order to receive all frames that I
send I must also add a filter that matches all frames that I send.

Is this the expected behavior? I can see why it works the way it does,
but I had expected that setting the RECV_OWN_MSGS flag would give me
all frames sent on the socket. Is there a way to get my expected
behavior without having to set a filter that matches all frames that I
plan to send?

// Erik

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CAN_RAW_RECV_OWN_MSGS and filters
  2021-04-14 19:22 CAN_RAW_RECV_OWN_MSGS and filters Erik Flodin
@ 2021-04-15  8:32 ` Marc Kleine-Budde
  2021-04-20 19:40   ` Erik Flodin
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-04-15  8:32 UTC (permalink / raw)
  To: Erik Flodin, Oliver Hartkopp; +Cc: linux-can

[-- Attachment #1: Type: text/plain, Size: 1743 bytes --]

On 14.04.2021 21:22:50, Erik Flodin wrote:
> I've been using a raw CAN socket with RECV_OWN_MSGS enabled to get a
> transmission confirmation when a frame has been sent. Today when I
> tried to enable filters to limit what I receive to only those frames
> that I'm interested in I noticed that the filters also affected
> reception of my own frames. So in order to receive all frames that I
> send I must also add a filter that matches all frames that I send.
> 
> Is this the expected behavior?

At least it's implemented this way.

On TX complete of a CAN frame it's pushed into the RX path of the
networking stack, along with the information of the originating socket.

Then the CAN frame is delivered into AF_CAN, where it is passed on to
all registered receivers depending on filters. One receiver is the
sending socket in CAN_RAW. Then in CAN_RAW the it is checked if the
sending socket has RECV_OWN_MSGS enabled.

> I can see why it works the way it does, but I had expected that
> setting the RECV_OWN_MSGS flag would give me all frames sent on the
> socket. Is there a way to get my expected behavior without having to
> set a filter that matches all frames that I plan to send?

I don't think there's a way to do that without modifying the kernel
code. One option is to add a new sockopt RECV_OWN_MSGS_ALL or
RECV_OWN_MSGS_UNFILTERED. The CAN_RAW can then register another receiver
at AF_CAN for own messages only.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CAN_RAW_RECV_OWN_MSGS and filters
  2021-04-15  8:32 ` Marc Kleine-Budde
@ 2021-04-20 19:40   ` Erik Flodin
  0 siblings, 0 replies; 3+ messages in thread
From: Erik Flodin @ 2021-04-20 19:40 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: Oliver Hartkopp, linux-can

On Thu, 15 Apr 2021 at 10:32, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>
> On 14.04.2021 21:22:50, Erik Flodin wrote:
> > I've been using a raw CAN socket with RECV_OWN_MSGS enabled to get a
> > transmission confirmation when a frame has been sent. Today when I
> > tried to enable filters to limit what I receive to only those frames
> > that I'm interested in I noticed that the filters also affected
> > reception of my own frames. So in order to receive all frames that I
> > send I must also add a filter that matches all frames that I send.
> >
> > Is this the expected behavior?
>
> At least it's implemented this way.
>
> On TX complete of a CAN frame it's pushed into the RX path of the
> networking stack, along with the information of the originating socket.
>
> Then the CAN frame is delivered into AF_CAN, where it is passed on to
> all registered receivers depending on filters. One receiver is the
> sending socket in CAN_RAW. Then in CAN_RAW the it is checked if the
> sending socket has RECV_OWN_MSGS enabled.

Thanks for the explanation. I've sent a patch to clarify in the
documentation that the socket's own frames are also subject to
filtering.

> I don't think there's a way to do that without modifying the kernel
> code. One option is to add a new sockopt RECV_OWN_MSGS_ALL or
> RECV_OWN_MSGS_UNFILTERED. The CAN_RAW can then register another receiver
> at AF_CAN for own messages only.

I'll see if I can figure something out. Unless someone beats me to it :)

// Erik

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-20 19:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 19:22 CAN_RAW_RECV_OWN_MSGS and filters Erik Flodin
2021-04-15  8:32 ` Marc Kleine-Budde
2021-04-20 19:40   ` Erik Flodin

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).