ccid3.c 32 KB

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