ccid3.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. /*
  2. * net/dccp/ccids/ccid3.c
  3. *
  4. * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
  5. * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.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 <linux/config.h>
  37. #include "../ccid.h"
  38. #include "../dccp.h"
  39. #include "../packet_history.h"
  40. #include "ccid3.h"
  41. #ifdef CCID3_DEBUG
  42. extern int ccid3_debug;
  43. #define ccid3_pr_debug(format, a...) \
  44. do { if (ccid3_debug) \
  45. printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \
  46. } while (0)
  47. #else
  48. #define ccid3_pr_debug(format, a...)
  49. #endif
  50. #define TFRC_MIN_PACKET_SIZE 16
  51. #define TFRC_STD_PACKET_SIZE 256
  52. #define TFRC_MAX_PACKET_SIZE 65535
  53. #define TFRC_INITIAL_TIMEOUT (2 * USEC_PER_SEC)
  54. /* two seconds as per CCID3 spec 11 */
  55. #define TFRC_OPSYS_HALF_TIME_GRAN (USEC_PER_SEC / (2 * HZ))
  56. /* above is in usecs - half the scheduling granularity as per RFC3448 4.6 */
  57. #define TFRC_WIN_COUNT_PER_RTT 4
  58. #define TFRC_WIN_COUNT_LIMIT 16
  59. #define TFRC_MAX_BACK_OFF_TIME 64
  60. /* above is in seconds */
  61. #define TFRC_SMALLEST_P 40
  62. #define TFRC_RECV_IVAL_F_LENGTH 8 /* length(w[]) */
  63. /* Number of later packets received before one is considered lost */
  64. #define TFRC_RECV_NUM_LATE_LOSS 3
  65. enum ccid3_options {
  66. TFRC_OPT_LOSS_EVENT_RATE = 192,
  67. TFRC_OPT_LOSS_INTERVALS = 193,
  68. TFRC_OPT_RECEIVE_RATE = 194,
  69. };
  70. static int ccid3_debug;
  71. static struct dccp_tx_hist *ccid3_tx_hist;
  72. static struct dccp_rx_hist *ccid3_rx_hist;
  73. static kmem_cache_t *ccid3_loss_interval_hist_slab __read_mostly;
  74. static inline struct ccid3_loss_interval_hist_entry *
  75. ccid3_loss_interval_hist_entry_new(const unsigned int __nocast prio)
  76. {
  77. return kmem_cache_alloc(ccid3_loss_interval_hist_slab, prio);
  78. }
  79. static inline void ccid3_loss_interval_hist_entry_delete(struct ccid3_loss_interval_hist_entry *entry)
  80. {
  81. if (entry != NULL)
  82. kmem_cache_free(ccid3_loss_interval_hist_slab, entry);
  83. }
  84. static void ccid3_loss_interval_history_delete(struct list_head *hist)
  85. {
  86. struct ccid3_loss_interval_hist_entry *entry, *next;
  87. list_for_each_entry_safe(entry, next, hist, ccid3lih_node) {
  88. list_del_init(&entry->ccid3lih_node);
  89. kmem_cache_free(ccid3_loss_interval_hist_slab, entry);
  90. }
  91. }
  92. static int ccid3_init(struct sock *sk)
  93. {
  94. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  95. return 0;
  96. }
  97. static void ccid3_exit(struct sock *sk)
  98. {
  99. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  100. }
  101. /* TFRC sender states */
  102. enum ccid3_hc_tx_states {
  103. TFRC_SSTATE_NO_SENT = 1,
  104. TFRC_SSTATE_NO_FBACK,
  105. TFRC_SSTATE_FBACK,
  106. TFRC_SSTATE_TERM,
  107. };
  108. #ifdef CCID3_DEBUG
  109. static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
  110. {
  111. static char *ccid3_state_names[] = {
  112. [TFRC_SSTATE_NO_SENT] = "NO_SENT",
  113. [TFRC_SSTATE_NO_FBACK] = "NO_FBACK",
  114. [TFRC_SSTATE_FBACK] = "FBACK",
  115. [TFRC_SSTATE_TERM] = "TERM",
  116. };
  117. return ccid3_state_names[state];
  118. }
  119. #endif
  120. static inline void ccid3_hc_tx_set_state(struct sock *sk, enum ccid3_hc_tx_states state)
  121. {
  122. struct dccp_sock *dp = dccp_sk(sk);
  123. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  124. enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
  125. ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
  126. dccp_role(sk), sk, ccid3_tx_state_name(oldstate), ccid3_tx_state_name(state));
  127. WARN_ON(state == oldstate);
  128. hctx->ccid3hctx_state = state;
  129. }
  130. static void timeval_sub(struct timeval large, struct timeval small,
  131. struct timeval *result)
  132. {
  133. result->tv_sec = large.tv_sec-small.tv_sec;
  134. if (large.tv_usec < small.tv_usec) {
  135. (result->tv_sec)--;
  136. result->tv_usec = USEC_PER_SEC +
  137. large.tv_usec - small.tv_usec;
  138. } else
  139. result->tv_usec = large.tv_usec-small.tv_usec;
  140. }
  141. static inline void timeval_fix(struct timeval *tv)
  142. {
  143. if (tv->tv_usec >= USEC_PER_SEC) {
  144. tv->tv_sec++;
  145. tv->tv_usec -= USEC_PER_SEC;
  146. }
  147. }
  148. #define CALCX_ARRSIZE 500
  149. #define CALCX_SPLIT 50000
  150. /* equivalent to 0.05 */
  151. static const u32 calcx_lookup[CALCX_ARRSIZE][2] = {
  152. { 37172 , 8172 },
  153. { 53499 , 11567 },
  154. { 66664 , 14180 },
  155. { 78298 , 16388 },
  156. { 89021 , 18339 },
  157. { 99147 , 20108 },
  158. { 108858 , 21738 },
  159. { 118273 , 23260 },
  160. { 127474 , 24693 },
  161. { 136520 , 26052 },
  162. { 145456 , 27348 },
  163. { 154316 , 28589 },
  164. { 163130 , 29783 },
  165. { 171919 , 30935 },
  166. { 180704 , 32049 },
  167. { 189502 , 33130 },
  168. { 198328 , 34180 },
  169. { 207194 , 35202 },
  170. { 216114 , 36198 },
  171. { 225097 , 37172 },
  172. { 234153 , 38123 },
  173. { 243294 , 39055 },
  174. { 252527 , 39968 },
  175. { 261861 , 40864 },
  176. { 271305 , 41743 },
  177. { 280866 , 42607 },
  178. { 290553 , 43457 },
  179. { 300372 , 44293 },
  180. { 310333 , 45117 },
  181. { 320441 , 45929 },
  182. { 330705 , 46729 },
  183. { 341131 , 47518 },
  184. { 351728 , 48297 },
  185. { 362501 , 49066 },
  186. { 373460 , 49826 },
  187. { 384609 , 50577 },
  188. { 395958 , 51320 },
  189. { 407513 , 52054 },
  190. { 419281 , 52780 },
  191. { 431270 , 53499 },
  192. { 443487 , 54211 },
  193. { 455940 , 54916 },
  194. { 468635 , 55614 },
  195. { 481581 , 56306 },
  196. { 494785 , 56991 },
  197. { 508254 , 57671 },
  198. { 521996 , 58345 },
  199. { 536019 , 59014 },
  200. { 550331 , 59677 },
  201. { 564939 , 60335 },
  202. { 579851 , 60988 },
  203. { 595075 , 61636 },
  204. { 610619 , 62279 },
  205. { 626491 , 62918 },
  206. { 642700 , 63553 },
  207. { 659253 , 64183 },
  208. { 676158 , 64809 },
  209. { 693424 , 65431 },
  210. { 711060 , 66050 },
  211. { 729073 , 66664 },
  212. { 747472 , 67275 },
  213. { 766266 , 67882 },
  214. { 785464 , 68486 },
  215. { 805073 , 69087 },
  216. { 825103 , 69684 },
  217. { 845562 , 70278 },
  218. { 866460 , 70868 },
  219. { 887805 , 71456 },
  220. { 909606 , 72041 },
  221. { 931873 , 72623 },
  222. { 954614 , 73202 },
  223. { 977839 , 73778 },
  224. { 1001557 , 74352 },
  225. { 1025777 , 74923 },
  226. { 1050508 , 75492 },
  227. { 1075761 , 76058 },
  228. { 1101544 , 76621 },
  229. { 1127867 , 77183 },
  230. { 1154739 , 77741 },
  231. { 1182172 , 78298 },
  232. { 1210173 , 78852 },
  233. { 1238753 , 79405 },
  234. { 1267922 , 79955 },
  235. { 1297689 , 80503 },
  236. { 1328066 , 81049 },
  237. { 1359060 , 81593 },
  238. { 1390684 , 82135 },
  239. { 1422947 , 82675 },
  240. { 1455859 , 83213 },
  241. { 1489430 , 83750 },
  242. { 1523671 , 84284 },
  243. { 1558593 , 84817 },
  244. { 1594205 , 85348 },
  245. { 1630518 , 85878 },
  246. { 1667543 , 86406 },
  247. { 1705290 , 86932 },
  248. { 1743770 , 87457 },
  249. { 1782994 , 87980 },
  250. { 1822973 , 88501 },
  251. { 1863717 , 89021 },
  252. { 1905237 , 89540 },
  253. { 1947545 , 90057 },
  254. { 1990650 , 90573 },
  255. { 2034566 , 91087 },
  256. { 2079301 , 91600 },
  257. { 2124869 , 92111 },
  258. { 2171279 , 92622 },
  259. { 2218543 , 93131 },
  260. { 2266673 , 93639 },
  261. { 2315680 , 94145 },
  262. { 2365575 , 94650 },
  263. { 2416371 , 95154 },
  264. { 2468077 , 95657 },
  265. { 2520707 , 96159 },
  266. { 2574271 , 96660 },
  267. { 2628782 , 97159 },
  268. { 2684250 , 97658 },
  269. { 2740689 , 98155 },
  270. { 2798110 , 98651 },
  271. { 2856524 , 99147 },
  272. { 2915944 , 99641 },
  273. { 2976382 , 100134 },
  274. { 3037850 , 100626 },
  275. { 3100360 , 101117 },
  276. { 3163924 , 101608 },
  277. { 3228554 , 102097 },
  278. { 3294263 , 102586 },
  279. { 3361063 , 103073 },
  280. { 3428966 , 103560 },
  281. { 3497984 , 104045 },
  282. { 3568131 , 104530 },
  283. { 3639419 , 105014 },
  284. { 3711860 , 105498 },
  285. { 3785467 , 105980 },
  286. { 3860253 , 106462 },
  287. { 3936229 , 106942 },
  288. { 4013410 , 107422 },
  289. { 4091808 , 107902 },
  290. { 4171435 , 108380 },
  291. { 4252306 , 108858 },
  292. { 4334431 , 109335 },
  293. { 4417825 , 109811 },
  294. { 4502501 , 110287 },
  295. { 4588472 , 110762 },
  296. { 4675750 , 111236 },
  297. { 4764349 , 111709 },
  298. { 4854283 , 112182 },
  299. { 4945564 , 112654 },
  300. { 5038206 , 113126 },
  301. { 5132223 , 113597 },
  302. { 5227627 , 114067 },
  303. { 5324432 , 114537 },
  304. { 5422652 , 115006 },
  305. { 5522299 , 115474 },
  306. { 5623389 , 115942 },
  307. { 5725934 , 116409 },
  308. { 5829948 , 116876 },
  309. { 5935446 , 117342 },
  310. { 6042439 , 117808 },
  311. { 6150943 , 118273 },
  312. { 6260972 , 118738 },
  313. { 6372538 , 119202 },
  314. { 6485657 , 119665 },
  315. { 6600342 , 120128 },
  316. { 6716607 , 120591 },
  317. { 6834467 , 121053 },
  318. { 6953935 , 121514 },
  319. { 7075025 , 121976 },
  320. { 7197752 , 122436 },
  321. { 7322131 , 122896 },
  322. { 7448175 , 123356 },
  323. { 7575898 , 123815 },
  324. { 7705316 , 124274 },
  325. { 7836442 , 124733 },
  326. { 7969291 , 125191 },
  327. { 8103877 , 125648 },
  328. { 8240216 , 126105 },
  329. { 8378321 , 126562 },
  330. { 8518208 , 127018 },
  331. { 8659890 , 127474 },
  332. { 8803384 , 127930 },
  333. { 8948702 , 128385 },
  334. { 9095861 , 128840 },
  335. { 9244875 , 129294 },
  336. { 9395760 , 129748 },
  337. { 9548529 , 130202 },
  338. { 9703198 , 130655 },
  339. { 9859782 , 131108 },
  340. { 10018296 , 131561 },
  341. { 10178755 , 132014 },
  342. { 10341174 , 132466 },
  343. { 10505569 , 132917 },
  344. { 10671954 , 133369 },
  345. { 10840345 , 133820 },
  346. { 11010757 , 134271 },
  347. { 11183206 , 134721 },
  348. { 11357706 , 135171 },
  349. { 11534274 , 135621 },
  350. { 11712924 , 136071 },
  351. { 11893673 , 136520 },
  352. { 12076536 , 136969 },
  353. { 12261527 , 137418 },
  354. { 12448664 , 137867 },
  355. { 12637961 , 138315 },
  356. { 12829435 , 138763 },
  357. { 13023101 , 139211 },
  358. { 13218974 , 139658 },
  359. { 13417071 , 140106 },
  360. { 13617407 , 140553 },
  361. { 13819999 , 140999 },
  362. { 14024862 , 141446 },
  363. { 14232012 , 141892 },
  364. { 14441465 , 142339 },
  365. { 14653238 , 142785 },
  366. { 14867346 , 143230 },
  367. { 15083805 , 143676 },
  368. { 15302632 , 144121 },
  369. { 15523842 , 144566 },
  370. { 15747453 , 145011 },
  371. { 15973479 , 145456 },
  372. { 16201939 , 145900 },
  373. { 16432847 , 146345 },
  374. { 16666221 , 146789 },
  375. { 16902076 , 147233 },
  376. { 17140429 , 147677 },
  377. { 17381297 , 148121 },
  378. { 17624696 , 148564 },
  379. { 17870643 , 149007 },
  380. { 18119154 , 149451 },
  381. { 18370247 , 149894 },
  382. { 18623936 , 150336 },
  383. { 18880241 , 150779 },
  384. { 19139176 , 151222 },
  385. { 19400759 , 151664 },
  386. { 19665007 , 152107 },
  387. { 19931936 , 152549 },
  388. { 20201564 , 152991 },
  389. { 20473907 , 153433 },
  390. { 20748982 , 153875 },
  391. { 21026807 , 154316 },
  392. { 21307399 , 154758 },
  393. { 21590773 , 155199 },
  394. { 21876949 , 155641 },
  395. { 22165941 , 156082 },
  396. { 22457769 , 156523 },
  397. { 22752449 , 156964 },
  398. { 23049999 , 157405 },
  399. { 23350435 , 157846 },
  400. { 23653774 , 158287 },
  401. { 23960036 , 158727 },
  402. { 24269236 , 159168 },
  403. { 24581392 , 159608 },
  404. { 24896521 , 160049 },
  405. { 25214642 , 160489 },
  406. { 25535772 , 160929 },
  407. { 25859927 , 161370 },
  408. { 26187127 , 161810 },
  409. { 26517388 , 162250 },
  410. { 26850728 , 162690 },
  411. { 27187165 , 163130 },
  412. { 27526716 , 163569 },
  413. { 27869400 , 164009 },
  414. { 28215234 , 164449 },
  415. { 28564236 , 164889 },
  416. { 28916423 , 165328 },
  417. { 29271815 , 165768 },
  418. { 29630428 , 166208 },
  419. { 29992281 , 166647 },
  420. { 30357392 , 167087 },
  421. { 30725779 , 167526 },
  422. { 31097459 , 167965 },
  423. { 31472452 , 168405 },
  424. { 31850774 , 168844 },
  425. { 32232445 , 169283 },
  426. { 32617482 , 169723 },
  427. { 33005904 , 170162 },
  428. { 33397730 , 170601 },
  429. { 33792976 , 171041 },
  430. { 34191663 , 171480 },
  431. { 34593807 , 171919 },
  432. { 34999428 , 172358 },
  433. { 35408544 , 172797 },
  434. { 35821174 , 173237 },
  435. { 36237335 , 173676 },
  436. { 36657047 , 174115 },
  437. { 37080329 , 174554 },
  438. { 37507197 , 174993 },
  439. { 37937673 , 175433 },
  440. { 38371773 , 175872 },
  441. { 38809517 , 176311 },
  442. { 39250924 , 176750 },
  443. { 39696012 , 177190 },
  444. { 40144800 , 177629 },
  445. { 40597308 , 178068 },
  446. { 41053553 , 178507 },
  447. { 41513554 , 178947 },
  448. { 41977332 , 179386 },
  449. { 42444904 , 179825 },
  450. { 42916290 , 180265 },
  451. { 43391509 , 180704 },
  452. { 43870579 , 181144 },
  453. { 44353520 , 181583 },
  454. { 44840352 , 182023 },
  455. { 45331092 , 182462 },
  456. { 45825761 , 182902 },
  457. { 46324378 , 183342 },
  458. { 46826961 , 183781 },
  459. { 47333531 , 184221 },
  460. { 47844106 , 184661 },
  461. { 48358706 , 185101 },
  462. { 48877350 , 185541 },
  463. { 49400058 , 185981 },
  464. { 49926849 , 186421 },
  465. { 50457743 , 186861 },
  466. { 50992759 , 187301 },
  467. { 51531916 , 187741 },
  468. { 52075235 , 188181 },
  469. { 52622735 , 188622 },
  470. { 53174435 , 189062 },
  471. { 53730355 , 189502 },
  472. { 54290515 , 189943 },
  473. { 54854935 , 190383 },
  474. { 55423634 , 190824 },
  475. { 55996633 , 191265 },
  476. { 56573950 , 191706 },
  477. { 57155606 , 192146 },
  478. { 57741621 , 192587 },
  479. { 58332014 , 193028 },
  480. { 58926806 , 193470 },
  481. { 59526017 , 193911 },
  482. { 60129666 , 194352 },
  483. { 60737774 , 194793 },
  484. { 61350361 , 195235 },
  485. { 61967446 , 195677 },
  486. { 62589050 , 196118 },
  487. { 63215194 , 196560 },
  488. { 63845897 , 197002 },
  489. { 64481179 , 197444 },
  490. { 65121061 , 197886 },
  491. { 65765563 , 198328 },
  492. { 66414705 , 198770 },
  493. { 67068508 , 199213 },
  494. { 67726992 , 199655 },
  495. { 68390177 , 200098 },
  496. { 69058085 , 200540 },
  497. { 69730735 , 200983 },
  498. { 70408147 , 201426 },
  499. { 71090343 , 201869 },
  500. { 71777343 , 202312 },
  501. { 72469168 , 202755 },
  502. { 73165837 , 203199 },
  503. { 73867373 , 203642 },
  504. { 74573795 , 204086 },
  505. { 75285124 , 204529 },
  506. { 76001380 , 204973 },
  507. { 76722586 , 205417 },
  508. { 77448761 , 205861 },
  509. { 78179926 , 206306 },
  510. { 78916102 , 206750 },
  511. { 79657310 , 207194 },
  512. { 80403571 , 207639 },
  513. { 81154906 , 208084 },
  514. { 81911335 , 208529 },
  515. { 82672880 , 208974 },
  516. { 83439562 , 209419 },
  517. { 84211402 , 209864 },
  518. { 84988421 , 210309 },
  519. { 85770640 , 210755 },
  520. { 86558080 , 211201 },
  521. { 87350762 , 211647 },
  522. { 88148708 , 212093 },
  523. { 88951938 , 212539 },
  524. { 89760475 , 212985 },
  525. { 90574339 , 213432 },
  526. { 91393551 , 213878 },
  527. { 92218133 , 214325 },
  528. { 93048107 , 214772 },
  529. { 93883493 , 215219 },
  530. { 94724314 , 215666 },
  531. { 95570590 , 216114 },
  532. { 96422343 , 216561 },
  533. { 97279594 , 217009 },
  534. { 98142366 , 217457 },
  535. { 99010679 , 217905 },
  536. { 99884556 , 218353 },
  537. { 100764018 , 218801 },
  538. { 101649086 , 219250 },
  539. { 102539782 , 219698 },
  540. { 103436128 , 220147 },
  541. { 104338146 , 220596 },
  542. { 105245857 , 221046 },
  543. { 106159284 , 221495 },
  544. { 107078448 , 221945 },
  545. { 108003370 , 222394 },
  546. { 108934074 , 222844 },
  547. { 109870580 , 223294 },
  548. { 110812910 , 223745 },
  549. { 111761087 , 224195 },
  550. { 112715133 , 224646 },
  551. { 113675069 , 225097 },
  552. { 114640918 , 225548 },
  553. { 115612702 , 225999 },
  554. { 116590442 , 226450 },
  555. { 117574162 , 226902 },
  556. { 118563882 , 227353 },
  557. { 119559626 , 227805 },
  558. { 120561415 , 228258 },
  559. { 121569272 , 228710 },
  560. { 122583219 , 229162 },
  561. { 123603278 , 229615 },
  562. { 124629471 , 230068 },
  563. { 125661822 , 230521 },
  564. { 126700352 , 230974 },
  565. { 127745083 , 231428 },
  566. { 128796039 , 231882 },
  567. { 129853241 , 232336 },
  568. { 130916713 , 232790 },
  569. { 131986475 , 233244 },
  570. { 133062553 , 233699 },
  571. { 134144966 , 234153 },
  572. { 135233739 , 234608 },
  573. { 136328894 , 235064 },
  574. { 137430453 , 235519 },
  575. { 138538440 , 235975 },
  576. { 139652876 , 236430 },
  577. { 140773786 , 236886 },
  578. { 141901190 , 237343 },
  579. { 143035113 , 237799 },
  580. { 144175576 , 238256 },
  581. { 145322604 , 238713 },
  582. { 146476218 , 239170 },
  583. { 147636442 , 239627 },
  584. { 148803298 , 240085 },
  585. { 149976809 , 240542 },
  586. { 151156999 , 241000 },
  587. { 152343890 , 241459 },
  588. { 153537506 , 241917 },
  589. { 154737869 , 242376 },
  590. { 155945002 , 242835 },
  591. { 157158929 , 243294 },
  592. { 158379673 , 243753 },
  593. { 159607257 , 244213 },
  594. { 160841704 , 244673 },
  595. { 162083037 , 245133 },
  596. { 163331279 , 245593 },
  597. { 164586455 , 246054 },
  598. { 165848586 , 246514 },
  599. { 167117696 , 246975 },
  600. { 168393810 , 247437 },
  601. { 169676949 , 247898 },
  602. { 170967138 , 248360 },
  603. { 172264399 , 248822 },
  604. { 173568757 , 249284 },
  605. { 174880235 , 249747 },
  606. { 176198856 , 250209 },
  607. { 177524643 , 250672 },
  608. { 178857621 , 251136 },
  609. { 180197813 , 251599 },
  610. { 181545242 , 252063 },
  611. { 182899933 , 252527 },
  612. { 184261908 , 252991 },
  613. { 185631191 , 253456 },
  614. { 187007807 , 253920 },
  615. { 188391778 , 254385 },
  616. { 189783129 , 254851 },
  617. { 191181884 , 255316 },
  618. { 192588065 , 255782 },
  619. { 194001698 , 256248 },
  620. { 195422805 , 256714 },
  621. { 196851411 , 257181 },
  622. { 198287540 , 257648 },
  623. { 199731215 , 258115 },
  624. { 201182461 , 258582 },
  625. { 202641302 , 259050 },
  626. { 204107760 , 259518 },
  627. { 205581862 , 259986 },
  628. { 207063630 , 260454 },
  629. { 208553088 , 260923 },
  630. { 210050262 , 261392 },
  631. { 211555174 , 261861 },
  632. { 213067849 , 262331 },
  633. { 214588312 , 262800 },
  634. { 216116586 , 263270 },
  635. { 217652696 , 263741 },
  636. { 219196666 , 264211 },
  637. { 220748520 , 264682 },
  638. { 222308282 , 265153 },
  639. { 223875978 , 265625 },
  640. { 225451630 , 266097 },
  641. { 227035265 , 266569 },
  642. { 228626905 , 267041 },
  643. { 230226576 , 267514 },
  644. { 231834302 , 267986 },
  645. { 233450107 , 268460 },
  646. { 235074016 , 268933 },
  647. { 236706054 , 269407 },
  648. { 238346244 , 269881 },
  649. { 239994613 , 270355 },
  650. { 241651183 , 270830 },
  651. { 243315981 , 271305 }
  652. };
  653. /* Calculate the send rate as per section 3.1 of RFC3448
  654. Returns send rate in bytes per second
  655. Integer maths and lookups are used as not allowed floating point in kernel
  656. The function for Xcalc as per section 3.1 of RFC3448 is:
  657. X = s
  658. -------------------------------------------------------------
  659. R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8) * p * (1+32*p^2)))
  660. where
  661. X is the trasmit rate in bytes/second
  662. s is the packet size in bytes
  663. R is the round trip time in seconds
  664. p is the loss event rate, between 0 and 1.0, of the number of loss events
  665. as a fraction of the number of packets transmitted
  666. t_RTO is the TCP retransmission timeout value in seconds
  667. b is the number of packets acknowledged by a single TCP acknowledgement
  668. we can assume that b = 1 and t_RTO is 4 * R. With this the equation becomes:
  669. X = s
  670. -----------------------------------------------------------------------
  671. R * sqrt(2 * p / 3) + (12 * R * (sqrt(3 * p / 8) * p * (1 + 32 * p^2)))
  672. which we can break down into:
  673. X = s
  674. --------
  675. R * f(p)
  676. where f(p) = sqrt(2 * p / 3) + (12 * sqrt(3 * p / 8) * p * (1 + 32 * p * p))
  677. Function parameters:
  678. s - bytes
  679. R - RTT in usecs
  680. p - loss rate (decimal fraction multiplied by 1,000,000)
  681. Returns Xcalc in bytes per second
  682. DON'T alter this code unless you run test cases against it as the code
  683. has been manipulated to stop underflow/overlow.
  684. */
  685. static u32 ccid3_calc_x(u16 s, u32 R, u32 p)
  686. {
  687. int index;
  688. u32 f;
  689. u64 tmp1, tmp2;
  690. if (p < CALCX_SPLIT)
  691. index = (p / (CALCX_SPLIT / CALCX_ARRSIZE)) - 1;
  692. else
  693. index = (p / (1000000 / CALCX_ARRSIZE)) - 1;
  694. if (index < 0)
  695. /* p should be 0 unless there is a bug in my code */
  696. index = 0;
  697. if (R == 0)
  698. R = 1; /* RTT can't be zero or else divide by zero */
  699. BUG_ON(index >= CALCX_ARRSIZE);
  700. if (p >= CALCX_SPLIT)
  701. f = calcx_lookup[index][0];
  702. else
  703. f = calcx_lookup[index][1];
  704. tmp1 = ((u64)s * 100000000);
  705. tmp2 = ((u64)R * (u64)f);
  706. do_div(tmp2,10000);
  707. do_div(tmp1,tmp2);
  708. /* don't alter above math unless you test due to overflow on 32 bit */
  709. return (u32)tmp1;
  710. }
  711. /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */
  712. static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx)
  713. {
  714. if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK)
  715. return;
  716. /* if no feedback spec says t_ipi is 1 second (set elsewhere and then
  717. * doubles after every no feedback timer (separate function) */
  718. if (hctx->ccid3hctx_x < 10) {
  719. ccid3_pr_debug("ccid3_calc_new_t_ipi - ccid3hctx_x < 10\n");
  720. hctx->ccid3hctx_x = 10;
  721. }
  722. hctx->ccid3hctx_t_ipi = (hctx->ccid3hctx_s * 100000)
  723. / (hctx->ccid3hctx_x / 10);
  724. /* reason for above maths with 10 in there is to avoid 32 bit
  725. * overflow for jumbo packets */
  726. }
  727. /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */
  728. static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx)
  729. {
  730. hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN);
  731. }
  732. /*
  733. * Update X by
  734. * If (p > 0)
  735. * x_calc = calcX(s, R, p);
  736. * X = max(min(X_calc, 2 * X_recv), s / t_mbi);
  737. * Else
  738. * If (now - tld >= R)
  739. * X = max(min(2 * X, 2 * X_recv), s / R);
  740. * tld = now;
  741. */
  742. static void ccid3_hc_tx_update_x(struct sock *sk)
  743. {
  744. struct dccp_sock *dp = dccp_sk(sk);
  745. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  746. if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { /* to avoid large error in calcX */
  747. hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s,
  748. hctx->ccid3hctx_rtt,
  749. hctx->ccid3hctx_p);
  750. hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 2 * hctx->ccid3hctx_x_recv),
  751. hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME);
  752. } else if (now_delta(hctx->ccid3hctx_t_ld) >= hctx->ccid3hctx_rtt) {
  753. u32 rtt = hctx->ccid3hctx_rtt;
  754. if (rtt < 10) {
  755. rtt = 10;
  756. } /* avoid divide by zero below */
  757. hctx->ccid3hctx_x = max_t(u32, min_t(u32, 2 * hctx->ccid3hctx_x_recv, 2 * hctx->ccid3hctx_x),
  758. (hctx->ccid3hctx_s * 100000) / (rtt / 10));
  759. /* Using 100000 and 10 to avoid 32 bit overflow for jumbo frames */
  760. do_gettimeofday(&hctx->ccid3hctx_t_ld);
  761. }
  762. if (hctx->ccid3hctx_x == 0) {
  763. ccid3_pr_debug("ccid3hctx_x = 0!\n");
  764. hctx->ccid3hctx_x = 1;
  765. }
  766. }
  767. static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
  768. {
  769. struct sock *sk = (struct sock *)data;
  770. struct dccp_sock *dp = dccp_sk(sk);
  771. unsigned long next_tmout = 0;
  772. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  773. u32 rtt;
  774. bh_lock_sock(sk);
  775. if (sock_owned_by_user(sk)) {
  776. /* Try again later. */
  777. /* XXX: set some sensible MIB */
  778. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + HZ / 5);
  779. goto out;
  780. }
  781. ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk,
  782. ccid3_tx_state_name(hctx->ccid3hctx_state));
  783. if (hctx->ccid3hctx_x < 10) {
  784. ccid3_pr_debug("TFRC_SSTATE_NO_FBACK ccid3hctx_x < 10\n");
  785. hctx->ccid3hctx_x = 10;
  786. }
  787. switch (hctx->ccid3hctx_state) {
  788. case TFRC_SSTATE_TERM:
  789. goto out;
  790. case TFRC_SSTATE_NO_FBACK:
  791. /* Halve send rate */
  792. hctx->ccid3hctx_x /= 2;
  793. if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME))
  794. hctx->ccid3hctx_x = hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME;
  795. ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d bytes/s\n",
  796. dccp_role(sk), sk, ccid3_tx_state_name(hctx->ccid3hctx_state),
  797. hctx->ccid3hctx_x);
  798. next_tmout = max_t(u32, 2 * (hctx->ccid3hctx_s * 100000)
  799. / (hctx->ccid3hctx_x / 10), TFRC_INITIAL_TIMEOUT);
  800. /* do above maths with 100000 and 10 to prevent overflow on 32 bit */
  801. /* FIXME - not sure above calculation is correct. See section 5 of CCID3 11
  802. * should adjust tx_t_ipi and double that to achieve it really */
  803. break;
  804. case TFRC_SSTATE_FBACK:
  805. /* Check if IDLE since last timeout and recv rate is less than 4 packets per RTT */
  806. rtt = hctx->ccid3hctx_rtt;
  807. if (rtt < 10)
  808. rtt = 10;
  809. /* stop divide by zero below */
  810. if (!hctx->ccid3hctx_idle || (hctx->ccid3hctx_x_recv >=
  811. 4 * (hctx->ccid3hctx_s * 100000) / (rtt / 10))) {
  812. ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", dccp_role(sk), sk,
  813. ccid3_tx_state_name(hctx->ccid3hctx_state));
  814. /* Halve sending rate */
  815. /* If (X_calc > 2 * X_recv)
  816. * X_recv = max(X_recv / 2, s / (2 * t_mbi));
  817. * Else
  818. * X_recv = X_calc / 4;
  819. */
  820. BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && hctx->ccid3hctx_x_calc == 0);
  821. /* check also if p is zero -> x_calc is infinity? */
  822. if (hctx->ccid3hctx_p < TFRC_SMALLEST_P ||
  823. hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv)
  824. hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2,
  825. hctx->ccid3hctx_s / (2 * TFRC_MAX_BACK_OFF_TIME));
  826. else
  827. hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4;
  828. /* Update sending rate */
  829. ccid3_hc_tx_update_x(sk);
  830. }
  831. if (hctx->ccid3hctx_x == 0) {
  832. ccid3_pr_debug("TFRC_SSTATE_FBACK ccid3hctx_x = 0!\n");
  833. hctx->ccid3hctx_x = 10;
  834. }
  835. /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */
  836. next_tmout = max_t(u32, hctx->ccid3hctx_t_rto,
  837. 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x / 10));
  838. break;
  839. default:
  840. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  841. __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state);
  842. dump_stack();
  843. goto out;
  844. }
  845. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
  846. jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout)));
  847. hctx->ccid3hctx_idle = 1;
  848. out:
  849. bh_unlock_sock(sk);
  850. sock_put(sk);
  851. }
  852. static int ccid3_hc_tx_send_packet(struct sock *sk,
  853. struct sk_buff *skb, int len)
  854. {
  855. struct dccp_sock *dp = dccp_sk(sk);
  856. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  857. struct dccp_tx_hist_entry *new_packet;
  858. struct timeval now;
  859. long delay;
  860. int rc = -ENOTCONN;
  861. // ccid3_pr_debug("%s, sk=%p, skb=%p, len=%d\n", dccp_role(sk), sk, skb, len);
  862. /*
  863. * check if pure ACK or Terminating */
  864. /* XXX: We only call this function for DATA and DATAACK, on, these packets can have
  865. * zero length, but why the comment about "pure ACK"?
  866. */
  867. if (hctx == NULL || len == 0 || hctx->ccid3hctx_state == TFRC_SSTATE_TERM)
  868. goto out;
  869. /* See if last packet allocated was not sent */
  870. new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
  871. if (new_packet == NULL || new_packet->dccphtx_sent) {
  872. new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist, SLAB_ATOMIC);
  873. rc = -ENOBUFS;
  874. if (new_packet == NULL) {
  875. ccid3_pr_debug("%s, sk=%p, not enough mem to add "
  876. "to history, send refused\n", dccp_role(sk), sk);
  877. goto out;
  878. }
  879. dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet);
  880. }
  881. do_gettimeofday(&now);
  882. switch (hctx->ccid3hctx_state) {
  883. case TFRC_SSTATE_NO_SENT:
  884. ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n", dccp_role(sk), sk,
  885. dp->dccps_gss);
  886. hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer;
  887. hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
  888. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT));
  889. hctx->ccid3hctx_last_win_count = 0;
  890. hctx->ccid3hctx_t_last_win_count = now;
  891. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
  892. hctx->ccid3hctx_t_ipi = TFRC_INITIAL_TIMEOUT;
  893. /* Set nominal send time for initial packet */
  894. hctx->ccid3hctx_t_nom = now;
  895. (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi;
  896. timeval_fix(&(hctx->ccid3hctx_t_nom));
  897. ccid3_calc_new_delta(hctx);
  898. rc = 0;
  899. break;
  900. case TFRC_SSTATE_NO_FBACK:
  901. case TFRC_SSTATE_FBACK:
  902. delay = (now_delta(hctx->ccid3hctx_t_nom) - hctx->ccid3hctx_delta);
  903. ccid3_pr_debug("send_packet delay=%ld\n", delay);
  904. delay /= -1000;
  905. /* divide by -1000 is to convert to ms and get sign right */
  906. rc = delay > 0 ? delay : 0;
  907. break;
  908. default:
  909. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  910. __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state);
  911. dump_stack();
  912. rc = -EINVAL;
  913. break;
  914. }
  915. /* Can we send? if so add options and add to packet history */
  916. if (rc == 0)
  917. new_packet->dccphtx_ccval =
  918. DCCP_SKB_CB(skb)->dccpd_ccval =
  919. hctx->ccid3hctx_last_win_count;
  920. out:
  921. return rc;
  922. }
  923. static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
  924. {
  925. struct dccp_sock *dp = dccp_sk(sk);
  926. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  927. struct timeval now;
  928. BUG_ON(hctx == NULL);
  929. if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) {
  930. ccid3_pr_debug("%s, sk=%p, while state is TFRC_SSTATE_TERM!\n",
  931. dccp_role(sk), sk);
  932. return;
  933. }
  934. do_gettimeofday(&now);
  935. /* check if we have sent a data packet */
  936. if (len > 0) {
  937. unsigned long quarter_rtt;
  938. struct dccp_tx_hist_entry *packet;
  939. packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
  940. if (packet == NULL) {
  941. printk(KERN_CRIT "%s: packet doesn't exists in history!\n", __FUNCTION__);
  942. return;
  943. }
  944. if (packet->dccphtx_sent) {
  945. printk(KERN_CRIT "%s: no unsent packet in history!\n", __FUNCTION__);
  946. return;
  947. }
  948. packet->dccphtx_tstamp = now;
  949. packet->dccphtx_seqno = dp->dccps_gss;
  950. #if 0
  951. ccid3_pr_debug("%s, sk=%p, seqno=%llu inserted!\n",
  952. dccp_role(sk), sk, packet->dccphtx_seqno);
  953. #endif
  954. /*
  955. * Check if win_count have changed */
  956. /* COMPLIANCE_BEGIN
  957. * Algorithm in "8.1. Window Counter Valuer" in draft-ietf-dccp-ccid3-11.txt
  958. */
  959. quarter_rtt = now_delta(hctx->ccid3hctx_t_last_win_count) / (hctx->ccid3hctx_rtt / 4);
  960. if (quarter_rtt > 0) {
  961. hctx->ccid3hctx_t_last_win_count = now;
  962. hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count +
  963. min_t(unsigned long, quarter_rtt, 5)) % 16;
  964. ccid3_pr_debug("%s, sk=%p, window changed from %u to %u!\n",
  965. dccp_role(sk), sk,
  966. packet->dccphtx_ccval,
  967. hctx->ccid3hctx_last_win_count);
  968. }
  969. /* COMPLIANCE_END */
  970. #if 0
  971. ccid3_pr_debug("%s, sk=%p, packet sent (%llu,%u)\n",
  972. dccp_role(sk), sk,
  973. packet->dccphtx_seqno,
  974. packet->dccphtx_ccval);
  975. #endif
  976. hctx->ccid3hctx_idle = 0;
  977. packet->dccphtx_rtt = hctx->ccid3hctx_rtt;
  978. packet->dccphtx_sent = 1;
  979. } else
  980. ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n",
  981. dccp_role(sk), sk, dp->dccps_gss);
  982. switch (hctx->ccid3hctx_state) {
  983. case TFRC_SSTATE_NO_SENT:
  984. /* if first wasn't pure ack */
  985. if (len != 0)
  986. printk(KERN_CRIT "%s: %s, First packet sent is noted as a data packet\n",
  987. __FUNCTION__, dccp_role(sk));
  988. return;
  989. case TFRC_SSTATE_NO_FBACK:
  990. case TFRC_SSTATE_FBACK:
  991. if (len > 0) {
  992. hctx->ccid3hctx_t_nom = now;
  993. ccid3_calc_new_t_ipi(hctx);
  994. ccid3_calc_new_delta(hctx);
  995. (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi;
  996. timeval_fix(&(hctx->ccid3hctx_t_nom));
  997. }
  998. break;
  999. default:
  1000. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  1001. __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state);
  1002. dump_stack();
  1003. break;
  1004. }
  1005. }
  1006. static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
  1007. {
  1008. struct dccp_sock *dp = dccp_sk(sk);
  1009. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  1010. struct ccid3_options_received *opt_recv;
  1011. struct dccp_tx_hist_entry *packet;
  1012. unsigned long next_tmout;
  1013. u32 t_elapsed;
  1014. u32 pinv;
  1015. u32 x_recv;
  1016. u32 r_sample;
  1017. #if 0
  1018. ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n",
  1019. dccp_role(sk), sk, dccp_state_name(sk->sk_state),
  1020. skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
  1021. #endif
  1022. if (hctx == NULL)
  1023. return;
  1024. if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) {
  1025. ccid3_pr_debug("%s, sk=%p, received a packet when terminating!\n", dccp_role(sk), sk);
  1026. return;
  1027. }
  1028. /* we are only interested in ACKs */
  1029. if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
  1030. DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
  1031. return;
  1032. opt_recv = &hctx->ccid3hctx_options_received;
  1033. t_elapsed = dp->dccps_options_received.dccpor_elapsed_time;
  1034. x_recv = opt_recv->ccid3or_receive_rate;
  1035. pinv = opt_recv->ccid3or_loss_event_rate;
  1036. switch (hctx->ccid3hctx_state) {
  1037. case TFRC_SSTATE_NO_SENT:
  1038. /* FIXME: what to do here? */
  1039. return;
  1040. case TFRC_SSTATE_NO_FBACK:
  1041. case TFRC_SSTATE_FBACK:
  1042. /* Calculate new round trip sample by
  1043. * R_sample = (now - t_recvdata) - t_delay */
  1044. /* get t_recvdata from history */
  1045. packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
  1046. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  1047. if (packet == NULL) {
  1048. ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't exist in history!\n",
  1049. dccp_role(sk), sk, DCCP_SKB_CB(skb)->dccpd_ack_seq,
  1050. dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
  1051. return;
  1052. }
  1053. /* Update RTT */
  1054. r_sample = now_delta(packet->dccphtx_tstamp);
  1055. /* FIXME: */
  1056. // r_sample -= usecs_to_jiffies(t_elapsed * 10);
  1057. /* Update RTT estimate by
  1058. * If (No feedback recv)
  1059. * R = R_sample;
  1060. * Else
  1061. * R = q * R + (1 - q) * R_sample;
  1062. *
  1063. * q is a constant, RFC 3448 recomments 0.9
  1064. */
  1065. if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) {
  1066. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
  1067. hctx->ccid3hctx_rtt = r_sample;
  1068. } else
  1069. hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + r_sample / 10;
  1070. /*
  1071. * XXX: this is to avoid a division by zero in ccid3_hc_tx_packet_sent
  1072. * implemention of the new window count.
  1073. */
  1074. if (hctx->ccid3hctx_rtt < 4)
  1075. hctx->ccid3hctx_rtt = 4;
  1076. ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, r_sample=%us\n",
  1077. dccp_role(sk), sk,
  1078. hctx->ccid3hctx_rtt,
  1079. r_sample);
  1080. /* Update timeout interval */
  1081. hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt,
  1082. USEC_PER_SEC);
  1083. /* Update receive rate */
  1084. hctx->ccid3hctx_x_recv = x_recv; /* x_recv in bytes per second */
  1085. /* Update loss event rate */
  1086. if (pinv == ~0 || pinv == 0)
  1087. hctx->ccid3hctx_p = 0;
  1088. else {
  1089. hctx->ccid3hctx_p = 1000000 / pinv;
  1090. if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) {
  1091. hctx->ccid3hctx_p = TFRC_SMALLEST_P;
  1092. ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", dccp_role(sk), sk);
  1093. }
  1094. }
  1095. /* unschedule no feedback timer */
  1096. sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
  1097. /* Update sending rate */
  1098. ccid3_hc_tx_update_x(sk);
  1099. /* Update next send time */
  1100. if (hctx->ccid3hctx_t_ipi > (hctx->ccid3hctx_t_nom).tv_usec) {
  1101. hctx->ccid3hctx_t_nom.tv_usec += USEC_PER_SEC;
  1102. (hctx->ccid3hctx_t_nom).tv_sec--;
  1103. }
  1104. /* FIXME - if no feedback then t_ipi can go > 1 second */
  1105. (hctx->ccid3hctx_t_nom).tv_usec -= hctx->ccid3hctx_t_ipi;
  1106. ccid3_calc_new_t_ipi(hctx);
  1107. (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi;
  1108. timeval_fix(&(hctx->ccid3hctx_t_nom));
  1109. ccid3_calc_new_delta(hctx);
  1110. /* remove all packets older than the one acked from history */
  1111. dccp_tx_hist_purge_older(ccid3_tx_hist,
  1112. &hctx->ccid3hctx_hist, packet);
  1113. if (hctx->ccid3hctx_x < 10) {
  1114. ccid3_pr_debug("ccid3_hc_tx_packet_recv hctx->ccid3hctx_x < 10\n");
  1115. hctx->ccid3hctx_x = 10;
  1116. }
  1117. /* to prevent divide by zero below */
  1118. /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */
  1119. next_tmout = max(hctx->ccid3hctx_t_rto,
  1120. (2 * (hctx->ccid3hctx_s * 100000) /
  1121. (hctx->ccid3hctx_x / 10)));
  1122. /* maths with 100000 and 10 is to prevent overflow with 32 bit */
  1123. ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to expire in %lu jiffies (%luus)\n",
  1124. dccp_role(sk), sk, usecs_to_jiffies(next_tmout), next_tmout);
  1125. sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
  1126. jiffies + max_t(u32,1,usecs_to_jiffies(next_tmout)));
  1127. /* set idle flag */
  1128. hctx->ccid3hctx_idle = 1;
  1129. break;
  1130. default:
  1131. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  1132. __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state);
  1133. dump_stack();
  1134. break;
  1135. }
  1136. }
  1137. static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
  1138. {
  1139. const struct dccp_sock *dp = dccp_sk(sk);
  1140. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  1141. if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
  1142. return;
  1143. DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
  1144. }
  1145. static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
  1146. unsigned char len, u16 idx, unsigned char *value)
  1147. {
  1148. int rc = 0;
  1149. struct dccp_sock *dp = dccp_sk(sk);
  1150. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  1151. struct ccid3_options_received *opt_recv;
  1152. if (hctx == NULL)
  1153. return 0;
  1154. opt_recv = &hctx->ccid3hctx_options_received;
  1155. if (opt_recv->ccid3or_seqno != dp->dccps_gsr) {
  1156. opt_recv->ccid3or_seqno = dp->dccps_gsr;
  1157. opt_recv->ccid3or_loss_event_rate = ~0;
  1158. opt_recv->ccid3or_loss_intervals_idx = 0;
  1159. opt_recv->ccid3or_loss_intervals_len = 0;
  1160. opt_recv->ccid3or_receive_rate = 0;
  1161. }
  1162. switch (option) {
  1163. case TFRC_OPT_LOSS_EVENT_RATE:
  1164. if (len != 4) {
  1165. ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_LOSS_EVENT_RATE\n",
  1166. dccp_role(sk), sk);
  1167. rc = -EINVAL;
  1168. } else {
  1169. opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value);
  1170. ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n",
  1171. dccp_role(sk), sk,
  1172. opt_recv->ccid3or_loss_event_rate);
  1173. }
  1174. break;
  1175. case TFRC_OPT_LOSS_INTERVALS:
  1176. opt_recv->ccid3or_loss_intervals_idx = idx;
  1177. opt_recv->ccid3or_loss_intervals_len = len;
  1178. ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n",
  1179. dccp_role(sk), sk,
  1180. opt_recv->ccid3or_loss_intervals_idx,
  1181. opt_recv->ccid3or_loss_intervals_len);
  1182. break;
  1183. case TFRC_OPT_RECEIVE_RATE:
  1184. if (len != 4) {
  1185. ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_RECEIVE_RATE\n",
  1186. dccp_role(sk), sk);
  1187. rc = -EINVAL;
  1188. } else {
  1189. opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value);
  1190. ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n",
  1191. dccp_role(sk), sk,
  1192. opt_recv->ccid3or_receive_rate);
  1193. }
  1194. break;
  1195. }
  1196. return rc;
  1197. }
  1198. static int ccid3_hc_tx_init(struct sock *sk)
  1199. {
  1200. struct dccp_sock *dp = dccp_sk(sk);
  1201. struct ccid3_hc_tx_sock *hctx;
  1202. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  1203. hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any());
  1204. if (hctx == NULL)
  1205. return -ENOMEM;
  1206. memset(hctx, 0, sizeof(*hctx));
  1207. if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE &&
  1208. dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE)
  1209. hctx->ccid3hctx_s = (u16)dp->dccps_avg_packet_size;
  1210. else
  1211. hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE;
  1212. hctx->ccid3hctx_x = hctx->ccid3hctx_s; /* set transmission rate to 1 packet per second */
  1213. hctx->ccid3hctx_rtt = 4; /* See ccid3_hc_tx_packet_sent win_count calculatation */
  1214. hctx->ccid3hctx_t_rto = USEC_PER_SEC;
  1215. hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
  1216. INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
  1217. init_timer(&hctx->ccid3hctx_no_feedback_timer);
  1218. return 0;
  1219. }
  1220. static void ccid3_hc_tx_exit(struct sock *sk)
  1221. {
  1222. struct dccp_sock *dp = dccp_sk(sk);
  1223. struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  1224. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  1225. BUG_ON(hctx == NULL);
  1226. ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
  1227. sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
  1228. /* Empty packet history */
  1229. dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist);
  1230. kfree(dp->dccps_hc_tx_ccid_private);
  1231. dp->dccps_hc_tx_ccid_private = NULL;
  1232. }
  1233. /*
  1234. * RX Half Connection methods
  1235. */
  1236. /* TFRC receiver states */
  1237. enum ccid3_hc_rx_states {
  1238. TFRC_RSTATE_NO_DATA = 1,
  1239. TFRC_RSTATE_DATA,
  1240. TFRC_RSTATE_TERM = 127,
  1241. };
  1242. #ifdef CCID3_DEBUG
  1243. static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
  1244. {
  1245. static char *ccid3_rx_state_names[] = {
  1246. [TFRC_RSTATE_NO_DATA] = "NO_DATA",
  1247. [TFRC_RSTATE_DATA] = "DATA",
  1248. [TFRC_RSTATE_TERM] = "TERM",
  1249. };
  1250. return ccid3_rx_state_names[state];
  1251. }
  1252. #endif
  1253. static inline void ccid3_hc_rx_set_state(struct sock *sk, enum ccid3_hc_rx_states state)
  1254. {
  1255. struct dccp_sock *dp = dccp_sk(sk);
  1256. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1257. enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
  1258. ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
  1259. dccp_role(sk), sk, ccid3_rx_state_name(oldstate), ccid3_rx_state_name(state));
  1260. WARN_ON(state == oldstate);
  1261. hcrx->ccid3hcrx_state = state;
  1262. }
  1263. static int ccid3_hc_rx_add_hist(struct sock *sk,
  1264. struct dccp_rx_hist_entry *packet)
  1265. {
  1266. struct dccp_sock *dp = dccp_sk(sk);
  1267. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1268. struct dccp_rx_hist_entry *entry, *next, *iter;
  1269. u8 num_later = 0;
  1270. iter = dccp_rx_hist_head(&hcrx->ccid3hcrx_hist);
  1271. if (iter == NULL)
  1272. dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, packet);
  1273. else {
  1274. const u64 seqno = packet->dccphrx_seqno;
  1275. if (after48(seqno, iter->dccphrx_seqno))
  1276. dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, packet);
  1277. else {
  1278. if (dccp_rx_hist_entry_data_packet(iter))
  1279. num_later = 1;
  1280. list_for_each_entry_continue(iter,
  1281. &hcrx->ccid3hcrx_hist,
  1282. dccphrx_node) {
  1283. if (after48(seqno, iter->dccphrx_seqno)) {
  1284. dccp_rx_hist_add_entry(&iter->dccphrx_node,
  1285. packet);
  1286. goto trim_history;
  1287. }
  1288. if (dccp_rx_hist_entry_data_packet(iter))
  1289. num_later++;
  1290. if (num_later == TFRC_RECV_NUM_LATE_LOSS) {
  1291. dccp_rx_hist_entry_delete(ccid3_rx_hist, packet);
  1292. ccid3_pr_debug("%s, sk=%p, packet(%llu) already lost!\n",
  1293. dccp_role(sk), sk, seqno);
  1294. return 1;
  1295. }
  1296. }
  1297. if (num_later < TFRC_RECV_NUM_LATE_LOSS)
  1298. dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist,
  1299. packet);
  1300. /* FIXME: else what? should we destroy the packet like above? */
  1301. }
  1302. }
  1303. trim_history:
  1304. /* Trim history (remove all packets after the NUM_LATE_LOSS + 1 data packets) */
  1305. num_later = TFRC_RECV_NUM_LATE_LOSS + 1;
  1306. if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
  1307. list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist,
  1308. dccphrx_node) {
  1309. if (num_later == 0) {
  1310. list_del_init(&entry->dccphrx_node);
  1311. dccp_rx_hist_entry_delete(ccid3_rx_hist, entry);
  1312. } else if (dccp_rx_hist_entry_data_packet(entry))
  1313. --num_later;
  1314. }
  1315. } else {
  1316. int step = 0;
  1317. u8 win_count = 0; /* Not needed, but lets shut up gcc */
  1318. int tmp;
  1319. /*
  1320. * We have no loss interval history so we need at least one
  1321. * rtt:s of data packets to approximate rtt.
  1322. */
  1323. list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist,
  1324. dccphrx_node) {
  1325. if (num_later == 0) {
  1326. switch (step) {
  1327. case 0:
  1328. step = 1;
  1329. /* OK, find next data packet */
  1330. num_later = 1;
  1331. break;
  1332. case 1:
  1333. step = 2;
  1334. /* OK, find next data packet */
  1335. num_later = 1;
  1336. win_count = entry->dccphrx_ccval;
  1337. break;
  1338. case 2:
  1339. tmp = win_count - entry->dccphrx_ccval;
  1340. if (tmp < 0)
  1341. tmp += TFRC_WIN_COUNT_LIMIT;
  1342. if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) {
  1343. /* we have found a packet older than one rtt
  1344. * remove the rest */
  1345. step = 3;
  1346. } else /* OK, find next data packet */
  1347. num_later = 1;
  1348. break;
  1349. case 3:
  1350. list_del_init(&entry->dccphrx_node);
  1351. dccp_rx_hist_entry_delete(ccid3_rx_hist, entry);
  1352. break;
  1353. }
  1354. } else if (dccp_rx_hist_entry_data_packet(entry))
  1355. --num_later;
  1356. }
  1357. }
  1358. return 0;
  1359. }
  1360. static void ccid3_hc_rx_send_feedback(struct sock *sk)
  1361. {
  1362. struct dccp_sock *dp = dccp_sk(sk);
  1363. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1364. struct dccp_rx_hist_entry *packet;
  1365. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  1366. switch (hcrx->ccid3hcrx_state) {
  1367. case TFRC_RSTATE_NO_DATA:
  1368. hcrx->ccid3hcrx_x_recv = 0;
  1369. break;
  1370. case TFRC_RSTATE_DATA: {
  1371. u32 delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback);
  1372. if (delta == 0)
  1373. delta = 1; /* to prevent divide by zero */
  1374. hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv *
  1375. USEC_PER_SEC) / delta;
  1376. }
  1377. break;
  1378. default:
  1379. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  1380. __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state);
  1381. dump_stack();
  1382. return;
  1383. }
  1384. packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist);
  1385. if (packet == NULL) {
  1386. printk(KERN_CRIT "%s: %s, sk=%p, no data packet in history!\n",
  1387. __FUNCTION__, dccp_role(sk), sk);
  1388. dump_stack();
  1389. return;
  1390. }
  1391. do_gettimeofday(&(hcrx->ccid3hcrx_tstamp_last_feedback));
  1392. hcrx->ccid3hcrx_last_counter = packet->dccphrx_ccval;
  1393. hcrx->ccid3hcrx_seqno_last_counter = packet->dccphrx_seqno;
  1394. hcrx->ccid3hcrx_bytes_recv = 0;
  1395. /* Convert to multiples of 10us */
  1396. hcrx->ccid3hcrx_elapsed_time = now_delta(packet->dccphrx_tstamp) / 10;
  1397. if (hcrx->ccid3hcrx_p == 0)
  1398. hcrx->ccid3hcrx_pinv = ~0;
  1399. else
  1400. hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p;
  1401. dccp_send_ack(sk);
  1402. }
  1403. static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
  1404. {
  1405. const struct dccp_sock *dp = dccp_sk(sk);
  1406. u32 x_recv, pinv;
  1407. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1408. if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
  1409. return;
  1410. DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter;
  1411. if (dccp_packet_without_ack(skb))
  1412. return;
  1413. if (hcrx->ccid3hcrx_elapsed_time != 0)
  1414. dccp_insert_option_elapsed_time(sk, skb,
  1415. hcrx->ccid3hcrx_elapsed_time);
  1416. dccp_insert_option_timestamp(sk, skb);
  1417. x_recv = htonl(hcrx->ccid3hcrx_x_recv);
  1418. pinv = htonl(hcrx->ccid3hcrx_pinv);
  1419. dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
  1420. &pinv, sizeof(pinv));
  1421. dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE,
  1422. &x_recv, sizeof(x_recv));
  1423. }
  1424. /* Weights used to calculate loss event rate */
  1425. /*
  1426. * These are integers as per section 8 of RFC3448. We can then divide by 4 *
  1427. * when we use it.
  1428. */
  1429. static const int ccid3_hc_rx_w[TFRC_RECV_IVAL_F_LENGTH] = {
  1430. 4, 4, 4, 4, 3, 2, 1, 1,
  1431. };
  1432. /*
  1433. * args: fvalue - function value to match
  1434. * returns: p closest to that value
  1435. *
  1436. * both fvalue and p are multiplied by 1,000,000 to use ints
  1437. */
  1438. static u32 calcx_reverse_lookup(u32 fvalue) {
  1439. int ctr = 0;
  1440. int small;
  1441. if (fvalue < calcx_lookup[0][1])
  1442. return 0;
  1443. if (fvalue <= calcx_lookup[CALCX_ARRSIZE-1][1])
  1444. small = 1;
  1445. else if (fvalue > calcx_lookup[CALCX_ARRSIZE-1][0])
  1446. return 1000000;
  1447. else
  1448. small = 0;
  1449. while (fvalue > calcx_lookup[ctr][small])
  1450. ctr++;
  1451. if (small)
  1452. return (CALCX_SPLIT * ctr / CALCX_ARRSIZE);
  1453. else
  1454. return (1000000 * ctr / CALCX_ARRSIZE) ;
  1455. }
  1456. /* calculate first loss interval
  1457. *
  1458. * returns estimated loss interval in usecs */
  1459. static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
  1460. {
  1461. struct dccp_sock *dp = dccp_sk(sk);
  1462. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1463. struct dccp_rx_hist_entry *entry, *next, *tail = NULL;
  1464. u32 rtt, delta, x_recv, fval, p, tmp2;
  1465. struct timeval tstamp = { 0 }, tmp_tv;
  1466. int interval = 0;
  1467. int win_count = 0;
  1468. int step = 0;
  1469. u64 tmp1;
  1470. list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist,
  1471. dccphrx_node) {
  1472. if (dccp_rx_hist_entry_data_packet(entry)) {
  1473. tail = entry;
  1474. switch (step) {
  1475. case 0:
  1476. tstamp = entry->dccphrx_tstamp;
  1477. win_count = entry->dccphrx_ccval;
  1478. step = 1;
  1479. break;
  1480. case 1:
  1481. interval = win_count - entry->dccphrx_ccval;
  1482. if (interval < 0)
  1483. interval += TFRC_WIN_COUNT_LIMIT;
  1484. if (interval > 4)
  1485. goto found;
  1486. break;
  1487. }
  1488. }
  1489. }
  1490. if (step == 0) {
  1491. printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no data packets!\n",
  1492. __FUNCTION__, dccp_role(sk), sk);
  1493. return ~0;
  1494. }
  1495. if (interval == 0) {
  1496. ccid3_pr_debug("%s, sk=%p, Could not find a win_count interval > 0. Defaulting to 1\n",
  1497. dccp_role(sk), sk);
  1498. interval = 1;
  1499. }
  1500. found:
  1501. timeval_sub(tstamp,tail->dccphrx_tstamp,&tmp_tv);
  1502. rtt = (tmp_tv.tv_sec * USEC_PER_SEC + tmp_tv.tv_usec) * 4 / interval;
  1503. ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n",
  1504. dccp_role(sk), sk, rtt);
  1505. if (rtt == 0)
  1506. rtt = 1;
  1507. delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback);
  1508. if (delta == 0)
  1509. delta = 1;
  1510. x_recv = (hcrx->ccid3hcrx_bytes_recv * USEC_PER_SEC) / delta;
  1511. tmp1 = (u64)x_recv * (u64)rtt;
  1512. do_div(tmp1,10000000);
  1513. tmp2 = (u32)tmp1;
  1514. fval = (hcrx->ccid3hcrx_s * 100000) / tmp2;
  1515. /* do not alter order above or you will get overflow on 32 bit */
  1516. p = calcx_reverse_lookup(fval);
  1517. ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied loss rate=%u\n",\
  1518. dccp_role(sk), sk, x_recv, p);
  1519. if (p == 0)
  1520. return ~0;
  1521. else
  1522. return 1000000 / p;
  1523. }
  1524. static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
  1525. {
  1526. struct dccp_sock *dp = dccp_sk(sk);
  1527. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1528. struct ccid3_loss_interval_hist_entry *li_entry;
  1529. if (seq_loss != DCCP_MAX_SEQNO + 1) {
  1530. ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, packet loss detected\n",
  1531. dccp_role(sk), sk, seq_loss, win_loss);
  1532. if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
  1533. struct ccid3_loss_interval_hist_entry *li_tail = NULL;
  1534. int i;
  1535. ccid3_pr_debug("%s, sk=%p, first loss event detected, creating history\n", dccp_role(sk), sk);
  1536. for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) {
  1537. li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC);
  1538. if (li_entry == NULL) {
  1539. ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist);
  1540. ccid3_pr_debug("%s, sk=%p, not enough mem for creating history\n",
  1541. dccp_role(sk), sk);
  1542. return;
  1543. }
  1544. if (li_tail == NULL)
  1545. li_tail = li_entry;
  1546. list_add(&li_entry->ccid3lih_node, &hcrx->ccid3hcrx_loss_interval_hist);
  1547. }
  1548. li_entry->ccid3lih_seqno = seq_loss;
  1549. li_entry->ccid3lih_win_count = win_loss;
  1550. li_tail->ccid3lih_interval = ccid3_hc_rx_calc_first_li(sk);
  1551. }
  1552. }
  1553. /* FIXME: find end of interval */
  1554. }
  1555. static void ccid3_hc_rx_detect_loss(struct sock *sk)
  1556. {
  1557. struct dccp_sock *dp = dccp_sk(sk);
  1558. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1559. struct dccp_rx_hist_entry *entry, *next, *packet;
  1560. struct dccp_rx_hist_entry *a_loss = NULL;
  1561. struct dccp_rx_hist_entry *b_loss = NULL;
  1562. u64 seq_loss = DCCP_MAX_SEQNO + 1;
  1563. u8 win_loss = 0;
  1564. u8 num_later = TFRC_RECV_NUM_LATE_LOSS;
  1565. list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist,
  1566. dccphrx_node) {
  1567. if (num_later == 0) {
  1568. b_loss = entry;
  1569. break;
  1570. } else if (dccp_rx_hist_entry_data_packet(entry))
  1571. --num_later;
  1572. }
  1573. if (b_loss == NULL)
  1574. goto out_update_li;
  1575. num_later = 1;
  1576. list_for_each_entry_safe_continue(entry, next, &hcrx->ccid3hcrx_hist,
  1577. dccphrx_node) {
  1578. if (num_later == 0) {
  1579. a_loss = entry;
  1580. break;
  1581. } else if (dccp_rx_hist_entry_data_packet(entry))
  1582. --num_later;
  1583. }
  1584. if (a_loss == NULL) {
  1585. if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) {
  1586. /* no loss event have occured yet */
  1587. ccid3_pr_debug("%s, sk=%p, TODO: find a lost data "
  1588. "packet by comparing to initial seqno\n",
  1589. dccp_role(sk), sk);
  1590. goto out_update_li;
  1591. } else {
  1592. pr_info("%s: %s, sk=%p, ERROR! Less than 4 data packets in history",
  1593. __FUNCTION__, dccp_role(sk), sk);
  1594. return;
  1595. }
  1596. }
  1597. /* Locate a lost data packet */
  1598. entry = packet = b_loss;
  1599. list_for_each_entry_safe_continue(entry, next, &hcrx->ccid3hcrx_hist,
  1600. dccphrx_node) {
  1601. u64 delta = dccp_delta_seqno(entry->dccphrx_seqno,
  1602. packet->dccphrx_seqno);
  1603. if (delta != 0) {
  1604. if (dccp_rx_hist_entry_data_packet(packet))
  1605. --delta;
  1606. /*
  1607. * FIXME: check this, probably this % usage is because
  1608. * in earlier drafts the ndp count was just 8 bits
  1609. * long, but now it cam be up to 24 bits long.
  1610. */
  1611. #if 0
  1612. if (delta % DCCP_NDP_LIMIT !=
  1613. (packet->dccphrx_ndp -
  1614. entry->dccphrx_ndp) % DCCP_NDP_LIMIT)
  1615. #endif
  1616. if (delta !=
  1617. packet->dccphrx_ndp - entry->dccphrx_ndp) {
  1618. seq_loss = entry->dccphrx_seqno;
  1619. dccp_inc_seqno(&seq_loss);
  1620. }
  1621. }
  1622. packet = entry;
  1623. if (packet == a_loss)
  1624. break;
  1625. }
  1626. if (seq_loss != DCCP_MAX_SEQNO + 1)
  1627. win_loss = a_loss->dccphrx_ccval;
  1628. out_update_li:
  1629. ccid3_hc_rx_update_li(sk, seq_loss, win_loss);
  1630. }
  1631. static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk)
  1632. {
  1633. struct dccp_sock *dp = dccp_sk(sk);
  1634. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1635. struct ccid3_loss_interval_hist_entry *li_entry, *li_next;
  1636. int i = 0;
  1637. u32 i_tot;
  1638. u32 i_tot0 = 0;
  1639. u32 i_tot1 = 0;
  1640. u32 w_tot = 0;
  1641. list_for_each_entry_safe(li_entry, li_next, &hcrx->ccid3hcrx_loss_interval_hist, ccid3lih_node) {
  1642. if (i < TFRC_RECV_IVAL_F_LENGTH) {
  1643. i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i];
  1644. w_tot += ccid3_hc_rx_w[i];
  1645. }
  1646. if (i != 0)
  1647. i_tot1 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i - 1];
  1648. if (++i > TFRC_RECV_IVAL_F_LENGTH)
  1649. break;
  1650. }
  1651. if (i != TFRC_RECV_IVAL_F_LENGTH) {
  1652. pr_info("%s: %s, sk=%p, ERROR! Missing entry in interval history!\n",
  1653. __FUNCTION__, dccp_role(sk), sk);
  1654. return 0;
  1655. }
  1656. i_tot = max(i_tot0, i_tot1);
  1657. /* FIXME: Why do we do this? -Ian McDonald */
  1658. if (i_tot * 4 < w_tot)
  1659. i_tot = w_tot * 4;
  1660. return i_tot * 4 / w_tot;
  1661. }
  1662. static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
  1663. {
  1664. struct dccp_sock *dp = dccp_sk(sk);
  1665. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1666. const struct dccp_options_received *opt_recv;
  1667. struct dccp_rx_hist_entry *packet;
  1668. struct timeval now;
  1669. u32 now_usecs;
  1670. u8 win_count;
  1671. u32 p_prev;
  1672. int ins;
  1673. #if 0
  1674. ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n",
  1675. dccp_role(sk), sk, dccp_state_name(sk->sk_state),
  1676. skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
  1677. #endif
  1678. if (hcrx == NULL)
  1679. return;
  1680. BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA ||
  1681. hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA));
  1682. opt_recv = &dp->dccps_options_received;
  1683. switch (DCCP_SKB_CB(skb)->dccpd_type) {
  1684. case DCCP_PKT_ACK:
  1685. if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
  1686. return;
  1687. case DCCP_PKT_DATAACK:
  1688. if (opt_recv->dccpor_timestamp_echo == 0)
  1689. break;
  1690. p_prev = hcrx->ccid3hcrx_rtt;
  1691. do_gettimeofday(&now);
  1692. now_usecs = now.tv_sec * USEC_PER_SEC + now.tv_usec;
  1693. hcrx->ccid3hcrx_rtt = now_usecs -
  1694. (opt_recv->dccpor_timestamp_echo -
  1695. opt_recv->dccpor_elapsed_time) * 10;
  1696. if (p_prev != hcrx->ccid3hcrx_rtt)
  1697. ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n",
  1698. dccp_role(sk), hcrx->ccid3hcrx_rtt,
  1699. opt_recv->dccpor_elapsed_time);
  1700. break;
  1701. case DCCP_PKT_DATA:
  1702. break;
  1703. default:
  1704. ccid3_pr_debug("%s, sk=%p, not DATA/DATAACK/ACK packet(%s)\n",
  1705. dccp_role(sk), sk,
  1706. dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
  1707. return;
  1708. }
  1709. packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp,
  1710. skb, SLAB_ATOMIC);
  1711. if (packet == NULL) {
  1712. ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet to history (consider it lost)!",
  1713. dccp_role(sk), sk);
  1714. return;
  1715. }
  1716. win_count = packet->dccphrx_ccval;
  1717. ins = ccid3_hc_rx_add_hist(sk, packet);
  1718. if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK)
  1719. return;
  1720. switch (hcrx->ccid3hcrx_state) {
  1721. case TFRC_RSTATE_NO_DATA:
  1722. ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial feedback\n",
  1723. dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb);
  1724. ccid3_hc_rx_send_feedback(sk);
  1725. ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
  1726. return;
  1727. case TFRC_RSTATE_DATA:
  1728. hcrx->ccid3hcrx_bytes_recv += skb->len - dccp_hdr(skb)->dccph_doff * 4;
  1729. if (ins == 0) {
  1730. if (now_delta(hcrx->ccid3hcrx_tstamp_last_ack) >=
  1731. hcrx->ccid3hcrx_rtt) {
  1732. do_gettimeofday(&hcrx->ccid3hcrx_tstamp_last_ack);
  1733. ccid3_hc_rx_send_feedback(sk);
  1734. }
  1735. return;
  1736. }
  1737. break;
  1738. default:
  1739. printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
  1740. __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state);
  1741. dump_stack();
  1742. return;
  1743. }
  1744. /* Dealing with packet loss */
  1745. ccid3_pr_debug("%s, sk=%p(%s), data loss! Reacting...\n",
  1746. dccp_role(sk), sk, dccp_state_name(sk->sk_state));
  1747. ccid3_hc_rx_detect_loss(sk);
  1748. p_prev = hcrx->ccid3hcrx_p;
  1749. /* Calculate loss event rate */
  1750. if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist))
  1751. /* Scaling up by 1000000 as fixed decimal */
  1752. hcrx->ccid3hcrx_p = 1000000 / ccid3_hc_rx_calc_i_mean(sk);
  1753. if (hcrx->ccid3hcrx_p > p_prev) {
  1754. ccid3_hc_rx_send_feedback(sk);
  1755. return;
  1756. }
  1757. }
  1758. static int ccid3_hc_rx_init(struct sock *sk)
  1759. {
  1760. struct dccp_sock *dp = dccp_sk(sk);
  1761. struct ccid3_hc_rx_sock *hcrx;
  1762. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  1763. hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any());
  1764. if (hcrx == NULL)
  1765. return -ENOMEM;
  1766. memset(hcrx, 0, sizeof(*hcrx));
  1767. if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE &&
  1768. dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE)
  1769. hcrx->ccid3hcrx_s = (u16)dp->dccps_avg_packet_size;
  1770. else
  1771. hcrx->ccid3hcrx_s = TFRC_STD_PACKET_SIZE;
  1772. hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
  1773. INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
  1774. INIT_LIST_HEAD(&hcrx->ccid3hcrx_loss_interval_hist);
  1775. /*
  1776. * XXX this seems to be paranoid, need to think more about this, for
  1777. * now start with something different than zero. -acme
  1778. */
  1779. hcrx->ccid3hcrx_rtt = USEC_PER_SEC / 5;
  1780. return 0;
  1781. }
  1782. static void ccid3_hc_rx_exit(struct sock *sk)
  1783. {
  1784. struct dccp_sock *dp = dccp_sk(sk);
  1785. struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1786. ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
  1787. if (hcrx == NULL)
  1788. return;
  1789. ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
  1790. /* Empty packet history */
  1791. dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist);
  1792. /* Empty loss interval history */
  1793. ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist);
  1794. kfree(dp->dccps_hc_rx_ccid_private);
  1795. dp->dccps_hc_rx_ccid_private = NULL;
  1796. }
  1797. static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
  1798. {
  1799. const struct dccp_sock *dp = dccp_sk(sk);
  1800. const struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
  1801. if (hcrx == NULL)
  1802. return;
  1803. info->tcpi_ca_state = hcrx->ccid3hcrx_state;
  1804. info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
  1805. info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt;
  1806. }
  1807. static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
  1808. {
  1809. const struct dccp_sock *dp = dccp_sk(sk);
  1810. const struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
  1811. if (hctx == NULL)
  1812. return;
  1813. info->tcpi_rto = hctx->ccid3hctx_t_rto;
  1814. info->tcpi_rtt = hctx->ccid3hctx_rtt;
  1815. }
  1816. static struct ccid ccid3 = {
  1817. .ccid_id = 3,
  1818. .ccid_name = "ccid3",
  1819. .ccid_owner = THIS_MODULE,
  1820. .ccid_init = ccid3_init,
  1821. .ccid_exit = ccid3_exit,
  1822. .ccid_hc_tx_init = ccid3_hc_tx_init,
  1823. .ccid_hc_tx_exit = ccid3_hc_tx_exit,
  1824. .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet,
  1825. .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent,
  1826. .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv,
  1827. .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options,
  1828. .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options,
  1829. .ccid_hc_rx_init = ccid3_hc_rx_init,
  1830. .ccid_hc_rx_exit = ccid3_hc_rx_exit,
  1831. .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options,
  1832. .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv,
  1833. .ccid_hc_rx_get_info = ccid3_hc_rx_get_info,
  1834. .ccid_hc_tx_get_info = ccid3_hc_tx_get_info,
  1835. };
  1836. module_param(ccid3_debug, int, 0444);
  1837. MODULE_PARM_DESC(ccid3_debug, "Enable debug messages");
  1838. static __init int ccid3_module_init(void)
  1839. {
  1840. int rc = -ENOBUFS;
  1841. ccid3_rx_hist = dccp_rx_hist_new("ccid3");
  1842. if (ccid3_rx_hist == NULL)
  1843. goto out;
  1844. ccid3_tx_hist = dccp_tx_hist_new("ccid3");
  1845. if (ccid3_tx_hist == NULL)
  1846. goto out_free_rx;
  1847. ccid3_loss_interval_hist_slab = kmem_cache_create("li_hist_ccid3",
  1848. sizeof(struct ccid3_loss_interval_hist_entry),
  1849. 0, SLAB_HWCACHE_ALIGN,
  1850. NULL, NULL);
  1851. if (ccid3_loss_interval_hist_slab == NULL)
  1852. goto out_free_tx;
  1853. rc = ccid_register(&ccid3);
  1854. if (rc != 0)
  1855. goto out_free_loss_interval_history;
  1856. out:
  1857. return rc;
  1858. out_free_loss_interval_history:
  1859. kmem_cache_destroy(ccid3_loss_interval_hist_slab);
  1860. ccid3_loss_interval_hist_slab = NULL;
  1861. out_free_tx:
  1862. dccp_tx_hist_delete(ccid3_tx_hist);
  1863. ccid3_tx_hist = NULL;
  1864. out_free_rx:
  1865. dccp_rx_hist_delete(ccid3_rx_hist);
  1866. ccid3_rx_hist = NULL;
  1867. goto out;
  1868. }
  1869. module_init(ccid3_module_init);
  1870. static __exit void ccid3_module_exit(void)
  1871. {
  1872. #ifdef CONFIG_IP_DCCP_UNLOAD_HACK
  1873. /*
  1874. * Hack to use while developing, so that we get rid of the control
  1875. * sock, that is what keeps a refcount on dccp.ko -acme
  1876. */
  1877. extern void dccp_ctl_sock_exit(void);
  1878. dccp_ctl_sock_exit();
  1879. #endif
  1880. ccid_unregister(&ccid3);
  1881. if (ccid3_tx_hist != NULL) {
  1882. dccp_tx_hist_delete(ccid3_tx_hist);
  1883. ccid3_tx_hist = NULL;
  1884. }
  1885. if (ccid3_rx_hist != NULL) {
  1886. dccp_rx_hist_delete(ccid3_rx_hist);
  1887. ccid3_rx_hist = NULL;
  1888. }
  1889. if (ccid3_loss_interval_hist_slab != NULL) {
  1890. kmem_cache_destroy(ccid3_loss_interval_hist_slab);
  1891. ccid3_loss_interval_hist_slab = NULL;
  1892. }
  1893. }
  1894. module_exit(ccid3_module_exit);
  1895. MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz> & Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
  1896. MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID");
  1897. MODULE_LICENSE("GPL");
  1898. MODULE_ALIAS("net-dccp-ccid-3");