blob: a880b8a69be0ccb4d3906b8c5c6fc8b8932be430 [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 Sun8b43aaa2020-04-15 01:55:58 +080034 /* IP tunnel flow */ \
35 _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
Chenmin Sun4ff8d612019-12-15 01:16:45 +080036 /* L4 tunnel flow*/ \
Damjan Mariona35cc142018-03-16 01:25:27 +010037 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
Chenmin Sunbf85a982019-10-18 07:35:16 +080038 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
39 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
40 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
41 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
42 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
43 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
44 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
45 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
46 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
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
Damjan Mariona35cc142018-03-16 01:25:27 +010051#define foreach_flow_entry_ip4_n_tuple \
52 _fe(ip4_address_and_mask_t, src_addr) \
53 _fe(ip4_address_and_mask_t, dst_addr) \
54 _fe(ip_port_and_mask_t, src_port) \
55 _fe(ip_port_and_mask_t, dst_port) \
56 _fe(ip_protocol_t, protocol)
57
58#define foreach_flow_entry_ip6_n_tuple \
59 _fe(ip6_address_and_mask_t, src_addr) \
60 _fe(ip6_address_and_mask_t, dst_addr) \
61 _fe(ip_port_and_mask_t, src_port) \
62 _fe(ip_port_and_mask_t, dst_port) \
63 _fe(ip_protocol_t, protocol)
64
Chenmin Sunf13830c2020-02-26 19:22:35 +080065#define foreach_flow_entry_ip4_n_tuple_tagged \
66 _fe(ip4_address_and_mask_t, src_addr) \
67 _fe(ip4_address_and_mask_t, dst_addr) \
68 _fe(ip_port_and_mask_t, src_port) \
69 _fe(ip_port_and_mask_t, dst_port) \
70 _fe(ip_protocol_t, protocol)
71
72#define foreach_flow_entry_ip6_n_tuple_tagged \
73 _fe(ip6_address_and_mask_t, src_addr) \
74 _fe(ip6_address_and_mask_t, dst_addr) \
75 _fe(ip_port_and_mask_t, src_port) \
76 _fe(ip_port_and_mask_t, dst_port) \
77 _fe(ip_protocol_t, protocol)
78
Chenmin Sun8b43aaa2020-04-15 01:55:58 +080079#define foreach_flow_entry_ip4_l2tpv3oip \
80 _fe(ip4_address_and_mask_t, src_addr) \
81 _fe(ip4_address_and_mask_t, dst_addr) \
82 _fe(ip_protocol_t, protocol) \
83 _fe(u32, session_id)
Chenmin Sunf13830c2020-02-26 19:22:35 +080084
Damjan Mariona35cc142018-03-16 01:25:27 +010085#define foreach_flow_entry_ip4_vxlan \
86 _fe(ip4_address_t, src_addr) \
87 _fe(ip4_address_t, dst_addr) \
88 _fe(u16, dst_port) \
89 _fe(u16, vni)
90
91#define foreach_flow_entry_ip6_vxlan \
92 _fe(ip6_address_t, src_addr) \
93 _fe(ip6_address_t, dst_addr) \
94 _fe(u16, dst_port) \
95 _fe(u16, vni)
96
Chenmin Sunbf85a982019-10-18 07:35:16 +080097#define foreach_flow_entry_ip4_gtpc \
98 foreach_flow_entry_ip4_n_tuple \
99 _fe(u32, teid)
100
101#define foreach_flow_entry_ip4_gtpu \
102 foreach_flow_entry_ip4_n_tuple \
103 _fe(u32, teid)
104
105#define foreach_flow_entry_ip4_gtpu_ip4 \
106 foreach_flow_entry_ip4_gtpu \
107 _fe(ip4_address_and_mask_t, inner_src_addr) \
108 _fe(ip4_address_and_mask_t, inner_dst_addr)
109
110#define foreach_flow_entry_ip4_gtpu_ip6 \
111 foreach_flow_entry_ip4_gtpu \
112 _fe(ip6_address_and_mask_t, inner_src_addr) \
113 _fe(ip6_address_and_mask_t, inner_dst_addr)
114
115#define foreach_flow_entry_ip6_gtpc \
116 foreach_flow_entry_ip6_n_tuple \
117 _fe(u32, teid)
118
119#define foreach_flow_entry_ip6_gtpu \
120 foreach_flow_entry_ip6_n_tuple \
121 _fe(u32, teid)
122
123#define foreach_flow_entry_ip6_gtpu_ip4 \
124 foreach_flow_entry_ip6_gtpu \
125 _fe(ip4_address_and_mask_t, inner_src_addr) \
126 _fe(ip4_address_and_mask_t, inner_dst_addr)
127
128#define foreach_flow_entry_ip6_gtpu_ip6 \
129 foreach_flow_entry_ip6_gtpu \
130 _fe(ip6_address_and_mask_t, inner_src_addr) \
131 _fe(ip6_address_and_mask_t, inner_dst_addr)
132
Damjan Mariona35cc142018-03-16 01:25:27 +0100133#define foreach_flow_action \
134 _(0, COUNT, "count") \
135 _(1, MARK, "mark") \
136 _(2, BUFFER_ADVANCE, "buffer-advance") \
137 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
138 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
Chenmin Sun24e2c502020-02-28 22:49:37 +0800139 _(5, RSS, "rss") \
140 _(6, DROP, "drop")
Damjan Mariona35cc142018-03-16 01:25:27 +0100141
142typedef enum
143{
144#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
145 foreach_flow_action
146#undef _
147} vnet_flow_action_t;
148
149
150#define foreach_flow_error \
151 _( -1, NOT_SUPPORTED, "not supported") \
152 _( -2, ALREADY_DONE, "already done") \
153 _( -3, ALREADY_EXISTS, "already exists") \
154 _( -4, NO_SUCH_ENTRY, "no such entry") \
155 _( -5, NO_SUCH_INTERFACE, "no such interface") \
156 _( -6, INTERNAL, "internal error")
157
Chenmin Sun24e2c502020-02-28 22:49:37 +0800158#define foreach_flow_rss_types \
159 _(0, FRAG_IPV4, "ipv4-frag") \
160 _(1, IPV4_TCP, "ipv4-tcp") \
161 _(2, IPV4_UDP, "ipv4-udp") \
162 _(3, IPV4_SCTP, "ipv4-sctp") \
163 _(4, IPV4_OTHER, "ipv4-other") \
164 _(5, IPV4, "ipv4") \
165 _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
166 _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
167 _(8, FRAG_IPV6, "ipv6-frag") \
168 _(9, IPV6_TCP, "ipv6-tcp") \
169 _(10, IPV6_UDP, "ipv6-udp") \
170 _(11, IPV6_SCTP, "ipv6-sctp") \
171 _(12, IPV6_OTHER, "ipv6-other") \
172 _(13, IPV6_EX, "ipv6-ex") \
173 _(14, IPV6, "ipv6") \
174 _(15, L2_PAYLOAD, "l2-payload") \
175 _(16, PORT, "port") \
176 _(17, VXLAN, "vxlan") \
177 _(18, GENEVE, "geneve") \
178 _(19, NVGRE, "nvgre") \
179 _(20, GTPU, "gtpu") \
180 _(60, L4_DST_ONLY, "l4-dst-only") \
181 _(61, L4_SRC_ONLY, "l4-src-only") \
182 _(62, L3_DST_ONLY, "l3-dst-only") \
183 _(63, L3_SRC_ONLY, "l3-src-only")
184
185#define foreach_rss_function \
186 _(DEFAULT, "default") \
187 _(TOEPLITZ, "toeplitz") \
188 _(SIMPLE_XOR, "simple_xor") \
189 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
190
Damjan Mariona35cc142018-03-16 01:25:27 +0100191typedef enum
192{
193 VNET_FLOW_NO_ERROR = 0,
194#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
195 foreach_flow_error
196#undef _
197} vnet_flow_error_t;
198
199typedef struct
200{
201 u16 port, mask;
202} ip_port_and_mask_t;
203
204typedef enum
205{
206 VNET_FLOW_TYPE_UNKNOWN,
207#define _(a,b,c) VNET_FLOW_TYPE_##a,
208 foreach_flow_type
209#undef _
210 VNET_FLOW_N_TYPES,
211} vnet_flow_type_t;
212
Chenmin Sun24e2c502020-02-28 22:49:37 +0800213typedef enum
214{
215#define _(a,b) VNET_RSS_FUNC_##a,
216 foreach_rss_function
217#undef _
218 VNET_RSS_N_TYPES,
219} vnet_rss_function_t;
Damjan Mariona35cc142018-03-16 01:25:27 +0100220
221/*
222 * Create typedef struct vnet_flow_XXX_t
223 */
224#define _fe(a, b) a b;
225#define _(a,b,c) \
226typedef struct { \
227int foo; \
228foreach_flow_entry_##b \
229} vnet_flow_##b##_t;
230foreach_flow_type;
231#undef _
232#undef _fe
233
234/* main flow struct */
235typedef struct
236{
237 /* flow type */
238 vnet_flow_type_t type;
239
240 /* flow index */
241 u32 index;
242
243 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
244 u32 actions;
245
246 /* flow id for VNET_FLOW_ACTION_MARK */
247 u32 mark_flow_id;
248
249 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
250 u32 redirect_node_index;
251 u32 redirect_device_input_next_index;
252
253 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
254 u32 redirect_queue;
255
256 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
257 i32 buffer_advance;
258
Chenmin Sun24e2c502020-02-28 22:49:37 +0800259 /* RSS types, including IPv4/IPv6/TCP/UDP... */
260 u64 rss_types;
261
262 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
263 vnet_rss_function_t rss_fun;
264
Damjan Mariona35cc142018-03-16 01:25:27 +0100265 union
266 {
267#define _(a,b,c) vnet_flow_##b##_t b;
268 foreach_flow_type
269#undef _
270 };
271
272 /* per-interface private data */
273 uword *private_data;
274} vnet_flow_t;
275
276int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
277 u32 * start);
278int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
279int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
280int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
281int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
282vnet_flow_t *vnet_get_flow (u32 flow_index);
283
284typedef struct
285{
286 u32 start;
287 u32 count;
288 u8 *owner;
289} vnet_flow_range_t;
290
291typedef struct
292{
293 /* pool of device flow entries */
294 vnet_flow_t *global_flow_pool;
295
296 /* flow ids allocated */
297 u32 flows_used;
298
299 /* vector of flow ranges */
300 vnet_flow_range_t *ranges;
301
302} vnet_flow_main_t;
303
304extern vnet_flow_main_t flow_main;
305
306format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300307format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100308
309#endif /* included_vnet_flow_flow_h */
310
311/*
312 * fd.io coding-style-patch-verification: ON
313 *
314 * Local Variables:
315 * eval: (c-set-style "gnu")
316 * End:
317 */