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