Commit | Line | Data |
---|---|---|
8f256622 PNA |
1 | #ifndef _NET_FLOW_OFFLOAD_H |
2 | #define _NET_FLOW_OFFLOAD_H | |
3 | ||
4 | #include <net/flow_dissector.h> | |
5 | ||
6 | struct flow_match { | |
7 | struct flow_dissector *dissector; | |
8 | void *mask; | |
9 | void *key; | |
10 | }; | |
11 | ||
12 | struct flow_match_basic { | |
13 | struct flow_dissector_key_basic *key, *mask; | |
14 | }; | |
15 | ||
16 | struct flow_match_control { | |
17 | struct flow_dissector_key_control *key, *mask; | |
18 | }; | |
19 | ||
20 | struct flow_match_eth_addrs { | |
21 | struct flow_dissector_key_eth_addrs *key, *mask; | |
22 | }; | |
23 | ||
24 | struct flow_match_vlan { | |
25 | struct flow_dissector_key_vlan *key, *mask; | |
26 | }; | |
27 | ||
28 | struct flow_match_ipv4_addrs { | |
29 | struct flow_dissector_key_ipv4_addrs *key, *mask; | |
30 | }; | |
31 | ||
32 | struct flow_match_ipv6_addrs { | |
33 | struct flow_dissector_key_ipv6_addrs *key, *mask; | |
34 | }; | |
35 | ||
36 | struct flow_match_ip { | |
37 | struct flow_dissector_key_ip *key, *mask; | |
38 | }; | |
39 | ||
40 | struct flow_match_ports { | |
41 | struct flow_dissector_key_ports *key, *mask; | |
42 | }; | |
43 | ||
44 | struct flow_match_icmp { | |
45 | struct flow_dissector_key_icmp *key, *mask; | |
46 | }; | |
47 | ||
48 | struct flow_match_tcp { | |
49 | struct flow_dissector_key_tcp *key, *mask; | |
50 | }; | |
51 | ||
52 | struct flow_match_mpls { | |
53 | struct flow_dissector_key_mpls *key, *mask; | |
54 | }; | |
55 | ||
56 | struct flow_match_enc_keyid { | |
57 | struct flow_dissector_key_keyid *key, *mask; | |
58 | }; | |
59 | ||
60 | struct flow_match_enc_opts { | |
61 | struct flow_dissector_key_enc_opts *key, *mask; | |
62 | }; | |
63 | ||
64 | struct flow_rule; | |
65 | ||
66 | void flow_rule_match_basic(const struct flow_rule *rule, | |
67 | struct flow_match_basic *out); | |
68 | void flow_rule_match_control(const struct flow_rule *rule, | |
69 | struct flow_match_control *out); | |
70 | void flow_rule_match_eth_addrs(const struct flow_rule *rule, | |
71 | struct flow_match_eth_addrs *out); | |
72 | void flow_rule_match_vlan(const struct flow_rule *rule, | |
73 | struct flow_match_vlan *out); | |
bae9ed69 EC |
74 | void flow_rule_match_cvlan(const struct flow_rule *rule, |
75 | struct flow_match_vlan *out); | |
8f256622 PNA |
76 | void flow_rule_match_ipv4_addrs(const struct flow_rule *rule, |
77 | struct flow_match_ipv4_addrs *out); | |
78 | void flow_rule_match_ipv6_addrs(const struct flow_rule *rule, | |
79 | struct flow_match_ipv6_addrs *out); | |
80 | void flow_rule_match_ip(const struct flow_rule *rule, | |
81 | struct flow_match_ip *out); | |
82 | void flow_rule_match_ports(const struct flow_rule *rule, | |
83 | struct flow_match_ports *out); | |
84 | void flow_rule_match_tcp(const struct flow_rule *rule, | |
85 | struct flow_match_tcp *out); | |
86 | void flow_rule_match_icmp(const struct flow_rule *rule, | |
87 | struct flow_match_icmp *out); | |
88 | void flow_rule_match_mpls(const struct flow_rule *rule, | |
89 | struct flow_match_mpls *out); | |
90 | void flow_rule_match_enc_control(const struct flow_rule *rule, | |
91 | struct flow_match_control *out); | |
92 | void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule, | |
93 | struct flow_match_ipv4_addrs *out); | |
94 | void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule, | |
95 | struct flow_match_ipv6_addrs *out); | |
96 | void flow_rule_match_enc_ip(const struct flow_rule *rule, | |
97 | struct flow_match_ip *out); | |
98 | void flow_rule_match_enc_ports(const struct flow_rule *rule, | |
99 | struct flow_match_ports *out); | |
100 | void flow_rule_match_enc_keyid(const struct flow_rule *rule, | |
101 | struct flow_match_enc_keyid *out); | |
102 | void flow_rule_match_enc_opts(const struct flow_rule *rule, | |
103 | struct flow_match_enc_opts *out); | |
104 | ||
e3ab786b PNA |
105 | enum flow_action_id { |
106 | FLOW_ACTION_ACCEPT = 0, | |
107 | FLOW_ACTION_DROP, | |
108 | FLOW_ACTION_TRAP, | |
109 | FLOW_ACTION_GOTO, | |
110 | FLOW_ACTION_REDIRECT, | |
111 | FLOW_ACTION_MIRRED, | |
112 | FLOW_ACTION_VLAN_PUSH, | |
113 | FLOW_ACTION_VLAN_POP, | |
114 | FLOW_ACTION_VLAN_MANGLE, | |
115 | FLOW_ACTION_TUNNEL_ENCAP, | |
116 | FLOW_ACTION_TUNNEL_DECAP, | |
117 | FLOW_ACTION_MANGLE, | |
118 | FLOW_ACTION_ADD, | |
119 | FLOW_ACTION_CSUM, | |
120 | FLOW_ACTION_MARK, | |
8bec2833 PNA |
121 | FLOW_ACTION_WAKE, |
122 | FLOW_ACTION_QUEUE, | |
a7a7be60 | 123 | FLOW_ACTION_SAMPLE, |
8c8cfc6e | 124 | FLOW_ACTION_POLICE, |
e3ab786b PNA |
125 | }; |
126 | ||
127 | /* This is mirroring enum pedit_header_type definition for easy mapping between | |
128 | * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to | |
129 | * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver. | |
130 | */ | |
131 | enum flow_action_mangle_base { | |
132 | FLOW_ACT_MANGLE_UNSPEC = 0, | |
133 | FLOW_ACT_MANGLE_HDR_TYPE_ETH, | |
134 | FLOW_ACT_MANGLE_HDR_TYPE_IP4, | |
135 | FLOW_ACT_MANGLE_HDR_TYPE_IP6, | |
136 | FLOW_ACT_MANGLE_HDR_TYPE_TCP, | |
137 | FLOW_ACT_MANGLE_HDR_TYPE_UDP, | |
138 | }; | |
139 | ||
140 | struct flow_action_entry { | |
141 | enum flow_action_id id; | |
142 | union { | |
143 | u32 chain_index; /* FLOW_ACTION_GOTO */ | |
144 | struct net_device *dev; /* FLOW_ACTION_REDIRECT */ | |
145 | struct { /* FLOW_ACTION_VLAN */ | |
146 | u16 vid; | |
147 | __be16 proto; | |
148 | u8 prio; | |
149 | } vlan; | |
150 | struct { /* FLOW_ACTION_PACKET_EDIT */ | |
151 | enum flow_action_mangle_base htype; | |
152 | u32 offset; | |
153 | u32 mask; | |
154 | u32 val; | |
155 | } mangle; | |
156 | const struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */ | |
157 | u32 csum_flags; /* FLOW_ACTION_CSUM */ | |
158 | u32 mark; /* FLOW_ACTION_MARK */ | |
8bec2833 PNA |
159 | struct { /* FLOW_ACTION_QUEUE */ |
160 | u32 ctx; | |
161 | u32 index; | |
162 | u8 vf; | |
163 | } queue; | |
a7a7be60 PJV |
164 | struct { /* FLOW_ACTION_SAMPLE */ |
165 | struct psample_group *psample_group; | |
166 | u32 rate; | |
167 | u32 trunc_size; | |
168 | bool truncate; | |
169 | } sample; | |
8c8cfc6e PJV |
170 | struct { /* FLOW_ACTION_POLICE */ |
171 | s64 burst; | |
172 | u64 rate_bytes_ps; | |
173 | } police; | |
e3ab786b PNA |
174 | }; |
175 | }; | |
176 | ||
177 | struct flow_action { | |
178 | unsigned int num_entries; | |
179 | struct flow_action_entry entries[0]; | |
180 | }; | |
181 | ||
182 | static inline bool flow_action_has_entries(const struct flow_action *action) | |
183 | { | |
184 | return action->num_entries; | |
185 | } | |
186 | ||
ab79af32 PJV |
187 | /** |
188 | * flow_action_has_one_action() - check if exactly one action is present | |
189 | * @action: tc filter flow offload action | |
190 | * | |
191 | * Returns true if exactly one action is present. | |
192 | */ | |
193 | static inline bool flow_offload_has_one_action(const struct flow_action *action) | |
194 | { | |
195 | return action->num_entries == 1; | |
196 | } | |
197 | ||
e3ab786b | 198 | #define flow_action_for_each(__i, __act, __actions) \ |
6663cf82 | 199 | for (__i = 0, __act = &(__actions)->entries[0]; __i < (__actions)->num_entries; __act = &(__actions)->entries[++__i]) |
e3ab786b | 200 | |
8f256622 PNA |
201 | struct flow_rule { |
202 | struct flow_match match; | |
e3ab786b | 203 | struct flow_action action; |
8f256622 PNA |
204 | }; |
205 | ||
e3ab786b | 206 | struct flow_rule *flow_rule_alloc(unsigned int num_actions); |
8f256622 PNA |
207 | |
208 | static inline bool flow_rule_match_key(const struct flow_rule *rule, | |
209 | enum flow_dissector_key_id key) | |
210 | { | |
211 | return dissector_uses_key(rule->match.dissector, key); | |
212 | } | |
213 | ||
3b1903ef PNA |
214 | struct flow_stats { |
215 | u64 pkts; | |
216 | u64 bytes; | |
217 | u64 lastused; | |
218 | }; | |
219 | ||
220 | static inline void flow_stats_update(struct flow_stats *flow_stats, | |
221 | u64 bytes, u64 pkts, u64 lastused) | |
222 | { | |
9f9dc493 JH |
223 | flow_stats->pkts += pkts; |
224 | flow_stats->bytes += bytes; | |
225 | flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused); | |
3b1903ef PNA |
226 | } |
227 | ||
8f256622 | 228 | #endif /* _NET_FLOW_OFFLOAD_H */ |