FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016,2020 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/adl/adl.h>
17 
18 typedef struct {
22 
23 /* packet trace format function */
24 static u8 * format_adl_input_trace (u8 * s, va_list * args)
25 {
26  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
27  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
28  adl_input_trace_t * t = va_arg (*args, adl_input_trace_t *);
29 
30  s = format (s, "ADL_INPUT: sw_if_index %d, next index %d",
31  t->sw_if_index, t->next_index);
32  return s;
33 }
34 
35 #define foreach_adl_input_error \
36 _(PROCESSED, "Allow/Deny packets processed")
37 
38 typedef enum {
39 #define _(sym,str) ADL_INPUT_ERROR_##sym,
41 #undef _
44 
45 static char * adl_input_error_strings[] = {
46 #define _(sym,string) string,
48 #undef _
49 };
50 
54 {
55  u32 n_left_from, * from, * to_next;
58 
60  n_left_from = frame->n_vectors;
61  next_index = node->cached_next_index;
62 
63  while (n_left_from > 0)
64  {
65  u32 n_left_to_next;
66 
68  to_next, n_left_to_next);
69 
70  while (n_left_from >= 4 && n_left_to_next >= 2)
71  {
72  u32 bi0, bi1;
73  vlib_buffer_t * b0, * b1;
74  u32 next0, next1;
75  u32 sw_if_index0, sw_if_index1;
76  ethernet_header_t * en0, * en1;
77  adl_config_main_t * ccm0, * ccm1;
78  u32 advance0, advance1;
79  int proto0, proto1;
80 
81  /* Prefetch next iteration. */
82  {
83  vlib_buffer_t * p2, * p3;
84 
85  p2 = vlib_get_buffer (vm, from[2]);
86  p3 = vlib_get_buffer (vm, from[3]);
87 
88  vlib_prefetch_buffer_header (p2, LOAD);
89  vlib_prefetch_buffer_header (p3, LOAD);
90 
93  }
94 
95  /* speculatively enqueue b0 and b1 to the current next frame */
96  to_next[0] = bi0 = from[0];
97  to_next[1] = bi1 = from[1];
98  from += 2;
99  to_next += 2;
100  n_left_from -= 2;
101  n_left_to_next -= 2;
102 
103  b0 = vlib_get_buffer (vm, bi0);
104  b1 = vlib_get_buffer (vm, bi1);
105 
106  en0 = vlib_buffer_get_current (b0);
107  en1 = vlib_buffer_get_current (b1);
108 
109  sw_if_index0 = adl_buffer(b0)->sw_if_index[VLIB_RX];
110  sw_if_index1 = adl_buffer(b1)->sw_if_index[VLIB_RX];
111 
112  proto0 = VNET_ADL_DEFAULT;
113  proto1 = VNET_ADL_DEFAULT;
114  advance0 = 0;
115  advance1 = 0;
116 
117  if (en0->type == clib_host_to_net_u16(ETHERNET_TYPE_IP4))
118  {
119  proto0 = VNET_ADL_IP4;
120  advance0 = sizeof(ethernet_header_t);
121  }
122  else if (en0->type == clib_host_to_net_u16(ETHERNET_TYPE_IP6))
123  {
124  proto0 = VNET_ADL_IP6;
125  advance0 = sizeof(ethernet_header_t);
126  }
127 
128  if (en1->type == clib_host_to_net_u16(ETHERNET_TYPE_IP4))
129  {
130  proto1 = VNET_ADL_IP4;
131  advance1 = sizeof(ethernet_header_t);
132  }
133  else if (en1->type == clib_host_to_net_u16(ETHERNET_TYPE_IP6))
134  {
135  proto1 = VNET_ADL_IP6;
136  advance1 = sizeof(ethernet_header_t);
137  }
138 
139  ccm0 = am->adl_config_mains + proto0;
140  ccm1 = am->adl_config_mains + proto1;
141  adl_buffer(b0)->adl.current_config_index =
142  ccm0->config_index_by_sw_if_index [sw_if_index0];
143 
144  adl_buffer(b1)->adl.current_config_index =
145  ccm1->config_index_by_sw_if_index [sw_if_index1];
146 
147  vlib_buffer_advance (b0, advance0);
148  vlib_buffer_advance (b1, advance1);
149 
151  &adl_buffer(b0)->adl.current_config_index,
152  &next0, 0 /* bytes of config data */);
153 
155  &adl_buffer(b1)->adl.current_config_index,
156  &next1, 0 /* bytes of config data */);
157 
159  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
160  {
161  adl_input_trace_t *t =
162  vlib_add_trace (vm, node, b0, sizeof (*t));
163  t->sw_if_index = sw_if_index0;
164  t->next_index = next0;
165  }
166 
168  && (b1->flags & VLIB_BUFFER_IS_TRACED)))
169  {
170  adl_input_trace_t *t =
171  vlib_add_trace (vm, node, b1, sizeof (*t));
172  t->sw_if_index = sw_if_index1;
173  t->next_index = next1;
174  }
175  /* verify speculative enqueues, maybe switch current next frame */
177  to_next, n_left_to_next,
178  bi0, bi1, next0, next1);
179  }
180 
181  while (n_left_from > 0 && n_left_to_next > 0)
182  {
183  u32 bi0;
184  vlib_buffer_t * b0;
185  u32 next0;
186  u32 sw_if_index0;
187  ethernet_header_t *en0;
188  adl_config_main_t *ccm0;
189  u32 advance0;
190  int proto0;
191 
192  /* speculatively enqueue b0 to the current next frame */
193  bi0 = from[0];
194  to_next[0] = bi0;
195  from += 1;
196  to_next += 1;
197  n_left_from -= 1;
198  n_left_to_next -= 1;
199 
200  b0 = vlib_get_buffer (vm, bi0);
201 
202  /*
203  * Direct from the driver, we should be at offset 0
204  * aka at &b0->data[0]
205  */
206  ASSERT (b0->current_data == 0);
207 
208  en0 = vlib_buffer_get_current (b0);
209 
210  sw_if_index0 = adl_buffer(b0)->sw_if_index[VLIB_RX];
211 
212  proto0 = VNET_ADL_DEFAULT;
213  advance0 = 0;
214 
215  if (en0->type == clib_host_to_net_u16(ETHERNET_TYPE_IP4))
216  {
217  proto0 = VNET_ADL_IP4;
218  advance0 = sizeof(ethernet_header_t);
219  }
220  else if (en0->type == clib_host_to_net_u16(ETHERNET_TYPE_IP6))
221  {
222  proto0 = VNET_ADL_IP6;
223  advance0 = sizeof(ethernet_header_t);
224  }
225 
226  ccm0 = am->adl_config_mains + proto0;
227  adl_buffer(b0)->adl.current_config_index =
228  ccm0->config_index_by_sw_if_index [sw_if_index0];
229 
230  vlib_buffer_advance (b0, advance0);
231 
233  &adl_buffer(b0)->adl.current_config_index,
234  &next0, 0 /* bytes of config data */);
235 
237  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
238  {
239  adl_input_trace_t *t =
240  vlib_add_trace (vm, node, b0, sizeof (*t));
241  t->sw_if_index = sw_if_index0;
242  t->next_index = next0;
243  }
244 
245  /* verify speculative enqueue, maybe switch current next frame */
247  to_next, n_left_to_next,
248  bi0, next0);
249  }
250 
251  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
252  }
254  ADL_INPUT_ERROR_PROCESSED, frame->n_vectors);
255  return frame->n_vectors;
256 }
257 
259  .name = "adl-input",
260  .vector_size = sizeof (u32),
261  .format_trace = format_adl_input_trace,
262  .unformat_buffer = unformat_ethernet_header,
264 
265  .n_errors = ARRAY_LEN(adl_input_error_strings),
266  .error_strings = adl_input_error_strings,
267 
268  .n_next_nodes = ADL_RX_N_FEATURES,
269 
270  /* edit / add dispositions here */
271  .next_nodes = {
272  [IP4_RX_ADL_ALLOWLIST] = "ip4-adl-allowlist",
273  [IP6_RX_ADL_ALLOWLIST] = "ip6-adl-allowlist",
274  [DEFAULT_RX_ADL_ALLOWLIST] = "default-adl-allowlist",
275  [IP4_RX_ADL_INPUT] = "ip4-input",
276  [IP6_RX_ADL_INPUT] = "ip6-input",
277  [DEFAULT_RX_ADL_INPUT] = "ethernet-input",
278  [RX_ADL_DROP] = "error-drop",
279  },
280 };
281 
282 #define foreach_adl_stub \
283 _(default-adl-allowlist, default_adl_allowlist)
284 
285 #define _(n,f) \
286  \
287 static uword \
288 f##_node_fn (vlib_main_t * vm, \
289  vlib_node_runtime_t * node, \
290  vlib_frame_t * frame) \
291 { \
292  clib_warning ("BUG: stub function called"); \
293  return 0; \
294 } \
295  \
296 VLIB_REGISTER_NODE (f##_input_node) = { \
297  .function = f##_node_fn, \
298  .name = #n, \
299  .vector_size = sizeof (u32), \
300  .type = VLIB_NODE_TYPE_INTERNAL, \
301  \
302  .n_errors = 0, \
303  .error_strings = 0, \
304  \
305  .n_next_nodes = 0, \
306 };
307 
adl_config_main_t::config_index_by_sw_if_index
u32 * config_index_by_sw_if_index
Definition: adl.h:57
VNET_ADL_IP4
@ VNET_ADL_IP4
Definition: adl.h:32
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
DEFAULT_RX_ADL_ALLOWLIST
@ DEFAULT_RX_ADL_ALLOWLIST
Definition: adl.h:42
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
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
ADL_RX_N_FEATURES
@ ADL_RX_N_FEATURES
Definition: adl.h:52
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
RX_ADL_DROP
@ RX_ADL_DROP
Definition: adl.h:50
DEFAULT_RX_ADL_INPUT
@ DEFAULT_RX_ADL_INPUT
Definition: adl.h:47
adl_feature_type_t
adl_feature_type_t
Definition: adl.h:38
adl_input_trace_t
Definition: node.c:18
am
app_main_t * am
Definition: application.c:489
ethernet_header_t::type
u16 type
Definition: packet.h:59
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
vlib_frame_t
Definition: node.h:372
adl_input_error_strings
static char * adl_input_error_strings[]
Definition: node.c:45
adl_main_t
Definition: adl.h:64
adl_input_error_t
adl_input_error_t
Definition: node.c:38
ADL_INPUT_N_ERROR
@ ADL_INPUT_N_ERROR
Definition: node.c:42
IP4_RX_ADL_ALLOWLIST
@ IP4_RX_ADL_ALLOWLIST
Definition: adl.h:40
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
foreach_adl_input_error
#define foreach_adl_input_error
Definition: node.c:35
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
VNET_ADL_IP6
@ VNET_ADL_IP6
Definition: adl.h:33
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
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
adl_input_node
vlib_node_registration_t adl_input_node
(constructor) VLIB_REGISTER_NODE (adl_input_node)
Definition: node.c:258
ethernet_header_t
Definition: packet.h:52
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
adl_config_main_t
Definition: adl.h:55
format_adl_input_trace
static u8 * format_adl_input_trace(u8 *s, va_list *args)
Definition: node.c:24
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
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
adl_input_trace_t::sw_if_index
u32 sw_if_index
Definition: node.c:20
unformat_ethernet_header
uword unformat_ethernet_header(unformat_input_t *input, va_list *args)
Definition: format.c:290
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)
u32
unsigned int u32
Definition: types.h:88
IP6_RX_ADL_ALLOWLIST
@ IP6_RX_ADL_ALLOWLIST
Definition: adl.h:41
VNET_ADL_DEFAULT
@ VNET_ADL_DEFAULT
Definition: adl.h:34
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
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
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vnet_get_config_data
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
Definition: config.h:123
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
IP4_RX_ADL_INPUT
@ IP4_RX_ADL_INPUT
Definition: adl.h:45
foreach_adl_stub
#define foreach_adl_stub
Definition: node.c:282
vlib_validate_buffer_enqueue_x2
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
clib_prefetch_store
static_always_inline void clib_prefetch_store(void *p)
Definition: cache.h:98
vlib_node_runtime_t
Definition: node.h:454
adl_main
adl_main_t adl_main
Definition: adl.c:20
from
from
Definition: nat44_ei_hairpinning.c:415
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
adl_config_main_t::config_main
vnet_config_main_t config_main
Definition: adl.h:56
adl_input_trace_t::next_index
u32 next_index
Definition: node.c:19
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
adl_buffer
#define adl_buffer(b)
Definition: adl.h:111
IP6_RX_ADL_INPUT
@ IP6_RX_ADL_INPUT
Definition: adl.h:46
adl.h
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