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