blob: d6850b282d762a1661c2bc63fd45df8ef007007d [file] [log] [blame]
Damjan Mariona35cc142018-03-16 01:25:27 +01001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef included_vnet_flow_flow_h
17#define included_vnet_flow_flow_h
18
19#include <vppinfra/clib.h>
Dave Barach3ae28732018-11-16 17:19:00 -050020#include <vppinfra/pcap.h>
Damjan Mariona35cc142018-03-16 01:25:27 +010021#include <vnet/l3_types.h>
22#include <vnet/ip/ip4_packet.h>
23#include <vnet/ip/ip6_packet.h>
Chenmin Sun4ff8d612019-12-15 01:16:45 +080024#include <vnet/ethernet/packet.h>
Damjan Mariona35cc142018-03-16 01:25:27 +010025
26#define foreach_flow_type \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080027 /* l2 flow*/ \
28 _(ETHERNET, ethernet, "ethernet") \
29 /* l4 flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010030 _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
Hongjun Ni95eec062018-12-28 18:27:04 +080031 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
Chenmin Sunf13830c2020-02-26 19:22:35 +080032 _(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
33 _(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080034 /* L4 tunnel flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010035 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
Chenmin Sunbf85a982019-10-18 07:35:16 +080036 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
37 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
38 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
39 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
40 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
41 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
42 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
43 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
44 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
Damjan Mariona35cc142018-03-16 01:25:27 +010045
Chenmin Sun4ff8d612019-12-15 01:16:45 +080046#define foreach_flow_entry_ethernet \
47 _fe(ethernet_header_t, eth_hdr)
48
Damjan Mariona35cc142018-03-16 01:25:27 +010049#define foreach_flow_entry_ip4_n_tuple \
50 _fe(ip4_address_and_mask_t, src_addr) \
51 _fe(ip4_address_and_mask_t, dst_addr) \
52 _fe(ip_port_and_mask_t, src_port) \
53 _fe(ip_port_and_mask_t, dst_port) \
54 _fe(ip_protocol_t, protocol)
55
56#define foreach_flow_entry_ip6_n_tuple \
57 _fe(ip6_address_and_mask_t, src_addr) \
58 _fe(ip6_address_and_mask_t, dst_addr) \
59 _fe(ip_port_and_mask_t, src_port) \
60 _fe(ip_port_and_mask_t, dst_port) \
61 _fe(ip_protocol_t, protocol)
62
Chenmin Sunf13830c2020-02-26 19:22:35 +080063#define foreach_flow_entry_ip4_n_tuple_tagged \
64 _fe(ip4_address_and_mask_t, src_addr) \
65 _fe(ip4_address_and_mask_t, dst_addr) \
66 _fe(ip_port_and_mask_t, src_port) \
67 _fe(ip_port_and_mask_t, dst_port) \
68 _fe(ip_protocol_t, protocol)
69
70#define foreach_flow_entry_ip6_n_tuple_tagged \
71 _fe(ip6_address_and_mask_t, src_addr) \
72 _fe(ip6_address_and_mask_t, dst_addr) \
73 _fe(ip_port_and_mask_t, src_port) \
74 _fe(ip_port_and_mask_t, dst_port) \
75 _fe(ip_protocol_t, protocol)
76
77
Damjan Mariona35cc142018-03-16 01:25:27 +010078#define foreach_flow_entry_ip4_vxlan \
79 _fe(ip4_address_t, src_addr) \
80 _fe(ip4_address_t, dst_addr) \
81 _fe(u16, dst_port) \
82 _fe(u16, vni)
83
84#define foreach_flow_entry_ip6_vxlan \
85 _fe(ip6_address_t, src_addr) \
86 _fe(ip6_address_t, dst_addr) \
87 _fe(u16, dst_port) \
88 _fe(u16, vni)
89
Chenmin Sunbf85a982019-10-18 07:35:16 +080090#define foreach_flow_entry_ip4_gtpc \
91 foreach_flow_entry_ip4_n_tuple \
92 _fe(u32, teid)
93
94#define foreach_flow_entry_ip4_gtpu \
95 foreach_flow_entry_ip4_n_tuple \
96 _fe(u32, teid)
97
98#define foreach_flow_entry_ip4_gtpu_ip4 \
99 foreach_flow_entry_ip4_gtpu \
100 _fe(ip4_address_and_mask_t, inner_src_addr) \
101 _fe(ip4_address_and_mask_t, inner_dst_addr)
102
103#define foreach_flow_entry_ip4_gtpu_ip6 \
104 foreach_flow_entry_ip4_gtpu \
105 _fe(ip6_address_and_mask_t, inner_src_addr) \
106 _fe(ip6_address_and_mask_t, inner_dst_addr)
107
108#define foreach_flow_entry_ip6_gtpc \
109 foreach_flow_entry_ip6_n_tuple \
110 _fe(u32, teid)
111
112#define foreach_flow_entry_ip6_gtpu \
113 foreach_flow_entry_ip6_n_tuple \
114 _fe(u32, teid)
115
116#define foreach_flow_entry_ip6_gtpu_ip4 \
117 foreach_flow_entry_ip6_gtpu \
118 _fe(ip4_address_and_mask_t, inner_src_addr) \
119 _fe(ip4_address_and_mask_t, inner_dst_addr)
120
121#define foreach_flow_entry_ip6_gtpu_ip6 \
122 foreach_flow_entry_ip6_gtpu \
123 _fe(ip6_address_and_mask_t, inner_src_addr) \
124 _fe(ip6_address_and_mask_t, inner_dst_addr)
125
Damjan Mariona35cc142018-03-16 01:25:27 +0100126#define foreach_flow_action \
127 _(0, COUNT, "count") \
128 _(1, MARK, "mark") \
129 _(2, BUFFER_ADVANCE, "buffer-advance") \
130 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
131 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
Chenmin Sun24e2c502020-02-28 22:49:37 +0800132 _(5, RSS, "rss") \
133 _(6, DROP, "drop")
Damjan Mariona35cc142018-03-16 01:25:27 +0100134
135typedef enum
136{
137#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
138 foreach_flow_action
139#undef _
140} vnet_flow_action_t;
141
142
143#define foreach_flow_error \
144 _( -1, NOT_SUPPORTED, "not supported") \
145 _( -2, ALREADY_DONE, "already done") \
146 _( -3, ALREADY_EXISTS, "already exists") \
147 _( -4, NO_SUCH_ENTRY, "no such entry") \
148 _( -5, NO_SUCH_INTERFACE, "no such interface") \
149 _( -6, INTERNAL, "internal error")
150
Chenmin Sun24e2c502020-02-28 22:49:37 +0800151#define foreach_flow_rss_types \
152 _(0, FRAG_IPV4, "ipv4-frag") \
153 _(1, IPV4_TCP, "ipv4-tcp") \
154 _(2, IPV4_UDP, "ipv4-udp") \
155 _(3, IPV4_SCTP, "ipv4-sctp") \
156 _(4, IPV4_OTHER, "ipv4-other") \
157 _(5, IPV4, "ipv4") \
158 _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
159 _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
160 _(8, FRAG_IPV6, "ipv6-frag") \
161 _(9, IPV6_TCP, "ipv6-tcp") \
162 _(10, IPV6_UDP, "ipv6-udp") \
163 _(11, IPV6_SCTP, "ipv6-sctp") \
164 _(12, IPV6_OTHER, "ipv6-other") \
165 _(13, IPV6_EX, "ipv6-ex") \
166 _(14, IPV6, "ipv6") \
167 _(15, L2_PAYLOAD, "l2-payload") \
168 _(16, PORT, "port") \
169 _(17, VXLAN, "vxlan") \
170 _(18, GENEVE, "geneve") \
171 _(19, NVGRE, "nvgre") \
172 _(20, GTPU, "gtpu") \
173 _(60, L4_DST_ONLY, "l4-dst-only") \
174 _(61, L4_SRC_ONLY, "l4-src-only") \
175 _(62, L3_DST_ONLY, "l3-dst-only") \
176 _(63, L3_SRC_ONLY, "l3-src-only")
177
178#define foreach_rss_function \
179 _(DEFAULT, "default") \
180 _(TOEPLITZ, "toeplitz") \
181 _(SIMPLE_XOR, "simple_xor") \
182 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
183
Damjan Mariona35cc142018-03-16 01:25:27 +0100184typedef enum
185{
186 VNET_FLOW_NO_ERROR = 0,
187#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
188 foreach_flow_error
189#undef _
190} vnet_flow_error_t;
191
192typedef struct
193{
194 u16 port, mask;
195} ip_port_and_mask_t;
196
197typedef enum
198{
199 VNET_FLOW_TYPE_UNKNOWN,
200#define _(a,b,c) VNET_FLOW_TYPE_##a,
201 foreach_flow_type
202#undef _
203 VNET_FLOW_N_TYPES,
204} vnet_flow_type_t;
205
Chenmin Sun24e2c502020-02-28 22:49:37 +0800206typedef enum
207{
208#define _(a,b) VNET_RSS_FUNC_##a,
209 foreach_rss_function
210#undef _
211 VNET_RSS_N_TYPES,
212} vnet_rss_function_t;
Damjan Mariona35cc142018-03-16 01:25:27 +0100213
214/*
215 * Create typedef struct vnet_flow_XXX_t
216 */
217#define _fe(a, b) a b;
218#define _(a,b,c) \
219typedef struct { \
220int foo; \
221foreach_flow_entry_##b \
222} vnet_flow_##b##_t;
223foreach_flow_type;
224#undef _
225#undef _fe
226
227/* main flow struct */
228typedef struct
229{
230 /* flow type */
231 vnet_flow_type_t type;
232
233 /* flow index */
234 u32 index;
235
236 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
237 u32 actions;
238
239 /* flow id for VNET_FLOW_ACTION_MARK */
240 u32 mark_flow_id;
241
242 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
243 u32 redirect_node_index;
244 u32 redirect_device_input_next_index;
245
246 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
247 u32 redirect_queue;
248
249 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
250 i32 buffer_advance;
251
Chenmin Sun24e2c502020-02-28 22:49:37 +0800252 /* RSS types, including IPv4/IPv6/TCP/UDP... */
253 u64 rss_types;
254
255 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
256 vnet_rss_function_t rss_fun;
257
Damjan Mariona35cc142018-03-16 01:25:27 +0100258 union
259 {
260#define _(a,b,c) vnet_flow_##b##_t b;
261 foreach_flow_type
262#undef _
263 };
264
265 /* per-interface private data */
266 uword *private_data;
267} vnet_flow_t;
268
269int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
270 u32 * start);
271int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
272int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
273int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
274int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
275vnet_flow_t *vnet_get_flow (u32 flow_index);
276
277typedef struct
278{
279 u32 start;
280 u32 count;
281 u8 *owner;
282} vnet_flow_range_t;
283
284typedef struct
285{
286 /* pool of device flow entries */
287 vnet_flow_t *global_flow_pool;
288
289 /* flow ids allocated */
290 u32 flows_used;
291
292 /* vector of flow ranges */
293 vnet_flow_range_t *ranges;
294
295} vnet_flow_main_t;
296
297extern vnet_flow_main_t flow_main;
298
299format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300300format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100301
302#endif /* included_vnet_flow_flow_h */
303
304/*
305 * fd.io coding-style-patch-verification: ON
306 *
307 * Local Variables:
308 * eval: (c-set-style "gnu")
309 * End:
310 */