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 | */ |
| 28 | |
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 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 38 | static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx) |
| 39 | { |
| 40 | int len = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 41 | int pipe = 0; |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 42 | struct ccid2_seq *seqp = hctx->ccid2hctx_seqh; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 43 | |
| 44 | /* there is data in the chain */ |
| 45 | if (seqp != hctx->ccid2hctx_seqt) { |
| 46 | seqp = seqp->ccid2s_prev; |
| 47 | len++; |
| 48 | if (!seqp->ccid2s_acked) |
| 49 | pipe++; |
| 50 | |
| 51 | while (seqp != hctx->ccid2hctx_seqt) { |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 52 | struct ccid2_seq *prev = seqp->ccid2s_prev; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 53 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 54 | len++; |
| 55 | if (!prev->ccid2s_acked) |
| 56 | pipe++; |
| 57 | |
| 58 | /* packets are sent sequentially */ |
Gerrit Renker | 5e28599 | 2007-10-04 14:43:09 -0700 | [diff] [blame] | 59 | BUG_ON(dccp_delta_seqno(seqp->ccid2s_seq, |
| 60 | prev->ccid2s_seq ) >= 0); |
Andrea Bittau | 29651cd | 2006-09-19 13:06:46 -0700 | [diff] [blame] | 61 | BUG_ON(time_before(seqp->ccid2s_sent, |
| 62 | prev->ccid2s_sent)); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 63 | |
| 64 | seqp = prev; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | BUG_ON(pipe != hctx->ccid2hctx_pipe); |
| 69 | ccid2_pr_debug("len of chain=%d\n", len); |
| 70 | |
| 71 | do { |
| 72 | seqp = seqp->ccid2s_prev; |
| 73 | len++; |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 74 | } while (seqp != hctx->ccid2hctx_seqh); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 75 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 76 | ccid2_pr_debug("total len=%d\n", len); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 77 | BUG_ON(len != hctx->ccid2hctx_seqbufc * CCID2_SEQBUF_LEN); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 78 | } |
| 79 | #else |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 80 | #define ccid2_pr_debug(format, a...) |
| 81 | #define ccid2_hc_tx_check_sanity(hctx) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 82 | #endif |
| 83 | |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 84 | 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] | 85 | { |
| 86 | struct ccid2_seq *seqp; |
| 87 | int i; |
| 88 | |
| 89 | /* check if we have space to preserve the pointer to the buffer */ |
| 90 | if (hctx->ccid2hctx_seqbufc >= (sizeof(hctx->ccid2hctx_seqbuf) / |
| 91 | sizeof(struct ccid2_seq*))) |
| 92 | return -ENOMEM; |
| 93 | |
| 94 | /* allocate buffer and initialize linked list */ |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 95 | seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any()); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 96 | if (seqp == NULL) |
| 97 | return -ENOMEM; |
| 98 | |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 99 | for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) { |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 100 | seqp[i].ccid2s_next = &seqp[i + 1]; |
| 101 | seqp[i + 1].ccid2s_prev = &seqp[i]; |
| 102 | } |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 103 | seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp; |
| 104 | seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 105 | |
| 106 | /* This is the first allocation. Initiate the head and tail. */ |
| 107 | if (hctx->ccid2hctx_seqbufc == 0) |
| 108 | hctx->ccid2hctx_seqh = hctx->ccid2hctx_seqt = seqp; |
| 109 | else { |
| 110 | /* link the existing list with the one we just created */ |
| 111 | hctx->ccid2hctx_seqh->ccid2s_next = seqp; |
| 112 | seqp->ccid2s_prev = hctx->ccid2hctx_seqh; |
| 113 | |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 114 | hctx->ccid2hctx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1]; |
| 115 | seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hctx->ccid2hctx_seqt; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* store the original pointer to the buffer so we can free it */ |
| 119 | hctx->ccid2hctx_seqbuf[hctx->ccid2hctx_seqbufc] = seqp; |
| 120 | hctx->ccid2hctx_seqbufc++; |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Gerrit Renker | 6b57c93 | 2006-11-28 19:55:06 -0200 | [diff] [blame] | 125 | 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] | 126 | { |
Gerrit Renker | 6c58324 | 2007-10-04 14:42:19 -0700 | [diff] [blame] | 127 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 128 | |
Gerrit Renker | 8339936 | 2007-11-24 22:09:35 -0200 | [diff] [blame] | 129 | if (hctx->ccid2hctx_pipe < hctx->ccid2hctx_cwnd) |
| 130 | return 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 131 | |
Andrea Bittau | 446dec3 | 2006-09-19 13:10:11 -0700 | [diff] [blame] | 132 | return 1; /* XXX CCID should dequeue when ready instead of polling */ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 135 | static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 136 | { |
| 137 | struct dccp_sock *dp = dccp_sk(sk); |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 138 | u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->ccid2hctx_cwnd, 2); |
| 139 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 140 | /* |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 141 | * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from |
| 142 | * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always |
| 143 | * acceptable since this causes starvation/deadlock whenever cwnd < 2. |
| 144 | * 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] | 145 | */ |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 146 | if (val == 0 || val > max_ratio) { |
| 147 | DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio); |
| 148 | val = max_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 149 | } |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 150 | if (val > 0xFFFF) /* RFC 4340, 11.3 */ |
| 151 | val = 0xFFFF; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 152 | |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 153 | if (val == dp->dccps_l_ack_ratio) |
| 154 | return; |
| 155 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 156 | ccid2_pr_debug("changing local ack ratio to %u\n", val); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 157 | dp->dccps_l_ack_ratio = val; |
| 158 | } |
| 159 | |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 160 | static void ccid2_change_srtt(struct ccid2_hc_tx_sock *hctx, long val) |
| 161 | { |
| 162 | ccid2_pr_debug("change SRTT to %ld\n", val); |
| 163 | hctx->ccid2hctx_srtt = val; |
| 164 | } |
| 165 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 166 | static void ccid2_start_rto_timer(struct sock *sk); |
| 167 | |
| 168 | static void ccid2_hc_tx_rto_expire(unsigned long data) |
| 169 | { |
| 170 | struct sock *sk = (struct sock *)data; |
| 171 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 172 | long s; |
| 173 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 174 | bh_lock_sock(sk); |
| 175 | if (sock_owned_by_user(sk)) { |
| 176 | sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, |
| 177 | jiffies + HZ / 5); |
| 178 | goto out; |
| 179 | } |
| 180 | |
| 181 | ccid2_pr_debug("RTO_EXPIRE\n"); |
| 182 | |
| 183 | ccid2_hc_tx_check_sanity(hctx); |
| 184 | |
| 185 | /* back-off timer */ |
| 186 | hctx->ccid2hctx_rto <<= 1; |
| 187 | |
| 188 | s = hctx->ccid2hctx_rto / HZ; |
| 189 | if (s > 60) |
| 190 | hctx->ccid2hctx_rto = 60 * HZ; |
| 191 | |
| 192 | ccid2_start_rto_timer(sk); |
| 193 | |
| 194 | /* adjust pipe, cwnd etc */ |
Gerrit Renker | 3deeadd | 2007-11-24 22:05:51 -0200 | [diff] [blame] | 195 | hctx->ccid2hctx_ssthresh = hctx->ccid2hctx_cwnd / 2; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 196 | if (hctx->ccid2hctx_ssthresh < 2) |
| 197 | hctx->ccid2hctx_ssthresh = 2; |
Gerrit Renker | 3deeadd | 2007-11-24 22:05:51 -0200 | [diff] [blame] | 198 | hctx->ccid2hctx_cwnd = 1; |
Gerrit Renker | 95b21d7 | 2007-11-24 22:06:52 -0200 | [diff] [blame] | 199 | hctx->ccid2hctx_pipe = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 200 | |
| 201 | /* clear state about stuff we sent */ |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame^] | 202 | hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqh; |
| 203 | hctx->ccid2hctx_packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 204 | |
| 205 | /* clear ack ratio state. */ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 206 | hctx->ccid2hctx_rpseq = 0; |
| 207 | hctx->ccid2hctx_rpdupack = -1; |
| 208 | ccid2_change_l_ack_ratio(sk, 1); |
| 209 | ccid2_hc_tx_check_sanity(hctx); |
| 210 | out: |
| 211 | bh_unlock_sock(sk); |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 212 | sock_put(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void ccid2_start_rto_timer(struct sock *sk) |
| 216 | { |
| 217 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 218 | |
| 219 | ccid2_pr_debug("setting RTO timeout=%ld\n", hctx->ccid2hctx_rto); |
| 220 | |
| 221 | BUG_ON(timer_pending(&hctx->ccid2hctx_rtotimer)); |
| 222 | sk_reset_timer(sk, &hctx->ccid2hctx_rtotimer, |
| 223 | jiffies + hctx->ccid2hctx_rto); |
| 224 | } |
| 225 | |
Gerrit Renker | 6b57c93 | 2006-11-28 19:55:06 -0200 | [diff] [blame] | 226 | static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 227 | { |
| 228 | struct dccp_sock *dp = dccp_sk(sk); |
| 229 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 230 | struct ccid2_seq *next; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 231 | u64 seq; |
| 232 | |
Gerrit Renker | 95b21d7 | 2007-11-24 22:06:52 -0200 | [diff] [blame] | 233 | hctx->ccid2hctx_pipe++; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 234 | |
| 235 | /* There is an issue. What if another packet is sent between |
| 236 | * packet_send() and packet_sent(). Then the sequence number would be |
| 237 | * wrong. |
| 238 | * -sorbo. |
| 239 | */ |
| 240 | seq = dp->dccps_gss; |
| 241 | |
| 242 | hctx->ccid2hctx_seqh->ccid2s_seq = seq; |
| 243 | hctx->ccid2hctx_seqh->ccid2s_acked = 0; |
| 244 | hctx->ccid2hctx_seqh->ccid2s_sent = jiffies; |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 245 | |
| 246 | next = hctx->ccid2hctx_seqh->ccid2s_next; |
| 247 | /* check if we need to alloc more space */ |
| 248 | if (next == hctx->ccid2hctx_seqt) { |
Gerrit Renker | 7d9e893 | 2007-10-04 14:41:26 -0700 | [diff] [blame] | 249 | if (ccid2_hc_tx_alloc_seq(hctx)) { |
| 250 | DCCP_CRIT("packet history - out of memory!"); |
| 251 | /* FIXME: find a more graceful way to bail out */ |
| 252 | return; |
| 253 | } |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 254 | next = hctx->ccid2hctx_seqh->ccid2s_next; |
| 255 | BUG_ON(next == hctx->ccid2hctx_seqt); |
| 256 | } |
| 257 | hctx->ccid2hctx_seqh = next; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 258 | |
| 259 | ccid2_pr_debug("cwnd=%d pipe=%d\n", hctx->ccid2hctx_cwnd, |
| 260 | hctx->ccid2hctx_pipe); |
| 261 | |
Gerrit Renker | 900bfed | 2007-11-24 21:58:33 -0200 | [diff] [blame] | 262 | /* |
| 263 | * FIXME: The code below is broken and the variables have been removed |
| 264 | * from the socket struct. The `ackloss' variable was always set to 0, |
| 265 | * and with arsent there are several problems: |
| 266 | * (i) it doesn't just count the number of Acks, but all sent packets; |
| 267 | * (ii) it is expressed in # of packets, not # of windows, so the |
| 268 | * comparison below uses the wrong formula: Appendix A of RFC 4341 |
| 269 | * comes up with the number K = cwnd / (R^2 - R) of consecutive windows |
| 270 | * of data with no lost or marked Ack packets. If arsent were the # of |
| 271 | * consecutive Acks received without loss, then Ack Ratio needs to be |
| 272 | * decreased by 1 when |
| 273 | * arsent >= K * cwnd / R = cwnd^2 / (R^3 - R^2) |
| 274 | * where cwnd / R is the number of Acks received per window of data |
| 275 | * (cf. RFC 4341, App. A). The problems are that |
| 276 | * - arsent counts other packets as well; |
| 277 | * - the comparison uses a formula different from RFC 4341; |
| 278 | * - computing a cubic/quadratic equation each time is too complicated. |
| 279 | * Hence a different algorithm is needed. |
| 280 | */ |
| 281 | #if 0 |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 282 | /* Ack Ratio. Need to maintain a concept of how many windows we sent */ |
| 283 | hctx->ccid2hctx_arsent++; |
| 284 | /* We had an ack loss in this window... */ |
| 285 | if (hctx->ccid2hctx_ackloss) { |
| 286 | if (hctx->ccid2hctx_arsent >= hctx->ccid2hctx_cwnd) { |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 287 | hctx->ccid2hctx_arsent = 0; |
| 288 | hctx->ccid2hctx_ackloss = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 289 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 290 | } else { |
| 291 | /* No acks lost up to now... */ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 292 | /* decrease ack ratio if enough packets were sent */ |
| 293 | if (dp->dccps_l_ack_ratio > 1) { |
| 294 | /* XXX don't calculate denominator each time */ |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 295 | int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio - |
| 296 | dp->dccps_l_ack_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 297 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 298 | denom = hctx->ccid2hctx_cwnd * hctx->ccid2hctx_cwnd / denom; |
| 299 | |
| 300 | if (hctx->ccid2hctx_arsent >= denom) { |
| 301 | ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1); |
| 302 | hctx->ccid2hctx_arsent = 0; |
| 303 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 304 | } else { |
| 305 | /* we can't increase ack ratio further [1] */ |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 306 | hctx->ccid2hctx_arsent = 0; /* or maybe set it to cwnd*/ |
| 307 | } |
| 308 | } |
Gerrit Renker | 900bfed | 2007-11-24 21:58:33 -0200 | [diff] [blame] | 309 | #endif |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 310 | |
| 311 | /* setup RTO timer */ |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 312 | if (!timer_pending(&hctx->ccid2hctx_rtotimer)) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 313 | ccid2_start_rto_timer(sk); |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 314 | |
Andrea Bittau | 8d424f6 | 2006-09-19 13:12:44 -0700 | [diff] [blame] | 315 | #ifdef CONFIG_IP_DCCP_CCID2_DEBUG |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 316 | ccid2_pr_debug("Sent: seq=%llu\n", (unsigned long long)seq); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 317 | do { |
| 318 | struct ccid2_seq *seqp = hctx->ccid2hctx_seqt; |
| 319 | |
| 320 | while (seqp != hctx->ccid2hctx_seqh) { |
| 321 | 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] | 322 | (unsigned long long)seqp->ccid2s_seq, |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 323 | seqp->ccid2s_acked, seqp->ccid2s_sent); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 324 | seqp = seqp->ccid2s_next; |
| 325 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 326 | } while (0); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 327 | ccid2_pr_debug("=========\n"); |
| 328 | ccid2_hc_tx_check_sanity(hctx); |
| 329 | #endif |
| 330 | } |
| 331 | |
| 332 | /* XXX Lame code duplication! |
| 333 | * returns -1 if none was found. |
| 334 | * else returns the next offset to use in the function call. |
| 335 | */ |
| 336 | static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset, |
| 337 | unsigned char **vec, unsigned char *veclen) |
| 338 | { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 339 | const struct dccp_hdr *dh = dccp_hdr(skb); |
| 340 | unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb); |
| 341 | unsigned char *opt_ptr; |
| 342 | const unsigned char *opt_end = (unsigned char *)dh + |
| 343 | (dh->dccph_doff * 4); |
| 344 | unsigned char opt, len; |
| 345 | unsigned char *value; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 346 | |
| 347 | BUG_ON(offset < 0); |
| 348 | options += offset; |
| 349 | opt_ptr = options; |
| 350 | if (opt_ptr >= opt_end) |
| 351 | return -1; |
| 352 | |
| 353 | while (opt_ptr != opt_end) { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 354 | opt = *opt_ptr++; |
| 355 | len = 0; |
| 356 | value = NULL; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 357 | |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 358 | /* Check if this isn't a single byte option */ |
| 359 | if (opt > DCCPO_MAX_RESERVED) { |
| 360 | if (opt_ptr == opt_end) |
| 361 | goto out_invalid_option; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 362 | |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 363 | len = *opt_ptr++; |
| 364 | if (len < 3) |
| 365 | goto out_invalid_option; |
| 366 | /* |
| 367 | * Remove the type and len fields, leaving |
| 368 | * just the value size |
| 369 | */ |
| 370 | len -= 2; |
| 371 | value = opt_ptr; |
| 372 | opt_ptr += len; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 373 | |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 374 | if (opt_ptr > opt_end) |
| 375 | goto out_invalid_option; |
| 376 | } |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 377 | |
| 378 | switch (opt) { |
| 379 | case DCCPO_ACK_VECTOR_0: |
| 380 | case DCCPO_ACK_VECTOR_1: |
| 381 | *vec = value; |
| 382 | *veclen = len; |
| 383 | return offset + (opt_ptr - options); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
| 387 | return -1; |
| 388 | |
| 389 | out_invalid_option: |
Gerrit Renker | 59348b1 | 2006-11-20 18:39:23 -0200 | [diff] [blame] | 390 | DCCP_BUG("Invalid option - this should not happen (previous parsing)!"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 391 | return -1; |
| 392 | } |
| 393 | |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 394 | static void ccid2_hc_tx_kill_rto_timer(struct sock *sk) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 395 | { |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 396 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 397 | |
| 398 | sk_stop_timer(sk, &hctx->ccid2hctx_rtotimer); |
| 399 | ccid2_pr_debug("deleted RTO timer\n"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static inline void ccid2_new_ack(struct sock *sk, |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 403 | struct ccid2_seq *seqp, |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 404 | unsigned int *maxincr) |
| 405 | { |
| 406 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 407 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 408 | if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) { |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame^] | 409 | if (*maxincr > 0 && ++hctx->ccid2hctx_packets_acked == 2) { |
| 410 | hctx->ccid2hctx_cwnd += 1; |
| 411 | *maxincr -= 1; |
| 412 | hctx->ccid2hctx_packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 413 | } |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame^] | 414 | } else if (++hctx->ccid2hctx_packets_acked >= hctx->ccid2hctx_cwnd) { |
| 415 | hctx->ccid2hctx_cwnd += 1; |
| 416 | hctx->ccid2hctx_packets_acked = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* update RTO */ |
| 420 | if (hctx->ccid2hctx_srtt == -1 || |
Andrea Bittau | 29651cd | 2006-09-19 13:06:46 -0700 | [diff] [blame] | 421 | time_after(jiffies, hctx->ccid2hctx_lastrtt + hctx->ccid2hctx_srtt)) { |
| 422 | unsigned long r = (long)jiffies - (long)seqp->ccid2s_sent; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 423 | int s; |
| 424 | |
| 425 | /* first measurement */ |
| 426 | if (hctx->ccid2hctx_srtt == -1) { |
| 427 | ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n", |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 428 | r, jiffies, |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 429 | (unsigned long long)seqp->ccid2s_seq); |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 430 | ccid2_change_srtt(hctx, r); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 431 | hctx->ccid2hctx_rttvar = r >> 1; |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 432 | } else { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 433 | /* RTTVAR */ |
| 434 | long tmp = hctx->ccid2hctx_srtt - r; |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 435 | long srtt; |
| 436 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 437 | if (tmp < 0) |
| 438 | tmp *= -1; |
| 439 | |
| 440 | tmp >>= 2; |
| 441 | hctx->ccid2hctx_rttvar *= 3; |
| 442 | hctx->ccid2hctx_rttvar >>= 2; |
| 443 | hctx->ccid2hctx_rttvar += tmp; |
| 444 | |
| 445 | /* SRTT */ |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 446 | srtt = hctx->ccid2hctx_srtt; |
| 447 | srtt *= 7; |
| 448 | srtt >>= 3; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 449 | tmp = r >> 3; |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 450 | srtt += tmp; |
| 451 | ccid2_change_srtt(hctx, srtt); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 452 | } |
| 453 | s = hctx->ccid2hctx_rttvar << 2; |
| 454 | /* clock granularity is 1 when based on jiffies */ |
| 455 | if (!s) |
| 456 | s = 1; |
| 457 | hctx->ccid2hctx_rto = hctx->ccid2hctx_srtt + s; |
| 458 | |
| 459 | /* must be at least a second */ |
| 460 | s = hctx->ccid2hctx_rto / HZ; |
| 461 | /* DCCP doesn't require this [but I like it cuz my code sux] */ |
| 462 | #if 1 |
| 463 | if (s < 1) |
| 464 | hctx->ccid2hctx_rto = HZ; |
| 465 | #endif |
| 466 | /* max 60 seconds */ |
| 467 | if (s > 60) |
| 468 | hctx->ccid2hctx_rto = HZ * 60; |
| 469 | |
| 470 | hctx->ccid2hctx_lastrtt = jiffies; |
| 471 | |
| 472 | ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n", |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 473 | hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, |
| 474 | hctx->ccid2hctx_rto, HZ, r); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /* we got a new ack, so re-start RTO timer */ |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 478 | ccid2_hc_tx_kill_rto_timer(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 479 | ccid2_start_rto_timer(sk); |
| 480 | } |
| 481 | |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 482 | static void ccid2_hc_tx_dec_pipe(struct sock *sk) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 483 | { |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 484 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 485 | |
Gerrit Renker | 95b21d7 | 2007-11-24 22:06:52 -0200 | [diff] [blame] | 486 | if (hctx->ccid2hctx_pipe == 0) |
| 487 | DCCP_BUG("pipe == 0"); |
| 488 | else |
| 489 | hctx->ccid2hctx_pipe--; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 490 | |
| 491 | if (hctx->ccid2hctx_pipe == 0) |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 492 | ccid2_hc_tx_kill_rto_timer(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 495 | static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp) |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 496 | { |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 497 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 498 | |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 499 | if (time_before(seqp->ccid2s_sent, hctx->ccid2hctx_last_cong)) { |
| 500 | ccid2_pr_debug("Multiple losses in an RTT---treating as one\n"); |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | hctx->ccid2hctx_last_cong = jiffies; |
| 505 | |
Gerrit Renker | 3deeadd | 2007-11-24 22:05:51 -0200 | [diff] [blame] | 506 | hctx->ccid2hctx_cwnd = hctx->ccid2hctx_cwnd / 2 ? : 1U; |
| 507 | hctx->ccid2hctx_ssthresh = max(hctx->ccid2hctx_cwnd, 2U); |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 508 | |
| 509 | /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */ |
| 510 | if (dccp_sk(sk)->dccps_l_ack_ratio > hctx->ccid2hctx_cwnd) |
| 511 | ccid2_change_l_ack_ratio(sk, hctx->ccid2hctx_cwnd); |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 514 | static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 515 | { |
| 516 | struct dccp_sock *dp = dccp_sk(sk); |
| 517 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
| 518 | u64 ackno, seqno; |
| 519 | struct ccid2_seq *seqp; |
| 520 | unsigned char *vector; |
| 521 | unsigned char veclen; |
| 522 | int offset = 0; |
| 523 | int done = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 524 | unsigned int maxincr = 0; |
| 525 | |
| 526 | ccid2_hc_tx_check_sanity(hctx); |
| 527 | /* check reverse path congestion */ |
| 528 | seqno = DCCP_SKB_CB(skb)->dccpd_seq; |
| 529 | |
| 530 | /* XXX this whole "algorithm" is broken. Need to fix it to keep track |
| 531 | * of the seqnos of the dupacks so that rpseq and rpdupack are correct |
| 532 | * -sorbo. |
| 533 | */ |
| 534 | /* need to bootstrap */ |
| 535 | if (hctx->ccid2hctx_rpdupack == -1) { |
| 536 | hctx->ccid2hctx_rpdupack = 0; |
| 537 | hctx->ccid2hctx_rpseq = seqno; |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 538 | } else { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 539 | /* check if packet is consecutive */ |
Gerrit Renker | 5e28599 | 2007-10-04 14:43:09 -0700 | [diff] [blame] | 540 | if (dccp_delta_seqno(hctx->ccid2hctx_rpseq, seqno) == 1) |
| 541 | hctx->ccid2hctx_rpseq = seqno; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 542 | /* it's a later packet */ |
| 543 | else if (after48(seqno, hctx->ccid2hctx_rpseq)) { |
| 544 | hctx->ccid2hctx_rpdupack++; |
| 545 | |
| 546 | /* check if we got enough dupacks */ |
Gerrit Renker | 63df18a | 2007-11-24 22:04:35 -0200 | [diff] [blame] | 547 | if (hctx->ccid2hctx_rpdupack >= NUMDUPACK) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 548 | hctx->ccid2hctx_rpdupack = -1; /* XXX lame */ |
| 549 | hctx->ccid2hctx_rpseq = 0; |
| 550 | |
Gerrit Renker | df054e1 | 2007-11-24 21:32:53 -0200 | [diff] [blame] | 551 | ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /* check forward path congestion */ |
| 557 | /* still didn't send out new data packets */ |
| 558 | if (hctx->ccid2hctx_seqh == hctx->ccid2hctx_seqt) |
| 559 | return; |
| 560 | |
| 561 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
| 562 | case DCCP_PKT_ACK: |
| 563 | case DCCP_PKT_DATAACK: |
| 564 | break; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 565 | default: |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq; |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 570 | if (after48(ackno, hctx->ccid2hctx_high_ack)) |
| 571 | hctx->ccid2hctx_high_ack = ackno; |
| 572 | |
| 573 | seqp = hctx->ccid2hctx_seqt; |
| 574 | while (before48(seqp->ccid2s_seq, ackno)) { |
| 575 | seqp = seqp->ccid2s_next; |
| 576 | if (seqp == hctx->ccid2hctx_seqh) { |
| 577 | seqp = hctx->ccid2hctx_seqh->ccid2s_prev; |
| 578 | break; |
| 579 | } |
| 580 | } |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 581 | |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame^] | 582 | /* |
| 583 | * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2 |
| 584 | * packets per acknowledgement. Rounding up avoids that cwnd is not |
| 585 | * advanced when Ack Ratio is 1 and gives a slight edge otherwise. |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 586 | */ |
Gerrit Renker | a302002 | 2007-11-24 22:10:29 -0200 | [diff] [blame^] | 587 | if (hctx->ccid2hctx_cwnd < hctx->ccid2hctx_ssthresh) |
| 588 | maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 589 | |
| 590 | /* go through all ack vectors */ |
| 591 | while ((offset = ccid2_ackvector(sk, skb, offset, |
| 592 | &vector, &veclen)) != -1) { |
| 593 | /* go through this ack vector */ |
| 594 | while (veclen--) { |
| 595 | const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK; |
Gerrit Renker | cfbbeab | 2007-11-24 20:43:59 -0200 | [diff] [blame] | 596 | u64 ackno_end_rl = SUB48(ackno, rl); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 597 | |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 598 | ccid2_pr_debug("ackvec start:%llu end:%llu\n", |
| 599 | (unsigned long long)ackno, |
| 600 | (unsigned long long)ackno_end_rl); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 601 | /* if the seqno we are analyzing is larger than the |
| 602 | * current ackno, then move towards the tail of our |
| 603 | * seqnos. |
| 604 | */ |
| 605 | while (after48(seqp->ccid2s_seq, ackno)) { |
| 606 | if (seqp == hctx->ccid2hctx_seqt) { |
| 607 | done = 1; |
| 608 | break; |
| 609 | } |
| 610 | seqp = seqp->ccid2s_prev; |
| 611 | } |
| 612 | if (done) |
| 613 | break; |
| 614 | |
| 615 | /* check all seqnos in the range of the vector |
| 616 | * run length |
| 617 | */ |
| 618 | while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) { |
Andrea Bittau | 8e27e46 | 2006-09-19 13:05:35 -0700 | [diff] [blame] | 619 | const u8 state = *vector & |
| 620 | DCCP_ACKVEC_STATE_MASK; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 621 | |
| 622 | /* new packet received or marked */ |
| 623 | if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED && |
| 624 | !seqp->ccid2s_acked) { |
Arnaldo Carvalho de Melo | 8109b02 | 2006-12-10 16:01:18 -0200 | [diff] [blame] | 625 | if (state == |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 626 | DCCP_ACKVEC_STATE_ECN_MARKED) { |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 627 | ccid2_congestion_event(sk, |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 628 | seqp); |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 629 | } else |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 630 | ccid2_new_ack(sk, seqp, |
| 631 | &maxincr); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 632 | |
| 633 | seqp->ccid2s_acked = 1; |
| 634 | ccid2_pr_debug("Got ack for %llu\n", |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 635 | (unsigned long long)seqp->ccid2s_seq); |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 636 | ccid2_hc_tx_dec_pipe(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 637 | } |
| 638 | if (seqp == hctx->ccid2hctx_seqt) { |
| 639 | done = 1; |
| 640 | break; |
| 641 | } |
Gerrit Renker | 3de5489 | 2007-11-24 20:37:48 -0200 | [diff] [blame] | 642 | seqp = seqp->ccid2s_prev; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 643 | } |
| 644 | if (done) |
| 645 | break; |
| 646 | |
Gerrit Renker | cfbbeab | 2007-11-24 20:43:59 -0200 | [diff] [blame] | 647 | ackno = SUB48(ackno_end_rl, 1); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 648 | vector++; |
| 649 | } |
| 650 | if (done) |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | /* The state about what is acked should be correct now |
| 655 | * Check for NUMDUPACK |
| 656 | */ |
Andrea Bittau | 32aac18 | 2006-11-16 14:28:40 -0200 | [diff] [blame] | 657 | seqp = hctx->ccid2hctx_seqt; |
| 658 | while (before48(seqp->ccid2s_seq, hctx->ccid2hctx_high_ack)) { |
| 659 | seqp = seqp->ccid2s_next; |
| 660 | if (seqp == hctx->ccid2hctx_seqh) { |
| 661 | seqp = hctx->ccid2hctx_seqh->ccid2s_prev; |
| 662 | break; |
| 663 | } |
| 664 | } |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 665 | done = 0; |
| 666 | while (1) { |
| 667 | if (seqp->ccid2s_acked) { |
| 668 | done++; |
Gerrit Renker | 63df18a | 2007-11-24 22:04:35 -0200 | [diff] [blame] | 669 | if (done == NUMDUPACK) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 670 | break; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 671 | } |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 672 | if (seqp == hctx->ccid2hctx_seqt) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 673 | break; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 674 | seqp = seqp->ccid2s_prev; |
| 675 | } |
| 676 | |
| 677 | /* If there are at least 3 acknowledgements, anything unacknowledged |
| 678 | * below the last sequence number is considered lost |
| 679 | */ |
Gerrit Renker | 63df18a | 2007-11-24 22:04:35 -0200 | [diff] [blame] | 680 | if (done == NUMDUPACK) { |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 681 | struct ccid2_seq *last_acked = seqp; |
| 682 | |
| 683 | /* check for lost packets */ |
| 684 | while (1) { |
| 685 | if (!seqp->ccid2s_acked) { |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 686 | ccid2_pr_debug("Packet lost: %llu\n", |
Randy Dunlap | 234af48 | 2006-10-29 16:03:30 -0800 | [diff] [blame] | 687 | (unsigned long long)seqp->ccid2s_seq); |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 688 | /* XXX need to traverse from tail -> head in |
| 689 | * order to detect multiple congestion events in |
| 690 | * one ack vector. |
| 691 | */ |
Gerrit Renker | d50ad16 | 2007-11-24 21:40:24 -0200 | [diff] [blame] | 692 | ccid2_congestion_event(sk, seqp); |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 693 | ccid2_hc_tx_dec_pipe(sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 694 | } |
| 695 | if (seqp == hctx->ccid2hctx_seqt) |
| 696 | break; |
| 697 | seqp = seqp->ccid2s_prev; |
| 698 | } |
| 699 | |
| 700 | hctx->ccid2hctx_seqt = last_acked; |
| 701 | } |
| 702 | |
| 703 | /* trim acked packets in tail */ |
| 704 | while (hctx->ccid2hctx_seqt != hctx->ccid2hctx_seqh) { |
| 705 | if (!hctx->ccid2hctx_seqt->ccid2s_acked) |
| 706 | break; |
| 707 | |
| 708 | hctx->ccid2hctx_seqt = hctx->ccid2hctx_seqt->ccid2s_next; |
| 709 | } |
| 710 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 711 | ccid2_hc_tx_check_sanity(hctx); |
| 712 | } |
| 713 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 714 | static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 715 | { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 716 | struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid); |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 717 | struct dccp_sock *dp = dccp_sk(sk); |
| 718 | u32 max_ratio; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 719 | |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 720 | /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */ |
Gerrit Renker | 3deeadd | 2007-11-24 22:05:51 -0200 | [diff] [blame] | 721 | hctx->ccid2hctx_ssthresh = ~0U; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 722 | |
Gerrit Renker | b00d2bb | 2007-11-24 21:44:30 -0200 | [diff] [blame] | 723 | /* |
| 724 | * RFC 4341, 5: "The cwnd parameter is initialized to at most four |
| 725 | * packets for new connections, following the rules from [RFC3390]". |
| 726 | * We need to convert the bytes of RFC3390 into the packets of RFC 4341. |
| 727 | */ |
| 728 | hctx->ccid2hctx_cwnd = min(4U, max(2U, 4380U / dp->dccps_mss_cache)); |
| 729 | |
| 730 | /* Make sure that Ack Ratio is enabled and within bounds. */ |
| 731 | max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2); |
| 732 | if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio) |
| 733 | dp->dccps_l_ack_ratio = max_ratio; |
| 734 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 735 | /* XXX init ~ to window size... */ |
Gerrit Renker | cd1f7d3 | 2007-10-04 14:41:00 -0700 | [diff] [blame] | 736 | if (ccid2_hc_tx_alloc_seq(hctx)) |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 737 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 738 | |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 739 | hctx->ccid2hctx_rto = 3 * HZ; |
Andrea Bittau | 593f16a | 2006-09-19 13:15:33 -0700 | [diff] [blame] | 740 | ccid2_change_srtt(hctx, -1); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 741 | hctx->ccid2hctx_rttvar = -1; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 742 | hctx->ccid2hctx_rpdupack = -1; |
Andrea Bittau | 374bcf3 | 2006-09-19 13:14:43 -0700 | [diff] [blame] | 743 | hctx->ccid2hctx_last_cong = jiffies; |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 744 | setup_timer(&hctx->ccid2hctx_rtotimer, ccid2_hc_tx_rto_expire, |
| 745 | (unsigned long)sk); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 746 | |
| 747 | ccid2_hc_tx_check_sanity(hctx); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static void ccid2_hc_tx_exit(struct sock *sk) |
| 752 | { |
YOSHIFUJI Hideaki | c9eaf17 | 2007-02-09 23:24:38 +0900 | [diff] [blame] | 753 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 754 | int i; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 755 | |
Andrea Bittau | 77ff72d | 2006-03-20 17:57:52 -0800 | [diff] [blame] | 756 | ccid2_hc_tx_kill_rto_timer(sk); |
Andrea Bittau | 07978aa | 2006-09-19 13:13:37 -0700 | [diff] [blame] | 757 | |
| 758 | for (i = 0; i < hctx->ccid2hctx_seqbufc; i++) |
| 759 | kfree(hctx->ccid2hctx_seqbuf[i]); |
| 760 | hctx->ccid2hctx_seqbufc = 0; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 764 | { |
| 765 | const struct dccp_sock *dp = dccp_sk(sk); |
| 766 | struct ccid2_hc_rx_sock *hcrx = ccid2_hc_rx_sk(sk); |
| 767 | |
| 768 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
| 769 | case DCCP_PKT_DATA: |
| 770 | case DCCP_PKT_DATAACK: |
| 771 | hcrx->ccid2hcrx_data++; |
| 772 | if (hcrx->ccid2hcrx_data >= dp->dccps_r_ack_ratio) { |
| 773 | dccp_send_ack(sk); |
| 774 | hcrx->ccid2hcrx_data = 0; |
| 775 | } |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 780 | static struct ccid_operations ccid2 = { |
Ian McDonald | 3dd9a7c | 2006-09-22 14:26:44 +1200 | [diff] [blame] | 781 | .ccid_id = DCCPC_CCID2, |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 782 | .ccid_name = "ccid2", |
| 783 | .ccid_owner = THIS_MODULE, |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 784 | .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock), |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 785 | .ccid_hc_tx_init = ccid2_hc_tx_init, |
| 786 | .ccid_hc_tx_exit = ccid2_hc_tx_exit, |
| 787 | .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet, |
| 788 | .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent, |
| 789 | .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv, |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 790 | .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock), |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 791 | .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv, |
| 792 | }; |
| 793 | |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 794 | #ifdef CONFIG_IP_DCCP_CCID2_DEBUG |
Gerrit Renker | 042d18f | 2007-10-04 14:39:53 -0700 | [diff] [blame] | 795 | module_param(ccid2_debug, bool, 0444); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 796 | MODULE_PARM_DESC(ccid2_debug, "Enable debug messages"); |
Gerrit Renker | 8411671 | 2006-11-20 18:26:03 -0200 | [diff] [blame] | 797 | #endif |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 798 | |
| 799 | static __init int ccid2_module_init(void) |
| 800 | { |
| 801 | return ccid_register(&ccid2); |
| 802 | } |
| 803 | module_init(ccid2_module_init); |
| 804 | |
| 805 | static __exit void ccid2_module_exit(void) |
| 806 | { |
| 807 | ccid_unregister(&ccid2); |
| 808 | } |
| 809 | module_exit(ccid2_module_exit); |
| 810 | |
| 811 | MODULE_AUTHOR("Andrea Bittau <a.bittau@cs.ucl.ac.uk>"); |
Arnaldo Carvalho de Melo | c0c736d | 2006-03-20 22:05:37 -0800 | [diff] [blame] | 812 | MODULE_DESCRIPTION("DCCP TCP-Like (CCID2) CCID"); |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 813 | MODULE_LICENSE("GPL"); |
| 814 | MODULE_ALIAS("net-dccp-ccid-2"); |