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
2424
2525 struct tcf_skbedit {
2626 struct tcf_common common;
27− u32 flags;
28− u32 priority;
29− u32 mark;
30− u16 queue_mapping;
31− /* XXX: 16-bit pad here? */
27+ u32 flags;
28+ u32 priority;
29+ u32 mark;
30+ u16 queue_mapping;
31+ u16 ptype;
3232 };
3333 #define to_skbedit(a) \
3434 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
2727 #define SKBEDIT_F_PRIORITY 0x1
2828 #define SKBEDIT_F_QUEUE_MAPPING 0x2
2929 #define SKBEDIT_F_MARK 0x4
30+#define SKBEDIT_F_PTYPE 0x8
3031
3132 struct tc_skbedit {
3233 tc_gen;
@@ -40,6 +41,7 @@ enum { · 7 unmodified lines
4041 TCA_SKBEDIT_QUEUE_MAPPING,
4142 TCA_SKBEDIT_MARK,
4243 TCA_SKBEDIT_PAD,
44+ TCA_SKBEDIT_PTYPE,
4345 __TCA_SKBEDIT_MAX
4446 };
4547 #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
4747 skb_set_queue_mapping(skb, d->queue_mapping);
4848 if (d->flags & SKBEDIT_F_MARK)
4949 skb->mark = d->mark;
50+ if (d->flags & SKBEDIT_F_PTYPE)
51+ skb->pkt_type = d->ptype;
5052
5153 spin_unlock(&d->tcf_lock);
5254 return d->tcf_action;
@@ -57,6 +59,7 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { · 4 unmodified lines
5759 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
5860 [TCA_SKBEDIT_QUEUE_MAPPING] = { .len = sizeof(u16) },
5961 [TCA_SKBEDIT_MARK] = { .len = sizeof(u32) },
62+ [TCA_SKBEDIT_PTYPE] = { .len = sizeof(u16) },
6063 };
6164
6265 static 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
6871 struct tc_skbedit *parm;
6972 struct tcf_skbedit *d;
7073 u32 flags = 0, *priority = NULL, *mark = NULL;
71− u16 *queue_mapping = NULL;
74+ u16 *queue_mapping = NULL, *ptype = NULL;
7275 bool exists = false;
7376 int ret = 0, err;
7477
@@ -92,6 +95,13 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, · 17 unmodified lines
9295 queue_mapping = nla_data(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
9396 }
9497
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+
95105 if (tb[TCA_SKBEDIT_MARK] != NULL) {
96106 flags |= SKBEDIT_F_MARK;
97107 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
132142 d->queue_mapping = *queue_mapping;
133143 if (flags & SKBEDIT_F_MARK)
134144 d->mark = *mark;
145+ if (flags & SKBEDIT_F_PTYPE)
146+ d->ptype = *ptype;
135147
136148 d->tcf_action = parm->action;
137149
@@ -169,6 +181,10 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, · 31 unmodified lines
169181 nla_put(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
170182 &d->mark))
171183 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;
172188
173189 tcf_tm_dump(&t, &d->tcf_tm);
174190 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