ccid3.c 32 KB

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