FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  * llc_node.c: llc packet processing
17  *
18  * Copyright (c) 2010 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #include <vlib/vlib.h>
41 #include <vnet/llc/llc.h>
42 
43 #define foreach_llc_input_next \
44  _ (PUNT, "error-punt") \
45  _ (DROP, "error-drop")
46 
47 typedef enum
48 {
49 #define _(s,n) LLC_INPUT_NEXT_##s,
51 #undef _
54 
55 typedef struct
56 {
57  u8 packet_data[32];
59 
60 static u8 *
61 format_llc_input_trace (u8 * s, va_list * va)
62 {
63  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
64  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
65  llc_input_trace_t *t = va_arg (*va, llc_input_trace_t *);
66 
67  s = format (s, "%U", format_llc_header, t->packet_data);
68 
69  return s;
70 }
71 
72 static uword
75 {
76  llc_main_t *lm = &llc_main;
77  u32 n_left_from, next_index, *from, *to_next;
78 
80  n_left_from = from_frame->n_vectors;
81 
82  if (node->flags & VLIB_NODE_FLAG_TRACE)
84  from,
86  sizeof (from[0]),
87  sizeof (llc_input_trace_t));
88 
89  next_index = node->cached_next_index;
90 
91  while (n_left_from > 0)
92  {
93  u32 n_left_to_next;
94 
95  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
96 
97  while (n_left_from >= 4 && n_left_to_next >= 2)
98  {
99  u32 bi0, bi1;
100  vlib_buffer_t *b0, *b1;
101  llc_header_t *h0, *h1;
102  u8 next0, next1, len0, len1, enqueue_code;
103 
104  /* Prefetch next iteration. */
105  {
106  vlib_buffer_t *b2, *b3;
107 
108  b2 = vlib_get_buffer (vm, from[2]);
109  b3 = vlib_get_buffer (vm, from[3]);
110 
111  vlib_prefetch_buffer_header (b2, LOAD);
112  vlib_prefetch_buffer_header (b3, LOAD);
113 
114  CLIB_PREFETCH (b2->data, sizeof (h0[0]), LOAD);
115  CLIB_PREFETCH (b3->data, sizeof (h1[0]), LOAD);
116  }
117 
118  bi0 = from[0];
119  bi1 = from[1];
120  to_next[0] = bi0;
121  to_next[1] = bi1;
122  from += 2;
123  to_next += 2;
124  n_left_to_next -= 2;
125  n_left_from -= 2;
126 
127  b0 = vlib_get_buffer (vm, bi0);
128  b1 = vlib_get_buffer (vm, bi1);
129 
130  h0 = vlib_buffer_get_current (b0);
131  h1 = vlib_buffer_get_current (b1);
132 
133  len0 = llc_header_length (h0);
134  len1 = llc_header_length (h1);
135 
136  vlib_buffer_advance (b0, len0);
137  vlib_buffer_advance (b1, len1);
138 
139  next0 = lm->input_next_by_protocol[h0->dst_sap];
140  next1 = lm->input_next_by_protocol[h1->dst_sap];
141 
142  b0->error =
143  node->errors[next0 ==
144  LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
145  LLC_ERROR_NONE];
146  b1->error =
147  node->errors[next1 ==
148  LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
149  LLC_ERROR_NONE];
150 
151  enqueue_code = (next0 != next_index) + 2 * (next1 != next_index);
152 
153  if (PREDICT_FALSE (enqueue_code != 0))
154  {
155  switch (enqueue_code)
156  {
157  case 1:
158  /* A B A */
159  to_next[-2] = bi1;
160  to_next -= 1;
161  n_left_to_next += 1;
162  vlib_set_next_frame_buffer (vm, node, next0, bi0);
163  break;
164 
165  case 2:
166  /* A A B */
167  to_next -= 1;
168  n_left_to_next += 1;
169  vlib_set_next_frame_buffer (vm, node, next1, bi1);
170  break;
171 
172  case 3:
173  /* A B B or A B C */
174  to_next -= 2;
175  n_left_to_next += 2;
176  vlib_set_next_frame_buffer (vm, node, next0, bi0);
177  vlib_set_next_frame_buffer (vm, node, next1, bi1);
178  if (next0 == next1)
179  {
181  n_left_to_next);
182  next_index = next1;
184  n_left_to_next);
185  }
186  }
187  }
188  }
189 
190  while (n_left_from > 0 && n_left_to_next > 0)
191  {
192  u32 bi0;
193  vlib_buffer_t *b0;
194  llc_header_t *h0;
195  u8 next0, len0;
196 
197  bi0 = from[0];
198  to_next[0] = bi0;
199  from += 1;
200  to_next += 1;
201  n_left_from -= 1;
202  n_left_to_next -= 1;
203 
204  b0 = vlib_get_buffer (vm, bi0);
205 
206  h0 = vlib_buffer_get_current (b0);
207 
208  len0 = llc_header_length (h0);
209 
210  vlib_buffer_advance (b0, len0);
211 
212  next0 = lm->input_next_by_protocol[h0->dst_sap];
213 
214  b0->error =
215  node->errors[next0 ==
216  LLC_INPUT_NEXT_DROP ? LLC_ERROR_UNKNOWN_PROTOCOL :
217  LLC_ERROR_NONE];
218 
219  /* Sent packet to wrong next? */
220  if (PREDICT_FALSE (next0 != next_index))
221  {
222  /* Return old frame; remove incorrectly enqueued packet. */
223  vlib_put_next_frame (vm, node, next_index, n_left_to_next + 1);
224 
225  /* Send to correct next. */
226  next_index = next0;
228  to_next, n_left_to_next);
229 
230  to_next[0] = bi0;
231  to_next += 1;
232  n_left_to_next -= 1;
233  }
234  }
235 
236  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
237  }
238 
239  return from_frame->n_vectors;
240 }
241 
242 static char *llc_error_strings[] = {
243 #define _(f,s) s,
245 #undef _
246 };
247 
248 /* *INDENT-OFF* */
250  .function = llc_input,
251  .name = "llc-input",
252  /* Takes a vector of packets. */
253  .vector_size = sizeof (u32),
254 
255  .n_errors = LLC_N_ERROR,
256  .error_strings = llc_error_strings,
257 
258  .n_next_nodes = LLC_INPUT_N_NEXT,
259  .next_nodes = {
260 #define _(s,n) [LLC_INPUT_NEXT_##s] = n,
262 #undef _
263  },
264 
265  .format_buffer = format_llc_header_with_length,
266  .format_trace = format_llc_input_trace,
267  .unformat_buffer = unformat_llc_header,
268 };
269 /* *INDENT-ON* */
270 
271 static clib_error_t *
273 {
274  llc_main_t *lm = &llc_main;
275 
276  {
278  if (error)
280  }
281 
283 
284  {
285  int i;
286  for (i = 0; i < ARRAY_LEN (lm->input_next_by_protocol); i++)
287  lm->input_next_by_protocol[i] = LLC_INPUT_NEXT_DROP;
288  }
289 
290  return 0;
291 }
292 
294 
295 void
298 {
299  llc_main_t *lm = &llc_main;
301 
302  {
304  if (error)
306  /* Otherwise, osi_input_init will wipe out e.g. the snap init */
308  if (error)
310  }
311 
312  pi = llc_get_protocol_info (lm, protocol);
313  pi->node_index = node_index;
315 
317 }
318 
319 /*
320  * fd.io coding-style-patch-verification: ON
321  *
322  * Local Variables:
323  * eval: (c-set-style "gnu")
324  * End:
325  */
vlib.h
llc_header_length
static u8 llc_header_length(llc_header_t *h)
Definition: llc.h:101
format_llc_header
format_function_t format_llc_header
Definition: llc.h:162
llc_main_t
Definition: llc.h:134
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
vlib_node_add_next
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1177
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
foreach_llc_error
#define foreach_llc_error
Definition: llc.h:121
LLC_INPUT_N_NEXT
@ LLC_INPUT_N_NEXT
Definition: node.c:52
llc_error_strings
static char * llc_error_strings[]
Definition: node.c:242
vlib_trace_frame_buffers_only
void vlib_trace_frame_buffers_only(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, uword n_buffers, uword next_buffer_stride, uword n_buffer_data_bytes_in_trace)
Definition: trace.c:48
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
llc_get_protocol_info
static llc_protocol_info_t * llc_get_protocol_info(llc_main_t *m, llc_protocol_t protocol)
Definition: llc.h:148
format_llc_input_trace
static u8 * format_llc_input_trace(u8 *s, va_list *va)
Definition: node.c:61
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition: init.h:259
llc_header_t::dst_sap
u8 dst_sap
Definition: llc.h:82
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
node_index
node node_index
Definition: interface_output.c:420
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
llc_input_node
vlib_node_registration_t llc_input_node
(constructor) VLIB_REGISTER_NODE (llc_input_node)
Definition: node.c:249
clib_error_report
#define clib_error_report(e)
Definition: error.h:113
vlib_frame_t
Definition: node.h:372
error
Definition: cJSON.c:88
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
llc_protocol_info_t
Definition: llc.h:106
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_buffer_t::error
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
llc_input_next_t
llc_input_next_t
Definition: node.c:47
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
llc_protocol_info_t::node_index
u32 node_index
Definition: llc.h:115
format_llc_header_with_length
format_function_t format_llc_header_with_length
Definition: llc.h:163
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
llc_header_t
Definition: llc.h:78
unformat_llc_header
unformat_function_t unformat_llc_header
Definition: llc.h:169
uword
u64 uword
Definition: types.h:112
llc_input_trace_t
Definition: node.c:55
foreach_llc_input_next
#define foreach_llc_input_next
Definition: node.c:43
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
llc_input_init
static clib_error_t * llc_input_init(vlib_main_t *vm)
Definition: node.c:272
llc_input_trace_t::packet_data
u8 packet_data[32]
Definition: node.c:57
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
LLC_N_ERROR
@ LLC_N_ERROR
Definition: llc.h:131
format
description fragment has unexpected format
Definition: map.api:433
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
llc_init
static clib_error_t * llc_init(vlib_main_t *vm)
Definition: llc.c:211
llc_main_t::input_next_by_protocol
u8 input_next_by_protocol[256]
Definition: llc.h:144
vlib_set_next_frame_buffer
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:428
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
llc_input
static uword llc_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: node.c:73
llc_main
llc_main_t llc_main
Definition: llc.c:44
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
llc.h
llc_setup_node
static void llc_setup_node(vlib_main_t *vm, u32 node_index)
Definition: llc.h:173
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
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
osi_input_init
static clib_error_t * osi_input_init(vlib_main_t *vm)
Definition: node.c:266
llc_register_input_protocol
void llc_register_input_protocol(vlib_main_t *vm, llc_protocol_t protocol, u32 node_index)
Definition: node.c:296
vlib_node_runtime_t
Definition: node.h:454
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
llc_protocol_info_t::next_index
u32 next_index
Definition: llc.h:118
llc_protocol_t
llc_protocol_t
Definition: llc.h:71
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169