]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/commitdiff
cls_can: Fixed protocol restriction + minor changes.
authorRostislav Lisovy <lisovy@gmail.com>
Fri, 4 May 2012 13:28:03 +0000 (15:28 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Fri, 4 May 2012 13:28:03 +0000 (15:28 +0200)
To be able to create can filter, "protocol can" or no protocol should be
passed to "tc" command when creating can filter.
Protocol of each skb is checked before our classify function is invoked.

net/sched/cls_can.c

index d32ad0784522ef70708fc76ae98278ab26219b26..cd0a0e8d973d4b1411a389d8d73876c9723f2391 100644 (file)
@@ -12,7 +12,7 @@
  *             (c) 2011 Volkswagen Group Research
  * Authors:    Michal Sojka <sojkam1@fel.cvut.cz>
  *             Pavel Pisa <pisa@cmp.felk.cvut.cz>
- *             Rostislav Lisovy <lisovy@kormus.cz>
+ *             Rostislav Lisovy <lisovy@gmail.cz>
  * Funded by:  Volkswagen Group Research
  *
  * Some function descriptions are heavily inspired by article "Linux Network
@@ -70,7 +70,6 @@ struct canfltr_rules {
                                        ID (11 bit) there is one record in this
                                        bitfield */
 #endif
-       int inv_match_en;               /* Inverted match flag */
        int rules_count;
        int eff_rules_count;
        int sff_rules_count;
@@ -152,7 +151,7 @@ static canid_t canfltr_get_id(struct sk_buff *skb)
  *   TC_POLICE_OK if succesfully classified (without regard to policing rules)
  *   TC_POLICE_UNSPEC if no matching rule was found
  */
-static int canfltr_classify(struct sk_buff *skb, struct tcf_proto *tp,
+static int canfltr_classify(struct sk_buff *skb, const struct tcf_proto *tp,
                          struct tcf_result *res)
 {
        struct canfltr_head *head = (struct canfltr_head *)tp->root;
@@ -269,7 +268,7 @@ static int canfltr_set_parms(struct tcf_proto *tp, struct canfltr_state *f,
 
        rules_tmp = kzalloc(sizeof(*rules_tmp), GFP_KERNEL);
        if (rules_tmp == NULL)
-               return -ENOBUFS; /* XXX: Why not -ENOMEM? */
+               return -ENOBUFS;
 
        err = -EINVAL;
        if (tb[TCA_CANFLTR_CLASSID] == NULL)
@@ -477,13 +476,19 @@ static int canfltr_init(struct tcf_proto *tp)
 {
        struct canfltr_head *head;
 
+       if ((tp->protocol != htons(ETH_P_ALL)) && (tp->protocol != htons(ETH_P_CAN)))
+               return -1;
+
+       /* Work only on CAN frames */
+       if (tp->protocol == htons(ETH_P_ALL))
+               tp->protocol = htons(ETH_P_CAN);
+
        head = kzalloc(sizeof(*head), GFP_KERNEL);
        if (head == NULL)
                return -ENOBUFS;
 
        INIT_LIST_HEAD(&head->flist);
        tp->root = head;
-       tp->protocol = htons(ETH_P_CAN); /* Work only on AF_CAN packets - not tested! */
 
        return 0;
 }
@@ -584,5 +589,5 @@ static void __exit exit_canfltr(void)
 module_init(init_canfltr);
 module_exit(exit_canfltr);
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Rostislav Lisovy <lisovy@kormus.cz>");
+MODULE_AUTHOR("Rostislav Lisovy <lisovy@gmail.cz>");
 MODULE_DESCRIPTION("Controller Area Network classifier");