]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/commitdiff
Check for EFF_FLAG in can_id AND can_mask in EFF frames.
authorRostislav Lisovy <lisovy@gmail.com>
Tue, 23 Aug 2011 09:51:45 +0000 (11:51 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Tue, 23 Aug 2011 09:51:45 +0000 (11:51 +0200)
net/sched/cls_canprio.c

index c344df066aa7d7bd0e66473a24d6cd19dd63a29c..45b7ee9424acbfccac9cbf39edbeea0f5330cd4f 100644 (file)
@@ -40,7 +40,6 @@
 #include <linux/rcupdate.h>
 #include <linux/can.h>
 
-//--------------------------------------
 
 /* Definition of Netlink messages */
 enum {
@@ -101,7 +100,7 @@ static void canprio_sff_match_add(struct canprio_filter *f, u32 canid, u32 mask)
 
        printk("%s() invoked\n", __FUNCTION__);
        mask &= CAN_SFF_MASK;
-       canid = canid & mask;
+       canid &= mask;
 
        if (mask == CAN_SFF_MASK) {
                set_bit(canid, f->rules.match_sff);
@@ -121,7 +120,8 @@ static int canprio_eff_match_add(struct canprio_filter *f, u32 canid, u32 mask)
 
        printk("%s() invoked\n", __FUNCTION__);
        mask &= CAN_EFF_MASK;
-       canid = canid & mask;
+       canid &= mask;
+
 
        eff = kmalloc(sizeof(struct canprio_eff_item), GFP_KERNEL);
        if (!eff)
@@ -142,13 +142,12 @@ static int canprio_eff_match_add(struct canprio_filter *f, u32 canid, u32 mask)
 /* 
  * Extracts Can ID ot ouf the sk_buff structure.
  */
-static u32 canprio_get_id(struct sk_buff *skb)
+static canid_t canprio_get_id(struct sk_buff *skb)
 {
        /* Can ID is inside of data field */
        struct can_frame *cf = (struct can_frame *)skb->data;
-       //canid_t canid = cf->canid;
 
-       return (u32)cf->can_id;
+       return cf->can_id;
 }
 
 /*
@@ -171,20 +170,22 @@ static int canprio_classify(struct sk_buff *skb, struct tcf_proto *tp,
        u32 canid;
 
        printk(" canprio_classify() invoked\n");
-       canid = canprio_get_id(skb);
+       canid = (u32)canprio_get_id(skb);
 
        list_for_each_entry(f, &head->flist, link) {
                bool match = false;
-               printk("  canprio_classify() can ID of received frame = 0x%x\n", canid);
 
                if (canid & CAN_EFF_FLAG) {
                        struct canprio_eff_item *effi;
                        struct hlist_node *next;
+                       canid &= CAN_EFF_MASK;
                        
                        rcu_read_lock();
 
                        hlist_for_each_entry_rcu(effi, next, &f->rules.match_eff, list) {
-                               if ((effi->rule.can_id ^ canid) & effi->rule.can_mask) {
+                               //if (((effi->rule.can_id) ^ canid) & effi->rule.can_mask) {
+                               if ((effi->rule.can_id & effi->rule.can_mask) == 
+                                       (canid & effi->rule.can_mask)) {
                                        match = true;
                                        break;
                                }
@@ -195,13 +196,13 @@ static int canprio_classify(struct sk_buff *skb, struct tcf_proto *tp,
                        match = test_bit(canid, f->rules.match_sff);
                }
 
-               if (f->rules.inv_match_en)
-                       match = !match;
+               //if (f->rules.inv_match_en)
+               //      match = !match;
 
                if (match) {
                        *res = f->res;
-                       return TC_POLICE_OK;
                        printk( "   canprio_classify() match ok: ID 0x%x\n", canid);
+                       return TC_POLICE_OK;
                }
        }
 
@@ -381,10 +382,10 @@ static int canprio_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                sizeof(struct can_filter) * f->rules.rules_count);
 
        for (i = 0; i < f->rules.rules_count; i++) {
-               /* FIXME: shouldn't use here the same logic as in
-                * can_rcv_filter() to filter for various combination
-                * of flags (EFF, RTR) */
-               if (canprio_nl_rules[i].can_id & CAN_EFF_FLAG) {
+               /* FIXME: is ok? */
+               if (canprio_nl_rules[i].can_id & CAN_EFF_FLAG &&
+                       canprio_nl_rules[i].can_mask & CAN_EFF_FLAG) {
+       
                        err = canprio_eff_match_add(f, canprio_nl_rules[i].can_id, 
                                canprio_nl_rules[i].can_mask);
                        if (err < 0)
@@ -429,7 +430,7 @@ static void canprio_delete_filter(struct tcf_proto *tp, struct canprio_filter *f
        rcu_barrier();  
 
        tcf_unbind_filter(tp, &f->res);
-       hlist_for_each_entry_safe(effi, p, n, &(f->rules.match_eff), list) {
+       hlist_for_each_entry_safe(effi, p, n, &f->rules.match_eff, list) {
                kfree(effi);
        }
 
@@ -511,7 +512,6 @@ static void canprio_walk(struct tcf_proto *tp, struct tcf_walker *arg)
                if (arg->count < arg->skip)
                        goto skip;
 
-               printk("calling canprio_dump()\n");
                if (arg->fn(tp, (unsigned long) f, arg) < 0) {
                        arg->stop = 1;
                        break;
@@ -544,10 +544,8 @@ static int canprio_dump(struct tcf_proto *tp, unsigned long fh,
        if (f->res.classid)
                NLA_PUT_U32(skb, TCA_CANPRIO_CLASSID, f->res.classid);
 
-       
        NLA_PUT(skb, TCA_CANPRIO_RULES, f->rules.rules_count * 
                sizeof(struct can_filter), f->rules.rules_raw);
-       printk(" sending %d rules.", f->rules.rules_count);
 
 
        nla_nest_end(skb, nest);