xref: /openbmc/linux/include/net/pkt_cls.h (revision 5b33f488)
11da177e4SLinus Torvalds #ifndef __NET_PKT_CLS_H
21da177e4SLinus Torvalds #define __NET_PKT_CLS_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds #include <linux/pkt_cls.h>
51da177e4SLinus Torvalds #include <net/sch_generic.h>
61da177e4SLinus Torvalds #include <net/act_api.h>
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds /* Basic packet classifier frontend definitions. */
91da177e4SLinus Torvalds 
10fd2c3ef7SEric Dumazet struct tcf_walker {
111da177e4SLinus Torvalds 	int	stop;
121da177e4SLinus Torvalds 	int	skip;
131da177e4SLinus Torvalds 	int	count;
141da177e4SLinus Torvalds 	int	(*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
151da177e4SLinus Torvalds };
161da177e4SLinus Torvalds 
175c15257fSJoe Perches int register_tcf_proto_ops(struct tcf_proto_ops *ops);
185c15257fSJoe Perches int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds static inline unsigned long
211da177e4SLinus Torvalds __cls_set_class(unsigned long *clp, unsigned long cl)
221da177e4SLinus Torvalds {
23a0efb80cSWANG Cong 	return xchg(clp, cl);
241da177e4SLinus Torvalds }
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds static inline unsigned long
271da177e4SLinus Torvalds cls_set_class(struct tcf_proto *tp, unsigned long *clp,
281da177e4SLinus Torvalds 	unsigned long cl)
291da177e4SLinus Torvalds {
301da177e4SLinus Torvalds 	unsigned long old_cl;
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds 	tcf_tree_lock(tp);
331da177e4SLinus Torvalds 	old_cl = __cls_set_class(clp, cl);
341da177e4SLinus Torvalds 	tcf_tree_unlock(tp);
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds 	return old_cl;
371da177e4SLinus Torvalds }
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds static inline void
401da177e4SLinus Torvalds tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base)
411da177e4SLinus Torvalds {
421da177e4SLinus Torvalds 	unsigned long cl;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds 	cl = tp->q->ops->cl_ops->bind_tcf(tp->q, base, r->classid);
451da177e4SLinus Torvalds 	cl = cls_set_class(tp, &r->class, cl);
461da177e4SLinus Torvalds 	if (cl)
471da177e4SLinus Torvalds 		tp->q->ops->cl_ops->unbind_tcf(tp->q, cl);
481da177e4SLinus Torvalds }
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds static inline void
511da177e4SLinus Torvalds tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
521da177e4SLinus Torvalds {
531da177e4SLinus Torvalds 	unsigned long cl;
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds 	if ((cl = __cls_set_class(&r->class, 0)) != 0)
561da177e4SLinus Torvalds 		tp->q->ops->cl_ops->unbind_tcf(tp->q, cl);
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds 
59fd2c3ef7SEric Dumazet struct tcf_exts {
601da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
6133be6271SWANG Cong 	__u32	type; /* for backward compat(TCA_OLD_COMPAT) */
6233be6271SWANG Cong 	struct list_head actions;
631da177e4SLinus Torvalds #endif
641da177e4SLinus Torvalds 	/* Map to export classifier specific extension TLV types to the
651da177e4SLinus Torvalds 	 * generic extensions API. Unsupported extensions must be set to 0.
661da177e4SLinus Torvalds 	 */
671da177e4SLinus Torvalds 	int action;
681da177e4SLinus Torvalds 	int police;
691da177e4SLinus Torvalds };
701da177e4SLinus Torvalds 
715da57f42SWANG Cong static inline void tcf_exts_init(struct tcf_exts *exts, int action, int police)
7233be6271SWANG Cong {
7333be6271SWANG Cong #ifdef CONFIG_NET_CLS_ACT
745da57f42SWANG Cong 	exts->type = 0;
7533be6271SWANG Cong 	INIT_LIST_HEAD(&exts->actions);
7633be6271SWANG Cong #endif
775da57f42SWANG Cong 	exts->action = action;
785da57f42SWANG Cong 	exts->police = police;
7933be6271SWANG Cong }
8033be6271SWANG Cong 
811da177e4SLinus Torvalds /**
821da177e4SLinus Torvalds  * tcf_exts_is_predicative - check if a predicative extension is present
831da177e4SLinus Torvalds  * @exts: tc filter extensions handle
841da177e4SLinus Torvalds  *
851da177e4SLinus Torvalds  * Returns 1 if a predicative extension is present, i.e. an extension which
861da177e4SLinus Torvalds  * might cause further actions and thus overrule the regular tcf_result.
871da177e4SLinus Torvalds  */
881da177e4SLinus Torvalds static inline int
891da177e4SLinus Torvalds tcf_exts_is_predicative(struct tcf_exts *exts)
901da177e4SLinus Torvalds {
911da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
9233be6271SWANG Cong 	return !list_empty(&exts->actions);
931da177e4SLinus Torvalds #else
941da177e4SLinus Torvalds 	return 0;
951da177e4SLinus Torvalds #endif
961da177e4SLinus Torvalds }
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds /**
991da177e4SLinus Torvalds  * tcf_exts_is_available - check if at least one extension is present
1001da177e4SLinus Torvalds  * @exts: tc filter extensions handle
1011da177e4SLinus Torvalds  *
1021da177e4SLinus Torvalds  * Returns 1 if at least one extension is present.
1031da177e4SLinus Torvalds  */
1041da177e4SLinus Torvalds static inline int
1051da177e4SLinus Torvalds tcf_exts_is_available(struct tcf_exts *exts)
1061da177e4SLinus Torvalds {
1071da177e4SLinus Torvalds 	/* All non-predicative extensions must be added here. */
1081da177e4SLinus Torvalds 	return tcf_exts_is_predicative(exts);
1091da177e4SLinus Torvalds }
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds /**
1121da177e4SLinus Torvalds  * tcf_exts_exec - execute tc filter extensions
1131da177e4SLinus Torvalds  * @skb: socket buffer
1141da177e4SLinus Torvalds  * @exts: tc filter extensions handle
1151da177e4SLinus Torvalds  * @res: desired result
1161da177e4SLinus Torvalds  *
1171da177e4SLinus Torvalds  * Executes all configured extensions. Returns 0 on a normal execution,
1181da177e4SLinus Torvalds  * a negative number if the filter must be considered unmatched or
1191da177e4SLinus Torvalds  * a positive action code (TC_ACT_*) which must be returned to the
1201da177e4SLinus Torvalds  * underlying layer.
1211da177e4SLinus Torvalds  */
1221da177e4SLinus Torvalds static inline int
1231da177e4SLinus Torvalds tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
1241da177e4SLinus Torvalds 	       struct tcf_result *res)
1251da177e4SLinus Torvalds {
1261da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
12733be6271SWANG Cong 	if (!list_empty(&exts->actions))
12833be6271SWANG Cong 		return tcf_action_exec(skb, &exts->actions, res);
1291da177e4SLinus Torvalds #endif
1301da177e4SLinus Torvalds 	return 0;
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds 
1335c15257fSJoe Perches int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
134c1b52739SBenjamin LaHaise 		      struct nlattr **tb, struct nlattr *rate_tlv,
1352f7ef2f8SCong Wang 		      struct tcf_exts *exts, bool ovr);
13618d0264fSWANG Cong void tcf_exts_destroy(struct tcf_exts *exts);
1375c15257fSJoe Perches void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
1381da177e4SLinus Torvalds 		     struct tcf_exts *src);
1395da57f42SWANG Cong int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
1405da57f42SWANG Cong int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds /**
1431da177e4SLinus Torvalds  * struct tcf_pkt_info - packet information
1441da177e4SLinus Torvalds  */
145fd2c3ef7SEric Dumazet struct tcf_pkt_info {
1461da177e4SLinus Torvalds 	unsigned char *		ptr;
1471da177e4SLinus Torvalds 	int			nexthdr;
1481da177e4SLinus Torvalds };
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds #ifdef CONFIG_NET_EMATCH
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds struct tcf_ematch_ops;
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds /**
1551da177e4SLinus Torvalds  * struct tcf_ematch - extended match (ematch)
1561da177e4SLinus Torvalds  *
1571da177e4SLinus Torvalds  * @matchid: identifier to allow userspace to reidentify a match
1581da177e4SLinus Torvalds  * @flags: flags specifying attributes and the relation to other matches
1591da177e4SLinus Torvalds  * @ops: the operations lookup table of the corresponding ematch module
1601da177e4SLinus Torvalds  * @datalen: length of the ematch specific configuration data
1611da177e4SLinus Torvalds  * @data: ematch specific data
1621da177e4SLinus Torvalds  */
163fd2c3ef7SEric Dumazet struct tcf_ematch {
1641da177e4SLinus Torvalds 	struct tcf_ematch_ops * ops;
1651da177e4SLinus Torvalds 	unsigned long		data;
1661da177e4SLinus Torvalds 	unsigned int		datalen;
1671da177e4SLinus Torvalds 	u16			matchid;
1681da177e4SLinus Torvalds 	u16			flags;
16982a470f1SJohn Fastabend 	struct net		*net;
1701da177e4SLinus Torvalds };
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds static inline int tcf_em_is_container(struct tcf_ematch *em)
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds 	return !em->ops;
1751da177e4SLinus Torvalds }
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds static inline int tcf_em_is_simple(struct tcf_ematch *em)
1781da177e4SLinus Torvalds {
1791da177e4SLinus Torvalds 	return em->flags & TCF_EM_SIMPLE;
1801da177e4SLinus Torvalds }
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds static inline int tcf_em_is_inverted(struct tcf_ematch *em)
1831da177e4SLinus Torvalds {
1841da177e4SLinus Torvalds 	return em->flags & TCF_EM_INVERT;
1851da177e4SLinus Torvalds }
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds static inline int tcf_em_last_match(struct tcf_ematch *em)
1881da177e4SLinus Torvalds {
1891da177e4SLinus Torvalds 	return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END;
1901da177e4SLinus Torvalds }
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds static inline int tcf_em_early_end(struct tcf_ematch *em, int result)
1931da177e4SLinus Torvalds {
1941da177e4SLinus Torvalds 	if (tcf_em_last_match(em))
1951da177e4SLinus Torvalds 		return 1;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	if (result == 0 && em->flags & TCF_EM_REL_AND)
1981da177e4SLinus Torvalds 		return 1;
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 	if (result != 0 && em->flags & TCF_EM_REL_OR)
2011da177e4SLinus Torvalds 		return 1;
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 	return 0;
2041da177e4SLinus Torvalds }
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds /**
2071da177e4SLinus Torvalds  * struct tcf_ematch_tree - ematch tree handle
2081da177e4SLinus Torvalds  *
2091da177e4SLinus Torvalds  * @hdr: ematch tree header supplied by userspace
2101da177e4SLinus Torvalds  * @matches: array of ematches
2111da177e4SLinus Torvalds  */
212fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
2131da177e4SLinus Torvalds 	struct tcf_ematch_tree_hdr hdr;
2141da177e4SLinus Torvalds 	struct tcf_ematch *	matches;
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds };
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds /**
2191da177e4SLinus Torvalds  * struct tcf_ematch_ops - ematch module operations
2201da177e4SLinus Torvalds  *
2211da177e4SLinus Torvalds  * @kind: identifier (kind) of this ematch module
2221da177e4SLinus Torvalds  * @datalen: length of expected configuration data (optional)
2231da177e4SLinus Torvalds  * @change: called during validation (optional)
2241da177e4SLinus Torvalds  * @match: called during ematch tree evaluation, must return 1/0
2251da177e4SLinus Torvalds  * @destroy: called during destroyage (optional)
2261da177e4SLinus Torvalds  * @dump: called during dumping process (optional)
2271da177e4SLinus Torvalds  * @owner: owner, must be set to THIS_MODULE
2281da177e4SLinus Torvalds  * @link: link to previous/next ematch module (internal use)
2291da177e4SLinus Torvalds  */
230fd2c3ef7SEric Dumazet struct tcf_ematch_ops {
2311da177e4SLinus Torvalds 	int			kind;
2321da177e4SLinus Torvalds 	int			datalen;
23382a470f1SJohn Fastabend 	int			(*change)(struct net *net, void *,
2341da177e4SLinus Torvalds 					  int, struct tcf_ematch *);
2351da177e4SLinus Torvalds 	int			(*match)(struct sk_buff *, struct tcf_ematch *,
2361da177e4SLinus Torvalds 					 struct tcf_pkt_info *);
23782a470f1SJohn Fastabend 	void			(*destroy)(struct tcf_ematch *);
2381da177e4SLinus Torvalds 	int			(*dump)(struct sk_buff *, struct tcf_ematch *);
2391da177e4SLinus Torvalds 	struct module		*owner;
2401da177e4SLinus Torvalds 	struct list_head	link;
2411da177e4SLinus Torvalds };
2421da177e4SLinus Torvalds 
2435c15257fSJoe Perches int tcf_em_register(struct tcf_ematch_ops *);
2445c15257fSJoe Perches void tcf_em_unregister(struct tcf_ematch_ops *);
2455c15257fSJoe Perches int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
2461da177e4SLinus Torvalds 			 struct tcf_ematch_tree *);
24782a470f1SJohn Fastabend void tcf_em_tree_destroy(struct tcf_ematch_tree *);
2485c15257fSJoe Perches int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
2495c15257fSJoe Perches int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
2501da177e4SLinus Torvalds 			struct tcf_pkt_info *);
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds /**
2531da177e4SLinus Torvalds  * tcf_em_tree_change - replace ematch tree of a running classifier
2541da177e4SLinus Torvalds  *
2551da177e4SLinus Torvalds  * @tp: classifier kind handle
2561da177e4SLinus Torvalds  * @dst: destination ematch tree variable
2571da177e4SLinus Torvalds  * @src: source ematch tree (temporary tree from tcf_em_tree_validate)
2581da177e4SLinus Torvalds  *
2591da177e4SLinus Torvalds  * This functions replaces the ematch tree in @dst with the ematch
2601da177e4SLinus Torvalds  * tree in @src. The classifier in charge of the ematch tree may be
2611da177e4SLinus Torvalds  * running.
2621da177e4SLinus Torvalds  */
2631da177e4SLinus Torvalds static inline void tcf_em_tree_change(struct tcf_proto *tp,
2641da177e4SLinus Torvalds 				      struct tcf_ematch_tree *dst,
2651da177e4SLinus Torvalds 				      struct tcf_ematch_tree *src)
2661da177e4SLinus Torvalds {
2671da177e4SLinus Torvalds 	tcf_tree_lock(tp);
2681da177e4SLinus Torvalds 	memcpy(dst, src, sizeof(*dst));
2691da177e4SLinus Torvalds 	tcf_tree_unlock(tp);
2701da177e4SLinus Torvalds }
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds /**
2731da177e4SLinus Torvalds  * tcf_em_tree_match - evaulate an ematch tree
2741da177e4SLinus Torvalds  *
2751da177e4SLinus Torvalds  * @skb: socket buffer of the packet in question
2761da177e4SLinus Torvalds  * @tree: ematch tree to be used for evaluation
2771da177e4SLinus Torvalds  * @info: packet information examined by classifier
2781da177e4SLinus Torvalds  *
2791da177e4SLinus Torvalds  * This function matches @skb against the ematch tree in @tree by going
2801da177e4SLinus Torvalds  * through all ematches respecting their logic relations returning
2811da177e4SLinus Torvalds  * as soon as the result is obvious.
2821da177e4SLinus Torvalds  *
2831da177e4SLinus Torvalds  * Returns 1 if the ematch tree as-one matches, no ematches are configured
2841da177e4SLinus Torvalds  * or ematch is not enabled in the kernel, otherwise 0 is returned.
2851da177e4SLinus Torvalds  */
2861da177e4SLinus Torvalds static inline int tcf_em_tree_match(struct sk_buff *skb,
2871da177e4SLinus Torvalds 				    struct tcf_ematch_tree *tree,
2881da177e4SLinus Torvalds 				    struct tcf_pkt_info *info)
2891da177e4SLinus Torvalds {
2901da177e4SLinus Torvalds 	if (tree->hdr.nmatches)
2911da177e4SLinus Torvalds 		return __tcf_em_tree_match(skb, tree, info);
2921da177e4SLinus Torvalds 	else
2931da177e4SLinus Torvalds 		return 1;
2941da177e4SLinus Torvalds }
2951da177e4SLinus Torvalds 
296db3d99c0SPatrick McHardy #define MODULE_ALIAS_TCF_EMATCH(kind)	MODULE_ALIAS("ematch-kind-" __stringify(kind))
297db3d99c0SPatrick McHardy 
2981da177e4SLinus Torvalds #else /* CONFIG_NET_EMATCH */
2991da177e4SLinus Torvalds 
300fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
3011da177e4SLinus Torvalds };
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
30482a470f1SJohn Fastabend #define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
3051da177e4SLinus Torvalds #define tcf_em_tree_dump(skb, t, tlv) (0)
3061da177e4SLinus Torvalds #define tcf_em_tree_change(tp, dst, src) do { } while(0)
3071da177e4SLinus Torvalds #define tcf_em_tree_match(skb, t, info) ((void)(info), 1)
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds #endif /* CONFIG_NET_EMATCH */
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	switch (layer) {
3141da177e4SLinus Torvalds 		case TCF_LAYER_LINK:
3151da177e4SLinus Torvalds 			return skb->data;
3161da177e4SLinus Torvalds 		case TCF_LAYER_NETWORK:
317d56f90a7SArnaldo Carvalho de Melo 			return skb_network_header(skb);
3181da177e4SLinus Torvalds 		case TCF_LAYER_TRANSPORT:
3199c70220bSArnaldo Carvalho de Melo 			return skb_transport_header(skb);
3201da177e4SLinus Torvalds 	}
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	return NULL;
3231da177e4SLinus Torvalds }
3241da177e4SLinus Torvalds 
325eddc9ec5SArnaldo Carvalho de Melo static inline int tcf_valid_offset(const struct sk_buff *skb,
326eddc9ec5SArnaldo Carvalho de Melo 				   const unsigned char *ptr, const int len)
3271da177e4SLinus Torvalds {
328da521b2cSDavid S. Miller 	return likely((ptr + len) <= skb_tail_pointer(skb) &&
329da521b2cSDavid S. Miller 		      ptr >= skb->head &&
330da521b2cSDavid S. Miller 		      (ptr <= (ptr + len)));
3311da177e4SLinus Torvalds }
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_IND
3340eeb8ffcSDenis V. Lunev #include <net/net_namespace.h>
3350eeb8ffcSDenis V. Lunev 
3361da177e4SLinus Torvalds static inline int
3372519a602SWANG Cong tcf_change_indev(struct net *net, struct nlattr *indev_tlv)
3381da177e4SLinus Torvalds {
3392519a602SWANG Cong 	char indev[IFNAMSIZ];
340c01003c2SPatrick McHardy 	struct net_device *dev;
341c01003c2SPatrick McHardy 
3422519a602SWANG Cong 	if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ)
3432519a602SWANG Cong 		return -EINVAL;
3442519a602SWANG Cong 	dev = __dev_get_by_name(net, indev);
3452519a602SWANG Cong 	if (!dev)
3462519a602SWANG Cong 		return -ENODEV;
3472519a602SWANG Cong 	return dev->ifindex;
3481da177e4SLinus Torvalds }
3491da177e4SLinus Torvalds 
3502519a602SWANG Cong static inline bool
3512519a602SWANG Cong tcf_match_indev(struct sk_buff *skb, int ifindex)
3522519a602SWANG Cong {
3532519a602SWANG Cong 	if (!ifindex)
3542519a602SWANG Cong 		return true;
3552519a602SWANG Cong 	if  (!skb->skb_iif)
3562519a602SWANG Cong 		return false;
3572519a602SWANG Cong 	return ifindex == skb->skb_iif;
3581da177e4SLinus Torvalds }
3591da177e4SLinus Torvalds #endif /* CONFIG_NET_CLS_IND */
3601da177e4SLinus Torvalds 
361a1b7c5fdSJohn Fastabend struct tc_cls_u32_knode {
362a1b7c5fdSJohn Fastabend 	struct tcf_exts *exts;
363e014860eSJohn Fastabend 	struct tc_u32_sel *sel;
364a1b7c5fdSJohn Fastabend 	u32 handle;
365a1b7c5fdSJohn Fastabend 	u32 val;
366a1b7c5fdSJohn Fastabend 	u32 mask;
367a1b7c5fdSJohn Fastabend 	u32 link_handle;
368e014860eSJohn Fastabend 	u8 fshift;
369a1b7c5fdSJohn Fastabend };
370a1b7c5fdSJohn Fastabend 
371a1b7c5fdSJohn Fastabend struct tc_cls_u32_hnode {
372a1b7c5fdSJohn Fastabend 	u32 handle;
373a1b7c5fdSJohn Fastabend 	u32 prio;
374a1b7c5fdSJohn Fastabend 	unsigned int divisor;
375a1b7c5fdSJohn Fastabend };
376a1b7c5fdSJohn Fastabend 
377a1b7c5fdSJohn Fastabend enum tc_clsu32_command {
378a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_KNODE,
379a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_KNODE,
380a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_KNODE,
381a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_HNODE,
382a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_HNODE,
383a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_HNODE,
384a1b7c5fdSJohn Fastabend };
385a1b7c5fdSJohn Fastabend 
386a1b7c5fdSJohn Fastabend struct tc_cls_u32_offload {
387a1b7c5fdSJohn Fastabend 	/* knode values */
388a1b7c5fdSJohn Fastabend 	enum tc_clsu32_command command;
389a1b7c5fdSJohn Fastabend 	union {
390a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_knode knode;
391a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_hnode hnode;
392a1b7c5fdSJohn Fastabend 	};
393a1b7c5fdSJohn Fastabend };
394a1b7c5fdSJohn Fastabend 
3959e8ce79cSJohn Fastabend /* tca flags definitions */
3969e8ce79cSJohn Fastabend #define TCA_CLS_FLAGS_SKIP_HW 1
3979e8ce79cSJohn Fastabend 
3989e8ce79cSJohn Fastabend static inline bool tc_should_offload(struct net_device *dev, u32 flags)
3996843e7a2SJohn Fastabend {
4002b6ab0d3SJohn Fastabend 	if (!(dev->features & NETIF_F_HW_TC))
4012b6ab0d3SJohn Fastabend 		return false;
4022b6ab0d3SJohn Fastabend 
4039e8ce79cSJohn Fastabend 	if (flags & TCA_CLS_FLAGS_SKIP_HW)
4049e8ce79cSJohn Fastabend 		return false;
4059e8ce79cSJohn Fastabend 
4069e8ce79cSJohn Fastabend 	if (!dev->netdev_ops->ndo_setup_tc)
4079e8ce79cSJohn Fastabend 		return false;
4089e8ce79cSJohn Fastabend 
4099e8ce79cSJohn Fastabend 	return true;
4106843e7a2SJohn Fastabend }
4116843e7a2SJohn Fastabend 
4125b33f488SAmir Vadai enum tc_fl_command {
4135b33f488SAmir Vadai 	TC_CLSFLOWER_REPLACE,
4145b33f488SAmir Vadai 	TC_CLSFLOWER_DESTROY,
4155b33f488SAmir Vadai };
4165b33f488SAmir Vadai 
4175b33f488SAmir Vadai struct tc_cls_flower_offload {
4185b33f488SAmir Vadai 	enum tc_fl_command command;
4195b33f488SAmir Vadai 	u64 cookie;
4205b33f488SAmir Vadai 	struct flow_dissector *dissector;
4215b33f488SAmir Vadai 	struct fl_flow_key *mask;
4225b33f488SAmir Vadai 	struct fl_flow_key *key;
4235b33f488SAmir Vadai 	struct tcf_exts *exts;
4245b33f488SAmir Vadai };
4255b33f488SAmir Vadai 
4261da177e4SLinus Torvalds #endif
427