]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - tc/f_can.c
can: Coding style + minor changes.
[lisovros/iproute2_canprio.git] / tc / f_can.c
index 903524dbda4ad4c173cdfbed7626edf2a625d6e0..571ca0f9a1700dd38a61a0200cd4d6d8a463183c 100644 (file)
@@ -1,18 +1,18 @@
-/* 
- * f_can.c  Filter for CAN packets 
+/*
+ * f_can.c  Filter for CAN packets
  *
  *             This program is free software; you can distribute it and/or
  *             modify it under the terms of the GNU General Public License
  *             as published by the Free Software Foundation; either version
  *             2 of the License, or (at your option) any later version.
  *
- * Idea:       Oliver Hartkopp <oliver.hartkopp@volkswagen.de> 
+ * 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
+ *             Rostislav Lisovy <lisovy@gmail.cz>
+ * Funded by:  Volkswagen Group Research
  */
 
 #include <stdio.h>
@@ -51,7 +51,8 @@
   };
 #endif
 
-#define RULES_SIZE     128
+#define RULES_SIZE             128 /* Maximum number of rules sent via the
+                               netlink message during creation/configuration */
 
 
 static void explain(void)
@@ -90,7 +91,7 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
 
        t->tcm_handle = h;
 
-       tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
+       tail = NLMSG_TAIL(n);
        addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
 
        while (argc > 0) {
@@ -104,7 +105,7 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
 
                        NEXT_ARG();
 
-                       if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) { 
+                       if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) {
                                if (sscanf(*argv, "%"SCNx32, &can_id) != 1) {
                                        fprintf(stderr, "Improperly formed CAN ID & mask '%s'\n", *argv);
                                        return -1;
@@ -114,7 +115,7 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
 
                        /* we do not support extra handling for RTR frames due to the bitmap approach */
                        if (can_id & ~CAN_SFF_MASK) {
-                               fprintf(stderr, "ID 0x%lx exceeded standard CAN ID range.\n", 
+                               fprintf(stderr, "ID 0x%lx exceeded standard CAN ID range.\n",
                                        (unsigned long)can_id);
                                return -1;
                        }
@@ -133,7 +134,7 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
 
                        NEXT_ARG();
 
-                       if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) { 
+                       if (sscanf(*argv, "%"SCNx32 ":" "%"SCNx32, &can_id, &can_mask) != 2) {
                                if (sscanf(*argv, "%"SCNx32, &can_id) != 1) {
                                        fprintf(stderr, "Improperly formed CAN ID & mask '%s'\n", *argv);
                                        return -1;
@@ -142,7 +143,7 @@ static int canfltr_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;
                        }
@@ -150,7 +151,7 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
                        canfltr_rules[rules_count].can_id = can_id | CAN_EFF_FLAG;
                        canfltr_rules[rules_count].can_mask = (can_mask & CAN_EFF_MASK) | CAN_EFF_FLAG;
                        rules_count++;
-                       
+
                } else if (matches(*argv, "classid") == 0 || strcmp(*argv, "flowid") == 0) {
                        unsigned handle;
                        NEXT_ARG();
@@ -171,18 +172,18 @@ static int canfltr_parse_opt(struct filter_util *qu, char *handle,
                }
                argc--; argv++;
        }
-       
-       addattr_l(n, MAX_MSG, TCA_CANFLTR_RULES, &canfltr_rules, 
+
+       addattr_l(n, MAX_MSG, TCA_CANFLTR_RULES, &canfltr_rules,
                sizeof(struct can_filter) * rules_count);
 
-       tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
+       tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
        return 0;
 }
 
 /* When "tc filter show dev XY" is executed, function canfltr_walk() (in kernel)
  * is called (which calls canfltr_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). 
+ * information about each instance of a filters to userspace -- to this function
+ * (which parses the message and prints it).
  */
 static int canfltr_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
                         __u32 handle)
@@ -210,7 +211,7 @@ static int canfltr_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt
        if (tb[TCA_CANFLTR_RULES]) {
                if (RTA_PAYLOAD(tb[TCA_CANFLTR_RULES]) < sizeof(struct can_filter))
                        return -1;
-       
+
                canfltr_rules = RTA_DATA(tb[TCA_CANFLTR_RULES]);
                rules_count = (RTA_PAYLOAD(tb[TCA_CANFLTR_RULES]) / sizeof(struct can_filter));
 
@@ -223,8 +224,7 @@ static int canfltr_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt
                                        fprintf(f, "effid 0x%lx:0x%lx ",
                                                (unsigned long)(canfltr_rules[i].can_id & CAN_EFF_MASK),
                                                (unsigned long)(canfltr_rules[i].can_mask & CAN_EFF_MASK));
-                       }
-                       else {
+                       } else {
                                if (canfltr_rules[i].can_mask == CAN_SFF_MASK)
                                        fprintf(f, "sffid 0x%lx ",
                                                (unsigned long)(canfltr_rules[i].can_id));
@@ -239,7 +239,6 @@ static int canfltr_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt
        return 0;
 }
 
-
 struct filter_util can_filter_util = {
        .id = "can",
        .parse_fopt = canfltr_parse_opt,