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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * interface_output.c: interface output node
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
40 #include <vnet/vnet.h>
41 #include <vnet/gso/gso.h>
42 #include <vnet/ip/icmp46_packet.h>
43 #include <vnet/ip/ip4.h>
44 #include <vnet/ip/ip6.h>
45 #include <vnet/udp/udp_packet.h>
46 #include <vnet/feature/feature.h>
47 #include <vnet/classify/trace_classify.h>
53 u8 data[128 - 2 * sizeof (u32)];
55 interface_output_trace_t;
57 #ifndef CLIB_MARCH_VARIANT
59 format_vnet_interface_output_trace (u8 * s, va_list * va)
61 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
62 vlib_node_t *node = va_arg (*va, vlib_node_t *);
63 interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *);
64 vnet_main_t *vnm = vnet_get_main ();
65 vnet_sw_interface_t *si;
68 if (t->sw_if_index != (u32) ~ 0)
70 indent = format_get_indent (s);
72 if (pool_is_free_index
73 (vnm->interface_main.sw_interfaces, t->sw_if_index))
75 /* the interface may have been deleted by the time the trace is printed */
76 s = format (s, "sw_if_index: %d ", t->sw_if_index);
80 si = vnet_get_sw_interface (vnm, t->sw_if_index);
82 format (s, "%U ", format_vnet_sw_interface_name, vnm, si,
86 format (s, "\n%U%U", format_white_space, indent,
87 node->format_buffer ? node->format_buffer : format_hex_bytes,
88 t->data, sizeof (t->data));
94 vnet_interface_output_trace (vlib_main_t * vm,
95 vlib_node_runtime_t * node,
96 vlib_frame_t * frame, uword n_buffers)
101 from = vlib_frame_vector_args (frame);
106 vlib_buffer_t *b0, *b1;
107 interface_output_trace_t *t0, *t1;
109 /* Prefetch next iteration. */
110 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
111 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
116 b0 = vlib_get_buffer (vm, bi0);
117 b1 = vlib_get_buffer (vm, bi1);
119 if (b0->flags & VLIB_BUFFER_IS_TRACED)
121 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
122 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
123 t0->flags = b0->flags;
124 clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0),
127 if (b1->flags & VLIB_BUFFER_IS_TRACED)
129 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
130 t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX];
131 t1->flags = b1->flags;
132 clib_memcpy_fast (t1->data, vlib_buffer_get_current (b1),
143 interface_output_trace_t *t0;
147 b0 = vlib_get_buffer (vm, bi0);
149 if (b0->flags & VLIB_BUFFER_IS_TRACED)
151 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
152 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
153 t0->flags = b0->flags;
154 clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0),
162 static_always_inline void
163 calc_checksums (vlib_main_t * vm, vlib_buffer_t * b)
167 gso_header_offset_t gho = { 0 };
169 int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0;
170 int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0;
172 ASSERT (!(is_ip4 && is_ip6));
174 gho = vnet_gso_header_offset_parser (b, is_ip6);
175 th = (tcp_header_t *) (vlib_buffer_get_current (b) + gho.l4_hdr_offset);
176 uh = (udp_header_t *) (vlib_buffer_get_current (b) + gho.l4_hdr_offset);
183 (ip4_header_t *) (vlib_buffer_get_current (b) + gho.l3_hdr_offset);
184 if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
185 ip4->checksum = ip4_header_checksum (ip4);
186 if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
189 th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
191 else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
194 uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
203 (ip6_header_t *) (vlib_buffer_get_current (b) + gho.l3_hdr_offset);
204 if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
208 ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
210 else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
214 ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
217 b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
218 b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
219 b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
222 static_always_inline uword
223 vnet_interface_output_node_inline (vlib_main_t * vm,
224 vlib_node_runtime_t * node,
225 vlib_frame_t * frame,
227 vnet_hw_interface_t * hi,
230 vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
231 vnet_sw_interface_t *si;
232 u32 n_left_to_tx, *from, *from_end, *to_tx;
233 u32 n_bytes, n_buffers, n_packets;
234 u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3;
235 u32 thread_index = vm->thread_index;
236 vnet_interface_main_t *im = &vnm->interface_main;
237 u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX;
238 u32 current_config_index = ~0;
239 u8 arc = im->output_feature_arc_index;
240 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
242 n_buffers = frame->n_vectors;
244 if (node->flags & VLIB_NODE_FLAG_TRACE)
245 vnet_interface_output_trace (vm, node, frame, n_buffers);
247 from = vlib_frame_vector_args (frame);
248 vlib_get_buffers (vm, from, b, n_buffers);
251 return vlib_error_drop_buffers (vm, node, from,
252 /* buffer stride */ 1,
254 VNET_INTERFACE_OUTPUT_NEXT_DROP,
256 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED);
258 si = vnet_get_sw_interface (vnm, rt->sw_if_index);
259 hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
260 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ||
261 !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
263 vlib_simple_counter_main_t *cm;
265 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
266 VNET_INTERFACE_COUNTER_TX_ERROR);
267 vlib_increment_simple_counter (cm, thread_index,
268 rt->sw_if_index, n_buffers);
270 return vlib_error_drop_buffers (vm, node, from,
271 /* buffer stride */ 1,
273 VNET_INTERFACE_OUTPUT_NEXT_DROP,
275 VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN);
278 from_end = from + n_buffers;
280 /* Total byte count of all buffers. */
284 /* interface-output feature arc handling */
285 if (PREDICT_FALSE (vnet_have_features (arc, rt->sw_if_index)))
287 vnet_feature_config_main_t *fcm;
288 fcm = vnet_feature_get_config_main (arc);
289 current_config_index = vnet_get_feature_config_index (arc,
291 vnet_get_config_data (&fcm->config_main, ¤t_config_index,
295 while (from < from_end)
297 /* Get new next frame since previous incomplete frame may have less
298 than VNET_FRAME_SIZE vectors in it. */
299 vlib_get_new_next_frame (vm, node, next_index, to_tx, n_left_to_tx);
301 while (from + 8 <= from_end && n_left_to_tx >= 4)
303 u32 bi0, bi1, bi2, bi3;
304 u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3;
307 /* Prefetch next iteration. */
308 vlib_prefetch_buffer_header (b[4], LOAD);
309 vlib_prefetch_buffer_header (b[5], LOAD);
310 vlib_prefetch_buffer_header (b[6], LOAD);
311 vlib_prefetch_buffer_header (b[7], LOAD);
322 or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags;
328 /* Be grumpy about zero length buffers for benefit of
329 driver tx function. */
330 ASSERT (b[0]->current_length > 0);
331 ASSERT (b[1]->current_length > 0);
332 ASSERT (b[2]->current_length > 0);
333 ASSERT (b[3]->current_length > 0);
335 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
336 n_bytes_b1 = vlib_buffer_length_in_chain (vm, b[1]);
337 n_bytes_b2 = vlib_buffer_length_in_chain (vm, b[2]);
338 n_bytes_b3 = vlib_buffer_length_in_chain (vm, b[3]);
339 tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
340 tx_swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
341 tx_swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
342 tx_swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
344 n_bytes += n_bytes_b0 + n_bytes_b1;
345 n_bytes += n_bytes_b2 + n_bytes_b3;
348 if (PREDICT_FALSE (current_config_index != ~0))
350 vnet_buffer (b[0])->feature_arc_index = arc;
351 vnet_buffer (b[1])->feature_arc_index = arc;
352 vnet_buffer (b[2])->feature_arc_index = arc;
353 vnet_buffer (b[3])->feature_arc_index = arc;
354 b[0]->current_config_index = current_config_index;
355 b[1]->current_config_index = current_config_index;
356 b[2]->current_config_index = current_config_index;
357 b[3]->current_config_index = current_config_index;
360 /* update vlan subif tx counts, if required */
361 if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
363 vlib_increment_combined_counter (im->combined_sw_if_counters +
364 VNET_INTERFACE_COUNTER_TX,
365 thread_index, tx_swif0, 1,
369 if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index))
372 vlib_increment_combined_counter (im->combined_sw_if_counters +
373 VNET_INTERFACE_COUNTER_TX,
374 thread_index, tx_swif1, 1,
378 if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index))
381 vlib_increment_combined_counter (im->combined_sw_if_counters +
382 VNET_INTERFACE_COUNTER_TX,
383 thread_index, tx_swif2, 1,
386 if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index))
389 vlib_increment_combined_counter (im->combined_sw_if_counters +
390 VNET_INTERFACE_COUNTER_TX,
391 thread_index, tx_swif3, 1,
398 (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
399 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM |
400 VNET_BUFFER_F_OFFLOAD_IP_CKSUM))
402 calc_checksums (vm, b[0]);
403 calc_checksums (vm, b[1]);
404 calc_checksums (vm, b[2]);
405 calc_checksums (vm, b[3]);
412 while (from + 1 <= from_end && n_left_to_tx >= 1)
423 /* Be grumpy about zero length buffers for benefit of
424 driver tx function. */
425 ASSERT (b[0]->current_length > 0);
427 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
428 tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
429 n_bytes += n_bytes_b0;
432 if (PREDICT_FALSE (current_config_index != ~0))
434 vnet_buffer (b[0])->feature_arc_index = arc;
435 b[0]->current_config_index = current_config_index;
438 if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
441 vlib_increment_combined_counter (im->combined_sw_if_counters +
442 VNET_INTERFACE_COUNTER_TX,
443 thread_index, tx_swif0, 1,
450 (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
451 VNET_BUFFER_F_OFFLOAD_UDP_CKSUM |
452 VNET_BUFFER_F_OFFLOAD_IP_CKSUM))
453 calc_checksums (vm, b[0]);
458 vlib_put_next_frame (vm, node, next_index, n_left_to_tx);
461 /* Update main interface stats. */
462 vlib_increment_combined_counter (im->combined_sw_if_counters
463 + VNET_INTERFACE_COUNTER_TX,
465 rt->sw_if_index, n_packets, n_bytes);
468 #endif /* CLIB_MARCH_VARIANT */
470 static_always_inline void vnet_interface_pcap_tx_trace
471 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame,
472 int sw_if_index_from_buffer)
474 u32 n_left_from, *from;
476 vnet_pcap_t *pp = &vlib_global_main.pcap;
478 if (PREDICT_TRUE (pp->pcap_tx_enable == 0))
481 if (sw_if_index_from_buffer == 0)
483 vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
484 sw_if_index = rt->sw_if_index;
489 n_left_from = frame->n_vectors;
490 from = vlib_frame_vector_args (frame);
492 while (n_left_from > 0)
494 int classify_filter_result;
496 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
500 if (pp->filter_classify_table_index != ~0)
502 classify_filter_result =
503 vnet_is_packet_traced_inline
504 (b0, pp->filter_classify_table_index, 0 /* full classify */ );
505 if (classify_filter_result)
506 pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
510 if (sw_if_index_from_buffer)
511 sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
513 if (pp->pcap_sw_if_index == 0 || pp->pcap_sw_if_index == sw_if_index)
515 vnet_main_t *vnm = vnet_get_main ();
516 vnet_hw_interface_t *hi =
517 vnet_get_sup_hw_interface (vnm, sw_if_index);
518 /* Capture pkt if not filtered, or if filter hits */
519 if (hi->trace_classify_table_index == ~0 ||
520 vnet_is_packet_traced_inline
521 (b0, hi->trace_classify_table_index, 0 /* full classify */ ))
522 pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
527 #ifndef CLIB_MARCH_VARIANT
530 vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node,
531 vlib_frame_t * frame)
533 vnet_main_t *vnm = vnet_get_main ();
534 vnet_hw_interface_t *hi;
535 vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
536 hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
538 vnet_interface_pcap_tx_trace (vm, node, frame,
539 0 /* sw_if_index_from_buffer */ );
541 if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD)
542 return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
543 /* do_tx_offloads */ 0);
545 return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
546 /* do_tx_offloads */ 1);
548 #endif /* CLIB_MARCH_VARIANT */
550 /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */
551 VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm,
552 vlib_node_runtime_t *
554 vlib_frame_t * frame)
556 vnet_main_t *vnm = vnet_get_main ();
557 u32 n_left_to_next, *from, *to_next;
558 u32 n_left_from, next_index;
560 vnet_interface_pcap_tx_trace (vm, node, frame,
561 1 /* sw_if_index_from_buffer */ );
563 n_left_from = frame->n_vectors;
565 from = vlib_frame_vector_args (frame);
566 next_index = node->cached_next_index;
568 while (n_left_from > 0)
570 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
572 while (n_left_from >= 4 && n_left_to_next >= 2)
574 u32 bi0, bi1, next0, next1;
575 vlib_buffer_t *b0, *b1;
576 vnet_hw_interface_t *hi0, *hi1;
578 /* Prefetch next iteration. */
579 vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
580 vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
591 b0 = vlib_get_buffer (vm, bi0);
592 b1 = vlib_get_buffer (vm, bi1);
595 vnet_get_sup_hw_interface (vnm,
596 vnet_buffer (b0)->sw_if_index
599 vnet_get_sup_hw_interface (vnm,
600 vnet_buffer (b1)->sw_if_index
603 next0 = hi0->output_node_next_index;
604 next1 = hi1->output_node_next_index;
606 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
607 n_left_to_next, bi0, bi1, next0,
611 while (n_left_from > 0 && n_left_to_next > 0)
615 vnet_hw_interface_t *hi0;
624 b0 = vlib_get_buffer (vm, bi0);
627 vnet_get_sup_hw_interface (vnm,
628 vnet_buffer (b0)->sw_if_index
631 next0 = hi0->output_node_next_index;
633 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
634 n_left_to_next, bi0, next0);
637 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
640 return frame->n_vectors;
643 typedef struct vnet_error_trace_t_
646 } vnet_error_trace_t;
650 format_vnet_error_trace (u8 * s, va_list * va)
652 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
653 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
654 vnet_error_trace_t *t = va_arg (*va, vnet_error_trace_t *);
656 s = format (s, "rx:%U", format_vnet_sw_if_index_name,
657 vnet_get_main (), t->sw_if_index);
663 interface_trace_buffers (vlib_main_t * vm,
664 vlib_node_runtime_t * node, vlib_frame_t * frame)
666 u32 n_left, *buffers;
668 buffers = vlib_frame_vector_args (frame);
669 n_left = frame->n_vectors;
674 vlib_buffer_t *b0, *b1;
675 vnet_error_trace_t *t0, *t1;
677 /* Prefetch next iteration. */
678 vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD);
679 vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD);
684 b0 = vlib_get_buffer (vm, bi0);
685 b1 = vlib_get_buffer (vm, bi1);
687 if (b0->flags & VLIB_BUFFER_IS_TRACED)
689 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
690 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
692 if (b1->flags & VLIB_BUFFER_IS_TRACED)
694 t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
695 t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX];
705 vnet_error_trace_t *t0;
709 b0 = vlib_get_buffer (vm, bi0);
711 if (b0->flags & VLIB_BUFFER_IS_TRACED)
713 t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
714 t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
723 VNET_ERROR_DISPOSITION_DROP,
724 VNET_ERROR_DISPOSITION_PUNT,
725 VNET_ERROR_N_DISPOSITION,
726 } vnet_error_disposition_t;
728 static_always_inline uword
729 interface_drop_punt (vlib_main_t * vm,
730 vlib_node_runtime_t * node,
731 vlib_frame_t * frame,
732 vnet_error_disposition_t disposition)
734 u32 *from, n_left, thread_index, *sw_if_index;
735 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
736 u32 sw_if_indices[VLIB_FRAME_SIZE];
737 vlib_simple_counter_main_t *cm;
738 u16 nexts[VLIB_FRAME_SIZE];
741 vnm = vnet_get_main ();
742 thread_index = vm->thread_index;
743 from = vlib_frame_vector_args (frame);
744 n_left = frame->n_vectors;
746 sw_if_index = sw_if_indices;
748 vlib_get_buffers (vm, from, bufs, n_left);
750 if (node->flags & VLIB_NODE_FLAG_TRACE)
751 interface_trace_buffers (vm, node, frame);
753 /* All going to drop regardless, this is just a counting exercise */
754 clib_memset (nexts, 0, sizeof (nexts));
756 cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
757 (disposition == VNET_ERROR_DISPOSITION_PUNT
758 ? VNET_INTERFACE_COUNTER_PUNT
759 : VNET_INTERFACE_COUNTER_DROP));
761 /* collect the array of interfaces first ... */
766 /* Prefetch 8 ahead - there's not much going on in each iteration */
767 vlib_prefetch_buffer_header (b[4], LOAD);
768 vlib_prefetch_buffer_header (b[5], LOAD);
769 vlib_prefetch_buffer_header (b[6], LOAD);
770 vlib_prefetch_buffer_header (b[7], LOAD);
772 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
773 sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
774 sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
775 sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
783 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
790 /* ... then count against them in blocks */
791 n_left = frame->n_vectors;
795 vnet_sw_interface_t *sw_if0;
798 off = frame->n_vectors - n_left;
800 sw_if_index = sw_if_indices + off;
802 count = clib_count_equal_u32 (sw_if_index, n_left);
805 vlib_increment_simple_counter (cm, thread_index, sw_if_index[0], count);
807 /* Increment super-interface drop/punt counters for
809 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index[0]);
810 if (sw_if0->sup_sw_if_index != sw_if_index[0])
811 vlib_increment_simple_counter
812 (cm, thread_index, sw_if0->sup_sw_if_index, count);
815 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
817 return frame->n_vectors;
821 pcap_drop_trace (vlib_main_t * vm,
822 vnet_interface_main_t * im,
823 vnet_pcap_t * pp, vlib_frame_t * f)
826 u32 n_left = f->n_vectors;
827 vlib_buffer_t *b0, *p1;
829 i16 save_current_data;
830 u16 save_current_length;
831 vlib_error_main_t *em = &vm->error_main;
835 from = vlib_frame_vector_args (f);
839 if (PREDICT_TRUE (n_left > 1))
841 p1 = vlib_get_buffer (vm, from[1]);
842 vlib_prefetch_buffer_header (p1, LOAD);
846 b0 = vlib_get_buffer (vm, bi0);
850 /* See if we're pointedly ignoring this specific error */
851 if (im->pcap_drop_filter_hash
852 && hash_get (im->pcap_drop_filter_hash, b0->error))
855 do_trace = (pp->pcap_sw_if_index == 0) ||
856 pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX];
859 (do_trace == 0 && pp->filter_classify_table_index != ~0))
861 do_trace = vnet_is_packet_traced_inline
862 (b0, pp->filter_classify_table_index, 0 /* full classify */ );
865 /* Trace all drops, or drops received on a specific interface */
868 save_current_data = b0->current_data;
869 save_current_length = b0->current_length;
872 * Typically, we'll need to rewind the buffer
873 * if l2_hdr_offset is valid, make sure to rewind to the start of
874 * the L2 header. This may not be the buffer start in case we pop-ed
876 * Otherwise, rewind to buffer start and hope for the best.
878 if (b0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID)
880 if (b0->current_data > vnet_buffer (b0)->l2_hdr_offset)
881 vlib_buffer_advance (b0,
882 vnet_buffer (b0)->l2_hdr_offset -
885 else if (b0->current_data > 0)
886 vlib_buffer_advance (b0, (word) - b0->current_data);
889 vlib_buffer_t *last = b0;
890 u32 error_node_index;
893 /* Length of the error string */
894 int error_string_len =
895 clib_strnlen (em->error_strings_heap[b0->error], 128);
897 /* Dig up the drop node */
898 error_node_index = vm->node_main.node_by_error[b0->error];
899 n = vlib_get_node (vm, error_node_index);
901 /* Length of full drop string, w/ "nodename: " prepended */
902 drop_string_len = error_string_len + vec_len (n->name) + 2;
904 /* Find the last buffer in the chain */
905 while (last->flags & VLIB_BUFFER_NEXT_PRESENT)
906 last = vlib_get_buffer (vm, last->next_buffer);
909 * Append <nodename>: <error-string> to the capture,
910 * only if we can do that without allocating a new buffer.
912 if (PREDICT_TRUE ((last->current_data + last->current_length)
913 < (VLIB_BUFFER_DEFAULT_DATA_SIZE
916 clib_memcpy_fast (last->data + last->current_data +
917 last->current_length, n->name,
919 clib_memcpy_fast (last->data + last->current_data +
920 last->current_length + vec_len (n->name),
922 clib_memcpy_fast (last->data + last->current_data +
923 last->current_length + vec_len (n->name) +
924 2, em->error_strings_heap[b0->error],
926 last->current_length += drop_string_len;
927 b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID);
928 pcap_add_buffer (&pp->pcap_main, vm, bi0,
929 pp->max_bytes_per_pkt);
930 last->current_length -= drop_string_len;
931 b0->current_data = save_current_data;
932 b0->current_length = save_current_length;
938 * Didn't have space in the last buffer, here's the dropped
941 pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
943 b0->current_data = save_current_data;
944 b0->current_length = save_current_length;
949 #ifndef CLIB_MARCH_VARIANT
951 vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add)
953 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
955 if (im->pcap_drop_filter_hash == 0)
956 im->pcap_drop_filter_hash = hash_create (0, sizeof (uword));
959 hash_set (im->pcap_drop_filter_hash, error_index, 1);
961 hash_unset (im->pcap_drop_filter_hash, error_index);
963 #endif /* CLIB_MARCH_VARIANT */
965 VLIB_NODE_FN (interface_drop) (vlib_main_t * vm,
966 vlib_node_runtime_t * node,
967 vlib_frame_t * frame)
969 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
970 vnet_pcap_t *pp = &vlib_global_main.pcap;
972 if (PREDICT_FALSE (pp->pcap_drop_enable))
973 pcap_drop_trace (vm, im, pp, frame);
975 return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP);
978 VLIB_NODE_FN (interface_punt) (vlib_main_t * vm,
979 vlib_node_runtime_t * node,
980 vlib_frame_t * frame)
982 return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT);
986 VLIB_REGISTER_NODE (interface_drop) = {
987 .name = "error-drop",
988 .vector_size = sizeof (u32),
989 .format_trace = format_vnet_error_trace,
998 VLIB_REGISTER_NODE (interface_punt) = {
999 .name = "error-punt",
1000 .vector_size = sizeof (u32),
1001 .format_trace = format_vnet_error_trace,
1010 VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = {
1011 .name = "interface-output",
1012 .vector_size = sizeof (u32),
1017 interface_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1018 vlib_frame_t * from_frame)
1020 vnet_main_t *vnm = vnet_get_main ();
1021 u32 last_sw_if_index = ~0;
1022 vlib_frame_t *to_frame = 0;
1023 vnet_hw_interface_t *hw = 0;
1024 u32 *from, *to_next = 0;
1027 from = vlib_frame_vector_args (from_frame);
1028 n_left_from = from_frame->n_vectors;
1029 while (n_left_from > 0)
1038 b0 = vlib_get_buffer (vm, bi0);
1039 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
1041 if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0))
1045 hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index);
1046 vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1048 last_sw_if_index = sw_if_index0;
1049 hw = vnet_get_sup_hw_interface (vnm, sw_if_index0);
1050 to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index);
1051 to_next = vlib_frame_vector_args (to_frame);
1056 to_frame->n_vectors++;
1058 vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1059 return from_frame->n_vectors;
1063 VLIB_REGISTER_NODE (interface_tx) = {
1064 .function = interface_tx_node_fn,
1065 .name = "interface-tx",
1066 .vector_size = sizeof (u32),
1073 VNET_FEATURE_ARC_INIT (interface_output, static) =
1075 .arc_name = "interface-output",
1076 .start_nodes = VNET_FEATURES (0),
1077 .last_in_arc = "interface-tx",
1078 .arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index,
1081 VNET_FEATURE_INIT (span_tx, static) = {
1082 .arc_name = "interface-output",
1083 .node_name = "span-output",
1084 .runs_before = VNET_FEATURES ("interface-tx"),
1087 VNET_FEATURE_INIT (ipsec_if_tx, static) = {
1088 .arc_name = "interface-output",
1089 .node_name = "ipsec-if-output",
1090 .runs_before = VNET_FEATURES ("interface-tx"),
1093 VNET_FEATURE_INIT (interface_tx, static) = {
1094 .arc_name = "interface-output",
1095 .node_name = "interface-tx",
1100 #ifndef CLIB_MARCH_VARIANT
1102 vnet_per_buffer_interface_output_hw_interface_add_del (vnet_main_t * vnm,
1106 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1109 if (hi->output_node_index == 0)
1112 next_index = vlib_node_add_next
1113 (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
1114 hi->output_node_index);
1115 hi->output_node_next_index = next_index;
1120 VNET_HW_INTERFACE_ADD_DEL_FUNCTION
1121 (vnet_per_buffer_interface_output_hw_interface_add_del);
1124 vnet_set_interface_output_node (vnet_main_t * vnm,
1125 u32 hw_if_index, u32 node_index)
1127 ASSERT (node_index);
1128 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1129 u32 next_index = vlib_node_add_next
1130 (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index);
1131 hi->output_node_next_index = next_index;
1132 hi->output_node_index = node_index;
1134 #endif /* CLIB_MARCH_VARIANT */
1137 * fd.io coding-style-patch-verification: ON
1140 * eval: (c-set-style "gnu")