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/l3_types.h>
22 #include <vnet/ip/ip4_packet.h>
23 #include <vnet/ip/ip6_packet.h>
24 #include <vnet/ethernet/packet.h>
26 #define foreach_flow_type \
28 _(ETHERNET, ethernet, "ethernet") \
30 _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
31 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
32 _(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") \
34 /* IP tunnel flow */ \
35 _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
36 _(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
37 _(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
39 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
40 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
41 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
42 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
43 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
44 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
45 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
46 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
47 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
48 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
50 #define foreach_flow_entry_ethernet \
51 _fe(ethernet_header_t, eth_hdr)
53 #define foreach_flow_entry_ip4_n_tuple \
54 _fe(ip4_address_and_mask_t, src_addr) \
55 _fe(ip4_address_and_mask_t, dst_addr) \
56 _fe(ip_port_and_mask_t, src_port) \
57 _fe(ip_port_and_mask_t, dst_port) \
58 _fe(ip_protocol_t, protocol)
60 #define foreach_flow_entry_ip6_n_tuple \
61 _fe(ip6_address_and_mask_t, src_addr) \
62 _fe(ip6_address_and_mask_t, dst_addr) \
63 _fe(ip_port_and_mask_t, src_port) \
64 _fe(ip_port_and_mask_t, dst_port) \
65 _fe(ip_protocol_t, protocol)
67 #define foreach_flow_entry_ip4_n_tuple_tagged \
68 _fe(ip4_address_and_mask_t, src_addr) \
69 _fe(ip4_address_and_mask_t, dst_addr) \
70 _fe(ip_port_and_mask_t, src_port) \
71 _fe(ip_port_and_mask_t, dst_port) \
72 _fe(ip_protocol_t, protocol)
74 #define foreach_flow_entry_ip6_n_tuple_tagged \
75 _fe(ip6_address_and_mask_t, src_addr) \
76 _fe(ip6_address_and_mask_t, dst_addr) \
77 _fe(ip_port_and_mask_t, src_port) \
78 _fe(ip_port_and_mask_t, dst_port) \
79 _fe(ip_protocol_t, protocol)
81 #define foreach_flow_entry_ip4_l2tpv3oip \
82 _fe(ip4_address_and_mask_t, src_addr) \
83 _fe(ip4_address_and_mask_t, dst_addr) \
84 _fe(ip_protocol_t, protocol) \
87 #define foreach_flow_entry_ip4_ipsec_esp \
88 _fe(ip4_address_and_mask_t, src_addr) \
89 _fe(ip4_address_and_mask_t, dst_addr) \
90 _fe(ip_protocol_t, protocol) \
93 #define foreach_flow_entry_ip4_ipsec_ah \
94 _fe(ip4_address_and_mask_t, src_addr) \
95 _fe(ip4_address_and_mask_t, dst_addr) \
96 _fe(ip_protocol_t, protocol) \
99 #define foreach_flow_entry_ip4_vxlan \
100 _fe(ip4_address_t, src_addr) \
101 _fe(ip4_address_t, dst_addr) \
105 #define foreach_flow_entry_ip6_vxlan \
106 _fe(ip6_address_t, src_addr) \
107 _fe(ip6_address_t, dst_addr) \
111 #define foreach_flow_entry_ip4_gtpc \
112 foreach_flow_entry_ip4_n_tuple \
115 #define foreach_flow_entry_ip4_gtpu \
116 foreach_flow_entry_ip4_n_tuple \
119 #define foreach_flow_entry_ip4_gtpu_ip4 \
120 foreach_flow_entry_ip4_gtpu \
121 _fe(ip4_address_and_mask_t, inner_src_addr) \
122 _fe(ip4_address_and_mask_t, inner_dst_addr)
124 #define foreach_flow_entry_ip4_gtpu_ip6 \
125 foreach_flow_entry_ip4_gtpu \
126 _fe(ip6_address_and_mask_t, inner_src_addr) \
127 _fe(ip6_address_and_mask_t, inner_dst_addr)
129 #define foreach_flow_entry_ip6_gtpc \
130 foreach_flow_entry_ip6_n_tuple \
133 #define foreach_flow_entry_ip6_gtpu \
134 foreach_flow_entry_ip6_n_tuple \
137 #define foreach_flow_entry_ip6_gtpu_ip4 \
138 foreach_flow_entry_ip6_gtpu \
139 _fe(ip4_address_and_mask_t, inner_src_addr) \
140 _fe(ip4_address_and_mask_t, inner_dst_addr)
142 #define foreach_flow_entry_ip6_gtpu_ip6 \
143 foreach_flow_entry_ip6_gtpu \
144 _fe(ip6_address_and_mask_t, inner_src_addr) \
145 _fe(ip6_address_and_mask_t, inner_dst_addr)
147 #define foreach_flow_action \
148 _(0, COUNT, "count") \
150 _(2, BUFFER_ADVANCE, "buffer-advance") \
151 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
152 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
158 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
161 } vnet_flow_action_t;
164 #define foreach_flow_error \
165 _( -1, NOT_SUPPORTED, "not supported") \
166 _( -2, ALREADY_DONE, "already done") \
167 _( -3, ALREADY_EXISTS, "already exists") \
168 _( -4, NO_SUCH_ENTRY, "no such entry") \
169 _( -5, NO_SUCH_INTERFACE, "no such interface") \
170 _( -6, INTERNAL, "internal error")
172 #define foreach_flow_rss_types \
173 _(0, FRAG_IPV4, "ipv4-frag") \
174 _(1, IPV4_TCP, "ipv4-tcp") \
175 _(2, IPV4_UDP, "ipv4-udp") \
176 _(3, IPV4_SCTP, "ipv4-sctp") \
177 _(4, IPV4_OTHER, "ipv4-other") \
179 _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
180 _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
181 _(8, FRAG_IPV6, "ipv6-frag") \
182 _(9, IPV6_TCP, "ipv6-tcp") \
183 _(10, IPV6_UDP, "ipv6-udp") \
184 _(11, IPV6_SCTP, "ipv6-sctp") \
185 _(12, IPV6_OTHER, "ipv6-other") \
186 _(13, IPV6_EX, "ipv6-ex") \
187 _(14, IPV6, "ipv6") \
188 _(15, L2_PAYLOAD, "l2-payload") \
189 _(16, PORT, "port") \
190 _(17, VXLAN, "vxlan") \
191 _(18, GENEVE, "geneve") \
192 _(19, NVGRE, "nvgre") \
193 _(20, GTPU, "gtpu") \
194 _(60, L4_DST_ONLY, "l4-dst-only") \
195 _(61, L4_SRC_ONLY, "l4-src-only") \
196 _(62, L3_DST_ONLY, "l3-dst-only") \
197 _(63, L3_SRC_ONLY, "l3-src-only")
199 #define foreach_rss_function \
200 _(DEFAULT, "default") \
201 _(TOEPLITZ, "toeplitz") \
202 _(SIMPLE_XOR, "simple_xor") \
203 _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
207 VNET_FLOW_NO_ERROR = 0,
208 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
216 } ip_port_and_mask_t;
220 VNET_FLOW_TYPE_UNKNOWN,
221 #define _(a,b,c) VNET_FLOW_TYPE_##a,
229 #define _(a,b) VNET_RSS_FUNC_##a,
233 } vnet_rss_function_t;
236 * Create typedef struct vnet_flow_XXX_t
238 #define _fe(a, b) a b;
242 foreach_flow_entry_##b \
248 /* main flow struct */
252 vnet_flow_type_t type;
257 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
260 /* flow id for VNET_FLOW_ACTION_MARK */
263 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
264 u32 redirect_node_index;
265 u32 redirect_device_input_next_index;
267 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
270 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
273 /* RSS types, including IPv4/IPv6/TCP/UDP... */
276 /* RSS functions, including IPv4/IPv6/TCP/UDP... */
277 vnet_rss_function_t rss_fun;
281 #define _(a,b,c) vnet_flow_##b##_t b;
286 /* per-interface private data */
290 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
292 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
293 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
294 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
295 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
296 vnet_flow_t *vnet_get_flow (u32 flow_index);
307 /* pool of device flow entries */
308 vnet_flow_t *global_flow_pool;
310 /* flow ids allocated */
313 /* vector of flow ranges */
314 vnet_flow_range_t *ranges;
318 extern vnet_flow_main_t flow_main;
320 format_function_t format_flow_actions;
321 format_function_t format_flow_enabled_hw;
323 #endif /* included_vnet_flow_flow_h */
326 * fd.io coding-style-patch-verification: ON
329 * eval: (c-set-style "gnu")