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") \
33 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
34 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
35 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
36 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
37 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
38 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
39 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
40 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
41 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
42 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
44 #define foreach_flow_entry_ethernet \
45 _fe(ethernet_header_t, eth_hdr)
47 #define foreach_flow_entry_ip4_n_tuple \
48 _fe(ip4_address_and_mask_t, src_addr) \
49 _fe(ip4_address_and_mask_t, dst_addr) \
50 _fe(ip_port_and_mask_t, src_port) \
51 _fe(ip_port_and_mask_t, dst_port) \
52 _fe(ip_protocol_t, protocol)
54 #define foreach_flow_entry_ip6_n_tuple \
55 _fe(ip6_address_and_mask_t, src_addr) \
56 _fe(ip6_address_and_mask_t, dst_addr) \
57 _fe(ip_port_and_mask_t, src_port) \
58 _fe(ip_port_and_mask_t, dst_port) \
59 _fe(ip_protocol_t, protocol)
61 #define foreach_flow_entry_ip4_vxlan \
62 _fe(ip4_address_t, src_addr) \
63 _fe(ip4_address_t, dst_addr) \
67 #define foreach_flow_entry_ip6_vxlan \
68 _fe(ip6_address_t, src_addr) \
69 _fe(ip6_address_t, dst_addr) \
73 #define foreach_flow_entry_ip4_gtpc \
74 foreach_flow_entry_ip4_n_tuple \
77 #define foreach_flow_entry_ip4_gtpu \
78 foreach_flow_entry_ip4_n_tuple \
81 #define foreach_flow_entry_ip4_gtpu_ip4 \
82 foreach_flow_entry_ip4_gtpu \
83 _fe(ip4_address_and_mask_t, inner_src_addr) \
84 _fe(ip4_address_and_mask_t, inner_dst_addr)
86 #define foreach_flow_entry_ip4_gtpu_ip6 \
87 foreach_flow_entry_ip4_gtpu \
88 _fe(ip6_address_and_mask_t, inner_src_addr) \
89 _fe(ip6_address_and_mask_t, inner_dst_addr)
91 #define foreach_flow_entry_ip6_gtpc \
92 foreach_flow_entry_ip6_n_tuple \
95 #define foreach_flow_entry_ip6_gtpu \
96 foreach_flow_entry_ip6_n_tuple \
99 #define foreach_flow_entry_ip6_gtpu_ip4 \
100 foreach_flow_entry_ip6_gtpu \
101 _fe(ip4_address_and_mask_t, inner_src_addr) \
102 _fe(ip4_address_and_mask_t, inner_dst_addr)
104 #define foreach_flow_entry_ip6_gtpu_ip6 \
105 foreach_flow_entry_ip6_gtpu \
106 _fe(ip6_address_and_mask_t, inner_src_addr) \
107 _fe(ip6_address_and_mask_t, inner_dst_addr)
109 #define foreach_flow_action \
110 _(0, COUNT, "count") \
112 _(2, BUFFER_ADVANCE, "buffer-advance") \
113 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
114 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
119 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
122 } vnet_flow_action_t;
125 #define foreach_flow_error \
126 _( -1, NOT_SUPPORTED, "not supported") \
127 _( -2, ALREADY_DONE, "already done") \
128 _( -3, ALREADY_EXISTS, "already exists") \
129 _( -4, NO_SUCH_ENTRY, "no such entry") \
130 _( -5, NO_SUCH_INTERFACE, "no such interface") \
131 _( -6, INTERNAL, "internal error")
135 VNET_FLOW_NO_ERROR = 0,
136 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
144 } ip_port_and_mask_t;
148 VNET_FLOW_TYPE_UNKNOWN,
149 #define _(a,b,c) VNET_FLOW_TYPE_##a,
157 * Create typedef struct vnet_flow_XXX_t
159 #define _fe(a, b) a b;
163 foreach_flow_entry_##b \
169 /* main flow struct */
173 vnet_flow_type_t type;
178 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
181 /* flow id for VNET_FLOW_ACTION_MARK */
184 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
185 u32 redirect_node_index;
186 u32 redirect_device_input_next_index;
188 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
191 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
196 #define _(a,b,c) vnet_flow_##b##_t b;
201 /* per-interface private data */
205 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
207 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
208 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
209 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
210 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
211 vnet_flow_t *vnet_get_flow (u32 flow_index);
222 /* pool of device flow entries */
223 vnet_flow_t *global_flow_pool;
225 /* flow ids allocated */
228 /* vector of flow ranges */
229 vnet_flow_range_t *ranges;
233 extern vnet_flow_main_t flow_main;
235 format_function_t format_flow_actions;
236 format_function_t format_flow_enabled_hw;
238 #endif /* included_vnet_flow_flow_h */
241 * fd.io coding-style-patch-verification: ON
244 * eval: (c-set-style "gnu")