]> The Tcpdump Group git mirrors - tcpdump/blob - dccp.h
From Ian McDonald and Arnaldo Carvalho de Melo: DCCP support.
[tcpdump] / dccp.h
1 #ifndef __DCCP_HDR__
2 #define __DCCP_HDR__
3 /*
4 * Copyright (C) Arnaldo Carvalho de Melo 2004
5 * Copyright (C) Ian McDonald 2005 <iam4@cs.waikato.ac.nz>
6 * Copyright (C) Yoshifumi Nishida 2005
7 *
8 * This software may be distributed either under the terms of the
9 * BSD-style license that accompanies tcpdump or the GNU GPL version 2
10 */
11
12 /**
13 * struct dccp_hdr - generic part of DCCP packet header
14 *
15 * @dccph_sport - Relevant port on the endpoint that sent this packet
16 * @dccph_dport - Relevant port on the other endpoint
17 * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
18 * @dccph_ccval - Used by the HC-Sender CCID
19 * @dccph_cscov - Parts of the packet that are covered by the Checksum field
20 * @dccph_checksum - Internet checksum, depends on dccph_cscov
21 * @dccph_x - 0 = 24 bit sequence number, 1 = 48
22 * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
23 * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
24 */
25 struct dccp_hdr {
26 u_int16_t dccph_sport,
27 dccph_dport;
28 u_int8_t dccph_doff;
29 u_int8_t dccph_ccval_cscov;
30 u_int16_t dccph_checksum;
31 union {
32 u_int8_t dccph_xtr;
33 u_int32_t dccph_seq;
34 } dccph_xtrs;
35 };
36
37 #define DCCPH_CCVAL(dh) (((dh)->dccph_ccval_cscov) & 0x0F)
38 #define DCCPH_CSCOV(dh) (((dh)->dccph_ccval_cscov >> 4) & 0x0F)
39
40 #define DCCPH_X(dh) ((dh)->dccph_xtrs.dccph_xtr & 1)
41 #define DCCPH_TYPE(dh) (((dh)->dccph_xtrs.dccph_xtr >> 1) & 0xF)
42 #define DCCPH_SEQ(dh) (((dh)->dccph_xtrs.dccph_seq) >> 8)
43
44 /**
45 * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
46 *
47 * @dccph_seq_low - low 24 bits of a 48 bit seq packet
48 */
49 struct dccp_hdr_ext {
50 u_int32_t dccph_seq_low;
51 };
52
53 /**
54 * struct dccp_hdr_request - Conection initiation request header
55 *
56 * @dccph_req_service - Service to which the client app wants to connect
57 */
58 struct dccp_hdr_request {
59 u_int32_t dccph_req_service;
60 };
61
62 /**
63 * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
64 *
65 * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
66 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
67 */
68 struct dccp_hdr_ack_bits {
69 u_int32_t dccph_ra;
70 u_int32_t dccph_ack_nr_low;
71 };
72
73 #define DCCPH_ACK(dh_ack) ((dh_ack)->dccph_ra >> 8)
74
75 /**
76 * struct dccp_hdr_response - Conection initiation response header
77 *
78 * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
79 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
80 * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
81 */
82 struct dccp_hdr_response {
83 struct dccp_hdr_ack_bits dccph_resp_ack;
84 u_int32_t dccph_resp_service;
85 };
86
87 static inline struct dccp_hdr_data *dccp_hdr_data(struct dccp_hdr *hdrg)
88 {
89 const int ext = DCCPH_X(hdrg) ? sizeof(struct dccp_hdr_ext) : 0;
90
91 return (struct dccp_hdr_data *)(((u_char *)hdrg) + sizeof(hdrg) + ext);
92 }
93
94 /**
95 * struct dccp_hdr_reset - Unconditionally shut down a connection
96 *
97 * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
98 */
99 struct dccp_hdr_reset {
100 struct dccp_hdr_ack_bits dccph_reset_ack;
101 u_int8_t dccph_reset_code,
102 dccph_reset_data[3];
103 };
104
105 enum dccp_pkt_type {
106 DCCP_PKT_REQUEST = 0,
107 DCCP_PKT_RESPONSE,
108 DCCP_PKT_DATA,
109 DCCP_PKT_ACK,
110 DCCP_PKT_DATAACK,
111 DCCP_PKT_CLOSEREQ,
112 DCCP_PKT_CLOSE,
113 DCCP_PKT_RESET,
114 DCCP_PKT_SYNC,
115 DCCP_PKT_SYNCACK,
116 DCCP_PKT_INVALID,
117 };
118
119 enum dccp_reset_codes {
120 DCCP_RESET_CODE_UNSPECIFIED = 0,
121 DCCP_RESET_CODE_CLOSED,
122 DCCP_RESET_CODE_ABORTED,
123 DCCP_RESET_CODE_NO_CONNECTION,
124 DCCP_RESET_CODE_PACKET_ERROR,
125 DCCP_RESET_CODE_OPTION_ERROR,
126 DCCP_RESET_CODE_MANDATORY_ERROR,
127 DCCP_RESET_CODE_CONNECTION_REFUSED,
128 DCCP_RESET_CODE_BAD_SERVICE_CODE,
129 DCCP_RESET_CODE_TOO_BUSY,
130 DCCP_RESET_CODE_BAD_INIT_COOKIE,
131 DCCP_RESET_CODE_AGGRESSION_PENALTY,
132 __DCCP_RESET_CODE_LAST,
133 };
134
135 #endif /* __DCCP_HDR__ */