2 * net/dccp/ccids/ccid2.c
4 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
6 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
8 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * This implementation should follow RFC 4341
29 * - sequence number wrapping
36 static int ccid2_debug;
38 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
39 #define ccid2_pr_debug(format, a...) \
40 do { if (ccid2_debug) \
41 printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \
44 #define ccid2_pr_debug(format, a...)
47 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
48 static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
52 struct ccid2_seq *seqp = hctx->ccid2hctx_seqh;
54 /* there is data in the chain */
55 if (seqp != hctx->ccid2hctx_seqt) {
56 seqp = seqp->ccid2s_prev;
58 if (!seqp->ccid2s_acked)
61 while (seqp != hctx->ccid2hctx_seqt) {
62 struct ccid2_seq *prev = seqp->ccid2s_prev;
65 if (!prev->ccid2s_acked)
68 /* packets are sent sequentially */
69 BUG_ON(seqp->ccid2s_seq <= prev->ccid2s_seq);
70 BUG_ON(time_before(seqp->ccid2s_sent,
77 BUG_ON(pipe != hctx->ccid2hctx_pipe);
78 ccid2_pr_debug("len of chain=%d\n", len);
81 seqp = seqp->ccid2s_prev;
83 } while (seqp != hctx->ccid2hctx_seqh);
85 ccid2_pr_debug("total len=%d\n", len);
86 BUG_ON(len != hctx->ccid2hctx_seqbufc * CCID2_SEQBUF_LEN);
89 #define ccid2_hc_tx_check_sanity(hctx) do {} while (0)
92 static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx, int num,
95 struct ccid2_seq *seqp;
98 /* check if we have space to preserve the pointer to the buffer */
99 if (hctx->ccid2hctx_seqbufc >= (sizeof(hctx->ccid2hctx_seqbuf) /
100 sizeof(struct ccid2_seq*)))
103 /* allocate buffer and initialize linked list */
104 seqp = kmalloc(sizeof(*seqp) * num, gfp);
108 for (i = 0; i < (num - 1); i++) {
109 seqp[i].ccid2s_next = &seqp[i + 1];
110 seqp[i + 1].ccid2s_prev = &seqp[i];
112 seqp[num - 1].ccid2s_next = seqp;
113 seqp->ccid2s_prev = &seqp[num - 1];
115 /* This is the first allocation. Initiate the head and tail. */
116 if (hctx->ccid2hctx_seqbufc == 0)
117 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqt = seqp;
119 /* link the existing list with the one we just created */
120 hctx->ccid2hctx_seqh->ccid2s_next = seqp;
121 seqp->ccid2s_prev = hctx->ccid2hctx_seqh;
123 hctx->ccid2hctx_seqt->ccid2s_prev = &seqp[num - 1];
124 seqp[num - 1].ccid2s_next = hctx->ccid2hctx_seqt;
127 /* store the original pointer to the buffer so we can free it */
128 hctx->ccid2hctx_seqbuf[hctx->ccid2hctx_seqbufc] = seqp;
129 hctx->ccid2hctx_seqbufc++;
134 static int ccid2_hc_tx_send_packet(struct sock *sk,
135 struct sk_buff *skb, int len)
137 struct ccid2_hc_tx_sock *hctx;
139 switch (DCCP_SKB_CB(skb)->dccpd_type) {
140 case 0: /* XXX data packets from userland come through like this */
142 case DCCP_PKT_DATAACK:
144 /* No congestion control on other packets */
149 hctx = ccid2_hc_tx_sk(sk);
151 ccid2_pr_debug("pipe=%d cwnd=%d\n", hctx->ccid2hctx_pipe,
152 hctx->ccid2hctx_cwnd);
154 if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd) {
155 /* OK we can send... make sure previous packet was sent off */
156 if (!hctx->ccid2hctx_sendwait) {
157 hctx->ccid2hctx_sendwait = 1;
162 return 1; /* XXX CCID should dequeue when ready instead of polling */
165 static void ccid2_change_l_ack_ratio(struct sock *sk, int val)
167 struct dccp_sock *dp = dccp_sk(sk);
169 * XXX I don't really agree with val != 2. If cwnd is 1, ack ratio
170 * should be 1... it shouldn't be allowed to become 2.
174 const struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
175 int max = hctx->ccid2hctx_cwnd / 2;
178 if (hctx->ccid2hctx_cwnd & 1)
185 ccid2_pr_debug("changing local ack ratio to %d\n", val);
187 dp->dccps_l_ack_ratio = val;
190 static void ccid2_change_cwnd(struct ccid2_hc_tx_sock *hctx, int val)
195 /* XXX do we need to change ack ratio? */
196 ccid2_pr_debug("change cwnd to %d\n", val);
199 hctx->ccid2hctx_cwnd = val;
202 static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val)
204 ccid2_pr_debug("change SRTT to %ld\n", val);
205 hctx->ccid2hctx_srtt = val;
208 static void ccid2_change_pipe(struct ccid2_hc_tx_sock *hctx, long val)
210 hctx->ccid2hctx_pipe = val;
213 static void ccid2_start_rto_timer(struct sock *sk);
215 static void ccid2_hc_tx_rto_expire(unsigned long data)
217 struct sock *sk = (struct sock *)data;
218 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
222 if (sock_owned_by_user(sk)) {
223 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
228 ccid2_pr_debug("RTO_EXPIRE\n");
230 ccid2_hc_tx_check_sanity(hctx);
233 hctx->ccid2hctx_rto <<= 1;
235 s = hctx->ccid2hctx_rto / HZ;
237 hctx->ccid2hctx_rto = 60 * HZ;
239 ccid2_start_rto_timer(sk);
241 /* adjust pipe, cwnd etc */
242 ccid2_change_pipe(hctx, 0);
243 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd >> 1;
244 if (hctx->ccid2hctx_ssthresh < 2)
245 hctx->ccid2hctx_ssthresh = 2;
246 ccid2_change_cwnd(hctx, 1);
248 /* clear state about stuff we sent */
249 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh;
250 hctx->ccid2hctx_ssacks = 0;
251 hctx->ccid2hctx_acks = 0;
252 hctx->ccid2hctx_sent = 0;
254 /* clear ack ratio state. */
255 hctx->ccid2hctx_arsent = 0;
256 hctx->ccid2hctx_ackloss = 0;
257 hctx->ccid2hctx_rpseq = 0;
258 hctx->ccid2hctx_rpdupack = -1;
259 ccid2_change_l_ack_ratio(sk, 1);
260 ccid2_hc_tx_check_sanity(hctx);
266 static void ccid2_start_rto_timer(struct sock *sk)
268 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
270 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto);
272 BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer));
273 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
274 jiffies + hctx->ccid2hctx_rto);
277 static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, int len)
279 struct dccp_sock *dp = dccp_sk(sk);
280 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
281 struct ccid2_seq *next;
284 ccid2_hc_tx_check_sanity(hctx);
286 BUG_ON(!hctx->ccid2hctx_sendwait);
287 hctx->ccid2hctx_sendwait = 0;
288 ccid2_change_pipe(hctx, hctx->ccid2hctx_pipe + 1);
289 BUG_ON(hctx->ccid2hctx_pipe < 0);
291 /* There is an issue. What if another packet is sent between
292 * packet_send() and packet_sent(). Then the sequence number would be
298 hctx->ccid2hctx_seqh->ccid2s_seq = seq;
299 hctx->ccid2hctx_seqh->ccid2s_acked = 0;
300 hctx->ccid2hctx_seqh->ccid2s_sent = jiffies;
302 next = hctx->ccid2hctx_seqh->ccid2s_next;
303 /* check if we need to alloc more space */
304 if (next == hctx->ccid2hctx_seqt) {
307 ccid2_pr_debug("allocating more space in history\n");
308 rc = ccid2_hc_tx_alloc_seq(hctx, CCID2_SEQBUF_LEN, GFP_KERNEL);
309 BUG_ON(rc); /* XXX what do we do? */
311 next = hctx->ccid2hctx_seqh->ccid2s_next;
312 BUG_ON(next == hctx->ccid2hctx_seqt);
314 hctx->ccid2hctx_seqh = next;
316 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd,
317 hctx->ccid2hctx_pipe);
319 hctx->ccid2hctx_sent++;
321 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
322 hctx->ccid2hctx_arsent++;
323 /* We had an ack loss in this window... */
324 if (hctx->ccid2hctx_ackloss) {
325 if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) {
326 hctx->ccid2hctx_arsent = 0;
327 hctx->ccid2hctx_ackloss = 0;
330 /* No acks lost up to now... */
331 /* decrease ack ratio if enough packets were sent */
332 if (dp->dccps_l_ack_ratio > 1) {
333 /* XXX don't calculate denominator each time */
334 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
335 dp->dccps_l_ack_ratio;
337 denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom;
339 if (hctx->ccid2hctx_arsent >= denom) {
340 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
341 hctx->ccid2hctx_arsent = 0;
344 /* we can't increase ack ratio further [1] */
345 hctx->ccid2hctx_arsent = 0; /* or maybe set it to cwnd*/
349 /* setup RTO timer */
350 if (!timer_pending(&hctx->ccid2hctx_rtotimer))
351 ccid2_start_rto_timer(sk);
353 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
354 ccid2_pr_debug("pipe=%d\n", hctx->ccid2hctx_pipe);
355 ccid2_pr_debug("Sent: seq=%llu\n", seq);
357 struct ccid2_seq *seqp = hctx->ccid2hctx_seqt;
359 while (seqp != hctx->ccid2hctx_seqh) {
360 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
361 seqp->ccid2s_seq, seqp->ccid2s_acked,
363 seqp = seqp->ccid2s_next;
366 ccid2_pr_debug("=========\n");
367 ccid2_hc_tx_check_sanity(hctx);
371 /* XXX Lame code duplication!
372 * returns -1 if none was found.
373 * else returns the next offset to use in the function call.
375 static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
376 unsigned char **vec, unsigned char *veclen)
378 const struct dccp_hdr *dh = dccp_hdr(skb);
379 unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
380 unsigned char *opt_ptr;
381 const unsigned char *opt_end = (unsigned char *)dh +
382 (dh->dccph_doff * 4);
383 unsigned char opt, len;
384 unsigned char *value;
389 if (opt_ptr >= opt_end)
392 while (opt_ptr != opt_end) {
397 /* Check if this isn't a single byte option */
398 if (opt > DCCPO_MAX_RESERVED) {
399 if (opt_ptr == opt_end)
400 goto out_invalid_option;
404 goto out_invalid_option;
406 * Remove the type and len fields, leaving
407 * just the value size
413 if (opt_ptr > opt_end)
414 goto out_invalid_option;
418 case DCCPO_ACK_VECTOR_0:
419 case DCCPO_ACK_VECTOR_1:
422 return offset + (opt_ptr - options);
429 BUG_ON(1); /* should never happen... options were previously parsed ! */
433 static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
435 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
437 sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer);
438 ccid2_pr_debug("deleted RTO timer\n");
441 static inline void ccid2_new_ack(struct sock *sk,
442 struct ccid2_seq *seqp,
443 unsigned int *maxincr)
445 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
448 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) {
449 hctx->ccid2hctx_acks = 0;
451 /* We can increase cwnd at most maxincr [ack_ratio/2] */
453 /* increase every 2 acks */
454 hctx->ccid2hctx_ssacks++;
455 if (hctx->ccid2hctx_ssacks == 2) {
456 ccid2_change_cwnd(hctx, hctx->ccid2hctx_cwnd+1);
457 hctx->ccid2hctx_ssacks = 0;
458 *maxincr = *maxincr - 1;
461 /* increased cwnd enough for this single ack */
462 hctx->ccid2hctx_ssacks = 0;
465 hctx->ccid2hctx_ssacks = 0;
466 hctx->ccid2hctx_acks++;
468 if (hctx->ccid2hctx_acks >= hctx->ccid2hctx_cwnd) {
469 ccid2_change_cwnd(hctx, hctx->ccid2hctx_cwnd + 1);
470 hctx->ccid2hctx_acks = 0;
475 if (hctx->ccid2hctx_srtt == -1 ||
476 time_after(jiffies, hctx->ccid2hctx_lastrtt + hctx->ccid2hctx_srtt)) {
477 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
480 /* first measurement */
481 if (hctx->ccid2hctx_srtt == -1) {
482 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
483 r, jiffies, seqp->ccid2s_seq);
484 ccid2_change_srtt(hctx, r);
485 hctx->ccid2hctx_rttvar = r >> 1;
488 long tmp = hctx->ccid2hctx_srtt - r;
495 hctx->ccid2hctx_rttvar *= 3;
496 hctx->ccid2hctx_rttvar >>= 2;
497 hctx->ccid2hctx_rttvar += tmp;
500 srtt = hctx->ccid2hctx_srtt;
505 ccid2_change_srtt(hctx, srtt);
507 s = hctx->ccid2hctx_rttvar << 2;
508 /* clock granularity is 1 when based on jiffies */
511 hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s;
513 /* must be at least a second */
514 s = hctx->ccid2hctx_rto / HZ;
515 /* DCCP doesn't require this [but I like it cuz my code sux] */
518 hctx->ccid2hctx_rto = HZ;
522 hctx->ccid2hctx_rto = HZ * 60;
524 hctx->ccid2hctx_lastrtt = jiffies;
526 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
527 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar,
528 hctx->ccid2hctx_rto, HZ, r);
529 hctx->ccid2hctx_sent = 0;
532 /* we got a new ack, so re-start RTO timer */
533 ccid2_hc_tx_kill_rto_timer(sk);
534 ccid2_start_rto_timer(sk);
537 static void ccid2_hc_tx_dec_pipe(struct sock *sk)
539 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
541 ccid2_change_pipe(hctx, hctx->ccid2hctx_pipe-1);
542 BUG_ON(hctx->ccid2hctx_pipe < 0);
544 if (hctx->ccid2hctx_pipe == 0)
545 ccid2_hc_tx_kill_rto_timer(sk);
548 static void ccid2_congestion_event(struct ccid2_hc_tx_sock *hctx,
549 struct ccid2_seq *seqp)
551 if (time_before(seqp->ccid2s_sent, hctx->ccid2hctx_last_cong)) {
552 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
556 hctx->ccid2hctx_last_cong = jiffies;
558 ccid2_change_cwnd(hctx, hctx->ccid2hctx_cwnd >> 1);
559 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd;
560 if (hctx->ccid2hctx_ssthresh < 2)
561 hctx->ccid2hctx_ssthresh = 2;
564 static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
566 struct dccp_sock *dp = dccp_sk(sk);
567 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
569 struct ccid2_seq *seqp;
570 unsigned char *vector;
571 unsigned char veclen;
574 unsigned int maxincr = 0;
576 ccid2_hc_tx_check_sanity(hctx);
577 /* check reverse path congestion */
578 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
580 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
581 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
584 /* need to bootstrap */
585 if (hctx->ccid2hctx_rpdupack == -1) {
586 hctx->ccid2hctx_rpdupack = 0;
587 hctx->ccid2hctx_rpseq = seqno;
589 /* check if packet is consecutive */
590 if ((hctx->ccid2hctx_rpseq + 1) == seqno)
591 hctx->ccid2hctx_rpseq++;
592 /* it's a later packet */
593 else if (after48(seqno, hctx->ccid2hctx_rpseq)) {
594 hctx->ccid2hctx_rpdupack++;
596 /* check if we got enough dupacks */
597 if (hctx->ccid2hctx_rpdupack >=
598 hctx->ccid2hctx_numdupack) {
599 hctx->ccid2hctx_rpdupack = -1; /* XXX lame */
600 hctx->ccid2hctx_rpseq = 0;
602 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio << 1);
607 /* check forward path congestion */
608 /* still didn't send out new data packets */
609 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt)
612 switch (DCCP_SKB_CB(skb)->dccpd_type) {
614 case DCCP_PKT_DATAACK:
620 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
621 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
623 /* If in slow-start, cwnd can increase at most Ack Ratio / 2 packets for
624 * this single ack. I round up.
627 maxincr = dp->dccps_l_ack_ratio >> 1;
630 /* go through all ack vectors */
631 while ((offset = ccid2_ackvector(sk, skb, offset,
632 &vector, &veclen)) != -1) {
633 /* go through this ack vector */
635 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
638 dccp_set_seqno(&ackno_end_rl, ackno - rl);
639 ccid2_pr_debug("ackvec start:%llu end:%llu\n", ackno,
641 /* if the seqno we are analyzing is larger than the
642 * current ackno, then move towards the tail of our
645 while (after48(seqp->ccid2s_seq, ackno)) {
646 if (seqp == hctx->ccid2hctx_seqt) {
650 seqp = seqp->ccid2s_prev;
655 /* check all seqnos in the range of the vector
658 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
659 const u8 state = *vector &
660 DCCP_ACKVEC_STATE_MASK;
662 /* new packet received or marked */
663 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
664 !seqp->ccid2s_acked) {
666 DCCP_ACKVEC_STATE_ECN_MARKED) {
667 ccid2_congestion_event(hctx,
670 ccid2_new_ack(sk, seqp,
673 seqp->ccid2s_acked = 1;
674 ccid2_pr_debug("Got ack for %llu\n",
676 ccid2_hc_tx_dec_pipe(sk);
678 if (seqp == hctx->ccid2hctx_seqt) {
682 seqp = seqp->ccid2s_next;
688 dccp_set_seqno(&ackno, ackno_end_rl - 1);
695 /* The state about what is acked should be correct now
696 * Check for NUMDUPACK
698 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
701 if (seqp->ccid2s_acked) {
703 if (done == hctx->ccid2hctx_numdupack)
706 if (seqp == hctx->ccid2hctx_seqt)
708 seqp = seqp->ccid2s_prev;
711 /* If there are at least 3 acknowledgements, anything unacknowledged
712 * below the last sequence number is considered lost
714 if (done == hctx->ccid2hctx_numdupack) {
715 struct ccid2_seq *last_acked = seqp;
717 /* check for lost packets */
719 if (!seqp->ccid2s_acked) {
720 ccid2_pr_debug("Packet lost: %llu\n",
722 /* XXX need to traverse from tail -> head in
723 * order to detect multiple congestion events in
726 ccid2_congestion_event(hctx, seqp);
727 ccid2_hc_tx_dec_pipe(sk);
729 if (seqp == hctx->ccid2hctx_seqt)
731 seqp = seqp->ccid2s_prev;
734 hctx->ccid2hctx_seqt = last_acked;
737 /* trim acked packets in tail */
738 while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) {
739 if (!hctx->ccid2hctx_seqt->ccid2s_acked)
742 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next;
745 ccid2_hc_tx_check_sanity(hctx);
748 static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
750 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid);
752 ccid2_change_cwnd(hctx, 1);
753 /* Initialize ssthresh to infinity. This means that we will exit the
754 * initial slow-start after the first packet loss. This is what we
757 hctx->ccid2hctx_ssthresh = ~0;
758 hctx->ccid2hctx_numdupack = 3;
759 hctx->ccid2hctx_seqbufc = 0;
761 /* XXX init ~ to window size... */
762 if (ccid2_hc_tx_alloc_seq(hctx, CCID2_SEQBUF_LEN, GFP_ATOMIC) != 0)
765 hctx->ccid2hctx_sent = 0;
766 hctx->ccid2hctx_rto = 3 * HZ;
767 ccid2_change_srtt(hctx, -1);
768 hctx->ccid2hctx_rttvar = -1;
769 hctx->ccid2hctx_lastrtt = 0;
770 hctx->ccid2hctx_rpdupack = -1;
771 hctx->ccid2hctx_last_cong = jiffies;
773 hctx->ccid2hctx_rtotimer.function = &ccid2_hc_tx_rto_expire;
774 hctx->ccid2hctx_rtotimer.data = (unsigned long)sk;
775 init_timer(&hctx->ccid2hctx_rtotimer);
777 ccid2_hc_tx_check_sanity(hctx);
781 static void ccid2_hc_tx_exit(struct sock *sk)
783 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
786 ccid2_hc_tx_kill_rto_timer(sk);
788 for (i = 0; i < hctx->ccid2hctx_seqbufc; i++)
789 kfree(hctx->ccid2hctx_seqbuf[i]);
790 hctx->ccid2hctx_seqbufc = 0;
793 static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
795 const struct dccp_sock *dp = dccp_sk(sk);
796 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk);
798 switch (DCCP_SKB_CB(skb)->dccpd_type) {
800 case DCCP_PKT_DATAACK:
801 hcrx->ccid2hcrx_data++;
802 if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) {
804 hcrx->ccid2hcrx_data = 0;
810 static struct ccid_operations ccid2 = {
811 .ccid_id = DCCPC_CCID2,
812 .ccid_name = "ccid2",
813 .ccid_owner = THIS_MODULE,
814 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
815 .ccid_hc_tx_init = ccid2_hc_tx_init,
816 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
817 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
818 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
819 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
820 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
821 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
824 module_param(ccid2_debug, int, 0444);
825 MODULE_PARM_DESC(ccid2_debug, "Enable debug messages");
827 static __init int ccid2_module_init(void)
829 return ccid_register(&ccid2);
831 module_init(ccid2_module_init);
833 static __exit void ccid2_module_exit(void)
835 ccid_unregister(&ccid2);
837 module_exit(ccid2_module_exit);
839 MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>");
840 MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID");
841 MODULE_LICENSE("GPL");
842 MODULE_ALIAS("net-dccp-ccid-2");