Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | #ifndef included_vnet_ping_h |
| 16 | #define included_vnet_ping_h |
| 17 | |
| 18 | |
| 19 | #include <vnet/ip/ip.h> |
| 20 | |
| 21 | #include <vnet/ip/lookup.h> |
| 22 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 23 | typedef enum |
| 24 | { |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 25 | PING_RESPONSE_IP6 = 42, |
| 26 | PING_RESPONSE_IP4, |
| 27 | } ping_response_type_t; |
| 28 | |
Neale Ranns | e9239c9 | 2018-10-15 05:47:58 -0700 | [diff] [blame] | 29 | #define foreach_ip46_ping_result \ |
| 30 | _ (OK, "OK") \ |
| 31 | _ (ALLOC_FAIL, "packet allocation failed") \ |
| 32 | _ (NO_INTERFACE, "no egress interface") \ |
| 33 | _ (NO_TABLE, "no IPv6 Table for lookup") \ |
| 34 | _ (NO_SRC_ADDRESS, "no source address for egress interface") \ |
| 35 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 36 | typedef enum |
| 37 | { |
Neale Ranns | e9239c9 | 2018-10-15 05:47:58 -0700 | [diff] [blame] | 38 | #define _(v, s) SEND_PING_##v, |
| 39 | foreach_ip46_ping_result |
| 40 | #undef _ |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 41 | } send_ip46_ping_result_t; |
| 42 | |
| 43 | /* |
| 44 | * Currently running ping command. |
| 45 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 46 | typedef struct ping_run_t |
| 47 | { |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 48 | u16 icmp_id; |
| 49 | u16 curr_seq; |
| 50 | uword cli_process_id; |
Mohammed Hawari | 03a6213 | 2017-07-18 09:25:01 +0200 | [diff] [blame] | 51 | uword cli_thread_index; |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 52 | } ping_run_t; |
| 53 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 54 | typedef struct ping_main_t |
| 55 | { |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 56 | ip6_main_t *ip6_main; |
| 57 | ip4_main_t *ip4_main; |
| 58 | ping_run_t *ping_runs; |
| 59 | /* hash table to find back the CLI process for a reply */ |
| 60 | // uword *cli_proc_by_icmp_id; |
| 61 | ping_run_t *ping_run_by_icmp_id; |
| 62 | } ping_main_t; |
| 63 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 64 | extern ping_main_t ping_main; |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 65 | |
| 66 | #define PING_DEFAULT_DATA_LEN 60 |
| 67 | #define PING_DEFAULT_INTERVAL 1.0 |
| 68 | |
Andrew Yourtchenko | 61459c9 | 2017-01-28 15:31:19 +0000 | [diff] [blame] | 69 | #define PING_MAXIMUM_DATA_SIZE (VLIB_BUFFER_DATA_SIZE - sizeof(ip6_header_t) - sizeof(icmp46_header_t) - offsetof(icmp46_echo_request_t, data)) |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 70 | |
Andrew Yourtchenko | 61459c9 | 2017-01-28 15:31:19 +0000 | [diff] [blame] | 71 | /* *INDENT-OFF* */ |
| 72 | |
| 73 | typedef CLIB_PACKED (struct { |
| 74 | u16 id; |
| 75 | u16 seq; |
| 76 | f64 time_sent; |
| 77 | u8 data[0]; |
| 78 | }) icmp46_echo_request_t; |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 79 | |
| 80 | |
Andrew Yourtchenko | 61459c9 | 2017-01-28 15:31:19 +0000 | [diff] [blame] | 81 | typedef CLIB_PACKED (struct { |
| 82 | ip6_header_t ip6; |
| 83 | icmp46_header_t icmp; |
| 84 | icmp46_echo_request_t icmp_echo; |
| 85 | }) icmp6_echo_request_header_t; |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 86 | |
Andrew Yourtchenko | 61459c9 | 2017-01-28 15:31:19 +0000 | [diff] [blame] | 87 | typedef CLIB_PACKED (struct { |
| 88 | ip4_header_t ip4; |
| 89 | icmp46_header_t icmp; |
| 90 | icmp46_echo_request_t icmp_echo; |
| 91 | }) icmp4_echo_request_header_t; |
| 92 | |
| 93 | /* *INDENT-ON* */ |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 94 | |
| 95 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 96 | typedef struct |
| 97 | { |
Alexander Popovsky | c90dfdc | 2016-12-04 02:39:38 -0800 | [diff] [blame] | 98 | u16 id; |
| 99 | u16 seq; |
| 100 | u8 bound; |
| 101 | } icmp_echo_trace_t; |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | |
| 105 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 106 | typedef enum |
| 107 | { |
Alexander Popovsky | c90dfdc | 2016-12-04 02:39:38 -0800 | [diff] [blame] | 108 | ICMP6_ECHO_REPLY_NEXT_DROP, |
| 109 | ICMP6_ECHO_REPLY_NEXT_PUNT, |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 110 | ICMP6_ECHO_REPLY_N_NEXT, |
| 111 | } icmp6_echo_reply_next_t; |
| 112 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 113 | typedef enum |
| 114 | { |
Alexander Popovsky | c90dfdc | 2016-12-04 02:39:38 -0800 | [diff] [blame] | 115 | ICMP4_ECHO_REPLY_NEXT_DROP, |
| 116 | ICMP4_ECHO_REPLY_NEXT_PUNT, |
Andrew Yourtchenko | 7e68220 | 2016-08-04 13:39:35 +0000 | [diff] [blame] | 117 | ICMP4_ECHO_REPLY_N_NEXT, |
| 118 | } icmp4_echo_reply_next_t; |
| 119 | |
| 120 | #endif /* included_vnet_ping_h */ |