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