net/sched/em_canid: Ematch rule to match CAN frames according to their CAN IDs
Subsystems (5)
RFC 1/1 net/sched/em_canid: Ematch rule to match CAN frames according to their CAN IDs
em_canid is an ematch capable of classifying CAN frames according to their CAN IDs.
This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.
There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Example: canid(sff 0x123 eff 0x124 sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID 0x124.
--- include/linux/can.h | 3 + include/linux/pkt_cls.h | 5 +- net/sched/Kconfig | 10 +++ net/sched/Makefile | 1 + net/sched/em_canid.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 234 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 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
@@ -485,6 +485,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 ID" + depends on NET_EMATCH && CAN + ---help--- + Say Y here if you want to be able to classify CAN frames based + on CAN ID. + + 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
@@ -53,3 +53,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 +217 -0
217 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Quoted 45 lines · Rostislav Lisovy
em_canidis an ematch capable of classifying CAN frames according to their CAN IDs.This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Example: canid(sff
0x123eff0x124sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID0x124.Signed-off-by Rostislav Lisovy <[email protected]>--- include/linux/can.h | 3 + include/linux/pkt_cls.h | 5 +- net/sched/Kconfig | 10 +++ net/sched/Makefile | 1 + net/sched/em_canid.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 net/sched/em_canid.cinclude/linux/can.h +6
-0@@ -38,6 +38,9 @@*/ typedef __u32 canid_t ; +#define CAN_SFF_ID_BITS 11 +#define CAN_EFF_ID_BITS 29 + +struct canid_match { +struct can_filter rules_raw[EM_CAN_RULES_SIZE ];/* Raw rules copied +from netlink message; Used for sending information to
include/linux/can.h
Quoted 10 lines
include/linux/can.h +10
-0+userspace (when 'tc filter show' is invoked) AND when +matching EFF frames*/ +DECLARE_BITMAP (match_sff, (1 <<CAN_SFF_ID_BITS ));/* For each SFF CAN +ID (11 bit) there is one record in this bitfield */ +int rules_count; +int eff_rules_count; +int sff_rules_count; + +struct rcu_head rcu; +};
The size of kmalloc() blob to hold this structure is 4 Mbytes
This is a huge cost, and unlikely to succeed but shortly after boot...
(this happens to be the largest possible kmalloc() allocation by the way on x86)
Quoted 59 lines · Eric Dumazet
Quoted 45 lines · Rostislav Lisovy
em_canidis an ematch capable of classifying CAN frames according to their CAN IDs.This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Example: canid(sff
0x123eff0x124sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID0x124.Signed-off-by Rostislav Lisovy <[email protected]>--- include/linux/can.h | 3 + include/linux/pkt_cls.h | 5 +- net/sched/Kconfig | 10 +++ net/sched/Makefile | 1 + net/sched/em_canid.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 net/sched/em_canid.cinclude/linux/can.h +6
-0@@ -38,6 +38,9 @@*/ typedef __u32 canid_t ; +#define CAN_SFF_ID_BITS 11 +#define CAN_EFF_ID_BITS 29 + +struct canid_match { +struct can_filter rules_raw[EM_CAN_RULES_SIZE ];/* Raw rules copied +from netlink message; Used for sending information to include/linux/can.h
Quoted 10 lines
include/linux/can.h +10
-0+userspace (when 'tc filter show' is invoked) AND when +matching EFF frames*/ +DECLARE_BITMAP (match_sff, (1 <<CAN_SFF_ID_BITS ));/* For each SFF CAN +ID (11 bit) there is one record in this bitfield */ +int rules_count; +int eff_rules_count; +int sff_rules_count; + +struct rcu_head rcu; +};The size of
kmalloc()blob to hold this structure is 4 Mbytes
Quoted 6 lines
This is a huge cost, and unlikely to succeed but shortly after boot...
(this happens to be the largest possible
kmalloc()allocation by the way on x86)
Oh well, I mixed CAN_SFF_ID_BITS / CAN_EFF_ID_BITS
Quoted 60 lines · Eric Dumazet
Quoted 59 lines · Eric Dumazet
Quoted 45 lines · Rostislav Lisovy
em_canidis an ematch capable of classifying CAN frames according to their CAN IDs.This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Example: canid(sff
0x123eff0x124sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID0x124.Signed-off-by Rostislav Lisovy <[email protected]>--- include/linux/can.h | 3 + include/linux/pkt_cls.h | 5 +- net/sched/Kconfig | 10 +++ net/sched/Makefile | 1 + net/sched/em_canid.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 net/sched/em_canid.cinclude/linux/can.h +6
-0@@ -38,6 +38,9 @@*/ typedef __u32 canid_t ; +#define CAN_SFF_ID_BITS 11 +#define CAN_EFF_ID_BITS 29 + +struct canid_match { +struct can_filter rules_raw[EM_CAN_RULES_SIZE ];/* Raw rules copied +from netlink message; Used for sending information to include/linux/can.h
Quoted 10 lines
include/linux/can.h +10
-0+userspace (when 'tc filter show' is invoked) AND when +matching EFF frames*/ +DECLARE_BITMAP (match_sff, (1 <<CAN_SFF_ID_BITS ));/* For each SFF CAN +ID (11 bit) there is one record in this bitfield */ +int rules_count; +int eff_rules_count; +int sff_rules_count; + +struct rcu_head rcu; +};The size of
kmalloc()blob to hold this structure is 4 Mbytes
Quoted 10 lines
Quoted 6 lines
This is a huge cost, and unlikely to succeed but shortly after boot...
(this happens to be the largest possible
kmalloc()allocation by the way on x86)Oh well, I mixed
CAN_SFF_ID_BITS/CAN_EFF_ID_BITS
Indeed; On x86_64 the sizeof(struct canid_match) is 544 bytes;
Regards;
Rostislav Lisovy
Oliver Hartkopp
maintainerHello Rostislav, hello Eric,
Quoted 19 lines · Rostislav Lisovy
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · Rostislav Lisovy
em_canidis an ematch capable of classifying CAN frames according to their CAN IDs.This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Example: canid(sff
0x123eff0x124sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID0x124.
i tried to figure out the difference between the implementation as classifier (link above) and this implementation as an ematch.
Do we have any disadvantages using the ematch? E.g. is it still possible to add additional ematches like checking for patterns inside can_frame.data[] (which is located in skb->data) with ematch_u32 or e.g. ematch_text ??
...
Btw.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
net/sched/em_canid.c line 29
Quoted 7 lines
net/sched/em_canid.c new file +7
-0+struct canid_match { +struct can_filter rules_raw[EM_CAN_RULES_SIZE ];/* Raw rules copied +from netlink message; Used for sending information to +userspace (when 'tc filter show' is invoked) AND when +matching EFF frames*/ + DECLARE_BITMAP(match_sff, (1 << CAN_SFF_ID_BITS)); /* For each SFF CAN +ID (11 bit) there is one record in this bitfield */
these comments have a styling problem :-)
Additional to these checkpatch warnings:
WARNING: line over 80 characters
#144: FILE: net/sched/em_canid.c:48:
+static void em_canid_sff_match_add(struct canid_match *cm, u32 can_id, u32 can_mask)
WARNING: line over 80 characters
#231: FILE: net/sched/em_canid.c:135:
+ if (cm->rules_count > EM_CAN_RULES_SIZE) /* Be sure to fit into the array */
WARNING: line over 80 characters
#256: FILE: net/sched/em_canid.c:160:
+ memcpy(cm->rules_raw + cm->eff_rules_count + cm->sff_rules_count,
Tnx & regards,
Oliver
Hello Oliver,
Quoted 23 lines · Oliver Hartkopp
Hello Rostislav, hello Eric,
Quoted 19 lines · Rostislav Lisovy
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · Rostislav Lisovy
em_canidis an ematch capable of classifying CAN frames according to their CAN IDs.This RFC/Patch contains a reworked classifier initially posted in
http://www.spinics.net/lists/netdev/msg200114.html
The functionality is the same however there is almost 50% reduction in the source code length.There is a slight difference between this ematch and other available ematches. Other ematches implement only a simple match operation and are meant to be combined with logic conjunctions (e.g. AND, OR). Our ematch makes it possible to use up to 32 rules in single 'configuration statement' (with OR semantics). This allows us to take the advantage of the bit field data-structure in the implementation of the match function.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Example: canid(sff
0x123eff0x124sff 0x230:0x7f0) This ematch would match CAN SFF frames with the following IDs:0x123, 0x230--0x23f or EFF frame with ID0x124.i tried to figure out the difference between the implementation as classifier (link above) and this implementation as an ematch.
Do we have any disadvantages using the ematch?
The performance of ematch might be slightly lower than of standalone classifier. Rosta will compare the performance soon.
Quoted 3 lines
E.g. is it still possible to add additional ematches like checking for patterns inside can_frame.data[] (which is located in
skb->data) withematch_u32or e.g.ematch_text??
AFAIK, this should be possible and it will be a big advantage over implementation as a standalone classifier.
Regards,
-Michal
Quoted 2 lines · Michal Sojka
The performance of ematch might be slightly lower than of standalone classifier. Rosta will compare the performance soon.
I think it doesn't make a difference, there is no additional locking involved. Numbers definitely welcome though.
Quoted 6 lines
Quoted 3 lines
E.g. is it still possible to add additional ematches like checking for patterns inside can_frame.data[] (which is located in
skb->data) withematch_u32or e.g.ematch_text??AFAIK, this should be possible and it will be a big advantage over implementation as a standalone classifier.
Definitely and the real advantage is that you can combine these using logic operators.