FD.io VPP  v19.04.2-12-g66b1689
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 
25 #define foreach_flow_type \
26  _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \
27  _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
28  _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
29  _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan")
30 
31 #define foreach_flow_entry_ip4_n_tuple \
32  _fe(ip4_address_and_mask_t, src_addr) \
33  _fe(ip4_address_and_mask_t, dst_addr) \
34  _fe(ip_port_and_mask_t, src_port) \
35  _fe(ip_port_and_mask_t, dst_port) \
36  _fe(ip_protocol_t, protocol)
37 
38 #define foreach_flow_entry_ip6_n_tuple \
39  _fe(ip6_address_and_mask_t, src_addr) \
40  _fe(ip6_address_and_mask_t, dst_addr) \
41  _fe(ip_port_and_mask_t, src_port) \
42  _fe(ip_port_and_mask_t, dst_port) \
43  _fe(ip_protocol_t, protocol)
44 
45 #define foreach_flow_entry_ip4_vxlan \
46  _fe(ip4_address_t, src_addr) \
47  _fe(ip4_address_t, dst_addr) \
48  _fe(u16, dst_port) \
49  _fe(u16, vni)
50 
51 #define foreach_flow_entry_ip6_vxlan \
52  _fe(ip6_address_t, src_addr) \
53  _fe(ip6_address_t, dst_addr) \
54  _fe(u16, dst_port) \
55  _fe(u16, vni)
56 
57 #define foreach_flow_action \
58  _(0, COUNT, "count") \
59  _(1, MARK, "mark") \
60  _(2, BUFFER_ADVANCE, "buffer-advance") \
61  _(3, REDIRECT_TO_NODE, "redirect-to-node") \
62  _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
63  _(5, DROP, "drop")
64 
65 typedef enum
66 {
67 #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
69 #undef _
71 
72 
73 #define foreach_flow_error \
74  _( -1, NOT_SUPPORTED, "not supported") \
75  _( -2, ALREADY_DONE, "already done") \
76  _( -3, ALREADY_EXISTS, "already exists") \
77  _( -4, NO_SUCH_ENTRY, "no such entry") \
78  _( -5, NO_SUCH_INTERFACE, "no such interface") \
79  _( -6, INTERNAL, "internal error")
80 
81 typedef enum
82 {
84 #define _(v,n,s) VNET_FLOW_ERROR_##n = v,
86 #undef _
88 
89 typedef struct
90 {
91  u16 port, mask;
93 
94 typedef enum
95 {
97 #define _(a,b,c) VNET_FLOW_TYPE_##a,
99 #undef _
102 
103 
104 /*
105  * Create typedef struct vnet_flow_XXX_t
106  */
107 #define _fe(a, b) a b;
108 #define _(a,b,c) \
109 typedef struct { \
110 int foo; \
111 foreach_flow_entry_##b \
112 } vnet_flow_##b##_t;
114 #undef _
115 #undef _fe
116 
117 /* main flow struct */
118 typedef struct
119 {
120  /* flow type */
122 
123  /* flow index */
125 
126  /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
128 
129  /* flow id for VNET_FLOW_ACTION_MARK */
131 
132  /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
135 
136  /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
138 
139  /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
141 
142  union
143  {
144 #define _(a,b,c) vnet_flow_##b##_t b;
146 #undef _
147  };
148 
149  /* per-interface private data */
151 } vnet_flow_t;
152 
153 int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
154  u32 * start);
155 int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
156 int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
157 int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
158 int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
159 vnet_flow_t *vnet_get_flow (u32 flow_index);
160 
161 typedef struct
162 {
167 
168 typedef struct
169 {
170  /* pool of device flow entries */
172 
173  /* flow ids allocated */
175 
176  /* vector of flow ranges */
178 
180 
182 
185 
186 #endif /* included_vnet_flow_flow_h */
187 
188 /*
189  * fd.io coding-style-patch-verification: ON
190  *
191  * Local Variables:
192  * eval: (c-set-style "gnu")
193  * End:
194  */
vnet_flow_type_t type
Definition: flow.h:121
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:25
vnet_flow_error_t
Definition: flow.h:81
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
vnet_flow_t * global_flow_pool
Definition: flow.h:171
u32 redirect_node_index
Definition: flow.h:133
unsigned char u8
Definition: types.h:56
vnet_flow_action_t
Definition: flow.h:65
u32 mark_flow_id
Definition: flow.h:130
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:177
u32 redirect_queue
Definition: flow.h:137
unsigned short u16
Definition: types.h:57
u32 index
Definition: flow.h:124
vnet_flow_main_t flow_main
Definition: flow.c:21
i32 buffer_advance
Definition: flow.h:140
u32 actions
Definition: flow.h:127
uword * private_data
Definition: flow.h:150
format_function_t format_flow_actions
Definition: flow.h:183
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:184
size_t count
Definition: vapi.c:47
u32 flows_used
Definition: flow.h:174
vnet_flow_type_t
Definition: flow.h:94
#define foreach_flow_error
Definition: flow.h:73
u64 uword
Definition: types.h:112
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:132
#define foreach_flow_action
Definition: flow.h:57
u32 redirect_device_input_next_index
Definition: flow.h:134
icmpr_flow_t * flow
Definition: main.c:123