__u32 canid;
__u32 canid_mask;
};
-struct canprio_rule canprio_rules[32];
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;
canprio_rules[rules_count].canid = canid;
canprio_rules[rules_count].canid_mask = canid_mask;
rules_count++;
-
}
} else if (matches(*argv, "matchid") == 0) {
}
argc--; argv++;
}
-
addattr_l(n, MAX_MSG, TCA_CANPRIO_RULES, &canprio_rules,
sizeof(struct canprio_rule) * rules_count);
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;
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;
}