2 mtr -- a network diagnostic tool
3 Copyright (C) 2016 Matt Kimball
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <netinet/in.h>
26 #include <sys/socket.h>
29 #include "portability/queue.h"
31 #ifdef PLATFORM_CYGWIN
32 #include "probe_cygwin.h"
34 #include "probe_unix.h"
37 #define MAX_PROBES 1024
39 /* Use the "jumbo" frame size as the max packet size */
40 #define PACKET_BUFFER_SIZE 9000
42 /* Parameters for sending a new probe */
43 struct probe_param_t
{
44 /* The version of the Internet Protocol to use. (4 or 6) */
47 /* The command token used to identify a probe when it is completed */
50 /* The IP address to probe */
51 const char *remote_address
;
53 /* The local address from which to send probes */
54 const char *local_address
;
56 /* The local device from which to send probes */
57 const char *local_device
;
59 /* Protocol for the probe, using the IPPROTO_* defines */
62 /* The destination port for non-ICMP probes */
65 /* The local port number to use when sending probes */
68 /* The "type of service" field in the IP header */
71 /* The packet "mark" used for mark-based routing on Linux */
72 uint32_t routing_mark
;
74 /* Time to live for the transmitted probe */
77 /* The packet size (in bytes) including protocol headers */
80 /* The value with which to fill the bytes of the packet. */
83 /* The number of seconds to wait before assuming the probe was lost */
86 /* true is the probe is to test byte order */
87 bool is_probing_byte_order
;
90 /* Tracking information for an outstanding probe */
92 /* Our entry in the probe list */
94 probe_t
) probe_list_entry
;
97 Also the ICMP sequence ID used to identify the probe.
99 Also used as the port number to use when binding stream protocol
100 sockets for this probe. (i.e. TCP or SCTP)
104 /* Command token of the probe request */
107 /* The address being probed */
108 struct sockaddr_storage remote_addr
;
110 /* The local address which was used */
111 struct sockaddr_storage local_addr
;
114 /* Platform specific probe tracking */
115 struct probe_platform_t platform
;
118 /* Global state for interacting with the network */
120 /* The number of entries in the outstanding_probes list */
121 int outstanding_probe_count
;
123 /* Tracking information for in-flight probes */
126 probe_t
) outstanding_probes
;
128 /* Platform specific tracking information */
129 struct net_state_platform_t platform
;
132 /* Multiprotocol Label Switching information */
133 struct mpls_label_t
{
135 uint8_t traffic_class
;
136 uint8_t bottom_of_stack
;
140 void init_net_state_privileged(
141 struct net_state_t
*net_state
);
144 struct net_state_t
*net_state
);
146 bool is_ip_version_supported(
147 struct net_state_t
*net_state
,
150 bool is_protocol_supported(
151 struct net_state_t
*net_state
,
154 bool get_next_probe_timeout(
155 const struct net_state_t
*net_state
,
156 struct timeval
*timeout
);
159 struct net_state_t
*net_state
,
160 const struct probe_param_t
*param
);
162 void receive_replies(
163 struct net_state_t
*net_state
);
165 void check_probe_timeouts(
166 struct net_state_t
*net_state
);
168 void respond_to_probe(
169 struct net_state_t
*net_state
,
170 struct probe_t
*probe
,
172 const struct sockaddr_storage
*remote_addr
,
173 unsigned int round_trip_us
,
175 const struct mpls_label_t
*mpls
);
177 int decode_address_string(
179 const char *address_string
,
180 struct sockaddr_storage
*address
);
182 int resolve_probe_addresses(
183 struct net_state_t
*net_state
,
184 const struct probe_param_t
*param
,
185 struct sockaddr_storage
*dest_sockaddr
,
186 struct sockaddr_storage
*src_sockaddr
);
188 struct probe_t
*alloc_probe(
189 struct net_state_t
*net_state
,
193 struct net_state_t
*net_state
,
194 struct probe_t
*probe
);
196 void platform_alloc_probe(
197 struct net_state_t
*net_state
,
198 struct probe_t
*probe
);
200 void platform_free_probe(
201 struct probe_t
*probe
);
203 struct probe_t
*find_probe(
204 struct net_state_t
*net_state
,
209 int find_source_addr(
210 struct sockaddr_storage
*srcaddr
,
211 const struct sockaddr_storage
*destaddr
);
213 extern char *probe_err
;