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") \
35 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
36 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
37 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
38 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
39 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
40 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
41 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
42 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
43 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
44 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
46 #define foreach_flow_entry_ethernet \
47 _fe(ethernet_header_t, eth_hdr)
49 #define foreach_flow_entry_ip4_n_tuple \
50 _fe(ip4_address_and_mask_t, src_addr) \
51 _fe(ip4_address_and_mask_t, dst_addr) \
52 _fe(ip_port_and_mask_t, src_port) \
53 _fe(ip_port_and_mask_t, dst_port) \
54 _fe(ip_protocol_t, protocol)
56 #define foreach_flow_entry_ip6_n_tuple \
57 _fe(ip6_address_and_mask_t, src_addr) \
58 _fe(ip6_address_and_mask_t, dst_addr) \
59 _fe(ip_port_and_mask_t, src_port) \
60 _fe(ip_port_and_mask_t, dst_port) \
61 _fe(ip_protocol_t, protocol)
63 #define foreach_flow_entry_ip4_n_tuple_tagged \
64 _fe(ip4_address_and_mask_t, src_addr) \
65 _fe(ip4_address_and_mask_t, dst_addr) \
66 _fe(ip_port_and_mask_t, src_port) \
67 _fe(ip_port_and_mask_t, dst_port) \
68 _fe(ip_protocol_t, protocol)
70 #define foreach_flow_entry_ip6_n_tuple_tagged \
71 _fe(ip6_address_and_mask_t, src_addr) \
72 _fe(ip6_address_and_mask_t, dst_addr) \
73 _fe(ip_port_and_mask_t, src_port) \
74 _fe(ip_port_and_mask_t, dst_port) \
75 _fe(ip_protocol_t, protocol)
78 #define foreach_flow_entry_ip4_vxlan \
79 _fe(ip4_address_t, src_addr) \
80 _fe(ip4_address_t, dst_addr) \
84 #define foreach_flow_entry_ip6_vxlan \
85 _fe(ip6_address_t, src_addr) \
86 _fe(ip6_address_t, dst_addr) \
90 #define foreach_flow_entry_ip4_gtpc \
91 foreach_flow_entry_ip4_n_tuple \
94 #define foreach_flow_entry_ip4_gtpu \
95 foreach_flow_entry_ip4_n_tuple \
98 #define foreach_flow_entry_ip4_gtpu_ip4 \
99 foreach_flow_entry_ip4_gtpu \
100 _fe(ip4_address_and_mask_t, inner_src_addr) \
101 _fe(ip4_address_and_mask_t, inner_dst_addr)
103 #define foreach_flow_entry_ip4_gtpu_ip6 \
104 foreach_flow_entry_ip4_gtpu \
105 _fe(ip6_address_and_mask_t, inner_src_addr) \
106 _fe(ip6_address_and_mask_t, inner_dst_addr)
108 #define foreach_flow_entry_ip6_gtpc \
109 foreach_flow_entry_ip6_n_tuple \
112 #define foreach_flow_entry_ip6_gtpu \
113 foreach_flow_entry_ip6_n_tuple \
116 #define foreach_flow_entry_ip6_gtpu_ip4 \
117 foreach_flow_entry_ip6_gtpu \
118 _fe(ip4_address_and_mask_t, inner_src_addr) \
119 _fe(ip4_address_and_mask_t, inner_dst_addr)
121 #define foreach_flow_entry_ip6_gtpu_ip6 \
122 foreach_flow_entry_ip6_gtpu \
123 _fe(ip6_address_and_mask_t, inner_src_addr) \
124 _fe(ip6_address_and_mask_t, inner_dst_addr)
126 #define foreach_flow_action \
127 _(0, COUNT, "count") \
129 _(2, BUFFER_ADVANCE, "buffer-advance") \
130 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
131 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
136 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
139 } vnet_flow_action_t;
142 #define foreach_flow_error \
143 _( -1, NOT_SUPPORTED, "not supported") \
144 _( -2, ALREADY_DONE, "already done") \
145 _( -3, ALREADY_EXISTS, "already exists") \
146 _( -4, NO_SUCH_ENTRY, "no such entry") \
147 _( -5, NO_SUCH_INTERFACE, "no such interface") \
148 _( -6, INTERNAL, "internal error")
152 VNET_FLOW_NO_ERROR = 0,
153 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
161 } ip_port_and_mask_t;
165 VNET_FLOW_TYPE_UNKNOWN,
166 #define _(a,b,c) VNET_FLOW_TYPE_##a,
174 * Create typedef struct vnet_flow_XXX_t
176 #define _fe(a, b) a b;
180 foreach_flow_entry_##b \
186 /* main flow struct */
190 vnet_flow_type_t type;
195 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
198 /* flow id for VNET_FLOW_ACTION_MARK */
201 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
202 u32 redirect_node_index;
203 u32 redirect_device_input_next_index;
205 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
208 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
213 #define _(a,b,c) vnet_flow_##b##_t b;
218 /* per-interface private data */
222 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
224 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
225 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
226 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
227 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
228 vnet_flow_t *vnet_get_flow (u32 flow_index);
239 /* pool of device flow entries */
240 vnet_flow_t *global_flow_pool;
242 /* flow ids allocated */
245 /* vector of flow ranges */
246 vnet_flow_range_t *ranges;
250 extern vnet_flow_main_t flow_main;
252 format_function_t format_flow_actions;
253 format_function_t format_flow_enabled_hw;
255 #endif /* included_vnet_flow_flow_h */
258 * fd.io coding-style-patch-verification: ON
261 * eval: (c-set-style "gnu")