Skip to content

Commit 1c55d62

Browse files
jamaldavem330
jamal
authored andcommitted
pkt_sched: skbedit add support for setting mark
This adds support for setting the skb mark. Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 188586b commit 1c55d62

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

include/linux/tc_act/tc_skbedit.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#define SKBEDIT_F_PRIORITY 0x1
2828
#define SKBEDIT_F_QUEUE_MAPPING 0x2
29+
#define SKBEDIT_F_MARK 0x4
2930

3031
struct tc_skbedit {
3132
tc_gen;
@@ -37,6 +38,7 @@ enum {
3738
TCA_SKBEDIT_PARMS,
3839
TCA_SKBEDIT_PRIORITY,
3940
TCA_SKBEDIT_QUEUE_MAPPING,
41+
TCA_SKBEDIT_MARK,
4042
__TCA_SKBEDIT_MAX
4143
};
4244
#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)

include/net/tc_act/tc_skbedit.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ struct tcf_skbedit {
2626
struct tcf_common common;
2727
u32 flags;
2828
u32 priority;
29+
u32 mark;
2930
u16 queue_mapping;
31+
/* XXX: 16-bit pad here? */
3032
};
3133
#define to_skbedit(pc) \
3234
container_of(pc, struct tcf_skbedit, common)

net/sched/act_skbedit.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static int tcf_skbedit(struct sk_buff *skb, struct tc_action *a,
5454
if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
5555
skb->dev->real_num_tx_queues > d->queue_mapping)
5656
skb_set_queue_mapping(skb, d->queue_mapping);
57+
if (d->flags & SKBEDIT_F_MARK)
58+
skb->mark = d->mark;
5759

5860
spin_unlock(&d->tcf_lock);
5961
return d->tcf_action;
@@ -63,6 +65,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
6365
[TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) },
6466
[TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
6567
[TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
68+
[TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
6669
};
6770

6871
static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
@@ -72,7 +75,7 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
7275
struct tc_skbedit *parm;
7376
struct tcf_skbedit *d;
7477
struct tcf_common *pc;
75-
u32 flags = 0, *priority = NULL;
78+
u32 flags = 0, *priority = NULL, *mark = NULL;
7679
u16 *queue_mapping = NULL;
7780
int ret = 0, err;
7881

@@ -95,6 +98,12 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
9598
flags |= SKBEDIT_F_QUEUE_MAPPING;
9699
queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
97100
}
101+
102+
if (tb[TCA_SKBEDIT_MARK] != NULL) {
103+
flags |= SKBEDIT_F_MARK;
104+
mark = nla_data(tb[TCA_SKBEDIT_MARK]);
105+
}
106+
98107
if (!flags)
99108
return -EINVAL;
100109

@@ -124,6 +133,9 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
124133
d->priority = *priority;
125134
if (flags & SKBEDIT_F_QUEUE_MAPPING)
126135
d->queue_mapping = *queue_mapping;
136+
if (flags & SKBEDIT_F_MARK)
137+
d->mark = *mark;
138+
127139
d->tcf_action = parm->action;
128140

129141
spin_unlock_bh(&d->tcf_lock);
@@ -161,6 +173,9 @@ static inline int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
161173
if (d->flags & SKBEDIT_F_QUEUE_MAPPING)
162174
NLA_PUT(skb, TCA_SKBEDIT_QUEUE_MAPPING,
163175
sizeof(d->queue_mapping), &d->queue_mapping);
176+
if (d->flags & SKBEDIT_F_MARK)
177+
NLA_PUT(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
178+
&d->mark);
164179
t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install);
165180
t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse);
166181
t.expires = jiffies_to_clock_t(d->tcf_tm.expires);

0 commit comments

Comments
 (0)