FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_fwd_dpo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #include <plugins/gbp/gbp.h>
18 
19 #include <vnet/ethernet/ethernet.h>
20 
21 
22 #ifndef CLIB_MARCH_VARIANT
23 /**
24  * The 'DB' of GBP FWD DPOs.
25  * There is one per-proto
26  */
28 
29 /**
30  * DPO type registered for these GBP FWD
31  */
33 
34 /**
35  * @brief pool of all interface DPOs
36  */
38 
39 static gbp_fwd_dpo_t *
41 {
42  gbp_fwd_dpo_t *gfd;
43 
45 
46  return (gfd);
47 }
48 
49 static inline gbp_fwd_dpo_t *
51 {
53 
54  return (gbp_fwd_dpo_get (dpo->dpoi_index));
55 }
56 
57 static inline index_t
59 {
60  return (gfd - gbp_fwd_dpo_pool);
61 }
62 
63 static void
65 {
66  gbp_fwd_dpo_t *gfd;
67 
68  gfd = gbp_fwd_dpo_get_from_dpo (dpo);
69  gfd->gfd_locks++;
70 }
71 
72 static void
74 {
75  gbp_fwd_dpo_t *gfd;
76 
77  gfd = gbp_fwd_dpo_get_from_dpo (dpo);
78  gfd->gfd_locks--;
79 
80  if (0 == gfd->gfd_locks)
81  {
84  }
85 }
86 
87 void
89 {
90  gbp_fwd_dpo_t *gfd;
91 
92  if (INDEX_INVALID == gbp_fwd_dpo_db[dproto])
93  {
94  gfd = gbp_fwd_dpo_alloc ();
95 
96  gfd->gfd_proto = dproto;
97 
98  gbp_fwd_dpo_db[dproto] = gbp_fwd_dpo_get_index (gfd);
99  }
100  else
101  {
102  gfd = gbp_fwd_dpo_get (gbp_fwd_dpo_db[dproto]);
103  }
104 
105  dpo_set (dpo, gbp_fwd_dpo_type, dproto, gbp_fwd_dpo_get_index (gfd));
106 }
107 
108 u8 *
109 format_gbp_fwd_dpo (u8 * s, va_list * ap)
110 {
111  index_t index = va_arg (*ap, index_t);
112  CLIB_UNUSED (u32 indent) = va_arg (*ap, u32);
114 
115  return (format (s, "gbp-fwd-dpo: %U", format_dpo_proto, gfd->gfd_proto));
116 }
117 
118 const static dpo_vft_t gbp_fwd_dpo_vft = {
120  .dv_unlock = gbp_fwd_dpo_unlock,
121  .dv_format = format_gbp_fwd_dpo,
122 };
123 
124 /**
125  * @brief The per-protocol VLIB graph nodes that are assigned to a glean
126  * object.
127  *
128  * this means that these graph nodes are ones from which a glean is the
129  * parent object in the DPO-graph.
130  */
131 const static char *const gbp_fwd_dpo_ip4_nodes[] = {
132  "ip4-gbp-fwd-dpo",
133  NULL,
134 };
135 
136 const static char *const gbp_fwd_dpo_ip6_nodes[] = {
137  "ip6-gbp-fwd-dpo",
138  NULL,
139 };
140 
141 const static char *const *const gbp_fwd_dpo_nodes[DPO_PROTO_NUM] = {
144 };
145 
148 {
149  return (gbp_fwd_dpo_type);
150 }
151 
152 static clib_error_t *
154 {
155  dpo_proto_t dproto;
156 
157  FOR_EACH_DPO_PROTO (dproto)
158  {
159  gbp_fwd_dpo_db[dproto] = INDEX_INVALID;
160  }
161 
164 
165  return (NULL);
166 }
167 
169 #endif /* CLIB_MARCH_VARIANT */
170 
171 typedef struct gbp_fwd_dpo_trace_t_
172 {
176 
177 typedef enum
178 {
183 
188 {
189  u32 n_left_from, next_index, *from, *to_next;
190 
192  n_left_from = from_frame->n_vectors;
193 
194  next_index = node->cached_next_index;
195 
196  while (n_left_from > 0)
197  {
198  u32 n_left_to_next;
199 
200  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
201 
202  while (n_left_from > 0 && n_left_to_next > 0)
203  {
204  const dpo_id_t *next_dpo0;
205  vlib_buffer_t *b0;
206  sclass_t sclass0;
207  u32 bi0, next0;
208 
209  bi0 = from[0];
210  to_next[0] = bi0;
211  from += 1;
212  to_next += 1;
213  n_left_from -= 1;
214  n_left_to_next -= 1;
215 
216  b0 = vlib_get_buffer (vm, bi0);
217 
218  sclass0 = vnet_buffer2 (b0)->gbp.sclass;
219  next_dpo0 = gbp_epg_dpo_lookup (sclass0, fproto);
220 
221  if (PREDICT_TRUE (NULL != next_dpo0))
222  {
223  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = next_dpo0->dpoi_index;
224  next0 = GBP_FWD_FWD;
225  }
226  else
227  {
228  next0 = GBP_FWD_DROP;
229  }
230 
231  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
232  {
234 
235  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
236  tr->sclass = sclass0;
237  tr->dpo_index = (NULL != next_dpo0 ?
238  next_dpo0->dpoi_index : ~0);
239  }
240 
242  n_left_to_next, bi0, next0);
243  }
244  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
245  }
246  return from_frame->n_vectors;
247 }
248 
249 static u8 *
250 format_gbp_fwd_dpo_trace (u8 * s, va_list * args)
251 {
252  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
253  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
254  gbp_fwd_dpo_trace_t *t = va_arg (*args, gbp_fwd_dpo_trace_t *);
255 
256  s = format (s, " sclass:%d dpo:%d", t->sclass, t->dpo_index);
257 
258  return s;
259 }
260 
264 {
266 }
267 
271 {
273 }
274 
275 /* *INDENT-OFF* */
277  .name = "ip4-gbp-fwd-dpo",
278  .vector_size = sizeof (u32),
279  .format_trace = format_gbp_fwd_dpo_trace,
280  .n_next_nodes = GBP_FWD_N_NEXT,
281  .next_nodes =
282  {
283  [GBP_FWD_DROP] = "ip4-drop",
284  [GBP_FWD_FWD] = "ip4-dvr-dpo",
285  }
286 };
288  .name = "ip6-gbp-fwd-dpo",
289  .vector_size = sizeof (u32),
290  .format_trace = format_gbp_fwd_dpo_trace,
291  .n_next_nodes = GBP_FWD_N_NEXT,
292  .next_nodes =
293  {
294  [GBP_FWD_DROP] = "ip6-drop",
295  [GBP_FWD_FWD] = "ip6-dvr-dpo",
296  }
297 };
298 /* *INDENT-ON* */
299 
300 /*
301  * fd.io coding-style-patch-verification: ON
302  *
303  * Local Variables:
304  * eval: (c-set-style "gnu")
305  * End:
306  */
gbp_fwd_next_t
gbp_fwd_next_t
Definition: gbp_fwd_dpo.c:177
GBP_FWD_FWD
@ GBP_FWD_FWD
Definition: gbp_fwd_dpo.c:180
FOR_EACH_DPO_PROTO
#define FOR_EACH_DPO_PROTO(_proto)
Definition: dpo.h:84
gbp_fwd_dpo_db
static index_t gbp_fwd_dpo_db[DPO_PROTO_NUM]
The 'DB' of GBP FWD DPOs.
Definition: gbp_fwd_dpo.c:27
dpo_register_new_type
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:349
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
GBP_FWD_DROP
@ GBP_FWD_DROP
Definition: gbp_fwd_dpo.c:179
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
dpo_id_t_::dpoi_type
dpo_type_t dpoi_type
the type
Definition: dpo.h:178
gbp_fwd_dpo_alloc
static gbp_fwd_dpo_t * gbp_fwd_dpo_alloc(void)
Definition: gbp_fwd_dpo.c:40
gbp_fwd_dpo_nodes
const static char *const *const gbp_fwd_dpo_nodes[DPO_PROTO_NUM]
Definition: gbp_fwd_dpo.c:141
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
gbp.h
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
gbp_fwd_dpo_inline
static uword gbp_fwd_dpo_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, fib_protocol_t fproto)
Definition: gbp_fwd_dpo.c:185
vnet_buffer2
#define vnet_buffer2(b)
Definition: buffer.h:505
vlib_frame_t
Definition: node.h:372
ethernet.h
gbp_fwd_dpo_t_::gfd_proto
dpo_proto_t gfd_proto
The protocol of packets using this DPO.
Definition: gbp_fwd_dpo.h:31
gbp_fwd_dpo_trace_t
struct gbp_fwd_dpo_trace_t_ gbp_fwd_dpo_trace_t
gbp_fwd_dpo_module_init
static clib_error_t * gbp_fwd_dpo_module_init(vlib_main_t *vm)
Definition: gbp_fwd_dpo.c:153
gbp_fwd_dpo_t_::gfd_locks
u16 gfd_locks
number of locks.
Definition: gbp_fwd_dpo.h:36
format_gbp_fwd_dpo_trace
static u8 * format_gbp_fwd_dpo_trace(u8 *s, va_list *args)
Definition: gbp_fwd_dpo.c:250
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
ip6_gbp_fwd_dpo_node
vlib_node_registration_t ip6_gbp_fwd_dpo_node
(constructor) VLIB_REGISTER_NODE (ip6_gbp_fwd_dpo_node)
Definition: gbp_fwd_dpo.c:287
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
gbp_fwd_dpo_add_or_lock
void gbp_fwd_dpo_add_or_lock(dpo_proto_t dproto, dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:88
gbp_fwd_dpo_vft
const static dpo_vft_t gbp_fwd_dpo_vft
Definition: gbp_fwd_dpo.c:118
uword
u64 uword
Definition: types.h:112
gbp_fwd_dpo.h
dpo_type_t
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type()
gbp_fwd_dpo_get_type
dpo_type_t gbp_fwd_dpo_get_type(void)
Definition: gbp_fwd_dpo.c:147
format_gbp_fwd_dpo
u8 * format_gbp_fwd_dpo(u8 *s, va_list *ap)
Definition: gbp_fwd_dpo.c:109
gbp_fwd_dpo_trace_t_
Definition: gbp_fwd_dpo.c:171
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
gbp_fwd_dpo_trace_t_::dpo_index
u32 dpo_index
Definition: gbp_fwd_dpo.c:174
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
gbp_fwd_dpo_trace_t_::sclass
u32 sclass
Definition: gbp_fwd_dpo.c:173
gbp_fwd_dpo_get_from_dpo
static gbp_fwd_dpo_t * gbp_fwd_dpo_get_from_dpo(const dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:50
sclass_t
u16 sclass_t
Definition: gbp_types.h:25
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
gbp_fwd_dpo_get
static gbp_fwd_dpo_t * gbp_fwd_dpo_get(index_t index)
Definition: gbp_fwd_dpo.h:49
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
GBP_FWD_N_NEXT
@ GBP_FWD_N_NEXT
Definition: gbp_fwd_dpo.c:181
ip4_gbp_fwd_dpo_node
vlib_node_registration_t ip4_gbp_fwd_dpo_node
(constructor) VLIB_REGISTER_NODE (ip4_gbp_fwd_dpo_node)
Definition: gbp_fwd_dpo.c:276
gbp_fwd_dpo_t_
The GBP FWD DPO.
Definition: gbp_fwd_dpo.h:26
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
gbp_fwd_dpo_pool
gbp_fwd_dpo_t * gbp_fwd_dpo_pool
pool of all interface DPOs
Definition: gbp_fwd_dpo.c:37
format_dpo_proto
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:180
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
gbp_fwd_dpo_get_index
static index_t gbp_fwd_dpo_get_index(gbp_fwd_dpo_t *gfd)
Definition: gbp_fwd_dpo.c:58
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
gbp_epg_dpo_lookup
static const dpo_id_t * gbp_epg_dpo_lookup(sclass_t sclass, fib_protocol_t fproto)
Definition: gbp_endpoint_group.h:142
gbp_fwd_dpo_unlock
static void gbp_fwd_dpo_unlock(dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:73
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
gbp_fwd_dpo_type
static dpo_type_t gbp_fwd_dpo_type
DPO type registered for these GBP FWD.
Definition: gbp_fwd_dpo.c:32
dpo_set
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:188
vlib_node_runtime_t
Definition: node.h:454
gbp_fwd_dpo_lock
static void gbp_fwd_dpo_lock(dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:64
from
from
Definition: nat44_ei_hairpinning.c:415
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
gbp_fwd_dpo_ip4_nodes
const static char *const gbp_fwd_dpo_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a glean object.
Definition: gbp_fwd_dpo.c:131
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
gbp_fwd_dpo_ip6_nodes
const static char *const gbp_fwd_dpo_ip6_nodes[]
Definition: gbp_fwd_dpo.c:136
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169