Annotation of embedaddon/mtr/packet/probe.h, revision 1.1.1.2
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:
1.1.1.2 ! misho 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.
1.1 misho 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:
1.1.1.2 ! misho 71: /* Time to live for the transmitted probe */
1.1 misho 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;
1.1.1.2 ! misho 82:
! 83: /* true is the probe is to test byte order */
! 84: bool is_probing_byte_order;
1.1 misho 85: };
86:
87: /* Tracking information for an outstanding probe */
88: struct probe_t {
89: /* Our entry in the probe list */
90: LIST_ENTRY(
91: probe_t) probe_list_entry;
92:
93: /*
94: Also the ICMP sequence ID used to identify the probe.
95:
96: Also used as the port number to use when binding stream protocol
97: sockets for this probe. (i.e. TCP or SCTP)
98: */
99: int sequence;
100:
101: /* Command token of the probe request */
102: int token;
103:
104: /* The address being probed */
105: struct sockaddr_storage remote_addr;
106:
1.1.1.2 ! misho 107: /* The local address which was used */
! 108: struct sockaddr_storage local_addr;
! 109:
! 110:
1.1 misho 111: /* Platform specific probe tracking */
112: struct probe_platform_t platform;
113: };
114:
115: /* Global state for interacting with the network */
116: struct net_state_t {
117: /* The number of entries in the outstanding_probes list */
118: int outstanding_probe_count;
119:
120: /* Tracking information for in-flight probes */
121: LIST_HEAD(
122: probe_list_head_t,
123: probe_t) outstanding_probes;
124:
125: /* Platform specific tracking information */
126: struct net_state_platform_t platform;
127: };
128:
129: /* Multiprotocol Label Switching information */
130: struct mpls_label_t {
131: uint32_t label;
1.1.1.2 ! misho 132: uint8_t traffic_class;
1.1 misho 133: uint8_t bottom_of_stack;
134: uint8_t ttl;
135: };
136:
137: void init_net_state_privileged(
138: struct net_state_t *net_state);
139:
140: void init_net_state(
141: struct net_state_t *net_state);
142:
143: bool is_ip_version_supported(
144: struct net_state_t *net_state,
145: int ip_version);
146:
147: bool is_protocol_supported(
148: struct net_state_t *net_state,
149: int protocol);
150:
151: bool get_next_probe_timeout(
152: const struct net_state_t *net_state,
153: struct timeval *timeout);
154:
155: void send_probe(
156: struct net_state_t *net_state,
157: const struct probe_param_t *param);
158:
159: void receive_replies(
160: struct net_state_t *net_state);
161:
162: void check_probe_timeouts(
163: struct net_state_t *net_state);
164:
165: void respond_to_probe(
166: struct net_state_t *net_state,
167: struct probe_t *probe,
168: int icmp_type,
169: const struct sockaddr_storage *remote_addr,
170: unsigned int round_trip_us,
171: int mpls_count,
172: const struct mpls_label_t *mpls);
173:
174: int decode_address_string(
175: int ip_version,
176: const char *address_string,
177: struct sockaddr_storage *address);
178:
179: int resolve_probe_addresses(
1.1.1.2 ! misho 180: struct net_state_t *net_state,
1.1 misho 181: const struct probe_param_t *param,
182: struct sockaddr_storage *dest_sockaddr,
183: struct sockaddr_storage *src_sockaddr);
184:
185: struct probe_t *alloc_probe(
186: struct net_state_t *net_state,
187: int token);
188:
189: void free_probe(
190: struct net_state_t *net_state,
191: struct probe_t *probe);
192:
193: void platform_alloc_probe(
194: struct net_state_t *net_state,
195: struct probe_t *probe);
196:
197: void platform_free_probe(
198: struct probe_t *probe);
199:
200: struct probe_t *find_probe(
201: struct net_state_t *net_state,
202: int protocol,
203: int icmp_id,
204: int icmp_sequence);
205:
206: int find_source_addr(
207: struct sockaddr_storage *srcaddr,
208: const struct sockaddr_storage *destaddr);
209:
1.1.1.2 ! misho 210: extern char *probe_err;
! 211:
1.1 misho 212: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>