blob: 04305edf92ad20726168707a5690656f40da636a [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") \
Chenmin Sun34bfa502020-07-27 17:40:17 +080029 /* l3 IP flow */ \
30 _(IP4, ip4, "ipv4") \
31 _(IP6, ip6, "ipv6") \
32 /* IP tunnel flow */ \
33 _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
34 _(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
35 _(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080036 /* l4 flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010037 _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
Hongjun Ni95eec062018-12-28 18:27:04 +080038 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
Chenmin Sunf13830c2020-02-26 19:22:35 +080039 _(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
40 _(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080041 /* L4 tunnel flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010042 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
Chenmin Sunbf85a982019-10-18 07:35:16 +080043 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
44 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
Chenmin Sun34bfa502020-07-27 17:40:17 +080045 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu")
Damjan Mariona35cc142018-03-16 01:25:27 +010046
Chenmin Sun4ff8d612019-12-15 01:16:45 +080047#define foreach_flow_entry_ethernet \
48 _fe(ethernet_header_t, eth_hdr)
49
Chenmin Sun34bfa502020-07-27 17:40:17 +080050#define foreach_flow_entry_ip4 \
Damjan Mariona35cc142018-03-16 01:25:27 +010051 _fe(ip4_address_and_mask_t, src_addr) \
52 _fe(ip4_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080053 _fe(ip_prot_and_mask_t, protocol)
Damjan Mariona35cc142018-03-16 01:25:27 +010054
Chenmin Sun34bfa502020-07-27 17:40:17 +080055#define foreach_flow_entry_ip6 \
Damjan Mariona35cc142018-03-16 01:25:27 +010056 _fe(ip6_address_and_mask_t, src_addr) \
57 _fe(ip6_address_and_mask_t, dst_addr) \
Chenmin Sun34bfa502020-07-27 17:40:17 +080058 _fe(ip_prot_and_mask_t, protocol)
Chenmin Sunf13830c2020-02-26 19:22:35 +080059
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080060#define foreach_flow_entry_ip4_l2tpv3oip \
Chenmin Sun34bfa502020-07-27 17:40:17 +080061 foreach_flow_entry_ip4 \
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080062 _fe(u32, session_id)
Chenmin Sunf13830c2020-02-26 19:22:35 +080063
Chenmin Sund4c36662020-06-22 18:21:31 +080064#define foreach_flow_entry_ip4_ipsec_esp \
Chenmin Sun34bfa502020-07-27 17:40:17 +080065 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080066 _fe(u32, spi)
67
68#define foreach_flow_entry_ip4_ipsec_ah \
Chenmin Sun34bfa502020-07-27 17:40:17 +080069 foreach_flow_entry_ip4 \
Chenmin Sund4c36662020-06-22 18:21:31 +080070 _fe(u32, spi)
71
Chenmin Sun34bfa502020-07-27 17:40:17 +080072#define foreach_flow_entry_ip4_n_tuple \
73 foreach_flow_entry_ip4 \
74 _fe(ip_port_and_mask_t, src_port) \
75 _fe(ip_port_and_mask_t, dst_port)
76
77#define foreach_flow_entry_ip6_n_tuple \
78 foreach_flow_entry_ip6 \
79 _fe(ip_port_and_mask_t, src_port) \
80 _fe(ip_port_and_mask_t, dst_port)
81
82#define foreach_flow_entry_ip4_n_tuple_tagged \
83 foreach_flow_entry_ip4 \
84 _fe(ip_port_and_mask_t, src_port) \
85 _fe(ip_port_and_mask_t, dst_port)
86
87#define foreach_flow_entry_ip6_n_tuple_tagged \
88 foreach_flow_entry_ip6 \
89 _fe(ip_port_and_mask_t, src_port) \
90 _fe(ip_port_and_mask_t, dst_port)
91
Damjan Mariona35cc142018-03-16 01:25:27 +010092#define foreach_flow_entry_ip4_vxlan \
Chenmin Sun34bfa502020-07-27 17:40:17 +080093 foreach_flow_entry_ip4_n_tuple \
Damjan Mariona35cc142018-03-16 01:25:27 +010094 _fe(u16, vni)
95
96#define foreach_flow_entry_ip6_vxlan \
Chenmin Sun34bfa502020-07-27 17:40:17 +080097 foreach_flow_entry_ip6_n_tuple \
Damjan Mariona35cc142018-03-16 01:25:27 +010098 _fe(u16, vni)
99
Chenmin Sunbf85a982019-10-18 07:35:16 +0800100#define foreach_flow_entry_ip4_gtpc \
101 foreach_flow_entry_ip4_n_tuple \
102 _fe(u32, teid)
103
104#define foreach_flow_entry_ip4_gtpu \
105 foreach_flow_entry_ip4_n_tuple \
106 _fe(u32, teid)
107
Damjan Mariona35cc142018-03-16 01:25:27 +0100108#define foreach_flow_action \
109 _(0, COUNT, "count") \
110 _(1, MARK, "mark") \
111 _(2, BUFFER_ADVANCE, "buffer-advance") \
112 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
113 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
Chenmin Sun24e2c502020-02-28 22:49:37 +0800114 _(5, RSS, "rss") \
115 _(6, DROP, "drop")
Damjan Mariona35cc142018-03-16 01:25:27 +0100116
117typedef enum
118{
119#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
120 foreach_flow_action
121#undef _
122} vnet_flow_action_t;
123
Damjan Mariona35cc142018-03-16 01:25:27 +0100124#define foreach_flow_error \
125 _( -1, NOT_SUPPORTED, "not supported") \
126 _( -2, ALREADY_DONE, "already done") \
127 _( -3, ALREADY_EXISTS, "already exists") \
128 _( -4, NO_SUCH_ENTRY, "no such entry") \
129 _( -5, NO_SUCH_INTERFACE, "no such interface") \
130 _( -6, INTERNAL, "internal error")
131
Chenmin Sun24e2c502020-02-28 22:49:37 +0800132#define foreach_flow_rss_types \
133 _(0, FRAG_IPV4, "ipv4-frag") \
134 _(1, IPV4_TCP, "ipv4-tcp") \
135 _(2, IPV4_UDP, "ipv4-udp") \
136 _(3, IPV4_SCTP, "ipv4-sctp") \
137 _(4, IPV4_OTHER, "ipv4-other") \
138 _(5, IPV4, "ipv4") \
139 _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
140 _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
141 _(8, FRAG_IPV6, "ipv6-frag") \
142 _(9, IPV6_TCP, "ipv6-tcp") \
143 _(10, IPV6_UDP, "ipv6-udp") \
144 _(11, IPV6_SCTP, "ipv6-sctp") \
145 _(12, IPV6_OTHER, "ipv6-other") \
146 _(13, IPV6_EX, "ipv6-ex") \
147 _(14, IPV6, "ipv6") \
148 _(15, L2_PAYLOAD, "l2-payload") \
149 _(16, PORT, "port") \
150 _(17, VXLAN, "vxlan") \
151 _(18, GENEVE, "geneve") \
152 _(19, NVGRE, "nvgre") \
153 _(20, GTPU, "gtpu") \
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
159#define foreach_rss_function \
160 _(DEFAULT, "default") \
161 _(TOEPLITZ, "toeplitz") \
162 _(SIMPLE_XOR, "simple_xor") \
163 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
164
Damjan Mariona35cc142018-03-16 01:25:27 +0100165typedef enum
166{
167 VNET_FLOW_NO_ERROR = 0,
168#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
169 foreach_flow_error
170#undef _
171} vnet_flow_error_t;
172
173typedef struct
174{
175 u16 port, mask;
176} ip_port_and_mask_t;
177
Chenmin Sun34bfa502020-07-27 17:40:17 +0800178typedef struct
179{
180 ip_protocol_t prot;
181 /* ip protocol mask should be either 0 or 0xFF */
182 /* other values are meanless */
183 u8 mask;
184} ip_prot_and_mask_t;
185
Damjan Mariona35cc142018-03-16 01:25:27 +0100186typedef enum
187{
188 VNET_FLOW_TYPE_UNKNOWN,
189#define _(a,b,c) VNET_FLOW_TYPE_##a,
190 foreach_flow_type
191#undef _
192 VNET_FLOW_N_TYPES,
193} vnet_flow_type_t;
194
Chenmin Sun24e2c502020-02-28 22:49:37 +0800195typedef enum
196{
197#define _(a,b) VNET_RSS_FUNC_##a,
198 foreach_rss_function
199#undef _
200 VNET_RSS_N_TYPES,
201} vnet_rss_function_t;
Damjan Mariona35cc142018-03-16 01:25:27 +0100202
203/*
204 * Create typedef struct vnet_flow_XXX_t
205 */
206#define _fe(a, b) a b;
207#define _(a,b,c) \
208typedef struct { \
209int foo; \
210foreach_flow_entry_##b \
211} vnet_flow_##b##_t;
212foreach_flow_type;
213#undef _
214#undef _fe
215
216/* main flow struct */
217typedef struct
218{
219 /* flow type */
220 vnet_flow_type_t type;
221
222 /* flow index */
223 u32 index;
224
225 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
226 u32 actions;
227
228 /* flow id for VNET_FLOW_ACTION_MARK */
229 u32 mark_flow_id;
230
231 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
232 u32 redirect_node_index;
233 u32 redirect_device_input_next_index;
234
235 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
236 u32 redirect_queue;
237
238 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
239 i32 buffer_advance;
240
Chenmin Sun24e2c502020-02-28 22:49:37 +0800241 /* RSS types, including IPv4/IPv6/TCP/UDP... */
242 u64 rss_types;
243
244 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
245 vnet_rss_function_t rss_fun;
246
Damjan Mariona35cc142018-03-16 01:25:27 +0100247 union
248 {
249#define _(a,b,c) vnet_flow_##b##_t b;
250 foreach_flow_type
251#undef _
252 };
253
254 /* per-interface private data */
255 uword *private_data;
256} vnet_flow_t;
257
258int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
259 u32 * start);
260int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
261int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
262int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
263int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
264vnet_flow_t *vnet_get_flow (u32 flow_index);
265
266typedef struct
267{
268 u32 start;
269 u32 count;
270 u8 *owner;
271} vnet_flow_range_t;
272
273typedef struct
274{
275 /* pool of device flow entries */
276 vnet_flow_t *global_flow_pool;
277
278 /* flow ids allocated */
279 u32 flows_used;
280
281 /* vector of flow ranges */
282 vnet_flow_range_t *ranges;
283
284} vnet_flow_main_t;
285
286extern vnet_flow_main_t flow_main;
287
288format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300289format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100290
291#endif /* included_vnet_flow_flow_h */
292
293/*
294 * fd.io coding-style-patch-verification: ON
295 *
296 * Local Variables:
297 * eval: (c-set-style "gnu")
298 * End:
299 */