]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Fully implemented canprio_print_opt() function. Not sure if 100% correct (I don't...
authorRostislav Lisovy <lisovy@gmail.com>
Thu, 18 Aug 2011 13:38:29 +0000 (15:38 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Wed, 23 May 2012 08:45:12 +0000 (10:45 +0200)
tc/f_canprio.c

index 6bd0e22ab25a91c04c4c6de1c9e104d1b42306b3..e82e42a7f95015f0595840e2ba0eb511f990733c 100644 (file)
@@ -35,7 +35,6 @@ struct canprio_rule {
        __u32 canid;
        __u32 canid_mask;
 };
-struct canprio_rule canprio_rules[32];
 
 static void explain(void)
 {
@@ -48,16 +47,16 @@ static void explain(void)
                         "NOTE: CLASSID, CANID, MASK is parsed as hexadecimal input.\n");
 }
 
-
 static int canprio_parse_opt(struct filter_util *qu, char *handle,
                         int argc, char **argv, struct nlmsghdr *n)
 {
        struct tcmsg *t = NLMSG_DATA(n);  // Why?
        struct rtattr *tail;
+       struct canprio_rule canprio_rules[32];
+       int rules_count = 0;
        long h = 0;
        __u32 canid;
        __u32 canid_mask;
-       int rules_count = 0;
 
        if (argc == 0)
                return 0;
@@ -91,7 +90,6 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                                canprio_rules[rules_count].canid = canid;
                                canprio_rules[rules_count].canid_mask = canid_mask;
                                rules_count++;
-
                        }
 
                } else if (matches(*argv, "matchid") == 0) {
@@ -152,7 +150,6 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
                }
                argc--; argv++;
        }
-
        
        addattr_l(n, MAX_MSG, TCA_CANPRIO_RULES, &canprio_rules, 
                sizeof(struct canprio_rule) * rules_count);
@@ -161,11 +158,17 @@ static int canprio_parse_opt(struct filter_util *qu, char *handle,
        return 0;
 }
 
+/* FIXME I don't know how to test if function is correct.
+I was not able to figure out how to call this function */
 static int canprio_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
                         __u32 handle)
 {
        struct rtattr *tb[TCA_CANPRIO_MAX+1];
+       struct canprio_rule *canprio_rules = NULL;
+       int rules_count = 0;
+       int i;
 
+       printf("canprio_print_opt() invoked \n");
 
        if (opt == NULL)
                return 0;
@@ -176,16 +179,25 @@ static int canprio_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt
                fprintf(f, "handle 0x%x ", handle);
 
        if (tb[TCA_BASIC_CLASSID]) {
-               SPRINT_BUF(b1); //FIXME wat?
+               SPRINT_BUF(b1); //allocate buffer b1
                fprintf(f, "flowid %s ",
                        sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_BASIC_CLASSID]), b1));
        }
 
-       //FIXME
-       //if (tb[TCA_CANPRIO_RULES])
-       //      fprintf(f, "Canid 0x%x ",
-       //                      *(__u32 *)RTA_DATA(tb[TCA_CANPRIO_MATCH]));
-
+       if (tb[TCA_CANPRIO_RULES]) {
+               if (RTA_PAYLOAD(tb[TCA_CANPRIO_RULES]) < sizeof(struct canprio_rule))
+                       return -1;
+       
+               canprio_rules = RTA_DATA(tb[TCA_CANPRIO_RULES]);
+               rules_count = RTA_LENGTH(canprio_rules);
+
+               for(i = 0; i < rules_count; i++) {
+                       fprintf(f, "CAN ID 0x%lx ", 
+                               (unsigned long)(canprio_rules[i].canid));
+                       fprintf(f, "CAN ID mask 0x%lx ", 
+                               (unsigned long)(canprio_rules[i].canid_mask));
+               }
+       }
 
        return 0;
 }