FD.io VPP  v19.08.1-401-g8e4ed521a
Vector Packet Processing
interface_output.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  * 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>
41 #include <vnet/ip/icmp46_packet.h>
42 #include <vnet/ip/ip4.h>
43 #include <vnet/ip/ip6.h>
44 #include <vnet/udp/udp_packet.h>
45 #include <vnet/feature/feature.h>
47 
48 typedef struct
49 {
54  u8 data[128 - 3 * sizeof (u32)];
55 }
57 
58 #ifndef CLIB_MARCH_VARIANT
59 u8 *
61 {
62  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
63  vlib_node_t *node = va_arg (*va, vlib_node_t *);
64  interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *);
65  vnet_main_t *vnm = vnet_get_main ();
67  u32 indent;
68 
69  if (t->sw_if_index != (u32) ~ 0)
70  {
71  indent = format_get_indent (s);
72 
75  {
76  /* the interface may have been deleted by the time the trace is printed */
77  s = format (s, "sw_if_index: %d ", t->sw_if_index);
78  }
79  else
80  {
81  si = vnet_get_sw_interface (vnm, t->sw_if_index);
82  s =
83  format (s, "%U ", format_vnet_sw_interface_name, vnm, si,
84  t->flags);
85  }
86 #define _(bit, name, v, x) \
87  if (v && (t->flags & VNET_BUFFER_F_##name)) \
88  s = format (s, "%s ", v);
90 #undef _
91  if (t->flags & VNET_BUFFER_F_GSO)
92  {
93  s = format (s, "\n%Ugso_sz %d gso_l4_hdr_sz %d",
94  format_white_space, indent + 2, t->gso_size,
95  t->gso_l4_hdr_sz);
96  }
97  s =
98  format (s, "\n%U%U", format_white_space, indent,
100  t->data, sizeof (t->data));
101  }
102  return s;
103 }
104 
105 static void
107  vlib_node_runtime_t * node,
108  vlib_frame_t * frame, uword n_buffers)
109 {
110  u32 n_left, *from;
111 
112  n_left = n_buffers;
113  from = vlib_frame_vector_args (frame);
114 
115  while (n_left >= 4)
116  {
117  u32 bi0, bi1;
118  vlib_buffer_t *b0, *b1;
119  interface_output_trace_t *t0, *t1;
120 
121  /* Prefetch next iteration. */
122  vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
123  vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
124 
125  bi0 = from[0];
126  bi1 = from[1];
127 
128  b0 = vlib_get_buffer (vm, bi0);
129  b1 = vlib_get_buffer (vm, bi1);
130 
131  if (b0->flags & VLIB_BUFFER_IS_TRACED)
132  {
133  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
134  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
135  t0->flags = b0->flags;
136  t0->gso_size = vnet_buffer2 (b0)->gso_size;
137  t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz;
139  sizeof (t0->data));
140  }
141  if (b1->flags & VLIB_BUFFER_IS_TRACED)
142  {
143  t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
144  t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX];
145  t1->flags = b1->flags;
146  t1->gso_size = vnet_buffer2 (b1)->gso_size;
147  t1->gso_l4_hdr_sz = vnet_buffer2 (b1)->gso_l4_hdr_sz;
149  sizeof (t1->data));
150  }
151  from += 2;
152  n_left -= 2;
153  }
154 
155  while (n_left >= 1)
156  {
157  u32 bi0;
158  vlib_buffer_t *b0;
159  interface_output_trace_t *t0;
160 
161  bi0 = from[0];
162 
163  b0 = vlib_get_buffer (vm, bi0);
164 
165  if (b0->flags & VLIB_BUFFER_IS_TRACED)
166  {
167  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
168  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
169  t0->flags = b0->flags;
170  t0->gso_size = vnet_buffer2 (b0)->gso_size;
171  t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz;
173  sizeof (t0->data));
174  }
175  from += 1;
176  n_left -= 1;
177  }
178 }
179 
182 {
183  tcp_header_t *th;
184  udp_header_t *uh;
185 
186  int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0;
187  int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0;
188 
189  ASSERT (!(is_ip4 && is_ip6));
190 
191  th = (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
192  uh = (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
193 
194  if (is_ip4)
195  {
196  ip4_header_t *ip4;
197 
198  ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
199  if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
200  ip4->checksum = ip4_header_checksum (ip4);
201  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
202  {
203  th->checksum = 0;
204  th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
205  }
206  else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
207  uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
208  }
209  else if (is_ip6)
210  {
211  int bogus;
212  ip6_header_t *ip6;
213 
214  ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
215  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
216  {
217  th->checksum = 0;
218  th->checksum =
219  ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
220  }
221  else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
222  {
223  uh->checksum = 0;
224  uh->checksum =
225  ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
226  }
227  }
228  b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
229  b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
230  b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
231 }
232 
236  vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz,
237  u16 gso_size)
238 {
239  u16 size =
240  clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz
241  - b0->current_data);
242 
243  /* rounded-up division */
244  u16 n_bufs = (n_bytes_b0 - l234_sz + (size - 1)) / size;
245  u16 n_alloc;
246 
247  ASSERT (n_bufs > 0);
248  vec_validate (ptd->split_buffers, n_bufs - 1);
249 
250  n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs);
251  if (n_alloc < n_bufs)
252  {
253  vlib_buffer_free (vm, ptd->split_buffers, n_alloc);
254  return 0;
255  }
256  return n_alloc;
257 }
258 
261  u32 flags, u16 length)
262 {
263  nb0->current_data = b0->current_data;
265  nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags;
266  nb0->trace_handle = b0->trace_handle;
267  clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque));
269  vlib_buffer_get_current (b0), length);
270  nb0->current_length = length;
271 }
272 
275  vlib_buffer_t * b0, u16 template_data_sz,
276  u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left,
277  u32 next_tcp_seq, u32 flags)
278 {
279  tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz);
280 
281  *p_dst_left =
282  clib_min (gso_size,
283  vlib_buffer_get_default_data_size (vm) - (template_data_sz +
284  nb0->current_data));
285  *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz;
286 
287  tcp_header_t *tcp =
288  (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset);
289  tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq);
290 }
291 
293 tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6)
294 {
295  u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
296  u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset;
297  ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset);
298  ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset);
299  tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset);
300 
301  tcp->flags = tcp_flags;
302 
303  if (is_ip6)
304  ip6->payload_length =
305  clib_host_to_net_u16 (b0->current_length -
306  (l4_hdr_offset - b0->current_data));
307  else
308  ip4->length =
309  clib_host_to_net_u16 (b0->current_length -
310  (l3_hdr_offset - b0->current_data));
311 }
312 
313 /**
314  * Allocate the necessary number of ptd->split_buffers,
315  * and segment the possibly chained buffer(s) from b0 into
316  * there.
317  *
318  * Return the cumulative number of bytes sent or zero
319  * if allocation failed.
320  */
321 
324  int do_tx_offloads, u32 sbi0, vlib_buffer_t * sb0,
325  u32 n_bytes_b0)
326 {
327  u32 n_tx_bytes = 0;
328  int is_ip4 = sb0->flags & VNET_BUFFER_F_IS_IP4;
329  int is_ip6 = sb0->flags & VNET_BUFFER_F_IS_IP6;
330  ASSERT (is_ip4 || is_ip6);
331  ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID);
332  ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID);
333  ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
334  u16 gso_size = vnet_buffer2 (sb0)->gso_size;
335 
336  int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz;
337  u8 save_tcp_flags = 0;
338  u8 tcp_flags_no_fin_psh = 0;
339  u32 next_tcp_seq = 0;
340 
341  tcp_header_t *tcp =
342  (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset);
343  next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number);
344  /* store original flags for last packet and reset FIN and PSH */
345  save_tcp_flags = tcp->flags;
346  tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH);
347  tcp->checksum = 0;
348 
349  u32 default_bflags =
350  sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT);
351  u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz
352  - sb0->current_data;
353  int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz);
354  next_tcp_seq += first_data_size;
355 
356  if (PREDICT_FALSE
357  (!tso_alloc_tx_bufs (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size)))
358  return 0;
359 
360  vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]);
361  tso_init_buf_from_template_base (b0, sb0, default_bflags,
362  l234_sz + first_data_size);
363 
364  u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size;
365  if (total_src_left)
366  {
367  /* Need to copy more segments */
368  u8 *src_ptr, *dst_ptr;
369  u16 src_left, dst_left;
370  /* current source buffer */
371  vlib_buffer_t *csb0 = sb0;
372  u32 csbi0 = sbi0;
373  /* current dest buffer */
374  vlib_buffer_t *cdb0;
375  u16 dbi = 1; /* the buffer [0] is b0 */
376 
377  src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size;
378  src_left = sb0->current_length - l234_sz - first_data_size;
379 
380  tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6);
381  if (do_tx_offloads)
382  calc_checksums (vm, b0);
383 
384  /* grab a second buffer and prepare the loop */
385  ASSERT (dbi < vec_len (ptd->split_buffers));
386  cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
387  tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr,
388  &dst_left, next_tcp_seq, default_bflags);
389 
390  /* an arbitrary large number to catch the runaway loops */
391  int nloops = 2000;
392  while (total_src_left)
393  {
394  if (nloops-- <= 0)
395  clib_panic ("infinite loop detected");
396  u16 bytes_to_copy = clib_min (src_left, dst_left);
397 
398  clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy);
399 
400  src_left -= bytes_to_copy;
401  src_ptr += bytes_to_copy;
402  total_src_left -= bytes_to_copy;
403  dst_left -= bytes_to_copy;
404  dst_ptr += bytes_to_copy;
405  next_tcp_seq += bytes_to_copy;
406  cdb0->current_length += bytes_to_copy;
407 
408  if (0 == src_left)
409  {
410  int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT);
411  u32 next_bi = csb0->next_buffer;
412 
413  /* init src to the next buffer in chain */
414  if (has_next)
415  {
416  csbi0 = next_bi;
417  csb0 = vlib_get_buffer (vm, csbi0);
418  src_left = csb0->current_length;
419  src_ptr = vlib_buffer_get_current (csb0);
420  }
421  else
422  {
423  ASSERT (total_src_left == 0);
424  break;
425  }
426  }
427  if (0 == dst_left && total_src_left)
428  {
429  if (do_tx_offloads)
430  calc_checksums (vm, cdb0);
431  n_tx_bytes += cdb0->current_length;
432  ASSERT (dbi < vec_len (ptd->split_buffers));
433  cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
434  tso_init_buf_from_template (vm, cdb0, b0, l234_sz,
435  gso_size, &dst_ptr, &dst_left,
436  next_tcp_seq, default_bflags);
437  }
438  }
439 
440  tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6);
441  if (do_tx_offloads)
442  calc_checksums (vm, cdb0);
443 
444  n_tx_bytes += cdb0->current_length;
445  }
446  n_tx_bytes += b0->current_length;
447  return n_tx_bytes;
448 }
449 
452  vlib_node_runtime_t * node, u32 * pbi0,
453  u32 drop_error_code)
454 {
455  u32 thread_index = vm->thread_index;
456  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
457 
459  cm =
462  vlib_increment_simple_counter (cm, thread_index, rt->sw_if_index, 1);
463 
464  vlib_error_drop_buffers (vm, node, pbi0,
465  /* buffer stride */ 1,
466  /* n_buffers */ 1,
468  node->node_index, drop_error_code);
469 }
470 
473  vlib_node_runtime_t * node,
474  vlib_frame_t * frame,
475  vnet_main_t * vnm,
477  int do_tx_offloads,
478  int do_segmentation)
479 {
480  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
482  u32 n_left_to_tx, *from, *from_end, *to_tx;
483  u32 n_bytes, n_buffers, n_packets;
484  u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3;
485  u32 thread_index = vm->thread_index;
487  u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX;
488  u32 current_config_index = ~0;
489  u8 arc = im->output_feature_arc_index;
491  vec_elt_at_index (im->per_thread_data, thread_index);
492  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
493 
494  n_buffers = frame->n_vectors;
495 
496  if (node->flags & VLIB_NODE_FLAG_TRACE)
497  vnet_interface_output_trace (vm, node, frame, n_buffers);
498 
499  from = vlib_frame_vector_args (frame);
500  vlib_get_buffers (vm, from, b, n_buffers);
501 
502  if (rt->is_deleted)
503  return vlib_error_drop_buffers (vm, node, from,
504  /* buffer stride */ 1,
505  n_buffers,
507  node->node_index,
509 
510  si = vnet_get_sw_interface (vnm, rt->sw_if_index);
511  hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
512  if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ||
514  {
516 
519  vlib_increment_simple_counter (cm, thread_index,
520  rt->sw_if_index, n_buffers);
521 
522  return vlib_error_drop_buffers (vm, node, from,
523  /* buffer stride */ 1,
524  n_buffers,
526  node->node_index,
528  }
529 
530  from_end = from + n_buffers;
531 
532  /* Total byte count of all buffers. */
533  n_bytes = 0;
534  n_packets = 0;
535 
536  /* interface-output feature arc handling */
538  {
540  fcm = vnet_feature_get_config_main (arc);
541  current_config_index = vnet_get_feature_config_index (arc,
542  rt->sw_if_index);
543  vnet_get_config_data (&fcm->config_main, &current_config_index,
544  &next_index, 0);
545  }
546 
547  while (from < from_end)
548  {
549  /* Get new next frame since previous incomplete frame may have less
550  than VNET_FRAME_SIZE vectors in it. */
551  vlib_get_new_next_frame (vm, node, next_index, to_tx, n_left_to_tx);
552 
553  while (from + 8 <= from_end && n_left_to_tx >= 4)
554  {
555  u32 bi0, bi1, bi2, bi3;
556  u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3;
557  u32 or_flags;
558 
559  /* Prefetch next iteration. */
560  vlib_prefetch_buffer_header (b[4], LOAD);
561  vlib_prefetch_buffer_header (b[5], LOAD);
562  vlib_prefetch_buffer_header (b[6], LOAD);
563  vlib_prefetch_buffer_header (b[7], LOAD);
564 
565  bi0 = from[0];
566  bi1 = from[1];
567  bi2 = from[2];
568  bi3 = from[3];
569  to_tx[0] = bi0;
570  to_tx[1] = bi1;
571  to_tx[2] = bi2;
572  to_tx[3] = bi3;
573 
574  or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags;
575 
576  if (do_segmentation)
577  {
578  /* go to single loop if we need TSO segmentation */
579  if (PREDICT_FALSE (or_flags & VNET_BUFFER_F_GSO))
580  break;
581  }
582  from += 4;
583  to_tx += 4;
584  n_left_to_tx -= 4;
585 
586  /* Be grumpy about zero length buffers for benefit of
587  driver tx function. */
588  ASSERT (b[0]->current_length > 0);
589  ASSERT (b[1]->current_length > 0);
590  ASSERT (b[2]->current_length > 0);
591  ASSERT (b[3]->current_length > 0);
592 
593  n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
594  n_bytes_b1 = vlib_buffer_length_in_chain (vm, b[1]);
595  n_bytes_b2 = vlib_buffer_length_in_chain (vm, b[2]);
596  n_bytes_b3 = vlib_buffer_length_in_chain (vm, b[3]);
597  tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
598  tx_swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
599  tx_swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
600  tx_swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
601 
602  n_bytes += n_bytes_b0 + n_bytes_b1;
603  n_bytes += n_bytes_b2 + n_bytes_b3;
604  n_packets += 4;
605 
606  if (PREDICT_FALSE (current_config_index != ~0))
607  {
608  vnet_buffer (b[0])->feature_arc_index = arc;
609  vnet_buffer (b[1])->feature_arc_index = arc;
610  vnet_buffer (b[2])->feature_arc_index = arc;
611  vnet_buffer (b[3])->feature_arc_index = arc;
612  b[0]->current_config_index = current_config_index;
613  b[1]->current_config_index = current_config_index;
614  b[2]->current_config_index = current_config_index;
615  b[3]->current_config_index = current_config_index;
616  }
617 
618  /* update vlan subif tx counts, if required */
619  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
620  {
621  vlib_increment_combined_counter (im->combined_sw_if_counters +
623  thread_index, tx_swif0, 1,
624  n_bytes_b0);
625  }
626 
627  if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index))
628  {
629 
630  vlib_increment_combined_counter (im->combined_sw_if_counters +
632  thread_index, tx_swif1, 1,
633  n_bytes_b1);
634  }
635 
636  if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index))
637  {
638 
639  vlib_increment_combined_counter (im->combined_sw_if_counters +
641  thread_index, tx_swif2, 1,
642  n_bytes_b2);
643  }
644  if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index))
645  {
646 
647  vlib_increment_combined_counter (im->combined_sw_if_counters +
649  thread_index, tx_swif3, 1,
650  n_bytes_b3);
651  }
652 
653  if (do_tx_offloads)
654  {
655  if (or_flags &
656  (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
657  VNET_BUFFER_F_OFFLOAD_UDP_CKSUM |
658  VNET_BUFFER_F_OFFLOAD_IP_CKSUM))
659  {
660  calc_checksums (vm, b[0]);
661  calc_checksums (vm, b[1]);
662  calc_checksums (vm, b[2]);
663  calc_checksums (vm, b[3]);
664  }
665  }
666  b += 4;
667 
668  }
669 
670  while (from + 1 <= from_end && n_left_to_tx >= 1)
671  {
672  u32 bi0;
673  u32 tx_swif0;
674 
675  bi0 = from[0];
676  to_tx[0] = bi0;
677  from += 1;
678  to_tx += 1;
679  n_left_to_tx -= 1;
680 
681  /* Be grumpy about zero length buffers for benefit of
682  driver tx function. */
683  ASSERT (b[0]->current_length > 0);
684 
685  n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
686  tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
687  n_bytes += n_bytes_b0;
688  n_packets += 1;
689 
690  if (PREDICT_FALSE (current_config_index != ~0))
691  {
692  vnet_buffer (b[0])->feature_arc_index = arc;
693  b[0]->current_config_index = current_config_index;
694  }
695 
696  if (do_segmentation)
697  {
698  if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO))
699  {
700  /*
701  * Undo the enqueue of the b0 - it is not going anywhere,
702  * and will be freed either after it's segmented or
703  * when dropped, if there is no buffers to segment into.
704  */
705  to_tx -= 1;
706  n_left_to_tx += 1;
707  /* undo the counting. */
708  n_bytes -= n_bytes_b0;
709  n_packets -= 1;
710 
711  u32 n_tx_bytes = 0;
712 
713  n_tx_bytes =
714  tso_segment_buffer (vm, ptd, do_tx_offloads, bi0, b[0],
715  n_bytes_b0);
716 
717  if (PREDICT_FALSE (n_tx_bytes == 0))
718  {
719  drop_one_buffer_and_count (vm, vnm, node, from - 1,
721  b += 1;
722  continue;
723  }
724 
725  u16 n_tx_bufs = vec_len (ptd->split_buffers);
726  u32 *from_tx_seg = ptd->split_buffers;
727 
728  while (n_tx_bufs > 0)
729  {
730  if (n_tx_bufs >= n_left_to_tx)
731  {
732  while (n_left_to_tx > 0)
733  {
734  to_tx[0] = from_tx_seg[0];
735  to_tx += 1;
736  from_tx_seg += 1;
737  n_left_to_tx -= 1;
738  n_tx_bufs -= 1;
739  n_packets += 1;
740  }
741  vlib_put_next_frame (vm, node, next_index,
742  n_left_to_tx);
743  vlib_get_new_next_frame (vm, node, next_index,
744  to_tx, n_left_to_tx);
745  }
746  while (n_tx_bufs > 0)
747  {
748  to_tx[0] = from_tx_seg[0];
749  to_tx += 1;
750  from_tx_seg += 1;
751  n_left_to_tx -= 1;
752  n_tx_bufs -= 1;
753  n_packets += 1;
754  }
755  }
756  n_bytes += n_tx_bytes;
757  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
758  {
759 
761  (im->combined_sw_if_counters +
762  VNET_INTERFACE_COUNTER_TX, thread_index, tx_swif0,
763  _vec_len (ptd->split_buffers), n_tx_bytes);
764  }
765  /* The buffers were enqueued. Reset the length */
766  _vec_len (ptd->split_buffers) = 0;
767  /* Free the now segmented buffer */
768  vlib_buffer_free_one (vm, bi0);
769  b += 1;
770  continue;
771  }
772  }
773 
774  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
775  {
776 
777  vlib_increment_combined_counter (im->combined_sw_if_counters +
779  thread_index, tx_swif0, 1,
780  n_bytes_b0);
781  }
782 
783  if (do_tx_offloads)
784  calc_checksums (vm, b[0]);
785 
786  b += 1;
787  }
788 
789  vlib_put_next_frame (vm, node, next_index, n_left_to_tx);
790  }
791 
792  /* Update main interface stats. */
793  vlib_increment_combined_counter (im->combined_sw_if_counters
795  thread_index,
796  rt->sw_if_index, n_packets, n_bytes);
797  return n_buffers;
798 }
799 #endif /* CLIB_MARCH_VARIANT */
800 
803  int sw_if_index_from_buffer)
804 {
805  u32 n_left_from, *from;
808 
809  if (PREDICT_TRUE (pp->pcap_tx_enable == 0))
810  return;
811 
812  if (sw_if_index_from_buffer == 0)
813  {
814  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
815  sw_if_index = rt->sw_if_index;
816  }
817  else
818  sw_if_index = ~0;
819 
820  n_left_from = frame->n_vectors;
821  from = vlib_frame_vector_args (frame);
822 
823  while (n_left_from > 0)
824  {
825  int classify_filter_result;
826  u32 bi0 = from[0];
827  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
828  from++;
829  n_left_from--;
830 
831  if (pp->filter_classify_table_index != ~0)
832  {
833  classify_filter_result =
835  (b0, pp->filter_classify_table_index, 0 /* full classify */ );
836  if (classify_filter_result)
837  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
838  continue;
839  }
840 
841  if (sw_if_index_from_buffer)
842  sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
843 
844  if (pp->pcap_sw_if_index == 0 || pp->pcap_sw_if_index == sw_if_index)
845  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
846  }
847 }
848 
849 #ifndef CLIB_MARCH_VARIANT
852  vlib_node_runtime_t * node,
853  vlib_frame_t * frame, vnet_main_t * vnm,
855  int do_tx_offloads)
856 {
857  /*
858  * The 3-headed "if" is here because we want to err on the side
859  * of not impacting the non-GSO performance - so for the more
860  * common case of no GSO interfaces we want to prevent the
861  * segmentation codepath from being there altogether.
862  */
864  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
865  do_tx_offloads,
866  /* do_segmentation */ 0);
868  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
869  do_tx_offloads,
870  /* do_segmentation */ 0);
871  else
872  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
873  do_tx_offloads,
874  /* do_segmentation */ 1);
875 }
876 
877 uword
879  vlib_frame_t * frame)
880 {
881  vnet_main_t *vnm = vnet_get_main ();
883  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
884  hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
885 
886  vnet_interface_pcap_tx_trace (vm, node, frame,
887  0 /* sw_if_index_from_buffer */ );
888 
890  return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
891  /* do_tx_offloads */ 0);
892  else
893  return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
894  /* do_tx_offloads */ 1);
895 }
896 #endif /* CLIB_MARCH_VARIANT */
897 
898 /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */
899 VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm,
901  node,
902  vlib_frame_t * frame)
903 {
904  vnet_main_t *vnm = vnet_get_main ();
905  u32 n_left_to_next, *from, *to_next;
906  u32 n_left_from, next_index;
907 
908  vnet_interface_pcap_tx_trace (vm, node, frame,
909  1 /* sw_if_index_from_buffer */ );
910 
911  n_left_from = frame->n_vectors;
912 
913  from = vlib_frame_vector_args (frame);
914  next_index = node->cached_next_index;
915 
916  while (n_left_from > 0)
917  {
918  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
919 
920  while (n_left_from >= 4 && n_left_to_next >= 2)
921  {
922  u32 bi0, bi1, next0, next1;
923  vlib_buffer_t *b0, *b1;
924  vnet_hw_interface_t *hi0, *hi1;
925 
926  /* Prefetch next iteration. */
927  vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
928  vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
929 
930  bi0 = from[0];
931  bi1 = from[1];
932  to_next[0] = bi0;
933  to_next[1] = bi1;
934  from += 2;
935  to_next += 2;
936  n_left_to_next -= 2;
937  n_left_from -= 2;
938 
939  b0 = vlib_get_buffer (vm, bi0);
940  b1 = vlib_get_buffer (vm, bi1);
941 
942  hi0 =
945  [VLIB_TX]);
946  hi1 =
949  [VLIB_TX]);
950 
951  next0 = hi0->output_node_next_index;
952  next1 = hi1->output_node_next_index;
953 
954  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
955  n_left_to_next, bi0, bi1, next0,
956  next1);
957  }
958 
959  while (n_left_from > 0 && n_left_to_next > 0)
960  {
961  u32 bi0, next0;
962  vlib_buffer_t *b0;
963  vnet_hw_interface_t *hi0;
964 
965  bi0 = from[0];
966  to_next[0] = bi0;
967  from += 1;
968  to_next += 1;
969  n_left_to_next -= 1;
970  n_left_from -= 1;
971 
972  b0 = vlib_get_buffer (vm, bi0);
973 
974  hi0 =
977  [VLIB_TX]);
978 
979  next0 = hi0->output_node_next_index;
980 
981  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
982  n_left_to_next, bi0, next0);
983  }
984 
985  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
986  }
987 
988  return frame->n_vectors;
989 }
990 
991 typedef struct vnet_error_trace_t_
992 {
995 
996 
997 static u8 *
998 format_vnet_error_trace (u8 * s, va_list * va)
999 {
1000  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
1001  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
1002  vnet_error_trace_t *t = va_arg (*va, vnet_error_trace_t *);
1003 
1004  s = format (s, "rx:%U", format_vnet_sw_if_index_name,
1005  vnet_get_main (), t->sw_if_index);
1006 
1007  return s;
1008 }
1009 
1010 static void
1012  vlib_node_runtime_t * node, vlib_frame_t * frame)
1013 {
1014  u32 n_left, *buffers;
1015 
1016  buffers = vlib_frame_vector_args (frame);
1017  n_left = frame->n_vectors;
1018 
1019  while (n_left >= 4)
1020  {
1021  u32 bi0, bi1;
1022  vlib_buffer_t *b0, *b1;
1023  vnet_error_trace_t *t0, *t1;
1024 
1025  /* Prefetch next iteration. */
1026  vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD);
1027  vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD);
1028 
1029  bi0 = buffers[0];
1030  bi1 = buffers[1];
1031 
1032  b0 = vlib_get_buffer (vm, bi0);
1033  b1 = vlib_get_buffer (vm, bi1);
1034 
1035  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1036  {
1037  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1038  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1039  }
1040  if (b1->flags & VLIB_BUFFER_IS_TRACED)
1041  {
1042  t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
1043  t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX];
1044  }
1045  buffers += 2;
1046  n_left -= 2;
1047  }
1048 
1049  while (n_left >= 1)
1050  {
1051  u32 bi0;
1052  vlib_buffer_t *b0;
1053  vnet_error_trace_t *t0;
1054 
1055  bi0 = buffers[0];
1056 
1057  b0 = vlib_get_buffer (vm, bi0);
1058 
1059  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1060  {
1061  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1062  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1063  }
1064  buffers += 1;
1065  n_left -= 1;
1066  }
1067 }
1068 
1069 typedef enum
1070 {
1075 
1078  vlib_node_runtime_t * node,
1079  vlib_frame_t * frame,
1080  vnet_error_disposition_t disposition)
1081 {
1082  u32 *from, n_left, thread_index, *sw_if_index;
1083  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1084  u32 sw_if_indices[VLIB_FRAME_SIZE];
1086  u16 nexts[VLIB_FRAME_SIZE];
1087  vnet_main_t *vnm;
1088 
1089  vnm = vnet_get_main ();
1090  thread_index = vm->thread_index;
1091  from = vlib_frame_vector_args (frame);
1092  n_left = frame->n_vectors;
1093  b = bufs;
1094  sw_if_index = sw_if_indices;
1095 
1096  vlib_get_buffers (vm, from, bufs, n_left);
1097 
1098  if (node->flags & VLIB_NODE_FLAG_TRACE)
1099  interface_trace_buffers (vm, node, frame);
1100 
1101  /* All going to drop regardless, this is just a counting exercise */
1102  clib_memset (nexts, 0, sizeof (nexts));
1103 
1105  (disposition == VNET_ERROR_DISPOSITION_PUNT
1108 
1109  /* collect the array of interfaces first ... */
1110  while (n_left >= 4)
1111  {
1112  if (n_left >= 12)
1113  {
1114  /* Prefetch 8 ahead - there's not much going on in each iteration */
1115  vlib_prefetch_buffer_header (b[4], LOAD);
1116  vlib_prefetch_buffer_header (b[5], LOAD);
1117  vlib_prefetch_buffer_header (b[6], LOAD);
1118  vlib_prefetch_buffer_header (b[7], LOAD);
1119  }
1120  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
1121  sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
1122  sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
1123  sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
1124 
1125  sw_if_index += 4;
1126  n_left -= 4;
1127  b += 4;
1128  }
1129  while (n_left)
1130  {
1131  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
1132 
1133  sw_if_index += 1;
1134  n_left -= 1;
1135  b += 1;
1136  }
1137 
1138  /* ... then count against them in blocks */
1139  n_left = frame->n_vectors;
1140 
1141  while (n_left)
1142  {
1143  vnet_sw_interface_t *sw_if0;
1144  u16 off, count;
1145 
1146  off = frame->n_vectors - n_left;
1147 
1148  sw_if_index = sw_if_indices + off;
1149 
1150  count = clib_count_equal_u32 (sw_if_index, n_left);
1151  n_left -= count;
1152 
1153  vlib_increment_simple_counter (cm, thread_index, sw_if_index[0], count);
1154 
1155  /* Increment super-interface drop/punt counters for
1156  sub-interfaces. */
1157  sw_if0 = vnet_get_sw_interface (vnm, sw_if_index[0]);
1158  if (sw_if0->sup_sw_if_index != sw_if_index[0])
1160  (cm, thread_index, sw_if0->sup_sw_if_index, count);
1161  }
1162 
1163  vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
1164 
1165  return frame->n_vectors;
1166 }
1167 
1168 static inline void
1170  vnet_interface_main_t * im,
1171  vnet_pcap_t * pp, vlib_frame_t * f)
1172 {
1173  u32 *from;
1174  u32 n_left = f->n_vectors;
1175  vlib_buffer_t *b0, *p1;
1176  u32 bi0;
1177  i16 save_current_data;
1178  u16 save_current_length;
1179  vlib_error_main_t *em = &vm->error_main;
1180  int do_trace = 0;
1181 
1182 
1183  from = vlib_frame_vector_args (f);
1184 
1185  while (n_left > 0)
1186  {
1187  if (PREDICT_TRUE (n_left > 1))
1188  {
1189  p1 = vlib_get_buffer (vm, from[1]);
1190  vlib_prefetch_buffer_header (p1, LOAD);
1191  }
1192 
1193  bi0 = from[0];
1194  b0 = vlib_get_buffer (vm, bi0);
1195  from++;
1196  n_left--;
1197 
1198  /* See if we're pointedly ignoring this specific error */
1199  if (im->pcap_drop_filter_hash
1200  && hash_get (im->pcap_drop_filter_hash, b0->error))
1201  continue;
1202 
1203  do_trace = (pp->pcap_sw_if_index == 0) ||
1204  pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX];
1205 
1206  if (PREDICT_FALSE
1207  (do_trace == 0 && pp->filter_classify_table_index != ~0))
1208  {
1209  do_trace = vnet_is_packet_traced_inline
1210  (b0, pp->filter_classify_table_index, 0 /* full classify */ );
1211  }
1212 
1213  /* Trace all drops, or drops received on a specific interface */
1214  if (do_trace)
1215  {
1216  save_current_data = b0->current_data;
1217  save_current_length = b0->current_length;
1218 
1219  /*
1220  * Typically, we'll need to rewind the buffer
1221  * if l2_hdr_offset is valid, make sure to rewind to the start of
1222  * the L2 header. This may not be the buffer start in case we pop-ed
1223  * vlan tags.
1224  * Otherwise, rewind to buffer start and hope for the best.
1225  */
1226  if (b0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID)
1227  {
1228  if (b0->current_data > vnet_buffer (b0)->l2_hdr_offset)
1229  vlib_buffer_advance (b0,
1230  vnet_buffer (b0)->l2_hdr_offset -
1231  b0->current_data);
1232  }
1233  else if (b0->current_data > 0)
1234  vlib_buffer_advance (b0, (word) - b0->current_data);
1235 
1236  {
1237  vlib_buffer_t *last = b0;
1238  u32 error_node_index;
1239  int drop_string_len;
1240  vlib_node_t *n;
1241  /* Length of the error string */
1242  int error_string_len =
1243  clib_strnlen (em->error_strings_heap[b0->error], 128);
1244 
1245  /* Dig up the drop node */
1246  error_node_index = vm->node_main.node_by_error[b0->error];
1247  n = vlib_get_node (vm, error_node_index);
1248 
1249  /* Length of full drop string, w/ "nodename: " prepended */
1250  drop_string_len = error_string_len + vec_len (n->name) + 2;
1251 
1252  /* Find the last buffer in the chain */
1253  while (last->flags & VLIB_BUFFER_NEXT_PRESENT)
1254  last = vlib_get_buffer (vm, last->next_buffer);
1255 
1256  /*
1257  * Append <nodename>: <error-string> to the capture,
1258  * only if we can do that without allocating a new buffer.
1259  */
1260  if (PREDICT_TRUE ((last->current_data + last->current_length)
1262  - drop_string_len)))
1263  {
1264  clib_memcpy_fast (last->data + last->current_data +
1265  last->current_length, n->name,
1266  vec_len (n->name));
1267  clib_memcpy_fast (last->data + last->current_data +
1268  last->current_length + vec_len (n->name),
1269  ": ", 2);
1270  clib_memcpy_fast (last->data + last->current_data +
1271  last->current_length + vec_len (n->name) +
1272  2, em->error_strings_heap[b0->error],
1273  error_string_len);
1274  last->current_length += drop_string_len;
1275  b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID);
1276  pcap_add_buffer (&pp->pcap_main, vm, bi0,
1277  pp->max_bytes_per_pkt);
1278  last->current_length -= drop_string_len;
1279  b0->current_data = save_current_data;
1280  b0->current_length = save_current_length;
1281  continue;
1282  }
1283  }
1284 
1285  /*
1286  * Didn't have space in the last buffer, here's the dropped
1287  * packet as-is
1288  */
1289  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
1290 
1291  b0->current_data = save_current_data;
1292  b0->current_length = save_current_length;
1293  }
1294  }
1295 }
1296 
1297 #ifndef CLIB_MARCH_VARIANT
1298 void
1299 vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add)
1300 {
1302 
1303  if (im->pcap_drop_filter_hash == 0)
1304  im->pcap_drop_filter_hash = hash_create (0, sizeof (uword));
1305 
1306  if (is_add)
1307  hash_set (im->pcap_drop_filter_hash, error_index, 1);
1308  else
1309  hash_unset (im->pcap_drop_filter_hash, error_index);
1310 }
1311 #endif /* CLIB_MARCH_VARIANT */
1312 
1313 VLIB_NODE_FN (interface_drop) (vlib_main_t * vm,
1314  vlib_node_runtime_t * node,
1315  vlib_frame_t * frame)
1316 {
1319 
1320  if (PREDICT_FALSE (pp->pcap_drop_enable))
1321  pcap_drop_trace (vm, im, pp, frame);
1322 
1323  return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP);
1324 }
1325 
1326 VLIB_NODE_FN (interface_punt) (vlib_main_t * vm,
1327  vlib_node_runtime_t * node,
1328  vlib_frame_t * frame)
1329 {
1330  return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT);
1331 }
1332 
1333 /* *INDENT-OFF* */
1334 VLIB_REGISTER_NODE (interface_drop) = {
1335  .name = "error-drop",
1336  .vector_size = sizeof (u32),
1337  .format_trace = format_vnet_error_trace,
1338  .n_next_nodes = 1,
1339  .next_nodes = {
1340  [0] = "drop",
1341  },
1342 };
1343 /* *INDENT-ON* */
1344 
1345 /* *INDENT-OFF* */
1346 VLIB_REGISTER_NODE (interface_punt) = {
1347  .name = "error-punt",
1348  .vector_size = sizeof (u32),
1349  .format_trace = format_vnet_error_trace,
1350  .n_next_nodes = 1,
1351  .next_nodes = {
1352  [0] = "punt",
1353  },
1354 };
1355 /* *INDENT-ON* */
1356 
1357 /* *INDENT-OFF* */
1358 VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = {
1359  .name = "interface-output",
1360  .vector_size = sizeof (u32),
1361 };
1362 /* *INDENT-ON* */
1363 
1364 static uword
1366  vlib_frame_t * from_frame)
1367 {
1368  vnet_main_t *vnm = vnet_get_main ();
1369  u32 last_sw_if_index = ~0;
1370  vlib_frame_t *to_frame = 0;
1371  vnet_hw_interface_t *hw = 0;
1372  u32 *from, *to_next = 0;
1373  u32 n_left_from;
1374 
1375  from = vlib_frame_vector_args (from_frame);
1376  n_left_from = from_frame->n_vectors;
1377  while (n_left_from > 0)
1378  {
1379  u32 bi0;
1380  vlib_buffer_t *b0;
1381  u32 sw_if_index0;
1382 
1383  bi0 = from[0];
1384  from++;
1385  n_left_from--;
1386  b0 = vlib_get_buffer (vm, bi0);
1387  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
1388 
1389  if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0))
1390  {
1391  if (to_frame)
1392  {
1393  hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index);
1394  vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1395  }
1396  last_sw_if_index = sw_if_index0;
1397  hw = vnet_get_sup_hw_interface (vnm, sw_if_index0);
1398  to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index);
1399  to_next = vlib_frame_vector_args (to_frame);
1400  }
1401 
1402  to_next[0] = bi0;
1403  to_next++;
1404  to_frame->n_vectors++;
1405  }
1406  vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1407  return from_frame->n_vectors;
1408 }
1409 
1410 /* *INDENT-OFF* */
1411 VLIB_REGISTER_NODE (interface_tx) = {
1412  .function = interface_tx_node_fn,
1413  .name = "interface-tx",
1414  .vector_size = sizeof (u32),
1415  .n_next_nodes = 1,
1416  .next_nodes = {
1417  [0] = "error-drop",
1418  },
1419 };
1420 
1421 VNET_FEATURE_ARC_INIT (interface_output, static) =
1422 {
1423  .arc_name = "interface-output",
1424  .start_nodes = VNET_FEATURES (0),
1425  .last_in_arc = "interface-tx",
1427 };
1428 
1429 VNET_FEATURE_INIT (span_tx, static) = {
1430  .arc_name = "interface-output",
1431  .node_name = "span-output",
1432  .runs_before = VNET_FEATURES ("interface-tx"),
1433 };
1434 
1435 VNET_FEATURE_INIT (ipsec_if_tx, static) = {
1436  .arc_name = "interface-output",
1437  .node_name = "ipsec-if-output",
1438  .runs_before = VNET_FEATURES ("interface-tx"),
1439 };
1440 
1441 VNET_FEATURE_INIT (interface_tx, static) = {
1442  .arc_name = "interface-output",
1443  .node_name = "interface-tx",
1444  .runs_before = 0,
1445 };
1446 /* *INDENT-ON* */
1447 
1448 #ifndef CLIB_MARCH_VARIANT
1449 clib_error_t *
1451  u32 hw_if_index,
1452  u32 is_create)
1453 {
1454  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1455  u32 next_index;
1456 
1457  if (hi->output_node_index == 0)
1458  return 0;
1459 
1460  next_index = vlib_node_add_next
1461  (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
1462  hi->output_node_index);
1463  hi->output_node_next_index = next_index;
1464 
1465  return 0;
1466 }
1467 
1470 
1471 void
1473  u32 hw_if_index, u32 node_index)
1474 {
1475  ASSERT (node_index);
1476  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1477  u32 next_index = vlib_node_add_next
1478  (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index);
1479  hi->output_node_next_index = next_index;
1480  hi->output_node_index = node_index;
1481 }
1482 #endif /* CLIB_MARCH_VARIANT */
1483 
1484 /*
1485  * fd.io coding-style-patch-verification: ON
1486  *
1487  * Local Variables:
1488  * eval: (c-set-style "gnu")
1489  * End:
1490  */
u8 * format_vnet_interface_output_trace(u8 *s, va_list *va)
vnet_config_main_t config_main
Definition: feature.h:82
static_always_inline uword vnet_interface_output_node_inline_gso(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vnet_main_t *vnm, vnet_hw_interface_t *hi, int do_tx_offloads, int do_segmentation)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
vmrglw vmrglh hi
pcap_main_t pcap_main
Definition: main.h:72
vlib_main_t vlib_global_main
Definition: main.c:1940
VNET_FEATURE_ARC_INIT(interface_output, static)
#define hash_set(h, key, value)
Definition: hash.h:255
u32 flags
Definition: vhost_user.h:141
#define clib_min(x, y)
Definition: clib.h:295
#define CLIB_UNUSED(x)
Definition: clib.h:82
void vnet_set_interface_output_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Set interface output node - for interface registered without its output/tx nodes created because its ...
static_always_inline uword vnet_interface_output_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vnet_main_t *vnm, vnet_hw_interface_t *hi, int do_tx_offloads)
#define hash_unset(h, key)
Definition: hash.h:261
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:220
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:865
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:523
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 max_bytes_per_pkt
Definition: main.h:70
#define vnet_buffer2(b)
Definition: buffer.h:424
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define PREDICT_TRUE(x)
Definition: clib.h:112
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
static_always_inline void drop_one_buffer_and_count(vlib_main_t *vm, vnet_main_t *vnm, vlib_node_runtime_t *node, u32 *pbi0, u32 drop_error_code)
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 thread_index
Definition: main.h:218
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
u8 data[0]
Packet data.
Definition: buffer.h:181
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
static_always_inline void tso_init_buf_from_template(vlib_main_t *vm, vlib_buffer_t *nb0, vlib_buffer_t *b0, u16 template_data_sz, u16 gso_size, u8 **p_dst_ptr, u16 *p_dst_left, u32 next_tcp_seq, u32 flags)
clib_error_t * vnet_per_buffer_interface_output_hw_interface_add_del(vnet_main_t *vnm, u32 hw_if_index, u32 is_create)
static void vnet_interface_output_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, uword n_buffers)
static u32 format_get_indent(u8 *s)
Definition: format.h:72
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:78
u8 data[128]
Definition: ipsec.api:251
static_always_inline int vnet_have_features(u8 arc, u32 sw_if_index)
Definition: feature.h:248
void vnet_pcap_drop_trace_filter_add_del(u32 error_index, int is_add)
#define VLIB_NODE_FN(node)
Definition: node.h:202
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:366
struct _tcp_header tcp_header_t
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:99
uword * pcap_drop_filter_hash
Definition: interface.h:855
i64 word
Definition: types.h:111
static_always_inline u32 tso_segment_buffer(vlib_main_t *vm, vnet_interface_per_thread_data_t *ptd, int do_tx_offloads, u32 sbi0, vlib_buffer_t *sb0, u32 n_bytes_b0)
Allocate the necessary number of ptd->split_buffers, and segment the possibly chained buffer(s) from ...
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
Definition: buffer_funcs.h:440
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
static_always_inline void calc_checksums(vlib_main_t *vm, vlib_buffer_t *b)
struct vnet_error_trace_t_ vnet_error_trace_t
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
vnet_hw_interface_flags_t flags
Definition: interface.h:506
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u32 filter_classify_table_index
Definition: main.h:73
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:84
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:185
#define vlib_get_new_next_frame(vm, node, next_index, vectors, n_vectors_left)
Definition: node_funcs.h:343
unsigned int u32
Definition: types.h:88
A collection of simple counters.
Definition: counter.h:57
#define VLIB_FRAME_SIZE
Definition: node.h:378
Use the vpp classifier to decide whether to trace packets.
static uword interface_tx_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
#define hash_get(h, key)
Definition: hash.h:249
format_function_t format_vnet_sw_interface_name
uword size
u8 data[128 - 3 *sizeof(u32)]
vlib_main_t * vlib_main
Definition: vnet.h:80
static_always_inline void tso_init_buf_from_template_base(vlib_buffer_t *nb0, vlib_buffer_t *b0, u32 flags, u16 length)
u8 pcap_drop_enable
Definition: main.h:68
static u8 * format_vnet_error_trace(u8 *s, va_list *va)
vlib_error_main_t error_main
Definition: main.h:179
VNET_FEATURE_INIT(span_tx, static)
uword vnet_interface_output_node(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
uword vlib_error_drop_buffers(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u32 next_buffer_stride, u32 n_buffers, u32 next_index, u32 drop_error_node, u32 drop_error_code)
Definition: error.c:45
unsigned short u16
Definition: types.h:57
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:194
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
vnet_error_disposition_t
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
Definition: config.h:122
u32 * node_by_error
Definition: node.h:767
u32 trace_handle
Specifies trace buffer handle if VLIB_PACKET_IS_TRACED flag is set.
Definition: buffer.h:163
#define PREDICT_FALSE(x)
Definition: clib.h:111
vnet_main_t vnet_main
Definition: misc.c:43
#define TCP_FLAG_FIN
Definition: fa_node.h:12
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:845
static_always_inline u16 tso_alloc_tx_bufs(vlib_main_t *vm, vnet_interface_per_thread_data_t *ptd, vlib_buffer_t *b0, u32 n_bytes_b0, u16 l234_sz, u16 gso_size)
format_function_t * format_buffer
Definition: node.h:358
u32 node_index
Node index.
Definition: node.h:496
u32 pcap_sw_if_index
Definition: main.h:71
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#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:338
static void interface_trace_buffers(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline void tso_fixup_segmented_buf(vlib_buffer_t *b0, u8 tcp_flags, int is_ip6)
u8 * name
Definition: node.h:264
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
char ** error_strings_heap
Definition: error.h:55
u16 n_vectors
Definition: node.h:397
vlib_main_t * vm
Definition: buffer.c:323
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
Definition: buffer_node.h:332
static void pcap_drop_trace(vlib_main_t *vm, vnet_interface_main_t *im, vnet_pcap_t *pp, vlib_frame_t *f)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
Definition: buffer.h:147
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:456
static int vnet_is_packet_traced_inline(vlib_buffer_t *b, u32 classify_table_index, int func)
vnet_is_packet_traced
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1010
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define ASSERT(truth)
u16 ip4_tcp_udp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
Definition: ip4_forward.c:1299
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
size_t count
Definition: vapi.c:47
static_always_inline void vnet_interface_pcap_tx_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int sw_if_index_from_buffer)
#define VNET_FEATURES(...)
Definition: feature.h:442
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
VNET_HW_INTERFACE_ADD_DEL_FUNCTION(vnet_per_buffer_interface_output_hw_interface_add_del)
Definition: defs.h:47
u16 payload_length
Definition: ip6_packet.h:374
#define VLIB_BUFFER_DEFAULT_DATA_SIZE
Definition: buffer.h:53
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static_always_inline u32 vnet_get_feature_config_index(u8 arc, u32 sw_if_index)
Definition: feature.h:255
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
vlib_node_main_t node_main
Definition: main.h:158
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:837
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define vnet_buffer(b)
Definition: buffer.h:365
#define clib_strnlen(s, m)
Definition: string.h:785
static_always_inline uword clib_count_equal_u32(u32 *data, uword max_count)
Definition: string.h:520
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:59
u16 flags
Copy of main node flags.
Definition: node.h:509
u8 pcap_tx_enable
Definition: main.h:66
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
Definition: buffer_funcs.h:898
vnet_pcap_t pcap
Definition: main.h:173
static_always_inline uword interface_drop_punt(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vnet_error_disposition_t disposition)
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
Definition: buffer_funcs.h:244
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:167
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:612
static_always_inline vnet_feature_config_main_t * vnet_feature_get_config_main(u16 arc)
Definition: feature.h:241
static void pcap_add_buffer(pcap_main_t *pm, struct vlib_main_t *vm, u32 buffer_index, u32 n_bytes_in_trace)
Add buffer (vlib_buffer_t) to the trace.
Definition: pcap_funcs.h:66
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
#define clib_panic(format, args...)
Definition: error.h:72
u32 opaque[10]
Opaque data used by sub-graphs for their own purposes.
Definition: buffer.h:153
Definition: defs.h:46
signed short i16
Definition: types.h:46