blob: 4945f4367c7271da18fababb5701e510e4ba9288 [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
27#define foreach_flow_type \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080028 /* l2 flow*/ \
29 _(ETHERNET, ethernet, "ethernet") \
Chenmin Sun34bfa502020-07-27 17:40:17 +080030 /* 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") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080037 /* l4 flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010038 _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
Hongjun Ni95eec062018-12-28 18:27:04 +080039 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
Chenmin Sunf13830c2020-02-26 19:22:35 +080040 _(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") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080042 /* L4 tunnel flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010043 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
Chenmin Sunbf85a982019-10-18 07:35:16 +080044 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
45 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
Chenmin Sun34bfa502020-07-27 17:40:17 +080046 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu")
Damjan Mariona35cc142018-03-16 01:25:27 +010047
Chenmin Sun4ff8d612019-12-15 01:16:45 +080048#define foreach_flow_entry_ethernet \
49 _fe(ethernet_header_t, eth_hdr)
50
Chenmin Sun34bfa502020-07-27 17:40:17 +080051#define foreach_flow_entry_ip4 \
Damjan Mariona35cc142018-03-16 01:25:27 +010052 _fe(ip4_address_and_mask_t, src_addr) \
53 _fe(ip4_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080054 _fe(ip_prot_and_mask_t, protocol)
Damjan Mariona35cc142018-03-16 01:25:27 +010055
Chenmin Sun34bfa502020-07-27 17:40:17 +080056#define foreach_flow_entry_ip6 \
Damjan Mariona35cc142018-03-16 01:25:27 +010057 _fe(ip6_address_and_mask_t, src_addr) \
58 _fe(ip6_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080059 _fe(ip_prot_and_mask_t, protocol)
Chenmin Sunf13830c2020-02-26 19:22:35 +080060
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080061#define foreach_flow_entry_ip4_l2tpv3oip \
Chenmin Sun34bfa502020-07-27 17:40:17 +080062 foreach_flow_entry_ip4 \
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080063 _fe(u32, session_id)
Chenmin Sunf13830c2020-02-26 19:22:35 +080064
Chenmin Sund4c36662020-06-22 18:21:31 +080065#define foreach_flow_entry_ip4_ipsec_esp \
Chenmin Sun34bfa502020-07-27 17:40:17 +080066 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080067 _fe(u32, spi)
68
69#define foreach_flow_entry_ip4_ipsec_ah \
Chenmin Sun34bfa502020-07-27 17:40:17 +080070 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080071 _fe(u32, spi)
72
Chenmin Sun34bfa502020-07-27 17:40:17 +080073#define foreach_flow_entry_ip4_n_tuple \
74 foreach_flow_entry_ip4 \
75 _fe(ip_port_and_mask_t, src_port) \
76 _fe(ip_port_and_mask_t, dst_port)
77
78#define foreach_flow_entry_ip6_n_tuple \
79 foreach_flow_entry_ip6 \
80 _fe(ip_port_and_mask_t, src_port) \
81 _fe(ip_port_and_mask_t, dst_port)
82
83#define foreach_flow_entry_ip4_n_tuple_tagged \
84 foreach_flow_entry_ip4 \
85 _fe(ip_port_and_mask_t, src_port) \
86 _fe(ip_port_and_mask_t, dst_port)
87
88#define foreach_flow_entry_ip6_n_tuple_tagged \
89 foreach_flow_entry_ip6 \
90 _fe(ip_port_and_mask_t, src_port) \
91 _fe(ip_port_and_mask_t, dst_port)
92
Chenmin Sun91f102e2020-12-08 00:42:43 +080093#define foreach_flow_entry_ip4_vxlan \
94 foreach_flow_entry_ip4_n_tuple _fe (u32, vni)
Damjan Mariona35cc142018-03-16 01:25:27 +010095
Chenmin Sun91f102e2020-12-08 00:42:43 +080096#define foreach_flow_entry_ip6_vxlan \
97 foreach_flow_entry_ip6_n_tuple _fe (u32, vni)
Damjan Mariona35cc142018-03-16 01:25:27 +010098
Chenmin Sunbf85a982019-10-18 07:35:16 +080099#define foreach_flow_entry_ip4_gtpc \
100 foreach_flow_entry_ip4_n_tuple \
101 _fe(u32, teid)
102
103#define foreach_flow_entry_ip4_gtpu \
104 foreach_flow_entry_ip4_n_tuple \
105 _fe(u32, teid)
106
Damjan Mariona35cc142018-03-16 01:25:27 +0100107#define foreach_flow_action \
108 _(0, COUNT, "count") \
109 _(1, MARK, "mark") \
110 _(2, BUFFER_ADVANCE, "buffer-advance") \
111 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
112 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
Chenmin Sun24e2c502020-02-28 22:49:37 +0800113 _(5, RSS, "rss") \
114 _(6, DROP, "drop")
Damjan Mariona35cc142018-03-16 01:25:27 +0100115
116typedef enum
117{
118#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
119 foreach_flow_action
120#undef _
121} vnet_flow_action_t;
122
Damjan Mariona35cc142018-03-16 01:25:27 +0100123#define foreach_flow_error \
124 _( -1, NOT_SUPPORTED, "not supported") \
125 _( -2, ALREADY_DONE, "already done") \
126 _( -3, ALREADY_EXISTS, "already exists") \
127 _( -4, NO_SUCH_ENTRY, "no such entry") \
128 _( -5, NO_SUCH_INTERFACE, "no such interface") \
129 _( -6, INTERNAL, "internal error")
130
Piotr Bronowskida6520b2021-07-02 09:20:03 +0000131#define foreach_flow_rss_types \
132 _ (0, FRAG_IPV4, "ipv4-frag") \
133 _ (1, IPV4_TCP, "ipv4-tcp") \
134 _ (2, IPV4_UDP, "ipv4-udp") \
135 _ (3, IPV4_SCTP, "ipv4-sctp") \
136 _ (4, IPV4_OTHER, "ipv4-other") \
137 _ (5, IPV4, "ipv4") \
138 _ (6, IPV6_TCP_EX, "ipv6-tcp-ex") \
139 _ (7, IPV6_UDP_EX, "ipv6-udp-ex") \
140 _ (8, FRAG_IPV6, "ipv6-frag") \
141 _ (9, IPV6_TCP, "ipv6-tcp") \
142 _ (10, IPV6_UDP, "ipv6-udp") \
143 _ (11, IPV6_SCTP, "ipv6-sctp") \
144 _ (12, IPV6_OTHER, "ipv6-other") \
145 _ (13, IPV6_EX, "ipv6-ex") \
146 _ (14, IPV6, "ipv6") \
147 _ (15, L2_PAYLOAD, "l2-payload") \
148 _ (16, PORT, "port") \
149 _ (17, VXLAN, "vxlan") \
150 _ (18, GENEVE, "geneve") \
151 _ (19, NVGRE, "nvgre") \
152 _ (20, GTPU, "gtpu") \
153 _ (21, ESP, "esp") \
154 _ (60, L4_DST_ONLY, "l4-dst-only") \
155 _ (61, L4_SRC_ONLY, "l4-src-only") \
156 _ (62, L3_DST_ONLY, "l3-dst-only") \
157 _ (63, L3_SRC_ONLY, "l3-src-only")
158
159typedef enum
160{
161#define _(v, n, s) VNET_FLOW_RSS_TYPES_##n = v,
162 foreach_flow_rss_types
163#undef _
164} vnet_flow_rss_types_t;
Chenmin Sun24e2c502020-02-28 22:49:37 +0800165
166#define foreach_rss_function \
167 _(DEFAULT, "default") \
168 _(TOEPLITZ, "toeplitz") \
169 _(SIMPLE_XOR, "simple_xor") \
170 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
171
Damjan Mariona35cc142018-03-16 01:25:27 +0100172typedef enum
173{
174 VNET_FLOW_NO_ERROR = 0,
175#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
176 foreach_flow_error
177#undef _
178} vnet_flow_error_t;
179
180typedef struct
181{
182 u16 port, mask;
183} ip_port_and_mask_t;
184
Chenmin Sun34bfa502020-07-27 17:40:17 +0800185typedef struct
186{
187 ip_protocol_t prot;
188 /* ip protocol mask should be either 0 or 0xFF */
189 /* other values are meanless */
190 u8 mask;
191} ip_prot_and_mask_t;
192
Damjan Mariona35cc142018-03-16 01:25:27 +0100193typedef enum
194{
195 VNET_FLOW_TYPE_UNKNOWN,
196#define _(a,b,c) VNET_FLOW_TYPE_##a,
197 foreach_flow_type
198#undef _
199 VNET_FLOW_N_TYPES,
200} vnet_flow_type_t;
201
Chenmin Sun24e2c502020-02-28 22:49:37 +0800202typedef enum
203{
204#define _(a,b) VNET_RSS_FUNC_##a,
205 foreach_rss_function
206#undef _
207 VNET_RSS_N_TYPES,
208} vnet_rss_function_t;
Damjan Mariona35cc142018-03-16 01:25:27 +0100209
210/*
211 * Create typedef struct vnet_flow_XXX_t
212 */
213#define _fe(a, b) a b;
214#define _(a,b,c) \
215typedef struct { \
216int foo; \
217foreach_flow_entry_##b \
218} vnet_flow_##b##_t;
219foreach_flow_type;
220#undef _
221#undef _fe
222
223/* main flow struct */
224typedef struct
225{
226 /* flow type */
227 vnet_flow_type_t type;
228
229 /* flow index */
230 u32 index;
231
232 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
233 u32 actions;
234
235 /* flow id for VNET_FLOW_ACTION_MARK */
236 u32 mark_flow_id;
237
238 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
239 u32 redirect_node_index;
240 u32 redirect_device_input_next_index;
241
242 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
243 u32 redirect_queue;
244
245 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
246 i32 buffer_advance;
247
Chenmin Sun24e2c502020-02-28 22:49:37 +0800248 /* RSS types, including IPv4/IPv6/TCP/UDP... */
249 u64 rss_types;
250
251 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
252 vnet_rss_function_t rss_fun;
253
Damjan Mariona35cc142018-03-16 01:25:27 +0100254 union
255 {
256#define _(a,b,c) vnet_flow_##b##_t b;
257 foreach_flow_type
258#undef _
259 };
260
261 /* per-interface private data */
262 uword *private_data;
263} vnet_flow_t;
264
265int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
266 u32 * start);
267int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
268int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
269int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
270int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
271vnet_flow_t *vnet_get_flow (u32 flow_index);
272
273typedef struct
274{
275 u32 start;
276 u32 count;
277 u8 *owner;
278} vnet_flow_range_t;
279
280typedef struct
281{
282 /* pool of device flow entries */
283 vnet_flow_t *global_flow_pool;
284
285 /* flow ids allocated */
286 u32 flows_used;
287
288 /* vector of flow ranges */
289 vnet_flow_range_t *ranges;
290
Filip Tehlar9597f082021-06-21 09:49:31 +0000291 u16 msg_id_base;
Damjan Mariona35cc142018-03-16 01:25:27 +0100292} vnet_flow_main_t;
293
294extern vnet_flow_main_t flow_main;
295
296format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300297format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100298
299#endif /* included_vnet_flow_flow_h */
300
301/*
302 * fd.io coding-style-patch-verification: ON
303 *
304 * Local Variables:
305 * eval: (c-set-style "gnu")
306 * End:
307 */