blob: 0e3b6101693144c95f5e70f31cd12cd44c313c5a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __NET_PKT_CLS_H
3#define __NET_PKT_CLS_H
4
5#include <linux/pkt_cls.h>
Cong Wang7aa00452017-10-26 18:24:28 -07006#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <net/sch_generic.h>
8#include <net/act_api.h>
Pablo Neira Ayuso8f256622019-02-02 12:50:43 +01009#include <net/flow_offload.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Paolo Abenicd11b1642018-07-30 14:30:44 +020011/* TC action not accessible from user space */
12#define TC_ACT_REINSERT (TC_ACT_VALUE_MAX + 1)
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/* Basic packet classifier frontend definitions. */
15
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000016struct tcf_walker {
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 int stop;
18 int skip;
19 int count;
Vlad Buslov01683a12018-07-09 13:29:11 +030020 unsigned long cookie;
WANG Cong8113c092017-08-04 21:31:43 -070021 int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022};
23
Joe Perches5c152572013-07-30 22:47:13 -070024int register_tcf_proto_ops(struct tcf_proto_ops *ops);
25int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Jiri Pirko8c4083b2017-10-19 15:50:29 +020027enum tcf_block_binder_type {
28 TCF_BLOCK_BINDER_TYPE_UNSPEC,
Jiri Pirko6e40cf22017-10-19 15:50:30 +020029 TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
30 TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS,
Jiri Pirko8c4083b2017-10-19 15:50:29 +020031};
32
33struct tcf_block_ext_info {
34 enum tcf_block_binder_type binder_type;
Jiri Pirkoc7eb7d72017-11-03 11:46:24 +010035 tcf_chain_head_change_t *chain_head_change;
36 void *chain_head_change_priv;
Jiri Pirko48617382018-01-17 11:46:46 +010037 u32 block_index;
Jiri Pirko8c4083b2017-10-19 15:50:29 +020038};
39
Jiri Pirkoacb67442017-10-19 15:50:31 +020040struct tcf_block_cb;
Cong Wangaaa908f2018-05-23 15:26:53 -070041bool tcf_queue_work(struct rcu_work *rwork, work_func_t func);
Jiri Pirkoacb67442017-10-19 15:50:31 +020042
Jiri Pirko8ae70032017-02-15 11:57:50 +010043#ifdef CONFIG_NET_CLS
Jiri Pirko1f3ed382018-07-27 09:45:05 +020044struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block,
45 u32 chain_index);
Jiri Pirko1f3ed382018-07-27 09:45:05 +020046void tcf_chain_put_by_act(struct tcf_chain *chain);
Vlad Buslovbbf73832019-02-11 10:55:36 +020047struct tcf_chain *tcf_get_next_chain(struct tcf_block *block,
48 struct tcf_chain *chain);
Vlad Buslovfe2923a2019-02-11 10:55:40 +020049struct tcf_proto *tcf_get_next_proto(struct tcf_chain *chain,
50 struct tcf_proto *tp);
Jiri Pirkof36fe1c2018-01-17 11:46:48 +010051void tcf_block_netif_keep_dst(struct tcf_block *block);
Jiri Pirko6529eab2017-05-17 11:07:55 +020052int tcf_block_get(struct tcf_block **p_block,
Alexander Aring8d1a77f2017-12-20 12:35:19 -050053 struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
54 struct netlink_ext_ack *extack);
Jiri Pirkoc7eb7d72017-11-03 11:46:24 +010055int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
Alexander Aring8d1a77f2017-12-20 12:35:19 -050056 struct tcf_block_ext_info *ei,
57 struct netlink_ext_ack *extack);
Jiri Pirko6529eab2017-05-17 11:07:55 +020058void tcf_block_put(struct tcf_block *block);
Jiri Pirkoc7eb7d72017-11-03 11:46:24 +010059void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
Jiri Pirko8c4083b2017-10-19 15:50:29 +020060 struct tcf_block_ext_info *ei);
Jiri Pirko44186462017-10-13 14:00:59 +020061
Jiri Pirko48617382018-01-17 11:46:46 +010062static inline bool tcf_block_shared(struct tcf_block *block)
63{
64 return block->index;
65}
66
Jiri Pirko44186462017-10-13 14:00:59 +020067static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
68{
Jiri Pirko48617382018-01-17 11:46:46 +010069 WARN_ON(tcf_block_shared(block));
Jiri Pirko44186462017-10-13 14:00:59 +020070 return block->q;
71}
72
Jiri Pirkoacb67442017-10-19 15:50:31 +020073void *tcf_block_cb_priv(struct tcf_block_cb *block_cb);
74struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
75 tc_setup_cb_t *cb, void *cb_ident);
76void tcf_block_cb_incref(struct tcf_block_cb *block_cb);
77unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb);
78struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
79 tc_setup_cb_t *cb, void *cb_ident,
John Hurley60513bd2018-06-25 14:30:04 -070080 void *cb_priv,
81 struct netlink_ext_ack *extack);
Jiri Pirkoacb67442017-10-19 15:50:31 +020082int tcf_block_cb_register(struct tcf_block *block,
83 tc_setup_cb_t *cb, void *cb_ident,
John Hurley60513bd2018-06-25 14:30:04 -070084 void *cb_priv, struct netlink_ext_ack *extack);
John Hurley32636742018-06-25 14:30:10 -070085void __tcf_block_cb_unregister(struct tcf_block *block,
86 struct tcf_block_cb *block_cb);
Jiri Pirkoacb67442017-10-19 15:50:31 +020087void tcf_block_cb_unregister(struct tcf_block *block,
88 tc_setup_cb_t *cb, void *cb_ident);
John Hurley7f76fa32018-11-09 21:21:26 -080089int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv,
90 tc_indr_block_bind_cb_t *cb, void *cb_ident);
91int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv,
92 tc_indr_block_bind_cb_t *cb, void *cb_ident);
93void __tc_indr_block_cb_unregister(struct net_device *dev,
94 tc_indr_block_bind_cb_t *cb, void *cb_ident);
95void tc_indr_block_cb_unregister(struct net_device *dev,
96 tc_indr_block_bind_cb_t *cb, void *cb_ident);
Jiri Pirkoacb67442017-10-19 15:50:31 +020097
Jiri Pirko87d83092017-05-17 11:07:54 +020098int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
99 struct tcf_result *res, bool compat_mode);
100
Jiri Pirko8ae70032017-02-15 11:57:50 +0100101#else
Jiri Pirko6529eab2017-05-17 11:07:55 +0200102static inline
103int tcf_block_get(struct tcf_block **p_block,
Sudip Mukherjee3c149092017-12-22 15:52:05 +0000104 struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
105 struct netlink_ext_ack *extack)
Jiri Pirko6529eab2017-05-17 11:07:55 +0200106{
107 return 0;
108}
109
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200110static inline
Jiri Pirkoc7eb7d72017-11-03 11:46:24 +0100111int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
Quentin Monnet33c30a82018-01-03 17:30:45 -0800112 struct tcf_block_ext_info *ei,
113 struct netlink_ext_ack *extack)
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200114{
115 return 0;
116}
117
Jiri Pirko6529eab2017-05-17 11:07:55 +0200118static inline void tcf_block_put(struct tcf_block *block)
Jiri Pirko8ae70032017-02-15 11:57:50 +0100119{
120}
Jiri Pirko87d83092017-05-17 11:07:54 +0200121
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200122static inline
Jiri Pirkoc7eb7d72017-11-03 11:46:24 +0100123void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200124 struct tcf_block_ext_info *ei)
125{
126}
127
Jiri Pirko44186462017-10-13 14:00:59 +0200128static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
129{
130 return NULL;
131}
132
Jiri Pirkoacb67442017-10-19 15:50:31 +0200133static inline
134int tc_setup_cb_block_register(struct tcf_block *block, tc_setup_cb_t *cb,
135 void *cb_priv)
136{
137 return 0;
138}
139
140static inline
141void tc_setup_cb_block_unregister(struct tcf_block *block, tc_setup_cb_t *cb,
142 void *cb_priv)
143{
144}
145
146static inline
147void *tcf_block_cb_priv(struct tcf_block_cb *block_cb)
148{
149 return NULL;
150}
151
152static inline
153struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
154 tc_setup_cb_t *cb, void *cb_ident)
155{
156 return NULL;
157}
158
159static inline
160void tcf_block_cb_incref(struct tcf_block_cb *block_cb)
161{
162}
163
164static inline
165unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
166{
167 return 0;
168}
169
170static inline
171struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
172 tc_setup_cb_t *cb, void *cb_ident,
John Hurley60513bd2018-06-25 14:30:04 -0700173 void *cb_priv,
174 struct netlink_ext_ack *extack)
Jiri Pirkoacb67442017-10-19 15:50:31 +0200175{
176 return NULL;
177}
178
179static inline
180int tcf_block_cb_register(struct tcf_block *block,
181 tc_setup_cb_t *cb, void *cb_ident,
John Hurley60513bd2018-06-25 14:30:04 -0700182 void *cb_priv, struct netlink_ext_ack *extack)
Jiri Pirkoacb67442017-10-19 15:50:31 +0200183{
184 return 0;
185}
186
187static inline
John Hurley32636742018-06-25 14:30:10 -0700188void __tcf_block_cb_unregister(struct tcf_block *block,
189 struct tcf_block_cb *block_cb)
Jiri Pirkoacb67442017-10-19 15:50:31 +0200190{
191}
192
193static inline
194void tcf_block_cb_unregister(struct tcf_block *block,
195 tc_setup_cb_t *cb, void *cb_ident)
196{
197}
198
John Hurley7f76fa32018-11-09 21:21:26 -0800199static inline
200int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv,
201 tc_indr_block_bind_cb_t *cb, void *cb_ident)
202{
203 return 0;
204}
205
206static inline
207int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv,
208 tc_indr_block_bind_cb_t *cb, void *cb_ident)
209{
210 return 0;
211}
212
213static inline
214void __tc_indr_block_cb_unregister(struct net_device *dev,
215 tc_indr_block_bind_cb_t *cb, void *cb_ident)
216{
217}
218
219static inline
220void tc_indr_block_cb_unregister(struct net_device *dev,
221 tc_indr_block_bind_cb_t *cb, void *cb_ident)
222{
223}
224
Jiri Pirko87d83092017-05-17 11:07:54 +0200225static inline int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
226 struct tcf_result *res, bool compat_mode)
227{
228 return TC_ACT_UNSPEC;
229}
Jiri Pirko8ae70032017-02-15 11:57:50 +0100230#endif
Jiri Pirkocf1facd2017-02-09 14:38:56 +0100231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static inline unsigned long
233__cls_set_class(unsigned long *clp, unsigned long cl)
234{
WANG Conga0efb802014-09-30 16:07:24 -0700235 return xchg(clp, cl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238static inline unsigned long
Jiri Pirko34e37592017-10-13 14:01:00 +0200239cls_set_class(struct Qdisc *q, unsigned long *clp, unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 unsigned long old_cl;
Jiri Pirko34e37592017-10-13 14:01:00 +0200242
243 sch_tree_lock(q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 old_cl = __cls_set_class(clp, cl);
Jiri Pirko34e37592017-10-13 14:01:00 +0200245 sch_tree_unlock(q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return old_cl;
247}
248
249static inline void
250tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base)
251{
Jiri Pirko34e37592017-10-13 14:01:00 +0200252 struct Qdisc *q = tp->chain->block->q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 unsigned long cl;
254
Jiri Pirko34e37592017-10-13 14:01:00 +0200255 /* Check q as it is not set for shared blocks. In that case,
256 * setting class is not supported.
257 */
258 if (!q)
259 return;
260 cl = q->ops->cl_ops->bind_tcf(q, base, r->classid);
261 cl = cls_set_class(q, &r->class, cl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (cl)
Jiri Pirko34e37592017-10-13 14:01:00 +0200263 q->ops->cl_ops->unbind_tcf(q, cl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
266static inline void
267tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
268{
Jiri Pirko34e37592017-10-13 14:01:00 +0200269 struct Qdisc *q = tp->chain->block->q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 unsigned long cl;
271
Jiri Pirko34e37592017-10-13 14:01:00 +0200272 if (!q)
273 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if ((cl = __cls_set_class(&r->class, 0)) != 0)
Jiri Pirko34e37592017-10-13 14:01:00 +0200275 q->ops->cl_ops->unbind_tcf(q, cl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000278struct tcf_exts {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#ifdef CONFIG_NET_CLS_ACT
WANG Cong33be6272013-12-15 20:15:05 -0800280 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
WANG Cong22dc13c2016-08-13 22:35:00 -0700281 int nr_actions;
282 struct tc_action **actions;
Cong Wange4b95c42017-11-06 13:47:19 -0800283 struct net *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
WANG Cong5da57f42013-12-15 20:15:07 -0800285 /* Map to export classifier specific extension TLV types to the
286 * generic extensions API. Unsupported extensions must be set to 0.
287 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 int action;
289 int police;
290};
291
WANG Congb9a24bb2016-08-19 12:36:54 -0700292static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police)
WANG Cong33be6272013-12-15 20:15:05 -0800293{
294#ifdef CONFIG_NET_CLS_ACT
WANG Cong5da57f42013-12-15 20:15:07 -0800295 exts->type = 0;
WANG Cong22dc13c2016-08-13 22:35:00 -0700296 exts->nr_actions = 0;
Cong Wange4b95c42017-11-06 13:47:19 -0800297 exts->net = NULL;
WANG Cong22dc13c2016-08-13 22:35:00 -0700298 exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *),
299 GFP_KERNEL);
WANG Congb9a24bb2016-08-19 12:36:54 -0700300 if (!exts->actions)
301 return -ENOMEM;
WANG Cong33be6272013-12-15 20:15:05 -0800302#endif
WANG Cong5da57f42013-12-15 20:15:07 -0800303 exts->action = action;
304 exts->police = police;
WANG Congb9a24bb2016-08-19 12:36:54 -0700305 return 0;
WANG Cong33be6272013-12-15 20:15:05 -0800306}
307
Cong Wange4b95c42017-11-06 13:47:19 -0800308/* Return false if the netns is being destroyed in cleanup_net(). Callers
309 * need to do cleanup synchronously in this case, otherwise may race with
310 * tc_action_net_exit(). Return true for other cases.
311 */
312static inline bool tcf_exts_get_net(struct tcf_exts *exts)
313{
314#ifdef CONFIG_NET_CLS_ACT
315 exts->net = maybe_get_net(exts->net);
316 return exts->net != NULL;
317#else
318 return true;
319#endif
320}
321
322static inline void tcf_exts_put_net(struct tcf_exts *exts)
323{
324#ifdef CONFIG_NET_CLS_ACT
325 if (exts->net)
326 put_net(exts->net);
327#endif
328}
329
WANG Cong22dc13c2016-08-13 22:35:00 -0700330#ifdef CONFIG_NET_CLS_ACT
Cong Wang244cd962018-08-19 12:22:09 -0700331#define tcf_exts_for_each_action(i, a, exts) \
332 for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++)
333#else
334#define tcf_exts_for_each_action(i, a, exts) \
Arnd Bergmann191672c2018-08-22 17:25:44 +0200335 for (; 0; (void)(i), (void)(a), (void)(exts))
WANG Cong22dc13c2016-08-13 22:35:00 -0700336#endif
WANG Cong22dc13c2016-08-13 22:35:00 -0700337
Jakub Kicinskid897a632017-05-31 08:06:43 -0700338static inline void
339tcf_exts_stats_update(const struct tcf_exts *exts,
340 u64 bytes, u64 packets, u64 lastuse)
341{
342#ifdef CONFIG_NET_CLS_ACT
343 int i;
344
345 preempt_disable();
346
347 for (i = 0; i < exts->nr_actions; i++) {
348 struct tc_action *a = exts->actions[i];
349
Eelco Chaudron28169ab2018-09-21 07:14:02 -0400350 tcf_action_stats_update(a, bytes, packets, lastuse, true);
Jakub Kicinskid897a632017-05-31 08:06:43 -0700351 }
352
353 preempt_enable();
354#endif
355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/**
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +0200358 * tcf_exts_has_actions - check if at least one action is present
359 * @exts: tc filter extensions handle
360 *
361 * Returns true if at least one action is present.
362 */
363static inline bool tcf_exts_has_actions(struct tcf_exts *exts)
364{
WANG Cong2734437e2016-08-13 22:34:59 -0700365#ifdef CONFIG_NET_CLS_ACT
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +0200366 return exts->nr_actions;
367#else
368 return false;
369#endif
370}
WANG Cong2734437e2016-08-13 22:34:59 -0700371
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +0200372/**
373 * tcf_exts_has_one_action - check if exactly one action is present
374 * @exts: tc filter extensions handle
375 *
376 * Returns true if exactly one action is present.
377 */
378static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)
379{
380#ifdef CONFIG_NET_CLS_ACT
381 return exts->nr_actions == 1;
382#else
383 return false;
384#endif
385}
WANG Cong2734437e2016-08-13 22:34:59 -0700386
Cong Wang244cd962018-08-19 12:22:09 -0700387static inline struct tc_action *tcf_exts_first_action(struct tcf_exts *exts)
388{
389#ifdef CONFIG_NET_CLS_ACT
390 return exts->actions[0];
391#else
392 return NULL;
393#endif
394}
395
Jiri Pirkoaf69afc2017-08-04 14:28:59 +0200396/**
397 * tcf_exts_exec - execute tc filter extensions
398 * @skb: socket buffer
399 * @exts: tc filter extensions handle
400 * @res: desired result
401 *
Jiri Pirkoaf089e72017-08-04 14:29:01 +0200402 * Executes all configured extensions. Returns TC_ACT_OK on a normal execution,
Jiri Pirkoaf69afc2017-08-04 14:28:59 +0200403 * a negative number if the filter must be considered unmatched or
404 * a positive action code (TC_ACT_*) which must be returned to the
405 * underlying layer.
406 */
407static inline int
408tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
409 struct tcf_result *res)
410{
411#ifdef CONFIG_NET_CLS_ACT
Jiri Pirkoec1a9cc2017-08-04 14:29:02 +0200412 return tcf_action_exec(skb, exts->actions, exts->nr_actions, res);
Jiri Pirkoaf69afc2017-08-04 14:28:59 +0200413#endif
Jiri Pirkoaf089e72017-08-04 14:29:01 +0200414 return TC_ACT_OK;
Jiri Pirkoaf69afc2017-08-04 14:28:59 +0200415}
416
Joe Perches5c152572013-07-30 22:47:13 -0700417int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
418 struct nlattr **tb, struct nlattr *rate_tlv,
Vlad Buslovec6743a2019-02-11 10:55:43 +0200419 struct tcf_exts *exts, bool ovr, bool rtnl_held,
Alexander Aring50a56192018-01-18 11:20:52 -0500420 struct netlink_ext_ack *extack);
WANG Cong18d02642014-09-25 10:26:37 -0700421void tcf_exts_destroy(struct tcf_exts *exts);
Jiri Pirko9b0d4442017-08-04 14:29:15 +0200422void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src);
WANG Cong5da57f42013-12-15 20:15:07 -0800423int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
424int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426/**
427 * struct tcf_pkt_info - packet information
428 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000429struct tcf_pkt_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 unsigned char * ptr;
431 int nexthdr;
432};
433
434#ifdef CONFIG_NET_EMATCH
435
436struct tcf_ematch_ops;
437
438/**
439 * struct tcf_ematch - extended match (ematch)
440 *
441 * @matchid: identifier to allow userspace to reidentify a match
442 * @flags: flags specifying attributes and the relation to other matches
443 * @ops: the operations lookup table of the corresponding ematch module
444 * @datalen: length of the ematch specific configuration data
445 * @data: ematch specific data
446 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000447struct tcf_ematch {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 struct tcf_ematch_ops * ops;
449 unsigned long data;
450 unsigned int datalen;
451 u16 matchid;
452 u16 flags;
John Fastabend82a470f2014-10-05 21:27:53 -0700453 struct net *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454};
455
456static inline int tcf_em_is_container(struct tcf_ematch *em)
457{
458 return !em->ops;
459}
460
461static inline int tcf_em_is_simple(struct tcf_ematch *em)
462{
463 return em->flags & TCF_EM_SIMPLE;
464}
465
466static inline int tcf_em_is_inverted(struct tcf_ematch *em)
467{
468 return em->flags & TCF_EM_INVERT;
469}
470
471static inline int tcf_em_last_match(struct tcf_ematch *em)
472{
473 return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END;
474}
475
476static inline int tcf_em_early_end(struct tcf_ematch *em, int result)
477{
478 if (tcf_em_last_match(em))
479 return 1;
480
481 if (result == 0 && em->flags & TCF_EM_REL_AND)
482 return 1;
483
484 if (result != 0 && em->flags & TCF_EM_REL_OR)
485 return 1;
486
487 return 0;
488}
489
490/**
491 * struct tcf_ematch_tree - ematch tree handle
492 *
493 * @hdr: ematch tree header supplied by userspace
494 * @matches: array of ematches
495 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000496struct tcf_ematch_tree {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 struct tcf_ematch_tree_hdr hdr;
498 struct tcf_ematch * matches;
499
500};
501
502/**
503 * struct tcf_ematch_ops - ematch module operations
504 *
505 * @kind: identifier (kind) of this ematch module
506 * @datalen: length of expected configuration data (optional)
507 * @change: called during validation (optional)
508 * @match: called during ematch tree evaluation, must return 1/0
509 * @destroy: called during destroyage (optional)
510 * @dump: called during dumping process (optional)
511 * @owner: owner, must be set to THIS_MODULE
512 * @link: link to previous/next ematch module (internal use)
513 */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000514struct tcf_ematch_ops {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 int kind;
516 int datalen;
John Fastabend82a470f2014-10-05 21:27:53 -0700517 int (*change)(struct net *net, void *,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 int, struct tcf_ematch *);
519 int (*match)(struct sk_buff *, struct tcf_ematch *,
520 struct tcf_pkt_info *);
John Fastabend82a470f2014-10-05 21:27:53 -0700521 void (*destroy)(struct tcf_ematch *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 int (*dump)(struct sk_buff *, struct tcf_ematch *);
523 struct module *owner;
524 struct list_head link;
525};
526
Joe Perches5c152572013-07-30 22:47:13 -0700527int tcf_em_register(struct tcf_ematch_ops *);
528void tcf_em_unregister(struct tcf_ematch_ops *);
529int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
530 struct tcf_ematch_tree *);
John Fastabend82a470f2014-10-05 21:27:53 -0700531void tcf_em_tree_destroy(struct tcf_ematch_tree *);
Joe Perches5c152572013-07-30 22:47:13 -0700532int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
533int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
534 struct tcf_pkt_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 * tcf_em_tree_match - evaulate an ematch tree
538 *
539 * @skb: socket buffer of the packet in question
540 * @tree: ematch tree to be used for evaluation
541 * @info: packet information examined by classifier
542 *
543 * This function matches @skb against the ematch tree in @tree by going
544 * through all ematches respecting their logic relations returning
545 * as soon as the result is obvious.
546 *
547 * Returns 1 if the ematch tree as-one matches, no ematches are configured
548 * or ematch is not enabled in the kernel, otherwise 0 is returned.
549 */
550static inline int tcf_em_tree_match(struct sk_buff *skb,
551 struct tcf_ematch_tree *tree,
552 struct tcf_pkt_info *info)
553{
554 if (tree->hdr.nmatches)
555 return __tcf_em_tree_match(skb, tree, info);
556 else
557 return 1;
558}
559
Patrick McHardydb3d99c2007-07-11 19:46:26 -0700560#define MODULE_ALIAS_TCF_EMATCH(kind) MODULE_ALIAS("ematch-kind-" __stringify(kind))
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#else /* CONFIG_NET_EMATCH */
563
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000564struct tcf_ematch_tree {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565};
566
567#define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
John Fastabend82a470f2014-10-05 21:27:53 -0700568#define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define tcf_em_tree_dump(skb, t, tlv) (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define tcf_em_tree_match(skb, t, info) ((void)(info), 1)
571
572#endif /* CONFIG_NET_EMATCH */
573
574static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
575{
576 switch (layer) {
577 case TCF_LAYER_LINK:
Wolfgang Bumillerd3303a62018-01-18 11:32:36 +0100578 return skb_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 case TCF_LAYER_NETWORK:
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -0700580 return skb_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 case TCF_LAYER_TRANSPORT:
Arnaldo Carvalho de Melo9c702202007-04-25 18:04:18 -0700582 return skb_transport_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
584
585 return NULL;
586}
587
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700588static inline int tcf_valid_offset(const struct sk_buff *skb,
589 const unsigned char *ptr, const int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
David S. Millerda521b22010-12-21 12:43:16 -0800591 return likely((ptr + len) <= skb_tail_pointer(skb) &&
592 ptr >= skb->head &&
593 (ptr <= (ptr + len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596#ifdef CONFIG_NET_CLS_IND
Denis V. Lunev0eeb8ff2007-12-04 01:15:45 -0800597#include <net/net_namespace.h>
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599static inline int
Alexander Aring1057c552018-01-18 11:20:54 -0500600tcf_change_indev(struct net *net, struct nlattr *indev_tlv,
601 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
WANG Cong2519a602014-01-09 16:14:02 -0800603 char indev[IFNAMSIZ];
Patrick McHardyc01003c2007-03-29 11:46:52 -0700604 struct net_device *dev;
605
Alexander Aring1057c552018-01-18 11:20:54 -0500606 if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) {
607 NL_SET_ERR_MSG(extack, "Interface name too long");
WANG Cong2519a602014-01-09 16:14:02 -0800608 return -EINVAL;
Alexander Aring1057c552018-01-18 11:20:54 -0500609 }
WANG Cong2519a602014-01-09 16:14:02 -0800610 dev = __dev_get_by_name(net, indev);
611 if (!dev)
612 return -ENODEV;
613 return dev->ifindex;
614}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
WANG Cong2519a602014-01-09 16:14:02 -0800616static inline bool
617tcf_match_indev(struct sk_buff *skb, int ifindex)
618{
619 if (!ifindex)
620 return true;
621 if (!skb->skb_iif)
622 return false;
623 return ifindex == skb->skb_iif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624}
625#endif /* CONFIG_NET_CLS_IND */
626
Pablo Neira Ayuso3a7b6862019-02-02 12:50:46 +0100627int tc_setup_flow_action(struct flow_action *flow_action,
628 const struct tcf_exts *exts);
Cong Wangaeb3fec2018-12-11 11:15:46 -0800629int tc_setup_cb_call(struct tcf_block *block, enum tc_setup_type type,
630 void *type_data, bool err_stop);
Pablo Neira Ayusoe3ab7862019-02-02 12:50:45 +0100631unsigned int tcf_exts_num_actions(struct tcf_exts *exts);
Jiri Pirko717503b2017-10-11 09:41:09 +0200632
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200633enum tc_block_command {
634 TC_BLOCK_BIND,
635 TC_BLOCK_UNBIND,
636};
637
638struct tc_block_offload {
639 enum tc_block_command command;
640 enum tcf_block_binder_type binder_type;
641 struct tcf_block *block;
John Hurley60513bd2018-06-25 14:30:04 -0700642 struct netlink_ext_ack *extack;
Jiri Pirko8c4083b2017-10-19 15:50:29 +0200643};
644
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200645struct tc_cls_common_offload {
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200646 u32 chain_index;
647 __be16 protocol;
Jiri Pirkod7c1c8d2017-08-07 10:15:30 +0200648 u32 prio;
Quentin Monnet8f0b4252018-01-19 17:44:47 -0800649 struct netlink_ext_ack *extack;
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200650};
651
John Fastabenda1b7c5f2016-02-16 21:17:09 -0800652struct tc_cls_u32_knode {
653 struct tcf_exts *exts;
Jakub Kicinski068ceb32018-11-19 15:21:46 -0800654 struct tcf_result *res;
John Fastabende0148602016-02-17 14:59:30 -0800655 struct tc_u32_sel *sel;
John Fastabenda1b7c5f2016-02-16 21:17:09 -0800656 u32 handle;
657 u32 val;
658 u32 mask;
659 u32 link_handle;
John Fastabende0148602016-02-17 14:59:30 -0800660 u8 fshift;
John Fastabenda1b7c5f2016-02-16 21:17:09 -0800661};
662
663struct tc_cls_u32_hnode {
664 u32 handle;
665 u32 prio;
666 unsigned int divisor;
667};
668
669enum tc_clsu32_command {
670 TC_CLSU32_NEW_KNODE,
671 TC_CLSU32_REPLACE_KNODE,
672 TC_CLSU32_DELETE_KNODE,
673 TC_CLSU32_NEW_HNODE,
674 TC_CLSU32_REPLACE_HNODE,
675 TC_CLSU32_DELETE_HNODE,
676};
677
678struct tc_cls_u32_offload {
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200679 struct tc_cls_common_offload common;
John Fastabenda1b7c5f2016-02-16 21:17:09 -0800680 /* knode values */
681 enum tc_clsu32_command command;
682 union {
683 struct tc_cls_u32_knode knode;
684 struct tc_cls_u32_hnode hnode;
685 };
686};
687
Jiri Pirko7b06e8a2017-08-09 14:30:35 +0200688static inline bool tc_can_offload(const struct net_device *dev)
John Fastabend6843e7a2016-02-26 07:53:49 -0800689{
Jiri Pirko70b5aee2017-11-01 11:47:41 +0100690 return dev->features & NETIF_F_HW_TC;
John Fastabend6843e7a2016-02-26 07:53:49 -0800691}
692
Quentin Monnetf9eda142018-01-19 17:44:48 -0800693static inline bool tc_can_offload_extack(const struct net_device *dev,
694 struct netlink_ext_ack *extack)
695{
696 bool can = tc_can_offload(dev);
697
698 if (!can)
699 NL_SET_ERR_MSG(extack, "TC offload is disabled on net device");
700
701 return can;
702}
703
Jakub Kicinski878db9f2018-01-25 14:00:43 -0800704static inline bool
705tc_cls_can_offload_and_chain0(const struct net_device *dev,
706 struct tc_cls_common_offload *common)
707{
708 if (!tc_can_offload_extack(dev, common->extack))
709 return false;
710 if (common->chain_index) {
711 NL_SET_ERR_MSG(common->extack,
712 "Driver supports only offload of chain 0");
713 return false;
714 }
715 return true;
716}
717
Hadar Hen Zion55330f02016-12-01 14:06:33 +0200718static inline bool tc_skip_hw(u32 flags)
719{
720 return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false;
721}
722
Samudrala, Sridhard34e3e12016-05-12 17:08:23 -0700723static inline bool tc_skip_sw(u32 flags)
724{
725 return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false;
726}
727
728/* SKIP_HW and SKIP_SW are mutually exclusive flags. */
729static inline bool tc_flags_valid(u32 flags)
730{
Marcelo Ricardo Leitner81c72882018-05-13 17:44:27 -0300731 if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW |
732 TCA_CLS_FLAGS_VERBOSE))
Samudrala, Sridhard34e3e12016-05-12 17:08:23 -0700733 return false;
734
Marcelo Ricardo Leitner81c72882018-05-13 17:44:27 -0300735 flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW;
Samudrala, Sridhard34e3e12016-05-12 17:08:23 -0700736 if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW)))
737 return false;
738
739 return true;
740}
741
Or Gerlitze6960282017-02-16 10:31:12 +0200742static inline bool tc_in_hw(u32 flags)
743{
744 return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false;
745}
746
Jakub Kicinski34832e12018-01-24 12:54:14 -0800747static inline void
748tc_cls_common_offload_init(struct tc_cls_common_offload *cls_common,
749 const struct tcf_proto *tp, u32 flags,
750 struct netlink_ext_ack *extack)
751{
752 cls_common->chain_index = tp->chain->index;
753 cls_common->protocol = tp->protocol;
754 cls_common->prio = tp->prio;
Marcelo Ricardo Leitner81c72882018-05-13 17:44:27 -0300755 if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE)
Jakub Kicinski34832e12018-01-24 12:54:14 -0800756 cls_common->extack = extack;
757}
758
Amir Vadai5b33f482016-03-08 12:42:29 +0200759enum tc_fl_command {
760 TC_CLSFLOWER_REPLACE,
761 TC_CLSFLOWER_DESTROY,
Amir Vadai10cbc682016-05-13 12:55:37 +0000762 TC_CLSFLOWER_STATS,
Jiri Pirko34738452018-07-23 09:23:11 +0200763 TC_CLSFLOWER_TMPLT_CREATE,
764 TC_CLSFLOWER_TMPLT_DESTROY,
Amir Vadai5b33f482016-03-08 12:42:29 +0200765};
766
767struct tc_cls_flower_offload {
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200768 struct tc_cls_common_offload common;
Amir Vadai5b33f482016-03-08 12:42:29 +0200769 enum tc_fl_command command;
Amir Vadai8208d212016-03-11 11:08:45 +0200770 unsigned long cookie;
Pablo Neira Ayuso8f256622019-02-02 12:50:43 +0100771 struct flow_rule *rule;
Pablo Neira Ayuso3b1903e2019-02-02 12:50:47 +0100772 struct flow_stats stats;
Amritha Nambiar384c1812017-10-27 02:35:34 -0700773 u32 classid;
Amir Vadai5b33f482016-03-08 12:42:29 +0200774};
775
Pablo Neira Ayuso8f256622019-02-02 12:50:43 +0100776static inline struct flow_rule *
777tc_cls_flower_offload_flow_rule(struct tc_cls_flower_offload *tc_flow_cmd)
778{
779 return tc_flow_cmd->rule;
780}
781
Yotam Gigib87f7932016-07-21 12:03:12 +0200782enum tc_matchall_command {
783 TC_CLSMATCHALL_REPLACE,
784 TC_CLSMATCHALL_DESTROY,
785};
786
787struct tc_cls_matchall_offload {
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200788 struct tc_cls_common_offload common;
Yotam Gigib87f7932016-07-21 12:03:12 +0200789 enum tc_matchall_command command;
790 struct tcf_exts *exts;
791 unsigned long cookie;
792};
793
Jakub Kicinski332ae8e2016-09-21 11:43:53 +0100794enum tc_clsbpf_command {
Jakub Kicinski102740b2017-12-19 13:32:13 -0800795 TC_CLSBPF_OFFLOAD,
Jakub Kicinski68d64062016-09-21 11:44:02 +0100796 TC_CLSBPF_STATS,
Jakub Kicinski332ae8e2016-09-21 11:43:53 +0100797};
798
799struct tc_cls_bpf_offload {
Jiri Pirko5fd9fc42017-08-07 10:15:29 +0200800 struct tc_cls_common_offload common;
Jakub Kicinski332ae8e2016-09-21 11:43:53 +0100801 enum tc_clsbpf_command command;
802 struct tcf_exts *exts;
803 struct bpf_prog *prog;
Jakub Kicinski102740b2017-12-19 13:32:13 -0800804 struct bpf_prog *oldprog;
Jakub Kicinski332ae8e2016-09-21 11:43:53 +0100805 const char *name;
806 bool exts_integrated;
807};
808
Amritha Nambiar4e8b86c2017-09-07 04:00:06 -0700809struct tc_mqprio_qopt_offload {
810 /* struct tc_mqprio_qopt must always be the first element */
811 struct tc_mqprio_qopt qopt;
812 u16 mode;
813 u16 shaper;
814 u32 flags;
815 u64 min_rate[TC_QOPT_MAX_QUEUE];
816 u64 max_rate[TC_QOPT_MAX_QUEUE];
817};
Jamal Hadi Salim1045ba72017-01-24 07:02:41 -0500818
819/* This structure holds cookie structure that is passed from user
820 * to the kernel for actions and classifiers
821 */
822struct tc_cookie {
823 u8 *data;
824 u32 len;
Vlad Busloveec94fd2018-07-05 17:24:23 +0300825 struct rcu_head rcu;
Jamal Hadi Salim1045ba72017-01-24 07:02:41 -0500826};
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100827
Nogah Frankelf34b4aa2018-01-10 14:59:58 +0100828struct tc_qopt_offload_stats {
829 struct gnet_stats_basic_packed *bstats;
830 struct gnet_stats_queue *qstats;
831};
832
Jakub Kicinskif971b132018-05-25 21:53:35 -0700833enum tc_mq_command {
834 TC_MQ_CREATE,
835 TC_MQ_DESTROY,
Jakub Kicinski47c669a42018-05-25 21:53:37 -0700836 TC_MQ_STATS,
Jakub Kicinskid577a3d2018-11-12 14:58:14 -0800837 TC_MQ_GRAFT,
838};
839
840struct tc_mq_opt_offload_graft_params {
841 unsigned long queue;
842 u32 child_handle;
Jakub Kicinskif971b132018-05-25 21:53:35 -0700843};
844
845struct tc_mq_qopt_offload {
846 enum tc_mq_command command;
847 u32 handle;
Jakub Kicinskid577a3d2018-11-12 14:58:14 -0800848 union {
849 struct tc_qopt_offload_stats stats;
850 struct tc_mq_opt_offload_graft_params graft_params;
851 };
Jakub Kicinskif971b132018-05-25 21:53:35 -0700852};
853
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100854enum tc_red_command {
855 TC_RED_REPLACE,
856 TC_RED_DESTROY,
857 TC_RED_STATS,
858 TC_RED_XSTATS,
Jakub Kicinskibf2a7522018-11-12 14:58:13 -0800859 TC_RED_GRAFT,
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100860};
861
862struct tc_red_qopt_offload_params {
863 u32 min;
864 u32 max;
865 u32 probability;
Jakub Kicinskic0b74902018-11-12 14:58:16 -0800866 u32 limit;
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100867 bool is_ecn;
Jakub Kicinski190852a2018-11-08 19:50:38 -0800868 bool is_harddrop;
Jakub Kicinski416ef9b2018-01-14 20:01:26 -0800869 struct gnet_stats_queue *qstats;
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100870};
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100871
872struct tc_red_qopt_offload {
873 enum tc_red_command command;
874 u32 handle;
875 u32 parent;
876 union {
877 struct tc_red_qopt_offload_params set;
Nogah Frankelf34b4aa2018-01-10 14:59:58 +0100878 struct tc_qopt_offload_stats stats;
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100879 struct red_stats *xstats;
Jakub Kicinskibf2a7522018-11-12 14:58:13 -0800880 u32 child_handle;
Nogah Frankel602f3ba2017-11-06 07:23:41 +0100881 };
882};
883
Jakub Kicinski890d8d22018-11-19 15:21:42 -0800884enum tc_gred_command {
885 TC_GRED_REPLACE,
886 TC_GRED_DESTROY,
Jakub Kicinskie49efd52018-11-19 15:21:43 -0800887 TC_GRED_STATS,
Jakub Kicinski890d8d22018-11-19 15:21:42 -0800888};
889
890struct tc_gred_vq_qopt_offload_params {
891 bool present;
892 u32 limit;
893 u32 prio;
894 u32 min;
895 u32 max;
896 bool is_ecn;
897 bool is_harddrop;
898 u32 probability;
899 /* Only need backlog, see struct tc_prio_qopt_offload_params */
900 u32 *backlog;
901};
902
903struct tc_gred_qopt_offload_params {
904 bool grio_on;
905 bool wred_on;
906 unsigned int dp_cnt;
907 unsigned int dp_def;
908 struct gnet_stats_queue *qstats;
909 struct tc_gred_vq_qopt_offload_params tab[MAX_DPs];
910};
911
Jakub Kicinskie49efd52018-11-19 15:21:43 -0800912struct tc_gred_qopt_offload_stats {
913 struct gnet_stats_basic_packed bstats[MAX_DPs];
914 struct gnet_stats_queue qstats[MAX_DPs];
915 struct red_stats *xstats[MAX_DPs];
916};
917
Jakub Kicinski890d8d22018-11-19 15:21:42 -0800918struct tc_gred_qopt_offload {
919 enum tc_gred_command command;
920 u32 handle;
921 u32 parent;
922 union {
923 struct tc_gred_qopt_offload_params set;
Jakub Kicinskie49efd52018-11-19 15:21:43 -0800924 struct tc_gred_qopt_offload_stats stats;
Jakub Kicinski890d8d22018-11-19 15:21:42 -0800925 };
926};
927
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100928enum tc_prio_command {
929 TC_PRIO_REPLACE,
930 TC_PRIO_DESTROY,
931 TC_PRIO_STATS,
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100932 TC_PRIO_GRAFT,
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100933};
934
935struct tc_prio_qopt_offload_params {
936 int bands;
937 u8 priomap[TC_PRIO_MAX + 1];
938 /* In case that a prio qdisc is offloaded and now is changed to a
939 * non-offloadedable config, it needs to update the backlog & qlen
940 * values to negate the HW backlog & qlen values (and only them).
941 */
942 struct gnet_stats_queue *qstats;
943};
944
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100945struct tc_prio_qopt_offload_graft_params {
946 u8 band;
947 u32 child_handle;
948};
949
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100950struct tc_prio_qopt_offload {
951 enum tc_prio_command command;
952 u32 handle;
953 u32 parent;
954 union {
955 struct tc_prio_qopt_offload_params replace_params;
956 struct tc_qopt_offload_stats stats;
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100957 struct tc_prio_qopt_offload_graft_params graft_params;
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100958 };
959};
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100960
Jakub Kicinski98b0e5f2018-11-12 14:58:10 -0800961enum tc_root_command {
962 TC_ROOT_GRAFT,
963};
964
965struct tc_root_qopt_offload {
966 enum tc_root_command command;
967 u32 handle;
968 bool ingress;
969};
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971#endif