blob: 9728bbf0acea50b6247825a319c693a025316c59 [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 Renker6c583242007-10-04 14:42:19 -0700126 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800127
Gerrit Renker1fb87502008-09-04 07:30:19 +0200128 if (hctx->pipe < hctx->cwnd)
Gerrit Renker83399362007-11-24 22:09:35 -0200129 return 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800130
Andrea Bittau446dec32006-09-19 13:10:11 -0700131 return 1; /* XXX CCID should dequeue when ready instead of polling */
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800132}
133
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200134static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800135{
136 struct dccp_sock *dp = dccp_sk(sk);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200137 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->cwnd, 2);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200138
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800139 /*
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200140 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
141 * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
142 * acceptable since this causes starvation/deadlock whenever cwnd < 2.
143 * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800144 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200145 if (val == 0 || val > max_ratio) {
146 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
147 val = max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800148 }
Gerrit Renker86349c82008-09-04 07:30:19 +0200149 if (val > DCCPF_ACK_RATIO_MAX)
150 val = DCCPF_ACK_RATIO_MAX;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800151
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200152 if (val == dp->dccps_l_ack_ratio)
153 return;
154
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200155 ccid2_pr_debug("changing local ack ratio to %u\n", val);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800156 dp->dccps_l_ack_ratio = val;
157}
158
Andrea Bittau593f16a2006-09-19 13:15:33 -0700159static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val)
160{
161 ccid2_pr_debug("change SRTT to %ld\n", val);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200162 hctx->srtt = val;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700163}
164
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800165static void ccid2_start_rto_timer(struct sock *sk);
166
167static void ccid2_hc_tx_rto_expire(unsigned long data)
168{
169 struct sock *sk = (struct sock *)data;
170 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
171 long s;
172
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800173 bh_lock_sock(sk);
174 if (sock_owned_by_user(sk)) {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200175 sk_reset_timer(sk, &hctx->rtotimer, jiffies + HZ / 5);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800176 goto out;
177 }
178
179 ccid2_pr_debug("RTO_EXPIRE\n");
180
181 ccid2_hc_tx_check_sanity(hctx);
182
183 /* back-off timer */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200184 hctx->rto <<= 1;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800185
Gerrit Renker1fb87502008-09-04 07:30:19 +0200186 s = hctx->rto / HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800187 if (s > 60)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200188 hctx->rto = 60 * HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800189
190 ccid2_start_rto_timer(sk);
191
192 /* adjust pipe, cwnd etc */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200193 hctx->ssthresh = hctx->cwnd / 2;
194 if (hctx->ssthresh < 2)
195 hctx->ssthresh = 2;
196 hctx->cwnd = 1;
197 hctx->pipe = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800198
199 /* clear state about stuff we sent */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200200 hctx->seqt = hctx->seqh;
201 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800202
203 /* clear ack ratio state. */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200204 hctx->rpseq = 0;
205 hctx->rpdupack = -1;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800206 ccid2_change_l_ack_ratio(sk, 1);
207 ccid2_hc_tx_check_sanity(hctx);
208out:
209 bh_unlock_sock(sk);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800210 sock_put(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800211}
212
213static void ccid2_start_rto_timer(struct sock *sk)
214{
215 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
216
Gerrit Renker1fb87502008-09-04 07:30:19 +0200217 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->rto);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800218
Gerrit Renker1fb87502008-09-04 07:30:19 +0200219 BUG_ON(timer_pending(&hctx->rtotimer));
220 sk_reset_timer(sk, &hctx->rtotimer,
221 jiffies + hctx->rto);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800222}
223
Gerrit Renker6b57c932006-11-28 19:55:06 -0200224static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800225{
226 struct dccp_sock *dp = dccp_sk(sk);
227 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700228 struct ccid2_seq *next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800229
Gerrit Renker1fb87502008-09-04 07:30:19 +0200230 hctx->pipe++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800231
Gerrit Renker1fb87502008-09-04 07:30:19 +0200232 hctx->seqh->ccid2s_seq = dp->dccps_gss;
233 hctx->seqh->ccid2s_acked = 0;
234 hctx->seqh->ccid2s_sent = jiffies;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700235
Gerrit Renker1fb87502008-09-04 07:30:19 +0200236 next = hctx->seqh->ccid2s_next;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700237 /* check if we need to alloc more space */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200238 if (next == hctx->seqt) {
Gerrit Renker7d9e8932007-10-04 14:41:26 -0700239 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 */
242 return;
243 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200244 next = hctx->seqh->ccid2s_next;
245 BUG_ON(next == hctx->seqt);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700246 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200247 hctx->seqh = next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800248
Gerrit Renker1fb87502008-09-04 07:30:19 +0200249 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->cwnd, hctx->pipe);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800250
Gerrit Renker900bfed2007-11-24 21:58:33 -0200251 /*
252 * FIXME: The code below is broken and the variables have been removed
253 * from the socket struct. The `ackloss' variable was always set to 0,
254 * and with arsent there are several problems:
255 * (i) it doesn't just count the number of Acks, but all sent packets;
256 * (ii) it is expressed in # of packets, not # of windows, so the
257 * comparison below uses the wrong formula: Appendix A of RFC 4341
258 * comes up with the number K = cwnd / (R^2 - R) of consecutive windows
259 * of data with no lost or marked Ack packets. If arsent were the # of
260 * consecutive Acks received without loss, then Ack Ratio needs to be
261 * decreased by 1 when
262 * arsent >= K * cwnd / R = cwnd^2 / (R^3 - R^2)
263 * where cwnd / R is the number of Acks received per window of data
264 * (cf. RFC 4341, App. A). The problems are that
265 * - arsent counts other packets as well;
266 * - the comparison uses a formula different from RFC 4341;
267 * - computing a cubic/quadratic equation each time is too complicated.
268 * Hence a different algorithm is needed.
269 */
270#if 0
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800271 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200272 hctx->arsent++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800273 /* We had an ack loss in this window... */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200274 if (hctx->ackloss) {
275 if (hctx->arsent >= hctx->cwnd) {
276 hctx->arsent = 0;
277 hctx->ackloss = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800278 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800279 } else {
280 /* No acks lost up to now... */
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800281 /* decrease ack ratio if enough packets were sent */
282 if (dp->dccps_l_ack_ratio > 1) {
283 /* XXX don't calculate denominator each time */
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800284 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
285 dp->dccps_l_ack_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800286
Gerrit Renker1fb87502008-09-04 07:30:19 +0200287 denom = hctx->cwnd * hctx->cwnd / denom;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800288
Gerrit Renker1fb87502008-09-04 07:30:19 +0200289 if (hctx->arsent >= denom) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800290 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200291 hctx->arsent = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800292 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800293 } else {
294 /* we can't increase ack ratio further [1] */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200295 hctx->arsent = 0; /* or maybe set it to cwnd*/
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800296 }
297 }
Gerrit Renker900bfed2007-11-24 21:58:33 -0200298#endif
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800299
300 /* setup RTO timer */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200301 if (!timer_pending(&hctx->rtotimer))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800302 ccid2_start_rto_timer(sk);
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800303
Andrea Bittau8d424f62006-09-19 13:12:44 -0700304#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800305 do {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200306 struct ccid2_seq *seqp = hctx->seqt;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800307
Gerrit Renker1fb87502008-09-04 07:30:19 +0200308 while (seqp != hctx->seqh) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800309 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200310 (unsigned long long)seqp->ccid2s_seq,
Randy Dunlap234af482006-10-29 16:03:30 -0800311 seqp->ccid2s_acked, seqp->ccid2s_sent);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800312 seqp = seqp->ccid2s_next;
313 }
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800314 } while (0);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800315 ccid2_pr_debug("=========\n");
316 ccid2_hc_tx_check_sanity(hctx);
317#endif
318}
319
320/* XXX Lame code duplication!
321 * returns -1 if none was found.
322 * else returns the next offset to use in the function call.
323 */
324static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
325 unsigned char **vec, unsigned char *veclen)
326{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900327 const struct dccp_hdr *dh = dccp_hdr(skb);
328 unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
329 unsigned char *opt_ptr;
330 const unsigned char *opt_end = (unsigned char *)dh +
331 (dh->dccph_doff * 4);
332 unsigned char opt, len;
333 unsigned char *value;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800334
335 BUG_ON(offset < 0);
336 options += offset;
337 opt_ptr = options;
338 if (opt_ptr >= opt_end)
339 return -1;
340
341 while (opt_ptr != opt_end) {
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900342 opt = *opt_ptr++;
343 len = 0;
344 value = NULL;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800345
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900346 /* Check if this isn't a single byte option */
347 if (opt > DCCPO_MAX_RESERVED) {
348 if (opt_ptr == opt_end)
349 goto out_invalid_option;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800350
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900351 len = *opt_ptr++;
352 if (len < 3)
353 goto out_invalid_option;
354 /*
355 * Remove the type and len fields, leaving
356 * just the value size
357 */
358 len -= 2;
359 value = opt_ptr;
360 opt_ptr += len;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800361
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900362 if (opt_ptr > opt_end)
363 goto out_invalid_option;
364 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800365
366 switch (opt) {
367 case DCCPO_ACK_VECTOR_0:
368 case DCCPO_ACK_VECTOR_1:
369 *vec = value;
370 *veclen = len;
371 return offset + (opt_ptr - options);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800372 }
373 }
374
375 return -1;
376
377out_invalid_option:
Gerrit Renker59348b12006-11-20 18:39:23 -0200378 DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800379 return -1;
380}
381
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800382static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800383{
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800384 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
385
Gerrit Renker1fb87502008-09-04 07:30:19 +0200386 sk_stop_timer(sk, &hctx->rtotimer);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800387 ccid2_pr_debug("deleted RTO timer\n");
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800388}
389
390static inline void ccid2_new_ack(struct sock *sk,
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900391 struct ccid2_seq *seqp,
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800392 unsigned int *maxincr)
393{
394 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
395
Gerrit Renker1fb87502008-09-04 07:30:19 +0200396 if (hctx->cwnd < hctx->ssthresh) {
397 if (*maxincr > 0 && ++hctx->packets_acked == 2) {
398 hctx->cwnd += 1;
399 *maxincr -= 1;
400 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800401 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200402 } else if (++hctx->packets_acked >= hctx->cwnd) {
403 hctx->cwnd += 1;
404 hctx->packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800405 }
406
407 /* update RTO */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200408 if (hctx->srtt == -1 ||
409 time_after(jiffies, hctx->lastrtt + hctx->srtt)) {
Andrea Bittau29651cd2006-09-19 13:06:46 -0700410 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800411 int s;
412
413 /* first measurement */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200414 if (hctx->srtt == -1) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800415 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200416 r, jiffies,
Randy Dunlap234af482006-10-29 16:03:30 -0800417 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau593f16a2006-09-19 13:15:33 -0700418 ccid2_change_srtt(hctx, r);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200419 hctx->rttvar = r >> 1;
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800420 } else {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800421 /* RTTVAR */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200422 long tmp = hctx->srtt - r;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700423 long srtt;
424
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800425 if (tmp < 0)
426 tmp *= -1;
427
428 tmp >>= 2;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200429 hctx->rttvar *= 3;
430 hctx->rttvar >>= 2;
431 hctx->rttvar += tmp;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800432
433 /* SRTT */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200434 srtt = hctx->srtt;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700435 srtt *= 7;
436 srtt >>= 3;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800437 tmp = r >> 3;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700438 srtt += tmp;
439 ccid2_change_srtt(hctx, srtt);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800440 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200441 s = hctx->rttvar << 2;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800442 /* clock granularity is 1 when based on jiffies */
443 if (!s)
444 s = 1;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200445 hctx->rto = hctx->srtt + s;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800446
447 /* must be at least a second */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200448 s = hctx->rto / HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800449 /* DCCP doesn't require this [but I like it cuz my code sux] */
450#if 1
451 if (s < 1)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200452 hctx->rto = HZ;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800453#endif
454 /* max 60 seconds */
455 if (s > 60)
Gerrit Renker1fb87502008-09-04 07:30:19 +0200456 hctx->rto = HZ * 60;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800457
Gerrit Renker1fb87502008-09-04 07:30:19 +0200458 hctx->lastrtt = jiffies;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800459
460 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
Gerrit Renker1fb87502008-09-04 07:30:19 +0200461 hctx->srtt, hctx->rttvar,
462 hctx->rto, HZ, r);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800463 }
464
465 /* we got a new ack, so re-start RTO timer */
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800466 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800467 ccid2_start_rto_timer(sk);
468}
469
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800470static void ccid2_hc_tx_dec_pipe(struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800471{
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800472 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
473
Gerrit Renker1fb87502008-09-04 07:30:19 +0200474 if (hctx->pipe == 0)
Gerrit Renker95b21d72007-11-24 22:06:52 -0200475 DCCP_BUG("pipe == 0");
476 else
Gerrit Renker1fb87502008-09-04 07:30:19 +0200477 hctx->pipe--;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800478
Gerrit Renker1fb87502008-09-04 07:30:19 +0200479 if (hctx->pipe == 0)
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800480 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800481}
482
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200483static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
Andrea Bittau374bcf32006-09-19 13:14:43 -0700484{
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200485 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
486
Gerrit Renker1fb87502008-09-04 07:30:19 +0200487 if (time_before(seqp->ccid2s_sent, hctx->last_cong)) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700488 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
489 return;
490 }
491
Gerrit Renker1fb87502008-09-04 07:30:19 +0200492 hctx->last_cong = jiffies;
Andrea Bittau374bcf32006-09-19 13:14:43 -0700493
Gerrit Renker1fb87502008-09-04 07:30:19 +0200494 hctx->cwnd = hctx->cwnd / 2 ? : 1U;
495 hctx->ssthresh = max(hctx->cwnd, 2U);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200496
497 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200498 if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->cwnd)
499 ccid2_change_l_ack_ratio(sk, hctx->cwnd);
Andrea Bittau374bcf32006-09-19 13:14:43 -0700500}
501
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800502static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
503{
504 struct dccp_sock *dp = dccp_sk(sk);
505 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
506 u64 ackno, seqno;
507 struct ccid2_seq *seqp;
508 unsigned char *vector;
509 unsigned char veclen;
510 int offset = 0;
511 int done = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800512 unsigned int maxincr = 0;
513
514 ccid2_hc_tx_check_sanity(hctx);
515 /* check reverse path congestion */
516 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
517
518 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
519 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
520 * -sorbo.
521 */
522 /* need to bootstrap */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200523 if (hctx->rpdupack == -1) {
524 hctx->rpdupack = 0;
525 hctx->rpseq = seqno;
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800526 } else {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800527 /* check if packet is consecutive */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200528 if (dccp_delta_seqno(hctx->rpseq, seqno) == 1)
529 hctx->rpseq = seqno;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800530 /* it's a later packet */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200531 else if (after48(seqno, hctx->rpseq)) {
532 hctx->rpdupack++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800533
534 /* check if we got enough dupacks */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200535 if (hctx->rpdupack >= NUMDUPACK) {
536 hctx->rpdupack = -1; /* XXX lame */
537 hctx->rpseq = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800538
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200539 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800540 }
541 }
542 }
543
544 /* check forward path congestion */
545 /* still didn't send out new data packets */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200546 if (hctx->seqh == hctx->seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800547 return;
548
549 switch (DCCP_SKB_CB(skb)->dccpd_type) {
550 case DCCP_PKT_ACK:
551 case DCCP_PKT_DATAACK:
552 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800553 default:
554 return;
555 }
556
557 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200558 if (after48(ackno, hctx->high_ack))
559 hctx->high_ack = ackno;
Andrea Bittau32aac182006-11-16 14:28:40 -0200560
Gerrit Renker1fb87502008-09-04 07:30:19 +0200561 seqp = hctx->seqt;
Andrea Bittau32aac182006-11-16 14:28:40 -0200562 while (before48(seqp->ccid2s_seq, ackno)) {
563 seqp = seqp->ccid2s_next;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200564 if (seqp == hctx->seqh) {
565 seqp = hctx->seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200566 break;
567 }
568 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800569
Gerrit Renkera3020022007-11-24 22:10:29 -0200570 /*
571 * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
572 * packets per acknowledgement. Rounding up avoids that cwnd is not
573 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800574 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200575 if (hctx->cwnd < hctx->ssthresh)
Gerrit Renkera3020022007-11-24 22:10:29 -0200576 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800577
578 /* go through all ack vectors */
579 while ((offset = ccid2_ackvector(sk, skb, offset,
580 &vector, &veclen)) != -1) {
581 /* go through this ack vector */
582 while (veclen--) {
583 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
Gerrit Renkercfbbeab2007-11-24 20:43:59 -0200584 u64 ackno_end_rl = SUB48(ackno, rl);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800585
Randy Dunlap234af482006-10-29 16:03:30 -0800586 ccid2_pr_debug("ackvec start:%llu end:%llu\n",
587 (unsigned long long)ackno,
588 (unsigned long long)ackno_end_rl);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800589 /* if the seqno we are analyzing is larger than the
590 * current ackno, then move towards the tail of our
591 * seqnos.
592 */
593 while (after48(seqp->ccid2s_seq, ackno)) {
Gerrit Renker1fb87502008-09-04 07:30:19 +0200594 if (seqp == hctx->seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800595 done = 1;
596 break;
597 }
598 seqp = seqp->ccid2s_prev;
599 }
600 if (done)
601 break;
602
603 /* check all seqnos in the range of the vector
604 * run length
605 */
606 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
Andrea Bittau8e27e462006-09-19 13:05:35 -0700607 const u8 state = *vector &
608 DCCP_ACKVEC_STATE_MASK;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800609
610 /* new packet received or marked */
611 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
612 !seqp->ccid2s_acked) {
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200613 if (state ==
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800614 DCCP_ACKVEC_STATE_ECN_MARKED) {
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200615 ccid2_congestion_event(sk,
Andrea Bittau374bcf32006-09-19 13:14:43 -0700616 seqp);
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800617 } else
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800618 ccid2_new_ack(sk, seqp,
619 &maxincr);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800620
621 seqp->ccid2s_acked = 1;
622 ccid2_pr_debug("Got ack for %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800623 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800624 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800625 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200626 if (seqp == hctx->seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800627 done = 1;
628 break;
629 }
Gerrit Renker3de54892007-11-24 20:37:48 -0200630 seqp = seqp->ccid2s_prev;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800631 }
632 if (done)
633 break;
634
Gerrit Renkercfbbeab2007-11-24 20:43:59 -0200635 ackno = SUB48(ackno_end_rl, 1);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800636 vector++;
637 }
638 if (done)
639 break;
640 }
641
642 /* The state about what is acked should be correct now
643 * Check for NUMDUPACK
644 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200645 seqp = hctx->seqt;
646 while (before48(seqp->ccid2s_seq, hctx->high_ack)) {
Andrea Bittau32aac182006-11-16 14:28:40 -0200647 seqp = seqp->ccid2s_next;
Gerrit Renker1fb87502008-09-04 07:30:19 +0200648 if (seqp == hctx->seqh) {
649 seqp = hctx->seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200650 break;
651 }
652 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800653 done = 0;
654 while (1) {
655 if (seqp->ccid2s_acked) {
656 done++;
Gerrit Renker63df18a2007-11-24 22:04:35 -0200657 if (done == NUMDUPACK)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800658 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800659 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200660 if (seqp == hctx->seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800661 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800662 seqp = seqp->ccid2s_prev;
663 }
664
665 /* If there are at least 3 acknowledgements, anything unacknowledged
666 * below the last sequence number is considered lost
667 */
Gerrit Renker63df18a2007-11-24 22:04:35 -0200668 if (done == NUMDUPACK) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800669 struct ccid2_seq *last_acked = seqp;
670
671 /* check for lost packets */
672 while (1) {
673 if (!seqp->ccid2s_acked) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700674 ccid2_pr_debug("Packet lost: %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800675 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau374bcf32006-09-19 13:14:43 -0700676 /* XXX need to traverse from tail -> head in
677 * order to detect multiple congestion events in
678 * one ack vector.
679 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200680 ccid2_congestion_event(sk, seqp);
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800681 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800682 }
Gerrit Renker1fb87502008-09-04 07:30:19 +0200683 if (seqp == hctx->seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800684 break;
685 seqp = seqp->ccid2s_prev;
686 }
687
Gerrit Renker1fb87502008-09-04 07:30:19 +0200688 hctx->seqt = last_acked;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800689 }
690
691 /* trim acked packets in tail */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200692 while (hctx->seqt != hctx->seqh) {
693 if (!hctx->seqt->ccid2s_acked)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800694 break;
695
Gerrit Renker1fb87502008-09-04 07:30:19 +0200696 hctx->seqt = hctx->seqt->ccid2s_next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800697 }
698
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800699 ccid2_hc_tx_check_sanity(hctx);
700}
701
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800702static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800703{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900704 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200705 struct dccp_sock *dp = dccp_sk(sk);
706 u32 max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800707
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200708 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200709 hctx->ssthresh = ~0U;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800710
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200711 /*
712 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
713 * packets for new connections, following the rules from [RFC3390]".
714 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
715 */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200716 hctx->cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200717
718 /* Make sure that Ack Ratio is enabled and within bounds. */
Gerrit Renker1fb87502008-09-04 07:30:19 +0200719 max_ratio = DIV_ROUND_UP(hctx->cwnd, 2);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200720 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
721 dp->dccps_l_ack_ratio = max_ratio;
722
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800723 /* XXX init ~ to window size... */
Gerrit Renkercd1f7d32007-10-04 14:41:00 -0700724 if (ccid2_hc_tx_alloc_seq(hctx))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800725 return -ENOMEM;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800726
Gerrit Renker1fb87502008-09-04 07:30:19 +0200727 hctx->rto = 3 * HZ;
Andrea Bittau593f16a2006-09-19 13:15:33 -0700728 ccid2_change_srtt(hctx, -1);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200729 hctx->rttvar = -1;
730 hctx->rpdupack = -1;
731 hctx->last_cong = jiffies;
732 setup_timer(&hctx->rtotimer, ccid2_hc_tx_rto_expire, (unsigned long)sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800733
734 ccid2_hc_tx_check_sanity(hctx);
735 return 0;
736}
737
738static void ccid2_hc_tx_exit(struct sock *sk)
739{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900740 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700741 int i;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800742
Andrea Bittau77ff72d2006-03-20 17:57:52 -0800743 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700744
Gerrit Renker1fb87502008-09-04 07:30:19 +0200745 for (i = 0; i < hctx->seqbufc; i++)
746 kfree(hctx->seqbuf[i]);
747 hctx->seqbufc = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800748}
749
750static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
751{
752 const struct dccp_sock *dp = dccp_sk(sk);
753 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk);
754
755 switch (DCCP_SKB_CB(skb)->dccpd_type) {
756 case DCCP_PKT_DATA:
757 case DCCP_PKT_DATAACK:
Gerrit Renker1fb87502008-09-04 07:30:19 +0200758 hcrx->data++;
759 if (hcrx->data >= dp->dccps_r_ack_ratio) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800760 dccp_send_ack(sk);
Gerrit Renker1fb87502008-09-04 07:30:19 +0200761 hcrx->data = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800762 }
763 break;
764 }
765}
766
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800767static struct ccid_operations ccid2 = {
Ian McDonald3dd9a7c2006-09-22 14:26:44 +1200768 .ccid_id = DCCPC_CCID2,
Gerrit Renker84a97b02007-12-13 23:33:25 -0200769 .ccid_name = "TCP-like",
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800770 .ccid_owner = THIS_MODULE,
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800771 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800772 .ccid_hc_tx_init = ccid2_hc_tx_init,
773 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
774 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
775 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
776 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800777 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800778 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
779};
780
Gerrit Renker84116712006-11-20 18:26:03 -0200781#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Gerrit Renker43264992008-08-23 13:28:27 +0200782module_param(ccid2_debug, bool, 0644);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800783MODULE_PARM_DESC(ccid2_debug, "Enable debug messages");
Gerrit Renker84116712006-11-20 18:26:03 -0200784#endif
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800785
786static __init int ccid2_module_init(void)
787{
788 return ccid_register(&ccid2);
789}
790module_init(ccid2_module_init);
791
792static __exit void ccid2_module_exit(void)
793{
794 ccid_unregister(&ccid2);
795}
796module_exit(ccid2_module_exit);
797
798MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>");
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800799MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID");
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800800MODULE_LICENSE("GPL");
801MODULE_ALIAS("net-dccp-ccid-2");