em_canid: Ematch rule to match CAN frames according to their identifiers
Subsystems (5)
PATCH v3 1/1 em_canid: Ematch rule to match CAN frames according to their identifiers
This ematch makes it possible to classify CAN frames (AF_CAN) according to their identifiers. This functionality can not be easily achieved with existing classifiers, such as u32, because CAN identifier is always stored in native endianness, whereas u32 expects Network byte order.
---
Results of simple benchmark are available at address:
http://rtime.felk.cvut.cz/~lisovros/em_canid_benchmark.pdf
In short: there is no significant difference between em_canid and cls_can (i.e. stand-alone AF_CAN classifier).
Changes in v3:
* Added zero-length check for configuration data
* Small fixes in patch format (patch created against net-next)
Changes in v2:
* Integrated remarks received from the mailing list
* Array containing rules (rules_raw) is dynamically allocated
* When processing a rule during configuration, CAN_EFF_FLAG in mask determines if we care about the value of CAN_EFF_FLAG in an identifier -- i.e. when CAN_EFF_FLAG is set in the mask, the rule will be added as SFF or EFF only depending on CAN_EFF_FLAG value in the identifier. If CAN_EFF_FLAG is 0 in the mask, the rule will be added as both SFF and EFF.
--- include/linux/can.h | 3 + include/linux/pkt_cls.h | 5 +- net/sched/Kconfig | 10 ++ net/sched/Makefile | 1 + net/sched/em_canid.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 net/sched/em_canid.c
include/linux/can.h +3 -0
@@ -38,6 +38,9 @@*/ typedef __u32 canid_t ; +#define CAN_SFF_ID_BITS 11 +#define CAN_EFF_ID_BITS 29 +/* * Controller Area Network Error Message Frame Mask structure *
include/linux/pkt_cls.h +3 -2
@@ -451,8 +451,9 @@ enum {#define TCF_EM_U32 3#define TCF_EM_META 4#define TCF_EM_TEXT 5 -#define TCF_EM_VLAN 6 -#define TCF_EM_MAX 6 +#define TCF_EM_VLAN 6 +#define TCF_EM_CANID 7 +#define TCF_EM_MAX 7enum {TCF_EM_PROG_TC
net/sched/Kconfig +10 -0
@@ -507,6 +507,16 @@ config NET_EMATCH_TEXT To compile this code as a module, choose M here: the module will be called em_text. +config NET_EMATCH_CANID + tristate "CAN Identifier" + depends on NET_EMATCH && CAN + ---help--- + Say Y here if you want to be able to classify CAN frames based + on CAN Identifier. + + To compile this code as a module, choose M here: the + module will be called em_canid. + config NET_CLS_ACT bool "Actions" ---help---
net/sched/Makefile +1 -0
@@ -55,3 +55,4 @@ obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o obj-$(CONFIG_NET_EMATCH_U32) += em_u32.o obj-$(CONFIG_NET_EMATCH_META) += em_meta.o obj-$(CONFIG_NET_EMATCH_TEXT) += em_text.o +obj-$(CONFIG_NET_EMATCH_CANID) += em_canid.o
net/sched/em_canid.c new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
1.7.10
Quoted 6 lines · Rostislav Lisovy
This ematch makes it possible to classify CAN frames (
AF_CAN) according to their identifiers. This functionality can not be easily achieved with existing classifiers, such as u32, because CAN identifier is always stored in native endianness, whereas u32 expects Network byte order.Signed-off-by Rostislav Lisovy <[email protected]>
Thanks Rostislav!
Oliver Hartkopp
maintainerUgh - sorry.
I still found some issues ...
net/sched/em_canid.c line 128
Quoted 7 lines · Rostislav Lisovy
net/sched/em_canid.c new file +7
-0+ +static int em_canid_change (struct tcf_proto *tp,void *data,int len, +struct tcf_ematch *m) +{ +struct can_filter *conf = data;/* Array with rules, +* fixed size EM_CAN_RULES_SIZE +*/
Remove this comment.
It's only an "array with rules" - but EM_CAN_RULES_SIZE is absent in the code now.
Quoted 13 lines
net/sched/em_canid.c new file +13
-0+struct canid_match *cm; +struct canid_match *cm_old = (struct canid_match *)m->data; +int i; +int rulescnt; + +if (!len) +return -EINVAL ; + +if (len %sizeof (struct can_filter )) +return -EINVAL ; + +if (len >sizeof (struct can_filter ) *EM_CAN_RULES_MAX ) +return -EINVAL ;
net/sched/em_canid.c line 151
Quoted 10 lines
net/sched/em_canid.c new file +10
-0+ + rulescnt = len /sizeof (struct can_filter ); + + cm =kzalloc (sizeof (struct canid_match ) +sizeof (struct can_filter ) * + rulescnt,GFP_KERNEL ); +if (!cm) +return -ENOMEM ; + + cm->sff_rules_count =0 ; + cm->eff_rules_count =0 ;
These two lines are obsolete as you used kzalloc(), right?
net/sched/em_canid.c line 160
Quoted 9 lines
net/sched/em_canid.c new file +9
-0+ cm->rules_count = rulescnt; + +/* +* We need two for() loops for copying rules into +* two contiguous areas in rules_raw +*/ + +/* Process EFF frame rules*/ +for (i =0 ; i < cm->rules_count; i++) {
use rulescnt instead of cm->rules_count (no need to derefence data)
Quoted 5 lines
net/sched/em_canid.c new file +5
-0+if (((conf[i].can_id &CAN_EFF_FLAG ) && + (conf[i].can_mask &CAN_EFF_FLAG )) || + !(conf[i].can_mask &CAN_EFF_FLAG )) { + memcpy(cm->rules_raw + cm->eff_rules_count, + &conf[i],
net/sched/em_canid.c line 175
Quoted 10 lines
net/sched/em_canid.c new file +10
-0+ sizeof(struct can_filter)); + + cm->eff_rules_count++; + }else { +continue ; + } + } + +/* Process SFF frame rules */ +for (i =0 ; i < cm->rules_count; i++) {
use rulescnt instead of cm->rules_count (no need to derefence data)
net/sched/em_canid.c line 177
Quoted 2 lines
net/sched/em_canid.c new file +2
-0+if ((conf[i].can_id &CAN_EFF_FLAG ) && + (conf[i].can_mask &CAN_EFF_FLAG )) {
|| !(conf[i].can_mask & CAN_EFF_FLAG)) {
is missing here (must be the same as the condition above!)
Quoted 5 lines
net/sched/em_canid.c new file +5
-0+continue ; + }else { + memcpy(cm->rules_raw + + cm->eff_rules_count + + cm->sff_rules_count,
net/sched/em_canid.c line 192
Quoted 10 lines
net/sched/em_canid.c new file +10
-0+ &conf[i], sizeof(struct can_filter)); + + cm->sff_rules_count++; + +em_canid_sff_match_add (cm, + conf[i].can_id, conf[i].can_mask); + } + } + + m->datalen =sizeof (*cm);
*cm is no longer a fixed structure as it was in the first patches.
Must be:
m->datalen = sizeof(struct canid_match) + sizeof(struct can_filter) * rulescnt
net/sched/em_canid.c line 194
Quoted 2 lines
net/sched/em_canid.c new file +2
-0+ m->data = (unsigned long )cm; +
Sorry, that i didn't see that before :-(
Regards,
Oliver
Oliver Hartkopp
maintainerOne more simplification:
Quoted 4 lines
net/sched/em_canid.c line 146
Quoted 4 lines
net/sched/em_canid.c new file +4
-0+ rulescnt = len /sizeof (struct can_filter ); + + cm =kzalloc (sizeof (struct canid_match ) +sizeof (struct can_filter ) * + rulescnt,GFP_KERNEL );
No need to multiply the value again ... you can take the len value as-is:
cm = kzalloc(sizeof(struct canid_match) + len, GFP_KERNEL);
Quoted 6 lines
*cm is no longer a fixed structure as it was in the first patches.
Must be:
m->datalen=sizeof(struct canid_match)+sizeof(struct can_filter)* rulescnt
dito:
m->datalen = sizeof(struct canid_match) + len;
Regards,
Oliver
Oliver Hartkopp
maintainerAwaiting upsteam? - Re: [PATCH net-next v3] em_canid: Ematch rule to match CAN frames according to their identifiers
Hello Dave,
i've seen that you tagged this patch as "Awaiting upstream" in Patchwork.
Does this mean, that *you* are waiting for another re-spin of the patch OR do you expect this patch go through a sub-tree like Marcs can-next tree?
Who is committing these "awaiting upstream" patches?
Thanks for clarification,
Oliver
David Miller
maintainerRe: Awaiting upsteam? - Re: [PATCH net-next v3] em_canid: Ematch rule to match CAN frames according to their identifiers
From: Oliver Hartkopp <[email protected]>
Date: Tue, 03 Jul 2012 07:15:49 +0200
Quoted 6 lines
Hello Dave,
i've seen that you tagged this patch as "Awaiting upstream" in Patchwork.
Does this mean, that *you* are waiting for another re-spin of the patch OR do you expect this patch go through a sub-tree like Marcs can-next tree?
It should go through the CAN tree.