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
27 u32 flags;27 u32 flags;
28 u32 priority;28 u32 priority;
29 u32 mark;29 u32 mark;
30 u32 mask;
30 u16 queue_mapping;31 u16 queue_mapping;
31 u16 ptype;32 u16 ptype;
32};33};
include/uapi/linux/tc_act/tc_skbedit.h+2−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
28#define SKBEDIT_F_QUEUE_MAPPING 0x228#define SKBEDIT_F_QUEUE_MAPPING 0x2
29#define SKBEDIT_F_MARK 0x429#define SKBEDIT_F_MARK 0x4
30#define SKBEDIT_F_PTYPE 0x830#define SKBEDIT_F_PTYPE 0x8
31#define SKBEDIT_F_MASK 0x10
31 32
32struct tc_skbedit {33struct tc_skbedit {
33 tc_gen;34 tc_gen;
@@ -42,6 +43,7 @@ enum { · 8 unmodified lines
42 TCA_SKBEDIT_MARK,43 TCA_SKBEDIT_MARK,
43 TCA_SKBEDIT_PAD,44 TCA_SKBEDIT_PAD,
44 TCA_SKBEDIT_PTYPE,45 TCA_SKBEDIT_PTYPE,
46 TCA_SKBEDIT_MASK,
45 __TCA_SKBEDIT_MAX47 __TCA_SKBEDIT_MAX
46};48};
47#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)49#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
46 if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&46 if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
47 skb->dev->real_num_tx_queues > d->queue_mapping)47 skb->dev->real_num_tx_queues > d->queue_mapping)
48 skb_set_queue_mapping(skb, d->queue_mapping);48 skb_set_queue_mapping(skb, d->queue_mapping);
49 if (d->flags & SKBEDIT_F_MARK)49 if (d->flags & SKBEDIT_F_MARK) {
50 skb->mark = d->mark;50 skb->mark &= ~d->mask;
51 skb->mark |= d->mark & d->mask;
52 }
51 if (d->flags & SKBEDIT_F_PTYPE)53 if (d->flags & SKBEDIT_F_PTYPE)
52 skb->pkt_type = d->ptype;54 skb->pkt_type = d->ptype;
53 55
@@ -61,6 +63,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { · 7 unmodified lines
61 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },63 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
62 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },64 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
63 [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },65 [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },
66 [TCA_SKBEDIT_MASK] = { .len = sizeof(u32) },
64};67};
65 68
66static int tcf_skbedit_init(struct net *net, struct nlattr *nla,69static 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
71 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];74 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
72 struct tc_skbedit *parm;75 struct tc_skbedit *parm;
73 struct tcf_skbedit *d;76 struct tcf_skbedit *d;
74 u32 flags = 0, *priority = NULL, *mark = NULL;77 u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
75 u16 *queue_mapping = NULL, *ptype = NULL;78 u16 *queue_mapping = NULL, *ptype = NULL;
76 bool exists = false;79 bool exists = false;
77 int ret = 0, err;80 int ret = 0, err;
@@ -108,6 +111,11 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, · 30 unmodified lines
108 mark = nla_data(tb[TCA_SKBEDIT_MARK]);111 mark = nla_data(tb[TCA_SKBEDIT_MARK]);
109 }112 }
110 113
114 if (tb[TCA_SKBEDIT_MASK] != NULL) {
115 flags |= SKBEDIT_F_MASK;
116 mask = nla_data(tb[TCA_SKBEDIT_MASK]);
117 }
118
111 parm = nla_data(tb[TCA_SKBEDIT_PARMS]);119 parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
112 120
113 exists = tcf_hash_check(tn, parm->index, a, bind);121 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
145 d->mark = *mark;153 d->mark = *mark;
146 if (flags & SKBEDIT_F_PTYPE)154 if (flags & SKBEDIT_F_PTYPE)
147 d->ptype = *ptype;155 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;
148 160
149 d->tcf_action = parm->action;161 d->tcf_action = parm->action;
150 162
@@ -182,6 +194,9 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, · 31 unmodified lines
182 if ((d->flags & SKBEDIT_F_PTYPE) &&194 if ((d->flags & SKBEDIT_F_PTYPE) &&
183 nla_put_u16(skb, TCA_SKBEDIT_PTYPE, d->ptype))195 nla_put_u16(skb, TCA_SKBEDIT_PTYPE, d->ptype))
184 goto nla_put_failure;196 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;
185 200
186 tcf_tm_dump(&t, &d->tcf_tm);201 tcf_tm_dump(&t, &d->tcf_tm);
187 if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))202 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