blob: 2c5c44f5f26ee51195969209d47127b75244ae03 [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
Neale Rannse9239c92018-10-15 05:47:58 -070049static u8 *
50format_ip46_ping_result (u8 * s, va_list * args)
51{
52 send_ip46_ping_result_t res = va_arg (*args, send_ip46_ping_result_t);
53
54 switch (res)
55 {
56#define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);
57 foreach_ip46_ping_result
58#undef _
59 }
60
61 return (s);
62}
63
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000064/*
65 * If we can find the ping run by an ICMP ID, then we send the signal
66 * to the CLI process referenced by that ping run, alongside with
67 * a freshly made copy of the packet.
68 * I opted for a packet copy to keep the main packet processing path
69 * the same as for all the other nodes.
70 *
71 */
72
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080073static int
Mohammed Hawari03a62132017-07-18 09:25:01 +020074signal_ip46_icmp_reply_event (u8 event_type, vlib_buffer_t * b0)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000075{
76 ping_main_t *pm = &ping_main;
77 u16 net_icmp_id = 0;
78 u32 bi0_copy = 0;
79
80 switch (event_type)
81 {
82 case PING_RESPONSE_IP4:
83 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050084 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
85 net_icmp_id = h0->icmp_echo.id;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000086 }
87 break;
88 case PING_RESPONSE_IP6:
89 {
Dave Barachd7cb1b52016-12-09 09:52:16 -050090 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
91 net_icmp_id = h0->icmp_echo.id;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000092 }
93 break;
94 default:
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -080095 return 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +000096 }
97
98 uword *p = hash_get (pm->ping_run_by_icmp_id,
Dave Barachd7cb1b52016-12-09 09:52:16 -050099 clib_net_to_host_u16 (net_icmp_id));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000100 if (!p)
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800101 return 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000102
103 ping_run_t *pr = vec_elt_at_index (pm->ping_runs, p[0]);
Mohammed Hawari03a62132017-07-18 09:25:01 +0200104 vlib_main_t *vm = vlib_mains[pr->cli_thread_index];
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000105 if (vlib_buffer_alloc (vm, &bi0_copy, 1) == 1)
106 {
Mohammed Hawari03a62132017-07-18 09:25:01 +0200107 void *dst = vlib_buffer_get_current (vlib_get_buffer (vm,
108 bi0_copy));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000109 clib_memcpy (dst, vlib_buffer_get_current (b0), b0->current_length);
110 }
111 /* If buffer_alloc failed, bi0_copy == 0 - just signaling an event. */
Mohammed Hawari03a62132017-07-18 09:25:01 +0200112 f64 nowts = vlib_time_now (vm);
113 /* Pass the timestamp to the cli_process thanks to the vnet_buffer unused metadata field */
114 clib_memcpy (vnet_buffer
115 (vlib_get_buffer
116 (vm, bi0_copy))->unused, &nowts, sizeof (nowts));
Dave Barach69128d02017-09-26 10:54:34 -0400117 vlib_process_signal_event_mt (vm, pr->cli_process_id, event_type, bi0_copy);
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800118 return 1;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000119}
120
121/*
122 * Process ICMPv6 echo replies
123 */
124static uword
125ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500126 vlib_node_runtime_t * node, vlib_frame_t * frame)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000127{
128 u32 n_left_from, *from;
129
Dave Barachd7cb1b52016-12-09 09:52:16 -0500130 from = vlib_frame_vector_args (frame); /* array of buffer indices */
131 n_left_from = frame->n_vectors; /* number of buffer indices */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000132
133 while (n_left_from > 0)
134 {
135 u32 bi0;
136 vlib_buffer_t *b0;
137 u32 next0;
138
139 bi0 = from[0];
140 b0 = vlib_get_buffer (vm, bi0);
141
Mohammed Hawari03a62132017-07-18 09:25:01 +0200142 next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP6, b0) ?
Dave Barachd7cb1b52016-12-09 09:52:16 -0500143 ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000144
Dave Barachd7cb1b52016-12-09 09:52:16 -0500145 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
146 {
147 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
148 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
149 tr->id = h0->icmp_echo.id;
150 tr->seq = h0->icmp_echo.seq;
151 tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
152 }
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800153
154 /* push this pkt to the next graph node */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000155 vlib_set_next_frame_buffer (vm, node, next0, bi0);
156
157 from += 1;
158 n_left_from -= 1;
159 }
160
161 return frame->n_vectors;
162}
163
164/* *INDENT-OFF* */
165VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
166{
167 .function = ip6_icmp_echo_reply_node_fn,
168 .name = "ip6-icmp-echo-reply",
169 .vector_size = sizeof (u32),
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800170 .format_trace = format_icmp_echo_trace,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000171 .n_next_nodes = ICMP6_ECHO_REPLY_N_NEXT,
172 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800173 [ICMP6_ECHO_REPLY_NEXT_DROP] = "ip6-drop",
174 [ICMP6_ECHO_REPLY_NEXT_PUNT] = "ip6-punt",
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000175 },
176};
177/* *INDENT-ON* */
178
179/*
180 * Process ICMPv4 echo replies
181 */
182static uword
183ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500184 vlib_node_runtime_t * node, vlib_frame_t * frame)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000185{
186 u32 n_left_from, *from;
187
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188 from = vlib_frame_vector_args (frame); /* array of buffer indices */
189 n_left_from = frame->n_vectors; /* number of buffer indices */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000190
191 while (n_left_from > 0)
192 {
193 u32 bi0;
194 vlib_buffer_t *b0;
195 u32 next0;
196
197 bi0 = from[0];
198 b0 = vlib_get_buffer (vm, bi0);
199
Mohammed Hawari03a62132017-07-18 09:25:01 +0200200 next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP4, b0) ?
Dave Barachd7cb1b52016-12-09 09:52:16 -0500201 ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000202
Dave Barachd7cb1b52016-12-09 09:52:16 -0500203 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
204 {
205 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
206 icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
207 tr->id = h0->icmp_echo.id;
208 tr->seq = h0->icmp_echo.seq;
209 tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
210 }
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800211
212 /* push this pkt to the next graph node */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000213 vlib_set_next_frame_buffer (vm, node, next0, bi0);
214
215 from += 1;
216 n_left_from -= 1;
217 }
218
219 return frame->n_vectors;
220}
221
222/* *INDENT-OFF* */
223VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) =
224{
225 .function = ip4_icmp_echo_reply_node_fn,
226 .name = "ip4-icmp-echo-reply",
227 .vector_size = sizeof (u32),
Alexander Popovskyc90dfdc2016-12-04 02:39:38 -0800228 .format_trace = format_icmp_echo_trace,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000229 .n_next_nodes = ICMP4_ECHO_REPLY_N_NEXT,
230 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800231 [ICMP4_ECHO_REPLY_NEXT_DROP] = "ip4-drop",
232 [ICMP4_ECHO_REPLY_NEXT_PUNT] = "ip4-punt",
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000233 },
234};
235/* *INDENT-ON* */
236
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000237/* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
238static u16
239init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500240 u16 seq_host, u16 id_host, u16 data_len)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000241{
242 int i;
243 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
244 icmp46_echo->id = clib_host_to_net_u16 (id_host);
245
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000246 if (data_len > PING_MAXIMUM_DATA_SIZE)
247 data_len = PING_MAXIMUM_DATA_SIZE;
248 for (i = 0; i < data_len; i++)
249 icmp46_echo->data[i] = i % 256;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000250 return data_len;
251}
252
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000253static send_ip46_ping_result_t
Neale Rannsf06aea52016-11-29 06:51:37 -0800254send_ip6_ping (vlib_main_t * vm, ip6_main_t * im,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500255 u32 table_id, ip6_address_t * pa6,
256 u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100257 u32 burst, u8 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000258{
259 icmp6_echo_request_header_t *h0;
260 u32 bi0 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000261 int bogus_length = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000262 vlib_buffer_t *p0;
263 vlib_frame_t *f;
264 u32 *to_next;
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000265 vlib_buffer_free_list_t *fl;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000266
267 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
268 return SEND_PING_ALLOC_FAIL;
269
270 p0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000271 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
272 vlib_buffer_init_for_free_list (p0, fl);
273 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000274
Neale Rannsf06aea52016-11-29 06:51:37 -0800275 /*
276 * if the user did not provide a source interface, use the any interface
277 * that the destination resolves via.
278 */
279 if (~0 == sw_if_index)
280 {
281 fib_node_index_t fib_entry_index;
282 u32 fib_index;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100283
Dave Barachd7cb1b52016-12-09 09:52:16 -0500284 fib_index = ip6_fib_index_from_table_id (table_id);
Neale Rannsf06aea52016-11-29 06:51:37 -0800285
286 if (~0 == fib_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500287 {
288 vlib_buffer_free (vm, &bi0, 1);
289 return SEND_PING_NO_TABLE;
290 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800291
Dave Barachd7cb1b52016-12-09 09:52:16 -0500292 fib_entry_index = ip6_fib_table_lookup (fib_index, pa6, 128);
293 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800294 /*
295 * Set the TX interface to force ip-lookup to use its table ID
296 */
297 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
298 }
299 else
300 {
301 /*
302 * force an IP lookup in the table bound to the user's chosen
303 * source interface.
304 */
305 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500306 ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800307 }
308
309 if (~0 == sw_if_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100310 {
311 vlib_buffer_free (vm, &bi0, 1);
312 return SEND_PING_NO_INTERFACE;
313 }
314
Neale Rannsf06aea52016-11-29 06:51:37 -0800315 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000316
317 h0 = vlib_buffer_get_current (p0);
318
319 /* Fill in ip6 header fields */
320 h0->ip6.ip_version_traffic_class_and_flow_label =
321 clib_host_to_net_u32 (0x6 << 28);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500322 h0->ip6.payload_length = 0; /* Set below */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000323 h0->ip6.protocol = IP_PROTOCOL_ICMP6;
324 h0->ip6.hop_limit = 255;
325 h0->ip6.dst_address = *pa6;
326 h0->ip6.src_address = *pa6;
327
328 /* Fill in the correct source now */
Neale Ranns53da2212018-02-24 02:11:19 -0800329 if (!ip6_src_address_for_packet (&im->lookup_main,
330 sw_if_index,
331 &h0->ip6.dst_address,
332 &h0->ip6.src_address))
Andrew Yourtchenko1b33fde2017-03-16 12:24:24 +0000333 {
334 vlib_buffer_free (vm, &bi0, 1);
335 return SEND_PING_NO_SRC_ADDRESS;
336 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000337
338 /* Fill in icmp fields */
339 h0->icmp.type = ICMP6_echo_request;
340 h0->icmp.code = 0;
341 h0->icmp.checksum = 0;
342
343 data_len =
344 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
345 h0->icmp_echo.time_sent = vlib_time_now (vm);
346
347 /* Fix up the lengths */
348 h0->ip6.payload_length =
349 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t));
350
351 p0->current_length = clib_net_to_host_u16 (h0->ip6.payload_length) +
352 STRUCT_OFFSET_OF (icmp6_echo_request_header_t, icmp);
353
354 /* Calculate the ICMP checksum */
355 h0->icmp.checksum = 0;
356 h0->icmp.checksum =
357 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip6, &bogus_length);
358
359 /* Enqueue the packet right now */
360 f = vlib_get_frame_to_node (vm, ip6_lookup_node.index);
361 to_next = vlib_frame_vector_args (f);
362 to_next[0] = bi0;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100363
364 ASSERT (burst <= VLIB_FRAME_SIZE);
365 f->n_vectors = burst;
366 while (--burst)
367 {
368 vlib_buffer_t *c0 = vlib_buffer_copy (vm, p0);
369 to_next++;
370 to_next[0] = vlib_get_buffer_index (vm, c0);
371 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000372 vlib_put_frame_to_node (vm, ip6_lookup_node.index, f);
373
374 return SEND_PING_OK;
375}
376
377static send_ip46_ping_result_t
378send_ip4_ping (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500379 ip4_main_t * im,
380 u32 table_id,
381 ip4_address_t * pa4,
382 u32 sw_if_index,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100383 u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000384{
385 icmp4_echo_request_header_t *h0;
386 u32 bi0 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000387 ip_lookup_main_t *lm = &im->lookup_main;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000388 vlib_buffer_t *p0;
389 vlib_frame_t *f;
390 u32 *to_next;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000391 u32 if_add_index0;
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000392 vlib_buffer_free_list_t *fl;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000393
394 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
395 return SEND_PING_ALLOC_FAIL;
396
397 p0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000398 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
399 vlib_buffer_init_for_free_list (p0, fl);
400 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000401
Neale Rannsf06aea52016-11-29 06:51:37 -0800402 /*
403 * if the user did not provide a source interface, use the any interface
404 * that the destination resolves via.
405 */
406 if (~0 == sw_if_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500407 {
Neale Rannsf06aea52016-11-29 06:51:37 -0800408 fib_node_index_t fib_entry_index;
409 u32 fib_index;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100410
Dave Barachd7cb1b52016-12-09 09:52:16 -0500411 fib_index = ip4_fib_index_from_table_id (table_id);
Neale Rannsf06aea52016-11-29 06:51:37 -0800412
413 if (~0 == fib_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500414 {
415 vlib_buffer_free (vm, &bi0, 1);
416 return SEND_PING_NO_TABLE;
417 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800418
Dave Barachd7cb1b52016-12-09 09:52:16 -0500419 fib_entry_index =
420 ip4_fib_table_lookup (ip4_fib_get (fib_index), pa4, 32);
421 sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800422 /*
423 * Set the TX interface to force ip-lookup to use the user's table ID
424 */
425 vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
426 }
427 else
428 {
429 /*
430 * force an IP lookup in the table bound to the user's chosen
431 * source interface.
432 */
433 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500434 ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
Neale Rannsf06aea52016-11-29 06:51:37 -0800435 }
436
437 if (~0 == sw_if_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100438 {
439 vlib_buffer_free (vm, &bi0, 1);
440 return SEND_PING_NO_INTERFACE;
441 }
442
Neale Rannsf06aea52016-11-29 06:51:37 -0800443 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000444
445 h0 = vlib_buffer_get_current (p0);
446
447 /* Fill in ip4 header fields */
448 h0->ip4.checksum = 0;
449 h0->ip4.ip_version_and_header_length = 0x45;
450 h0->ip4.tos = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500451 h0->ip4.length = 0; /* Set below */
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000452 h0->ip4.fragment_id = 0;
453 h0->ip4.flags_and_fragment_offset = 0;
454 h0->ip4.ttl = 0xff;
455 h0->ip4.protocol = IP_PROTOCOL_ICMP;
456 h0->ip4.dst_address = *pa4;
457 h0->ip4.src_address = *pa4;
458
459 /* Fill in the correct source now */
Neale Rannsf06aea52016-11-29 06:51:37 -0800460 if_add_index0 = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000461 if (PREDICT_TRUE (if_add_index0 != ~0))
462 {
463 ip_interface_address_t *if_add =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500464 pool_elt_at_index (lm->if_address_pool, if_add_index0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000465 ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
466 h0->ip4.src_address = *if_ip;
467 if (verbose)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500468 {
469 vlib_cli_output (vm, "Source address: %U",
470 format_ip4_address, &h0->ip4.src_address);
471 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000472 }
473
474 /* Fill in icmp fields */
475 h0->icmp.type = ICMP4_echo_request;
476 h0->icmp.code = 0;
477 h0->icmp.checksum = 0;
478
479 data_len =
480 init_icmp46_echo_request (&h0->icmp_echo, seq_host, id_host, data_len);
481 h0->icmp_echo.time_sent = vlib_time_now (vm);
482
483 /* Fix up the lengths */
484 h0->ip4.length =
485 clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t) +
Dave Barachd7cb1b52016-12-09 09:52:16 -0500486 sizeof (ip4_header_t));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000487
488 p0->current_length = clib_net_to_host_u16 (h0->ip4.length);
489
490 /* Calculate the IP and ICMP checksums */
491 h0->ip4.checksum = ip4_header_checksum (&(h0->ip4));
492 h0->icmp.checksum =
493 ~ip_csum_fold (ip_incremental_checksum (0, &(h0->icmp),
Dave Barachd7cb1b52016-12-09 09:52:16 -0500494 p0->current_length -
495 sizeof (ip4_header_t)));
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000496
497 /* Enqueue the packet right now */
498 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
499 to_next = vlib_frame_vector_args (f);
500 to_next[0] = bi0;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100501
502 ASSERT (burst <= VLIB_FRAME_SIZE);
503 f->n_vectors = burst;
504 while (--burst)
505 {
506 vlib_buffer_t *c0 = vlib_buffer_copy (vm, p0);
507 to_next++;
508 to_next[0] = vlib_get_buffer_index (vm, c0);
509 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000510 vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
511
512 return SEND_PING_OK;
513}
514
515
516static void
517print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0)
518{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500519 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000520 icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
Mohammed Hawari03a62132017-07-18 09:25:01 +0200521 f64 rtt = 0;
522 clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt));
523 rtt -= h0->icmp_echo.time_sent;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000524 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500525 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
526 clib_host_to_net_u16 (h0->ip6.payload_length),
527 format_ip6_address,
528 &h0->ip6.src_address,
529 clib_host_to_net_u16 (h0->icmp_echo.seq),
530 h0->ip6.hop_limit, rtt * 1000.0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000531}
532
533static void
534print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
535{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500536 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000537 icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
Mohammed Hawari03a62132017-07-18 09:25:01 +0200538 f64 rtt = 0;
539 clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt));
540 rtt -= h0->icmp_echo.time_sent;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000541 u32 rcvd_icmp_len =
542 clib_host_to_net_u16 (h0->ip4.length) -
543 (4 * (0xF & h0->ip4.ip_version_and_header_length));
544
545 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500546 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
547 rcvd_icmp_len,
548 format_ip4_address,
549 &h0->ip4.src_address,
550 clib_host_to_net_u16 (h0->icmp_echo.seq),
551 h0->ip4.ttl, rtt * 1000.0);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000552}
553
554
555/*
556 * Perform the ping run with the given parameters in the current CLI process.
557 * Depending on whether pa4 or pa6 is set, runs IPv4 or IPv6 ping.
558 * The amusing side effect is of course if both are set, then both pings are sent.
559 * This behavior can be used to ping a dualstack host over IPv4 and IPv6 at once.
560 */
561
562static void
Neale Rannsf06aea52016-11-29 06:51:37 -0800563run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500564 ip6_address_t * pa6, u32 sw_if_index,
565 f64 ping_interval, u32 ping_repeat, u32 data_len,
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100566 u32 ping_burst, u32 verbose)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000567{
568 int i;
569 ping_main_t *pm = &ping_main;
570 uword curr_proc = vlib_current_process (vm);
571 u32 n_replies = 0;
572 u32 n_requests = 0;
573 ping_run_t *pr = 0;
574 u32 ping_run_index = 0;
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000575 u16 icmp_id;
576
577 static u32 rand_seed = 0;
578
Dave Barachd7cb1b52016-12-09 09:52:16 -0500579 if (PREDICT_FALSE (!rand_seed))
580 rand_seed = random_default_seed ();
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000581
Dave Barachd7cb1b52016-12-09 09:52:16 -0500582 icmp_id = random_u32 (&rand_seed) & 0xffff;
Andrew Yourtchenkoacfb47d2016-09-14 15:51:16 +0000583
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000584 while (hash_get (pm->ping_run_by_icmp_id, icmp_id))
585 {
586 vlib_cli_output (vm, "ICMP ID collision at %d, incrementing", icmp_id);
587 icmp_id++;
588 }
589 pool_get (pm->ping_runs, pr);
590 ping_run_index = pr - pm->ping_runs;
591 pr->cli_process_id = curr_proc;
Damjan Marion067cd622018-07-11 12:47:43 +0200592 pr->cli_thread_index = vm->thread_index;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000593 pr->icmp_id = icmp_id;
594 hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index);
595 for (i = 1; i <= ping_repeat; i++)
596 {
Neale Rannse9239c92018-10-15 05:47:58 -0700597 send_ip46_ping_result_t res = SEND_PING_OK;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000598 f64 sleep_interval;
599 f64 time_ping_sent = vlib_time_now (vm);
600 /* Reset pr: running ping in other process could have changed pm->ping_runs */
601 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
602 pr->curr_seq = i;
Neale Rannse9239c92018-10-15 05:47:58 -0700603 if (pa6)
604 {
605 res = send_ip6_ping (vm, ping_main.ip6_main, table_id,
606 pa6, sw_if_index, i, icmp_id,
607 data_len, ping_burst, verbose);
608 }
609 if (pa4)
610 {
611 res = send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4,
612 sw_if_index, i, icmp_id, data_len,
613 ping_burst, verbose);
614 }
615 if (SEND_PING_OK == res)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500616 {
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100617 n_requests += ping_burst;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500618 }
Neale Rannse9239c92018-10-15 05:47:58 -0700619 else
620 vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000621 while ((i <= ping_repeat)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500622 &&
623 ((sleep_interval =
624 time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
625 {
626 uword event_type, *event_data = 0;
627 vlib_process_wait_for_event_or_clock (vm, sleep_interval);
628 event_type = vlib_process_get_events (vm, &event_data);
629 switch (event_type)
630 {
631 case ~0: /* no events => timeout */
632 break;
633 case PING_RESPONSE_IP6:
634 {
635 int i;
636 for (i = 0; i < vec_len (event_data); i++)
637 {
Andrew Yourtchenkof69ecfe2017-01-24 15:47:27 +0100638 u32 bi0 = event_data[i];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500639 print_ip6_icmp_reply (vm, bi0);
640 n_replies++;
641 if (0 != bi0)
642 {
643 vlib_buffer_free (vm, &bi0, 1);
644 }
645 }
646 }
647 break;
648 case PING_RESPONSE_IP4:
649 {
650 int i;
651 for (i = 0; i < vec_len (event_data); i++)
652 {
Andrew Yourtchenkof69ecfe2017-01-24 15:47:27 +0100653 u32 bi0 = event_data[i];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500654 print_ip4_icmp_reply (vm, bi0);
655 n_replies++;
656 if (0 != bi0)
657 {
658 vlib_buffer_free (vm, &bi0, 1);
659 }
660 }
661 }
662 break;
663 default:
664 /* someone pressed a key, abort */
665 vlib_cli_output (vm, "Aborted due to a keypress.");
666 i = 1 + ping_repeat;
667 break;
668 }
Dave Barach69128d02017-09-26 10:54:34 -0400669 vec_free (event_data);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500670 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000671 }
672 vlib_cli_output (vm, "\n");
673 {
674 float loss =
675 (0 ==
676 n_requests) ? 0 : 100.0 * ((float) n_requests -
Dave Barachd7cb1b52016-12-09 09:52:16 -0500677 (float) n_replies) / (float) n_requests;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000678 vlib_cli_output (vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500679 "Statistics: %u sent, %u received, %f%% packet loss\n",
680 n_requests, n_replies, loss);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000681 /* Reset pr: running ping in other process could have changed pm->ping_runs */
682 pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
683 hash_unset (pm->ping_run_by_icmp_id, icmp_id);
684 pool_put (pm->ping_runs, pr);
685 }
686}
687
688
689
690
691
692static clib_error_t *
693ping_ip_address (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500694 unformat_input_t * input, vlib_cli_command_t * cmd)
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000695{
696 ip4_address_t a4;
697 ip6_address_t a6;
698 clib_error_t *error = 0;
699 u32 ping_repeat = 5;
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100700 u32 ping_burst = 1;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000701 u8 ping_ip4, ping_ip6;
702 vnet_main_t *vnm = vnet_get_main ();
703 u32 data_len = PING_DEFAULT_DATA_LEN;
704 u32 verbose = 0;
705 f64 ping_interval = PING_DEFAULT_INTERVAL;
Neale Rannsf06aea52016-11-29 06:51:37 -0800706 u32 sw_if_index, table_id;
707
708 table_id = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000709 ping_ip4 = ping_ip6 = 0;
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000710 sw_if_index = ~0;
Neale Rannsf06aea52016-11-29 06:51:37 -0800711
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000712 if (unformat (input, "%U", unformat_ip4_address, &a4))
713 {
714 ping_ip4 = 1;
715 }
716 else if (unformat (input, "%U", unformat_ip6_address, &a6))
717 {
718 ping_ip6 = 1;
719 }
720 else if (unformat (input, "ipv4"))
721 {
722 if (unformat (input, "%U", unformat_ip4_address, &a4))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500723 {
724 ping_ip4 = 1;
725 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000726 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500727 {
728 error =
729 clib_error_return (0,
730 "expecting IPv4 address but got `%U'",
731 format_unformat_error, input);
732 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000733 }
734 else if (unformat (input, "ipv6"))
735 {
736 if (unformat (input, "%U", unformat_ip6_address, &a6))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500737 {
738 ping_ip6 = 1;
739 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000740 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500741 {
742 error =
743 clib_error_return (0,
744 "expecting IPv6 address but got `%U'",
745 format_unformat_error, input);
746 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000747 }
748 else
749 {
750 error =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500751 clib_error_return (0,
752 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
753 format_unformat_error, input);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000754 goto done;
755 }
756
757 /* allow for the second AF in the same ping */
758 if (!ping_ip4 && (unformat (input, "ipv4")))
759 {
760 if (unformat (input, "%U", unformat_ip4_address, &a4))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500761 {
762 ping_ip4 = 1;
763 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000764 }
765 else if (!ping_ip6 && (unformat (input, "ipv6")))
766 {
767 if (unformat (input, "%U", unformat_ip6_address, &a6))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500768 {
769 ping_ip6 = 1;
770 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000771 }
772
773 /* parse the rest of the parameters in a cycle */
774 while (!unformat_eof (input, NULL))
775 {
776 if (unformat (input, "source"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500777 {
778 if (!unformat_user
779 (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
780 {
781 error =
782 clib_error_return (0,
783 "unknown interface `%U'",
784 format_unformat_error, input);
785 goto done;
786 }
787 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000788 else if (unformat (input, "size"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500789 {
790 if (!unformat (input, "%u", &data_len))
791 {
792 error =
793 clib_error_return (0,
794 "expecting size but got `%U'",
795 format_unformat_error, input);
796 goto done;
797 }
Andrew Yourtchenko61459c92017-01-28 15:31:19 +0000798 if (data_len > PING_MAXIMUM_DATA_SIZE)
799 {
800 error =
801 clib_error_return (0,
802 "%d is bigger than maximum allowed payload size %d",
803 data_len, PING_MAXIMUM_DATA_SIZE);
804 goto done;
805 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500806 }
Neale Rannsf06aea52016-11-29 06:51:37 -0800807 else if (unformat (input, "table-id"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500808 {
wenxian li6e19b372017-06-04 13:52:07 +0000809 if (!unformat (input, "%u", &table_id))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500810 {
811 error =
812 clib_error_return (0,
813 "expecting table-id but got `%U'",
814 format_unformat_error, input);
815 goto done;
816 }
817 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000818 else if (unformat (input, "interval"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500819 {
820 if (!unformat (input, "%f", &ping_interval))
821 {
822 error =
823 clib_error_return (0,
824 "expecting interval (floating point number) got `%U'",
825 format_unformat_error, input);
826 goto done;
827 }
828 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000829 else if (unformat (input, "repeat"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500830 {
831 if (!unformat (input, "%u", &ping_repeat))
832 {
833 error =
834 clib_error_return (0,
835 "expecting repeat count but got `%U'",
836 format_unformat_error, input);
837 goto done;
838 }
839 }
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100840 else if (unformat (input, "burst"))
841 {
842 if (!unformat (input, "%u", &ping_burst))
843 {
844 error =
845 clib_error_return (0,
846 "expecting burst count but got `%U'",
847 format_unformat_error, input);
848 goto done;
849 }
850 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000851 else if (unformat (input, "verbose"))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500852 {
853 verbose = 1;
854 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000855 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500856 {
857 error = clib_error_return (0, "unknown input `%U'",
858 format_unformat_error, input);
859 goto done;
860 }
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000861 }
862
Andrew Yourtchenko864b25d2017-03-22 10:51:14 +0100863 if (ping_burst < 1 || ping_burst > VLIB_FRAME_SIZE)
864 return clib_error_return (0, "burst size must be between 1 and %u",
865 VLIB_FRAME_SIZE);
866
Dave Barachd7cb1b52016-12-09 09:52:16 -0500867 run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
868 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
Andrew Yourtchenkoe3d52802017-03-24 17:46:42 +0100869 ping_repeat, data_len, ping_burst, verbose);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000870done:
871 return error;
872}
873
Billy McFall0683c9c2016-10-13 08:27:31 -0400874/*?
875 * This command sends an ICMP ECHO_REQUEST to network hosts. The address
876 * can be an IPv4 or IPv6 address (or both at the same time).
877 *
878 * @cliexpar
879 * @parblock
880 * Example of how ping an IPv4 address:
881 * @cliexstart{ping 172.16.1.2 source GigabitEthernet2/0/0 repeat 2}
882 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1090 ms
883 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0914 ms
884 *
885 * Statistics: 2 sent, 2 received, 0% packet loss
886 * @cliexend
887 *
888 * Example of how ping both an IPv4 address and IPv6 address at the same time:
889 * @cliexstart{ping 172.16.1.2 ipv6 fe80::24a5:f6ff:fe9c:3a36 source GigabitEthernet2/0/0 repeat 2 verbose}
890 * Adjacency index: 10, sw_if_index: 1
891 * Adj: ip6-discover-neighbor
892 * Adj Interface: 0
893 * Forced set interface: 1
894 * Adjacency index: 0, sw_if_index: 4294967295
895 * Adj: ip4-miss
896 * Adj Interface: 0
897 * Forced set interface: 1
898 * Source address: 172.16.1.1
899 * 64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=.1899 ms
900 * Adjacency index: 10, sw_if_index: 1
901 * Adj: ip6-discover-neighbor
902 * Adj Interface: 0
903 * Forced set interface: 1
904 * Adjacency index: 0, sw_if_index: 4294967295
905 * Adj: ip4-miss
906 * Adj Interface: 0
907 * Forced set interface: 1
908 * Source address: 172.16.1.1
909 * 64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=.0910 ms
910 *
911 * Statistics: 4 sent, 2 received, 50% packet loss
912 * @cliexend
913 * @endparblock
914?*/
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000915/* *INDENT-OFF* */
916VLIB_CLI_COMMAND (ping_command, static) =
917{
918 .path = "ping",
919 .function = ping_ip_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500920 .short_help = "ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
921 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
922 " [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>]"
923 " [verbose]",
flyingeagle2392a838b2017-05-15 16:57:20 +0800924 .is_mp_safe = 1,
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000925};
926/* *INDENT-ON* */
927
928static clib_error_t *
929ping_cli_init (vlib_main_t * vm)
930{
931 ping_main_t *pm = &ping_main;
932 pm->ip6_main = &ip6_main;
933 pm->ip4_main = &ip4_main;
934 icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
935 ip4_icmp_register_type (vm, ICMP4_echo_reply,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500936 ip4_icmp_echo_reply_node.index);
Andrew Yourtchenko7e682202016-08-04 13:39:35 +0000937 return 0;
938}
939
940VLIB_INIT_FUNCTION (ping_cli_init);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500941
942/*
943 * fd.io coding-style-patch-verification: ON
944 *
945 * Local Variables:
946 * eval: (c-set-style "gnu")
947 * End:
948 */