History

net sched actions: skbedit add support for mod-ing skb pkt_type

Extremely useful for setting packet type to host so i dont have to modify the dst mac address using pedit (which requires that i know the mac address) Example usage: tc filter add dev eth0 parent ffff: protocol ip pref 9 u32 \ match ip src 5.5.5.5/32 \ flowid 1:5 action skbedit ptype host This will tag all packets incoming from 5.5.5.5 with type PACKET_HOST

Jamal Hadi Salim committed 10 years ago

Commit ff202ee1 parent 8b10cab3 files · +24 −6Browse files

Unified · Split

3 files
  1. include/net/tc_act/tc_skbedit.h +5 −5
  2. include/uapi/linux/tc_act/tc_skbedit.h +2 −0
  3. net/sched/act_skbedit.c +17 −1
include/net/tc_act/tc_skbedit.h+5−5
@@ -24,11 +24,11 @@ · 23 unmodified lines
24 24
25struct tcf_skbedit {25struct tcf_skbedit {
26 struct tcf_common common;26 struct tcf_common common;
27 u32 flags;27 u32 flags;
28 u32 priority;28 u32 priority;
29 u32 mark;29 u32 mark;
30 u16 queue_mapping;30 u16 queue_mapping;
31 /* XXX: 16-bit pad here? */31 u16 ptype;
32};32};
33#define to_skbedit(a) \33#define to_skbedit(a) \
34 container_of(a->priv, struct tcf_skbedit, common)34 container_of(a->priv, struct tcf_skbedit, common)
include/uapi/linux/tc_act/tc_skbedit.h+2−0
@@ -27,6 +27,7 @@ · 26 unmodified lines
27#define SKBEDIT_F_PRIORITY 0x127#define SKBEDIT_F_PRIORITY 0x1
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 0x8
30 31
31struct tc_skbedit {32struct tc_skbedit {
32 tc_gen;33 tc_gen;
@@ -40,6 +41,7 @@ enum { · 7 unmodified lines
40 TCA_SKBEDIT_QUEUE_MAPPING,41 TCA_SKBEDIT_QUEUE_MAPPING,
41 TCA_SKBEDIT_MARK,42 TCA_SKBEDIT_MARK,
42 TCA_SKBEDIT_PAD,43 TCA_SKBEDIT_PAD,
44 TCA_SKBEDIT_PTYPE,
43 __TCA_SKBEDIT_MAX45 __TCA_SKBEDIT_MAX
44};46};
45#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)47#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)
net/sched/act_skbedit.c+17−1
@@ -47,6 +47,8 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a, · 46 unmodified lines
47 skb_set_queue_mapping(skb, d->queue_mapping);47 skb_set_queue_mapping(skb, d->queue_mapping);
48 if (d->flags & SKBEDIT_F_MARK)48 if (d->flags & SKBEDIT_F_MARK)
49 skb->mark = d->mark;49 skb->mark = d->mark;
50 if (d->flags & SKBEDIT_F_PTYPE)
51 skb->pkt_type = d->ptype;
50 52
51 spin_unlock(&d->tcf_lock);53 spin_unlock(&d->tcf_lock);
52 return d->tcf_action;54 return d->tcf_action;
@@ -57,6 +59,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { · 4 unmodified lines
57 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },59 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
58 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },60 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
59 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },61 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
62 [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },
60};63};
61 64
62static int tcf_skbedit_init(struct net *net, struct nlattr *nla,65static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
@@ -68,7 +71,7 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, · 5 unmodified lines
68 struct tc_skbedit *parm;71 struct tc_skbedit *parm;
69 struct tcf_skbedit *d;72 struct tcf_skbedit *d;
70 u32 flags = 0, *priority = NULL, *mark = NULL;73 u32 flags = 0, *priority = NULL, *mark = NULL;
71 u16 *queue_mapping = NULL;74 u16 *queue_mapping = NULL, *ptype = NULL;
72 bool exists = false;75 bool exists = false;
73 int ret = 0, err;76 int ret = 0, err;
74 77
@@ -92,6 +95,13 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, · 17 unmodified lines
92 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);95 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
93 }96 }
94 97
98 if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
99 ptype = nla_data(tb[TCA_SKBEDIT_PTYPE]);
100 if (!skb_pkt_type_ok(*ptype))
101 return -EINVAL;
102 flags |= SKBEDIT_F_PTYPE;
103 }
104
95 if (tb[TCA_SKBEDIT_MARK] != NULL) {105 if (tb[TCA_SKBEDIT_MARK] != NULL) {
96 flags |= SKBEDIT_F_MARK;106 flags |= SKBEDIT_F_MARK;
97 mark = nla_data(tb[TCA_SKBEDIT_MARK]);107 mark = nla_data(tb[TCA_SKBEDIT_MARK]);
@@ -132,6 +142,8 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, · 34 unmodified lines
132 d->queue_mapping = *queue_mapping;142 d->queue_mapping = *queue_mapping;
133 if (flags & SKBEDIT_F_MARK)143 if (flags & SKBEDIT_F_MARK)
134 d->mark = *mark;144 d->mark = *mark;
145 if (flags & SKBEDIT_F_PTYPE)
146 d->ptype = *ptype;
135 147
136 d->tcf_action = parm->action;148 d->tcf_action = parm->action;
137 149
@@ -169,6 +181,10 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, · 31 unmodified lines
169 nla_put(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),181 nla_put(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
170 &d->mark))182 &d->mark))
171 goto nla_put_failure;183 goto nla_put_failure;
184 if ((d->flags & SKBEDIT_F_PTYPE) &&
185 nla_put(skb, TCA_SKBEDIT_PTYPE, sizeof(d->ptype),
186 &d->ptype))
187 goto nla_put_failure;
172 188
173 tcf_tm_dump(&t, &d->tcf_tm);189 tcf_tm_dump(&t, &d->tcf_tm);
174 if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))190 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