blob: e8cf99e880b0c765bf2c983b7118939f2c0977a5 [file] [log] [blame]
Andrea Bittau2a91aa32006-03-20 17:41:47 -08001/*
Andrea Bittau2a91aa32006-03-20 17:41:47 -08002 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
3 *
4 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
5 *
6 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23/*
Gerrit Renker0e64e942006-10-24 16:17:51 -070024 * This implementation should follow RFC 4341
Andrea Bittau2a91aa32006-03-20 17:41:47 -080025 */
Gerrit Renkere8ef9672008-11-12 00:43:40 -080026#include "../feat.h"
Andrea Bittau2a91aa32006-03-20 17:41:47 -080027#include "../ccid.h"
28#include "../dccp.h"
29#include "ccid2.h"
30
Gerrit Renker84116712006-11-20 18:26:03 -020031
32#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Andrea Bittau2a91aa32006-03-20 17:41:47 -080033static int ccid2_debug;
Gerrit Renker84116712006-11-20 18:26:03 -020034#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
Gerrit Renker410e27a2008-09-09 13:27:22 +020035
36static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
37{
38 int len = 0;
39 int pipe = 0;
40 struct ccid2_seq *seqp = hctx->ccid2hctx_seqh;
41
42 /* there is data in the chain */
43 if (seqp != hctx->ccid2hctx_seqt) {
44 seqp = seqp->ccid2s_prev;
45 len++;
46 if (!seqp->ccid2s_acked)
47 pipe++;
48
49 while (seqp != hctx->ccid2hctx_seqt) {
50 struct ccid2_seq *prev = seqp->ccid2s_prev;
51
52 len++;
53 if (!prev->ccid2s_acked)
54 pipe++;
55
56 /* packets are sent sequentially */
57 BUG_ON(dccp_delta_seqno(seqp->ccid2s_seq,
58 prev->ccid2s_seq ) >= 0);
59 BUG_ON(time_before(seqp->ccid2s_sent,
60 prev->ccid2s_sent));
61
62 seqp = prev;
63 }
64 }
65
66 BUG_ON(pipe != hctx->ccid2hctx_pipe);
67 ccid2_pr_debug("len of chain=%d\n", len);
68
69 do {
70 seqp = seqp->ccid2s_prev;
71 len++;
72 } while (seqp != hctx->ccid2hctx_seqh);
73
74 ccid2_pr_debug("total len=%d\n", len);
75 BUG_ON(len != hctx->ccid2hctx_seqbufc * CCID2_SEQBUF_LEN);
76}
Andrea Bittau2a91aa32006-03-20 17:41:47 -080077#else
Gerrit Renker84116712006-11-20 18:26:03 -020078#define ccid2_pr_debug(format, a...)
Gerrit Renker410e27a2008-09-09 13:27:22 +020079#define ccid2_hc_tx_check_sanity(hctx)
Andrea Bittau2a91aa32006-03-20 17:41:47 -080080#endif
81
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070082static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx)
Andrea Bittau07978aa2006-09-19 13:13:37 -070083{
84 struct ccid2_seq *seqp;
85 int i;
86
87 /* check if we have space to preserve the pointer to the buffer */
Gerrit Renker410e27a2008-09-09 13:27:22 +020088 if (hctx->ccid2hctx_seqbufc >= (sizeof(hctx->ccid2hctx_seqbuf) /
89 sizeof(struct ccid2_seq*)))
Andrea Bittau07978aa2006-09-19 13:13:37 -070090 return -ENOMEM;
91
92 /* allocate buffer and initialize linked list */
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070093 seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any());
Andrea Bittau07978aa2006-09-19 13:13:37 -070094 if (seqp == NULL)
95 return -ENOMEM;
96
Gerrit Renkercd1f7d32007-10-04 14:41:00 -070097 for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) {
Andrea Bittau07978aa2006-09-19 13:13:37 -070098 seqp[i].ccid2s_next = &seqp[i + 1];
99 seqp[i + 1].ccid2s_prev = &seqp[i];
100 }
Gerrit Renkercd1f7d32007-10-04 14:41:00 -0700101 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp;
102 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
Andrea Bittau07978aa2006-09-19 13:13:37 -0700103
104 /* This is the first allocation. Initiate the head and tail. */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200105 if (hctx->ccid2hctx_seqbufc == 0)
106 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqt = seqp;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700107 else {
108 /* link the existing list with the one we just created */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200109 hctx->ccid2hctx_seqh->ccid2s_next = seqp;
110 seqp->ccid2s_prev = hctx->ccid2hctx_seqh;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700111
Gerrit Renker410e27a2008-09-09 13:27:22 +0200112 hctx->ccid2hctx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
113 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->ccid2hctx_seqt;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700114 }
115
116 /* store the original pointer to the buffer so we can free it */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200117 hctx->ccid2hctx_seqbuf[hctx->ccid2hctx_seqbufc] = seqp;
118 hctx->ccid2hctx_seqbufc++;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700119
120 return 0;
121}
122
Gerrit Renker6b57c932006-11-28 19:55:06 -0200123static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800124{
Gerrit Renker410e27a2008-09-09 13:27:22 +0200125 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
126
127 if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd)
128 return 0;
129
130 return 1; /* XXX CCID should dequeue when ready instead of polling */
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800131}
132
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200133static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800134{
135 struct dccp_sock *dp = dccp_sk(sk);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200136 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->ccid2hctx_cwnd, 2);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200137
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800138 /*
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200139 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
140 * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
141 * acceptable since this causes starvation/deadlock whenever cwnd < 2.
142 * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800143 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200144 if (val == 0 || val > max_ratio) {
145 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
146 val = max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800147 }
Gerrit Renkere8ef9672008-11-12 00:43:40 -0800148 if (val > DCCPF_ACK_RATIO_MAX)
149 val = DCCPF_ACK_RATIO_MAX;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800150
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200151 if (val == dp->dccps_l_ack_ratio)
152 return;
153
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200154 ccid2_pr_debug("changing local ack ratio to %u\n", val);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800155 dp->dccps_l_ack_ratio = val;
156}
157
Gerrit Renker410e27a2008-09-09 13:27:22 +0200158static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val)
159{
160 ccid2_pr_debug("change SRTT to %ld\n", val);
161 hctx->ccid2hctx_srtt = val;
162}
163
164static void ccid2_start_rto_timer(struct sock *sk);
165
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800166static void ccid2_hc_tx_rto_expire(unsigned long data)
167{
168 struct sock *sk = (struct sock *)data;
169 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200170 long s;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800171
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800172 bh_lock_sock(sk);
173 if (sock_owned_by_user(sk)) {
Gerrit Renker410e27a2008-09-09 13:27:22 +0200174 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
175 jiffies + HZ / 5);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800176 goto out;
177 }
178
179 ccid2_pr_debug("RTO_EXPIRE\n");
180
Gerrit Renker410e27a2008-09-09 13:27:22 +0200181 ccid2_hc_tx_check_sanity(hctx);
182
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800183 /* back-off timer */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200184 hctx->ccid2hctx_rto <<= 1;
185
186 s = hctx->ccid2hctx_rto / HZ;
187 if (s > 60)
188 hctx->ccid2hctx_rto = 60 * HZ;
189
190 ccid2_start_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800191
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800192 /* adjust pipe, cwnd etc */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200193 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd / 2;
194 if (hctx->ccid2hctx_ssthresh < 2)
195 hctx->ccid2hctx_ssthresh = 2;
196 hctx->ccid2hctx_cwnd = 1;
197 hctx->ccid2hctx_pipe = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800198
199 /* clear state about stuff we sent */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200200 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh;
201 hctx->ccid2hctx_packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800202
203 /* clear ack ratio state. */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200204 hctx->ccid2hctx_rpseq = 0;
205 hctx->ccid2hctx_rpdupack = -1;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800206 ccid2_change_l_ack_ratio(sk, 1);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200207 ccid2_hc_tx_check_sanity(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800208out:
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
Gerrit Renker410e27a2008-09-09 13:27:22 +0200213static void ccid2_start_rto_timer(struct sock *sk)
214{
215 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
216
217 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto);
218
219 BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer));
220 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer,
221 jiffies + hctx->ccid2hctx_rto);
222}
223
224static 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 Renker410e27a2008-09-09 13:27:22 +0200230 hctx->ccid2hctx_pipe++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800231
Gerrit Renker410e27a2008-09-09 13:27:22 +0200232 hctx->ccid2hctx_seqh->ccid2s_seq = dp->dccps_gss;
233 hctx->ccid2hctx_seqh->ccid2s_acked = 0;
234 hctx->ccid2hctx_seqh->ccid2s_sent = jiffies;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700235
Gerrit Renker410e27a2008-09-09 13:27:22 +0200236 next = hctx->ccid2hctx_seqh->ccid2s_next;
Andrea Bittau07978aa2006-09-19 13:13:37 -0700237 /* check if we need to alloc more space */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200238 if (next == hctx->ccid2hctx_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 Renker410e27a2008-09-09 13:27:22 +0200244 next = hctx->ccid2hctx_seqh->ccid2s_next;
245 BUG_ON(next == hctx->ccid2hctx_seqt);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700246 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200247 hctx->ccid2hctx_seqh = next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800248
Gerrit Renker410e27a2008-09-09 13:27:22 +0200249 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd,
250 hctx->ccid2hctx_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 Renker410e27a2008-09-09 13:27:22 +0200273 hctx->ccid2hctx_arsent++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800274 /* We had an ack loss in this window... */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200275 if (hctx->ccid2hctx_ackloss) {
276 if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) {
277 hctx->ccid2hctx_arsent = 0;
278 hctx->ccid2hctx_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 Renker410e27a2008-09-09 13:27:22 +0200288 denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800289
Gerrit Renker410e27a2008-09-09 13:27:22 +0200290 if (hctx->ccid2hctx_arsent >= denom) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800291 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200292 hctx->ccid2hctx_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 Renker410e27a2008-09-09 13:27:22 +0200296 hctx->ccid2hctx_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 Renker410e27a2008-09-09 13:27:22 +0200302 if (!timer_pending(&hctx->ccid2hctx_rtotimer))
303 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 Renker410e27a2008-09-09 13:27:22 +0200307 struct ccid2_seq *seqp = hctx->ccid2hctx_seqt;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800308
Gerrit Renker410e27a2008-09-09 13:27:22 +0200309 while (seqp != hctx->ccid2hctx_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");
Gerrit Renker410e27a2008-09-09 13:27:22 +0200317 ccid2_hc_tx_check_sanity(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800318#endif
319}
320
Gerrit Renker410e27a2008-09-09 13:27:22 +0200321/* XXX Lame code duplication!
322 * returns -1 if none was found.
323 * else returns the next offset to use in the function call.
Gerrit Renker14355622008-09-04 07:30:19 +0200324 */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200325static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
326 unsigned char **vec, unsigned char *veclen)
Gerrit Renker14355622008-09-04 07:30:19 +0200327{
Gerrit Renker410e27a2008-09-09 13:27:22 +0200328 const struct dccp_hdr *dh = dccp_hdr(skb);
329 unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
330 unsigned char *opt_ptr;
331 const unsigned char *opt_end = (unsigned char *)dh +
332 (dh->dccph_doff * 4);
333 unsigned char opt, len;
334 unsigned char *value;
Gerrit Renker14355622008-09-04 07:30:19 +0200335
Gerrit Renker410e27a2008-09-09 13:27:22 +0200336 BUG_ON(offset < 0);
337 options += offset;
338 opt_ptr = options;
339 if (opt_ptr >= opt_end)
340 return -1;
Gerrit Renker14355622008-09-04 07:30:19 +0200341
Gerrit Renker410e27a2008-09-09 13:27:22 +0200342 while (opt_ptr != opt_end) {
343 opt = *opt_ptr++;
344 len = 0;
345 value = NULL;
Gerrit Renker14355622008-09-04 07:30:19 +0200346
Gerrit Renker410e27a2008-09-09 13:27:22 +0200347 /* Check if this isn't a single byte option */
348 if (opt > DCCPO_MAX_RESERVED) {
349 if (opt_ptr == opt_end)
350 goto out_invalid_option;
351
352 len = *opt_ptr++;
353 if (len < 3)
354 goto out_invalid_option;
Gerrit Renker14355622008-09-04 07:30:19 +0200355 /*
Gerrit Renker410e27a2008-09-09 13:27:22 +0200356 * Remove the type and len fields, leaving
357 * just the value size
Gerrit Renker14355622008-09-04 07:30:19 +0200358 */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200359 len -= 2;
360 value = opt_ptr;
361 opt_ptr += len;
Gerrit Renker14355622008-09-04 07:30:19 +0200362
Gerrit Renker410e27a2008-09-09 13:27:22 +0200363 if (opt_ptr > opt_end)
364 goto out_invalid_option;
Gerrit Renker14355622008-09-04 07:30:19 +0200365 }
366
Gerrit Renker410e27a2008-09-09 13:27:22 +0200367 switch (opt) {
368 case DCCPO_ACK_VECTOR_0:
369 case DCCPO_ACK_VECTOR_1:
370 *vec = value;
371 *veclen = len;
372 return offset + (opt_ptr - options);
Gerrit Renker14355622008-09-04 07:30:19 +0200373 }
374 }
375
Gerrit Renker410e27a2008-09-09 13:27:22 +0200376 return -1;
Gerrit Renker14355622008-09-04 07:30:19 +0200377
Gerrit Renker410e27a2008-09-09 13:27:22 +0200378out_invalid_option:
379 DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
380 return -1;
Gerrit Renker14355622008-09-04 07:30:19 +0200381}
382
Gerrit Renker410e27a2008-09-09 13:27:22 +0200383static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800384{
385 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
386
Gerrit Renker410e27a2008-09-09 13:27:22 +0200387 sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer);
388 ccid2_pr_debug("deleted RTO timer\n");
389}
390
391static inline void ccid2_new_ack(struct sock *sk,
392 struct ccid2_seq *seqp,
393 unsigned int *maxincr)
394{
395 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
396
397 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) {
398 if (*maxincr > 0 && ++hctx->ccid2hctx_packets_acked == 2) {
399 hctx->ccid2hctx_cwnd += 1;
400 *maxincr -= 1;
401 hctx->ccid2hctx_packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800402 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200403 } else if (++hctx->ccid2hctx_packets_acked >= hctx->ccid2hctx_cwnd) {
404 hctx->ccid2hctx_cwnd += 1;
405 hctx->ccid2hctx_packets_acked = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800406 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200407
408 /* update RTO */
409 if (hctx->ccid2hctx_srtt == -1 ||
410 time_after(jiffies, hctx->ccid2hctx_lastrtt + hctx->ccid2hctx_srtt)) {
411 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
412 int s;
413
414 /* first measurement */
415 if (hctx->ccid2hctx_srtt == -1) {
416 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
417 r, jiffies,
418 (unsigned long long)seqp->ccid2s_seq);
419 ccid2_change_srtt(hctx, r);
420 hctx->ccid2hctx_rttvar = r >> 1;
421 } else {
422 /* RTTVAR */
423 long tmp = hctx->ccid2hctx_srtt - r;
424 long srtt;
425
426 if (tmp < 0)
427 tmp *= -1;
428
429 tmp >>= 2;
430 hctx->ccid2hctx_rttvar *= 3;
431 hctx->ccid2hctx_rttvar >>= 2;
432 hctx->ccid2hctx_rttvar += tmp;
433
434 /* SRTT */
435 srtt = hctx->ccid2hctx_srtt;
436 srtt *= 7;
437 srtt >>= 3;
438 tmp = r >> 3;
439 srtt += tmp;
440 ccid2_change_srtt(hctx, srtt);
441 }
442 s = hctx->ccid2hctx_rttvar << 2;
443 /* clock granularity is 1 when based on jiffies */
444 if (!s)
445 s = 1;
446 hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s;
447
448 /* must be at least a second */
449 s = hctx->ccid2hctx_rto / HZ;
450 /* DCCP doesn't require this [but I like it cuz my code sux] */
451#if 1
452 if (s < 1)
453 hctx->ccid2hctx_rto = HZ;
454#endif
455 /* max 60 seconds */
456 if (s > 60)
457 hctx->ccid2hctx_rto = HZ * 60;
458
459 hctx->ccid2hctx_lastrtt = jiffies;
460
461 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
462 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar,
463 hctx->ccid2hctx_rto, HZ, r);
464 }
465
466 /* we got a new ack, so re-start RTO timer */
467 ccid2_hc_tx_kill_rto_timer(sk);
468 ccid2_start_rto_timer(sk);
469}
470
471static void ccid2_hc_tx_dec_pipe(struct sock *sk)
472{
473 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
474
475 if (hctx->ccid2hctx_pipe == 0)
476 DCCP_BUG("pipe == 0");
477 else
478 hctx->ccid2hctx_pipe--;
479
480 if (hctx->ccid2hctx_pipe == 0)
481 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800482}
483
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200484static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
Andrea Bittau374bcf32006-09-19 13:14:43 -0700485{
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200486 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
487
Gerrit Renker410e27a2008-09-09 13:27:22 +0200488 if (time_before(seqp->ccid2s_sent, hctx->ccid2hctx_last_cong)) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700489 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
490 return;
491 }
492
Gerrit Renker410e27a2008-09-09 13:27:22 +0200493 hctx->ccid2hctx_last_cong = jiffies;
Andrea Bittau374bcf32006-09-19 13:14:43 -0700494
Gerrit Renker410e27a2008-09-09 13:27:22 +0200495 hctx->ccid2hctx_cwnd = hctx->ccid2hctx_cwnd / 2 ? : 1U;
496 hctx->ccid2hctx_ssthresh = max(hctx->ccid2hctx_cwnd, 2U);
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200497
498 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200499 if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->ccid2hctx_cwnd)
500 ccid2_change_l_ack_ratio(sk, hctx->ccid2hctx_cwnd);
Gerrit Renkerc8bf4622008-09-04 07:30:19 +0200501}
502
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800503static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
504{
505 struct dccp_sock *dp = dccp_sk(sk);
506 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
507 u64 ackno, seqno;
508 struct ccid2_seq *seqp;
Gerrit Renker410e27a2008-09-09 13:27:22 +0200509 unsigned char *vector;
510 unsigned char veclen;
511 int offset = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800512 int done = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800513 unsigned int maxincr = 0;
514
Gerrit Renker410e27a2008-09-09 13:27:22 +0200515 ccid2_hc_tx_check_sanity(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800516 /* check reverse path congestion */
517 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
518
519 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
520 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
521 * -sorbo.
522 */
523 /* need to bootstrap */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200524 if (hctx->ccid2hctx_rpdupack == -1) {
525 hctx->ccid2hctx_rpdupack = 0;
526 hctx->ccid2hctx_rpseq = seqno;
Arnaldo Carvalho de Meloc0c736d2006-03-20 22:05:37 -0800527 } else {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800528 /* check if packet is consecutive */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200529 if (dccp_delta_seqno(hctx->ccid2hctx_rpseq, seqno) == 1)
530 hctx->ccid2hctx_rpseq = seqno;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800531 /* it's a later packet */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200532 else if (after48(seqno, hctx->ccid2hctx_rpseq)) {
533 hctx->ccid2hctx_rpdupack++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800534
535 /* check if we got enough dupacks */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200536 if (hctx->ccid2hctx_rpdupack >= NUMDUPACK) {
537 hctx->ccid2hctx_rpdupack = -1; /* XXX lame */
538 hctx->ccid2hctx_rpseq = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800539
Gerrit Renkerdf054e12007-11-24 21:32:53 -0200540 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800541 }
542 }
543 }
544
545 /* check forward path congestion */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200546 /* still didn't send out new data packets */
547 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800548 return;
549
Gerrit Renker410e27a2008-09-09 13:27:22 +0200550 switch (DCCP_SKB_CB(skb)->dccpd_type) {
551 case DCCP_PKT_ACK:
552 case DCCP_PKT_DATAACK:
553 break;
554 default:
555 return;
556 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800557
558 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
Gerrit Renker410e27a2008-09-09 13:27:22 +0200559 if (after48(ackno, hctx->ccid2hctx_high_ack))
560 hctx->ccid2hctx_high_ack = ackno;
Andrea Bittau32aac182006-11-16 14:28:40 -0200561
Gerrit Renker410e27a2008-09-09 13:27:22 +0200562 seqp = hctx->ccid2hctx_seqt;
Andrea Bittau32aac182006-11-16 14:28:40 -0200563 while (before48(seqp->ccid2s_seq, ackno)) {
564 seqp = seqp->ccid2s_next;
Gerrit Renker410e27a2008-09-09 13:27:22 +0200565 if (seqp == hctx->ccid2hctx_seqh) {
566 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200567 break;
568 }
569 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800570
Gerrit Renkera3020022007-11-24 22:10:29 -0200571 /*
572 * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
573 * packets per acknowledgement. Rounding up avoids that cwnd is not
574 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800575 */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200576 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh)
Gerrit Renkera3020022007-11-24 22:10:29 -0200577 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800578
579 /* go through all ack vectors */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200580 while ((offset = ccid2_ackvector(sk, skb, offset,
581 &vector, &veclen)) != -1) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800582 /* go through this ack vector */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200583 while (veclen--) {
584 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
585 u64 ackno_end_rl = SUB48(ackno, rl);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800586
Gerrit Renker410e27a2008-09-09 13:27:22 +0200587 ccid2_pr_debug("ackvec start:%llu end:%llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800588 (unsigned long long)ackno,
Gerrit Renker410e27a2008-09-09 13:27:22 +0200589 (unsigned long long)ackno_end_rl);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800590 /* if the seqno we are analyzing is larger than the
591 * current ackno, then move towards the tail of our
592 * seqnos.
593 */
594 while (after48(seqp->ccid2s_seq, ackno)) {
Gerrit Renker410e27a2008-09-09 13:27:22 +0200595 if (seqp == hctx->ccid2hctx_seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800596 done = 1;
597 break;
598 }
599 seqp = seqp->ccid2s_prev;
600 }
601 if (done)
602 break;
603
604 /* check all seqnos in the range of the vector
605 * run length
606 */
607 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
Gerrit Renker410e27a2008-09-09 13:27:22 +0200608 const u8 state = *vector &
609 DCCP_ACKVEC_STATE_MASK;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800610
611 /* new packet received or marked */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200612 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800613 !seqp->ccid2s_acked) {
Gerrit Renker410e27a2008-09-09 13:27:22 +0200614 if (state ==
615 DCCP_ACKVEC_STATE_ECN_MARKED) {
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200616 ccid2_congestion_event(sk,
Andrea Bittau374bcf32006-09-19 13:14:43 -0700617 seqp);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200618 } else
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800619 ccid2_new_ack(sk, seqp,
620 &maxincr);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800621
622 seqp->ccid2s_acked = 1;
623 ccid2_pr_debug("Got ack for %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800624 (unsigned long long)seqp->ccid2s_seq);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200625 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800626 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200627 if (seqp == hctx->ccid2hctx_seqt) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800628 done = 1;
629 break;
630 }
Gerrit Renker3de54892007-11-24 20:37:48 -0200631 seqp = seqp->ccid2s_prev;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800632 }
633 if (done)
634 break;
635
Gerrit Renkercfbbeab2007-11-24 20:43:59 -0200636 ackno = SUB48(ackno_end_rl, 1);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200637 vector++;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800638 }
639 if (done)
640 break;
641 }
642
643 /* The state about what is acked should be correct now
644 * Check for NUMDUPACK
645 */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200646 seqp = hctx->ccid2hctx_seqt;
647 while (before48(seqp->ccid2s_seq, hctx->ccid2hctx_high_ack)) {
Andrea Bittau32aac182006-11-16 14:28:40 -0200648 seqp = seqp->ccid2s_next;
Gerrit Renker410e27a2008-09-09 13:27:22 +0200649 if (seqp == hctx->ccid2hctx_seqh) {
650 seqp = hctx->ccid2hctx_seqh->ccid2s_prev;
Andrea Bittau32aac182006-11-16 14:28:40 -0200651 break;
652 }
653 }
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800654 done = 0;
655 while (1) {
656 if (seqp->ccid2s_acked) {
657 done++;
Gerrit Renker63df18a2007-11-24 22:04:35 -0200658 if (done == NUMDUPACK)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800659 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800660 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200661 if (seqp == hctx->ccid2hctx_seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800662 break;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800663 seqp = seqp->ccid2s_prev;
664 }
665
666 /* If there are at least 3 acknowledgements, anything unacknowledged
667 * below the last sequence number is considered lost
668 */
Gerrit Renker63df18a2007-11-24 22:04:35 -0200669 if (done == NUMDUPACK) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800670 struct ccid2_seq *last_acked = seqp;
671
672 /* check for lost packets */
673 while (1) {
674 if (!seqp->ccid2s_acked) {
Andrea Bittau374bcf32006-09-19 13:14:43 -0700675 ccid2_pr_debug("Packet lost: %llu\n",
Randy Dunlap234af482006-10-29 16:03:30 -0800676 (unsigned long long)seqp->ccid2s_seq);
Andrea Bittau374bcf32006-09-19 13:14:43 -0700677 /* XXX need to traverse from tail -> head in
678 * order to detect multiple congestion events in
679 * one ack vector.
680 */
Gerrit Renkerd50ad162007-11-24 21:40:24 -0200681 ccid2_congestion_event(sk, seqp);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200682 ccid2_hc_tx_dec_pipe(sk);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800683 }
Gerrit Renker410e27a2008-09-09 13:27:22 +0200684 if (seqp == hctx->ccid2hctx_seqt)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800685 break;
686 seqp = seqp->ccid2s_prev;
687 }
688
Gerrit Renker410e27a2008-09-09 13:27:22 +0200689 hctx->ccid2hctx_seqt = last_acked;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800690 }
691
692 /* trim acked packets in tail */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200693 while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) {
694 if (!hctx->ccid2hctx_seqt->ccid2s_acked)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800695 break;
696
Gerrit Renker410e27a2008-09-09 13:27:22 +0200697 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800698 }
699
Gerrit Renker410e27a2008-09-09 13:27:22 +0200700 ccid2_hc_tx_check_sanity(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800701}
702
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800703static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800704{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900705 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200706 struct dccp_sock *dp = dccp_sk(sk);
707 u32 max_ratio;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800708
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200709 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200710 hctx->ccid2hctx_ssthresh = ~0U;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800711
Gerrit Renker410e27a2008-09-09 13:27:22 +0200712 /*
713 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
714 * packets for new connections, following the rules from [RFC3390]".
715 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
716 */
717 hctx->ccid2hctx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200718
719 /* Make sure that Ack Ratio is enabled and within bounds. */
Gerrit Renker410e27a2008-09-09 13:27:22 +0200720 max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2);
Gerrit Renkerb00d2bb2007-11-24 21:44:30 -0200721 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
722 dp->dccps_l_ack_ratio = max_ratio;
723
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800724 /* XXX init ~ to window size... */
Gerrit Renkercd1f7d32007-10-04 14:41:00 -0700725 if (ccid2_hc_tx_alloc_seq(hctx))
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800726 return -ENOMEM;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800727
Gerrit Renker410e27a2008-09-09 13:27:22 +0200728 hctx->ccid2hctx_rto = 3 * HZ;
729 ccid2_change_srtt(hctx, -1);
730 hctx->ccid2hctx_rttvar = -1;
731 hctx->ccid2hctx_rpdupack = -1;
732 hctx->ccid2hctx_last_cong = jiffies;
733 setup_timer(&hctx->ccid2hctx_rtotimer, ccid2_hc_tx_rto_expire,
734 (unsigned long)sk);
735
736 ccid2_hc_tx_check_sanity(hctx);
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800737 return 0;
738}
739
740static void ccid2_hc_tx_exit(struct sock *sk)
741{
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +0900742 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700743 int i;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800744
Gerrit Renker410e27a2008-09-09 13:27:22 +0200745 ccid2_hc_tx_kill_rto_timer(sk);
Andrea Bittau07978aa2006-09-19 13:13:37 -0700746
Gerrit Renker410e27a2008-09-09 13:27:22 +0200747 for (i = 0; i < hctx->ccid2hctx_seqbufc; i++)
748 kfree(hctx->ccid2hctx_seqbuf[i]);
749 hctx->ccid2hctx_seqbufc = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800750}
751
752static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
753{
754 const struct dccp_sock *dp = dccp_sk(sk);
755 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk);
756
757 switch (DCCP_SKB_CB(skb)->dccpd_type) {
758 case DCCP_PKT_DATA:
759 case DCCP_PKT_DATAACK:
Gerrit Renker410e27a2008-09-09 13:27:22 +0200760 hcrx->ccid2hcrx_data++;
761 if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) {
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800762 dccp_send_ack(sk);
Gerrit Renker410e27a2008-09-09 13:27:22 +0200763 hcrx->ccid2hcrx_data = 0;
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800764 }
765 break;
766 }
767}
768
Gerrit Renkerddebc972009-01-04 21:42:53 -0800769struct ccid_operations ccid2_ops = {
Gerrit Renker410e27a2008-09-09 13:27:22 +0200770 .ccid_id = DCCPC_CCID2,
771 .ccid_name = "TCP-like",
Gerrit Renker410e27a2008-09-09 13:27:22 +0200772 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
773 .ccid_hc_tx_init = ccid2_hc_tx_init,
774 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
775 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
776 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
777 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
778 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
779 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
Andrea Bittau2a91aa32006-03-20 17:41:47 -0800780};
781
Gerrit Renker84116712006-11-20 18:26:03 -0200782#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
Gerrit Renker43264992008-08-23 13:28:27 +0200783module_param(ccid2_debug, bool, 0644);
Gerrit Renkerddebc972009-01-04 21:42:53 -0800784MODULE_PARM_DESC(ccid2_debug, "Enable CCID-2 debug messages");
Gerrit Renker84116712006-11-20 18:26:03 -0200785#endif