FD.io VPP  v19.08.3-2-gbabecb413
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  {
208  uh->checksum = 0;
209  uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
210  }
211  }
212  else if (is_ip6)
213  {
214  int bogus;
215  ip6_header_t *ip6;
216 
217  ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
218  if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
219  {
220  th->checksum = 0;
221  th->checksum =
222  ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
223  }
224  else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
225  {
226  uh->checksum = 0;
227  uh->checksum =
228  ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
229  }
230  }
231  b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
232  b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
233  b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
234 }
235 
239  vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz,
240  u16 gso_size)
241 {
242  u16 size =
243  clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz
244  - b0->current_data);
245 
246  /* rounded-up division */
247  u16 n_bufs = (n_bytes_b0 - l234_sz + (size - 1)) / size;
248  u16 n_alloc;
249 
250  ASSERT (n_bufs > 0);
251  vec_validate (ptd->split_buffers, n_bufs - 1);
252 
253  n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs);
254  if (n_alloc < n_bufs)
255  {
256  vlib_buffer_free (vm, ptd->split_buffers, n_alloc);
257  return 0;
258  }
259  return n_alloc;
260 }
261 
264  u32 flags, u16 length)
265 {
266  nb0->current_data = b0->current_data;
268  nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags;
269  nb0->trace_handle = b0->trace_handle;
270  clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque));
272  vlib_buffer_get_current (b0), length);
273  nb0->current_length = length;
274 }
275 
278  vlib_buffer_t * b0, u16 template_data_sz,
279  u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left,
280  u32 next_tcp_seq, u32 flags)
281 {
282  tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz);
283 
284  *p_dst_left =
285  clib_min (gso_size,
286  vlib_buffer_get_default_data_size (vm) - (template_data_sz +
287  nb0->current_data));
288  *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz;
289 
290  tcp_header_t *tcp =
291  (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset);
292  tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq);
293 }
294 
296 tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6)
297 {
298  u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
299  u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset;
300  ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset);
301  ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset);
302  tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset);
303 
304  tcp->flags = tcp_flags;
305 
306  if (is_ip6)
307  ip6->payload_length =
308  clib_host_to_net_u16 (b0->current_length -
309  (l4_hdr_offset - b0->current_data));
310  else
311  ip4->length =
312  clib_host_to_net_u16 (b0->current_length -
313  (l3_hdr_offset - b0->current_data));
314 }
315 
316 /**
317  * Allocate the necessary number of ptd->split_buffers,
318  * and segment the possibly chained buffer(s) from b0 into
319  * there.
320  *
321  * Return the cumulative number of bytes sent or zero
322  * if allocation failed.
323  */
324 
327  int do_tx_offloads, u32 sbi0, vlib_buffer_t * sb0,
328  u32 n_bytes_b0)
329 {
330  u32 n_tx_bytes = 0;
331  int is_ip4 = sb0->flags & VNET_BUFFER_F_IS_IP4;
332  int is_ip6 = sb0->flags & VNET_BUFFER_F_IS_IP6;
333  ASSERT (is_ip4 || is_ip6);
334  ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID);
335  ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID);
336  ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
337  u16 gso_size = vnet_buffer2 (sb0)->gso_size;
338 
339  int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz;
340  u8 save_tcp_flags = 0;
341  u8 tcp_flags_no_fin_psh = 0;
342  u32 next_tcp_seq = 0;
343 
344  tcp_header_t *tcp =
345  (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset);
346  next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number);
347  /* store original flags for last packet and reset FIN and PSH */
348  save_tcp_flags = tcp->flags;
349  tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH);
350  tcp->checksum = 0;
351 
352  u32 default_bflags =
353  sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT);
354  u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz
355  - sb0->current_data;
356  int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz);
357  next_tcp_seq += first_data_size;
358 
359  if (PREDICT_FALSE
360  (!tso_alloc_tx_bufs (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size)))
361  return 0;
362 
363  vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]);
364  tso_init_buf_from_template_base (b0, sb0, default_bflags,
365  l234_sz + first_data_size);
366 
367  u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size;
368  if (total_src_left)
369  {
370  /* Need to copy more segments */
371  u8 *src_ptr, *dst_ptr;
372  u16 src_left, dst_left;
373  /* current source buffer */
374  vlib_buffer_t *csb0 = sb0;
375  u32 csbi0 = sbi0;
376  /* current dest buffer */
377  vlib_buffer_t *cdb0;
378  u16 dbi = 1; /* the buffer [0] is b0 */
379 
380  src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size;
381  src_left = sb0->current_length - l234_sz - first_data_size;
382 
383  tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6);
384  if (do_tx_offloads)
385  calc_checksums (vm, b0);
386 
387  /* grab a second buffer and prepare the loop */
388  ASSERT (dbi < vec_len (ptd->split_buffers));
389  cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
390  tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr,
391  &dst_left, next_tcp_seq, default_bflags);
392 
393  /* an arbitrary large number to catch the runaway loops */
394  int nloops = 2000;
395  while (total_src_left)
396  {
397  if (nloops-- <= 0)
398  clib_panic ("infinite loop detected");
399  u16 bytes_to_copy = clib_min (src_left, dst_left);
400 
401  clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy);
402 
403  src_left -= bytes_to_copy;
404  src_ptr += bytes_to_copy;
405  total_src_left -= bytes_to_copy;
406  dst_left -= bytes_to_copy;
407  dst_ptr += bytes_to_copy;
408  next_tcp_seq += bytes_to_copy;
409  cdb0->current_length += bytes_to_copy;
410 
411  if (0 == src_left)
412  {
413  int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT);
414  u32 next_bi = csb0->next_buffer;
415 
416  /* init src to the next buffer in chain */
417  if (has_next)
418  {
419  csbi0 = next_bi;
420  csb0 = vlib_get_buffer (vm, csbi0);
421  src_left = csb0->current_length;
422  src_ptr = vlib_buffer_get_current (csb0);
423  }
424  else
425  {
426  ASSERT (total_src_left == 0);
427  break;
428  }
429  }
430  if (0 == dst_left && total_src_left)
431  {
432  if (do_tx_offloads)
433  calc_checksums (vm, cdb0);
434  n_tx_bytes += cdb0->current_length;
435  ASSERT (dbi < vec_len (ptd->split_buffers));
436  cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
437  tso_init_buf_from_template (vm, cdb0, b0, l234_sz,
438  gso_size, &dst_ptr, &dst_left,
439  next_tcp_seq, default_bflags);
440  }
441  }
442 
443  tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6);
444  if (do_tx_offloads)
445  calc_checksums (vm, cdb0);
446 
447  n_tx_bytes += cdb0->current_length;
448  }
449  n_tx_bytes += b0->current_length;
450  return n_tx_bytes;
451 }
452 
455  vlib_node_runtime_t * node, u32 * pbi0,
456  u32 drop_error_code)
457 {
458  u32 thread_index = vm->thread_index;
459  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
460 
462  cm =
465  vlib_increment_simple_counter (cm, thread_index, rt->sw_if_index, 1);
466 
467  vlib_error_drop_buffers (vm, node, pbi0,
468  /* buffer stride */ 1,
469  /* n_buffers */ 1,
471  node->node_index, drop_error_code);
472 }
473 
476  vlib_node_runtime_t * node,
477  vlib_frame_t * frame,
478  vnet_main_t * vnm,
480  int do_tx_offloads,
481  int do_segmentation)
482 {
483  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
485  u32 n_left_to_tx, *from, *from_end, *to_tx;
486  u32 n_bytes, n_buffers, n_packets;
487  u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3;
488  u32 thread_index = vm->thread_index;
490  u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX;
491  u32 current_config_index = ~0;
492  u8 arc = im->output_feature_arc_index;
494  vec_elt_at_index (im->per_thread_data, thread_index);
495  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
496 
497  n_buffers = frame->n_vectors;
498 
499  if (node->flags & VLIB_NODE_FLAG_TRACE)
500  vnet_interface_output_trace (vm, node, frame, n_buffers);
501 
502  from = vlib_frame_vector_args (frame);
503  vlib_get_buffers (vm, from, b, n_buffers);
504 
505  if (rt->is_deleted)
506  return vlib_error_drop_buffers (vm, node, from,
507  /* buffer stride */ 1,
508  n_buffers,
510  node->node_index,
512 
513  si = vnet_get_sw_interface (vnm, rt->sw_if_index);
514  hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
515  if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ||
517  {
519 
522  vlib_increment_simple_counter (cm, thread_index,
523  rt->sw_if_index, n_buffers);
524 
525  return vlib_error_drop_buffers (vm, node, from,
526  /* buffer stride */ 1,
527  n_buffers,
529  node->node_index,
531  }
532 
533  from_end = from + n_buffers;
534 
535  /* Total byte count of all buffers. */
536  n_bytes = 0;
537  n_packets = 0;
538 
539  /* interface-output feature arc handling */
541  {
543  fcm = vnet_feature_get_config_main (arc);
544  current_config_index = vnet_get_feature_config_index (arc,
545  rt->sw_if_index);
546  vnet_get_config_data (&fcm->config_main, &current_config_index,
547  &next_index, 0);
548  }
549 
550  while (from < from_end)
551  {
552  /* Get new next frame since previous incomplete frame may have less
553  than VNET_FRAME_SIZE vectors in it. */
554  vlib_get_new_next_frame (vm, node, next_index, to_tx, n_left_to_tx);
555 
556  while (from + 8 <= from_end && n_left_to_tx >= 4)
557  {
558  u32 bi0, bi1, bi2, bi3;
559  u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3;
560  u32 or_flags;
561 
562  /* Prefetch next iteration. */
563  vlib_prefetch_buffer_header (b[4], LOAD);
564  vlib_prefetch_buffer_header (b[5], LOAD);
565  vlib_prefetch_buffer_header (b[6], LOAD);
566  vlib_prefetch_buffer_header (b[7], LOAD);
567 
568  bi0 = from[0];
569  bi1 = from[1];
570  bi2 = from[2];
571  bi3 = from[3];
572  to_tx[0] = bi0;
573  to_tx[1] = bi1;
574  to_tx[2] = bi2;
575  to_tx[3] = bi3;
576 
577  or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags;
578 
579  if (do_segmentation)
580  {
581  /* go to single loop if we need TSO segmentation */
582  if (PREDICT_FALSE (or_flags & VNET_BUFFER_F_GSO))
583  break;
584  }
585  from += 4;
586  to_tx += 4;
587  n_left_to_tx -= 4;
588 
589  /* Be grumpy about zero length buffers for benefit of
590  driver tx function. */
591  ASSERT (b[0]->current_length > 0);
592  ASSERT (b[1]->current_length > 0);
593  ASSERT (b[2]->current_length > 0);
594  ASSERT (b[3]->current_length > 0);
595 
596  n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
597  n_bytes_b1 = vlib_buffer_length_in_chain (vm, b[1]);
598  n_bytes_b2 = vlib_buffer_length_in_chain (vm, b[2]);
599  n_bytes_b3 = vlib_buffer_length_in_chain (vm, b[3]);
600  tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
601  tx_swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
602  tx_swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
603  tx_swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
604 
605  n_bytes += n_bytes_b0 + n_bytes_b1;
606  n_bytes += n_bytes_b2 + n_bytes_b3;
607  n_packets += 4;
608 
609  if (PREDICT_FALSE (current_config_index != ~0))
610  {
611  vnet_buffer (b[0])->feature_arc_index = arc;
612  vnet_buffer (b[1])->feature_arc_index = arc;
613  vnet_buffer (b[2])->feature_arc_index = arc;
614  vnet_buffer (b[3])->feature_arc_index = arc;
615  b[0]->current_config_index = current_config_index;
616  b[1]->current_config_index = current_config_index;
617  b[2]->current_config_index = current_config_index;
618  b[3]->current_config_index = current_config_index;
619  }
620 
621  /* update vlan subif tx counts, if required */
622  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
623  {
624  vlib_increment_combined_counter (im->combined_sw_if_counters +
626  thread_index, tx_swif0, 1,
627  n_bytes_b0);
628  }
629 
630  if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index))
631  {
632 
633  vlib_increment_combined_counter (im->combined_sw_if_counters +
635  thread_index, tx_swif1, 1,
636  n_bytes_b1);
637  }
638 
639  if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index))
640  {
641 
642  vlib_increment_combined_counter (im->combined_sw_if_counters +
644  thread_index, tx_swif2, 1,
645  n_bytes_b2);
646  }
647  if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index))
648  {
649 
650  vlib_increment_combined_counter (im->combined_sw_if_counters +
652  thread_index, tx_swif3, 1,
653  n_bytes_b3);
654  }
655 
656  if (do_tx_offloads)
657  {
658  if (or_flags &
659  (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
660  VNET_BUFFER_F_OFFLOAD_UDP_CKSUM |
661  VNET_BUFFER_F_OFFLOAD_IP_CKSUM))
662  {
663  calc_checksums (vm, b[0]);
664  calc_checksums (vm, b[1]);
665  calc_checksums (vm, b[2]);
666  calc_checksums (vm, b[3]);
667  }
668  }
669  b += 4;
670 
671  }
672 
673  while (from + 1 <= from_end && n_left_to_tx >= 1)
674  {
675  u32 bi0;
676  u32 tx_swif0;
677 
678  bi0 = from[0];
679  to_tx[0] = bi0;
680  from += 1;
681  to_tx += 1;
682  n_left_to_tx -= 1;
683 
684  /* Be grumpy about zero length buffers for benefit of
685  driver tx function. */
686  ASSERT (b[0]->current_length > 0);
687 
688  n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
689  tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
690  n_bytes += n_bytes_b0;
691  n_packets += 1;
692 
693  if (PREDICT_FALSE (current_config_index != ~0))
694  {
695  vnet_buffer (b[0])->feature_arc_index = arc;
696  b[0]->current_config_index = current_config_index;
697  }
698 
699  if (do_segmentation)
700  {
701  if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO))
702  {
703  /*
704  * Undo the enqueue of the b0 - it is not going anywhere,
705  * and will be freed either after it's segmented or
706  * when dropped, if there is no buffers to segment into.
707  */
708  to_tx -= 1;
709  n_left_to_tx += 1;
710  /* undo the counting. */
711  n_bytes -= n_bytes_b0;
712  n_packets -= 1;
713 
714  u32 n_tx_bytes = 0;
715 
716  n_tx_bytes =
717  tso_segment_buffer (vm, ptd, do_tx_offloads, bi0, b[0],
718  n_bytes_b0);
719 
720  if (PREDICT_FALSE (n_tx_bytes == 0))
721  {
722  drop_one_buffer_and_count (vm, vnm, node, from - 1,
724  b += 1;
725  continue;
726  }
727 
728  u16 n_tx_bufs = vec_len (ptd->split_buffers);
729  u32 *from_tx_seg = ptd->split_buffers;
730 
731  while (n_tx_bufs > 0)
732  {
733  if (n_tx_bufs >= n_left_to_tx)
734  {
735  while (n_left_to_tx > 0)
736  {
737  to_tx[0] = from_tx_seg[0];
738  to_tx += 1;
739  from_tx_seg += 1;
740  n_left_to_tx -= 1;
741  n_tx_bufs -= 1;
742  n_packets += 1;
743  }
744  vlib_put_next_frame (vm, node, next_index,
745  n_left_to_tx);
746  vlib_get_new_next_frame (vm, node, next_index,
747  to_tx, n_left_to_tx);
748  }
749  while (n_tx_bufs > 0)
750  {
751  to_tx[0] = from_tx_seg[0];
752  to_tx += 1;
753  from_tx_seg += 1;
754  n_left_to_tx -= 1;
755  n_tx_bufs -= 1;
756  n_packets += 1;
757  }
758  }
759  n_bytes += n_tx_bytes;
760  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
761  {
762 
764  (im->combined_sw_if_counters +
765  VNET_INTERFACE_COUNTER_TX, thread_index, tx_swif0,
766  _vec_len (ptd->split_buffers), n_tx_bytes);
767  }
768  /* The buffers were enqueued. Reset the length */
769  _vec_len (ptd->split_buffers) = 0;
770  /* Free the now segmented buffer */
771  vlib_buffer_free_one (vm, bi0);
772  b += 1;
773  continue;
774  }
775  }
776 
777  if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index))
778  {
779 
780  vlib_increment_combined_counter (im->combined_sw_if_counters +
782  thread_index, tx_swif0, 1,
783  n_bytes_b0);
784  }
785 
786  if (do_tx_offloads)
787  calc_checksums (vm, b[0]);
788 
789  b += 1;
790  }
791 
792  vlib_put_next_frame (vm, node, next_index, n_left_to_tx);
793  }
794 
795  /* Update main interface stats. */
796  vlib_increment_combined_counter (im->combined_sw_if_counters
798  thread_index,
799  rt->sw_if_index, n_packets, n_bytes);
800  return n_buffers;
801 }
802 #endif /* CLIB_MARCH_VARIANT */
803 
806  int sw_if_index_from_buffer)
807 {
808  u32 n_left_from, *from;
811 
812  if (PREDICT_TRUE (pp->pcap_tx_enable == 0))
813  return;
814 
815  if (sw_if_index_from_buffer == 0)
816  {
817  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
818  sw_if_index = rt->sw_if_index;
819  }
820  else
821  sw_if_index = ~0;
822 
823  n_left_from = frame->n_vectors;
824  from = vlib_frame_vector_args (frame);
825 
826  while (n_left_from > 0)
827  {
828  int classify_filter_result;
829  u32 bi0 = from[0];
830  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
831  from++;
832  n_left_from--;
833 
834  if (pp->filter_classify_table_index != ~0)
835  {
836  classify_filter_result =
838  (b0, pp->filter_classify_table_index, 0 /* full classify */ );
839  if (classify_filter_result)
840  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
841  continue;
842  }
843 
844  if (sw_if_index_from_buffer)
845  sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
846 
847  if (pp->pcap_sw_if_index == 0 || pp->pcap_sw_if_index == sw_if_index)
848  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
849  }
850 }
851 
852 #ifndef CLIB_MARCH_VARIANT
855  vlib_node_runtime_t * node,
856  vlib_frame_t * frame, vnet_main_t * vnm,
858  int do_tx_offloads)
859 {
860  /*
861  * The 3-headed "if" is here because we want to err on the side
862  * of not impacting the non-GSO performance - so for the more
863  * common case of no GSO interfaces we want to prevent the
864  * segmentation codepath from being there altogether.
865  */
867  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
868  do_tx_offloads,
869  /* do_segmentation */ 0);
871  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
872  do_tx_offloads,
873  /* do_segmentation */ 0);
874  else
875  return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi,
876  do_tx_offloads,
877  /* do_segmentation */ 1);
878 }
879 
880 uword
882  vlib_frame_t * frame)
883 {
884  vnet_main_t *vnm = vnet_get_main ();
886  vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
887  hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
888 
889  vnet_interface_pcap_tx_trace (vm, node, frame,
890  0 /* sw_if_index_from_buffer */ );
891 
893  return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
894  /* do_tx_offloads */ 0);
895  else
896  return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
897  /* do_tx_offloads */ 1);
898 }
899 #endif /* CLIB_MARCH_VARIANT */
900 
901 /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */
902 VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm,
904  node,
905  vlib_frame_t * frame)
906 {
907  vnet_main_t *vnm = vnet_get_main ();
908  u32 n_left_to_next, *from, *to_next;
909  u32 n_left_from, next_index;
910 
911  vnet_interface_pcap_tx_trace (vm, node, frame,
912  1 /* sw_if_index_from_buffer */ );
913 
914  n_left_from = frame->n_vectors;
915 
916  from = vlib_frame_vector_args (frame);
917  next_index = node->cached_next_index;
918 
919  while (n_left_from > 0)
920  {
921  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
922 
923  while (n_left_from >= 4 && n_left_to_next >= 2)
924  {
925  u32 bi0, bi1, next0, next1;
926  vlib_buffer_t *b0, *b1;
927  vnet_hw_interface_t *hi0, *hi1;
928 
929  /* Prefetch next iteration. */
930  vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
931  vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
932 
933  bi0 = from[0];
934  bi1 = from[1];
935  to_next[0] = bi0;
936  to_next[1] = bi1;
937  from += 2;
938  to_next += 2;
939  n_left_to_next -= 2;
940  n_left_from -= 2;
941 
942  b0 = vlib_get_buffer (vm, bi0);
943  b1 = vlib_get_buffer (vm, bi1);
944 
945  hi0 =
948  [VLIB_TX]);
949  hi1 =
952  [VLIB_TX]);
953 
954  next0 = hi0->output_node_next_index;
955  next1 = hi1->output_node_next_index;
956 
957  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
958  n_left_to_next, bi0, bi1, next0,
959  next1);
960  }
961 
962  while (n_left_from > 0 && n_left_to_next > 0)
963  {
964  u32 bi0, next0;
965  vlib_buffer_t *b0;
966  vnet_hw_interface_t *hi0;
967 
968  bi0 = from[0];
969  to_next[0] = bi0;
970  from += 1;
971  to_next += 1;
972  n_left_to_next -= 1;
973  n_left_from -= 1;
974 
975  b0 = vlib_get_buffer (vm, bi0);
976 
977  hi0 =
980  [VLIB_TX]);
981 
982  next0 = hi0->output_node_next_index;
983 
984  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
985  n_left_to_next, bi0, next0);
986  }
987 
988  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
989  }
990 
991  return frame->n_vectors;
992 }
993 
994 typedef struct vnet_error_trace_t_
995 {
998 
999 
1000 static u8 *
1001 format_vnet_error_trace (u8 * s, va_list * va)
1002 {
1003  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
1004  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
1005  vnet_error_trace_t *t = va_arg (*va, vnet_error_trace_t *);
1006 
1007  s = format (s, "rx:%U", format_vnet_sw_if_index_name,
1008  vnet_get_main (), t->sw_if_index);
1009 
1010  return s;
1011 }
1012 
1013 static void
1015  vlib_node_runtime_t * node, vlib_frame_t * frame)
1016 {
1017  u32 n_left, *buffers;
1018 
1019  buffers = vlib_frame_vector_args (frame);
1020  n_left = frame->n_vectors;
1021 
1022  while (n_left >= 4)
1023  {
1024  u32 bi0, bi1;
1025  vlib_buffer_t *b0, *b1;
1026  vnet_error_trace_t *t0, *t1;
1027 
1028  /* Prefetch next iteration. */
1029  vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD);
1030  vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD);
1031 
1032  bi0 = buffers[0];
1033  bi1 = buffers[1];
1034 
1035  b0 = vlib_get_buffer (vm, bi0);
1036  b1 = vlib_get_buffer (vm, bi1);
1037 
1038  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1039  {
1040  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1041  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1042  }
1043  if (b1->flags & VLIB_BUFFER_IS_TRACED)
1044  {
1045  t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
1046  t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX];
1047  }
1048  buffers += 2;
1049  n_left -= 2;
1050  }
1051 
1052  while (n_left >= 1)
1053  {
1054  u32 bi0;
1055  vlib_buffer_t *b0;
1056  vnet_error_trace_t *t0;
1057 
1058  bi0 = buffers[0];
1059 
1060  b0 = vlib_get_buffer (vm, bi0);
1061 
1062  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1063  {
1064  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1065  t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1066  }
1067  buffers += 1;
1068  n_left -= 1;
1069  }
1070 }
1071 
1072 typedef enum
1073 {
1078 
1081  vlib_node_runtime_t * node,
1082  vlib_frame_t * frame,
1083  vnet_error_disposition_t disposition)
1084 {
1085  u32 *from, n_left, thread_index, *sw_if_index;
1086  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1087  u32 sw_if_indices[VLIB_FRAME_SIZE];
1089  u16 nexts[VLIB_FRAME_SIZE];
1090  vnet_main_t *vnm;
1091 
1092  vnm = vnet_get_main ();
1093  thread_index = vm->thread_index;
1094  from = vlib_frame_vector_args (frame);
1095  n_left = frame->n_vectors;
1096  b = bufs;
1097  sw_if_index = sw_if_indices;
1098 
1099  vlib_get_buffers (vm, from, bufs, n_left);
1100 
1101  if (node->flags & VLIB_NODE_FLAG_TRACE)
1102  interface_trace_buffers (vm, node, frame);
1103 
1104  /* All going to drop regardless, this is just a counting exercise */
1105  clib_memset (nexts, 0, sizeof (nexts));
1106 
1108  (disposition == VNET_ERROR_DISPOSITION_PUNT
1111 
1112  /* collect the array of interfaces first ... */
1113  while (n_left >= 4)
1114  {
1115  if (n_left >= 12)
1116  {
1117  /* Prefetch 8 ahead - there's not much going on in each iteration */
1118  vlib_prefetch_buffer_header (b[4], LOAD);
1119  vlib_prefetch_buffer_header (b[5], LOAD);
1120  vlib_prefetch_buffer_header (b[6], LOAD);
1121  vlib_prefetch_buffer_header (b[7], LOAD);
1122  }
1123  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
1124  sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
1125  sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
1126  sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
1127 
1128  sw_if_index += 4;
1129  n_left -= 4;
1130  b += 4;
1131  }
1132  while (n_left)
1133  {
1134  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
1135 
1136  sw_if_index += 1;
1137  n_left -= 1;
1138  b += 1;
1139  }
1140 
1141  /* ... then count against them in blocks */
1142  n_left = frame->n_vectors;
1143 
1144  while (n_left)
1145  {
1146  vnet_sw_interface_t *sw_if0;
1147  u16 off, count;
1148 
1149  off = frame->n_vectors - n_left;
1150 
1151  sw_if_index = sw_if_indices + off;
1152 
1153  count = clib_count_equal_u32 (sw_if_index, n_left);
1154  n_left -= count;
1155 
1156  vlib_increment_simple_counter (cm, thread_index, sw_if_index[0], count);
1157 
1158  /* Increment super-interface drop/punt counters for
1159  sub-interfaces. */
1160  sw_if0 = vnet_get_sw_interface (vnm, sw_if_index[0]);
1161  if (sw_if0->sup_sw_if_index != sw_if_index[0])
1163  (cm, thread_index, sw_if0->sup_sw_if_index, count);
1164  }
1165 
1166  vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
1167 
1168  return frame->n_vectors;
1169 }
1170 
1171 static inline void
1173  vnet_interface_main_t * im,
1174  vnet_pcap_t * pp, vlib_frame_t * f)
1175 {
1176  u32 *from;
1177  u32 n_left = f->n_vectors;
1178  vlib_buffer_t *b0, *p1;
1179  u32 bi0;
1180  i16 save_current_data;
1181  u16 save_current_length;
1182  vlib_error_main_t *em = &vm->error_main;
1183  int do_trace = 0;
1184 
1185 
1186  from = vlib_frame_vector_args (f);
1187 
1188  while (n_left > 0)
1189  {
1190  if (PREDICT_TRUE (n_left > 1))
1191  {
1192  p1 = vlib_get_buffer (vm, from[1]);
1193  vlib_prefetch_buffer_header (p1, LOAD);
1194  }
1195 
1196  bi0 = from[0];
1197  b0 = vlib_get_buffer (vm, bi0);
1198  from++;
1199  n_left--;
1200 
1201  /* See if we're pointedly ignoring this specific error */
1202  if (im->pcap_drop_filter_hash
1203  && hash_get (im->pcap_drop_filter_hash, b0->error))
1204  continue;
1205 
1206  do_trace = (pp->pcap_sw_if_index == 0) ||
1207  pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX];
1208 
1209  if (PREDICT_FALSE
1210  (do_trace == 0 && pp->filter_classify_table_index != ~0))
1211  {
1212  do_trace = vnet_is_packet_traced_inline
1213  (b0, pp->filter_classify_table_index, 0 /* full classify */ );
1214  }
1215 
1216  /* Trace all drops, or drops received on a specific interface */
1217  if (do_trace)
1218  {
1219  save_current_data = b0->current_data;
1220  save_current_length = b0->current_length;
1221 
1222  /*
1223  * Typically, we'll need to rewind the buffer
1224  * if l2_hdr_offset is valid, make sure to rewind to the start of
1225  * the L2 header. This may not be the buffer start in case we pop-ed
1226  * vlan tags.
1227  * Otherwise, rewind to buffer start and hope for the best.
1228  */
1229  if (b0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID)
1230  {
1231  if (b0->current_data > vnet_buffer (b0)->l2_hdr_offset)
1232  vlib_buffer_advance (b0,
1233  vnet_buffer (b0)->l2_hdr_offset -
1234  b0->current_data);
1235  }
1236  else if (b0->current_data > 0)
1237  vlib_buffer_advance (b0, (word) - b0->current_data);
1238 
1239  {
1240  vlib_buffer_t *last = b0;
1241  u32 error_node_index;
1242  int drop_string_len;
1243  vlib_node_t *n;
1244  /* Length of the error string */
1245  int error_string_len =
1246  clib_strnlen (em->error_strings_heap[b0->error], 128);
1247 
1248  /* Dig up the drop node */
1249  error_node_index = vm->node_main.node_by_error[b0->error];
1250  n = vlib_get_node (vm, error_node_index);
1251 
1252  /* Length of full drop string, w/ "nodename: " prepended */
1253  drop_string_len = error_string_len + vec_len (n->name) + 2;
1254 
1255  /* Find the last buffer in the chain */
1256  while (last->flags & VLIB_BUFFER_NEXT_PRESENT)
1257  last = vlib_get_buffer (vm, last->next_buffer);
1258 
1259  /*
1260  * Append <nodename>: <error-string> to the capture,
1261  * only if we can do that without allocating a new buffer.
1262  */
1263  if (PREDICT_TRUE ((last->current_data + last->current_length)
1265  - drop_string_len)))
1266  {
1267  clib_memcpy_fast (last->data + last->current_data +
1268  last->current_length, n->name,
1269  vec_len (n->name));
1270  clib_memcpy_fast (last->data + last->current_data +
1271  last->current_length + vec_len (n->name),
1272  ": ", 2);
1273  clib_memcpy_fast (last->data + last->current_data +
1274  last->current_length + vec_len (n->name) +
1275  2, em->error_strings_heap[b0->error],
1276  error_string_len);
1277  last->current_length += drop_string_len;
1278  b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID);
1279  pcap_add_buffer (&pp->pcap_main, vm, bi0,
1280  pp->max_bytes_per_pkt);
1281  last->current_length -= drop_string_len;
1282  b0->current_data = save_current_data;
1283  b0->current_length = save_current_length;
1284  continue;
1285  }
1286  }
1287 
1288  /*
1289  * Didn't have space in the last buffer, here's the dropped
1290  * packet as-is
1291  */
1292  pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
1293 
1294  b0->current_data = save_current_data;
1295  b0->current_length = save_current_length;
1296  }
1297  }
1298 }
1299 
1300 #ifndef CLIB_MARCH_VARIANT
1301 void
1302 vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add)
1303 {
1305 
1306  if (im->pcap_drop_filter_hash == 0)
1307  im->pcap_drop_filter_hash = hash_create (0, sizeof (uword));
1308 
1309  if (is_add)
1310  hash_set (im->pcap_drop_filter_hash, error_index, 1);
1311  else
1312  hash_unset (im->pcap_drop_filter_hash, error_index);
1313 }
1314 #endif /* CLIB_MARCH_VARIANT */
1315 
1316 VLIB_NODE_FN (interface_drop) (vlib_main_t * vm,
1317  vlib_node_runtime_t * node,
1318  vlib_frame_t * frame)
1319 {
1322 
1323  if (PREDICT_FALSE (pp->pcap_drop_enable))
1324  pcap_drop_trace (vm, im, pp, frame);
1325 
1326  return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP);
1327 }
1328 
1329 VLIB_NODE_FN (interface_punt) (vlib_main_t * vm,
1330  vlib_node_runtime_t * node,
1331  vlib_frame_t * frame)
1332 {
1333  return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT);
1334 }
1335 
1336 /* *INDENT-OFF* */
1337 VLIB_REGISTER_NODE (interface_drop) = {
1338  .name = "error-drop",
1339  .vector_size = sizeof (u32),
1340  .format_trace = format_vnet_error_trace,
1341  .n_next_nodes = 1,
1342  .next_nodes = {
1343  [0] = "drop",
1344  },
1345 };
1346 /* *INDENT-ON* */
1347 
1348 /* *INDENT-OFF* */
1349 VLIB_REGISTER_NODE (interface_punt) = {
1350  .name = "error-punt",
1351  .vector_size = sizeof (u32),
1352  .format_trace = format_vnet_error_trace,
1353  .n_next_nodes = 1,
1354  .next_nodes = {
1355  [0] = "punt",
1356  },
1357 };
1358 /* *INDENT-ON* */
1359 
1360 /* *INDENT-OFF* */
1361 VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = {
1362  .name = "interface-output",
1363  .vector_size = sizeof (u32),
1364 };
1365 /* *INDENT-ON* */
1366 
1367 static uword
1369  vlib_frame_t * from_frame)
1370 {
1371  vnet_main_t *vnm = vnet_get_main ();
1372  u32 last_sw_if_index = ~0;
1373  vlib_frame_t *to_frame = 0;
1374  vnet_hw_interface_t *hw = 0;
1375  u32 *from, *to_next = 0;
1376  u32 n_left_from;
1377 
1378  from = vlib_frame_vector_args (from_frame);
1379  n_left_from = from_frame->n_vectors;
1380  while (n_left_from > 0)
1381  {
1382  u32 bi0;
1383  vlib_buffer_t *b0;
1384  u32 sw_if_index0;
1385 
1386  bi0 = from[0];
1387  from++;
1388  n_left_from--;
1389  b0 = vlib_get_buffer (vm, bi0);
1390  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
1391 
1392  if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0))
1393  {
1394  if (to_frame)
1395  {
1396  hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index);
1397  vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1398  }
1399  last_sw_if_index = sw_if_index0;
1400  hw = vnet_get_sup_hw_interface (vnm, sw_if_index0);
1401  to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index);
1402  to_next = vlib_frame_vector_args (to_frame);
1403  }
1404 
1405  to_next[0] = bi0;
1406  to_next++;
1407  to_frame->n_vectors++;
1408  }
1409  vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame);
1410  return from_frame->n_vectors;
1411 }
1412 
1413 /* *INDENT-OFF* */
1414 VLIB_REGISTER_NODE (interface_tx) = {
1415  .function = interface_tx_node_fn,
1416  .name = "interface-tx",
1417  .vector_size = sizeof (u32),
1418  .n_next_nodes = 1,
1419  .next_nodes = {
1420  [0] = "error-drop",
1421  },
1422 };
1423 
1424 VNET_FEATURE_ARC_INIT (interface_output, static) =
1425 {
1426  .arc_name = "interface-output",
1427  .start_nodes = VNET_FEATURES (0),
1428  .last_in_arc = "interface-tx",
1430 };
1431 
1432 VNET_FEATURE_INIT (span_tx, static) = {
1433  .arc_name = "interface-output",
1434  .node_name = "span-output",
1435  .runs_before = VNET_FEATURES ("interface-tx"),
1436 };
1437 
1438 VNET_FEATURE_INIT (ipsec_if_tx, static) = {
1439  .arc_name = "interface-output",
1440  .node_name = "ipsec-if-output",
1441  .runs_before = VNET_FEATURES ("interface-tx"),
1442 };
1443 
1444 VNET_FEATURE_INIT (interface_tx, static) = {
1445  .arc_name = "interface-output",
1446  .node_name = "interface-tx",
1447  .runs_before = 0,
1448 };
1449 /* *INDENT-ON* */
1450 
1451 #ifndef CLIB_MARCH_VARIANT
1452 clib_error_t *
1454  u32 hw_if_index,
1455  u32 is_create)
1456 {
1457  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1458  u32 next_index;
1459 
1460  if (hi->output_node_index == 0)
1461  return 0;
1462 
1463  next_index = vlib_node_add_next
1464  (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
1465  hi->output_node_index);
1466  hi->output_node_next_index = next_index;
1467 
1468  return 0;
1469 }
1470 
1473 
1474 void
1476  u32 hw_if_index, u32 node_index)
1477 {
1478  ASSERT (node_index);
1479  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1480  u32 next_index = vlib_node_add_next
1481  (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index);
1482  hi->output_node_next_index = next_index;
1483  hi->output_node_index = node_index;
1484 }
1485 #endif /* CLIB_MARCH_VARIANT */
1486 
1487 /*
1488  * fd.io coding-style-patch-verification: ON
1489  *
1490  * Local Variables:
1491  * eval: (c-set-style "gnu")
1492  * End:
1493  */
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:302
#define CLIB_UNUSED(x)
Definition: clib.h:83
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:113
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
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:100
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:112
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
u8 data[]
Packet data.
Definition: buffer.h:181
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:768
static_always_inline uword clib_count_equal_u32(u32 *data, uword max_count)
Definition: string.h:518
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:67
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