dccp.h revision 162017
1162017Ssam/* @(#) $Header: /tcpdump/master/tcpdump/dccp.h,v 1.1.2.2 2005/09/20 06:25:45 guy Exp $ (LBL) */
2162017Ssam/*
3162017Ssam * Copyright (C) Arnaldo Carvalho de Melo 2004
4162017Ssam * Copyright (C) Ian McDonald 2005 <iam4@cs.waikato.ac.nz>
5162017Ssam * Copyright (C) Yoshifumi Nishida 2005
6162017Ssam *
7162017Ssam * This software may be distributed either under the terms of the
8162017Ssam * BSD-style license that accompanies tcpdump or the GNU GPL version 2
9162017Ssam */
10162017Ssam
11162017Ssam#ifndef __DCCP_HDR__
12162017Ssam#define __DCCP_HDR__
13162017Ssam
14162017Ssam/**
15162017Ssam * struct dccp_hdr - generic part of DCCP packet header
16162017Ssam *
17162017Ssam * @dccph_sport - Relevant port on the endpoint that sent this packet
18162017Ssam * @dccph_dport - Relevant port on the other endpoint
19162017Ssam * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
20162017Ssam * @dccph_ccval - Used by the HC-Sender CCID
21162017Ssam * @dccph_cscov - Parts of the packet that are covered by the Checksum field
22162017Ssam * @dccph_checksum - Internet checksum, depends on dccph_cscov
23162017Ssam * @dccph_x - 0 = 24 bit sequence number, 1 = 48
24162017Ssam * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
25162017Ssam * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
26162017Ssam */
27162017Ssamstruct dccp_hdr {
28162017Ssam	u_int16_t	dccph_sport,
29162017Ssam			dccph_dport;
30162017Ssam	u_int8_t	dccph_doff;
31162017Ssam	u_int8_t	dccph_ccval_cscov;
32162017Ssam	u_int16_t	dccph_checksum;
33162017Ssam	union {
34162017Ssam	u_int8_t	dccph_xtr;
35162017Ssam	u_int32_t	dccph_seq;
36162017Ssam	}		dccph_xtrs;
37162017Ssam};
38162017Ssam
39162017Ssam#define DCCPH_CCVAL(dh)	(((dh)->dccph_ccval_cscov) & 0x0F)
40162017Ssam#define DCCPH_CSCOV(dh)	(((dh)->dccph_ccval_cscov >> 4) & 0x0F)
41162017Ssam
42162017Ssam#define DCCPH_X(dh)	((dh)->dccph_xtrs.dccph_xtr & 1)
43162017Ssam#define DCCPH_TYPE(dh)	(((dh)->dccph_xtrs.dccph_xtr >> 1) & 0xF)
44162017Ssam#define DCCPH_SEQ(dh)   (((dh)->dccph_xtrs.dccph_seq) >> 8)
45162017Ssam
46162017Ssam/**
47162017Ssam * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
48162017Ssam *
49162017Ssam * @dccph_seq_low - low 24 bits of a 48 bit seq packet
50162017Ssam */
51162017Ssamstruct dccp_hdr_ext {
52162017Ssam	u_int32_t	dccph_seq_low;
53162017Ssam};
54162017Ssam
55162017Ssam/**
56162017Ssam * struct dccp_hdr_request - Conection initiation request header
57162017Ssam *
58162017Ssam * @dccph_req_service - Service to which the client app wants to connect
59162017Ssam */
60162017Ssamstruct dccp_hdr_request {
61162017Ssam	u_int32_t	dccph_req_service;
62162017Ssam};
63162017Ssam
64162017Ssam/**
65162017Ssam * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
66162017Ssam *
67162017Ssam * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
68162017Ssam * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
69162017Ssam */
70162017Ssamstruct dccp_hdr_ack_bits {
71162017Ssam	u_int32_t	dccph_ra;
72162017Ssam	u_int32_t	dccph_ack_nr_low;
73162017Ssam};
74162017Ssam
75162017Ssam#define DCCPH_ACK(dh_ack)   ((dh_ack)->dccph_ra >> 8)
76162017Ssam
77162017Ssam/**
78162017Ssam * struct dccp_hdr_response - Conection initiation response header
79162017Ssam *
80162017Ssam * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
81162017Ssam * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
82162017Ssam * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
83162017Ssam */
84162017Ssamstruct dccp_hdr_response {
85162017Ssam	struct dccp_hdr_ack_bits	dccph_resp_ack;
86162017Ssam	u_int32_t			dccph_resp_service;
87162017Ssam};
88162017Ssam
89162017Ssamstatic inline struct dccp_hdr_data *dccp_hdr_data(struct dccp_hdr *hdrg)
90162017Ssam{
91162017Ssam	const int ext = DCCPH_X(hdrg) ? sizeof(struct dccp_hdr_ext) : 0;
92162017Ssam
93162017Ssam	return (struct dccp_hdr_data *)(((u_char *)hdrg) + sizeof(hdrg) + ext);
94162017Ssam}
95162017Ssam
96162017Ssam/**
97162017Ssam * struct dccp_hdr_reset - Unconditionally shut down a connection
98162017Ssam *
99162017Ssam * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
100162017Ssam */
101162017Ssamstruct dccp_hdr_reset {
102162017Ssam	struct dccp_hdr_ack_bits	dccph_reset_ack;
103162017Ssam	u_int8_t			dccph_reset_code,
104162017Ssam					dccph_reset_data[3];
105162017Ssam};
106162017Ssam
107162017Ssamenum dccp_pkt_type {
108162017Ssam	DCCP_PKT_REQUEST = 0,
109162017Ssam	DCCP_PKT_RESPONSE,
110162017Ssam	DCCP_PKT_DATA,
111162017Ssam	DCCP_PKT_ACK,
112162017Ssam	DCCP_PKT_DATAACK,
113162017Ssam	DCCP_PKT_CLOSEREQ,
114162017Ssam	DCCP_PKT_CLOSE,
115162017Ssam	DCCP_PKT_RESET,
116162017Ssam	DCCP_PKT_SYNC,
117162017Ssam	DCCP_PKT_SYNCACK,
118162017Ssam	DCCP_PKT_INVALID,
119162017Ssam};
120162017Ssam
121162017Ssamenum dccp_reset_codes {
122162017Ssam	DCCP_RESET_CODE_UNSPECIFIED = 0,
123162017Ssam	DCCP_RESET_CODE_CLOSED,
124162017Ssam	DCCP_RESET_CODE_ABORTED,
125162017Ssam	DCCP_RESET_CODE_NO_CONNECTION,
126162017Ssam	DCCP_RESET_CODE_PACKET_ERROR,
127162017Ssam	DCCP_RESET_CODE_OPTION_ERROR,
128162017Ssam	DCCP_RESET_CODE_MANDATORY_ERROR,
129162017Ssam	DCCP_RESET_CODE_CONNECTION_REFUSED,
130162017Ssam	DCCP_RESET_CODE_BAD_SERVICE_CODE,
131162017Ssam	DCCP_RESET_CODE_TOO_BUSY,
132162017Ssam	DCCP_RESET_CODE_BAD_INIT_COOKIE,
133162017Ssam	DCCP_RESET_CODE_AGGRESSION_PENALTY,
134162017Ssam	__DCCP_RESET_CODE_LAST,
135162017Ssam};
136162017Ssam
137162017Ssam#endif /* __DCCP_HDR__ */
138