Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __NET_PKT_CLS_H |
3 | #define __NET_PKT_CLS_H | |
4 | ||
5 | #include <linux/pkt_cls.h> | |
7aa0045d | 6 | #include <linux/workqueue.h> |
1da177e4 LT |
7 | #include <net/sch_generic.h> |
8 | #include <net/act_api.h> | |
9 | ||
cd11b164 PA |
10 | /* TC action not accessible from user space */ |
11 | #define TC_ACT_REINSERT (TC_ACT_VALUE_MAX + 1) | |
12 | ||
1da177e4 LT |
13 | /* Basic packet classifier frontend definitions. */ |
14 | ||
fd2c3ef7 | 15 | struct tcf_walker { |
1da177e4 LT |
16 | int stop; |
17 | int skip; | |
18 | int count; | |
01683a14 | 19 | unsigned long cookie; |
8113c095 | 20 | int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *); |
1da177e4 LT |
21 | }; |
22 | ||
5c15257f JP |
23 | int register_tcf_proto_ops(struct tcf_proto_ops *ops); |
24 | int unregister_tcf_proto_ops(struct tcf_proto_ops *ops); | |
1da177e4 | 25 | |
8c4083b3 JP |
26 | enum tcf_block_binder_type { |
27 | TCF_BLOCK_BINDER_TYPE_UNSPEC, | |
6e40cf2d JP |
28 | TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS, |
29 | TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS, | |
8c4083b3 JP |
30 | }; |
31 | ||
32 | struct tcf_block_ext_info { | |
33 | enum tcf_block_binder_type binder_type; | |
c7eb7d72 JP |
34 | tcf_chain_head_change_t *chain_head_change; |
35 | void *chain_head_change_priv; | |
48617387 | 36 | u32 block_index; |
8c4083b3 JP |
37 | }; |
38 | ||
acb67442 | 39 | struct tcf_block_cb; |
aaa908ff | 40 | bool tcf_queue_work(struct rcu_work *rwork, work_func_t func); |
acb67442 | 41 | |
8ae70032 | 42 | #ifdef CONFIG_NET_CLS |
1f3ed383 JP |
43 | struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block, |
44 | u32 chain_index); | |
1f3ed383 | 45 | void tcf_chain_put_by_act(struct tcf_chain *chain); |
f36fe1c4 | 46 | void tcf_block_netif_keep_dst(struct tcf_block *block); |
6529eaba | 47 | int tcf_block_get(struct tcf_block **p_block, |
8d1a77f9 AA |
48 | struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, |
49 | struct netlink_ext_ack *extack); | |
c7eb7d72 | 50 | int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, |
8d1a77f9 AA |
51 | struct tcf_block_ext_info *ei, |
52 | struct netlink_ext_ack *extack); | |
6529eaba | 53 | void tcf_block_put(struct tcf_block *block); |
c7eb7d72 | 54 | void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, |
8c4083b3 | 55 | struct tcf_block_ext_info *ei); |
44186460 | 56 | |
48617387 JP |
57 | static inline bool tcf_block_shared(struct tcf_block *block) |
58 | { | |
59 | return block->index; | |
60 | } | |
61 | ||
44186460 JP |
62 | static inline struct Qdisc *tcf_block_q(struct tcf_block *block) |
63 | { | |
48617387 | 64 | WARN_ON(tcf_block_shared(block)); |
44186460 JP |
65 | return block->q; |
66 | } | |
67 | ||
acb67442 JP |
68 | void *tcf_block_cb_priv(struct tcf_block_cb *block_cb); |
69 | struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, | |
70 | tc_setup_cb_t *cb, void *cb_ident); | |
71 | void tcf_block_cb_incref(struct tcf_block_cb *block_cb); | |
72 | unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb); | |
73 | struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, | |
74 | tc_setup_cb_t *cb, void *cb_ident, | |
60513bd8 JH |
75 | void *cb_priv, |
76 | struct netlink_ext_ack *extack); | |
acb67442 JP |
77 | int tcf_block_cb_register(struct tcf_block *block, |
78 | tc_setup_cb_t *cb, void *cb_ident, | |
60513bd8 | 79 | void *cb_priv, struct netlink_ext_ack *extack); |
32636742 JH |
80 | void __tcf_block_cb_unregister(struct tcf_block *block, |
81 | struct tcf_block_cb *block_cb); | |
acb67442 JP |
82 | void tcf_block_cb_unregister(struct tcf_block *block, |
83 | tc_setup_cb_t *cb, void *cb_ident); | |
7f76fa36 JH |
84 | int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, |
85 | tc_indr_block_bind_cb_t *cb, void *cb_ident); | |
86 | int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, | |
87 | tc_indr_block_bind_cb_t *cb, void *cb_ident); | |
88 | void __tc_indr_block_cb_unregister(struct net_device *dev, | |
89 | tc_indr_block_bind_cb_t *cb, void *cb_ident); | |
90 | void tc_indr_block_cb_unregister(struct net_device *dev, | |
91 | tc_indr_block_bind_cb_t *cb, void *cb_ident); | |
acb67442 | 92 | |
87d83093 JP |
93 | int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, |
94 | struct tcf_result *res, bool compat_mode); | |
95 | ||
8ae70032 | 96 | #else |
6529eaba JP |
97 | static inline |
98 | int tcf_block_get(struct tcf_block **p_block, | |
3c149091 SM |
99 | struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, |
100 | struct netlink_ext_ack *extack) | |
6529eaba JP |
101 | { |
102 | return 0; | |
103 | } | |
104 | ||
8c4083b3 | 105 | static inline |
c7eb7d72 | 106 | int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, |
33c30a8b QM |
107 | struct tcf_block_ext_info *ei, |
108 | struct netlink_ext_ack *extack) | |
8c4083b3 JP |
109 | { |
110 | return 0; | |
111 | } | |
112 | ||
6529eaba | 113 | static inline void tcf_block_put(struct tcf_block *block) |
8ae70032 JP |
114 | { |
115 | } | |
87d83093 | 116 | |
8c4083b3 | 117 | static inline |
c7eb7d72 | 118 | void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, |
8c4083b3 JP |
119 | struct tcf_block_ext_info *ei) |
120 | { | |
121 | } | |
122 | ||
44186460 JP |
123 | static inline struct Qdisc *tcf_block_q(struct tcf_block *block) |
124 | { | |
125 | return NULL; | |
126 | } | |
127 | ||
acb67442 JP |
128 | static inline |
129 | int tc_setup_cb_block_register(struct tcf_block *block, tc_setup_cb_t *cb, | |
130 | void *cb_priv) | |
131 | { | |
132 | return 0; | |
133 | } | |
134 | ||
135 | static inline | |
136 | void tc_setup_cb_block_unregister(struct tcf_block *block, tc_setup_cb_t *cb, | |
137 | void *cb_priv) | |
138 | { | |
139 | } | |
140 | ||
141 | static inline | |
142 | void *tcf_block_cb_priv(struct tcf_block_cb *block_cb) | |
143 | { | |
144 | return NULL; | |
145 | } | |
146 | ||
147 | static inline | |
148 | struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, | |
149 | tc_setup_cb_t *cb, void *cb_ident) | |
150 | { | |
151 | return NULL; | |
152 | } | |
153 | ||
154 | static inline | |
155 | void tcf_block_cb_incref(struct tcf_block_cb *block_cb) | |
156 | { | |
157 | } | |
158 | ||
159 | static inline | |
160 | unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb) | |
161 | { | |
162 | return 0; | |
163 | } | |
164 | ||
165 | static inline | |
166 | struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, | |
167 | tc_setup_cb_t *cb, void *cb_ident, | |
60513bd8 JH |
168 | void *cb_priv, |
169 | struct netlink_ext_ack *extack) | |
acb67442 JP |
170 | { |
171 | return NULL; | |
172 | } | |
173 | ||
174 | static inline | |
175 | int tcf_block_cb_register(struct tcf_block *block, | |
176 | tc_setup_cb_t *cb, void *cb_ident, | |
60513bd8 | 177 | void *cb_priv, struct netlink_ext_ack *extack) |
acb67442 JP |
178 | { |
179 | return 0; | |
180 | } | |
181 | ||
182 | static inline | |
32636742 JH |
183 | void __tcf_block_cb_unregister(struct tcf_block *block, |
184 | struct tcf_block_cb *block_cb) | |
acb67442 JP |
185 | { |
186 | } | |
187 | ||
188 | static inline | |
189 | void tcf_block_cb_unregister(struct tcf_block *block, | |
190 | tc_setup_cb_t *cb, void *cb_ident) | |
191 | { | |
192 | } | |
193 | ||
7f76fa36 JH |
194 | static inline |
195 | int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, | |
196 | tc_indr_block_bind_cb_t *cb, void *cb_ident) | |
197 | { | |
198 | return 0; | |
199 | } | |
200 | ||
201 | static inline | |
202 | int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, | |
203 | tc_indr_block_bind_cb_t *cb, void *cb_ident) | |
204 | { | |
205 | return 0; | |
206 | } | |
207 | ||
208 | static inline | |
209 | void __tc_indr_block_cb_unregister(struct net_device *dev, | |
210 | tc_indr_block_bind_cb_t *cb, void *cb_ident) | |
211 | { | |
212 | } | |
213 | ||
214 | static inline | |
215 | void tc_indr_block_cb_unregister(struct net_device *dev, | |
216 | tc_indr_block_bind_cb_t *cb, void *cb_ident) | |
217 | { | |
218 | } | |
219 | ||
87d83093 JP |
220 | static inline int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, |
221 | struct tcf_result *res, bool compat_mode) | |
222 | { | |
223 | return TC_ACT_UNSPEC; | |
224 | } | |
8ae70032 | 225 | #endif |
cf1facda | 226 | |
1da177e4 LT |
227 | static inline unsigned long |
228 | __cls_set_class(unsigned long *clp, unsigned long cl) | |
229 | { | |
a0efb80c | 230 | return xchg(clp, cl); |
1da177e4 LT |
231 | } |
232 | ||
233 | static inline unsigned long | |
34e3759c | 234 | cls_set_class(struct Qdisc *q, unsigned long *clp, unsigned long cl) |
1da177e4 LT |
235 | { |
236 | unsigned long old_cl; | |
34e3759c JP |
237 | |
238 | sch_tree_lock(q); | |
1da177e4 | 239 | old_cl = __cls_set_class(clp, cl); |
34e3759c | 240 | sch_tree_unlock(q); |
1da177e4 LT |
241 | return old_cl; |
242 | } | |
243 | ||
244 | static inline void | |
245 | tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base) | |
246 | { | |
34e3759c | 247 | struct Qdisc *q = tp->chain->block->q; |
1da177e4 LT |
248 | unsigned long cl; |
249 | ||
34e3759c JP |
250 | /* Check q as it is not set for shared blocks. In that case, |
251 | * setting class is not supported. | |
252 | */ | |
253 | if (!q) | |
254 | return; | |
255 | cl = q->ops->cl_ops->bind_tcf(q, base, r->classid); | |
256 | cl = cls_set_class(q, &r->class, cl); | |
1da177e4 | 257 | if (cl) |
34e3759c | 258 | q->ops->cl_ops->unbind_tcf(q, cl); |
1da177e4 LT |
259 | } |
260 | ||
261 | static inline void | |
262 | tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r) | |
263 | { | |
34e3759c | 264 | struct Qdisc *q = tp->chain->block->q; |
1da177e4 LT |
265 | unsigned long cl; |
266 | ||
34e3759c JP |
267 | if (!q) |
268 | return; | |
1da177e4 | 269 | if ((cl = __cls_set_class(&r->class, 0)) != 0) |
34e3759c | 270 | q->ops->cl_ops->unbind_tcf(q, cl); |
1da177e4 LT |
271 | } |
272 | ||
fd2c3ef7 | 273 | struct tcf_exts { |
1da177e4 | 274 | #ifdef CONFIG_NET_CLS_ACT |
33be6271 | 275 | __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ |
22dc13c8 WC |
276 | int nr_actions; |
277 | struct tc_action **actions; | |
e4b95c41 | 278 | struct net *net; |
1da177e4 | 279 | #endif |
5da57f42 WC |
280 | /* Map to export classifier specific extension TLV types to the |
281 | * generic extensions API. Unsupported extensions must be set to 0. | |
282 | */ | |
1da177e4 LT |
283 | int action; |
284 | int police; | |
285 | }; | |
286 | ||
b9a24bb7 | 287 | static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police) |
33be6271 WC |
288 | { |
289 | #ifdef CONFIG_NET_CLS_ACT | |
5da57f42 | 290 | exts->type = 0; |
22dc13c8 | 291 | exts->nr_actions = 0; |
e4b95c41 | 292 | exts->net = NULL; |
22dc13c8 WC |
293 | exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *), |
294 | GFP_KERNEL); | |
b9a24bb7 WC |
295 | if (!exts->actions) |
296 | return -ENOMEM; | |
33be6271 | 297 | #endif |
5da57f42 WC |
298 | exts->action = action; |
299 | exts->police = police; | |
b9a24bb7 | 300 | return 0; |
33be6271 WC |
301 | } |
302 | ||
e4b95c41 CW |
303 | /* Return false if the netns is being destroyed in cleanup_net(). Callers |
304 | * need to do cleanup synchronously in this case, otherwise may race with | |
305 | * tc_action_net_exit(). Return true for other cases. | |
306 | */ | |
307 | static inline bool tcf_exts_get_net(struct tcf_exts *exts) | |
308 | { | |
309 | #ifdef CONFIG_NET_CLS_ACT | |
310 | exts->net = maybe_get_net(exts->net); | |
311 | return exts->net != NULL; | |
312 | #else | |
313 | return true; | |
314 | #endif | |
315 | } | |
316 | ||
317 | static inline void tcf_exts_put_net(struct tcf_exts *exts) | |
318 | { | |
319 | #ifdef CONFIG_NET_CLS_ACT | |
320 | if (exts->net) | |
321 | put_net(exts->net); | |
322 | #endif | |
323 | } | |
324 | ||
22dc13c8 | 325 | #ifdef CONFIG_NET_CLS_ACT |
244cd96a CW |
326 | #define tcf_exts_for_each_action(i, a, exts) \ |
327 | for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++) | |
328 | #else | |
329 | #define tcf_exts_for_each_action(i, a, exts) \ | |
191672ca | 330 | for (; 0; (void)(i), (void)(a), (void)(exts)) |
22dc13c8 | 331 | #endif |
22dc13c8 | 332 | |
d897a638 JK |
333 | static inline void |
334 | tcf_exts_stats_update(const struct tcf_exts *exts, | |
335 | u64 bytes, u64 packets, u64 lastuse) | |
336 | { | |
337 | #ifdef CONFIG_NET_CLS_ACT | |
338 | int i; | |
339 | ||
340 | preempt_disable(); | |
341 | ||
342 | for (i = 0; i < exts->nr_actions; i++) { | |
343 | struct tc_action *a = exts->actions[i]; | |
344 | ||
28169aba | 345 | tcf_action_stats_update(a, bytes, packets, lastuse, true); |
d897a638 JK |
346 | } |
347 | ||
348 | preempt_enable(); | |
349 | #endif | |
350 | } | |
351 | ||
3bcc0cec JP |
352 | /** |
353 | * tcf_exts_has_actions - check if at least one action is present | |
354 | * @exts: tc filter extensions handle | |
355 | * | |
356 | * Returns true if at least one action is present. | |
357 | */ | |
358 | static inline bool tcf_exts_has_actions(struct tcf_exts *exts) | |
359 | { | |
2734437e | 360 | #ifdef CONFIG_NET_CLS_ACT |
3bcc0cec JP |
361 | return exts->nr_actions; |
362 | #else | |
363 | return false; | |
364 | #endif | |
365 | } | |
2734437e | 366 | |
3bcc0cec JP |
367 | /** |
368 | * tcf_exts_has_one_action - check if exactly one action is present | |
369 | * @exts: tc filter extensions handle | |
370 | * | |
371 | * Returns true if exactly one action is present. | |
372 | */ | |
373 | static inline bool tcf_exts_has_one_action(struct tcf_exts *exts) | |
374 | { | |
375 | #ifdef CONFIG_NET_CLS_ACT | |
376 | return exts->nr_actions == 1; | |
377 | #else | |
378 | return false; | |
379 | #endif | |
380 | } | |
2734437e | 381 | |
244cd96a CW |
382 | static inline struct tc_action *tcf_exts_first_action(struct tcf_exts *exts) |
383 | { | |
384 | #ifdef CONFIG_NET_CLS_ACT | |
385 | return exts->actions[0]; | |
386 | #else | |
387 | return NULL; | |
388 | #endif | |
389 | } | |
390 | ||
af69afc5 JP |
391 | /** |
392 | * tcf_exts_exec - execute tc filter extensions | |
393 | * @skb: socket buffer | |
394 | * @exts: tc filter extensions handle | |
395 | * @res: desired result | |
396 | * | |
af089e70 | 397 | * Executes all configured extensions. Returns TC_ACT_OK on a normal execution, |
af69afc5 JP |
398 | * a negative number if the filter must be considered unmatched or |
399 | * a positive action code (TC_ACT_*) which must be returned to the | |
400 | * underlying layer. | |
401 | */ | |
402 | static inline int | |
403 | tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, | |
404 | struct tcf_result *res) | |
405 | { | |
406 | #ifdef CONFIG_NET_CLS_ACT | |
ec1a9cca | 407 | return tcf_action_exec(skb, exts->actions, exts->nr_actions, res); |
af69afc5 | 408 | #endif |
af089e70 | 409 | return TC_ACT_OK; |
af69afc5 JP |
410 | } |
411 | ||
5c15257f JP |
412 | int tcf_exts_validate(struct net *net, struct tcf_proto *tp, |
413 | struct nlattr **tb, struct nlattr *rate_tlv, | |
50a56190 AA |
414 | struct tcf_exts *exts, bool ovr, |
415 | struct netlink_ext_ack *extack); | |
18d0264f | 416 | void tcf_exts_destroy(struct tcf_exts *exts); |
9b0d4446 | 417 | void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src); |
5da57f42 WC |
418 | int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts); |
419 | int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts); | |
1da177e4 LT |
420 | |
421 | /** | |
422 | * struct tcf_pkt_info - packet information | |
423 | */ | |
fd2c3ef7 | 424 | struct tcf_pkt_info { |
1da177e4 LT |
425 | unsigned char * ptr; |
426 | int nexthdr; | |
427 | }; | |
428 | ||
429 | #ifdef CONFIG_NET_EMATCH | |
430 | ||
431 | struct tcf_ematch_ops; | |
432 | ||
433 | /** | |
434 | * struct tcf_ematch - extended match (ematch) | |
435 | * | |
436 | * @matchid: identifier to allow userspace to reidentify a match | |
437 | * @flags: flags specifying attributes and the relation to other matches | |
438 | * @ops: the operations lookup table of the corresponding ematch module | |
439 | * @datalen: length of the ematch specific configuration data | |
440 | * @data: ematch specific data | |
441 | */ | |
fd2c3ef7 | 442 | struct tcf_ematch { |
1da177e4 LT |
443 | struct tcf_ematch_ops * ops; |
444 | unsigned long data; | |
445 | unsigned int datalen; | |
446 | u16 matchid; | |
447 | u16 flags; | |
82a470f1 | 448 | struct net *net; |
1da177e4 LT |
449 | }; |
450 | ||
451 | static inline int tcf_em_is_container(struct tcf_ematch *em) | |
452 | { | |
453 | return !em->ops; | |
454 | } | |
455 | ||
456 | static inline int tcf_em_is_simple(struct tcf_ematch *em) | |
457 | { | |
458 | return em->flags & TCF_EM_SIMPLE; | |
459 | } | |
460 | ||
461 | static inline int tcf_em_is_inverted(struct tcf_ematch *em) | |
462 | { | |
463 | return em->flags & TCF_EM_INVERT; | |
464 | } | |
465 | ||
466 | static inline int tcf_em_last_match(struct tcf_ematch *em) | |
467 | { | |
468 | return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END; | |
469 | } | |
470 | ||
471 | static inline int tcf_em_early_end(struct tcf_ematch *em, int result) | |
472 | { | |
473 | if (tcf_em_last_match(em)) | |
474 | return 1; | |
475 | ||
476 | if (result == 0 && em->flags & TCF_EM_REL_AND) | |
477 | return 1; | |
478 | ||
479 | if (result != 0 && em->flags & TCF_EM_REL_OR) | |
480 | return 1; | |
481 | ||
482 | return 0; | |
483 | } | |
484 | ||
485 | /** | |
486 | * struct tcf_ematch_tree - ematch tree handle | |
487 | * | |
488 | * @hdr: ematch tree header supplied by userspace | |
489 | * @matches: array of ematches | |
490 | */ | |
fd2c3ef7 | 491 | struct tcf_ematch_tree { |
1da177e4 LT |
492 | struct tcf_ematch_tree_hdr hdr; |
493 | struct tcf_ematch * matches; | |
494 | ||
495 | }; | |
496 | ||
497 | /** | |
498 | * struct tcf_ematch_ops - ematch module operations | |
499 | * | |
500 | * @kind: identifier (kind) of this ematch module | |
501 | * @datalen: length of expected configuration data (optional) | |
502 | * @change: called during validation (optional) | |
503 | * @match: called during ematch tree evaluation, must return 1/0 | |
504 | * @destroy: called during destroyage (optional) | |
505 | * @dump: called during dumping process (optional) | |
506 | * @owner: owner, must be set to THIS_MODULE | |
507 | * @link: link to previous/next ematch module (internal use) | |
508 | */ | |
fd2c3ef7 | 509 | struct tcf_ematch_ops { |
1da177e4 LT |
510 | int kind; |
511 | int datalen; | |
82a470f1 | 512 | int (*change)(struct net *net, void *, |
1da177e4 LT |
513 | int, struct tcf_ematch *); |
514 | int (*match)(struct sk_buff *, struct tcf_ematch *, | |
515 | struct tcf_pkt_info *); | |
82a470f1 | 516 | void (*destroy)(struct tcf_ematch *); |
1da177e4 LT |
517 | int (*dump)(struct sk_buff *, struct tcf_ematch *); |
518 | struct module *owner; | |
519 | struct list_head link; | |
520 | }; | |
521 | ||
5c15257f JP |
522 | int tcf_em_register(struct tcf_ematch_ops *); |
523 | void tcf_em_unregister(struct tcf_ematch_ops *); | |
524 | int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *, | |
525 | struct tcf_ematch_tree *); | |
82a470f1 | 526 | void tcf_em_tree_destroy(struct tcf_ematch_tree *); |
5c15257f JP |
527 | int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int); |
528 | int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *, | |
529 | struct tcf_pkt_info *); | |
1da177e4 | 530 | |
1da177e4 LT |
531 | /** |
532 | * tcf_em_tree_match - evaulate an ematch tree | |
533 | * | |
534 | * @skb: socket buffer of the packet in question | |
535 | * @tree: ematch tree to be used for evaluation | |
536 | * @info: packet information examined by classifier | |
537 | * | |
538 | * This function matches @skb against the ematch tree in @tree by going | |
539 | * through all ematches respecting their logic relations returning | |
540 | * as soon as the result is obvious. | |
541 | * | |
542 | * Returns 1 if the ematch tree as-one matches, no ematches are configured | |
543 | * or ematch is not enabled in the kernel, otherwise 0 is returned. | |
544 | */ | |
545 | static inline int tcf_em_tree_match(struct sk_buff *skb, | |
546 | struct tcf_ematch_tree *tree, | |
547 | struct tcf_pkt_info *info) | |
548 | { | |
549 | if (tree->hdr.nmatches) | |
550 | return __tcf_em_tree_match(skb, tree, info); | |
551 | else | |
552 | return 1; | |
553 | } | |
554 | ||
db3d99c0 PM |
555 | #define MODULE_ALIAS_TCF_EMATCH(kind) MODULE_ALIAS("ematch-kind-" __stringify(kind)) |
556 | ||
1da177e4 LT |
557 | #else /* CONFIG_NET_EMATCH */ |
558 | ||
fd2c3ef7 | 559 | struct tcf_ematch_tree { |
1da177e4 LT |
560 | }; |
561 | ||
562 | #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0) | |
82a470f1 | 563 | #define tcf_em_tree_destroy(t) do { (void)(t); } while(0) |
1da177e4 | 564 | #define tcf_em_tree_dump(skb, t, tlv) (0) |
1da177e4 LT |
565 | #define tcf_em_tree_match(skb, t, info) ((void)(info), 1) |
566 | ||
567 | #endif /* CONFIG_NET_EMATCH */ | |
568 | ||
569 | static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer) | |
570 | { | |
571 | switch (layer) { | |
572 | case TCF_LAYER_LINK: | |
d3303a65 | 573 | return skb_mac_header(skb); |
1da177e4 | 574 | case TCF_LAYER_NETWORK: |
d56f90a7 | 575 | return skb_network_header(skb); |
1da177e4 | 576 | case TCF_LAYER_TRANSPORT: |
9c70220b | 577 | return skb_transport_header(skb); |
1da177e4 LT |
578 | } |
579 | ||
580 | return NULL; | |
581 | } | |
582 | ||
eddc9ec5 ACM |
583 | static inline int tcf_valid_offset(const struct sk_buff *skb, |
584 | const unsigned char *ptr, const int len) | |
1da177e4 | 585 | { |
da521b2c DM |
586 | return likely((ptr + len) <= skb_tail_pointer(skb) && |
587 | ptr >= skb->head && | |
588 | (ptr <= (ptr + len))); | |
1da177e4 LT |
589 | } |
590 | ||
591 | #ifdef CONFIG_NET_CLS_IND | |
0eeb8ffc DL |
592 | #include <net/net_namespace.h> |
593 | ||
1da177e4 | 594 | static inline int |
1057c55f AA |
595 | tcf_change_indev(struct net *net, struct nlattr *indev_tlv, |
596 | struct netlink_ext_ack *extack) | |
1da177e4 | 597 | { |
2519a602 WC |
598 | char indev[IFNAMSIZ]; |
599 | struct net_device *dev; | |
600 | ||
1057c55f AA |
601 | if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) { |
602 | NL_SET_ERR_MSG(extack, "Interface name too long"); | |
1da177e4 | 603 | return -EINVAL; |
1057c55f | 604 | } |
2519a602 WC |
605 | dev = __dev_get_by_name(net, indev); |
606 | if (!dev) | |
607 | return -ENODEV; | |
608 | return dev->ifindex; | |
1da177e4 LT |
609 | } |
610 | ||
2519a602 WC |
611 | static inline bool |
612 | tcf_match_indev(struct sk_buff *skb, int ifindex) | |
1da177e4 | 613 | { |
2519a602 WC |
614 | if (!ifindex) |
615 | return true; | |
616 | if (!skb->skb_iif) | |
617 | return false; | |
618 | return ifindex == skb->skb_iif; | |
1da177e4 LT |
619 | } |
620 | #endif /* CONFIG_NET_CLS_IND */ | |
621 | ||
208c0f4b JP |
622 | int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts, |
623 | enum tc_setup_type type, void *type_data, bool err_stop); | |
717503b9 | 624 | |
8c4083b3 JP |
625 | enum tc_block_command { |
626 | TC_BLOCK_BIND, | |
627 | TC_BLOCK_UNBIND, | |
628 | }; | |
629 | ||
630 | struct tc_block_offload { | |
631 | enum tc_block_command command; | |
632 | enum tcf_block_binder_type binder_type; | |
633 | struct tcf_block *block; | |
60513bd8 | 634 | struct netlink_ext_ack *extack; |
8c4083b3 JP |
635 | }; |
636 | ||
5fd9fc4e | 637 | struct tc_cls_common_offload { |
5fd9fc4e JP |
638 | u32 chain_index; |
639 | __be16 protocol; | |
d7c1c8d2 | 640 | u32 prio; |
8f0b425a | 641 | struct netlink_ext_ack *extack; |
5fd9fc4e JP |
642 | }; |
643 | ||
a1b7c5fd JF |
644 | struct tc_cls_u32_knode { |
645 | struct tcf_exts *exts; | |
e014860e | 646 | struct tc_u32_sel *sel; |
a1b7c5fd JF |
647 | u32 handle; |
648 | u32 val; | |
649 | u32 mask; | |
650 | u32 link_handle; | |
e014860e | 651 | u8 fshift; |
a1b7c5fd JF |
652 | }; |
653 | ||
654 | struct tc_cls_u32_hnode { | |
655 | u32 handle; | |
656 | u32 prio; | |
657 | unsigned int divisor; | |
658 | }; | |
659 | ||
660 | enum tc_clsu32_command { | |
661 | TC_CLSU32_NEW_KNODE, | |
662 | TC_CLSU32_REPLACE_KNODE, | |
663 | TC_CLSU32_DELETE_KNODE, | |
664 | TC_CLSU32_NEW_HNODE, | |
665 | TC_CLSU32_REPLACE_HNODE, | |
666 | TC_CLSU32_DELETE_HNODE, | |
667 | }; | |
668 | ||
669 | struct tc_cls_u32_offload { | |
5fd9fc4e | 670 | struct tc_cls_common_offload common; |
a1b7c5fd JF |
671 | /* knode values */ |
672 | enum tc_clsu32_command command; | |
673 | union { | |
674 | struct tc_cls_u32_knode knode; | |
675 | struct tc_cls_u32_hnode hnode; | |
676 | }; | |
677 | }; | |
678 | ||
7b06e8ae | 679 | static inline bool tc_can_offload(const struct net_device *dev) |
6843e7a2 | 680 | { |
70b5aee4 | 681 | return dev->features & NETIF_F_HW_TC; |
6843e7a2 JF |
682 | } |
683 | ||
f9eda14f QM |
684 | static inline bool tc_can_offload_extack(const struct net_device *dev, |
685 | struct netlink_ext_ack *extack) | |
686 | { | |
687 | bool can = tc_can_offload(dev); | |
688 | ||
689 | if (!can) | |
690 | NL_SET_ERR_MSG(extack, "TC offload is disabled on net device"); | |
691 | ||
692 | return can; | |
693 | } | |
694 | ||
878db9f0 JK |
695 | static inline bool |
696 | tc_cls_can_offload_and_chain0(const struct net_device *dev, | |
697 | struct tc_cls_common_offload *common) | |
698 | { | |
699 | if (!tc_can_offload_extack(dev, common->extack)) | |
700 | return false; | |
701 | if (common->chain_index) { | |
702 | NL_SET_ERR_MSG(common->extack, | |
703 | "Driver supports only offload of chain 0"); | |
704 | return false; | |
705 | } | |
706 | return true; | |
707 | } | |
708 | ||
55330f05 HHZ |
709 | static inline bool tc_skip_hw(u32 flags) |
710 | { | |
711 | return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false; | |
712 | } | |
713 | ||
d34e3e18 SS |
714 | static inline bool tc_skip_sw(u32 flags) |
715 | { | |
716 | return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false; | |
717 | } | |
718 | ||
719 | /* SKIP_HW and SKIP_SW are mutually exclusive flags. */ | |
720 | static inline bool tc_flags_valid(u32 flags) | |
721 | { | |
81c7288b MRL |
722 | if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW | |
723 | TCA_CLS_FLAGS_VERBOSE)) | |
d34e3e18 SS |
724 | return false; |
725 | ||
81c7288b | 726 | flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW; |
d34e3e18 SS |
727 | if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW))) |
728 | return false; | |
729 | ||
730 | return true; | |
731 | } | |
732 | ||
e696028a OG |
733 | static inline bool tc_in_hw(u32 flags) |
734 | { | |
735 | return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false; | |
736 | } | |
737 | ||
34832e1c JK |
738 | static inline void |
739 | tc_cls_common_offload_init(struct tc_cls_common_offload *cls_common, | |
740 | const struct tcf_proto *tp, u32 flags, | |
741 | struct netlink_ext_ack *extack) | |
742 | { | |
743 | cls_common->chain_index = tp->chain->index; | |
744 | cls_common->protocol = tp->protocol; | |
745 | cls_common->prio = tp->prio; | |
81c7288b | 746 | if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE) |
34832e1c JK |
747 | cls_common->extack = extack; |
748 | } | |
749 | ||
5b33f488 AV |
750 | enum tc_fl_command { |
751 | TC_CLSFLOWER_REPLACE, | |
752 | TC_CLSFLOWER_DESTROY, | |
10cbc684 | 753 | TC_CLSFLOWER_STATS, |
34738452 JP |
754 | TC_CLSFLOWER_TMPLT_CREATE, |
755 | TC_CLSFLOWER_TMPLT_DESTROY, | |
5b33f488 AV |
756 | }; |
757 | ||
758 | struct tc_cls_flower_offload { | |
5fd9fc4e | 759 | struct tc_cls_common_offload common; |
5b33f488 | 760 | enum tc_fl_command command; |
8208d21b | 761 | unsigned long cookie; |
5b33f488 AV |
762 | struct flow_dissector *dissector; |
763 | struct fl_flow_key *mask; | |
764 | struct fl_flow_key *key; | |
765 | struct tcf_exts *exts; | |
384c181e | 766 | u32 classid; |
5b33f488 AV |
767 | }; |
768 | ||
b87f7936 YG |
769 | enum tc_matchall_command { |
770 | TC_CLSMATCHALL_REPLACE, | |
771 | TC_CLSMATCHALL_DESTROY, | |
772 | }; | |
773 | ||
774 | struct tc_cls_matchall_offload { | |
5fd9fc4e | 775 | struct tc_cls_common_offload common; |
b87f7936 YG |
776 | enum tc_matchall_command command; |
777 | struct tcf_exts *exts; | |
778 | unsigned long cookie; | |
779 | }; | |
780 | ||
332ae8e2 | 781 | enum tc_clsbpf_command { |
102740bd | 782 | TC_CLSBPF_OFFLOAD, |
68d64063 | 783 | TC_CLSBPF_STATS, |
332ae8e2 JK |
784 | }; |
785 | ||
786 | struct tc_cls_bpf_offload { | |
5fd9fc4e | 787 | struct tc_cls_common_offload common; |
332ae8e2 JK |
788 | enum tc_clsbpf_command command; |
789 | struct tcf_exts *exts; | |
790 | struct bpf_prog *prog; | |
102740bd | 791 | struct bpf_prog *oldprog; |
332ae8e2 JK |
792 | const char *name; |
793 | bool exts_integrated; | |
794 | }; | |
795 | ||
4e8b86c0 AN |
796 | struct tc_mqprio_qopt_offload { |
797 | /* struct tc_mqprio_qopt must always be the first element */ | |
798 | struct tc_mqprio_qopt qopt; | |
799 | u16 mode; | |
800 | u16 shaper; | |
801 | u32 flags; | |
802 | u64 min_rate[TC_QOPT_MAX_QUEUE]; | |
803 | u64 max_rate[TC_QOPT_MAX_QUEUE]; | |
804 | }; | |
1045ba77 JHS |
805 | |
806 | /* This structure holds cookie structure that is passed from user | |
807 | * to the kernel for actions and classifiers | |
808 | */ | |
809 | struct tc_cookie { | |
810 | u8 *data; | |
811 | u32 len; | |
eec94fdb | 812 | struct rcu_head rcu; |
1045ba77 | 813 | }; |
602f3baf | 814 | |
f34b4aac NF |
815 | struct tc_qopt_offload_stats { |
816 | struct gnet_stats_basic_packed *bstats; | |
817 | struct gnet_stats_queue *qstats; | |
818 | }; | |
819 | ||
f971b132 JK |
820 | enum tc_mq_command { |
821 | TC_MQ_CREATE, | |
822 | TC_MQ_DESTROY, | |
47c669a4 | 823 | TC_MQ_STATS, |
f971b132 JK |
824 | }; |
825 | ||
826 | struct tc_mq_qopt_offload { | |
827 | enum tc_mq_command command; | |
828 | u32 handle; | |
47c669a4 | 829 | struct tc_qopt_offload_stats stats; |
f971b132 JK |
830 | }; |
831 | ||
602f3baf NF |
832 | enum tc_red_command { |
833 | TC_RED_REPLACE, | |
834 | TC_RED_DESTROY, | |
835 | TC_RED_STATS, | |
836 | TC_RED_XSTATS, | |
bf2a752b | 837 | TC_RED_GRAFT, |
602f3baf NF |
838 | }; |
839 | ||
840 | struct tc_red_qopt_offload_params { | |
841 | u32 min; | |
842 | u32 max; | |
843 | u32 probability; | |
844 | bool is_ecn; | |
190852a5 | 845 | bool is_harddrop; |
416ef9b1 | 846 | struct gnet_stats_queue *qstats; |
602f3baf | 847 | }; |
602f3baf NF |
848 | |
849 | struct tc_red_qopt_offload { | |
850 | enum tc_red_command command; | |
851 | u32 handle; | |
852 | u32 parent; | |
853 | union { | |
854 | struct tc_red_qopt_offload_params set; | |
f34b4aac | 855 | struct tc_qopt_offload_stats stats; |
602f3baf | 856 | struct red_stats *xstats; |
bf2a752b | 857 | u32 child_handle; |
602f3baf NF |
858 | }; |
859 | }; | |
860 | ||
7fdb61b4 NF |
861 | enum tc_prio_command { |
862 | TC_PRIO_REPLACE, | |
863 | TC_PRIO_DESTROY, | |
864 | TC_PRIO_STATS, | |
b9c7a7ac | 865 | TC_PRIO_GRAFT, |
7fdb61b4 NF |
866 | }; |
867 | ||
868 | struct tc_prio_qopt_offload_params { | |
869 | int bands; | |
870 | u8 priomap[TC_PRIO_MAX + 1]; | |
871 | /* In case that a prio qdisc is offloaded and now is changed to a | |
872 | * non-offloadedable config, it needs to update the backlog & qlen | |
873 | * values to negate the HW backlog & qlen values (and only them). | |
874 | */ | |
875 | struct gnet_stats_queue *qstats; | |
876 | }; | |
877 | ||
b9c7a7ac NF |
878 | struct tc_prio_qopt_offload_graft_params { |
879 | u8 band; | |
880 | u32 child_handle; | |
881 | }; | |
882 | ||
7fdb61b4 NF |
883 | struct tc_prio_qopt_offload { |
884 | enum tc_prio_command command; | |
885 | u32 handle; | |
886 | u32 parent; | |
887 | union { | |
888 | struct tc_prio_qopt_offload_params replace_params; | |
889 | struct tc_qopt_offload_stats stats; | |
b9c7a7ac | 890 | struct tc_prio_qopt_offload_graft_params graft_params; |
7fdb61b4 NF |
891 | }; |
892 | }; | |
b9c7a7ac | 893 | |
98b0e5f6 JK |
894 | enum tc_root_command { |
895 | TC_ROOT_GRAFT, | |
896 | }; | |
897 | ||
898 | struct tc_root_qopt_offload { | |
899 | enum tc_root_command command; | |
900 | u32 handle; | |
901 | bool ingress; | |
902 | }; | |
903 | ||
1da177e4 | 904 | #endif |