]> The Tcpdump Group git mirrors - libpcap/blob - rpcap-protocol.h
CI: Call print_so_deps() on rpcapd in remote enabled build
[libpcap] / rpcap-protocol.h
1 /*
2 * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2008 CACE Technologies, Davis (California)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16 * nor the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
18 * permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef __RPCAP_PROTOCOL_H__
35 #define __RPCAP_PROTOCOL_H__
36
37 #define RPCAP_DEFAULT_NETPORT "2002" /* Default port on which the RPCAP daemon is waiting for connections. */
38 /* Default port on which the client workstation is waiting for connections in case of active mode. */
39 #define RPCAP_DEFAULT_NETPORT_ACTIVE "2003"
40 #define RPCAP_DEFAULT_NETADDR "" /* Default network address on which the RPCAP daemon binds to. */
41
42 /*
43 * Minimum and maximum supported versions of the protocol.
44 *
45 * If new message types are added, the protocol version MUST be changed,
46 * so that a client knows, from the negotiated protocol version, what
47 * messages can be sent to the server.
48 *
49 * If the format of an existing message type is changed, the protocol
50 * version MUST be changed, so that each side knows, from the negotiated
51 * protocol version, what format should be used.
52 *
53 * The RPCAP_MSG_ERROR format MUST not change, as it's used to, among
54 * other things, report "incorrect version number" errors, where, if
55 * the format changed, the sender of the message might not know what
56 * versions the recipient would understand, or might know a version
57 * they support (the version number they sent) but might not know
58 * the format of the message in that version.
59 *
60 * Other message versions SHOULD not change, as that would complicate
61 * the process of interpreting the message, making it version-dependent.
62 * Introducing a new message with a new format is preferable.
63 *
64 * Version negotiation is done as part of the authentication process:
65 *
66 * The client sends an authentication request, with a version number
67 * of 0. All servers must accept authentication requests with a version
68 * number of 0, even if they don't support version 0 for any other
69 * requests.
70 *
71 * The server attempts to authenticate the client. If that succeeds,
72 * older servers - which only support version 0 - will send an
73 * authentication reply with no payload. Newer servers - which might
74 * support other versions - will send an authentication reply with
75 * a payload giving the minimum and maximum versions it supports.
76 *
77 * The client attempts to find the largest version number that is
78 * in both its range of supported versions and the server's supported
79 * versions. If it fails, it gives up; otherwise, it uses that version.
80 */
81 #define RPCAP_MIN_VERSION 0
82 #define RPCAP_MAX_VERSION 0
83
84 /*
85 * Version numbers are unsigned, so if RPCAP_MIN_VERSION is 0, they
86 * are >= the minimum version, by definition; don't check against
87 * RPCAP_MIN_VERSION, as you may get compiler warnings that the
88 * comparison will always succeed.
89 */
90 #if RPCAP_MIN_VERSION == 0
91 #define RPCAP_VERSION_IS_SUPPORTED(v) \
92 ((v) <= RPCAP_MAX_VERSION)
93 #else
94 #define RPCAP_VERSION_IS_SUPPORTED(v) \
95 ((v) >= RPCAP_MIN_VERSION && (v) <= RPCAP_MAX_VERSION)
96 #endif
97
98 /*
99 * Separators used for the host list.
100 *
101 * It is used:
102 * - by the rpcapd daemon, when you types a list of allowed connecting hosts
103 * - by the rpcap client in active mode, when the client waits for incoming
104 * connections from other hosts
105 */
106 #define RPCAP_HOSTLIST_SEP " ,;\n\r"
107
108 /*********************************************************
109 * *
110 * Protocol messages formats *
111 * *
112 *********************************************************/
113 /*
114 * WARNING: This file defines some structures that are used to transfer
115 * data on the network.
116 * Note that your compiler MUST not insert padding into these structures
117 * for better alignment.
118 * These structures have been created in order to be correctly aligned to
119 * a 32-bit boundary, but be careful in any case.
120 *
121 * The layout of these structures MUST not be changed. If a packet
122 * format is different in different versions of the protocol, versions
123 * of the structure should be provided for all the different versions or
124 * version ranges (if more than one version of the protocol has the same
125 * layout) that we support.
126 *
127 * We use the C99 intN_t and uintN_t types to indicate fields that are
128 * exactly N bits long on the network. Do not use types that might
129 * differ in their lengths.
130 *
131 * XXX - both libpcap and programs that use it will require significant
132 * work if you have machines where integral data types are not multiples
133 * of 8-bit bytes. If, for example, you're trying to get this to work
134 * on a PDP-10x, good luck.
135 */
136
137 /* Common header for all the RPCAP messages */
138 struct rpcap_header
139 {
140 uint8_t ver; /* RPCAP version number */
141 uint8_t type; /* RPCAP message type (error, findalldevs, ...) */
142 uint16_t value; /* Message-dependent value (not always used) */
143 uint32_t plen; /* Length of the payload of this RPCAP message */
144 };
145
146 /*
147 * Format of data that may appear at the end of an authentication reply,
148 * giving the minimum and maximum versions of the protocol that the
149 * server supports.
150 *
151 * Older servers don't provide this; they support only version 0.
152 */
153 struct rpcap_authreply
154 {
155 uint8_t minvers; /* Minimum version supported */
156 uint8_t maxvers; /* Maximum version supported */
157 uint8_t pad[2]; /* Pad to 4-byte boundary **/
158 uint32_t byte_order_magic; /* RPCAP_BYTE_ORDER_MAGIC, in server byte order */
159 };
160
161 /*
162 * Any resemblance between this and the pcap file magic number
163 * is purely coincidental, trust me.
164 */
165 #define RPCAP_BYTE_ORDER_MAGIC 0xa1b2c3d4U
166 #define RPCAP_BYTE_ORDER_MAGIC_SWAPPED 0xd4c3b2a1U
167
168 /*
169 * Older version of authentication reply, without byte order indication
170 * and padding.
171 */
172 struct rpcap_authreply_old
173 {
174 uint8_t minvers; /* Minimum version supported */
175 uint8_t maxvers; /* Maximum version supported */
176 };
177
178 /* Format of the message for the interface description (findalldevs command) */
179 struct rpcap_findalldevs_if
180 {
181 uint16_t namelen; /* Length of the interface name */
182 uint16_t desclen; /* Length of the interface description */
183 uint32_t flags; /* Interface flags */
184 uint16_t naddr; /* Number of addresses */
185 uint16_t dummy; /* Must be zero */
186 };
187
188 /*
189 * Format of an address as sent over the wire.
190 *
191 * Do *NOT* use struct sockaddr_storage, as the layout for that is
192 * machine-dependent.
193 *
194 * RFC 2553 gives two sample layouts, both of which are 128 bytes long,
195 * both of which are aligned on an 8-byte boundary, and both of which
196 * have 2 bytes before the address data.
197 *
198 * However, one has a 2-byte address family value at the beginning
199 * and the other has a 1-byte address length value and a 1-byte
200 * address family value; this reflects the fact that the original
201 * BSD sockaddr structure had a 2-byte address family value, which
202 * was later changed to a 1-byte address length value and a 1-byte
203 * address family value, when support for variable-length OSI
204 * network-layer addresses was added.
205 *
206 * Furthermore, Solaris's struct sockaddr_storage is 256 bytes
207 * long.
208 *
209 * This structure is supposed to be aligned on an 8-byte boundary;
210 * the message header is 8 bytes long, so we don't have to do
211 * anything to ensure it's aligned on that boundary within a packet,
212 * so we just define it as 128 bytes long, with a 2-byte address
213 * family. (We only support IPv4 and IPv6 addresses, which are fixed-
214 * length.) That way, it's the same size as sockaddr_storage on
215 * Windows, and it'll look like what an older Windows client will
216 * expect.
217 *
218 * In addition, do *NOT* use the host's AF_ value for an address,
219 * as the value for AF_INET6 is machine-dependent. We use the
220 * Windows value, so it'll look like what an older Windows client
221 * will expect.
222 *
223 * (The Windows client is the only one that has been distributed
224 * as a standard part of *pcap; UN*X clients are probably built
225 * from source by the user or administrator, so they're in a
226 * better position to upgrade an old client. Therefore, we
227 * try to make what goes over the wire look like what comes
228 * from a Windows server.)
229 */
230 struct rpcap_sockaddr
231 {
232 uint16_t family; /* Address family */
233 char data[128-2]; /* Data */
234 };
235
236 /*
237 * Format of an IPv4 address as sent over the wire.
238 */
239 #define RPCAP_AF_INET 2 /* Value on all OSes except for Haiku */
240 struct rpcap_sockaddr_in
241 {
242 uint16_t family; /* Address family */
243 uint16_t port; /* Port number */
244 uint32_t addr; /* IPv4 address */
245 uint8_t zero[8]; /* Padding */
246 };
247
248 /*
249 * Format of an IPv6 address as sent over the wire.
250 */
251 #define RPCAP_AF_INET6 23 /* Value on Windows */
252 struct rpcap_sockaddr_in6
253 {
254 uint16_t family; /* Address family */
255 uint16_t port; /* Port number */
256 uint32_t flowinfo; /* IPv6 flow information */
257 uint8_t addr[16]; /* IPv6 address */
258 uint32_t scope_id; /* Scope zone index */
259 };
260
261 /* Format of the message for the address listing (findalldevs command) */
262 struct rpcap_findalldevs_ifaddr
263 {
264 struct rpcap_sockaddr addr; /* Network address */
265 struct rpcap_sockaddr netmask; /* Netmask for that address */
266 struct rpcap_sockaddr broadaddr; /* Broadcast address for that address */
267 struct rpcap_sockaddr dstaddr; /* P2P destination address for that address */
268 };
269
270 /*
271 * \brief Format of the message of the connection opening reply (open command).
272 *
273 * This structure transfers over the network some of the values useful on the client side.
274 */
275 struct rpcap_openreply
276 {
277 int32_t linktype; /* Link type */
278 int32_t tzoff; /* Timezone offset - not used by newer clients */
279 };
280
281 /* Format of the message that starts a remote capture (startcap command) */
282 struct rpcap_startcapreq
283 {
284 uint32_t snaplen; /* Length of the snapshot (number of bytes to capture for each packet) */
285 uint32_t read_timeout; /* Read timeout in milliseconds */
286 uint16_t flags; /* Flags (see RPCAP_STARTCAPREQ_FLAG_xxx) */
287 uint16_t portdata; /* Network port on which the client is waiting at (if 'serveropen') */
288 };
289
290 /* Format of the reply message that devoted to start a remote capture (startcap reply command) */
291 struct rpcap_startcapreply
292 {
293 int32_t bufsize; /* Size of the user buffer allocated by WinPcap; it can be different from the one we chose */
294 uint16_t portdata; /* Network port on which the server is waiting at (passive mode only) */
295 uint16_t dummy; /* Must be zero */
296 };
297
298 /*
299 * \brief Format of the header which encapsulates captured packets when transmitted on the network.
300 *
301 * This message requires the general header as well, since we want to be able to exchange
302 * more information across the network in the future (for example statistics, and kind like that).
303 */
304 struct rpcap_pkthdr
305 {
306 /*
307 * This protocol needs to be updated with a new version before
308 * 2038-01-19 03:14:07 UTC.
309 */
310 uint32_t timestamp_sec; /* 'struct timeval' compatible, it represents the 'tv_sec' field */
311 uint32_t timestamp_usec; /* 'struct timeval' compatible, it represents the 'tv_usec' field */
312 uint32_t caplen; /* Length of portion present in the capture */
313 uint32_t len; /* Real length of this packet (off wire) */
314 uint32_t npkt; /* Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc) */
315 };
316
317 /* General header used for the pcap_setfilter() command; keeps just the number of BPF instructions */
318 struct rpcap_filter
319 {
320 uint16_t filtertype; /* type of the filter transferred (BPF instructions, ...) */
321 uint16_t dummy; /* Must be zero */
322 uint32_t nitems; /* Number of items contained into the filter (e.g. BPF instructions for BPF filters) */
323 };
324
325 /* Structure that keeps a single BPF instruction; it is repeated 'ninsn' times according to the 'rpcap_filterbpf' header */
326 struct rpcap_filterbpf_insn
327 {
328 uint16_t code; /* opcode of the instruction */
329 uint8_t jt; /* relative offset to jump to in case of 'true' */
330 uint8_t jf; /* relative offset to jump to in case of 'false' */
331 int32_t k; /* instruction-dependent value */
332 };
333
334 /* Structure that keeps the data required for the authentication on the remote host */
335 struct rpcap_auth
336 {
337 uint16_t type; /* Authentication type */
338 uint16_t dummy; /* Must be zero */
339 uint16_t slen1; /* Length of the first authentication item (e.g. username) */
340 uint16_t slen2; /* Length of the second authentication item (e.g. password) */
341 };
342
343 /* Structure that keeps the statistics about the number of packets captured, dropped, etc. */
344 struct rpcap_stats
345 {
346 uint32_t ifrecv; /* Packets received by the kernel filter (i.e. pcap_stats.ps_recv) */
347 uint32_t ifdrop; /* Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop) */
348 uint32_t krnldrop; /* Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop) */
349 uint32_t svrcapt; /* Packets captured by the RPCAP daemon and sent on the network */
350 };
351
352 /* Structure that is needed to set sampling parameters */
353 struct rpcap_sampling
354 {
355 uint8_t method; /* Sampling method */
356 uint8_t dummy1; /* Must be zero */
357 uint16_t dummy2; /* Must be zero */
358 uint32_t value; /* Parameter related to the sampling method */
359 };
360
361 /*
362 * Messages field coding.
363 *
364 * These values are used in messages sent over the network, and MUST
365 * not be changed.
366 */
367 #define RPCAP_MSG_IS_REPLY 0x080 /* Flag indicating a reply */
368
369 #define RPCAP_MSG_ERROR 0x01 /* Message that keeps an error notification */
370 #define RPCAP_MSG_FINDALLIF_REQ 0x02 /* Request to list all the remote interfaces */
371 #define RPCAP_MSG_OPEN_REQ 0x03 /* Request to open a remote device */
372 #define RPCAP_MSG_STARTCAP_REQ 0x04 /* Request to start a capture on a remote device */
373 #define RPCAP_MSG_UPDATEFILTER_REQ 0x05 /* Send a compiled filter into the remote device */
374 #define RPCAP_MSG_CLOSE 0x06 /* Close the connection with the remote peer */
375 #define RPCAP_MSG_PACKET 0x07 /* This is a 'data' message, which carries a network packet */
376 #define RPCAP_MSG_AUTH_REQ 0x08 /* Message that keeps the authentication parameters */
377 #define RPCAP_MSG_STATS_REQ 0x09 /* It requires to have network statistics */
378 #define RPCAP_MSG_ENDCAP_REQ 0x0A /* Stops the current capture, keeping the device open */
379 #define RPCAP_MSG_SETSAMPLING_REQ 0x0B /* Set sampling parameters */
380
381 #define RPCAP_MSG_FINDALLIF_REPLY (RPCAP_MSG_FINDALLIF_REQ | RPCAP_MSG_IS_REPLY) /* Keeps the list of all the remote interfaces */
382 #define RPCAP_MSG_OPEN_REPLY (RPCAP_MSG_OPEN_REQ | RPCAP_MSG_IS_REPLY) /* The remote device has been opened correctly */
383 #define RPCAP_MSG_STARTCAP_REPLY (RPCAP_MSG_STARTCAP_REQ | RPCAP_MSG_IS_REPLY) /* The capture is starting correctly */
384 #define RPCAP_MSG_UPDATEFILTER_REPLY (RPCAP_MSG_UPDATEFILTER_REQ | RPCAP_MSG_IS_REPLY) /* The filter has been applied correctly on the remote device */
385 #define RPCAP_MSG_AUTH_REPLY (RPCAP_MSG_AUTH_REQ | RPCAP_MSG_IS_REPLY) /* Sends a message that says 'ok, authorization successful' */
386 #define RPCAP_MSG_STATS_REPLY (RPCAP_MSG_STATS_REQ | RPCAP_MSG_IS_REPLY) /* Message that keeps the network statistics */
387 #define RPCAP_MSG_ENDCAP_REPLY (RPCAP_MSG_ENDCAP_REQ | RPCAP_MSG_IS_REPLY) /* Confirms that the capture stopped successfully */
388 #define RPCAP_MSG_SETSAMPLING_REPLY (RPCAP_MSG_SETSAMPLING_REQ | RPCAP_MSG_IS_REPLY) /* Confirms that the capture stopped successfully */
389
390 #define RPCAP_STARTCAPREQ_FLAG_PROMISC 0x00000001 /* Enables promiscuous mode (default: disabled) */
391 #define RPCAP_STARTCAPREQ_FLAG_DGRAM 0x00000002 /* Use a datagram (i.e. UDP) connection for the data stream (default: use TCP)*/
392 #define RPCAP_STARTCAPREQ_FLAG_SERVEROPEN 0x00000004 /* The server has to open the data connection toward the client */
393 #define RPCAP_STARTCAPREQ_FLAG_INBOUND 0x00000008 /* Capture only inbound packets (take care: the flag has no effect with promiscuous enabled) */
394 #define RPCAP_STARTCAPREQ_FLAG_OUTBOUND 0x00000010 /* Capture only outbound packets (take care: the flag has no effect with promiscuous enabled) */
395
396 #define RPCAP_UPDATEFILTER_BPF 1 /* This code tells us that the filter is encoded with the BPF/NPF syntax */
397
398 /*
399 * Network error codes.
400 *
401 * These values are used in messages sent over the network, and MUST
402 * not be changed.
403 */
404 #define PCAP_ERR_NETW 1 /* Network error */
405 #define PCAP_ERR_INITTIMEOUT 2 /* The RPCAP initial timeout has expired */
406 #define PCAP_ERR_AUTH 3 /* Generic authentication error */
407 #define PCAP_ERR_FINDALLIF 4 /* Generic findalldevs error */
408 #define PCAP_ERR_NOREMOTEIF 5 /* The findalldevs was ok, but the remote end had no interfaces to list */
409 #define PCAP_ERR_OPEN 6 /* Generic pcap_open error */
410 #define PCAP_ERR_UPDATEFILTER 7 /* Generic updatefilter error */
411 #define PCAP_ERR_GETSTATS 8 /* Generic pcap_stats error */
412 #define PCAP_ERR_READEX 9 /* Generic pcap_next_ex error */
413 #define PCAP_ERR_HOSTNOAUTH 10 /* The host is not authorized to connect to this server */
414 #define PCAP_ERR_REMOTEACCEPT 11 /* Generic pcap_remoteaccept error */
415 #define PCAP_ERR_STARTCAPTURE 12 /* Generic pcap_startcapture error */
416 #define PCAP_ERR_ENDCAPTURE 13 /* Generic pcap_endcapture error */
417 #define PCAP_ERR_RUNTIMETIMEOUT 14 /* The RPCAP run-time timeout has expired */
418 #define PCAP_ERR_SETSAMPLING 15 /* Error during the settings of sampling parameters */
419 #define PCAP_ERR_WRONGMSG 16 /* The other end endpoint sent a message which has not been recognized */
420 #define PCAP_ERR_WRONGVER 17 /* The other end endpoint has a version number that is not compatible with our */
421 #define PCAP_ERR_AUTH_FAILED 18 /* The user couldn't be authenticated */
422 #define PCAP_ERR_TLS_REQUIRED 19 /* The server requires TLS to connect */
423 #define PCAP_ERR_AUTH_TYPE_NOTSUP 20 /* The authentication type isn't supported */
424
425 /*
426 * \brief Buffer used by socket functions to send-receive packets.
427 * In case you plan to have messages larger than this value, you have to increase it.
428 */
429 #define RPCAP_NETBUF_SIZE 64000
430
431 /*********************************************************
432 * *
433 * Routines used by the rpcap client and rpcap daemon *
434 * *
435 *********************************************************/
436
437 #include "sockutils.h"
438 #include "sslutils.h"
439
440 extern void rpcap_createhdr(struct rpcap_header *header, uint8_t ver, uint8_t type, uint16_t value, uint32_t length);
441 extern const char *rpcap_msg_type_string(uint8_t type);
442 extern int rpcap_senderror(PCAP_SOCKET sock, SSL *ssl, uint8_t ver, uint16_t errcode, const char *error, char *errbuf);
443
444 #endif