1 #ifndef _NET_FLOW_OFFLOAD_H
2 #define _NET_FLOW_OFFLOAD_H
4 #include <linux/kernel.h>
5 #include <linux/list.h>
6 #include <net/flow_dissector.h>
7 #include <linux/rhashtable.h>
10 struct flow_dissector *dissector;
15 struct flow_match_meta {
16 struct flow_dissector_key_meta *key, *mask;
19 struct flow_match_basic {
20 struct flow_dissector_key_basic *key, *mask;
23 struct flow_match_control {
24 struct flow_dissector_key_control *key, *mask;
27 struct flow_match_eth_addrs {
28 struct flow_dissector_key_eth_addrs *key, *mask;
31 struct flow_match_vlan {
32 struct flow_dissector_key_vlan *key, *mask;
35 struct flow_match_ipv4_addrs {
36 struct flow_dissector_key_ipv4_addrs *key, *mask;
39 struct flow_match_ipv6_addrs {
40 struct flow_dissector_key_ipv6_addrs *key, *mask;
43 struct flow_match_ip {
44 struct flow_dissector_key_ip *key, *mask;
47 struct flow_match_ports {
48 struct flow_dissector_key_ports *key, *mask;
51 struct flow_match_icmp {
52 struct flow_dissector_key_icmp *key, *mask;
55 struct flow_match_tcp {
56 struct flow_dissector_key_tcp *key, *mask;
59 struct flow_match_mpls {
60 struct flow_dissector_key_mpls *key, *mask;
63 struct flow_match_enc_keyid {
64 struct flow_dissector_key_keyid *key, *mask;
67 struct flow_match_enc_opts {
68 struct flow_dissector_key_enc_opts *key, *mask;
73 void flow_rule_match_meta(const struct flow_rule *rule,
74 struct flow_match_meta *out);
75 void flow_rule_match_basic(const struct flow_rule *rule,
76 struct flow_match_basic *out);
77 void flow_rule_match_control(const struct flow_rule *rule,
78 struct flow_match_control *out);
79 void flow_rule_match_eth_addrs(const struct flow_rule *rule,
80 struct flow_match_eth_addrs *out);
81 void flow_rule_match_vlan(const struct flow_rule *rule,
82 struct flow_match_vlan *out);
83 void flow_rule_match_cvlan(const struct flow_rule *rule,
84 struct flow_match_vlan *out);
85 void flow_rule_match_ipv4_addrs(const struct flow_rule *rule,
86 struct flow_match_ipv4_addrs *out);
87 void flow_rule_match_ipv6_addrs(const struct flow_rule *rule,
88 struct flow_match_ipv6_addrs *out);
89 void flow_rule_match_ip(const struct flow_rule *rule,
90 struct flow_match_ip *out);
91 void flow_rule_match_ports(const struct flow_rule *rule,
92 struct flow_match_ports *out);
93 void flow_rule_match_tcp(const struct flow_rule *rule,
94 struct flow_match_tcp *out);
95 void flow_rule_match_icmp(const struct flow_rule *rule,
96 struct flow_match_icmp *out);
97 void flow_rule_match_mpls(const struct flow_rule *rule,
98 struct flow_match_mpls *out);
99 void flow_rule_match_enc_control(const struct flow_rule *rule,
100 struct flow_match_control *out);
101 void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule,
102 struct flow_match_ipv4_addrs *out);
103 void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule,
104 struct flow_match_ipv6_addrs *out);
105 void flow_rule_match_enc_ip(const struct flow_rule *rule,
106 struct flow_match_ip *out);
107 void flow_rule_match_enc_ports(const struct flow_rule *rule,
108 struct flow_match_ports *out);
109 void flow_rule_match_enc_keyid(const struct flow_rule *rule,
110 struct flow_match_enc_keyid *out);
111 void flow_rule_match_enc_opts(const struct flow_rule *rule,
112 struct flow_match_enc_opts *out);
114 enum flow_action_id {
115 FLOW_ACTION_ACCEPT = 0,
119 FLOW_ACTION_REDIRECT,
121 FLOW_ACTION_REDIRECT_INGRESS,
122 FLOW_ACTION_MIRRED_INGRESS,
123 FLOW_ACTION_VLAN_PUSH,
124 FLOW_ACTION_VLAN_POP,
125 FLOW_ACTION_VLAN_MANGLE,
126 FLOW_ACTION_TUNNEL_ENCAP,
127 FLOW_ACTION_TUNNEL_DECAP,
138 FLOW_ACTION_MPLS_PUSH,
139 FLOW_ACTION_MPLS_POP,
140 FLOW_ACTION_MPLS_MANGLE,
144 /* This is mirroring enum pedit_header_type definition for easy mapping between
145 * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to
146 * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver.
148 enum flow_action_mangle_base {
149 FLOW_ACT_MANGLE_UNSPEC = 0,
150 FLOW_ACT_MANGLE_HDR_TYPE_ETH,
151 FLOW_ACT_MANGLE_HDR_TYPE_IP4,
152 FLOW_ACT_MANGLE_HDR_TYPE_IP6,
153 FLOW_ACT_MANGLE_HDR_TYPE_TCP,
154 FLOW_ACT_MANGLE_HDR_TYPE_UDP,
157 struct flow_action_entry {
158 enum flow_action_id id;
160 u32 chain_index; /* FLOW_ACTION_GOTO */
161 struct net_device *dev; /* FLOW_ACTION_REDIRECT */
162 struct { /* FLOW_ACTION_VLAN */
167 struct { /* FLOW_ACTION_PACKET_EDIT */
168 enum flow_action_mangle_base htype;
173 const struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */
174 u32 csum_flags; /* FLOW_ACTION_CSUM */
175 u32 mark; /* FLOW_ACTION_MARK */
176 u16 ptype; /* FLOW_ACTION_PTYPE */
177 struct { /* FLOW_ACTION_QUEUE */
182 struct { /* FLOW_ACTION_SAMPLE */
183 struct psample_group *psample_group;
188 struct { /* FLOW_ACTION_POLICE */
192 struct { /* FLOW_ACTION_CT */
196 struct { /* FLOW_ACTION_MPLS_PUSH */
203 struct { /* FLOW_ACTION_MPLS_POP */
206 struct { /* FLOW_ACTION_MPLS_MANGLE */
216 unsigned int num_entries;
217 struct flow_action_entry entries[0];
220 static inline bool flow_action_has_entries(const struct flow_action *action)
222 return action->num_entries;
226 * flow_action_has_one_action() - check if exactly one action is present
227 * @action: tc filter flow offload action
229 * Returns true if exactly one action is present.
231 static inline bool flow_offload_has_one_action(const struct flow_action *action)
233 return action->num_entries == 1;
236 #define flow_action_for_each(__i, __act, __actions) \
237 for (__i = 0, __act = &(__actions)->entries[0]; __i < (__actions)->num_entries; __act = &(__actions)->entries[++__i])
240 struct flow_match match;
241 struct flow_action action;
244 struct flow_rule *flow_rule_alloc(unsigned int num_actions);
246 static inline bool flow_rule_match_key(const struct flow_rule *rule,
247 enum flow_dissector_key_id key)
249 return dissector_uses_key(rule->match.dissector, key);
258 static inline void flow_stats_update(struct flow_stats *flow_stats,
259 u64 bytes, u64 pkts, u64 lastused)
261 flow_stats->pkts += pkts;
262 flow_stats->bytes += bytes;
263 flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused);
266 enum flow_block_command {
271 enum flow_block_binder_type {
272 FLOW_BLOCK_BINDER_TYPE_UNSPEC,
273 FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
274 FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS,
278 struct list_head cb_list;
281 struct netlink_ext_ack;
283 struct flow_block_offload {
284 enum flow_block_command command;
285 enum flow_block_binder_type binder_type;
287 bool unlocked_driver_cb;
289 struct flow_block *block;
290 struct list_head cb_list;
291 struct list_head *driver_block_list;
292 struct netlink_ext_ack *extack;
296 typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data,
299 struct flow_block_cb {
300 struct list_head driver_list;
301 struct list_head list;
305 void (*release)(void *cb_priv);
309 struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb,
310 void *cb_ident, void *cb_priv,
311 void (*release)(void *cb_priv));
312 void flow_block_cb_free(struct flow_block_cb *block_cb);
314 struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block,
315 flow_setup_cb_t *cb, void *cb_ident);
317 void *flow_block_cb_priv(struct flow_block_cb *block_cb);
318 void flow_block_cb_incref(struct flow_block_cb *block_cb);
319 unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb);
321 static inline void flow_block_cb_add(struct flow_block_cb *block_cb,
322 struct flow_block_offload *offload)
324 list_add_tail(&block_cb->list, &offload->cb_list);
327 static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
328 struct flow_block_offload *offload)
330 list_move(&block_cb->list, &offload->cb_list);
333 bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident,
334 struct list_head *driver_block_list);
336 int flow_block_cb_setup_simple(struct flow_block_offload *f,
337 struct list_head *driver_list,
339 void *cb_ident, void *cb_priv, bool ingress_only);
341 enum flow_cls_command {
345 FLOW_CLS_TMPLT_CREATE,
346 FLOW_CLS_TMPLT_DESTROY,
349 struct flow_cls_common_offload {
353 struct netlink_ext_ack *extack;
356 struct flow_cls_offload {
357 struct flow_cls_common_offload common;
358 enum flow_cls_command command;
359 unsigned long cookie;
360 struct flow_rule *rule;
361 struct flow_stats stats;
365 static inline struct flow_rule *
366 flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd)
368 return flow_cmd->rule;
371 static inline void flow_block_init(struct flow_block *flow_block)
373 INIT_LIST_HEAD(&flow_block->cb_list);
376 typedef int flow_indr_block_bind_cb_t(struct net_device *dev, void *cb_priv,
377 enum tc_setup_type type, void *type_data);
379 typedef void flow_indr_block_ing_cmd_t(struct net_device *dev,
380 flow_indr_block_bind_cb_t *cb,
382 enum flow_block_command command);
384 struct flow_indr_block_ing_entry {
385 flow_indr_block_ing_cmd_t *cb;
386 struct list_head list;
389 void flow_indr_add_block_ing_cb(struct flow_indr_block_ing_entry *entry);
391 void flow_indr_del_block_ing_cb(struct flow_indr_block_ing_entry *entry);
393 int __flow_indr_block_cb_register(struct net_device *dev, void *cb_priv,
394 flow_indr_block_bind_cb_t *cb,
397 void __flow_indr_block_cb_unregister(struct net_device *dev,
398 flow_indr_block_bind_cb_t *cb,
401 int flow_indr_block_cb_register(struct net_device *dev, void *cb_priv,
402 flow_indr_block_bind_cb_t *cb, void *cb_ident);
404 void flow_indr_block_cb_unregister(struct net_device *dev,
405 flow_indr_block_bind_cb_t *cb,
408 void flow_indr_block_call(struct net_device *dev,
409 struct flow_block_offload *bo,
410 enum flow_block_command command);
412 #endif /* _NET_FLOW_OFFLOAD_H */