History

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.

Antonio Quartulli committed 10 years ago

Commit 4fe77d81 parent 6edf1013 files · +21 −3Browse files

Unified · Split

3 files
  1. include/net/tc_act/tc_skbedit.h +1 −0
  2. include/uapi/linux/tc_act/tc_skbedit.h +2 −0
  3. net/sched/act_skbedit.c +18 −3
include/net/tc_act/tc_skbedit.h+1−0
@@ -27,6 +27,7 @@ struct tcf_skbedit { · 26 unmodified lines
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+2−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
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 { · 8 unmodified lines
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+18−3
@@ -46,8 +46,10 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a, · 45 unmodified lines
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] = { · 7 unmodified lines
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, · 4 unmodified lines
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, · 30 unmodified lines
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, · 31 unmodified lines
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, · 31 unmodified lines
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))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t