5 #include <linux/list.h>
6 #include <linux/types.h>
8 #include <linux/workqueue.h>
10 #include <net/inet_connection_sock.h>
12 #include <net/tcp_states.h>
15 /* FIXME: this is utterly wrong */
16 struct sockaddr_dccp {
17 struct sockaddr_in in;
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,
41 #define DCCP_STATE_MASK 0xf
42 #define DCCP_ACTION_FIN (1<<7)
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,
56 * struct dccp_hdr - generic part of DCCP packet header
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
72 #if defined(__LITTLE_ENDIAN_BITFIELD)
75 #elif defined(__BIG_ENDIAN_BITFIELD)
79 #error "Adjust your <asm/byteorder.h> defines"
82 #if defined(__LITTLE_ENDIAN_BITFIELD)
87 #elif defined(__BIG_ENDIAN_BITFIELD)
88 __u32 dccph_reserved:3,
93 #error "Adjust your <asm/byteorder.h> defines"
97 static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
99 return (struct dccp_hdr *)skb->h.raw;
103 * struct dccp_hdr_ext - the low bits of a 48 bit seq packet
105 * @dccph_seq_low - low 24 bits of a 48 bit seq packet
107 struct dccp_hdr_ext {
111 static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
113 return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
116 static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
118 const struct dccp_hdr *dh = dccp_hdr(skb);
119 return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0);
122 static inline __u64 dccp_hdr_seq(const struct sk_buff *skb)
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);
130 #error "Adjust your <asm/byteorder.h> defines"
133 if (dh->dccph_x != 0)
134 seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(skb)->dccph_seq_low);
140 * struct dccp_hdr_request - Conection initiation request header
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
145 struct dccp_hdr_request {
146 __u32 dccph_req_service;
149 static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb)
151 return (struct dccp_hdr_request *)(skb->h.raw + dccp_basic_hdr_len(skb));
155 * struct dccp_hdr_ack_bits - acknowledgment bits common to most packets
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
160 struct dccp_hdr_ack_bits {
161 __u32 dccph_reserved1:8,
162 dccph_ack_nr_high:24;
163 __u32 dccph_ack_nr_low;
166 static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb)
168 return (struct dccp_hdr_ack_bits *)(skb->h.raw + dccp_basic_hdr_len(skb));
171 static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
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);
179 #error "Adjust your <asm/byteorder.h> defines"
184 * struct dccp_hdr_response - Conection initiation response header
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
191 struct dccp_hdr_response {
192 struct dccp_hdr_ack_bits dccph_resp_ack;
193 __u32 dccph_resp_service;
196 static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
198 return (struct dccp_hdr_response *)(skb->h.raw + dccp_basic_hdr_len(skb));
202 * struct dccp_hdr_reset - Unconditionally shut down a connection
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
207 struct dccp_hdr_reset {
208 struct dccp_hdr_ack_bits dccph_reset_ack;
209 __u8 dccph_reset_code,
213 static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb)
215 return (struct dccp_hdr_reset *)(skb->h.raw + dccp_basic_hdr_len(skb));
219 DCCP_PKT_REQUEST = 0,
232 #define DCCP_NR_PKT_TYPES DCCP_PKT_INVALID
234 static inline unsigned int dccp_packet_hdr_len(const __u8 type)
236 if (type == DCCP_PKT_DATA)
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);
252 static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
254 return dccp_basic_hdr_len(skb) +
255 dccp_packet_hdr_len(dccp_hdr(skb)->dccph_type);
258 enum 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,
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,
286 DCCPO_MIN_CCID_SPECIFIC = 128,
287 DCCPO_MAX_CCID_SPECIFIC = 255,
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,
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
309 #define DCCP_NDP_LIMIT 0xFFFFFF
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)
318 struct dccp_options {
319 __u64 dccpo_sequence_window;
321 __u8 dccpo_send_ack_vector;
322 __u8 dccpo_send_ndp_count;
325 extern void __dccp_options_init(struct dccp_options *dccpo);
326 extern void dccp_options_init(struct dccp_options *dccpo);
327 extern int dccp_parse_options(struct sock *sk, struct sk_buff *skb);
329 struct dccp_request_sock {
330 struct inet_request_sock dreq_inet_rsk;
336 static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
338 return (struct dccp_request_sock *)req;
341 /* Read about the ECN nonce to see why it is 253 */
342 #define DCCP_MAX_ACK_VECTOR_LEN 253
344 struct dccp_options_received {
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;
364 * struct dccp_sock - DCCP socket state
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
386 /* inet_connection_sock has to be the first member of dccp_sock */
387 struct inet_connection_sock dccps_inet_connection;
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;
416 static inline struct dccp_sock *dccp_sk(const struct sock *sk)
418 return (struct dccp_sock *)sk;
421 static inline const char *dccp_role(const struct sock *sk)
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";
432 #endif /* _LINUX_DCCP_H */