Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 1 | /* |
| 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 Renker | 0e64e94 | 2006-10-24 16:17:51 -0700 | [diff] [blame] | 26 | * This implementation should follow RFC 4341 |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 27 | */ |
Gerrit Renker | 86349c8 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 28 | #include "../feat.h" |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 29 | #include "../ccid.h" |
| 30 | #include "../dccp.h" |
| 31 | #include "ccid2.h" |
| 32 | |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 33 | |
| 34 | #ifdef CONFIG_IP_DCCP_CCID2_DEBUG |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 35 | static int ccid2_debug; |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 36 | #define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 37 | #else |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 38 | #define ccid2_pr_debug(format, a...) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 39 | #endif |
| 40 | |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 41 | static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx) |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 42 | { |
| 43 | struct ccid2_seq *seqp; |
| 44 | int i; |
| 45 | |
| 46 | /* check if we have space to preserve the pointer to the buffer */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 47 | if (hctx->seqbufc >= sizeof(hctx->seqbuf) / sizeof(struct ccid2_seq *)) |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 48 | return -ENOMEM; |
| 49 | |
| 50 | /* allocate buffer and initialize linked list */ |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 51 | seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any()); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 52 | if (seqp == NULL) |
| 53 | return -ENOMEM; |
| 54 | |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 55 | for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) { |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 56 | seqp[i].ccid2s_next = &seqp[i + 1]; |
| 57 | seqp[i + 1].ccid2s_prev = &seqp[i]; |
| 58 | } |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 59 | seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp; |
| 60 | seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 61 | |
| 62 | /* This is the first allocation. Initiate the head and tail. */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 63 | if (hctx->seqbufc == 0) |
| 64 | hctx->seqh = hctx->seqt = seqp; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 65 | else { |
| 66 | /* link the existing list with the one we just created */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 67 | hctx->seqh->ccid2s_next = seqp; |
| 68 | seqp->ccid2s_prev = hctx->seqh; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 69 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 70 | hctx->seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; |
| 71 | seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->seqt; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* store the original pointer to the buffer so we can free it */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 75 | hctx->seqbuf[hctx->seqbufc] = seqp; |
| 76 | hctx->seqbufc++; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Gerrit Renker | 6b57c93 | 2006-11-28 19:55:06 -0200 | [diff] [blame] | 81 | static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 82 | { |
Gerrit Renker | 83337da | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 83 | if (ccid2_cwnd_network_limited(ccid2_hc_tx_sk(sk))) |
| 84 | return CCID_PACKET_WILL_DEQUEUE_LATER; |
| 85 | return CCID_PACKET_SEND_AT_ONCE; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 88 | static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 89 | { |
| 90 | struct dccp_sock *dp = dccp_sk(sk); |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 91 | u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->cwnd, 2); |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 92 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 93 | /* |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 94 | * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from |
| 95 | * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always |
| 96 | * acceptable since this causes starvation/deadlock whenever cwnd < 2. |
| 97 | * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled). |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 98 | */ |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 99 | if (val == 0 || val > max_ratio) { |
| 100 | DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio); |
| 101 | val = max_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 102 | } |
Gerrit Renker | 86349c8 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 103 | if (val > DCCPF_ACK_RATIO_MAX) |
| 104 | val = DCCPF_ACK_RATIO_MAX; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 105 | |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 106 | if (val == dp->dccps_l_ack_ratio) |
| 107 | return; |
| 108 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 109 | ccid2_pr_debug("changing local ack ratio to %u\n", val); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 110 | dp->dccps_l_ack_ratio = val; |
| 111 | } |
| 112 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 113 | static void ccid2_start_rto_timer(struct sock *sk); |
| 114 | |
| 115 | static void ccid2_hc_tx_rto_expire(unsigned long data) |
| 116 | { |
| 117 | struct sock *sk = (struct sock *)data; |
| 118 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Gerrit Renker | 83337da | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 119 | const bool sender_was_blocked = ccid2_cwnd_network_limited(hctx); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 120 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 121 | bh_lock_sock(sk); |
| 122 | if (sock_owned_by_user(sk)) { |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 123 | sk_reset_timer(sk, &hctx->rtotimer, jiffies + HZ / 5); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 124 | goto out; |
| 125 | } |
| 126 | |
| 127 | ccid2_pr_debug("RTO_EXPIRE\n"); |
| 128 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 129 | /* back-off timer */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 130 | hctx->rto <<= 1; |
Gerrit Renker | 1435562 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 131 | if (hctx->rto > DCCP_RTO_MAX) |
| 132 | hctx->rto = DCCP_RTO_MAX; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 133 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 134 | /* adjust pipe, cwnd etc */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 135 | hctx->ssthresh = hctx->cwnd / 2; |
| 136 | if (hctx->ssthresh < 2) |
| 137 | hctx->ssthresh = 2; |
| 138 | hctx->cwnd = 1; |
| 139 | hctx->pipe = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 140 | |
| 141 | /* clear state about stuff we sent */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 142 | hctx->seqt = hctx->seqh; |
| 143 | hctx->packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 144 | |
| 145 | /* clear ack ratio state. */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 146 | hctx->rpseq = 0; |
| 147 | hctx->rpdupack = -1; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 148 | ccid2_change_l_ack_ratio(sk, 1); |
Gerrit Renker | 83337da | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 149 | |
| 150 | /* if we were blocked before, we may now send cwnd=1 packet */ |
| 151 | if (sender_was_blocked) |
| 152 | tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet); |
| 153 | ccid2_start_rto_timer(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 154 | out: |
| 155 | bh_unlock_sock(sk); |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 156 | sock_put(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void ccid2_start_rto_timer(struct sock *sk) |
| 160 | { |
| 161 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 162 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 163 | ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->rto); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 164 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 165 | BUG_ON(timer_pending(&hctx->rtotimer)); |
| 166 | sk_reset_timer(sk, &hctx->rtotimer, |
| 167 | jiffies + hctx->rto); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Gerrit Renker | c506d91 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 170 | static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 171 | { |
| 172 | struct dccp_sock *dp = dccp_sk(sk); |
| 173 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 174 | struct ccid2_seq *next; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 175 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 176 | hctx->pipe++; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 177 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 178 | hctx->seqh->ccid2s_seq = dp->dccps_gss; |
| 179 | hctx->seqh->ccid2s_acked = 0; |
| 180 | hctx->seqh->ccid2s_sent = jiffies; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 181 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 182 | next = hctx->seqh->ccid2s_next; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 183 | /* check if we need to alloc more space */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 184 | if (next == hctx->seqt) { |
Gerrit Renker | 7d9e893 | 2007-10-04 14:41:26 -0700 | [diff] [blame] | 185 | if (ccid2_hc_tx_alloc_seq(hctx)) { |
| 186 | DCCP_CRIT("packet history - out of memory!"); |
| 187 | /* FIXME: find a more graceful way to bail out */ |
| 188 | return; |
| 189 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 190 | next = hctx->seqh->ccid2s_next; |
| 191 | BUG_ON(next == hctx->seqt); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 192 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 193 | hctx->seqh = next; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 194 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 195 | ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->cwnd, hctx->pipe); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 196 | |
Gerrit Renker | 900bfed | 2007-11-24 21:58:33 -0200 | [diff] [blame] | 197 | /* |
| 198 | * FIXME: The code below is broken and the variables have been removed |
| 199 | * from the socket struct. The `ackloss' variable was always set to 0, |
| 200 | * and with arsent there are several problems: |
| 201 | * (i) it doesn't just count the number of Acks, but all sent packets; |
| 202 | * (ii) it is expressed in # of packets, not # of windows, so the |
| 203 | * comparison below uses the wrong formula: Appendix A of RFC 4341 |
| 204 | * comes up with the number K = cwnd / (R^2 - R) of consecutive windows |
| 205 | * of data with no lost or marked Ack packets. If arsent were the # of |
| 206 | * consecutive Acks received without loss, then Ack Ratio needs to be |
| 207 | * decreased by 1 when |
| 208 | * arsent >= K * cwnd / R = cwnd^2 / (R^3 - R^2) |
| 209 | * where cwnd / R is the number of Acks received per window of data |
| 210 | * (cf. RFC 4341, App. A). The problems are that |
| 211 | * - arsent counts other packets as well; |
| 212 | * - the comparison uses a formula different from RFC 4341; |
| 213 | * - computing a cubic/quadratic equation each time is too complicated. |
| 214 | * Hence a different algorithm is needed. |
| 215 | */ |
| 216 | #if 0 |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 217 | /* Ack Ratio. Need to maintain a concept of how many windows we sent */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 218 | hctx->arsent++; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 219 | /* We had an ack loss in this window... */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 220 | if (hctx->ackloss) { |
| 221 | if (hctx->arsent >= hctx->cwnd) { |
| 222 | hctx->arsent = 0; |
| 223 | hctx->ackloss = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 224 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 225 | } else { |
| 226 | /* No acks lost up to now... */ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 227 | /* decrease ack ratio if enough packets were sent */ |
| 228 | if (dp->dccps_l_ack_ratio > 1) { |
| 229 | /* XXX don't calculate denominator each time */ |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 230 | int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio - |
| 231 | dp->dccps_l_ack_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 232 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 233 | denom = hctx->cwnd * hctx->cwnd / denom; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 234 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 235 | if (hctx->arsent >= denom) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 236 | ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1); |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 237 | hctx->arsent = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 238 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 239 | } else { |
| 240 | /* we can't increase ack ratio further [1] */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 241 | hctx->arsent = 0; /* or maybe set it to cwnd*/ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
Gerrit Renker | 900bfed | 2007-11-24 21:58:33 -0200 | [diff] [blame] | 244 | #endif |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 245 | |
| 246 | /* setup RTO timer */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 247 | if (!timer_pending(&hctx->rtotimer)) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 248 | ccid2_start_rto_timer(sk); |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 249 | |
Andrea Bittau | 8d424f6 | 2006-09-19 13:12:44 -0700 | [diff] [blame] | 250 | #ifdef CONFIG_IP_DCCP_CCID2_DEBUG |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 251 | do { |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 252 | struct ccid2_seq *seqp = hctx->seqt; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 253 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 254 | while (seqp != hctx->seqh) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 255 | ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n", |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 256 | (unsigned long long)seqp->ccid2s_seq, |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 257 | seqp->ccid2s_acked, seqp->ccid2s_sent); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 258 | seqp = seqp->ccid2s_next; |
| 259 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 260 | } while (0); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 261 | ccid2_pr_debug("=========\n"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 262 | #endif |
| 263 | } |
| 264 | |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 265 | static void ccid2_hc_tx_kill_rto_timer(struct sock *sk) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 266 | { |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 267 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 268 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 269 | sk_stop_timer(sk, &hctx->rtotimer); |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 270 | ccid2_pr_debug("deleted RTO timer\n"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Gerrit Renker | 1435562 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 273 | /** |
| 274 | * ccid2_rtt_estimator - Sample RTT and compute RTO using RFC2988 algorithm |
| 275 | * This code is almost identical with TCP's tcp_rtt_estimator(), since |
| 276 | * - it has a higher sampling frequency (recommended by RFC 1323), |
| 277 | * - the RTO does not collapse into RTT due to RTTVAR going towards zero, |
| 278 | * - it is simple (cf. more complex proposals such as Eifel timer or research |
| 279 | * which suggests that the gain should be set according to window size), |
| 280 | * - in tests it was found to work well with CCID2 [gerrit]. |
| 281 | */ |
| 282 | static void ccid2_rtt_estimator(struct sock *sk, const long mrtt) |
| 283 | { |
| 284 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 285 | long m = mrtt ? : 1; |
| 286 | |
| 287 | if (hctx->srtt == 0) { |
| 288 | /* First measurement m */ |
| 289 | hctx->srtt = m << 3; |
| 290 | hctx->mdev = m << 1; |
| 291 | |
| 292 | hctx->mdev_max = max(TCP_RTO_MIN, hctx->mdev); |
| 293 | hctx->rttvar = hctx->mdev_max; |
| 294 | hctx->rtt_seq = dccp_sk(sk)->dccps_gss; |
| 295 | } else { |
| 296 | /* Update scaled SRTT as SRTT += 1/8 * (m - SRTT) */ |
| 297 | m -= (hctx->srtt >> 3); |
| 298 | hctx->srtt += m; |
| 299 | |
| 300 | /* Similarly, update scaled mdev with regard to |m| */ |
| 301 | if (m < 0) { |
| 302 | m = -m; |
| 303 | m -= (hctx->mdev >> 2); |
| 304 | /* |
| 305 | * This neutralises RTO increase when RTT < SRTT - mdev |
| 306 | * (see P. Sarolahti, A. Kuznetsov,"Congestion Control |
| 307 | * in Linux TCP", USENIX 2002, pp. 49-62). |
| 308 | */ |
| 309 | if (m > 0) |
| 310 | m >>= 3; |
| 311 | } else { |
| 312 | m -= (hctx->mdev >> 2); |
| 313 | } |
| 314 | hctx->mdev += m; |
| 315 | |
| 316 | if (hctx->mdev > hctx->mdev_max) { |
| 317 | hctx->mdev_max = hctx->mdev; |
| 318 | if (hctx->mdev_max > hctx->rttvar) |
| 319 | hctx->rttvar = hctx->mdev_max; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Decay RTTVAR at most once per flight, exploiting that |
| 324 | * 1) pipe <= cwnd <= Sequence_Window = W (RFC 4340, 7.5.2) |
| 325 | * 2) AWL = GSS-W+1 <= GAR <= GSS (RFC 4340, 7.5.1) |
| 326 | * GAR is a useful bound for FlightSize = pipe, AWL is probably |
| 327 | * too low as it over-estimates pipe. |
| 328 | */ |
| 329 | if (after48(dccp_sk(sk)->dccps_gar, hctx->rtt_seq)) { |
| 330 | if (hctx->mdev_max < hctx->rttvar) |
| 331 | hctx->rttvar -= (hctx->rttvar - |
| 332 | hctx->mdev_max) >> 2; |
| 333 | hctx->rtt_seq = dccp_sk(sk)->dccps_gss; |
| 334 | hctx->mdev_max = TCP_RTO_MIN; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Set RTO from SRTT and RTTVAR |
| 340 | * Clock granularity is ignored since the minimum error for RTTVAR is |
| 341 | * clamped to 50msec (corresponding to HZ=20). This leads to a minimum |
| 342 | * RTO of 200msec. This agrees with TCP and RFC 4341, 5.: "Because DCCP |
| 343 | * does not retransmit data, DCCP does not require TCP's recommended |
| 344 | * minimum timeout of one second". |
| 345 | */ |
| 346 | hctx->rto = (hctx->srtt >> 3) + hctx->rttvar; |
| 347 | |
| 348 | if (hctx->rto > DCCP_RTO_MAX) |
| 349 | hctx->rto = DCCP_RTO_MAX; |
| 350 | } |
| 351 | |
| 352 | static void ccid2_new_ack(struct sock *sk, struct ccid2_seq *seqp, |
| 353 | unsigned int *maxincr) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 354 | { |
| 355 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 356 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 357 | if (hctx->cwnd < hctx->ssthresh) { |
| 358 | if (*maxincr > 0 && ++hctx->packets_acked == 2) { |
| 359 | hctx->cwnd += 1; |
| 360 | *maxincr -= 1; |
| 361 | hctx->packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 362 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 363 | } else if (++hctx->packets_acked >= hctx->cwnd) { |
| 364 | hctx->cwnd += 1; |
| 365 | hctx->packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 366 | } |
Gerrit Renker | 1435562 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 367 | /* |
| 368 | * FIXME: RTT is sampled several times per acknowledgment (for each |
| 369 | * entry in the Ack Vector), instead of once per Ack (as in TCP SACK). |
| 370 | * This causes the RTT to be over-estimated, since the older entries |
| 371 | * in the Ack Vector have earlier sending times. |
| 372 | * The cleanest solution is to not use the ccid2s_sent field at all |
| 373 | * and instead use DCCP timestamps - need to be resolved at some time. |
| 374 | */ |
| 375 | ccid2_rtt_estimator(sk, jiffies - seqp->ccid2s_sent); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 378 | static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp) |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 379 | { |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 380 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 381 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 382 | if (time_before(seqp->ccid2s_sent, hctx->last_cong)) { |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 383 | ccid2_pr_debug("Multiple losses in an RTT---treating as one\n"); |
| 384 | return; |
| 385 | } |
| 386 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 387 | hctx->last_cong = jiffies; |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 388 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 389 | hctx->cwnd = hctx->cwnd / 2 ? : 1U; |
| 390 | hctx->ssthresh = max(hctx->cwnd, 2U); |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 391 | |
| 392 | /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 393 | if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->cwnd) |
| 394 | ccid2_change_l_ack_ratio(sk, hctx->cwnd); |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 397 | static int ccid2_hc_tx_parse_options(struct sock *sk, u8 packet_type, |
| 398 | u8 option, u8 *optval, u8 optlen) |
| 399 | { |
| 400 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 401 | |
| 402 | switch (option) { |
| 403 | case DCCPO_ACK_VECTOR_0: |
| 404 | case DCCPO_ACK_VECTOR_1: |
| 405 | return dccp_ackvec_parsed_add(&hctx->av_chunks, optval, optlen, |
| 406 | option - DCCPO_ACK_VECTOR_0); |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 411 | static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 412 | { |
| 413 | struct dccp_sock *dp = dccp_sk(sk); |
| 414 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Gerrit Renker | 83337da | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 415 | const bool sender_was_blocked = ccid2_cwnd_network_limited(hctx); |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 416 | struct dccp_ackvec_parsed *avp; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 417 | u64 ackno, seqno; |
| 418 | struct ccid2_seq *seqp; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 419 | int done = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 420 | unsigned int maxincr = 0; |
| 421 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 422 | /* check reverse path congestion */ |
| 423 | seqno = DCCP_SKB_CB(skb)->dccpd_seq; |
| 424 | |
| 425 | /* XXX this whole "algorithm" is broken. Need to fix it to keep track |
| 426 | * of the seqnos of the dupacks so that rpseq and rpdupack are correct |
| 427 | * -sorbo. |
| 428 | */ |
| 429 | /* need to bootstrap */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 430 | if (hctx->rpdupack == -1) { |
| 431 | hctx->rpdupack = 0; |
| 432 | hctx->rpseq = seqno; |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 433 | } else { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 434 | /* check if packet is consecutive */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 435 | if (dccp_delta_seqno(hctx->rpseq, seqno) == 1) |
| 436 | hctx->rpseq = seqno; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 437 | /* it's a later packet */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 438 | else if (after48(seqno, hctx->rpseq)) { |
| 439 | hctx->rpdupack++; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 440 | |
| 441 | /* check if we got enough dupacks */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 442 | if (hctx->rpdupack >= NUMDUPACK) { |
| 443 | hctx->rpdupack = -1; /* XXX lame */ |
| 444 | hctx->rpseq = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 445 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 446 | ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /* check forward path congestion */ |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 452 | if (dccp_packet_without_ack(skb)) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 453 | return; |
| 454 | |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 455 | /* still didn't send out new data packets */ |
| 456 | if (hctx->seqh == hctx->seqt) |
| 457 | goto done; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 458 | |
| 459 | ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq; |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 460 | if (after48(ackno, hctx->high_ack)) |
| 461 | hctx->high_ack = ackno; |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 462 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 463 | seqp = hctx->seqt; |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 464 | while (before48(seqp->ccid2s_seq, ackno)) { |
| 465 | seqp = seqp->ccid2s_next; |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 466 | if (seqp == hctx->seqh) { |
| 467 | seqp = hctx->seqh->ccid2s_prev; |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | } |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 471 | |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame] | 472 | /* |
| 473 | * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2 |
| 474 | * packets per acknowledgement. Rounding up avoids that cwnd is not |
| 475 | * advanced when Ack Ratio is 1 and gives a slight edge otherwise. |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 476 | */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 477 | if (hctx->cwnd < hctx->ssthresh) |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame] | 478 | maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 479 | |
| 480 | /* go through all ack vectors */ |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 481 | list_for_each_entry(avp, &hctx->av_chunks, node) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 482 | /* go through this ack vector */ |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 483 | for (; avp->len--; avp->vec++) { |
| 484 | u64 ackno_end_rl = SUB48(ackno, |
| 485 | dccp_ackvec_runlen(avp->vec)); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 486 | |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 487 | ccid2_pr_debug("ackvec %llu |%u,%u|\n", |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 488 | (unsigned long long)ackno, |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 489 | dccp_ackvec_state(avp->vec) >> 6, |
| 490 | dccp_ackvec_runlen(avp->vec)); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 491 | /* if the seqno we are analyzing is larger than the |
| 492 | * current ackno, then move towards the tail of our |
| 493 | * seqnos. |
| 494 | */ |
| 495 | while (after48(seqp->ccid2s_seq, ackno)) { |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 496 | if (seqp == hctx->seqt) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 497 | done = 1; |
| 498 | break; |
| 499 | } |
| 500 | seqp = seqp->ccid2s_prev; |
| 501 | } |
| 502 | if (done) |
| 503 | break; |
| 504 | |
| 505 | /* check all seqnos in the range of the vector |
| 506 | * run length |
| 507 | */ |
| 508 | while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) { |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 509 | const u8 state = dccp_ackvec_state(avp->vec); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 510 | |
| 511 | /* new packet received or marked */ |
Gerrit Renker | ff49e27 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 512 | if (state != DCCPAV_NOT_RECEIVED && |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 513 | !seqp->ccid2s_acked) { |
Gerrit Renker | ff49e27 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 514 | if (state == DCCPAV_ECN_MARKED) |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 515 | ccid2_congestion_event(sk, |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 516 | seqp); |
Gerrit Renker | ff49e27 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 517 | else |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 518 | ccid2_new_ack(sk, seqp, |
| 519 | &maxincr); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 520 | |
| 521 | seqp->ccid2s_acked = 1; |
| 522 | ccid2_pr_debug("Got ack for %llu\n", |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 523 | (unsigned long long)seqp->ccid2s_seq); |
Gerrit Renker | e9803c0 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 524 | hctx->pipe--; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 525 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 526 | if (seqp == hctx->seqt) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 527 | done = 1; |
| 528 | break; |
| 529 | } |
Gerrit Renker | 3de5489 | 2007-11-24 20:37:48 -0200 | [diff] [blame] | 530 | seqp = seqp->ccid2s_prev; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 531 | } |
| 532 | if (done) |
| 533 | break; |
| 534 | |
Gerrit Renker | cfbbeab | 2007-11-24 20:43:59 -0200 | [diff] [blame] | 535 | ackno = SUB48(ackno_end_rl, 1); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 536 | } |
| 537 | if (done) |
| 538 | break; |
| 539 | } |
| 540 | |
| 541 | /* The state about what is acked should be correct now |
| 542 | * Check for NUMDUPACK |
| 543 | */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 544 | seqp = hctx->seqt; |
| 545 | while (before48(seqp->ccid2s_seq, hctx->high_ack)) { |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 546 | seqp = seqp->ccid2s_next; |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 547 | if (seqp == hctx->seqh) { |
| 548 | seqp = hctx->seqh->ccid2s_prev; |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | } |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 552 | done = 0; |
| 553 | while (1) { |
| 554 | if (seqp->ccid2s_acked) { |
| 555 | done++; |
Gerrit Renker | 63df18a | 2007-11-24 22:04:35 -0200 | [diff] [blame] | 556 | if (done == NUMDUPACK) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 557 | break; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 558 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 559 | if (seqp == hctx->seqt) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 560 | break; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 561 | seqp = seqp->ccid2s_prev; |
| 562 | } |
| 563 | |
| 564 | /* If there are at least 3 acknowledgements, anything unacknowledged |
| 565 | * below the last sequence number is considered lost |
| 566 | */ |
Gerrit Renker | 63df18a | 2007-11-24 22:04:35 -0200 | [diff] [blame] | 567 | if (done == NUMDUPACK) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 568 | struct ccid2_seq *last_acked = seqp; |
| 569 | |
| 570 | /* check for lost packets */ |
| 571 | while (1) { |
| 572 | if (!seqp->ccid2s_acked) { |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 573 | ccid2_pr_debug("Packet lost: %llu\n", |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 574 | (unsigned long long)seqp->ccid2s_seq); |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 575 | /* XXX need to traverse from tail -> head in |
| 576 | * order to detect multiple congestion events in |
| 577 | * one ack vector. |
| 578 | */ |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 579 | ccid2_congestion_event(sk, seqp); |
Gerrit Renker | e9803c0 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 580 | hctx->pipe--; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 581 | } |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 582 | if (seqp == hctx->seqt) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 583 | break; |
| 584 | seqp = seqp->ccid2s_prev; |
| 585 | } |
| 586 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 587 | hctx->seqt = last_acked; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /* trim acked packets in tail */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 591 | while (hctx->seqt != hctx->seqh) { |
| 592 | if (!hctx->seqt->ccid2s_acked) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 593 | break; |
| 594 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 595 | hctx->seqt = hctx->seqt->ccid2s_next; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 596 | } |
| 597 | |
Gerrit Renker | e9803c0 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 598 | /* restart RTO timer if not all outstanding data has been acked */ |
| 599 | if (hctx->pipe == 0) |
| 600 | sk_stop_timer(sk, &hctx->rtotimer); |
| 601 | else |
Gerrit Renker | 1435562 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 602 | sk_reset_timer(sk, &hctx->rtotimer, jiffies + hctx->rto); |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 603 | done: |
Gerrit Renker | 83337da | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 604 | /* check if incoming Acks allow pending packets to be sent */ |
| 605 | if (sender_was_blocked && !ccid2_cwnd_network_limited(hctx)) |
| 606 | tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet); |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 607 | dccp_ackvec_parsed_cleanup(&hctx->av_chunks); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 610 | static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 611 | { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 612 | struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid); |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 613 | struct dccp_sock *dp = dccp_sk(sk); |
| 614 | u32 max_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 615 | |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 616 | /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 617 | hctx->ssthresh = ~0U; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 618 | |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 619 | /* |
| 620 | * RFC 4341, 5: "The cwnd parameter is initialized to at most four |
| 621 | * packets for new connections, following the rules from [RFC3390]". |
| 622 | * We need to convert the bytes of RFC3390 into the packets of RFC 4341. |
| 623 | */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 624 | hctx->cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U); |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 625 | |
| 626 | /* Make sure that Ack Ratio is enabled and within bounds. */ |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 627 | max_ratio = DIV_ROUND_UP(hctx->cwnd, 2); |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 628 | if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio) |
| 629 | dp->dccps_l_ack_ratio = max_ratio; |
| 630 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 631 | /* XXX init ~ to window size... */ |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 632 | if (ccid2_hc_tx_alloc_seq(hctx)) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 633 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 634 | |
Gerrit Renker | 1435562 | 2008-09-04 07:30:19 +0200 | [diff] [blame^] | 635 | hctx->rto = DCCP_TIMEOUT_INIT; |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 636 | hctx->rpdupack = -1; |
| 637 | hctx->last_cong = jiffies; |
| 638 | setup_timer(&hctx->rtotimer, ccid2_hc_tx_rto_expire, (unsigned long)sk); |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 639 | INIT_LIST_HEAD(&hctx->av_chunks); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static void ccid2_hc_tx_exit(struct sock *sk) |
| 644 | { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 645 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 646 | int i; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 647 | |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 648 | ccid2_hc_tx_kill_rto_timer(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 649 | |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 650 | for (i = 0; i < hctx->seqbufc; i++) |
| 651 | kfree(hctx->seqbuf[i]); |
| 652 | hctx->seqbufc = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 656 | { |
| 657 | const struct dccp_sock *dp = dccp_sk(sk); |
| 658 | struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk); |
| 659 | |
| 660 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
| 661 | case DCCP_PKT_DATA: |
| 662 | case DCCP_PKT_DATAACK: |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 663 | hcrx->data++; |
| 664 | if (hcrx->data >= dp->dccps_r_ack_ratio) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 665 | dccp_send_ack(sk); |
Gerrit Renker | 1fb8750 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 666 | hcrx->data = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 667 | } |
| 668 | break; |
| 669 | } |
| 670 | } |
| 671 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 672 | static struct ccid_operations ccid2 = { |
Gerrit Renker | c8bf462 | 2008-09-04 07:30:19 +0200 | [diff] [blame] | 673 | .ccid_id = DCCPC_CCID2, |
| 674 | .ccid_name = "TCP-like", |
| 675 | .ccid_owner = THIS_MODULE, |
| 676 | .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock), |
| 677 | .ccid_hc_tx_init = ccid2_hc_tx_init, |
| 678 | .ccid_hc_tx_exit = ccid2_hc_tx_exit, |
| 679 | .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet, |
| 680 | .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent, |
| 681 | .ccid_hc_tx_parse_options = ccid2_hc_tx_parse_options, |
| 682 | .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv, |
| 683 | .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock), |
| 684 | .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv, |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 685 | }; |
| 686 | |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 687 | #ifdef CONFIG_IP_DCCP_CCID2_DEBUG |
Gerrit Renker | 4326499 | 2008-08-23 13:28:27 +0200 | [diff] [blame] | 688 | module_param(ccid2_debug, bool, 0644); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 689 | MODULE_PARM_DESC(ccid2_debug, "Enable debug messages"); |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 690 | #endif |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 691 | |
| 692 | static __init int ccid2_module_init(void) |
| 693 | { |
| 694 | return ccid_register(&ccid2); |
| 695 | } |
| 696 | module_init(ccid2_module_init); |
| 697 | |
| 698 | static __exit void ccid2_module_exit(void) |
| 699 | { |
| 700 | ccid_unregister(&ccid2); |
| 701 | } |
| 702 | module_exit(ccid2_module_exit); |
| 703 | |
| 704 | MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>"); |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 705 | MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 706 | MODULE_LICENSE("GPL"); |
| 707 | MODULE_ALIAS("net-dccp-ccid-2"); |