Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 1 | #ifndef _NET_FLOW_OFFLOAD_H |
| 2 | #define _NET_FLOW_OFFLOAD_H |
| 3 | |
Edward Cree | fa85999 | 2019-05-31 22:47:21 +0100 | [diff] [blame] | 4 | #include <linux/kernel.h> |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 5 | #include <linux/list.h> |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 6 | #include <linux/netlink.h> |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 7 | #include <net/flow_dissector.h> |
| 8 | |
| 9 | struct flow_match { |
| 10 | struct flow_dissector *dissector; |
| 11 | void *mask; |
| 12 | void *key; |
| 13 | }; |
| 14 | |
Jiri Pirko | 9558a83 | 2019-06-19 09:41:04 +0300 | [diff] [blame] | 15 | struct flow_match_meta { |
| 16 | struct flow_dissector_key_meta *key, *mask; |
| 17 | }; |
| 18 | |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 19 | struct flow_match_basic { |
| 20 | struct flow_dissector_key_basic *key, *mask; |
| 21 | }; |
| 22 | |
| 23 | struct flow_match_control { |
| 24 | struct flow_dissector_key_control *key, *mask; |
| 25 | }; |
| 26 | |
| 27 | struct flow_match_eth_addrs { |
| 28 | struct flow_dissector_key_eth_addrs *key, *mask; |
| 29 | }; |
| 30 | |
| 31 | struct flow_match_vlan { |
| 32 | struct flow_dissector_key_vlan *key, *mask; |
| 33 | }; |
| 34 | |
| 35 | struct flow_match_ipv4_addrs { |
| 36 | struct flow_dissector_key_ipv4_addrs *key, *mask; |
| 37 | }; |
| 38 | |
| 39 | struct flow_match_ipv6_addrs { |
| 40 | struct flow_dissector_key_ipv6_addrs *key, *mask; |
| 41 | }; |
| 42 | |
| 43 | struct flow_match_ip { |
| 44 | struct flow_dissector_key_ip *key, *mask; |
| 45 | }; |
| 46 | |
| 47 | struct flow_match_ports { |
| 48 | struct flow_dissector_key_ports *key, *mask; |
| 49 | }; |
| 50 | |
| 51 | struct flow_match_icmp { |
| 52 | struct flow_dissector_key_icmp *key, *mask; |
| 53 | }; |
| 54 | |
| 55 | struct flow_match_tcp { |
| 56 | struct flow_dissector_key_tcp *key, *mask; |
| 57 | }; |
| 58 | |
| 59 | struct flow_match_mpls { |
| 60 | struct flow_dissector_key_mpls *key, *mask; |
| 61 | }; |
| 62 | |
| 63 | struct flow_match_enc_keyid { |
| 64 | struct flow_dissector_key_keyid *key, *mask; |
| 65 | }; |
| 66 | |
| 67 | struct flow_match_enc_opts { |
| 68 | struct flow_dissector_key_enc_opts *key, *mask; |
| 69 | }; |
| 70 | |
Paul Blakey | ee1c45e | 2020-03-12 12:23:13 +0200 | [diff] [blame] | 71 | struct flow_match_ct { |
| 72 | struct flow_dissector_key_ct *key, *mask; |
| 73 | }; |
| 74 | |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 75 | struct flow_rule; |
| 76 | |
Jiri Pirko | 9558a83 | 2019-06-19 09:41:04 +0300 | [diff] [blame] | 77 | void flow_rule_match_meta(const struct flow_rule *rule, |
| 78 | struct flow_match_meta *out); |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 79 | void flow_rule_match_basic(const struct flow_rule *rule, |
| 80 | struct flow_match_basic *out); |
| 81 | void flow_rule_match_control(const struct flow_rule *rule, |
| 82 | struct flow_match_control *out); |
| 83 | void flow_rule_match_eth_addrs(const struct flow_rule *rule, |
| 84 | struct flow_match_eth_addrs *out); |
| 85 | void flow_rule_match_vlan(const struct flow_rule *rule, |
| 86 | struct flow_match_vlan *out); |
Edward Cree | bae9ed6 | 2019-05-14 21:18:12 +0100 | [diff] [blame] | 87 | void flow_rule_match_cvlan(const struct flow_rule *rule, |
| 88 | struct flow_match_vlan *out); |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 89 | void flow_rule_match_ipv4_addrs(const struct flow_rule *rule, |
| 90 | struct flow_match_ipv4_addrs *out); |
| 91 | void flow_rule_match_ipv6_addrs(const struct flow_rule *rule, |
| 92 | struct flow_match_ipv6_addrs *out); |
| 93 | void flow_rule_match_ip(const struct flow_rule *rule, |
| 94 | struct flow_match_ip *out); |
| 95 | void flow_rule_match_ports(const struct flow_rule *rule, |
| 96 | struct flow_match_ports *out); |
| 97 | void flow_rule_match_tcp(const struct flow_rule *rule, |
| 98 | struct flow_match_tcp *out); |
| 99 | void flow_rule_match_icmp(const struct flow_rule *rule, |
| 100 | struct flow_match_icmp *out); |
| 101 | void flow_rule_match_mpls(const struct flow_rule *rule, |
| 102 | struct flow_match_mpls *out); |
| 103 | void flow_rule_match_enc_control(const struct flow_rule *rule, |
| 104 | struct flow_match_control *out); |
| 105 | void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule, |
| 106 | struct flow_match_ipv4_addrs *out); |
| 107 | void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule, |
| 108 | struct flow_match_ipv6_addrs *out); |
| 109 | void flow_rule_match_enc_ip(const struct flow_rule *rule, |
| 110 | struct flow_match_ip *out); |
| 111 | void flow_rule_match_enc_ports(const struct flow_rule *rule, |
| 112 | struct flow_match_ports *out); |
| 113 | void flow_rule_match_enc_keyid(const struct flow_rule *rule, |
| 114 | struct flow_match_enc_keyid *out); |
| 115 | void flow_rule_match_enc_opts(const struct flow_rule *rule, |
| 116 | struct flow_match_enc_opts *out); |
Paul Blakey | ee1c45e | 2020-03-12 12:23:13 +0200 | [diff] [blame] | 117 | void flow_rule_match_ct(const struct flow_rule *rule, |
| 118 | struct flow_match_ct *out); |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 119 | |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 120 | enum flow_action_id { |
| 121 | FLOW_ACTION_ACCEPT = 0, |
| 122 | FLOW_ACTION_DROP, |
| 123 | FLOW_ACTION_TRAP, |
| 124 | FLOW_ACTION_GOTO, |
| 125 | FLOW_ACTION_REDIRECT, |
| 126 | FLOW_ACTION_MIRRED, |
John Hurley | 48e584a | 2019-08-04 16:09:06 +0100 | [diff] [blame] | 127 | FLOW_ACTION_REDIRECT_INGRESS, |
| 128 | FLOW_ACTION_MIRRED_INGRESS, |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 129 | FLOW_ACTION_VLAN_PUSH, |
| 130 | FLOW_ACTION_VLAN_POP, |
| 131 | FLOW_ACTION_VLAN_MANGLE, |
| 132 | FLOW_ACTION_TUNNEL_ENCAP, |
| 133 | FLOW_ACTION_TUNNEL_DECAP, |
| 134 | FLOW_ACTION_MANGLE, |
| 135 | FLOW_ACTION_ADD, |
| 136 | FLOW_ACTION_CSUM, |
| 137 | FLOW_ACTION_MARK, |
John Hurley | fb1b775 | 2019-08-04 16:09:04 +0100 | [diff] [blame] | 138 | FLOW_ACTION_PTYPE, |
Petr Machata | 2ce1241 | 2020-03-19 15:47:21 +0200 | [diff] [blame] | 139 | FLOW_ACTION_PRIORITY, |
Pablo Neira Ayuso | 8bec283 | 2019-02-02 12:50:50 +0100 | [diff] [blame] | 140 | FLOW_ACTION_WAKE, |
| 141 | FLOW_ACTION_QUEUE, |
Pieter Jansen van Vuuren | a7a7be6 | 2019-05-04 04:46:16 -0700 | [diff] [blame] | 142 | FLOW_ACTION_SAMPLE, |
Pieter Jansen van Vuuren | 8c8cfc6 | 2019-05-04 04:46:22 -0700 | [diff] [blame] | 143 | FLOW_ACTION_POLICE, |
Paul Blakey | b57dc7c | 2019-07-09 10:30:48 +0300 | [diff] [blame] | 144 | FLOW_ACTION_CT, |
Paul Blakey | 9c26ba9 | 2020-03-12 12:23:06 +0200 | [diff] [blame] | 145 | FLOW_ACTION_CT_METADATA, |
John Hurley | 6749d590 | 2019-07-23 15:33:59 +0100 | [diff] [blame] | 146 | FLOW_ACTION_MPLS_PUSH, |
| 147 | FLOW_ACTION_MPLS_POP, |
| 148 | FLOW_ACTION_MPLS_MANGLE, |
Po Liu | d29bdd6 | 2020-05-01 08:53:16 +0800 | [diff] [blame] | 149 | FLOW_ACTION_GATE, |
Pablo Neira Ayuso | 563ae55 | 2021-03-24 02:30:49 +0100 | [diff] [blame] | 150 | FLOW_ACTION_PPPOE_PUSH, |
Dmytro Linkin | 7a97875 | 2019-06-27 10:55:02 +0000 | [diff] [blame] | 151 | NUM_FLOW_ACTIONS, |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 152 | }; |
| 153 | |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 154 | /* This is mirroring enum pedit_header_type definition for easy mapping between |
| 155 | * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to |
| 156 | * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver. |
| 157 | */ |
| 158 | enum flow_action_mangle_base { |
| 159 | FLOW_ACT_MANGLE_UNSPEC = 0, |
| 160 | FLOW_ACT_MANGLE_HDR_TYPE_ETH, |
| 161 | FLOW_ACT_MANGLE_HDR_TYPE_IP4, |
| 162 | FLOW_ACT_MANGLE_HDR_TYPE_IP6, |
| 163 | FLOW_ACT_MANGLE_HDR_TYPE_TCP, |
| 164 | FLOW_ACT_MANGLE_HDR_TYPE_UDP, |
| 165 | }; |
| 166 | |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 167 | enum flow_action_hw_stats_bit { |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 168 | FLOW_ACTION_HW_STATS_IMMEDIATE_BIT, |
| 169 | FLOW_ACTION_HW_STATS_DELAYED_BIT, |
Pablo Neira Ayuso | 16f8036 | 2020-05-06 20:34:50 +0200 | [diff] [blame] | 170 | FLOW_ACTION_HW_STATS_DISABLED_BIT, |
Edward Cree | 060b638 | 2020-05-20 19:18:10 +0100 | [diff] [blame] | 171 | |
| 172 | FLOW_ACTION_HW_STATS_NUM_BITS |
Jiri Pirko | 42d5fe5 | 2020-03-10 16:49:08 +0100 | [diff] [blame] | 173 | }; |
| 174 | |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 175 | enum flow_action_hw_stats { |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 176 | FLOW_ACTION_HW_STATS_IMMEDIATE = |
| 177 | BIT(FLOW_ACTION_HW_STATS_IMMEDIATE_BIT), |
| 178 | FLOW_ACTION_HW_STATS_DELAYED = BIT(FLOW_ACTION_HW_STATS_DELAYED_BIT), |
| 179 | FLOW_ACTION_HW_STATS_ANY = FLOW_ACTION_HW_STATS_IMMEDIATE | |
| 180 | FLOW_ACTION_HW_STATS_DELAYED, |
Pablo Neira Ayuso | 16f8036 | 2020-05-06 20:34:50 +0200 | [diff] [blame] | 181 | FLOW_ACTION_HW_STATS_DISABLED = |
| 182 | BIT(FLOW_ACTION_HW_STATS_DISABLED_BIT), |
Edward Cree | 060b638 | 2020-05-20 19:18:10 +0100 | [diff] [blame] | 183 | FLOW_ACTION_HW_STATS_DONT_CARE = BIT(FLOW_ACTION_HW_STATS_NUM_BITS) - 1, |
Jiri Pirko | 42d5fe5 | 2020-03-10 16:49:08 +0100 | [diff] [blame] | 184 | }; |
Jiri Pirko | 2514921 | 2020-03-07 12:40:11 +0100 | [diff] [blame] | 185 | |
Vlad Buslov | 1158958 | 2019-09-13 18:28:39 +0300 | [diff] [blame] | 186 | typedef void (*action_destr)(void *priv); |
| 187 | |
Jiri Pirko | 2008495 | 2020-02-25 11:45:18 +0100 | [diff] [blame] | 188 | struct flow_action_cookie { |
| 189 | u32 cookie_len; |
| 190 | u8 cookie[]; |
| 191 | }; |
| 192 | |
| 193 | struct flow_action_cookie *flow_action_cookie_create(void *data, |
| 194 | unsigned int len, |
| 195 | gfp_t gfp); |
| 196 | void flow_action_cookie_destroy(struct flow_action_cookie *cookie); |
| 197 | |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 198 | struct flow_action_entry { |
| 199 | enum flow_action_id id; |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 200 | enum flow_action_hw_stats hw_stats; |
Vlad Buslov | 1158958 | 2019-09-13 18:28:39 +0300 | [diff] [blame] | 201 | action_destr destructor; |
| 202 | void *destructor_priv; |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 203 | union { |
| 204 | u32 chain_index; /* FLOW_ACTION_GOTO */ |
| 205 | struct net_device *dev; /* FLOW_ACTION_REDIRECT */ |
| 206 | struct { /* FLOW_ACTION_VLAN */ |
| 207 | u16 vid; |
| 208 | __be16 proto; |
| 209 | u8 prio; |
| 210 | } vlan; |
Petr Machata | 1f40be6 | 2020-03-26 16:01:09 +0200 | [diff] [blame] | 211 | struct { /* FLOW_ACTION_MANGLE */ |
| 212 | /* FLOW_ACTION_ADD */ |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 213 | enum flow_action_mangle_base htype; |
| 214 | u32 offset; |
| 215 | u32 mask; |
| 216 | u32 val; |
| 217 | } mangle; |
Vlad Buslov | 1158958 | 2019-09-13 18:28:39 +0300 | [diff] [blame] | 218 | struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */ |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 219 | u32 csum_flags; /* FLOW_ACTION_CSUM */ |
| 220 | u32 mark; /* FLOW_ACTION_MARK */ |
John Hurley | fb1b775 | 2019-08-04 16:09:04 +0100 | [diff] [blame] | 221 | u16 ptype; /* FLOW_ACTION_PTYPE */ |
Petr Machata | 2ce1241 | 2020-03-19 15:47:21 +0200 | [diff] [blame] | 222 | u32 priority; /* FLOW_ACTION_PRIORITY */ |
Pablo Neira Ayuso | 8bec283 | 2019-02-02 12:50:50 +0100 | [diff] [blame] | 223 | struct { /* FLOW_ACTION_QUEUE */ |
| 224 | u32 ctx; |
| 225 | u32 index; |
| 226 | u8 vf; |
| 227 | } queue; |
Pieter Jansen van Vuuren | a7a7be6 | 2019-05-04 04:46:16 -0700 | [diff] [blame] | 228 | struct { /* FLOW_ACTION_SAMPLE */ |
| 229 | struct psample_group *psample_group; |
| 230 | u32 rate; |
| 231 | u32 trunc_size; |
| 232 | bool truncate; |
| 233 | } sample; |
Pieter Jansen van Vuuren | 8c8cfc6 | 2019-05-04 04:46:22 -0700 | [diff] [blame] | 234 | struct { /* FLOW_ACTION_POLICE */ |
Po Liu | 627e39b | 2020-06-24 17:36:30 +0800 | [diff] [blame] | 235 | u32 index; |
Po Liu | 5f035af | 2020-06-29 14:54:16 +0800 | [diff] [blame] | 236 | u32 burst; |
Pieter Jansen van Vuuren | 8c8cfc6 | 2019-05-04 04:46:22 -0700 | [diff] [blame] | 237 | u64 rate_bytes_ps; |
Xingfeng Hu | 2566015 | 2021-03-12 15:08:29 +0100 | [diff] [blame] | 238 | u64 burst_pkt; |
| 239 | u64 rate_pkt_ps; |
Po Liu | 19e528d | 2020-06-24 17:36:28 +0800 | [diff] [blame] | 240 | u32 mtu; |
Pieter Jansen van Vuuren | 8c8cfc6 | 2019-05-04 04:46:22 -0700 | [diff] [blame] | 241 | } police; |
Paul Blakey | b57dc7c | 2019-07-09 10:30:48 +0300 | [diff] [blame] | 242 | struct { /* FLOW_ACTION_CT */ |
| 243 | int action; |
| 244 | u16 zone; |
Paul Blakey | edd5861 | 2020-03-12 12:23:09 +0200 | [diff] [blame] | 245 | struct nf_flowtable *flow_table; |
Paul Blakey | b57dc7c | 2019-07-09 10:30:48 +0300 | [diff] [blame] | 246 | } ct; |
Paul Blakey | 9c26ba9 | 2020-03-12 12:23:06 +0200 | [diff] [blame] | 247 | struct { |
Paul Blakey | 30b0cf9 | 2020-03-12 12:23:07 +0200 | [diff] [blame] | 248 | unsigned long cookie; |
Paul Blakey | 9c26ba9 | 2020-03-12 12:23:06 +0200 | [diff] [blame] | 249 | u32 mark; |
| 250 | u32 labels[4]; |
Paul Blakey | 941eff5 | 2021-01-27 16:32:46 +0200 | [diff] [blame] | 251 | bool orig_dir; |
Paul Blakey | 9c26ba9 | 2020-03-12 12:23:06 +0200 | [diff] [blame] | 252 | } ct_metadata; |
John Hurley | 6749d590 | 2019-07-23 15:33:59 +0100 | [diff] [blame] | 253 | struct { /* FLOW_ACTION_MPLS_PUSH */ |
| 254 | u32 label; |
| 255 | __be16 proto; |
| 256 | u8 tc; |
| 257 | u8 bos; |
| 258 | u8 ttl; |
| 259 | } mpls_push; |
| 260 | struct { /* FLOW_ACTION_MPLS_POP */ |
| 261 | __be16 proto; |
| 262 | } mpls_pop; |
| 263 | struct { /* FLOW_ACTION_MPLS_MANGLE */ |
| 264 | u32 label; |
| 265 | u8 tc; |
| 266 | u8 bos; |
| 267 | u8 ttl; |
| 268 | } mpls_mangle; |
Po Liu | d29bdd6 | 2020-05-01 08:53:16 +0800 | [diff] [blame] | 269 | struct { |
| 270 | u32 index; |
| 271 | s32 prio; |
| 272 | u64 basetime; |
| 273 | u64 cycletime; |
| 274 | u64 cycletimeext; |
| 275 | u32 num_entries; |
| 276 | struct action_gate_entry *entries; |
| 277 | } gate; |
Pablo Neira Ayuso | 563ae55 | 2021-03-24 02:30:49 +0100 | [diff] [blame] | 278 | struct { /* FLOW_ACTION_PPPOE_PUSH */ |
| 279 | u16 sid; |
| 280 | } pppoe; |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 281 | }; |
Jiri Pirko | 2008495 | 2020-02-25 11:45:18 +0100 | [diff] [blame] | 282 | struct flow_action_cookie *cookie; /* user defined action cookie */ |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | struct flow_action { |
| 286 | unsigned int num_entries; |
Gustavo A. R. Silva | 8661b6e | 2020-02-28 19:02:54 -0600 | [diff] [blame] | 287 | struct flow_action_entry entries[]; |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | static inline bool flow_action_has_entries(const struct flow_action *action) |
| 291 | { |
| 292 | return action->num_entries; |
| 293 | } |
| 294 | |
Pieter Jansen van Vuuren | ab79af3 | 2019-05-04 04:46:18 -0700 | [diff] [blame] | 295 | /** |
Bijie Xu | c87a4c5 | 2021-08-03 11:40:18 +0200 | [diff] [blame] | 296 | * flow_offload_has_one_action() - check if exactly one action is present |
Pieter Jansen van Vuuren | ab79af3 | 2019-05-04 04:46:18 -0700 | [diff] [blame] | 297 | * @action: tc filter flow offload action |
| 298 | * |
| 299 | * Returns true if exactly one action is present. |
| 300 | */ |
| 301 | static inline bool flow_offload_has_one_action(const struct flow_action *action) |
| 302 | { |
| 303 | return action->num_entries == 1; |
| 304 | } |
| 305 | |
Jiri Pirko | 62751b6 | 2020-03-10 11:11:57 +0100 | [diff] [blame] | 306 | #define flow_action_for_each(__i, __act, __actions) \ |
| 307 | for (__i = 0, __act = &(__actions)->entries[0]; \ |
| 308 | __i < (__actions)->num_entries; \ |
| 309 | __act = &(__actions)->entries[++__i]) |
| 310 | |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 311 | static inline bool |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 312 | flow_action_mixed_hw_stats_check(const struct flow_action *action, |
| 313 | struct netlink_ext_ack *extack) |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 314 | { |
| 315 | const struct flow_action_entry *action_entry; |
Kees Cook | 3f649ab | 2020-06-03 13:09:38 -0700 | [diff] [blame] | 316 | u8 last_hw_stats; |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 317 | int i; |
| 318 | |
| 319 | if (flow_offload_has_one_action(action)) |
| 320 | return true; |
| 321 | |
Ido Schimmel | fa05bdb | 2021-08-19 13:58:42 +0300 | [diff] [blame] | 322 | flow_action_for_each(i, action_entry, action) { |
| 323 | if (i && action_entry->hw_stats != last_hw_stats) { |
| 324 | NL_SET_ERR_MSG_MOD(extack, "Mixing HW stats types for actions is not supported"); |
| 325 | return false; |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 326 | } |
Ido Schimmel | fa05bdb | 2021-08-19 13:58:42 +0300 | [diff] [blame] | 327 | last_hw_stats = action_entry->hw_stats; |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 328 | } |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | static inline const struct flow_action_entry * |
| 333 | flow_action_first_entry_get(const struct flow_action *action) |
| 334 | { |
| 335 | WARN_ON(!flow_action_has_entries(action)); |
| 336 | return &action->entries[0]; |
| 337 | } |
| 338 | |
| 339 | static inline bool |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 340 | __flow_action_hw_stats_check(const struct flow_action *action, |
| 341 | struct netlink_ext_ack *extack, |
| 342 | bool check_allow_bit, |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 343 | enum flow_action_hw_stats_bit allow_bit) |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 344 | { |
| 345 | const struct flow_action_entry *action_entry; |
| 346 | |
| 347 | if (!flow_action_has_entries(action)) |
| 348 | return true; |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 349 | if (!flow_action_mixed_hw_stats_check(action, extack)) |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 350 | return false; |
Pablo Neira Ayuso | 16f8036 | 2020-05-06 20:34:50 +0200 | [diff] [blame] | 351 | |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 352 | action_entry = flow_action_first_entry_get(action); |
Edward Cree | 060b638 | 2020-05-20 19:18:10 +0100 | [diff] [blame] | 353 | |
| 354 | /* Zero is not a legal value for hw_stats, catch anyone passing it */ |
| 355 | WARN_ON_ONCE(!action_entry->hw_stats); |
Pablo Neira Ayuso | 16f8036 | 2020-05-06 20:34:50 +0200 | [diff] [blame] | 356 | |
Jiri Pirko | a16fa28 | 2020-03-10 16:49:09 +0100 | [diff] [blame] | 357 | if (!check_allow_bit && |
Edward Cree | 060b638 | 2020-05-20 19:18:10 +0100 | [diff] [blame] | 358 | ~action_entry->hw_stats & FLOW_ACTION_HW_STATS_ANY) { |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 359 | NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\""); |
| 360 | return false; |
Jiri Pirko | a16fa28 | 2020-03-10 16:49:09 +0100 | [diff] [blame] | 361 | } else if (check_allow_bit && |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 362 | !(action_entry->hw_stats & BIT(allow_bit))) { |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 363 | NL_SET_ERR_MSG_MOD(extack, "Driver does not support selected HW stats type"); |
| 364 | return false; |
| 365 | } |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | static inline bool |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 370 | flow_action_hw_stats_check(const struct flow_action *action, |
| 371 | struct netlink_ext_ack *extack, |
Jakub Kicinski | 0dfb2d8 | 2020-03-19 16:26:23 -0700 | [diff] [blame] | 372 | enum flow_action_hw_stats_bit allow_bit) |
Jiri Pirko | a16fa28 | 2020-03-10 16:49:09 +0100 | [diff] [blame] | 373 | { |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 374 | return __flow_action_hw_stats_check(action, extack, true, allow_bit); |
Jiri Pirko | a16fa28 | 2020-03-10 16:49:09 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static inline bool |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 378 | flow_action_basic_hw_stats_check(const struct flow_action *action, |
| 379 | struct netlink_ext_ack *extack) |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 380 | { |
Jakub Kicinski | 53eca1f | 2020-03-16 18:42:11 -0700 | [diff] [blame] | 381 | return __flow_action_hw_stats_check(action, extack, false, 0); |
Jiri Pirko | 319a1d1 | 2020-03-07 12:40:13 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Pablo Neira Ayuso | e3ab786 | 2019-02-02 12:50:45 +0100 | [diff] [blame] | 384 | struct flow_rule { |
| 385 | struct flow_match match; |
| 386 | struct flow_action action; |
| 387 | }; |
| 388 | |
| 389 | struct flow_rule *flow_rule_alloc(unsigned int num_actions); |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 390 | |
| 391 | static inline bool flow_rule_match_key(const struct flow_rule *rule, |
| 392 | enum flow_dissector_key_id key) |
| 393 | { |
| 394 | return dissector_uses_key(rule->match.dissector, key); |
| 395 | } |
| 396 | |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 397 | struct flow_stats { |
| 398 | u64 pkts; |
| 399 | u64 bytes; |
Po Liu | 4b61d3e | 2020-06-19 14:01:07 +0800 | [diff] [blame] | 400 | u64 drops; |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 401 | u64 lastused; |
Jiri Pirko | 93a129e | 2020-03-28 16:37:43 +0100 | [diff] [blame] | 402 | enum flow_action_hw_stats used_hw_stats; |
| 403 | bool used_hw_stats_valid; |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | static inline void flow_stats_update(struct flow_stats *flow_stats, |
Po Liu | 4b61d3e | 2020-06-19 14:01:07 +0800 | [diff] [blame] | 407 | u64 bytes, u64 pkts, |
| 408 | u64 drops, u64 lastused, |
Jiri Pirko | 93a129e | 2020-03-28 16:37:43 +0100 | [diff] [blame] | 409 | enum flow_action_hw_stats used_hw_stats) |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 410 | { |
John Hurley | 9f9dc49 | 2019-02-13 00:23:52 +0000 | [diff] [blame] | 411 | flow_stats->pkts += pkts; |
| 412 | flow_stats->bytes += bytes; |
Po Liu | 4b61d3e | 2020-06-19 14:01:07 +0800 | [diff] [blame] | 413 | flow_stats->drops += drops; |
John Hurley | 9f9dc49 | 2019-02-13 00:23:52 +0000 | [diff] [blame] | 414 | flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused); |
Jiri Pirko | 93a129e | 2020-03-28 16:37:43 +0100 | [diff] [blame] | 415 | |
| 416 | /* The driver should pass value with a maximum of one bit set. |
| 417 | * Passing FLOW_ACTION_HW_STATS_ANY is invalid. |
| 418 | */ |
| 419 | WARN_ON(used_hw_stats == FLOW_ACTION_HW_STATS_ANY); |
| 420 | flow_stats->used_hw_stats |= used_hw_stats; |
| 421 | flow_stats->used_hw_stats_valid = true; |
Pablo Neira Ayuso | 3b1903e | 2019-02-02 12:50:47 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 424 | enum flow_block_command { |
Pablo Neira Ayuso | 9c0e189 | 2019-07-09 22:55:40 +0200 | [diff] [blame] | 425 | FLOW_BLOCK_BIND, |
| 426 | FLOW_BLOCK_UNBIND, |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | enum flow_block_binder_type { |
Pablo Neira Ayuso | 32f8c40 | 2019-07-09 22:55:41 +0200 | [diff] [blame] | 430 | FLOW_BLOCK_BINDER_TYPE_UNSPEC, |
| 431 | FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS, |
| 432 | FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS, |
Petr Machata | aee9caa | 2020-06-27 01:45:28 +0300 | [diff] [blame] | 433 | FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP, |
| 434 | FLOW_BLOCK_BINDER_TYPE_RED_MARK, |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 435 | }; |
| 436 | |
Pablo Neira Ayuso | 14bfb13 | 2019-07-19 18:20:16 +0200 | [diff] [blame] | 437 | struct flow_block { |
| 438 | struct list_head cb_list; |
| 439 | }; |
| 440 | |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 441 | struct netlink_ext_ack; |
| 442 | |
| 443 | struct flow_block_offload { |
| 444 | enum flow_block_command command; |
| 445 | enum flow_block_binder_type binder_type; |
Pablo Neira Ayuso | 955bcb6 | 2019-07-09 22:55:46 +0200 | [diff] [blame] | 446 | bool block_shared; |
Vlad Buslov | c9f1447 | 2019-08-26 16:45:01 +0300 | [diff] [blame] | 447 | bool unlocked_driver_cb; |
Pablo Neira Ayuso | da3eeb9 | 2019-07-09 22:55:43 +0200 | [diff] [blame] | 448 | struct net *net; |
Pablo Neira Ayuso | 14bfb13 | 2019-07-19 18:20:16 +0200 | [diff] [blame] | 449 | struct flow_block *block; |
Pablo Neira Ayuso | da3eeb9 | 2019-07-09 22:55:43 +0200 | [diff] [blame] | 450 | struct list_head cb_list; |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 451 | struct list_head *driver_block_list; |
| 452 | struct netlink_ext_ack *extack; |
Petr Machata | c40f4e5 | 2020-07-11 00:55:03 +0300 | [diff] [blame] | 453 | struct Qdisc *sch; |
Eli Cohen | 74fc4f8 | 2021-08-17 20:05:18 +0300 | [diff] [blame] | 454 | struct list_head *cb_list_head; |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 455 | }; |
| 456 | |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 457 | enum tc_setup_type; |
| 458 | typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data, |
| 459 | void *cb_priv); |
| 460 | |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 461 | struct flow_block_cb; |
| 462 | |
| 463 | struct flow_block_indr { |
| 464 | struct list_head list; |
| 465 | struct net_device *dev; |
Petr Machata | c40f4e5 | 2020-07-11 00:55:03 +0300 | [diff] [blame] | 466 | struct Qdisc *sch; |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 467 | enum flow_block_binder_type binder_type; |
| 468 | void *data; |
wenxu | a1db217 | 2020-06-18 20:49:10 +0800 | [diff] [blame] | 469 | void *cb_priv; |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 470 | void (*cleanup)(struct flow_block_cb *block_cb); |
| 471 | }; |
| 472 | |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 473 | struct flow_block_cb { |
Pablo Neira Ayuso | da3eeb9 | 2019-07-09 22:55:43 +0200 | [diff] [blame] | 474 | struct list_head driver_list; |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 475 | struct list_head list; |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 476 | flow_setup_cb_t *cb; |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 477 | void *cb_ident; |
| 478 | void *cb_priv; |
| 479 | void (*release)(void *cb_priv); |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 480 | struct flow_block_indr indr; |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 481 | unsigned int refcnt; |
| 482 | }; |
| 483 | |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 484 | struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb, |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 485 | void *cb_ident, void *cb_priv, |
| 486 | void (*release)(void *cb_priv)); |
wenxu | 26f2eb2 | 2020-06-18 20:49:08 +0800 | [diff] [blame] | 487 | struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb, |
| 488 | void *cb_ident, void *cb_priv, |
| 489 | void (*release)(void *cb_priv), |
| 490 | struct flow_block_offload *bo, |
Petr Machata | c40f4e5 | 2020-07-11 00:55:03 +0300 | [diff] [blame] | 491 | struct net_device *dev, |
| 492 | struct Qdisc *sch, void *data, |
wenxu | a1db217 | 2020-06-18 20:49:10 +0800 | [diff] [blame] | 493 | void *indr_cb_priv, |
wenxu | 26f2eb2 | 2020-06-18 20:49:08 +0800 | [diff] [blame] | 494 | void (*cleanup)(struct flow_block_cb *block_cb)); |
Pablo Neira Ayuso | d63db30 | 2019-07-09 22:55:42 +0200 | [diff] [blame] | 495 | void flow_block_cb_free(struct flow_block_cb *block_cb); |
| 496 | |
Pablo Neira Ayuso | 14bfb13 | 2019-07-19 18:20:16 +0200 | [diff] [blame] | 497 | struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block, |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 498 | flow_setup_cb_t *cb, void *cb_ident); |
Pablo Neira Ayuso | da3eeb9 | 2019-07-09 22:55:43 +0200 | [diff] [blame] | 499 | |
Pablo Neira Ayuso | 67bd0d5 | 2019-07-09 22:55:44 +0200 | [diff] [blame] | 500 | void *flow_block_cb_priv(struct flow_block_cb *block_cb); |
| 501 | void flow_block_cb_incref(struct flow_block_cb *block_cb); |
| 502 | unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb); |
| 503 | |
Pablo Neira Ayuso | da3eeb9 | 2019-07-09 22:55:43 +0200 | [diff] [blame] | 504 | static inline void flow_block_cb_add(struct flow_block_cb *block_cb, |
| 505 | struct flow_block_offload *offload) |
| 506 | { |
| 507 | list_add_tail(&block_cb->list, &offload->cb_list); |
| 508 | } |
| 509 | |
| 510 | static inline void flow_block_cb_remove(struct flow_block_cb *block_cb, |
| 511 | struct flow_block_offload *offload) |
| 512 | { |
| 513 | list_move(&block_cb->list, &offload->cb_list); |
| 514 | } |
| 515 | |
wenxu | 26f2eb2 | 2020-06-18 20:49:08 +0800 | [diff] [blame] | 516 | static inline void flow_indr_block_cb_remove(struct flow_block_cb *block_cb, |
| 517 | struct flow_block_offload *offload) |
| 518 | { |
| 519 | list_del(&block_cb->indr.list); |
| 520 | list_move(&block_cb->list, &offload->cb_list); |
| 521 | } |
| 522 | |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 523 | bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident, |
Pablo Neira Ayuso | 0d4fd02 | 2019-07-09 22:55:48 +0200 | [diff] [blame] | 524 | struct list_head *driver_block_list); |
| 525 | |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 526 | int flow_block_cb_setup_simple(struct flow_block_offload *f, |
Pablo Neira Ayuso | a732331 | 2019-07-19 18:20:15 +0200 | [diff] [blame] | 527 | struct list_head *driver_list, |
| 528 | flow_setup_cb_t *cb, |
Pablo Neira Ayuso | 4e95bc2 | 2019-07-09 22:55:39 +0200 | [diff] [blame] | 529 | void *cb_ident, void *cb_priv, bool ingress_only); |
| 530 | |
Pablo Neira Ayuso | f9e3008 | 2019-07-09 22:55:49 +0200 | [diff] [blame] | 531 | enum flow_cls_command { |
| 532 | FLOW_CLS_REPLACE, |
| 533 | FLOW_CLS_DESTROY, |
| 534 | FLOW_CLS_STATS, |
| 535 | FLOW_CLS_TMPLT_CREATE, |
| 536 | FLOW_CLS_TMPLT_DESTROY, |
| 537 | }; |
| 538 | |
| 539 | struct flow_cls_common_offload { |
| 540 | u32 chain_index; |
| 541 | __be16 protocol; |
| 542 | u32 prio; |
| 543 | struct netlink_ext_ack *extack; |
| 544 | }; |
| 545 | |
| 546 | struct flow_cls_offload { |
| 547 | struct flow_cls_common_offload common; |
| 548 | enum flow_cls_command command; |
| 549 | unsigned long cookie; |
| 550 | struct flow_rule *rule; |
| 551 | struct flow_stats stats; |
| 552 | u32 classid; |
| 553 | }; |
| 554 | |
| 555 | static inline struct flow_rule * |
| 556 | flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd) |
| 557 | { |
| 558 | return flow_cmd->rule; |
| 559 | } |
| 560 | |
Pablo Neira Ayuso | 14bfb13 | 2019-07-19 18:20:16 +0200 | [diff] [blame] | 561 | static inline void flow_block_init(struct flow_block *flow_block) |
| 562 | { |
| 563 | INIT_LIST_HEAD(&flow_block->cb_list); |
| 564 | } |
| 565 | |
Petr Machata | c40f4e5 | 2020-07-11 00:55:03 +0300 | [diff] [blame] | 566 | typedef int flow_indr_block_bind_cb_t(struct net_device *dev, struct Qdisc *sch, void *cb_priv, |
wenxu | 66f1939a | 2020-06-18 20:49:09 +0800 | [diff] [blame] | 567 | enum tc_setup_type type, void *type_data, |
| 568 | void *data, |
| 569 | void (*cleanup)(struct flow_block_cb *block_cb)); |
wenxu | 4e48190 | 2019-08-07 09:13:52 +0800 | [diff] [blame] | 570 | |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 571 | int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv); |
| 572 | void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv, |
wenxu | a1db217 | 2020-06-18 20:49:10 +0800 | [diff] [blame] | 573 | void (*release)(void *cb_priv)); |
Petr Machata | c40f4e5 | 2020-07-11 00:55:03 +0300 | [diff] [blame] | 574 | int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, |
Pablo Neira Ayuso | 1fac52d | 2020-05-29 02:25:35 +0200 | [diff] [blame] | 575 | enum tc_setup_type type, void *data, |
| 576 | struct flow_block_offload *bo, |
| 577 | void (*cleanup)(struct flow_block_cb *block_cb)); |
| 578 | |
Pablo Neira Ayuso | 8f25662 | 2019-02-02 12:50:43 +0100 | [diff] [blame] | 579 | #endif /* _NET_FLOW_OFFLOAD_H */ |