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