ccid3.c 31 KB

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