From: Rostislav Lisovy Date: Tue, 23 Aug 2011 09:51:45 +0000 (+0200) Subject: Check for EFF_FLAG in can_id AND can_mask in EFF frames. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/lisovros/linux_canprio.git/commitdiff_plain/7f8e71813e7c257e1f569d13a851360bdaf4cac1 Check for EFF_FLAG in can_id AND can_mask in EFF frames. --- diff --git a/net/sched/cls_canprio.c b/net/sched/cls_canprio.c index c344df066aa..45b7ee9424a 100644 --- a/net/sched/cls_canprio.c +++ b/net/sched/cls_canprio.c @@ -40,7 +40,6 @@ #include #include -//-------------------------------------- /* 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);