FD.io VPP  v18.10-34-gcce845e
Vector Packet Processing
gbp_classify.c
Go to the documentation of this file.
1 /*
2  * gbp.h : Group Based Policy
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <plugins/gbp/gbp.h>
19 #include <vnet/l2/l2_input.h>
20 #include <vnet/l2/feat_bitmap.h>
21 
23 {
27 
28 #define GBP_SRC_N_CLASSIFY (GBP_SRC_CLASSIFY_PORT + 1)
29 
30 /**
31  * Grouping of global data for the GBP source EPG classification feature
32  */
34 {
35  /**
36  * Next nodes for L2 output features
37  */
40 
42 
43 /**
44  * per-packet trace data
45  */
46 typedef struct gbp_classify_trace_t_
47 {
48  /* per-pkt trace data */
51 
52 /*
53  * determine the SRC EPG form the input port
54  */
57  vlib_node_runtime_t * node,
58  vlib_frame_t * frame,
59  gbp_src_classify_type_t type, u8 is_l3)
60 {
62  u32 n_left_from, *from, *to_next;
63  u32 next_index;
64 
65  next_index = 0;
66  n_left_from = frame->n_vectors;
67  from = vlib_frame_vector_args (frame);
68 
69  while (n_left_from > 0)
70  {
71  u32 n_left_to_next;
72 
73  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
74 
75  while (n_left_from > 0 && n_left_to_next > 0)
76  {
77  u32 next0, bi0, src_epg, sw_if_index0;
78  const gbp_endpoint_t *gep0;
79  vlib_buffer_t *b0;
80 
81  bi0 = from[0];
82  to_next[0] = bi0;
83  from += 1;
84  to_next += 1;
85  n_left_from -= 1;
86  n_left_to_next -= 1;
87 
88  b0 = vlib_get_buffer (vm, bi0);
89 
90  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
91 
92  if (GBP_SRC_CLASSIFY_NULL == type)
93  {
94  src_epg = EPG_INVALID;
95  next0 =
97  L2INPUT_FEAT_GBP_NULL_CLASSIFY);
98  }
99  else
100  {
101  gep0 = gbp_endpoint_get_itf (sw_if_index0);
102  src_epg = gep0->ge_epg_id;
103  if (is_l3)
104  {
105  /*
106  * Go straight to lookup, do not pass go, do not collect $200
107  */
108  next0 = 0;
109  }
110  else
111  {
112  next0 =
113  vnet_l2_feature_next (b0, gscm->l2_input_feat_next[type],
114  L2INPUT_FEAT_GBP_SRC_CLASSIFY);
115  }
116  }
117 
118  vnet_buffer2 (b0)->gbp.src_epg = src_epg;
119 
120  if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
121  {
123  vlib_add_trace (vm, node, b0, sizeof (*t));
124  t->src_epg = src_epg;
125  }
126 
127  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
128  to_next, n_left_to_next,
129  bi0, next0);
130  }
131 
132  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
133  }
134 
135  return frame->n_vectors;
136 }
137 
138 static uword
140  vlib_node_runtime_t * node, vlib_frame_t * frame)
141 {
142  return (gbp_classify_inline (vm, node, frame, GBP_SRC_CLASSIFY_PORT, 0));
143 }
144 
145 static uword
147  vlib_node_runtime_t * node, vlib_frame_t * frame)
148 {
149  return (gbp_classify_inline (vm, node, frame, GBP_SRC_CLASSIFY_NULL, 0));
150 }
151 
152 static uword
154  vlib_node_runtime_t * node, vlib_frame_t * frame)
155 {
156  return (gbp_classify_inline (vm, node, frame, 0, 1));
157 }
158 
159 static uword
161  vlib_node_runtime_t * node, vlib_frame_t * frame)
162 {
163  return (gbp_classify_inline (vm, node, frame, 0, 1));
164 }
165 
166 
167 /* packet trace format function */
168 static u8 *
169 format_gbp_classify_trace (u8 * s, va_list * args)
170 {
171  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
172  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
173  gbp_classify_trace_t *t = va_arg (*args, gbp_classify_trace_t *);
174 
175  s = format (s, "src-epg:%d", t->src_epg);
176 
177  return s;
178 }
179 
180 /* *INDENT-OFF* */
182  .function = gbp_null_classify,
183  .name = "gbp-null-classify",
184  .vector_size = sizeof (u32),
185  .format_trace = format_gbp_classify_trace,
186  .type = VLIB_NODE_TYPE_INTERNAL,
187 
188  .n_errors = 0,
189  .n_next_nodes = 0,
190 };
191 
193 
195  .function = gbp_src_classify,
196  .name = "gbp-src-classify",
197  .vector_size = sizeof (u32),
198  .format_trace = format_gbp_classify_trace,
199  .type = VLIB_NODE_TYPE_INTERNAL,
200 
201  .n_errors = 0,
202  .n_next_nodes = 0,
203 };
204 
206 
208  .function = gbp_ip4_src_classify,
209  .name = "ip4-gbp-src-classify",
210  .vector_size = sizeof (u32),
211  .format_trace = format_gbp_classify_trace,
212  .type = VLIB_NODE_TYPE_INTERNAL,
213 
214  .n_errors = 0,
215  .n_next_nodes = 1,
216  .next_nodes = {
217  [0] = "ip4-lookup"
218  },
219 };
220 
222 
224  .function = gbp_ip6_src_classify,
225  .name = "ip6-gbp-src-classify",
226  .vector_size = sizeof (u32),
227  .format_trace = format_gbp_classify_trace,
228  .type = VLIB_NODE_TYPE_INTERNAL,
229 
230  .n_errors = 0,
231  .n_next_nodes = 1,
232  .next_nodes = {
233  [0] = "ip6-lookup"
234  },
235 };
236 
238 
239 VNET_FEATURE_INIT (gbp_ip4_src_classify_feat_node, static) =
240 {
241  .arc_name = "ip4-unicast",
242  .node_name = "ip4-gbp-src-classify",
243  .runs_before = VNET_FEATURES ("nat44-out2in"),
244 };
245 VNET_FEATURE_INIT (gbp_ip6_src_classify_feat_node, static) =
246 {
247  .arc_name = "ip6-unicast",
248  .node_name = "ip6-gbp-src-classify",
249  .runs_before = VNET_FEATURES ("nat66-out2in"),
250 };
251 
252 static clib_error_t *
254 {
256 
257  /* Initialize the feature next-node indexes */
259  gbp_src_classify_node.index,
268 
269  return 0;
270 }
271 
273 
274 /*
275  * fd.io coding-style-patch-verification: ON
276  *
277  * Local Variables:
278  * eval: (c-set-style "gnu")
279  * End:
280  */
static u8 * format_gbp_classify_trace(u8 *s, va_list *args)
Definition: gbp_classify.c:169
static uword gbp_null_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: gbp_classify.c:146
u16 epg_id_t
Definition: gbp_types.h:21
A Group Based Policy Endpoint.
Definition: gbp_endpoint.h:46
#define CLIB_UNUSED(x)
Definition: clib.h:81
vlib_node_registration_t gbp_src_classify_node
(constructor) VLIB_REGISTER_NODE (gbp_src_classify_node)
Definition: gbp_classify.c:194
#define vnet_buffer2(b)
Definition: buffer.h:389
static gbp_src_classify_main_t gbp_src_classify_main
Definition: gbp_classify.c:41
static uword gbp_src_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: gbp_classify.c:139
struct gbp_classify_trace_t_ gbp_classify_trace_t
per-packet trace data
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
unsigned char u8
Definition: types.h:56
static u32 vnet_l2_feature_next(vlib_buffer_t *b, u32 *next_nodes, u32 feat_bit)
Return the graph node index for the feature corresponding to the next set bit after clearing the curr...
Definition: feat_bitmap.h:94
#define GBP_SRC_N_CLASSIFY
Definition: gbp_classify.c:28
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
#define always_inline
Definition: clib.h:94
gbp_src_classify_type_t_
Definition: gbp_classify.c:22
static uword gbp_classify_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, gbp_src_classify_type_t type, u8 is_l3)
Definition: gbp_classify.c:56
static clib_error_t * gbp_src_classify_init(vlib_main_t *vm)
Definition: gbp_classify.c:253
struct gbp_src_classify_main_t_ gbp_src_classify_main_t
Grouping of global data for the GBP source EPG classification feature.
unsigned int u32
Definition: types.h:88
static uword gbp_ip4_src_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: gbp_classify.c:153
static uword gbp_ip6_src_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: gbp_classify.c:160
per-packet trace data
Definition: gbp_classify.c:46
#define PREDICT_FALSE(x)
Definition: clib.h:107
#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:218
enum gbp_src_classify_type_t_ gbp_src_classify_type_t
#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:364
vlib_node_registration_t gbp_ip6_src_classify_node
(constructor) VLIB_REGISTER_NODE (gbp_ip6_src_classify_node)
Definition: gbp_classify.c:223
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:155
u16 n_vectors
Definition: node.h:401
vlib_main_t * vm
Definition: buffer.c:294
Grouping of global data for the GBP source EPG classification feature.
Definition: gbp_classify.c:33
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
Definition: feat_bitmap.h:43
u32 l2_input_feat_next[GBP_SRC_N_CLASSIFY][32]
Next nodes for L2 output features.
Definition: gbp_classify.c:38
static gbp_endpoint_t * gbp_endpoint_get_itf(u32 sw_if_index)
Definition: gbp_endpoint.h:122
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:455
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:60
VLIB_NODE_FUNCTION_MULTIARCH(gbp_null_classify_node, gbp_null_classify)
#define EPG_INVALID
Definition: gbp_types.h:22
#define VNET_FEATURES(...)
Definition: feature.h:386
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
vlib_node_registration_t gbp_ip4_src_classify_node
(constructor) VLIB_REGISTER_NODE (gbp_ip4_src_classify_node)
Definition: gbp_classify.c:207
epg_id_t ge_epg_id
The endpoint&#39;s designated EPG.
Definition: gbp_endpoint.h:66
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
#define vnet_buffer(b)
Definition: buffer.h:344
VNET_FEATURE_INIT(gbp_ip4_src_classify_feat_node, static)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:116
vlib_node_registration_t gbp_null_classify_node
(constructor) VLIB_REGISTER_NODE (gbp_null_classify_node)
Definition: gbp_classify.c:181
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:58
Definition: defs.h:46