ccid3.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. /*
  2. * net/dccp/ccids/ccid3.c
  3. *
  4. * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
  5. * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
  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/
  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. #include "../ccid.h"
  37. #include "../dccp.h"
  38. #include "lib/packet_history.h"
  39. #include "lib/loss_interval.h"
  40. #include "lib/tfrc.h"
  41. #include "ccid3.h"
  42. #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
  43. static int ccid3_debug;
  44. #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
  45. #else
  46. #define ccid3_pr_debug(format, a...)
  47. #endif
  48. static struct dccp_tx_hist *ccid3_tx_hist;
  49. static struct dccp_rx_hist *ccid3_rx_hist;
  50. /*
  51. * Transmitter Half-Connection Routines
  52. */
  53. #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
  54. static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
  55. {
  56. static char *ccid3_state_names[] = {
  57. [TFRC_SSTATE_NO_SENT] = "NO_SENT",
  58. [TFRC_SSTATE_NO_FBACK] = "NO_FBACK",
  59. [TFRC_SSTATE_FBACK] = "FBACK",
  60. [TFRC_SSTATE_TERM] = "TERM",
  61. };
  62. return ccid3_state_names[state];
  63. }
  64. #endif
  65. static void ccid3_hc_tx_set_state(struct sock *sk,
  66. enum ccid3_hc_tx_states state)
  67. {
  68. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  69. enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
  70. ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
  71. dccp_role(sk), sk, ccid3_tx_state_name(oldstate),
  72. ccid3_tx_state_name(state));
  73. WARN_ON(state == oldstate);
  74. hctx->ccid3hctx_state = state;
  75. }
  76. /*
  77. * Compute the initial sending rate X_init according to RFC 3390:
  78. * w_init = min(4 * MSS, max(2 * MSS, 4380 bytes))
  79. * X_init = w_init / RTT
  80. * For consistency with other parts of the code, X_init is scaled by 2^6.
  81. */
  82. static inline u64 rfc3390_initial_rate(struct sock *sk)
  83. {
  84. const struct dccp_sock *dp = dccp_sk(sk);
  85. const __u32 w_init = min(4 * dp->dccps_mss_cache,
  86. max(2 * dp->dccps_mss_cache, 4380U));
  87. return scaled_div(w_init << 6, ccid3_hc_tx_sk(sk)->ccid3hctx_rtt);
  88. }
  89. /*
  90. * Recalculate t_ipi and delta (should be called whenever X changes)
  91. */
  92. static inline void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hctx)
  93. {
  94. /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */
  95. hctx->ccid3hctx_t_ipi = scaled_div32(((u64)hctx->ccid3hctx_s) << 6,
  96. hctx->ccid3hctx_x);
  97. /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */
  98. hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2,
  99. TFRC_OPSYS_HALF_TIME_GRAN);
  100. ccid3_pr_debug("t_ipi=%u, delta=%u, s=%u, X=%u\n",
  101. hctx->ccid3hctx_t_ipi, hctx->ccid3hctx_delta,
  102. hctx->ccid3hctx_s, (unsigned)(hctx->ccid3hctx_x >> 6));
  103. }
  104. /*
  105. * Update X by
  106. * If (p > 0)
  107. * X_calc = calcX(s, R, p);
  108. * X = max(min(X_calc, 2 * X_recv), s / t_mbi);
  109. * Else
  110. * If (now - tld >= R)
  111. * X = max(min(2 * X, 2 * X_recv), s / R);
  112. * tld = now;
  113. *
  114. * Note: X and X_recv are both stored in units of 64 * bytes/second, to support
  115. * fine-grained resolution of sending rates. This requires scaling by 2^6
  116. * throughout the code. Only X_calc is unscaled (in bytes/second).
  117. *
  118. */
  119. static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now)
  120. {
  121. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  122. __u64 min_rate = 2 * hctx->ccid3hctx_x_recv;
  123. const __u64 old_x = hctx->ccid3hctx_x;
  124. /*
  125. * Handle IDLE periods: do not reduce below RFC3390 initial sending rate
  126. * when idling [RFC 4342, 5.1]. See also draft-ietf-dccp-rfc3448bis.
  127. * For consistency with X and X_recv, min_rate is also scaled by 2^6.
  128. */
  129. if (unlikely(hctx->ccid3hctx_idle)) {
  130. min_rate = rfc3390_initial_rate(sk);
  131. min_rate = max(min_rate, 2 * hctx->ccid3hctx_x_recv);
  132. }
  133. if (hctx->ccid3hctx_p > 0) {
  134. hctx->ccid3hctx_x = min(((__u64)hctx->ccid3hctx_x_calc) << 6,
  135. min_rate);
  136. hctx->ccid3hctx_x = max(hctx->ccid3hctx_x,
  137. (((__u64)hctx->ccid3hctx_s) << 6) /
  138. TFRC_T_MBI);
  139. } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) -
  140. (suseconds_t)hctx->ccid3hctx_rtt >= 0) {
  141. hctx->ccid3hctx_x =
  142. max(min(2 * hctx->ccid3hctx_x, min_rate),
  143. scaled_div(((__u64)hctx->ccid3hctx_s) << 6,
  144. hctx->ccid3hctx_rtt));
  145. hctx->ccid3hctx_t_ld = *now;
  146. }
  147. if (hctx->ccid3hctx_x != old_x) {
  148. ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, "
  149. "X_recv=%u\n", (unsigned)(old_x >> 6),
  150. (unsigned)(hctx->ccid3hctx_x >> 6),
  151. hctx->ccid3hctx_x_calc,
  152. (unsigned)(hctx->ccid3hctx_x_recv >> 6));
  153. ccid3_update_send_interval(hctx);
  154. }
  155. }
  156. /*
  157. * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1)
  158. * @len: DCCP packet payload size in bytes
  159. */
  160. static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len)
  161. {
  162. const u16 old_s = hctx->ccid3hctx_s;
  163. hctx->ccid3hctx_s = old_s == 0 ? len : (9 * old_s + len) / 10;
  164. if (hctx->ccid3hctx_s != old_s)
  165. ccid3_update_send_interval(hctx);
  166. }
  167. /*
  168. * Update Window Counter using the algorithm from [RFC 4342, 8.1].
  169. * The algorithm is not applicable if RTT < 4 microseconds.
  170. */
  171. static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx,
  172. ktime_t now)
  173. {
  174. u32 quarter_rtts;
  175. if (unlikely(hctx->ccid3hctx_rtt < 4)) /* avoid divide-by-zero */
  176. return;
  177. quarter_rtts = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count);
  178. quarter_rtts /= hctx->ccid3hctx_rtt / 4;
  179. if (quarter_rtts > 0) {
  180. hctx->ccid3hctx_t_last_win_count = now;
  181. hctx->ccid3hctx_last_win_count += min_t(u32, quarter_rtts, 5);
  182. hctx->ccid3hctx_last_win_count &= 0xF; /* mod 16 */
  183. }
  184. }
  185. static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
  186. {
  187. struct sock *sk = (struct sock *)data;
  188. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  189. struct timeval now;
  190. unsigned long t_nfb = USEC_PER_SEC / 5;
  191. bh_lock_sock(sk);
  192. if (sock_owned_by_user(sk)) {
  193. /* Try again later. */
  194. /* XXX: set some sensible MIB */
  195. goto restart_timer;
  196. }
  197. ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk,
  198. ccid3_tx_state_name(hctx->ccid3hctx_state));
  199. hctx->ccid3hctx_idle = 1;
  200. switch (hctx->ccid3hctx_state) {
  201. case TFRC_SSTATE_NO_FBACK:
  202. /* RFC 3448, 4.4: Halve send rate directly */
  203. hctx->ccid3hctx_x = max(hctx->ccid3hctx_x / 2,
  204. (((__u64)hctx->ccid3hctx_s) << 6) /
  205. TFRC_T_MBI);
  206. ccid3_pr_debug("%s(%p, state=%s), updated tx rate to %u "
  207. "bytes/s\n", dccp_role(sk), sk,
  208. ccid3_tx_state_name(hctx->ccid3hctx_state),
  209. (unsigned)(hctx->ccid3hctx_x >> 6));
  210. /* The value of R is still undefined and so we can not recompute
  211. * the timout value. Keep initial value as per [RFC 4342, 5]. */
  212. t_nfb = TFRC_INITIAL_TIMEOUT;
  213. ccid3_update_send_interval(hctx);
  214. break;
  215. case TFRC_SSTATE_FBACK:
  216. /*
  217. * Modify the cached value of X_recv [RFC 3448, 4.4]
  218. *
  219. * If (p == 0 || X_calc > 2 * X_recv)
  220. * X_recv = max(X_recv / 2, s / (2 * t_mbi));
  221. * Else
  222. * X_recv = X_calc / 4;
  223. *
  224. * Note that X_recv is scaled by 2^6 while X_calc is not
  225. */
  226. BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc);
  227. if (hctx->ccid3hctx_p == 0 ||
  228. (hctx->ccid3hctx_x_calc > (hctx->ccid3hctx_x_recv >> 5))) {
  229. hctx->ccid3hctx_x_recv =
  230. max(hctx->ccid3hctx_x_recv / 2,
  231. (((__u64)hctx->ccid3hctx_s) << 6) /
  232. (2 * TFRC_T_MBI));
  233. if (hctx->ccid3hctx_p == 0)
  234. dccp_timestamp(sk, &now);
  235. } else {
  236. hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc;
  237. hctx->ccid3hctx_x_recv <<= 4;
  238. }
  239. /* Now recalculate X [RFC 3448, 4.3, step (4)] */
  240. ccid3_hc_tx_update_x(sk, &now);
  241. /*
  242. * Schedule no feedback timer to expire in
  243. * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi)
  244. * See comments in packet_recv() regarding the value of t_RTO.
  245. */
  246. t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi);
  247. break;
  248. case TFRC_SSTATE_NO_SENT:
  249. DCCP_BUG("%s(%p) - Illegal state NO_SENT", dccp_role(sk), sk);
  250. /* fall through */
  251. case TFRC_SSTATE_TERM:
  252. goto out;
  253. }
  254. restart_timer:
  255. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
  256. jiffies + usecs_to_jiffies(t_nfb));
  257. out:
  258. bh_unlock_sock(sk);
  259. sock_put(sk);
  260. }
  261. /*
  262. * returns
  263. * > 0: delay (in msecs) that should pass before actually sending
  264. * = 0: can send immediately
  265. * < 0: error condition; do not send packet
  266. */
  267. static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
  268. {
  269. struct dccp_sock *dp = dccp_sk(sk);
  270. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  271. ktime_t now = ktime_get_real();
  272. s64 delay;
  273. BUG_ON(hctx == NULL);
  274. /*
  275. * This function is called only for Data and DataAck packets. Sending
  276. * zero-sized Data(Ack)s is theoretically possible, but for congestion
  277. * control this case is pathological - ignore it.
  278. */
  279. if (unlikely(skb->len == 0))
  280. return -EBADMSG;
  281. switch (hctx->ccid3hctx_state) {
  282. case TFRC_SSTATE_NO_SENT:
  283. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
  284. (jiffies +
  285. usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)));
  286. hctx->ccid3hctx_last_win_count = 0;
  287. hctx->ccid3hctx_t_last_win_count = now;
  288. /* Set t_0 for initial packet */
  289. hctx->ccid3hctx_t_nom = now;
  290. hctx->ccid3hctx_s = skb->len;
  291. /*
  292. * Use initial RTT sample when available: recommended by erratum
  293. * to RFC 4342. This implements the initialisation procedure of
  294. * draft rfc3448bis, section 4.2. Remember, X is scaled by 2^6.
  295. */
  296. if (dp->dccps_syn_rtt) {
  297. ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt);
  298. hctx->ccid3hctx_rtt = dp->dccps_syn_rtt;
  299. hctx->ccid3hctx_x = rfc3390_initial_rate(sk);
  300. hctx->ccid3hctx_t_ld = ktime_to_timeval(now);
  301. } else {
  302. /* Sender does not have RTT sample: X = MSS/second */
  303. hctx->ccid3hctx_x = dp->dccps_mss_cache;
  304. hctx->ccid3hctx_x <<= 6;
  305. }
  306. ccid3_update_send_interval(hctx);
  307. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
  308. break;
  309. case TFRC_SSTATE_NO_FBACK:
  310. case TFRC_SSTATE_FBACK:
  311. delay = ktime_us_delta(hctx->ccid3hctx_t_nom, now);
  312. ccid3_pr_debug("delay=%ld\n", (long)delay);
  313. /*
  314. * Scheduling of packet transmissions [RFC 3448, 4.6]
  315. *
  316. * if (t_now > t_nom - delta)
  317. * // send the packet now
  318. * else
  319. * // send the packet in (t_nom - t_now) milliseconds.
  320. */
  321. if (delay - (s64)hctx->ccid3hctx_delta >= 1000)
  322. return (u32)delay / 1000L;
  323. ccid3_hc_tx_update_win_count(hctx, now);
  324. break;
  325. case TFRC_SSTATE_TERM:
  326. DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
  327. return -EINVAL;
  328. }
  329. /* prepare to send now (add options etc.) */
  330. dp->dccps_hc_tx_insert_options = 1;
  331. DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
  332. hctx->ccid3hctx_idle = 0;
  333. /* set the nominal send time for the next following packet */
  334. hctx->ccid3hctx_t_nom = ktime_add_us(hctx->ccid3hctx_t_nom,
  335. hctx->ccid3hctx_t_ipi);
  336. return 0;
  337. }
  338. static void ccid3_hc_tx_packet_sent(struct sock *sk, int more,
  339. unsigned int len)
  340. {
  341. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  342. struct timeval now;
  343. struct dccp_tx_hist_entry *packet;
  344. BUG_ON(hctx == NULL);
  345. ccid3_hc_tx_update_s(hctx, len);
  346. packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC);
  347. if (unlikely(packet == NULL)) {
  348. DCCP_CRIT("packet history - out of memory!");
  349. return;
  350. }
  351. dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, packet);
  352. dccp_timestamp(sk, &now);
  353. packet->dccphtx_tstamp = now;
  354. packet->dccphtx_seqno = dccp_sk(sk)->dccps_gss;
  355. packet->dccphtx_rtt = hctx->ccid3hctx_rtt;
  356. packet->dccphtx_sent = 1;
  357. }
  358. static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
  359. {
  360. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  361. struct ccid3_options_received *opt_recv;
  362. struct dccp_tx_hist_entry *packet;
  363. struct timeval now;
  364. unsigned long t_nfb;
  365. u32 pinv, r_sample;
  366. BUG_ON(hctx == NULL);
  367. /* we are only interested in ACKs */
  368. if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
  369. DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
  370. return;
  371. opt_recv = &hctx->ccid3hctx_options_received;
  372. switch (hctx->ccid3hctx_state) {
  373. case TFRC_SSTATE_NO_FBACK:
  374. case TFRC_SSTATE_FBACK:
  375. /* get packet from history to look up t_recvdata */
  376. packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
  377. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  378. if (unlikely(packet == NULL)) {
  379. DCCP_WARN("%s(%p), seqno %llu(%s) doesn't exist "
  380. "in history!\n", dccp_role(sk), sk,
  381. (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
  382. dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
  383. return;
  384. }
  385. /* Update receive rate in units of 64 * bytes/second */
  386. hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate;
  387. hctx->ccid3hctx_x_recv <<= 6;
  388. /* Update loss event rate */
  389. pinv = opt_recv->ccid3or_loss_event_rate;
  390. if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */
  391. hctx->ccid3hctx_p = 0;
  392. else /* can not exceed 100% */
  393. hctx->ccid3hctx_p = 1000000 / pinv;
  394. dccp_timestamp(sk, &now);
  395. /*
  396. * Calculate new round trip sample as per [RFC 3448, 4.3] by
  397. * R_sample = (now - t_recvdata) - t_elapsed
  398. */
  399. r_sample = dccp_sample_rtt(sk, &now, &packet->dccphtx_tstamp);
  400. /*
  401. * Update RTT estimate by
  402. * If (No feedback recv)
  403. * R = R_sample;
  404. * Else
  405. * R = q * R + (1 - q) * R_sample;
  406. *
  407. * q is a constant, RFC 3448 recomments 0.9
  408. */
  409. if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) {
  410. /*
  411. * Larger Initial Windows [RFC 4342, sec. 5]
  412. */
  413. hctx->ccid3hctx_rtt = r_sample;
  414. hctx->ccid3hctx_x = rfc3390_initial_rate(sk);
  415. hctx->ccid3hctx_t_ld = now;
  416. ccid3_update_send_interval(hctx);
  417. ccid3_pr_debug("%s(%p), s=%u, MSS=%u, "
  418. "R_sample=%uus, X=%u\n", dccp_role(sk),
  419. sk, hctx->ccid3hctx_s,
  420. dccp_sk(sk)->dccps_mss_cache, r_sample,
  421. (unsigned)(hctx->ccid3hctx_x >> 6));
  422. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
  423. } else {
  424. hctx->ccid3hctx_rtt = (9 * hctx->ccid3hctx_rtt +
  425. r_sample) / 10;
  426. /* Update sending rate (step 4 of [RFC 3448, 4.3]) */
  427. if (hctx->ccid3hctx_p > 0)
  428. hctx->ccid3hctx_x_calc =
  429. tfrc_calc_x(hctx->ccid3hctx_s,
  430. hctx->ccid3hctx_rtt,
  431. hctx->ccid3hctx_p);
  432. ccid3_hc_tx_update_x(sk, &now);
  433. ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, "
  434. "p=%u, X_calc=%u, X_recv=%u, X=%u\n",
  435. dccp_role(sk),
  436. sk, hctx->ccid3hctx_rtt, r_sample,
  437. hctx->ccid3hctx_s, hctx->ccid3hctx_p,
  438. hctx->ccid3hctx_x_calc,
  439. (unsigned)(hctx->ccid3hctx_x_recv >> 6),
  440. (unsigned)(hctx->ccid3hctx_x >> 6));
  441. }
  442. /* unschedule no feedback timer */
  443. sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
  444. /* remove all packets older than the one acked from history */
  445. dccp_tx_hist_purge_older(ccid3_tx_hist,
  446. &hctx->ccid3hctx_hist, packet);
  447. /*
  448. * As we have calculated new ipi, delta, t_nom it is possible
  449. * that we now can send a packet, so wake up dccp_wait_for_ccid
  450. */
  451. sk->sk_write_space(sk);
  452. /*
  453. * Update timeout interval for the nofeedback timer.
  454. * We use a configuration option to increase the lower bound.
  455. * This can help avoid triggering the nofeedback timer too
  456. * often ('spinning') on LANs with small RTTs.
  457. */
  458. hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt,
  459. CONFIG_IP_DCCP_CCID3_RTO *
  460. (USEC_PER_SEC/1000));
  461. /*
  462. * Schedule no feedback timer to expire in
  463. * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi)
  464. */
  465. t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi);
  466. ccid3_pr_debug("%s(%p), Scheduled no feedback timer to "
  467. "expire in %lu jiffies (%luus)\n",
  468. dccp_role(sk),
  469. sk, usecs_to_jiffies(t_nfb), t_nfb);
  470. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
  471. jiffies + usecs_to_jiffies(t_nfb));
  472. /* set idle flag */
  473. hctx->ccid3hctx_idle = 1;
  474. break;
  475. case TFRC_SSTATE_NO_SENT: /* fall through */
  476. case TFRC_SSTATE_TERM: /* ignore feedback when closing */
  477. break;
  478. }
  479. }
  480. static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
  481. unsigned char len, u16 idx,
  482. unsigned char *value)
  483. {
  484. int rc = 0;
  485. const struct dccp_sock *dp = dccp_sk(sk);
  486. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  487. struct ccid3_options_received *opt_recv;
  488. BUG_ON(hctx == NULL);
  489. opt_recv = &hctx->ccid3hctx_options_received;
  490. if (opt_recv->ccid3or_seqno != dp->dccps_gsr) {
  491. opt_recv->ccid3or_seqno = dp->dccps_gsr;
  492. opt_recv->ccid3or_loss_event_rate = ~0;
  493. opt_recv->ccid3or_loss_intervals_idx = 0;
  494. opt_recv->ccid3or_loss_intervals_len = 0;
  495. opt_recv->ccid3or_receive_rate = 0;
  496. }
  497. switch (option) {
  498. case TFRC_OPT_LOSS_EVENT_RATE:
  499. if (unlikely(len != 4)) {
  500. DCCP_WARN("%s(%p), invalid len %d "
  501. "for TFRC_OPT_LOSS_EVENT_RATE\n",
  502. dccp_role(sk), sk, len);
  503. rc = -EINVAL;
  504. } else {
  505. opt_recv->ccid3or_loss_event_rate =
  506. ntohl(*(__be32 *)value);
  507. ccid3_pr_debug("%s(%p), LOSS_EVENT_RATE=%u\n",
  508. dccp_role(sk), sk,
  509. opt_recv->ccid3or_loss_event_rate);
  510. }
  511. break;
  512. case TFRC_OPT_LOSS_INTERVALS:
  513. opt_recv->ccid3or_loss_intervals_idx = idx;
  514. opt_recv->ccid3or_loss_intervals_len = len;
  515. ccid3_pr_debug("%s(%p), LOSS_INTERVALS=(%u, %u)\n",
  516. dccp_role(sk), sk,
  517. opt_recv->ccid3or_loss_intervals_idx,
  518. opt_recv->ccid3or_loss_intervals_len);
  519. break;
  520. case TFRC_OPT_RECEIVE_RATE:
  521. if (unlikely(len != 4)) {
  522. DCCP_WARN("%s(%p), invalid len %d "
  523. "for TFRC_OPT_RECEIVE_RATE\n",
  524. dccp_role(sk), sk, len);
  525. rc = -EINVAL;
  526. } else {
  527. opt_recv->ccid3or_receive_rate =
  528. ntohl(*(__be32 *)value);
  529. ccid3_pr_debug("%s(%p), RECEIVE_RATE=%u\n",
  530. dccp_role(sk), sk,
  531. opt_recv->ccid3or_receive_rate);
  532. }
  533. break;
  534. }
  535. return rc;
  536. }
  537. static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
  538. {
  539. struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid);
  540. hctx->ccid3hctx_s = 0;
  541. hctx->ccid3hctx_rtt = 0;
  542. hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
  543. INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
  544. hctx->ccid3hctx_no_feedback_timer.function =
  545. ccid3_hc_tx_no_feedback_timer;
  546. hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
  547. init_timer(&hctx->ccid3hctx_no_feedback_timer);
  548. return 0;
  549. }
  550. static void ccid3_hc_tx_exit(struct sock *sk)
  551. {
  552. struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  553. BUG_ON(hctx == NULL);
  554. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
  555. sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
  556. /* Empty packet history */
  557. dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist);
  558. }
  559. static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
  560. {
  561. const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  562. /* Listen socks doesn't have a private CCID block */
  563. if (sk->sk_state == DCCP_LISTEN)
  564. return;
  565. BUG_ON(hctx == NULL);
  566. info->tcpi_rto = hctx->ccid3hctx_t_rto;
  567. info->tcpi_rtt = hctx->ccid3hctx_rtt;
  568. }
  569. static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
  570. u32 __user *optval, int __user *optlen)
  571. {
  572. const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
  573. const void *val;
  574. /* Listen socks doesn't have a private CCID block */
  575. if (sk->sk_state == DCCP_LISTEN)
  576. return -EINVAL;
  577. switch (optname) {
  578. case DCCP_SOCKOPT_CCID_TX_INFO:
  579. if (len < sizeof(hctx->ccid3hctx_tfrc))
  580. return -EINVAL;
  581. len = sizeof(hctx->ccid3hctx_tfrc);
  582. val = &hctx->ccid3hctx_tfrc;
  583. break;
  584. default:
  585. return -ENOPROTOOPT;
  586. }
  587. if (put_user(len, optlen) || copy_to_user(optval, val, len))
  588. return -EFAULT;
  589. return 0;
  590. }
  591. /*
  592. * Receiver Half-Connection Routines
  593. */
  594. #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
  595. static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
  596. {
  597. static char *ccid3_rx_state_names[] = {
  598. [TFRC_RSTATE_NO_DATA] = "NO_DATA",
  599. [TFRC_RSTATE_DATA] = "DATA",
  600. [TFRC_RSTATE_TERM] = "TERM",
  601. };
  602. return ccid3_rx_state_names[state];
  603. }
  604. #endif
  605. static void ccid3_hc_rx_set_state(struct sock *sk,
  606. enum ccid3_hc_rx_states state)
  607. {
  608. struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  609. enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
  610. ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
  611. dccp_role(sk), sk, ccid3_rx_state_name(oldstate),
  612. ccid3_rx_state_name(state));
  613. WARN_ON(state == oldstate);
  614. hcrx->ccid3hcrx_state = state;
  615. }
  616. static inline void ccid3_hc_rx_update_s(struct ccid3_hc_rx_sock *hcrx, int len)
  617. {
  618. if (unlikely(len == 0)) /* don't update on empty packets (e.g. ACKs) */
  619. ccid3_pr_debug("Packet payload length is 0 - not updating\n");
  620. else
  621. hcrx->ccid3hcrx_s = hcrx->ccid3hcrx_s == 0 ? len :
  622. (9 * hcrx->ccid3hcrx_s + len) / 10;
  623. }
  624. static void ccid3_hc_rx_send_feedback(struct sock *sk)
  625. {
  626. struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  627. struct dccp_sock *dp = dccp_sk(sk);
  628. struct dccp_rx_hist_entry *packet;
  629. struct timeval now;
  630. suseconds_t delta;
  631. ccid3_pr_debug("%s(%p) - entry \n", dccp_role(sk), sk);
  632. dccp_timestamp(sk, &now);
  633. switch (hcrx->ccid3hcrx_state) {
  634. case TFRC_RSTATE_NO_DATA:
  635. hcrx->ccid3hcrx_x_recv = 0;
  636. break;
  637. case TFRC_RSTATE_DATA:
  638. delta = timeval_delta(&now,
  639. &hcrx->ccid3hcrx_tstamp_last_feedback);
  640. DCCP_BUG_ON(delta < 0);
  641. hcrx->ccid3hcrx_x_recv =
  642. scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
  643. break;
  644. case TFRC_RSTATE_TERM:
  645. DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
  646. return;
  647. }
  648. packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist);
  649. if (unlikely(packet == NULL)) {
  650. DCCP_WARN("%s(%p), no data packet in history!\n",
  651. dccp_role(sk), sk);
  652. return;
  653. }
  654. hcrx->ccid3hcrx_tstamp_last_feedback = now;
  655. hcrx->ccid3hcrx_ccval_last_counter = packet->dccphrx_ccval;
  656. hcrx->ccid3hcrx_bytes_recv = 0;
  657. /* Elapsed time information [RFC 4340, 13.2] in units of 10 * usecs */
  658. delta = timeval_delta(&now, &packet->dccphrx_tstamp);
  659. DCCP_BUG_ON(delta < 0);
  660. hcrx->ccid3hcrx_elapsed_time = delta / 10;
  661. if (hcrx->ccid3hcrx_p == 0)
  662. hcrx->ccid3hcrx_pinv = ~0U; /* see RFC 4342, 8.5 */
  663. else if (hcrx->ccid3hcrx_p > 1000000) {
  664. DCCP_WARN("p (%u) > 100%%\n", hcrx->ccid3hcrx_p);
  665. hcrx->ccid3hcrx_pinv = 1; /* use 100% in this case */
  666. } else
  667. hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p;
  668. dp->dccps_hc_rx_insert_options = 1;
  669. dccp_send_ack(sk);
  670. }
  671. static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
  672. {
  673. const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  674. __be32 x_recv, pinv;
  675. BUG_ON(hcrx == NULL);
  676. if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
  677. return 0;
  678. DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_ccval_last_counter;
  679. if (dccp_packet_without_ack(skb))
  680. return 0;
  681. x_recv = htonl(hcrx->ccid3hcrx_x_recv);
  682. pinv = htonl(hcrx->ccid3hcrx_pinv);
  683. if ((hcrx->ccid3hcrx_elapsed_time != 0 &&
  684. dccp_insert_option_elapsed_time(sk, skb,
  685. hcrx->ccid3hcrx_elapsed_time)) ||
  686. dccp_insert_option_timestamp(sk, skb) ||
  687. dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
  688. &pinv, sizeof(pinv)) ||
  689. dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE,
  690. &x_recv, sizeof(x_recv)))
  691. return -1;
  692. return 0;
  693. }
  694. static int ccid3_hc_rx_detect_loss(struct sock *sk,
  695. struct dccp_rx_hist_entry *packet)
  696. {
  697. struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  698. struct dccp_rx_hist_entry *rx_hist =
  699. dccp_rx_hist_head(&hcrx->ccid3hcrx_hist);
  700. u64 seqno = packet->dccphrx_seqno;
  701. u64 tmp_seqno;
  702. int loss = 0;
  703. u8 ccval;
  704. tmp_seqno = hcrx->ccid3hcrx_seqno_nonloss;
  705. if (!rx_hist ||
  706. follows48(packet->dccphrx_seqno, hcrx->ccid3hcrx_seqno_nonloss)) {
  707. hcrx->ccid3hcrx_seqno_nonloss = seqno;
  708. hcrx->ccid3hcrx_ccval_nonloss = packet->dccphrx_ccval;
  709. goto detect_out;
  710. }
  711. while (dccp_delta_seqno(hcrx->ccid3hcrx_seqno_nonloss, seqno)
  712. > TFRC_RECV_NUM_LATE_LOSS) {
  713. loss = 1;
  714. dccp_li_update_li(sk,
  715. &hcrx->ccid3hcrx_li_hist,
  716. &hcrx->ccid3hcrx_hist,
  717. &hcrx->ccid3hcrx_tstamp_last_feedback,
  718. hcrx->ccid3hcrx_s,
  719. hcrx->ccid3hcrx_bytes_recv,
  720. hcrx->ccid3hcrx_x_recv,
  721. hcrx->ccid3hcrx_seqno_nonloss,
  722. hcrx->ccid3hcrx_ccval_nonloss);
  723. tmp_seqno = hcrx->ccid3hcrx_seqno_nonloss;
  724. dccp_inc_seqno(&tmp_seqno);
  725. hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno;
  726. dccp_inc_seqno(&tmp_seqno);
  727. while (dccp_rx_hist_find_entry(&hcrx->ccid3hcrx_hist,
  728. tmp_seqno, &ccval)) {
  729. hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno;
  730. hcrx->ccid3hcrx_ccval_nonloss = ccval;
  731. dccp_inc_seqno(&tmp_seqno);
  732. }
  733. }
  734. /* FIXME - this code could be simplified with above while */
  735. /* but works at moment */
  736. if (follows48(packet->dccphrx_seqno, hcrx->ccid3hcrx_seqno_nonloss)) {
  737. hcrx->ccid3hcrx_seqno_nonloss = seqno;
  738. hcrx->ccid3hcrx_ccval_nonloss = packet->dccphrx_ccval;
  739. }
  740. detect_out:
  741. dccp_rx_hist_add_packet(ccid3_rx_hist, &hcrx->ccid3hcrx_hist,
  742. &hcrx->ccid3hcrx_li_hist, packet,
  743. hcrx->ccid3hcrx_seqno_nonloss);
  744. return loss;
  745. }
  746. static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
  747. {
  748. struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  749. const struct dccp_options_received *opt_recv;
  750. struct dccp_rx_hist_entry *packet;
  751. struct timeval now;
  752. u32 p_prev, r_sample, rtt_prev;
  753. int loss, payload_size;
  754. BUG_ON(hcrx == NULL);
  755. opt_recv = &dccp_sk(sk)->dccps_options_received;
  756. switch (DCCP_SKB_CB(skb)->dccpd_type) {
  757. case DCCP_PKT_ACK:
  758. if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
  759. return;
  760. case DCCP_PKT_DATAACK:
  761. if (opt_recv->dccpor_timestamp_echo == 0)
  762. break;
  763. rtt_prev = hcrx->ccid3hcrx_rtt;
  764. dccp_timestamp(sk, &now);
  765. r_sample = dccp_sample_rtt(sk, &now, NULL);
  766. if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
  767. hcrx->ccid3hcrx_rtt = r_sample;
  768. else
  769. hcrx->ccid3hcrx_rtt = (hcrx->ccid3hcrx_rtt * 9) / 10 +
  770. r_sample / 10;
  771. if (rtt_prev != hcrx->ccid3hcrx_rtt)
  772. ccid3_pr_debug("%s(%p), New RTT=%uus, elapsed time=%u\n",
  773. dccp_role(sk), sk, hcrx->ccid3hcrx_rtt,
  774. opt_recv->dccpor_elapsed_time);
  775. break;
  776. case DCCP_PKT_DATA:
  777. break;
  778. default: /* We're not interested in other packet types, move along */
  779. return;
  780. }
  781. packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
  782. skb, GFP_ATOMIC);
  783. if (unlikely(packet == NULL)) {
  784. DCCP_WARN("%s(%p), Not enough mem to add rx packet "
  785. "to history, consider it lost!\n", dccp_role(sk), sk);
  786. return;
  787. }
  788. loss = ccid3_hc_rx_detect_loss(sk, packet);
  789. if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK)
  790. return;
  791. payload_size = skb->len - dccp_hdr(skb)->dccph_doff * 4;
  792. ccid3_hc_rx_update_s(hcrx, payload_size);
  793. switch (hcrx->ccid3hcrx_state) {
  794. case TFRC_RSTATE_NO_DATA:
  795. ccid3_pr_debug("%s(%p, state=%s), skb=%p, sending initial "
  796. "feedback\n", dccp_role(sk), sk,
  797. dccp_state_name(sk->sk_state), skb);
  798. ccid3_hc_rx_send_feedback(sk);
  799. ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
  800. return;
  801. case TFRC_RSTATE_DATA:
  802. hcrx->ccid3hcrx_bytes_recv += payload_size;
  803. if (loss)
  804. break;
  805. dccp_timestamp(sk, &now);
  806. if ((timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) -
  807. (suseconds_t)hcrx->ccid3hcrx_rtt) >= 0) {
  808. hcrx->ccid3hcrx_tstamp_last_ack = now;
  809. ccid3_hc_rx_send_feedback(sk);
  810. }
  811. return;
  812. case TFRC_RSTATE_TERM:
  813. DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
  814. return;
  815. }
  816. /* Dealing with packet loss */
  817. ccid3_pr_debug("%s(%p, state=%s), data loss! Reacting...\n",
  818. dccp_role(sk), sk, dccp_state_name(sk->sk_state));
  819. p_prev = hcrx->ccid3hcrx_p;
  820. /* Calculate loss event rate */
  821. if (!list_empty(&hcrx->ccid3hcrx_li_hist)) {
  822. u32 i_mean = dccp_li_hist_calc_i_mean(&hcrx->ccid3hcrx_li_hist);
  823. /* Scaling up by 1000000 as fixed decimal */
  824. if (i_mean != 0)
  825. hcrx->ccid3hcrx_p = 1000000 / i_mean;
  826. } else
  827. DCCP_BUG("empty loss history");
  828. if (hcrx->ccid3hcrx_p > p_prev) {
  829. ccid3_hc_rx_send_feedback(sk);
  830. return;
  831. }
  832. }
  833. static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
  834. {
  835. struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid);
  836. ccid3_pr_debug("entry\n");
  837. hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
  838. INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
  839. INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist);
  840. dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
  841. hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
  842. hcrx->ccid3hcrx_s = 0;
  843. hcrx->ccid3hcrx_rtt = 0;
  844. return 0;
  845. }
  846. static void ccid3_hc_rx_exit(struct sock *sk)
  847. {
  848. struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  849. BUG_ON(hcrx == NULL);
  850. ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
  851. /* Empty packet history */
  852. dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist);
  853. /* Empty loss interval history */
  854. dccp_li_hist_purge(&hcrx->ccid3hcrx_li_hist);
  855. }
  856. static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
  857. {
  858. const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  859. /* Listen socks doesn't have a private CCID block */
  860. if (sk->sk_state == DCCP_LISTEN)
  861. return;
  862. BUG_ON(hcrx == NULL);
  863. info->tcpi_ca_state = hcrx->ccid3hcrx_state;
  864. info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
  865. info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt;
  866. }
  867. static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
  868. u32 __user *optval, int __user *optlen)
  869. {
  870. const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
  871. const void *val;
  872. /* Listen socks doesn't have a private CCID block */
  873. if (sk->sk_state == DCCP_LISTEN)
  874. return -EINVAL;
  875. switch (optname) {
  876. case DCCP_SOCKOPT_CCID_RX_INFO:
  877. if (len < sizeof(hcrx->ccid3hcrx_tfrc))
  878. return -EINVAL;
  879. len = sizeof(hcrx->ccid3hcrx_tfrc);
  880. val = &hcrx->ccid3hcrx_tfrc;
  881. break;
  882. default:
  883. return -ENOPROTOOPT;
  884. }
  885. if (put_user(len, optlen) || copy_to_user(optval, val, len))
  886. return -EFAULT;
  887. return 0;
  888. }
  889. static struct ccid_operations ccid3 = {
  890. .ccid_id = DCCPC_CCID3,
  891. .ccid_name = "ccid3",
  892. .ccid_owner = THIS_MODULE,
  893. .ccid_hc_tx_obj_size = sizeof(struct ccid3_hc_tx_sock),
  894. .ccid_hc_tx_init = ccid3_hc_tx_init,
  895. .ccid_hc_tx_exit = ccid3_hc_tx_exit,
  896. .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet,
  897. .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent,
  898. .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv,
  899. .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options,
  900. .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock),
  901. .ccid_hc_rx_init = ccid3_hc_rx_init,
  902. .ccid_hc_rx_exit = ccid3_hc_rx_exit,
  903. .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options,
  904. .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv,
  905. .ccid_hc_rx_get_info = ccid3_hc_rx_get_info,
  906. .ccid_hc_tx_get_info = ccid3_hc_tx_get_info,
  907. .ccid_hc_rx_getsockopt = ccid3_hc_rx_getsockopt,
  908. .ccid_hc_tx_getsockopt = ccid3_hc_tx_getsockopt,
  909. };
  910. #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
  911. module_param(ccid3_debug, int, 0444);
  912. MODULE_PARM_DESC(ccid3_debug, "Enable debug messages");
  913. #endif
  914. static __init int ccid3_module_init(void)
  915. {
  916. int rc = -ENOBUFS;
  917. ccid3_rx_hist = dccp_rx_hist_new("ccid3");
  918. if (ccid3_rx_hist == NULL)
  919. goto out;
  920. ccid3_tx_hist = dccp_tx_hist_new("ccid3");
  921. if (ccid3_tx_hist == NULL)
  922. goto out_free_rx;
  923. rc = ccid_register(&ccid3);
  924. if (rc != 0)
  925. goto out_free_tx;
  926. out:
  927. return rc;
  928. out_free_tx:
  929. dccp_tx_hist_delete(ccid3_tx_hist);
  930. ccid3_tx_hist = NULL;
  931. out_free_rx:
  932. dccp_rx_hist_delete(ccid3_rx_hist);
  933. ccid3_rx_hist = NULL;
  934. goto out;
  935. }
  936. module_init(ccid3_module_init);
  937. static __exit void ccid3_module_exit(void)
  938. {
  939. ccid_unregister(&ccid3);
  940. if (ccid3_tx_hist != NULL) {
  941. dccp_tx_hist_delete(ccid3_tx_hist);
  942. ccid3_tx_hist = NULL;
  943. }
  944. if (ccid3_rx_hist != NULL) {
  945. dccp_rx_hist_delete(ccid3_rx_hist);
  946. ccid3_rx_hist = NULL;
  947. }
  948. }
  949. module_exit(ccid3_module_exit);
  950. MODULE_AUTHOR("Ian McDonald <ian.mcdonald@jandi.co.nz>, "
  951. "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
  952. MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID");
  953. MODULE_LICENSE("GPL");
  954. MODULE_ALIAS("net-dccp-ccid-3");