blob: a142754bdf761aa9583c777e59570798fe6a96ee [file] [log] [blame]
Andrew Yourtchenko7e682202016-08-04 13:39:35 +00001/*
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
Andrew Yourtchenko61459c92017-01-28 15:31:19 +000016#include <stddef.h>
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000017#include <vnet/ip/ping.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010018#include <vnet/fib/ip6_fib.h>
19#include <vnet/fib/ip4_fib.h>
20#include <vnet/fib/fib_entry.h>
Mohammed Hawari03a62132017-07-18 09:25:01 +020021#include <vlib/vlib.h>
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000022
Dave Wallace71612d62017-10-24 01:32:41 -040023ping_main_t ping_main;
24
Billy McFall0683c9c2016-10-13 08:27:31 -040025/**
26 * @file
27 * @brief IPv4 and IPv6 ICMP Ping.
28 *
29 * This file contains code to suppport IPv4 or IPv6 ICMP ECHO_REQUEST to
30 * network hosts.
31 *
32 */
33
34
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000035u8 *
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080036format_icmp_echo_trace (u8 * s, va_list * va)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000037{
38 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
39 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080040 icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000041
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080042 s = format (s, "ICMP echo id %d seq %d%s",
Dave Barachd7cb1b52016-12-09 09:52:16 -050043 clib_net_to_host_u16 (t->id),
44 clib_net_to_host_u16 (t->seq), t->bound ? "" : " (unknown)");
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000045
46 return s;
47}
48
49/*
50 * If we can find the ping run by an ICMP ID, then we send the signal
51 * to the CLI process referenced by that ping run, alongside with
52 * a freshly made copy of the packet.
53 * I opted for a packet copy to keep the main packet processing path
54 * the same as for all the other nodes.
55 *
56 */
57
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080058static int
Mohammed Hawari03a62132017-07-18 09:25:01 +020059signal_ip46_icmp_reply_event (u8 event_type, vlib_buffer_t * b0)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000060{
61 ping_main_t *pm = &ping_main;
62 u16 net_icmp_id = 0;
63 u32 bi0_copy = 0;
64
65 switch (event_type)
66 {
67 case PING_RESPONSE_IP4:
68 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050069 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
70 net_icmp_id = h0->icmp_echo.id;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000071 }
72 break;
73 case PING_RESPONSE_IP6:
74 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050075 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
76 net_icmp_id = h0->icmp_echo.id;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000077 }
78 break;
79 default:
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080080 return 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000081 }
82
83 uword *p = hash_get (pm->ping_run_by_icmp_id,
Dave Barachd7cb1b52016-12-09 09:52:16 -050084 clib_net_to_host_u16 (net_icmp_id));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000085 if (!p)
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080086 return 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000087
88 ping_run_t *pr = vec_elt_at_index (pm->ping_runs, p[0]);
Mohammed Hawari03a62132017-07-18 09:25:01 +020089 vlib_main_t *vm = vlib_mains[pr->cli_thread_index];
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000090 if (vlib_buffer_alloc (vm, &bi0_copy, 1) == 1)
91 {
Mohammed Hawari03a62132017-07-18 09:25:01 +020092 void *dst = vlib_buffer_get_current (vlib_get_buffer (vm,
93 bi0_copy));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000094 clib_memcpy (dst, vlib_buffer_get_current (b0), b0->current_length);
95 }
96 /* If buffer_alloc failed, bi0_copy == 0 - just signaling an event. */
Mohammed Hawari03a62132017-07-18 09:25:01 +020097 f64 nowts = vlib_time_now (vm);
98 /* Pass the timestamp to the cli_process thanks to the vnet_buffer unused metadata field */
99 clib_memcpy (vnet_buffer
100 (vlib_get_buffer
101 (vm, bi0_copy))->unused, &nowts, sizeof (nowts));
Dave Barach69128d02017-09-26 10:54:34 -0400102 vlib_process_signal_event_mt (vm, pr->cli_process_id, event_type, bi0_copy);
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800103 return 1;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000104}
105
106/*
107 * Process ICMPv6 echo replies
108 */
109static uword
110ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500111 vlib_node_runtime_t * node, vlib_frame_t * frame)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000112{
113 u32 n_left_from, *from;
114
Dave Barachd7cb1b52016-12-09 09:52:16 -0500115 from = vlib_frame_vector_args (frame); /* array of buffer indices */
116 n_left_from = frame->n_vectors; /* number of buffer indices */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000117
118 while (n_left_from > 0)
119 {
120 u32 bi0;
121 vlib_buffer_t *b0;
122 u32 next0;
123
124 bi0 = from[0];
125 b0 = vlib_get_buffer (vm, bi0);
126
Mohammed Hawari03a62132017-07-18 09:25:01 +0200127 next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP6, b0) ?
Dave Barachd7cb1b52016-12-09 09:52:16 -0500128 ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000129
Dave Barachd7cb1b52016-12-09 09:52:16 -0500130 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
131 {
132 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
133 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
134 tr->id = h0->icmp_echo.id;
135 tr->seq = h0->icmp_echo.seq;
136 tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
137 }
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800138
139 /* push this pkt to the next graph node */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000140 vlib_set_next_frame_buffer (vm, node, next0, bi0);
141
142 from += 1;
143 n_left_from -= 1;
144 }
145
146 return frame->n_vectors;
147}
148
149/* *INDENT-OFF* */
150VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
151{
152 .function = ip6_icmp_echo_reply_node_fn,
153 .name = "ip6-icmp-echo-reply",
154 .vector_size = sizeof (u32),
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800155 .format_trace = format_icmp_echo_trace,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000156 .n_next_nodes = ICMP6_ECHO_REPLY_N_NEXT,
157 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800158 [ICMP6_ECHO_REPLY_NEXT_DROP] = "ip6-drop",
159 [ICMP6_ECHO_REPLY_NEXT_PUNT] = "ip6-punt",
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000160 },
161};
162/* *INDENT-ON* */
163
164/*
165 * Process ICMPv4 echo replies
166 */
167static uword
168ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500169 vlib_node_runtime_t * node, vlib_frame_t * frame)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000170{
171 u32 n_left_from, *from;
172
Dave Barachd7cb1b52016-12-09 09:52:16 -0500173 from = vlib_frame_vector_args (frame); /* array of buffer indices */
174 n_left_from = frame->n_vectors; /* number of buffer indices */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000175
176 while (n_left_from > 0)
177 {
178 u32 bi0;
179 vlib_buffer_t *b0;
180 u32 next0;
181
182 bi0 = from[0];
183 b0 = vlib_get_buffer (vm, bi0);
184
Mohammed Hawari03a62132017-07-18 09:25:01 +0200185 next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP4, b0) ?
Dave Barachd7cb1b52016-12-09 09:52:16 -0500186 ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000187
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
189 {
190 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
191 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
192 tr->id = h0->icmp_echo.id;
193 tr->seq = h0->icmp_echo.seq;
194 tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
195 }
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800196
197 /* push this pkt to the next graph node */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000198 vlib_set_next_frame_buffer (vm, node, next0, bi0);
199
200 from += 1;
201 n_left_from -= 1;
202 }
203
204 return frame->n_vectors;
205}
206
207/* *INDENT-OFF* */
208VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) =
209{
210 .function = ip4_icmp_echo_reply_node_fn,
211 .name = "ip4-icmp-echo-reply",
212 .vector_size = sizeof (u32),
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800213 .format_trace = format_icmp_echo_trace,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000214 .n_next_nodes = ICMP4_ECHO_REPLY_N_NEXT,
215 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800216 [ICMP4_ECHO_REPLY_NEXT_DROP] = "ip4-drop",
217 [ICMP4_ECHO_REPLY_NEXT_PUNT] = "ip4-punt",
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000218 },
219};
220/* *INDENT-ON* */
221
222char *ip6_lookup_next_nodes[] = IP6_LOOKUP_NEXT_NODES;
223char *ip4_lookup_next_nodes[] = IP4_LOOKUP_NEXT_NODES;
224
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000225/* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
226static u16
227init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500228 u16 seq_host, u16 id_host, u16 data_len)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000229{
230 int i;
231 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
232 icmp46_echo->id = clib_host_to_net_u16 (id_host);
233
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000234 if (data_len > PING_MAXIMUM_DATA_SIZE)
235 data_len = PING_MAXIMUM_DATA_SIZE;
236 for (i = 0; i < data_len; i++)
237 icmp46_echo->data[i] = i % 256;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000238 return data_len;
239}
240
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000241static send_ip46_ping_result_t
Neale Rannsf06aea52016-11-29 06:51:37 -0800242send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500243 u32 table_id, ip6_address_t * pa6,
244 u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100245 u32 burst, u8 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000246{
247 icmp6_echo_request_header_t *h0;
248 u32 bi0 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000249 int bogus_length = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000250 vlib_buffer_t *p0;
251 vlib_frame_t *f;
252 u32 *to_next;
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000253 vlib_buffer_free_list_t *fl;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000254
255 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
256 return SEND_PING_ALLOC_FAIL;
257
258 p0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000259 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
260 vlib_buffer_init_for_free_list (p0, fl);
261 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000262
Neale Rannsf06aea52016-11-29 06:51:37 -0800263 /*
264 * if the user did not provide a source interface, use the any interface
265 * that the destination resolves via.
266 */
267 if (~0 == sw_if_index)
268 {
269 fib_node_index_t fib_entry_index;
270 u32 fib_index;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100271
Dave Barachd7cb1b52016-12-09 09:52:16 -0500272 fib_index = ip6_fib_index_from_table_id (table_id);
Neale Rannsf06aea52016-11-29 06:51:37 -0800273
274 if (~0 == fib_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500275 {
276 vlib_buffer_free (vm, &bi0, 1);
277 return SEND_PING_NO_TABLE;
278 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800279
Dave Barachd7cb1b52016-12-09 09:52:16 -0500280 fib_entry_index = ip6_fib_table_lookup (fib_index, pa6, 128);
281 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800282 /*
283 * Set the TX interface to force ip-lookup to use its table ID
284 */
285 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
286 }
287 else
288 {
289 /*
290 * force an IP lookup in the table bound to the user's chosen
291 * source interface.
292 */
293 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500294 ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800295 }
296
297 if (~0 == sw_if_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100298 {
299 vlib_buffer_free (vm, &bi0, 1);
300 return SEND_PING_NO_INTERFACE;
301 }
302
Neale Rannsf06aea52016-11-29 06:51:37 -0800303 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000304
305 h0 = vlib_buffer_get_current (p0);
306
307 /* Fill in ip6 header fields */
308 h0->ip6.ip_version_traffic_class_and_flow_label =
309 clib_host_to_net_u32 (0x6 << 28);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500310 h0->ip6.payload_length = 0; /* Set below */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000311 h0->ip6.protocol = IP_PROTOCOL_ICMP6;
312 h0->ip6.hop_limit = 255;
313 h0->ip6.dst_address = *pa6;
314 h0->ip6.src_address = *pa6;
315
316 /* Fill in the correct source now */
Neale Rannsf06aea52016-11-29 06:51:37 -0800317 ip6_address_t *a = ip6_interface_first_address (im, sw_if_index);
Andrew Yourtchenko1b33fde2017-03-16 12:24:24 +0000318 if (!a)
319 {
320 vlib_buffer_free (vm, &bi0, 1);
321 return SEND_PING_NO_SRC_ADDRESS;
322 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000323 h0->ip6.src_address = a[0];
324
325 /* Fill in icmp fields */
326 h0->icmp.type = ICMP6_echo_request;
327 h0->icmp.code = 0;
328 h0->icmp.checksum = 0;
329
330 data_len =
331 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
332 h0->icmp_echo.time_sent = vlib_time_now (vm);
333
334 /* Fix up the lengths */
335 h0->ip6.payload_length =
336 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t));
337
338 p0->current_length = clib_net_to_host_u16 (h0->ip6.payload_length) +
339 STRUCT_OFFSET_OF (icmp6_echo_request_header_t, icmp);
340
341 /* Calculate the ICMP checksum */
342 h0->icmp.checksum = 0;
343 h0->icmp.checksum =
344 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip6, &bogus_length);
345
346 /* Enqueue the packet right now */
347 f = vlib_get_frame_to_node (vm, ip6_lookup_node.index);
348 to_next = vlib_frame_vector_args (f);
349 to_next[0] = bi0;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100350
351 ASSERT (burst <= VLIB_FRAME_SIZE);
352 f->n_vectors = burst;
353 while (--burst)
354 {
355 vlib_buffer_t *c0 = vlib_buffer_copy (vm, p0);
356 to_next++;
357 to_next[0] = vlib_get_buffer_index (vm, c0);
358 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000359 vlib_put_frame_to_node (vm, ip6_lookup_node.index, f);
360
361 return SEND_PING_OK;
362}
363
364static send_ip46_ping_result_t
365send_ip4_ping (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500366 ip4_main_t * im,
367 u32 table_id,
368 ip4_address_t * pa4,
369 u32 sw_if_index,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100370 u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000371{
372 icmp4_echo_request_header_t *h0;
373 u32 bi0 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000374 ip_lookup_main_t *lm = &im->lookup_main;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000375 vlib_buffer_t *p0;
376 vlib_frame_t *f;
377 u32 *to_next;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000378 u32 if_add_index0;
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000379 vlib_buffer_free_list_t *fl;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000380
381 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
382 return SEND_PING_ALLOC_FAIL;
383
384 p0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000385 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);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000388
Neale Rannsf06aea52016-11-29 06:51:37 -0800389 /*
390 * if the user did not provide a source interface, use the any interface
391 * that the destination resolves via.
392 */
393 if (~0 == sw_if_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500394 {
Neale Rannsf06aea52016-11-29 06:51:37 -0800395 fib_node_index_t fib_entry_index;
396 u32 fib_index;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100397
Dave Barachd7cb1b52016-12-09 09:52:16 -0500398 fib_index = ip4_fib_index_from_table_id (table_id);
Neale Rannsf06aea52016-11-29 06:51:37 -0800399
400 if (~0 == fib_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500401 {
402 vlib_buffer_free (vm, &bi0, 1);
403 return SEND_PING_NO_TABLE;
404 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800405
Dave Barachd7cb1b52016-12-09 09:52:16 -0500406 fib_entry_index =
407 ip4_fib_table_lookup (ip4_fib_get (fib_index), pa4, 32);
408 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800409 /*
410 * Set the TX interface to force ip-lookup to use the user's table ID
411 */
412 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
413 }
414 else
415 {
416 /*
417 * force an IP lookup in the table bound to the user's chosen
418 * source interface.
419 */
420 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500421 ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800422 }
423
424 if (~0 == sw_if_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100425 {
426 vlib_buffer_free (vm, &bi0, 1);
427 return SEND_PING_NO_INTERFACE;
428 }
429
Neale Rannsf06aea52016-11-29 06:51:37 -0800430 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000431
432 h0 = vlib_buffer_get_current (p0);
433
434 /* Fill in ip4 header fields */
435 h0->ip4.checksum = 0;
436 h0->ip4.ip_version_and_header_length = 0x45;
437 h0->ip4.tos = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500438 h0->ip4.length = 0; /* Set below */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000439 h0->ip4.fragment_id = 0;
440 h0->ip4.flags_and_fragment_offset = 0;
441 h0->ip4.ttl = 0xff;
442 h0->ip4.protocol = IP_PROTOCOL_ICMP;
443 h0->ip4.dst_address = *pa4;
444 h0->ip4.src_address = *pa4;
445
446 /* Fill in the correct source now */
Neale Rannsf06aea52016-11-29 06:51:37 -0800447 if_add_index0 = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000448 if (PREDICT_TRUE (if_add_index0 != ~0))
449 {
450 ip_interface_address_t *if_add =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500451 pool_elt_at_index (lm->if_address_pool, if_add_index0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000452 ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
453 h0->ip4.src_address = *if_ip;
454 if (verbose)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500455 {
456 vlib_cli_output (vm, "Source address: %U",
457 format_ip4_address, &h0->ip4.src_address);
458 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000459 }
460
461 /* Fill in icmp fields */
462 h0->icmp.type = ICMP4_echo_request;
463 h0->icmp.code = 0;
464 h0->icmp.checksum = 0;
465
466 data_len =
467 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
468 h0->icmp_echo.time_sent = vlib_time_now (vm);
469
470 /* Fix up the lengths */
471 h0->ip4.length =
472 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t) +
Dave Barachd7cb1b52016-12-09 09:52:16 -0500473 sizeof (ip4_header_t));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000474
475 p0->current_length = clib_net_to_host_u16 (h0->ip4.length);
476
477 /* Calculate the IP and ICMP checksums */
478 h0->ip4.checksum = ip4_header_checksum (&(h0->ip4));
479 h0->icmp.checksum =
480 ~ip_csum_fold (ip_incremental_checksum (0, &(h0->icmp),
Dave Barachd7cb1b52016-12-09 09:52:16 -0500481 p0->current_length -
482 sizeof (ip4_header_t)));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000483
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);
487 to_next[0] = bi0;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100488
489 ASSERT (burst <= VLIB_FRAME_SIZE);
490 f->n_vectors = burst;
491 while (--burst)
492 {
493 vlib_buffer_t *c0 = vlib_buffer_copy (vm, p0);
494 to_next++;
495 to_next[0] = vlib_get_buffer_index (vm, c0);
496 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000497 vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
498
499 return SEND_PING_OK;
500}
501
502
503static void
504print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0)
505{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500506 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000507 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
Mohammed Hawari03a62132017-07-18 09:25:01 +0200508 f64 rtt = 0;
509 clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt));
510 rtt -= h0->icmp_echo.time_sent;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000511 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500512 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
513 clib_host_to_net_u16 (h0->ip6.payload_length),
514 format_ip6_address,
515 &h0->ip6.src_address,
516 clib_host_to_net_u16 (h0->icmp_echo.seq),
517 h0->ip6.hop_limit, rtt * 1000.0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000518}
519
520static void
521print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
522{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500523 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000524 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
Mohammed Hawari03a62132017-07-18 09:25:01 +0200525 f64 rtt = 0;
526 clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt));
527 rtt -= h0->icmp_echo.time_sent;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000528 u32 rcvd_icmp_len =
529 clib_host_to_net_u16 (h0->ip4.length) -
530 (4 * (0xF & h0->ip4.ip_version_and_header_length));
531
532 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500533 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
534 rcvd_icmp_len,
535 format_ip4_address,
536 &h0->ip4.src_address,
537 clib_host_to_net_u16 (h0->icmp_echo.seq),
538 h0->ip4.ttl, rtt * 1000.0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000539}
540
541
542/*
543 * Perform the ping run with the given parameters in the current CLI process.
544 * Depending on whether pa4 or pa6 is set, runs IPv4 or IPv6 ping.
545 * The amusing side effect is of course if both are set, then both pings are sent.
546 * This behavior can be used to ping a dualstack host over IPv4 and IPv6 at once.
547 */
548
549static void
Neale Rannsf06aea52016-11-29 06:51:37 -0800550run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500551 ip6_address_t * pa6, u32 sw_if_index,
552 f64 ping_interval, u32 ping_repeat, u32 data_len,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100553 u32 ping_burst, u32 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000554{
555 int i;
556 ping_main_t *pm = &ping_main;
557 uword curr_proc = vlib_current_process (vm);
558 u32 n_replies = 0;
559 u32 n_requests = 0;
560 ping_run_t *pr = 0;
561 u32 ping_run_index = 0;
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000562 u16 icmp_id;
563
564 static u32 rand_seed = 0;
565
Dave Barachd7cb1b52016-12-09 09:52:16 -0500566 if (PREDICT_FALSE (!rand_seed))
567 rand_seed = random_default_seed ();
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000568
Dave Barachd7cb1b52016-12-09 09:52:16 -0500569 icmp_id = random_u32 (&rand_seed) & 0xffff;
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000570
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000571 while (hash_get (pm->ping_run_by_icmp_id, icmp_id))
572 {
573 vlib_cli_output (vm, "ICMP ID collision at %d, incrementing", icmp_id);
574 icmp_id++;
575 }
576 pool_get (pm->ping_runs, pr);
577 ping_run_index = pr - pm->ping_runs;
578 pr->cli_process_id = curr_proc;
Mohammed Hawari03a62132017-07-18 09:25:01 +0200579 pr->cli_thread_index = vlib_get_thread_index ();
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000580 pr->icmp_id = icmp_id;
581 hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index);
582 for (i = 1; i <= ping_repeat; i++)
583 {
584 f64 sleep_interval;
585 f64 time_ping_sent = vlib_time_now (vm);
586 /* Reset pr: running ping in other process could have changed pm->ping_runs */
587 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
588 pr->curr_seq = i;
589 if (pa6 &&
Dave Barachd7cb1b52016-12-09 09:52:16 -0500590 (SEND_PING_OK ==
591 send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100592 i, icmp_id, data_len, ping_burst, verbose)))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500593 {
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100594 n_requests += ping_burst;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500595 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000596 if (pa4 &&
Dave Barachd7cb1b52016-12-09 09:52:16 -0500597 (SEND_PING_OK ==
598 send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100599 i, icmp_id, data_len, ping_burst, verbose)))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500600 {
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100601 n_requests += ping_burst;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500602 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000603 while ((i <= ping_repeat)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500604 &&
605 ((sleep_interval =
606 time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
607 {
608 uword event_type, *event_data = 0;
609 vlib_process_wait_for_event_or_clock (vm, sleep_interval);
610 event_type = vlib_process_get_events (vm, &event_data);
611 switch (event_type)
612 {
613 case ~0: /* no events => timeout */
614 break;
615 case PING_RESPONSE_IP6:
616 {
617 int i;
618 for (i = 0; i < vec_len (event_data); i++)
619 {
Andrew Yourtchenkof69ecfe2017-01-24 15:47:27 +0100620 u32 bi0 = event_data[i];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500621 print_ip6_icmp_reply (vm, bi0);
622 n_replies++;
623 if (0 != bi0)
624 {
625 vlib_buffer_free (vm, &bi0, 1);
626 }
627 }
628 }
629 break;
630 case PING_RESPONSE_IP4:
631 {
632 int i;
633 for (i = 0; i < vec_len (event_data); i++)
634 {
Andrew Yourtchenkof69ecfe2017-01-24 15:47:27 +0100635 u32 bi0 = event_data[i];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500636 print_ip4_icmp_reply (vm, bi0);
637 n_replies++;
638 if (0 != bi0)
639 {
640 vlib_buffer_free (vm, &bi0, 1);
641 }
642 }
643 }
644 break;
645 default:
646 /* someone pressed a key, abort */
647 vlib_cli_output (vm, "Aborted due to a keypress.");
648 i = 1 + ping_repeat;
649 break;
650 }
Dave Barach69128d02017-09-26 10:54:34 -0400651 vec_free (event_data);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500652 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000653 }
654 vlib_cli_output (vm, "\n");
655 {
656 float loss =
657 (0 ==
658 n_requests) ? 0 : 100.0 * ((float) n_requests -
Dave Barachd7cb1b52016-12-09 09:52:16 -0500659 (float) n_replies) / (float) n_requests;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000660 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500661 "Statistics: %u sent, %u received, %f%% packet loss\n",
662 n_requests, n_replies, loss);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000663 /* Reset pr: running ping in other process could have changed pm->ping_runs */
664 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
665 hash_unset (pm->ping_run_by_icmp_id, icmp_id);
666 pool_put (pm->ping_runs, pr);
667 }
668}
669
670
671
672
673
674static clib_error_t *
675ping_ip_address (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500676 unformat_input_t * input, vlib_cli_command_t * cmd)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000677{
678 ip4_address_t a4;
679 ip6_address_t a6;
680 clib_error_t *error = 0;
681 u32 ping_repeat = 5;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100682 u32 ping_burst = 1;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000683 u8 ping_ip4, ping_ip6;
684 vnet_main_t *vnm = vnet_get_main ();
685 u32 data_len = PING_DEFAULT_DATA_LEN;
686 u32 verbose = 0;
687 f64 ping_interval = PING_DEFAULT_INTERVAL;
Neale Rannsf06aea52016-11-29 06:51:37 -0800688 u32 sw_if_index, table_id;
689
690 table_id = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000691 ping_ip4 = ping_ip6 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000692 sw_if_index = ~0;
Neale Rannsf06aea52016-11-29 06:51:37 -0800693
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000694 if (unformat (input, "%U", unformat_ip4_address, &a4))
695 {
696 ping_ip4 = 1;
697 }
698 else if (unformat (input, "%U", unformat_ip6_address, &a6))
699 {
700 ping_ip6 = 1;
701 }
702 else if (unformat (input, "ipv4"))
703 {
704 if (unformat (input, "%U", unformat_ip4_address, &a4))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500705 {
706 ping_ip4 = 1;
707 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000708 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500709 {
710 error =
711 clib_error_return (0,
712 "expecting IPv4 address but got `%U'",
713 format_unformat_error, input);
714 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000715 }
716 else if (unformat (input, "ipv6"))
717 {
718 if (unformat (input, "%U", unformat_ip6_address, &a6))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500719 {
720 ping_ip6 = 1;
721 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000722 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500723 {
724 error =
725 clib_error_return (0,
726 "expecting IPv6 address but got `%U'",
727 format_unformat_error, input);
728 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000729 }
730 else
731 {
732 error =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500733 clib_error_return (0,
734 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
735 format_unformat_error, input);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000736 goto done;
737 }
738
739 /* allow for the second AF in the same ping */
740 if (!ping_ip4 && (unformat (input, "ipv4")))
741 {
742 if (unformat (input, "%U", unformat_ip4_address, &a4))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500743 {
744 ping_ip4 = 1;
745 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000746 }
747 else if (!ping_ip6 && (unformat (input, "ipv6")))
748 {
749 if (unformat (input, "%U", unformat_ip6_address, &a6))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500750 {
751 ping_ip6 = 1;
752 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000753 }
754
755 /* parse the rest of the parameters in a cycle */
756 while (!unformat_eof (input, NULL))
757 {
758 if (unformat (input, "source"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500759 {
760 if (!unformat_user
761 (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
762 {
763 error =
764 clib_error_return (0,
765 "unknown interface `%U'",
766 format_unformat_error, input);
767 goto done;
768 }
769 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000770 else if (unformat (input, "size"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500771 {
772 if (!unformat (input, "%u", &data_len))
773 {
774 error =
775 clib_error_return (0,
776 "expecting size but got `%U'",
777 format_unformat_error, input);
778 goto done;
779 }
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000780 if (data_len > PING_MAXIMUM_DATA_SIZE)
781 {
782 error =
783 clib_error_return (0,
784 "%d is bigger than maximum allowed payload size %d",
785 data_len, PING_MAXIMUM_DATA_SIZE);
786 goto done;
787 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500788 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800789 else if (unformat (input, "table-id"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500790 {
wenxian li6e19b372017-06-04 13:52:07 +0000791 if (!unformat (input, "%u", &table_id))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500792 {
793 error =
794 clib_error_return (0,
795 "expecting table-id but got `%U'",
796 format_unformat_error, input);
797 goto done;
798 }
799 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000800 else if (unformat (input, "interval"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500801 {
802 if (!unformat (input, "%f", &ping_interval))
803 {
804 error =
805 clib_error_return (0,
806 "expecting interval (floating point number) got `%U'",
807 format_unformat_error, input);
808 goto done;
809 }
810 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000811 else if (unformat (input, "repeat"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500812 {
813 if (!unformat (input, "%u", &ping_repeat))
814 {
815 error =
816 clib_error_return (0,
817 "expecting repeat count but got `%U'",
818 format_unformat_error, input);
819 goto done;
820 }
821 }
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100822 else if (unformat (input, "burst"))
823 {
824 if (!unformat (input, "%u", &ping_burst))
825 {
826 error =
827 clib_error_return (0,
828 "expecting burst count but got `%U'",
829 format_unformat_error, input);
830 goto done;
831 }
832 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000833 else if (unformat (input, "verbose"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500834 {
835 verbose = 1;
836 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000837 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500838 {
839 error = clib_error_return (0, "unknown input `%U'",
840 format_unformat_error, input);
841 goto done;
842 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000843 }
844
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100845 if (ping_burst < 1 || ping_burst > VLIB_FRAME_SIZE)
846 return clib_error_return (0, "burst size must be between 1 and %u",
847 VLIB_FRAME_SIZE);
848
Dave Barachd7cb1b52016-12-09 09:52:16 -0500849 run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
850 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
Andrew Yourtchenkoe3d52802017-03-24 17:46:42 +0100851 ping_repeat, data_len, ping_burst, verbose);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000852done:
853 return error;
854}
855
Billy McFall0683c9c2016-10-13 08:27:31 -0400856/*?
857 * This command sends an ICMP ECHO_REQUEST to network hosts. The address
858 * can be an IPv4 or IPv6 address (or both at the same time).
859 *
860 * @cliexpar
861 * @parblock
862 * Example of how ping an IPv4 address:
863 * @cliexstart{ping 172.16.1.2 source GigabitEthernet2/0/0 repeat 2}
864 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1090 ms
865 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0914 ms
866 *
867 * Statistics: 2 sent, 2 received, 0% packet loss
868 * @cliexend
869 *
870 * Example of how ping both an IPv4 address and IPv6 address at the same time:
871 * @cliexstart{ping 172.16.1.2 ipv6 fe80::24a5:f6ff:fe9c:3a36 source GigabitEthernet2/0/0 repeat 2 verbose}
872 * Adjacency index: 10, sw_if_index: 1
873 * Adj: ip6-discover-neighbor
874 * Adj Interface: 0
875 * Forced set interface: 1
876 * Adjacency index: 0, sw_if_index: 4294967295
877 * Adj: ip4-miss
878 * Adj Interface: 0
879 * Forced set interface: 1
880 * Source address: 172.16.1.1
881 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1899 ms
882 * Adjacency index: 10, sw_if_index: 1
883 * Adj: ip6-discover-neighbor
884 * Adj Interface: 0
885 * Forced set interface: 1
886 * Adjacency index: 0, sw_if_index: 4294967295
887 * Adj: ip4-miss
888 * Adj Interface: 0
889 * Forced set interface: 1
890 * Source address: 172.16.1.1
891 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0910 ms
892 *
893 * Statistics: 4 sent, 2 received, 50% packet loss
894 * @cliexend
895 * @endparblock
896?*/
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000897/* *INDENT-OFF* */
898VLIB_CLI_COMMAND (ping_command, static) =
899{
900 .path = "ping",
901 .function = ping_ip_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500902 .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
903 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
904 " [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>]"
905 " [verbose]",
flyingeagle2392a838b2017-05-15 16:57:20 +0800906 .is_mp_safe = 1,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000907};
908/* *INDENT-ON* */
909
910static clib_error_t *
911ping_cli_init (vlib_main_t * vm)
912{
913 ping_main_t *pm = &ping_main;
914 pm->ip6_main = &ip6_main;
915 pm->ip4_main = &ip4_main;
916 icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
917 ip4_icmp_register_type (vm, ICMP4_echo_reply,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500918 ip4_icmp_echo_reply_node.index);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000919 return 0;
920}
921
922VLIB_INIT_FUNCTION (ping_cli_init);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500923
924/*
925 * fd.io coding-style-patch-verification: ON
926 *
927 * Local Variables:
928 * eval: (c-set-style "gnu")
929 * End:
930 */