]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
'tc filter show' seems to work correctly. Fixed setting of EFF_FLAG not only for...
authorRostislav Lisovy <lisovy@gmail.com>
Mon, 22 Aug 2011 15:53:00 +0000 (17:53 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Wed, 23 May 2012 08:45:12 +0000 (10:45 +0200)
tc/f_canprio.c

index 0fc0edb2c0ea6de125da15d32b6fb0903924e9f2..079271d7f8795dc88d9fd54d1a7d02e403a3335c 100644 (file)
@@ -6,11 +6,13 @@
  *             as published by the Free Software Foundation; either version
  *             2 of the License, or (at your option) any later version.
  *
- * FIXME add patch made by Oliver 
+ * Idea:       Oliver Hartkopp <oliver.hartkopp@volkswagen.de> 
  * Copyright:  (c) 2011 Czech Technical University in Prague
+ *             (c) 2011 Volkswagen Group Research
  * Authors:    Michal Sojka <sojkam1@fel.cvut.cz>
  *             Pavel Pisa <pisa@cmp.felk.cvut.cz>
  *             Rostislav Lisovy <lisovy@kormus.cz>
+ * Founded by: Volkswagen Group Research
  */
 
 #include <stdio.h>
@@ -91,8 +93,8 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
        addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
        while (argc > 0) {
+//---------------------- legacy option; will be deleted in future -------------
                if (matches(*argv, "match") == 0) {
-                       //printf("  [parsing match ...");
                        NEXT_ARG();
 
                        if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) { 
@@ -106,8 +108,9 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                                canprio_rules[rules_count].can_mask = can_mask;
                                rules_count++;
                        }
+//---------------------- legacy option; will be deleted in future -------------
 
-               } else if (matches(*argv, "matchid") == 0) {
+               } else if (matches(*argv, "matchid") == 0) { //Parse SFF ID
                        NEXT_ARG();
 
                        if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) { 
@@ -115,8 +118,8 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                                return -1;
                        }
 
-                       if (can_id & ~CAN_SFF_MASK) {
-                               fprintf(stderr, "Id 0x%lx exceeded standard CAN ID range.\n", 
+                       if (can_id & ~CAN_SFF_MASK) { //FIXME what about RTR flags?
+                               fprintf(stderr, "ID 0x%lx exceeded standard CAN ID range.\n", 
                                        (unsigned long)can_id);
                                return -1;
                        }
@@ -125,7 +128,7 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                        canprio_rules[rules_count].can_mask = (can_mask & CAN_SFF_MASK);
                        rules_count++;
 
-               } else if (matches(*argv, "matcheid") == 0) {
+               } else if (matches(*argv, "matcheid") == 0) { //Parse EFF ID
                        NEXT_ARG();
 
                        if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) { 
@@ -134,13 +137,14 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                        }
 
                        if (can_id & ~CAN_EFF_MASK) {
-                               fprintf(stderr, "Id 0x%lx exceeded extended CAN ID range.", 
+                               fprintf(stderr, "ID 0x%lx exceeded extended CAN ID range.", 
                                        (unsigned long)can_id);
                                return -1;
                        }
 
                        canprio_rules[rules_count].can_id = can_id | CAN_EFF_FLAG;
-                       canprio_rules[rules_count].can_mask = (can_mask & CAN_EFF_MASK);
+                       canprio_rules[rules_count].can_mask = 
+                               (can_mask & CAN_EFF_MASK) | CAN_EFF_FLAG;
                        rules_count++;
                        
                } else if (matches(*argv, "classid") == 0 ||
@@ -174,9 +178,10 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
 }
 
 /* When "tc filter show dev XY" is executed, function canprio_walk() (in kernel)
-is called (which calls canprio_dump() for each instance of a filter) which sends
-information about each instance of a filters to userspace -- to this function 
-(which parses the message and prints it. */
+ * is called (which calls canprio_dump() for each instance of a filter) which sends
+ * information about each instance of a filters to userspace -- to this function 
+ * (which parses the message and prints it. 
+ */
 static int canprio_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
                         __u32 handle)
 {
@@ -200,22 +205,27 @@ static int canprio_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt
                        sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_BASIC_CLASSID]), b1));
        }
 
-/*     if (tb[TCA_CANPRIO_RULES]) {
+       if (tb[TCA_CANPRIO_RULES]) {
                if (RTA_PAYLOAD(tb[TCA_CANPRIO_RULES]) < sizeof(struct can_filter))
                        return -1;
        
                canprio_rules = RTA_DATA(tb[TCA_CANPRIO_RULES]);
-               rules_count = RTA_PAYLOAD(tb[TCA_CANPRIO_RULES]);
+               rules_count = (RTA_PAYLOAD(tb[TCA_CANPRIO_RULES]) / sizeof(struct can_filter));
 
-               //printf("TCA_CANPRIO_RULES count = %d\n", rules_count);
                for(i = 0; i < rules_count; i++) {
-                       fprintf(f, "match 0x%lx:0x%lx ", 
-                               (unsigned long)(canprio_rules[i].can_id),
-                               (unsigned long)(canprio_rules[i].can_mask));
-                       //FIXME differentiate among SFF and EFF
+                       if (canprio_rules[i].can_id & CAN_EFF_FLAG) {
+                               fprintf(f, "matcheid 0x%lx:0x%lx ", 
+                                       (unsigned long)(canprio_rules[i].can_id & CAN_EFF_MASK),
+                                       (unsigned long)(canprio_rules[i].can_mask & CAN_EFF_MASK));
+                       }
+                       else {
+                               fprintf(f, "matchid 0x%lx:0x%lx ", 
+                                       (unsigned long)(canprio_rules[i].can_id),
+                                       (unsigned long)(canprio_rules[i].can_mask));
+                       }
                }
        }
-*/
+
        return 0;
 }