Annotation of embedaddon/mtr/packet/probe.h, revision 1.1.1.1
1.1 misho 1: /*
2: mtr -- a network diagnostic tool
3: Copyright (C) 2016 Matt Kimball
4:
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.
8:
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.
13:
14: You should have received a copy of the GNU General Public License
15: along with this program; if not, write to the Free Software
16: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17: */
18:
19: #ifndef PROBE_H
20: #define PROBE_H
21:
22: #include "platform.h"
23:
24: #include <netinet/in.h>
25: #include <stdbool.h>
26: #include <sys/socket.h>
27: #include <sys/time.h>
28:
29: #include "portability/queue.h"
30:
31: #ifdef PLATFORM_CYGWIN
32: #include "probe_cygwin.h"
33: #else
34: #include "probe_unix.h"
35: #endif
36:
37: #define MAX_PROBES 1024
38:
39: /* Use the "jumbo" frame size as the max packet size */
40: #define PACKET_BUFFER_SIZE 9000
41:
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;
46:
47: /* The command token used to identify a probe when it is completed */
48: int command_token;
49:
50: /* The IP address to probe */
51: const char *remote_address;
52:
53: /* The local address from which to send probes */
54: const char *local_address;
55:
56: /* Protocol for the probe, using the IPPROTO_* defines */
57: int protocol;
58:
59: /* The destination port for non-ICMP probes */
60: int dest_port;
61:
62: /* The local port number to use when sending probes */
63: int local_port;
64:
65: /* The "type of service" field in the IP header */
66: int type_of_service;
67:
68: /* The packet "mark" used for mark-based routing on Linux */
69: int routing_mark;
70:
71: /* Time to live for the transmited probe */
72: int ttl;
73:
74: /* The packet size (in bytes) including protocol headers */
75: int packet_size;
76:
77: /* The value with which to fill the bytes of the packet. */
78: int bit_pattern;
79:
80: /* The number of seconds to wait before assuming the probe was lost */
81: int timeout;
82: };
83:
84: /* Tracking information for an outstanding probe */
85: struct probe_t {
86: /* Our entry in the probe list */
87: LIST_ENTRY(
88: probe_t) probe_list_entry;
89:
90: /*
91: Also the ICMP sequence ID used to identify the probe.
92:
93: Also used as the port number to use when binding stream protocol
94: sockets for this probe. (i.e. TCP or SCTP)
95: */
96: int sequence;
97:
98: /* Command token of the probe request */
99: int token;
100:
101: /* The address being probed */
102: struct sockaddr_storage remote_addr;
103:
104: /* Platform specific probe tracking */
105: struct probe_platform_t platform;
106: };
107:
108: /* Global state for interacting with the network */
109: struct net_state_t {
110: /* The number of entries in the outstanding_probes list */
111: int outstanding_probe_count;
112:
113: /* Tracking information for in-flight probes */
114: LIST_HEAD(
115: probe_list_head_t,
116: probe_t) outstanding_probes;
117:
118: /* Platform specific tracking information */
119: struct net_state_platform_t platform;
120: };
121:
122: /* Multiprotocol Label Switching information */
123: struct mpls_label_t {
124: uint32_t label;
125: uint8_t experimental_use;
126: uint8_t bottom_of_stack;
127: uint8_t ttl;
128: };
129:
130: void init_net_state_privileged(
131: struct net_state_t *net_state);
132:
133: void init_net_state(
134: struct net_state_t *net_state);
135:
136: bool is_ip_version_supported(
137: struct net_state_t *net_state,
138: int ip_version);
139:
140: bool is_protocol_supported(
141: struct net_state_t *net_state,
142: int protocol);
143:
144: bool get_next_probe_timeout(
145: const struct net_state_t *net_state,
146: struct timeval *timeout);
147:
148: void send_probe(
149: struct net_state_t *net_state,
150: const struct probe_param_t *param);
151:
152: void receive_replies(
153: struct net_state_t *net_state);
154:
155: void check_probe_timeouts(
156: struct net_state_t *net_state);
157:
158: void respond_to_probe(
159: struct net_state_t *net_state,
160: struct probe_t *probe,
161: int icmp_type,
162: const struct sockaddr_storage *remote_addr,
163: unsigned int round_trip_us,
164: int mpls_count,
165: const struct mpls_label_t *mpls);
166:
167: int decode_address_string(
168: int ip_version,
169: const char *address_string,
170: struct sockaddr_storage *address);
171:
172: int resolve_probe_addresses(
173: const struct probe_param_t *param,
174: struct sockaddr_storage *dest_sockaddr,
175: struct sockaddr_storage *src_sockaddr);
176:
177: struct probe_t *alloc_probe(
178: struct net_state_t *net_state,
179: int token);
180:
181: void free_probe(
182: struct net_state_t *net_state,
183: struct probe_t *probe);
184:
185: void platform_alloc_probe(
186: struct net_state_t *net_state,
187: struct probe_t *probe);
188:
189: void platform_free_probe(
190: struct probe_t *probe);
191:
192: struct probe_t *find_probe(
193: struct net_state_t *net_state,
194: int protocol,
195: int icmp_id,
196: int icmp_sequence);
197:
198: int find_source_addr(
199: struct sockaddr_storage *srcaddr,
200: const struct sockaddr_storage *destaddr);
201:
202: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>