X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fping.c;h=2c5c44f5f26ee51195969209d47127b75244ae03;hb=b4d2c967f86b4cc0d8d772abafdb6dbf3f11de04;hp=c847e6969174d12e6f083d962343adcfe8990aca;hpb=9d9265899e89c2c8db5b5b11a09fdf4034a2149c;p=vpp.git diff --git a/src/vnet/ip/ping.c b/src/vnet/ip/ping.c index c847e696917..2c5c44f5f26 100755 --- a/src/vnet/ip/ping.c +++ b/src/vnet/ip/ping.c @@ -20,6 +20,8 @@ #include #include +ping_main_t ping_main; + /** * @file * @brief IPv4 and IPv6 ICMP Ping. @@ -44,6 +46,21 @@ format_icmp_echo_trace (u8 * s, va_list * va) return s; } +static u8 * +format_ip46_ping_result (u8 * s, va_list * args) +{ + send_ip46_ping_result_t res = va_arg (*args, send_ip46_ping_result_t); + + switch (res) + { +#define _(v, n) case SEND_PING_##v: s = format(s, "%s", n); + foreach_ip46_ping_result +#undef _ + } + + return (s); +} + /* * If we can find the ping run by an ICMP ID, then we send the signal * to the CLI process referenced by that ping run, alongside with @@ -97,7 +114,7 @@ signal_ip46_icmp_reply_event (u8 event_type, vlib_buffer_t * b0) clib_memcpy (vnet_buffer (vlib_get_buffer (vm, bi0_copy))->unused, &nowts, sizeof (nowts)); - vlib_process_signal_event (vm, pr->cli_process_id, event_type, bi0_copy); + vlib_process_signal_event_mt (vm, pr->cli_process_id, event_type, bi0_copy); return 1; } @@ -153,8 +170,8 @@ VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) = .format_trace = format_icmp_echo_trace, .n_next_nodes = ICMP6_ECHO_REPLY_N_NEXT, .next_nodes = { - [ICMP6_ECHO_REPLY_NEXT_DROP] = "error-drop", - [ICMP6_ECHO_REPLY_NEXT_PUNT] = "error-punt", + [ICMP6_ECHO_REPLY_NEXT_DROP] = "ip6-drop", + [ICMP6_ECHO_REPLY_NEXT_PUNT] = "ip6-punt", }, }; /* *INDENT-ON* */ @@ -211,15 +228,12 @@ VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node, static) = .format_trace = format_icmp_echo_trace, .n_next_nodes = ICMP4_ECHO_REPLY_N_NEXT, .next_nodes = { - [ICMP4_ECHO_REPLY_NEXT_DROP] = "error-drop", - [ICMP4_ECHO_REPLY_NEXT_PUNT] = "error-punt", + [ICMP4_ECHO_REPLY_NEXT_DROP] = "ip4-drop", + [ICMP4_ECHO_REPLY_NEXT_PUNT] = "ip4-punt", }, }; /* *INDENT-ON* */ -char *ip6_lookup_next_nodes[] = IP6_LOOKUP_NEXT_NODES; -char *ip4_lookup_next_nodes[] = IP4_LOOKUP_NEXT_NODES; - /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */ static u16 init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo, @@ -312,13 +326,14 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im, h0->ip6.src_address = *pa6; /* Fill in the correct source now */ - ip6_address_t *a = ip6_interface_first_address (im, sw_if_index); - if (!a) + if (!ip6_src_address_for_packet (&im->lookup_main, + sw_if_index, + &h0->ip6.dst_address, + &h0->ip6.src_address)) { vlib_buffer_free (vm, &bi0, 1); return SEND_PING_NO_SRC_ADDRESS; } - h0->ip6.src_address = a[0]; /* Fill in icmp fields */ h0->icmp.type = ICMP6_echo_request; @@ -574,30 +589,35 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4, pool_get (pm->ping_runs, pr); ping_run_index = pr - pm->ping_runs; pr->cli_process_id = curr_proc; - pr->cli_thread_index = vlib_get_thread_index (); + pr->cli_thread_index = vm->thread_index; pr->icmp_id = icmp_id; hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index); for (i = 1; i <= ping_repeat; i++) { + send_ip46_ping_result_t res = SEND_PING_OK; f64 sleep_interval; f64 time_ping_sent = vlib_time_now (vm); /* Reset pr: running ping in other process could have changed pm->ping_runs */ pr = vec_elt_at_index (pm->ping_runs, ping_run_index); pr->curr_seq = i; - if (pa6 && - (SEND_PING_OK == - send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index, - i, icmp_id, data_len, ping_burst, verbose))) + if (pa6) { - n_requests += ping_burst; + res = send_ip6_ping (vm, ping_main.ip6_main, table_id, + pa6, sw_if_index, i, icmp_id, + data_len, ping_burst, verbose); } - if (pa4 && - (SEND_PING_OK == - send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index, - i, icmp_id, data_len, ping_burst, verbose))) + if (pa4) + { + res = send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, + sw_if_index, i, icmp_id, data_len, + ping_burst, verbose); + } + if (SEND_PING_OK == res) { n_requests += ping_burst; } + else + vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res); while ((i <= ping_repeat) && ((sleep_interval = @@ -646,7 +666,7 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4, i = 1 + ping_repeat; break; } - vec_free(event_data); + vec_free (event_data); } } vlib_cli_output (vm, "\n");