blob: c7d83e3c1648ceaf63d49d9867f554cbda042fa7 [file] [log] [blame]
Andrea Bittau2a91aa32006-03-20 17:41:47 -08001/*
2 * net/dccp/ccids/ccid2.c
3 *
4 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
5 *
6 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
7 *
8 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
9 *
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.
14 *
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.
19 *
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.
23 */
24
25/*
Gerrit Renker0e64e942006-10-24 16:17:51 -070026 * This implementation should follow RFC 4341
Andrea Bittau2a91aa32006-03-20 17:41:47 -080027 */
Gerrit Renker86349c82008-09-04 07:30:19 +020028#include "../feat.h"
Andrea Bittau2a91aa32006-03-20 17:41:47 -080029#include "../ccid.h"
30#include "../dccp.h"
31#include "ccid2.h"
32
Gerrit Renker84116712006-11-20 18:26:03 -020033
34#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Andrea Bittau2a91aa32006-03-20 17:41:47 -080035static int ccid2_debug;
Gerrit Renker84116712006-11-20 18:26:03 -020036#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
Andrea Bittau2a91aa32006-03-20 17:41:47 -080037
Andrea Bittau2a91aa32006-03-20 17:41:47 -080038static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
39{
40 int len = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -080041 int pipe = 0;
Gerrit Renker1fb87502008-09-04 07:30:19 +020042 struct ccid2_seq *seqp = hctx->seqh;
Andrea Bittau2a91aa32006-03-20 17:41:47 -080043
44 /* there is data in the chain */
Gerrit Renker1fb87502008-09-04 07:30:19 +020045 if (seqp != hctx->seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -080046 seqp = seqp->ccid2s_prev;
47 len++;
48 if (!seqp->ccid2s_acked)
49 pipe++;
50
Gerrit Renker1fb87502008-09-04 07:30:19 +020051 while (seqp != hctx->seqt) {
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -080052 struct ccid2_seq *prev = seqp->ccid2s_prev;
Andrea Bittau2a91aa32006-03-20 17:41:47 -080053
Andrea Bittau2a91aa32006-03-20 17:41:47 -080054 len++;
55 if (!prev->ccid2s_acked)
56 pipe++;
57
58 /* packets are sent sequentially */
Gerrit Renker5e285992007-10-04 14:43:09 -070059 BUG_ON(dccp_delta_seqno(seqp->ccid2s_seq,
60 prev->ccid2s_seq ) >= 0);
Andrea Bittau29651cd2006-09-19 13:06:46 -070061 BUG_ON(time_before(seqp->ccid2s_sent,
62 prev->ccid2s_sent));
Andrea Bittau2a91aa32006-03-20 17:41:47 -080063
64 seqp = prev;
65 }
66 }
67
Gerrit Renker1fb87502008-09-04 07:30:19 +020068 BUG_ON(pipe != hctx->pipe);
Andrea Bittau2a91aa32006-03-20 17:41:47 -080069 ccid2_pr_debug("len of chain=%d\n", len);
70
71 do {
72 seqp = seqp->ccid2s_prev;
73 len++;
Gerrit Renker1fb87502008-09-04 07:30:19 +020074 } while (seqp != hctx->seqh);
Andrea Bittau2a91aa32006-03-20 17:41:47 -080075
Andrea Bittau2a91aa32006-03-20 17:41:47 -080076 ccid2_pr_debug("total len=%d\n", len);
Gerrit Renker1fb87502008-09-04 07:30:19 +020077 BUG_ON(len != hctx->seqbufc * CCID2_SEQBUF_LEN);
Andrea Bittau2a91aa32006-03-20 17:41:47 -080078}
79#else
Gerrit Renker84116712006-11-20 18:26:03 -020080#define ccid2_pr_debug(format, a...)
81#define ccid2_hc_tx_check_sanity(hctx)
Andrea Bittau2a91aa32006-03-20 17:41:47 -080082#endif
83
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070084static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx)
Andrea Bittau07978aa2006-09-19 13:13:37 -070085{
86 struct ccid2_seq *seqp;
87 int i;
88
89 /* check if we have space to preserve the pointer to the buffer */
Gerrit Renker1fb87502008-09-04 07:30:19 +020090 if (hctx->seqbufc >= sizeof(hctx->seqbuf) / sizeof(struct ccid2_seq *))
Andrea Bittau07978aa2006-09-19 13:13:37 -070091 return -ENOMEM;
92
93 /* allocate buffer and initialize linked list */
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070094 seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any());
Andrea Bittau07978aa2006-09-19 13:13:37 -070095 if (seqp == NULL)
96 return -ENOMEM;
97
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070098 for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) {
Andrea Bittau07978aa2006-09-19 13:13:37 -070099 seqp[i].ccid2s_next = &seqp[i + 1];
100 seqp[i + 1].ccid2s_prev = &seqp[i];
101 }
Gerrit Renkercd1f7d32007-10-04 14:41:00 -0700102 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp;
103 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
Andrea Bittau07978aa2006-09-19 13:13:37 -0700104
105 /* This is the first allocation. Initiate the head and tail. */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200106 if (hctx->seqbufc == 0)
107 hctx->seqh = hctx->seqt = seqp;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700108 else {
109 /* link the existing list with the one we just created */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200110 hctx->seqh->ccid2s_next = seqp;
111 seqp->ccid2s_prev = hctx->seqh;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700112
Gerrit Renker1fb87502008-09-04 07:30:19 +0200113 hctx->seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
114 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->seqt;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700115 }
116
117 /* store the original pointer to the buffer so we can free it */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200118 hctx->seqbuf[hctx->seqbufc] = seqp;
119 hctx->seqbufc++;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700120
121 return 0;
122}
123
Gerrit Renker6b57c932006-11-28 19:55:06 -0200124static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800125{
Gerrit Renker83337da2008-09-04 07:30:19 +0200126 if (ccid2_cwnd_network_limited(ccid2_hc_tx_sk(sk)))
127 return CCID_PACKET_WILL_DEQUEUE_LATER;
128 return CCID_PACKET_SEND_AT_ONCE;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800129}
130
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200131static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800132{
133 struct dccp_sock *dp = dccp_sk(sk);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200134 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->cwnd, 2);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200135
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800136 /*
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200137 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
138 * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
139 * acceptable since this causes starvation/deadlock whenever cwnd < 2.
140 * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800141 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200142 if (val == 0 || val > max_ratio) {
143 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
144 val = max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800145 }
Gerrit Renker86349c82008-09-04 07:30:19 +0200146 if (val > DCCPF_ACK_RATIO_MAX)
147 val = DCCPF_ACK_RATIO_MAX;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800148
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200149 if (val == dp->dccps_l_ack_ratio)
150 return;
151
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200152 ccid2_pr_debug("changing local ack ratio to %u\n", val);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800153 dp->dccps_l_ack_ratio = val;
154}
155
Andrea Bittau593f16a2006-09-19 13:15:33 -0700156static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val)
157{
158 ccid2_pr_debug("change SRTT to %ld\n", val);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200159 hctx->srtt = val;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700160}
161
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800162static void ccid2_start_rto_timer(struct sock *sk);
163
164static void ccid2_hc_tx_rto_expire(unsigned long data)
165{
166 struct sock *sk = (struct sock *)data;
167 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Gerrit Renker83337da2008-09-04 07:30:19 +0200168 const bool sender_was_blocked = ccid2_cwnd_network_limited(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800169 long s;
170
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800171 bh_lock_sock(sk);
172 if (sock_owned_by_user(sk)) {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200173 sk_reset_timer(sk, &hctx->rtotimer, jiffies + HZ / 5);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800174 goto out;
175 }
176
177 ccid2_pr_debug("RTO_EXPIRE\n");
178
179 ccid2_hc_tx_check_sanity(hctx);
180
181 /* back-off timer */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200182 hctx->rto <<= 1;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800183
Gerrit Renker1fb87502008-09-04 07:30:19 +0200184 s = hctx->rto / HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800185 if (s > 60)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200186 hctx->rto = 60 * HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800187
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800188 /* adjust pipe, cwnd etc */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200189 hctx->ssthresh = hctx->cwnd / 2;
190 if (hctx->ssthresh < 2)
191 hctx->ssthresh = 2;
192 hctx->cwnd = 1;
193 hctx->pipe = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800194
195 /* clear state about stuff we sent */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200196 hctx->seqt = hctx->seqh;
197 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800198
199 /* clear ack ratio state. */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200200 hctx->rpseq = 0;
201 hctx->rpdupack = -1;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800202 ccid2_change_l_ack_ratio(sk, 1);
203 ccid2_hc_tx_check_sanity(hctx);
Gerrit Renker83337da2008-09-04 07:30:19 +0200204
205 /* if we were blocked before, we may now send cwnd=1 packet */
206 if (sender_was_blocked)
207 tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet);
208 ccid2_start_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800209out:
210 bh_unlock_sock(sk);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800211 sock_put(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800212}
213
214static void ccid2_start_rto_timer(struct sock *sk)
215{
216 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
217
Gerrit Renker1fb87502008-09-04 07:30:19 +0200218 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->rto);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800219
Gerrit Renker1fb87502008-09-04 07:30:19 +0200220 BUG_ON(timer_pending(&hctx->rtotimer));
221 sk_reset_timer(sk, &hctx->rtotimer,
222 jiffies + hctx->rto);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800223}
224
Gerrit Renkerc506d912008-09-04 07:30:19 +0200225static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800226{
227 struct dccp_sock *dp = dccp_sk(sk);
228 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700229 struct ccid2_seq *next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800230
Gerrit Renker1fb87502008-09-04 07:30:19 +0200231 hctx->pipe++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800232
Gerrit Renker1fb87502008-09-04 07:30:19 +0200233 hctx->seqh->ccid2s_seq = dp->dccps_gss;
234 hctx->seqh->ccid2s_acked = 0;
235 hctx->seqh->ccid2s_sent = jiffies;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700236
Gerrit Renker1fb87502008-09-04 07:30:19 +0200237 next = hctx->seqh->ccid2s_next;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700238 /* check if we need to alloc more space */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200239 if (next == hctx->seqt) {
Gerrit Renker7d9e8932007-10-04 14:41:26 -0700240 if (ccid2_hc_tx_alloc_seq(hctx)) {
241 DCCP_CRIT("packet history - out of memory!");
242 /* FIXME: find a more graceful way to bail out */
243 return;
244 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200245 next = hctx->seqh->ccid2s_next;
246 BUG_ON(next == hctx->seqt);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700247 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200248 hctx->seqh = next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800249
Gerrit Renker1fb87502008-09-04 07:30:19 +0200250 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->cwnd, hctx->pipe);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800251
Gerrit Renker900bfed2007-11-24 21:58:33 -0200252 /*
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.
270 */
271#if 0
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800272 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200273 hctx->arsent++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800274 /* We had an ack loss in this window... */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200275 if (hctx->ackloss) {
276 if (hctx->arsent >= hctx->cwnd) {
277 hctx->arsent = 0;
278 hctx->ackloss = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800279 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800280 } else {
281 /* No acks lost up to now... */
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800282 /* decrease ack ratio if enough packets were sent */
283 if (dp->dccps_l_ack_ratio > 1) {
284 /* XXX don't calculate denominator each time */
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800285 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
286 dp->dccps_l_ack_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800287
Gerrit Renker1fb87502008-09-04 07:30:19 +0200288 denom = hctx->cwnd * hctx->cwnd / denom;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800289
Gerrit Renker1fb87502008-09-04 07:30:19 +0200290 if (hctx->arsent >= denom) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800291 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200292 hctx->arsent = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800293 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800294 } else {
295 /* we can't increase ack ratio further [1] */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200296 hctx->arsent = 0; /* or maybe set it to cwnd*/
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800297 }
298 }
Gerrit Renker900bfed2007-11-24 21:58:33 -0200299#endif
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800300
301 /* setup RTO timer */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200302 if (!timer_pending(&hctx->rtotimer))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800303 ccid2_start_rto_timer(sk);
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800304
Andrea Bittau8d424f62006-09-19 13:12:44 -0700305#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800306 do {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200307 struct ccid2_seq *seqp = hctx->seqt;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800308
Gerrit Renker1fb87502008-09-04 07:30:19 +0200309 while (seqp != hctx->seqh) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800310 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200311 (unsigned long long)seqp->ccid2s_seq,
Randy Dunlap234af482006-10-29 16:03:30 -0800312 seqp->ccid2s_acked, seqp->ccid2s_sent);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800313 seqp = seqp->ccid2s_next;
314 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800315 } while (0);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800316 ccid2_pr_debug("=========\n");
317 ccid2_hc_tx_check_sanity(hctx);
318#endif
319}
320
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800321static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800322{
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800323 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
324
Gerrit Renker1fb87502008-09-04 07:30:19 +0200325 sk_stop_timer(sk, &hctx->rtotimer);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800326 ccid2_pr_debug("deleted RTO timer\n");
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800327}
328
329static inline void ccid2_new_ack(struct sock *sk,
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900330 struct ccid2_seq *seqp,
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800331 unsigned int *maxincr)
332{
333 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
334
Gerrit Renker1fb87502008-09-04 07:30:19 +0200335 if (hctx->cwnd < hctx->ssthresh) {
336 if (*maxincr > 0 && ++hctx->packets_acked == 2) {
337 hctx->cwnd += 1;
338 *maxincr -= 1;
339 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800340 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200341 } else if (++hctx->packets_acked >= hctx->cwnd) {
342 hctx->cwnd += 1;
343 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800344 }
345
346 /* update RTO */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200347 if (hctx->srtt == -1 ||
348 time_after(jiffies, hctx->lastrtt + hctx->srtt)) {
Andrea Bittau29651cd2006-09-19 13:06:46 -0700349 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800350 int s;
351
352 /* first measurement */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200353 if (hctx->srtt == -1) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800354 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200355 r, jiffies,
Randy Dunlap234af482006-10-29 16:03:30 -0800356 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau593f16a2006-09-19 13:15:33 -0700357 ccid2_change_srtt(hctx, r);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200358 hctx->rttvar = r >> 1;
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800359 } else {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800360 /* RTTVAR */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200361 long tmp = hctx->srtt - r;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700362 long srtt;
363
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800364 if (tmp < 0)
365 tmp *= -1;
366
367 tmp >>= 2;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200368 hctx->rttvar *= 3;
369 hctx->rttvar >>= 2;
370 hctx->rttvar += tmp;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800371
372 /* SRTT */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200373 srtt = hctx->srtt;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700374 srtt *= 7;
375 srtt >>= 3;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800376 tmp = r >> 3;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700377 srtt += tmp;
378 ccid2_change_srtt(hctx, srtt);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800379 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200380 s = hctx->rttvar << 2;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800381 /* clock granularity is 1 when based on jiffies */
382 if (!s)
383 s = 1;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200384 hctx->rto = hctx->srtt + s;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800385
386 /* must be at least a second */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200387 s = hctx->rto / HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800388 /* DCCP doesn't require this [but I like it cuz my code sux] */
389#if 1
390 if (s < 1)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200391 hctx->rto = HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800392#endif
393 /* max 60 seconds */
394 if (s > 60)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200395 hctx->rto = HZ * 60;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800396
Gerrit Renker1fb87502008-09-04 07:30:19 +0200397 hctx->lastrtt = jiffies;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800398
399 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
Gerrit Renker1fb87502008-09-04 07:30:19 +0200400 hctx->srtt, hctx->rttvar,
401 hctx->rto, HZ, r);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800402 }
403
404 /* we got a new ack, so re-start RTO timer */
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800405 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800406 ccid2_start_rto_timer(sk);
407}
408
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800409static void ccid2_hc_tx_dec_pipe(struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800410{
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800411 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
412
Gerrit Renker1fb87502008-09-04 07:30:19 +0200413 if (hctx->pipe == 0)
Gerrit Renker95b21d72007-11-24 22:06:52 -0200414 DCCP_BUG("pipe == 0");
415 else
Gerrit Renker1fb87502008-09-04 07:30:19 +0200416 hctx->pipe--;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800417
Gerrit Renker1fb87502008-09-04 07:30:19 +0200418 if (hctx->pipe == 0)
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800419 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800420}
421
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200422static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
Andrea Bittau374bcf32006-09-19 13:14:43 -0700423{
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200424 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
425
Gerrit Renker1fb87502008-09-04 07:30:19 +0200426 if (time_before(seqp->ccid2s_sent, hctx->last_cong)) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700427 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
428 return;
429 }
430
Gerrit Renker1fb87502008-09-04 07:30:19 +0200431 hctx->last_cong = jiffies;
Andrea Bittau374bcf32006-09-19 13:14:43 -0700432
Gerrit Renker1fb87502008-09-04 07:30:19 +0200433 hctx->cwnd = hctx->cwnd / 2 ? : 1U;
434 hctx->ssthresh = max(hctx->cwnd, 2U);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200435
436 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200437 if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->cwnd)
438 ccid2_change_l_ack_ratio(sk, hctx->cwnd);
Andrea Bittau374bcf32006-09-19 13:14:43 -0700439}
440
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200441static int ccid2_hc_tx_parse_options(struct sock *sk, u8 packet_type,
442 u8 option, u8 *optval, u8 optlen)
443{
444 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
445
446 switch (option) {
447 case DCCPO_ACK_VECTOR_0:
448 case DCCPO_ACK_VECTOR_1:
449 return dccp_ackvec_parsed_add(&hctx->av_chunks, optval, optlen,
450 option - DCCPO_ACK_VECTOR_0);
451 }
452 return 0;
453}
454
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800455static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
456{
457 struct dccp_sock *dp = dccp_sk(sk);
458 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Gerrit Renker83337da2008-09-04 07:30:19 +0200459 const bool sender_was_blocked = ccid2_cwnd_network_limited(hctx);
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200460 struct dccp_ackvec_parsed *avp;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800461 u64 ackno, seqno;
462 struct ccid2_seq *seqp;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800463 int done = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800464 unsigned int maxincr = 0;
465
466 ccid2_hc_tx_check_sanity(hctx);
467 /* check reverse path congestion */
468 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
469
470 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
471 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
472 * -sorbo.
473 */
474 /* need to bootstrap */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200475 if (hctx->rpdupack == -1) {
476 hctx->rpdupack = 0;
477 hctx->rpseq = seqno;
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800478 } else {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800479 /* check if packet is consecutive */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200480 if (dccp_delta_seqno(hctx->rpseq, seqno) == 1)
481 hctx->rpseq = seqno;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800482 /* it's a later packet */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200483 else if (after48(seqno, hctx->rpseq)) {
484 hctx->rpdupack++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800485
486 /* check if we got enough dupacks */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200487 if (hctx->rpdupack >= NUMDUPACK) {
488 hctx->rpdupack = -1; /* XXX lame */
489 hctx->rpseq = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800490
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200491 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800492 }
493 }
494 }
495
496 /* check forward path congestion */
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200497 if (dccp_packet_without_ack(skb))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800498 return;
499
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200500 /* still didn't send out new data packets */
501 if (hctx->seqh == hctx->seqt)
502 goto done;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800503
504 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200505 if (after48(ackno, hctx->high_ack))
506 hctx->high_ack = ackno;
Andrea Bittau32aac182006-11-16 14:28:40 -0200507
Gerrit Renker1fb87502008-09-04 07:30:19 +0200508 seqp = hctx->seqt;
Andrea Bittau32aac182006-11-16 14:28:40 -0200509 while (before48(seqp->ccid2s_seq, ackno)) {
510 seqp = seqp->ccid2s_next;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200511 if (seqp == hctx->seqh) {
512 seqp = hctx->seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200513 break;
514 }
515 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800516
Gerrit Renkera3020022007-11-24 22:10:29 -0200517 /*
518 * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
519 * packets per acknowledgement. Rounding up avoids that cwnd is not
520 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800521 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200522 if (hctx->cwnd < hctx->ssthresh)
Gerrit Renkera3020022007-11-24 22:10:29 -0200523 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800524
525 /* go through all ack vectors */
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200526 list_for_each_entry(avp, &hctx->av_chunks, node) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800527 /* go through this ack vector */
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200528 for (; avp->len--; avp->vec++) {
529 u64 ackno_end_rl = SUB48(ackno,
530 dccp_ackvec_runlen(avp->vec));
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800531
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200532 ccid2_pr_debug("ackvec %llu |%u,%u|\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800533 (unsigned long long)ackno,
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200534 dccp_ackvec_state(avp->vec) >> 6,
535 dccp_ackvec_runlen(avp->vec));
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800536 /* if the seqno we are analyzing is larger than the
537 * current ackno, then move towards the tail of our
538 * seqnos.
539 */
540 while (after48(seqp->ccid2s_seq, ackno)) {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200541 if (seqp == hctx->seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800542 done = 1;
543 break;
544 }
545 seqp = seqp->ccid2s_prev;
546 }
547 if (done)
548 break;
549
550 /* check all seqnos in the range of the vector
551 * run length
552 */
553 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200554 const u8 state = dccp_ackvec_state(avp->vec);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800555
556 /* new packet received or marked */
Gerrit Renkerff49e272008-09-04 07:30:19 +0200557 if (state != DCCPAV_NOT_RECEIVED &&
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800558 !seqp->ccid2s_acked) {
Gerrit Renkerff49e272008-09-04 07:30:19 +0200559 if (state == DCCPAV_ECN_MARKED)
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200560 ccid2_congestion_event(sk,
Andrea Bittau374bcf32006-09-19 13:14:43 -0700561 seqp);
Gerrit Renkerff49e272008-09-04 07:30:19 +0200562 else
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800563 ccid2_new_ack(sk, seqp,
564 &maxincr);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800565
566 seqp->ccid2s_acked = 1;
567 ccid2_pr_debug("Got ack for %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800568 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800569 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800570 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200571 if (seqp == hctx->seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800572 done = 1;
573 break;
574 }
Gerrit Renker3de54892007-11-24 20:37:48 -0200575 seqp = seqp->ccid2s_prev;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800576 }
577 if (done)
578 break;
579
Gerrit Renkercfbbeab2007-11-24 20:43:59 -0200580 ackno = SUB48(ackno_end_rl, 1);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800581 }
582 if (done)
583 break;
584 }
585
586 /* The state about what is acked should be correct now
587 * Check for NUMDUPACK
588 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200589 seqp = hctx->seqt;
590 while (before48(seqp->ccid2s_seq, hctx->high_ack)) {
Andrea Bittau32aac182006-11-16 14:28:40 -0200591 seqp = seqp->ccid2s_next;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200592 if (seqp == hctx->seqh) {
593 seqp = hctx->seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200594 break;
595 }
596 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800597 done = 0;
598 while (1) {
599 if (seqp->ccid2s_acked) {
600 done++;
Gerrit Renker63df18a2007-11-24 22:04:35 -0200601 if (done == NUMDUPACK)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800602 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800603 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200604 if (seqp == hctx->seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800605 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800606 seqp = seqp->ccid2s_prev;
607 }
608
609 /* If there are at least 3 acknowledgements, anything unacknowledged
610 * below the last sequence number is considered lost
611 */
Gerrit Renker63df18a2007-11-24 22:04:35 -0200612 if (done == NUMDUPACK) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800613 struct ccid2_seq *last_acked = seqp;
614
615 /* check for lost packets */
616 while (1) {
617 if (!seqp->ccid2s_acked) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700618 ccid2_pr_debug("Packet lost: %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800619 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau374bcf32006-09-19 13:14:43 -0700620 /* XXX need to traverse from tail -> head in
621 * order to detect multiple congestion events in
622 * one ack vector.
623 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200624 ccid2_congestion_event(sk, seqp);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800625 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800626 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200627 if (seqp == hctx->seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800628 break;
629 seqp = seqp->ccid2s_prev;
630 }
631
Gerrit Renker1fb87502008-09-04 07:30:19 +0200632 hctx->seqt = last_acked;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800633 }
634
635 /* trim acked packets in tail */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200636 while (hctx->seqt != hctx->seqh) {
637 if (!hctx->seqt->ccid2s_acked)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800638 break;
639
Gerrit Renker1fb87502008-09-04 07:30:19 +0200640 hctx->seqt = hctx->seqt->ccid2s_next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800641 }
642
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800643 ccid2_hc_tx_check_sanity(hctx);
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200644done:
Gerrit Renker83337da2008-09-04 07:30:19 +0200645 /* check if incoming Acks allow pending packets to be sent */
646 if (sender_was_blocked && !ccid2_cwnd_network_limited(hctx))
647 tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet);
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200648 dccp_ackvec_parsed_cleanup(&hctx->av_chunks);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800649}
650
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800651static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800652{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900653 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200654 struct dccp_sock *dp = dccp_sk(sk);
655 u32 max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800656
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200657 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200658 hctx->ssthresh = ~0U;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800659
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200660 /*
661 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
662 * packets for new connections, following the rules from [RFC3390]".
663 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
664 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200665 hctx->cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200666
667 /* Make sure that Ack Ratio is enabled and within bounds. */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200668 max_ratio = DIV_ROUND_UP(hctx->cwnd, 2);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200669 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
670 dp->dccps_l_ack_ratio = max_ratio;
671
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800672 /* XXX init ~ to window size... */
Gerrit Renkercd1f7d32007-10-04 14:41:00 -0700673 if (ccid2_hc_tx_alloc_seq(hctx))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800674 return -ENOMEM;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800675
Gerrit Renker1fb87502008-09-04 07:30:19 +0200676 hctx->rto = 3 * HZ;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700677 ccid2_change_srtt(hctx, -1);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200678 hctx->rttvar = -1;
679 hctx->rpdupack = -1;
680 hctx->last_cong = jiffies;
681 setup_timer(&hctx->rtotimer, ccid2_hc_tx_rto_expire, (unsigned long)sk);
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200682 INIT_LIST_HEAD(&hctx->av_chunks);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800683
684 ccid2_hc_tx_check_sanity(hctx);
685 return 0;
686}
687
688static void ccid2_hc_tx_exit(struct sock *sk)
689{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900690 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700691 int i;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800692
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800693 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700694
Gerrit Renker1fb87502008-09-04 07:30:19 +0200695 for (i = 0; i < hctx->seqbufc; i++)
696 kfree(hctx->seqbuf[i]);
697 hctx->seqbufc = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800698}
699
700static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
701{
702 const struct dccp_sock *dp = dccp_sk(sk);
703 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk);
704
705 switch (DCCP_SKB_CB(skb)->dccpd_type) {
706 case DCCP_PKT_DATA:
707 case DCCP_PKT_DATAACK:
Gerrit Renker1fb87502008-09-04 07:30:19 +0200708 hcrx->data++;
709 if (hcrx->data >= dp->dccps_r_ack_ratio) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800710 dccp_send_ack(sk);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200711 hcrx->data = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800712 }
713 break;
714 }
715}
716
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800717static struct ccid_operations ccid2 = {
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200718 .ccid_id = DCCPC_CCID2,
719 .ccid_name = "TCP-like",
720 .ccid_owner = THIS_MODULE,
721 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
722 .ccid_hc_tx_init = ccid2_hc_tx_init,
723 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
724 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
725 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
726 .ccid_hc_tx_parse_options = ccid2_hc_tx_parse_options,
727 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
728 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
729 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800730};
731
Gerrit Renker84116712006-11-20 18:26:03 -0200732#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Gerrit Renker43264992008-08-23 13:28:27 +0200733module_param(ccid2_debug, bool, 0644);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800734MODULE_PARM_DESC(ccid2_debug, "Enable debug messages");
Gerrit Renker84116712006-11-20 18:26:03 -0200735#endif
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800736
737static __init int ccid2_module_init(void)
738{
739 return ccid_register(&ccid2);
740}
741module_init(ccid2_module_init);
742
743static __exit void ccid2_module_exit(void)
744{
745 ccid_unregister(&ccid2);
746}
747module_exit(ccid2_module_exit);
748
749MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>");
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800750MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID");
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800751MODULE_LICENSE("GPL");
752MODULE_ALIAS("net-dccp-ccid-2");