Skip to content

Commit 4fe77d8

Browse files
ordexdavem330
authored andcommitted
skbedit: allow the user to specify bitmask for mark
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 <[email protected]> Signed-off-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6edf101 commit 4fe77d8

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

include/net/tc_act/tc_skbedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct tcf_skbedit {
2727
u32 flags;
2828
u32 priority;
2929
u32 mark;
30+
u32 mask;
3031
u16 queue_mapping;
3132
u16 ptype;
3233
};

include/uapi/linux/tc_act/tc_skbedit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define SKBEDIT_F_QUEUE_MAPPING 0x2
2929
#define SKBEDIT_F_MARK 0x4
3030
#define SKBEDIT_F_PTYPE 0x8
31+
#define SKBEDIT_F_MASK 0x10
3132

3233
struct tc_skbedit {
3334
tc_gen;
@@ -42,6 +43,7 @@ enum {
4243
TCA_SKBEDIT_MARK,
4344
TCA_SKBEDIT_PAD,
4445
TCA_SKBEDIT_PTYPE,
46+
TCA_SKBEDIT_MASK,
4547
__TCA_SKBEDIT_MAX
4648
};
4749
#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)

net/sched/act_skbedit.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a,
4646
if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
4747
skb->dev->real_num_tx_queues > d->queue_mapping)
4848
skb_set_queue_mapping(skb, d->queue_mapping);
49-
if (d->flags & SKBEDIT_F_MARK)
50-
skb->mark = d->mark;
49+
if (d->flags & SKBEDIT_F_MARK) {
50+
skb->mark &= ~d->mask;
51+
skb->mark |= d->mark & d->mask;
52+
}
5153
if (d->flags & SKBEDIT_F_PTYPE)
5254
skb->pkt_type = d->ptype;
5355

@@ -61,6 +63,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
6163
[TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
6264
[TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
6365
[TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },
66+
[TCA_SKBEDIT_MASK] = { .len = sizeof(u32) },
6467
};
6568

6669
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,
7174
struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
7275
struct tc_skbedit *parm;
7376
struct tcf_skbedit *d;
74-
u32 flags = 0, *priority = NULL, *mark = NULL;
77+
u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
7578
u16 *queue_mapping = NULL, *ptype = NULL;
7679
bool exists = false;
7780
int ret = 0, err;
@@ -108,6 +111,11 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
108111
mark = nla_data(tb[TCA_SKBEDIT_MARK]);
109112
}
110113

114+
if (tb[TCA_SKBEDIT_MASK] != NULL) {
115+
flags |= SKBEDIT_F_MASK;
116+
mask = nla_data(tb[TCA_SKBEDIT_MASK]);
117+
}
118+
111119
parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
112120

113121
exists = tcf_hash_check(tn, parm->index, a, bind);
@@ -145,6 +153,10 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
145153
d->mark = *mark;
146154
if (flags & SKBEDIT_F_PTYPE)
147155
d->ptype = *ptype;
156+
/* default behaviour is to use all the bits */
157+
d->mask = 0xffffffff;
158+
if (flags & SKBEDIT_F_MASK)
159+
d->mask = *mask;
148160

149161
d->tcf_action = parm->action;
150162

@@ -182,6 +194,9 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
182194
if ((d->flags & SKBEDIT_F_PTYPE) &&
183195
nla_put_u16(skb, TCA_SKBEDIT_PTYPE, d->ptype))
184196
goto nla_put_failure;
197+
if ((d->flags & SKBEDIT_F_MASK) &&
198+
nla_put_u32(skb, TCA_SKBEDIT_MASK, d->mask))
199+
goto nla_put_failure;
185200

186201
tcf_tm_dump(&t, &d->tcf_tm);
187202
if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))

0 commit comments

Comments
 (0)