blob: c0aa9119ce104d4bcb6fadcf278e4302ca579cfa [file] [log] [blame]
Damjan Mariona35cc142018-03-16 01:25:27 +01001/*
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>
Dave Barach3ae28732018-11-16 17:19:00 -050020#include <vppinfra/pcap.h>
Damjan Mariona35cc142018-03-16 01:25:27 +010021#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") \
Hongjun Ni95eec062018-12-28 18:27:04 +080027 _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \
Damjan Mariona35cc142018-03-16 01:25:27 +010028 _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \
Chenmin Sunbf85a982019-10-18 07:35:16 +080029 _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \
30 _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \
31 _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \
32 _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \
33 _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \
34 _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \
35 _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \
36 _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \
37 _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6")
Damjan Mariona35cc142018-03-16 01:25:27 +010038
39#define foreach_flow_entry_ip4_n_tuple \
40 _fe(ip4_address_and_mask_t, src_addr) \
41 _fe(ip4_address_and_mask_t, dst_addr) \
42 _fe(ip_port_and_mask_t, src_port) \
43 _fe(ip_port_and_mask_t, dst_port) \
44 _fe(ip_protocol_t, protocol)
45
46#define foreach_flow_entry_ip6_n_tuple \
47 _fe(ip6_address_and_mask_t, src_addr) \
48 _fe(ip6_address_and_mask_t, dst_addr) \
49 _fe(ip_port_and_mask_t, src_port) \
50 _fe(ip_port_and_mask_t, dst_port) \
51 _fe(ip_protocol_t, protocol)
52
53#define foreach_flow_entry_ip4_vxlan \
54 _fe(ip4_address_t, src_addr) \
55 _fe(ip4_address_t, dst_addr) \
56 _fe(u16, dst_port) \
57 _fe(u16, vni)
58
59#define foreach_flow_entry_ip6_vxlan \
60 _fe(ip6_address_t, src_addr) \
61 _fe(ip6_address_t, dst_addr) \
62 _fe(u16, dst_port) \
63 _fe(u16, vni)
64
Chenmin Sunbf85a982019-10-18 07:35:16 +080065#define foreach_flow_entry_ip4_gtpc \
66 foreach_flow_entry_ip4_n_tuple \
67 _fe(u32, teid)
68
69#define foreach_flow_entry_ip4_gtpu \
70 foreach_flow_entry_ip4_n_tuple \
71 _fe(u32, teid)
72
73#define foreach_flow_entry_ip4_gtpu_ip4 \
74 foreach_flow_entry_ip4_gtpu \
75 _fe(ip4_address_and_mask_t, inner_src_addr) \
76 _fe(ip4_address_and_mask_t, inner_dst_addr)
77
78#define foreach_flow_entry_ip4_gtpu_ip6 \
79 foreach_flow_entry_ip4_gtpu \
80 _fe(ip6_address_and_mask_t, inner_src_addr) \
81 _fe(ip6_address_and_mask_t, inner_dst_addr)
82
83#define foreach_flow_entry_ip6_gtpc \
84 foreach_flow_entry_ip6_n_tuple \
85 _fe(u32, teid)
86
87#define foreach_flow_entry_ip6_gtpu \
88 foreach_flow_entry_ip6_n_tuple \
89 _fe(u32, teid)
90
91#define foreach_flow_entry_ip6_gtpu_ip4 \
92 foreach_flow_entry_ip6_gtpu \
93 _fe(ip4_address_and_mask_t, inner_src_addr) \
94 _fe(ip4_address_and_mask_t, inner_dst_addr)
95
96#define foreach_flow_entry_ip6_gtpu_ip6 \
97 foreach_flow_entry_ip6_gtpu \
98 _fe(ip6_address_and_mask_t, inner_src_addr) \
99 _fe(ip6_address_and_mask_t, inner_dst_addr)
100
Damjan Mariona35cc142018-03-16 01:25:27 +0100101#define foreach_flow_action \
102 _(0, COUNT, "count") \
103 _(1, MARK, "mark") \
104 _(2, BUFFER_ADVANCE, "buffer-advance") \
105 _(3, REDIRECT_TO_NODE, "redirect-to-node") \
106 _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \
107 _(5, DROP, "drop")
108
109typedef enum
110{
111#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
112 foreach_flow_action
113#undef _
114} vnet_flow_action_t;
115
116
117#define foreach_flow_error \
118 _( -1, NOT_SUPPORTED, "not supported") \
119 _( -2, ALREADY_DONE, "already done") \
120 _( -3, ALREADY_EXISTS, "already exists") \
121 _( -4, NO_SUCH_ENTRY, "no such entry") \
122 _( -5, NO_SUCH_INTERFACE, "no such interface") \
123 _( -6, INTERNAL, "internal error")
124
125typedef enum
126{
127 VNET_FLOW_NO_ERROR = 0,
128#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
129 foreach_flow_error
130#undef _
131} vnet_flow_error_t;
132
133typedef struct
134{
135 u16 port, mask;
136} ip_port_and_mask_t;
137
138typedef enum
139{
140 VNET_FLOW_TYPE_UNKNOWN,
141#define _(a,b,c) VNET_FLOW_TYPE_##a,
142 foreach_flow_type
143#undef _
144 VNET_FLOW_N_TYPES,
145} vnet_flow_type_t;
146
147
148/*
149 * Create typedef struct vnet_flow_XXX_t
150 */
151#define _fe(a, b) a b;
152#define _(a,b,c) \
153typedef struct { \
154int foo; \
155foreach_flow_entry_##b \
156} vnet_flow_##b##_t;
157foreach_flow_type;
158#undef _
159#undef _fe
160
161/* main flow struct */
162typedef struct
163{
164 /* flow type */
165 vnet_flow_type_t type;
166
167 /* flow index */
168 u32 index;
169
170 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
171 u32 actions;
172
173 /* flow id for VNET_FLOW_ACTION_MARK */
174 u32 mark_flow_id;
175
176 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
177 u32 redirect_node_index;
178 u32 redirect_device_input_next_index;
179
180 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
181 u32 redirect_queue;
182
183 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
184 i32 buffer_advance;
185
186 union
187 {
188#define _(a,b,c) vnet_flow_##b##_t b;
189 foreach_flow_type
190#undef _
191 };
192
193 /* per-interface private data */
194 uword *private_data;
195} vnet_flow_t;
196
197int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
198 u32 * start);
199int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
200int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
201int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
202int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
203vnet_flow_t *vnet_get_flow (u32 flow_index);
204
205typedef struct
206{
207 u32 start;
208 u32 count;
209 u8 *owner;
210} vnet_flow_range_t;
211
212typedef struct
213{
214 /* pool of device flow entries */
215 vnet_flow_t *global_flow_pool;
216
217 /* flow ids allocated */
218 u32 flows_used;
219
220 /* vector of flow ranges */
221 vnet_flow_range_t *ranges;
222
223} vnet_flow_main_t;
224
225extern vnet_flow_main_t flow_main;
226
227format_function_t format_flow_actions;
Eyal Barid3de7562018-05-31 11:30:16 +0300228format_function_t format_flow_enabled_hw;
Damjan Mariona35cc142018-03-16 01:25:27 +0100229
230#endif /* included_vnet_flow_flow_h */
231
232/*
233 * fd.io coding-style-patch-verification: ON
234 *
235 * Local Variables:
236 * eval: (c-set-style "gnu")
237 * End:
238 */