xref: /openbmc/linux/include/net/pkt_cls.h (revision 191672ca)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef __NET_PKT_CLS_H
31da177e4SLinus Torvalds #define __NET_PKT_CLS_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/pkt_cls.h>
67aa0045dSCong Wang #include <linux/workqueue.h>
71da177e4SLinus Torvalds #include <net/sch_generic.h>
81da177e4SLinus Torvalds #include <net/act_api.h>
91da177e4SLinus Torvalds 
10cd11b164SPaolo Abeni /* TC action not accessible from user space */
11cd11b164SPaolo Abeni #define TC_ACT_REINSERT		(TC_ACT_VALUE_MAX + 1)
12cd11b164SPaolo Abeni 
131da177e4SLinus Torvalds /* Basic packet classifier frontend definitions. */
141da177e4SLinus Torvalds 
15fd2c3ef7SEric Dumazet struct tcf_walker {
161da177e4SLinus Torvalds 	int	stop;
171da177e4SLinus Torvalds 	int	skip;
181da177e4SLinus Torvalds 	int	count;
1901683a14SVlad Buslov 	unsigned long cookie;
208113c095SWANG Cong 	int	(*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
211da177e4SLinus Torvalds };
221da177e4SLinus Torvalds 
235c15257fSJoe Perches int register_tcf_proto_ops(struct tcf_proto_ops *ops);
245c15257fSJoe Perches int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
251da177e4SLinus Torvalds 
268c4083b3SJiri Pirko enum tcf_block_binder_type {
278c4083b3SJiri Pirko 	TCF_BLOCK_BINDER_TYPE_UNSPEC,
286e40cf2dSJiri Pirko 	TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
296e40cf2dSJiri Pirko 	TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS,
308c4083b3SJiri Pirko };
318c4083b3SJiri Pirko 
328c4083b3SJiri Pirko struct tcf_block_ext_info {
338c4083b3SJiri Pirko 	enum tcf_block_binder_type binder_type;
34c7eb7d72SJiri Pirko 	tcf_chain_head_change_t *chain_head_change;
35c7eb7d72SJiri Pirko 	void *chain_head_change_priv;
3648617387SJiri Pirko 	u32 block_index;
378c4083b3SJiri Pirko };
388c4083b3SJiri Pirko 
39acb67442SJiri Pirko struct tcf_block_cb;
40aaa908ffSCong Wang bool tcf_queue_work(struct rcu_work *rwork, work_func_t func);
41acb67442SJiri Pirko 
428ae70032SJiri Pirko #ifdef CONFIG_NET_CLS
431f3ed383SJiri Pirko struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block,
441f3ed383SJiri Pirko 				       u32 chain_index);
451f3ed383SJiri Pirko void tcf_chain_put_by_act(struct tcf_chain *chain);
46f36fe1c4SJiri Pirko void tcf_block_netif_keep_dst(struct tcf_block *block);
476529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block,
488d1a77f9SAlexander Aring 		  struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
498d1a77f9SAlexander Aring 		  struct netlink_ext_ack *extack);
50c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
518d1a77f9SAlexander Aring 		      struct tcf_block_ext_info *ei,
528d1a77f9SAlexander Aring 		      struct netlink_ext_ack *extack);
536529eabaSJiri Pirko void tcf_block_put(struct tcf_block *block);
54c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
558c4083b3SJiri Pirko 		       struct tcf_block_ext_info *ei);
5644186460SJiri Pirko 
5748617387SJiri Pirko static inline bool tcf_block_shared(struct tcf_block *block)
5848617387SJiri Pirko {
5948617387SJiri Pirko 	return block->index;
6048617387SJiri Pirko }
6148617387SJiri Pirko 
6244186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
6344186460SJiri Pirko {
6448617387SJiri Pirko 	WARN_ON(tcf_block_shared(block));
6544186460SJiri Pirko 	return block->q;
6644186460SJiri Pirko }
6744186460SJiri Pirko 
6844186460SJiri Pirko static inline struct net_device *tcf_block_dev(struct tcf_block *block)
6944186460SJiri Pirko {
7044186460SJiri Pirko 	return tcf_block_q(block)->dev_queue->dev;
7144186460SJiri Pirko }
7244186460SJiri Pirko 
73acb67442SJiri Pirko void *tcf_block_cb_priv(struct tcf_block_cb *block_cb);
74acb67442SJiri Pirko struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
75acb67442SJiri Pirko 					 tc_setup_cb_t *cb, void *cb_ident);
76acb67442SJiri Pirko void tcf_block_cb_incref(struct tcf_block_cb *block_cb);
77acb67442SJiri Pirko unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb);
78acb67442SJiri Pirko struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
79acb67442SJiri Pirko 					     tc_setup_cb_t *cb, void *cb_ident,
8060513bd8SJohn Hurley 					     void *cb_priv,
8160513bd8SJohn Hurley 					     struct netlink_ext_ack *extack);
82acb67442SJiri Pirko int tcf_block_cb_register(struct tcf_block *block,
83acb67442SJiri Pirko 			  tc_setup_cb_t *cb, void *cb_ident,
8460513bd8SJohn Hurley 			  void *cb_priv, struct netlink_ext_ack *extack);
8532636742SJohn Hurley void __tcf_block_cb_unregister(struct tcf_block *block,
8632636742SJohn Hurley 			       struct tcf_block_cb *block_cb);
87acb67442SJiri Pirko void tcf_block_cb_unregister(struct tcf_block *block,
88acb67442SJiri Pirko 			     tc_setup_cb_t *cb, void *cb_ident);
89acb67442SJiri Pirko 
9087d83093SJiri Pirko int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
9187d83093SJiri Pirko 		 struct tcf_result *res, bool compat_mode);
9287d83093SJiri Pirko 
938ae70032SJiri Pirko #else
946529eabaSJiri Pirko static inline
956529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block,
963c149091SSudip Mukherjee 		  struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
973c149091SSudip Mukherjee 		  struct netlink_ext_ack *extack)
986529eabaSJiri Pirko {
996529eabaSJiri Pirko 	return 0;
1006529eabaSJiri Pirko }
1016529eabaSJiri Pirko 
1028c4083b3SJiri Pirko static inline
103c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
10433c30a8bSQuentin Monnet 		      struct tcf_block_ext_info *ei,
10533c30a8bSQuentin Monnet 		      struct netlink_ext_ack *extack)
1068c4083b3SJiri Pirko {
1078c4083b3SJiri Pirko 	return 0;
1088c4083b3SJiri Pirko }
1098c4083b3SJiri Pirko 
1106529eabaSJiri Pirko static inline void tcf_block_put(struct tcf_block *block)
1118ae70032SJiri Pirko {
1128ae70032SJiri Pirko }
11387d83093SJiri Pirko 
1148c4083b3SJiri Pirko static inline
115c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
1168c4083b3SJiri Pirko 		       struct tcf_block_ext_info *ei)
1178c4083b3SJiri Pirko {
1188c4083b3SJiri Pirko }
1198c4083b3SJiri Pirko 
12044186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
12144186460SJiri Pirko {
12244186460SJiri Pirko 	return NULL;
12344186460SJiri Pirko }
12444186460SJiri Pirko 
12544186460SJiri Pirko static inline struct net_device *tcf_block_dev(struct tcf_block *block)
12644186460SJiri Pirko {
12744186460SJiri Pirko 	return NULL;
12844186460SJiri Pirko }
12944186460SJiri Pirko 
130acb67442SJiri Pirko static inline
131acb67442SJiri Pirko int tc_setup_cb_block_register(struct tcf_block *block, tc_setup_cb_t *cb,
132acb67442SJiri Pirko 			       void *cb_priv)
133acb67442SJiri Pirko {
134acb67442SJiri Pirko 	return 0;
135acb67442SJiri Pirko }
136acb67442SJiri Pirko 
137acb67442SJiri Pirko static inline
138acb67442SJiri Pirko void tc_setup_cb_block_unregister(struct tcf_block *block, tc_setup_cb_t *cb,
139acb67442SJiri Pirko 				  void *cb_priv)
140acb67442SJiri Pirko {
141acb67442SJiri Pirko }
142acb67442SJiri Pirko 
143acb67442SJiri Pirko static inline
144acb67442SJiri Pirko void *tcf_block_cb_priv(struct tcf_block_cb *block_cb)
145acb67442SJiri Pirko {
146acb67442SJiri Pirko 	return NULL;
147acb67442SJiri Pirko }
148acb67442SJiri Pirko 
149acb67442SJiri Pirko static inline
150acb67442SJiri Pirko struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
151acb67442SJiri Pirko 					 tc_setup_cb_t *cb, void *cb_ident)
152acb67442SJiri Pirko {
153acb67442SJiri Pirko 	return NULL;
154acb67442SJiri Pirko }
155acb67442SJiri Pirko 
156acb67442SJiri Pirko static inline
157acb67442SJiri Pirko void tcf_block_cb_incref(struct tcf_block_cb *block_cb)
158acb67442SJiri Pirko {
159acb67442SJiri Pirko }
160acb67442SJiri Pirko 
161acb67442SJiri Pirko static inline
162acb67442SJiri Pirko unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
163acb67442SJiri Pirko {
164acb67442SJiri Pirko 	return 0;
165acb67442SJiri Pirko }
166acb67442SJiri Pirko 
167acb67442SJiri Pirko static inline
168acb67442SJiri Pirko struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
169acb67442SJiri Pirko 					     tc_setup_cb_t *cb, void *cb_ident,
17060513bd8SJohn Hurley 					     void *cb_priv,
17160513bd8SJohn Hurley 					     struct netlink_ext_ack *extack)
172acb67442SJiri Pirko {
173acb67442SJiri Pirko 	return NULL;
174acb67442SJiri Pirko }
175acb67442SJiri Pirko 
176acb67442SJiri Pirko static inline
177acb67442SJiri Pirko int tcf_block_cb_register(struct tcf_block *block,
178acb67442SJiri Pirko 			  tc_setup_cb_t *cb, void *cb_ident,
17960513bd8SJohn Hurley 			  void *cb_priv, struct netlink_ext_ack *extack)
180acb67442SJiri Pirko {
181acb67442SJiri Pirko 	return 0;
182acb67442SJiri Pirko }
183acb67442SJiri Pirko 
184acb67442SJiri Pirko static inline
18532636742SJohn Hurley void __tcf_block_cb_unregister(struct tcf_block *block,
18632636742SJohn Hurley 			       struct tcf_block_cb *block_cb)
187acb67442SJiri Pirko {
188acb67442SJiri Pirko }
189acb67442SJiri Pirko 
190acb67442SJiri Pirko static inline
191acb67442SJiri Pirko void tcf_block_cb_unregister(struct tcf_block *block,
192acb67442SJiri Pirko 			     tc_setup_cb_t *cb, void *cb_ident)
193acb67442SJiri Pirko {
194acb67442SJiri Pirko }
195acb67442SJiri Pirko 
19687d83093SJiri Pirko static inline int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
19787d83093SJiri Pirko 			       struct tcf_result *res, bool compat_mode)
19887d83093SJiri Pirko {
19987d83093SJiri Pirko 	return TC_ACT_UNSPEC;
20087d83093SJiri Pirko }
2018ae70032SJiri Pirko #endif
202cf1facdaSJiri Pirko 
2031da177e4SLinus Torvalds static inline unsigned long
2041da177e4SLinus Torvalds __cls_set_class(unsigned long *clp, unsigned long cl)
2051da177e4SLinus Torvalds {
206a0efb80cSWANG Cong 	return xchg(clp, cl);
2071da177e4SLinus Torvalds }
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds static inline unsigned long
21034e3759cSJiri Pirko cls_set_class(struct Qdisc *q, unsigned long *clp, unsigned long cl)
2111da177e4SLinus Torvalds {
2121da177e4SLinus Torvalds 	unsigned long old_cl;
2131da177e4SLinus Torvalds 
21434e3759cSJiri Pirko 	sch_tree_lock(q);
2151da177e4SLinus Torvalds 	old_cl = __cls_set_class(clp, cl);
21634e3759cSJiri Pirko 	sch_tree_unlock(q);
2171da177e4SLinus Torvalds 	return old_cl;
2181da177e4SLinus Torvalds }
2191da177e4SLinus Torvalds 
2201da177e4SLinus Torvalds static inline void
2211da177e4SLinus Torvalds tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base)
2221da177e4SLinus Torvalds {
22334e3759cSJiri Pirko 	struct Qdisc *q = tp->chain->block->q;
2241da177e4SLinus Torvalds 	unsigned long cl;
2251da177e4SLinus Torvalds 
22634e3759cSJiri Pirko 	/* Check q as it is not set for shared blocks. In that case,
22734e3759cSJiri Pirko 	 * setting class is not supported.
22834e3759cSJiri Pirko 	 */
22934e3759cSJiri Pirko 	if (!q)
23034e3759cSJiri Pirko 		return;
23134e3759cSJiri Pirko 	cl = q->ops->cl_ops->bind_tcf(q, base, r->classid);
23234e3759cSJiri Pirko 	cl = cls_set_class(q, &r->class, cl);
2331da177e4SLinus Torvalds 	if (cl)
23434e3759cSJiri Pirko 		q->ops->cl_ops->unbind_tcf(q, cl);
2351da177e4SLinus Torvalds }
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds static inline void
2381da177e4SLinus Torvalds tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
2391da177e4SLinus Torvalds {
24034e3759cSJiri Pirko 	struct Qdisc *q = tp->chain->block->q;
2411da177e4SLinus Torvalds 	unsigned long cl;
2421da177e4SLinus Torvalds 
24334e3759cSJiri Pirko 	if (!q)
24434e3759cSJiri Pirko 		return;
2451da177e4SLinus Torvalds 	if ((cl = __cls_set_class(&r->class, 0)) != 0)
24634e3759cSJiri Pirko 		q->ops->cl_ops->unbind_tcf(q, cl);
2471da177e4SLinus Torvalds }
2481da177e4SLinus Torvalds 
249fd2c3ef7SEric Dumazet struct tcf_exts {
2501da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
25133be6271SWANG Cong 	__u32	type; /* for backward compat(TCA_OLD_COMPAT) */
25222dc13c8SWANG Cong 	int nr_actions;
25322dc13c8SWANG Cong 	struct tc_action **actions;
254e4b95c41SCong Wang 	struct net *net;
2551da177e4SLinus Torvalds #endif
2561da177e4SLinus Torvalds 	/* Map to export classifier specific extension TLV types to the
2571da177e4SLinus Torvalds 	 * generic extensions API. Unsupported extensions must be set to 0.
2581da177e4SLinus Torvalds 	 */
2591da177e4SLinus Torvalds 	int action;
2601da177e4SLinus Torvalds 	int police;
2611da177e4SLinus Torvalds };
2621da177e4SLinus Torvalds 
263b9a24bb7SWANG Cong static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police)
26433be6271SWANG Cong {
26533be6271SWANG Cong #ifdef CONFIG_NET_CLS_ACT
2665da57f42SWANG Cong 	exts->type = 0;
26722dc13c8SWANG Cong 	exts->nr_actions = 0;
268e4b95c41SCong Wang 	exts->net = NULL;
26922dc13c8SWANG Cong 	exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *),
27022dc13c8SWANG Cong 				GFP_KERNEL);
271b9a24bb7SWANG Cong 	if (!exts->actions)
272b9a24bb7SWANG Cong 		return -ENOMEM;
27333be6271SWANG Cong #endif
2745da57f42SWANG Cong 	exts->action = action;
2755da57f42SWANG Cong 	exts->police = police;
276b9a24bb7SWANG Cong 	return 0;
27733be6271SWANG Cong }
27833be6271SWANG Cong 
279e4b95c41SCong Wang /* Return false if the netns is being destroyed in cleanup_net(). Callers
280e4b95c41SCong Wang  * need to do cleanup synchronously in this case, otherwise may race with
281e4b95c41SCong Wang  * tc_action_net_exit(). Return true for other cases.
282e4b95c41SCong Wang  */
283e4b95c41SCong Wang static inline bool tcf_exts_get_net(struct tcf_exts *exts)
284e4b95c41SCong Wang {
285e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT
286e4b95c41SCong Wang 	exts->net = maybe_get_net(exts->net);
287e4b95c41SCong Wang 	return exts->net != NULL;
288e4b95c41SCong Wang #else
289e4b95c41SCong Wang 	return true;
290e4b95c41SCong Wang #endif
291e4b95c41SCong Wang }
292e4b95c41SCong Wang 
293e4b95c41SCong Wang static inline void tcf_exts_put_net(struct tcf_exts *exts)
294e4b95c41SCong Wang {
295e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT
296e4b95c41SCong Wang 	if (exts->net)
297e4b95c41SCong Wang 		put_net(exts->net);
298e4b95c41SCong Wang #endif
299e4b95c41SCong Wang }
300e4b95c41SCong Wang 
30122dc13c8SWANG Cong #ifdef CONFIG_NET_CLS_ACT
302244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \
303244cd96aSCong Wang 	for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++)
304244cd96aSCong Wang #else
305244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \
306191672caSArnd Bergmann 	for (; 0; (void)(i), (void)(a), (void)(exts))
30722dc13c8SWANG Cong #endif
30822dc13c8SWANG Cong 
309d897a638SJakub Kicinski static inline void
310d897a638SJakub Kicinski tcf_exts_stats_update(const struct tcf_exts *exts,
311d897a638SJakub Kicinski 		      u64 bytes, u64 packets, u64 lastuse)
312d897a638SJakub Kicinski {
313d897a638SJakub Kicinski #ifdef CONFIG_NET_CLS_ACT
314d897a638SJakub Kicinski 	int i;
315d897a638SJakub Kicinski 
316d897a638SJakub Kicinski 	preempt_disable();
317d897a638SJakub Kicinski 
318d897a638SJakub Kicinski 	for (i = 0; i < exts->nr_actions; i++) {
319d897a638SJakub Kicinski 		struct tc_action *a = exts->actions[i];
320d897a638SJakub Kicinski 
321d897a638SJakub Kicinski 		tcf_action_stats_update(a, bytes, packets, lastuse);
322d897a638SJakub Kicinski 	}
323d897a638SJakub Kicinski 
324d897a638SJakub Kicinski 	preempt_enable();
325d897a638SJakub Kicinski #endif
326d897a638SJakub Kicinski }
327d897a638SJakub Kicinski 
3281da177e4SLinus Torvalds /**
3293bcc0cecSJiri Pirko  * tcf_exts_has_actions - check if at least one action is present
3303bcc0cecSJiri Pirko  * @exts: tc filter extensions handle
3313bcc0cecSJiri Pirko  *
3323bcc0cecSJiri Pirko  * Returns true if at least one action is present.
3333bcc0cecSJiri Pirko  */
3343bcc0cecSJiri Pirko static inline bool tcf_exts_has_actions(struct tcf_exts *exts)
3353bcc0cecSJiri Pirko {
3362734437eSWANG Cong #ifdef CONFIG_NET_CLS_ACT
3373bcc0cecSJiri Pirko 	return exts->nr_actions;
3383bcc0cecSJiri Pirko #else
3393bcc0cecSJiri Pirko 	return false;
3403bcc0cecSJiri Pirko #endif
3413bcc0cecSJiri Pirko }
3422734437eSWANG Cong 
3433bcc0cecSJiri Pirko /**
3443bcc0cecSJiri Pirko  * tcf_exts_has_one_action - check if exactly one action is present
3453bcc0cecSJiri Pirko  * @exts: tc filter extensions handle
3463bcc0cecSJiri Pirko  *
3473bcc0cecSJiri Pirko  * Returns true if exactly one action is present.
3483bcc0cecSJiri Pirko  */
3493bcc0cecSJiri Pirko static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)
3503bcc0cecSJiri Pirko {
3513bcc0cecSJiri Pirko #ifdef CONFIG_NET_CLS_ACT
3523bcc0cecSJiri Pirko 	return exts->nr_actions == 1;
3533bcc0cecSJiri Pirko #else
3543bcc0cecSJiri Pirko 	return false;
3553bcc0cecSJiri Pirko #endif
3563bcc0cecSJiri Pirko }
3572734437eSWANG Cong 
358244cd96aSCong Wang static inline struct tc_action *tcf_exts_first_action(struct tcf_exts *exts)
359244cd96aSCong Wang {
360244cd96aSCong Wang #ifdef CONFIG_NET_CLS_ACT
361244cd96aSCong Wang 	return exts->actions[0];
362244cd96aSCong Wang #else
363244cd96aSCong Wang 	return NULL;
364244cd96aSCong Wang #endif
365244cd96aSCong Wang }
366244cd96aSCong Wang 
367af69afc5SJiri Pirko /**
368af69afc5SJiri Pirko  * tcf_exts_exec - execute tc filter extensions
369af69afc5SJiri Pirko  * @skb: socket buffer
370af69afc5SJiri Pirko  * @exts: tc filter extensions handle
371af69afc5SJiri Pirko  * @res: desired result
372af69afc5SJiri Pirko  *
373af089e70SJiri Pirko  * Executes all configured extensions. Returns TC_ACT_OK on a normal execution,
374af69afc5SJiri Pirko  * a negative number if the filter must be considered unmatched or
375af69afc5SJiri Pirko  * a positive action code (TC_ACT_*) which must be returned to the
376af69afc5SJiri Pirko  * underlying layer.
377af69afc5SJiri Pirko  */
378af69afc5SJiri Pirko static inline int
379af69afc5SJiri Pirko tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
380af69afc5SJiri Pirko 	      struct tcf_result *res)
381af69afc5SJiri Pirko {
382af69afc5SJiri Pirko #ifdef CONFIG_NET_CLS_ACT
383ec1a9ccaSJiri Pirko 	return tcf_action_exec(skb, exts->actions, exts->nr_actions, res);
384af69afc5SJiri Pirko #endif
385af089e70SJiri Pirko 	return TC_ACT_OK;
386af69afc5SJiri Pirko }
387af69afc5SJiri Pirko 
3885c15257fSJoe Perches int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
389c1b52739SBenjamin LaHaise 		      struct nlattr **tb, struct nlattr *rate_tlv,
39050a56190SAlexander Aring 		      struct tcf_exts *exts, bool ovr,
39150a56190SAlexander Aring 		      struct netlink_ext_ack *extack);
39218d0264fSWANG Cong void tcf_exts_destroy(struct tcf_exts *exts);
3939b0d4446SJiri Pirko void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src);
3945da57f42SWANG Cong int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
3955da57f42SWANG Cong int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds /**
3981da177e4SLinus Torvalds  * struct tcf_pkt_info - packet information
3991da177e4SLinus Torvalds  */
400fd2c3ef7SEric Dumazet struct tcf_pkt_info {
4011da177e4SLinus Torvalds 	unsigned char *		ptr;
4021da177e4SLinus Torvalds 	int			nexthdr;
4031da177e4SLinus Torvalds };
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds #ifdef CONFIG_NET_EMATCH
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds struct tcf_ematch_ops;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds /**
4101da177e4SLinus Torvalds  * struct tcf_ematch - extended match (ematch)
4111da177e4SLinus Torvalds  *
4121da177e4SLinus Torvalds  * @matchid: identifier to allow userspace to reidentify a match
4131da177e4SLinus Torvalds  * @flags: flags specifying attributes and the relation to other matches
4141da177e4SLinus Torvalds  * @ops: the operations lookup table of the corresponding ematch module
4151da177e4SLinus Torvalds  * @datalen: length of the ematch specific configuration data
4161da177e4SLinus Torvalds  * @data: ematch specific data
4171da177e4SLinus Torvalds  */
418fd2c3ef7SEric Dumazet struct tcf_ematch {
4191da177e4SLinus Torvalds 	struct tcf_ematch_ops * ops;
4201da177e4SLinus Torvalds 	unsigned long		data;
4211da177e4SLinus Torvalds 	unsigned int		datalen;
4221da177e4SLinus Torvalds 	u16			matchid;
4231da177e4SLinus Torvalds 	u16			flags;
42482a470f1SJohn Fastabend 	struct net		*net;
4251da177e4SLinus Torvalds };
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds static inline int tcf_em_is_container(struct tcf_ematch *em)
4281da177e4SLinus Torvalds {
4291da177e4SLinus Torvalds 	return !em->ops;
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds static inline int tcf_em_is_simple(struct tcf_ematch *em)
4331da177e4SLinus Torvalds {
4341da177e4SLinus Torvalds 	return em->flags & TCF_EM_SIMPLE;
4351da177e4SLinus Torvalds }
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds static inline int tcf_em_is_inverted(struct tcf_ematch *em)
4381da177e4SLinus Torvalds {
4391da177e4SLinus Torvalds 	return em->flags & TCF_EM_INVERT;
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds static inline int tcf_em_last_match(struct tcf_ematch *em)
4431da177e4SLinus Torvalds {
4441da177e4SLinus Torvalds 	return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END;
4451da177e4SLinus Torvalds }
4461da177e4SLinus Torvalds 
4471da177e4SLinus Torvalds static inline int tcf_em_early_end(struct tcf_ematch *em, int result)
4481da177e4SLinus Torvalds {
4491da177e4SLinus Torvalds 	if (tcf_em_last_match(em))
4501da177e4SLinus Torvalds 		return 1;
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 	if (result == 0 && em->flags & TCF_EM_REL_AND)
4531da177e4SLinus Torvalds 		return 1;
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds 	if (result != 0 && em->flags & TCF_EM_REL_OR)
4561da177e4SLinus Torvalds 		return 1;
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds 	return 0;
4591da177e4SLinus Torvalds }
4601da177e4SLinus Torvalds 
4611da177e4SLinus Torvalds /**
4621da177e4SLinus Torvalds  * struct tcf_ematch_tree - ematch tree handle
4631da177e4SLinus Torvalds  *
4641da177e4SLinus Torvalds  * @hdr: ematch tree header supplied by userspace
4651da177e4SLinus Torvalds  * @matches: array of ematches
4661da177e4SLinus Torvalds  */
467fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
4681da177e4SLinus Torvalds 	struct tcf_ematch_tree_hdr hdr;
4691da177e4SLinus Torvalds 	struct tcf_ematch *	matches;
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds };
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds /**
4741da177e4SLinus Torvalds  * struct tcf_ematch_ops - ematch module operations
4751da177e4SLinus Torvalds  *
4761da177e4SLinus Torvalds  * @kind: identifier (kind) of this ematch module
4771da177e4SLinus Torvalds  * @datalen: length of expected configuration data (optional)
4781da177e4SLinus Torvalds  * @change: called during validation (optional)
4791da177e4SLinus Torvalds  * @match: called during ematch tree evaluation, must return 1/0
4801da177e4SLinus Torvalds  * @destroy: called during destroyage (optional)
4811da177e4SLinus Torvalds  * @dump: called during dumping process (optional)
4821da177e4SLinus Torvalds  * @owner: owner, must be set to THIS_MODULE
4831da177e4SLinus Torvalds  * @link: link to previous/next ematch module (internal use)
4841da177e4SLinus Torvalds  */
485fd2c3ef7SEric Dumazet struct tcf_ematch_ops {
4861da177e4SLinus Torvalds 	int			kind;
4871da177e4SLinus Torvalds 	int			datalen;
48882a470f1SJohn Fastabend 	int			(*change)(struct net *net, void *,
4891da177e4SLinus Torvalds 					  int, struct tcf_ematch *);
4901da177e4SLinus Torvalds 	int			(*match)(struct sk_buff *, struct tcf_ematch *,
4911da177e4SLinus Torvalds 					 struct tcf_pkt_info *);
49282a470f1SJohn Fastabend 	void			(*destroy)(struct tcf_ematch *);
4931da177e4SLinus Torvalds 	int			(*dump)(struct sk_buff *, struct tcf_ematch *);
4941da177e4SLinus Torvalds 	struct module		*owner;
4951da177e4SLinus Torvalds 	struct list_head	link;
4961da177e4SLinus Torvalds };
4971da177e4SLinus Torvalds 
4985c15257fSJoe Perches int tcf_em_register(struct tcf_ematch_ops *);
4995c15257fSJoe Perches void tcf_em_unregister(struct tcf_ematch_ops *);
5005c15257fSJoe Perches int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
5011da177e4SLinus Torvalds 			 struct tcf_ematch_tree *);
50282a470f1SJohn Fastabend void tcf_em_tree_destroy(struct tcf_ematch_tree *);
5035c15257fSJoe Perches int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
5045c15257fSJoe Perches int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
5051da177e4SLinus Torvalds 			struct tcf_pkt_info *);
5061da177e4SLinus Torvalds 
5071da177e4SLinus Torvalds /**
5081da177e4SLinus Torvalds  * tcf_em_tree_match - evaulate an ematch tree
5091da177e4SLinus Torvalds  *
5101da177e4SLinus Torvalds  * @skb: socket buffer of the packet in question
5111da177e4SLinus Torvalds  * @tree: ematch tree to be used for evaluation
5121da177e4SLinus Torvalds  * @info: packet information examined by classifier
5131da177e4SLinus Torvalds  *
5141da177e4SLinus Torvalds  * This function matches @skb against the ematch tree in @tree by going
5151da177e4SLinus Torvalds  * through all ematches respecting their logic relations returning
5161da177e4SLinus Torvalds  * as soon as the result is obvious.
5171da177e4SLinus Torvalds  *
5181da177e4SLinus Torvalds  * Returns 1 if the ematch tree as-one matches, no ematches are configured
5191da177e4SLinus Torvalds  * or ematch is not enabled in the kernel, otherwise 0 is returned.
5201da177e4SLinus Torvalds  */
5211da177e4SLinus Torvalds static inline int tcf_em_tree_match(struct sk_buff *skb,
5221da177e4SLinus Torvalds 				    struct tcf_ematch_tree *tree,
5231da177e4SLinus Torvalds 				    struct tcf_pkt_info *info)
5241da177e4SLinus Torvalds {
5251da177e4SLinus Torvalds 	if (tree->hdr.nmatches)
5261da177e4SLinus Torvalds 		return __tcf_em_tree_match(skb, tree, info);
5271da177e4SLinus Torvalds 	else
5281da177e4SLinus Torvalds 		return 1;
5291da177e4SLinus Torvalds }
5301da177e4SLinus Torvalds 
531db3d99c0SPatrick McHardy #define MODULE_ALIAS_TCF_EMATCH(kind)	MODULE_ALIAS("ematch-kind-" __stringify(kind))
532db3d99c0SPatrick McHardy 
5331da177e4SLinus Torvalds #else /* CONFIG_NET_EMATCH */
5341da177e4SLinus Torvalds 
535fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
5361da177e4SLinus Torvalds };
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
53982a470f1SJohn Fastabend #define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
5401da177e4SLinus Torvalds #define tcf_em_tree_dump(skb, t, tlv) (0)
5411da177e4SLinus Torvalds #define tcf_em_tree_match(skb, t, info) ((void)(info), 1)
5421da177e4SLinus Torvalds 
5431da177e4SLinus Torvalds #endif /* CONFIG_NET_EMATCH */
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
5461da177e4SLinus Torvalds {
5471da177e4SLinus Torvalds 	switch (layer) {
5481da177e4SLinus Torvalds 		case TCF_LAYER_LINK:
549d3303a65SWolfgang Bumiller 			return skb_mac_header(skb);
5501da177e4SLinus Torvalds 		case TCF_LAYER_NETWORK:
551d56f90a7SArnaldo Carvalho de Melo 			return skb_network_header(skb);
5521da177e4SLinus Torvalds 		case TCF_LAYER_TRANSPORT:
5539c70220bSArnaldo Carvalho de Melo 			return skb_transport_header(skb);
5541da177e4SLinus Torvalds 	}
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds 	return NULL;
5571da177e4SLinus Torvalds }
5581da177e4SLinus Torvalds 
559eddc9ec5SArnaldo Carvalho de Melo static inline int tcf_valid_offset(const struct sk_buff *skb,
560eddc9ec5SArnaldo Carvalho de Melo 				   const unsigned char *ptr, const int len)
5611da177e4SLinus Torvalds {
562da521b2cSDavid S. Miller 	return likely((ptr + len) <= skb_tail_pointer(skb) &&
563da521b2cSDavid S. Miller 		      ptr >= skb->head &&
564da521b2cSDavid S. Miller 		      (ptr <= (ptr + len)));
5651da177e4SLinus Torvalds }
5661da177e4SLinus Torvalds 
5671da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_IND
5680eeb8ffcSDenis V. Lunev #include <net/net_namespace.h>
5690eeb8ffcSDenis V. Lunev 
5701da177e4SLinus Torvalds static inline int
5711057c55fSAlexander Aring tcf_change_indev(struct net *net, struct nlattr *indev_tlv,
5721057c55fSAlexander Aring 		 struct netlink_ext_ack *extack)
5731da177e4SLinus Torvalds {
5742519a602SWANG Cong 	char indev[IFNAMSIZ];
575c01003c2SPatrick McHardy 	struct net_device *dev;
576c01003c2SPatrick McHardy 
5771057c55fSAlexander Aring 	if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) {
5781057c55fSAlexander Aring 		NL_SET_ERR_MSG(extack, "Interface name too long");
5792519a602SWANG Cong 		return -EINVAL;
5801057c55fSAlexander Aring 	}
5812519a602SWANG Cong 	dev = __dev_get_by_name(net, indev);
5822519a602SWANG Cong 	if (!dev)
5832519a602SWANG Cong 		return -ENODEV;
5842519a602SWANG Cong 	return dev->ifindex;
5851da177e4SLinus Torvalds }
5861da177e4SLinus Torvalds 
5872519a602SWANG Cong static inline bool
5882519a602SWANG Cong tcf_match_indev(struct sk_buff *skb, int ifindex)
5892519a602SWANG Cong {
5902519a602SWANG Cong 	if (!ifindex)
5912519a602SWANG Cong 		return true;
5922519a602SWANG Cong 	if  (!skb->skb_iif)
5932519a602SWANG Cong 		return false;
5942519a602SWANG Cong 	return ifindex == skb->skb_iif;
5951da177e4SLinus Torvalds }
5961da177e4SLinus Torvalds #endif /* CONFIG_NET_CLS_IND */
5971da177e4SLinus Torvalds 
598208c0f4bSJiri Pirko int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts,
599208c0f4bSJiri Pirko 		     enum tc_setup_type type, void *type_data, bool err_stop);
600717503b9SJiri Pirko 
6018c4083b3SJiri Pirko enum tc_block_command {
6028c4083b3SJiri Pirko 	TC_BLOCK_BIND,
6038c4083b3SJiri Pirko 	TC_BLOCK_UNBIND,
6048c4083b3SJiri Pirko };
6058c4083b3SJiri Pirko 
6068c4083b3SJiri Pirko struct tc_block_offload {
6078c4083b3SJiri Pirko 	enum tc_block_command command;
6088c4083b3SJiri Pirko 	enum tcf_block_binder_type binder_type;
6098c4083b3SJiri Pirko 	struct tcf_block *block;
61060513bd8SJohn Hurley 	struct netlink_ext_ack *extack;
6118c4083b3SJiri Pirko };
6128c4083b3SJiri Pirko 
6135fd9fc4eSJiri Pirko struct tc_cls_common_offload {
6145fd9fc4eSJiri Pirko 	u32 chain_index;
6155fd9fc4eSJiri Pirko 	__be16 protocol;
616d7c1c8d2SJiri Pirko 	u32 prio;
6178f0b425aSQuentin Monnet 	struct netlink_ext_ack *extack;
6185fd9fc4eSJiri Pirko };
6195fd9fc4eSJiri Pirko 
620a1b7c5fdSJohn Fastabend struct tc_cls_u32_knode {
621a1b7c5fdSJohn Fastabend 	struct tcf_exts *exts;
622e014860eSJohn Fastabend 	struct tc_u32_sel *sel;
623a1b7c5fdSJohn Fastabend 	u32 handle;
624a1b7c5fdSJohn Fastabend 	u32 val;
625a1b7c5fdSJohn Fastabend 	u32 mask;
626a1b7c5fdSJohn Fastabend 	u32 link_handle;
627e014860eSJohn Fastabend 	u8 fshift;
628a1b7c5fdSJohn Fastabend };
629a1b7c5fdSJohn Fastabend 
630a1b7c5fdSJohn Fastabend struct tc_cls_u32_hnode {
631a1b7c5fdSJohn Fastabend 	u32 handle;
632a1b7c5fdSJohn Fastabend 	u32 prio;
633a1b7c5fdSJohn Fastabend 	unsigned int divisor;
634a1b7c5fdSJohn Fastabend };
635a1b7c5fdSJohn Fastabend 
636a1b7c5fdSJohn Fastabend enum tc_clsu32_command {
637a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_KNODE,
638a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_KNODE,
639a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_KNODE,
640a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_HNODE,
641a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_HNODE,
642a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_HNODE,
643a1b7c5fdSJohn Fastabend };
644a1b7c5fdSJohn Fastabend 
645a1b7c5fdSJohn Fastabend struct tc_cls_u32_offload {
6465fd9fc4eSJiri Pirko 	struct tc_cls_common_offload common;
647a1b7c5fdSJohn Fastabend 	/* knode values */
648a1b7c5fdSJohn Fastabend 	enum tc_clsu32_command command;
649a1b7c5fdSJohn Fastabend 	union {
650a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_knode knode;
651a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_hnode hnode;
652a1b7c5fdSJohn Fastabend 	};
653a1b7c5fdSJohn Fastabend };
654a1b7c5fdSJohn Fastabend 
6557b06e8aeSJiri Pirko static inline bool tc_can_offload(const struct net_device *dev)
6566843e7a2SJohn Fastabend {
65770b5aee4SJiri Pirko 	return dev->features & NETIF_F_HW_TC;
6586843e7a2SJohn Fastabend }
6596843e7a2SJohn Fastabend 
660f9eda14fSQuentin Monnet static inline bool tc_can_offload_extack(const struct net_device *dev,
661f9eda14fSQuentin Monnet 					 struct netlink_ext_ack *extack)
662f9eda14fSQuentin Monnet {
663f9eda14fSQuentin Monnet 	bool can = tc_can_offload(dev);
664f9eda14fSQuentin Monnet 
665f9eda14fSQuentin Monnet 	if (!can)
666f9eda14fSQuentin Monnet 		NL_SET_ERR_MSG(extack, "TC offload is disabled on net device");
667f9eda14fSQuentin Monnet 
668f9eda14fSQuentin Monnet 	return can;
669f9eda14fSQuentin Monnet }
670f9eda14fSQuentin Monnet 
671878db9f0SJakub Kicinski static inline bool
672878db9f0SJakub Kicinski tc_cls_can_offload_and_chain0(const struct net_device *dev,
673878db9f0SJakub Kicinski 			      struct tc_cls_common_offload *common)
674878db9f0SJakub Kicinski {
675878db9f0SJakub Kicinski 	if (!tc_can_offload_extack(dev, common->extack))
676878db9f0SJakub Kicinski 		return false;
677878db9f0SJakub Kicinski 	if (common->chain_index) {
678878db9f0SJakub Kicinski 		NL_SET_ERR_MSG(common->extack,
679878db9f0SJakub Kicinski 			       "Driver supports only offload of chain 0");
680878db9f0SJakub Kicinski 		return false;
681878db9f0SJakub Kicinski 	}
682878db9f0SJakub Kicinski 	return true;
683878db9f0SJakub Kicinski }
684878db9f0SJakub Kicinski 
68555330f05SHadar Hen Zion static inline bool tc_skip_hw(u32 flags)
68655330f05SHadar Hen Zion {
68755330f05SHadar Hen Zion 	return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false;
68855330f05SHadar Hen Zion }
68955330f05SHadar Hen Zion 
690d34e3e18SSamudrala, Sridhar static inline bool tc_skip_sw(u32 flags)
691d34e3e18SSamudrala, Sridhar {
692d34e3e18SSamudrala, Sridhar 	return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false;
693d34e3e18SSamudrala, Sridhar }
694d34e3e18SSamudrala, Sridhar 
695d34e3e18SSamudrala, Sridhar /* SKIP_HW and SKIP_SW are mutually exclusive flags. */
696d34e3e18SSamudrala, Sridhar static inline bool tc_flags_valid(u32 flags)
697d34e3e18SSamudrala, Sridhar {
69881c7288bSMarcelo Ricardo Leitner 	if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW |
69981c7288bSMarcelo Ricardo Leitner 		      TCA_CLS_FLAGS_VERBOSE))
700d34e3e18SSamudrala, Sridhar 		return false;
701d34e3e18SSamudrala, Sridhar 
70281c7288bSMarcelo Ricardo Leitner 	flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW;
703d34e3e18SSamudrala, Sridhar 	if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW)))
704d34e3e18SSamudrala, Sridhar 		return false;
705d34e3e18SSamudrala, Sridhar 
706d34e3e18SSamudrala, Sridhar 	return true;
707d34e3e18SSamudrala, Sridhar }
708d34e3e18SSamudrala, Sridhar 
709e696028aSOr Gerlitz static inline bool tc_in_hw(u32 flags)
710e696028aSOr Gerlitz {
711e696028aSOr Gerlitz 	return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false;
712e696028aSOr Gerlitz }
713e696028aSOr Gerlitz 
71434832e1cSJakub Kicinski static inline void
71534832e1cSJakub Kicinski tc_cls_common_offload_init(struct tc_cls_common_offload *cls_common,
71634832e1cSJakub Kicinski 			   const struct tcf_proto *tp, u32 flags,
71734832e1cSJakub Kicinski 			   struct netlink_ext_ack *extack)
71834832e1cSJakub Kicinski {
71934832e1cSJakub Kicinski 	cls_common->chain_index = tp->chain->index;
72034832e1cSJakub Kicinski 	cls_common->protocol = tp->protocol;
72134832e1cSJakub Kicinski 	cls_common->prio = tp->prio;
72281c7288bSMarcelo Ricardo Leitner 	if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE)
72334832e1cSJakub Kicinski 		cls_common->extack = extack;
72434832e1cSJakub Kicinski }
72534832e1cSJakub Kicinski 
7265b33f488SAmir Vadai enum tc_fl_command {
7275b33f488SAmir Vadai 	TC_CLSFLOWER_REPLACE,
7285b33f488SAmir Vadai 	TC_CLSFLOWER_DESTROY,
72910cbc684SAmir Vadai 	TC_CLSFLOWER_STATS,
73034738452SJiri Pirko 	TC_CLSFLOWER_TMPLT_CREATE,
73134738452SJiri Pirko 	TC_CLSFLOWER_TMPLT_DESTROY,
7325b33f488SAmir Vadai };
7335b33f488SAmir Vadai 
7345b33f488SAmir Vadai struct tc_cls_flower_offload {
7355fd9fc4eSJiri Pirko 	struct tc_cls_common_offload common;
7365b33f488SAmir Vadai 	enum tc_fl_command command;
7378208d21bSAmir Vadai 	unsigned long cookie;
7385b33f488SAmir Vadai 	struct flow_dissector *dissector;
7395b33f488SAmir Vadai 	struct fl_flow_key *mask;
7405b33f488SAmir Vadai 	struct fl_flow_key *key;
7415b33f488SAmir Vadai 	struct tcf_exts *exts;
742384c181eSAmritha Nambiar 	u32 classid;
7435b33f488SAmir Vadai };
7445b33f488SAmir Vadai 
745b87f7936SYotam Gigi enum tc_matchall_command {
746b87f7936SYotam Gigi 	TC_CLSMATCHALL_REPLACE,
747b87f7936SYotam Gigi 	TC_CLSMATCHALL_DESTROY,
748b87f7936SYotam Gigi };
749b87f7936SYotam Gigi 
750b87f7936SYotam Gigi struct tc_cls_matchall_offload {
7515fd9fc4eSJiri Pirko 	struct tc_cls_common_offload common;
752b87f7936SYotam Gigi 	enum tc_matchall_command command;
753b87f7936SYotam Gigi 	struct tcf_exts *exts;
754b87f7936SYotam Gigi 	unsigned long cookie;
755b87f7936SYotam Gigi };
756b87f7936SYotam Gigi 
757332ae8e2SJakub Kicinski enum tc_clsbpf_command {
758102740bdSJakub Kicinski 	TC_CLSBPF_OFFLOAD,
75968d64063SJakub Kicinski 	TC_CLSBPF_STATS,
760332ae8e2SJakub Kicinski };
761332ae8e2SJakub Kicinski 
762332ae8e2SJakub Kicinski struct tc_cls_bpf_offload {
7635fd9fc4eSJiri Pirko 	struct tc_cls_common_offload common;
764332ae8e2SJakub Kicinski 	enum tc_clsbpf_command command;
765332ae8e2SJakub Kicinski 	struct tcf_exts *exts;
766332ae8e2SJakub Kicinski 	struct bpf_prog *prog;
767102740bdSJakub Kicinski 	struct bpf_prog *oldprog;
768332ae8e2SJakub Kicinski 	const char *name;
769332ae8e2SJakub Kicinski 	bool exts_integrated;
770332ae8e2SJakub Kicinski };
771332ae8e2SJakub Kicinski 
7724e8b86c0SAmritha Nambiar struct tc_mqprio_qopt_offload {
7734e8b86c0SAmritha Nambiar 	/* struct tc_mqprio_qopt must always be the first element */
7744e8b86c0SAmritha Nambiar 	struct tc_mqprio_qopt qopt;
7754e8b86c0SAmritha Nambiar 	u16 mode;
7764e8b86c0SAmritha Nambiar 	u16 shaper;
7774e8b86c0SAmritha Nambiar 	u32 flags;
7784e8b86c0SAmritha Nambiar 	u64 min_rate[TC_QOPT_MAX_QUEUE];
7794e8b86c0SAmritha Nambiar 	u64 max_rate[TC_QOPT_MAX_QUEUE];
7804e8b86c0SAmritha Nambiar };
7811045ba77SJamal Hadi Salim 
7821045ba77SJamal Hadi Salim /* This structure holds cookie structure that is passed from user
7831045ba77SJamal Hadi Salim  * to the kernel for actions and classifiers
7841045ba77SJamal Hadi Salim  */
7851045ba77SJamal Hadi Salim struct tc_cookie {
7861045ba77SJamal Hadi Salim 	u8  *data;
7871045ba77SJamal Hadi Salim 	u32 len;
788eec94fdbSVlad Buslov 	struct rcu_head rcu;
7891045ba77SJamal Hadi Salim };
790602f3bafSNogah Frankel 
791f34b4aacSNogah Frankel struct tc_qopt_offload_stats {
792f34b4aacSNogah Frankel 	struct gnet_stats_basic_packed *bstats;
793f34b4aacSNogah Frankel 	struct gnet_stats_queue *qstats;
794f34b4aacSNogah Frankel };
795f34b4aacSNogah Frankel 
796f971b132SJakub Kicinski enum tc_mq_command {
797f971b132SJakub Kicinski 	TC_MQ_CREATE,
798f971b132SJakub Kicinski 	TC_MQ_DESTROY,
79947c669a4SJakub Kicinski 	TC_MQ_STATS,
800f971b132SJakub Kicinski };
801f971b132SJakub Kicinski 
802f971b132SJakub Kicinski struct tc_mq_qopt_offload {
803f971b132SJakub Kicinski 	enum tc_mq_command command;
804f971b132SJakub Kicinski 	u32 handle;
80547c669a4SJakub Kicinski 	struct tc_qopt_offload_stats stats;
806f971b132SJakub Kicinski };
807f971b132SJakub Kicinski 
808602f3bafSNogah Frankel enum tc_red_command {
809602f3bafSNogah Frankel 	TC_RED_REPLACE,
810602f3bafSNogah Frankel 	TC_RED_DESTROY,
811602f3bafSNogah Frankel 	TC_RED_STATS,
812602f3bafSNogah Frankel 	TC_RED_XSTATS,
813602f3bafSNogah Frankel };
814602f3bafSNogah Frankel 
815602f3bafSNogah Frankel struct tc_red_qopt_offload_params {
816602f3bafSNogah Frankel 	u32 min;
817602f3bafSNogah Frankel 	u32 max;
818602f3bafSNogah Frankel 	u32 probability;
819602f3bafSNogah Frankel 	bool is_ecn;
820416ef9b1SJakub Kicinski 	struct gnet_stats_queue *qstats;
821602f3bafSNogah Frankel };
822602f3bafSNogah Frankel 
823602f3bafSNogah Frankel struct tc_red_qopt_offload {
824602f3bafSNogah Frankel 	enum tc_red_command command;
825602f3bafSNogah Frankel 	u32 handle;
826602f3bafSNogah Frankel 	u32 parent;
827602f3bafSNogah Frankel 	union {
828602f3bafSNogah Frankel 		struct tc_red_qopt_offload_params set;
829f34b4aacSNogah Frankel 		struct tc_qopt_offload_stats stats;
830602f3bafSNogah Frankel 		struct red_stats *xstats;
831602f3bafSNogah Frankel 	};
832602f3bafSNogah Frankel };
833602f3bafSNogah Frankel 
8347fdb61b4SNogah Frankel enum tc_prio_command {
8357fdb61b4SNogah Frankel 	TC_PRIO_REPLACE,
8367fdb61b4SNogah Frankel 	TC_PRIO_DESTROY,
8377fdb61b4SNogah Frankel 	TC_PRIO_STATS,
838b9c7a7acSNogah Frankel 	TC_PRIO_GRAFT,
8397fdb61b4SNogah Frankel };
8407fdb61b4SNogah Frankel 
8417fdb61b4SNogah Frankel struct tc_prio_qopt_offload_params {
8427fdb61b4SNogah Frankel 	int bands;
8437fdb61b4SNogah Frankel 	u8 priomap[TC_PRIO_MAX + 1];
8447fdb61b4SNogah Frankel 	/* In case that a prio qdisc is offloaded and now is changed to a
8457fdb61b4SNogah Frankel 	 * non-offloadedable config, it needs to update the backlog & qlen
8467fdb61b4SNogah Frankel 	 * values to negate the HW backlog & qlen values (and only them).
8477fdb61b4SNogah Frankel 	 */
8487fdb61b4SNogah Frankel 	struct gnet_stats_queue *qstats;
8497fdb61b4SNogah Frankel };
8507fdb61b4SNogah Frankel 
851b9c7a7acSNogah Frankel struct tc_prio_qopt_offload_graft_params {
852b9c7a7acSNogah Frankel 	u8 band;
853b9c7a7acSNogah Frankel 	u32 child_handle;
854b9c7a7acSNogah Frankel };
855b9c7a7acSNogah Frankel 
8567fdb61b4SNogah Frankel struct tc_prio_qopt_offload {
8577fdb61b4SNogah Frankel 	enum tc_prio_command command;
8587fdb61b4SNogah Frankel 	u32 handle;
8597fdb61b4SNogah Frankel 	u32 parent;
8607fdb61b4SNogah Frankel 	union {
8617fdb61b4SNogah Frankel 		struct tc_prio_qopt_offload_params replace_params;
8627fdb61b4SNogah Frankel 		struct tc_qopt_offload_stats stats;
863b9c7a7acSNogah Frankel 		struct tc_prio_qopt_offload_graft_params graft_params;
8647fdb61b4SNogah Frankel 	};
8657fdb61b4SNogah Frankel };
866b9c7a7acSNogah Frankel 
8671da177e4SLinus Torvalds #endif
868