blob: bc9b2f19cc3b1a3aab72b23020824f281b843c6f [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>
20#include <vnet/unix/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, "ipv4-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
65typedef enum
66{
67#define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v),
68 foreach_flow_action
69#undef _
70} vnet_flow_action_t;
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
81typedef enum
82{
83 VNET_FLOW_NO_ERROR = 0,
84#define _(v,n,s) VNET_FLOW_ERROR_##n = v,
85 foreach_flow_error
86#undef _
87} vnet_flow_error_t;
88
89typedef struct
90{
91 u16 port, mask;
92} ip_port_and_mask_t;
93
94typedef enum
95{
96 VNET_FLOW_TYPE_UNKNOWN,
97#define _(a,b,c) VNET_FLOW_TYPE_##a,
98 foreach_flow_type
99#undef _
100 VNET_FLOW_N_TYPES,
101} vnet_flow_type_t;
102
103
104/*
105 * Create typedef struct vnet_flow_XXX_t
106 */
107#define _fe(a, b) a b;
108#define _(a,b,c) \
109typedef struct { \
110int foo; \
111foreach_flow_entry_##b \
112} vnet_flow_##b##_t;
113foreach_flow_type;
114#undef _
115#undef _fe
116
117/* main flow struct */
118typedef struct
119{
120 /* flow type */
121 vnet_flow_type_t type;
122
123 /* flow index */
124 u32 index;
125
126 /* bitmap of flow actions (VNET_FLOW_ACTION_*) */
127 u32 actions;
128
129 /* flow id for VNET_FLOW_ACTION_MARK */
130 u32 mark_flow_id;
131
132 /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */
133 u32 redirect_node_index;
134 u32 redirect_device_input_next_index;
135
136 /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */
137 u32 redirect_queue;
138
139 /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */
140 i32 buffer_advance;
141
142 union
143 {
144#define _(a,b,c) vnet_flow_##b##_t b;
145 foreach_flow_type
146#undef _
147 };
148
149 /* per-interface private data */
150 uword *private_data;
151} vnet_flow_t;
152
153int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count,
154 u32 * start);
155int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index);
156int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
157int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index);
158int vnet_flow_del (vnet_main_t * vnm, u32 flow_index);
159vnet_flow_t *vnet_get_flow (u32 flow_index);
160
161typedef struct
162{
163 u32 start;
164 u32 count;
165 u8 *owner;
166} vnet_flow_range_t;
167
168typedef struct
169{
170 /* pool of device flow entries */
171 vnet_flow_t *global_flow_pool;
172
173 /* flow ids allocated */
174 u32 flows_used;
175
176 /* vector of flow ranges */
177 vnet_flow_range_t *ranges;
178
179} vnet_flow_main_t;
180
181extern vnet_flow_main_t flow_main;
182
183format_function_t format_flow_actions;
184
185#endif /* included_vnet_flow_flow_h */
186
187/*
188 * fd.io coding-style-patch-verification: ON
189 *
190 * Local Variables:
191 * eval: (c-set-style "gnu")
192 * End:
193 */