2 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
4 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
6 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * This implementation should follow RFC 4341
32 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
33 static int ccid2_debug
;
34 #define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
36 static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock
*hctx
)
40 struct ccid2_seq
*seqp
= hctx
->ccid2hctx_seqh
;
42 /* there is data in the chain */
43 if (seqp
!= hctx
->ccid2hctx_seqt
) {
44 seqp
= seqp
->ccid2s_prev
;
46 if (!seqp
->ccid2s_acked
)
49 while (seqp
!= hctx
->ccid2hctx_seqt
) {
50 struct ccid2_seq
*prev
= seqp
->ccid2s_prev
;
53 if (!prev
->ccid2s_acked
)
56 /* packets are sent sequentially */
57 BUG_ON(dccp_delta_seqno(seqp
->ccid2s_seq
,
58 prev
->ccid2s_seq
) >= 0);
59 BUG_ON(time_before(seqp
->ccid2s_sent
,
66 BUG_ON(pipe
!= hctx
->ccid2hctx_pipe
);
67 ccid2_pr_debug("len of chain=%d\n", len
);
70 seqp
= seqp
->ccid2s_prev
;
72 } while (seqp
!= hctx
->ccid2hctx_seqh
);
74 ccid2_pr_debug("total len=%d\n", len
);
75 BUG_ON(len
!= hctx
->ccid2hctx_seqbufc
* CCID2_SEQBUF_LEN
);
78 #define ccid2_pr_debug(format, a...)
79 #define ccid2_hc_tx_check_sanity(hctx)
82 static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock
*hctx
)
84 struct ccid2_seq
*seqp
;
87 /* check if we have space to preserve the pointer to the buffer */
88 if (hctx
->ccid2hctx_seqbufc
>= (sizeof(hctx
->ccid2hctx_seqbuf
) /
89 sizeof(struct ccid2_seq
*)))
92 /* allocate buffer and initialize linked list */
93 seqp
= kmalloc(CCID2_SEQBUF_LEN
* sizeof(struct ccid2_seq
), gfp_any());
97 for (i
= 0; i
< (CCID2_SEQBUF_LEN
- 1); i
++) {
98 seqp
[i
].ccid2s_next
= &seqp
[i
+ 1];
99 seqp
[i
+ 1].ccid2s_prev
= &seqp
[i
];
101 seqp
[CCID2_SEQBUF_LEN
- 1].ccid2s_next
= seqp
;
102 seqp
->ccid2s_prev
= &seqp
[CCID2_SEQBUF_LEN
- 1];
104 /* This is the first allocation. Initiate the head and tail. */
105 if (hctx
->ccid2hctx_seqbufc
== 0)
106 hctx
->ccid2hctx_seqh
= hctx
->ccid2hctx_seqt
= seqp
;
108 /* link the existing list with the one we just created */
109 hctx
->ccid2hctx_seqh
->ccid2s_next
= seqp
;
110 seqp
->ccid2s_prev
= hctx
->ccid2hctx_seqh
;
112 hctx
->ccid2hctx_seqt
->ccid2s_prev
= &seqp
[CCID2_SEQBUF_LEN
- 1];
113 seqp
[CCID2_SEQBUF_LEN
- 1].ccid2s_next
= hctx
->ccid2hctx_seqt
;
116 /* store the original pointer to the buffer so we can free it */
117 hctx
->ccid2hctx_seqbuf
[hctx
->ccid2hctx_seqbufc
] = seqp
;
118 hctx
->ccid2hctx_seqbufc
++;
123 static int ccid2_hc_tx_send_packet(struct sock
*sk
, struct sk_buff
*skb
)
125 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
127 if (hctx
->ccid2hctx_pipe
< hctx
->ccid2hctx_cwnd
)
130 return 1; /* XXX CCID should dequeue when ready instead of polling */
133 static void ccid2_change_l_ack_ratio(struct sock
*sk
, u32 val
)
135 struct dccp_sock
*dp
= dccp_sk(sk
);
136 u32 max_ratio
= DIV_ROUND_UP(ccid2_hc_tx_sk(sk
)->ccid2hctx_cwnd
, 2);
139 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
140 * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
141 * acceptable since this causes starvation/deadlock whenever cwnd < 2.
142 * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
144 if (val
== 0 || val
> max_ratio
) {
145 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val
, max_ratio
);
148 if (val
> DCCPF_ACK_RATIO_MAX
)
149 val
= DCCPF_ACK_RATIO_MAX
;
151 if (val
== dp
->dccps_l_ack_ratio
)
154 ccid2_pr_debug("changing local ack ratio to %u\n", val
);
155 dp
->dccps_l_ack_ratio
= val
;
158 static void ccid2_change_srtt(struct ccid2_hc_tx_sock
*hctx
, long val
)
160 ccid2_pr_debug("change SRTT to %ld\n", val
);
161 hctx
->ccid2hctx_srtt
= val
;
164 static void ccid2_start_rto_timer(struct sock
*sk
);
166 static void ccid2_hc_tx_rto_expire(unsigned long data
)
168 struct sock
*sk
= (struct sock
*)data
;
169 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
173 if (sock_owned_by_user(sk
)) {
174 sk_reset_timer(sk
, &hctx
->ccid2hctx_rtotimer
,
179 ccid2_pr_debug("RTO_EXPIRE\n");
181 ccid2_hc_tx_check_sanity(hctx
);
184 hctx
->ccid2hctx_rto
<<= 1;
186 s
= hctx
->ccid2hctx_rto
/ HZ
;
188 hctx
->ccid2hctx_rto
= 60 * HZ
;
190 ccid2_start_rto_timer(sk
);
192 /* adjust pipe, cwnd etc */
193 hctx
->ccid2hctx_ssthresh
= hctx
->ccid2hctx_cwnd
/ 2;
194 if (hctx
->ccid2hctx_ssthresh
< 2)
195 hctx
->ccid2hctx_ssthresh
= 2;
196 hctx
->ccid2hctx_cwnd
= 1;
197 hctx
->ccid2hctx_pipe
= 0;
199 /* clear state about stuff we sent */
200 hctx
->ccid2hctx_seqt
= hctx
->ccid2hctx_seqh
;
201 hctx
->ccid2hctx_packets_acked
= 0;
203 /* clear ack ratio state. */
204 hctx
->ccid2hctx_rpseq
= 0;
205 hctx
->ccid2hctx_rpdupack
= -1;
206 ccid2_change_l_ack_ratio(sk
, 1);
207 ccid2_hc_tx_check_sanity(hctx
);
213 static void ccid2_start_rto_timer(struct sock
*sk
)
215 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
217 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx
->ccid2hctx_rto
);
219 BUG_ON(timer_pending(&hctx
->ccid2hctx_rtotimer
));
220 sk_reset_timer(sk
, &hctx
->ccid2hctx_rtotimer
,
221 jiffies
+ hctx
->ccid2hctx_rto
);
224 static void ccid2_hc_tx_packet_sent(struct sock
*sk
, int more
, unsigned int len
)
226 struct dccp_sock
*dp
= dccp_sk(sk
);
227 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
228 struct ccid2_seq
*next
;
230 hctx
->ccid2hctx_pipe
++;
232 hctx
->ccid2hctx_seqh
->ccid2s_seq
= dp
->dccps_gss
;
233 hctx
->ccid2hctx_seqh
->ccid2s_acked
= 0;
234 hctx
->ccid2hctx_seqh
->ccid2s_sent
= jiffies
;
236 next
= hctx
->ccid2hctx_seqh
->ccid2s_next
;
237 /* check if we need to alloc more space */
238 if (next
== hctx
->ccid2hctx_seqt
) {
239 if (ccid2_hc_tx_alloc_seq(hctx
)) {
240 DCCP_CRIT("packet history - out of memory!");
241 /* FIXME: find a more graceful way to bail out */
244 next
= hctx
->ccid2hctx_seqh
->ccid2s_next
;
245 BUG_ON(next
== hctx
->ccid2hctx_seqt
);
247 hctx
->ccid2hctx_seqh
= next
;
249 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx
->ccid2hctx_cwnd
,
250 hctx
->ccid2hctx_pipe
);
253 * FIXME: The code below is broken and the variables have been removed
254 * from the socket struct. The `ackloss' variable was always set to 0,
255 * and with arsent there are several problems:
256 * (i) it doesn't just count the number of Acks, but all sent packets;
257 * (ii) it is expressed in # of packets, not # of windows, so the
258 * comparison below uses the wrong formula: Appendix A of RFC 4341
259 * comes up with the number K = cwnd / (R^2 - R) of consecutive windows
260 * of data with no lost or marked Ack packets. If arsent were the # of
261 * consecutive Acks received without loss, then Ack Ratio needs to be
262 * decreased by 1 when
263 * arsent >= K * cwnd / R = cwnd^2 / (R^3 - R^2)
264 * where cwnd / R is the number of Acks received per window of data
265 * (cf. RFC 4341, App. A). The problems are that
266 * - arsent counts other packets as well;
267 * - the comparison uses a formula different from RFC 4341;
268 * - computing a cubic/quadratic equation each time is too complicated.
269 * Hence a different algorithm is needed.
272 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
273 hctx
->ccid2hctx_arsent
++;
274 /* We had an ack loss in this window... */
275 if (hctx
->ccid2hctx_ackloss
) {
276 if (hctx
->ccid2hctx_arsent
>= hctx
->ccid2hctx_cwnd
) {
277 hctx
->ccid2hctx_arsent
= 0;
278 hctx
->ccid2hctx_ackloss
= 0;
281 /* No acks lost up to now... */
282 /* decrease ack ratio if enough packets were sent */
283 if (dp
->dccps_l_ack_ratio
> 1) {
284 /* XXX don't calculate denominator each time */
285 int denom
= dp
->dccps_l_ack_ratio
* dp
->dccps_l_ack_ratio
-
286 dp
->dccps_l_ack_ratio
;
288 denom
= hctx
->ccid2hctx_cwnd
* hctx
->ccid2hctx_cwnd
/ denom
;
290 if (hctx
->ccid2hctx_arsent
>= denom
) {
291 ccid2_change_l_ack_ratio(sk
, dp
->dccps_l_ack_ratio
- 1);
292 hctx
->ccid2hctx_arsent
= 0;
295 /* we can't increase ack ratio further [1] */
296 hctx
->ccid2hctx_arsent
= 0; /* or maybe set it to cwnd*/
301 /* setup RTO timer */
302 if (!timer_pending(&hctx
->ccid2hctx_rtotimer
))
303 ccid2_start_rto_timer(sk
);
305 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
307 struct ccid2_seq
*seqp
= hctx
->ccid2hctx_seqt
;
309 while (seqp
!= hctx
->ccid2hctx_seqh
) {
310 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
311 (unsigned long long)seqp
->ccid2s_seq
,
312 seqp
->ccid2s_acked
, seqp
->ccid2s_sent
);
313 seqp
= seqp
->ccid2s_next
;
316 ccid2_pr_debug("=========\n");
317 ccid2_hc_tx_check_sanity(hctx
);
321 /* XXX Lame code duplication!
322 * returns -1 if none was found.
323 * else returns the next offset to use in the function call.
325 static int ccid2_ackvector(struct sock
*sk
, struct sk_buff
*skb
, int offset
,
326 unsigned char **vec
, unsigned char *veclen
)
328 const struct dccp_hdr
*dh
= dccp_hdr(skb
);
329 unsigned char *options
= (unsigned char *)dh
+ dccp_hdr_len(skb
);
330 unsigned char *opt_ptr
;
331 const unsigned char *opt_end
= (unsigned char *)dh
+
332 (dh
->dccph_doff
* 4);
333 unsigned char opt
, len
;
334 unsigned char *value
;
339 if (opt_ptr
>= opt_end
)
342 while (opt_ptr
!= opt_end
) {
347 /* Check if this isn't a single byte option */
348 if (opt
> DCCPO_MAX_RESERVED
) {
349 if (opt_ptr
== opt_end
)
350 goto out_invalid_option
;
354 goto out_invalid_option
;
356 * Remove the type and len fields, leaving
357 * just the value size
363 if (opt_ptr
> opt_end
)
364 goto out_invalid_option
;
368 case DCCPO_ACK_VECTOR_0
:
369 case DCCPO_ACK_VECTOR_1
:
372 return offset
+ (opt_ptr
- options
);
379 DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
383 static void ccid2_hc_tx_kill_rto_timer(struct sock
*sk
)
385 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
387 sk_stop_timer(sk
, &hctx
->ccid2hctx_rtotimer
);
388 ccid2_pr_debug("deleted RTO timer\n");
391 static inline void ccid2_new_ack(struct sock
*sk
,
392 struct ccid2_seq
*seqp
,
393 unsigned int *maxincr
)
395 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
397 if (hctx
->ccid2hctx_cwnd
< hctx
->ccid2hctx_ssthresh
) {
398 if (*maxincr
> 0 && ++hctx
->ccid2hctx_packets_acked
== 2) {
399 hctx
->ccid2hctx_cwnd
+= 1;
401 hctx
->ccid2hctx_packets_acked
= 0;
403 } else if (++hctx
->ccid2hctx_packets_acked
>= hctx
->ccid2hctx_cwnd
) {
404 hctx
->ccid2hctx_cwnd
+= 1;
405 hctx
->ccid2hctx_packets_acked
= 0;
409 if (hctx
->ccid2hctx_srtt
== -1 ||
410 time_after(jiffies
, hctx
->ccid2hctx_lastrtt
+ hctx
->ccid2hctx_srtt
)) {
411 unsigned long r
= (long)jiffies
- (long)seqp
->ccid2s_sent
;
414 /* first measurement */
415 if (hctx
->ccid2hctx_srtt
== -1) {
416 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
418 (unsigned long long)seqp
->ccid2s_seq
);
419 ccid2_change_srtt(hctx
, r
);
420 hctx
->ccid2hctx_rttvar
= r
>> 1;
423 long tmp
= hctx
->ccid2hctx_srtt
- r
;
430 hctx
->ccid2hctx_rttvar
*= 3;
431 hctx
->ccid2hctx_rttvar
>>= 2;
432 hctx
->ccid2hctx_rttvar
+= tmp
;
435 srtt
= hctx
->ccid2hctx_srtt
;
440 ccid2_change_srtt(hctx
, srtt
);
442 s
= hctx
->ccid2hctx_rttvar
<< 2;
443 /* clock granularity is 1 when based on jiffies */
446 hctx
->ccid2hctx_rto
= hctx
->ccid2hctx_srtt
+ s
;
448 /* must be at least a second */
449 s
= hctx
->ccid2hctx_rto
/ HZ
;
450 /* DCCP doesn't require this [but I like it cuz my code sux] */
453 hctx
->ccid2hctx_rto
= HZ
;
457 hctx
->ccid2hctx_rto
= HZ
* 60;
459 hctx
->ccid2hctx_lastrtt
= jiffies
;
461 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
462 hctx
->ccid2hctx_srtt
, hctx
->ccid2hctx_rttvar
,
463 hctx
->ccid2hctx_rto
, HZ
, r
);
466 /* we got a new ack, so re-start RTO timer */
467 ccid2_hc_tx_kill_rto_timer(sk
);
468 ccid2_start_rto_timer(sk
);
471 static void ccid2_hc_tx_dec_pipe(struct sock
*sk
)
473 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
475 if (hctx
->ccid2hctx_pipe
== 0)
476 DCCP_BUG("pipe == 0");
478 hctx
->ccid2hctx_pipe
--;
480 if (hctx
->ccid2hctx_pipe
== 0)
481 ccid2_hc_tx_kill_rto_timer(sk
);
484 static void ccid2_congestion_event(struct sock
*sk
, struct ccid2_seq
*seqp
)
486 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
488 if (time_before(seqp
->ccid2s_sent
, hctx
->ccid2hctx_last_cong
)) {
489 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
493 hctx
->ccid2hctx_last_cong
= jiffies
;
495 hctx
->ccid2hctx_cwnd
= hctx
->ccid2hctx_cwnd
/ 2 ? : 1U;
496 hctx
->ccid2hctx_ssthresh
= max(hctx
->ccid2hctx_cwnd
, 2U);
498 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
499 if (dccp_sk(sk
)->dccps_l_ack_ratio
> hctx
->ccid2hctx_cwnd
)
500 ccid2_change_l_ack_ratio(sk
, hctx
->ccid2hctx_cwnd
);
503 static void ccid2_hc_tx_packet_recv(struct sock
*sk
, struct sk_buff
*skb
)
505 struct dccp_sock
*dp
= dccp_sk(sk
);
506 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
508 struct ccid2_seq
*seqp
;
509 unsigned char *vector
;
510 unsigned char veclen
;
513 unsigned int maxincr
= 0;
515 ccid2_hc_tx_check_sanity(hctx
);
516 /* check reverse path congestion */
517 seqno
= DCCP_SKB_CB(skb
)->dccpd_seq
;
519 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
520 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
523 /* need to bootstrap */
524 if (hctx
->ccid2hctx_rpdupack
== -1) {
525 hctx
->ccid2hctx_rpdupack
= 0;
526 hctx
->ccid2hctx_rpseq
= seqno
;
528 /* check if packet is consecutive */
529 if (dccp_delta_seqno(hctx
->ccid2hctx_rpseq
, seqno
) == 1)
530 hctx
->ccid2hctx_rpseq
= seqno
;
531 /* it's a later packet */
532 else if (after48(seqno
, hctx
->ccid2hctx_rpseq
)) {
533 hctx
->ccid2hctx_rpdupack
++;
535 /* check if we got enough dupacks */
536 if (hctx
->ccid2hctx_rpdupack
>= NUMDUPACK
) {
537 hctx
->ccid2hctx_rpdupack
= -1; /* XXX lame */
538 hctx
->ccid2hctx_rpseq
= 0;
540 ccid2_change_l_ack_ratio(sk
, 2 * dp
->dccps_l_ack_ratio
);
545 /* check forward path congestion */
546 /* still didn't send out new data packets */
547 if (hctx
->ccid2hctx_seqh
== hctx
->ccid2hctx_seqt
)
550 switch (DCCP_SKB_CB(skb
)->dccpd_type
) {
552 case DCCP_PKT_DATAACK
:
558 ackno
= DCCP_SKB_CB(skb
)->dccpd_ack_seq
;
559 if (after48(ackno
, hctx
->ccid2hctx_high_ack
))
560 hctx
->ccid2hctx_high_ack
= ackno
;
562 seqp
= hctx
->ccid2hctx_seqt
;
563 while (before48(seqp
->ccid2s_seq
, ackno
)) {
564 seqp
= seqp
->ccid2s_next
;
565 if (seqp
== hctx
->ccid2hctx_seqh
) {
566 seqp
= hctx
->ccid2hctx_seqh
->ccid2s_prev
;
572 * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
573 * packets per acknowledgement. Rounding up avoids that cwnd is not
574 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
576 if (hctx
->ccid2hctx_cwnd
< hctx
->ccid2hctx_ssthresh
)
577 maxincr
= DIV_ROUND_UP(dp
->dccps_l_ack_ratio
, 2);
579 /* go through all ack vectors */
580 while ((offset
= ccid2_ackvector(sk
, skb
, offset
,
581 &vector
, &veclen
)) != -1) {
582 /* go through this ack vector */
584 const u8 rl
= *vector
& DCCP_ACKVEC_LEN_MASK
;
585 u64 ackno_end_rl
= SUB48(ackno
, rl
);
587 ccid2_pr_debug("ackvec start:%llu end:%llu\n",
588 (unsigned long long)ackno
,
589 (unsigned long long)ackno_end_rl
);
590 /* if the seqno we are analyzing is larger than the
591 * current ackno, then move towards the tail of our
594 while (after48(seqp
->ccid2s_seq
, ackno
)) {
595 if (seqp
== hctx
->ccid2hctx_seqt
) {
599 seqp
= seqp
->ccid2s_prev
;
604 /* check all seqnos in the range of the vector
607 while (between48(seqp
->ccid2s_seq
,ackno_end_rl
,ackno
)) {
608 const u8 state
= *vector
&
609 DCCP_ACKVEC_STATE_MASK
;
611 /* new packet received or marked */
612 if (state
!= DCCP_ACKVEC_STATE_NOT_RECEIVED
&&
613 !seqp
->ccid2s_acked
) {
615 DCCP_ACKVEC_STATE_ECN_MARKED
) {
616 ccid2_congestion_event(sk
,
619 ccid2_new_ack(sk
, seqp
,
622 seqp
->ccid2s_acked
= 1;
623 ccid2_pr_debug("Got ack for %llu\n",
624 (unsigned long long)seqp
->ccid2s_seq
);
625 ccid2_hc_tx_dec_pipe(sk
);
627 if (seqp
== hctx
->ccid2hctx_seqt
) {
631 seqp
= seqp
->ccid2s_prev
;
636 ackno
= SUB48(ackno_end_rl
, 1);
643 /* The state about what is acked should be correct now
644 * Check for NUMDUPACK
646 seqp
= hctx
->ccid2hctx_seqt
;
647 while (before48(seqp
->ccid2s_seq
, hctx
->ccid2hctx_high_ack
)) {
648 seqp
= seqp
->ccid2s_next
;
649 if (seqp
== hctx
->ccid2hctx_seqh
) {
650 seqp
= hctx
->ccid2hctx_seqh
->ccid2s_prev
;
656 if (seqp
->ccid2s_acked
) {
658 if (done
== NUMDUPACK
)
661 if (seqp
== hctx
->ccid2hctx_seqt
)
663 seqp
= seqp
->ccid2s_prev
;
666 /* If there are at least 3 acknowledgements, anything unacknowledged
667 * below the last sequence number is considered lost
669 if (done
== NUMDUPACK
) {
670 struct ccid2_seq
*last_acked
= seqp
;
672 /* check for lost packets */
674 if (!seqp
->ccid2s_acked
) {
675 ccid2_pr_debug("Packet lost: %llu\n",
676 (unsigned long long)seqp
->ccid2s_seq
);
677 /* XXX need to traverse from tail -> head in
678 * order to detect multiple congestion events in
681 ccid2_congestion_event(sk
, seqp
);
682 ccid2_hc_tx_dec_pipe(sk
);
684 if (seqp
== hctx
->ccid2hctx_seqt
)
686 seqp
= seqp
->ccid2s_prev
;
689 hctx
->ccid2hctx_seqt
= last_acked
;
692 /* trim acked packets in tail */
693 while (hctx
->ccid2hctx_seqt
!= hctx
->ccid2hctx_seqh
) {
694 if (!hctx
->ccid2hctx_seqt
->ccid2s_acked
)
697 hctx
->ccid2hctx_seqt
= hctx
->ccid2hctx_seqt
->ccid2s_next
;
700 ccid2_hc_tx_check_sanity(hctx
);
703 static int ccid2_hc_tx_init(struct ccid
*ccid
, struct sock
*sk
)
705 struct ccid2_hc_tx_sock
*hctx
= ccid_priv(ccid
);
706 struct dccp_sock
*dp
= dccp_sk(sk
);
709 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
710 hctx
->ccid2hctx_ssthresh
= ~0U;
713 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
714 * packets for new connections, following the rules from [RFC3390]".
715 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
717 hctx
->ccid2hctx_cwnd
= clamp(4380U / dp
->dccps_mss_cache
, 2U, 4U);
719 /* Make sure that Ack Ratio is enabled and within bounds. */
720 max_ratio
= DIV_ROUND_UP(hctx
->ccid2hctx_cwnd
, 2);
721 if (dp
->dccps_l_ack_ratio
== 0 || dp
->dccps_l_ack_ratio
> max_ratio
)
722 dp
->dccps_l_ack_ratio
= max_ratio
;
724 /* XXX init ~ to window size... */
725 if (ccid2_hc_tx_alloc_seq(hctx
))
728 hctx
->ccid2hctx_rto
= 3 * HZ
;
729 ccid2_change_srtt(hctx
, -1);
730 hctx
->ccid2hctx_rttvar
= -1;
731 hctx
->ccid2hctx_rpdupack
= -1;
732 hctx
->ccid2hctx_last_cong
= jiffies
;
733 setup_timer(&hctx
->ccid2hctx_rtotimer
, ccid2_hc_tx_rto_expire
,
736 ccid2_hc_tx_check_sanity(hctx
);
740 static void ccid2_hc_tx_exit(struct sock
*sk
)
742 struct ccid2_hc_tx_sock
*hctx
= ccid2_hc_tx_sk(sk
);
745 ccid2_hc_tx_kill_rto_timer(sk
);
747 for (i
= 0; i
< hctx
->ccid2hctx_seqbufc
; i
++)
748 kfree(hctx
->ccid2hctx_seqbuf
[i
]);
749 hctx
->ccid2hctx_seqbufc
= 0;
752 static void ccid2_hc_rx_packet_recv(struct sock
*sk
, struct sk_buff
*skb
)
754 const struct dccp_sock
*dp
= dccp_sk(sk
);
755 struct ccid2_hc_rx_sock
*hcrx
= ccid2_hc_rx_sk(sk
);
757 switch (DCCP_SKB_CB(skb
)->dccpd_type
) {
759 case DCCP_PKT_DATAACK
:
760 hcrx
->ccid2hcrx_data
++;
761 if (hcrx
->ccid2hcrx_data
>= dp
->dccps_r_ack_ratio
) {
763 hcrx
->ccid2hcrx_data
= 0;
769 struct ccid_operations ccid2_ops
= {
770 .ccid_id
= DCCPC_CCID2
,
771 .ccid_name
= "TCP-like",
772 .ccid_hc_tx_obj_size
= sizeof(struct ccid2_hc_tx_sock
),
773 .ccid_hc_tx_init
= ccid2_hc_tx_init
,
774 .ccid_hc_tx_exit
= ccid2_hc_tx_exit
,
775 .ccid_hc_tx_send_packet
= ccid2_hc_tx_send_packet
,
776 .ccid_hc_tx_packet_sent
= ccid2_hc_tx_packet_sent
,
777 .ccid_hc_tx_packet_recv
= ccid2_hc_tx_packet_recv
,
778 .ccid_hc_rx_obj_size
= sizeof(struct ccid2_hc_rx_sock
),
779 .ccid_hc_rx_packet_recv
= ccid2_hc_rx_packet_recv
,
782 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
783 module_param(ccid2_debug
, bool, 0644);
784 MODULE_PARM_DESC(ccid2_debug
, "Enable CCID-2 debug messages");