FD.io VPP  v19.08.1-401-g8e4ed521a
Vector Packet Processing
ping.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 #include <stddef.h>
17 
18 #include <vlib/vlib.h>
19 #include <vnet/fib/ip6_fib.h>
20 #include <vnet/fib/ip4_fib.h>
21 #include <vnet/fib/fib_entry.h>
22 #include <vnet/plugin/plugin.h>
23 #include <vpp/app/version.h>
24 
25 #include <vnet/ip/icmp4.h>
26 #include <ping/ping.h>
27 
29 
30 /**
31  * @file
32  * @brief IPv4 and IPv6 ICMP Ping.
33  *
34  * This file contains code to support IPv4 or IPv6 ICMP ECHO_REQUEST to
35  * network hosts.
36  *
37  */
38 
39 typedef struct
40 {
46 
47 
48 u8 *
49 format_icmp_echo_trace (u8 * s, va_list * va)
50 {
51  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
52  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
53  icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
54 
55  s =
56  format (s, "ICMP%s echo id %d seq %d", t->is_ip6 ? "6" : "4", t->id,
57  t->seq);
59  {
60  s = format (s, " (unknown)");
61  }
62  else
63  {
64  s = format (s, " send to cli node %d", t->cli_process_node);
65  }
66 
67  return s;
68 }
69 
70 
71 static u8 *
72 format_ip46_ping_result (u8 * s, va_list * args)
73 {
75 
76  switch (res)
77  {
78 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break;
80 #undef _
81  }
82 
83  return (s);
84 }
85 
86 
87 /*
88  * Poor man's get-set-clear functions
89  * for manipulation of icmp_id -> cli_process_id
90  * mappings.
91  *
92  * There should normally be very few (0..1..2) of these
93  * mappings, so the linear search is a good strategy.
94  *
95  * Make them thread-safe via a simple spinlock.
96  *
97  */
98 
99 
102 {
103  ping_main_t *pm = &ping_main;
104  uword cli_process_id = PING_CLI_UNKNOWN_NODE;
105  ping_run_t *pr;
106 
108  vec_foreach (pr, pm->active_ping_runs)
109  {
110  if (pr->icmp_id == icmp_id)
111  {
112  cli_process_id = pr->cli_process_id;
113  break;
114  }
115  }
117  return cli_process_id;
118 }
119 
120 
123  uword cli_process_id)
124 {
125  ping_main_t *pm = &ping_main;
126  ping_run_t *pr;
127 
129  vec_foreach (pr, pm->active_ping_runs)
130  {
131  if (pr->icmp_id == icmp_id)
132  {
133  pr->cli_process_id = cli_process_id;
134  goto have_found_and_set;
135  }
136  }
137  /* no such key yet - add a new one */
138  ping_run_t new_pr = {.icmp_id = icmp_id,.cli_process_id = cli_process_id };
139  vec_add1 (pm->active_ping_runs, new_pr);
140 have_found_and_set:
142 }
143 
144 
147 {
148  ping_main_t *pm = &ping_main;
149  ping_run_t *pr;
150 
152  vec_foreach (pr, pm->active_ping_runs)
153  {
154  if (pr->icmp_id == icmp_id)
155  {
157  break;
158  }
159  }
161 }
162 
165  u16 * out_icmp_id, u16 * out_icmp_seq, int is_ip6)
166 {
167  int l4_offset;
168  if (is_ip6)
169  {
171  if (ip6->protocol != IP_PROTOCOL_ICMP6)
172  {
173  return 0;
174  }
175  l4_offset = sizeof (*ip6); // IPv6 EH
176  }
177  else
178  {
180  l4_offset = ip4_header_bytes (ip4);
181 
182  }
183  icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
184  icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
185 
186  *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
187  *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
188  return 1;
189 }
190 
191 /*
192  * post the buffer to a given cli process node - the caller should forget bi0 after return.
193  */
194 
197  int is_ip6)
198 {
199  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
200  u64 nowts = clib_cpu_time_now ();
201 
202  /* Pass the timestamp to the cli_process thanks to the vnet_buffer unused metadata field */
203 
204  /* Camping on unused data... just ensure statically that there is enough space */
205  STATIC_ASSERT (ARRAY_LEN (vnet_buffer (b0)->unused) *
206  sizeof (vnet_buffer (b0)->unused[0]) > sizeof (nowts),
207  "ping reply timestamp fits within remaining space of vnet_buffer unused data");
208  u64 *pnowts = (void *) &vnet_buffer (b0)->unused[0];
209  *pnowts = nowts;
210 
211  u32 event_id = is_ip6 ? PING_RESPONSE_IP6 : PING_RESPONSE_IP4;
212  vlib_process_signal_event_mt (vm, cli_process_id, event_id, bi0);
213 }
214 
215 
218  vlib_node_runtime_t * node,
219  uword cli_process_id, u16 id, u16 seq,
220  vlib_buffer_t * b0, int is_ip6)
221 {
222  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
223  {
224  icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
225  tr->id = id;
226  tr->seq = seq;
227  tr->cli_process_node = cli_process_id;
228  tr->is_ip6 = is_ip6;
229  }
230 }
231 
232 
235  vlib_node_runtime_t * node,
236  vlib_frame_t * frame, int do_trace,
237  int is_ip6)
238 {
239  u32 n_left_from, *from, *to_next;
240  icmp46_echo_reply_next_t next_index;
241 
242  from = vlib_frame_vector_args (frame);
243  n_left_from = frame->n_vectors;
244 
245  next_index = node->cached_next_index;
246 
247  while (n_left_from > 0)
248  {
249  u32 n_left_to_next;
250  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
251 
252  while (n_left_from > 0 && n_left_to_next > 0)
253  {
254  u32 bi0;
255  vlib_buffer_t *b0;
256  /*
257  * The buffers (replies) are either posted to the CLI thread
258  * awaiting for them for subsequent analysis and disposal,
259  * or are sent to the punt node.
260  *
261  * So the only "next" node is a punt, normally.
262  */
264 
265  bi0 = from[0];
266  b0 = vlib_get_buffer (vm, bi0);
267  from += 1;
268  n_left_from -= 1;
269 
270  u16 icmp_id = ~0;
271  u16 icmp_seq = ~0;
272  uword cli_process_id = PING_CLI_UNKNOWN_NODE;
273 
274  if (ip46_get_icmp_id_and_seq (vm, b0, &icmp_id, &icmp_seq, is_ip6))
275  {
276  cli_process_id = get_cli_process_id_by_icmp_id_mt (vm, icmp_id);
277  }
278 
279  if (do_trace)
280  ip46_echo_reply_maybe_trace_buffer (vm, node, cli_process_id,
281  icmp_id, icmp_seq, b0,
282  is_ip6);
283 
284  if (~0 == cli_process_id)
285  {
286  /* no outstanding requests for this reply, punt */
287  /* speculatively enqueue b0 to the current next frame */
288  to_next[0] = bi0;
289  to_next += 1;
290  n_left_to_next -= 1;
291  /* verify speculative enqueue, maybe switch current next frame */
292  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
293  to_next, n_left_to_next,
294  bi0, next0);
295  }
296  else
297  {
298  /* Post the buffer to CLI thread. It will take care of freeing it. */
299  ip46_post_icmp_reply_event (vm, cli_process_id, bi0, is_ip6);
300  }
301  }
302  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
303  }
304  return frame->n_vectors;
305 }
306 
307 /*
308  * select "with-trace" or "without-trace" codepaths upfront.
309  */
312  vlib_node_runtime_t * node,
313  vlib_frame_t * frame, int is_ip6)
314 {
315  if (node->flags & VLIB_NODE_FLAG_TRACE)
316  return ip46_icmp_echo_reply_inner_node_fn (vm, node, frame,
317  1 /* do_trace */ , is_ip6);
318  else
319  return ip46_icmp_echo_reply_inner_node_fn (vm, node, frame,
320  0 /* do_trace */ , is_ip6);
321 }
322 
323 static uword
325  vlib_node_runtime_t * node, vlib_frame_t * frame)
326 {
327  return ip46_icmp_echo_reply_outer_node_fn (vm, node, frame,
328  0 /* is_ip6 */ );
329 }
330 
331 static uword
333  vlib_node_runtime_t * node, vlib_frame_t * frame)
334 {
335  return ip46_icmp_echo_reply_outer_node_fn (vm, node, frame,
336  1 /* is_ip6 */ );
337 }
338 
339 /* *INDENT-OFF* */
341 {
342  .function = ip6_icmp_echo_reply_node_fn,
343  .name = "ip6-icmp-echo-reply",
344  .vector_size = sizeof (u32),
345  .format_trace = format_icmp_echo_trace,
346  .n_next_nodes = ICMP46_ECHO_REPLY_N_NEXT,
347  .next_nodes = {
348  [ICMP46_ECHO_REPLY_NEXT_DROP] = "ip6-drop",
349  [ICMP46_ECHO_REPLY_NEXT_PUNT] = "ip6-punt",
350  },
351 };
352 
354 {
355  .function = ip4_icmp_echo_reply_node_fn,
356  .name = "ip4-icmp-echo-reply",
357  .vector_size = sizeof (u32),
358  .format_trace = format_icmp_echo_trace,
359  .n_next_nodes = ICMP46_ECHO_REPLY_N_NEXT,
360  .next_nodes = {
361  [ICMP46_ECHO_REPLY_NEXT_DROP] = "ip4-drop",
362  [ICMP46_ECHO_REPLY_NEXT_PUNT] = "ip4-punt",
363  },
364 };
365 /* *INDENT-ON* */
366 
367 
368 /*
369  * A swarm of address-family agnostic helper functions
370  * for building and sending the ICMP echo request.
371  *
372  * Deliberately mostly "static" rather than "static inline"
373  * so one can trace them sanely if needed in debugger, if needed.
374  *
375  */
376 
379 {
380  return (offset % 256);
381 }
382 
383 /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
384 static u16
386  int l4_header_offset,
387  icmp46_echo_request_t * icmp46_echo, u16 seq_host,
388  u16 id_host, u64 now, u16 data_len)
389 {
390  int i;
391 
392 
393  int l34_len =
394  l4_header_offset + sizeof (icmp46_header_t) +
395  offsetof (icmp46_echo_request_t, data);
396  int max_data_len = vlib_buffer_get_default_data_size (vm) - l34_len;
397 
398  int first_buf_data_len = data_len < max_data_len ? data_len : max_data_len;
399 
400  int payload_offset = 0;
401  for (i = 0; i < first_buf_data_len; i++)
402  icmp46_echo->data[i] = get_icmp_echo_payload_byte (payload_offset++);
403 
404  /* inspired by vlib_buffer_add_data */
405  vlib_buffer_t *hb = b0;
406  int remaining_data_len = data_len - first_buf_data_len;
407  while (remaining_data_len)
408  {
409  int this_buf_data_len =
410  remaining_data_len <
411  vlib_buffer_get_default_data_size (vm) ? remaining_data_len :
413  int n_alloc = vlib_buffer_alloc (vm, &b0->next_buffer, 1);
414  if (n_alloc < 1)
415  {
416  /* That is how much we have so far - return it... */
417  return (data_len - remaining_data_len);
418  }
419  b0->flags |= VLIB_BUFFER_NEXT_PRESENT;
420  /* move on to the newly acquired buffer */
421  b0 = vlib_get_buffer (vm, b0->next_buffer);
422  /* initialize the data */
423  for (i = 0; i < this_buf_data_len; i++)
424  {
425  b0->data[i] = get_icmp_echo_payload_byte (payload_offset++);
426  }
427  b0->current_length = this_buf_data_len;
428  b0->current_data = 0;
429  remaining_data_len -= this_buf_data_len;
430  }
431  hb->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
432  hb->current_length = l34_len + first_buf_data_len;
433  hb->total_length_not_including_first_buffer = data_len - first_buf_data_len;
434 
435  icmp46_echo->time_sent = now;
436  icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
437  icmp46_echo->id = clib_host_to_net_u16 (id_host);
438  return data_len;
439 }
440 
441 
442 static u32
444 {
445  u32 fib_index = is_ip6 ?
446  ip6_fib_index_from_table_id (table_id) :
447  ip4_fib_index_from_table_id (table_id);
448  return fib_index;
449 }
450 
451 static fib_node_index_t
452 ip46_fib_table_lookup_host (u32 fib_index, ip46_address_t * pa46, int is_ip6)
453 {
454  fib_node_index_t fib_entry_index = is_ip6 ?
455  ip6_fib_table_lookup (fib_index, &pa46->ip6, 128) :
456  ip4_fib_table_lookup (ip4_fib_get (fib_index), &pa46->ip4, 32);
457  return fib_entry_index;
458 }
459 
460 static u32
461 ip46_get_resolving_interface (u32 fib_index, ip46_address_t * pa46,
462  int is_ip6)
463 {
464  u32 sw_if_index = ~0;
465  if (~0 != fib_index)
466  {
467  fib_node_index_t fib_entry_index;
468  fib_entry_index = ip46_fib_table_lookup_host (fib_index, pa46, is_ip6);
469  sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
470  }
471  return sw_if_index;
472 }
473 
474 static u32
476 {
477  u32 fib_table_index = is_ip6 ?
480  return fib_table_index;
481 
482 }
483 
484 
485 static int
486 ip46_fill_l3_header (ip46_address_t * pa46, vlib_buffer_t * b0, int is_ip6)
487 {
488  if (is_ip6)
489  {
491  /* Fill in ip6 header fields */
493  clib_host_to_net_u32 (0x6 << 28);
494  ip6->payload_length = 0; /* will be set later */
495  ip6->protocol = IP_PROTOCOL_ICMP6;
496  ip6->hop_limit = 255;
497  ip6->dst_address = pa46->ip6;
498  ip6->src_address = pa46->ip6;
499  return (sizeof (ip6_header_t));
500  }
501  else
502  {
504  /* Fill in ip4 header fields */
505  ip4->checksum = 0;
506  ip4->ip_version_and_header_length = 0x45;
507  ip4->tos = 0;
508  ip4->length = 0; /* will be set later */
509  ip4->fragment_id = 0;
510  ip4->flags_and_fragment_offset = 0;
511  ip4->ttl = 0xff;
512  ip4->protocol = IP_PROTOCOL_ICMP;
513  ip4->src_address = pa46->ip4;
514  ip4->dst_address = pa46->ip4;
515  return (sizeof (ip4_header_t));
516  }
517 }
518 
519 static int
521 {
522  int res;
523  if (is_ip6)
524  {
525  ip6_main_t *im = &ip6_main;
527  res =
528  ip6_src_address_for_packet (&im->lookup_main, sw_if_index,
529  &ip6->dst_address, &ip6->src_address);
530  }
531  else
532  {
533  ip4_main_t *im = &ip4_main;
535  res =
536  ip4_src_address_for_packet (&im->lookup_main, sw_if_index,
537  &ip4->src_address);
538  /* IP4 and IP6 paths have the inverse logic. Harmonize. */
539  res = !res;
540  }
541  return res;
542 }
543 
544 static void
546  int is_ip6)
547 {
548  void *format_addr_func;
549  void *paddr;
550  if (is_ip6)
551  {
553  format_addr_func = format_ip6_address;
554  paddr = &ip6->src_address;
555  }
556  else
557  {
559  format_addr_func = format_ip4_address;
560  paddr = &ip4->src_address;
561  }
562  vlib_cli_output (vm, "Source address: %U ", format_addr_func, paddr);
563 }
564 
565 static u16
566 ip46_fill_icmp_request_at (vlib_main_t * vm, int l4_offset, u16 seq_host,
567  u16 id_host, u16 data_len, vlib_buffer_t * b0,
568  int is_ip6)
569 {
570  icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
571 
572  icmp46->type = is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
573  icmp46->code = 0;
574  icmp46->checksum = 0;
575 
576  icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
577 
578  data_len =
579  init_icmp46_echo_request (vm, b0, l4_offset, icmp46_echo, seq_host,
580  id_host, clib_cpu_time_now (), data_len);
581  return data_len;
582 }
583 
584 
585 /* Compute ICMP4 checksum with multibuffer support. */
586 u16
588  ip4_header_t * ip0)
589 {
590  ip_csum_t sum0;
591  u32 ip_header_length, payload_length_host_byte_order;
592  u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
593  u16 sum16;
594  void *data_this_buffer;
595 
596  ip_header_length = ip4_header_bytes (ip0);
597  payload_length_host_byte_order =
598  clib_net_to_host_u16 (ip0->length) - ip_header_length;
599 
600  /* ICMP4 checksum does not include the IP header */
601  sum0 = 0;
602 
603  n_bytes_left = n_this_buffer = payload_length_host_byte_order;
604  data_this_buffer = (void *) ip0 + ip_header_length;
605  n_ip_bytes_this_buffer =
606  p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
607  if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
608  {
609  n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
610  n_ip_bytes_this_buffer - ip_header_length : 0;
611  }
612  while (1)
613  {
614  sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
615  n_bytes_left -= n_this_buffer;
616  if (n_bytes_left == 0)
617  break;
618 
619  ASSERT (p0->flags & VLIB_BUFFER_NEXT_PRESENT);
620  p0 = vlib_get_buffer (vm, p0->next_buffer);
621  data_this_buffer = vlib_buffer_get_current (p0);
622  n_this_buffer = p0->current_length;
623  }
624 
625  sum16 = ~ip_csum_fold (sum0);
626 
627  return sum16;
628 }
629 
630 
631 static void
632 ip46_fix_len_and_csum (vlib_main_t * vm, int l4_offset, u16 data_len,
633  vlib_buffer_t * b0, int is_ip6)
634 {
635  u16 payload_length =
636  data_len + sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
637  data);
638  u16 total_length = payload_length + l4_offset;
639  icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
640  icmp46->checksum = 0;
641 
642  if (is_ip6)
643  {
645  ip6->payload_length = clib_host_to_net_u16 (payload_length);
646 
647  int bogus_length = 0;
648  icmp46->checksum =
649  ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus_length);
650  }
651  else
652  {
654  ip4->length = clib_host_to_net_u16 (total_length);
655 
656  ip4->checksum = ip4_header_checksum (ip4);
657  icmp46->checksum = ip4_icmp_compute_checksum (vm, b0, ip4);
658  }
659 }
660 
661 static u16
663 {
664  return count > VLIB_FRAME_SIZE ? VLIB_FRAME_SIZE : count;
665 }
666 
667 static int
669  int is_ip6)
670 {
671  vlib_frame_t *f = 0;
672  u32 lookup_node_index =
673  is_ip6 ? ip6_lookup_node.index : ip4_lookup_node.index;
674  int n_sent = 0;
675 
676  u16 n_to_send;
677 
678  /*
679  * Enqueue the packet, possibly as one or more frames of copies to make
680  * bursts. We enqueue b0 as the very last buffer, when there is no possibility
681  * for error in vlib_buffer_copy, so as to allow the caller to free it
682  * in case we encounter the error in the middle of the loop.
683  */
684  for (n_to_send = at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
685  n_to_send = at_most_a_frame (burst), burst -= n_to_send)
686  {
687  f = vlib_get_frame_to_node (vm, lookup_node_index);
688  /* f can not be NULL here - frame allocation failure causes panic */
689 
690  u32 *to_next = vlib_frame_vector_args (f);
691  f->n_vectors = n_to_send;
692 
693  while (n_to_send > 1)
694  {
695  vlib_buffer_t *b0copy = vlib_buffer_copy (vm, b0);
696  if (PREDICT_FALSE (b0copy == NULL))
697  goto ship_and_ret;
698  *to_next++ = vlib_get_buffer_index (vm, b0copy);
699  n_to_send--;
700  n_sent++;
701  }
702 
703  /* n_to_send is guaranteed to equal 1 here */
704  if (burst > 0)
705  {
706  /* not the last burst, so still make a copy for the last buffer */
707  vlib_buffer_t *b0copy = vlib_buffer_copy (vm, b0);
708  if (PREDICT_FALSE (b0copy == NULL))
709  goto ship_and_ret;
710  n_to_send--;
711  *to_next++ = vlib_get_buffer_index (vm, b0copy);
712  }
713  else
714  {
715  /* put the original buffer as the last one of an error-free run */
716  *to_next++ = vlib_get_buffer_index (vm, b0);
717  }
718  vlib_put_frame_to_node (vm, lookup_node_index, f);
719  n_sent += f->n_vectors;
720  }
721  return n_sent;
722  /*
723  * We reach here in case we already enqueued one or more buffers
724  * and maybe one or more frames but could not make more copies.
725  * There is an outstanding frame - so ship it and return.
726  * Caller will have to free the b0 in this case, since
727  * we did not enqueue it here yet.
728  */
729 ship_and_ret:
730  ASSERT (n_to_send <= f->n_vectors);
731  f->n_vectors -= n_to_send;
732  n_sent += f->n_vectors;
733  vlib_put_frame_to_node (vm, lookup_node_index, f);
734  return n_sent;
735 }
736 
737 
738 /*
739  * An address-family agnostic ping send function.
740  */
741 
742 #define ERROR_OUT(e) do { err = e; goto done; } while (0)
743 
746  u32 table_id,
747  ip46_address_t * pa46,
749  u16 seq_host, u16 id_host, u16 data_len, u32 burst,
750  u8 verbose, int is_ip6)
751 {
752  int err = SEND_PING_OK;
753  u32 bi0 = 0;
754  int n_buf0 = 0;
755  vlib_buffer_t *b0;
756 
757  n_buf0 = vlib_buffer_alloc (vm, &bi0, 1);
758  if (n_buf0 < 1)
759  ERROR_OUT (SEND_PING_ALLOC_FAIL);
760 
761  b0 = vlib_get_buffer (vm, bi0);
763 
764  /*
765  * if the user did not provide a source interface,
766  * perform a resolution and use an interface
767  * via which it succeeds.
768  */
769  u32 fib_index;
770  if (~0 == sw_if_index)
771  {
772  fib_index = ip46_fib_index_from_table_id (table_id, is_ip6);
773  sw_if_index = ip46_get_resolving_interface (fib_index, pa46, is_ip6);
774  }
775  else
776  fib_index =
777  ip46_fib_table_get_index_for_sw_if_index (sw_if_index, is_ip6);
778 
779  if (~0 == fib_index)
780  ERROR_OUT (SEND_PING_NO_TABLE);
781  if (~0 == sw_if_index)
782  ERROR_OUT (SEND_PING_NO_INTERFACE);
783 
784  vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index;
785  vnet_buffer (b0)->sw_if_index[VLIB_TX] = fib_index;
786 
787  int l4_header_offset = ip46_fill_l3_header (pa46, b0, is_ip6);
788 
789  /* set the src address in the buffer */
790  if (!ip46_set_src_address (sw_if_index, b0, is_ip6))
791  ERROR_OUT (SEND_PING_NO_SRC_ADDRESS);
792  if (verbose)
793  ip46_print_buffer_src_address (vm, b0, is_ip6);
794 
795  data_len =
796  ip46_fill_icmp_request_at (vm, l4_header_offset, seq_host, id_host,
797  data_len, b0, is_ip6);
798 
799  ip46_fix_len_and_csum (vm, l4_header_offset, data_len, b0, is_ip6);
800 
801  int n_sent = ip46_enqueue_packet (vm, b0, burst, is_ip6);
802  if (n_sent < burst)
803  err = SEND_PING_NO_BUFFERS;
804 
805 done:
806  if (err != SEND_PING_OK)
807  {
808  if (n_buf0 > 0)
809  vlib_buffer_free (vm, &bi0, 1);
810  }
811  return err;
812 }
813 
816  u32 table_id, ip6_address_t * pa6,
817  u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
818  u32 burst, u8 verbose)
819 {
820  ip46_address_t target;
821  target.ip6 = *pa6;
822  return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
823  id_host, data_len, burst, verbose, 1 /* is_ip6 */ );
824 }
825 
828  u32 table_id, ip4_address_t * pa4,
829  u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
830  u32 burst, u8 verbose)
831 {
832  ip46_address_t target;
833  ip46_address_set_ip4 (&target, pa4);
834  return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
835  id_host, data_len, burst, verbose, 0 /* is_ip6 */ );
836 }
837 
838 static void
840 {
841  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
842  int l4_offset;
843  void *paddr;
844  void *format_addr_func;
845  u16 payload_length;
846  u8 ttl;
847  if (is_ip6)
848  {
850  paddr = (void *) &ip6->src_address;
851  format_addr_func = (void *) format_ip6_address;
852  ttl = ip6->hop_limit;
853  l4_offset = sizeof (ip6_header_t); // FIXME - EH processing ?
854  payload_length = clib_net_to_host_u16 (ip6->payload_length);
855  }
856  else
857  {
859  paddr = (void *) &ip4->src_address;
860  format_addr_func = (void *) format_ip4_address;
861  ttl = ip4->ttl;
862  l4_offset = ip4_header_bytes (ip4);
863  payload_length =
864  clib_net_to_host_u16 (ip4->length) + ip4_header_bytes (ip4);
865  }
866  icmp46_header_t *icmp = vlib_buffer_get_current (b0) + l4_offset;
867  icmp46_echo_request_t *icmp_echo = (icmp46_echo_request_t *) (icmp + 1);
868  u64 *dataplane_ts = (u64 *) & vnet_buffer (b0)->unused[0];
869 
870  f64 clocks_per_second = ((f64) vm->clib_time.clocks_per_second);
871  f64 rtt =
872  ((f64) (*dataplane_ts - icmp_echo->time_sent)) / clocks_per_second;
873 
874  vlib_cli_output (vm,
875  "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
876  payload_length,
877  format_addr_func,
878  paddr,
879  clib_host_to_net_u16 (icmp_echo->seq), ttl, rtt * 1000.0);
880 }
881 
882 /*
883  * Perform the ping run with the given parameters in the current CLI process.
884  * Depending on whether pa4 or pa6 is set, runs IPv4 or IPv6 ping.
885  * The amusing side effect is of course if both are set, then both pings are sent.
886  * This behavior can be used to ping a dualstack host over IPv4 and IPv6 at once.
887  */
888 
889 static void
892  f64 ping_interval, u32 ping_repeat, u32 data_len,
893  u32 ping_burst, u32 verbose)
894 {
895  int i;
896  uword curr_proc = vlib_current_process (vm);
897  u32 n_replies = 0;
898  u32 n_requests = 0;
899  u16 icmp_id;
900 
901  static u32 rand_seed = 0;
902 
903  if (PREDICT_FALSE (!rand_seed))
904  rand_seed = random_default_seed ();
905 
906  icmp_id = random_u32 (&rand_seed) & 0xffff;
907 
908  while (~0 != get_cli_process_id_by_icmp_id_mt (vm, icmp_id))
909  {
910  vlib_cli_output (vm, "ICMP ID collision at %d, incrementing", icmp_id);
911  icmp_id++;
912  }
913 
914  set_cli_process_id_by_icmp_id_mt (vm, icmp_id, curr_proc);
915 
916  for (i = 1; i <= ping_repeat; i++)
917  {
918  send_ip46_ping_result_t res = SEND_PING_OK;
919  f64 sleep_interval;
920  f64 time_ping_sent = vlib_time_now (vm);
921  if (pa6)
922  {
923  res = send_ip6_ping (vm, table_id,
924  pa6, sw_if_index, i, icmp_id,
925  data_len, ping_burst, verbose);
926  if (SEND_PING_OK == res)
927  n_requests += ping_burst;
928  else
929  vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
930  }
931  if (pa4)
932  {
933  res = send_ip4_ping (vm, table_id, pa4,
934  sw_if_index, i, icmp_id, data_len,
935  ping_burst, verbose);
936  if (SEND_PING_OK == res)
937  n_requests += ping_burst;
938  else
939  vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
940  }
941 
942  /* Collect and print the responses until it is time to send a next ping */
943 
944  while ((i <= ping_repeat)
945  &&
946  ((sleep_interval =
947  time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
948  {
949  uword event_type, *event_data = 0;
950  vlib_process_wait_for_event_or_clock (vm, sleep_interval);
951  event_type = vlib_process_get_events (vm, &event_data);
952  switch (event_type)
953  {
954  case ~0: /* no events => timeout */
955  break;
956  case PING_RESPONSE_IP6:
957  /* fall-through */
958  case PING_RESPONSE_IP4:
959  {
960  int ii;
961  int is_ip6 = (event_type == PING_RESPONSE_IP6);
962  for (ii = 0; ii < vec_len (event_data); ii++)
963  {
964  u32 bi0 = event_data[ii];
965  print_ip46_icmp_reply (vm, bi0, is_ip6);
966  n_replies++;
967  if (0 != bi0)
968  vlib_buffer_free (vm, &bi0, 1);
969  }
970  }
971  break;
972  default:
973  /* someone pressed a key, abort */
974  vlib_cli_output (vm, "Aborted due to a keypress.");
975  goto double_break;
976  break;
977  }
978  vec_free (event_data);
979  }
980  }
981 double_break:
982  vlib_cli_output (vm, "\n");
983  {
984  float loss =
985  (0 ==
986  n_requests) ? 0 : 100.0 * ((float) n_requests -
987  (float) n_replies) / (float) n_requests;
988  vlib_cli_output (vm,
989  "Statistics: %u sent, %u received, %f%% packet loss\n",
990  n_requests, n_replies, loss);
992  }
993 }
994 
995 
996 
997 static clib_error_t *
999  unformat_input_t * input, vlib_cli_command_t * cmd)
1000 {
1001  ip4_address_t a4;
1002  ip6_address_t a6;
1003  clib_error_t *error = 0;
1004  u32 ping_repeat = 5;
1005  u32 ping_burst = 1;
1006  u8 ping_ip4, ping_ip6;
1007  vnet_main_t *vnm = vnet_get_main ();
1008  u32 data_len = PING_DEFAULT_DATA_LEN;
1009  u32 verbose = 0;
1010  f64 ping_interval = PING_DEFAULT_INTERVAL;
1012 
1013  table_id = 0;
1014  ping_ip4 = ping_ip6 = 0;
1015  sw_if_index = ~0;
1016 
1017  if (unformat (input, "%U", unformat_ip4_address, &a4))
1018  {
1019  ping_ip4 = 1;
1020  }
1021  else if (unformat (input, "%U", unformat_ip6_address, &a6))
1022  {
1023  ping_ip6 = 1;
1024  }
1025  else if (unformat (input, "ipv4"))
1026  {
1027  if (unformat (input, "%U", unformat_ip4_address, &a4))
1028  {
1029  ping_ip4 = 1;
1030  }
1031  else
1032  {
1033  error =
1034  clib_error_return (0,
1035  "expecting IPv4 address but got `%U'",
1036  format_unformat_error, input);
1037  }
1038  }
1039  else if (unformat (input, "ipv6"))
1040  {
1041  if (unformat (input, "%U", unformat_ip6_address, &a6))
1042  {
1043  ping_ip6 = 1;
1044  }
1045  else
1046  {
1047  error =
1048  clib_error_return (0,
1049  "expecting IPv6 address but got `%U'",
1050  format_unformat_error, input);
1051  }
1052  }
1053  else
1054  {
1055  error =
1056  clib_error_return (0,
1057  "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
1058  format_unformat_error, input);
1059  goto done;
1060  }
1061 
1062  /* allow for the second AF in the same ping */
1063  if (!ping_ip4 && (unformat (input, "ipv4")))
1064  {
1065  if (unformat (input, "%U", unformat_ip4_address, &a4))
1066  {
1067  ping_ip4 = 1;
1068  }
1069  }
1070  else if (!ping_ip6 && (unformat (input, "ipv6")))
1071  {
1072  if (unformat (input, "%U", unformat_ip6_address, &a6))
1073  {
1074  ping_ip6 = 1;
1075  }
1076  }
1077 
1078  /* parse the rest of the parameters in a cycle */
1079  while (!unformat_eof (input, NULL))
1080  {
1081  if (unformat (input, "source"))
1082  {
1083  if (!unformat_user
1084  (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1085  {
1086  error =
1087  clib_error_return (0,
1088  "unknown interface `%U'",
1089  format_unformat_error, input);
1090  goto done;
1091  }
1092  }
1093  else if (unformat (input, "size"))
1094  {
1095  if (!unformat (input, "%u", &data_len))
1096  {
1097  error =
1098  clib_error_return (0,
1099  "expecting size but got `%U'",
1100  format_unformat_error, input);
1101  goto done;
1102  }
1103  if (data_len > PING_MAXIMUM_DATA_SIZE)
1104  {
1105  error =
1106  clib_error_return (0,
1107  "%d is bigger than maximum allowed payload size %d",
1108  data_len, PING_MAXIMUM_DATA_SIZE);
1109  goto done;
1110  }
1111  }
1112  else if (unformat (input, "table-id"))
1113  {
1114  if (!unformat (input, "%u", &table_id))
1115  {
1116  error =
1117  clib_error_return (0,
1118  "expecting table-id but got `%U'",
1119  format_unformat_error, input);
1120  goto done;
1121  }
1122  }
1123  else if (unformat (input, "interval"))
1124  {
1125  if (!unformat (input, "%f", &ping_interval))
1126  {
1127  error =
1128  clib_error_return (0,
1129  "expecting interval (floating point number) got `%U'",
1130  format_unformat_error, input);
1131  goto done;
1132  }
1133  }
1134  else if (unformat (input, "repeat"))
1135  {
1136  if (!unformat (input, "%u", &ping_repeat))
1137  {
1138  error =
1139  clib_error_return (0,
1140  "expecting repeat count but got `%U'",
1141  format_unformat_error, input);
1142  goto done;
1143  }
1144  }
1145  else if (unformat (input, "burst"))
1146  {
1147  if (!unformat (input, "%u", &ping_burst))
1148  {
1149  error =
1150  clib_error_return (0,
1151  "expecting burst count but got `%U'",
1152  format_unformat_error, input);
1153  goto done;
1154  }
1155  }
1156  else if (unformat (input, "verbose"))
1157  {
1158  verbose = 1;
1159  }
1160  else
1161  {
1162  error = clib_error_return (0, "unknown input `%U'",
1163  format_unformat_error, input);
1164  goto done;
1165  }
1166  }
1167 
1168 /*
1169  * Operationally, one won't (and shouldn't) need to send more than a frame worth of pings.
1170  * But it may be handy during the debugging.
1171  */
1172 
1173 #ifdef CLIB_DEBUG
1174 #define MAX_PING_BURST (10*VLIB_FRAME_SIZE)
1175 #else
1176 #define MAX_PING_BURST (VLIB_FRAME_SIZE)
1177 #endif
1178 
1179  if (ping_burst < 1 || ping_burst > MAX_PING_BURST)
1180  return clib_error_return (0, "burst size must be between 1 and %u",
1181  MAX_PING_BURST);
1182 
1183  run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
1184  ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
1185  ping_repeat, data_len, ping_burst, verbose);
1186 done:
1187  return error;
1188 }
1189 
1190 /*?
1191  * This command sends an ICMP ECHO_REQUEST to network hosts. The address
1192  * can be an IPv4 or IPv6 address (or both at the same time).
1193  *
1194  * @cliexpar
1195  * @parblock
1196  * Example of how ping an IPv4 address:
1197  * @cliexstart{ping 172.16.1.2 source GigabitEthernet2/0/0 repeat 2}
1198  * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1090 ms
1199  * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0914 ms
1200  *
1201  * Statistics: 2 sent, 2 received, 0% packet loss
1202  * @cliexend
1203  *
1204  * Example of how ping both an IPv4 address and IPv6 address at the same time:
1205  * @cliexstart{ping 172.16.1.2 ipv6 fe80::24a5:f6ff:fe9c:3a36 source GigabitEthernet2/0/0 repeat 2 verbose}
1206  * Adjacency index: 10, sw_if_index: 1
1207  * Adj: ip6-discover-neighbor
1208  * Adj Interface: 0
1209  * Forced set interface: 1
1210  * Adjacency index: 0, sw_if_index: 4294967295
1211  * Adj: ip4-miss
1212  * Adj Interface: 0
1213  * Forced set interface: 1
1214  * Source address: 172.16.1.1
1215  * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1899 ms
1216  * Adjacency index: 10, sw_if_index: 1
1217  * Adj: ip6-discover-neighbor
1218  * Adj Interface: 0
1219  * Forced set interface: 1
1220  * Adjacency index: 0, sw_if_index: 4294967295
1221  * Adj: ip4-miss
1222  * Adj Interface: 0
1223  * Forced set interface: 1
1224  * Source address: 172.16.1.1
1225  * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0910 ms
1226  *
1227  * Statistics: 4 sent, 2 received, 50% packet loss
1228  * @cliexend
1229  * @endparblock
1230 ?*/
1231 /* *INDENT-OFF* */
1232 VLIB_CLI_COMMAND (ping_command, static) =
1233 {
1234  .path = "ping",
1235  .function = ping_ip_address,
1236  .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
1237  " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
1238  " [size <pktsize:60>] [interval <sec:1>] [repeat <cnt:5>] [table-id <id:0>]"
1239  " [burst <count:1>] [verbose]",
1240  .is_mp_safe = 1,
1241 };
1242 /* *INDENT-ON* */
1243 
1244 static clib_error_t *
1246 {
1248  ping_main_t *pm = &ping_main;
1249 
1250  pm->ip6_main = &ip6_main;
1251  pm->ip4_main = &ip4_main;
1252  icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
1253  ip4_icmp_register_type (vm, ICMP4_echo_reply,
1254  ip4_icmp_echo_reply_node.index);
1255  if (tm->n_vlib_mains > 1)
1257  return 0;
1258 }
1259 
1261 
1262 /* *INDENT-OFF* */
1263 VLIB_PLUGIN_REGISTER () = {
1264  .version = VPP_BUILD_VER,
1265  .description = "Ping (ping)",
1266 };
1267 /* *INDENT-ON* */
1268 
1269 /*
1270  * fd.io coding-style-patch-verification: ON
1271  *
1272  * Local Variables:
1273  * eval: (c-set-style "gnu")
1274  * End:
1275  */
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
static_always_inline void clear_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
Definition: ping.c:146
icmp46_echo_reply_next_t
Definition: ping.h:84
static void ip46_fix_len_and_csum(vlib_main_t *vm, int l4_offset, u16 data_len, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:632
#define CLIB_UNUSED(x)
Definition: clib.h:82
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)
Definition: random.h:91
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:673
static int ip46_fill_l3_header(ip46_address_t *pa46, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:486
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
ip4_address_t src_address
Definition: ip4_packet.h:170
static int ip46_set_src_address(u32 sw_if_index, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:520
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static uword vlib_current_process(vlib_main_t *vm)
Definition: node_funcs.h:400
unformat_function_t unformat_eof
Definition: format.h:293
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
unsigned long u64
Definition: types.h:89
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:279
f64 clocks_per_second
Definition: time.h:54
static u32 ip46_fib_index_from_table_id(u32 table_id, int is_ip6)
Definition: ping.c:443
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:110
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static_always_inline int ip46_get_icmp_id_and_seq(vlib_main_t *vm, vlib_buffer_t *b0, u16 *out_icmp_id, u16 *out_icmp_seq, int is_ip6)
Definition: ping.c:164
u8 data[0]
Packet data.
Definition: buffer.h:181
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static u64 clib_cpu_time_now(void)
Definition: time.h:81
static send_ip46_ping_result_t send_ip46_ping(vlib_main_t *vm, u32 table_id, ip46_address_t *pa46, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose, int is_ip6)
Definition: ping.c:745
clib_spinlock_t ping_run_check_lock
Definition: ping.h:60
int i
ip4_main_t * ip4_main
Definition: ping.h:56
static int ip46_enqueue_packet(vlib_main_t *vm, vlib_buffer_t *b0, u32 burst, int is_ip6)
Definition: ping.c:668
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
ip_lookup_main_t lookup_main
Definition: ip4.h:107
uword ip_csum_t
Definition: ip_packet.h:219
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u16 flags_and_fragment_offset
Definition: ip4_packet.h:151
unformat_function_t unformat_vnet_sw_interface
u8 data[128]
Definition: ipsec.api:251
clib_time_t clib_time
Definition: main.h:87
static u16 init_icmp46_echo_request(vlib_main_t *vm, vlib_buffer_t *b0, int l4_header_offset, icmp46_echo_request_t *icmp46_echo, u16 seq_host, u16 id_host, u64 now, u16 data_len)
Definition: ping.c:385
ip6_address_t src_address
Definition: ip6_packet.h:383
u8 * format_icmp_echo_trace(u8 *s, va_list *va)
Definition: ping.c:49
unsigned char u8
Definition: types.h:56
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:964
static void print_ip46_icmp_reply(vlib_main_t *vm, u32 bi0, int is_ip6)
Definition: ping.c:839
send_ip46_ping_result_t
Definition: ping.h:37
double f64
Definition: types.h:142
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
Definition: ip4_forward.c:101
static uword ip4_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ping.c:324
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip4_fib.c:224
format_function_t format_ip4_address
Definition: format.h:75
static_always_inline u8 get_icmp_echo_payload_byte(int offset)
Definition: ping.c:378
#define static_always_inline
Definition: clib.h:99
unformat_function_t unformat_ip4_address
Definition: format.h:70
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:516
ip4_address_t dst_address
Definition: ip4_packet.h:170
static u16 at_most_a_frame(u32 count)
Definition: ping.c:662
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:185
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
static u32 ip46_get_resolving_interface(u32 fib_index, ip46_address_t *pa46, int is_ip6)
Definition: ping.c:461
#define VLIB_FRAME_SIZE
Definition: node.h:378
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:326
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:257
static u8 * format_ip46_ping_result(u8 *s, va_list *args)
Definition: ping.c:72
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
void ip4_icmp_register_type(vlib_main_t *vm, icmp4_type_t type, u32 node_index)
Definition: icmp4.c:728
static clib_error_t * ping_cli_init(vlib_main_t *vm)
Definition: ping.c:1245
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:172
struct _unformat_input_t unformat_input_t
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
#define PREDICT_FALSE(x)
Definition: clib.h:111
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:804
#define MAX_PING_BURST
static u16 ip46_fill_icmp_request_at(vlib_main_t *vm, int l4_offset, u16 seq_host, u16 id_host, u16 data_len, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:566
#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_always_inline uword get_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
Definition: ping.c:101
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1458
unformat_function_t unformat_ip6_address
Definition: format.h:91
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:291
static int ip6_src_address_for_packet(ip_lookup_main_t *lm, u32 sw_if_index, const ip6_address_t *dst, ip6_address_t *src)
Definition: ip6.h:308
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define PING_DEFAULT_INTERVAL
Definition: ping.h:66
u16 n_vectors
Definition: node.h:397
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:323
static vlib_node_registration_t ip6_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node)
Definition: ping.c:340
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void vlib_process_signal_event_mt(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Signal event to process from any thread.
Definition: node_funcs.h:958
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
Definition: ip4_fib.h:113
static vlib_node_registration_t ip4_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node)
Definition: ping.c:353
ip6_main_t * ip6_main
Definition: ping.h:55
u8 ttl
Definition: fib_types.api:26
static send_ip46_ping_result_t send_ip4_ping(vlib_main_t *vm, u32 table_id, ip4_address_t *pa4, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
Definition: ping.c:827
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
ping_main_t ping_main
Definition: ping.c:28
static_always_inline uword ip46_icmp_echo_reply_outer_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip6)
Definition: ping.c:311
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:145
#define ARRAY_LEN(x)
Definition: clib.h:62
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 void run_ping_ip46_address(vlib_main_t *vm, u32 table_id, ip4_address_t *pa4, ip6_address_t *pa6, u32 sw_if_index, f64 ping_interval, u32 ping_repeat, u32 data_len, u32 ping_burst, u32 verbose)
Definition: ping.c:890
uword cli_process_id
Definition: ping.h:50
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
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
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
Definition: ip6_forward.c:656
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
ping_run_t * active_ping_runs
Definition: ping.h:58
#define ASSERT(truth)
static_always_inline void ip46_post_icmp_reply_event(vlib_main_t *vm, uword cli_process_id, u32 bi0, int is_ip6)
Definition: ping.c:196
ip6_main_t ip6_main
Definition: ip6_forward.c:2732
ip_lookup_main_t lookup_main
Definition: ip6.h:179
#define PING_MAXIMUM_DATA_SIZE
Definition: ping.h:68
ip_dscp_t tos
Definition: ip4_packet.h:141
#define ip46_address_set_ip4(ip46, ip)
Definition: ip6_packet.h:90
IPv4 main type.
Definition: ip4.h:105
size_t count
Definition: vapi.c:47
#define PING_CLI_UNKNOWN_NODE
Definition: ping.h:70
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
VLIB_PLUGIN_REGISTER()
template key/value backing page structure
Definition: bihash_doc.h:44
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:370
Definition: defs.h:47
u16 payload_length
Definition: ip6_packet.h:374
void icmp6_register_type(vlib_main_t *vm, icmp6_type_t type, u32 node_index)
Definition: icmp6.c:750
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define ERROR_OUT(e)
Definition: ping.c:742
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
u32 cli_process_node
Definition: ping.c:43
#define STATIC_ASSERT(truth,...)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:489
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static u32 ip46_fib_table_get_index_for_sw_if_index(u32 sw_if_index, int is_ip6)
Definition: ping.c:475
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
u16 ip4_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
Definition: ping.c:587
static void ip46_print_buffer_src_address(vlib_main_t *vm, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:545
static_always_inline void set_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id, uword cli_process_id)
Definition: ping.c:122
#define vnet_buffer(b)
Definition: buffer.h:365
static uword ip6_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ping.c:332
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
u16 icmp_id
Definition: ping.h:49
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1076
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define vec_foreach(var, vec)
Vector iterator.
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:172
u16 flags
Copy of main node flags.
Definition: node.h:509
#define PING_DEFAULT_DATA_LEN
Definition: ping.h:65
u32 id
Definition: udp.api:45
static int ip4_header_bytes(const ip4_header_t *i)
Definition: ip4_packet.h:235
u8 ip_version_and_header_length
Definition: ip4_packet.h:138
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
static clib_error_t * ping_ip_address(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ping.c:998
static_always_inline void ip46_echo_reply_maybe_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, uword cli_process_id, u16 id, u16 seq, vlib_buffer_t *b0, int is_ip6)
Definition: ping.c:217
static send_ip46_ping_result_t send_ip6_ping(vlib_main_t *vm, u32 table_id, ip6_address_t *pa6, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
Definition: ping.c:815
u32 table_id
Definition: fib_types.api:118
static_always_inline uword ip46_icmp_echo_reply_inner_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int do_trace, int is_ip6)
Definition: ping.c:234
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 fib_node_index_t ip46_fib_table_lookup_host(u32 fib_index, ip46_address_t *pa46, int is_ip6)
Definition: ping.c:452
static int ip4_src_address_for_packet(ip_lookup_main_t *lm, u32 sw_if_index, ip4_address_t *src)
Definition: ip4.h:211
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:95
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
Definition: ip_packet.h:293
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
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:275
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
Definition: defs.h:46
ip6_address_t dst_address
Definition: ip6_packet.h:383