FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
flow.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef included_vnet_flow_flow_h
17 #define included_vnet_flow_flow_h
18 
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>
25 
26 #define foreach_flow_type \
27  /* l2 flow*/ \
28  _(ETHERNET, ethernet, "ethernet") \
29  /* l4 flow*/ \
30  _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
31  _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
32  /* L4 tunnel flow*/ \
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")
43 
44 #define foreach_flow_entry_ethernet \
45  _fe(ethernet_header_t, eth_hdr)
46 
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)
53 
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)
60 
61 #define foreach_flow_entry_ip4_vxlan \
62  _fe(ip4_address_t, src_addr) \
63  _fe(ip4_address_t, dst_addr) \
64  _fe(u16, dst_port) \
65  _fe(u16, vni)
66 
67 #define foreach_flow_entry_ip6_vxlan \
68  _fe(ip6_address_t, src_addr) \
69  _fe(ip6_address_t, dst_addr) \
70  _fe(u16, dst_port) \
71  _fe(u16, vni)
72 
73 #define foreach_flow_entry_ip4_gtpc \
74  foreach_flow_entry_ip4_n_tuple \
75  _fe(u32, teid)
76 
77 #define foreach_flow_entry_ip4_gtpu \
78  foreach_flow_entry_ip4_n_tuple \
79  _fe(u32, teid)
80 
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)
85 
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)
90 
91 #define foreach_flow_entry_ip6_gtpc \
92  foreach_flow_entry_ip6_n_tuple \
93  _fe(u32, teid)
94 
95 #define foreach_flow_entry_ip6_gtpu \
96  foreach_flow_entry_ip6_n_tuple \
97  _fe(u32, teid)
98 
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)
103 
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)
108 
109 #define foreach_flow_action \
110  _(0, COUNT, "count") \
111  _(1, MARK, "mark") \
112  _(2, BUFFER_ADVANCE, "buffer-advance") \
113  _(3, REDIRECT_TO_NODE, "redirect-to-node") \
114  _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
115  _(5, DROP, "drop")
116 
117 typedef enum
118 {
119 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
121 #undef _
123 
124 
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")
132 
133 typedef enum
134 {
136 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
138 #undef _
140 
141 typedef struct
142 {
143  u16 port, mask;
145 
146 typedef enum
147 {
149 #define _(a,b,c) VNET_FLOW_TYPE_##a,
151 #undef _
154 
155 
156 /*
157  * Create typedef struct vnet_flow_XXX_t
158  */
159 #define _fe(a, b) a b;
160 #define _(a,b,c) \
161 typedef struct { \
162 int foo; \
163 foreach_flow_entry_##b \
164 } vnet_flow_##b##_t;
166 #undef _
167 #undef _fe
168 
169 /* main flow struct */
170 typedef struct
171 {
172  /* flow type */
174 
175  /* flow index */
177 
178  /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
180 
181  /* flow id for VNET_FLOW_ACTION_MARK */
183 
184  /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
187 
188  /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
190 
191  /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
193 
194  union
195  {
196 #define _(a,b,c) vnet_flow_##b##_t b;
198 #undef _
199  };
200 
201  /* per-interface private data */
203 } vnet_flow_t;
204 
205 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
206  u32 * start);
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);
212 
213 typedef struct
214 {
219 
220 typedef struct
221 {
222  /* pool of device flow entries */
224 
225  /* flow ids allocated */
227 
228  /* vector of flow ranges */
230 
232 
234 
237 
238 #endif /* included_vnet_flow_flow_h */
239 
240 /*
241  * fd.io coding-style-patch-verification: ON
242  *
243  * Local Variables:
244  * eval: (c-set-style "gnu")
245  * End:
246  */
u8 count
Definition: dhcp.api:208
vnet_flow_type_t type
Definition: flow.h:173
int vnet_flow_get_range(vnet_main_t *vnm, char *owner, u32 count, u32 *start)
Definition: flow.c:24
PCAP utility definitions.
#define foreach_flow_type
Definition: flow.h:26
vnet_flow_error_t
Definition: flow.h:133
vnet_flow_t * global_flow_pool
Definition: flow.h:223
u32 redirect_node_index
Definition: flow.h:185
unsigned char u8
Definition: types.h:56
vnet_flow_action_t
Definition: flow.h:117
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
u32 mark_flow_id
Definition: flow.h:182
unsigned int u32
Definition: types.h:88
int vnet_flow_enable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:91
vnet_flow_range_t * ranges
Definition: flow.h:229
u32 redirect_queue
Definition: flow.h:189
unsigned short u16
Definition: types.h:57
u32 index
Definition: flow.h:176
vnet_flow_main_t flow_main
Definition: flow.c:21
i32 buffer_advance
Definition: flow.h:192
u32 actions
Definition: flow.h:179
uword * private_data
Definition: flow.h:202
format_function_t format_flow_actions
Definition: flow.h:235
vnet_flow_t * vnet_get_flow(u32 flow_index)
Definition: flow.c:57
signed int i32
Definition: types.h:77
int vnet_flow_del(vnet_main_t *vnm, u32 flow_index)
Definition: flow.c:67
int vnet_flow_add(vnet_main_t *vnm, vnet_flow_t *flow, u32 *flow_index)
Definition: flow.c:43
format_function_t format_flow_enabled_hw
Definition: flow.h:236
u32 flows_used
Definition: flow.h:226
vnet_flow_type_t
Definition: flow.h:146
#define foreach_flow_error
Definition: flow.h:125
u64 uword
Definition: types.h:112
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:135
#define foreach_flow_action
Definition: flow.h:109
u32 redirect_device_input_next_index
Definition: flow.h:186
icmpr_flow_t * flow
Definition: main.c:123