]> git.karo-electronics.de Git - linux-beck.git/commitdiff
skbedit: allow the user to specify bitmask for mark
authorAntonio Quartulli <a@unstable.cc>
Mon, 24 Oct 2016 12:32:57 +0000 (20:32 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Oct 2016 20:07:25 +0000 (16:07 -0400)
The user may want to use only some bits of the skb mark in
his skbedit rules because the remaining part might be used by
something else.

Introduce the "mask" parameter to the skbedit actor in order
to implement such functionality.

When the mask is specified, only those bits selected by the
latter are altered really changed by the actor, while the
rest is left untouched.

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tc_act/tc_skbedit.h
include/uapi/linux/tc_act/tc_skbedit.h
net/sched/act_skbedit.c

index 5767e9dbcf92453e7e4336481db5956f729c38ed..19cd3d3458049a2fe6d317bc48ff9e5c0524587b 100644 (file)
@@ -27,6 +27,7 @@ struct tcf_skbedit {
        u32             flags;
        u32             priority;
        u32             mark;
+       u32             mask;
        u16             queue_mapping;
        u16             ptype;
 };
index a4d00c608d8f7e307e0be65e1e8b78371e4dc908..2884425738ce73e3bbbbf8dcfa79c6e345022476 100644 (file)
@@ -28,6 +28,7 @@
 #define SKBEDIT_F_QUEUE_MAPPING                0x2
 #define SKBEDIT_F_MARK                 0x4
 #define SKBEDIT_F_PTYPE                        0x8
+#define SKBEDIT_F_MASK                 0x10
 
 struct tc_skbedit {
        tc_gen;
@@ -42,6 +43,7 @@ enum {
        TCA_SKBEDIT_MARK,
        TCA_SKBEDIT_PAD,
        TCA_SKBEDIT_PTYPE,
+       TCA_SKBEDIT_MASK,
        __TCA_SKBEDIT_MAX
 };
 #define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)
index a133dcb821323c45e03360b26977f292c5d50d09..024f3a3afeff62e9edb625f45a83f5b2f61a7e54 100644 (file)
@@ -46,8 +46,10 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a,
        if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
            skb->dev->real_num_tx_queues > d->queue_mapping)
                skb_set_queue_mapping(skb, d->queue_mapping);
-       if (d->flags & SKBEDIT_F_MARK)
-               skb->mark = d->mark;
+       if (d->flags & SKBEDIT_F_MARK) {
+               skb->mark &= ~d->mask;
+               skb->mark |= d->mark & d->mask;
+       }
        if (d->flags & SKBEDIT_F_PTYPE)
                skb->pkt_type = d->ptype;
 
@@ -61,6 +63,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
        [TCA_SKBEDIT_QUEUE_MAPPING]     = { .len = sizeof(u16) },
        [TCA_SKBEDIT_MARK]              = { .len = sizeof(u32) },
        [TCA_SKBEDIT_PTYPE]             = { .len = sizeof(u16) },
+       [TCA_SKBEDIT_MASK]              = { .len = sizeof(u32) },
 };
 
 static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
@@ -71,7 +74,7 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
        struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
        struct tc_skbedit *parm;
        struct tcf_skbedit *d;
-       u32 flags = 0, *priority = NULL, *mark = NULL;
+       u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
        u16 *queue_mapping = NULL, *ptype = NULL;
        bool exists = false;
        int ret = 0, err;
@@ -108,6 +111,11 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
                mark = nla_data(tb[TCA_SKBEDIT_MARK]);
        }
 
+       if (tb[TCA_SKBEDIT_MASK] != NULL) {
+               flags |= SKBEDIT_F_MASK;
+               mask = nla_data(tb[TCA_SKBEDIT_MASK]);
+       }
+
        parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
 
        exists = tcf_hash_check(tn, parm->index, a, bind);
@@ -145,6 +153,10 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
                d->mark = *mark;
        if (flags & SKBEDIT_F_PTYPE)
                d->ptype = *ptype;
+       /* default behaviour is to use all the bits */
+       d->mask = 0xffffffff;
+       if (flags & SKBEDIT_F_MASK)
+               d->mask = *mask;
 
        d->tcf_action = parm->action;
 
@@ -182,6 +194,9 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
        if ((d->flags & SKBEDIT_F_PTYPE) &&
            nla_put_u16(skb, TCA_SKBEDIT_PTYPE, d->ptype))
                goto nla_put_failure;
+       if ((d->flags & SKBEDIT_F_MASK) &&
+           nla_put_u32(skb, TCA_SKBEDIT_MASK, d->mask))
+               goto nla_put_failure;
 
        tcf_tm_dump(&t, &d->tcf_tm);
        if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))