Commit | Line | Data |
---|---|---|
8f256622 PNA |
1 | #ifndef _NET_FLOW_OFFLOAD_H |
2 | #define _NET_FLOW_OFFLOAD_H | |
3 | ||
fa85999f | 4 | #include <linux/kernel.h> |
a7323311 | 5 | #include <linux/list.h> |
319a1d19 | 6 | #include <linux/netlink.h> |
8f256622 PNA |
7 | #include <net/flow_dissector.h> |
8 | ||
9 | struct flow_match { | |
10 | struct flow_dissector *dissector; | |
11 | void *mask; | |
12 | void *key; | |
13 | }; | |
14 | ||
9558a83a JP |
15 | struct flow_match_meta { |
16 | struct flow_dissector_key_meta *key, *mask; | |
17 | }; | |
18 | ||
8f256622 PNA |
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 | ||
83d85bb0 MG |
51 | struct flow_match_ports_range { |
52 | struct flow_dissector_key_ports_range *key, *mask; | |
53 | }; | |
54 | ||
8f256622 PNA |
55 | struct flow_match_icmp { |
56 | struct flow_dissector_key_icmp *key, *mask; | |
57 | }; | |
58 | ||
59 | struct flow_match_tcp { | |
60 | struct flow_dissector_key_tcp *key, *mask; | |
61 | }; | |
62 | ||
63 | struct flow_match_mpls { | |
64 | struct flow_dissector_key_mpls *key, *mask; | |
65 | }; | |
66 | ||
67 | struct flow_match_enc_keyid { | |
68 | struct flow_dissector_key_keyid *key, *mask; | |
69 | }; | |
70 | ||
71 | struct flow_match_enc_opts { | |
72 | struct flow_dissector_key_enc_opts *key, *mask; | |
73 | }; | |
74 | ||
ee1c45e8 PB |
75 | struct flow_match_ct { |
76 | struct flow_dissector_key_ct *key, *mask; | |
77 | }; | |
78 | ||
6a21b085 WD |
79 | struct flow_match_pppoe { |
80 | struct flow_dissector_key_pppoe *key, *mask; | |
81 | }; | |
82 | ||
2c1befac WD |
83 | struct flow_match_l2tpv3 { |
84 | struct flow_dissector_key_l2tpv3 *key, *mask; | |
85 | }; | |
86 | ||
8f256622 PNA |
87 | struct flow_rule; |
88 | ||
9558a83a JP |
89 | void flow_rule_match_meta(const struct flow_rule *rule, |
90 | struct flow_match_meta *out); | |
8f256622 PNA |
91 | void flow_rule_match_basic(const struct flow_rule *rule, |
92 | struct flow_match_basic *out); | |
93 | void flow_rule_match_control(const struct flow_rule *rule, | |
94 | struct flow_match_control *out); | |
95 | void flow_rule_match_eth_addrs(const struct flow_rule *rule, | |
96 | struct flow_match_eth_addrs *out); | |
97 | void flow_rule_match_vlan(const struct flow_rule *rule, | |
98 | struct flow_match_vlan *out); | |
bae9ed69 EC |
99 | void flow_rule_match_cvlan(const struct flow_rule *rule, |
100 | struct flow_match_vlan *out); | |
8f256622 PNA |
101 | void flow_rule_match_ipv4_addrs(const struct flow_rule *rule, |
102 | struct flow_match_ipv4_addrs *out); | |
103 | void flow_rule_match_ipv6_addrs(const struct flow_rule *rule, | |
104 | struct flow_match_ipv6_addrs *out); | |
105 | void flow_rule_match_ip(const struct flow_rule *rule, | |
106 | struct flow_match_ip *out); | |
107 | void flow_rule_match_ports(const struct flow_rule *rule, | |
108 | struct flow_match_ports *out); | |
83d85bb0 MG |
109 | void flow_rule_match_ports_range(const struct flow_rule *rule, |
110 | struct flow_match_ports_range *out); | |
8f256622 PNA |
111 | void flow_rule_match_tcp(const struct flow_rule *rule, |
112 | struct flow_match_tcp *out); | |
113 | void flow_rule_match_icmp(const struct flow_rule *rule, | |
114 | struct flow_match_icmp *out); | |
115 | void flow_rule_match_mpls(const struct flow_rule *rule, | |
116 | struct flow_match_mpls *out); | |
117 | void flow_rule_match_enc_control(const struct flow_rule *rule, | |
118 | struct flow_match_control *out); | |
119 | void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule, | |
120 | struct flow_match_ipv4_addrs *out); | |
121 | void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule, | |
122 | struct flow_match_ipv6_addrs *out); | |
123 | void flow_rule_match_enc_ip(const struct flow_rule *rule, | |
124 | struct flow_match_ip *out); | |
125 | void flow_rule_match_enc_ports(const struct flow_rule *rule, | |
126 | struct flow_match_ports *out); | |
127 | void flow_rule_match_enc_keyid(const struct flow_rule *rule, | |
128 | struct flow_match_enc_keyid *out); | |
129 | void flow_rule_match_enc_opts(const struct flow_rule *rule, | |
130 | struct flow_match_enc_opts *out); | |
ee1c45e8 PB |
131 | void flow_rule_match_ct(const struct flow_rule *rule, |
132 | struct flow_match_ct *out); | |
6a21b085 WD |
133 | void flow_rule_match_pppoe(const struct flow_rule *rule, |
134 | struct flow_match_pppoe *out); | |
2c1befac WD |
135 | void flow_rule_match_l2tpv3(const struct flow_rule *rule, |
136 | struct flow_match_l2tpv3 *out); | |
8f256622 | 137 | |
e3ab786b PNA |
138 | enum flow_action_id { |
139 | FLOW_ACTION_ACCEPT = 0, | |
140 | FLOW_ACTION_DROP, | |
141 | FLOW_ACTION_TRAP, | |
142 | FLOW_ACTION_GOTO, | |
143 | FLOW_ACTION_REDIRECT, | |
144 | FLOW_ACTION_MIRRED, | |
48e584ac JH |
145 | FLOW_ACTION_REDIRECT_INGRESS, |
146 | FLOW_ACTION_MIRRED_INGRESS, | |
e3ab786b PNA |
147 | FLOW_ACTION_VLAN_PUSH, |
148 | FLOW_ACTION_VLAN_POP, | |
149 | FLOW_ACTION_VLAN_MANGLE, | |
150 | FLOW_ACTION_TUNNEL_ENCAP, | |
151 | FLOW_ACTION_TUNNEL_DECAP, | |
152 | FLOW_ACTION_MANGLE, | |
153 | FLOW_ACTION_ADD, | |
154 | FLOW_ACTION_CSUM, | |
155 | FLOW_ACTION_MARK, | |
fb1b775a | 156 | FLOW_ACTION_PTYPE, |
2ce12410 | 157 | FLOW_ACTION_PRIORITY, |
8bec2833 PNA |
158 | FLOW_ACTION_WAKE, |
159 | FLOW_ACTION_QUEUE, | |
a7a7be60 | 160 | FLOW_ACTION_SAMPLE, |
8c8cfc6e | 161 | FLOW_ACTION_POLICE, |
b57dc7c1 | 162 | FLOW_ACTION_CT, |
9c26ba9b | 163 | FLOW_ACTION_CT_METADATA, |
6749d590 JH |
164 | FLOW_ACTION_MPLS_PUSH, |
165 | FLOW_ACTION_MPLS_POP, | |
166 | FLOW_ACTION_MPLS_MANGLE, | |
d29bdd69 | 167 | FLOW_ACTION_GATE, |
563ae557 | 168 | FLOW_ACTION_PPPOE_PUSH, |
b8cd5831 JL |
169 | FLOW_ACTION_JUMP, |
170 | FLOW_ACTION_PIPE, | |
ab95465c MD |
171 | FLOW_ACTION_VLAN_PUSH_ETH, |
172 | FLOW_ACTION_VLAN_POP_ETH, | |
052f744f | 173 | FLOW_ACTION_CONTINUE, |
7a978759 | 174 | NUM_FLOW_ACTIONS, |
e3ab786b PNA |
175 | }; |
176 | ||
177 | /* This is mirroring enum pedit_header_type definition for easy mapping between | |
178 | * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to | |
179 | * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver. | |
180 | */ | |
181 | enum flow_action_mangle_base { | |
182 | FLOW_ACT_MANGLE_UNSPEC = 0, | |
183 | FLOW_ACT_MANGLE_HDR_TYPE_ETH, | |
184 | FLOW_ACT_MANGLE_HDR_TYPE_IP4, | |
185 | FLOW_ACT_MANGLE_HDR_TYPE_IP6, | |
186 | FLOW_ACT_MANGLE_HDR_TYPE_TCP, | |
187 | FLOW_ACT_MANGLE_HDR_TYPE_UDP, | |
188 | }; | |
189 | ||
0dfb2d82 | 190 | enum flow_action_hw_stats_bit { |
53eca1f3 JK |
191 | FLOW_ACTION_HW_STATS_IMMEDIATE_BIT, |
192 | FLOW_ACTION_HW_STATS_DELAYED_BIT, | |
16f80360 | 193 | FLOW_ACTION_HW_STATS_DISABLED_BIT, |
060b6381 EC |
194 | |
195 | FLOW_ACTION_HW_STATS_NUM_BITS | |
42d5fe5f JP |
196 | }; |
197 | ||
0dfb2d82 | 198 | enum flow_action_hw_stats { |
53eca1f3 JK |
199 | FLOW_ACTION_HW_STATS_IMMEDIATE = |
200 | BIT(FLOW_ACTION_HW_STATS_IMMEDIATE_BIT), | |
201 | FLOW_ACTION_HW_STATS_DELAYED = BIT(FLOW_ACTION_HW_STATS_DELAYED_BIT), | |
202 | FLOW_ACTION_HW_STATS_ANY = FLOW_ACTION_HW_STATS_IMMEDIATE | | |
203 | FLOW_ACTION_HW_STATS_DELAYED, | |
16f80360 PNA |
204 | FLOW_ACTION_HW_STATS_DISABLED = |
205 | BIT(FLOW_ACTION_HW_STATS_DISABLED_BIT), | |
060b6381 | 206 | FLOW_ACTION_HW_STATS_DONT_CARE = BIT(FLOW_ACTION_HW_STATS_NUM_BITS) - 1, |
42d5fe5f | 207 | }; |
2514921e | 208 | |
1158958a VB |
209 | typedef void (*action_destr)(void *priv); |
210 | ||
2008495d JP |
211 | struct flow_action_cookie { |
212 | u32 cookie_len; | |
213 | u8 cookie[]; | |
214 | }; | |
215 | ||
216 | struct flow_action_cookie *flow_action_cookie_create(void *data, | |
217 | unsigned int len, | |
218 | gfp_t gfp); | |
219 | void flow_action_cookie_destroy(struct flow_action_cookie *cookie); | |
220 | ||
e3ab786b PNA |
221 | struct flow_action_entry { |
222 | enum flow_action_id id; | |
5a995900 | 223 | u32 hw_index; |
0dfb2d82 | 224 | enum flow_action_hw_stats hw_stats; |
1158958a VB |
225 | action_destr destructor; |
226 | void *destructor_priv; | |
e3ab786b PNA |
227 | union { |
228 | u32 chain_index; /* FLOW_ACTION_GOTO */ | |
229 | struct net_device *dev; /* FLOW_ACTION_REDIRECT */ | |
230 | struct { /* FLOW_ACTION_VLAN */ | |
231 | u16 vid; | |
232 | __be16 proto; | |
233 | u8 prio; | |
234 | } vlan; | |
ab95465c MD |
235 | struct { /* FLOW_ACTION_VLAN_PUSH_ETH */ |
236 | unsigned char dst[ETH_ALEN]; | |
237 | unsigned char src[ETH_ALEN]; | |
238 | } vlan_push_eth; | |
1f40be6a PM |
239 | struct { /* FLOW_ACTION_MANGLE */ |
240 | /* FLOW_ACTION_ADD */ | |
e3ab786b PNA |
241 | enum flow_action_mangle_base htype; |
242 | u32 offset; | |
243 | u32 mask; | |
244 | u32 val; | |
245 | } mangle; | |
1158958a | 246 | struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */ |
e3ab786b PNA |
247 | u32 csum_flags; /* FLOW_ACTION_CSUM */ |
248 | u32 mark; /* FLOW_ACTION_MARK */ | |
fb1b775a | 249 | u16 ptype; /* FLOW_ACTION_PTYPE */ |
2ce12410 | 250 | u32 priority; /* FLOW_ACTION_PRIORITY */ |
8bec2833 PNA |
251 | struct { /* FLOW_ACTION_QUEUE */ |
252 | u32 ctx; | |
253 | u32 index; | |
254 | u8 vf; | |
255 | } queue; | |
a7a7be60 PJV |
256 | struct { /* FLOW_ACTION_SAMPLE */ |
257 | struct psample_group *psample_group; | |
258 | u32 rate; | |
259 | u32 trunc_size; | |
260 | bool truncate; | |
261 | } sample; | |
8c8cfc6e | 262 | struct { /* FLOW_ACTION_POLICE */ |
5f035af7 | 263 | u32 burst; |
8c8cfc6e | 264 | u64 rate_bytes_ps; |
b8cd5831 JL |
265 | u64 peakrate_bytes_ps; |
266 | u32 avrate; | |
267 | u16 overhead; | |
25660156 XH |
268 | u64 burst_pkt; |
269 | u64 rate_pkt_ps; | |
19e528dc | 270 | u32 mtu; |
b8cd5831 JL |
271 | struct { |
272 | enum flow_action_id act_id; | |
273 | u32 extval; | |
274 | } exceed, notexceed; | |
8c8cfc6e | 275 | } police; |
b57dc7c1 PB |
276 | struct { /* FLOW_ACTION_CT */ |
277 | int action; | |
278 | u16 zone; | |
edd5861e | 279 | struct nf_flowtable *flow_table; |
b57dc7c1 | 280 | } ct; |
9c26ba9b | 281 | struct { |
30b0cf90 | 282 | unsigned long cookie; |
9c26ba9b PB |
283 | u32 mark; |
284 | u32 labels[4]; | |
941eff5a | 285 | bool orig_dir; |
9c26ba9b | 286 | } ct_metadata; |
6749d590 JH |
287 | struct { /* FLOW_ACTION_MPLS_PUSH */ |
288 | u32 label; | |
289 | __be16 proto; | |
290 | u8 tc; | |
291 | u8 bos; | |
292 | u8 ttl; | |
293 | } mpls_push; | |
294 | struct { /* FLOW_ACTION_MPLS_POP */ | |
295 | __be16 proto; | |
296 | } mpls_pop; | |
297 | struct { /* FLOW_ACTION_MPLS_MANGLE */ | |
298 | u32 label; | |
299 | u8 tc; | |
300 | u8 bos; | |
301 | u8 ttl; | |
302 | } mpls_mangle; | |
d29bdd69 | 303 | struct { |
d29bdd69 PL |
304 | s32 prio; |
305 | u64 basetime; | |
306 | u64 cycletime; | |
307 | u64 cycletimeext; | |
308 | u32 num_entries; | |
309 | struct action_gate_entry *entries; | |
310 | } gate; | |
563ae557 PNA |
311 | struct { /* FLOW_ACTION_PPPOE_PUSH */ |
312 | u16 sid; | |
313 | } pppoe; | |
e3ab786b | 314 | }; |
2008495d | 315 | struct flow_action_cookie *cookie; /* user defined action cookie */ |
e3ab786b PNA |
316 | }; |
317 | ||
318 | struct flow_action { | |
319 | unsigned int num_entries; | |
8661b6e7 | 320 | struct flow_action_entry entries[]; |
e3ab786b PNA |
321 | }; |
322 | ||
323 | static inline bool flow_action_has_entries(const struct flow_action *action) | |
324 | { | |
325 | return action->num_entries; | |
326 | } | |
327 | ||
ab79af32 | 328 | /** |
c87a4c54 | 329 | * flow_offload_has_one_action() - check if exactly one action is present |
ab79af32 PJV |
330 | * @action: tc filter flow offload action |
331 | * | |
332 | * Returns true if exactly one action is present. | |
333 | */ | |
334 | static inline bool flow_offload_has_one_action(const struct flow_action *action) | |
335 | { | |
336 | return action->num_entries == 1; | |
337 | } | |
338 | ||
d97b4b10 JL |
339 | static inline bool flow_action_is_last_entry(const struct flow_action *action, |
340 | const struct flow_action_entry *entry) | |
341 | { | |
342 | return entry == &action->entries[action->num_entries - 1]; | |
343 | } | |
344 | ||
62751b68 JP |
345 | #define flow_action_for_each(__i, __act, __actions) \ |
346 | for (__i = 0, __act = &(__actions)->entries[0]; \ | |
347 | __i < (__actions)->num_entries; \ | |
348 | __act = &(__actions)->entries[++__i]) | |
349 | ||
319a1d19 | 350 | static inline bool |
53eca1f3 JK |
351 | flow_action_mixed_hw_stats_check(const struct flow_action *action, |
352 | struct netlink_ext_ack *extack) | |
319a1d19 JP |
353 | { |
354 | const struct flow_action_entry *action_entry; | |
3f649ab7 | 355 | u8 last_hw_stats; |
319a1d19 JP |
356 | int i; |
357 | ||
358 | if (flow_offload_has_one_action(action)) | |
359 | return true; | |
360 | ||
fa05bdb8 IS |
361 | flow_action_for_each(i, action_entry, action) { |
362 | if (i && action_entry->hw_stats != last_hw_stats) { | |
363 | NL_SET_ERR_MSG_MOD(extack, "Mixing HW stats types for actions is not supported"); | |
364 | return false; | |
319a1d19 | 365 | } |
fa05bdb8 | 366 | last_hw_stats = action_entry->hw_stats; |
319a1d19 JP |
367 | } |
368 | return true; | |
369 | } | |
370 | ||
371 | static inline const struct flow_action_entry * | |
372 | flow_action_first_entry_get(const struct flow_action *action) | |
373 | { | |
374 | WARN_ON(!flow_action_has_entries(action)); | |
375 | return &action->entries[0]; | |
376 | } | |
377 | ||
378 | static inline bool | |
53eca1f3 JK |
379 | __flow_action_hw_stats_check(const struct flow_action *action, |
380 | struct netlink_ext_ack *extack, | |
381 | bool check_allow_bit, | |
0dfb2d82 | 382 | enum flow_action_hw_stats_bit allow_bit) |
319a1d19 JP |
383 | { |
384 | const struct flow_action_entry *action_entry; | |
385 | ||
386 | if (!flow_action_has_entries(action)) | |
387 | return true; | |
53eca1f3 | 388 | if (!flow_action_mixed_hw_stats_check(action, extack)) |
319a1d19 | 389 | return false; |
16f80360 | 390 | |
319a1d19 | 391 | action_entry = flow_action_first_entry_get(action); |
060b6381 EC |
392 | |
393 | /* Zero is not a legal value for hw_stats, catch anyone passing it */ | |
394 | WARN_ON_ONCE(!action_entry->hw_stats); | |
16f80360 | 395 | |
a16fa289 | 396 | if (!check_allow_bit && |
060b6381 | 397 | ~action_entry->hw_stats & FLOW_ACTION_HW_STATS_ANY) { |
319a1d19 JP |
398 | NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\""); |
399 | return false; | |
a16fa289 | 400 | } else if (check_allow_bit && |
0dfb2d82 | 401 | !(action_entry->hw_stats & BIT(allow_bit))) { |
319a1d19 JP |
402 | NL_SET_ERR_MSG_MOD(extack, "Driver does not support selected HW stats type"); |
403 | return false; | |
404 | } | |
405 | return true; | |
406 | } | |
407 | ||
a16fa289 | 408 | static inline bool |
53eca1f3 JK |
409 | flow_action_hw_stats_check(const struct flow_action *action, |
410 | struct netlink_ext_ack *extack, | |
0dfb2d82 | 411 | enum flow_action_hw_stats_bit allow_bit) |
a16fa289 | 412 | { |
53eca1f3 | 413 | return __flow_action_hw_stats_check(action, extack, true, allow_bit); |
a16fa289 JP |
414 | } |
415 | ||
319a1d19 | 416 | static inline bool |
53eca1f3 JK |
417 | flow_action_basic_hw_stats_check(const struct flow_action *action, |
418 | struct netlink_ext_ack *extack) | |
319a1d19 | 419 | { |
53eca1f3 | 420 | return __flow_action_hw_stats_check(action, extack, false, 0); |
319a1d19 JP |
421 | } |
422 | ||
8f256622 PNA |
423 | struct flow_rule { |
424 | struct flow_match match; | |
e3ab786b | 425 | struct flow_action action; |
8f256622 PNA |
426 | }; |
427 | ||
e3ab786b | 428 | struct flow_rule *flow_rule_alloc(unsigned int num_actions); |
8f256622 PNA |
429 | |
430 | static inline bool flow_rule_match_key(const struct flow_rule *rule, | |
431 | enum flow_dissector_key_id key) | |
432 | { | |
433 | return dissector_uses_key(rule->match.dissector, key); | |
434 | } | |
435 | ||
3b1903ef PNA |
436 | struct flow_stats { |
437 | u64 pkts; | |
438 | u64 bytes; | |
4b61d3e8 | 439 | u64 drops; |
3b1903ef | 440 | u64 lastused; |
93a129eb JP |
441 | enum flow_action_hw_stats used_hw_stats; |
442 | bool used_hw_stats_valid; | |
3b1903ef PNA |
443 | }; |
444 | ||
445 | static inline void flow_stats_update(struct flow_stats *flow_stats, | |
4b61d3e8 PL |
446 | u64 bytes, u64 pkts, |
447 | u64 drops, u64 lastused, | |
93a129eb | 448 | enum flow_action_hw_stats used_hw_stats) |
3b1903ef | 449 | { |
9f9dc493 JH |
450 | flow_stats->pkts += pkts; |
451 | flow_stats->bytes += bytes; | |
4b61d3e8 | 452 | flow_stats->drops += drops; |
9f9dc493 | 453 | flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused); |
93a129eb JP |
454 | |
455 | /* The driver should pass value with a maximum of one bit set. | |
456 | * Passing FLOW_ACTION_HW_STATS_ANY is invalid. | |
457 | */ | |
458 | WARN_ON(used_hw_stats == FLOW_ACTION_HW_STATS_ANY); | |
459 | flow_stats->used_hw_stats |= used_hw_stats; | |
460 | flow_stats->used_hw_stats_valid = true; | |
3b1903ef PNA |
461 | } |
462 | ||
4e95bc26 | 463 | enum flow_block_command { |
9c0e189e PNA |
464 | FLOW_BLOCK_BIND, |
465 | FLOW_BLOCK_UNBIND, | |
4e95bc26 PNA |
466 | }; |
467 | ||
468 | enum flow_block_binder_type { | |
32f8c409 PNA |
469 | FLOW_BLOCK_BINDER_TYPE_UNSPEC, |
470 | FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS, | |
471 | FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS, | |
aee9caa0 PM |
472 | FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP, |
473 | FLOW_BLOCK_BINDER_TYPE_RED_MARK, | |
4e95bc26 PNA |
474 | }; |
475 | ||
14bfb13f PNA |
476 | struct flow_block { |
477 | struct list_head cb_list; | |
478 | }; | |
479 | ||
4e95bc26 PNA |
480 | struct netlink_ext_ack; |
481 | ||
482 | struct flow_block_offload { | |
483 | enum flow_block_command command; | |
484 | enum flow_block_binder_type binder_type; | |
955bcb6e | 485 | bool block_shared; |
c9f14470 | 486 | bool unlocked_driver_cb; |
da3eeb90 | 487 | struct net *net; |
14bfb13f | 488 | struct flow_block *block; |
da3eeb90 | 489 | struct list_head cb_list; |
4e95bc26 PNA |
490 | struct list_head *driver_block_list; |
491 | struct netlink_ext_ack *extack; | |
c40f4e50 | 492 | struct Qdisc *sch; |
74fc4f82 | 493 | struct list_head *cb_list_head; |
4e95bc26 PNA |
494 | }; |
495 | ||
a7323311 PNA |
496 | enum tc_setup_type; |
497 | typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data, | |
498 | void *cb_priv); | |
499 | ||
1fac52da PNA |
500 | struct flow_block_cb; |
501 | ||
502 | struct flow_block_indr { | |
503 | struct list_head list; | |
504 | struct net_device *dev; | |
c40f4e50 | 505 | struct Qdisc *sch; |
1fac52da PNA |
506 | enum flow_block_binder_type binder_type; |
507 | void *data; | |
a1db2178 | 508 | void *cb_priv; |
1fac52da PNA |
509 | void (*cleanup)(struct flow_block_cb *block_cb); |
510 | }; | |
511 | ||
d63db30c | 512 | struct flow_block_cb { |
da3eeb90 | 513 | struct list_head driver_list; |
d63db30c | 514 | struct list_head list; |
a7323311 | 515 | flow_setup_cb_t *cb; |
d63db30c PNA |
516 | void *cb_ident; |
517 | void *cb_priv; | |
518 | void (*release)(void *cb_priv); | |
1fac52da | 519 | struct flow_block_indr indr; |
d63db30c PNA |
520 | unsigned int refcnt; |
521 | }; | |
522 | ||
a7323311 | 523 | struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb, |
d63db30c PNA |
524 | void *cb_ident, void *cb_priv, |
525 | void (*release)(void *cb_priv)); | |
26f2eb27 | 526 | struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb, |
527 | void *cb_ident, void *cb_priv, | |
528 | void (*release)(void *cb_priv), | |
529 | struct flow_block_offload *bo, | |
c40f4e50 PM |
530 | struct net_device *dev, |
531 | struct Qdisc *sch, void *data, | |
a1db2178 | 532 | void *indr_cb_priv, |
26f2eb27 | 533 | void (*cleanup)(struct flow_block_cb *block_cb)); |
d63db30c PNA |
534 | void flow_block_cb_free(struct flow_block_cb *block_cb); |
535 | ||
14bfb13f | 536 | struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block, |
a7323311 | 537 | flow_setup_cb_t *cb, void *cb_ident); |
da3eeb90 | 538 | |
67bd0d5e PNA |
539 | void *flow_block_cb_priv(struct flow_block_cb *block_cb); |
540 | void flow_block_cb_incref(struct flow_block_cb *block_cb); | |
541 | unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb); | |
542 | ||
da3eeb90 PNA |
543 | static inline void flow_block_cb_add(struct flow_block_cb *block_cb, |
544 | struct flow_block_offload *offload) | |
545 | { | |
546 | list_add_tail(&block_cb->list, &offload->cb_list); | |
547 | } | |
548 | ||
549 | static inline void flow_block_cb_remove(struct flow_block_cb *block_cb, | |
550 | struct flow_block_offload *offload) | |
551 | { | |
552 | list_move(&block_cb->list, &offload->cb_list); | |
553 | } | |
554 | ||
26f2eb27 | 555 | static inline void flow_indr_block_cb_remove(struct flow_block_cb *block_cb, |
556 | struct flow_block_offload *offload) | |
557 | { | |
558 | list_del(&block_cb->indr.list); | |
559 | list_move(&block_cb->list, &offload->cb_list); | |
560 | } | |
561 | ||
a7323311 | 562 | bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident, |
0d4fd02e PNA |
563 | struct list_head *driver_block_list); |
564 | ||
4e95bc26 | 565 | int flow_block_cb_setup_simple(struct flow_block_offload *f, |
a7323311 PNA |
566 | struct list_head *driver_list, |
567 | flow_setup_cb_t *cb, | |
4e95bc26 PNA |
568 | void *cb_ident, void *cb_priv, bool ingress_only); |
569 | ||
f9e30088 PNA |
570 | enum flow_cls_command { |
571 | FLOW_CLS_REPLACE, | |
572 | FLOW_CLS_DESTROY, | |
573 | FLOW_CLS_STATS, | |
574 | FLOW_CLS_TMPLT_CREATE, | |
575 | FLOW_CLS_TMPLT_DESTROY, | |
576 | }; | |
577 | ||
578 | struct flow_cls_common_offload { | |
579 | u32 chain_index; | |
580 | __be16 protocol; | |
581 | u32 prio; | |
582 | struct netlink_ext_ack *extack; | |
583 | }; | |
584 | ||
585 | struct flow_cls_offload { | |
586 | struct flow_cls_common_offload common; | |
587 | enum flow_cls_command command; | |
588 | unsigned long cookie; | |
589 | struct flow_rule *rule; | |
590 | struct flow_stats stats; | |
591 | u32 classid; | |
592 | }; | |
593 | ||
8cbfe939 BZ |
594 | enum offload_act_command { |
595 | FLOW_ACT_REPLACE, | |
596 | FLOW_ACT_DESTROY, | |
597 | FLOW_ACT_STATS, | |
598 | }; | |
599 | ||
600 | struct flow_offload_action { | |
601 | struct netlink_ext_ack *extack; /* NULL in FLOW_ACT_STATS process*/ | |
602 | enum offload_act_command command; | |
603 | enum flow_action_id id; | |
604 | u32 index; | |
605 | struct flow_stats stats; | |
606 | struct flow_action action; | |
607 | }; | |
608 | ||
609 | struct flow_offload_action *offload_action_alloc(unsigned int num_actions); | |
610 | ||
f9e30088 PNA |
611 | static inline struct flow_rule * |
612 | flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd) | |
613 | { | |
614 | return flow_cmd->rule; | |
615 | } | |
616 | ||
14bfb13f PNA |
617 | static inline void flow_block_init(struct flow_block *flow_block) |
618 | { | |
619 | INIT_LIST_HEAD(&flow_block->cb_list); | |
620 | } | |
621 | ||
c40f4e50 | 622 | typedef int flow_indr_block_bind_cb_t(struct net_device *dev, struct Qdisc *sch, void *cb_priv, |
66f1939a | 623 | enum tc_setup_type type, void *type_data, |
624 | void *data, | |
625 | void (*cleanup)(struct flow_block_cb *block_cb)); | |
4e481908 | 626 | |
1fac52da PNA |
627 | int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv); |
628 | void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv, | |
a1db2178 | 629 | void (*release)(void *cb_priv)); |
c40f4e50 | 630 | int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, |
1fac52da PNA |
631 | enum tc_setup_type type, void *data, |
632 | struct flow_block_offload *bo, | |
633 | void (*cleanup)(struct flow_block_cb *block_cb)); | |
3a41c64d | 634 | bool flow_indr_dev_exists(void); |
1fac52da | 635 | |
8f256622 | 636 | #endif /* _NET_FLOW_OFFLOAD_H */ |