Changed how conflicitng first/max TTL works.
[mtr.git] / packet / probe.h
blob5a5dc3af0acdeac7e6eaef0f02aa9bda75450711
1 /*
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.
19 #ifndef PROBE_H
20 #define PROBE_H
22 #include "platform.h"
24 #include <netinet/in.h>
25 #include <stdbool.h>
26 #include <sys/socket.h>
27 #include <sys/time.h>
29 #include "portability/queue.h"
31 #ifdef PLATFORM_CYGWIN
32 #include "probe_cygwin.h"
33 #else
34 #include "probe_unix.h"
35 #endif
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) */
45 int ip_version;
47 /* The command token used to identify a probe when it is completed */
48 int command_token;
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 */
60 int protocol;
62 /* The destination port for non-ICMP probes */
63 int dest_port;
65 /* The local port number to use when sending probes */
66 int local_port;
68 /* The "type of service" field in the IP header */
69 int type_of_service;
71 /* The packet "mark" used for mark-based routing on Linux */
72 uint32_t routing_mark;
74 /* Time to live for the transmitted probe */
75 int ttl;
77 /* The packet size (in bytes) including protocol headers */
78 int packet_size;
80 /* The value with which to fill the bytes of the packet. */
81 int bit_pattern;
83 /* The number of seconds to wait before assuming the probe was lost */
84 int timeout;
86 /* true is the probe is to test byte order */
87 bool is_probing_byte_order;
90 /* Tracking information for an outstanding probe */
91 struct probe_t {
92 /* Our entry in the probe list */
93 LIST_ENTRY(
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)
102 int sequence;
104 /* Command token of the probe request */
105 int token;
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 */
119 struct net_state_t {
120 /* The number of entries in the outstanding_probes list */
121 int outstanding_probe_count;
123 /* Tracking information for in-flight probes */
124 LIST_HEAD(
125 probe_list_head_t,
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 {
134 uint32_t label;
135 uint8_t traffic_class;
136 uint8_t bottom_of_stack;
137 uint8_t ttl;
140 void init_net_state_privileged(
141 struct net_state_t *net_state);
143 void init_net_state(
144 struct net_state_t *net_state);
146 bool is_ip_version_supported(
147 struct net_state_t *net_state,
148 int ip_version);
150 bool is_protocol_supported(
151 struct net_state_t *net_state,
152 int protocol);
154 bool get_next_probe_timeout(
155 const struct net_state_t *net_state,
156 struct timeval *timeout);
158 void send_probe(
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,
171 int icmp_type,
172 const struct sockaddr_storage *remote_addr,
173 unsigned int round_trip_us,
174 int mpls_count,
175 const struct mpls_label_t *mpls);
177 int decode_address_string(
178 int ip_version,
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,
190 int token);
192 void free_probe(
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,
205 int protocol,
206 int icmp_id,
207 int icmp_sequence);
209 int find_source_addr(
210 struct sockaddr_storage *srcaddr,
211 const struct sockaddr_storage *destaddr);
213 extern char *probe_err;
215 #endif