From: Andre Naujoks <nautsch2@gmail.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>
Cc: "linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: Re: [PATCH] can: add new socket option CAN_RAW_FILTER_UNIQUE to eliminate duplicate matches
Date: Tue, 17 Mar 2015 16:40:21 +0100 [thread overview]
Message-ID: <55084AE5.4020908@gmail.com> (raw)
In-Reply-To: <5508477F.80303@hartkopp.net>
On 17.03.2015 16:25, Oliver Hartkopp wrote:
> Hi Marc,
>
> I know why I thought it will get messy ...
>
> E.g. when you notch three CAN IDs like this:
>
> candump can0,100~7FF,200~7FF,400~7FF
>
> You will get *without* the unify option:
>
> cansend can0 100# -> two times CAN frame with 0x100
> cansend can0 200# -> two times CAN frame with 0x200
> cansend can0 400# -> two times CAN frame with 0x400
> cansend can0 333# -> three times CAN frame with 0x333
>
> You will get *with* the unify option from the posted patch:
>
> cansend can0 100# -> one time CAN frame with 0x100
> cansend can0 200# -> one time CAN frame with 0x200
> cansend can0 400# -> one time CAN frame with 0x400
> cansend can0 333# -> one time CAN frame with 0x333
>
> ... the same as 'candump can0' %-(
>
> So what you probably *want* to have is:
>
> cansend can0 100# -> no CAN frame
> cansend can0 200# -> no CAN frame
> cansend can0 400# -> no CAN frame
> cansend can0 333# -> one CAN frame with 0x333
>
> Right?
>
> An approach to solve exactly this use case could be to check whether
> *all* configured filters have passed the CAN frame.
I would like to see this as a socket option, too. That way you can
choose which way you want it. Either one filter match is required or all
filters have to match in order for a CAN-frame to pass.
Regards
Andre
>
> This could be done by counting the receptions of the identical frames:
>
> diff --git a/net/can/raw.c b/net/can/raw.c
> index e593dc7..3022c25 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -78,6 +78,7 @@ MODULE_ALIAS("can-proto-1");
> struct unique_can_frame {
> struct sk_buff *skb;
> ktime_t tstamp;
> + int rx_count;
> };
>
> struct raw_sock {
> @@ -130,11 +131,15 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
> /* eliminate multiple filter matches for the same skb */
> if (ro->filter_unique) {
> if (ro->uniq_cf.skb == oskb &&
> - ktime_equal(ro->uniq_cf.tstamp, oskb->tstamp))
> - return;
> -
> - ro->uniq_cf.skb = oskb;
> - ro->uniq_cf.tstamp = oskb->tstamp;
> + ktime_equal(ro->uniq_cf.tstamp, oskb->tstamp)){
> + ro->uniq_cf.rx_count++;
> + if (ro->uniq_cf.rx_count < ro->count)
> + return;
> + } else {
> + ro->uniq_cf.skb = oskb;
> + ro->uniq_cf.tstamp = oskb->tstamp;
> + ro->uniq_cf.rx_count = 1;
> + }
> }
>
> /* do not pass non-CAN2.0 frames to a legacy socket */
>
> (based on the patch before)
>
> But does it really make sense to put such a tricky thing into the raw
> socket?
>
> It flips the OR sematic to an AND semantic over the provided filters.
> And then the name of the socket option should be adapted too.
> Something like "all filters must match"
>
> Regards,
> Oliver
>
>
>
> On 17.03.2015 14:23, Oliver Hartkopp wrote:
>> Hi Marc,
>>
>> On 17.03.2015 13:58, Oliver Hartkopp wrote:
>>> The CAN_RAW socket can set multiple CAN identifier specific filters
>>> that lead
>>> to multiple filters in the af_can.c filter processing. These filters are
>>> indenpendent from each other which leads to logical OR'ed filters
>>> when applied.
>>>
>>> Especially when the filter is intended to notch single CAN IDs or CAN
>>> ID ranges
>>> a problem emerges when using more than just one filter: The notched
>>> CAN IDs
>>> will be delivered once while the other CAN IDs will be delivered twice.
>>>
>>> This patch implements a new option to make sure that every CAN frame
>>> which is
>>> filtered for a specific socket is only delivered once to the user space.
>>> This is independent from the number of matching CAN filters of this
>>> socket.
>>
>> Just to make sure, this patch really helps:
>>
>> With the example above all CAN frames are delivered just once. The OR'ed
>> filters still match. So you won't have the solution that you can have
>> different notched areas of CAN IDs ...
>>
>> I hope I expressed myself clearly.
>>
>> Regards,
>> Oliver
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-03-17 15:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 12:58 [PATCH] can: add new socket option CAN_RAW_FILTER_UNIQUE to eliminate duplicate matches Oliver Hartkopp
2015-03-17 13:23 ` Oliver Hartkopp
2015-03-17 15:25 ` Oliver Hartkopp
2015-03-17 15:40 ` Andre Naujoks [this message]
2015-03-17 15:36 ` Andre Naujoks
2015-03-17 15:49 ` Oliver Hartkopp
2015-03-17 15:58 ` Andre Naujoks
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=55084AE5.4020908@gmail.com \
--to=nautsch2@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=socketcan@hartkopp.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.