Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __NET_PKT_CLS_H |
| 3 | #define __NET_PKT_CLS_H |
| 4 | |
| 5 | #include <linux/pkt_cls.h> |
Cong Wang | 7aa0045 | 2017-10-26 18:24:28 -0700 | [diff] [blame] | 6 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <net/sch_generic.h> |
| 8 | #include <net/act_api.h> |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 9 | #include <net/flow_offload.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Paolo Abeni | cd11b164 | 2018-07-30 14:30:44 +0200 | [diff] [blame] | 11 | /* TC action not accessible from user space */ |
| 12 | #define TC_ACT_REINSERT (TC_ACT_VALUE_MAX + 1) |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* Basic packet classifier frontend definitions. */ |
| 15 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 16 | struct tcf_walker { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | int stop; |
| 18 | int skip; |
| 19 | int count; |
Vlad Buslov | 6676d5e | 2019-02-25 17:38:31 +0200 | [diff] [blame] | 20 | bool nonempty; |
Vlad Buslov | 01683a1 | 2018-07-09 13:29:11 +0300 | [diff] [blame] | 21 | unsigned long cookie; |
WANG Cong | 8113c09 | 2017-08-04 21:31:43 -0700 | [diff] [blame] | 22 | int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Joe Perches | 5c15257 | 2013-07-30 22:47:13 -0700 | [diff] [blame] | 25 | int register_tcf_proto_ops(struct tcf_proto_ops *ops); |
| 26 | int unregister_tcf_proto_ops(struct tcf_proto_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 28 | enum tcf_block_binder_type { |
| 29 | TCF_BLOCK_BINDER_TYPE_UNSPEC, |
Jiri Pirko | 6e40cf2 | 2017-10-19 15:50:30 +0200 | [diff] [blame] | 30 | TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS, |
| 31 | TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS, |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct tcf_block_ext_info { |
| 35 | enum tcf_block_binder_type binder_type; |
Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 36 | tcf_chain_head_change_t *chain_head_change; |
| 37 | void *chain_head_change_priv; |
Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 38 | u32 block_index; |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 41 | struct tcf_block_cb; |
Cong Wang | aaa908f | 2018-05-23 15:26:53 -0700 | [diff] [blame] | 42 | bool tcf_queue_work(struct rcu_work *rwork, work_func_t func); |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 43 | |
Jiri Pirko | 8ae7003 | 2017-02-15 11:57:50 +0100 | [diff] [blame] | 44 | #ifdef CONFIG_NET_CLS |
Jiri Pirko | 1f3ed38 | 2018-07-27 09:45:05 +0200 | [diff] [blame] | 45 | struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block, |
| 46 | u32 chain_index); |
Jiri Pirko | 1f3ed38 | 2018-07-27 09:45:05 +0200 | [diff] [blame] | 47 | void tcf_chain_put_by_act(struct tcf_chain *chain); |
Vlad Buslov | bbf7383 | 2019-02-11 10:55:36 +0200 | [diff] [blame] | 48 | struct tcf_chain *tcf_get_next_chain(struct tcf_block *block, |
| 49 | struct tcf_chain *chain); |
Vlad Buslov | fe2923a | 2019-02-11 10:55:40 +0200 | [diff] [blame] | 50 | struct tcf_proto *tcf_get_next_proto(struct tcf_chain *chain, |
Vlad Buslov | 12db03b | 2019-02-11 10:55:45 +0200 | [diff] [blame] | 51 | struct tcf_proto *tp, bool rtnl_held); |
Jiri Pirko | f36fe1c | 2018-01-17 11:46:48 +0100 | [diff] [blame] | 52 | void tcf_block_netif_keep_dst(struct tcf_block *block); |
Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 53 | int tcf_block_get(struct tcf_block **p_block, |
Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 54 | struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, |
| 55 | struct netlink_ext_ack *extack); |
Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 56 | int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, |
Alexander Aring | 8d1a77f | 2017-12-20 12:35:19 -0500 | [diff] [blame] | 57 | struct tcf_block_ext_info *ei, |
| 58 | struct netlink_ext_ack *extack); |
Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 59 | void tcf_block_put(struct tcf_block *block); |
Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 60 | void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 61 | struct tcf_block_ext_info *ei); |
Jiri Pirko | 4418646 | 2017-10-13 14:00:59 +0200 | [diff] [blame] | 62 | |
Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 63 | static inline bool tcf_block_shared(struct tcf_block *block) |
| 64 | { |
| 65 | return block->index; |
| 66 | } |
| 67 | |
Jiri Pirko | 4418646 | 2017-10-13 14:00:59 +0200 | [diff] [blame] | 68 | static inline struct Qdisc *tcf_block_q(struct tcf_block *block) |
| 69 | { |
Jiri Pirko | 4861738 | 2018-01-17 11:46:46 +0100 | [diff] [blame] | 70 | WARN_ON(tcf_block_shared(block)); |
Jiri Pirko | 4418646 | 2017-10-13 14:00:59 +0200 | [diff] [blame] | 71 | return block->q; |
| 72 | } |
| 73 | |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 74 | void *tcf_block_cb_priv(struct tcf_block_cb *block_cb); |
| 75 | struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, |
| 76 | tc_setup_cb_t *cb, void *cb_ident); |
| 77 | void tcf_block_cb_incref(struct tcf_block_cb *block_cb); |
| 78 | unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb); |
| 79 | struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, |
| 80 | tc_setup_cb_t *cb, void *cb_ident, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 81 | void *cb_priv, |
| 82 | struct netlink_ext_ack *extack); |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 83 | int tcf_block_cb_register(struct tcf_block *block, |
| 84 | tc_setup_cb_t *cb, void *cb_ident, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 85 | void *cb_priv, struct netlink_ext_ack *extack); |
John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 86 | void __tcf_block_cb_unregister(struct tcf_block *block, |
| 87 | struct tcf_block_cb *block_cb); |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 88 | void tcf_block_cb_unregister(struct tcf_block *block, |
| 89 | tc_setup_cb_t *cb, void *cb_ident); |
John Hurley | 7f76fa3 | 2018-11-09 21:21:26 -0800 | [diff] [blame] | 90 | int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, |
| 91 | tc_indr_block_bind_cb_t *cb, void *cb_ident); |
| 92 | int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, |
| 93 | tc_indr_block_bind_cb_t *cb, void *cb_ident); |
| 94 | void __tc_indr_block_cb_unregister(struct net_device *dev, |
| 95 | tc_indr_block_bind_cb_t *cb, void *cb_ident); |
| 96 | void tc_indr_block_cb_unregister(struct net_device *dev, |
| 97 | tc_indr_block_bind_cb_t *cb, void *cb_ident); |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 98 | |
Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 99 | int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, |
| 100 | struct tcf_result *res, bool compat_mode); |
| 101 | |
Jiri Pirko | 8ae7003 | 2017-02-15 11:57:50 +0100 | [diff] [blame] | 102 | #else |
Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 103 | static inline |
| 104 | int tcf_block_get(struct tcf_block **p_block, |
Sudip Mukherjee | 3c14909 | 2017-12-22 15:52:05 +0000 | [diff] [blame] | 105 | struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q, |
| 106 | struct netlink_ext_ack *extack) |
Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 107 | { |
| 108 | return 0; |
| 109 | } |
| 110 | |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 111 | static inline |
Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 112 | int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q, |
Quentin Monnet | 33c30a8 | 2018-01-03 17:30:45 -0800 | [diff] [blame] | 113 | struct tcf_block_ext_info *ei, |
| 114 | struct netlink_ext_ack *extack) |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | |
Jiri Pirko | 6529eab | 2017-05-17 11:07:55 +0200 | [diff] [blame] | 119 | static inline void tcf_block_put(struct tcf_block *block) |
Jiri Pirko | 8ae7003 | 2017-02-15 11:57:50 +0100 | [diff] [blame] | 120 | { |
| 121 | } |
Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 122 | |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 123 | static inline |
Jiri Pirko | c7eb7d7 | 2017-11-03 11:46:24 +0100 | [diff] [blame] | 124 | void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q, |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 125 | struct tcf_block_ext_info *ei) |
| 126 | { |
| 127 | } |
| 128 | |
Jiri Pirko | 4418646 | 2017-10-13 14:00:59 +0200 | [diff] [blame] | 129 | static inline struct Qdisc *tcf_block_q(struct tcf_block *block) |
| 130 | { |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 134 | static inline |
| 135 | int tc_setup_cb_block_register(struct tcf_block *block, tc_setup_cb_t *cb, |
| 136 | void *cb_priv) |
| 137 | { |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static inline |
| 142 | void tc_setup_cb_block_unregister(struct tcf_block *block, tc_setup_cb_t *cb, |
| 143 | void *cb_priv) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | static inline |
| 148 | void *tcf_block_cb_priv(struct tcf_block_cb *block_cb) |
| 149 | { |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | static inline |
| 154 | struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block, |
| 155 | tc_setup_cb_t *cb, void *cb_ident) |
| 156 | { |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | static inline |
| 161 | void tcf_block_cb_incref(struct tcf_block_cb *block_cb) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | static inline |
| 166 | unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb) |
| 167 | { |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static inline |
| 172 | struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block, |
| 173 | tc_setup_cb_t *cb, void *cb_ident, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 174 | void *cb_priv, |
| 175 | struct netlink_ext_ack *extack) |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 176 | { |
| 177 | return NULL; |
| 178 | } |
| 179 | |
| 180 | static inline |
| 181 | int tcf_block_cb_register(struct tcf_block *block, |
| 182 | tc_setup_cb_t *cb, void *cb_ident, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 183 | void *cb_priv, struct netlink_ext_ack *extack) |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 184 | { |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static inline |
John Hurley | 3263674 | 2018-06-25 14:30:10 -0700 | [diff] [blame] | 189 | void __tcf_block_cb_unregister(struct tcf_block *block, |
| 190 | struct tcf_block_cb *block_cb) |
Jiri Pirko | acb6744 | 2017-10-19 15:50:31 +0200 | [diff] [blame] | 191 | { |
| 192 | } |
| 193 | |
| 194 | static inline |
| 195 | void tcf_block_cb_unregister(struct tcf_block *block, |
| 196 | tc_setup_cb_t *cb, void *cb_ident) |
| 197 | { |
| 198 | } |
| 199 | |
John Hurley | 7f76fa3 | 2018-11-09 21:21:26 -0800 | [diff] [blame] | 200 | static inline |
| 201 | int __tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, |
| 202 | tc_indr_block_bind_cb_t *cb, void *cb_ident) |
| 203 | { |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static inline |
| 208 | int tc_indr_block_cb_register(struct net_device *dev, void *cb_priv, |
| 209 | tc_indr_block_bind_cb_t *cb, void *cb_ident) |
| 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static inline |
| 215 | void __tc_indr_block_cb_unregister(struct net_device *dev, |
| 216 | tc_indr_block_bind_cb_t *cb, void *cb_ident) |
| 217 | { |
| 218 | } |
| 219 | |
| 220 | static inline |
| 221 | void tc_indr_block_cb_unregister(struct net_device *dev, |
| 222 | tc_indr_block_bind_cb_t *cb, void *cb_ident) |
| 223 | { |
| 224 | } |
| 225 | |
Jiri Pirko | 87d8309 | 2017-05-17 11:07:54 +0200 | [diff] [blame] | 226 | static inline int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, |
| 227 | struct tcf_result *res, bool compat_mode) |
| 228 | { |
| 229 | return TC_ACT_UNSPEC; |
| 230 | } |
Jiri Pirko | 8ae7003 | 2017-02-15 11:57:50 +0100 | [diff] [blame] | 231 | #endif |
Jiri Pirko | cf1facd | 2017-02-09 14:38:56 +0100 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static inline unsigned long |
| 234 | __cls_set_class(unsigned long *clp, unsigned long cl) |
| 235 | { |
WANG Cong | a0efb80 | 2014-09-30 16:07:24 -0700 | [diff] [blame] | 236 | return xchg(clp, cl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static inline unsigned long |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 240 | cls_set_class(struct Qdisc *q, unsigned long *clp, unsigned long cl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | unsigned long old_cl; |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 243 | |
| 244 | sch_tree_lock(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | old_cl = __cls_set_class(clp, cl); |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 246 | sch_tree_unlock(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return old_cl; |
| 248 | } |
| 249 | |
| 250 | static inline void |
| 251 | tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base) |
| 252 | { |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 253 | struct Qdisc *q = tp->chain->block->q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | unsigned long cl; |
| 255 | |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 256 | /* Check q as it is not set for shared blocks. In that case, |
| 257 | * setting class is not supported. |
| 258 | */ |
| 259 | if (!q) |
| 260 | return; |
| 261 | cl = q->ops->cl_ops->bind_tcf(q, base, r->classid); |
| 262 | cl = cls_set_class(q, &r->class, cl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (cl) |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 264 | q->ops->cl_ops->unbind_tcf(q, cl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static inline void |
| 268 | tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r) |
| 269 | { |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 270 | struct Qdisc *q = tp->chain->block->q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned long cl; |
| 272 | |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 273 | if (!q) |
| 274 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if ((cl = __cls_set_class(&r->class, 0)) != 0) |
Jiri Pirko | 34e3759 | 2017-10-13 14:01:00 +0200 | [diff] [blame] | 276 | q->ops->cl_ops->unbind_tcf(q, cl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 279 | struct tcf_exts { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | #ifdef CONFIG_NET_CLS_ACT |
WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 281 | __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 282 | int nr_actions; |
| 283 | struct tc_action **actions; |
Cong Wang | e4b95c4 | 2017-11-06 13:47:19 -0800 | [diff] [blame] | 284 | struct net *net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | #endif |
WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 286 | /* Map to export classifier specific extension TLV types to the |
| 287 | * generic extensions API. Unsupported extensions must be set to 0. |
| 288 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | int action; |
| 290 | int police; |
| 291 | }; |
| 292 | |
Cong Wang | 1421510 | 2019-02-20 21:37:42 -0800 | [diff] [blame] | 293 | static inline int tcf_exts_init(struct tcf_exts *exts, struct net *net, |
| 294 | int action, int police) |
WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 295 | { |
| 296 | #ifdef CONFIG_NET_CLS_ACT |
WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 297 | exts->type = 0; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 298 | exts->nr_actions = 0; |
Cong Wang | 1421510 | 2019-02-20 21:37:42 -0800 | [diff] [blame] | 299 | exts->net = net; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 300 | exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *), |
| 301 | GFP_KERNEL); |
WANG Cong | b9a24bb | 2016-08-19 12:36:54 -0700 | [diff] [blame] | 302 | if (!exts->actions) |
| 303 | return -ENOMEM; |
WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 304 | #endif |
WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 305 | exts->action = action; |
| 306 | exts->police = police; |
WANG Cong | b9a24bb | 2016-08-19 12:36:54 -0700 | [diff] [blame] | 307 | return 0; |
WANG Cong | 33be627 | 2013-12-15 20:15:05 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Cong Wang | e4b95c4 | 2017-11-06 13:47:19 -0800 | [diff] [blame] | 310 | /* Return false if the netns is being destroyed in cleanup_net(). Callers |
| 311 | * need to do cleanup synchronously in this case, otherwise may race with |
| 312 | * tc_action_net_exit(). Return true for other cases. |
| 313 | */ |
| 314 | static inline bool tcf_exts_get_net(struct tcf_exts *exts) |
| 315 | { |
| 316 | #ifdef CONFIG_NET_CLS_ACT |
| 317 | exts->net = maybe_get_net(exts->net); |
| 318 | return exts->net != NULL; |
| 319 | #else |
| 320 | return true; |
| 321 | #endif |
| 322 | } |
| 323 | |
| 324 | static inline void tcf_exts_put_net(struct tcf_exts *exts) |
| 325 | { |
| 326 | #ifdef CONFIG_NET_CLS_ACT |
| 327 | if (exts->net) |
| 328 | put_net(exts->net); |
| 329 | #endif |
| 330 | } |
| 331 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 332 | #ifdef CONFIG_NET_CLS_ACT |
Cong Wang | 244cd96 | 2018-08-19 12:22:09 -0700 | [diff] [blame] | 333 | #define tcf_exts_for_each_action(i, a, exts) \ |
| 334 | for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++) |
| 335 | #else |
| 336 | #define tcf_exts_for_each_action(i, a, exts) \ |
Arnd Bergmann | 191672c | 2018-08-22 17:25:44 +0200 | [diff] [blame] | 337 | for (; 0; (void)(i), (void)(a), (void)(exts)) |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 338 | #endif |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 339 | |
Jakub Kicinski | d897a63 | 2017-05-31 08:06:43 -0700 | [diff] [blame] | 340 | static inline void |
| 341 | tcf_exts_stats_update(const struct tcf_exts *exts, |
| 342 | u64 bytes, u64 packets, u64 lastuse) |
| 343 | { |
| 344 | #ifdef CONFIG_NET_CLS_ACT |
| 345 | int i; |
| 346 | |
| 347 | preempt_disable(); |
| 348 | |
| 349 | for (i = 0; i < exts->nr_actions; i++) { |
| 350 | struct tc_action *a = exts->actions[i]; |
| 351 | |
Eelco Chaudron | 28169ab | 2018-09-21 07:14:02 -0400 | [diff] [blame] | 352 | tcf_action_stats_update(a, bytes, packets, lastuse, true); |
Jakub Kicinski | d897a63 | 2017-05-31 08:06:43 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | preempt_enable(); |
| 356 | #endif |
| 357 | } |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /** |
Jiri Pirko | 3bcc0ce | 2017-08-04 14:28:58 +0200 | [diff] [blame] | 360 | * tcf_exts_has_actions - check if at least one action is present |
| 361 | * @exts: tc filter extensions handle |
| 362 | * |
| 363 | * Returns true if at least one action is present. |
| 364 | */ |
| 365 | static inline bool tcf_exts_has_actions(struct tcf_exts *exts) |
| 366 | { |
WANG Cong | 2734437e | 2016-08-13 22:34:59 -0700 | [diff] [blame] | 367 | #ifdef CONFIG_NET_CLS_ACT |
Jiri Pirko | 3bcc0ce | 2017-08-04 14:28:58 +0200 | [diff] [blame] | 368 | return exts->nr_actions; |
| 369 | #else |
| 370 | return false; |
| 371 | #endif |
| 372 | } |
WANG Cong | 2734437e | 2016-08-13 22:34:59 -0700 | [diff] [blame] | 373 | |
Jiri Pirko | 3bcc0ce | 2017-08-04 14:28:58 +0200 | [diff] [blame] | 374 | /** |
| 375 | * tcf_exts_has_one_action - check if exactly one action is present |
| 376 | * @exts: tc filter extensions handle |
| 377 | * |
| 378 | * Returns true if exactly one action is present. |
| 379 | */ |
| 380 | static inline bool tcf_exts_has_one_action(struct tcf_exts *exts) |
| 381 | { |
| 382 | #ifdef CONFIG_NET_CLS_ACT |
| 383 | return exts->nr_actions == 1; |
| 384 | #else |
| 385 | return false; |
| 386 | #endif |
| 387 | } |
WANG Cong | 2734437e | 2016-08-13 22:34:59 -0700 | [diff] [blame] | 388 | |
Cong Wang | 244cd96 | 2018-08-19 12:22:09 -0700 | [diff] [blame] | 389 | static inline struct tc_action *tcf_exts_first_action(struct tcf_exts *exts) |
| 390 | { |
| 391 | #ifdef CONFIG_NET_CLS_ACT |
| 392 | return exts->actions[0]; |
| 393 | #else |
| 394 | return NULL; |
| 395 | #endif |
| 396 | } |
| 397 | |
Jiri Pirko | af69afc | 2017-08-04 14:28:59 +0200 | [diff] [blame] | 398 | /** |
| 399 | * tcf_exts_exec - execute tc filter extensions |
| 400 | * @skb: socket buffer |
| 401 | * @exts: tc filter extensions handle |
| 402 | * @res: desired result |
| 403 | * |
Jiri Pirko | af089e7 | 2017-08-04 14:29:01 +0200 | [diff] [blame] | 404 | * Executes all configured extensions. Returns TC_ACT_OK on a normal execution, |
Jiri Pirko | af69afc | 2017-08-04 14:28:59 +0200 | [diff] [blame] | 405 | * a negative number if the filter must be considered unmatched or |
| 406 | * a positive action code (TC_ACT_*) which must be returned to the |
| 407 | * underlying layer. |
| 408 | */ |
| 409 | static inline int |
| 410 | tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, |
| 411 | struct tcf_result *res) |
| 412 | { |
| 413 | #ifdef CONFIG_NET_CLS_ACT |
Jiri Pirko | ec1a9cc | 2017-08-04 14:29:02 +0200 | [diff] [blame] | 414 | return tcf_action_exec(skb, exts->actions, exts->nr_actions, res); |
Jiri Pirko | af69afc | 2017-08-04 14:28:59 +0200 | [diff] [blame] | 415 | #endif |
Jiri Pirko | af089e7 | 2017-08-04 14:29:01 +0200 | [diff] [blame] | 416 | return TC_ACT_OK; |
Jiri Pirko | af69afc | 2017-08-04 14:28:59 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Joe Perches | 5c15257 | 2013-07-30 22:47:13 -0700 | [diff] [blame] | 419 | int tcf_exts_validate(struct net *net, struct tcf_proto *tp, |
| 420 | struct nlattr **tb, struct nlattr *rate_tlv, |
Vlad Buslov | ec6743a | 2019-02-11 10:55:43 +0200 | [diff] [blame] | 421 | struct tcf_exts *exts, bool ovr, bool rtnl_held, |
Alexander Aring | 50a5619 | 2018-01-18 11:20:52 -0500 | [diff] [blame] | 422 | struct netlink_ext_ack *extack); |
WANG Cong | 18d0264 | 2014-09-25 10:26:37 -0700 | [diff] [blame] | 423 | void tcf_exts_destroy(struct tcf_exts *exts); |
Jiri Pirko | 9b0d444 | 2017-08-04 14:29:15 +0200 | [diff] [blame] | 424 | void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src); |
WANG Cong | 5da57f4 | 2013-12-15 20:15:07 -0800 | [diff] [blame] | 425 | int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts); |
| 426 | int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * struct tcf_pkt_info - packet information |
| 430 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 431 | struct tcf_pkt_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | unsigned char * ptr; |
| 433 | int nexthdr; |
| 434 | }; |
| 435 | |
| 436 | #ifdef CONFIG_NET_EMATCH |
| 437 | |
| 438 | struct tcf_ematch_ops; |
| 439 | |
| 440 | /** |
| 441 | * struct tcf_ematch - extended match (ematch) |
| 442 | * |
| 443 | * @matchid: identifier to allow userspace to reidentify a match |
| 444 | * @flags: flags specifying attributes and the relation to other matches |
| 445 | * @ops: the operations lookup table of the corresponding ematch module |
| 446 | * @datalen: length of the ematch specific configuration data |
| 447 | * @data: ematch specific data |
| 448 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 449 | struct tcf_ematch { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | struct tcf_ematch_ops * ops; |
| 451 | unsigned long data; |
| 452 | unsigned int datalen; |
| 453 | u16 matchid; |
| 454 | u16 flags; |
John Fastabend | 82a470f | 2014-10-05 21:27:53 -0700 | [diff] [blame] | 455 | struct net *net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | static inline int tcf_em_is_container(struct tcf_ematch *em) |
| 459 | { |
| 460 | return !em->ops; |
| 461 | } |
| 462 | |
| 463 | static inline int tcf_em_is_simple(struct tcf_ematch *em) |
| 464 | { |
| 465 | return em->flags & TCF_EM_SIMPLE; |
| 466 | } |
| 467 | |
| 468 | static inline int tcf_em_is_inverted(struct tcf_ematch *em) |
| 469 | { |
| 470 | return em->flags & TCF_EM_INVERT; |
| 471 | } |
| 472 | |
| 473 | static inline int tcf_em_last_match(struct tcf_ematch *em) |
| 474 | { |
| 475 | return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END; |
| 476 | } |
| 477 | |
| 478 | static inline int tcf_em_early_end(struct tcf_ematch *em, int result) |
| 479 | { |
| 480 | if (tcf_em_last_match(em)) |
| 481 | return 1; |
| 482 | |
| 483 | if (result == 0 && em->flags & TCF_EM_REL_AND) |
| 484 | return 1; |
| 485 | |
| 486 | if (result != 0 && em->flags & TCF_EM_REL_OR) |
| 487 | return 1; |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * struct tcf_ematch_tree - ematch tree handle |
| 494 | * |
| 495 | * @hdr: ematch tree header supplied by userspace |
| 496 | * @matches: array of ematches |
| 497 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 498 | struct tcf_ematch_tree { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | struct tcf_ematch_tree_hdr hdr; |
| 500 | struct tcf_ematch * matches; |
| 501 | |
| 502 | }; |
| 503 | |
| 504 | /** |
| 505 | * struct tcf_ematch_ops - ematch module operations |
| 506 | * |
| 507 | * @kind: identifier (kind) of this ematch module |
| 508 | * @datalen: length of expected configuration data (optional) |
| 509 | * @change: called during validation (optional) |
| 510 | * @match: called during ematch tree evaluation, must return 1/0 |
| 511 | * @destroy: called during destroyage (optional) |
| 512 | * @dump: called during dumping process (optional) |
| 513 | * @owner: owner, must be set to THIS_MODULE |
| 514 | * @link: link to previous/next ematch module (internal use) |
| 515 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 516 | struct tcf_ematch_ops { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | int kind; |
| 518 | int datalen; |
John Fastabend | 82a470f | 2014-10-05 21:27:53 -0700 | [diff] [blame] | 519 | int (*change)(struct net *net, void *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | int, struct tcf_ematch *); |
| 521 | int (*match)(struct sk_buff *, struct tcf_ematch *, |
| 522 | struct tcf_pkt_info *); |
John Fastabend | 82a470f | 2014-10-05 21:27:53 -0700 | [diff] [blame] | 523 | void (*destroy)(struct tcf_ematch *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | int (*dump)(struct sk_buff *, struct tcf_ematch *); |
| 525 | struct module *owner; |
| 526 | struct list_head link; |
| 527 | }; |
| 528 | |
Joe Perches | 5c15257 | 2013-07-30 22:47:13 -0700 | [diff] [blame] | 529 | int tcf_em_register(struct tcf_ematch_ops *); |
| 530 | void tcf_em_unregister(struct tcf_ematch_ops *); |
| 531 | int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *, |
| 532 | struct tcf_ematch_tree *); |
John Fastabend | 82a470f | 2014-10-05 21:27:53 -0700 | [diff] [blame] | 533 | void tcf_em_tree_destroy(struct tcf_ematch_tree *); |
Joe Perches | 5c15257 | 2013-07-30 22:47:13 -0700 | [diff] [blame] | 534 | int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int); |
| 535 | int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *, |
| 536 | struct tcf_pkt_info *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | * tcf_em_tree_match - evaulate an ematch tree |
| 540 | * |
| 541 | * @skb: socket buffer of the packet in question |
| 542 | * @tree: ematch tree to be used for evaluation |
| 543 | * @info: packet information examined by classifier |
| 544 | * |
| 545 | * This function matches @skb against the ematch tree in @tree by going |
| 546 | * through all ematches respecting their logic relations returning |
| 547 | * as soon as the result is obvious. |
| 548 | * |
| 549 | * Returns 1 if the ematch tree as-one matches, no ematches are configured |
| 550 | * or ematch is not enabled in the kernel, otherwise 0 is returned. |
| 551 | */ |
| 552 | static inline int tcf_em_tree_match(struct sk_buff *skb, |
| 553 | struct tcf_ematch_tree *tree, |
| 554 | struct tcf_pkt_info *info) |
| 555 | { |
| 556 | if (tree->hdr.nmatches) |
| 557 | return __tcf_em_tree_match(skb, tree, info); |
| 558 | else |
| 559 | return 1; |
| 560 | } |
| 561 | |
Patrick McHardy | db3d99c | 2007-07-11 19:46:26 -0700 | [diff] [blame] | 562 | #define MODULE_ALIAS_TCF_EMATCH(kind) MODULE_ALIAS("ematch-kind-" __stringify(kind)) |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | #else /* CONFIG_NET_EMATCH */ |
| 565 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 566 | struct tcf_ematch_tree { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | }; |
| 568 | |
| 569 | #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0) |
John Fastabend | 82a470f | 2014-10-05 21:27:53 -0700 | [diff] [blame] | 570 | #define tcf_em_tree_destroy(t) do { (void)(t); } while(0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | #define tcf_em_tree_dump(skb, t, tlv) (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | #define tcf_em_tree_match(skb, t, info) ((void)(info), 1) |
| 573 | |
| 574 | #endif /* CONFIG_NET_EMATCH */ |
| 575 | |
| 576 | static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer) |
| 577 | { |
| 578 | switch (layer) { |
| 579 | case TCF_LAYER_LINK: |
Wolfgang Bumiller | d3303a6 | 2018-01-18 11:32:36 +0100 | [diff] [blame] | 580 | return skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | case TCF_LAYER_NETWORK: |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 582 | return skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | case TCF_LAYER_TRANSPORT: |
Arnaldo Carvalho de Melo | 9c70220 | 2007-04-25 18:04:18 -0700 | [diff] [blame] | 584 | return skb_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | return NULL; |
| 588 | } |
| 589 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 590 | static inline int tcf_valid_offset(const struct sk_buff *skb, |
| 591 | const unsigned char *ptr, const int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
David S. Miller | da521b2 | 2010-12-21 12:43:16 -0800 | [diff] [blame] | 593 | return likely((ptr + len) <= skb_tail_pointer(skb) && |
| 594 | ptr >= skb->head && |
| 595 | (ptr <= (ptr + len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | #ifdef CONFIG_NET_CLS_IND |
Denis V. Lunev | 0eeb8ff | 2007-12-04 01:15:45 -0800 | [diff] [blame] | 599 | #include <net/net_namespace.h> |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | static inline int |
Alexander Aring | 1057c55 | 2018-01-18 11:20:54 -0500 | [diff] [blame] | 602 | tcf_change_indev(struct net *net, struct nlattr *indev_tlv, |
| 603 | struct netlink_ext_ack *extack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
WANG Cong | 2519a60 | 2014-01-09 16:14:02 -0800 | [diff] [blame] | 605 | char indev[IFNAMSIZ]; |
Patrick McHardy | c01003c | 2007-03-29 11:46:52 -0700 | [diff] [blame] | 606 | struct net_device *dev; |
| 607 | |
Alexander Aring | 1057c55 | 2018-01-18 11:20:54 -0500 | [diff] [blame] | 608 | if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) { |
| 609 | NL_SET_ERR_MSG(extack, "Interface name too long"); |
WANG Cong | 2519a60 | 2014-01-09 16:14:02 -0800 | [diff] [blame] | 610 | return -EINVAL; |
Alexander Aring | 1057c55 | 2018-01-18 11:20:54 -0500 | [diff] [blame] | 611 | } |
WANG Cong | 2519a60 | 2014-01-09 16:14:02 -0800 | [diff] [blame] | 612 | dev = __dev_get_by_name(net, indev); |
| 613 | if (!dev) |
| 614 | return -ENODEV; |
| 615 | return dev->ifindex; |
| 616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
WANG Cong | 2519a60 | 2014-01-09 16:14:02 -0800 | [diff] [blame] | 618 | static inline bool |
| 619 | tcf_match_indev(struct sk_buff *skb, int ifindex) |
| 620 | { |
| 621 | if (!ifindex) |
| 622 | return true; |
| 623 | if (!skb->skb_iif) |
| 624 | return false; |
| 625 | return ifindex == skb->skb_iif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | #endif /* CONFIG_NET_CLS_IND */ |
| 628 | |
Pablo Neira Ayuso | 3a7b686 | 2019-02-02 12:50:46 +0100 | [diff] [blame] | 629 | int tc_setup_flow_action(struct flow_action *flow_action, |
| 630 | const struct tcf_exts *exts); |
Cong Wang | aeb3fec | 2018-12-11 11:15:46 -0800 | [diff] [blame] | 631 | int tc_setup_cb_call(struct tcf_block *block, enum tc_setup_type type, |
| 632 | void *type_data, bool err_stop); |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 633 | unsigned int tcf_exts_num_actions(struct tcf_exts *exts); |
Jiri Pirko | 717503b | 2017-10-11 09:41:09 +0200 | [diff] [blame] | 634 | |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 635 | enum tc_block_command { |
| 636 | TC_BLOCK_BIND, |
| 637 | TC_BLOCK_UNBIND, |
| 638 | }; |
| 639 | |
| 640 | struct tc_block_offload { |
| 641 | enum tc_block_command command; |
| 642 | enum tcf_block_binder_type binder_type; |
| 643 | struct tcf_block *block; |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 644 | struct netlink_ext_ack *extack; |
Jiri Pirko | 8c4083b | 2017-10-19 15:50:29 +0200 | [diff] [blame] | 645 | }; |
| 646 | |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 647 | struct tc_cls_common_offload { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 648 | u32 chain_index; |
| 649 | __be16 protocol; |
Jiri Pirko | d7c1c8d | 2017-08-07 10:15:30 +0200 | [diff] [blame] | 650 | u32 prio; |
Quentin Monnet | 8f0b425 | 2018-01-19 17:44:47 -0800 | [diff] [blame] | 651 | struct netlink_ext_ack *extack; |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 652 | }; |
| 653 | |
John Fastabend | a1b7c5f | 2016-02-16 21:17:09 -0800 | [diff] [blame] | 654 | struct tc_cls_u32_knode { |
| 655 | struct tcf_exts *exts; |
Jakub Kicinski | 068ceb3 | 2018-11-19 15:21:46 -0800 | [diff] [blame] | 656 | struct tcf_result *res; |
John Fastabend | e014860 | 2016-02-17 14:59:30 -0800 | [diff] [blame] | 657 | struct tc_u32_sel *sel; |
John Fastabend | a1b7c5f | 2016-02-16 21:17:09 -0800 | [diff] [blame] | 658 | u32 handle; |
| 659 | u32 val; |
| 660 | u32 mask; |
| 661 | u32 link_handle; |
John Fastabend | e014860 | 2016-02-17 14:59:30 -0800 | [diff] [blame] | 662 | u8 fshift; |
John Fastabend | a1b7c5f | 2016-02-16 21:17:09 -0800 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | struct tc_cls_u32_hnode { |
| 666 | u32 handle; |
| 667 | u32 prio; |
| 668 | unsigned int divisor; |
| 669 | }; |
| 670 | |
| 671 | enum tc_clsu32_command { |
| 672 | TC_CLSU32_NEW_KNODE, |
| 673 | TC_CLSU32_REPLACE_KNODE, |
| 674 | TC_CLSU32_DELETE_KNODE, |
| 675 | TC_CLSU32_NEW_HNODE, |
| 676 | TC_CLSU32_REPLACE_HNODE, |
| 677 | TC_CLSU32_DELETE_HNODE, |
| 678 | }; |
| 679 | |
| 680 | struct tc_cls_u32_offload { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 681 | struct tc_cls_common_offload common; |
John Fastabend | a1b7c5f | 2016-02-16 21:17:09 -0800 | [diff] [blame] | 682 | /* knode values */ |
| 683 | enum tc_clsu32_command command; |
| 684 | union { |
| 685 | struct tc_cls_u32_knode knode; |
| 686 | struct tc_cls_u32_hnode hnode; |
| 687 | }; |
| 688 | }; |
| 689 | |
Jiri Pirko | 7b06e8a | 2017-08-09 14:30:35 +0200 | [diff] [blame] | 690 | static inline bool tc_can_offload(const struct net_device *dev) |
John Fastabend | 6843e7a | 2016-02-26 07:53:49 -0800 | [diff] [blame] | 691 | { |
Jiri Pirko | 70b5aee | 2017-11-01 11:47:41 +0100 | [diff] [blame] | 692 | return dev->features & NETIF_F_HW_TC; |
John Fastabend | 6843e7a | 2016-02-26 07:53:49 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Quentin Monnet | f9eda14 | 2018-01-19 17:44:48 -0800 | [diff] [blame] | 695 | static inline bool tc_can_offload_extack(const struct net_device *dev, |
| 696 | struct netlink_ext_ack *extack) |
| 697 | { |
| 698 | bool can = tc_can_offload(dev); |
| 699 | |
| 700 | if (!can) |
| 701 | NL_SET_ERR_MSG(extack, "TC offload is disabled on net device"); |
| 702 | |
| 703 | return can; |
| 704 | } |
| 705 | |
Jakub Kicinski | 878db9f | 2018-01-25 14:00:43 -0800 | [diff] [blame] | 706 | static inline bool |
| 707 | tc_cls_can_offload_and_chain0(const struct net_device *dev, |
| 708 | struct tc_cls_common_offload *common) |
| 709 | { |
| 710 | if (!tc_can_offload_extack(dev, common->extack)) |
| 711 | return false; |
| 712 | if (common->chain_index) { |
| 713 | NL_SET_ERR_MSG(common->extack, |
| 714 | "Driver supports only offload of chain 0"); |
| 715 | return false; |
| 716 | } |
| 717 | return true; |
| 718 | } |
| 719 | |
Hadar Hen Zion | 55330f0 | 2016-12-01 14:06:33 +0200 | [diff] [blame] | 720 | static inline bool tc_skip_hw(u32 flags) |
| 721 | { |
| 722 | return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false; |
| 723 | } |
| 724 | |
Samudrala, Sridhar | d34e3e1 | 2016-05-12 17:08:23 -0700 | [diff] [blame] | 725 | static inline bool tc_skip_sw(u32 flags) |
| 726 | { |
| 727 | return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false; |
| 728 | } |
| 729 | |
| 730 | /* SKIP_HW and SKIP_SW are mutually exclusive flags. */ |
| 731 | static inline bool tc_flags_valid(u32 flags) |
| 732 | { |
Marcelo Ricardo Leitner | 81c7288 | 2018-05-13 17:44:27 -0300 | [diff] [blame] | 733 | if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW | |
| 734 | TCA_CLS_FLAGS_VERBOSE)) |
Samudrala, Sridhar | d34e3e1 | 2016-05-12 17:08:23 -0700 | [diff] [blame] | 735 | return false; |
| 736 | |
Marcelo Ricardo Leitner | 81c7288 | 2018-05-13 17:44:27 -0300 | [diff] [blame] | 737 | flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW; |
Samudrala, Sridhar | d34e3e1 | 2016-05-12 17:08:23 -0700 | [diff] [blame] | 738 | if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW))) |
| 739 | return false; |
| 740 | |
| 741 | return true; |
| 742 | } |
| 743 | |
Or Gerlitz | e696028 | 2017-02-16 10:31:12 +0200 | [diff] [blame] | 744 | static inline bool tc_in_hw(u32 flags) |
| 745 | { |
| 746 | return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false; |
| 747 | } |
| 748 | |
Jakub Kicinski | 34832e1 | 2018-01-24 12:54:14 -0800 | [diff] [blame] | 749 | static inline void |
| 750 | tc_cls_common_offload_init(struct tc_cls_common_offload *cls_common, |
| 751 | const struct tcf_proto *tp, u32 flags, |
| 752 | struct netlink_ext_ack *extack) |
| 753 | { |
| 754 | cls_common->chain_index = tp->chain->index; |
| 755 | cls_common->protocol = tp->protocol; |
| 756 | cls_common->prio = tp->prio; |
Marcelo Ricardo Leitner | 81c7288 | 2018-05-13 17:44:27 -0300 | [diff] [blame] | 757 | if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE) |
Jakub Kicinski | 34832e1 | 2018-01-24 12:54:14 -0800 | [diff] [blame] | 758 | cls_common->extack = extack; |
| 759 | } |
| 760 | |
Amir Vadai | 5b33f48 | 2016-03-08 12:42:29 +0200 | [diff] [blame] | 761 | enum tc_fl_command { |
| 762 | TC_CLSFLOWER_REPLACE, |
| 763 | TC_CLSFLOWER_DESTROY, |
Amir Vadai | 10cbc68 | 2016-05-13 12:55:37 +0000 | [diff] [blame] | 764 | TC_CLSFLOWER_STATS, |
Jiri Pirko | 3473845 | 2018-07-23 09:23:11 +0200 | [diff] [blame] | 765 | TC_CLSFLOWER_TMPLT_CREATE, |
| 766 | TC_CLSFLOWER_TMPLT_DESTROY, |
Amir Vadai | 5b33f48 | 2016-03-08 12:42:29 +0200 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | struct tc_cls_flower_offload { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 770 | struct tc_cls_common_offload common; |
Amir Vadai | 5b33f48 | 2016-03-08 12:42:29 +0200 | [diff] [blame] | 771 | enum tc_fl_command command; |
Amir Vadai | 8208d21 | 2016-03-11 11:08:45 +0200 | [diff] [blame] | 772 | unsigned long cookie; |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 773 | struct flow_rule *rule; |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 774 | struct flow_stats stats; |
Amritha Nambiar | 384c181 | 2017-10-27 02:35:34 -0700 | [diff] [blame] | 775 | u32 classid; |
Amir Vadai | 5b33f48 | 2016-03-08 12:42:29 +0200 | [diff] [blame] | 776 | }; |
| 777 | |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 778 | static inline struct flow_rule * |
| 779 | tc_cls_flower_offload_flow_rule(struct tc_cls_flower_offload *tc_flow_cmd) |
| 780 | { |
| 781 | return tc_flow_cmd->rule; |
| 782 | } |
| 783 | |
Yotam Gigi | b87f793 | 2016-07-21 12:03:12 +0200 | [diff] [blame] | 784 | enum tc_matchall_command { |
| 785 | TC_CLSMATCHALL_REPLACE, |
| 786 | TC_CLSMATCHALL_DESTROY, |
| 787 | }; |
| 788 | |
| 789 | struct tc_cls_matchall_offload { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 790 | struct tc_cls_common_offload common; |
Yotam Gigi | b87f793 | 2016-07-21 12:03:12 +0200 | [diff] [blame] | 791 | enum tc_matchall_command command; |
| 792 | struct tcf_exts *exts; |
| 793 | unsigned long cookie; |
| 794 | }; |
| 795 | |
Jakub Kicinski | 332ae8e | 2016-09-21 11:43:53 +0100 | [diff] [blame] | 796 | enum tc_clsbpf_command { |
Jakub Kicinski | 102740b | 2017-12-19 13:32:13 -0800 | [diff] [blame] | 797 | TC_CLSBPF_OFFLOAD, |
Jakub Kicinski | 68d6406 | 2016-09-21 11:44:02 +0100 | [diff] [blame] | 798 | TC_CLSBPF_STATS, |
Jakub Kicinski | 332ae8e | 2016-09-21 11:43:53 +0100 | [diff] [blame] | 799 | }; |
| 800 | |
| 801 | struct tc_cls_bpf_offload { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 802 | struct tc_cls_common_offload common; |
Jakub Kicinski | 332ae8e | 2016-09-21 11:43:53 +0100 | [diff] [blame] | 803 | enum tc_clsbpf_command command; |
| 804 | struct tcf_exts *exts; |
| 805 | struct bpf_prog *prog; |
Jakub Kicinski | 102740b | 2017-12-19 13:32:13 -0800 | [diff] [blame] | 806 | struct bpf_prog *oldprog; |
Jakub Kicinski | 332ae8e | 2016-09-21 11:43:53 +0100 | [diff] [blame] | 807 | const char *name; |
| 808 | bool exts_integrated; |
| 809 | }; |
| 810 | |
Amritha Nambiar | 4e8b86c | 2017-09-07 04:00:06 -0700 | [diff] [blame] | 811 | struct tc_mqprio_qopt_offload { |
| 812 | /* struct tc_mqprio_qopt must always be the first element */ |
| 813 | struct tc_mqprio_qopt qopt; |
| 814 | u16 mode; |
| 815 | u16 shaper; |
| 816 | u32 flags; |
| 817 | u64 min_rate[TC_QOPT_MAX_QUEUE]; |
| 818 | u64 max_rate[TC_QOPT_MAX_QUEUE]; |
| 819 | }; |
Jamal Hadi Salim | 1045ba7 | 2017-01-24 07:02:41 -0500 | [diff] [blame] | 820 | |
| 821 | /* This structure holds cookie structure that is passed from user |
| 822 | * to the kernel for actions and classifiers |
| 823 | */ |
| 824 | struct tc_cookie { |
| 825 | u8 *data; |
| 826 | u32 len; |
Vlad Buslov | eec94fd | 2018-07-05 17:24:23 +0300 | [diff] [blame] | 827 | struct rcu_head rcu; |
Jamal Hadi Salim | 1045ba7 | 2017-01-24 07:02:41 -0500 | [diff] [blame] | 828 | }; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 829 | |
Nogah Frankel | f34b4aa | 2018-01-10 14:59:58 +0100 | [diff] [blame] | 830 | struct tc_qopt_offload_stats { |
| 831 | struct gnet_stats_basic_packed *bstats; |
| 832 | struct gnet_stats_queue *qstats; |
| 833 | }; |
| 834 | |
Jakub Kicinski | f971b13 | 2018-05-25 21:53:35 -0700 | [diff] [blame] | 835 | enum tc_mq_command { |
| 836 | TC_MQ_CREATE, |
| 837 | TC_MQ_DESTROY, |
Jakub Kicinski | 47c669a4 | 2018-05-25 21:53:37 -0700 | [diff] [blame] | 838 | TC_MQ_STATS, |
Jakub Kicinski | d577a3d | 2018-11-12 14:58:14 -0800 | [diff] [blame] | 839 | TC_MQ_GRAFT, |
| 840 | }; |
| 841 | |
| 842 | struct tc_mq_opt_offload_graft_params { |
| 843 | unsigned long queue; |
| 844 | u32 child_handle; |
Jakub Kicinski | f971b13 | 2018-05-25 21:53:35 -0700 | [diff] [blame] | 845 | }; |
| 846 | |
| 847 | struct tc_mq_qopt_offload { |
| 848 | enum tc_mq_command command; |
| 849 | u32 handle; |
Jakub Kicinski | d577a3d | 2018-11-12 14:58:14 -0800 | [diff] [blame] | 850 | union { |
| 851 | struct tc_qopt_offload_stats stats; |
| 852 | struct tc_mq_opt_offload_graft_params graft_params; |
| 853 | }; |
Jakub Kicinski | f971b13 | 2018-05-25 21:53:35 -0700 | [diff] [blame] | 854 | }; |
| 855 | |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 856 | enum tc_red_command { |
| 857 | TC_RED_REPLACE, |
| 858 | TC_RED_DESTROY, |
| 859 | TC_RED_STATS, |
| 860 | TC_RED_XSTATS, |
Jakub Kicinski | bf2a752 | 2018-11-12 14:58:13 -0800 | [diff] [blame] | 861 | TC_RED_GRAFT, |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 862 | }; |
| 863 | |
| 864 | struct tc_red_qopt_offload_params { |
| 865 | u32 min; |
| 866 | u32 max; |
| 867 | u32 probability; |
Jakub Kicinski | c0b7490 | 2018-11-12 14:58:16 -0800 | [diff] [blame] | 868 | u32 limit; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 869 | bool is_ecn; |
Jakub Kicinski | 190852a | 2018-11-08 19:50:38 -0800 | [diff] [blame] | 870 | bool is_harddrop; |
Jakub Kicinski | 416ef9b | 2018-01-14 20:01:26 -0800 | [diff] [blame] | 871 | struct gnet_stats_queue *qstats; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 872 | }; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 873 | |
| 874 | struct tc_red_qopt_offload { |
| 875 | enum tc_red_command command; |
| 876 | u32 handle; |
| 877 | u32 parent; |
| 878 | union { |
| 879 | struct tc_red_qopt_offload_params set; |
Nogah Frankel | f34b4aa | 2018-01-10 14:59:58 +0100 | [diff] [blame] | 880 | struct tc_qopt_offload_stats stats; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 881 | struct red_stats *xstats; |
Jakub Kicinski | bf2a752 | 2018-11-12 14:58:13 -0800 | [diff] [blame] | 882 | u32 child_handle; |
Nogah Frankel | 602f3ba | 2017-11-06 07:23:41 +0100 | [diff] [blame] | 883 | }; |
| 884 | }; |
| 885 | |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 886 | enum tc_gred_command { |
| 887 | TC_GRED_REPLACE, |
| 888 | TC_GRED_DESTROY, |
Jakub Kicinski | e49efd5 | 2018-11-19 15:21:43 -0800 | [diff] [blame] | 889 | TC_GRED_STATS, |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 890 | }; |
| 891 | |
| 892 | struct tc_gred_vq_qopt_offload_params { |
| 893 | bool present; |
| 894 | u32 limit; |
| 895 | u32 prio; |
| 896 | u32 min; |
| 897 | u32 max; |
| 898 | bool is_ecn; |
| 899 | bool is_harddrop; |
| 900 | u32 probability; |
| 901 | /* Only need backlog, see struct tc_prio_qopt_offload_params */ |
| 902 | u32 *backlog; |
| 903 | }; |
| 904 | |
| 905 | struct tc_gred_qopt_offload_params { |
| 906 | bool grio_on; |
| 907 | bool wred_on; |
| 908 | unsigned int dp_cnt; |
| 909 | unsigned int dp_def; |
| 910 | struct gnet_stats_queue *qstats; |
| 911 | struct tc_gred_vq_qopt_offload_params tab[MAX_DPs]; |
| 912 | }; |
| 913 | |
Jakub Kicinski | e49efd5 | 2018-11-19 15:21:43 -0800 | [diff] [blame] | 914 | struct tc_gred_qopt_offload_stats { |
| 915 | struct gnet_stats_basic_packed bstats[MAX_DPs]; |
| 916 | struct gnet_stats_queue qstats[MAX_DPs]; |
| 917 | struct red_stats *xstats[MAX_DPs]; |
| 918 | }; |
| 919 | |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 920 | struct tc_gred_qopt_offload { |
| 921 | enum tc_gred_command command; |
| 922 | u32 handle; |
| 923 | u32 parent; |
| 924 | union { |
| 925 | struct tc_gred_qopt_offload_params set; |
Jakub Kicinski | e49efd5 | 2018-11-19 15:21:43 -0800 | [diff] [blame] | 926 | struct tc_gred_qopt_offload_stats stats; |
Jakub Kicinski | 890d8d2 | 2018-11-19 15:21:42 -0800 | [diff] [blame] | 927 | }; |
| 928 | }; |
| 929 | |
Nogah Frankel | 7fdb61b | 2018-01-14 12:33:15 +0100 | [diff] [blame] | 930 | enum tc_prio_command { |
| 931 | TC_PRIO_REPLACE, |
| 932 | TC_PRIO_DESTROY, |
| 933 | TC_PRIO_STATS, |
Nogah Frankel | b9c7a7a | 2018-02-28 10:45:06 +0100 | [diff] [blame] | 934 | TC_PRIO_GRAFT, |
Nogah Frankel | 7fdb61b | 2018-01-14 12:33:15 +0100 | [diff] [blame] | 935 | }; |
| 936 | |
| 937 | struct tc_prio_qopt_offload_params { |
| 938 | int bands; |
| 939 | u8 priomap[TC_PRIO_MAX + 1]; |
| 940 | /* In case that a prio qdisc is offloaded and now is changed to a |
| 941 | * non-offloadedable config, it needs to update the backlog & qlen |
| 942 | * values to negate the HW backlog & qlen values (and only them). |
| 943 | */ |
| 944 | struct gnet_stats_queue *qstats; |
| 945 | }; |
| 946 | |
Nogah Frankel | b9c7a7a | 2018-02-28 10:45:06 +0100 | [diff] [blame] | 947 | struct tc_prio_qopt_offload_graft_params { |
| 948 | u8 band; |
| 949 | u32 child_handle; |
| 950 | }; |
| 951 | |
Nogah Frankel | 7fdb61b | 2018-01-14 12:33:15 +0100 | [diff] [blame] | 952 | struct tc_prio_qopt_offload { |
| 953 | enum tc_prio_command command; |
| 954 | u32 handle; |
| 955 | u32 parent; |
| 956 | union { |
| 957 | struct tc_prio_qopt_offload_params replace_params; |
| 958 | struct tc_qopt_offload_stats stats; |
Nogah Frankel | b9c7a7a | 2018-02-28 10:45:06 +0100 | [diff] [blame] | 959 | struct tc_prio_qopt_offload_graft_params graft_params; |
Nogah Frankel | 7fdb61b | 2018-01-14 12:33:15 +0100 | [diff] [blame] | 960 | }; |
| 961 | }; |
Nogah Frankel | b9c7a7a | 2018-02-28 10:45:06 +0100 | [diff] [blame] | 962 | |
Jakub Kicinski | 98b0e5f | 2018-11-12 14:58:10 -0800 | [diff] [blame] | 963 | enum tc_root_command { |
| 964 | TC_ROOT_GRAFT, |
| 965 | }; |
| 966 | |
| 967 | struct tc_root_qopt_offload { |
| 968 | enum tc_root_command command; |
| 969 | u32 handle; |
| 970 | bool ingress; |
| 971 | }; |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | #endif |