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>
25 #define foreach_flow_type \
26 _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
27 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
28 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
29 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
30 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
31 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
32 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
33 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
34 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
35 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
36 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
37 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
39 #define foreach_flow_entry_ip4_n_tuple \
40 _fe(ip4_address_and_mask_t, src_addr) \
41 _fe(ip4_address_and_mask_t, dst_addr) \
42 _fe(ip_port_and_mask_t, src_port) \
43 _fe(ip_port_and_mask_t, dst_port) \
44 _fe(ip_protocol_t, protocol)
46 #define foreach_flow_entry_ip6_n_tuple \
47 _fe(ip6_address_and_mask_t, src_addr) \
48 _fe(ip6_address_and_mask_t, dst_addr) \
49 _fe(ip_port_and_mask_t, src_port) \
50 _fe(ip_port_and_mask_t, dst_port) \
51 _fe(ip_protocol_t, protocol)
53 #define foreach_flow_entry_ip4_vxlan \
54 _fe(ip4_address_t, src_addr) \
55 _fe(ip4_address_t, dst_addr) \
59 #define foreach_flow_entry_ip6_vxlan \
60 _fe(ip6_address_t, src_addr) \
61 _fe(ip6_address_t, dst_addr) \
65 #define foreach_flow_entry_ip4_gtpc \
66 foreach_flow_entry_ip4_n_tuple \
69 #define foreach_flow_entry_ip4_gtpu \
70 foreach_flow_entry_ip4_n_tuple \
73 #define foreach_flow_entry_ip4_gtpu_ip4 \
74 foreach_flow_entry_ip4_gtpu \
75 _fe(ip4_address_and_mask_t, inner_src_addr) \
76 _fe(ip4_address_and_mask_t, inner_dst_addr)
78 #define foreach_flow_entry_ip4_gtpu_ip6 \
79 foreach_flow_entry_ip4_gtpu \
80 _fe(ip6_address_and_mask_t, inner_src_addr) \
81 _fe(ip6_address_and_mask_t, inner_dst_addr)
83 #define foreach_flow_entry_ip6_gtpc \
84 foreach_flow_entry_ip6_n_tuple \
87 #define foreach_flow_entry_ip6_gtpu \
88 foreach_flow_entry_ip6_n_tuple \
91 #define foreach_flow_entry_ip6_gtpu_ip4 \
92 foreach_flow_entry_ip6_gtpu \
93 _fe(ip4_address_and_mask_t, inner_src_addr) \
94 _fe(ip4_address_and_mask_t, inner_dst_addr)
96 #define foreach_flow_entry_ip6_gtpu_ip6 \
97 foreach_flow_entry_ip6_gtpu \
98 _fe(ip6_address_and_mask_t, inner_src_addr) \
99 _fe(ip6_address_and_mask_t, inner_dst_addr)
101 #define foreach_flow_action \
102 _(0, COUNT, "count") \
104 _(2, BUFFER_ADVANCE, "buffer-advance") \
105 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
106 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
111 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
114 } vnet_flow_action_t;
117 #define foreach_flow_error \
118 _( -1, NOT_SUPPORTED, "not supported") \
119 _( -2, ALREADY_DONE, "already done") \
120 _( -3, ALREADY_EXISTS, "already exists") \
121 _( -4, NO_SUCH_ENTRY, "no such entry") \
122 _( -5, NO_SUCH_INTERFACE, "no such interface") \
123 _( -6, INTERNAL, "internal error")
127 VNET_FLOW_NO_ERROR = 0,
128 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
136 } ip_port_and_mask_t;
140 VNET_FLOW_TYPE_UNKNOWN,
141 #define _(a,b,c) VNET_FLOW_TYPE_##a,
149 * Create typedef struct vnet_flow_XXX_t
151 #define _fe(a, b) a b;
155 foreach_flow_entry_##b \
161 /* main flow struct */
165 vnet_flow_type_t type;
170 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
173 /* flow id for VNET_FLOW_ACTION_MARK */
176 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
177 u32 redirect_node_index;
178 u32 redirect_device_input_next_index;
180 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
183 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
188 #define _(a,b,c) vnet_flow_##b##_t b;
193 /* per-interface private data */
197 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
199 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
200 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
201 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
202 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
203 vnet_flow_t *vnet_get_flow (u32 flow_index);
214 /* pool of device flow entries */
215 vnet_flow_t *global_flow_pool;
217 /* flow ids allocated */
220 /* vector of flow ranges */
221 vnet_flow_range_t *ranges;
225 extern vnet_flow_main_t flow_main;
227 format_function_t format_flow_actions;
228 format_function_t format_flow_enabled_hw;
230 #endif /* included_vnet_flow_flow_h */
233 * fd.io coding-style-patch-verification: ON
236 * eval: (c-set-style "gnu")