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> 98f256622SPablo Neira Ayuso #include <net/flow_offload.h> 101da177e4SLinus Torvalds 11cd11b164SPaolo Abeni /* TC action not accessible from user space */ 12cd11b164SPaolo Abeni #define TC_ACT_REINSERT (TC_ACT_VALUE_MAX + 1) 13cd11b164SPaolo Abeni 141da177e4SLinus Torvalds /* Basic packet classifier frontend definitions. */ 151da177e4SLinus Torvalds 16fd2c3ef7SEric Dumazet struct tcf_walker { 171da177e4SLinus Torvalds int stop; 181da177e4SLinus Torvalds int skip; 191da177e4SLinus Torvalds int count; 206676d5e4SVlad Buslov bool nonempty; 2101683a14SVlad Buslov unsigned long cookie; 228113c095SWANG Cong int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *); 231da177e4SLinus Torvalds }; 241da177e4SLinus Torvalds 255c15257fSJoe Perches int register_tcf_proto_ops(struct tcf_proto_ops *ops); 265c15257fSJoe Perches int unregister_tcf_proto_ops(struct tcf_proto_ops *ops); 271da177e4SLinus Torvalds 288c4083b3SJiri Pirko enum tcf_block_binder_type { 298c4083b3SJiri Pirko TCF_BLOCK_BINDER_TYPE_UNSPEC, 306e40cf2dSJiri Pirko TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS, 316e40cf2dSJiri Pirko TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS, 328c4083b3SJiri Pirko }; 338c4083b3SJiri Pirko 348c4083b3SJiri Pirko struct tcf_block_ext_info { 358c4083b3SJiri Pirko enum tcf_block_binder_type binder_type; 36c7eb7d72SJiri Pirko tcf_chain_head_change_t *chain_head_change; 37c7eb7d72SJiri Pirko void *chain_head_change_priv; 3848617387SJiri Pirko u32 block_index; 398c4083b3SJiri Pirko }; 408c4083b3SJiri Pirko 41acb67442SJiri Pirko struct tcf_block_cb; 42aaa908ffSCong Wang bool tcf_queue_work(struct rcu_work *rwork, work_func_t func); 43acb67442SJiri Pirko 448ae70032SJiri Pirko #ifdef CONFIG_NET_CLS 451f3ed383SJiri Pirko struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block, 461f3ed383SJiri Pirko u32 chain_index); 471f3ed383SJiri Pirko void tcf_chain_put_by_act(struct tcf_chain *chain); 48bbf73830SVlad Buslov struct tcf_chain *tcf_get_next_chain(struct tcf_block *block, 49bbf73830SVlad Buslov struct tcf_chain *chain); 50fe2923afSVlad Buslov struct tcf_proto *tcf_get_next_proto(struct tcf_chain *chain, 5112db03b6SVlad Buslov struct tcf_proto *tp, bool rtnl_held); 52f36fe1c4SJiri Pirko void tcf_block_netif_keep_dst(struct tcf_block *block); 536529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block, 548d1a77f9SAlexander Aring struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, 558d1a77f9SAlexander Aring struct netlink_ext_ack *extack); 56c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, 578d1a77f9SAlexander Aring struct tcf_block_ext_info *ei, 588d1a77f9SAlexander Aring struct netlink_ext_ack *extack); 596529eabaSJiri Pirko void tcf_block_put(struct tcf_block *block); 60c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, 618c4083b3SJiri Pirko struct tcf_block_ext_info *ei); 6244186460SJiri Pirko 6348617387SJiri Pirko static inline bool tcf_block_shared(struct tcf_block *block) 6448617387SJiri Pirko { 6548617387SJiri Pirko return block->index; 6648617387SJiri Pirko } 6748617387SJiri Pirko 6844186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block) 6944186460SJiri Pirko { 7048617387SJiri Pirko WARN_ON(tcf_block_shared(block)); 7144186460SJiri Pirko return block->q; 7244186460SJiri Pirko } 7344186460SJiri Pirko 74acb67442SJiri Pirko void *tcf_block_cb_priv(struct tcf_block_cb *block_cb); 75acb67442SJiri Pirko struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, 76acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident); 77acb67442SJiri Pirko void tcf_block_cb_incref(struct tcf_block_cb *block_cb); 78acb67442SJiri Pirko unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb); 79acb67442SJiri Pirko struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, 80acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident, 8160513bd8SJohn Hurley void *cb_priv, 8260513bd8SJohn Hurley struct netlink_ext_ack *extack); 83acb67442SJiri Pirko int tcf_block_cb_register(struct tcf_block *block, 84acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident, 8560513bd8SJohn Hurley void *cb_priv, struct netlink_ext_ack *extack); 8632636742SJohn Hurley void __tcf_block_cb_unregister(struct tcf_block *block, 8732636742SJohn Hurley struct tcf_block_cb *block_cb); 88acb67442SJiri Pirko void tcf_block_cb_unregister(struct tcf_block *block, 89acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident); 907f76fa36SJohn Hurley int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, 917f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident); 927f76fa36SJohn Hurley int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, 937f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident); 947f76fa36SJohn Hurley void __tc_indr_block_cb_unregister(struct net_device *dev, 957f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident); 967f76fa36SJohn Hurley void tc_indr_block_cb_unregister(struct net_device *dev, 977f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident); 98acb67442SJiri Pirko 9987d83093SJiri Pirko int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, 10087d83093SJiri Pirko struct tcf_result *res, bool compat_mode); 10187d83093SJiri Pirko 1028ae70032SJiri Pirko #else 1036529eabaSJiri Pirko static inline 1046529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block, 1053c149091SSudip Mukherjee struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, 1063c149091SSudip Mukherjee struct netlink_ext_ack *extack) 1076529eabaSJiri Pirko { 1086529eabaSJiri Pirko return 0; 1096529eabaSJiri Pirko } 1106529eabaSJiri Pirko 1118c4083b3SJiri Pirko static inline 112c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, 11333c30a8bSQuentin Monnet struct tcf_block_ext_info *ei, 11433c30a8bSQuentin Monnet struct netlink_ext_ack *extack) 1158c4083b3SJiri Pirko { 1168c4083b3SJiri Pirko return 0; 1178c4083b3SJiri Pirko } 1188c4083b3SJiri Pirko 1196529eabaSJiri Pirko static inline void tcf_block_put(struct tcf_block *block) 1208ae70032SJiri Pirko { 1218ae70032SJiri Pirko } 12287d83093SJiri Pirko 1238c4083b3SJiri Pirko static inline 124c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, 1258c4083b3SJiri Pirko struct tcf_block_ext_info *ei) 1268c4083b3SJiri Pirko { 1278c4083b3SJiri Pirko } 1288c4083b3SJiri Pirko 12944186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block) 13044186460SJiri Pirko { 13144186460SJiri Pirko return NULL; 13244186460SJiri Pirko } 13344186460SJiri Pirko 134acb67442SJiri Pirko static inline 135acb67442SJiri Pirko int tc_setup_cb_block_register(struct tcf_block *block, tc_setup_cb_t *cb, 136acb67442SJiri Pirko void *cb_priv) 137acb67442SJiri Pirko { 138acb67442SJiri Pirko return 0; 139acb67442SJiri Pirko } 140acb67442SJiri Pirko 141acb67442SJiri Pirko static inline 142acb67442SJiri Pirko void tc_setup_cb_block_unregister(struct tcf_block *block, tc_setup_cb_t *cb, 143acb67442SJiri Pirko void *cb_priv) 144acb67442SJiri Pirko { 145acb67442SJiri Pirko } 146acb67442SJiri Pirko 147acb67442SJiri Pirko static inline 148acb67442SJiri Pirko void *tcf_block_cb_priv(struct tcf_block_cb *block_cb) 149acb67442SJiri Pirko { 150acb67442SJiri Pirko return NULL; 151acb67442SJiri Pirko } 152acb67442SJiri Pirko 153acb67442SJiri Pirko static inline 154acb67442SJiri Pirko struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, 155acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident) 156acb67442SJiri Pirko { 157acb67442SJiri Pirko return NULL; 158acb67442SJiri Pirko } 159acb67442SJiri Pirko 160acb67442SJiri Pirko static inline 161acb67442SJiri Pirko void tcf_block_cb_incref(struct tcf_block_cb *block_cb) 162acb67442SJiri Pirko { 163acb67442SJiri Pirko } 164acb67442SJiri Pirko 165acb67442SJiri Pirko static inline 166acb67442SJiri Pirko unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb) 167acb67442SJiri Pirko { 168acb67442SJiri Pirko return 0; 169acb67442SJiri Pirko } 170acb67442SJiri Pirko 171acb67442SJiri Pirko static inline 172acb67442SJiri Pirko struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, 173acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident, 17460513bd8SJohn Hurley void *cb_priv, 17560513bd8SJohn Hurley struct netlink_ext_ack *extack) 176acb67442SJiri Pirko { 177acb67442SJiri Pirko return NULL; 178acb67442SJiri Pirko } 179acb67442SJiri Pirko 180acb67442SJiri Pirko static inline 181acb67442SJiri Pirko int tcf_block_cb_register(struct tcf_block *block, 182acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident, 18360513bd8SJohn Hurley void *cb_priv, struct netlink_ext_ack *extack) 184acb67442SJiri Pirko { 185acb67442SJiri Pirko return 0; 186acb67442SJiri Pirko } 187acb67442SJiri Pirko 188acb67442SJiri Pirko static inline 18932636742SJohn Hurley void __tcf_block_cb_unregister(struct tcf_block *block, 19032636742SJohn Hurley struct tcf_block_cb *block_cb) 191acb67442SJiri Pirko { 192acb67442SJiri Pirko } 193acb67442SJiri Pirko 194acb67442SJiri Pirko static inline 195acb67442SJiri Pirko void tcf_block_cb_unregister(struct tcf_block *block, 196acb67442SJiri Pirko tc_setup_cb_t *cb, void *cb_ident) 197acb67442SJiri Pirko { 198acb67442SJiri Pirko } 199acb67442SJiri Pirko 2007f76fa36SJohn Hurley static inline 2017f76fa36SJohn Hurley int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, 2027f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident) 2037f76fa36SJohn Hurley { 2047f76fa36SJohn Hurley return 0; 2057f76fa36SJohn Hurley } 2067f76fa36SJohn Hurley 2077f76fa36SJohn Hurley static inline 2087f76fa36SJohn Hurley int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, 2097f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident) 2107f76fa36SJohn Hurley { 2117f76fa36SJohn Hurley return 0; 2127f76fa36SJohn Hurley } 2137f76fa36SJohn Hurley 2147f76fa36SJohn Hurley static inline 2157f76fa36SJohn Hurley void __tc_indr_block_cb_unregister(struct net_device *dev, 2167f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident) 2177f76fa36SJohn Hurley { 2187f76fa36SJohn Hurley } 2197f76fa36SJohn Hurley 2207f76fa36SJohn Hurley static inline 2217f76fa36SJohn Hurley void tc_indr_block_cb_unregister(struct net_device *dev, 2227f76fa36SJohn Hurley tc_indr_block_bind_cb_t *cb, void *cb_ident) 2237f76fa36SJohn Hurley { 2247f76fa36SJohn Hurley } 2257f76fa36SJohn Hurley 22687d83093SJiri Pirko static inline int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, 22787d83093SJiri Pirko struct tcf_result *res, bool compat_mode) 22887d83093SJiri Pirko { 22987d83093SJiri Pirko return TC_ACT_UNSPEC; 23087d83093SJiri Pirko } 2318ae70032SJiri Pirko #endif 232cf1facdaSJiri Pirko 2331da177e4SLinus Torvalds static inline unsigned long 2341da177e4SLinus Torvalds __cls_set_class(unsigned long *clp, unsigned long cl) 2351da177e4SLinus Torvalds { 236a0efb80cSWANG Cong return xchg(clp, cl); 2371da177e4SLinus Torvalds } 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds static inline unsigned long 24034e3759cSJiri Pirko cls_set_class(struct Qdisc *q, unsigned long *clp, unsigned long cl) 2411da177e4SLinus Torvalds { 2421da177e4SLinus Torvalds unsigned long old_cl; 2431da177e4SLinus Torvalds 24434e3759cSJiri Pirko sch_tree_lock(q); 2451da177e4SLinus Torvalds old_cl = __cls_set_class(clp, cl); 24634e3759cSJiri Pirko sch_tree_unlock(q); 2471da177e4SLinus Torvalds return old_cl; 2481da177e4SLinus Torvalds } 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds static inline void 2511da177e4SLinus Torvalds tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base) 2521da177e4SLinus Torvalds { 25334e3759cSJiri Pirko struct Qdisc *q = tp->chain->block->q; 2541da177e4SLinus Torvalds unsigned long cl; 2551da177e4SLinus Torvalds 25634e3759cSJiri Pirko /* Check q as it is not set for shared blocks. In that case, 25734e3759cSJiri Pirko * setting class is not supported. 25834e3759cSJiri Pirko */ 25934e3759cSJiri Pirko if (!q) 26034e3759cSJiri Pirko return; 26134e3759cSJiri Pirko cl = q->ops->cl_ops->bind_tcf(q, base, r->classid); 26234e3759cSJiri Pirko cl = cls_set_class(q, &r->class, cl); 2631da177e4SLinus Torvalds if (cl) 26434e3759cSJiri Pirko q->ops->cl_ops->unbind_tcf(q, cl); 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds static inline void 2681da177e4SLinus Torvalds tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r) 2691da177e4SLinus Torvalds { 27034e3759cSJiri Pirko struct Qdisc *q = tp->chain->block->q; 2711da177e4SLinus Torvalds unsigned long cl; 2721da177e4SLinus Torvalds 27334e3759cSJiri Pirko if (!q) 27434e3759cSJiri Pirko return; 2751da177e4SLinus Torvalds if ((cl = __cls_set_class(&r->class, 0)) != 0) 27634e3759cSJiri Pirko q->ops->cl_ops->unbind_tcf(q, cl); 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds 279fd2c3ef7SEric Dumazet struct tcf_exts { 2801da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT 28133be6271SWANG Cong __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ 28222dc13c8SWANG Cong int nr_actions; 28322dc13c8SWANG Cong struct tc_action **actions; 284e4b95c41SCong Wang struct net *net; 2851da177e4SLinus Torvalds #endif 2861da177e4SLinus Torvalds /* Map to export classifier specific extension TLV types to the 2871da177e4SLinus Torvalds * generic extensions API. Unsupported extensions must be set to 0. 2881da177e4SLinus Torvalds */ 2891da177e4SLinus Torvalds int action; 2901da177e4SLinus Torvalds int police; 2911da177e4SLinus Torvalds }; 2921da177e4SLinus Torvalds 29314215108SCong Wang static inline int tcf_exts_init(struct tcf_exts *exts, struct net *net, 29414215108SCong Wang int action, int police) 29533be6271SWANG Cong { 29633be6271SWANG Cong #ifdef CONFIG_NET_CLS_ACT 2975da57f42SWANG Cong exts->type = 0; 29822dc13c8SWANG Cong exts->nr_actions = 0; 29914215108SCong Wang exts->net = net; 30022dc13c8SWANG Cong exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *), 30122dc13c8SWANG Cong GFP_KERNEL); 302b9a24bb7SWANG Cong if (!exts->actions) 303b9a24bb7SWANG Cong return -ENOMEM; 30433be6271SWANG Cong #endif 3055da57f42SWANG Cong exts->action = action; 3065da57f42SWANG Cong exts->police = police; 307b9a24bb7SWANG Cong return 0; 30833be6271SWANG Cong } 30933be6271SWANG Cong 310e4b95c41SCong Wang /* Return false if the netns is being destroyed in cleanup_net(). Callers 311e4b95c41SCong Wang * need to do cleanup synchronously in this case, otherwise may race with 312e4b95c41SCong Wang * tc_action_net_exit(). Return true for other cases. 313e4b95c41SCong Wang */ 314e4b95c41SCong Wang static inline bool tcf_exts_get_net(struct tcf_exts *exts) 315e4b95c41SCong Wang { 316e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT 317e4b95c41SCong Wang exts->net = maybe_get_net(exts->net); 318e4b95c41SCong Wang return exts->net != NULL; 319e4b95c41SCong Wang #else 320e4b95c41SCong Wang return true; 321e4b95c41SCong Wang #endif 322e4b95c41SCong Wang } 323e4b95c41SCong Wang 324e4b95c41SCong Wang static inline void tcf_exts_put_net(struct tcf_exts *exts) 325e4b95c41SCong Wang { 326e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT 327e4b95c41SCong Wang if (exts->net) 328e4b95c41SCong Wang put_net(exts->net); 329e4b95c41SCong Wang #endif 330e4b95c41SCong Wang } 331e4b95c41SCong Wang 33222dc13c8SWANG Cong #ifdef CONFIG_NET_CLS_ACT 333244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \ 334244cd96aSCong Wang for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++) 335244cd96aSCong Wang #else 336244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \ 337191672caSArnd Bergmann for (; 0; (void)(i), (void)(a), (void)(exts)) 33822dc13c8SWANG Cong #endif 33922dc13c8SWANG Cong 340d897a638SJakub Kicinski static inline void 341d897a638SJakub Kicinski tcf_exts_stats_update(const struct tcf_exts *exts, 342d897a638SJakub Kicinski u64 bytes, u64 packets, u64 lastuse) 343d897a638SJakub Kicinski { 344d897a638SJakub Kicinski #ifdef CONFIG_NET_CLS_ACT 345d897a638SJakub Kicinski int i; 346d897a638SJakub Kicinski 347d897a638SJakub Kicinski preempt_disable(); 348d897a638SJakub Kicinski 349d897a638SJakub Kicinski for (i = 0; i < exts->nr_actions; i++) { 350d897a638SJakub Kicinski struct tc_action *a = exts->actions[i]; 351d897a638SJakub Kicinski 35228169abaSEelco Chaudron tcf_action_stats_update(a, bytes, packets, lastuse, true); 353d897a638SJakub Kicinski } 354d897a638SJakub Kicinski 355d897a638SJakub Kicinski preempt_enable(); 356d897a638SJakub Kicinski #endif 357d897a638SJakub Kicinski } 358d897a638SJakub Kicinski 3591da177e4SLinus Torvalds /** 3603bcc0cecSJiri Pirko * tcf_exts_has_actions - check if at least one action is present 3613bcc0cecSJiri Pirko * @exts: tc filter extensions handle 3623bcc0cecSJiri Pirko * 3633bcc0cecSJiri Pirko * Returns true if at least one action is present. 3643bcc0cecSJiri Pirko */ 3653bcc0cecSJiri Pirko static inline bool tcf_exts_has_actions(struct tcf_exts *exts) 3663bcc0cecSJiri Pirko { 3672734437eSWANG Cong #ifdef CONFIG_NET_CLS_ACT 3683bcc0cecSJiri Pirko return exts->nr_actions; 3693bcc0cecSJiri Pirko #else 3703bcc0cecSJiri Pirko return false; 3713bcc0cecSJiri Pirko #endif 3723bcc0cecSJiri Pirko } 3732734437eSWANG Cong 3743bcc0cecSJiri Pirko /** 375af69afc5SJiri Pirko * tcf_exts_exec - execute tc filter extensions 376af69afc5SJiri Pirko * @skb: socket buffer 377af69afc5SJiri Pirko * @exts: tc filter extensions handle 378af69afc5SJiri Pirko * @res: desired result 379af69afc5SJiri Pirko * 380af089e70SJiri Pirko * Executes all configured extensions. Returns TC_ACT_OK on a normal execution, 381af69afc5SJiri Pirko * a negative number if the filter must be considered unmatched or 382af69afc5SJiri Pirko * a positive action code (TC_ACT_*) which must be returned to the 383af69afc5SJiri Pirko * underlying layer. 384af69afc5SJiri Pirko */ 385af69afc5SJiri Pirko static inline int 386af69afc5SJiri Pirko tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, 387af69afc5SJiri Pirko struct tcf_result *res) 388af69afc5SJiri Pirko { 389af69afc5SJiri Pirko #ifdef CONFIG_NET_CLS_ACT 390ec1a9ccaSJiri Pirko return tcf_action_exec(skb, exts->actions, exts->nr_actions, res); 391af69afc5SJiri Pirko #endif 392af089e70SJiri Pirko return TC_ACT_OK; 393af69afc5SJiri Pirko } 394af69afc5SJiri Pirko 3955c15257fSJoe Perches int tcf_exts_validate(struct net *net, struct tcf_proto *tp, 396c1b52739SBenjamin LaHaise struct nlattr **tb, struct nlattr *rate_tlv, 397ec6743a1SVlad Buslov struct tcf_exts *exts, bool ovr, bool rtnl_held, 39850a56190SAlexander Aring struct netlink_ext_ack *extack); 39918d0264fSWANG Cong void tcf_exts_destroy(struct tcf_exts *exts); 4009b0d4446SJiri Pirko void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src); 4015da57f42SWANG Cong int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts); 4025da57f42SWANG Cong int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts); 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds /** 4051da177e4SLinus Torvalds * struct tcf_pkt_info - packet information 4061da177e4SLinus Torvalds */ 407fd2c3ef7SEric Dumazet struct tcf_pkt_info { 4081da177e4SLinus Torvalds unsigned char * ptr; 4091da177e4SLinus Torvalds int nexthdr; 4101da177e4SLinus Torvalds }; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds #ifdef CONFIG_NET_EMATCH 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds struct tcf_ematch_ops; 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds /** 4171da177e4SLinus Torvalds * struct tcf_ematch - extended match (ematch) 4181da177e4SLinus Torvalds * 4191da177e4SLinus Torvalds * @matchid: identifier to allow userspace to reidentify a match 4201da177e4SLinus Torvalds * @flags: flags specifying attributes and the relation to other matches 4211da177e4SLinus Torvalds * @ops: the operations lookup table of the corresponding ematch module 4221da177e4SLinus Torvalds * @datalen: length of the ematch specific configuration data 4231da177e4SLinus Torvalds * @data: ematch specific data 4241da177e4SLinus Torvalds */ 425fd2c3ef7SEric Dumazet struct tcf_ematch { 4261da177e4SLinus Torvalds struct tcf_ematch_ops * ops; 4271da177e4SLinus Torvalds unsigned long data; 4281da177e4SLinus Torvalds unsigned int datalen; 4291da177e4SLinus Torvalds u16 matchid; 4301da177e4SLinus Torvalds u16 flags; 43182a470f1SJohn Fastabend struct net *net; 4321da177e4SLinus Torvalds }; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds static inline int tcf_em_is_container(struct tcf_ematch *em) 4351da177e4SLinus Torvalds { 4361da177e4SLinus Torvalds return !em->ops; 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds static inline int tcf_em_is_simple(struct tcf_ematch *em) 4401da177e4SLinus Torvalds { 4411da177e4SLinus Torvalds return em->flags & TCF_EM_SIMPLE; 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds static inline int tcf_em_is_inverted(struct tcf_ematch *em) 4451da177e4SLinus Torvalds { 4461da177e4SLinus Torvalds return em->flags & TCF_EM_INVERT; 4471da177e4SLinus Torvalds } 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds static inline int tcf_em_last_match(struct tcf_ematch *em) 4501da177e4SLinus Torvalds { 4511da177e4SLinus Torvalds return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END; 4521da177e4SLinus Torvalds } 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds static inline int tcf_em_early_end(struct tcf_ematch *em, int result) 4551da177e4SLinus Torvalds { 4561da177e4SLinus Torvalds if (tcf_em_last_match(em)) 4571da177e4SLinus Torvalds return 1; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds if (result == 0 && em->flags & TCF_EM_REL_AND) 4601da177e4SLinus Torvalds return 1; 4611da177e4SLinus Torvalds 4621da177e4SLinus Torvalds if (result != 0 && em->flags & TCF_EM_REL_OR) 4631da177e4SLinus Torvalds return 1; 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds return 0; 4661da177e4SLinus Torvalds } 4671da177e4SLinus Torvalds 4681da177e4SLinus Torvalds /** 4691da177e4SLinus Torvalds * struct tcf_ematch_tree - ematch tree handle 4701da177e4SLinus Torvalds * 4711da177e4SLinus Torvalds * @hdr: ematch tree header supplied by userspace 4721da177e4SLinus Torvalds * @matches: array of ematches 4731da177e4SLinus Torvalds */ 474fd2c3ef7SEric Dumazet struct tcf_ematch_tree { 4751da177e4SLinus Torvalds struct tcf_ematch_tree_hdr hdr; 4761da177e4SLinus Torvalds struct tcf_ematch * matches; 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds }; 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds /** 4811da177e4SLinus Torvalds * struct tcf_ematch_ops - ematch module operations 4821da177e4SLinus Torvalds * 4831da177e4SLinus Torvalds * @kind: identifier (kind) of this ematch module 4841da177e4SLinus Torvalds * @datalen: length of expected configuration data (optional) 4851da177e4SLinus Torvalds * @change: called during validation (optional) 4861da177e4SLinus Torvalds * @match: called during ematch tree evaluation, must return 1/0 4871da177e4SLinus Torvalds * @destroy: called during destroyage (optional) 4881da177e4SLinus Torvalds * @dump: called during dumping process (optional) 4891da177e4SLinus Torvalds * @owner: owner, must be set to THIS_MODULE 4901da177e4SLinus Torvalds * @link: link to previous/next ematch module (internal use) 4911da177e4SLinus Torvalds */ 492fd2c3ef7SEric Dumazet struct tcf_ematch_ops { 4931da177e4SLinus Torvalds int kind; 4941da177e4SLinus Torvalds int datalen; 49582a470f1SJohn Fastabend int (*change)(struct net *net, void *, 4961da177e4SLinus Torvalds int, struct tcf_ematch *); 4971da177e4SLinus Torvalds int (*match)(struct sk_buff *, struct tcf_ematch *, 4981da177e4SLinus Torvalds struct tcf_pkt_info *); 49982a470f1SJohn Fastabend void (*destroy)(struct tcf_ematch *); 5001da177e4SLinus Torvalds int (*dump)(struct sk_buff *, struct tcf_ematch *); 5011da177e4SLinus Torvalds struct module *owner; 5021da177e4SLinus Torvalds struct list_head link; 5031da177e4SLinus Torvalds }; 5041da177e4SLinus Torvalds 5055c15257fSJoe Perches int tcf_em_register(struct tcf_ematch_ops *); 5065c15257fSJoe Perches void tcf_em_unregister(struct tcf_ematch_ops *); 5075c15257fSJoe Perches int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *, 5081da177e4SLinus Torvalds struct tcf_ematch_tree *); 50982a470f1SJohn Fastabend void tcf_em_tree_destroy(struct tcf_ematch_tree *); 5105c15257fSJoe Perches int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int); 5115c15257fSJoe Perches int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *, 5121da177e4SLinus Torvalds struct tcf_pkt_info *); 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds /** 5151da177e4SLinus Torvalds * tcf_em_tree_match - evaulate an ematch tree 5161da177e4SLinus Torvalds * 5171da177e4SLinus Torvalds * @skb: socket buffer of the packet in question 5181da177e4SLinus Torvalds * @tree: ematch tree to be used for evaluation 5191da177e4SLinus Torvalds * @info: packet information examined by classifier 5201da177e4SLinus Torvalds * 5211da177e4SLinus Torvalds * This function matches @skb against the ematch tree in @tree by going 5221da177e4SLinus Torvalds * through all ematches respecting their logic relations returning 5231da177e4SLinus Torvalds * as soon as the result is obvious. 5241da177e4SLinus Torvalds * 5251da177e4SLinus Torvalds * Returns 1 if the ematch tree as-one matches, no ematches are configured 5261da177e4SLinus Torvalds * or ematch is not enabled in the kernel, otherwise 0 is returned. 5271da177e4SLinus Torvalds */ 5281da177e4SLinus Torvalds static inline int tcf_em_tree_match(struct sk_buff *skb, 5291da177e4SLinus Torvalds struct tcf_ematch_tree *tree, 5301da177e4SLinus Torvalds struct tcf_pkt_info *info) 5311da177e4SLinus Torvalds { 5321da177e4SLinus Torvalds if (tree->hdr.nmatches) 5331da177e4SLinus Torvalds return __tcf_em_tree_match(skb, tree, info); 5341da177e4SLinus Torvalds else 5351da177e4SLinus Torvalds return 1; 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 538db3d99c0SPatrick McHardy #define MODULE_ALIAS_TCF_EMATCH(kind) MODULE_ALIAS("ematch-kind-" __stringify(kind)) 539db3d99c0SPatrick McHardy 5401da177e4SLinus Torvalds #else /* CONFIG_NET_EMATCH */ 5411da177e4SLinus Torvalds 542fd2c3ef7SEric Dumazet struct tcf_ematch_tree { 5431da177e4SLinus Torvalds }; 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0) 54682a470f1SJohn Fastabend #define tcf_em_tree_destroy(t) do { (void)(t); } while(0) 5471da177e4SLinus Torvalds #define tcf_em_tree_dump(skb, t, tlv) (0) 5481da177e4SLinus Torvalds #define tcf_em_tree_match(skb, t, info) ((void)(info), 1) 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds #endif /* CONFIG_NET_EMATCH */ 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer) 5531da177e4SLinus Torvalds { 5541da177e4SLinus Torvalds switch (layer) { 5551da177e4SLinus Torvalds case TCF_LAYER_LINK: 556d3303a65SWolfgang Bumiller return skb_mac_header(skb); 5571da177e4SLinus Torvalds case TCF_LAYER_NETWORK: 558d56f90a7SArnaldo Carvalho de Melo return skb_network_header(skb); 5591da177e4SLinus Torvalds case TCF_LAYER_TRANSPORT: 5609c70220bSArnaldo Carvalho de Melo return skb_transport_header(skb); 5611da177e4SLinus Torvalds } 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds return NULL; 5641da177e4SLinus Torvalds } 5651da177e4SLinus Torvalds 566eddc9ec5SArnaldo Carvalho de Melo static inline int tcf_valid_offset(const struct sk_buff *skb, 567eddc9ec5SArnaldo Carvalho de Melo const unsigned char *ptr, const int len) 5681da177e4SLinus Torvalds { 569da521b2cSDavid S. Miller return likely((ptr + len) <= skb_tail_pointer(skb) && 570da521b2cSDavid S. Miller ptr >= skb->head && 571da521b2cSDavid S. Miller (ptr <= (ptr + len))); 5721da177e4SLinus Torvalds } 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_IND 5750eeb8ffcSDenis V. Lunev #include <net/net_namespace.h> 5760eeb8ffcSDenis V. Lunev 5771da177e4SLinus Torvalds static inline int 5781057c55fSAlexander Aring tcf_change_indev(struct net *net, struct nlattr *indev_tlv, 5791057c55fSAlexander Aring struct netlink_ext_ack *extack) 5801da177e4SLinus Torvalds { 5812519a602SWANG Cong char indev[IFNAMSIZ]; 582c01003c2SPatrick McHardy struct net_device *dev; 583c01003c2SPatrick McHardy 5841057c55fSAlexander Aring if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) { 5851057c55fSAlexander Aring NL_SET_ERR_MSG(extack, "Interface name too long"); 5862519a602SWANG Cong return -EINVAL; 5871057c55fSAlexander Aring } 5882519a602SWANG Cong dev = __dev_get_by_name(net, indev); 5892519a602SWANG Cong if (!dev) 5902519a602SWANG Cong return -ENODEV; 5912519a602SWANG Cong return dev->ifindex; 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds 5942519a602SWANG Cong static inline bool 5952519a602SWANG Cong tcf_match_indev(struct sk_buff *skb, int ifindex) 5962519a602SWANG Cong { 5972519a602SWANG Cong if (!ifindex) 5982519a602SWANG Cong return true; 5992519a602SWANG Cong if (!skb->skb_iif) 6002519a602SWANG Cong return false; 6012519a602SWANG Cong return ifindex == skb->skb_iif; 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds #endif /* CONFIG_NET_CLS_IND */ 6041da177e4SLinus Torvalds 6053a7b6861SPablo Neira Ayuso int tc_setup_flow_action(struct flow_action *flow_action, 6063a7b6861SPablo Neira Ayuso const struct tcf_exts *exts); 607aeb3fecdSCong Wang int tc_setup_cb_call(struct tcf_block *block, enum tc_setup_type type, 608aeb3fecdSCong Wang void *type_data, bool err_stop); 609e3ab786bSPablo Neira Ayuso unsigned int tcf_exts_num_actions(struct tcf_exts *exts); 610717503b9SJiri Pirko 6118c4083b3SJiri Pirko enum tc_block_command { 6128c4083b3SJiri Pirko TC_BLOCK_BIND, 6138c4083b3SJiri Pirko TC_BLOCK_UNBIND, 6148c4083b3SJiri Pirko }; 6158c4083b3SJiri Pirko 6168c4083b3SJiri Pirko struct tc_block_offload { 6178c4083b3SJiri Pirko enum tc_block_command command; 6188c4083b3SJiri Pirko enum tcf_block_binder_type binder_type; 6198c4083b3SJiri Pirko struct tcf_block *block; 62060513bd8SJohn Hurley struct netlink_ext_ack *extack; 6218c4083b3SJiri Pirko }; 6228c4083b3SJiri Pirko 6235fd9fc4eSJiri Pirko struct tc_cls_common_offload { 6245fd9fc4eSJiri Pirko u32 chain_index; 6255fd9fc4eSJiri Pirko __be16 protocol; 626d7c1c8d2SJiri Pirko u32 prio; 6278f0b425aSQuentin Monnet struct netlink_ext_ack *extack; 6285fd9fc4eSJiri Pirko }; 6295fd9fc4eSJiri Pirko 630a1b7c5fdSJohn Fastabend struct tc_cls_u32_knode { 631a1b7c5fdSJohn Fastabend struct tcf_exts *exts; 632068ceb35SJakub Kicinski struct tcf_result *res; 633e014860eSJohn Fastabend struct tc_u32_sel *sel; 634a1b7c5fdSJohn Fastabend u32 handle; 635a1b7c5fdSJohn Fastabend u32 val; 636a1b7c5fdSJohn Fastabend u32 mask; 637a1b7c5fdSJohn Fastabend u32 link_handle; 638e014860eSJohn Fastabend u8 fshift; 639a1b7c5fdSJohn Fastabend }; 640a1b7c5fdSJohn Fastabend 641a1b7c5fdSJohn Fastabend struct tc_cls_u32_hnode { 642a1b7c5fdSJohn Fastabend u32 handle; 643a1b7c5fdSJohn Fastabend u32 prio; 644a1b7c5fdSJohn Fastabend unsigned int divisor; 645a1b7c5fdSJohn Fastabend }; 646a1b7c5fdSJohn Fastabend 647a1b7c5fdSJohn Fastabend enum tc_clsu32_command { 648a1b7c5fdSJohn Fastabend TC_CLSU32_NEW_KNODE, 649a1b7c5fdSJohn Fastabend TC_CLSU32_REPLACE_KNODE, 650a1b7c5fdSJohn Fastabend TC_CLSU32_DELETE_KNODE, 651a1b7c5fdSJohn Fastabend TC_CLSU32_NEW_HNODE, 652a1b7c5fdSJohn Fastabend TC_CLSU32_REPLACE_HNODE, 653a1b7c5fdSJohn Fastabend TC_CLSU32_DELETE_HNODE, 654a1b7c5fdSJohn Fastabend }; 655a1b7c5fdSJohn Fastabend 656a1b7c5fdSJohn Fastabend struct tc_cls_u32_offload { 6575fd9fc4eSJiri Pirko struct tc_cls_common_offload common; 658a1b7c5fdSJohn Fastabend /* knode values */ 659a1b7c5fdSJohn Fastabend enum tc_clsu32_command command; 660a1b7c5fdSJohn Fastabend union { 661a1b7c5fdSJohn Fastabend struct tc_cls_u32_knode knode; 662a1b7c5fdSJohn Fastabend struct tc_cls_u32_hnode hnode; 663a1b7c5fdSJohn Fastabend }; 664a1b7c5fdSJohn Fastabend }; 665a1b7c5fdSJohn Fastabend 6667b06e8aeSJiri Pirko static inline bool tc_can_offload(const struct net_device *dev) 6676843e7a2SJohn Fastabend { 66870b5aee4SJiri Pirko return dev->features & NETIF_F_HW_TC; 6696843e7a2SJohn Fastabend } 6706843e7a2SJohn Fastabend 671f9eda14fSQuentin Monnet static inline bool tc_can_offload_extack(const struct net_device *dev, 672f9eda14fSQuentin Monnet struct netlink_ext_ack *extack) 673f9eda14fSQuentin Monnet { 674f9eda14fSQuentin Monnet bool can = tc_can_offload(dev); 675f9eda14fSQuentin Monnet 676f9eda14fSQuentin Monnet if (!can) 677f9eda14fSQuentin Monnet NL_SET_ERR_MSG(extack, "TC offload is disabled on net device"); 678f9eda14fSQuentin Monnet 679f9eda14fSQuentin Monnet return can; 680f9eda14fSQuentin Monnet } 681f9eda14fSQuentin Monnet 682878db9f0SJakub Kicinski static inline bool 683878db9f0SJakub Kicinski tc_cls_can_offload_and_chain0(const struct net_device *dev, 684878db9f0SJakub Kicinski struct tc_cls_common_offload *common) 685878db9f0SJakub Kicinski { 686878db9f0SJakub Kicinski if (!tc_can_offload_extack(dev, common->extack)) 687878db9f0SJakub Kicinski return false; 688878db9f0SJakub Kicinski if (common->chain_index) { 689878db9f0SJakub Kicinski NL_SET_ERR_MSG(common->extack, 690878db9f0SJakub Kicinski "Driver supports only offload of chain 0"); 691878db9f0SJakub Kicinski return false; 692878db9f0SJakub Kicinski } 693878db9f0SJakub Kicinski return true; 694878db9f0SJakub Kicinski } 695878db9f0SJakub Kicinski 69655330f05SHadar Hen Zion static inline bool tc_skip_hw(u32 flags) 69755330f05SHadar Hen Zion { 69855330f05SHadar Hen Zion return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false; 69955330f05SHadar Hen Zion } 70055330f05SHadar Hen Zion 701d34e3e18SSamudrala, Sridhar static inline bool tc_skip_sw(u32 flags) 702d34e3e18SSamudrala, Sridhar { 703d34e3e18SSamudrala, Sridhar return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false; 704d34e3e18SSamudrala, Sridhar } 705d34e3e18SSamudrala, Sridhar 706d34e3e18SSamudrala, Sridhar /* SKIP_HW and SKIP_SW are mutually exclusive flags. */ 707d34e3e18SSamudrala, Sridhar static inline bool tc_flags_valid(u32 flags) 708d34e3e18SSamudrala, Sridhar { 70981c7288bSMarcelo Ricardo Leitner if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW | 71081c7288bSMarcelo Ricardo Leitner TCA_CLS_FLAGS_VERBOSE)) 711d34e3e18SSamudrala, Sridhar return false; 712d34e3e18SSamudrala, Sridhar 71381c7288bSMarcelo Ricardo Leitner flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW; 714d34e3e18SSamudrala, Sridhar if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW))) 715d34e3e18SSamudrala, Sridhar return false; 716d34e3e18SSamudrala, Sridhar 717d34e3e18SSamudrala, Sridhar return true; 718d34e3e18SSamudrala, Sridhar } 719d34e3e18SSamudrala, Sridhar 720e696028aSOr Gerlitz static inline bool tc_in_hw(u32 flags) 721e696028aSOr Gerlitz { 722e696028aSOr Gerlitz return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false; 723e696028aSOr Gerlitz } 724e696028aSOr Gerlitz 72534832e1cSJakub Kicinski static inline void 72634832e1cSJakub Kicinski tc_cls_common_offload_init(struct tc_cls_common_offload *cls_common, 72734832e1cSJakub Kicinski const struct tcf_proto *tp, u32 flags, 72834832e1cSJakub Kicinski struct netlink_ext_ack *extack) 72934832e1cSJakub Kicinski { 73034832e1cSJakub Kicinski cls_common->chain_index = tp->chain->index; 73134832e1cSJakub Kicinski cls_common->protocol = tp->protocol; 73234832e1cSJakub Kicinski cls_common->prio = tp->prio; 73381c7288bSMarcelo Ricardo Leitner if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE) 73434832e1cSJakub Kicinski cls_common->extack = extack; 73534832e1cSJakub Kicinski } 73634832e1cSJakub Kicinski 7375b33f488SAmir Vadai enum tc_fl_command { 7385b33f488SAmir Vadai TC_CLSFLOWER_REPLACE, 7395b33f488SAmir Vadai TC_CLSFLOWER_DESTROY, 74010cbc684SAmir Vadai TC_CLSFLOWER_STATS, 74134738452SJiri Pirko TC_CLSFLOWER_TMPLT_CREATE, 74234738452SJiri Pirko TC_CLSFLOWER_TMPLT_DESTROY, 7435b33f488SAmir Vadai }; 7445b33f488SAmir Vadai 7455b33f488SAmir Vadai struct tc_cls_flower_offload { 7465fd9fc4eSJiri Pirko struct tc_cls_common_offload common; 7475b33f488SAmir Vadai enum tc_fl_command command; 7488208d21bSAmir Vadai unsigned long cookie; 7498f256622SPablo Neira Ayuso struct flow_rule *rule; 7503b1903efSPablo Neira Ayuso struct flow_stats stats; 751384c181eSAmritha Nambiar u32 classid; 7525b33f488SAmir Vadai }; 7535b33f488SAmir Vadai 7548f256622SPablo Neira Ayuso static inline struct flow_rule * 7558f256622SPablo Neira Ayuso tc_cls_flower_offload_flow_rule(struct tc_cls_flower_offload *tc_flow_cmd) 7568f256622SPablo Neira Ayuso { 7578f256622SPablo Neira Ayuso return tc_flow_cmd->rule; 7588f256622SPablo Neira Ayuso } 7598f256622SPablo Neira Ayuso 760b87f7936SYotam Gigi enum tc_matchall_command { 761b87f7936SYotam Gigi TC_CLSMATCHALL_REPLACE, 762b87f7936SYotam Gigi TC_CLSMATCHALL_DESTROY, 763b7fe4ab8SPieter Jansen van Vuuren TC_CLSMATCHALL_STATS, 764b87f7936SYotam Gigi }; 765b87f7936SYotam Gigi 766b87f7936SYotam Gigi struct tc_cls_matchall_offload { 7675fd9fc4eSJiri Pirko struct tc_cls_common_offload common; 768b87f7936SYotam Gigi enum tc_matchall_command command; 769f00cbf19SPieter Jansen van Vuuren struct flow_rule *rule; 770b7fe4ab8SPieter Jansen van Vuuren struct flow_stats stats; 771b87f7936SYotam Gigi unsigned long cookie; 772b87f7936SYotam Gigi }; 773b87f7936SYotam Gigi 774332ae8e2SJakub Kicinski enum tc_clsbpf_command { 775102740bdSJakub Kicinski TC_CLSBPF_OFFLOAD, 77668d64063SJakub Kicinski TC_CLSBPF_STATS, 777332ae8e2SJakub Kicinski }; 778332ae8e2SJakub Kicinski 779332ae8e2SJakub Kicinski struct tc_cls_bpf_offload { 7805fd9fc4eSJiri Pirko struct tc_cls_common_offload common; 781332ae8e2SJakub Kicinski enum tc_clsbpf_command command; 782332ae8e2SJakub Kicinski struct tcf_exts *exts; 783332ae8e2SJakub Kicinski struct bpf_prog *prog; 784102740bdSJakub Kicinski struct bpf_prog *oldprog; 785332ae8e2SJakub Kicinski const char *name; 786332ae8e2SJakub Kicinski bool exts_integrated; 787332ae8e2SJakub Kicinski }; 788332ae8e2SJakub Kicinski 7894e8b86c0SAmritha Nambiar struct tc_mqprio_qopt_offload { 7904e8b86c0SAmritha Nambiar /* struct tc_mqprio_qopt must always be the first element */ 7914e8b86c0SAmritha Nambiar struct tc_mqprio_qopt qopt; 7924e8b86c0SAmritha Nambiar u16 mode; 7934e8b86c0SAmritha Nambiar u16 shaper; 7944e8b86c0SAmritha Nambiar u32 flags; 7954e8b86c0SAmritha Nambiar u64 min_rate[TC_QOPT_MAX_QUEUE]; 7964e8b86c0SAmritha Nambiar u64 max_rate[TC_QOPT_MAX_QUEUE]; 7974e8b86c0SAmritha Nambiar }; 7981045ba77SJamal Hadi Salim 7991045ba77SJamal Hadi Salim /* This structure holds cookie structure that is passed from user 8001045ba77SJamal Hadi Salim * to the kernel for actions and classifiers 8011045ba77SJamal Hadi Salim */ 8021045ba77SJamal Hadi Salim struct tc_cookie { 8031045ba77SJamal Hadi Salim u8 *data; 8041045ba77SJamal Hadi Salim u32 len; 805eec94fdbSVlad Buslov struct rcu_head rcu; 8061045ba77SJamal Hadi Salim }; 807602f3bafSNogah Frankel 808f34b4aacSNogah Frankel struct tc_qopt_offload_stats { 809f34b4aacSNogah Frankel struct gnet_stats_basic_packed *bstats; 810f34b4aacSNogah Frankel struct gnet_stats_queue *qstats; 811f34b4aacSNogah Frankel }; 812f34b4aacSNogah Frankel 813f971b132SJakub Kicinski enum tc_mq_command { 814f971b132SJakub Kicinski TC_MQ_CREATE, 815f971b132SJakub Kicinski TC_MQ_DESTROY, 81647c669a4SJakub Kicinski TC_MQ_STATS, 817d577a3d2SJakub Kicinski TC_MQ_GRAFT, 818d577a3d2SJakub Kicinski }; 819d577a3d2SJakub Kicinski 820d577a3d2SJakub Kicinski struct tc_mq_opt_offload_graft_params { 821d577a3d2SJakub Kicinski unsigned long queue; 822d577a3d2SJakub Kicinski u32 child_handle; 823f971b132SJakub Kicinski }; 824f971b132SJakub Kicinski 825f971b132SJakub Kicinski struct tc_mq_qopt_offload { 826f971b132SJakub Kicinski enum tc_mq_command command; 827f971b132SJakub Kicinski u32 handle; 828d577a3d2SJakub Kicinski union { 82947c669a4SJakub Kicinski struct tc_qopt_offload_stats stats; 830d577a3d2SJakub Kicinski struct tc_mq_opt_offload_graft_params graft_params; 831d577a3d2SJakub Kicinski }; 832f971b132SJakub Kicinski }; 833f971b132SJakub Kicinski 834602f3bafSNogah Frankel enum tc_red_command { 835602f3bafSNogah Frankel TC_RED_REPLACE, 836602f3bafSNogah Frankel TC_RED_DESTROY, 837602f3bafSNogah Frankel TC_RED_STATS, 838602f3bafSNogah Frankel TC_RED_XSTATS, 839bf2a752bSJakub Kicinski TC_RED_GRAFT, 840602f3bafSNogah Frankel }; 841602f3bafSNogah Frankel 842602f3bafSNogah Frankel struct tc_red_qopt_offload_params { 843602f3bafSNogah Frankel u32 min; 844602f3bafSNogah Frankel u32 max; 845602f3bafSNogah Frankel u32 probability; 846c0b7490bSJakub Kicinski u32 limit; 847602f3bafSNogah Frankel bool is_ecn; 848190852a5SJakub Kicinski bool is_harddrop; 849416ef9b1SJakub Kicinski struct gnet_stats_queue *qstats; 850602f3bafSNogah Frankel }; 851602f3bafSNogah Frankel 852602f3bafSNogah Frankel struct tc_red_qopt_offload { 853602f3bafSNogah Frankel enum tc_red_command command; 854602f3bafSNogah Frankel u32 handle; 855602f3bafSNogah Frankel u32 parent; 856602f3bafSNogah Frankel union { 857602f3bafSNogah Frankel struct tc_red_qopt_offload_params set; 858f34b4aacSNogah Frankel struct tc_qopt_offload_stats stats; 859602f3bafSNogah Frankel struct red_stats *xstats; 860bf2a752bSJakub Kicinski u32 child_handle; 861602f3bafSNogah Frankel }; 862602f3bafSNogah Frankel }; 863602f3bafSNogah Frankel 864890d8d23SJakub Kicinski enum tc_gred_command { 865890d8d23SJakub Kicinski TC_GRED_REPLACE, 866890d8d23SJakub Kicinski TC_GRED_DESTROY, 867e49efd52SJakub Kicinski TC_GRED_STATS, 868890d8d23SJakub Kicinski }; 869890d8d23SJakub Kicinski 870890d8d23SJakub Kicinski struct tc_gred_vq_qopt_offload_params { 871890d8d23SJakub Kicinski bool present; 872890d8d23SJakub Kicinski u32 limit; 873890d8d23SJakub Kicinski u32 prio; 874890d8d23SJakub Kicinski u32 min; 875890d8d23SJakub Kicinski u32 max; 876890d8d23SJakub Kicinski bool is_ecn; 877890d8d23SJakub Kicinski bool is_harddrop; 878890d8d23SJakub Kicinski u32 probability; 879890d8d23SJakub Kicinski /* Only need backlog, see struct tc_prio_qopt_offload_params */ 880890d8d23SJakub Kicinski u32 *backlog; 881890d8d23SJakub Kicinski }; 882890d8d23SJakub Kicinski 883890d8d23SJakub Kicinski struct tc_gred_qopt_offload_params { 884890d8d23SJakub Kicinski bool grio_on; 885890d8d23SJakub Kicinski bool wred_on; 886890d8d23SJakub Kicinski unsigned int dp_cnt; 887890d8d23SJakub Kicinski unsigned int dp_def; 888890d8d23SJakub Kicinski struct gnet_stats_queue *qstats; 889890d8d23SJakub Kicinski struct tc_gred_vq_qopt_offload_params tab[MAX_DPs]; 890890d8d23SJakub Kicinski }; 891890d8d23SJakub Kicinski 892e49efd52SJakub Kicinski struct tc_gred_qopt_offload_stats { 893e49efd52SJakub Kicinski struct gnet_stats_basic_packed bstats[MAX_DPs]; 894e49efd52SJakub Kicinski struct gnet_stats_queue qstats[MAX_DPs]; 895e49efd52SJakub Kicinski struct red_stats *xstats[MAX_DPs]; 896e49efd52SJakub Kicinski }; 897e49efd52SJakub Kicinski 898890d8d23SJakub Kicinski struct tc_gred_qopt_offload { 899890d8d23SJakub Kicinski enum tc_gred_command command; 900890d8d23SJakub Kicinski u32 handle; 901890d8d23SJakub Kicinski u32 parent; 902890d8d23SJakub Kicinski union { 903890d8d23SJakub Kicinski struct tc_gred_qopt_offload_params set; 904e49efd52SJakub Kicinski struct tc_gred_qopt_offload_stats stats; 905890d8d23SJakub Kicinski }; 906890d8d23SJakub Kicinski }; 907890d8d23SJakub Kicinski 9087fdb61b4SNogah Frankel enum tc_prio_command { 9097fdb61b4SNogah Frankel TC_PRIO_REPLACE, 9107fdb61b4SNogah Frankel TC_PRIO_DESTROY, 9117fdb61b4SNogah Frankel TC_PRIO_STATS, 912b9c7a7acSNogah Frankel TC_PRIO_GRAFT, 9137fdb61b4SNogah Frankel }; 9147fdb61b4SNogah Frankel 9157fdb61b4SNogah Frankel struct tc_prio_qopt_offload_params { 9167fdb61b4SNogah Frankel int bands; 9177fdb61b4SNogah Frankel u8 priomap[TC_PRIO_MAX + 1]; 9187fdb61b4SNogah Frankel /* In case that a prio qdisc is offloaded and now is changed to a 9197fdb61b4SNogah Frankel * non-offloadedable config, it needs to update the backlog & qlen 9207fdb61b4SNogah Frankel * values to negate the HW backlog & qlen values (and only them). 9217fdb61b4SNogah Frankel */ 9227fdb61b4SNogah Frankel struct gnet_stats_queue *qstats; 9237fdb61b4SNogah Frankel }; 9247fdb61b4SNogah Frankel 925b9c7a7acSNogah Frankel struct tc_prio_qopt_offload_graft_params { 926b9c7a7acSNogah Frankel u8 band; 927b9c7a7acSNogah Frankel u32 child_handle; 928b9c7a7acSNogah Frankel }; 929b9c7a7acSNogah Frankel 9307fdb61b4SNogah Frankel struct tc_prio_qopt_offload { 9317fdb61b4SNogah Frankel enum tc_prio_command command; 9327fdb61b4SNogah Frankel u32 handle; 9337fdb61b4SNogah Frankel u32 parent; 9347fdb61b4SNogah Frankel union { 9357fdb61b4SNogah Frankel struct tc_prio_qopt_offload_params replace_params; 9367fdb61b4SNogah Frankel struct tc_qopt_offload_stats stats; 937b9c7a7acSNogah Frankel struct tc_prio_qopt_offload_graft_params graft_params; 9387fdb61b4SNogah Frankel }; 9397fdb61b4SNogah Frankel }; 940b9c7a7acSNogah Frankel 94198b0e5f6SJakub Kicinski enum tc_root_command { 94298b0e5f6SJakub Kicinski TC_ROOT_GRAFT, 94398b0e5f6SJakub Kicinski }; 94498b0e5f6SJakub Kicinski 94598b0e5f6SJakub Kicinski struct tc_root_qopt_offload { 94698b0e5f6SJakub Kicinski enum tc_root_command command; 94798b0e5f6SJakub Kicinski u32 handle; 94898b0e5f6SJakub Kicinski bool ingress; 94998b0e5f6SJakub Kicinski }; 95098b0e5f6SJakub Kicinski 9511da177e4SLinus Torvalds #endif 952