blob: ada822257e3d0b675b29c703c8d3f3dfd55c714f [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>
Neale Rannsf7040f02022-02-15 09:02:27 +000021#include <vnet/vnet.h>
Damjan Mariona35cc142018-03-16 01:25:27 +010022#include <vnet/l3_types.h>
23#include <vnet/ip/ip4_packet.h>
24#include <vnet/ip/ip6_packet.h>
Chenmin Sun4ff8d612019-12-15 01:16:45 +080025#include <vnet/ethernet/packet.h>
Damjan Mariona35cc142018-03-16 01:25:27 +010026
Ting Xu3a366822021-09-16 08:37:25 +000027#define foreach_flow_type \
28 /* l2 flow*/ \
29 _ (ETHERNET, ethernet, "ethernet") \
30 /* l3 IP flow */ \
31 _ (IP4, ip4, "ipv4") \
32 _ (IP6, ip6, "ipv6") \
33 /* IP tunnel flow */ \
34 _ (IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
35 _ (IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
36 _ (IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
37 /* l4 flow*/ \
38 _ (IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
39 _ (IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
40 _ (IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
41 _ (IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
42 /* L4 tunnel flow*/ \
43 _ (IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
44 _ (IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
45 _ (IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
46 _ (IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
47 /* generic flow */ \
Xinyao Cai99d3a402023-02-28 14:44:58 +080048 _ (GENERIC, generic, "generic") \
49 /* IP in IP */ \
50 _ (IP6_IP6, ip6_ip6, "ipv6-ipv6") \
51 _ (IP6_IP4, ip6_ip4, "ipv6-ipv4") \
52 _ (IP4_IP6, ip4_ip6, "ipv4-ipv6") \
53 _ (IP4_IP4, ip4_ip4, "ipv4-ipv4") \
54 _ (IP6_IP6_N_TUPLE, ip6_ip6_n_tuple, "ipv6-ipv6-n-tuple") \
55 _ (IP6_IP4_N_TUPLE, ip6_ip4_n_tuple, "ipv6-ipv4-n-tuple") \
56 _ (IP4_IP6_N_TUPLE, ip4_ip6_n_tuple, "ipv4-ipv6-n-tuple") \
57 _ (IP4_IP4_N_TUPLE, ip4_ip4_n_tuple, "ipv4-ipv4-n-tuple")
Damjan Mariona35cc142018-03-16 01:25:27 +010058
Chenmin Sun4ff8d612019-12-15 01:16:45 +080059#define foreach_flow_entry_ethernet \
60 _fe(ethernet_header_t, eth_hdr)
61
Chenmin Sun34bfa502020-07-27 17:40:17 +080062#define foreach_flow_entry_ip4 \
Damjan Mariona35cc142018-03-16 01:25:27 +010063 _fe(ip4_address_and_mask_t, src_addr) \
64 _fe(ip4_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080065 _fe(ip_prot_and_mask_t, protocol)
Damjan Mariona35cc142018-03-16 01:25:27 +010066
Chenmin Sun34bfa502020-07-27 17:40:17 +080067#define foreach_flow_entry_ip6 \
Damjan Mariona35cc142018-03-16 01:25:27 +010068 _fe(ip6_address_and_mask_t, src_addr) \
69 _fe(ip6_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080070 _fe(ip_prot_and_mask_t, protocol)
Chenmin Sunf13830c2020-02-26 19:22:35 +080071
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080072#define foreach_flow_entry_ip4_l2tpv3oip \
Chenmin Sun34bfa502020-07-27 17:40:17 +080073 foreach_flow_entry_ip4 \
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080074 _fe(u32, session_id)
Chenmin Sunf13830c2020-02-26 19:22:35 +080075
Chenmin Sund4c36662020-06-22 18:21:31 +080076#define foreach_flow_entry_ip4_ipsec_esp \
Chenmin Sun34bfa502020-07-27 17:40:17 +080077 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080078 _fe(u32, spi)
79
80#define foreach_flow_entry_ip4_ipsec_ah \
Chenmin Sun34bfa502020-07-27 17:40:17 +080081 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080082 _fe(u32, spi)
83
Chenmin Sun34bfa502020-07-27 17:40:17 +080084#define foreach_flow_entry_ip4_n_tuple \
85 foreach_flow_entry_ip4 \
86 _fe(ip_port_and_mask_t, src_port) \
87 _fe(ip_port_and_mask_t, dst_port)
88
89#define foreach_flow_entry_ip6_n_tuple \
90 foreach_flow_entry_ip6 \
91 _fe(ip_port_and_mask_t, src_port) \
92 _fe(ip_port_and_mask_t, dst_port)
93
94#define foreach_flow_entry_ip4_n_tuple_tagged \
95 foreach_flow_entry_ip4 \
96 _fe(ip_port_and_mask_t, src_port) \
97 _fe(ip_port_and_mask_t, dst_port)
98
99#define foreach_flow_entry_ip6_n_tuple_tagged \
100 foreach_flow_entry_ip6 \
101 _fe(ip_port_and_mask_t, src_port) \
102 _fe(ip_port_and_mask_t, dst_port)
103
Chenmin Sun91f102e2020-12-08 00:42:43 +0800104#define foreach_flow_entry_ip4_vxlan \
105 foreach_flow_entry_ip4_n_tuple _fe (u32, vni)
Damjan Mariona35cc142018-03-16 01:25:27 +0100106
Chenmin Sun91f102e2020-12-08 00:42:43 +0800107#define foreach_flow_entry_ip6_vxlan \
108 foreach_flow_entry_ip6_n_tuple _fe (u32, vni)
Damjan Mariona35cc142018-03-16 01:25:27 +0100109
Chenmin Sunbf85a982019-10-18 07:35:16 +0800110#define foreach_flow_entry_ip4_gtpc \
111 foreach_flow_entry_ip4_n_tuple \
112 _fe(u32, teid)
113
114#define foreach_flow_entry_ip4_gtpu \
115 foreach_flow_entry_ip4_n_tuple \
116 _fe(u32, teid)
117
Xinyao Cai99d3a402023-02-28 14:44:58 +0800118#define foreach_flow_entry_ip6_ip6 \
119 foreach_flow_entry_ip6 _fe (ip6_address_and_mask_t, in_src_addr) \
120 _fe (ip6_address_and_mask_t, in_dst_addr) \
121 _fe (ip_prot_and_mask_t, in_protocol)
122
123#define foreach_flow_entry_ip6_ip6_n_tuple \
124 foreach_flow_entry_ip6_ip6 _fe (ip_port_and_mask_t, in_src_port) \
125 _fe (ip_port_and_mask_t, in_dst_port)
126
127#define foreach_flow_entry_ip6_ip4 \
128 foreach_flow_entry_ip6 _fe (ip4_address_and_mask_t, in_src_addr) \
129 _fe (ip4_address_and_mask_t, in_dst_addr) \
130 _fe (ip_prot_and_mask_t, in_protocol)
131
132#define foreach_flow_entry_ip6_ip4_n_tuple \
133 foreach_flow_entry_ip6_ip4 _fe (ip_port_and_mask_t, in_src_port) \
134 _fe (ip_port_and_mask_t, in_dst_port)
135
136#define foreach_flow_entry_ip4_ip6 \
137 foreach_flow_entry_ip4 _fe (ip6_address_and_mask_t, in_src_addr) \
138 _fe (ip6_address_and_mask_t, in_dst_addr) \
139 _fe (ip_prot_and_mask_t, in_protocol)
140
141#define foreach_flow_entry_ip4_ip6_n_tuple \
142 foreach_flow_entry_ip4_ip6 _fe (ip_port_and_mask_t, in_src_port) \
143 _fe (ip_port_and_mask_t, in_dst_port)
144
145#define foreach_flow_entry_ip4_ip4 \
146 foreach_flow_entry_ip4 _fe (ip4_address_and_mask_t, in_src_addr) \
147 _fe (ip4_address_and_mask_t, in_dst_addr) \
148 _fe (ip_prot_and_mask_t, in_protocol)
149
150#define foreach_flow_entry_ip4_ip4_n_tuple \
151 foreach_flow_entry_ip4_ip4 _fe (ip_port_and_mask_t, in_src_port) \
152 _fe (ip_port_and_mask_t, in_dst_port)
153
Ting Xu3a366822021-09-16 08:37:25 +0000154#define foreach_flow_entry_generic _fe (generic_pattern_t, pattern)
155
Damjan Mariona35cc142018-03-16 01:25:27 +0100156#define foreach_flow_action \
157 _(0, COUNT, "count") \
158 _(1, MARK, "mark") \
159 _(2, BUFFER_ADVANCE, "buffer-advance") \
160 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
161 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
Chenmin Sun24e2c502020-02-28 22:49:37 +0800162 _(5, RSS, "rss") \
163 _(6, DROP, "drop")
Damjan Mariona35cc142018-03-16 01:25:27 +0100164
165typedef enum
166{
167#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
168 foreach_flow_action
169#undef _
170} vnet_flow_action_t;
171
Damjan Mariona35cc142018-03-16 01:25:27 +0100172#define foreach_flow_error \
173 _( -1, NOT_SUPPORTED, "not supported") \
174 _( -2, ALREADY_DONE, "already done") \
175 _( -3, ALREADY_EXISTS, "already exists") \
176 _( -4, NO_SUCH_ENTRY, "no such entry") \
177 _( -5, NO_SUCH_INTERFACE, "no such interface") \
178 _( -6, INTERNAL, "internal error")
179
Piotr Bronowskida6520b2021-07-02 09:20:03 +0000180#define foreach_flow_rss_types \
181 _ (0, FRAG_IPV4, "ipv4-frag") \
182 _ (1, IPV4_TCP, "ipv4-tcp") \
183 _ (2, IPV4_UDP, "ipv4-udp") \
184 _ (3, IPV4_SCTP, "ipv4-sctp") \
185 _ (4, IPV4_OTHER, "ipv4-other") \
186 _ (5, IPV4, "ipv4") \
187 _ (6, IPV6_TCP_EX, "ipv6-tcp-ex") \
188 _ (7, IPV6_UDP_EX, "ipv6-udp-ex") \
189 _ (8, FRAG_IPV6, "ipv6-frag") \
190 _ (9, IPV6_TCP, "ipv6-tcp") \
191 _ (10, IPV6_UDP, "ipv6-udp") \
192 _ (11, IPV6_SCTP, "ipv6-sctp") \
193 _ (12, IPV6_OTHER, "ipv6-other") \
194 _ (13, IPV6_EX, "ipv6-ex") \
195 _ (14, IPV6, "ipv6") \
196 _ (15, L2_PAYLOAD, "l2-payload") \
197 _ (16, PORT, "port") \
198 _ (17, VXLAN, "vxlan") \
199 _ (18, GENEVE, "geneve") \
200 _ (19, NVGRE, "nvgre") \
201 _ (20, GTPU, "gtpu") \
202 _ (21, ESP, "esp") \
Xinyao Cai6cb72732023-05-25 09:16:57 +0800203 _ (22, L2TPV3, "l2tpv3") \
Piotr Bronowskida6520b2021-07-02 09:20:03 +0000204 _ (60, L4_DST_ONLY, "l4-dst-only") \
205 _ (61, L4_SRC_ONLY, "l4-src-only") \
206 _ (62, L3_DST_ONLY, "l3-dst-only") \
207 _ (63, L3_SRC_ONLY, "l3-src-only")
208
209typedef enum
210{
211#define _(v, n, s) VNET_FLOW_RSS_TYPES_##n = v,
212 foreach_flow_rss_types
213#undef _
214} vnet_flow_rss_types_t;
Chenmin Sun24e2c502020-02-28 22:49:37 +0800215
216#define foreach_rss_function \
217 _(DEFAULT, "default") \
218 _(TOEPLITZ, "toeplitz") \
219 _(SIMPLE_XOR, "simple_xor") \
220 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
221
Damjan Mariona35cc142018-03-16 01:25:27 +0100222typedef enum
223{
224 VNET_FLOW_NO_ERROR = 0,
225#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
226 foreach_flow_error
227#undef _
228} vnet_flow_error_t;
229
230typedef struct
231{
232 u16 port, mask;
233} ip_port_and_mask_t;
234
Chenmin Sun34bfa502020-07-27 17:40:17 +0800235typedef struct
236{
237 ip_protocol_t prot;
238 /* ip protocol mask should be either 0 or 0xFF */
239 /* other values are meanless */
240 u8 mask;
241} ip_prot_and_mask_t;
242
Ting Xu3a366822021-09-16 08:37:25 +0000243typedef struct
244{
245 u8 spec[1024];
246 u8 mask[1024];
247} generic_pattern_t;
248
Damjan Mariona35cc142018-03-16 01:25:27 +0100249typedef enum
250{
251 VNET_FLOW_TYPE_UNKNOWN,
252#define _(a,b,c) VNET_FLOW_TYPE_##a,
253 foreach_flow_type
254#undef _
255 VNET_FLOW_N_TYPES,
256} vnet_flow_type_t;
257
Chenmin Sun24e2c502020-02-28 22:49:37 +0800258typedef enum
259{
260#define _(a,b) VNET_RSS_FUNC_##a,
261 foreach_rss_function
262#undef _
263 VNET_RSS_N_TYPES,
264} vnet_rss_function_t;
Damjan Mariona35cc142018-03-16 01:25:27 +0100265
266/*
267 * Create typedef struct vnet_flow_XXX_t
268 */
269#define _fe(a, b) a b;
270#define _(a,b,c) \
271typedef struct { \
272int foo; \
273foreach_flow_entry_##b \
274} vnet_flow_##b##_t;
275foreach_flow_type;
276#undef _
277#undef _fe
278
279/* main flow struct */
280typedef struct
281{
282 /* flow type */
283 vnet_flow_type_t type;
284
285 /* flow index */
286 u32 index;
287
288 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
289 u32 actions;
290
291 /* flow id for VNET_FLOW_ACTION_MARK */
292 u32 mark_flow_id;
293
294 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
295 u32 redirect_node_index;
296 u32 redirect_device_input_next_index;
297
298 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
299 u32 redirect_queue;
300
Ting Xub95e6d42022-03-25 03:45:07 +0000301 /* start queue index and queue numbers for RSS queue group */
302 u32 queue_index;
303 u32 queue_num;
304
Damjan Mariona35cc142018-03-16 01:25:27 +0100305 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
306 i32 buffer_advance;
307
Chenmin Sun24e2c502020-02-28 22:49:37 +0800308 /* RSS types, including IPv4/IPv6/TCP/UDP... */
309 u64 rss_types;
310
311 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
312 vnet_rss_function_t rss_fun;
313
Damjan Mariona35cc142018-03-16 01:25:27 +0100314 union
315 {
316#define _(a,b,c) vnet_flow_##b##_t b;
317 foreach_flow_type
318#undef _
319 };
320
321 /* per-interface private data */
322 uword *private_data;
323} vnet_flow_t;
324
325int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
326 u32 * start);
327int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
328int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
329int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
330int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
331vnet_flow_t *vnet_get_flow (u32 flow_index);
332
333typedef struct
334{
335 u32 start;
336 u32 count;
337 u8 *owner;
338} vnet_flow_range_t;
339
340typedef struct
341{
342 /* pool of device flow entries */
343 vnet_flow_t *global_flow_pool;
344
345 /* flow ids allocated */
346 u32 flows_used;
347
348 /* vector of flow ranges */
349 vnet_flow_range_t *ranges;
350
Filip Tehlar9597f082021-06-21 09:49:31 +0000351 u16 msg_id_base;
Damjan Mariona35cc142018-03-16 01:25:27 +0100352} vnet_flow_main_t;
353
354extern vnet_flow_main_t flow_main;
355
356format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300357format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100358
359#endif /* included_vnet_flow_flow_h */
360
361/*
362 * fd.io coding-style-patch-verification: ON
363 *
364 * Local Variables:
365 * eval: (c-set-style "gnu")
366 * End:
367 */