blob: add4908b8e577b78c8bc6151eefad7092992f9ce [file] [log] [blame]
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -07001#ifndef _LINUX_DCCP_H
2#define _LINUX_DCCP_H
3
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -07004#include <linux/types.h>
Harald Welte5a47a472005-08-09 20:26:03 -07005#include <asm/byteorder.h>
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -07006
7/* FIXME: this is utterly wrong */
8struct sockaddr_dccp {
9 struct sockaddr_in in;
10 unsigned int service;
11};
12
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070013/**
14 * struct dccp_hdr - generic part of DCCP packet header
15 *
16 * @dccph_sport - Relevant port on the endpoint that sent this packet
17 * @dccph_dport - Relevant port on the other endpoint
18 * @dccph_doff - Data Offset from the start of the DCCP header, in 32-bit words
19 * @dccph_ccval - Used by the HC-Sender CCID
20 * @dccph_cscov - Parts of the packet that are covered by the Checksum field
21 * @dccph_checksum - Internet checksum, depends on dccph_cscov
22 * @dccph_x - 0 = 24 bit sequence number, 1 = 48
23 * @dccph_type - packet type, see DCCP_PKT_ prefixed macros
24 * @dccph_seq - sequence number high or low order 24 bits, depends on dccph_x
25 */
26struct dccp_hdr {
27 __u16 dccph_sport,
28 dccph_dport;
29 __u8 dccph_doff;
30#if defined(__LITTLE_ENDIAN_BITFIELD)
31 __u8 dccph_cscov:4,
32 dccph_ccval:4;
33#elif defined(__BIG_ENDIAN_BITFIELD)
34 __u8 dccph_ccval:4,
35 dccph_cscov:4;
36#else
37#error "Adjust your <asm/byteorder.h> defines"
38#endif
39 __u16 dccph_checksum;
40#if defined(__LITTLE_ENDIAN_BITFIELD)
41 __u32 dccph_x:1,
42 dccph_type:4,
43 dccph_reserved:3,
44 dccph_seq:24;
45#elif defined(__BIG_ENDIAN_BITFIELD)
46 __u32 dccph_reserved:3,
47 dccph_type:4,
48 dccph_x:1,
49 dccph_seq:24;
50#else
51#error "Adjust your <asm/byteorder.h> defines"
52#endif
53};
54
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070055/**
56 * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
57 *
58 * @dccph_seq_low - low 24 bits of a 48 bit seq packet
59 */
60struct dccp_hdr_ext {
61 __u32 dccph_seq_low;
62};
63
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070064/**
65 * struct dccp_hdr_request - Conection initiation request header
66 *
67 * @dccph_req_service - Service to which the client app wants to connect
68 * @dccph_req_options - list of options (must be a multiple of 32 bits
69 */
70struct dccp_hdr_request {
71 __u32 dccph_req_service;
72};
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070073/**
74 * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
75 *
76 * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
77 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
78 */
79struct dccp_hdr_ack_bits {
80 __u32 dccph_reserved1:8,
81 dccph_ack_nr_high:24;
82 __u32 dccph_ack_nr_low;
83};
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070084/**
85 * struct dccp_hdr_response - Conection initiation response header
86 *
87 * @dccph_resp_ack_nr_high - 48 bit ack number high order bits, contains GSR
88 * @dccph_resp_ack_nr_low - 48 bit ack number low order bits, contains GSR
89 * @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
90 * @dccph_resp_options - list of options (must be a multiple of 32 bits
91 */
92struct dccp_hdr_response {
93 struct dccp_hdr_ack_bits dccph_resp_ack;
94 __u32 dccph_resp_service;
95};
96
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070097/**
98 * struct dccp_hdr_reset - Unconditionally shut down a connection
99 *
100 * @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
101 * @dccph_reset_options - list of options (must be a multiple of 32 bits
102 */
103struct dccp_hdr_reset {
104 struct dccp_hdr_ack_bits dccph_reset_ack;
105 __u8 dccph_reset_code,
106 dccph_reset_data[3];
107};
108
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700109enum dccp_pkt_type {
110 DCCP_PKT_REQUEST = 0,
111 DCCP_PKT_RESPONSE,
112 DCCP_PKT_DATA,
113 DCCP_PKT_ACK,
114 DCCP_PKT_DATAACK,
115 DCCP_PKT_CLOSEREQ,
116 DCCP_PKT_CLOSE,
117 DCCP_PKT_RESET,
118 DCCP_PKT_SYNC,
119 DCCP_PKT_SYNCACK,
120 DCCP_PKT_INVALID,
121};
122
123#define DCCP_NR_PKT_TYPES DCCP_PKT_INVALID
124
125static inline unsigned int dccp_packet_hdr_len(const __u8 type)
126{
127 if (type == DCCP_PKT_DATA)
128 return 0;
129 if (type == DCCP_PKT_DATAACK ||
130 type == DCCP_PKT_ACK ||
131 type == DCCP_PKT_SYNC ||
132 type == DCCP_PKT_SYNCACK ||
133 type == DCCP_PKT_CLOSE ||
134 type == DCCP_PKT_CLOSEREQ)
135 return sizeof(struct dccp_hdr_ack_bits);
136 if (type == DCCP_PKT_REQUEST)
137 return sizeof(struct dccp_hdr_request);
138 if (type == DCCP_PKT_RESPONSE)
139 return sizeof(struct dccp_hdr_response);
140 return sizeof(struct dccp_hdr_reset);
141}
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700142enum dccp_reset_codes {
143 DCCP_RESET_CODE_UNSPECIFIED = 0,
144 DCCP_RESET_CODE_CLOSED,
145 DCCP_RESET_CODE_ABORTED,
146 DCCP_RESET_CODE_NO_CONNECTION,
147 DCCP_RESET_CODE_PACKET_ERROR,
148 DCCP_RESET_CODE_OPTION_ERROR,
149 DCCP_RESET_CODE_MANDATORY_ERROR,
150 DCCP_RESET_CODE_CONNECTION_REFUSED,
151 DCCP_RESET_CODE_BAD_SERVICE_CODE,
152 DCCP_RESET_CODE_TOO_BUSY,
153 DCCP_RESET_CODE_BAD_INIT_COOKIE,
154 DCCP_RESET_CODE_AGGRESSION_PENALTY,
155};
156
157/* DCCP options */
158enum {
159 DCCPO_PADDING = 0,
160 DCCPO_MANDATORY = 1,
161 DCCPO_MIN_RESERVED = 3,
162 DCCPO_MAX_RESERVED = 31,
163 DCCPO_NDP_COUNT = 37,
164 DCCPO_ACK_VECTOR_0 = 38,
165 DCCPO_ACK_VECTOR_1 = 39,
166 DCCPO_TIMESTAMP = 41,
167 DCCPO_TIMESTAMP_ECHO = 42,
168 DCCPO_ELAPSED_TIME = 43,
169 DCCPO_MAX = 45,
170 DCCPO_MIN_CCID_SPECIFIC = 128,
171 DCCPO_MAX_CCID_SPECIFIC = 255,
172};
173
174/* DCCP features */
175enum {
176 DCCPF_RESERVED = 0,
177 DCCPF_SEQUENCE_WINDOW = 3,
178 DCCPF_SEND_ACK_VECTOR = 6,
179 DCCPF_SEND_NDP_COUNT = 7,
180 /* 10-127 reserved */
181 DCCPF_MIN_CCID_SPECIFIC = 128,
182 DCCPF_MAX_CCID_SPECIFIC = 255,
183};
184
Harald Welte5a47a472005-08-09 20:26:03 -0700185#ifdef __KERNEL__
186
187#include <linux/in.h>
188#include <linux/list.h>
189#include <linux/uio.h>
190#include <linux/workqueue.h>
191
192#include <net/inet_connection_sock.h>
193#include <net/sock.h>
194#include <net/tcp_states.h>
195#include <net/tcp.h>
196
197enum dccp_state {
198 DCCP_OPEN = TCP_ESTABLISHED,
199 DCCP_REQUESTING = TCP_SYN_SENT,
200 DCCP_PARTOPEN = TCP_FIN_WAIT1, /* FIXME:
201 This mapping is horrible, but TCP has
202 no matching state for DCCP_PARTOPEN,
203 as TCP_SYN_RECV is already used by
204 DCCP_RESPOND, why don't stop using TCP
205 mapping of states? OK, now we don't use
206 sk_stream_sendmsg anymore, so doesn't
207 seem to exist any reason for us to
208 do the TCP mapping here */
209 DCCP_LISTEN = TCP_LISTEN,
210 DCCP_RESPOND = TCP_SYN_RECV,
211 DCCP_CLOSING = TCP_CLOSING,
212 DCCP_TIME_WAIT = TCP_TIME_WAIT,
213 DCCP_CLOSED = TCP_CLOSE,
214 DCCP_MAX_STATES = TCP_MAX_STATES,
215};
216
217#define DCCP_STATE_MASK 0xf
218#define DCCP_ACTION_FIN (1<<7)
219
220enum {
221 DCCPF_OPEN = TCPF_ESTABLISHED,
222 DCCPF_REQUESTING = TCPF_SYN_SENT,
223 DCCPF_PARTOPEN = TCPF_FIN_WAIT1,
224 DCCPF_LISTEN = TCPF_LISTEN,
225 DCCPF_RESPOND = TCPF_SYN_RECV,
226 DCCPF_CLOSING = TCPF_CLOSING,
227 DCCPF_TIME_WAIT = TCPF_TIME_WAIT,
228 DCCPF_CLOSED = TCPF_CLOSE,
229};
230
231static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
232{
233 return (struct dccp_hdr *)skb->h.raw;
234}
235
236static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
237{
238 return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
239}
240
241static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
242{
243 const struct dccp_hdr *dh = dccp_hdr(skb);
244 return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0);
245}
246
247static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)
248{
249 const struct dccp_hdr *dh = dccp_hdr(skb);
250#if defined(__LITTLE_ENDIAN_BITFIELD)
251 __u64 seq_nr = ntohl(dh->dccph_seq << 8);
252#elif defined(__BIG_ENDIAN_BITFIELD)
253 __u64 seq_nr = ntohl(dh->dccph_seq);
254#else
255#error "Adjust your <asm/byteorder.h> defines"
256#endif
257
258 if (dh->dccph_x != 0)
259 seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low);
260
261 return seq_nr;
262}
263
264static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb)
265{
266 return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb));
267}
268
269static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb)
270{
271 return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb));
272}
273
274static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
275{
276 const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb);
277#if defined(__LITTLE_ENDIAN_BITFIELD)
278 return (((u64)ntohl(dhack->dccph_ack_nr_high << 8)) << 32) + ntohl(dhack->dccph_ack_nr_low);
279#elif defined(__BIG_ENDIAN_BITFIELD)
280 return (((u64)ntohl(dhack->dccph_ack_nr_high)) << 32) + ntohl(dhack->dccph_ack_nr_low);
281#else
282#error "Adjust your <asm/byteorder.h> defines"
283#endif
284}
285
286static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
287{
288 return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb));
289}
290
291static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb)
292{
293 return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb));
294}
295
296static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
297{
298 return dccp_basic_hdr_len(skb) +
299 dccp_packet_hdr_len(dccp_hdr(skb)->dccph_type);
300}
301
302
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700303/* initial values for each feature */
304#define DCCPF_INITIAL_SEQUENCE_WINDOW 100
305/* FIXME: for now we're using CCID 3 (TFRC) */
306#define DCCPF_INITIAL_CCID 3
307#define DCCPF_INITIAL_SEND_ACK_VECTOR 0
308/* FIXME: for now we're default to 1 but it should really be 0 */
309#define DCCPF_INITIAL_SEND_NDP_COUNT 1
310
311#define DCCP_NDP_LIMIT 0xFFFFFF
312
313/**
314 * struct dccp_options - option values for a DCCP connection
315 * @dccpo_sequence_window - Sequence Window Feature (section 7.5.2)
316 * @dccpo_ccid - Congestion Control Id (CCID) (section 10)
317 * @dccpo_send_ack_vector - Send Ack Vector Feature (section 11.5)
318 * @dccpo_send_ndp_count - Send NDP Count Feature (7.7.2)
319 */
320struct dccp_options {
321 __u64 dccpo_sequence_window;
322 __u8 dccpo_ccid;
323 __u8 dccpo_send_ack_vector;
324 __u8 dccpo_send_ndp_count;
325};
326
327extern void __dccp_options_init(struct dccp_options *dccpo);
328extern void dccp_options_init(struct dccp_options *dccpo);
329extern int dccp_parse_options(struct sock *sk, struct sk_buff *skb);
330
331struct dccp_request_sock {
332 struct inet_request_sock dreq_inet_rsk;
333 __u64 dreq_iss;
334 __u64 dreq_isr;
335 __u32 dreq_service;
336};
337
338static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
339{
340 return (struct dccp_request_sock *)req;
341}
342
343/* Read about the ECN nonce to see why it is 253 */
344#define DCCP_MAX_ACK_VECTOR_LEN 253
345
346struct dccp_options_received {
347 u32 dccpor_ndp:24,
348 dccpor_ack_vector_len:8;
349 u32 dccpor_ack_vector_idx:10;
350 /* 22 bits hole, try to pack */
351 u32 dccpor_timestamp;
352 u32 dccpor_timestamp_echo;
353 u32 dccpor_elapsed_time;
354};
355
356struct ccid;
357
358enum dccp_role {
359 DCCP_ROLE_UNDEFINED,
360 DCCP_ROLE_LISTEN,
361 DCCP_ROLE_CLIENT,
362 DCCP_ROLE_SERVER,
363};
364
365/**
366 * struct dccp_sock - DCCP socket state
367 *
368 * @dccps_swl - sequence number window low
369 * @dccps_swh - sequence number window high
370 * @dccps_awl - acknowledgement number window low
371 * @dccps_awh - acknowledgement number window high
372 * @dccps_iss - initial sequence number sent
373 * @dccps_isr - initial sequence number received
374 * @dccps_osr - first OPEN sequence number received
375 * @dccps_gss - greatest sequence number sent
376 * @dccps_gsr - greatest valid sequence number received
377 * @dccps_gar - greatest valid ack number received on a non-Sync; initialized to %dccps_iss
378 * @dccps_timestamp_time - time of latest TIMESTAMP option
379 * @dccps_timestamp_echo - latest timestamp received on a TIMESTAMP option
380 * @dccps_ext_header_len - network protocol overhead (IP/IPv6 options)
381 * @dccps_pmtu_cookie - Last pmtu seen by socket
382 * @dccps_avg_packet_size - FIXME: has to be set by the app thru some setsockopt or ioctl, CCID3 uses it
383 * @dccps_role - Role of this sock, one of %dccp_role
384 * @dccps_ndp_count - number of Non Data Packets since last data packet
385 * @dccps_hc_rx_ackpkts - receiver half connection acked packets
386 */
387struct dccp_sock {
388 /* inet_connection_sock has to be the first member of dccp_sock */
389 struct inet_connection_sock dccps_inet_connection;
390 __u64 dccps_swl;
391 __u64 dccps_swh;
392 __u64 dccps_awl;
393 __u64 dccps_awh;
394 __u64 dccps_iss;
395 __u64 dccps_isr;
396 __u64 dccps_osr;
397 __u64 dccps_gss;
398 __u64 dccps_gsr;
399 __u64 dccps_gar;
400 unsigned long dccps_service;
401 unsigned long dccps_timestamp_time;
402 __u32 dccps_timestamp_echo;
403 __u32 dccps_avg_packet_size;
404 unsigned long dccps_ndp_count;
405 __u16 dccps_ext_header_len;
406 __u32 dccps_pmtu_cookie;
407 __u32 dccps_mss_cache;
408 struct dccp_options dccps_options;
409 struct dccp_ackpkts *dccps_hc_rx_ackpkts;
410 void *dccps_hc_rx_ccid_private;
411 void *dccps_hc_tx_ccid_private;
412 struct ccid *dccps_hc_rx_ccid;
413 struct ccid *dccps_hc_tx_ccid;
414 struct dccp_options_received dccps_options_received;
415 enum dccp_role dccps_role:2;
416};
417
418static inline struct dccp_sock *dccp_sk(const struct sock *sk)
419{
420 return (struct dccp_sock *)sk;
421}
422
423static inline const char *dccp_role(const struct sock *sk)
424{
425 switch (dccp_sk(sk)->dccps_role) {
426 case DCCP_ROLE_UNDEFINED: return "undefined";
427 case DCCP_ROLE_LISTEN: return "listen";
428 case DCCP_ROLE_SERVER: return "server";
429 case DCCP_ROLE_CLIENT: return "client";
430 }
431 return NULL;
432}
433
Harald Welte5a47a472005-08-09 20:26:03 -0700434#endif /* __KERNEL__ */
435
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700436#endif /* _LINUX_DCCP_H */