]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/commitdiff
Matching Can ID with regards to Mask.
authorRostislav Lisovy <lisovy@gmail.com>
Tue, 9 Aug 2011 09:55:08 +0000 (11:55 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Tue, 9 Aug 2011 09:55:08 +0000 (11:55 +0200)
net/sched/cls_canprio.c

index a4e2aa63be45b6a72bbf2cd0cc5b8c441594cf13..b517e19046fc222f632d35358fe71aae8f4e94e2 100644 (file)
@@ -25,15 +25,15 @@ enum {
        TCA_CANPRIO_A_UNSPEC,
        TCA_CANPRIO_CLASSID,
        TCA_CANPRIO_MATCH,
-       TCA_CANPRIO_XY,
+       TCA_CANPRIO_MATCH_MASK,
        __TCA_CANPRIO_MAX,
 };
 #define TCA_CANPRIO_MAX (__TCA_CANPRIO_MAX - 1)
 
 static const struct nla_policy canprio_policy[TCA_CANPRIO_MAX + 1] = {
-       [TCA_CANPRIO_CLASSID]   = { .type = NLA_U32 },
-       [TCA_CANPRIO_MATCH]     = { .type = NLA_U32 }, //{ .type = NLA_NESTED },
-       [TCA_CANPRIO_XY]        = { .type = NLA_U32 },
+       [TCA_CANPRIO_CLASSID]    = { .type = NLA_U32 },
+       [TCA_CANPRIO_MATCH]      = { .type = NLA_U32 }, //{ .type = NLA_NESTED },
+       [TCA_CANPRIO_MATCH_MASK] = { .type = NLA_U32 },
 };
 
 struct canprio_head {
@@ -43,7 +43,8 @@ struct canprio_head {
 
 struct canprio_filter {
        u32                  handle;
-       u32                  match; // Matching CAN ID. Will be sth like list os lists
+       u32                  canid;
+       u32                  canid_mask;
        struct tcf_result    res;
        struct list_head     link;
 };
@@ -82,12 +83,13 @@ static int canprio_classify(struct sk_buff *skb, struct tcf_proto *tp,
        struct canprio_head *head = (struct canprio_head *)tp->root;
        struct canprio_filter *f;
 
-       printk(" canprio_classify invoked\n");
+       printk(" canprio_classify() invoked\n");
 
        list_for_each_entry(f, &head->flist, link) {
-               printk("  canprio_classify can ID = 0x%x\n", canprio_get_id(skb));
-               if (canprio_get_id(skb) == f->match) {
-                       printk( "   canprio_classify match ID 0x%x\n", f->match);
+               printk("  canprio_classify() can ID of received frame = 0x%x\n", canprio_get_id(skb));
+               if ((canprio_get_id(skb) & f->canid_mask) == (f->canid & f->canid_mask)) {
+                       printk( "   canprio_classify() match ok: ID 0x%x mask 0x%x\n", 
+                               f->canid, f->canid_mask);
                        *res = f->res;
                        return TC_POLICE_OK;
                }
@@ -104,6 +106,7 @@ static int canprio_set_parms(struct tcf_proto *tp, struct canprio_filter *f,
                           struct nlattr *est)
 { 
        //int err;
+       printk(" canprio_set_parms invoked\n");
 
        if (tb[TCA_CANPRIO_CLASSID]) {
                f->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
@@ -166,6 +169,9 @@ static int canprio_change(struct tcf_proto *tp, unsigned long base, u32 handle,
        if (tca[TCA_OPTIONS] == NULL)
                return -EINVAL;
 
+       //Parses a stream of attributes and stores a pointer to each attribute in
+       //the tb array accessible via the attribute type. Policy may be set to NULL 
+       //if no validation is required.
        err = nla_parse_nested(tb, TCA_CANPRIO_MAX, tca[TCA_OPTIONS], canprio_policy);
        if (err < 0)                
                return err;
@@ -216,8 +222,9 @@ static int canprio_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                return -EINVAL;
 
        //f->match = nla_data(tb[TCA_CANPRIO_MATCH]);
-       f->match = nla_get_u32(tb[TCA_CANPRIO_MATCH]);
-       printk(" can ID to match = 0x%x\n", f->match);
+       f->canid = nla_get_u32(tb[TCA_CANPRIO_MATCH]);
+       f->canid_mask = nla_get_u32(tb[TCA_CANPRIO_MATCH_MASK]);
+       printk(" can ID to match = 0x%x with mask 0x%x\n", f->canid, f->canid_mask);
 
        //Add newly created filter to list of all filters
        tcf_tree_lock(tp);