xref: /linux/include/uapi/linux/dccp.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*6f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI_LINUX_DCCP_H
3607ca46eSDavid Howells #define _UAPI_LINUX_DCCP_H
4607ca46eSDavid Howells 
5607ca46eSDavid Howells #include <linux/types.h>
6607ca46eSDavid Howells #include <asm/byteorder.h>
7607ca46eSDavid Howells 
8607ca46eSDavid Howells /**
9607ca46eSDavid Howells  * struct dccp_hdr - generic part of DCCP packet header
10607ca46eSDavid Howells  *
11607ca46eSDavid Howells  * @dccph_sport - Relevant port on the endpoint that sent this packet
12607ca46eSDavid Howells  * @dccph_dport - Relevant port on the other endpoint
13607ca46eSDavid Howells  * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
14607ca46eSDavid Howells  * @dccph_ccval - Used by the HC-Sender CCID
15607ca46eSDavid Howells  * @dccph_cscov - Parts of the packet that are covered by the Checksum field
16607ca46eSDavid Howells  * @dccph_checksum - Internet checksum, depends on dccph_cscov
17607ca46eSDavid Howells  * @dccph_x - 0 = 24 bit sequence number, 1 = 48
18607ca46eSDavid Howells  * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
19607ca46eSDavid Howells  * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
20607ca46eSDavid Howells  */
21607ca46eSDavid Howells struct dccp_hdr {
22607ca46eSDavid Howells 	__be16	dccph_sport,
23607ca46eSDavid Howells 		dccph_dport;
24607ca46eSDavid Howells 	__u8	dccph_doff;
25607ca46eSDavid Howells #if defined(__LITTLE_ENDIAN_BITFIELD)
26607ca46eSDavid Howells 	__u8	dccph_cscov:4,
27607ca46eSDavid Howells 		dccph_ccval:4;
28607ca46eSDavid Howells #elif defined(__BIG_ENDIAN_BITFIELD)
29607ca46eSDavid Howells 	__u8	dccph_ccval:4,
30607ca46eSDavid Howells 		dccph_cscov:4;
31607ca46eSDavid Howells #else
32607ca46eSDavid Howells #error  "Adjust your <asm/byteorder.h> defines"
33607ca46eSDavid Howells #endif
34607ca46eSDavid Howells 	__sum16	dccph_checksum;
35607ca46eSDavid Howells #if defined(__LITTLE_ENDIAN_BITFIELD)
36607ca46eSDavid Howells 	__u8	dccph_x:1,
37607ca46eSDavid Howells 		dccph_type:4,
38607ca46eSDavid Howells 		dccph_reserved:3;
39607ca46eSDavid Howells #elif defined(__BIG_ENDIAN_BITFIELD)
40607ca46eSDavid Howells 	__u8	dccph_reserved:3,
41607ca46eSDavid Howells 		dccph_type:4,
42607ca46eSDavid Howells 		dccph_x:1;
43607ca46eSDavid Howells #else
44607ca46eSDavid Howells #error  "Adjust your <asm/byteorder.h> defines"
45607ca46eSDavid Howells #endif
46607ca46eSDavid Howells 	__u8	dccph_seq2;
47607ca46eSDavid Howells 	__be16	dccph_seq;
48607ca46eSDavid Howells };
49607ca46eSDavid Howells 
50607ca46eSDavid Howells /**
51607ca46eSDavid Howells  * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
52607ca46eSDavid Howells  *
53607ca46eSDavid Howells  * @dccph_seq_low - low 24 bits of a 48 bit seq packet
54607ca46eSDavid Howells  */
55607ca46eSDavid Howells struct dccp_hdr_ext {
56607ca46eSDavid Howells 	__be32	dccph_seq_low;
57607ca46eSDavid Howells };
58607ca46eSDavid Howells 
59607ca46eSDavid Howells /**
60607ca46eSDavid Howells  * struct dccp_hdr_request - Connection initiation request header
61607ca46eSDavid Howells  *
62607ca46eSDavid Howells  * @dccph_req_service - Service to which the client app wants to connect
63607ca46eSDavid Howells  */
64607ca46eSDavid Howells struct dccp_hdr_request {
65607ca46eSDavid Howells 	__be32	dccph_req_service;
66607ca46eSDavid Howells };
67607ca46eSDavid Howells /**
68607ca46eSDavid Howells  * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
69607ca46eSDavid Howells  *
70607ca46eSDavid Howells  * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
71607ca46eSDavid Howells  * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
72607ca46eSDavid Howells  */
73607ca46eSDavid Howells struct dccp_hdr_ack_bits {
74607ca46eSDavid Howells 	__be16	dccph_reserved1;
75607ca46eSDavid Howells 	__be16	dccph_ack_nr_high;
76607ca46eSDavid Howells 	__be32	dccph_ack_nr_low;
77607ca46eSDavid Howells };
78607ca46eSDavid Howells /**
79607ca46eSDavid Howells  * struct dccp_hdr_response - Connection initiation response header
80607ca46eSDavid Howells  *
81607ca46eSDavid Howells  * @dccph_resp_ack - 48 bit Acknowledgment Number Subheader (5.3)
82607ca46eSDavid Howells  * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
83607ca46eSDavid Howells  */
84607ca46eSDavid Howells struct dccp_hdr_response {
85607ca46eSDavid Howells 	struct dccp_hdr_ack_bits	dccph_resp_ack;
86607ca46eSDavid Howells 	__be32				dccph_resp_service;
87607ca46eSDavid Howells };
88607ca46eSDavid Howells 
89607ca46eSDavid Howells /**
90607ca46eSDavid Howells  * struct dccp_hdr_reset - Unconditionally shut down a connection
91607ca46eSDavid Howells  *
92607ca46eSDavid Howells  * @dccph_reset_ack - 48 bit Acknowledgment Number Subheader (5.6)
93607ca46eSDavid Howells  * @dccph_reset_code - one of %dccp_reset_codes
94607ca46eSDavid Howells  * @dccph_reset_data - the Data 1 ... Data 3 fields from 5.6
95607ca46eSDavid Howells  */
96607ca46eSDavid Howells struct dccp_hdr_reset {
97607ca46eSDavid Howells 	struct dccp_hdr_ack_bits	dccph_reset_ack;
98607ca46eSDavid Howells 	__u8				dccph_reset_code,
99607ca46eSDavid Howells 					dccph_reset_data[3];
100607ca46eSDavid Howells };
101607ca46eSDavid Howells 
102607ca46eSDavid Howells enum dccp_pkt_type {
103607ca46eSDavid Howells 	DCCP_PKT_REQUEST = 0,
104607ca46eSDavid Howells 	DCCP_PKT_RESPONSE,
105607ca46eSDavid Howells 	DCCP_PKT_DATA,
106607ca46eSDavid Howells 	DCCP_PKT_ACK,
107607ca46eSDavid Howells 	DCCP_PKT_DATAACK,
108607ca46eSDavid Howells 	DCCP_PKT_CLOSEREQ,
109607ca46eSDavid Howells 	DCCP_PKT_CLOSE,
110607ca46eSDavid Howells 	DCCP_PKT_RESET,
111607ca46eSDavid Howells 	DCCP_PKT_SYNC,
112607ca46eSDavid Howells 	DCCP_PKT_SYNCACK,
113607ca46eSDavid Howells 	DCCP_PKT_INVALID,
114607ca46eSDavid Howells };
115607ca46eSDavid Howells 
116607ca46eSDavid Howells #define DCCP_NR_PKT_TYPES DCCP_PKT_INVALID
117607ca46eSDavid Howells 
dccp_packet_hdr_len(const __u8 type)118607ca46eSDavid Howells static inline unsigned int dccp_packet_hdr_len(const __u8 type)
119607ca46eSDavid Howells {
120607ca46eSDavid Howells 	if (type == DCCP_PKT_DATA)
121607ca46eSDavid Howells 		return 0;
122607ca46eSDavid Howells 	if (type == DCCP_PKT_DATAACK	||
123607ca46eSDavid Howells 	    type == DCCP_PKT_ACK	||
124607ca46eSDavid Howells 	    type == DCCP_PKT_SYNC	||
125607ca46eSDavid Howells 	    type == DCCP_PKT_SYNCACK	||
126607ca46eSDavid Howells 	    type == DCCP_PKT_CLOSE	||
127607ca46eSDavid Howells 	    type == DCCP_PKT_CLOSEREQ)
128607ca46eSDavid Howells 		return sizeof(struct dccp_hdr_ack_bits);
129607ca46eSDavid Howells 	if (type == DCCP_PKT_REQUEST)
130607ca46eSDavid Howells 		return sizeof(struct dccp_hdr_request);
131607ca46eSDavid Howells 	if (type == DCCP_PKT_RESPONSE)
132607ca46eSDavid Howells 		return sizeof(struct dccp_hdr_response);
133607ca46eSDavid Howells 	return sizeof(struct dccp_hdr_reset);
134607ca46eSDavid Howells }
135607ca46eSDavid Howells enum dccp_reset_codes {
136607ca46eSDavid Howells 	DCCP_RESET_CODE_UNSPECIFIED = 0,
137607ca46eSDavid Howells 	DCCP_RESET_CODE_CLOSED,
138607ca46eSDavid Howells 	DCCP_RESET_CODE_ABORTED,
139607ca46eSDavid Howells 	DCCP_RESET_CODE_NO_CONNECTION,
140607ca46eSDavid Howells 	DCCP_RESET_CODE_PACKET_ERROR,
141607ca46eSDavid Howells 	DCCP_RESET_CODE_OPTION_ERROR,
142607ca46eSDavid Howells 	DCCP_RESET_CODE_MANDATORY_ERROR,
143607ca46eSDavid Howells 	DCCP_RESET_CODE_CONNECTION_REFUSED,
144607ca46eSDavid Howells 	DCCP_RESET_CODE_BAD_SERVICE_CODE,
145607ca46eSDavid Howells 	DCCP_RESET_CODE_TOO_BUSY,
146607ca46eSDavid Howells 	DCCP_RESET_CODE_BAD_INIT_COOKIE,
147607ca46eSDavid Howells 	DCCP_RESET_CODE_AGGRESSION_PENALTY,
148607ca46eSDavid Howells 
149607ca46eSDavid Howells 	DCCP_MAX_RESET_CODES		/* Leave at the end!  */
150607ca46eSDavid Howells };
151607ca46eSDavid Howells 
152607ca46eSDavid Howells /* DCCP options */
153607ca46eSDavid Howells enum {
154607ca46eSDavid Howells 	DCCPO_PADDING = 0,
155607ca46eSDavid Howells 	DCCPO_MANDATORY = 1,
156607ca46eSDavid Howells 	DCCPO_MIN_RESERVED = 3,
157607ca46eSDavid Howells 	DCCPO_MAX_RESERVED = 31,
158607ca46eSDavid Howells 	DCCPO_CHANGE_L = 32,
159607ca46eSDavid Howells 	DCCPO_CONFIRM_L = 33,
160607ca46eSDavid Howells 	DCCPO_CHANGE_R = 34,
161607ca46eSDavid Howells 	DCCPO_CONFIRM_R = 35,
162607ca46eSDavid Howells 	DCCPO_NDP_COUNT = 37,
163607ca46eSDavid Howells 	DCCPO_ACK_VECTOR_0 = 38,
164607ca46eSDavid Howells 	DCCPO_ACK_VECTOR_1 = 39,
165607ca46eSDavid Howells 	DCCPO_TIMESTAMP = 41,
166607ca46eSDavid Howells 	DCCPO_TIMESTAMP_ECHO = 42,
167607ca46eSDavid Howells 	DCCPO_ELAPSED_TIME = 43,
168607ca46eSDavid Howells 	DCCPO_MAX = 45,
169607ca46eSDavid Howells 	DCCPO_MIN_RX_CCID_SPECIFIC = 128,	/* from sender to receiver */
170607ca46eSDavid Howells 	DCCPO_MAX_RX_CCID_SPECIFIC = 191,
171607ca46eSDavid Howells 	DCCPO_MIN_TX_CCID_SPECIFIC = 192,	/* from receiver to sender */
172607ca46eSDavid Howells 	DCCPO_MAX_TX_CCID_SPECIFIC = 255,
173607ca46eSDavid Howells };
174607ca46eSDavid Howells /* maximum size of a single TLV-encoded DCCP option (sans type/len bytes) */
175607ca46eSDavid Howells #define DCCP_SINGLE_OPT_MAXLEN	253
176607ca46eSDavid Howells 
177607ca46eSDavid Howells /* DCCP CCIDS */
178607ca46eSDavid Howells enum {
179607ca46eSDavid Howells 	DCCPC_CCID2 = 2,
180607ca46eSDavid Howells 	DCCPC_CCID3 = 3,
181607ca46eSDavid Howells };
182607ca46eSDavid Howells 
183607ca46eSDavid Howells /* DCCP features (RFC 4340 section 6.4) */
184607ca46eSDavid Howells enum dccp_feature_numbers {
185607ca46eSDavid Howells 	DCCPF_RESERVED = 0,
186607ca46eSDavid Howells 	DCCPF_CCID = 1,
187607ca46eSDavid Howells 	DCCPF_SHORT_SEQNOS = 2,
188607ca46eSDavid Howells 	DCCPF_SEQUENCE_WINDOW = 3,
189607ca46eSDavid Howells 	DCCPF_ECN_INCAPABLE = 4,
190607ca46eSDavid Howells 	DCCPF_ACK_RATIO = 5,
191607ca46eSDavid Howells 	DCCPF_SEND_ACK_VECTOR = 6,
192607ca46eSDavid Howells 	DCCPF_SEND_NDP_COUNT = 7,
193607ca46eSDavid Howells 	DCCPF_MIN_CSUM_COVER = 8,
194607ca46eSDavid Howells 	DCCPF_DATA_CHECKSUM = 9,
195607ca46eSDavid Howells 	/* 10-127 reserved */
196607ca46eSDavid Howells 	DCCPF_MIN_CCID_SPECIFIC = 128,
197607ca46eSDavid Howells 	DCCPF_SEND_LEV_RATE = 192,	/* RFC 4342, sec. 8.4 */
198607ca46eSDavid Howells 	DCCPF_MAX_CCID_SPECIFIC = 255,
199607ca46eSDavid Howells };
200607ca46eSDavid Howells 
201607ca46eSDavid Howells /* DCCP socket control message types for cmsg */
202607ca46eSDavid Howells enum dccp_cmsg_type {
203607ca46eSDavid Howells 	DCCP_SCM_PRIORITY = 1,
204607ca46eSDavid Howells 	DCCP_SCM_QPOLICY_MAX = 0xFFFF,
205607ca46eSDavid Howells 	/* ^-- Up to here reserved exclusively for qpolicy parameters */
206607ca46eSDavid Howells 	DCCP_SCM_MAX
207607ca46eSDavid Howells };
208607ca46eSDavid Howells 
209607ca46eSDavid Howells /* DCCP priorities for outgoing/queued packets */
210607ca46eSDavid Howells enum dccp_packet_dequeueing_policy {
211607ca46eSDavid Howells 	DCCPQ_POLICY_SIMPLE,
212607ca46eSDavid Howells 	DCCPQ_POLICY_PRIO,
213607ca46eSDavid Howells 	DCCPQ_POLICY_MAX
214607ca46eSDavid Howells };
215607ca46eSDavid Howells 
216607ca46eSDavid Howells /* DCCP socket options */
217607ca46eSDavid Howells #define DCCP_SOCKOPT_PACKET_SIZE	1 /* XXX deprecated, without effect */
218607ca46eSDavid Howells #define DCCP_SOCKOPT_SERVICE		2
219607ca46eSDavid Howells #define DCCP_SOCKOPT_CHANGE_L		3
220607ca46eSDavid Howells #define DCCP_SOCKOPT_CHANGE_R		4
221607ca46eSDavid Howells #define DCCP_SOCKOPT_GET_CUR_MPS	5
222607ca46eSDavid Howells #define DCCP_SOCKOPT_SERVER_TIMEWAIT	6
223607ca46eSDavid Howells #define DCCP_SOCKOPT_SEND_CSCOV		10
224607ca46eSDavid Howells #define DCCP_SOCKOPT_RECV_CSCOV		11
225607ca46eSDavid Howells #define DCCP_SOCKOPT_AVAILABLE_CCIDS	12
226607ca46eSDavid Howells #define DCCP_SOCKOPT_CCID		13
227607ca46eSDavid Howells #define DCCP_SOCKOPT_TX_CCID		14
228607ca46eSDavid Howells #define DCCP_SOCKOPT_RX_CCID		15
229607ca46eSDavid Howells #define DCCP_SOCKOPT_QPOLICY_ID		16
230607ca46eSDavid Howells #define DCCP_SOCKOPT_QPOLICY_TXQLEN	17
231607ca46eSDavid Howells #define DCCP_SOCKOPT_CCID_RX_INFO	128
232607ca46eSDavid Howells #define DCCP_SOCKOPT_CCID_TX_INFO	192
233607ca46eSDavid Howells 
234607ca46eSDavid Howells /* maximum number of services provided on the same listening port */
235607ca46eSDavid Howells #define DCCP_SERVICE_LIST_MAX_LEN      32
236607ca46eSDavid Howells 
237607ca46eSDavid Howells 
238607ca46eSDavid Howells #endif /* _UAPI_LINUX_DCCP_H */
239