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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vnet_flow_flow_h
17 #define included_vnet_flow_flow_h
19 #include <vppinfra/clib.h>
20 #include <vppinfra/pcap.h>
21 #include <vnet/vnet.h>
22 #include <vnet/l3_types.h>
23 #include <vnet/ip/ip4_packet.h>
24 #include <vnet/ip/ip6_packet.h>
25 #include <vnet/ethernet/packet.h>
27 #define foreach_flow_type \
29 _ (ETHERNET, ethernet, "ethernet") \
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") \
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") \
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") \
48 _ (GENERIC, generic, "generic") \
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")
59 #define foreach_flow_entry_ethernet \
60 _fe(ethernet_header_t, eth_hdr)
62 #define foreach_flow_entry_ip4 \
63 _fe(ip4_address_and_mask_t, src_addr) \
64 _fe(ip4_address_and_mask_t, dst_addr) \
65 _fe(ip_prot_and_mask_t, protocol)
67 #define foreach_flow_entry_ip6 \
68 _fe(ip6_address_and_mask_t, src_addr) \
69 _fe(ip6_address_and_mask_t, dst_addr) \
70 _fe(ip_prot_and_mask_t, protocol)
72 #define foreach_flow_entry_ip4_l2tpv3oip \
73 foreach_flow_entry_ip4 \
76 #define foreach_flow_entry_ip4_ipsec_esp \
77 foreach_flow_entry_ip4 \
80 #define foreach_flow_entry_ip4_ipsec_ah \
81 foreach_flow_entry_ip4 \
84 #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)
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)
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)
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)
104 #define foreach_flow_entry_ip4_vxlan \
105 foreach_flow_entry_ip4_n_tuple _fe (u32, vni)
107 #define foreach_flow_entry_ip6_vxlan \
108 foreach_flow_entry_ip6_n_tuple _fe (u32, vni)
110 #define foreach_flow_entry_ip4_gtpc \
111 foreach_flow_entry_ip4_n_tuple \
114 #define foreach_flow_entry_ip4_gtpu \
115 foreach_flow_entry_ip4_n_tuple \
118 #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)
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)
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)
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)
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)
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)
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)
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)
154 #define foreach_flow_entry_generic _fe (generic_pattern_t, pattern)
156 #define foreach_flow_action \
157 _(0, COUNT, "count") \
159 _(2, BUFFER_ADVANCE, "buffer-advance") \
160 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
161 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
167 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
170 } vnet_flow_action_t;
172 #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")
180 #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") \
203 _ (60, L4_DST_ONLY, "l4-dst-only") \
204 _ (61, L4_SRC_ONLY, "l4-src-only") \
205 _ (62, L3_DST_ONLY, "l3-dst-only") \
206 _ (63, L3_SRC_ONLY, "l3-src-only")
210 #define _(v, n, s) VNET_FLOW_RSS_TYPES_##n = v,
211 foreach_flow_rss_types
213 } vnet_flow_rss_types_t;
215 #define foreach_rss_function \
216 _(DEFAULT, "default") \
217 _(TOEPLITZ, "toeplitz") \
218 _(SIMPLE_XOR, "simple_xor") \
219 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
223 VNET_FLOW_NO_ERROR = 0,
224 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
232 } ip_port_and_mask_t;
237 /* ip protocol mask should be either 0 or 0xFF */
238 /* other values are meanless */
240 } ip_prot_and_mask_t;
250 VNET_FLOW_TYPE_UNKNOWN,
251 #define _(a,b,c) VNET_FLOW_TYPE_##a,
259 #define _(a,b) VNET_RSS_FUNC_##a,
263 } vnet_rss_function_t;
266 * Create typedef struct vnet_flow_XXX_t
268 #define _fe(a, b) a b;
272 foreach_flow_entry_##b \
278 /* main flow struct */
282 vnet_flow_type_t type;
287 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
290 /* flow id for VNET_FLOW_ACTION_MARK */
293 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
294 u32 redirect_node_index;
295 u32 redirect_device_input_next_index;
297 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
300 /* start queue index and queue numbers for RSS queue group */
304 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
307 /* RSS types, including IPv4/IPv6/TCP/UDP... */
310 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
311 vnet_rss_function_t rss_fun;
315 #define _(a,b,c) vnet_flow_##b##_t b;
320 /* per-interface private data */
324 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
326 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
327 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
328 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
329 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
330 vnet_flow_t *vnet_get_flow (u32 flow_index);
341 /* pool of device flow entries */
342 vnet_flow_t *global_flow_pool;
344 /* flow ids allocated */
347 /* vector of flow ranges */
348 vnet_flow_range_t *ranges;
353 extern vnet_flow_main_t flow_main;
355 format_function_t format_flow_actions;
356 format_function_t format_flow_enabled_hw;
358 #endif /* included_vnet_flow_flow_h */
361 * fd.io coding-style-patch-verification: ON
364 * eval: (c-set-style "gnu")