blob: 846eb57b95e8a8d447c479b6e8c32d505bd3c109 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 * interface_output.c: interface output node
17 *
18 * Copyright (c) 2008 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 <vnet/vnet.h>
Damjan Marion152e21d2016-11-29 14:55:43 +010041#include <vnet/feature/feature.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
Dave Barachba868bb2016-08-08 09:51:21 -040043typedef struct
44{
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 u32 sw_if_index;
Chris Luke1c9f6ce2016-04-26 10:55:52 -040046 u8 data[128 - sizeof (u32)];
Dave Barachba868bb2016-08-08 09:51:21 -040047}
48interface_output_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070049
Dave Barachba868bb2016-08-08 09:51:21 -040050u8 *
51format_vnet_interface_output_trace (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -070052{
53 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
Dave Barachba868bb2016-08-08 09:51:21 -040054 vlib_node_t *node = va_arg (*va, vlib_node_t *);
55 interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *);
56 vnet_main_t *vnm = vnet_get_main ();
57 vnet_sw_interface_t *si;
Ed Warnickecb9cada2015-12-08 15:45:58 -070058 uword indent;
59
Dave Barachba868bb2016-08-08 09:51:21 -040060 if (t->sw_if_index != (u32) ~ 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -070061 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070062 indent = format_get_indent (s);
Dave Barachba868bb2016-08-08 09:51:21 -040063
Neale Ranns177bbdc2016-11-15 09:46:51 +000064 if (pool_is_free_index
65 (vnm->interface_main.sw_interfaces, t->sw_if_index))
66 {
67 /* the interface may have been deleted by the time the trace is printed */
68 s = format (s, "sw_if_index: %d\n%U%U",
69 t->sw_if_index,
70 format_white_space, indent,
71 node->format_buffer ? node->
72 format_buffer : format_hex_bytes, t->data,
73 sizeof (t->data));
74 }
75 else
76 {
77 si = vnet_get_sw_interface (vnm, t->sw_if_index);
78
79 s = format (s, "%U\n%U%U",
80 format_vnet_sw_interface_name, vnm, si,
81 format_white_space, indent,
82 node->format_buffer ? node->
83 format_buffer : format_hex_bytes, t->data,
84 sizeof (t->data));
85 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070086 }
87 return s;
88}
89
90static void
91vnet_interface_output_trace (vlib_main_t * vm,
92 vlib_node_runtime_t * node,
Dave Barachba868bb2016-08-08 09:51:21 -040093 vlib_frame_t * frame, uword n_buffers)
Ed Warnickecb9cada2015-12-08 15:45:58 -070094{
Dave Barachba868bb2016-08-08 09:51:21 -040095 u32 n_left, *from;
Ed Warnickecb9cada2015-12-08 15:45:58 -070096
97 n_left = n_buffers;
98 from = vlib_frame_args (frame);
Dave Barachba868bb2016-08-08 09:51:21 -040099
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 while (n_left >= 4)
101 {
102 u32 bi0, bi1;
Dave Barachba868bb2016-08-08 09:51:21 -0400103 vlib_buffer_t *b0, *b1;
104 interface_output_trace_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105
106 /* Prefetch next iteration. */
107 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
108 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
109
110 bi0 = from[0];
111 bi1 = from[1];
112
113 b0 = vlib_get_buffer (vm, bi0);
114 b1 = vlib_get_buffer (vm, bi1);
115
116 if (b0->flags & VLIB_BUFFER_IS_TRACED)
117 {
118 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
119 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
Damjan Marionf1213b82016-03-13 02:22:06 +0100120 clib_memcpy (t0->data, vlib_buffer_get_current (b0),
Dave Barachba868bb2016-08-08 09:51:21 -0400121 sizeof (t0->data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 }
123 if (b1->flags & VLIB_BUFFER_IS_TRACED)
124 {
125 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
126 t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX];
Damjan Marionf1213b82016-03-13 02:22:06 +0100127 clib_memcpy (t1->data, vlib_buffer_get_current (b1),
Dave Barachba868bb2016-08-08 09:51:21 -0400128 sizeof (t1->data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129 }
130 from += 2;
131 n_left -= 2;
132 }
133
134 while (n_left >= 1)
135 {
136 u32 bi0;
Dave Barachba868bb2016-08-08 09:51:21 -0400137 vlib_buffer_t *b0;
138 interface_output_trace_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139
140 bi0 = from[0];
141
142 b0 = vlib_get_buffer (vm, bi0);
143
144 if (b0->flags & VLIB_BUFFER_IS_TRACED)
145 {
146 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
147 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
Damjan Marionf1213b82016-03-13 02:22:06 +0100148 clib_memcpy (t0->data, vlib_buffer_get_current (b0),
Dave Barachba868bb2016-08-08 09:51:21 -0400149 sizeof (t0->data));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150 }
151 from += 1;
152 n_left -= 1;
153 }
154}
155
156static never_inline u32
157slow_path (vlib_main_t * vm,
158 u32 bi,
159 vlib_buffer_t * b,
Dave Barachba868bb2016-08-08 09:51:21 -0400160 u32 n_left_to_tx, u32 * to_tx, u32 * n_slow_bytes_result)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161{
162 /* We've already enqueued a single buffer. */
163 u32 n_buffers = 0;
164 u32 n_slow_bytes = 0;
165
166 while (n_left_to_tx > 0)
167 {
168 to_tx[0] = bi;
169 to_tx += 1;
170 n_left_to_tx -= 1;
171 n_buffers += 1;
172 n_slow_bytes += vlib_buffer_length_in_chain (vm, b);
173
174 /* Be grumpy about zero length buffers for benefit of
Dave Barachba868bb2016-08-08 09:51:21 -0400175 driver tx function. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700176 ASSERT (b->current_length > 0);
177
Dave Barachba868bb2016-08-08 09:51:21 -0400178 if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700179 break;
180
181 bi = b->next_buffer;
182 b = vlib_get_buffer (vm, bi);
183 }
184
185 /* Ran out of space in next frame trying to enqueue buffers? */
186 if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
187 return 0;
188
189 *n_slow_bytes_result = n_slow_bytes;
190 return n_buffers;
191}
192
Dave Barachba868bb2016-08-08 09:51:21 -0400193/*
194 * Increment TX stats. Roll up consecutive increments to the same sw_if_index
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195 * into one increment.
196 */
Dave Barachba868bb2016-08-08 09:51:21 -0400197static_always_inline void
198incr_output_stats (vnet_main_t * vnm,
Damjan Marion586afd72017-04-05 19:18:20 +0200199 u32 thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400200 u32 length,
201 u32 sw_if_index,
202 u32 * last_sw_if_index, u32 * n_packets, u32 * n_bytes)
203{
204 vnet_interface_main_t *im;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205
Dave Barachba868bb2016-08-08 09:51:21 -0400206 if (PREDICT_TRUE (sw_if_index == *last_sw_if_index))
207 {
208 *n_packets += 1;
209 *n_bytes += length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210 }
Dave Barachba868bb2016-08-08 09:51:21 -0400211 else
212 {
213 if (PREDICT_TRUE (*last_sw_if_index != ~0))
214 {
215 im = &vnm->interface_main;
216
217 vlib_increment_combined_counter (im->combined_sw_if_counters
218 + VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200219 thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400220 *last_sw_if_index,
221 *n_packets, *n_bytes);
222 }
223 *last_sw_if_index = sw_if_index;
224 *n_packets = 1;
225 *n_bytes = length;
226 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700227}
228
229
230/* Interface output functions. */
231uword
Damjan Marion8b2247d2016-12-02 08:09:45 +0100232vnet_interface_output_node_flatten (vlib_main_t * vm,
233 vlib_node_runtime_t * node,
234 vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235{
Dave Barachba868bb2016-08-08 09:51:21 -0400236 vnet_main_t *vnm = vnet_get_main ();
237 vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
238 vnet_sw_interface_t *si;
239 vnet_hw_interface_t *hi;
240 u32 n_left_to_tx, *from, *from_end, *to_tx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700241 u32 n_bytes, n_buffers, n_packets;
242 u32 last_sw_if_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200243 u32 thread_index = vm->thread_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700244
245 n_buffers = frame->n_vectors;
246
247 if (node->flags & VLIB_NODE_FLAG_TRACE)
248 vnet_interface_output_trace (vm, node, frame, n_buffers);
249
250 from = vlib_frame_args (frame);
251
252 if (rt->is_deleted)
Dave Barachba868bb2016-08-08 09:51:21 -0400253 return vlib_error_drop_buffers (vm, node, from,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254 /* buffer stride */ 1,
255 n_buffers,
256 VNET_INTERFACE_OUTPUT_NEXT_DROP,
257 node->node_index,
258 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED);
259
260 si = vnet_get_sw_interface (vnm, rt->sw_if_index);
261 hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
Steve Shin042a6212017-07-07 14:57:46 -0700262 if (!(si->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP |
263 VNET_SW_INTERFACE_FLAG_BOND_SLAVE)) ||
Dave Barachba868bb2016-08-08 09:51:21 -0400264 !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265 {
Dave Barachba868bb2016-08-08 09:51:21 -0400266 vlib_simple_counter_main_t *cm;
267
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
Dave Barachba868bb2016-08-08 09:51:21 -0400269 VNET_INTERFACE_COUNTER_TX_ERROR);
Damjan Marion586afd72017-04-05 19:18:20 +0200270 vlib_increment_simple_counter (cm, thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400271 rt->sw_if_index, n_buffers);
272 return vlib_error_drop_buffers (vm, node, from,
273 /* buffer stride */ 1,
274 n_buffers,
275 VNET_INTERFACE_OUTPUT_NEXT_DROP,
276 node->node_index,
277 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278 }
279
280 from_end = from + n_buffers;
281
282 /* Total byte count of all buffers. */
283 n_bytes = 0;
284 n_packets = 0;
285 last_sw_if_index = ~0;
286
287 while (from < from_end)
288 {
289 /* Get new next frame since previous incomplete frame may have less
Dave Barachba868bb2016-08-08 09:51:21 -0400290 than VNET_FRAME_SIZE vectors in it. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291 vlib_get_new_next_frame (vm, node, VNET_INTERFACE_OUTPUT_NEXT_TX,
292 to_tx, n_left_to_tx);
293
294 while (from + 4 <= from_end && n_left_to_tx >= 2)
295 {
296 u32 bi0, bi1;
Dave Barachba868bb2016-08-08 09:51:21 -0400297 vlib_buffer_t *b0, *b1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700298
299 /* Prefetch next iteration. */
300 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
301 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
302
303 bi0 = from[0];
304 bi1 = from[1];
305 to_tx[0] = bi0;
306 to_tx[1] = bi1;
307 from += 2;
308 to_tx += 2;
309 n_left_to_tx -= 2;
310
311 b0 = vlib_get_buffer (vm, bi0);
312 b1 = vlib_get_buffer (vm, bi1);
313
314 /* Be grumpy about zero length buffers for benefit of
315 driver tx function. */
316 ASSERT (b0->current_length > 0);
317 ASSERT (b1->current_length > 0);
318
Dave Barachba868bb2016-08-08 09:51:21 -0400319 if (PREDICT_FALSE
320 ((b0->flags | b1->flags) & VLIB_BUFFER_NEXT_PRESENT))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700321 {
322 u32 n_buffers, n_slow_bytes, i;
323
324 /* Undo. */
325 from -= 2;
326 to_tx -= 2;
327 n_left_to_tx += 2;
328
329 /* Do slow path two times. */
330 for (i = 0; i < 2; i++)
331 {
332 u32 bi = i ? bi1 : bi0;
Dave Barachba868bb2016-08-08 09:51:21 -0400333 vlib_buffer_t *b = i ? b1 : b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334
335 n_buffers = slow_path (vm, bi, b,
336 n_left_to_tx, to_tx, &n_slow_bytes);
337
338 /* Not enough room for single packet? */
339 if (n_buffers == 0)
340 goto put;
341
342 from += 1;
343 to_tx += n_buffers;
344 n_left_to_tx -= n_buffers;
Damjan Marion586afd72017-04-05 19:18:20 +0200345 incr_output_stats (vnm, thread_index, n_slow_bytes,
Dave Barachba868bb2016-08-08 09:51:21 -0400346 vnet_buffer (b)->sw_if_index[VLIB_TX],
347 &last_sw_if_index, &n_packets, &n_bytes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700348 }
Dave Barachba868bb2016-08-08 09:51:21 -0400349 }
350 else
351 {
Damjan Marion586afd72017-04-05 19:18:20 +0200352 incr_output_stats (vnm, thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400353 vlib_buffer_length_in_chain (vm, b0),
354 vnet_buffer (b0)->sw_if_index[VLIB_TX],
355 &last_sw_if_index, &n_packets, &n_bytes);
Damjan Marion586afd72017-04-05 19:18:20 +0200356 incr_output_stats (vnm, thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400357 vlib_buffer_length_in_chain (vm, b0),
358 vnet_buffer (b1)->sw_if_index[VLIB_TX],
359 &last_sw_if_index, &n_packets, &n_bytes);
360 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700361 }
362
363 while (from + 1 <= from_end && n_left_to_tx >= 1)
364 {
365 u32 bi0;
Dave Barachba868bb2016-08-08 09:51:21 -0400366 vlib_buffer_t *b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367
368 bi0 = from[0];
369 to_tx[0] = bi0;
370 from += 1;
371 to_tx += 1;
372 n_left_to_tx -= 1;
373
374 b0 = vlib_get_buffer (vm, bi0);
375
376 /* Be grumpy about zero length buffers for benefit of
377 driver tx function. */
378 ASSERT (b0->current_length > 0);
379
380 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_NEXT_PRESENT))
381 {
382 u32 n_buffers, n_slow_bytes;
383
384 /* Undo. */
385 from -= 1;
386 to_tx -= 1;
387 n_left_to_tx += 1;
388
389 n_buffers = slow_path (vm, bi0, b0,
390 n_left_to_tx, to_tx, &n_slow_bytes);
391
392 /* Not enough room for single packet? */
393 if (n_buffers == 0)
394 goto put;
395
396 from += 1;
397 to_tx += n_buffers;
398 n_left_to_tx -= n_buffers;
399 }
Damjan Marion586afd72017-04-05 19:18:20 +0200400 incr_output_stats (vnm, thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400401 vlib_buffer_length_in_chain (vm, b0),
402 vnet_buffer (b0)->sw_if_index[VLIB_TX],
403 &last_sw_if_index, &n_packets, &n_bytes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404 }
405
406 put:
Dave Barachba868bb2016-08-08 09:51:21 -0400407 vlib_put_next_frame (vm, node, VNET_INTERFACE_OUTPUT_NEXT_TX,
408 n_left_to_tx);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700409 }
410
411 /* Final update of interface stats. */
Damjan Marion586afd72017-04-05 19:18:20 +0200412 incr_output_stats (vnm, thread_index, 0, ~0, /* ~0 will flush stats */
Dave Barachba868bb2016-08-08 09:51:21 -0400413 &last_sw_if_index, &n_packets, &n_bytes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414
415 return n_buffers;
416}
417
Damjan Marion8b2247d2016-12-02 08:09:45 +0100418VLIB_NODE_FUNCTION_MULTIARCH_CLONE (vnet_interface_output_node_flatten);
419CLIB_MULTIARCH_SELECT_FN (vnet_interface_output_node_flatten);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100421uword
Damjan Marion8b2247d2016-12-02 08:09:45 +0100422vnet_interface_output_node (vlib_main_t * vm,
423 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424{
Dave Barachba868bb2016-08-08 09:51:21 -0400425 vnet_main_t *vnm = vnet_get_main ();
426 vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
427 vnet_sw_interface_t *si;
428 vnet_hw_interface_t *hi;
429 u32 n_left_to_tx, *from, *from_end, *to_tx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 u32 n_bytes, n_buffers, n_packets;
Damjan Marion363640d2017-03-06 11:53:10 +0100431 u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3;
Damjan Marion586afd72017-04-05 19:18:20 +0200432 u32 thread_index = vm->thread_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400433 vnet_interface_main_t *im = &vnm->interface_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434 u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX;
Damjan Marion152e21d2016-11-29 14:55:43 +0100435 u32 current_config_index = ~0;
436 u8 arc = im->output_feature_arc_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700437
438 n_buffers = frame->n_vectors;
439
440 if (node->flags & VLIB_NODE_FLAG_TRACE)
441 vnet_interface_output_trace (vm, node, frame, n_buffers);
442
443 from = vlib_frame_args (frame);
444
445 if (rt->is_deleted)
Dave Barachba868bb2016-08-08 09:51:21 -0400446 return vlib_error_drop_buffers (vm, node, from,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 /* buffer stride */ 1,
448 n_buffers,
449 VNET_INTERFACE_OUTPUT_NEXT_DROP,
450 node->node_index,
451 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED);
452
453 si = vnet_get_sw_interface (vnm, rt->sw_if_index);
454 hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
Steve Shin042a6212017-07-07 14:57:46 -0700455 if (!(si->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP |
456 VNET_SW_INTERFACE_FLAG_BOND_SLAVE)) ||
Dave Barachba868bb2016-08-08 09:51:21 -0400457 !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700458 {
Dave Barachba868bb2016-08-08 09:51:21 -0400459 vlib_simple_counter_main_t *cm;
460
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
Dave Barachba868bb2016-08-08 09:51:21 -0400462 VNET_INTERFACE_COUNTER_TX_ERROR);
Damjan Marion586afd72017-04-05 19:18:20 +0200463 vlib_increment_simple_counter (cm, thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400464 rt->sw_if_index, n_buffers);
465
466 return vlib_error_drop_buffers (vm, node, from,
467 /* buffer stride */ 1,
468 n_buffers,
469 VNET_INTERFACE_OUTPUT_NEXT_DROP,
470 node->node_index,
471 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472 }
473
474 from_end = from + n_buffers;
475
476 /* Total byte count of all buffers. */
477 n_bytes = 0;
478 n_packets = 0;
479
Damjan Marion152e21d2016-11-29 14:55:43 +0100480 /* interface-output feature arc handling */
481 if (PREDICT_FALSE (vnet_have_features (arc, rt->sw_if_index)))
482 {
483 vnet_feature_config_main_t *fcm;
484 fcm = vnet_feature_get_config_main (arc);
485 current_config_index = vnet_get_feature_config_index (arc,
486 rt->sw_if_index);
487 vnet_get_config_data (&fcm->config_main, &current_config_index,
488 &next_index, 0);
489 }
490
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 while (from < from_end)
492 {
493 /* Get new next frame since previous incomplete frame may have less
Dave Barachba868bb2016-08-08 09:51:21 -0400494 than VNET_FRAME_SIZE vectors in it. */
495 vlib_get_new_next_frame (vm, node, next_index, to_tx, n_left_to_tx);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496
Damjan Marion363640d2017-03-06 11:53:10 +0100497 while (from + 8 <= from_end && n_left_to_tx >= 4)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700498 {
Damjan Marion363640d2017-03-06 11:53:10 +0100499 u32 bi0, bi1, bi2, bi3;
500 vlib_buffer_t *b0, *b1, *b2, *b3;
501 u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502
503 /* Prefetch next iteration. */
Damjan Marion363640d2017-03-06 11:53:10 +0100504 vlib_prefetch_buffer_with_index (vm, from[4], LOAD);
505 vlib_prefetch_buffer_with_index (vm, from[5], LOAD);
506 vlib_prefetch_buffer_with_index (vm, from[6], LOAD);
507 vlib_prefetch_buffer_with_index (vm, from[7], LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700508
509 bi0 = from[0];
510 bi1 = from[1];
Damjan Marion363640d2017-03-06 11:53:10 +0100511 bi2 = from[2];
512 bi3 = from[3];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513 to_tx[0] = bi0;
514 to_tx[1] = bi1;
Damjan Marion363640d2017-03-06 11:53:10 +0100515 to_tx[2] = bi2;
516 to_tx[3] = bi3;
517 from += 4;
518 to_tx += 4;
519 n_left_to_tx -= 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700520
521 b0 = vlib_get_buffer (vm, bi0);
522 b1 = vlib_get_buffer (vm, bi1);
Damjan Marion363640d2017-03-06 11:53:10 +0100523 b2 = vlib_get_buffer (vm, bi2);
524 b3 = vlib_get_buffer (vm, bi3);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525
526 /* Be grumpy about zero length buffers for benefit of
527 driver tx function. */
528 ASSERT (b0->current_length > 0);
529 ASSERT (b1->current_length > 0);
Damjan Marion363640d2017-03-06 11:53:10 +0100530 ASSERT (b2->current_length > 0);
531 ASSERT (b3->current_length > 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532
Dave Barachba868bb2016-08-08 09:51:21 -0400533 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b0);
534 n_bytes_b1 = vlib_buffer_length_in_chain (vm, b1);
Damjan Marion363640d2017-03-06 11:53:10 +0100535 n_bytes_b2 = vlib_buffer_length_in_chain (vm, b2);
536 n_bytes_b3 = vlib_buffer_length_in_chain (vm, b3);
Dave Barachba868bb2016-08-08 09:51:21 -0400537 tx_swif0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
538 tx_swif1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
Damjan Marion363640d2017-03-06 11:53:10 +0100539 tx_swif2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
540 tx_swif3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700541
542 n_bytes += n_bytes_b0 + n_bytes_b1;
Damjan Marion363640d2017-03-06 11:53:10 +0100543 n_bytes += n_bytes_b2 + n_bytes_b3;
544 n_packets += 4;
Dave Barachba868bb2016-08-08 09:51:21 -0400545
Damjan Marion152e21d2016-11-29 14:55:43 +0100546 if (PREDICT_FALSE (current_config_index != ~0))
547 {
548 b0->feature_arc_index = arc;
549 b1->feature_arc_index = arc;
Damjan Marion363640d2017-03-06 11:53:10 +0100550 b2->feature_arc_index = arc;
551 b3->feature_arc_index = arc;
Damjan Marion152e21d2016-11-29 14:55:43 +0100552 b0->current_config_index = current_config_index;
553 b1->current_config_index = current_config_index;
Damjan Marion363640d2017-03-06 11:53:10 +0100554 b2->current_config_index = current_config_index;
555 b3->current_config_index = current_config_index;
Damjan Marion152e21d2016-11-29 14:55:43 +0100556 }
557
Damjan Marion363640d2017-03-06 11:53:10 +0100558 /* update vlan subif tx counts, if required */
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100559 if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -0400560 {
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100561 vlib_increment_combined_counter (im->combined_sw_if_counters +
562 VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200563 thread_index, tx_swif0, 1,
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100564 n_bytes_b0);
Dave Barachba868bb2016-08-08 09:51:21 -0400565 }
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100566
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100567 if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index))
568 {
569
570 vlib_increment_combined_counter (im->combined_sw_if_counters +
571 VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200572 thread_index, tx_swif1, 1,
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100573 n_bytes_b1);
574 }
Damjan Marion363640d2017-03-06 11:53:10 +0100575
576 if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index))
577 {
578
579 vlib_increment_combined_counter (im->combined_sw_if_counters +
580 VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200581 thread_index, tx_swif2, 1,
Damjan Marion363640d2017-03-06 11:53:10 +0100582 n_bytes_b2);
583 }
584 if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index))
585 {
586
587 vlib_increment_combined_counter (im->combined_sw_if_counters +
588 VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200589 thread_index, tx_swif3, 1,
Damjan Marion363640d2017-03-06 11:53:10 +0100590 n_bytes_b3);
591 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592 }
593
594 while (from + 1 <= from_end && n_left_to_tx >= 1)
595 {
596 u32 bi0;
Dave Barachba868bb2016-08-08 09:51:21 -0400597 vlib_buffer_t *b0;
598 u32 tx_swif0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599
600 bi0 = from[0];
601 to_tx[0] = bi0;
602 from += 1;
603 to_tx += 1;
604 n_left_to_tx -= 1;
605
606 b0 = vlib_get_buffer (vm, bi0);
607
608 /* Be grumpy about zero length buffers for benefit of
609 driver tx function. */
610 ASSERT (b0->current_length > 0);
611
Dave Barachba868bb2016-08-08 09:51:21 -0400612 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b0);
613 tx_swif0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614 n_bytes += n_bytes_b0;
615 n_packets += 1;
616
Damjan Marion152e21d2016-11-29 14:55:43 +0100617 if (PREDICT_FALSE (current_config_index != ~0))
618 {
619 b0->feature_arc_index = arc;
620 b0->current_config_index = current_config_index;
621 }
622
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100623 if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -0400624 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700625
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100626 vlib_increment_combined_counter (im->combined_sw_if_counters +
627 VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200628 thread_index, tx_swif0, 1,
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100629 n_bytes_b0);
Dave Barachba868bb2016-08-08 09:51:21 -0400630 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700631 }
632
Dave Barachba868bb2016-08-08 09:51:21 -0400633 vlib_put_next_frame (vm, node, next_index, n_left_to_tx);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700634 }
635
636 /* Update main interface stats. */
637 vlib_increment_combined_counter (im->combined_sw_if_counters
Dave Barachba868bb2016-08-08 09:51:21 -0400638 + VNET_INTERFACE_COUNTER_TX,
Damjan Marion586afd72017-04-05 19:18:20 +0200639 thread_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400640 rt->sw_if_index, n_packets, n_bytes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700641 return n_buffers;
642}
643
Damjan Marion8b2247d2016-12-02 08:09:45 +0100644VLIB_NODE_FUNCTION_MULTIARCH_CLONE (vnet_interface_output_node);
645CLIB_MULTIARCH_SELECT_FN (vnet_interface_output_node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700646
647/* Use buffer's sw_if_index[VNET_TX] to choose output interface. */
648static uword
649vnet_per_buffer_interface_output (vlib_main_t * vm,
650 vlib_node_runtime_t * node,
651 vlib_frame_t * frame)
652{
Dave Barachba868bb2016-08-08 09:51:21 -0400653 vnet_main_t *vnm = vnet_get_main ();
654 u32 n_left_to_next, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700655 u32 n_left_from, next_index;
656
657 n_left_from = frame->n_vectors;
658
659 from = vlib_frame_args (frame);
660 next_index = node->cached_next_index;
661
662 while (n_left_from > 0)
663 {
664 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
665
666 while (n_left_from >= 4 && n_left_to_next >= 2)
667 {
668 u32 bi0, bi1, next0, next1;
Dave Barachba868bb2016-08-08 09:51:21 -0400669 vlib_buffer_t *b0, *b1;
670 vnet_hw_interface_t *hi0, *hi1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671
672 /* Prefetch next iteration. */
673 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
674 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
675
676 bi0 = from[0];
677 bi1 = from[1];
678 to_next[0] = bi0;
679 to_next[1] = bi1;
680 from += 2;
681 to_next += 2;
682 n_left_to_next -= 2;
683 n_left_from -= 2;
684
685 b0 = vlib_get_buffer (vm, bi0);
686 b1 = vlib_get_buffer (vm, bi1);
687
Dave Barachba868bb2016-08-08 09:51:21 -0400688 hi0 =
689 vnet_get_sup_hw_interface (vnm,
690 vnet_buffer (b0)->sw_if_index
691 [VLIB_TX]);
692 hi1 =
693 vnet_get_sup_hw_interface (vnm,
694 vnet_buffer (b1)->sw_if_index
695 [VLIB_TX]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
697 next0 = hi0->hw_if_index;
698 next1 = hi1->hw_if_index;
699
Dave Barachba868bb2016-08-08 09:51:21 -0400700 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
701 n_left_to_next, bi0, bi1, next0,
702 next1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703 }
704
705 while (n_left_from > 0 && n_left_to_next > 0)
706 {
707 u32 bi0, next0;
Dave Barachba868bb2016-08-08 09:51:21 -0400708 vlib_buffer_t *b0;
709 vnet_hw_interface_t *hi0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710
711 bi0 = from[0];
712 to_next[0] = bi0;
713 from += 1;
714 to_next += 1;
715 n_left_to_next -= 1;
716 n_left_from -= 1;
717
718 b0 = vlib_get_buffer (vm, bi0);
719
Dave Barachba868bb2016-08-08 09:51:21 -0400720 hi0 =
721 vnet_get_sup_hw_interface (vnm,
722 vnet_buffer (b0)->sw_if_index
723 [VLIB_TX]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700724
725 next0 = hi0->hw_if_index;
726
Dave Barachba868bb2016-08-08 09:51:21 -0400727 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
728 n_left_to_next, bi0, next0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700729 }
730
731 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
732 }
733
734 return frame->n_vectors;
735}
736
737always_inline u32
738counter_index (vlib_main_t * vm, vlib_error_t e)
739{
Dave Barachba868bb2016-08-08 09:51:21 -0400740 vlib_node_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741 u32 ci, ni;
742
743 ni = vlib_error_get_node (e);
744 n = vlib_get_node (vm, ni);
745
746 ci = vlib_error_get_code (e);
747 ASSERT (ci < n->n_errors);
748
749 ci += n->error_heap_index;
750
751 return ci;
752}
753
Dave Barachba868bb2016-08-08 09:51:21 -0400754static u8 *
755format_vnet_error_trace (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700756{
Dave Barachba868bb2016-08-08 09:51:21 -0400757 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700758 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
Dave Barachba868bb2016-08-08 09:51:21 -0400759 vlib_error_t *e = va_arg (*va, vlib_error_t *);
760 vlib_node_t *error_node;
761 vlib_error_main_t *em = &vm->error_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762 u32 i;
763
764 error_node = vlib_get_node (vm, vlib_error_get_node (e[0]));
765 i = counter_index (vm, e[0]);
766 s = format (s, "%v: %s", error_node->name, em->error_strings_heap[i]);
767
768 return s;
769}
770
771static void
772trace_errors_with_buffers (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400773 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700774{
Dave Barachba868bb2016-08-08 09:51:21 -0400775 u32 n_left, *buffers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700776
777 buffers = vlib_frame_vector_args (frame);
778 n_left = frame->n_vectors;
Dave Barachba868bb2016-08-08 09:51:21 -0400779
Ed Warnickecb9cada2015-12-08 15:45:58 -0700780 while (n_left >= 4)
781 {
782 u32 bi0, bi1;
Dave Barachba868bb2016-08-08 09:51:21 -0400783 vlib_buffer_t *b0, *b1;
784 vlib_error_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700785
786 /* Prefetch next iteration. */
787 vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD);
788 vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD);
789
790 bi0 = buffers[0];
791 bi1 = buffers[1];
792
793 b0 = vlib_get_buffer (vm, bi0);
794 b1 = vlib_get_buffer (vm, bi1);
795
796 if (b0->flags & VLIB_BUFFER_IS_TRACED)
797 {
798 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
799 t0[0] = b0->error;
800 }
801 if (b1->flags & VLIB_BUFFER_IS_TRACED)
802 {
803 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
804 t1[0] = b1->error;
805 }
806 buffers += 2;
807 n_left -= 2;
808 }
809
810 while (n_left >= 1)
811 {
812 u32 bi0;
Dave Barachba868bb2016-08-08 09:51:21 -0400813 vlib_buffer_t *b0;
814 vlib_error_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700815
816 bi0 = buffers[0];
817
818 b0 = vlib_get_buffer (vm, bi0);
819
820 if (b0->flags & VLIB_BUFFER_IS_TRACED)
821 {
822 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
823 t0[0] = b0->error;
824 }
825 buffers += 1;
826 n_left -= 1;
827 }
828}
829
830static u8 *
831validate_error (vlib_main_t * vm, vlib_error_t * e, u32 index)
832{
833 uword node_index = vlib_error_get_node (e[0]);
834 uword code = vlib_error_get_code (e[0]);
Dave Barachba868bb2016-08-08 09:51:21 -0400835 vlib_node_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836
837 if (node_index >= vec_len (vm->node_main.nodes))
838 return format (0, "[%d], node index out of range 0x%x, error 0x%x",
839 index, node_index, e[0]);
840
841 n = vlib_get_node (vm, node_index);
842 if (code >= n->n_errors)
843 return format (0, "[%d], code %d out of range for node %v",
844 index, code, n->name);
845
846 return 0;
847}
848
849static u8 *
850validate_error_frame (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400851 vlib_node_runtime_t * node, vlib_frame_t * f)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700852{
Dave Barachba868bb2016-08-08 09:51:21 -0400853 u32 *buffers = vlib_frame_args (f);
854 vlib_buffer_t *b;
855 u8 *msg = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700856 uword i;
857
858 for (i = 0; i < f->n_vectors; i++)
859 {
860 b = vlib_get_buffer (vm, buffers[i]);
861 msg = validate_error (vm, &b->error, i);
862 if (msg)
863 return msg;
864 }
865
866 return msg;
867}
868
Dave Barachba868bb2016-08-08 09:51:21 -0400869typedef enum
870{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700871 VNET_ERROR_DISPOSITION_DROP,
872 VNET_ERROR_DISPOSITION_PUNT,
873 VNET_ERROR_N_DISPOSITION,
874} vnet_error_disposition_t;
875
876always_inline void
877do_packet (vlib_main_t * vm, vlib_error_t a)
878{
Dave Barachba868bb2016-08-08 09:51:21 -0400879 vlib_error_main_t *em = &vm->error_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700880 u32 i = counter_index (vm, a);
881 em->counters[i] += 1;
882 vlib_error_elog_count (vm, i, 1);
883}
Dave Barachba868bb2016-08-08 09:51:21 -0400884
Ed Warnickecb9cada2015-12-08 15:45:58 -0700885static_always_inline uword
886process_drop_punt (vlib_main_t * vm,
887 vlib_node_runtime_t * node,
Dave Barachba868bb2016-08-08 09:51:21 -0400888 vlib_frame_t * frame, vnet_error_disposition_t disposition)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700889{
Dave Barachba868bb2016-08-08 09:51:21 -0400890 vnet_main_t *vnm = vnet_get_main ();
891 vlib_error_main_t *em = &vm->error_main;
892 u32 *buffers, *first_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700893 vlib_error_t current_error;
894 u32 current_counter_index, n_errors_left;
895 u32 current_sw_if_index, n_errors_current_sw_if_index;
896 u64 current_counter;
Dave Barachba868bb2016-08-08 09:51:21 -0400897 vlib_simple_counter_main_t *cm;
Damjan Marion586afd72017-04-05 19:18:20 +0200898 u32 thread_index = vm->thread_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899
900 static vlib_error_t memory[VNET_ERROR_N_DISPOSITION];
901 static char memory_init[VNET_ERROR_N_DISPOSITION];
902
903 buffers = vlib_frame_args (frame);
904 first_buffer = buffers;
905
906 {
Dave Barachba868bb2016-08-08 09:51:21 -0400907 vlib_buffer_t *b = vlib_get_buffer (vm, first_buffer[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700908
Dave Barachba868bb2016-08-08 09:51:21 -0400909 if (!memory_init[disposition])
Ed Warnickecb9cada2015-12-08 15:45:58 -0700910 {
911 memory_init[disposition] = 1;
912 memory[disposition] = b->error;
913 }
914
915 current_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
916 n_errors_current_sw_if_index = 0;
917 }
918
919 current_error = memory[disposition];
920 current_counter_index = counter_index (vm, memory[disposition]);
921 current_counter = em->counters[current_counter_index];
922
923 if (node->flags & VLIB_NODE_FLAG_TRACE)
924 trace_errors_with_buffers (vm, node, frame);
Dave Barachba868bb2016-08-08 09:51:21 -0400925
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926 n_errors_left = frame->n_vectors;
927 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
928 (disposition == VNET_ERROR_DISPOSITION_PUNT
929 ? VNET_INTERFACE_COUNTER_PUNT
930 : VNET_INTERFACE_COUNTER_DROP));
931
932 while (n_errors_left >= 2)
933 {
Dave Barachba868bb2016-08-08 09:51:21 -0400934 vlib_buffer_t *b0, *b1;
935 vnet_sw_interface_t *sw_if0, *sw_if1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700936 vlib_error_t e0, e1;
937 u32 bi0, bi1;
938 u32 sw_if_index0, sw_if_index1;
939
940 bi0 = buffers[0];
941 bi1 = buffers[1];
942
943 buffers += 2;
944 n_errors_left -= 2;
945
946 b0 = vlib_get_buffer (vm, bi0);
947 b1 = vlib_get_buffer (vm, bi1);
948
949 e0 = b0->error;
950 e1 = b1->error;
951
952 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
953 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
954
955 /* Speculate that sw_if_index == sw_if_index[01]. */
956 n_errors_current_sw_if_index += 2;
957
958 /* Speculatively assume all 2 (node, code) pairs are equal
Dave Barachba868bb2016-08-08 09:51:21 -0400959 to current (node, code). */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960 current_counter += 2;
961
962 if (PREDICT_FALSE (e0 != current_error
963 || e1 != current_error
964 || sw_if_index0 != current_sw_if_index
965 || sw_if_index1 != current_sw_if_index))
966 {
967 current_counter -= 2;
968 n_errors_current_sw_if_index -= 2;
969
Damjan Marion586afd72017-04-05 19:18:20 +0200970 vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1);
971 vlib_increment_simple_counter (cm, thread_index, sw_if_index1, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700972
973 /* Increment super-interface drop/punt counters for
974 sub-interfaces. */
975 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0);
976 vlib_increment_simple_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200977 (cm, thread_index, sw_if0->sup_sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400978 sw_if0->sup_sw_if_index != sw_if_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700979
980 sw_if1 = vnet_get_sw_interface (vnm, sw_if_index1);
981 vlib_increment_simple_counter
Damjan Marion586afd72017-04-05 19:18:20 +0200982 (cm, thread_index, sw_if1->sup_sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400983 sw_if1->sup_sw_if_index != sw_if_index1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700984
985 em->counters[current_counter_index] = current_counter;
986 do_packet (vm, e0);
987 do_packet (vm, e1);
988
989 /* For 2 repeated errors, change current error. */
990 if (e0 == e1 && e1 != current_error)
991 {
992 current_error = e0;
993 current_counter_index = counter_index (vm, e0);
994 }
995 current_counter = em->counters[current_counter_index];
996 }
997 }
998
999 while (n_errors_left >= 1)
1000 {
Dave Barachba868bb2016-08-08 09:51:21 -04001001 vlib_buffer_t *b0;
1002 vnet_sw_interface_t *sw_if0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003 vlib_error_t e0;
1004 u32 bi0, sw_if_index0;
1005
1006 bi0 = buffers[0];
1007
1008 buffers += 1;
1009 n_errors_left -= 1;
1010 current_counter += 1;
1011
1012 b0 = vlib_get_buffer (vm, bi0);
1013 e0 = b0->error;
1014
1015 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1016
1017 /* Increment drop/punt counters. */
Damjan Marion586afd72017-04-05 19:18:20 +02001018 vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001019
1020 /* Increment super-interface drop/punt counters for sub-interfaces. */
1021 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0);
Damjan Marion586afd72017-04-05 19:18:20 +02001022 vlib_increment_simple_counter (cm, thread_index,
1023 sw_if0->sup_sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001024 sw_if0->sup_sw_if_index != sw_if_index0);
1025
1026 if (PREDICT_FALSE (e0 != current_error))
1027 {
1028 current_counter -= 1;
1029
1030 vlib_error_elog_count (vm, current_counter_index,
1031 (current_counter
1032 - em->counters[current_counter_index]));
Dave Barachba868bb2016-08-08 09:51:21 -04001033
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034 em->counters[current_counter_index] = current_counter;
1035
1036 do_packet (vm, e0);
1037 current_error = e0;
1038 current_counter_index = counter_index (vm, e0);
1039 current_counter = em->counters[current_counter_index];
1040 }
1041 }
1042
1043 if (n_errors_current_sw_if_index > 0)
1044 {
Dave Barachba868bb2016-08-08 09:51:21 -04001045 vnet_sw_interface_t *si;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001046
Damjan Marion586afd72017-04-05 19:18:20 +02001047 vlib_increment_simple_counter (cm, thread_index, current_sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001048 n_errors_current_sw_if_index);
1049
1050 si = vnet_get_sw_interface (vnm, current_sw_if_index);
1051 if (si->sup_sw_if_index != current_sw_if_index)
Damjan Marion586afd72017-04-05 19:18:20 +02001052 vlib_increment_simple_counter (cm, thread_index, si->sup_sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -04001053 n_errors_current_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001054 }
1055
1056 vlib_error_elog_count (vm, current_counter_index,
1057 (current_counter
1058 - em->counters[current_counter_index]));
1059
1060 /* Return cached counter. */
1061 em->counters[current_counter_index] = current_counter;
1062
1063 /* Save memory for next iteration. */
1064 memory[disposition] = current_error;
1065
Dave Barachba868bb2016-08-08 09:51:21 -04001066 if (disposition == VNET_ERROR_DISPOSITION_DROP || !vm->os_punt_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001067 {
Dave Barachba868bb2016-08-08 09:51:21 -04001068 vlib_buffer_free (vm, first_buffer, frame->n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069
1070 /* If there is no punt function, free the frame as well. */
Dave Barachba868bb2016-08-08 09:51:21 -04001071 if (disposition == VNET_ERROR_DISPOSITION_PUNT && !vm->os_punt_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072 vlib_frame_free (vm, node, frame);
1073 }
1074 else
1075 vm->os_punt_frame (vm, node, frame);
1076
1077 return frame->n_vectors;
1078}
1079
Dave Barachba868bb2016-08-08 09:51:21 -04001080static inline void
1081pcap_drop_trace (vlib_main_t * vm,
1082 vnet_interface_main_t * im, vlib_frame_t * f)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001083{
Dave Barachba868bb2016-08-08 09:51:21 -04001084 u32 *from;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001085 u32 n_left = f->n_vectors;
Dave Barachba868bb2016-08-08 09:51:21 -04001086 vlib_buffer_t *b0, *p1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001087 u32 bi0;
1088 i16 save_current_data;
1089 u16 save_current_length;
1090
1091 from = vlib_frame_vector_args (f);
1092
1093 while (n_left > 0)
1094 {
1095 if (PREDICT_TRUE (n_left > 1))
Dave Barachba868bb2016-08-08 09:51:21 -04001096 {
1097 p1 = vlib_get_buffer (vm, from[1]);
1098 vlib_prefetch_buffer_header (p1, LOAD);
1099 }
1100
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101 bi0 = from[0];
1102 b0 = vlib_get_buffer (vm, bi0);
1103 from++;
1104 n_left--;
Dave Barachba868bb2016-08-08 09:51:21 -04001105
Ed Warnickecb9cada2015-12-08 15:45:58 -07001106 /* See if we're pointedly ignoring this specific error */
Dave Barachba868bb2016-08-08 09:51:21 -04001107 if (im->pcap_drop_filter_hash
1108 && hash_get (im->pcap_drop_filter_hash, b0->error))
1109 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001110
1111 /* Trace all drops, or drops received on a specific interface */
1112 if (im->pcap_sw_if_index == 0 ||
Dave Barachba868bb2016-08-08 09:51:21 -04001113 im->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX])
1114 {
1115 save_current_data = b0->current_data;
1116 save_current_length = b0->current_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117
Dave Barachba868bb2016-08-08 09:51:21 -04001118 /*
1119 * Typically, we'll need to rewind the buffer
1120 */
1121 if (b0->current_data > 0)
1122 vlib_buffer_advance (b0, (word) - b0->current_data);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123
Dave Barachba868bb2016-08-08 09:51:21 -04001124 pcap_add_buffer (&im->pcap_main, vm, bi0, 512);
1125
1126 b0->current_data = save_current_data;
1127 b0->current_length = save_current_length;
1128 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129 }
1130}
1131
Dave Barachba868bb2016-08-08 09:51:21 -04001132void
1133vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134{
Dave Barachba868bb2016-08-08 09:51:21 -04001135 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001136
1137 if (im->pcap_drop_filter_hash == 0)
Dave Barachba868bb2016-08-08 09:51:21 -04001138 im->pcap_drop_filter_hash = hash_create (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001139
1140 if (is_add)
1141 hash_set (im->pcap_drop_filter_hash, error_index, 1);
1142 else
1143 hash_unset (im->pcap_drop_filter_hash, error_index);
1144}
1145
1146static uword
1147process_drop (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001148 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149{
Dave Barachba868bb2016-08-08 09:51:21 -04001150 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001151
1152 if (PREDICT_FALSE (im->drop_pcap_enable))
1153 pcap_drop_trace (vm, im, frame);
1154
1155 return process_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP);
1156}
1157
1158static uword
1159process_punt (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001160 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001161{
1162 return process_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT);
1163}
1164
Dave Barachba868bb2016-08-08 09:51:21 -04001165/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001166VLIB_REGISTER_NODE (drop_buffers,static) = {
1167 .function = process_drop,
1168 .name = "error-drop",
1169 .flags = VLIB_NODE_FLAG_IS_DROP,
1170 .vector_size = sizeof (u32),
1171 .format_trace = format_vnet_error_trace,
1172 .validate_frame = validate_error_frame,
1173};
Dave Barachba868bb2016-08-08 09:51:21 -04001174/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001175
Dave Barachba868bb2016-08-08 09:51:21 -04001176VLIB_NODE_FUNCTION_MULTIARCH (drop_buffers, process_drop);
Damjan Marion1c80e832016-05-11 23:07:18 +02001177
Dave Barachba868bb2016-08-08 09:51:21 -04001178/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001179VLIB_REGISTER_NODE (punt_buffers,static) = {
1180 .function = process_punt,
1181 .flags = (VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH
1182 | VLIB_NODE_FLAG_IS_PUNT),
1183 .name = "error-punt",
1184 .vector_size = sizeof (u32),
1185 .format_trace = format_vnet_error_trace,
1186 .validate_frame = validate_error_frame,
1187};
Dave Barachba868bb2016-08-08 09:51:21 -04001188/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001189
Dave Barachba868bb2016-08-08 09:51:21 -04001190VLIB_NODE_FUNCTION_MULTIARCH (punt_buffers, process_punt);
Damjan Marion1c80e832016-05-11 23:07:18 +02001191
Dave Barachba868bb2016-08-08 09:51:21 -04001192/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001193VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node,static) = {
1194 .function = vnet_per_buffer_interface_output,
1195 .name = "interface-output",
1196 .vector_size = sizeof (u32),
1197};
Dave Barachba868bb2016-08-08 09:51:21 -04001198/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001199
Dave Barachba868bb2016-08-08 09:51:21 -04001200VLIB_NODE_FUNCTION_MULTIARCH (vnet_per_buffer_interface_output_node,
1201 vnet_per_buffer_interface_output);
Damjan Marion1c80e832016-05-11 23:07:18 +02001202
Damjan Marion152e21d2016-11-29 14:55:43 +01001203static uword
1204interface_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1205 vlib_frame_t * from_frame)
1206{
1207 vnet_main_t *vnm = vnet_get_main ();
1208 u32 last_sw_if_index = ~0;
1209 vlib_frame_t *to_frame = 0;
1210 vnet_hw_interface_t *hw = 0;
1211 u32 *from, *to_next = 0;
1212 u32 n_left_from;
1213
1214 from = vlib_frame_vector_args (from_frame);
1215 n_left_from = from_frame->n_vectors;
1216 while (n_left_from > 0)
1217 {
1218 u32 bi0;
1219 vlib_buffer_t *b0;
1220 u32 sw_if_index0;
1221
1222 bi0 = from[0];
1223 from++;
1224 n_left_from--;
1225 b0 = vlib_get_buffer (vm, bi0);
1226 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
1227
1228 if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0))
1229 {
1230 if (to_frame)
1231 {
1232 hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index);
1233 vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1234 }
1235 last_sw_if_index = sw_if_index0;
1236 hw = vnet_get_sup_hw_interface (vnm, sw_if_index0);
1237 to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index);
1238 to_next = vlib_frame_vector_args (to_frame);
1239 }
1240
1241 to_next[0] = bi0;
1242 to_next++;
1243 to_frame->n_vectors++;
1244 }
1245 vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1246 return from_frame->n_vectors;
1247}
1248
1249/* *INDENT-OFF* */
1250VLIB_REGISTER_NODE (interface_tx, static) = {
1251 .function = interface_tx_node_fn,
1252 .name = "interface-tx",
1253 .vector_size = sizeof (u32),
1254 .n_next_nodes = 1,
1255 .next_nodes = {
1256 [0] = "error-drop",
1257 },
1258};
1259
1260VNET_FEATURE_ARC_INIT (interface_output, static) =
1261{
1262 .arc_name = "interface-output",
1263 .start_nodes = VNET_FEATURES (0),
1264 .arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index,
1265};
1266
Pavel Kotucek3a2a1c42016-12-06 10:10:10 +01001267VNET_FEATURE_INIT (span_tx, static) = {
1268 .arc_name = "interface-output",
1269 .node_name = "span-output",
1270 .runs_before = VNET_FEATURES ("interface-tx"),
1271};
1272
Damjan Marion152e21d2016-11-29 14:55:43 +01001273VNET_FEATURE_INIT (interface_tx, static) = {
1274 .arc_name = "interface-output",
1275 .node_name = "interface-tx",
1276 .runs_before = 0,
1277};
1278/* *INDENT-ON* */
1279
Ed Warnickecb9cada2015-12-08 15:45:58 -07001280clib_error_t *
1281vnet_per_buffer_interface_output_hw_interface_add_del (vnet_main_t * vnm,
1282 u32 hw_if_index,
1283 u32 is_create)
1284{
Dave Barachba868bb2016-08-08 09:51:21 -04001285 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001286 u32 next_index;
1287
1288 next_index = vlib_node_add_next_with_slot
1289 (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
1290 hi->output_node_index,
1291 /* next_index */ hw_if_index);
1292
1293 ASSERT (next_index == hw_if_index);
1294
1295 return 0;
1296}
1297
Dave Barachba868bb2016-08-08 09:51:21 -04001298VNET_HW_INTERFACE_ADD_DEL_FUNCTION
1299 (vnet_per_buffer_interface_output_hw_interface_add_del);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001300
1301static clib_error_t *
1302pcap_drop_trace_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001303 unformat_input_t * input,
1304 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001305{
Dave Barachba868bb2016-08-08 09:51:21 -04001306 vnet_main_t *vnm = vnet_get_main ();
1307 vnet_interface_main_t *im = &vnm->interface_main;
1308 u8 *filename;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001309 u32 max;
1310 int matched = 0;
Dave Barachba868bb2016-08-08 09:51:21 -04001311 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001312
Dave Barachba868bb2016-08-08 09:51:21 -04001313 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001314 {
1315 if (unformat (input, "on"))
Dave Barachba868bb2016-08-08 09:51:21 -04001316 {
1317 if (im->drop_pcap_enable == 0)
1318 {
1319 if (im->pcap_filename == 0)
1320 im->pcap_filename = format (0, "/tmp/drop.pcap%c", 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001321
Dave Barachba868bb2016-08-08 09:51:21 -04001322 memset (&im->pcap_main, 0, sizeof (im->pcap_main));
1323 im->pcap_main.file_name = (char *) im->pcap_filename;
1324 im->pcap_main.n_packets_to_capture = 100;
1325 if (im->pcap_pkts_to_capture)
1326 im->pcap_main.n_packets_to_capture = im->pcap_pkts_to_capture;
1327
1328 im->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
1329 im->drop_pcap_enable = 1;
1330 matched = 1;
1331 vlib_cli_output (vm, "pcap drop capture on...");
1332 }
1333 else
1334 {
1335 vlib_cli_output (vm, "pcap drop capture already on...");
1336 }
1337 matched = 1;
1338 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001339 else if (unformat (input, "off"))
Dave Barachba868bb2016-08-08 09:51:21 -04001340 {
1341 matched = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001342
Dave Barachba868bb2016-08-08 09:51:21 -04001343 if (im->drop_pcap_enable)
1344 {
1345 vlib_cli_output (vm, "captured %d pkts...",
1346 im->pcap_main.n_packets_captured);
1347 if (im->pcap_main.n_packets_captured)
1348 {
1349 im->pcap_main.n_packets_to_capture =
1350 im->pcap_main.n_packets_captured;
1351 error = pcap_write (&im->pcap_main);
1352 if (error)
1353 clib_error_report (error);
1354 else
1355 vlib_cli_output (vm, "saved to %s...", im->pcap_filename);
1356 }
1357 }
1358 else
1359 {
1360 vlib_cli_output (vm, "pcap drop capture already off...");
1361 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001362
Dave Barachba868bb2016-08-08 09:51:21 -04001363 im->drop_pcap_enable = 0;
1364 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001365 else if (unformat (input, "max %d", &max))
Dave Barachba868bb2016-08-08 09:51:21 -04001366 {
1367 im->pcap_pkts_to_capture = max;
1368 matched = 1;
1369 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001370
Dave Barachba868bb2016-08-08 09:51:21 -04001371 else if (unformat (input, "intfc %U",
1372 unformat_vnet_sw_interface, vnm,
1373 &im->pcap_sw_if_index))
1374 matched = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001375 else if (unformat (input, "intfc any"))
Dave Barachba868bb2016-08-08 09:51:21 -04001376 {
1377 im->pcap_sw_if_index = 0;
1378 matched = 1;
1379 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001380 else if (unformat (input, "file %s", &filename))
Dave Barachba868bb2016-08-08 09:51:21 -04001381 {
1382 u8 *chroot_filename;
1383 /* Brain-police user path input */
1384 if (strstr ((char *) filename, "..")
1385 || index ((char *) filename, '/'))
1386 {
1387 vlib_cli_output (vm, "illegal characters in filename '%s'",
1388 filename);
1389 continue;
1390 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001391
Dave Barachba868bb2016-08-08 09:51:21 -04001392 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1393 vec_free (filename);
1394
1395 if (im->pcap_filename)
1396 vec_free (im->pcap_filename);
Dave Barachba868bb2016-08-08 09:51:21 -04001397 im->pcap_filename = chroot_filename;
jerryian361abef2017-04-10 18:48:07 +08001398 im->pcap_main.file_name = (char *) im->pcap_filename;
Dave Barachba868bb2016-08-08 09:51:21 -04001399 matched = 1;
1400 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001401 else if (unformat (input, "status"))
Dave Barachba868bb2016-08-08 09:51:21 -04001402 {
1403 if (im->drop_pcap_enable == 0)
1404 {
1405 vlib_cli_output (vm, "pcap drop capture is off...");
1406 continue;
1407 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001408
Dave Barachba868bb2016-08-08 09:51:21 -04001409 vlib_cli_output (vm, "pcap drop capture: %d of %d pkts...",
1410 im->pcap_main.n_packets_captured,
1411 im->pcap_main.n_packets_to_capture);
1412 matched = 1;
1413 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001414
1415 else
Dave Barachba868bb2016-08-08 09:51:21 -04001416 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001417 }
1418
1419 if (matched == 0)
Dave Barachba868bb2016-08-08 09:51:21 -04001420 return clib_error_return (0, "unknown input `%U'",
1421 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001422
1423 return 0;
1424}
1425
Dave Barachba868bb2016-08-08 09:51:21 -04001426/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001427VLIB_CLI_COMMAND (pcap_trace_command, static) = {
Dave Barachba868bb2016-08-08 09:51:21 -04001428 .path = "pcap drop trace",
1429 .short_help =
1430 "pcap drop trace on off max <nn> intfc <intfc> file <name> status",
1431 .function = pcap_drop_trace_command_fn,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432};
Dave Barachba868bb2016-08-08 09:51:21 -04001433/* *INDENT-ON* */
1434
1435/*
1436 * fd.io coding-style-patch-verification: ON
1437 *
1438 * Local Variables:
1439 * eval: (c-set-style "gnu")
1440 * End:
1441 */