Skip to contentSkip to conversation

em_canid: Ematch rule to match CAN frames according to their identifiers

PATCH In review Oliver Hartkopp 1 participant 2 messages Jul 4, 2012 – Jul 6, 2012

Subsystems (5)
lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

PATCH v4 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 v4:
* fixed obsolete comment due to code changes
* removed obsolete rulescnt variable
* removed obsolete initialisation due to kzalloc()
* fixed the SFF frame detection for the rules_raw processing
* fixed the m->datalen value to the allocated memory size

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    |  243 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 260 insertions(+), 2 deletions(-)
 create mode 100644 net/sched/em_canid.c
include/linux/can.h +2 -0
index 1a66cf61..018055e 100644
@@ -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
index defbde2..7fbe6c2 100644
@@ -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		7
  enum {
 	TCF_EM_PROG_TC
net/sched/Kconfig +9 -0
index e7a8976..8f759b6 100644
@@ -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
index 5940a19..bcada75 100644
@@ -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 +243 -0

243 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw
Quoted 7 lines · Oliver Hartkopp

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.

This patch is originally from Rostislav and is already part of this can-next pull request:

http://marc.info/?l=linux-netdev&m=134141429413608&w=2

Tnx & regards,
Oliver