FD.io VPP  v20.05.1-6-gf53edbc3b
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  _(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  /* L4 tunnel flow*/ \
37  _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
38  _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
39  _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
40  _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
41  _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
42  _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
43  _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
44  _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
45  _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
46  _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
47 
48 #define foreach_flow_entry_ethernet \
49  _fe(ethernet_header_t, eth_hdr)
50 
51 #define foreach_flow_entry_ip4_n_tuple \
52  _fe(ip4_address_and_mask_t, src_addr) \
53  _fe(ip4_address_and_mask_t, dst_addr) \
54  _fe(ip_port_and_mask_t, src_port) \
55  _fe(ip_port_and_mask_t, dst_port) \
56  _fe(ip_protocol_t, protocol)
57 
58 #define foreach_flow_entry_ip6_n_tuple \
59  _fe(ip6_address_and_mask_t, src_addr) \
60  _fe(ip6_address_and_mask_t, dst_addr) \
61  _fe(ip_port_and_mask_t, src_port) \
62  _fe(ip_port_and_mask_t, dst_port) \
63  _fe(ip_protocol_t, protocol)
64 
65 #define foreach_flow_entry_ip4_n_tuple_tagged \
66  _fe(ip4_address_and_mask_t, src_addr) \
67  _fe(ip4_address_and_mask_t, dst_addr) \
68  _fe(ip_port_and_mask_t, src_port) \
69  _fe(ip_port_and_mask_t, dst_port) \
70  _fe(ip_protocol_t, protocol)
71 
72 #define foreach_flow_entry_ip6_n_tuple_tagged \
73  _fe(ip6_address_and_mask_t, src_addr) \
74  _fe(ip6_address_and_mask_t, dst_addr) \
75  _fe(ip_port_and_mask_t, src_port) \
76  _fe(ip_port_and_mask_t, dst_port) \
77  _fe(ip_protocol_t, protocol)
78 
79 #define foreach_flow_entry_ip4_l2tpv3oip \
80  _fe(ip4_address_and_mask_t, src_addr) \
81  _fe(ip4_address_and_mask_t, dst_addr) \
82  _fe(ip_protocol_t, protocol) \
83  _fe(u32, session_id)
84 
85 #define foreach_flow_entry_ip4_vxlan \
86  _fe(ip4_address_t, src_addr) \
87  _fe(ip4_address_t, dst_addr) \
88  _fe(u16, dst_port) \
89  _fe(u16, vni)
90 
91 #define foreach_flow_entry_ip6_vxlan \
92  _fe(ip6_address_t, src_addr) \
93  _fe(ip6_address_t, dst_addr) \
94  _fe(u16, dst_port) \
95  _fe(u16, vni)
96 
97 #define foreach_flow_entry_ip4_gtpc \
98  foreach_flow_entry_ip4_n_tuple \
99  _fe(u32, teid)
100 
101 #define foreach_flow_entry_ip4_gtpu \
102  foreach_flow_entry_ip4_n_tuple \
103  _fe(u32, teid)
104 
105 #define foreach_flow_entry_ip4_gtpu_ip4 \
106  foreach_flow_entry_ip4_gtpu \
107  _fe(ip4_address_and_mask_t, inner_src_addr) \
108  _fe(ip4_address_and_mask_t, inner_dst_addr)
109 
110 #define foreach_flow_entry_ip4_gtpu_ip6 \
111  foreach_flow_entry_ip4_gtpu \
112  _fe(ip6_address_and_mask_t, inner_src_addr) \
113  _fe(ip6_address_and_mask_t, inner_dst_addr)
114 
115 #define foreach_flow_entry_ip6_gtpc \
116  foreach_flow_entry_ip6_n_tuple \
117  _fe(u32, teid)
118 
119 #define foreach_flow_entry_ip6_gtpu \
120  foreach_flow_entry_ip6_n_tuple \
121  _fe(u32, teid)
122 
123 #define foreach_flow_entry_ip6_gtpu_ip4 \
124  foreach_flow_entry_ip6_gtpu \
125  _fe(ip4_address_and_mask_t, inner_src_addr) \
126  _fe(ip4_address_and_mask_t, inner_dst_addr)
127 
128 #define foreach_flow_entry_ip6_gtpu_ip6 \
129  foreach_flow_entry_ip6_gtpu \
130  _fe(ip6_address_and_mask_t, inner_src_addr) \
131  _fe(ip6_address_and_mask_t, inner_dst_addr)
132 
133 #define foreach_flow_action \
134  _(0, COUNT, "count") \
135  _(1, MARK, "mark") \
136  _(2, BUFFER_ADVANCE, "buffer-advance") \
137  _(3, REDIRECT_TO_NODE, "redirect-to-node") \
138  _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
139  _(5, RSS, "rss") \
140  _(6, DROP, "drop")
141 
142 typedef enum
143 {
144 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
146 #undef _
148 
149 
150 #define foreach_flow_error \
151  _( -1, NOT_SUPPORTED, "not supported") \
152  _( -2, ALREADY_DONE, "already done") \
153  _( -3, ALREADY_EXISTS, "already exists") \
154  _( -4, NO_SUCH_ENTRY, "no such entry") \
155  _( -5, NO_SUCH_INTERFACE, "no such interface") \
156  _( -6, INTERNAL, "internal error")
157 
158 #define foreach_flow_rss_types \
159  _(0, FRAG_IPV4, "ipv4-frag") \
160  _(1, IPV4_TCP, "ipv4-tcp") \
161  _(2, IPV4_UDP, "ipv4-udp") \
162  _(3, IPV4_SCTP, "ipv4-sctp") \
163  _(4, IPV4_OTHER, "ipv4-other") \
164  _(5, IPV4, "ipv4") \
165  _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
166  _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
167  _(8, FRAG_IPV6, "ipv6-frag") \
168  _(9, IPV6_TCP, "ipv6-tcp") \
169  _(10, IPV6_UDP, "ipv6-udp") \
170  _(11, IPV6_SCTP, "ipv6-sctp") \
171  _(12, IPV6_OTHER, "ipv6-other") \
172  _(13, IPV6_EX, "ipv6-ex") \
173  _(14, IPV6, "ipv6") \
174  _(15, L2_PAYLOAD, "l2-payload") \
175  _(16, PORT, "port") \
176  _(17, VXLAN, "vxlan") \
177  _(18, GENEVE, "geneve") \
178  _(19, NVGRE, "nvgre") \
179  _(20, GTPU, "gtpu") \
180  _(60, L4_DST_ONLY, "l4-dst-only") \
181  _(61, L4_SRC_ONLY, "l4-src-only") \
182  _(62, L3_DST_ONLY, "l3-dst-only") \
183  _(63, L3_SRC_ONLY, "l3-src-only")
184 
185 #define foreach_rss_function \
186  _(DEFAULT, "default") \
187  _(TOEPLITZ, "toeplitz") \
188  _(SIMPLE_XOR, "simple_xor") \
189  _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
190 
191 typedef enum
192 {
194 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
196 #undef _
198 
199 typedef struct
200 {
201  u16 port, mask;
203 
204 typedef enum
205 {
207 #define _(a,b,c) VNET_FLOW_TYPE_##a,
209 #undef _
212 
213 typedef enum
214 {
215 #define _(a,b) VNET_RSS_FUNC_##a,
217 #undef _
220 
221 /*
222  * Create typedef struct vnet_flow_XXX_t
223  */
224 #define _fe(a, b) a b;
225 #define _(a,b,c) \
226 typedef struct { \
227 int foo; \
228 foreach_flow_entry_##b \
229 } vnet_flow_##b##_t;
231 #undef _
232 #undef _fe
233 
234 /* main flow struct */
235 typedef struct
236 {
237  /* flow type */
239 
240  /* flow index */
242 
243  /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
245 
246  /* flow id for VNET_FLOW_ACTION_MARK */
248 
249  /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
252 
253  /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
255 
256  /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
258 
259  /* RSS types, including IPv4/IPv6/TCP/UDP... */
261 
262  /* RSS functions, including IPv4/IPv6/TCP/UDP... */
264 
265  union
266  {
267 #define _(a,b,c) vnet_flow_##b##_t b;
269 #undef _
270  };
271 
272  /* per-interface private data */
274 } vnet_flow_t;
275 
276 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
277  u32 * start);
278 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
279 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
280 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
281 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
282 vnet_flow_t *vnet_get_flow (u32 flow_index);
283 
284 typedef struct
285 {
290 
291 typedef struct
292 {
293  /* pool of device flow entries */
295 
296  /* flow ids allocated */
298 
299  /* vector of flow ranges */
301 
303 
305 
308 
309 #endif /* included_vnet_flow_flow_h */
310 
311 /*
312  * fd.io coding-style-patch-verification: ON
313  *
314  * Local Variables:
315  * eval: (c-set-style "gnu")
316  * End:
317  */
u8 count
Definition: dhcp.api:208
vnet_rss_function_t rss_fun
Definition: flow.h:263
u64 rss_types
Definition: flow.h:260
vnet_flow_type_t type
Definition: flow.h:238
int vnet_flow_get_range(vnet_main_t *vnm, char *owner, u32 count, u32 *start)
Definition: flow.c:24
#define foreach_rss_function
Definition: flow.h:185
unsigned long u64
Definition: types.h:89
PCAP utility definitions.
#define foreach_flow_type
Definition: flow.h:26
vnet_flow_error_t
Definition: flow.h:191
vnet_flow_t * global_flow_pool
Definition: flow.h:294
u32 redirect_node_index
Definition: flow.h:250
unsigned char u8
Definition: types.h:56
vnet_flow_action_t
Definition: flow.h:142
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
u32 mark_flow_id
Definition: flow.h:247
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:300
u32 redirect_queue
Definition: flow.h:254
unsigned short u16
Definition: types.h:57
u32 index
Definition: flow.h:241
vnet_flow_main_t flow_main
Definition: flow.c:21
i32 buffer_advance
Definition: flow.h:257
u32 actions
Definition: flow.h:244
uword * private_data
Definition: flow.h:273
format_function_t format_flow_actions
Definition: flow.h:306
vnet_flow_t * vnet_get_flow(u32 flow_index)
Definition: flow.c:57
vnet_rss_function_t
Definition: flow.h:213
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:307
u32 flows_used
Definition: flow.h:297
vnet_flow_type_t
Definition: flow.h:204
#define foreach_flow_error
Definition: flow.h:150
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:133
u32 redirect_device_input_next_index
Definition: flow.h:251
icmpr_flow_t * flow
Definition: main.c:123