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:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 #include <vnet/ip/ping.h>
18 #include <vnet/fib/ip6_fib.h>
19 #include <vnet/fib/ip4_fib.h>
20 #include <vnet/fib/fib_entry.h>
24 * @brief IPv4 and IPv6 ICMP Ping.
26 * This file contains code to suppport IPv4 or IPv6 ICMP ECHO_REQUEST to
33 format_icmp_echo_trace (u8 * s, va_list * va)
35 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
36 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
37 icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
39 s = format (s, "ICMP echo id %d seq %d%s",
40 clib_net_to_host_u16 (t->id),
41 clib_net_to_host_u16 (t->seq), t->bound ? "" : " (unknown)");
47 * If we can find the ping run by an ICMP ID, then we send the signal
48 * to the CLI process referenced by that ping run, alongside with
49 * a freshly made copy of the packet.
50 * I opted for a packet copy to keep the main packet processing path
51 * the same as for all the other nodes.
56 signal_ip46_icmp_reply_event (vlib_main_t * vm,
57 u8 event_type, vlib_buffer_t * b0)
59 ping_main_t *pm = &ping_main;
65 case PING_RESPONSE_IP4:
67 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
68 net_icmp_id = h0->icmp_echo.id;
71 case PING_RESPONSE_IP6:
73 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
74 net_icmp_id = h0->icmp_echo.id;
81 uword *p = hash_get (pm->ping_run_by_icmp_id,
82 clib_net_to_host_u16 (net_icmp_id));
86 ping_run_t *pr = vec_elt_at_index (pm->ping_runs, p[0]);
87 if (vlib_buffer_alloc (vm, &bi0_copy, 1) == 1)
89 void *dst = vlib_buffer_get_current (vlib_get_buffer (vm, bi0_copy));
90 clib_memcpy (dst, vlib_buffer_get_current (b0), b0->current_length);
92 /* If buffer_alloc failed, bi0_copy == 0 - just signaling an event. */
94 vlib_process_signal_event (vm, pr->cli_process_id, event_type, bi0_copy);
99 * Process ICMPv6 echo replies
102 ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
103 vlib_node_runtime_t * node, vlib_frame_t * frame)
105 u32 n_left_from, *from;
107 from = vlib_frame_vector_args (frame); /* array of buffer indices */
108 n_left_from = frame->n_vectors; /* number of buffer indices */
110 while (n_left_from > 0)
117 b0 = vlib_get_buffer (vm, bi0);
119 next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP6, b0) ?
120 ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
122 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
124 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
125 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
126 tr->id = h0->icmp_echo.id;
127 tr->seq = h0->icmp_echo.seq;
128 tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
131 /* push this pkt to the next graph node */
132 vlib_set_next_frame_buffer (vm, node, next0, bi0);
138 return frame->n_vectors;
142 VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
144 .function = ip6_icmp_echo_reply_node_fn,
145 .name = "ip6-icmp-echo-reply",
146 .vector_size = sizeof (u32),
147 .format_trace = format_icmp_echo_trace,
148 .n_next_nodes = ICMP6_ECHO_REPLY_N_NEXT,
150 [ICMP6_ECHO_REPLY_NEXT_DROP] = "error-drop",
151 [ICMP6_ECHO_REPLY_NEXT_PUNT] = "error-punt",
157 * Process ICMPv4 echo replies
160 ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
161 vlib_node_runtime_t * node, vlib_frame_t * frame)
163 u32 n_left_from, *from;
165 from = vlib_frame_vector_args (frame); /* array of buffer indices */
166 n_left_from = frame->n_vectors; /* number of buffer indices */
168 while (n_left_from > 0)
175 b0 = vlib_get_buffer (vm, bi0);
177 next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP4, b0) ?
178 ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
180 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
182 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
183 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
184 tr->id = h0->icmp_echo.id;
185 tr->seq = h0->icmp_echo.seq;
186 tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
189 /* push this pkt to the next graph node */
190 vlib_set_next_frame_buffer (vm, node, next0, bi0);
196 return frame->n_vectors;
200 VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) =
202 .function = ip4_icmp_echo_reply_node_fn,
203 .name = "ip4-icmp-echo-reply",
204 .vector_size = sizeof (u32),
205 .format_trace = format_icmp_echo_trace,
206 .n_next_nodes = ICMP4_ECHO_REPLY_N_NEXT,
208 [ICMP4_ECHO_REPLY_NEXT_DROP] = "error-drop",
209 [ICMP4_ECHO_REPLY_NEXT_PUNT] = "error-punt",
214 char *ip6_lookup_next_nodes[] = IP6_LOOKUP_NEXT_NODES;
215 char *ip4_lookup_next_nodes[] = IP4_LOOKUP_NEXT_NODES;
217 /* get first interface address */
218 static ip6_address_t *
219 ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
221 ip_lookup_main_t *lm = &im->lookup_main;
222 ip_interface_address_t *ia = 0;
223 ip6_address_t *result = 0;
226 foreach_ip_interface_address (lm, ia, sw_if_index,
227 1 /* honor unnumbered */ ,
230 ip_interface_address_get_address (lm, ia);
238 /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
240 init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
241 u16 seq_host, u16 id_host, u16 data_len)
244 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
245 icmp46_echo->id = clib_host_to_net_u16 (id_host);
247 if (data_len > PING_MAXIMUM_DATA_SIZE)
248 data_len = PING_MAXIMUM_DATA_SIZE;
249 for (i = 0; i < data_len; i++)
250 icmp46_echo->data[i] = i % 256;
254 static send_ip46_ping_result_t
255 send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
256 u32 table_id, ip6_address_t * pa6,
257 u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
260 icmp6_echo_request_header_t *h0;
262 int bogus_length = 0;
266 vlib_buffer_free_list_t *fl;
268 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
269 return SEND_PING_ALLOC_FAIL;
271 p0 = vlib_get_buffer (vm, bi0);
272 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
273 vlib_buffer_init_for_free_list (p0, fl);
274 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
277 * if the user did not provide a source interface, use the any interface
278 * that the destination resolves via.
280 if (~0 == sw_if_index)
282 fib_node_index_t fib_entry_index;
285 fib_index = ip6_fib_index_from_table_id (table_id);
289 vlib_buffer_free (vm, &bi0, 1);
290 return SEND_PING_NO_TABLE;
293 fib_entry_index = ip6_fib_table_lookup (fib_index, pa6, 128);
294 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
296 * Set the TX interface to force ip-lookup to use its table ID
298 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
303 * force an IP lookup in the table bound to the user's chosen
306 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
307 ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
310 if (~0 == sw_if_index)
312 vlib_buffer_free (vm, &bi0, 1);
313 return SEND_PING_NO_INTERFACE;
316 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
318 h0 = vlib_buffer_get_current (p0);
320 /* Fill in ip6 header fields */
321 h0->ip6.ip_version_traffic_class_and_flow_label =
322 clib_host_to_net_u32 (0x6 << 28);
323 h0->ip6.payload_length = 0; /* Set below */
324 h0->ip6.protocol = IP_PROTOCOL_ICMP6;
325 h0->ip6.hop_limit = 255;
326 h0->ip6.dst_address = *pa6;
327 h0->ip6.src_address = *pa6;
329 /* Fill in the correct source now */
330 ip6_address_t *a = ip6_interface_first_address (im, sw_if_index);
331 h0->ip6.src_address = a[0];
333 /* Fill in icmp fields */
334 h0->icmp.type = ICMP6_echo_request;
336 h0->icmp.checksum = 0;
339 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
340 h0->icmp_echo.time_sent = vlib_time_now (vm);
342 /* Fix up the lengths */
343 h0->ip6.payload_length =
344 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t));
346 p0->current_length = clib_net_to_host_u16 (h0->ip6.payload_length) +
347 STRUCT_OFFSET_OF (icmp6_echo_request_header_t, icmp);
349 /* Calculate the ICMP checksum */
350 h0->icmp.checksum = 0;
352 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip6, &bogus_length);
354 /* Enqueue the packet right now */
355 f = vlib_get_frame_to_node (vm, ip6_lookup_node.index);
356 to_next = vlib_frame_vector_args (f);
359 vlib_put_frame_to_node (vm, ip6_lookup_node.index, f);
364 static send_ip46_ping_result_t
365 send_ip4_ping (vlib_main_t * vm,
370 u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
372 icmp4_echo_request_header_t *h0;
374 ip_lookup_main_t *lm = &im->lookup_main;
379 vlib_buffer_free_list_t *fl;
381 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
382 return SEND_PING_ALLOC_FAIL;
384 p0 = vlib_get_buffer (vm, bi0);
385 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
386 vlib_buffer_init_for_free_list (p0, fl);
387 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
390 * if the user did not provide a source interface, use the any interface
391 * that the destination resolves via.
393 if (~0 == sw_if_index)
395 fib_node_index_t fib_entry_index;
398 fib_index = ip4_fib_index_from_table_id (table_id);
402 vlib_buffer_free (vm, &bi0, 1);
403 return SEND_PING_NO_TABLE;
407 ip4_fib_table_lookup (ip4_fib_get (fib_index), pa4, 32);
408 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
410 * Set the TX interface to force ip-lookup to use the user's table ID
412 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
417 * force an IP lookup in the table bound to the user's chosen
420 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
421 ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
424 if (~0 == sw_if_index)
426 vlib_buffer_free (vm, &bi0, 1);
427 return SEND_PING_NO_INTERFACE;
430 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
432 h0 = vlib_buffer_get_current (p0);
434 /* Fill in ip4 header fields */
435 h0->ip4.checksum = 0;
436 h0->ip4.ip_version_and_header_length = 0x45;
438 h0->ip4.length = 0; /* Set below */
439 h0->ip4.fragment_id = 0;
440 h0->ip4.flags_and_fragment_offset = 0;
442 h0->ip4.protocol = IP_PROTOCOL_ICMP;
443 h0->ip4.dst_address = *pa4;
444 h0->ip4.src_address = *pa4;
446 /* Fill in the correct source now */
447 if_add_index0 = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
448 if (PREDICT_TRUE (if_add_index0 != ~0))
450 ip_interface_address_t *if_add =
451 pool_elt_at_index (lm->if_address_pool, if_add_index0);
452 ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
453 h0->ip4.src_address = *if_ip;
456 vlib_cli_output (vm, "Source address: %U",
457 format_ip4_address, &h0->ip4.src_address);
461 /* Fill in icmp fields */
462 h0->icmp.type = ICMP4_echo_request;
464 h0->icmp.checksum = 0;
467 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
468 h0->icmp_echo.time_sent = vlib_time_now (vm);
470 /* Fix up the lengths */
472 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t) +
473 sizeof (ip4_header_t));
475 p0->current_length = clib_net_to_host_u16 (h0->ip4.length);
477 /* Calculate the IP and ICMP checksums */
478 h0->ip4.checksum = ip4_header_checksum (&(h0->ip4));
480 ~ip_csum_fold (ip_incremental_checksum (0, &(h0->icmp),
482 sizeof (ip4_header_t)));
484 /* Enqueue the packet right now */
485 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
486 to_next = vlib_frame_vector_args (f);
489 vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
496 print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0)
498 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
499 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
500 f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
503 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
504 clib_host_to_net_u16 (h0->ip6.payload_length),
506 &h0->ip6.src_address,
507 clib_host_to_net_u16 (h0->icmp_echo.seq),
508 h0->ip6.hop_limit, rtt * 1000.0);
512 print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
514 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
515 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
516 f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
518 clib_host_to_net_u16 (h0->ip4.length) -
519 (4 * (0xF & h0->ip4.ip_version_and_header_length));
522 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
525 &h0->ip4.src_address,
526 clib_host_to_net_u16 (h0->icmp_echo.seq),
527 h0->ip4.ttl, rtt * 1000.0);
532 * Perform the ping run with the given parameters in the current CLI process.
533 * Depending on whether pa4 or pa6 is set, runs IPv4 or IPv6 ping.
534 * The amusing side effect is of course if both are set, then both pings are sent.
535 * This behavior can be used to ping a dualstack host over IPv4 and IPv6 at once.
539 run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
540 ip6_address_t * pa6, u32 sw_if_index,
541 f64 ping_interval, u32 ping_repeat, u32 data_len,
545 ping_main_t *pm = &ping_main;
546 uword curr_proc = vlib_current_process (vm);
550 u32 ping_run_index = 0;
553 static u32 rand_seed = 0;
555 if (PREDICT_FALSE (!rand_seed))
556 rand_seed = random_default_seed ();
558 icmp_id = random_u32 (&rand_seed) & 0xffff;
560 while (hash_get (pm->ping_run_by_icmp_id, icmp_id))
562 vlib_cli_output (vm, "ICMP ID collision at %d, incrementing", icmp_id);
565 pool_get (pm->ping_runs, pr);
566 ping_run_index = pr - pm->ping_runs;
567 pr->cli_process_id = curr_proc;
568 pr->icmp_id = icmp_id;
569 hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index);
570 for (i = 1; i <= ping_repeat; i++)
573 f64 time_ping_sent = vlib_time_now (vm);
574 /* Reset pr: running ping in other process could have changed pm->ping_runs */
575 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
579 send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index,
580 i, icmp_id, data_len, verbose)))
586 send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index,
587 i, icmp_id, data_len, verbose)))
591 while ((i <= ping_repeat)
594 time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
596 uword event_type, *event_data = 0;
597 vlib_process_wait_for_event_or_clock (vm, sleep_interval);
598 event_type = vlib_process_get_events (vm, &event_data);
601 case ~0: /* no events => timeout */
603 case PING_RESPONSE_IP6:
606 for (i = 0; i < vec_len (event_data); i++)
608 u32 bi0 = event_data[i];
609 print_ip6_icmp_reply (vm, bi0);
613 vlib_buffer_free (vm, &bi0, 1);
618 case PING_RESPONSE_IP4:
621 for (i = 0; i < vec_len (event_data); i++)
623 u32 bi0 = event_data[i];
624 print_ip4_icmp_reply (vm, bi0);
628 vlib_buffer_free (vm, &bi0, 1);
634 /* someone pressed a key, abort */
635 vlib_cli_output (vm, "Aborted due to a keypress.");
641 vlib_cli_output (vm, "\n");
645 n_requests) ? 0 : 100.0 * ((float) n_requests -
646 (float) n_replies) / (float) n_requests;
648 "Statistics: %u sent, %u received, %f%% packet loss\n",
649 n_requests, n_replies, loss);
650 /* Reset pr: running ping in other process could have changed pm->ping_runs */
651 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
652 hash_unset (pm->ping_run_by_icmp_id, icmp_id);
653 pool_put (pm->ping_runs, pr);
661 static clib_error_t *
662 ping_ip_address (vlib_main_t * vm,
663 unformat_input_t * input, vlib_cli_command_t * cmd)
667 clib_error_t *error = 0;
669 u8 ping_ip4, ping_ip6;
670 vnet_main_t *vnm = vnet_get_main ();
671 u32 data_len = PING_DEFAULT_DATA_LEN;
673 f64 ping_interval = PING_DEFAULT_INTERVAL;
674 u32 sw_if_index, table_id;
677 ping_ip4 = ping_ip6 = 0;
680 if (unformat (input, "%U", unformat_ip4_address, &a4))
684 else if (unformat (input, "%U", unformat_ip6_address, &a6))
688 else if (unformat (input, "ipv4"))
690 if (unformat (input, "%U", unformat_ip4_address, &a4))
697 clib_error_return (0,
698 "expecting IPv4 address but got `%U'",
699 format_unformat_error, input);
702 else if (unformat (input, "ipv6"))
704 if (unformat (input, "%U", unformat_ip6_address, &a6))
711 clib_error_return (0,
712 "expecting IPv6 address but got `%U'",
713 format_unformat_error, input);
719 clib_error_return (0,
720 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
721 format_unformat_error, input);
725 /* allow for the second AF in the same ping */
726 if (!ping_ip4 && (unformat (input, "ipv4")))
728 if (unformat (input, "%U", unformat_ip4_address, &a4))
733 else if (!ping_ip6 && (unformat (input, "ipv6")))
735 if (unformat (input, "%U", unformat_ip6_address, &a6))
741 /* parse the rest of the parameters in a cycle */
742 while (!unformat_eof (input, NULL))
744 if (unformat (input, "source"))
747 (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
750 clib_error_return (0,
751 "unknown interface `%U'",
752 format_unformat_error, input);
756 else if (unformat (input, "size"))
758 if (!unformat (input, "%u", &data_len))
761 clib_error_return (0,
762 "expecting size but got `%U'",
763 format_unformat_error, input);
766 if (data_len > PING_MAXIMUM_DATA_SIZE)
769 clib_error_return (0,
770 "%d is bigger than maximum allowed payload size %d",
771 data_len, PING_MAXIMUM_DATA_SIZE);
775 else if (unformat (input, "table-id"))
777 if (!unformat (input, "du", &table_id))
780 clib_error_return (0,
781 "expecting table-id but got `%U'",
782 format_unformat_error, input);
786 else if (unformat (input, "interval"))
788 if (!unformat (input, "%f", &ping_interval))
791 clib_error_return (0,
792 "expecting interval (floating point number) got `%U'",
793 format_unformat_error, input);
797 else if (unformat (input, "repeat"))
799 if (!unformat (input, "%u", &ping_repeat))
802 clib_error_return (0,
803 "expecting repeat count but got `%U'",
804 format_unformat_error, input);
808 else if (unformat (input, "verbose"))
814 error = clib_error_return (0, "unknown input `%U'",
815 format_unformat_error, input);
820 run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
821 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
822 ping_repeat, data_len, verbose);
828 * This command sends an ICMP ECHO_REQUEST to network hosts. The address
829 * can be an IPv4 or IPv6 address (or both at the same time).
833 * Example of how ping an IPv4 address:
834 * @cliexstart{ping 172.16.1.2 source GigabitEthernet2/0/0 repeat 2}
835 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1090 ms
836 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0914 ms
838 * Statistics: 2 sent, 2 received, 0% packet loss
841 * Example of how ping both an IPv4 address and IPv6 address at the same time:
842 * @cliexstart{ping 172.16.1.2 ipv6 fe80::24a5:f6ff:fe9c:3a36 source GigabitEthernet2/0/0 repeat 2 verbose}
843 * Adjacency index: 10, sw_if_index: 1
844 * Adj: ip6-discover-neighbor
846 * Forced set interface: 1
847 * Adjacency index: 0, sw_if_index: 4294967295
850 * Forced set interface: 1
851 * Source address: 172.16.1.1
852 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1899 ms
853 * Adjacency index: 10, sw_if_index: 1
854 * Adj: ip6-discover-neighbor
856 * Forced set interface: 1
857 * Adjacency index: 0, sw_if_index: 4294967295
860 * Forced set interface: 1
861 * Source address: 172.16.1.1
862 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0910 ms
864 * Statistics: 4 sent, 2 received, 50% packet loss
869 VLIB_CLI_COMMAND (ping_command, static) =
872 .function = ping_ip_address,
873 .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
874 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
875 " [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>]"
880 static clib_error_t *
881 ping_cli_init (vlib_main_t * vm)
883 ping_main_t *pm = &ping_main;
884 pm->ip6_main = &ip6_main;
885 pm->ip4_main = &ip4_main;
886 icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
887 ip4_icmp_register_type (vm, ICMP4_echo_reply,
888 ip4_icmp_echo_reply_node.index);
892 VLIB_INIT_FUNCTION (ping_cli_init);
895 * fd.io coding-style-patch-verification: ON
898 * eval: (c-set-style "gnu")