Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/ccids/ccid3.c |
| 3 | * |
| 4 | * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. |
Ian McDonald | 1bc0986 | 2005-08-20 00:23:43 -0300 | [diff] [blame] | 5 | * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 6 | * |
| 7 | * An implementation of the DCCP protocol |
| 8 | * |
| 9 | * This code has been developed by the University of Waikato WAND |
| 10 | * research group. For further information please see http://www.wand.net.nz/ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 11 | * |
| 12 | * This code also uses code from Lulea University, rereleased as GPL by its |
| 13 | * authors: |
| 14 | * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon |
| 15 | * |
| 16 | * Changes to meet Linux coding standards, to make it meet latest ccid3 draft |
| 17 | * and to make it work as a loadable module in the DCCP stack written by |
| 18 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br>. |
| 19 | * |
| 20 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2 of the License, or |
| 25 | * (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | */ |
| 36 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 37 | #include <linux/config.h> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 38 | #include "../ccid.h" |
| 39 | #include "../dccp.h" |
Arnaldo Carvalho de Melo | 4524b25 | 2005-08-27 23:18:26 -0300 | [diff] [blame] | 40 | #include "lib/packet_history.h" |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 41 | #include "lib/loss_interval.h" |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame] | 42 | #include "lib/tfrc.h" |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 43 | #include "ccid3.h" |
| 44 | |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 45 | /* |
Arnaldo Carvalho de Melo | 0ba7a3b | 2005-09-09 02:28:47 -0300 | [diff] [blame] | 46 | * Reason for maths here is to avoid 32 bit overflow when a is big. |
| 47 | * With this we get close to the limit. |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 48 | */ |
| 49 | static inline u32 usecs_div(const u32 a, const u32 b) |
| 50 | { |
Arnaldo Carvalho de Melo | 0ba7a3b | 2005-09-09 02:28:47 -0300 | [diff] [blame] | 51 | const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 : |
| 52 | a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 : |
| 53 | a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 : |
| 54 | a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 : |
| 55 | a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 : |
| 56 | a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 : |
| 57 | a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 : |
| 58 | a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 : |
| 59 | 100000; |
| 60 | const u32 tmp = a * (USEC_PER_SEC / div); |
| 61 | return (b >= 2 * div) ? tmp / (b / div) : tmp; |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 62 | } |
| 63 | |
Arnaldo Carvalho de Melo | cfc3c52 | 2005-08-27 20:20:37 -0300 | [diff] [blame] | 64 | static int ccid3_debug; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 65 | |
Arnaldo Carvalho de Melo | cfc3c52 | 2005-08-27 20:20:37 -0300 | [diff] [blame] | 66 | #ifdef CCID3_DEBUG |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 67 | #define ccid3_pr_debug(format, a...) \ |
| 68 | do { if (ccid3_debug) \ |
| 69 | printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \ |
| 70 | } while (0) |
| 71 | #else |
| 72 | #define ccid3_pr_debug(format, a...) |
| 73 | #endif |
| 74 | |
Arnaldo Carvalho de Melo | a1d3a35 | 2005-08-13 22:42:25 -0300 | [diff] [blame] | 75 | static struct dccp_tx_hist *ccid3_tx_hist; |
| 76 | static struct dccp_rx_hist *ccid3_rx_hist; |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 77 | static struct dccp_li_hist *ccid3_li_hist; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 78 | |
| 79 | static int ccid3_init(struct sock *sk) |
| 80 | { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static void ccid3_exit(struct sock *sk) |
| 85 | { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* TFRC sender states */ |
| 89 | enum ccid3_hc_tx_states { |
| 90 | TFRC_SSTATE_NO_SENT = 1, |
| 91 | TFRC_SSTATE_NO_FBACK, |
| 92 | TFRC_SSTATE_FBACK, |
| 93 | TFRC_SSTATE_TERM, |
| 94 | }; |
| 95 | |
| 96 | #ifdef CCID3_DEBUG |
| 97 | static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state) |
| 98 | { |
| 99 | static char *ccid3_state_names[] = { |
| 100 | [TFRC_SSTATE_NO_SENT] = "NO_SENT", |
| 101 | [TFRC_SSTATE_NO_FBACK] = "NO_FBACK", |
| 102 | [TFRC_SSTATE_FBACK] = "FBACK", |
| 103 | [TFRC_SSTATE_TERM] = "TERM", |
| 104 | }; |
| 105 | |
| 106 | return ccid3_state_names[state]; |
| 107 | } |
| 108 | #endif |
| 109 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 110 | static inline void ccid3_hc_tx_set_state(struct sock *sk, |
| 111 | enum ccid3_hc_tx_states state) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 112 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 113 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 114 | enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; |
| 115 | |
| 116 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 117 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), |
| 118 | ccid3_tx_state_name(state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 119 | WARN_ON(state == oldstate); |
| 120 | hctx->ccid3hctx_state = state; |
| 121 | } |
| 122 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 123 | /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ |
| 124 | static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) |
| 125 | { |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 126 | /* |
| 127 | * If no feedback spec says t_ipi is 1 second (set elsewhere and then |
| 128 | * doubles after every no feedback timer (separate function) |
| 129 | */ |
| 130 | if (hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) |
| 131 | hctx->ccid3hctx_t_ipi = usecs_div(hctx->ccid3hctx_s, |
| 132 | hctx->ccid3hctx_x); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ |
| 136 | static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx) |
| 137 | { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 138 | hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, |
| 139 | TFRC_OPSYS_HALF_TIME_GRAN); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Update X by |
| 144 | * If (p > 0) |
| 145 | * x_calc = calcX(s, R, p); |
| 146 | * X = max(min(X_calc, 2 * X_recv), s / t_mbi); |
| 147 | * Else |
| 148 | * If (now - tld >= R) |
| 149 | * X = max(min(2 * X, 2 * X_recv), s / R); |
| 150 | * tld = now; |
| 151 | */ |
| 152 | static void ccid3_hc_tx_update_x(struct sock *sk) |
| 153 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 154 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 155 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 156 | /* To avoid large error in calcX */ |
| 157 | if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame] | 158 | hctx->ccid3hctx_x_calc = tfrc_calc_x(hctx->ccid3hctx_s, |
| 159 | hctx->ccid3hctx_rtt, |
| 160 | hctx->ccid3hctx_p); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 161 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, |
| 162 | 2 * hctx->ccid3hctx_x_recv), |
| 163 | (hctx->ccid3hctx_s / |
| 164 | TFRC_MAX_BACK_OFF_TIME)); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 165 | } else { |
| 166 | struct timeval now; |
| 167 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 168 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 169 | if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >= |
| 170 | hctx->ccid3hctx_rtt) { |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 171 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv, |
| 172 | hctx->ccid3hctx_x) * 2, |
| 173 | usecs_div(hctx->ccid3hctx_s, |
| 174 | hctx->ccid3hctx_rtt)); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 175 | hctx->ccid3hctx_t_ld = now; |
| 176 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 177 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void ccid3_hc_tx_no_feedback_timer(unsigned long data) |
| 181 | { |
| 182 | struct sock *sk = (struct sock *)data; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 183 | unsigned long next_tmout = 0; |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 184 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 185 | |
| 186 | bh_lock_sock(sk); |
| 187 | if (sock_owned_by_user(sk)) { |
| 188 | /* Try again later. */ |
| 189 | /* XXX: set some sensible MIB */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 190 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
| 191 | jiffies + HZ / 5); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 192 | goto out; |
| 193 | } |
| 194 | |
| 195 | ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, |
| 196 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
| 197 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 198 | switch (hctx->ccid3hctx_state) { |
| 199 | case TFRC_SSTATE_TERM: |
| 200 | goto out; |
| 201 | case TFRC_SSTATE_NO_FBACK: |
| 202 | /* Halve send rate */ |
| 203 | hctx->ccid3hctx_x /= 2; |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 204 | if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / |
| 205 | TFRC_MAX_BACK_OFF_TIME)) |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 206 | hctx->ccid3hctx_x = (hctx->ccid3hctx_s / |
| 207 | TFRC_MAX_BACK_OFF_TIME); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 208 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 209 | ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d " |
| 210 | "bytes/s\n", |
| 211 | dccp_role(sk), sk, |
| 212 | ccid3_tx_state_name(hctx->ccid3hctx_state), |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 213 | hctx->ccid3hctx_x); |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 214 | next_tmout = max_t(u32, 2 * usecs_div(hctx->ccid3hctx_s, |
| 215 | hctx->ccid3hctx_x), |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 216 | TFRC_INITIAL_TIMEOUT); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 217 | /* |
| 218 | * FIXME - not sure above calculation is correct. See section |
| 219 | * 5 of CCID3 11 should adjust tx_t_ipi and double that to |
| 220 | * achieve it really |
| 221 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 222 | break; |
| 223 | case TFRC_SSTATE_FBACK: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 224 | /* |
| 225 | * Check if IDLE since last timeout and recv rate is less than |
| 226 | * 4 packets per RTT |
| 227 | */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 228 | if (!hctx->ccid3hctx_idle || |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 229 | (hctx->ccid3hctx_x_recv >= |
| 230 | 4 * usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_rtt))) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 231 | ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", |
| 232 | dccp_role(sk), sk, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 233 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
| 234 | /* Halve sending rate */ |
| 235 | |
| 236 | /* If (X_calc > 2 * X_recv) |
| 237 | * X_recv = max(X_recv / 2, s / (2 * t_mbi)); |
| 238 | * Else |
| 239 | * X_recv = X_calc / 4; |
| 240 | */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 241 | BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && |
| 242 | hctx->ccid3hctx_x_calc == 0); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 243 | |
| 244 | /* check also if p is zero -> x_calc is infinity? */ |
| 245 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P || |
| 246 | hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) |
| 247 | hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, |
| 248 | hctx->ccid3hctx_s / (2 * TFRC_MAX_BACK_OFF_TIME)); |
| 249 | else |
| 250 | hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; |
| 251 | |
| 252 | /* Update sending rate */ |
| 253 | ccid3_hc_tx_update_x(sk); |
| 254 | } |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 255 | /* |
| 256 | * Schedule no feedback timer to expire in |
| 257 | * max(4 * R, 2 * s / X) |
| 258 | */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 259 | next_tmout = max_t(u32, hctx->ccid3hctx_t_rto, |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 260 | 2 * usecs_div(hctx->ccid3hctx_s, |
| 261 | hctx->ccid3hctx_x)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 262 | break; |
| 263 | default: |
| 264 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 265 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 266 | dump_stack(); |
| 267 | goto out; |
| 268 | } |
| 269 | |
| 270 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 271 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 272 | hctx->ccid3hctx_idle = 1; |
| 273 | out: |
| 274 | bh_unlock_sock(sk); |
| 275 | sock_put(sk); |
| 276 | } |
| 277 | |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 278 | static int ccid3_hc_tx_send_packet(struct sock *sk, |
| 279 | struct sk_buff *skb, int len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 280 | { |
| 281 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 282 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 283 | struct dccp_tx_hist_entry *new_packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 284 | struct timeval now; |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 285 | long delay; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 286 | int rc = -ENOTCONN; |
| 287 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 288 | BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 289 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 290 | /* Check if pure ACK or Terminating*/ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 291 | /* |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 292 | * XXX: We only call this function for DATA and DATAACK, on, these |
| 293 | * packets can have zero length, but why the comment about "pure ACK"? |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 294 | */ |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 295 | if (unlikely(len == 0)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 296 | goto out; |
| 297 | |
| 298 | /* See if last packet allocated was not sent */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 299 | new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); |
| 300 | if (new_packet == NULL || new_packet->dccphtx_sent) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 301 | new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist, |
| 302 | SLAB_ATOMIC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 303 | |
| 304 | rc = -ENOBUFS; |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 305 | if (unlikely(new_packet == NULL)) { |
| 306 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, not enough " |
| 307 | "mem to add to history, send refused\n", |
| 308 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 309 | goto out; |
| 310 | } |
| 311 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 312 | dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 315 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 316 | |
| 317 | switch (hctx->ccid3hctx_state) { |
| 318 | case TFRC_SSTATE_NO_SENT: |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 319 | hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; |
| 320 | hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 321 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
| 322 | jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 323 | hctx->ccid3hctx_last_win_count = 0; |
| 324 | hctx->ccid3hctx_t_last_win_count = now; |
| 325 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); |
Arnaldo Carvalho de Melo | d7e0fb9 | 2005-09-09 19:58:18 -0300 | [diff] [blame] | 326 | hctx->ccid3hctx_t_ipi = TFRC_INITIAL_IPI; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 327 | |
| 328 | /* Set nominal send time for initial packet */ |
| 329 | hctx->ccid3hctx_t_nom = now; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 330 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 331 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 332 | ccid3_calc_new_delta(hctx); |
| 333 | rc = 0; |
| 334 | break; |
| 335 | case TFRC_SSTATE_NO_FBACK: |
| 336 | case TFRC_SSTATE_FBACK: |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 337 | delay = (timeval_delta(&now, &hctx->ccid3hctx_t_nom) - |
| 338 | hctx->ccid3hctx_delta); |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 339 | delay /= -1000; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 340 | /* divide by -1000 is to convert to ms and get sign right */ |
Arnaldo Carvalho de Melo | d6809c1 | 2005-08-27 03:06:35 -0300 | [diff] [blame] | 341 | rc = delay > 0 ? delay : 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 342 | break; |
| 343 | default: |
| 344 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 345 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 346 | dump_stack(); |
| 347 | rc = -EINVAL; |
| 348 | break; |
| 349 | } |
| 350 | |
| 351 | /* Can we send? if so add options and add to packet history */ |
Arnaldo Carvalho de Melo | 507d37c | 2005-09-09 02:30:07 -0300 | [diff] [blame] | 352 | if (rc == 0) { |
| 353 | dp->dccps_hc_tx_insert_options = 1; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 354 | new_packet->dccphtx_ccval = |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 355 | DCCP_SKB_CB(skb)->dccpd_ccval = |
| 356 | hctx->ccid3hctx_last_win_count; |
Arnaldo Carvalho de Melo | 507d37c | 2005-09-09 02:30:07 -0300 | [diff] [blame] | 357 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 358 | out: |
| 359 | return rc; |
| 360 | } |
| 361 | |
| 362 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) |
| 363 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 364 | const struct dccp_sock *dp = dccp_sk(sk); |
| 365 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 366 | struct timeval now; |
| 367 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 368 | BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 369 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 370 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 371 | |
| 372 | /* check if we have sent a data packet */ |
| 373 | if (len > 0) { |
| 374 | unsigned long quarter_rtt; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 375 | struct dccp_tx_hist_entry *packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 376 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 377 | packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 378 | if (unlikely(packet == NULL)) { |
| 379 | LIMIT_NETDEBUG(KERN_WARNING "%s: packet doesn't " |
| 380 | "exists in history!\n", __FUNCTION__); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 381 | return; |
| 382 | } |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 383 | if (unlikely(packet->dccphtx_sent)) { |
| 384 | LIMIT_NETDEBUG(KERN_WARNING "%s: no unsent packet in " |
| 385 | "history!\n", __FUNCTION__); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 386 | return; |
| 387 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 388 | packet->dccphtx_tstamp = now; |
| 389 | packet->dccphtx_seqno = dp->dccps_gss; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 390 | /* |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 391 | * Check if win_count have changed |
| 392 | * Algorithm in "8.1. Window Counter Valuer" in |
| 393 | * draft-ietf-dccp-ccid3-11.txt |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 394 | */ |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 395 | quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count); |
| 396 | if (likely(hctx->ccid3hctx_rtt > 8)) |
| 397 | quarter_rtt /= hctx->ccid3hctx_rtt / 4; |
| 398 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 399 | if (quarter_rtt > 0) { |
| 400 | hctx->ccid3hctx_t_last_win_count = now; |
| 401 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + |
| 402 | min_t(unsigned long, quarter_rtt, 5)) % 16; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 403 | ccid3_pr_debug("%s, sk=%p, window changed from " |
| 404 | "%u to %u!\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 405 | dccp_role(sk), sk, |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 406 | packet->dccphtx_ccval, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 407 | hctx->ccid3hctx_last_win_count); |
| 408 | } |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 409 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 410 | hctx->ccid3hctx_idle = 0; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 411 | packet->dccphtx_rtt = hctx->ccid3hctx_rtt; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 412 | packet->dccphtx_sent = 1; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 413 | } else |
| 414 | ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n", |
| 415 | dccp_role(sk), sk, dp->dccps_gss); |
| 416 | |
| 417 | switch (hctx->ccid3hctx_state) { |
| 418 | case TFRC_SSTATE_NO_SENT: |
| 419 | /* if first wasn't pure ack */ |
| 420 | if (len != 0) |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 421 | printk(KERN_CRIT "%s: %s, First packet sent is noted " |
| 422 | "as a data packet\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 423 | __FUNCTION__, dccp_role(sk)); |
| 424 | return; |
| 425 | case TFRC_SSTATE_NO_FBACK: |
| 426 | case TFRC_SSTATE_FBACK: |
| 427 | if (len > 0) { |
| 428 | hctx->ccid3hctx_t_nom = now; |
| 429 | ccid3_calc_new_t_ipi(hctx); |
| 430 | ccid3_calc_new_delta(hctx); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 431 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 432 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 433 | } |
| 434 | break; |
| 435 | default: |
| 436 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 437 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 438 | dump_stack(); |
| 439 | break; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 444 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 445 | const struct dccp_sock *dp = dccp_sk(sk); |
| 446 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 447 | struct ccid3_options_received *opt_recv; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 448 | struct dccp_tx_hist_entry *packet; |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 449 | struct timeval now; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 450 | unsigned long next_tmout; |
Ian McDonald | 1bc0986 | 2005-08-20 00:23:43 -0300 | [diff] [blame] | 451 | u32 t_elapsed; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 452 | u32 pinv; |
| 453 | u32 x_recv; |
| 454 | u32 r_sample; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 455 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 456 | BUG_ON(hctx == NULL || hctx->ccid3hctx_state == TFRC_SSTATE_TERM); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 457 | |
| 458 | /* we are only interested in ACKs */ |
| 459 | if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || |
| 460 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) |
| 461 | return; |
| 462 | |
| 463 | opt_recv = &hctx->ccid3hctx_options_received; |
| 464 | |
Arnaldo Carvalho de Melo | 1a28599 | 2005-09-09 02:32:56 -0300 | [diff] [blame] | 465 | t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 466 | x_recv = opt_recv->ccid3or_receive_rate; |
| 467 | pinv = opt_recv->ccid3or_loss_event_rate; |
| 468 | |
| 469 | switch (hctx->ccid3hctx_state) { |
| 470 | case TFRC_SSTATE_NO_SENT: |
| 471 | /* FIXME: what to do here? */ |
| 472 | return; |
| 473 | case TFRC_SSTATE_NO_FBACK: |
| 474 | case TFRC_SSTATE_FBACK: |
| 475 | /* Calculate new round trip sample by |
| 476 | * R_sample = (now - t_recvdata) - t_delay */ |
| 477 | /* get t_recvdata from history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 478 | packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, |
| 479 | DCCP_SKB_CB(skb)->dccpd_ack_seq); |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 480 | if (unlikely(packet == NULL)) { |
| 481 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, seqno " |
| 482 | "%llu(%s) does't exist in history!\n", |
| 483 | __FUNCTION__, dccp_role(sk), sk, |
| 484 | (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, |
| 485 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 486 | return; |
| 487 | } |
| 488 | |
| 489 | /* Update RTT */ |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 490 | dccp_timestamp(sk, &now); |
| 491 | r_sample = timeval_delta(&now, &packet->dccphtx_tstamp); |
Arnaldo Carvalho de Melo | 1a28599 | 2005-09-09 02:32:56 -0300 | [diff] [blame] | 492 | if (unlikely(r_sample <= t_elapsed)) |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 493 | LIMIT_NETDEBUG(KERN_WARNING "%s: r_sample=%uus, " |
| 494 | "t_elapsed=%uus\n", |
Arnaldo Carvalho de Melo | 1a28599 | 2005-09-09 02:32:56 -0300 | [diff] [blame] | 495 | __FUNCTION__, r_sample, t_elapsed); |
| 496 | else |
| 497 | r_sample -= t_elapsed; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 498 | |
| 499 | /* Update RTT estimate by |
| 500 | * If (No feedback recv) |
| 501 | * R = R_sample; |
| 502 | * Else |
| 503 | * R = q * R + (1 - q) * R_sample; |
| 504 | * |
| 505 | * q is a constant, RFC 3448 recomments 0.9 |
| 506 | */ |
| 507 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { |
| 508 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); |
| 509 | hctx->ccid3hctx_rtt = r_sample; |
| 510 | } else |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 511 | hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + |
| 512 | r_sample / 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 513 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 514 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, " |
| 515 | "r_sample=%us\n", dccp_role(sk), sk, |
| 516 | hctx->ccid3hctx_rtt, r_sample); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 517 | |
| 518 | /* Update timeout interval */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 519 | hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, |
| 520 | USEC_PER_SEC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 521 | |
| 522 | /* Update receive rate */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 523 | hctx->ccid3hctx_x_recv = x_recv;/* X_recv in bytes per sec */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 524 | |
| 525 | /* Update loss event rate */ |
| 526 | if (pinv == ~0 || pinv == 0) |
| 527 | hctx->ccid3hctx_p = 0; |
| 528 | else { |
| 529 | hctx->ccid3hctx_p = 1000000 / pinv; |
| 530 | |
| 531 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) { |
| 532 | hctx->ccid3hctx_p = TFRC_SMALLEST_P; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 533 | ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", |
| 534 | dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | /* unschedule no feedback timer */ |
| 539 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
| 540 | |
| 541 | /* Update sending rate */ |
| 542 | ccid3_hc_tx_update_x(sk); |
| 543 | |
| 544 | /* Update next send time */ |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 545 | timeval_sub_usecs(&hctx->ccid3hctx_t_nom, |
| 546 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 547 | ccid3_calc_new_t_ipi(hctx); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 548 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 549 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 550 | ccid3_calc_new_delta(hctx); |
| 551 | |
| 552 | /* remove all packets older than the one acked from history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 553 | dccp_tx_hist_purge_older(ccid3_tx_hist, |
| 554 | &hctx->ccid3hctx_hist, packet); |
Arnaldo Carvalho de Melo | c530cfb | 2005-08-29 02:15:54 -0300 | [diff] [blame] | 555 | /* |
| 556 | * As we have calculated new ipi, delta, t_nom it is possible that |
| 557 | * we now can send a packet, so wake up dccp_wait_for_ccids. |
| 558 | */ |
| 559 | sk->sk_write_space(sk); |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 560 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 561 | /* |
| 562 | * Schedule no feedback timer to expire in |
| 563 | * max(4 * R, 2 * s / X) |
| 564 | */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 565 | next_tmout = max(hctx->ccid3hctx_t_rto, |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 566 | 2 * usecs_div(hctx->ccid3hctx_s, |
| 567 | hctx->ccid3hctx_x)); |
| 568 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 569 | ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to " |
| 570 | "expire in %lu jiffies (%luus)\n", |
| 571 | dccp_role(sk), sk, |
| 572 | usecs_to_jiffies(next_tmout), next_tmout); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 573 | |
| 574 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 575 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 576 | |
| 577 | /* set idle flag */ |
| 578 | hctx->ccid3hctx_idle = 1; |
| 579 | break; |
| 580 | default: |
| 581 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 582 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 583 | dump_stack(); |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) |
| 589 | { |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 590 | const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 591 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 592 | BUG_ON(hctx == NULL); |
| 593 | |
| 594 | if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 595 | return; |
| 596 | |
| 597 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; |
| 598 | } |
| 599 | |
| 600 | static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 601 | unsigned char len, u16 idx, |
| 602 | unsigned char *value) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 603 | { |
| 604 | int rc = 0; |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 605 | const struct dccp_sock *dp = dccp_sk(sk); |
| 606 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 607 | struct ccid3_options_received *opt_recv; |
| 608 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 609 | BUG_ON(hctx == NULL); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 610 | |
| 611 | opt_recv = &hctx->ccid3hctx_options_received; |
| 612 | |
| 613 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { |
| 614 | opt_recv->ccid3or_seqno = dp->dccps_gsr; |
| 615 | opt_recv->ccid3or_loss_event_rate = ~0; |
| 616 | opt_recv->ccid3or_loss_intervals_idx = 0; |
| 617 | opt_recv->ccid3or_loss_intervals_len = 0; |
| 618 | opt_recv->ccid3or_receive_rate = 0; |
| 619 | } |
| 620 | |
| 621 | switch (option) { |
| 622 | case TFRC_OPT_LOSS_EVENT_RATE: |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 623 | if (unlikely(len != 4)) { |
| 624 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, invalid " |
| 625 | "len for TFRC_OPT_LOSS_EVENT_RATE\n", |
| 626 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 627 | rc = -EINVAL; |
| 628 | } else { |
| 629 | opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); |
| 630 | ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", |
| 631 | dccp_role(sk), sk, |
| 632 | opt_recv->ccid3or_loss_event_rate); |
| 633 | } |
| 634 | break; |
| 635 | case TFRC_OPT_LOSS_INTERVALS: |
| 636 | opt_recv->ccid3or_loss_intervals_idx = idx; |
| 637 | opt_recv->ccid3or_loss_intervals_len = len; |
| 638 | ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", |
| 639 | dccp_role(sk), sk, |
| 640 | opt_recv->ccid3or_loss_intervals_idx, |
| 641 | opt_recv->ccid3or_loss_intervals_len); |
| 642 | break; |
| 643 | case TFRC_OPT_RECEIVE_RATE: |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 644 | if (unlikely(len != 4)) { |
| 645 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, invalid " |
| 646 | "len for TFRC_OPT_RECEIVE_RATE\n", |
| 647 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 648 | rc = -EINVAL; |
| 649 | } else { |
| 650 | opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); |
| 651 | ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", |
| 652 | dccp_role(sk), sk, |
| 653 | opt_recv->ccid3or_receive_rate); |
| 654 | } |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | return rc; |
| 659 | } |
| 660 | |
| 661 | static int ccid3_hc_tx_init(struct sock *sk) |
| 662 | { |
| 663 | struct dccp_sock *dp = dccp_sk(sk); |
| 664 | struct ccid3_hc_tx_sock *hctx; |
| 665 | |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 666 | dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any()); |
| 667 | if (dp->dccps_hc_tx_ccid_private == NULL) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 668 | return -ENOMEM; |
| 669 | |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 670 | hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 671 | memset(hctx, 0, sizeof(*hctx)); |
| 672 | |
Arnaldo Carvalho de Melo | a84ffe4 | 2005-08-28 04:51:32 -0300 | [diff] [blame] | 673 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && |
| 674 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) |
| 675 | hctx->ccid3hctx_s = dp->dccps_packet_size; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 676 | else |
| 677 | hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE; |
| 678 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 679 | /* Set transmission rate to 1 packet per second */ |
| 680 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 681 | hctx->ccid3hctx_t_rto = USEC_PER_SEC; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 682 | hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; |
| 683 | INIT_LIST_HEAD(&hctx->ccid3hctx_hist); |
| 684 | init_timer(&hctx->ccid3hctx_no_feedback_timer); |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | static void ccid3_hc_tx_exit(struct sock *sk) |
| 690 | { |
| 691 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 692 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 693 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 694 | BUG_ON(hctx == NULL); |
| 695 | |
| 696 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); |
| 697 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
| 698 | |
| 699 | /* Empty packet history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 700 | dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 701 | |
| 702 | kfree(dp->dccps_hc_tx_ccid_private); |
| 703 | dp->dccps_hc_tx_ccid_private = NULL; |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * RX Half Connection methods |
| 708 | */ |
| 709 | |
| 710 | /* TFRC receiver states */ |
| 711 | enum ccid3_hc_rx_states { |
| 712 | TFRC_RSTATE_NO_DATA = 1, |
| 713 | TFRC_RSTATE_DATA, |
| 714 | TFRC_RSTATE_TERM = 127, |
| 715 | }; |
| 716 | |
| 717 | #ifdef CCID3_DEBUG |
| 718 | static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state) |
| 719 | { |
| 720 | static char *ccid3_rx_state_names[] = { |
| 721 | [TFRC_RSTATE_NO_DATA] = "NO_DATA", |
| 722 | [TFRC_RSTATE_DATA] = "DATA", |
| 723 | [TFRC_RSTATE_TERM] = "TERM", |
| 724 | }; |
| 725 | |
| 726 | return ccid3_rx_state_names[state]; |
| 727 | } |
| 728 | #endif |
| 729 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 730 | static inline void ccid3_hc_rx_set_state(struct sock *sk, |
| 731 | enum ccid3_hc_rx_states state) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 732 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 733 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 734 | enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; |
| 735 | |
| 736 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 737 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), |
| 738 | ccid3_rx_state_name(state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 739 | WARN_ON(state == oldstate); |
| 740 | hcrx->ccid3hcrx_state = state; |
| 741 | } |
| 742 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 743 | static void ccid3_hc_rx_send_feedback(struct sock *sk) |
| 744 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 745 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 746 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 747 | struct dccp_rx_hist_entry *packet; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 748 | struct timeval now; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 749 | |
| 750 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 751 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 752 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 753 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 754 | switch (hcrx->ccid3hcrx_state) { |
| 755 | case TFRC_RSTATE_NO_DATA: |
| 756 | hcrx->ccid3hcrx_x_recv = 0; |
| 757 | break; |
| 758 | case TFRC_RSTATE_DATA: { |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 759 | const u32 delta = timeval_delta(&now, |
| 760 | &hcrx->ccid3hcrx_tstamp_last_feedback); |
Arnaldo Carvalho de Melo | 27ae543e | 2005-09-09 02:31:07 -0300 | [diff] [blame] | 761 | hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, |
| 762 | delta); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 763 | } |
| 764 | break; |
| 765 | default: |
| 766 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 767 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
| 768 | dump_stack(); |
| 769 | return; |
| 770 | } |
| 771 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 772 | packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 773 | if (unlikely(packet == NULL)) { |
| 774 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, no data packet " |
| 775 | "in history!\n", |
| 776 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 777 | return; |
| 778 | } |
| 779 | |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 780 | hcrx->ccid3hcrx_tstamp_last_feedback = now; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 781 | hcrx->ccid3hcrx_last_counter = packet->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 782 | hcrx->ccid3hcrx_seqno_last_counter = packet->dccphrx_seqno; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 783 | hcrx->ccid3hcrx_bytes_recv = 0; |
| 784 | |
| 785 | /* Convert to multiples of 10us */ |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 786 | hcrx->ccid3hcrx_elapsed_time = |
| 787 | timeval_delta(&now, &packet->dccphrx_tstamp) / 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 788 | if (hcrx->ccid3hcrx_p == 0) |
| 789 | hcrx->ccid3hcrx_pinv = ~0; |
| 790 | else |
| 791 | hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; |
Arnaldo Carvalho de Melo | 507d37c | 2005-09-09 02:30:07 -0300 | [diff] [blame] | 792 | dp->dccps_hc_rx_insert_options = 1; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 793 | dccp_send_ack(sk); |
| 794 | } |
| 795 | |
| 796 | static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) |
| 797 | { |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 798 | const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 799 | u32 x_recv, pinv; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 800 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 801 | BUG_ON(hcrx == NULL); |
| 802 | |
| 803 | if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 804 | return; |
| 805 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 806 | DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 807 | |
| 808 | if (dccp_packet_without_ack(skb)) |
| 809 | return; |
| 810 | |
| 811 | if (hcrx->ccid3hcrx_elapsed_time != 0) |
| 812 | dccp_insert_option_elapsed_time(sk, skb, |
| 813 | hcrx->ccid3hcrx_elapsed_time); |
| 814 | dccp_insert_option_timestamp(sk, skb); |
| 815 | x_recv = htonl(hcrx->ccid3hcrx_x_recv); |
| 816 | pinv = htonl(hcrx->ccid3hcrx_pinv); |
| 817 | dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, |
| 818 | &pinv, sizeof(pinv)); |
| 819 | dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, |
| 820 | &x_recv, sizeof(x_recv)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 823 | /* calculate first loss interval |
| 824 | * |
| 825 | * returns estimated loss interval in usecs */ |
| 826 | |
| 827 | static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) |
| 828 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 829 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 830 | struct dccp_rx_hist_entry *entry, *next, *tail = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 831 | u32 rtt, delta, x_recv, fval, p, tmp2; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 832 | struct timeval tstamp = { 0, }; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 833 | int interval = 0; |
| 834 | int win_count = 0; |
| 835 | int step = 0; |
| 836 | u64 tmp1; |
| 837 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 838 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, |
| 839 | dccphrx_node) { |
| 840 | if (dccp_rx_hist_entry_data_packet(entry)) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 841 | tail = entry; |
| 842 | |
| 843 | switch (step) { |
| 844 | case 0: |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 845 | tstamp = entry->dccphrx_tstamp; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 846 | win_count = entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 847 | step = 1; |
| 848 | break; |
| 849 | case 1: |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 850 | interval = win_count - entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 851 | if (interval < 0) |
| 852 | interval += TFRC_WIN_COUNT_LIMIT; |
| 853 | if (interval > 4) |
| 854 | goto found; |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 860 | if (unlikely(step == 0)) { |
| 861 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, packet history " |
| 862 | "contains no data packets!\n", |
| 863 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 864 | return ~0; |
| 865 | } |
| 866 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 867 | if (unlikely(interval == 0)) { |
| 868 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, Could not find a " |
| 869 | "win_count interval > 0. Defaulting to 1\n", |
| 870 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 871 | interval = 1; |
| 872 | } |
| 873 | found: |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 874 | rtt = timeval_delta(&tstamp, &tail->dccphrx_tstamp) * 4 / interval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 875 | ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n", |
| 876 | dccp_role(sk), sk, rtt); |
| 877 | if (rtt == 0) |
| 878 | rtt = 1; |
| 879 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 880 | dccp_timestamp(sk, &tstamp); |
| 881 | delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback); |
| 882 | x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 883 | |
| 884 | tmp1 = (u64)x_recv * (u64)rtt; |
| 885 | do_div(tmp1,10000000); |
| 886 | tmp2 = (u32)tmp1; |
| 887 | fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; |
| 888 | /* do not alter order above or you will get overflow on 32 bit */ |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame] | 889 | p = tfrc_calc_x_reverse_lookup(fval); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 890 | ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " |
| 891 | "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 892 | |
| 893 | if (p == 0) |
| 894 | return ~0; |
| 895 | else |
| 896 | return 1000000 / p; |
| 897 | } |
| 898 | |
| 899 | static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) |
| 900 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 901 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 902 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 903 | if (seq_loss != DCCP_MAX_SEQNO + 1 && |
| 904 | list_empty(&hcrx->ccid3hcrx_li_hist)) { |
| 905 | struct dccp_li_hist_entry *li_tail; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 906 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 907 | li_tail = dccp_li_hist_interval_new(ccid3_li_hist, |
| 908 | &hcrx->ccid3hcrx_li_hist, |
| 909 | seq_loss, win_loss); |
| 910 | if (li_tail == NULL) |
| 911 | return; |
| 912 | li_tail->dccplih_interval = ccid3_hc_rx_calc_first_li(sk); |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 913 | } else |
| 914 | LIMIT_NETDEBUG(KERN_WARNING "%s: FIXME: find end of " |
| 915 | "interval\n", __FUNCTION__); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static void ccid3_hc_rx_detect_loss(struct sock *sk) |
| 919 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 920 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 29e4f8b | 2005-08-28 02:00:28 -0300 | [diff] [blame] | 921 | u8 win_loss; |
| 922 | const u64 seq_loss = dccp_rx_hist_detect_loss(&hcrx->ccid3hcrx_hist, |
| 923 | &hcrx->ccid3hcrx_li_hist, |
| 924 | &win_loss); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 925 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 926 | ccid3_hc_rx_update_li(sk, seq_loss, win_loss); |
| 927 | } |
| 928 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 929 | static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 930 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 931 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 932 | const struct dccp_options_received *opt_recv; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 933 | struct dccp_rx_hist_entry *packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 934 | struct timeval now; |
| 935 | u8 win_count; |
Arnaldo Carvalho de Melo | b3a3077 | 2005-09-09 02:34:10 -0300 | [diff] [blame] | 936 | u32 p_prev, r_sample, t_elapsed; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 937 | int ins; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 938 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 939 | BUG_ON(hcrx == NULL || |
| 940 | !(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA || |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 941 | hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); |
| 942 | |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 943 | opt_recv = &dccp_sk(sk)->dccps_options_received; |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 944 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 945 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
| 946 | case DCCP_PKT_ACK: |
| 947 | if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) |
| 948 | return; |
| 949 | case DCCP_PKT_DATAACK: |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 950 | if (opt_recv->dccpor_timestamp_echo == 0) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 951 | break; |
| 952 | p_prev = hcrx->ccid3hcrx_rtt; |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 953 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | b3a3077 | 2005-09-09 02:34:10 -0300 | [diff] [blame] | 954 | timeval_sub_usecs(&now, opt_recv->dccpor_timestamp_echo * 10); |
| 955 | r_sample = timeval_usecs(&now); |
| 956 | t_elapsed = opt_recv->dccpor_elapsed_time * 10; |
| 957 | |
| 958 | if (unlikely(r_sample <= t_elapsed)) |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 959 | LIMIT_NETDEBUG(KERN_WARNING "%s: r_sample=%uus, " |
| 960 | "t_elapsed=%uus\n", |
Arnaldo Carvalho de Melo | b3a3077 | 2005-09-09 02:34:10 -0300 | [diff] [blame] | 961 | __FUNCTION__, r_sample, t_elapsed); |
| 962 | else |
| 963 | r_sample -= t_elapsed; |
| 964 | |
| 965 | if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) |
| 966 | hcrx->ccid3hcrx_rtt = r_sample; |
| 967 | else |
| 968 | hcrx->ccid3hcrx_rtt = (hcrx->ccid3hcrx_rtt * 9) / 10 + |
| 969 | r_sample / 10; |
| 970 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 971 | if (p_prev != hcrx->ccid3hcrx_rtt) |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 972 | ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n", |
| 973 | dccp_role(sk), hcrx->ccid3hcrx_rtt, |
| 974 | opt_recv->dccpor_elapsed_time); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 975 | break; |
| 976 | case DCCP_PKT_DATA: |
| 977 | break; |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 978 | default: /* We're not interested in other packet types, move along */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 979 | return; |
| 980 | } |
| 981 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 982 | packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp, |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 983 | skb, SLAB_ATOMIC); |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 984 | if (unlikely(packet == NULL)) { |
| 985 | LIMIT_NETDEBUG(KERN_WARNING "%s: %s, sk=%p, Not enough mem to " |
| 986 | "add rx packet to history, consider it lost!\n", |
| 987 | __FUNCTION__, dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 991 | win_count = packet->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 992 | |
Arnaldo Carvalho de Melo | 072ab6c | 2005-08-28 01:19:14 -0300 | [diff] [blame] | 993 | ins = dccp_rx_hist_add_packet(ccid3_rx_hist, &hcrx->ccid3hcrx_hist, |
| 994 | &hcrx->ccid3hcrx_li_hist, packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 995 | |
| 996 | if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK) |
| 997 | return; |
| 998 | |
| 999 | switch (hcrx->ccid3hcrx_state) { |
| 1000 | case TFRC_RSTATE_NO_DATA: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1001 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial " |
| 1002 | "feedback\n", |
| 1003 | dccp_role(sk), sk, |
| 1004 | dccp_state_name(sk->sk_state), skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1005 | ccid3_hc_rx_send_feedback(sk); |
| 1006 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); |
| 1007 | return; |
| 1008 | case TFRC_RSTATE_DATA: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1009 | hcrx->ccid3hcrx_bytes_recv += skb->len - |
| 1010 | dccp_hdr(skb)->dccph_doff * 4; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1011 | if (ins != 0) |
| 1012 | break; |
| 1013 | |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 1014 | dccp_timestamp(sk, &now); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1015 | if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= |
| 1016 | hcrx->ccid3hcrx_rtt) { |
| 1017 | hcrx->ccid3hcrx_tstamp_last_ack = now; |
| 1018 | ccid3_hc_rx_send_feedback(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1019 | } |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1020 | return; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1021 | default: |
| 1022 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 1023 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
| 1024 | dump_stack(); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | /* Dealing with packet loss */ |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1029 | ccid3_pr_debug("%s, sk=%p(%s), data loss! Reacting...\n", |
| 1030 | dccp_role(sk), sk, dccp_state_name(sk->sk_state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1031 | |
| 1032 | ccid3_hc_rx_detect_loss(sk); |
| 1033 | p_prev = hcrx->ccid3hcrx_p; |
| 1034 | |
| 1035 | /* Calculate loss event rate */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1036 | if (!list_empty(&hcrx->ccid3hcrx_li_hist)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1037 | /* Scaling up by 1000000 as fixed decimal */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1038 | hcrx->ccid3hcrx_p = 1000000 / dccp_li_hist_calc_i_mean(&hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1039 | |
| 1040 | if (hcrx->ccid3hcrx_p > p_prev) { |
| 1041 | ccid3_hc_rx_send_feedback(sk); |
| 1042 | return; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | static int ccid3_hc_rx_init(struct sock *sk) |
| 1047 | { |
| 1048 | struct dccp_sock *dp = dccp_sk(sk); |
| 1049 | struct ccid3_hc_rx_sock *hcrx; |
| 1050 | |
| 1051 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 1052 | |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 1053 | dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any()); |
| 1054 | if (dp->dccps_hc_rx_ccid_private == NULL) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1055 | return -ENOMEM; |
| 1056 | |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 1057 | hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1058 | memset(hcrx, 0, sizeof(*hcrx)); |
| 1059 | |
Arnaldo Carvalho de Melo | a84ffe4 | 2005-08-28 04:51:32 -0300 | [diff] [blame] | 1060 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && |
| 1061 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) |
| 1062 | hcrx->ccid3hcrx_s = dp->dccps_packet_size; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1063 | else |
| 1064 | hcrx->ccid3hcrx_s = TFRC_STD_PACKET_SIZE; |
| 1065 | |
| 1066 | hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; |
| 1067 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1068 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 1069 | dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack); |
Arnaldo Carvalho de Melo | 954ee31 | 2005-09-09 02:37:05 -0300 | [diff] [blame] | 1070 | hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack; |
| 1071 | hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | static void ccid3_hc_rx_exit(struct sock *sk) |
| 1076 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 1077 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1078 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1079 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 1080 | BUG_ON(hcrx == NULL); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1081 | |
| 1082 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); |
| 1083 | |
| 1084 | /* Empty packet history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1085 | dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1086 | |
| 1087 | /* Empty loss interval history */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1088 | dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1089 | |
| 1090 | kfree(dp->dccps_hc_rx_ccid_private); |
| 1091 | dp->dccps_hc_rx_ccid_private = NULL; |
| 1092 | } |
| 1093 | |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1094 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) |
| 1095 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 1096 | const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1097 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 1098 | BUG_ON(hcrx == NULL); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1099 | |
| 1100 | info->tcpi_ca_state = hcrx->ccid3hcrx_state; |
| 1101 | info->tcpi_options |= TCPI_OPT_TIMESTAMPS; |
| 1102 | info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; |
| 1103 | } |
| 1104 | |
| 1105 | static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) |
| 1106 | { |
Arnaldo Carvalho de Melo | 59725dc | 2005-09-09 02:40:58 -0300 | [diff] [blame] | 1107 | const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1108 | |
Arnaldo Carvalho de Melo | 59d203f | 2005-09-09 20:01:25 -0300 | [diff] [blame^] | 1109 | BUG_ON(hctx == NULL); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1110 | |
| 1111 | info->tcpi_rto = hctx->ccid3hctx_t_rto; |
| 1112 | info->tcpi_rtt = hctx->ccid3hctx_rtt; |
| 1113 | } |
| 1114 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1115 | static struct ccid ccid3 = { |
| 1116 | .ccid_id = 3, |
| 1117 | .ccid_name = "ccid3", |
| 1118 | .ccid_owner = THIS_MODULE, |
| 1119 | .ccid_init = ccid3_init, |
| 1120 | .ccid_exit = ccid3_exit, |
| 1121 | .ccid_hc_tx_init = ccid3_hc_tx_init, |
| 1122 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, |
| 1123 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, |
| 1124 | .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, |
| 1125 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, |
| 1126 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, |
| 1127 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, |
| 1128 | .ccid_hc_rx_init = ccid3_hc_rx_init, |
| 1129 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, |
| 1130 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, |
| 1131 | .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv, |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1132 | .ccid_hc_rx_get_info = ccid3_hc_rx_get_info, |
| 1133 | .ccid_hc_tx_get_info = ccid3_hc_tx_get_info, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1134 | }; |
| 1135 | |
| 1136 | module_param(ccid3_debug, int, 0444); |
| 1137 | MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); |
| 1138 | |
| 1139 | static __init int ccid3_module_init(void) |
| 1140 | { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1141 | int rc = -ENOBUFS; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1142 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1143 | ccid3_rx_hist = dccp_rx_hist_new("ccid3"); |
| 1144 | if (ccid3_rx_hist == NULL) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1145 | goto out; |
| 1146 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1147 | ccid3_tx_hist = dccp_tx_hist_new("ccid3"); |
| 1148 | if (ccid3_tx_hist == NULL) |
| 1149 | goto out_free_rx; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1150 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1151 | ccid3_li_hist = dccp_li_hist_new("ccid3"); |
| 1152 | if (ccid3_li_hist == NULL) |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1153 | goto out_free_tx; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1154 | |
| 1155 | rc = ccid_register(&ccid3); |
| 1156 | if (rc != 0) |
| 1157 | goto out_free_loss_interval_history; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1158 | out: |
| 1159 | return rc; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1160 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1161 | out_free_loss_interval_history: |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1162 | dccp_li_hist_delete(ccid3_li_hist); |
| 1163 | ccid3_li_hist = NULL; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1164 | out_free_tx: |
| 1165 | dccp_tx_hist_delete(ccid3_tx_hist); |
| 1166 | ccid3_tx_hist = NULL; |
| 1167 | out_free_rx: |
| 1168 | dccp_rx_hist_delete(ccid3_rx_hist); |
| 1169 | ccid3_rx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1170 | goto out; |
| 1171 | } |
| 1172 | module_init(ccid3_module_init); |
| 1173 | |
| 1174 | static __exit void ccid3_module_exit(void) |
| 1175 | { |
Arnaldo Carvalho de Melo | 725ba8e | 2005-08-13 20:35:39 -0300 | [diff] [blame] | 1176 | #ifdef CONFIG_IP_DCCP_UNLOAD_HACK |
| 1177 | /* |
| 1178 | * Hack to use while developing, so that we get rid of the control |
| 1179 | * sock, that is what keeps a refcount on dccp.ko -acme |
| 1180 | */ |
| 1181 | extern void dccp_ctl_sock_exit(void); |
| 1182 | |
| 1183 | dccp_ctl_sock_exit(); |
| 1184 | #endif |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1185 | ccid_unregister(&ccid3); |
| 1186 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1187 | if (ccid3_tx_hist != NULL) { |
| 1188 | dccp_tx_hist_delete(ccid3_tx_hist); |
| 1189 | ccid3_tx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1190 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1191 | if (ccid3_rx_hist != NULL) { |
| 1192 | dccp_rx_hist_delete(ccid3_rx_hist); |
| 1193 | ccid3_rx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1194 | } |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1195 | if (ccid3_li_hist != NULL) { |
| 1196 | dccp_li_hist_delete(ccid3_li_hist); |
| 1197 | ccid3_li_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | module_exit(ccid3_module_exit); |
| 1201 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1202 | MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz>, " |
| 1203 | "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1204 | MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID"); |
| 1205 | MODULE_LICENSE("GPL"); |
| 1206 | MODULE_ALIAS("net-dccp-ccid-3"); |