aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ccids/ccid2.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/dccp/ccids/ccid2.c')
-rw-r--r--net/dccp/ccids/ccid2.c328
1 files changed, 163 insertions, 165 deletions
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index e8cf99e880b0..9b3ae9922be1 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -23,6 +23,7 @@
23/* 23/*
24 * This implementation should follow RFC 4341 24 * This implementation should follow RFC 4341
25 */ 25 */
26#include <linux/slab.h>
26#include "../feat.h" 27#include "../feat.h"
27#include "../ccid.h" 28#include "../ccid.h"
28#include "../dccp.h" 29#include "../dccp.h"
@@ -33,20 +34,20 @@
33static int ccid2_debug; 34static int ccid2_debug;
34#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a) 35#define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
35 36
36static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx) 37static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hc)
37{ 38{
38 int len = 0; 39 int len = 0;
39 int pipe = 0; 40 int pipe = 0;
40 struct ccid2_seq *seqp = hctx->ccid2hctx_seqh; 41 struct ccid2_seq *seqp = hc->tx_seqh;
41 42
42 /* there is data in the chain */ 43 /* there is data in the chain */
43 if (seqp != hctx->ccid2hctx_seqt) { 44 if (seqp != hc->tx_seqt) {
44 seqp = seqp->ccid2s_prev; 45 seqp = seqp->ccid2s_prev;
45 len++; 46 len++;
46 if (!seqp->ccid2s_acked) 47 if (!seqp->ccid2s_acked)
47 pipe++; 48 pipe++;
48 49
49 while (seqp != hctx->ccid2hctx_seqt) { 50 while (seqp != hc->tx_seqt) {
50 struct ccid2_seq *prev = seqp->ccid2s_prev; 51 struct ccid2_seq *prev = seqp->ccid2s_prev;
51 52
52 len++; 53 len++;
@@ -63,30 +64,30 @@ static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx)
63 } 64 }
64 } 65 }
65 66
66 BUG_ON(pipe != hctx->ccid2hctx_pipe); 67 BUG_ON(pipe != hc->tx_pipe);
67 ccid2_pr_debug("len of chain=%d\n", len); 68 ccid2_pr_debug("len of chain=%d\n", len);
68 69
69 do { 70 do {
70 seqp = seqp->ccid2s_prev; 71 seqp = seqp->ccid2s_prev;
71 len++; 72 len++;
72 } while (seqp != hctx->ccid2hctx_seqh); 73 } while (seqp != hc->tx_seqh);
73 74
74 ccid2_pr_debug("total len=%d\n", len); 75 ccid2_pr_debug("total len=%d\n", len);
75 BUG_ON(len != hctx->ccid2hctx_seqbufc * CCID2_SEQBUF_LEN); 76 BUG_ON(len != hc->tx_seqbufc * CCID2_SEQBUF_LEN);
76} 77}
77#else 78#else
78#define ccid2_pr_debug(format, a...) 79#define ccid2_pr_debug(format, a...)
79#define ccid2_hc_tx_check_sanity(hctx) 80#define ccid2_hc_tx_check_sanity(hc)
80#endif 81#endif
81 82
82static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx) 83static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
83{ 84{
84 struct ccid2_seq *seqp; 85 struct ccid2_seq *seqp;
85 int i; 86 int i;
86 87
87 /* check if we have space to preserve the pointer to the buffer */ 88 /* check if we have space to preserve the pointer to the buffer */
88 if (hctx->ccid2hctx_seqbufc >= (sizeof(hctx->ccid2hctx_seqbuf) / 89 if (hc->tx_seqbufc >= (sizeof(hc->tx_seqbuf) /
89 sizeof(struct ccid2_seq*))) 90 sizeof(struct ccid2_seq *)))
90 return -ENOMEM; 91 return -ENOMEM;
91 92
92 /* allocate buffer and initialize linked list */ 93 /* allocate buffer and initialize linked list */
@@ -102,29 +103,29 @@ static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx)
102 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; 103 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
103 104
104 /* This is the first allocation. Initiate the head and tail. */ 105 /* This is the first allocation. Initiate the head and tail. */
105 if (hctx->ccid2hctx_seqbufc == 0) 106 if (hc->tx_seqbufc == 0)
106 hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqt = seqp; 107 hc->tx_seqh = hc->tx_seqt = seqp;
107 else { 108 else {
108 /* link the existing list with the one we just created */ 109 /* link the existing list with the one we just created */
109 hctx->ccid2hctx_seqh->ccid2s_next = seqp; 110 hc->tx_seqh->ccid2s_next = seqp;
110 seqp->ccid2s_prev = hctx->ccid2hctx_seqh; 111 seqp->ccid2s_prev = hc->tx_seqh;
111 112
112 hctx->ccid2hctx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; 113 hc->tx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
113 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->ccid2hctx_seqt; 114 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hc->tx_seqt;
114 } 115 }
115 116
116 /* store the original pointer to the buffer so we can free it */ 117 /* store the original pointer to the buffer so we can free it */
117 hctx->ccid2hctx_seqbuf[hctx->ccid2hctx_seqbufc] = seqp; 118 hc->tx_seqbuf[hc->tx_seqbufc] = seqp;
118 hctx->ccid2hctx_seqbufc++; 119 hc->tx_seqbufc++;
119 120
120 return 0; 121 return 0;
121} 122}
122 123
123static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) 124static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
124{ 125{
125 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 126 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
126 127
127 if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd) 128 if (hc->tx_pipe < hc->tx_cwnd)
128 return 0; 129 return 0;
129 130
130 return 1; /* XXX CCID should dequeue when ready instead of polling */ 131 return 1; /* XXX CCID should dequeue when ready instead of polling */
@@ -133,7 +134,7 @@ static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
133static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val) 134static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
134{ 135{
135 struct dccp_sock *dp = dccp_sk(sk); 136 struct dccp_sock *dp = dccp_sk(sk);
136 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->ccid2hctx_cwnd, 2); 137 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->tx_cwnd, 2);
137 138
138 /* 139 /*
139 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from 140 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
@@ -155,10 +156,10 @@ static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
155 dp->dccps_l_ack_ratio = val; 156 dp->dccps_l_ack_ratio = val;
156} 157}
157 158
158static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val) 159static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hc, long val)
159{ 160{
160 ccid2_pr_debug("change SRTT to %ld\n", val); 161 ccid2_pr_debug("change SRTT to %ld\n", val);
161 hctx->ccid2hctx_srtt = val; 162 hc->tx_srtt = val;
162} 163}
163 164
164static void ccid2_start_rto_timer(struct sock *sk); 165static void ccid2_start_rto_timer(struct sock *sk);
@@ -166,45 +167,44 @@ static void ccid2_start_rto_timer(struct sock *sk);
166static void ccid2_hc_tx_rto_expire(unsigned long data) 167static void ccid2_hc_tx_rto_expire(unsigned long data)
167{ 168{
168 struct sock *sk = (struct sock *)data; 169 struct sock *sk = (struct sock *)data;
169 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 170 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
170 long s; 171 long s;
171 172
172 bh_lock_sock(sk); 173 bh_lock_sock(sk);
173 if (sock_owned_by_user(sk)) { 174 if (sock_owned_by_user(sk)) {
174 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, 175 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + HZ / 5);
175 jiffies + HZ / 5);
176 goto out; 176 goto out;
177 } 177 }
178 178
179 ccid2_pr_debug("RTO_EXPIRE\n"); 179 ccid2_pr_debug("RTO_EXPIRE\n");
180 180
181 ccid2_hc_tx_check_sanity(hctx); 181 ccid2_hc_tx_check_sanity(hc);
182 182
183 /* back-off timer */ 183 /* back-off timer */
184 hctx->ccid2hctx_rto <<= 1; 184 hc->tx_rto <<= 1;
185 185
186 s = hctx->ccid2hctx_rto / HZ; 186 s = hc->tx_rto / HZ;
187 if (s > 60) 187 if (s > 60)
188 hctx->ccid2hctx_rto = 60 * HZ; 188 hc->tx_rto = 60 * HZ;
189 189
190 ccid2_start_rto_timer(sk); 190 ccid2_start_rto_timer(sk);
191 191
192 /* adjust pipe, cwnd etc */ 192 /* adjust pipe, cwnd etc */
193 hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd / 2; 193 hc->tx_ssthresh = hc->tx_cwnd / 2;
194 if (hctx->ccid2hctx_ssthresh < 2) 194 if (hc->tx_ssthresh < 2)
195 hctx->ccid2hctx_ssthresh = 2; 195 hc->tx_ssthresh = 2;
196 hctx->ccid2hctx_cwnd = 1; 196 hc->tx_cwnd = 1;
197 hctx->ccid2hctx_pipe = 0; 197 hc->tx_pipe = 0;
198 198
199 /* clear state about stuff we sent */ 199 /* clear state about stuff we sent */
200 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh; 200 hc->tx_seqt = hc->tx_seqh;
201 hctx->ccid2hctx_packets_acked = 0; 201 hc->tx_packets_acked = 0;
202 202
203 /* clear ack ratio state. */ 203 /* clear ack ratio state. */
204 hctx->ccid2hctx_rpseq = 0; 204 hc->tx_rpseq = 0;
205 hctx->ccid2hctx_rpdupack = -1; 205 hc->tx_rpdupack = -1;
206 ccid2_change_l_ack_ratio(sk, 1); 206 ccid2_change_l_ack_ratio(sk, 1);
207 ccid2_hc_tx_check_sanity(hctx); 207 ccid2_hc_tx_check_sanity(hc);
208out: 208out:
209 bh_unlock_sock(sk); 209 bh_unlock_sock(sk);
210 sock_put(sk); 210 sock_put(sk);
@@ -212,42 +212,40 @@ out:
212 212
213static void ccid2_start_rto_timer(struct sock *sk) 213static void ccid2_start_rto_timer(struct sock *sk)
214{ 214{
215 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 215 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
216 216
217 ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto); 217 ccid2_pr_debug("setting RTO timeout=%ld\n", hc->tx_rto);
218 218
219 BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer)); 219 BUG_ON(timer_pending(&hc->tx_rtotimer));
220 sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, 220 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
221 jiffies + hctx->ccid2hctx_rto);
222} 221}
223 222
224static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) 223static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
225{ 224{
226 struct dccp_sock *dp = dccp_sk(sk); 225 struct dccp_sock *dp = dccp_sk(sk);
227 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 226 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
228 struct ccid2_seq *next; 227 struct ccid2_seq *next;
229 228
230 hctx->ccid2hctx_pipe++; 229 hc->tx_pipe++;
231 230
232 hctx->ccid2hctx_seqh->ccid2s_seq = dp->dccps_gss; 231 hc->tx_seqh->ccid2s_seq = dp->dccps_gss;
233 hctx->ccid2hctx_seqh->ccid2s_acked = 0; 232 hc->tx_seqh->ccid2s_acked = 0;
234 hctx->ccid2hctx_seqh->ccid2s_sent = jiffies; 233 hc->tx_seqh->ccid2s_sent = jiffies;
235 234
236 next = hctx->ccid2hctx_seqh->ccid2s_next; 235 next = hc->tx_seqh->ccid2s_next;
237 /* check if we need to alloc more space */ 236 /* check if we need to alloc more space */
238 if (next == hctx->ccid2hctx_seqt) { 237 if (next == hc->tx_seqt) {
239 if (ccid2_hc_tx_alloc_seq(hctx)) { 238 if (ccid2_hc_tx_alloc_seq(hc)) {
240 DCCP_CRIT("packet history - out of memory!"); 239 DCCP_CRIT("packet history - out of memory!");
241 /* FIXME: find a more graceful way to bail out */ 240 /* FIXME: find a more graceful way to bail out */
242 return; 241 return;
243 } 242 }
244 next = hctx->ccid2hctx_seqh->ccid2s_next; 243 next = hc->tx_seqh->ccid2s_next;
245 BUG_ON(next == hctx->ccid2hctx_seqt); 244 BUG_ON(next == hc->tx_seqt);
246 } 245 }
247 hctx->ccid2hctx_seqh = next; 246 hc->tx_seqh = next;
248 247
249 ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd, 248 ccid2_pr_debug("cwnd=%d pipe=%d\n", hc->tx_cwnd, hc->tx_pipe);
250 hctx->ccid2hctx_pipe);
251 249
252 /* 250 /*
253 * FIXME: The code below is broken and the variables have been removed 251 * FIXME: The code below is broken and the variables have been removed
@@ -270,12 +268,12 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
270 */ 268 */
271#if 0 269#if 0
272 /* Ack Ratio. Need to maintain a concept of how many windows we sent */ 270 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
273 hctx->ccid2hctx_arsent++; 271 hc->tx_arsent++;
274 /* We had an ack loss in this window... */ 272 /* We had an ack loss in this window... */
275 if (hctx->ccid2hctx_ackloss) { 273 if (hc->tx_ackloss) {
276 if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) { 274 if (hc->tx_arsent >= hc->tx_cwnd) {
277 hctx->ccid2hctx_arsent = 0; 275 hc->tx_arsent = 0;
278 hctx->ccid2hctx_ackloss = 0; 276 hc->tx_ackloss = 0;
279 } 277 }
280 } else { 278 } else {
281 /* No acks lost up to now... */ 279 /* No acks lost up to now... */
@@ -285,28 +283,28 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
285 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio - 283 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
286 dp->dccps_l_ack_ratio; 284 dp->dccps_l_ack_ratio;
287 285
288 denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom; 286 denom = hc->tx_cwnd * hc->tx_cwnd / denom;
289 287
290 if (hctx->ccid2hctx_arsent >= denom) { 288 if (hc->tx_arsent >= denom) {
291 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1); 289 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
292 hctx->ccid2hctx_arsent = 0; 290 hc->tx_arsent = 0;
293 } 291 }
294 } else { 292 } else {
295 /* we can't increase ack ratio further [1] */ 293 /* we can't increase ack ratio further [1] */
296 hctx->ccid2hctx_arsent = 0; /* or maybe set it to cwnd*/ 294 hc->tx_arsent = 0; /* or maybe set it to cwnd*/
297 } 295 }
298 } 296 }
299#endif 297#endif
300 298
301 /* setup RTO timer */ 299 /* setup RTO timer */
302 if (!timer_pending(&hctx->ccid2hctx_rtotimer)) 300 if (!timer_pending(&hc->tx_rtotimer))
303 ccid2_start_rto_timer(sk); 301 ccid2_start_rto_timer(sk);
304 302
305#ifdef CONFIG_IP_DCCP_CCID2_DEBUG 303#ifdef CONFIG_IP_DCCP_CCID2_DEBUG
306 do { 304 do {
307 struct ccid2_seq *seqp = hctx->ccid2hctx_seqt; 305 struct ccid2_seq *seqp = hc->tx_seqt;
308 306
309 while (seqp != hctx->ccid2hctx_seqh) { 307 while (seqp != hc->tx_seqh) {
310 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n", 308 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
311 (unsigned long long)seqp->ccid2s_seq, 309 (unsigned long long)seqp->ccid2s_seq,
312 seqp->ccid2s_acked, seqp->ccid2s_sent); 310 seqp->ccid2s_acked, seqp->ccid2s_sent);
@@ -314,7 +312,7 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
314 } 312 }
315 } while (0); 313 } while (0);
316 ccid2_pr_debug("=========\n"); 314 ccid2_pr_debug("=========\n");
317 ccid2_hc_tx_check_sanity(hctx); 315 ccid2_hc_tx_check_sanity(hc);
318#endif 316#endif
319} 317}
320 318
@@ -382,9 +380,9 @@ out_invalid_option:
382 380
383static void ccid2_hc_tx_kill_rto_timer(struct sock *sk) 381static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
384{ 382{
385 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 383 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
386 384
387 sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer); 385 sk_stop_timer(sk, &hc->tx_rtotimer);
388 ccid2_pr_debug("deleted RTO timer\n"); 386 ccid2_pr_debug("deleted RTO timer\n");
389} 387}
390 388
@@ -392,75 +390,75 @@ static inline void ccid2_new_ack(struct sock *sk,
392 struct ccid2_seq *seqp, 390 struct ccid2_seq *seqp,
393 unsigned int *maxincr) 391 unsigned int *maxincr)
394{ 392{
395 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 393 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
396 394
397 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) { 395 if (hc->tx_cwnd < hc->tx_ssthresh) {
398 if (*maxincr > 0 && ++hctx->ccid2hctx_packets_acked == 2) { 396 if (*maxincr > 0 && ++hc->tx_packets_acked == 2) {
399 hctx->ccid2hctx_cwnd += 1; 397 hc->tx_cwnd += 1;
400 *maxincr -= 1; 398 *maxincr -= 1;
401 hctx->ccid2hctx_packets_acked = 0; 399 hc->tx_packets_acked = 0;
402 } 400 }
403 } else if (++hctx->ccid2hctx_packets_acked >= hctx->ccid2hctx_cwnd) { 401 } else if (++hc->tx_packets_acked >= hc->tx_cwnd) {
404 hctx->ccid2hctx_cwnd += 1; 402 hc->tx_cwnd += 1;
405 hctx->ccid2hctx_packets_acked = 0; 403 hc->tx_packets_acked = 0;
406 } 404 }
407 405
408 /* update RTO */ 406 /* update RTO */
409 if (hctx->ccid2hctx_srtt == -1 || 407 if (hc->tx_srtt == -1 ||
410 time_after(jiffies, hctx->ccid2hctx_lastrtt + hctx->ccid2hctx_srtt)) { 408 time_after(jiffies, hc->tx_lastrtt + hc->tx_srtt)) {
411 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent; 409 unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent;
412 int s; 410 int s;
413 411
414 /* first measurement */ 412 /* first measurement */
415 if (hctx->ccid2hctx_srtt == -1) { 413 if (hc->tx_srtt == -1) {
416 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n", 414 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
417 r, jiffies, 415 r, jiffies,
418 (unsigned long long)seqp->ccid2s_seq); 416 (unsigned long long)seqp->ccid2s_seq);
419 ccid2_change_srtt(hctx, r); 417 ccid2_change_srtt(hc, r);
420 hctx->ccid2hctx_rttvar = r >> 1; 418 hc->tx_rttvar = r >> 1;
421 } else { 419 } else {
422 /* RTTVAR */ 420 /* RTTVAR */
423 long tmp = hctx->ccid2hctx_srtt - r; 421 long tmp = hc->tx_srtt - r;
424 long srtt; 422 long srtt;
425 423
426 if (tmp < 0) 424 if (tmp < 0)
427 tmp *= -1; 425 tmp *= -1;
428 426
429 tmp >>= 2; 427 tmp >>= 2;
430 hctx->ccid2hctx_rttvar *= 3; 428 hc->tx_rttvar *= 3;
431 hctx->ccid2hctx_rttvar >>= 2; 429 hc->tx_rttvar >>= 2;
432 hctx->ccid2hctx_rttvar += tmp; 430 hc->tx_rttvar += tmp;
433 431
434 /* SRTT */ 432 /* SRTT */
435 srtt = hctx->ccid2hctx_srtt; 433 srtt = hc->tx_srtt;
436 srtt *= 7; 434 srtt *= 7;
437 srtt >>= 3; 435 srtt >>= 3;
438 tmp = r >> 3; 436 tmp = r >> 3;
439 srtt += tmp; 437 srtt += tmp;
440 ccid2_change_srtt(hctx, srtt); 438 ccid2_change_srtt(hc, srtt);
441 } 439 }
442 s = hctx->ccid2hctx_rttvar << 2; 440 s = hc->tx_rttvar << 2;
443 /* clock granularity is 1 when based on jiffies */ 441 /* clock granularity is 1 when based on jiffies */
444 if (!s) 442 if (!s)
445 s = 1; 443 s = 1;
446 hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s; 444 hc->tx_rto = hc->tx_srtt + s;
447 445
448 /* must be at least a second */ 446 /* must be at least a second */
449 s = hctx->ccid2hctx_rto / HZ; 447 s = hc->tx_rto / HZ;
450 /* DCCP doesn't require this [but I like it cuz my code sux] */ 448 /* DCCP doesn't require this [but I like it cuz my code sux] */
451#if 1 449#if 1
452 if (s < 1) 450 if (s < 1)
453 hctx->ccid2hctx_rto = HZ; 451 hc->tx_rto = HZ;
454#endif 452#endif
455 /* max 60 seconds */ 453 /* max 60 seconds */
456 if (s > 60) 454 if (s > 60)
457 hctx->ccid2hctx_rto = HZ * 60; 455 hc->tx_rto = HZ * 60;
458 456
459 hctx->ccid2hctx_lastrtt = jiffies; 457 hc->tx_lastrtt = jiffies;
460 458
461 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n", 459 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
462 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, 460 hc->tx_srtt, hc->tx_rttvar,
463 hctx->ccid2hctx_rto, HZ, r); 461 hc->tx_rto, HZ, r);
464 } 462 }
465 463
466 /* we got a new ack, so re-start RTO timer */ 464 /* we got a new ack, so re-start RTO timer */
@@ -470,40 +468,40 @@ static inline void ccid2_new_ack(struct sock *sk,
470 468
471static void ccid2_hc_tx_dec_pipe(struct sock *sk) 469static void ccid2_hc_tx_dec_pipe(struct sock *sk)
472{ 470{
473 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 471 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
474 472
475 if (hctx->ccid2hctx_pipe == 0) 473 if (hc->tx_pipe == 0)
476 DCCP_BUG("pipe == 0"); 474 DCCP_BUG("pipe == 0");
477 else 475 else
478 hctx->ccid2hctx_pipe--; 476 hc->tx_pipe--;
479 477
480 if (hctx->ccid2hctx_pipe == 0) 478 if (hc->tx_pipe == 0)
481 ccid2_hc_tx_kill_rto_timer(sk); 479 ccid2_hc_tx_kill_rto_timer(sk);
482} 480}
483 481
484static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp) 482static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
485{ 483{
486 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 484 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
487 485
488 if (time_before(seqp->ccid2s_sent, hctx->ccid2hctx_last_cong)) { 486 if (time_before(seqp->ccid2s_sent, hc->tx_last_cong)) {
489 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n"); 487 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
490 return; 488 return;
491 } 489 }
492 490
493 hctx->ccid2hctx_last_cong = jiffies; 491 hc->tx_last_cong = jiffies;
494 492
495 hctx->ccid2hctx_cwnd = hctx->ccid2hctx_cwnd / 2 ? : 1U; 493 hc->tx_cwnd = hc->tx_cwnd / 2 ? : 1U;
496 hctx->ccid2hctx_ssthresh = max(hctx->ccid2hctx_cwnd, 2U); 494 hc->tx_ssthresh = max(hc->tx_cwnd, 2U);
497 495
498 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */ 496 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
499 if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->ccid2hctx_cwnd) 497 if (dccp_sk(sk)->dccps_l_ack_ratio > hc->tx_cwnd)
500 ccid2_change_l_ack_ratio(sk, hctx->ccid2hctx_cwnd); 498 ccid2_change_l_ack_ratio(sk, hc->tx_cwnd);
501} 499}
502 500
503static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 501static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
504{ 502{
505 struct dccp_sock *dp = dccp_sk(sk); 503 struct dccp_sock *dp = dccp_sk(sk);
506 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 504 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
507 u64 ackno, seqno; 505 u64 ackno, seqno;
508 struct ccid2_seq *seqp; 506 struct ccid2_seq *seqp;
509 unsigned char *vector; 507 unsigned char *vector;
@@ -512,7 +510,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
512 int done = 0; 510 int done = 0;
513 unsigned int maxincr = 0; 511 unsigned int maxincr = 0;
514 512
515 ccid2_hc_tx_check_sanity(hctx); 513 ccid2_hc_tx_check_sanity(hc);
516 /* check reverse path congestion */ 514 /* check reverse path congestion */
517 seqno = DCCP_SKB_CB(skb)->dccpd_seq; 515 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
518 516
@@ -521,21 +519,21 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
521 * -sorbo. 519 * -sorbo.
522 */ 520 */
523 /* need to bootstrap */ 521 /* need to bootstrap */
524 if (hctx->ccid2hctx_rpdupack == -1) { 522 if (hc->tx_rpdupack == -1) {
525 hctx->ccid2hctx_rpdupack = 0; 523 hc->tx_rpdupack = 0;
526 hctx->ccid2hctx_rpseq = seqno; 524 hc->tx_rpseq = seqno;
527 } else { 525 } else {
528 /* check if packet is consecutive */ 526 /* check if packet is consecutive */
529 if (dccp_delta_seqno(hctx->ccid2hctx_rpseq, seqno) == 1) 527 if (dccp_delta_seqno(hc->tx_rpseq, seqno) == 1)
530 hctx->ccid2hctx_rpseq = seqno; 528 hc->tx_rpseq = seqno;
531 /* it's a later packet */ 529 /* it's a later packet */
532 else if (after48(seqno, hctx->ccid2hctx_rpseq)) { 530 else if (after48(seqno, hc->tx_rpseq)) {
533 hctx->ccid2hctx_rpdupack++; 531 hc->tx_rpdupack++;
534 532
535 /* check if we got enough dupacks */ 533 /* check if we got enough dupacks */
536 if (hctx->ccid2hctx_rpdupack >= NUMDUPACK) { 534 if (hc->tx_rpdupack >= NUMDUPACK) {
537 hctx->ccid2hctx_rpdupack = -1; /* XXX lame */ 535 hc->tx_rpdupack = -1; /* XXX lame */
538 hctx->ccid2hctx_rpseq = 0; 536 hc->tx_rpseq = 0;
539 537
540 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio); 538 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
541 } 539 }
@@ -544,7 +542,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
544 542
545 /* check forward path congestion */ 543 /* check forward path congestion */
546 /* still didn't send out new data packets */ 544 /* still didn't send out new data packets */
547 if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt) 545 if (hc->tx_seqh == hc->tx_seqt)
548 return; 546 return;
549 547
550 switch (DCCP_SKB_CB(skb)->dccpd_type) { 548 switch (DCCP_SKB_CB(skb)->dccpd_type) {
@@ -556,14 +554,14 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
556 } 554 }
557 555
558 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq; 556 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
559 if (after48(ackno, hctx->ccid2hctx_high_ack)) 557 if (after48(ackno, hc->tx_high_ack))
560 hctx->ccid2hctx_high_ack = ackno; 558 hc->tx_high_ack = ackno;
561 559
562 seqp = hctx->ccid2hctx_seqt; 560 seqp = hc->tx_seqt;
563 while (before48(seqp->ccid2s_seq, ackno)) { 561 while (before48(seqp->ccid2s_seq, ackno)) {
564 seqp = seqp->ccid2s_next; 562 seqp = seqp->ccid2s_next;
565 if (seqp == hctx->ccid2hctx_seqh) { 563 if (seqp == hc->tx_seqh) {
566 seqp = hctx->ccid2hctx_seqh->ccid2s_prev; 564 seqp = hc->tx_seqh->ccid2s_prev;
567 break; 565 break;
568 } 566 }
569 } 567 }
@@ -573,7 +571,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
573 * packets per acknowledgement. Rounding up avoids that cwnd is not 571 * packets per acknowledgement. Rounding up avoids that cwnd is not
574 * advanced when Ack Ratio is 1 and gives a slight edge otherwise. 572 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
575 */ 573 */
576 if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) 574 if (hc->tx_cwnd < hc->tx_ssthresh)
577 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2); 575 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
578 576
579 /* go through all ack vectors */ 577 /* go through all ack vectors */
@@ -592,7 +590,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
592 * seqnos. 590 * seqnos.
593 */ 591 */
594 while (after48(seqp->ccid2s_seq, ackno)) { 592 while (after48(seqp->ccid2s_seq, ackno)) {
595 if (seqp == hctx->ccid2hctx_seqt) { 593 if (seqp == hc->tx_seqt) {
596 done = 1; 594 done = 1;
597 break; 595 break;
598 } 596 }
@@ -624,7 +622,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
624 (unsigned long long)seqp->ccid2s_seq); 622 (unsigned long long)seqp->ccid2s_seq);
625 ccid2_hc_tx_dec_pipe(sk); 623 ccid2_hc_tx_dec_pipe(sk);
626 } 624 }
627 if (seqp == hctx->ccid2hctx_seqt) { 625 if (seqp == hc->tx_seqt) {
628 done = 1; 626 done = 1;
629 break; 627 break;
630 } 628 }
@@ -643,11 +641,11 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
643 /* The state about what is acked should be correct now 641 /* The state about what is acked should be correct now
644 * Check for NUMDUPACK 642 * Check for NUMDUPACK
645 */ 643 */
646 seqp = hctx->ccid2hctx_seqt; 644 seqp = hc->tx_seqt;
647 while (before48(seqp->ccid2s_seq, hctx->ccid2hctx_high_ack)) { 645 while (before48(seqp->ccid2s_seq, hc->tx_high_ack)) {
648 seqp = seqp->ccid2s_next; 646 seqp = seqp->ccid2s_next;
649 if (seqp == hctx->ccid2hctx_seqh) { 647 if (seqp == hc->tx_seqh) {
650 seqp = hctx->ccid2hctx_seqh->ccid2s_prev; 648 seqp = hc->tx_seqh->ccid2s_prev;
651 break; 649 break;
652 } 650 }
653 } 651 }
@@ -658,7 +656,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
658 if (done == NUMDUPACK) 656 if (done == NUMDUPACK)
659 break; 657 break;
660 } 658 }
661 if (seqp == hctx->ccid2hctx_seqt) 659 if (seqp == hc->tx_seqt)
662 break; 660 break;
663 seqp = seqp->ccid2s_prev; 661 seqp = seqp->ccid2s_prev;
664 } 662 }
@@ -681,86 +679,86 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
681 ccid2_congestion_event(sk, seqp); 679 ccid2_congestion_event(sk, seqp);
682 ccid2_hc_tx_dec_pipe(sk); 680 ccid2_hc_tx_dec_pipe(sk);
683 } 681 }
684 if (seqp == hctx->ccid2hctx_seqt) 682 if (seqp == hc->tx_seqt)
685 break; 683 break;
686 seqp = seqp->ccid2s_prev; 684 seqp = seqp->ccid2s_prev;
687 } 685 }
688 686
689 hctx->ccid2hctx_seqt = last_acked; 687 hc->tx_seqt = last_acked;
690 } 688 }
691 689
692 /* trim acked packets in tail */ 690 /* trim acked packets in tail */
693 while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) { 691 while (hc->tx_seqt != hc->tx_seqh) {
694 if (!hctx->ccid2hctx_seqt->ccid2s_acked) 692 if (!hc->tx_seqt->ccid2s_acked)
695 break; 693 break;
696 694
697 hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next; 695 hc->tx_seqt = hc->tx_seqt->ccid2s_next;
698 } 696 }
699 697
700 ccid2_hc_tx_check_sanity(hctx); 698 ccid2_hc_tx_check_sanity(hc);
701} 699}
702 700
703static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) 701static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
704{ 702{
705 struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid); 703 struct ccid2_hc_tx_sock *hc = ccid_priv(ccid);
706 struct dccp_sock *dp = dccp_sk(sk); 704 struct dccp_sock *dp = dccp_sk(sk);
707 u32 max_ratio; 705 u32 max_ratio;
708 706
709 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */ 707 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
710 hctx->ccid2hctx_ssthresh = ~0U; 708 hc->tx_ssthresh = ~0U;
711 709
712 /* 710 /*
713 * RFC 4341, 5: "The cwnd parameter is initialized to at most four 711 * RFC 4341, 5: "The cwnd parameter is initialized to at most four
714 * packets for new connections, following the rules from [RFC3390]". 712 * packets for new connections, following the rules from [RFC3390]".
715 * We need to convert the bytes of RFC3390 into the packets of RFC 4341. 713 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
716 */ 714 */
717 hctx->ccid2hctx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U); 715 hc->tx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
718 716
719 /* Make sure that Ack Ratio is enabled and within bounds. */ 717 /* Make sure that Ack Ratio is enabled and within bounds. */
720 max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2); 718 max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2);
721 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio) 719 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
722 dp->dccps_l_ack_ratio = max_ratio; 720 dp->dccps_l_ack_ratio = max_ratio;
723 721
724 /* XXX init ~ to window size... */ 722 /* XXX init ~ to window size... */
725 if (ccid2_hc_tx_alloc_seq(hctx)) 723 if (ccid2_hc_tx_alloc_seq(hc))
726 return -ENOMEM; 724 return -ENOMEM;
727 725
728 hctx->ccid2hctx_rto = 3 * HZ; 726 hc->tx_rto = 3 * HZ;
729 ccid2_change_srtt(hctx, -1); 727 ccid2_change_srtt(hc, -1);
730 hctx->ccid2hctx_rttvar = -1; 728 hc->tx_rttvar = -1;
731 hctx->ccid2hctx_rpdupack = -1; 729 hc->tx_rpdupack = -1;
732 hctx->ccid2hctx_last_cong = jiffies; 730 hc->tx_last_cong = jiffies;
733 setup_timer(&hctx->ccid2hctx_rtotimer, ccid2_hc_tx_rto_expire, 731 setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire,
734 (unsigned long)sk); 732 (unsigned long)sk);
735 733
736 ccid2_hc_tx_check_sanity(hctx); 734 ccid2_hc_tx_check_sanity(hc);
737 return 0; 735 return 0;
738} 736}
739 737
740static void ccid2_hc_tx_exit(struct sock *sk) 738static void ccid2_hc_tx_exit(struct sock *sk)
741{ 739{
742 struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); 740 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
743 int i; 741 int i;
744 742
745 ccid2_hc_tx_kill_rto_timer(sk); 743 ccid2_hc_tx_kill_rto_timer(sk);
746 744
747 for (i = 0; i < hctx->ccid2hctx_seqbufc; i++) 745 for (i = 0; i < hc->tx_seqbufc; i++)
748 kfree(hctx->ccid2hctx_seqbuf[i]); 746 kfree(hc->tx_seqbuf[i]);
749 hctx->ccid2hctx_seqbufc = 0; 747 hc->tx_seqbufc = 0;
750} 748}
751 749
752static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 750static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
753{ 751{
754 const struct dccp_sock *dp = dccp_sk(sk); 752 const struct dccp_sock *dp = dccp_sk(sk);
755 struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk); 753 struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk);
756 754
757 switch (DCCP_SKB_CB(skb)->dccpd_type) { 755 switch (DCCP_SKB_CB(skb)->dccpd_type) {
758 case DCCP_PKT_DATA: 756 case DCCP_PKT_DATA:
759 case DCCP_PKT_DATAACK: 757 case DCCP_PKT_DATAACK:
760 hcrx->ccid2hcrx_data++; 758 hc->rx_data++;
761 if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) { 759 if (hc->rx_data >= dp->dccps_r_ack_ratio) {
762 dccp_send_ack(sk); 760 dccp_send_ack(sk);
763 hcrx->ccid2hcrx_data = 0; 761 hc->rx_data = 0;
764 } 762 }
765 break; 763 break;
766 } 764 }