1 #ifndef _NET_FLOW_OFFLOAD_H
2 #define _NET_FLOW_OFFLOAD_H
4 #include <linux/kernel.h>
5 #include <net/flow_dissector.h>
8 struct flow_dissector *dissector;
13 struct flow_match_meta {
14 struct flow_dissector_key_meta *key, *mask;
17 struct flow_match_basic {
18 struct flow_dissector_key_basic *key, *mask;
21 struct flow_match_control {
22 struct flow_dissector_key_control *key, *mask;
25 struct flow_match_eth_addrs {
26 struct flow_dissector_key_eth_addrs *key, *mask;
29 struct flow_match_vlan {
30 struct flow_dissector_key_vlan *key, *mask;
33 struct flow_match_ipv4_addrs {
34 struct flow_dissector_key_ipv4_addrs *key, *mask;
37 struct flow_match_ipv6_addrs {
38 struct flow_dissector_key_ipv6_addrs *key, *mask;
41 struct flow_match_ip {
42 struct flow_dissector_key_ip *key, *mask;
45 struct flow_match_ports {
46 struct flow_dissector_key_ports *key, *mask;
49 struct flow_match_icmp {
50 struct flow_dissector_key_icmp *key, *mask;
53 struct flow_match_tcp {
54 struct flow_dissector_key_tcp *key, *mask;
57 struct flow_match_mpls {
58 struct flow_dissector_key_mpls *key, *mask;
61 struct flow_match_enc_keyid {
62 struct flow_dissector_key_keyid *key, *mask;
65 struct flow_match_enc_opts {
66 struct flow_dissector_key_enc_opts *key, *mask;
71 void flow_rule_match_meta(const struct flow_rule *rule,
72 struct flow_match_meta *out);
73 void flow_rule_match_basic(const struct flow_rule *rule,
74 struct flow_match_basic *out);
75 void flow_rule_match_control(const struct flow_rule *rule,
76 struct flow_match_control *out);
77 void flow_rule_match_eth_addrs(const struct flow_rule *rule,
78 struct flow_match_eth_addrs *out);
79 void flow_rule_match_vlan(const struct flow_rule *rule,
80 struct flow_match_vlan *out);
81 void flow_rule_match_cvlan(const struct flow_rule *rule,
82 struct flow_match_vlan *out);
83 void flow_rule_match_ipv4_addrs(const struct flow_rule *rule,
84 struct flow_match_ipv4_addrs *out);
85 void flow_rule_match_ipv6_addrs(const struct flow_rule *rule,
86 struct flow_match_ipv6_addrs *out);
87 void flow_rule_match_ip(const struct flow_rule *rule,
88 struct flow_match_ip *out);
89 void flow_rule_match_ports(const struct flow_rule *rule,
90 struct flow_match_ports *out);
91 void flow_rule_match_tcp(const struct flow_rule *rule,
92 struct flow_match_tcp *out);
93 void flow_rule_match_icmp(const struct flow_rule *rule,
94 struct flow_match_icmp *out);
95 void flow_rule_match_mpls(const struct flow_rule *rule,
96 struct flow_match_mpls *out);
97 void flow_rule_match_enc_control(const struct flow_rule *rule,
98 struct flow_match_control *out);
99 void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule,
100 struct flow_match_ipv4_addrs *out);
101 void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule,
102 struct flow_match_ipv6_addrs *out);
103 void flow_rule_match_enc_ip(const struct flow_rule *rule,
104 struct flow_match_ip *out);
105 void flow_rule_match_enc_ports(const struct flow_rule *rule,
106 struct flow_match_ports *out);
107 void flow_rule_match_enc_keyid(const struct flow_rule *rule,
108 struct flow_match_enc_keyid *out);
109 void flow_rule_match_enc_opts(const struct flow_rule *rule,
110 struct flow_match_enc_opts *out);
112 enum flow_action_id {
113 FLOW_ACTION_ACCEPT = 0,
117 FLOW_ACTION_REDIRECT,
119 FLOW_ACTION_VLAN_PUSH,
120 FLOW_ACTION_VLAN_POP,
121 FLOW_ACTION_VLAN_MANGLE,
122 FLOW_ACTION_TUNNEL_ENCAP,
123 FLOW_ACTION_TUNNEL_DECAP,
134 /* This is mirroring enum pedit_header_type definition for easy mapping between
135 * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to
136 * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver.
138 enum flow_action_mangle_base {
139 FLOW_ACT_MANGLE_UNSPEC = 0,
140 FLOW_ACT_MANGLE_HDR_TYPE_ETH,
141 FLOW_ACT_MANGLE_HDR_TYPE_IP4,
142 FLOW_ACT_MANGLE_HDR_TYPE_IP6,
143 FLOW_ACT_MANGLE_HDR_TYPE_TCP,
144 FLOW_ACT_MANGLE_HDR_TYPE_UDP,
147 struct flow_action_entry {
148 enum flow_action_id id;
150 u32 chain_index; /* FLOW_ACTION_GOTO */
151 struct net_device *dev; /* FLOW_ACTION_REDIRECT */
152 struct { /* FLOW_ACTION_VLAN */
157 struct { /* FLOW_ACTION_PACKET_EDIT */
158 enum flow_action_mangle_base htype;
163 const struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */
164 u32 csum_flags; /* FLOW_ACTION_CSUM */
165 u32 mark; /* FLOW_ACTION_MARK */
166 struct { /* FLOW_ACTION_QUEUE */
171 struct { /* FLOW_ACTION_SAMPLE */
172 struct psample_group *psample_group;
177 struct { /* FLOW_ACTION_POLICE */
185 unsigned int num_entries;
186 struct flow_action_entry entries[0];
189 static inline bool flow_action_has_entries(const struct flow_action *action)
191 return action->num_entries;
195 * flow_action_has_one_action() - check if exactly one action is present
196 * @action: tc filter flow offload action
198 * Returns true if exactly one action is present.
200 static inline bool flow_offload_has_one_action(const struct flow_action *action)
202 return action->num_entries == 1;
205 #define flow_action_for_each(__i, __act, __actions) \
206 for (__i = 0, __act = &(__actions)->entries[0]; __i < (__actions)->num_entries; __act = &(__actions)->entries[++__i])
209 struct flow_match match;
210 struct flow_action action;
213 struct flow_rule *flow_rule_alloc(unsigned int num_actions);
215 static inline bool flow_rule_match_key(const struct flow_rule *rule,
216 enum flow_dissector_key_id key)
218 return dissector_uses_key(rule->match.dissector, key);
227 static inline void flow_stats_update(struct flow_stats *flow_stats,
228 u64 bytes, u64 pkts, u64 lastused)
230 flow_stats->pkts += pkts;
231 flow_stats->bytes += bytes;
232 flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused);
235 #endif /* _NET_FLOW_OFFLOAD_H */