FD.io VPP  v21.06-3-gbb25fbf28
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  /* l3 IP flow */ \
30  _(IP4, ip4, "ipv4") \
31  _(IP6, ip6, "ipv6") \
32  /* IP tunnel flow */ \
33  _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \
34  _(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \
35  _(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \
36  /* l4 flow*/ \
37  _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
38  _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
39  _(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \
40  _(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \
41  /* L4 tunnel flow*/ \
42  _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
43  _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
44  _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
45  _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu")
46 
47 #define foreach_flow_entry_ethernet \
48  _fe(ethernet_header_t, eth_hdr)
49 
50 #define foreach_flow_entry_ip4 \
51  _fe(ip4_address_and_mask_t, src_addr) \
52  _fe(ip4_address_and_mask_t, dst_addr) \
53  _fe(ip_prot_and_mask_t, protocol)
54 
55 #define foreach_flow_entry_ip6 \
56  _fe(ip6_address_and_mask_t, src_addr) \
57  _fe(ip6_address_and_mask_t, dst_addr) \
58  _fe(ip_prot_and_mask_t, protocol)
59 
60 #define foreach_flow_entry_ip4_l2tpv3oip \
61  foreach_flow_entry_ip4 \
62  _fe(u32, session_id)
63 
64 #define foreach_flow_entry_ip4_ipsec_esp \
65  foreach_flow_entry_ip4 \
66  _fe(u32, spi)
67 
68 #define foreach_flow_entry_ip4_ipsec_ah \
69  foreach_flow_entry_ip4 \
70  _fe(u32, spi)
71 
72 #define foreach_flow_entry_ip4_n_tuple \
73  foreach_flow_entry_ip4 \
74  _fe(ip_port_and_mask_t, src_port) \
75  _fe(ip_port_and_mask_t, dst_port)
76 
77 #define foreach_flow_entry_ip6_n_tuple \
78  foreach_flow_entry_ip6 \
79  _fe(ip_port_and_mask_t, src_port) \
80  _fe(ip_port_and_mask_t, dst_port)
81 
82 #define foreach_flow_entry_ip4_n_tuple_tagged \
83  foreach_flow_entry_ip4 \
84  _fe(ip_port_and_mask_t, src_port) \
85  _fe(ip_port_and_mask_t, dst_port)
86 
87 #define foreach_flow_entry_ip6_n_tuple_tagged \
88  foreach_flow_entry_ip6 \
89  _fe(ip_port_and_mask_t, src_port) \
90  _fe(ip_port_and_mask_t, dst_port)
91 
92 #define foreach_flow_entry_ip4_vxlan \
93  foreach_flow_entry_ip4_n_tuple _fe (u32, vni)
94 
95 #define foreach_flow_entry_ip6_vxlan \
96  foreach_flow_entry_ip6_n_tuple _fe (u32, vni)
97 
98 #define foreach_flow_entry_ip4_gtpc \
99  foreach_flow_entry_ip4_n_tuple \
100  _fe(u32, teid)
101 
102 #define foreach_flow_entry_ip4_gtpu \
103  foreach_flow_entry_ip4_n_tuple \
104  _fe(u32, teid)
105 
106 #define foreach_flow_action \
107  _(0, COUNT, "count") \
108  _(1, MARK, "mark") \
109  _(2, BUFFER_ADVANCE, "buffer-advance") \
110  _(3, REDIRECT_TO_NODE, "redirect-to-node") \
111  _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
112  _(5, RSS, "rss") \
113  _(6, DROP, "drop")
114 
115 typedef enum
116 {
117 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
119 #undef _
121 
122 #define foreach_flow_error \
123  _( -1, NOT_SUPPORTED, "not supported") \
124  _( -2, ALREADY_DONE, "already done") \
125  _( -3, ALREADY_EXISTS, "already exists") \
126  _( -4, NO_SUCH_ENTRY, "no such entry") \
127  _( -5, NO_SUCH_INTERFACE, "no such interface") \
128  _( -6, INTERNAL, "internal error")
129 
130 #define foreach_flow_rss_types \
131  _(0, FRAG_IPV4, "ipv4-frag") \
132  _(1, IPV4_TCP, "ipv4-tcp") \
133  _(2, IPV4_UDP, "ipv4-udp") \
134  _(3, IPV4_SCTP, "ipv4-sctp") \
135  _(4, IPV4_OTHER, "ipv4-other") \
136  _(5, IPV4, "ipv4") \
137  _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \
138  _(7, IPV6_UDP_EX, "ipv6-udp-ex") \
139  _(8, FRAG_IPV6, "ipv6-frag") \
140  _(9, IPV6_TCP, "ipv6-tcp") \
141  _(10, IPV6_UDP, "ipv6-udp") \
142  _(11, IPV6_SCTP, "ipv6-sctp") \
143  _(12, IPV6_OTHER, "ipv6-other") \
144  _(13, IPV6_EX, "ipv6-ex") \
145  _(14, IPV6, "ipv6") \
146  _(15, L2_PAYLOAD, "l2-payload") \
147  _(16, PORT, "port") \
148  _(17, VXLAN, "vxlan") \
149  _(18, GENEVE, "geneve") \
150  _(19, NVGRE, "nvgre") \
151  _(20, GTPU, "gtpu") \
152  _(60, L4_DST_ONLY, "l4-dst-only") \
153  _(61, L4_SRC_ONLY, "l4-src-only") \
154  _(62, L3_DST_ONLY, "l3-dst-only") \
155  _(63, L3_SRC_ONLY, "l3-src-only")
156 
157 #define foreach_rss_function \
158  _(DEFAULT, "default") \
159  _(TOEPLITZ, "toeplitz") \
160  _(SIMPLE_XOR, "simple_xor") \
161  _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz")
162 
163 typedef enum
164 {
166 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
168 #undef _
170 
171 typedef struct
172 {
175 
176 typedef struct
177 {
179  /* ip protocol mask should be either 0 or 0xFF */
180  /* other values are meanless */
183 
184 typedef enum
185 {
187 #define _(a,b,c) VNET_FLOW_TYPE_##a,
189 #undef _
192 
193 typedef enum
194 {
195 #define _(a,b) VNET_RSS_FUNC_##a,
197 #undef _
200 
201 /*
202  * Create typedef struct vnet_flow_XXX_t
203  */
204 #define _fe(a, b) a b;
205 #define _(a,b,c) \
206 typedef struct { \
207 int foo; \
208 foreach_flow_entry_##b \
209 } vnet_flow_##b##_t;
211 #undef _
212 #undef _fe
213 
214 /* main flow struct */
215 typedef struct
216 {
217  /* flow type */
219 
220  /* flow index */
222 
223  /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
225 
226  /* flow id for VNET_FLOW_ACTION_MARK */
228 
229  /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
232 
233  /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
235 
236  /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
238 
239  /* RSS types, including IPv4/IPv6/TCP/UDP... */
241 
242  /* RSS functions, including IPv4/IPv6/TCP/UDP... */
244 
245  union
246  {
247 #define _(a,b,c) vnet_flow_##b##_t b;
249 #undef _
250  };
251 
252  /* per-interface private data */
254 } vnet_flow_t;
255 
256 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
257  u32 * start);
258 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
259 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
260 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
261 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
262 vnet_flow_t *vnet_get_flow (u32 flow_index);
263 
264 typedef struct
265 {
270 
271 typedef struct
272 {
273  /* pool of device flow entries */
275 
276  /* flow ids allocated */
278 
279  /* vector of flow ranges */
281 
283 
285 
288 
289 #endif /* included_vnet_flow_flow_h */
290 
291 /*
292  * fd.io coding-style-patch-verification: ON
293  *
294  * Local Variables:
295  * eval: (c-set-style "gnu")
296  * End:
297  */
vnet_flow_t::redirect_queue
u32 redirect_queue
Definition: flow.h:234
VNET_FLOW_NO_ERROR
@ VNET_FLOW_NO_ERROR
Definition: flow.h:165
vnet_flow_type_t
vnet_flow_type_t
Definition: flow.h:184
vnet_flow_add
int vnet_flow_add(vnet_main_t *vnm, vnet_flow_t *flow, u32 *flow_index)
Definition: flow.c:43
vnet_flow_t::private_data
uword * private_data
Definition: flow.h:253
vnet_flow_range_t::count
u32 count
Definition: flow.h:267
vnet_flow_disable
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:135
clib.h
vnet_flow_t::index
u32 index
Definition: flow.h:221
vnet_get_flow
vnet_flow_t * vnet_get_flow(u32 flow_index)
Definition: flow.c:57
vnet_rss_function_t
vnet_rss_function_t
Definition: flow.h:193
u16
unsigned short u16
Definition: types.h:57
vnet_flow_range_t
Definition: flow.h:264
flow
Definition: flow_types.api:196
flow_main
vnet_flow_main_t flow_main
Definition: flow.c:21
vnet_flow_range_t::owner
u8 * owner
Definition: flow.h:268
i32
signed int i32
Definition: types.h:77
vnet_flow_del
int vnet_flow_del(vnet_main_t *vnm, u32 flow_index)
Definition: flow.c:67
ip6_packet.h
ip_prot_and_mask_t::prot
ip_protocol_t prot
Definition: flow.h:178
foreach_flow_action
#define foreach_flow_action
Definition: flow.h:106
foreach_rss_function
#define foreach_rss_function
Definition: flow.h:157
count
u8 count
Definition: dhcp.api:208
vnet_flow_t::mark_flow_id
u32 mark_flow_id
Definition: flow.h:227
vnet_flow_t::redirect_device_input_next_index
u32 redirect_device_input_next_index
Definition: flow.h:231
packet.h
format_flow_enabled_hw
format_function_t format_flow_enabled_hw
Definition: flow.h:287
l3_types.h
uword
u64 uword
Definition: types.h:112
vnet_flow_t::redirect_node_index
u32 redirect_node_index
Definition: flow.h:230
pcap.h
PCAP utility definitions.
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
vnet_flow_main_t::global_flow_pool
vnet_flow_t * global_flow_pool
Definition: flow.h:274
vnet_flow_action_t
vnet_flow_action_t
Definition: flow.h:115
vnet_flow_t
Definition: flow.h:215
vnet_flow_main_t::ranges
vnet_flow_range_t * ranges
Definition: flow.h:280
ip_port_and_mask_t::port
u16 port
Definition: flow.h:173
vnet_flow_main_t::flows_used
u32 flows_used
Definition: flow.h:277
ip4_packet.h
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vnet_flow_t::actions
u32 actions
Definition: flow.h:224
vnet_main_t
Definition: vnet.h:76
u64
unsigned long u64
Definition: types.h:89
u32
unsigned int u32
Definition: types.h:88
vnet_flow_get_range
int vnet_flow_get_range(vnet_main_t *vnm, char *owner, u32 count, u32 *start)
Definition: flow.c:24
VNET_FLOW_N_TYPES
@ VNET_FLOW_N_TYPES
Definition: flow.h:190
ip_prot_and_mask_t::mask
u8 mask
Definition: flow.h:181
vnet_flow_enable
int vnet_flow_enable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:91
foreach_flow_type
#define foreach_flow_type
Definition: flow.h:26
foreach_flow_error
#define foreach_flow_error
Definition: flow.h:122
ip_protocol_t
enum ip_protocol ip_protocol_t
vnet_flow_t::buffer_advance
i32 buffer_advance
Definition: flow.h:237
vnet_flow_main_t
Definition: flow.h:271
u8
unsigned char u8
Definition: types.h:56
VNET_FLOW_TYPE_UNKNOWN
@ VNET_FLOW_TYPE_UNKNOWN
Definition: flow.h:186
vnet_flow_t::type
vnet_flow_type_t type
Definition: flow.h:218
vnet_flow_error_t
vnet_flow_error_t
Definition: flow.h:163
vnet_flow_range_t::start
u32 start
Definition: flow.h:266
format_flow_actions
format_function_t format_flow_actions
Definition: flow.h:286
ip_port_and_mask_t
Definition: flow.h:171
vnet_flow_t::rss_types
u64 rss_types
Definition: flow.h:240
ip_prot_and_mask_t
Definition: flow.h:176
vnet_flow_t::rss_fun
vnet_rss_function_t rss_fun
Definition: flow.h:243
VNET_RSS_N_TYPES
@ VNET_RSS_N_TYPES
Definition: flow.h:198