2 * m_skbedit.c SKB Editing module
4 * Copyright (c) 2008, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses>.
18 * Authors: Alexander Duyck <alexander.h.duyck@intel.com>
28 #include <linux/tc_act/tc_skbedit.h>
29 #include <linux/if_packet.h>
31 static void explain(void)
33 fprintf(stderr
, "Usage: ... skbedit <[QM] [PM] [MM] [PT] [IF]>\n"
34 "QM = queue_mapping QUEUE_MAPPING\n"
35 "PM = priority PRIORITY\n"
37 "PT = ptype PACKETYPE\n"
38 "IF = inheritdsfield\n"
39 "PACKETYPE = is one of:\n"
40 " host, otherhost, broadcast, multicast\n"
41 "QUEUE_MAPPING = device transmit queue to use\n"
42 "PRIORITY = classID to assign to priority field\n"
43 "MARK = firewall mark to set\n"
44 "note: inheritdsfield maps DS field to skb->priority\n");
55 parse_skbedit(struct action_util
*a
, int *argc_p
, char ***argv_p
, int tca_id
,
59 char **argv
= *argv_p
;
63 __u16 queue_mapping
, ptype
;
64 __u32 flags
= 0, priority
, mark
;
66 struct tc_skbedit sel
= { 0 };
68 if (matches(*argv
, "skbedit") != 0)
74 if (matches(*argv
, "queue_mapping") == 0) {
75 flags
|= SKBEDIT_F_QUEUE_MAPPING
;
77 if (get_unsigned(&tmp
, *argv
, 10) || tmp
> 65535) {
78 fprintf(stderr
, "Illegal queue_mapping\n");
83 } else if (matches(*argv
, "priority") == 0) {
84 flags
|= SKBEDIT_F_PRIORITY
;
86 if (get_tc_classid(&priority
, *argv
)) {
87 fprintf(stderr
, "Illegal priority\n");
91 } else if (matches(*argv
, "mark") == 0) {
92 flags
|= SKBEDIT_F_MARK
;
94 if (get_u32(&mark
, *argv
, 0)) {
95 fprintf(stderr
, "Illegal mark\n");
99 } else if (matches(*argv
, "ptype") == 0) {
102 if (matches(*argv
, "host") == 0) {
104 } else if (matches(*argv
, "broadcast") == 0) {
105 ptype
= PACKET_BROADCAST
;
106 } else if (matches(*argv
, "multicast") == 0) {
107 ptype
= PACKET_MULTICAST
;
108 } else if (matches(*argv
, "otherhost") == 0) {
109 ptype
= PACKET_OTHERHOST
;
111 fprintf(stderr
, "Illegal ptype (%s)\n",
115 flags
|= SKBEDIT_F_PTYPE
;
117 } else if (matches(*argv
, "inheritdsfield") == 0) {
118 pure_flags
|= SKBEDIT_F_INHERITDSFIELD
;
120 } else if (matches(*argv
, "help") == 0) {
129 parse_action_control_dflt(&argc
, &argv
, &sel
.action
,
133 if (matches(*argv
, "index") == 0) {
135 if (get_u32(&sel
.index
, *argv
, 10)) {
136 fprintf(stderr
, "Pedit: Illegal \"index\"\n");
151 tail
= addattr_nest(n
, MAX_MSG
, tca_id
);
152 addattr_l(n
, MAX_MSG
, TCA_SKBEDIT_PARMS
, &sel
, sizeof(sel
));
153 if (flags
& SKBEDIT_F_QUEUE_MAPPING
)
154 addattr_l(n
, MAX_MSG
, TCA_SKBEDIT_QUEUE_MAPPING
,
155 &queue_mapping
, sizeof(queue_mapping
));
156 if (flags
& SKBEDIT_F_PRIORITY
)
157 addattr_l(n
, MAX_MSG
, TCA_SKBEDIT_PRIORITY
,
158 &priority
, sizeof(priority
));
159 if (flags
& SKBEDIT_F_MARK
)
160 addattr_l(n
, MAX_MSG
, TCA_SKBEDIT_MARK
,
161 &mark
, sizeof(mark
));
162 if (flags
& SKBEDIT_F_PTYPE
)
163 addattr_l(n
, MAX_MSG
, TCA_SKBEDIT_PTYPE
,
164 &ptype
, sizeof(ptype
));
166 addattr64(n
, MAX_MSG
, TCA_SKBEDIT_FLAGS
, pure_flags
);
167 addattr_nest_end(n
, tail
);
174 static int print_skbedit(struct action_util
*au
, FILE *f
, struct rtattr
*arg
)
176 struct rtattr
*tb
[TCA_SKBEDIT_MAX
+ 1];
181 struct tc_skbedit
*p
= NULL
;
186 parse_rtattr_nested(tb
, TCA_SKBEDIT_MAX
, arg
);
188 if (tb
[TCA_SKBEDIT_PARMS
] == NULL
) {
189 print_string(PRINT_FP
, NULL
, "%s", "[NULL skbedit parameters]");
192 p
= RTA_DATA(tb
[TCA_SKBEDIT_PARMS
]);
194 print_string(PRINT_ANY
, "kind", "%s ", "skbedit");
196 if (tb
[TCA_SKBEDIT_QUEUE_MAPPING
] != NULL
) {
197 print_uint(PRINT_ANY
, "queue_mapping", "queue_mapping %u",
198 rta_getattr_u16(tb
[TCA_SKBEDIT_QUEUE_MAPPING
]));
200 if (tb
[TCA_SKBEDIT_PRIORITY
] != NULL
) {
201 priority
= rta_getattr_u32(tb
[TCA_SKBEDIT_PRIORITY
]);
202 print_string(PRINT_ANY
, "priority", " priority %s",
203 sprint_tc_classid(priority
, b1
));
205 if (tb
[TCA_SKBEDIT_MARK
] != NULL
) {
206 print_uint(PRINT_ANY
, "mark", " mark %u",
207 rta_getattr_u32(tb
[TCA_SKBEDIT_MARK
]));
209 if (tb
[TCA_SKBEDIT_PTYPE
] != NULL
) {
210 ptype
= rta_getattr_u16(tb
[TCA_SKBEDIT_PTYPE
]);
211 if (ptype
== PACKET_HOST
)
212 print_string(PRINT_ANY
, "ptype", " ptype %s", "host");
213 else if (ptype
== PACKET_BROADCAST
)
214 print_string(PRINT_ANY
, "ptype", " ptype %s",
216 else if (ptype
== PACKET_MULTICAST
)
217 print_string(PRINT_ANY
, "ptype", " ptype %s",
219 else if (ptype
== PACKET_OTHERHOST
)
220 print_string(PRINT_ANY
, "ptype", " ptype %s",
223 print_uint(PRINT_ANY
, "ptype", " ptype %u", ptype
);
225 if (tb
[TCA_SKBEDIT_FLAGS
] != NULL
) {
226 __u64 flags
= rta_getattr_u64(tb
[TCA_SKBEDIT_FLAGS
]);
228 if (flags
& SKBEDIT_F_INHERITDSFIELD
)
229 print_null(PRINT_ANY
, "inheritdsfield", " %s",
233 print_action_control(f
, " ", p
->action
, "");
235 print_string(PRINT_FP
, NULL
, "%s", _SL_
);
236 print_uint(PRINT_ANY
, "index", "\t index %u", p
->index
);
237 print_int(PRINT_ANY
, "ref", " ref %d", p
->refcnt
);
238 print_int(PRINT_ANY
, "bind", " bind %d", p
->bindcnt
);
241 if (tb
[TCA_SKBEDIT_TM
]) {
242 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_SKBEDIT_TM
]);
248 print_string(PRINT_FP
, NULL
, "%s", _SL_
);
253 struct action_util skbedit_action_util
= {
255 .parse_aopt
= parse_skbedit
,
256 .print_aopt
= print_skbedit
,