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.
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vnet/fib/ip6_fib.h>
21 #include <vnet/fib/ip4_fib.h>
22 #include <vnet/ip/ip_sas.h>
23 #include <vnet/ip/ip6_link.h>
24 #include <vnet/ip/ip6_ll_table.h>
25 #include <vnet/plugin/plugin.h>
26 #include <vpp/app/version.h>
28 #include <vnet/ip/icmp4.h>
29 #include <ping/ping.h>
31 ping_main_t ping_main;
35 * @brief IPv4 and IPv6 ICMP Ping.
37 * This file contains code to support IPv4 or IPv6 ICMP ECHO_REQUEST to
52 format_icmp_echo_trace (u8 * s, va_list * va)
54 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
55 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
56 icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
59 format (s, "ICMP%s echo id %d seq %d", t->is_ip6 ? "6" : "4", t->id,
61 if (t->cli_process_node == PING_CLI_UNKNOWN_NODE)
63 s = format (s, " (unknown)");
67 s = format (s, " send to cli node %d", t->cli_process_node);
75 format_ip46_ping_result (u8 * s, va_list * args)
77 send_ip46_ping_result_t res = va_arg (*args, send_ip46_ping_result_t);
81 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break;
82 foreach_ip46_ping_result
91 * Poor man's get-set-clear functions
92 * for manipulation of icmp_id -> cli_process_id
95 * There should normally be very few (0..1..2) of these
96 * mappings, so the linear search is a good strategy.
98 * Make them thread-safe via a simple spinlock.
102 static_always_inline int
103 ip46_get_icmp_id_and_seq (vlib_main_t * vm, vlib_buffer_t * b0,
104 u16 * out_icmp_id, u16 * out_icmp_seq, int is_ip6)
109 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
110 if (ip6->protocol != IP_PROTOCOL_ICMP6)
114 l4_offset = sizeof (*ip6); // IPv6 EH
118 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
119 l4_offset = ip4_header_bytes (ip4);
122 icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
123 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
125 *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
126 *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
131 * post the buffer to a given cli process node - the caller should forget bi0 after return.
134 static_always_inline void
135 ip46_post_icmp_reply_event (vlib_main_t * vm, uword cli_process_id, u32 bi0,
138 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
139 u64 nowts = clib_cpu_time_now ();
141 /* Pass the timestamp to the cli_process thanks to the vnet_buffer unused metadata field */
143 /* Camping on unused data... just ensure statically that there is enough space */
144 STATIC_ASSERT (ARRAY_LEN (vnet_buffer (b0)->unused) *
145 sizeof (vnet_buffer (b0)->unused[0]) > sizeof (nowts),
146 "ping reply timestamp fits within remaining space of vnet_buffer unused data");
147 u64 *pnowts = (void *) &vnet_buffer (b0)->unused[0];
150 u32 event_id = is_ip6 ? PING_RESPONSE_IP6 : PING_RESPONSE_IP4;
151 vlib_process_signal_event_mt (vm, cli_process_id, event_id, bi0);
155 static_always_inline void
156 ip46_echo_reply_maybe_trace_buffer (vlib_main_t * vm,
157 vlib_node_runtime_t * node,
158 uword cli_process_id, u16 id, u16 seq,
159 vlib_buffer_t * b0, int is_ip6)
161 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
163 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
166 tr->cli_process_node = cli_process_id;
172 static_always_inline uword
173 ip46_icmp_echo_reply_inner_node_fn (vlib_main_t * vm,
174 vlib_node_runtime_t * node,
175 vlib_frame_t * frame, int do_trace,
178 u32 n_left_from, *from, *to_next;
179 icmp46_echo_reply_next_t next_index;
181 from = vlib_frame_vector_args (frame);
182 n_left_from = frame->n_vectors;
184 next_index = node->cached_next_index;
186 while (n_left_from > 0)
189 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
191 while (n_left_from > 0 && n_left_to_next > 0)
196 * The buffers (replies) are either posted to the CLI thread
197 * awaiting for them for subsequent analysis and disposal,
198 * or are sent to the punt node.
200 * So the only "next" node is a punt, normally.
202 u32 next0 = ICMP46_ECHO_REPLY_NEXT_PUNT;
205 b0 = vlib_get_buffer (vm, bi0);
211 uword cli_process_id = PING_CLI_UNKNOWN_NODE;
213 if (ip46_get_icmp_id_and_seq (vm, b0, &icmp_id, &icmp_seq, is_ip6))
215 cli_process_id = get_cli_process_id_by_icmp_id_mt (vm, icmp_id);
219 ip46_echo_reply_maybe_trace_buffer (vm, node, cli_process_id,
220 icmp_id, icmp_seq, b0,
223 if (~0 == cli_process_id)
225 /* no outstanding requests for this reply, punt */
226 /* speculatively enqueue b0 to the current next frame */
230 /* verify speculative enqueue, maybe switch current next frame */
231 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
232 to_next, n_left_to_next,
237 /* Post the buffer to CLI thread. It will take care of freeing it. */
238 ip46_post_icmp_reply_event (vm, cli_process_id, bi0, is_ip6);
241 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
243 return frame->n_vectors;
247 * select "with-trace" or "without-trace" codepaths upfront.
249 static_always_inline uword
250 ip46_icmp_echo_reply_outer_node_fn (vlib_main_t * vm,
251 vlib_node_runtime_t * node,
252 vlib_frame_t * frame, int is_ip6)
254 if (node->flags & VLIB_NODE_FLAG_TRACE)
255 return ip46_icmp_echo_reply_inner_node_fn (vm, node, frame,
256 1 /* do_trace */ , is_ip6);
258 return ip46_icmp_echo_reply_inner_node_fn (vm, node, frame,
259 0 /* do_trace */ , is_ip6);
263 ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
264 vlib_node_runtime_t * node, vlib_frame_t * frame)
266 return ip46_icmp_echo_reply_outer_node_fn (vm, node, frame,
271 ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
272 vlib_node_runtime_t * node, vlib_frame_t * frame)
274 return ip46_icmp_echo_reply_outer_node_fn (vm, node, frame,
278 VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
280 .function = ip6_icmp_echo_reply_node_fn,
281 .name = "ip6-icmp-echo-reply",
282 .vector_size = sizeof (u32),
283 .format_trace = format_icmp_echo_trace,
284 .n_next_nodes = ICMP46_ECHO_REPLY_N_NEXT,
286 [ICMP46_ECHO_REPLY_NEXT_DROP] = "ip6-drop",
287 [ICMP46_ECHO_REPLY_NEXT_PUNT] = "ip6-punt",
291 VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) =
293 .function = ip4_icmp_echo_reply_node_fn,
294 .name = "ip4-icmp-echo-reply",
295 .vector_size = sizeof (u32),
296 .format_trace = format_icmp_echo_trace,
297 .n_next_nodes = ICMP46_ECHO_REPLY_N_NEXT,
299 [ICMP46_ECHO_REPLY_NEXT_DROP] = "ip4-drop",
300 [ICMP46_ECHO_REPLY_NEXT_PUNT] = "ip4-punt",
305 ip4_icmp_echo_request (vlib_main_t * vm,
306 vlib_node_runtime_t * node, vlib_frame_t * frame)
308 uword n_packets = frame->n_vectors;
310 u32 n_left_from, n_left_to_next, next;
311 ip4_main_t *i4m = &ip4_main;
312 u16 *fragment_ids, *fid;
313 u8 host_config_ttl = i4m->host_config.ttl;
315 from = vlib_frame_vector_args (frame);
316 n_left_from = n_packets;
317 next = node->cached_next_index;
319 if (node->flags & VLIB_NODE_FLAG_TRACE)
320 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
322 sizeof (icmp_input_trace_t));
324 /* Get random fragment IDs for replies. */
325 fid = fragment_ids = clib_random_buffer_get_data (&vm->random_buffer,
327 sizeof (fragment_ids[0]));
329 while (n_left_from > 0)
331 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
333 while (n_left_from > 2 && n_left_to_next > 2)
335 vlib_buffer_t *p0, *p1;
336 ip4_header_t *ip0, *ip1;
337 icmp46_header_t *icmp0, *icmp1;
340 ip_csum_t sum0, sum1;
342 bi0 = to_next[0] = from[0];
343 bi1 = to_next[1] = from[1];
350 p0 = vlib_get_buffer (vm, bi0);
351 p1 = vlib_get_buffer (vm, bi1);
352 ip0 = vlib_buffer_get_current (p0);
353 ip1 = vlib_buffer_get_current (p1);
354 icmp0 = ip4_next_header (ip0);
355 icmp1 = ip4_next_header (ip1);
357 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
358 vnet_main.local_interface_sw_if_index;
359 vnet_buffer (p1)->sw_if_index[VLIB_RX] =
360 vnet_main.local_interface_sw_if_index;
362 /* Update ICMP checksum. */
363 sum0 = icmp0->checksum;
364 sum1 = icmp1->checksum;
366 ASSERT (icmp0->type == ICMP4_echo_request);
367 ASSERT (icmp1->type == ICMP4_echo_request);
368 sum0 = ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
369 icmp46_header_t, type);
370 sum1 = ip_csum_update (sum1, ICMP4_echo_request, ICMP4_echo_reply,
371 icmp46_header_t, type);
372 icmp0->type = ICMP4_echo_reply;
373 icmp1->type = ICMP4_echo_reply;
375 icmp0->checksum = ip_csum_fold (sum0);
376 icmp1->checksum = ip_csum_fold (sum1);
378 src0 = ip0->src_address.data_u32;
379 src1 = ip1->src_address.data_u32;
380 dst0 = ip0->dst_address.data_u32;
381 dst1 = ip1->dst_address.data_u32;
383 /* Swap source and destination address.
384 Does not change checksum. */
385 ip0->src_address.data_u32 = dst0;
386 ip1->src_address.data_u32 = dst1;
387 ip0->dst_address.data_u32 = src0;
388 ip1->dst_address.data_u32 = src1;
390 /* Update IP checksum. */
391 sum0 = ip0->checksum;
392 sum1 = ip1->checksum;
394 sum0 = ip_csum_update (sum0, ip0->ttl, host_config_ttl,
396 sum1 = ip_csum_update (sum1, ip1->ttl, host_config_ttl,
398 ip0->ttl = host_config_ttl;
399 ip1->ttl = host_config_ttl;
401 /* New fragment id. */
402 sum0 = ip_csum_update (sum0, ip0->fragment_id, fid[0],
403 ip4_header_t, fragment_id);
404 sum1 = ip_csum_update (sum1, ip1->fragment_id, fid[1],
405 ip4_header_t, fragment_id);
406 ip0->fragment_id = fid[0];
407 ip1->fragment_id = fid[1];
410 ip0->checksum = ip_csum_fold (sum0);
411 ip1->checksum = ip_csum_fold (sum1);
413 ASSERT (ip4_header_checksum_is_valid (ip0));
414 ASSERT (ip4_header_checksum_is_valid (ip1));
416 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
417 p1->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
420 while (n_left_from > 0 && n_left_to_next > 0)
424 icmp46_header_t *icmp0;
428 bi0 = to_next[0] = from[0];
435 p0 = vlib_get_buffer (vm, bi0);
436 ip0 = vlib_buffer_get_current (p0);
437 icmp0 = ip4_next_header (ip0);
439 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
440 vnet_main.local_interface_sw_if_index;
442 /* Update ICMP checksum. */
443 sum0 = icmp0->checksum;
445 ASSERT (icmp0->type == ICMP4_echo_request);
446 sum0 = ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
447 icmp46_header_t, type);
448 icmp0->type = ICMP4_echo_reply;
449 icmp0->checksum = ip_csum_fold (sum0);
451 src0 = ip0->src_address.data_u32;
452 dst0 = ip0->dst_address.data_u32;
453 ip0->src_address.data_u32 = dst0;
454 ip0->dst_address.data_u32 = src0;
456 /* Update IP checksum. */
457 sum0 = ip0->checksum;
459 sum0 = ip_csum_update (sum0, ip0->ttl, host_config_ttl,
461 ip0->ttl = host_config_ttl;
463 sum0 = ip_csum_update (sum0, ip0->fragment_id, fid[0],
464 ip4_header_t, fragment_id);
465 ip0->fragment_id = fid[0];
468 ip0->checksum = ip_csum_fold (sum0);
470 ASSERT (ip4_header_checksum_is_valid (ip0));
472 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
475 vlib_put_next_frame (vm, node, next, n_left_to_next);
478 vlib_error_count (vm, ip4_icmp_input_node.index,
479 ICMP4_ERROR_ECHO_REPLIES_SENT, frame->n_vectors);
481 return frame->n_vectors;
485 format_icmp_input_trace (u8 * s, va_list * va)
487 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
488 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
489 icmp_input_trace_t *t = va_arg (*va, icmp_input_trace_t *);
492 format_ip4_header, t->packet_data, sizeof (t->packet_data));
497 VLIB_REGISTER_NODE (ip4_icmp_echo_request_node,static) = {
498 .function = ip4_icmp_echo_request,
499 .name = "ip4-icmp-echo-request",
501 .vector_size = sizeof (u32),
503 .format_trace = format_icmp_input_trace,
507 [0] = "ip4-load-balance",
513 ICMP6_ECHO_REQUEST_NEXT_LOOKUP,
514 ICMP6_ECHO_REQUEST_NEXT_OUTPUT,
515 ICMP6_ECHO_REQUEST_N_NEXT,
516 } icmp6_echo_request_next_t;
519 ip6_icmp_echo_request (vlib_main_t *vm, vlib_node_runtime_t *node,
523 u32 n_left_from, n_left_to_next, next_index;
524 ip6_main_t *im = &ip6_main;
526 from = vlib_frame_vector_args (frame);
527 n_left_from = frame->n_vectors;
528 next_index = node->cached_next_index;
530 if (node->flags & VLIB_NODE_FLAG_TRACE)
531 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
533 sizeof (icmp6_input_trace_t));
535 while (n_left_from > 0)
537 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
539 while (n_left_from > 2 && n_left_to_next > 2)
541 vlib_buffer_t *p0, *p1;
542 ip6_header_t *ip0, *ip1;
543 icmp46_header_t *icmp0, *icmp1;
544 ip6_address_t tmp0, tmp1;
545 ip_csum_t sum0, sum1;
547 u32 fib_index0, fib_index1;
548 u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
549 u32 next1 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
551 bi0 = to_next[0] = from[0];
552 bi1 = to_next[1] = from[1];
559 p0 = vlib_get_buffer (vm, bi0);
560 p1 = vlib_get_buffer (vm, bi1);
561 ip0 = vlib_buffer_get_current (p0);
562 ip1 = vlib_buffer_get_current (p1);
563 icmp0 = ip6_next_header (ip0);
564 icmp1 = ip6_next_header (ip1);
566 /* Check icmp type to echo reply and update icmp checksum. */
567 sum0 = icmp0->checksum;
568 sum1 = icmp1->checksum;
570 ASSERT (icmp0->type == ICMP6_echo_request);
571 ASSERT (icmp1->type == ICMP6_echo_request);
572 sum0 = ip_csum_update (sum0, ICMP6_echo_request, ICMP6_echo_reply,
573 icmp46_header_t, type);
574 sum1 = ip_csum_update (sum1, ICMP6_echo_request, ICMP6_echo_reply,
575 icmp46_header_t, type);
577 icmp0->checksum = ip_csum_fold (sum0);
578 icmp1->checksum = ip_csum_fold (sum1);
580 icmp0->type = ICMP6_echo_reply;
581 icmp1->type = ICMP6_echo_reply;
583 /* Swap source and destination address. */
584 tmp0 = ip0->src_address;
585 tmp1 = ip1->src_address;
587 ip0->src_address = ip0->dst_address;
588 ip1->src_address = ip1->dst_address;
590 ip0->dst_address = tmp0;
591 ip1->dst_address = tmp1;
594 ip0->hop_limit = im->host_config.ttl;
595 ip1->hop_limit = im->host_config.ttl;
597 if (ip6_address_is_link_local_unicast (&ip0->src_address) &&
598 !ip6_address_is_link_local_unicast (&ip0->dst_address))
600 fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
601 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
602 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index0;
604 if (ip6_address_is_link_local_unicast (&ip1->src_address) &&
605 !ip6_address_is_link_local_unicast (&ip1->dst_address))
607 fib_index1 = vec_elt (im->fib_index_by_sw_if_index,
608 vnet_buffer (p1)->sw_if_index[VLIB_RX]);
609 vnet_buffer (p1)->sw_if_index[VLIB_TX] = fib_index1;
611 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
612 p1->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
614 /* verify speculative enqueues, maybe switch current next frame */
615 /* if next0==next1==next_index then nothing special needs to be done
617 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
618 n_left_to_next, bi0, bi1, next0,
622 while (n_left_from > 0 && n_left_to_next > 0)
626 icmp46_header_t *icmp0;
631 u32 next0 = ICMP6_ECHO_REQUEST_NEXT_LOOKUP;
633 bi0 = to_next[0] = from[0];
640 p0 = vlib_get_buffer (vm, bi0);
641 ip0 = vlib_buffer_get_current (p0);
642 icmp0 = ip6_next_header (ip0);
644 /* Check icmp type to echo reply and update icmp checksum. */
645 sum0 = icmp0->checksum;
647 ASSERT (icmp0->type == ICMP6_echo_request);
648 sum0 = ip_csum_update (sum0, ICMP6_echo_request, ICMP6_echo_reply,
649 icmp46_header_t, type);
651 icmp0->checksum = ip_csum_fold (sum0);
653 icmp0->type = ICMP6_echo_reply;
655 /* Swap source and destination address. */
656 tmp0 = ip0->src_address;
657 ip0->src_address = ip0->dst_address;
658 ip0->dst_address = tmp0;
660 ip0->hop_limit = im->host_config.ttl;
662 if (ip6_address_is_link_local_unicast (&ip0->src_address) &&
663 !ip6_address_is_link_local_unicast (&ip0->dst_address))
665 /* if original packet was to the link local, then the
666 * fib index is that of the LL table, we can't use that
667 * to foward the response if the new destination
668 * is global, so reset to the fib index of the link.
669 * In other case, the fib index we need has been written
670 * to the buffer already. */
671 fib_index0 = vec_elt (im->fib_index_by_sw_if_index,
672 vnet_buffer (p0)->sw_if_index[VLIB_RX]);
673 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index0;
675 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
676 /* Verify speculative enqueue, maybe switch current next frame */
677 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
678 n_left_to_next, bi0, next0);
681 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
684 vlib_error_count (vm, ip6_icmp_input_node.index,
685 ICMP6_ERROR_ECHO_REPLIES_SENT, frame->n_vectors);
687 return frame->n_vectors;
690 VLIB_REGISTER_NODE (ip6_icmp_echo_request_node,static) = {
691 .function = ip6_icmp_echo_request,
692 .name = "ip6-icmp-echo-request",
694 .vector_size = sizeof (u32),
696 .format_trace = format_icmp6_input_trace,
698 .n_next_nodes = ICMP6_ECHO_REQUEST_N_NEXT,
700 [ICMP6_ECHO_REQUEST_NEXT_LOOKUP] = "ip6-lookup",
701 [ICMP6_ECHO_REQUEST_NEXT_OUTPUT] = "interface-output",
706 * A swarm of address-family agnostic helper functions
707 * for building and sending the ICMP echo request.
709 * Deliberately mostly "static" rather than "static inline"
710 * so one can trace them sanely if needed in debugger, if needed.
714 static_always_inline u8
715 get_icmp_echo_payload_byte (int offset)
717 return (offset % 256);
720 /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
722 init_icmp46_echo_request (vlib_main_t * vm, vlib_buffer_t * b0,
723 int l4_header_offset,
724 icmp46_echo_request_t * icmp46_echo, u16 seq_host,
725 u16 id_host, u64 now, u16 data_len)
731 l4_header_offset + sizeof (icmp46_header_t) +
732 offsetof (icmp46_echo_request_t, data);
733 int max_data_len = vlib_buffer_get_default_data_size (vm) - l34_len;
735 int first_buf_data_len = data_len < max_data_len ? data_len : max_data_len;
737 int payload_offset = 0;
738 for (i = 0; i < first_buf_data_len; i++)
739 icmp46_echo->data[i] = get_icmp_echo_payload_byte (payload_offset++);
741 /* inspired by vlib_buffer_add_data */
742 vlib_buffer_t *hb = b0;
743 int remaining_data_len = data_len - first_buf_data_len;
744 while (remaining_data_len)
746 int this_buf_data_len =
748 vlib_buffer_get_default_data_size (vm) ? remaining_data_len :
749 vlib_buffer_get_default_data_size (vm);
750 int n_alloc = vlib_buffer_alloc (vm, &b0->next_buffer, 1);
753 /* That is how much we have so far - return it... */
754 return (data_len - remaining_data_len);
756 b0->flags |= VLIB_BUFFER_NEXT_PRESENT;
757 /* move on to the newly acquired buffer */
758 b0 = vlib_get_buffer (vm, b0->next_buffer);
759 /* initialize the data */
760 for (i = 0; i < this_buf_data_len; i++)
762 b0->data[i] = get_icmp_echo_payload_byte (payload_offset++);
764 b0->current_length = this_buf_data_len;
765 b0->current_data = 0;
766 remaining_data_len -= this_buf_data_len;
768 hb->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
769 hb->current_length = l34_len + first_buf_data_len;
770 hb->total_length_not_including_first_buffer = data_len - first_buf_data_len;
772 icmp46_echo->time_sent = now;
773 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
774 icmp46_echo->id = clib_host_to_net_u16 (id_host);
780 ip46_fib_index_from_table_id (u32 table_id, int is_ip6)
782 u32 fib_index = is_ip6 ?
783 ip6_fib_index_from_table_id (table_id) :
784 ip4_fib_index_from_table_id (table_id);
788 static fib_node_index_t
789 ip46_fib_table_lookup_host (u32 fib_index, ip46_address_t * pa46, int is_ip6)
791 fib_node_index_t fib_entry_index = is_ip6 ?
792 ip6_fib_table_lookup (fib_index, &pa46->ip6, 128) :
793 ip4_fib_table_lookup (ip4_fib_get (fib_index), &pa46->ip4, 32);
794 return fib_entry_index;
798 ip46_get_resolving_interface (u32 fib_index, ip46_address_t * pa46,
801 u32 sw_if_index = ~0;
804 fib_node_index_t fib_entry_index;
805 fib_entry_index = ip46_fib_table_lookup_host (fib_index, pa46, is_ip6);
806 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
812 ip46_fib_table_get_index_for_sw_if_index (u32 sw_if_index, int is_ip6,
813 ip46_address_t *pa46)
817 if (ip6_address_is_link_local_unicast (&pa46->ip6))
818 return ip6_ll_fib_get (sw_if_index);
819 return ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
821 return ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
826 ip46_fill_l3_header (ip46_address_t * pa46, vlib_buffer_t * b0, int is_ip6)
830 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
831 /* Fill in ip6 header fields */
832 ip6->ip_version_traffic_class_and_flow_label =
833 clib_host_to_net_u32 (0x6 << 28);
834 ip6->payload_length = 0; /* will be set later */
835 ip6->protocol = IP_PROTOCOL_ICMP6;
836 ip6->hop_limit = 255;
837 ip6->dst_address = pa46->ip6;
838 ip6->src_address = pa46->ip6;
839 return (sizeof (ip6_header_t));
843 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
844 /* Fill in ip4 header fields */
846 ip4->ip_version_and_header_length = 0x45;
848 ip4->length = 0; /* will be set later */
849 ip4->fragment_id = 0;
850 ip4->flags_and_fragment_offset = 0;
852 ip4->protocol = IP_PROTOCOL_ICMP;
853 ip4->src_address = pa46->ip4;
854 ip4->dst_address = pa46->ip4;
855 return (sizeof (ip4_header_t));
860 ip46_set_src_address (u32 sw_if_index, vlib_buffer_t * b0, int is_ip6)
866 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
868 res = ip6_sas_by_sw_if_index (sw_if_index, &ip6->dst_address,
873 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
875 res = ip4_sas_by_sw_if_index (sw_if_index, &ip4->dst_address,
882 ip46_print_buffer_src_address (vlib_main_t * vm, vlib_buffer_t * b0,
885 void *format_addr_func;
889 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
890 format_addr_func = format_ip6_address;
891 paddr = &ip6->src_address;
895 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
896 format_addr_func = format_ip4_address;
897 paddr = &ip4->src_address;
899 vlib_cli_output (vm, "Source address: %U ", format_addr_func, paddr);
903 ip46_fill_icmp_request_at (vlib_main_t * vm, int l4_offset, u16 seq_host,
904 u16 id_host, u16 data_len, vlib_buffer_t * b0,
907 icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
909 icmp46->type = is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
911 icmp46->checksum = 0;
913 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
916 init_icmp46_echo_request (vm, b0, l4_offset, icmp46_echo, seq_host,
917 id_host, clib_cpu_time_now (), data_len);
922 /* Compute ICMP4 checksum with multibuffer support. */
924 ip4_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
928 u32 ip_header_length, payload_length_host_byte_order;
929 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
931 void *data_this_buffer;
933 ip_header_length = ip4_header_bytes (ip0);
934 payload_length_host_byte_order =
935 clib_net_to_host_u16 (ip0->length) - ip_header_length;
937 /* ICMP4 checksum does not include the IP header */
940 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
941 data_this_buffer = (void *) ip0 + ip_header_length;
942 n_ip_bytes_this_buffer =
943 p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
944 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
946 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
947 n_ip_bytes_this_buffer - ip_header_length : 0;
951 sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
952 n_bytes_left -= n_this_buffer;
953 if (n_bytes_left == 0)
956 ASSERT (p0->flags & VLIB_BUFFER_NEXT_PRESENT);
957 p0 = vlib_get_buffer (vm, p0->next_buffer);
958 data_this_buffer = vlib_buffer_get_current (p0);
959 n_this_buffer = p0->current_length;
962 sum16 = ~ip_csum_fold (sum0);
969 ip46_fix_len_and_csum (vlib_main_t * vm, int l4_offset, u16 data_len,
970 vlib_buffer_t * b0, int is_ip6)
973 data_len + sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
975 u16 total_length = payload_length + l4_offset;
976 icmp46_header_t *icmp46 = vlib_buffer_get_current (b0) + l4_offset;
977 icmp46->checksum = 0;
981 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
982 ip6->payload_length = clib_host_to_net_u16 (payload_length);
984 int bogus_length = 0;
986 ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus_length);
990 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
991 ip4->length = clib_host_to_net_u16 (total_length);
993 ip4->checksum = ip4_header_checksum (ip4);
994 icmp46->checksum = ip4_icmp_compute_checksum (vm, b0, ip4);
999 at_most_a_frame (u32 count)
1001 return count > VLIB_FRAME_SIZE ? VLIB_FRAME_SIZE : count;
1005 ip46_enqueue_packet (vlib_main_t *vm, vlib_buffer_t *b0, u32 burst,
1006 u32 lookup_node_index)
1008 vlib_frame_t *f = 0;
1014 * Enqueue the packet, possibly as one or more frames of copies to make
1015 * bursts. We enqueue b0 as the very last buffer, when there is no possibility
1016 * for error in vlib_buffer_copy, so as to allow the caller to free it
1017 * in case we encounter the error in the middle of the loop.
1019 for (n_to_send = at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
1020 n_to_send = at_most_a_frame (burst), burst -= n_to_send)
1022 f = vlib_get_frame_to_node (vm, lookup_node_index);
1023 /* f can not be NULL here - frame allocation failure causes panic */
1025 u32 *to_next = vlib_frame_vector_args (f);
1026 f->n_vectors = n_to_send;
1028 while (n_to_send > 1)
1030 vlib_buffer_t *b0copy = vlib_buffer_copy (vm, b0);
1031 if (PREDICT_FALSE (b0copy == NULL))
1033 *to_next++ = vlib_get_buffer_index (vm, b0copy);
1038 /* n_to_send is guaranteed to equal 1 here */
1041 /* not the last burst, so still make a copy for the last buffer */
1042 vlib_buffer_t *b0copy = vlib_buffer_copy (vm, b0);
1043 if (PREDICT_FALSE (b0copy == NULL))
1046 *to_next++ = vlib_get_buffer_index (vm, b0copy);
1050 /* put the original buffer as the last one of an error-free run */
1051 *to_next++ = vlib_get_buffer_index (vm, b0);
1053 vlib_put_frame_to_node (vm, lookup_node_index, f);
1054 n_sent += f->n_vectors;
1058 * We reach here in case we already enqueued one or more buffers
1059 * and maybe one or more frames but could not make more copies.
1060 * There is an outstanding frame - so ship it and return.
1061 * Caller will have to free the b0 in this case, since
1062 * we did not enqueue it here yet.
1065 ASSERT (n_to_send <= f->n_vectors);
1066 f->n_vectors -= n_to_send;
1067 n_sent += f->n_vectors;
1068 vlib_put_frame_to_node (vm, lookup_node_index, f);
1074 * An address-family agnostic ping send function.
1077 #define ERROR_OUT(e) do { err = e; goto done; } while (0)
1079 static send_ip46_ping_result_t
1080 send_ip46_ping (vlib_main_t * vm,
1082 ip46_address_t * pa46,
1084 u16 seq_host, u16 id_host, u16 data_len, u32 burst,
1085 u8 verbose, int is_ip6)
1087 int err = SEND_PING_OK;
1092 n_buf0 = vlib_buffer_alloc (vm, &bi0, 1);
1094 ERROR_OUT (SEND_PING_ALLOC_FAIL);
1096 b0 = vlib_get_buffer (vm, bi0);
1099 * if the user did not provide a source interface,
1100 * perform a resolution and use an interface
1101 * via which it succeeds.
1104 if (~0 == sw_if_index)
1106 fib_index = ip46_fib_index_from_table_id (table_id, is_ip6);
1107 sw_if_index = ip46_get_resolving_interface (fib_index, pa46, is_ip6);
1111 ip46_fib_table_get_index_for_sw_if_index (sw_if_index, is_ip6, pa46);
1113 if (~0 == fib_index)
1114 ERROR_OUT (SEND_PING_NO_TABLE);
1115 if (~0 == sw_if_index)
1116 ERROR_OUT (SEND_PING_NO_INTERFACE);
1118 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index;
1119 vnet_buffer (b0)->sw_if_index[VLIB_TX] = fib_index;
1121 int l4_header_offset = ip46_fill_l3_header (pa46, b0, is_ip6);
1123 /* set the src address in the buffer */
1124 if (!ip46_set_src_address (sw_if_index, b0, is_ip6))
1125 ERROR_OUT (SEND_PING_NO_SRC_ADDRESS);
1127 ip46_print_buffer_src_address (vm, b0, is_ip6);
1130 ip46_fill_icmp_request_at (vm, l4_header_offset, seq_host, id_host,
1131 data_len, b0, is_ip6);
1133 ip46_fix_len_and_csum (vm, l4_header_offset, data_len, b0, is_ip6);
1135 u32 node_index = ip6_lookup_node.index;
1138 if (pa46->ip6.as_u32[0] == clib_host_to_net_u32 (0xff020000))
1140 node_index = ip6_rewrite_mcast_node.index;
1141 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index;
1142 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index;
1143 vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
1144 ip6_link_get_mcast_adj (sw_if_index);
1149 node_index = ip4_lookup_node.index;
1151 int n_sent = ip46_enqueue_packet (vm, b0, burst, node_index);
1153 err = SEND_PING_NO_BUFFERS;
1156 if (err != SEND_PING_OK)
1159 vlib_buffer_free (vm, &bi0, 1);
1164 send_ip46_ping_result_t
1165 send_ip6_ping (vlib_main_t *vm, u32 table_id, ip6_address_t *pa6,
1166 u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
1167 u32 burst, u8 verbose)
1169 ip46_address_t target;
1171 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
1172 id_host, data_len, burst, verbose, 1 /* is_ip6 */ );
1175 send_ip46_ping_result_t
1176 send_ip4_ping (vlib_main_t *vm, u32 table_id, ip4_address_t *pa4,
1177 u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
1178 u32 burst, u8 verbose)
1180 ip46_address_t target;
1181 ip46_address_set_ip4 (&target, pa4);
1182 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
1183 id_host, data_len, burst, verbose, 0 /* is_ip6 */ );
1187 print_ip46_icmp_reply (vlib_main_t * vm, u32 bi0, int is_ip6)
1189 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
1192 void *format_addr_func;
1197 ip6_header_t *ip6 = vlib_buffer_get_current (b0);
1198 paddr = (void *) &ip6->src_address;
1199 format_addr_func = (void *) format_ip6_address;
1200 ttl = ip6->hop_limit;
1201 l4_offset = sizeof (ip6_header_t); // FIXME - EH processing ?
1202 payload_length = clib_net_to_host_u16 (ip6->payload_length);
1206 ip4_header_t *ip4 = vlib_buffer_get_current (b0);
1207 paddr = (void *) &ip4->src_address;
1208 format_addr_func = (void *) format_ip4_address;
1210 l4_offset = ip4_header_bytes (ip4);
1212 clib_net_to_host_u16 (ip4->length) + ip4_header_bytes (ip4);
1214 icmp46_header_t *icmp = vlib_buffer_get_current (b0) + l4_offset;
1215 icmp46_echo_request_t *icmp_echo = (icmp46_echo_request_t *) (icmp + 1);
1216 u64 *dataplane_ts = (u64 *) & vnet_buffer (b0)->unused[0];
1218 f64 clocks_per_second = ((f64) vm->clib_time.clocks_per_second);
1220 ((f64) (*dataplane_ts - icmp_echo->time_sent)) / clocks_per_second;
1222 vlib_cli_output (vm,
1223 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
1227 clib_host_to_net_u16 (icmp_echo->seq), ttl, rtt * 1000.0);
1231 * Perform the ping run with the given parameters in the current CLI process.
1232 * Depending on whether pa4 or pa6 is set, runs IPv4 or IPv6 ping.
1233 * The amusing side effect is of course if both are set, then both pings are sent.
1234 * This behavior can be used to ping a dualstack host over IPv4 and IPv6 at once.
1238 run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
1239 ip6_address_t * pa6, u32 sw_if_index,
1240 f64 ping_interval, u32 ping_repeat, u32 data_len,
1241 u32 ping_burst, u32 verbose)
1244 uword curr_proc = vlib_current_process (vm);
1249 static u32 rand_seed = 0;
1251 if (PREDICT_FALSE (!rand_seed))
1252 rand_seed = random_default_seed ();
1254 icmp_id = random_u32 (&rand_seed) & 0xffff;
1256 while (~0 != get_cli_process_id_by_icmp_id_mt (vm, icmp_id))
1258 vlib_cli_output (vm, "ICMP ID collision at %d, incrementing", icmp_id);
1262 set_cli_process_id_by_icmp_id_mt (vm, icmp_id, curr_proc);
1264 for (i = 1; i <= ping_repeat; i++)
1266 send_ip46_ping_result_t res = SEND_PING_OK;
1268 f64 time_ping_sent = vlib_time_now (vm);
1271 res = send_ip6_ping (vm, table_id,
1272 pa6, sw_if_index, i, icmp_id,
1273 data_len, ping_burst, verbose);
1274 if (SEND_PING_OK == res)
1275 n_requests += ping_burst;
1277 vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
1281 res = send_ip4_ping (vm, table_id, pa4,
1282 sw_if_index, i, icmp_id, data_len,
1283 ping_burst, verbose);
1284 if (SEND_PING_OK == res)
1285 n_requests += ping_burst;
1287 vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
1290 /* Collect and print the responses until it is time to send a next ping */
1292 while ((i <= ping_repeat)
1295 time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
1297 uword event_type, *event_data = 0;
1298 vlib_process_wait_for_event_or_clock (vm, sleep_interval);
1299 event_type = vlib_process_get_events (vm, &event_data);
1302 case ~0: /* no events => timeout */
1304 case PING_RESPONSE_IP6:
1306 case PING_RESPONSE_IP4:
1309 int is_ip6 = (event_type == PING_RESPONSE_IP6);
1310 for (ii = 0; ii < vec_len (event_data); ii++)
1312 u32 bi0 = event_data[ii];
1313 print_ip46_icmp_reply (vm, bi0, is_ip6);
1316 vlib_buffer_free (vm, &bi0, 1);
1320 case UNIX_CLI_PROCESS_EVENT_READ_READY:
1321 case UNIX_CLI_PROCESS_EVENT_QUIT:
1322 /* someone pressed a key, abort */
1323 vlib_cli_output (vm, "Aborted due to a keypress.");
1326 vec_free (event_data);
1330 vlib_cli_output (vm, "\n");
1334 n_requests) ? 0 : 100.0 * ((float) n_requests -
1335 (float) n_replies) / (float) n_requests;
1336 vlib_cli_output (vm,
1337 "Statistics: %u sent, %u received, %f%% packet loss\n",
1338 n_requests, n_replies, loss);
1339 clear_cli_process_id_by_icmp_id_mt (vm, icmp_id);
1345 static clib_error_t *
1346 ping_ip_address (vlib_main_t * vm,
1347 unformat_input_t * input, vlib_cli_command_t * cmd)
1351 clib_error_t *error = 0;
1352 u32 ping_repeat = 5;
1354 u8 ping_ip4, ping_ip6;
1355 vnet_main_t *vnm = vnet_get_main ();
1356 u32 data_len = PING_DEFAULT_DATA_LEN;
1358 f64 ping_interval = PING_DEFAULT_INTERVAL;
1359 u32 sw_if_index, table_id;
1362 ping_ip4 = ping_ip6 = 0;
1365 if (unformat (input, "%U", unformat_ip4_address, &a4))
1369 else if (unformat (input, "%U", unformat_ip6_address, &a6))
1373 else if (unformat (input, "ipv4"))
1375 if (unformat (input, "%U", unformat_ip4_address, &a4))
1382 clib_error_return (0,
1383 "expecting IPv4 address but got `%U'",
1384 format_unformat_error, input);
1387 else if (unformat (input, "ipv6"))
1389 if (unformat (input, "%U", unformat_ip6_address, &a6))
1396 clib_error_return (0,
1397 "expecting IPv6 address but got `%U'",
1398 format_unformat_error, input);
1404 clib_error_return (0,
1405 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
1406 format_unformat_error, input);
1410 /* allow for the second AF in the same ping */
1411 if (!ping_ip4 && (unformat (input, "ipv4")))
1413 if (unformat (input, "%U", unformat_ip4_address, &a4))
1418 else if (!ping_ip6 && (unformat (input, "ipv6")))
1420 if (unformat (input, "%U", unformat_ip6_address, &a6))
1426 /* parse the rest of the parameters in a cycle */
1427 while (!unformat_eof (input, NULL))
1429 if (unformat (input, "source"))
1432 (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1435 clib_error_return (0,
1436 "unknown interface `%U'",
1437 format_unformat_error, input);
1441 else if (unformat (input, "size"))
1443 if (!unformat (input, "%u", &data_len))
1446 clib_error_return (0,
1447 "expecting size but got `%U'",
1448 format_unformat_error, input);
1451 if (data_len > PING_MAXIMUM_DATA_SIZE)
1454 clib_error_return (0,
1455 "%d is bigger than maximum allowed payload size %d",
1456 data_len, PING_MAXIMUM_DATA_SIZE);
1460 else if (unformat (input, "table-id"))
1462 if (!unformat (input, "%u", &table_id))
1465 clib_error_return (0,
1466 "expecting table-id but got `%U'",
1467 format_unformat_error, input);
1471 else if (unformat (input, "interval"))
1473 if (!unformat (input, "%f", &ping_interval))
1476 clib_error_return (0,
1477 "expecting interval (floating point number) got `%U'",
1478 format_unformat_error, input);
1482 else if (unformat (input, "repeat"))
1484 if (!unformat (input, "%u", &ping_repeat))
1487 clib_error_return (0,
1488 "expecting repeat count but got `%U'",
1489 format_unformat_error, input);
1493 else if (unformat (input, "burst"))
1495 if (!unformat (input, "%u", &ping_burst))
1498 clib_error_return (0,
1499 "expecting burst count but got `%U'",
1500 format_unformat_error, input);
1504 else if (unformat (input, "verbose"))
1510 error = clib_error_return (0, "unknown input `%U'",
1511 format_unformat_error, input);
1517 * Operationally, one won't (and shouldn't) need to send more than a frame worth of pings.
1518 * But it may be handy during the debugging.
1522 #define MAX_PING_BURST (10*VLIB_FRAME_SIZE)
1524 #define MAX_PING_BURST (VLIB_FRAME_SIZE)
1527 if (ping_burst < 1 || ping_burst > MAX_PING_BURST)
1528 return clib_error_return (0, "burst size must be between 1 and %u",
1531 run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
1532 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
1533 ping_repeat, data_len, ping_burst, verbose);
1539 * This command sends an ICMP ECHO_REQUEST to network hosts. The address
1540 * can be an IPv4 or IPv6 address (or both at the same time).
1544 * Example of how ping an IPv4 address:
1545 * @cliexstart{ping 172.16.1.2 source GigabitEthernet2/0/0 repeat 2}
1546 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1090 ms
1547 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0914 ms
1549 * Statistics: 2 sent, 2 received, 0% packet loss
1552 * Example of how ping both an IPv4 address and IPv6 address at the same time:
1553 * @cliexstart{ping 172.16.1.2 ipv6 fe80::24a5:f6ff:fe9c:3a36 source GigabitEthernet2/0/0 repeat 2 verbose}
1554 * Adjacency index: 10, sw_if_index: 1
1555 * Adj: ip6-discover-neighbor
1557 * Forced set interface: 1
1558 * Adjacency index: 0, sw_if_index: 4294967295
1561 * Forced set interface: 1
1562 * Source address: 172.16.1.1
1563 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1899 ms
1564 * Adjacency index: 10, sw_if_index: 1
1565 * Adj: ip6-discover-neighbor
1567 * Forced set interface: 1
1568 * Adjacency index: 0, sw_if_index: 4294967295
1571 * Forced set interface: 1
1572 * Source address: 172.16.1.1
1573 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0910 ms
1575 * Statistics: 4 sent, 2 received, 50% packet loss
1579 VLIB_CLI_COMMAND (ping_command, static) =
1582 .function = ping_ip_address,
1583 .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
1584 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
1585 " [size <pktsize:60>] [interval <sec:1>] [repeat <cnt:5>] [table-id <id:0>]"
1586 " [burst <count:1>] [verbose]",
1590 static clib_error_t *
1591 ping_cli_init (vlib_main_t * vm)
1593 vlib_thread_main_t *tm = vlib_get_thread_main ();
1594 ping_main_t *pm = &ping_main;
1596 pm->ip6_main = &ip6_main;
1597 pm->ip4_main = &ip4_main;
1598 icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
1599 ip4_icmp_register_type (vm, ICMP4_echo_reply,
1600 ip4_icmp_echo_reply_node.index);
1601 if (tm->n_vlib_mains > 1)
1602 clib_spinlock_init (&pm->ping_run_check_lock);
1604 ip4_icmp_register_type (vm, ICMP4_echo_request,
1605 ip4_icmp_echo_request_node.index);
1606 icmp6_register_type (vm, ICMP6_echo_request,
1607 ip6_icmp_echo_request_node.index);
1609 ping_plugin_api_hookup (vm);
1614 VLIB_INIT_FUNCTION (ping_cli_init);
1616 VLIB_PLUGIN_REGISTER () = {
1617 .version = VPP_BUILD_VER,
1618 .description = "Ping (ping)",
1622 * fd.io coding-style-patch-verification: ON
1625 * eval: (c-set-style "gnu")