4 * An implementation of the DCCP protocol
5 * Copyright (c) 2005 Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
6 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
7 * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 #include <linux/config.h>
15 #include <linux/dccp.h>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/skbuff.h>
24 static void dccp_ackpkts_check_rcv_ackvector(struct dccp_ackpkts
*ap
,
27 const unsigned char len
,
28 const unsigned char *vector
);
30 /* stores the default values for new connection. may be changed with sysctl */
31 static const struct dccp_options dccpo_default_values
= {
32 .dccpo_sequence_window
= DCCPF_INITIAL_SEQUENCE_WINDOW
,
33 .dccpo_ccid
= DCCPF_INITIAL_CCID
,
34 .dccpo_send_ack_vector
= DCCPF_INITIAL_SEND_ACK_VECTOR
,
35 .dccpo_send_ndp_count
= DCCPF_INITIAL_SEND_NDP_COUNT
,
38 void dccp_options_init(struct dccp_options
*dccpo
)
40 memcpy(dccpo
, &dccpo_default_values
, sizeof(*dccpo
));
43 static u32
dccp_decode_value_var(const unsigned char *bf
, const u8 len
)
59 int dccp_parse_options(struct sock
*sk
, struct sk_buff
*skb
)
61 struct dccp_sock
*dp
= dccp_sk(sk
);
62 #ifdef CONFIG_IP_DCCP_DEBUG
63 const char *debug_prefix
= dp
->dccps_role
== DCCP_ROLE_CLIENT
?
64 "CLIENT rx opt: " : "server rx opt: ";
66 const struct dccp_hdr
*dh
= dccp_hdr(skb
);
67 const u8 pkt_type
= DCCP_SKB_CB(skb
)->dccpd_type
;
68 unsigned char *options
= (unsigned char *)dh
+ dccp_hdr_len(skb
);
69 unsigned char *opt_ptr
= options
;
70 const unsigned char *opt_end
= (unsigned char *)dh
+
72 struct dccp_options_received
*opt_recv
= &dp
->dccps_options_received
;
73 unsigned char opt
, len
;
76 memset(opt_recv
, 0, sizeof(*opt_recv
));
78 while (opt_ptr
!= opt_end
) {
83 /* Check if this isn't a single byte option */
84 if (opt
> DCCPO_MAX_RESERVED
) {
85 if (opt_ptr
== opt_end
)
86 goto out_invalid_option
;
90 goto out_invalid_option
;
92 * Remove the type and len fields, leaving
99 if (opt_ptr
> opt_end
)
100 goto out_invalid_option
;
106 case DCCPO_NDP_COUNT
:
108 goto out_invalid_option
;
110 opt_recv
->dccpor_ndp
= dccp_decode_value_var(value
, len
);
111 dccp_pr_debug("%sNDP count=%d\n", debug_prefix
,
112 opt_recv
->dccpor_ndp
);
114 case DCCPO_ACK_VECTOR_0
:
115 if (len
> DCCP_MAX_ACK_VECTOR_LEN
)
116 goto out_invalid_option
;
118 if (pkt_type
== DCCP_PKT_DATA
)
121 opt_recv
->dccpor_ack_vector_len
= len
;
122 opt_recv
->dccpor_ack_vector_idx
= value
- options
;
124 dccp_pr_debug("%sACK vector 0, len=%d, ack_ackno=%llu\n",
127 DCCP_SKB_CB(skb
)->dccpd_ack_seq
);
128 dccp_ackvector_print(DCCP_SKB_CB(skb
)->dccpd_ack_seq
,
130 dccp_ackpkts_check_rcv_ackvector(dp
->dccps_hc_rx_ackpkts
,
132 DCCP_SKB_CB(skb
)->dccpd_ack_seq
,
135 case DCCPO_TIMESTAMP
:
137 goto out_invalid_option
;
139 opt_recv
->dccpor_timestamp
= ntohl(*(u32
*)value
);
141 dp
->dccps_timestamp_echo
= opt_recv
->dccpor_timestamp
;
142 do_gettimeofday(&dp
->dccps_timestamp_time
);
144 dccp_pr_debug("%sTIMESTAMP=%u, ackno=%llu\n",
145 debug_prefix
, opt_recv
->dccpor_timestamp
,
147 DCCP_SKB_CB(skb
)->dccpd_ack_seq
);
149 case DCCPO_TIMESTAMP_ECHO
:
150 if (len
!= 4 && len
!= 6 && len
!= 8)
151 goto out_invalid_option
;
153 opt_recv
->dccpor_timestamp_echo
= ntohl(*(u32
*)value
);
155 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, ackno=%llu, ",
157 opt_recv
->dccpor_timestamp_echo
,
160 DCCP_SKB_CB(skb
)->dccpd_ack_seq
);
164 opt_recv
->dccpor_elapsed_time
=
165 ntohs(*(u16
*)(value
+ 4));
167 opt_recv
->dccpor_elapsed_time
=
168 ntohl(*(u32
*)(value
+ 4));
170 dccp_pr_debug("%sTIMESTAMP_ECHO ELAPSED_TIME=%d\n",
172 opt_recv
->dccpor_elapsed_time
);
175 case DCCPO_ELAPSED_TIME
:
176 if (len
!= 2 && len
!= 4)
177 goto out_invalid_option
;
179 if (pkt_type
== DCCP_PKT_DATA
)
183 opt_recv
->dccpor_elapsed_time
=
184 ntohs(*(u16
*)value
);
186 opt_recv
->dccpor_elapsed_time
=
187 ntohl(*(u32
*)value
);
189 dccp_pr_debug("%sELAPSED_TIME=%d\n", debug_prefix
,
190 opt_recv
->dccpor_elapsed_time
);
193 * From draft-ietf-dccp-spec-11.txt:
195 * Option numbers 128 through 191 are for
196 * options sent from the HC-Sender to the
197 * HC-Receiver; option numbers 192 through 255
198 * are for options sent from the HC-Receiver to
202 const u16 idx
= value
- options
;
204 if (ccid_hc_rx_parse_options(dp
->dccps_hc_rx_ccid
, sk
,
207 goto out_invalid_option
;
211 const u16 idx
= value
- options
;
213 if (ccid_hc_tx_parse_options(dp
->dccps_hc_tx_ccid
, sk
,
216 goto out_invalid_option
;
220 pr_info("DCCP(%p): option %d(len=%d) not "
221 "implemented, ignoring\n",
230 DCCP_INC_STATS_BH(DCCP_MIB_INVALIDOPT
);
231 DCCP_SKB_CB(skb
)->dccpd_reset_code
= DCCP_RESET_CODE_OPTION_ERROR
;
232 pr_info("DCCP(%p): invalid option %d, len=%d\n", sk
, opt
, len
);
236 static void dccp_encode_value_var(const u32 value
, unsigned char *to
,
237 const unsigned int len
)
240 *to
++ = (value
& 0xFF000000) >> 24;
242 *to
++ = (value
& 0xFF0000) >> 16;
244 *to
++ = (value
& 0xFF00) >> 8;
246 *to
++ = (value
& 0xFF);
249 static inline int dccp_ndp_len(const int ndp
)
251 return likely(ndp
<= 0xFF) ? 1 : ndp
<= 0xFFFF ? 2 : 3;
254 void dccp_insert_option(struct sock
*sk
, struct sk_buff
*skb
,
255 const unsigned char option
,
256 const void *value
, const unsigned char len
)
260 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
+ len
+ 2 > DCCP_MAX_OPT_LEN
) {
261 LIMIT_NETDEBUG(KERN_INFO
"DCCP: packet too small to insert "
262 "%d option!\n", option
);
266 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= len
+ 2;
268 to
= skb_push(skb
, len
+ 2);
272 memcpy(to
, value
, len
);
275 EXPORT_SYMBOL_GPL(dccp_insert_option
);
277 static void dccp_insert_option_ndp(struct sock
*sk
, struct sk_buff
*skb
)
279 struct dccp_sock
*dp
= dccp_sk(sk
);
280 int ndp
= dp
->dccps_ndp_count
;
282 if (dccp_non_data_packet(skb
))
283 ++dp
->dccps_ndp_count
;
285 dp
->dccps_ndp_count
= 0;
289 const int ndp_len
= dccp_ndp_len(ndp
);
290 const int len
= ndp_len
+ 2;
292 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
+ len
> DCCP_MAX_OPT_LEN
)
295 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= len
;
297 ptr
= skb_push(skb
, len
);
298 *ptr
++ = DCCPO_NDP_COUNT
;
300 dccp_encode_value_var(ndp
, ptr
, ndp_len
);
304 static inline int dccp_elapsed_time_len(const u32 elapsed_time
)
306 return elapsed_time
== 0 ? 0 : elapsed_time
<= 0xFFFF ? 2 : 4;
309 void dccp_insert_option_elapsed_time(struct sock
*sk
,
313 #ifdef CONFIG_IP_DCCP_DEBUG
314 struct dccp_sock
*dp
= dccp_sk(sk
);
315 const char *debug_prefix
= dp
->dccps_role
== DCCP_ROLE_CLIENT
?
316 "CLIENT TX opt: " : "server TX opt: ";
318 const int elapsed_time_len
= dccp_elapsed_time_len(elapsed_time
);
319 const int len
= 2 + elapsed_time_len
;
322 if (elapsed_time_len
== 0)
325 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
+ len
> DCCP_MAX_OPT_LEN
) {
326 LIMIT_NETDEBUG(KERN_INFO
"DCCP: packet too small to "
327 "insert elapsed time!\n");
331 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= len
;
333 to
= skb_push(skb
, len
);
334 *to
++ = DCCPO_ELAPSED_TIME
;
337 if (elapsed_time_len
== 2) {
338 const u16 var16
= htons((u16
)elapsed_time
);
339 memcpy(to
, &var16
, 2);
341 const u32 var32
= htonl(elapsed_time
);
342 memcpy(to
, &var32
, 4);
345 dccp_pr_debug("%sELAPSED_TIME=%u, len=%d, seqno=%llu\n",
346 debug_prefix
, elapsed_time
,
348 (unsigned long long) DCCP_SKB_CB(skb
)->dccpd_seq
);
351 EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time
);
353 static void dccp_insert_option_ack_vector(struct sock
*sk
, struct sk_buff
*skb
)
355 struct dccp_sock
*dp
= dccp_sk(sk
);
356 #ifdef CONFIG_IP_DCCP_DEBUG
357 const char *debug_prefix
= dp
->dccps_role
== DCCP_ROLE_CLIENT
?
358 "CLIENT TX opt: " : "server TX opt: ";
360 struct dccp_ackpkts
*ap
= dp
->dccps_hc_rx_ackpkts
;
361 int len
= ap
->dccpap_buf_vector_len
+ 2;
362 const u32 elapsed_time
= timeval_now_delta(&ap
->dccpap_time
) / 10;
363 unsigned char *to
, *from
;
365 if (elapsed_time
!= 0)
366 dccp_insert_option_elapsed_time(sk
, skb
, elapsed_time
);
368 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
+ len
> DCCP_MAX_OPT_LEN
) {
369 LIMIT_NETDEBUG(KERN_INFO
"DCCP: packet too small to "
370 "insert ACK Vector!\n");
375 * XXX: now we have just one ack vector sent record, so
376 * we have to wait for it to be cleared.
378 * Of course this is not acceptable, but this is just for
381 if (ap
->dccpap_ack_seqno
!= DCCP_MAX_SEQNO
+ 1)
384 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= len
;
386 to
= skb_push(skb
, len
);
387 *to
++ = DCCPO_ACK_VECTOR_0
;
390 len
= ap
->dccpap_buf_vector_len
;
391 from
= ap
->dccpap_buf
+ ap
->dccpap_buf_head
;
393 /* Check if buf_head wraps */
394 if (ap
->dccpap_buf_head
+ len
> ap
->dccpap_buf_len
) {
395 const unsigned int tailsize
= (ap
->dccpap_buf_len
-
396 ap
->dccpap_buf_head
);
398 memcpy(to
, from
, tailsize
);
401 from
= ap
->dccpap_buf
;
404 memcpy(to
, from
, len
);
406 * From draft-ietf-dccp-spec-11.txt:
408 * For each acknowledgement it sends, the HC-Receiver will add an
409 * acknowledgement record. ack_seqno will equal the HC-Receiver
410 * sequence number it used for the ack packet; ack_ptr will equal
411 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
414 * This implemention uses just one ack record for now.
416 ap
->dccpap_ack_seqno
= DCCP_SKB_CB(skb
)->dccpd_seq
;
417 ap
->dccpap_ack_ptr
= ap
->dccpap_buf_head
;
418 ap
->dccpap_ack_ackno
= ap
->dccpap_buf_ackno
;
419 ap
->dccpap_ack_nonce
= ap
->dccpap_buf_nonce
;
420 ap
->dccpap_ack_vector_len
= ap
->dccpap_buf_vector_len
;
422 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, "
424 debug_prefix
, ap
->dccpap_ack_vector_len
,
425 (unsigned long long) ap
->dccpap_ack_seqno
,
426 (unsigned long long) ap
->dccpap_ack_ackno
);
429 void dccp_insert_option_timestamp(struct sock
*sk
, struct sk_buff
*skb
)
434 do_gettimeofday(&tv
);
435 now
= (tv
.tv_sec
* USEC_PER_SEC
+ tv
.tv_usec
) / 10;
436 /* yes this will overflow but that is the point as we want a
437 * 10 usec 32 bit timer which mean it wraps every 11.9 hours */
440 dccp_insert_option(sk
, skb
, DCCPO_TIMESTAMP
, &now
, sizeof(now
));
443 EXPORT_SYMBOL_GPL(dccp_insert_option_timestamp
);
445 static void dccp_insert_option_timestamp_echo(struct sock
*sk
,
448 struct dccp_sock
*dp
= dccp_sk(sk
);
449 #ifdef CONFIG_IP_DCCP_DEBUG
450 const char *debug_prefix
= dp
->dccps_role
== DCCP_ROLE_CLIENT
?
451 "CLIENT TX opt: " : "server TX opt: ";
454 const u32 elapsed_time
=
455 timeval_now_delta(&dp
->dccps_timestamp_time
) / 10;
456 const int elapsed_time_len
= dccp_elapsed_time_len(elapsed_time
);
457 const int len
= 6 + elapsed_time_len
;
460 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
+ len
> DCCP_MAX_OPT_LEN
) {
461 LIMIT_NETDEBUG(KERN_INFO
"DCCP: packet too small to insert "
462 "timestamp echo!\n");
466 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= len
;
468 to
= skb_push(skb
, len
);
469 *to
++ = DCCPO_TIMESTAMP_ECHO
;
472 tstamp_echo
= htonl(dp
->dccps_timestamp_echo
);
473 memcpy(to
, &tstamp_echo
, 4);
476 if (elapsed_time_len
== 2) {
477 const u16 var16
= htons((u16
)elapsed_time
);
478 memcpy(to
, &var16
, 2);
479 } else if (elapsed_time_len
== 4) {
480 const u32 var32
= htonl(elapsed_time
);
481 memcpy(to
, &var32
, 4);
484 dccp_pr_debug("%sTIMESTAMP_ECHO=%u, len=%d, seqno=%llu\n",
485 debug_prefix
, dp
->dccps_timestamp_echo
,
487 (unsigned long long) DCCP_SKB_CB(skb
)->dccpd_seq
);
489 dp
->dccps_timestamp_echo
= 0;
490 dp
->dccps_timestamp_time
.tv_sec
= 0;
491 dp
->dccps_timestamp_time
.tv_usec
= 0;
494 void dccp_insert_options(struct sock
*sk
, struct sk_buff
*skb
)
496 struct dccp_sock
*dp
= dccp_sk(sk
);
498 DCCP_SKB_CB(skb
)->dccpd_opt_len
= 0;
500 if (dp
->dccps_options
.dccpo_send_ndp_count
)
501 dccp_insert_option_ndp(sk
, skb
);
503 if (!dccp_packet_without_ack(skb
)) {
504 if (dp
->dccps_options
.dccpo_send_ack_vector
&&
505 (dp
->dccps_hc_rx_ackpkts
->dccpap_buf_ackno
!=
507 dccp_insert_option_ack_vector(sk
, skb
);
509 if (dp
->dccps_timestamp_echo
!= 0)
510 dccp_insert_option_timestamp_echo(sk
, skb
);
513 ccid_hc_rx_insert_options(dp
->dccps_hc_rx_ccid
, sk
, skb
);
514 ccid_hc_tx_insert_options(dp
->dccps_hc_tx_ccid
, sk
, skb
);
516 /* XXX: insert other options when appropriate */
518 if (DCCP_SKB_CB(skb
)->dccpd_opt_len
!= 0) {
519 /* The length of all options has to be a multiple of 4 */
520 int padding
= DCCP_SKB_CB(skb
)->dccpd_opt_len
% 4;
523 padding
= 4 - padding
;
524 memset(skb_push(skb
, padding
), 0, padding
);
525 DCCP_SKB_CB(skb
)->dccpd_opt_len
+= padding
;
530 struct dccp_ackpkts
*dccp_ackpkts_alloc(const unsigned int len
,
531 const unsigned int __nocast priority
)
533 struct dccp_ackpkts
*ap
= kmalloc(sizeof(*ap
) + len
, priority
);
536 #ifdef CONFIG_IP_DCCP_DEBUG
537 memset(ap
->dccpap_buf
, 0xFF, len
);
539 ap
->dccpap_buf_len
= len
;
540 ap
->dccpap_buf_head
=
541 ap
->dccpap_buf_tail
=
542 ap
->dccpap_buf_len
- 1;
543 ap
->dccpap_buf_ackno
=
544 ap
->dccpap_ack_ackno
=
545 ap
->dccpap_ack_seqno
= DCCP_MAX_SEQNO
+ 1;
546 ap
->dccpap_buf_nonce
= ap
->dccpap_buf_nonce
= 0;
547 ap
->dccpap_ack_ptr
= 0;
548 ap
->dccpap_time
.tv_sec
= 0;
549 ap
->dccpap_time
.tv_usec
= 0;
550 ap
->dccpap_buf_vector_len
= ap
->dccpap_ack_vector_len
= 0;
556 void dccp_ackpkts_free(struct dccp_ackpkts
*ap
)
559 #ifdef CONFIG_IP_DCCP_DEBUG
560 memset(ap
, 0xFF, sizeof(*ap
) + ap
->dccpap_buf_len
);
566 static inline u8
dccp_ackpkts_state(const struct dccp_ackpkts
*ap
,
567 const unsigned int index
)
569 return ap
->dccpap_buf
[index
] & DCCP_ACKPKTS_STATE_MASK
;
572 static inline u8
dccp_ackpkts_len(const struct dccp_ackpkts
*ap
,
573 const unsigned int index
)
575 return ap
->dccpap_buf
[index
] & DCCP_ACKPKTS_LEN_MASK
;
579 * If several packets are missing, the HC-Receiver may prefer to enter multiple
580 * bytes with run length 0, rather than a single byte with a larger run length;
581 * this simplifies table updates if one of the missing packets arrives.
583 static inline int dccp_ackpkts_set_buf_head_state(struct dccp_ackpkts
*ap
,
584 const unsigned int packets
,
585 const unsigned char state
)
588 signed long new_head
;
590 if (ap
->dccpap_buf_vector_len
+ packets
> ap
->dccpap_buf_len
)
594 new_head
= ap
->dccpap_buf_head
- packets
;
598 memset(ap
->dccpap_buf
, DCCP_ACKPKTS_STATE_NOT_RECEIVED
,
602 new_head
+= ap
->dccpap_buf_len
;
605 ap
->dccpap_buf_head
= new_head
;
608 memset(ap
->dccpap_buf
+ ap
->dccpap_buf_head
+ 1,
609 DCCP_ACKPKTS_STATE_NOT_RECEIVED
, gap
);
611 ap
->dccpap_buf
[ap
->dccpap_buf_head
] = state
;
612 ap
->dccpap_buf_vector_len
+= packets
;
617 * Implements the draft-ietf-dccp-spec-11.txt Appendix A
619 int dccp_ackpkts_add(struct dccp_ackpkts
*ap
, u64 ackno
, u8 state
)
622 * Check at the right places if the buffer is full, if it is, tell the
623 * caller to start dropping packets till the HC-Sender acks our ACK
624 * vectors, when we will free up space in dccpap_buf.
626 * We may well decide to do buffer compression, etc, but for now lets
631 * Of course, the circular buffer may overflow, either when the
632 * HC-Sender is sending data at a very high rate, when the
633 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
634 * or when the HC-Sender is forgetting to acknowledge those acks
635 * (so the HC-Receiver is unable to clean up old state). In this
636 * case, the HC-Receiver should either compress the buffer (by
637 * increasing run lengths when possible), transfer its state to
638 * a larger buffer, or, as a last resort, drop all received
639 * packets, without processing them whatsoever, until its buffer
643 /* See if this is the first ackno being inserted */
644 if (ap
->dccpap_buf_vector_len
== 0) {
645 ap
->dccpap_buf
[ap
->dccpap_buf_head
] = state
;
646 ap
->dccpap_buf_vector_len
= 1;
647 } else if (after48(ackno
, ap
->dccpap_buf_ackno
)) {
648 const u64 delta
= dccp_delta_seqno(ap
->dccpap_buf_ackno
,
652 * Look if the state of this packet is the same as the
653 * previous ackno and if so if we can bump the head len.
656 dccp_ackpkts_state(ap
, ap
->dccpap_buf_head
) == state
&&
657 (dccp_ackpkts_len(ap
, ap
->dccpap_buf_head
) <
658 DCCP_ACKPKTS_LEN_MASK
))
659 ap
->dccpap_buf
[ap
->dccpap_buf_head
]++;
660 else if (dccp_ackpkts_set_buf_head_state(ap
, delta
, state
))
666 * When a packet with Sequence Number S arrives, and
667 * S <= buf_ackno, the HC-Receiver will scan the table
668 * for the byte corresponding to S. (Indexing structures
669 * could reduce the complexity of this scan.)
671 u64 delta
= dccp_delta_seqno(ackno
, ap
->dccpap_buf_ackno
);
672 unsigned int index
= ap
->dccpap_buf_head
;
675 const u8 len
= dccp_ackpkts_len(ap
, index
);
676 const u8 state
= dccp_ackpkts_state(ap
, index
);
678 * valid packets not yet in dccpap_buf have a reserved
679 * entry, with a len equal to 0.
681 if (state
== DCCP_ACKPKTS_STATE_NOT_RECEIVED
&&
682 len
== 0 && delta
== 0) { /* Found our
684 dccp_pr_debug("Found %llu reserved seat!\n",
685 (unsigned long long) ackno
);
686 ap
->dccpap_buf
[index
] = state
;
689 /* len == 0 means one packet */
694 if (++index
== ap
->dccpap_buf_len
)
699 ap
->dccpap_buf_ackno
= ackno
;
700 do_gettimeofday(&ap
->dccpap_time
);
703 dccp_ackpkts_print(ap
);
707 /* Duplicate packet */
708 dccp_pr_debug("Received a dup or already considered lost "
709 "packet: %llu\n", (unsigned long long) ackno
);
713 #ifdef CONFIG_IP_DCCP_DEBUG
714 void dccp_ackvector_print(const u64 ackno
, const unsigned char *vector
,
720 printk("ACK vector len=%d, ackno=%llu |", len
,
721 (unsigned long long) ackno
);
724 const u8 state
= (*vector
& DCCP_ACKPKTS_STATE_MASK
) >> 6;
725 const u8 rl
= (*vector
& DCCP_ACKPKTS_LEN_MASK
);
727 printk("%d,%d|", state
, rl
);
734 void dccp_ackpkts_print(const struct dccp_ackpkts
*ap
)
736 dccp_ackvector_print(ap
->dccpap_buf_ackno
,
737 ap
->dccpap_buf
+ ap
->dccpap_buf_head
,
738 ap
->dccpap_buf_vector_len
);
742 static void dccp_ackpkts_trow_away_ack_record(struct dccp_ackpkts
*ap
)
745 * As we're keeping track of the ack vector size
746 * (dccpap_buf_vector_len) and the sent ack vector size
747 * (dccpap_ack_vector_len) we don't need dccpap_buf_tail at all, but
748 * keep this code here as in the future we'll implement a vector of
749 * ack records, as suggested in draft-ietf-dccp-spec-11.txt
753 ap
->dccpap_buf_tail
= ap
->dccpap_ack_ptr
+ 1;
754 if (ap
->dccpap_buf_tail
>= ap
->dccpap_buf_len
)
755 ap
->dccpap_buf_tail
-= ap
->dccpap_buf_len
;
757 ap
->dccpap_buf_vector_len
-= ap
->dccpap_ack_vector_len
;
760 void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts
*ap
, struct sock
*sk
,
763 /* Check if we actually sent an ACK vector */
764 if (ap
->dccpap_ack_seqno
== DCCP_MAX_SEQNO
+ 1)
767 if (ackno
== ap
->dccpap_ack_seqno
) {
768 #ifdef CONFIG_IP_DCCP_DEBUG
769 struct dccp_sock
*dp
= dccp_sk(sk
);
770 const char *debug_prefix
= dp
->dccps_role
== DCCP_ROLE_CLIENT
?
771 "CLIENT rx ack: " : "server rx ack: ";
773 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, "
774 "ack_ackno=%llu, ACKED!\n",
776 (unsigned long long) ap
->dccpap_ack_seqno
,
777 (unsigned long long) ap
->dccpap_ack_ackno
);
778 dccp_ackpkts_trow_away_ack_record(ap
);
779 ap
->dccpap_ack_seqno
= DCCP_MAX_SEQNO
+ 1;
783 static void dccp_ackpkts_check_rcv_ackvector(struct dccp_ackpkts
*ap
,
784 struct sock
*sk
, u64 ackno
,
785 const unsigned char len
,
786 const unsigned char *vector
)
790 /* Check if we actually sent an ACK vector */
791 if (ap
->dccpap_ack_seqno
== DCCP_MAX_SEQNO
+ 1)
794 * We're in the receiver half connection, so if the received an ACK
795 * vector ackno (e.g. 50) before dccpap_ack_seqno (e.g. 52), we're
798 * Extra explanation with example:
800 * if we received an ACK vector with ackno 50, it can only be acking
801 * 50, 49, 48, etc, not 52 (the seqno for the ACK vector we sent).
803 /* dccp_pr_debug("is %llu < %llu? ", ackno, ap->dccpap_ack_seqno); */
804 if (before48(ackno
, ap
->dccpap_ack_seqno
)) {
805 /* dccp_pr_debug_cat("yes\n"); */
808 /* dccp_pr_debug_cat("no\n"); */
812 const u8 rl
= (*vector
& DCCP_ACKPKTS_LEN_MASK
);
815 dccp_set_seqno(&ackno_end_rl
, ackno
- rl
);
818 * dccp_pr_debug("is %llu <= %llu <= %llu? ", ackno_end_rl,
819 * ap->dccpap_ack_seqno, ackno);
821 if (between48(ap
->dccpap_ack_seqno
, ackno_end_rl
, ackno
)) {
822 const u8 state
= (*vector
&
823 DCCP_ACKPKTS_STATE_MASK
) >> 6;
824 /* dccp_pr_debug_cat("yes\n"); */
826 if (state
!= DCCP_ACKPKTS_STATE_NOT_RECEIVED
) {
827 #ifdef CONFIG_IP_DCCP_DEBUG
828 struct dccp_sock
*dp
= dccp_sk(sk
);
829 const char *debug_prefix
=
830 dp
->dccps_role
== DCCP_ROLE_CLIENT
?
831 "CLIENT rx ack: " : "server rx ack: ";
833 dccp_pr_debug("%sACK vector 0, len=%d, "
834 "ack_seqno=%llu, ack_ackno=%llu, "
838 ap
->dccpap_ack_seqno
,
840 ap
->dccpap_ack_ackno
);
841 dccp_ackpkts_trow_away_ack_record(ap
);
844 * If dccpap_ack_seqno was not received, no problem
845 * we'll send another ACK vector.
847 ap
->dccpap_ack_seqno
= DCCP_MAX_SEQNO
+ 1;
850 /* dccp_pr_debug_cat("no\n"); */
852 dccp_set_seqno(&ackno
, ackno_end_rl
- 1);