2 * Connection oriented routing
3 * Copyright (C) 2007-2011 Michael Blizek
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/mutex.h>
25 DEFINE_MUTEX(cor_bindnodes
);
26 DEFINE_SPINLOCK(conn_free
);
28 DEFINE_MUTEX(connid_gen
);
38 struct kmem_cache
*conn_slab
;
39 struct kmem_cache
*connid_reuse_slab
;
42 struct htable connid_table
;
43 struct htable reverse_connid_table
;
44 struct htable connid_reuse_table
;
48 struct kmem_cache
*bindnode_slab
;
49 struct kmem_cache
*connlistener_slab
;
52 /* see cor.h/KP_ACK_CONN */
53 static const __u32 log_64_11_table
[] = {0,
54 64, 68, 73, 77, 82, 88, 93, 99, 106, 113, 120,
55 128, 136, 145, 155, 165, 175, 187, 199, 212, 226, 240,
56 256, 273, 290, 309, 329, 351, 374, 398, 424, 451, 481,
57 512, 545, 581, 619, 659, 702, 747, 796, 848, 903, 961,
58 1024, 1091, 1162, 1237, 1318, 1403, 1495, 1592, 1695, 1805,
60 2048, 2181, 2323, 2474, 2635, 2806, 2989, 3183, 3390, 3611,
62 4096, 4362, 4646, 4948, 5270, 5613, 5978, 6367, 6781, 7222,
64 8192, 8725, 9292, 9897, 10540, 11226, 11956, 12734, 13562,
66 16384, 17450, 18585, 19793, 21081, 22452, 23912, 25467, 27124,
68 32768, 34899, 37169, 39587, 42161, 44904, 47824, 50935, 54248,
70 65536, 69799, 74338, 79173, 84323, 89807, 95648, 101870, 108495,
72 131072, 139597, 148677, 158347, 168646, 179615, 191297, 203739,
73 216991, 231104, 246135,
74 262144, 279194, 297353, 316693, 337291, 359229, 382594, 407478,
75 433981, 462208, 492270,
76 524288, 558388, 594706, 633387, 674583, 718459, 765188, 814957,
77 867962, 924415, 984540,
78 1048576, 1116777, 1189413, 1266774, 1349166, 1436917, 1530376,
79 1629913, 1735924, 1848831, 1969081,
80 2097152, 2233553, 2378826, 2533547, 2698332, 2873834, 3060752,
81 3259826, 3471849, 3697662, 3938162,
82 4194304, 4467106, 4757652, 5067094, 5396664, 5747669, 6121503,
83 6519652, 6943698, 7395323, 7876323,
84 8388608, 8934212, 9515303, 10134189, 10793327, 11495337,
85 12243006, 13039305, 13887396, 14790647,
87 16777216, 17868424, 19030606, 20268378, 21586655, 22990674,
88 24486013, 26078610, 27774791, 29581294,
90 33554432, 35736849, 38061212, 40536755, 43173310, 45981349,
91 48972026, 52157220, 55549582, 59162588,
93 67108864, 71473698, 76122425, 81073510, 86346620, 91962698,
94 97944052, 104314440, 111099165, 118325175,
96 134217728, 142947395, 152244850, 162147020, 172693239,
97 183925396, 195888104, 208628880, 222198329,
99 268435456, 285894791, 304489699, 324294041, 345386479,
100 367850791, 391776208, 417257759, 444396658,
101 473300701, 504084694,
102 536870912, 571789581};
104 static const __u64 log_300_24_table
[] = {0LL,
105 300LL, 308LL, 317LL, 327LL, 336LL, 346LL, 356LL, 367LL, 377LL,
106 389LL, 400LL, 412LL, 424LL, 436LL, 449LL, 462LL, 476LL,
107 490LL, 504LL, 519LL, 534LL, 550LL, 566LL, 582LL,
108 600LL, 617LL, 635LL, 654LL, 673LL, 693LL, 713LL, 734LL, 755LL,
109 778LL, 800LL, 824LL, 848LL, 873LL, 898LL, 925LL, 952LL,
110 980LL, 1009LL, 1038LL, 1069LL, 1100LL, 1132LL, 1165LL,
111 1200LL, 1235LL, 1271LL, 1308LL, 1346LL, 1386LL, 1427LL, 1468LL,
112 1511LL, 1556LL, 1601LL, 1648LL, 1697LL, 1746LL, 1797LL,
113 1850LL, 1904LL, 1960LL, 2018LL, 2077LL, 2138LL, 2200LL,
115 2400LL, 2470LL, 2542LL, 2617LL, 2693LL, 2772LL, 2854LL, 2937LL,
116 3023LL, 3112LL, 3203LL, 3297LL, 3394LL, 3493LL, 3595LL,
117 3701LL, 3809LL, 3921LL, 4036LL, 4154LL, 4276LL, 4401LL,
119 4800LL, 4940LL, 5085LL, 5234LL, 5387LL, 5545LL, 5708LL, 5875LL,
120 6047LL, 6224LL, 6407LL, 6594LL, 6788LL, 6987LL, 7191LL,
121 7402LL, 7619LL, 7842LL, 8072LL, 8309LL, 8552LL, 8803LL,
123 9600LL, 9881LL, 10170LL, 10468LL, 10775LL, 11091LL, 11416LL,
124 11750LL, 12095LL, 12449LL, 12814LL, 13189LL, 13576LL,
125 13974LL, 14383LL, 14805LL, 15239LL, 15685LL, 16145LL,
126 16618LL, 17105LL, 17606LL, 18122LL, 18653LL,
127 19200LL, 19762LL, 20341LL, 20937LL, 21551LL, 22182LL, 22832LL,
128 23501LL, 24190LL, 24899LL, 25628LL, 26379LL, 27152LL,
129 27948LL, 28767LL, 29610LL, 30478LL, 31371LL, 32290LL,
130 33236LL, 34210LL, 35212LL, 36244LL, 37306LL,
131 38400LL, 39525LL, 40683LL, 41875LL, 43102LL, 44365LL, 45665LL,
132 47003LL, 48380LL, 49798LL, 51257LL, 52759LL, 54305LL,
133 55897LL, 57534LL, 59220LL, 60956LL, 62742LL, 64580LL,
134 66473LL, 68421LL, 70425LL, 72489LL, 74613LL,
135 76800LL, 79050LL, 81366LL, 83750LL, 86205LL, 88731LL, 91331LL,
136 94007LL, 96761LL, 99597LL, 102515LL, 105519LL, 108611LL,
137 111794LL, 115069LL, 118441LL, 121912LL, 125484LL,
138 129161LL, 132946LL, 136842LL, 140851LL, 144979LL,
140 153600LL, 158100LL, 162733LL, 167501LL, 172410LL, 177462LL,
141 182662LL, 188014LL, 193523LL, 199194LL, 205031LL,
142 211039LL, 217223LL, 223588LL, 230139LL, 236883LL,
143 243824LL, 250969LL, 258323LL, 265892LL, 273684LL,
144 281703LL, 289958LL, 298454LL,
145 307200LL, 316201LL, 325467LL, 335003LL, 344820LL, 354924LL,
146 365324LL, 376029LL, 387047LL, 398389LL, 410062LL,
147 422078LL, 434446LL, 447176LL, 460279LL, 473767LL,
148 487649LL, 501938LL, 516646LL, 531785LL, 547368LL,
149 563407LL, 579916LL, 596909LL,
150 614400LL, 632403LL, 650934LL, 670007LL, 689640LL, 709848LL,
151 730648LL, 752058LL, 774095LL, 796778LL, 820125LL,
152 844157LL, 868892LL, 894353LL, 920559LL, 947534LL,
153 975299LL, 1003877LL, 1033293LL, 1063571LL, 1094736LL,
154 1126814LL, 1159832LL, 1193818LL,
155 1228800LL, 1264806LL, 1301868LL, 1340015LL, 1379281LL,
156 1419697LL, 1461297LL, 1504116LL, 1548190LL, 1593556LL,
157 1640251LL, 1688314LL, 1737785LL, 1788706LL, 1841119LL,
158 1895068LL, 1950598LL, 2007755LL, 2066587LL, 2127142LL,
159 2189472LL, 2253629LL, 2319665LL, 2387636LL,
160 2457600LL, 2529613LL, 2603736LL, 2680031LL, 2758562LL,
161 2839394LL, 2922595LL, 3008233LL, 3096381LL, 3187112LL,
162 3280502LL, 3376628LL, 3475571LL, 3577413LL, 3682239LL,
163 3790137LL, 3901196LL, 4015510LL, 4133174LL, 4254285LL,
164 4378945LL, 4507258LL, 4639331LL, 4775273LL,
165 4915200LL, 5059226LL, 5207473LL, 5360063LL, 5517125LL,
166 5678789LL, 5845190LL, 6016467LL, 6192763LL, 6374225LL,
167 6561004LL, 6753256LL, 6951142LL, 7154826LL, 7364478LL,
168 7580274LL, 7802393LL, 8031021LL, 8266348LL, 8508570LL,
169 8757890LL, 9014516LL, 9278662LL, 9550547LL,
170 9830400LL, 10118452LL, 10414946LL, 10720127LL, 11034250LL,
171 11357579LL, 11690381LL, 12032935LL, 12385527LL,
172 12748451LL, 13122009LL, 13506513LL, 13902285LL,
173 14309653LL, 14728957LL, 15160549LL, 15604787LL,
174 16062042LL, 16532696LL, 17017141LL, 17515781LL,
175 18029033LL, 18557324LL, 19101095LL,
176 19660800LL, 20236905LL, 20829892LL, 21440254LL, 22068501LL,
177 22715158LL, 23380763LL, 24065871LL, 24771055LL,
178 25496903LL, 26244019LL, 27013027LL, 27804570LL,
179 28619306LL, 29457915LL, 30321098LL, 31209574LL,
180 32124084LL, 33065392LL, 34034282LL, 35031563LL,
181 36058066LL, 37114648LL, 38202190LL,
182 39321600LL, 40473810LL, 41659784LL, 42880508LL, 44137003LL,
183 45430316LL, 46761526LL, 48131743LL, 49542111LL,
184 50993806LL, 52488038LL, 54026055LL, 55609140LL,
185 57238612LL, 58915831LL, 60642197LL, 62419149LL,
186 64248169LL, 66130784LL, 68068564LL, 70063126LL,
187 72116132LL, 74229296LL, 76404380LL,
188 78643200LL, 80947621LL, 83319568LL, 85761017LL, 88274007LL,
189 90860633LL, 93523052LL, 96263487LL, 99084223LL,
190 101987612LL, 104976077LL, 108052111LL, 111218280LL,
191 114477224LL, 117831663LL, 121284394LL, 124838298LL,
192 128496339LL, 132261569LL, 136137129LL, 140126252LL,
193 144232264LL, 148458592LL, 152808761LL,
194 157286400LL, 161895243LL, 166639136LL, 171522035LL, 176548014LL,
195 181721266LL, 187046105LL, 192526975LL, 198168446LL,
196 203975224LL, 209952155LL, 216104222LL, 222436560LL,
197 228954448LL, 235663326LL, 242568788LL, 249676596LL,
198 256992679LL, 264523139LL, 272274259LL, 280252504LL,
199 288464529LL, 296917185LL, 305617523LL,
200 314572800LL, 323790486LL, 333278272LL, 343044070LL, 353096029LL,
201 363442532LL, 374092211LL, 385053950LL, 396336892LL,
202 407950449LL, 419904310LL, 432208445LL, 444873120LL,
203 457908897LL, 471326652LL, 485137577LL, 499353193LL,
204 513985359LL, 529046279LL, 544548518LL, 560505008LL,
205 576929058LL, 593834370LL, 611235046LL,
206 629145600LL, 647580973LL, 666556544LL, 686088141LL,
207 706192058LL, 726885065LL, 748184423LL, 770107900LL,
208 792673784LL, 815900899LL, 839808620LL, 864416891LL,
209 889746240LL, 915817795LL, 942653304LL, 970275155LL,
210 998706387LL, 1027970718LL, 1058092559LL, 1089097037LL,
211 1121010017LL, 1153858117LL, 1187668741LL, 1222470092LL,
212 1258291200LL, 1295161946LL, 1333113088LL, 1372176283LL,
213 1412384117LL, 1453770131LL, 1496368847LL, 1540215801LL,
214 1585347569LL, 1631801799LL, 1679617241LL, 1728833783LL,
215 1779492480LL, 1831635590LL, 1885306609LL, 1940550310LL,
216 1997412774LL, 2055941436LL, 2116185118LL, 2178194075LL,
217 2242020034LL, 2307716235LL, 2375337483LL, 2444940184LL,
218 2516582400LL, 2590323893LL, 2666226176LL, 2744352567LL,
219 2824768235LL, 2907540262LL, 2992737695LL, 3080431603LL,
220 3170695139LL, 3263603598LL, 3359234483LL, 3457667567LL,
221 3558984960LL, 3663271180LL, 3770613219LL, 3881100620LL,
222 3994825549LL, 4111882872LL, 4232370237LL, 4356388151LL,
223 4484040068LL, 4615432471LL, 4750674966LL, 4889880368LL,
224 5033164800LL, 5180647786LL, 5332452353LL, 5488705134LL,
225 5649536470LL, 5815080525LL, 5985475391LL, 6160863207LL,
226 6341390279LL, 6527207197LL, 6718468967LL, 6915335135LL,
227 7117969921LL, 7326542360LL, 7541226438LL, 7762201240LL,
228 7989651098LL, 8223765745LL, 8464740475LL, 8712776303LL,
229 8968080137LL, 9230864943LL, 9501349932LL, 9779760736LL,
230 10066329600LL, 10361295572LL, 10664904706LL, 10977410268LL,
231 11299072941LL, 11630161050LL, 11970950782LL,
232 12321726414LL, 12682780558LL, 13054414395LL,
233 13436937935LL, 13830670270LL, 14235939843LL,
234 14653084721LL, 15082452877LL, 15524402481LL,
235 15979302196LL, 16447531490LL, 16929480950LL,
236 17425552607LL, 17936160274LL, 18461729886LL,
237 19002699864LL, 19559521473LL,
238 20132659200LL, 20722591144LL, 21329809413LL, 21954820536LL,
239 22598145883LL, 23260322101LL, 23941901564LL,
240 24643452829LL, 25365561116LL, 26108828790LL,
241 26873875870LL, 27661340540LL, 28471879687LL,
242 29306169443LL, 30164905755LL, 31048804962LL,
243 31958604392LL, 32895062981LL, 33858961901LL,
244 34851105215LL, 35872320548LL, 36923459773LL,
245 38005399729LL, 39119042946LL,
246 40265318400LL, 41445182288LL,42659618827LL,43909641073LL,
247 45196291767LL, 46520644203LL, 47883803129LL,
248 49286905659LL, 50731122232LL, 52217657581LL,
249 53747751741LL, 55322681081LL, 56943759374LL,
250 58612338887LL, 60329811511LL, 62097609924LL,
251 63917208785LL, 65790125963LL, 67717923803LL,
252 69702210431LL, 71744641096LL, 73846919547LL,
253 76010799459LL, 78238085892LL,
254 80530636800LL, 82890364576LL, 85319237654LL, 87819282146LL,
255 90392583534LL, 93041288407LL, 95767606258LL,
256 98573811319LL, 101462244465LL, 104435315163LL,
257 107495503482LL, 110645362163LL, 113887518749LL,
258 117224677774LL, 120659623022LL, 124195219849LL,
259 127834417571LL, 131580251926LL, 135435847606LL,
260 139404420863LL, 143489282192LL, 147693839094LL,
261 152021598918LL, 156476171785LL,
262 161061273600LL, 165780729153LL, 170638475309LL, 175638564293LL,
263 180785167068LL, 186082576815LL, 191535212516LL,
264 197147622639LL, 202924488931LL, 208870630326LL,
265 214991006964LL, 221290724326LL, 227775037498LL,
266 234449355548LL, 241319246045LL, 248390439699LL,
267 255668835143LL, 263160503853LL, 270871695212LL,
268 278808841726LL, 286978564384LL, 295387678189LL,
269 304043197837LL, 312952343570LL,
270 322122547200LL, 331561458306LL, 341276950619LL, 351277128587LL,
271 361570334136LL, 372165153630LL, 383070425033LL,
272 394295245278LL, 405848977863LL, 417741260653LL,
273 429982013929LL, 442581448653LL, 455550074996LL,
274 468898711096LL, 482638492091LL, 496780879399LL,
275 511337670287LL, 526321007707LL, 541743390425LL,
276 557617683452LL, 573957128769LL, 590775356379LL,
277 608086395675LL, 625904687141LL,
278 644245094400LL, 663122916612LL, 682553901238LL, 702554257174LL,
279 723140668273LL, 744330307261LL, 766140850066LL,
280 788590490556LL, 811697955726LL, 835482521307LL,
281 859964027858LL, 885162897307LL, 911100149992LL,
282 937797422193LL, 965276984182LL, 993561758799LL,
283 1022675340575LL, 1052642015414LL, 1083486780851LL,
284 1115235366904LL, 1147914257538LL, 1181550712759LL,
285 1216172791350LL, 1251809374282LL,
286 1288490188800LL, 1326245833225LL, 1365107802477LL,
287 1405108514349LL, 1446281336546LL, 1488660614523LL,
288 1532281700132LL, 1577180981113LL, 1623395911452LL,
289 1670965042615LL, 1719928055717LL, 1770325794615LL,
290 1822200299985LL, 1875594844387LL, 1930553968365LL,
291 1987123517599LL, 2045350681151LL, 2105284030829LL,
292 2166973561703LL, 2230470733808LL, 2295828515076LL,
293 2363101425518LL, 2432345582701LL, 2503618748564LL,
294 2576980377600LL, 2652491666450LL, 2730215604955LL,
295 2810217028699LL, 2892562673093LL, 2977321229047LL,
296 3064563400264LL, 3154361962227LL, 3246791822904LL,
297 3341930085231LL, 3439856111434LL, 3540651589231LL,
298 3644400599971LL, 3751189688775LL, 3861107936730LL,
299 3974247035198LL, 4090701362303LL, 4210568061659LL,
300 4333947123406LL, 4460941467616LL, 4591657030153LL,
301 4726202851036LL, 4864691165402LL, 5007237497128LL,
302 5153960755200LL, 5304983332900LL, 5460431209910LL,
303 5620434057398LL, 5785125346187LL, 5954642458094LL,
304 6129126800528LL, 6308723924455LL, 6493583645808LL,
305 6683860170462LL, 6879712222869LL, 7081303178462LL,
306 7288801199942LL, 7502379377550LL, 7722215873460LL,
307 7948494070397LL, 8181402724607LL, 8421136123319LL,
308 8667894246812LL, 8921882935232LL, 9183314060306LL,
309 9452405702073LL, 9729382330805LL, 10014474994257LL,
310 10307921510400LL, 10609966665800LL, 10920862419821LL,
311 11240868114797LL, 11570250692375LL, 11909284916188LL,
312 12258253601057LL, 12617447848911LL, 12987167291617LL,
313 13367720340924LL, 13759424445738LL, 14162606356925LL,
314 14577602399885LL, 15004758755101LL, 15444431746921LL,
315 15896988140794LL, 16362805449214LL, 16842272246638LL,
316 17335788493624LL, 17843765870465LL, 18366628120613LL,
317 18904811404146LL, 19458764661611LL, 20028949988515LL,
318 20615843020800LL, 21219933331600LL, 21841724839642LL,
319 22481736229595LL, 23140501384751LL, 23818569832376LL,
320 24516507202114LL, 25234895697822LL, 25974334583234LL,
321 26735440681849LL, 27518848891476LL, 28325212713851LL,
322 29155204799770LL, 30009517510202LL, 30888863493843LL,
323 31793976281588LL, 32725610898429LL, 33684544493277LL,
324 34671576987248LL, 35687531740931LL, 36733256241226LL,
325 37809622808292LL, 38917529323222LL, 40057899977031LL,
326 41231686041600LL, 42439866663201LL, 43683449679284LL,
327 44963472459190LL, 46281002769503LL, 47637139664753LL,
328 49033014404229LL, 50469791395645LL, 51948669166468LL,
329 53470881363698LL, 55037697782953LL, 56650425427703LL,
330 58310409599540LL, 60019035020404LL, 61777726987686LL,
331 63587952563177LL, 65451221796858LL, 67369088986555LL,
332 69343153974496LL, 71375063481862LL, 73466512482452LL,
333 75619245616585LL, 77835058646445LL, 80115799954063LL,
334 82463372083200LL, 84879733326402LL, 87366899358568LL,
335 89926944918381LL, 92562005539006LL, 95274279329506LL,
336 98066028808458LL, 100939582791291LL, 103897338332936LL,
337 106941762727397LL, 110075395565907LL, 113300850855406LL,
338 116620819199080LL, 120038070040809LL, 123555453975373LL,
339 127175905126354LL, 130902443593716LL, 134738177973111LL,
340 138686307948992LL, 142750126963725LL, 146933024964905LL,
341 151238491233171LL, 155670117292890LL, 160231599908126LL,
342 164926744166400LL, 169759466652804LL, 174733798717137LL,
343 179853889836763LL, 185124011078013LL, 190548558659013LL,
344 196132057616916LL, 201879165582582LL, 207794676665873LL,
345 213883525454795LL, 220150791131815LL, 226601701710812LL,
346 233241638398160LL, 240076140081619LL, 247110907950747LL,
347 254351810252708LL, 261804887187433LL, 269476355946222LL,
348 277372615897984LL, 285500253927451LL, 293866049929810LL,
349 302476982466342LL, 311340234585780LL, 320463199816253LL,
350 329853488332800LL, 339518933305609LL, 349467597434275LL,
351 359707779673527LL, 370248022156026LL, 381097117318027LL,
352 392264115233832LL, 403758331165164LL, 415589353331747LL,
353 427767050909590LL, 440301582263631LL, 453203403421624LL,
354 466483276796321LL, 480152280163238LL, 494221815901494LL,
355 508703620505416LL, 523609774374866LL, 538952711892444LL,
356 554745231795968LL, 571000507854903LL, 587732099859621LL,
357 604953964932684LL, 622680469171561LL, 640926399632506LL,
358 659706976665600LL, 679037866611218LL, 698935194868551LL,
359 719415559347055LL, 740496044312053LL, 762194234636054LL,
360 784528230467665LL, 807516662330329LL, 831178706663495LL,
361 855534101819180LL, 880603164527263LL, 906406806843249LL,
362 932966553592642LL, 960304560326477LL, 988443631802988LL,
363 1017407241010832LL, 1047219548749733LL,
364 1077905423784889LL, 1109490463591937LL,
365 1142001015709806LL, 1175464199719243LL,
366 1209907929865369LL, 1245360938343122LL,
368 1319413953331200LL, 1358075733222436LL, 1397870389737103LL,
369 1438831118694110LL, 1480992088624106LL,
370 1524388469272109LL, 1569056460935331LL,
371 1615033324660658LL, 1662357413326990LL,
372 1711068203638361LL, 1761206329054527LL,
373 1812813613686499LL, 1865933107185284LL,
374 1920609120652954LL, 1976887263605976LL};
377 __u8
__attribute__((const)) enc_log_64_11(__u32 value
)
380 BUG_ON(log_64_11_table
[255] != 571789581);
381 for (i
=1;i
<256;i
++) {
382 if (log_64_11_table
[i
] > value
)
386 return (__u8
)(i
-1); /* round down */
389 __u32
__attribute__((const)) dec_log_64_11(__u8 value
)
391 BUG_ON(log_64_11_table
[255] != 571789581);
392 return log_64_11_table
[value
];
395 static void check_log_64_11_table(void)
398 BUG_ON(log_64_11_table
[0] != 0);
399 for (i
=1;i
<256;i
++) {
400 BUG_ON(log_64_11_table
[i
] <= log_64_11_table
[i
-1]);
404 __u16
__attribute__((const)) enc_log_300_24(__u64 value
)
407 BUG_ON(log_300_24_table
[1023] != 1976887263605976LL);
408 for (i
=1;i
<1024;i
++) {
409 if (log_300_24_table
[i
] > value
)
413 return (__u16
)(i
-1); /* round down */
416 __u64
__attribute__((const)) dec_log_300_24(__u16 value
)
418 BUG_ON(value
>= 1024);
419 BUG_ON(log_300_24_table
[1023] != 1976887263605976LL);
420 return log_300_24_table
[value
];
423 static void check_log_300_24_table(void)
426 BUG_ON(log_300_24_table
[0] != 0);
427 for (i
=1;i
<1024;i
++) {
428 BUG_ON(log_300_24_table
[i
] <= log_300_24_table
[i
-1]);
432 static inline __u64
mul_saturated(__u64 a
, __u64 b
)
435 if (unlikely(res
/ a
!= b
))
440 static inline int numdigits(__u64 value
)
443 for (;value
!= 0;value
= (value
>> 1)) {
449 static void mul(__u64 a
, __u64 b
, __u64
*reshigh
, __u64
*reslow
)
452 __u32 ah
= (a
>> 32);
454 __u32 bh
= (b
>> 32);
456 __u64 r1
= ((__u64
) al
) * bl
;
457 __u64 r20
= (r1
>> 32);
458 __u64 r21
= ((__u64
) ah
) * bl
;
459 __u64 r22
= ((__u64
) al
) * bh
;
460 __u64 r2
= r20
+ ((r21
<< 32) >> 32) + ((r22
<< 32) >> 32);
461 __u64 r30
= (r21
>> 32) + (r22
>> 32) + (r2
>> 32);
462 __u64 r31
= ((__u64
) ah
) * bh
;
464 BUG_ON(reshigh
== 0);
467 (*reslow
) = ((r1
<< 32) >> 32) + (r2
<< 32);
468 (*reshigh
) = r30
+ r31
;
471 /* calculate (a*b+rem)/c */
472 __u64
multiply_div2(__u64 a
, __u64 b
, __s64 rem
, __u64 c
, __u64
*remainder
)
482 mul(a
, b
, &high
, &low
);
485 __u64 rem0
= (rem
== S64_MIN
) ? (((__u64
) S64_MAX
) + 1) :
487 if (low
- rem0
> low
)
491 if (low
+ ((__u64
) rem
) < low
)
493 low
+= ((__u64
) rem
);
501 __u64 tmpres
= res
+ (1LL << u
);
503 mul(c
, tmpres
, &tmphigh
, &tmplow
);
524 if (remainder
!= 0) {
525 (*remainder
) = low
- reslow
;
526 if ((*remainder
) > c
)
534 static inline int hdr_size(void)
536 return ((sizeof(struct cell_hdr
) + sizeof(void *) - 1) / sizeof(void *)
540 static inline int elements_per_cell(int cell_size
)
542 return (cell_size
- hdr_size())/sizeof(void *);
545 static inline struct cell_hdr
*cell_addr(struct htable
*ht
, __u32 id
)
547 int idx
= (id
%ht
->htable_size
) / (elements_per_cell(ht
->cell_size
));
548 return (struct cell_hdr
*) (((char *)ht
->htable
) + ht
->cell_size
* idx
);
551 static inline char **element_addr(struct htable
*ht
, __u32 id
)
553 int idx
= (id
%ht
->htable_size
) % (elements_per_cell(ht
->cell_size
));
555 ( ((char *)cell_addr(ht
, id
)) +
556 hdr_size() + idx
*sizeof(void *));
560 static inline char **next_element(struct htable
*ht
, char *element
)
562 return (char **)(element
+ ht
->entry_offset
);
565 static inline struct kref
*element_kref(struct htable
*ht
, char *element
)
567 return (struct kref
*)(element
+ ht
->kref_offset
);
571 static inline void unlock_element(struct htable
*ht
, __u32 key
)
573 struct cell_hdr
*hdr
= cell_addr(ht
, key
);
574 spin_unlock(&(hdr
->lock
));
578 static char **get_element_nounlock(struct htable
*ht
, __u32 key
,
581 struct cell_hdr
*hdr
= cell_addr(ht
, key
);
582 char **element
= element_addr(ht
, key
);
584 BUG_ON(0 == element
);
586 spin_lock(&(hdr
->lock
));
591 if (searcheditem
!= 0 && ht
->matches(*element
, searcheditem
))
593 element
= next_element(ht
, *element
);
599 char *htable_get(struct htable
*ht
, __u32 key
, void *searcheditem
)
601 unsigned long iflags
;
604 if (unlikely(ht
->htable
== 0))
607 local_irq_save(iflags
);
608 element
= *(get_element_nounlock(ht
, key
, searcheditem
));
609 if (likely(element
!= 0))
610 kref_get(element_kref(ht
, element
));
611 unlock_element(ht
, key
);
612 local_irq_restore(iflags
);
617 int htable_delete(struct htable
*ht
, __u32 key
,
618 void *searcheditem
, void (*free
) (struct kref
*ref
))
620 unsigned long iflags
;
625 if (unlikely(ht
->htable
== 0))
628 local_irq_save(iflags
);
630 element
= get_element_nounlock(ht
, key
, searcheditem
);
631 BUG_ON(0 == element
);
633 if (unlikely(*element
== 0)) {
634 /* key not in table */
639 next
= next_element(ht
, *element
);
640 kref_put(element_kref(ht
, *element
), free
);
644 unlock_element(ht
, key
);
645 local_irq_restore(iflags
);
650 void htable_insert(struct htable
*ht
, char *newelement
, __u32 key
)
652 unsigned long iflags
;
655 if (unlikely(ht
->htable
== 0))
658 BUG_ON(*next_element(ht
, newelement
) != 0);
659 local_irq_save(iflags
);
661 element
= get_element_nounlock(ht
, key
, 0);
663 BUG_ON(element
== 0);
664 BUG_ON(*element
!= 0);
666 *element
= newelement
;
667 kref_get(element_kref(ht
, newelement
));
669 unlock_element(ht
, key
);
670 local_irq_restore(iflags
);
674 void htable_init(struct htable
*ht
, int (*matches
)(void *htentry
,
675 void *searcheditem
), __u32 entry_offset
, __u32 kref_offset
)
682 ht
->htable
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
683 if (unlikely(ht
->htable
== 0)) {
684 printk(KERN_CRIT
"cor: error allocating htable (out of "
688 memset(ht
->htable
, 0, PAGE_SIZE
);
691 num_cells
= PAGE_SIZE
/ht
->cell_size
;
693 for (j
=0;j
<num_cells
;j
++) {
694 struct cell_hdr
*hdr
= (struct cell_hdr
*)
695 ( ((char *) ht
->htable
) + j
* ht
->cell_size
);
696 spin_lock_init(&(hdr
->lock
));
699 ht
->htable_size
= num_cells
* elements_per_cell(ht
->cell_size
);
700 ht
->num_elements
= 0;
702 ht
->matches
= matches
;
703 ht
->entry_offset
= entry_offset
;
704 ht
->kref_offset
= kref_offset
;
707 struct reverse_connid_matchparam
{
712 static __u32
rcm_to_key(struct reverse_connid_matchparam
*rcm
)
714 return (((__u32
) rcm
->nb
) ^ rcm
->conn_id
);
717 static int matches_reverse_connid(void *htentry
, void *searcheditem
)
719 struct conn
*conn
= (struct conn
*) htentry
;
720 struct reverse_connid_matchparam
*rcm
=
721 (struct reverse_connid_matchparam
*) searcheditem
;
722 BUG_ON(conn
->targettype
!= TARGET_OUT
);
723 return (conn
->target
.out
.nb
== rcm
->nb
) &&
724 (conn
->target
.out
.conn_id
== rcm
->conn_id
);
727 struct conn
*get_conn_reverse(struct neighbor
*nb
, __u32 conn_id
)
729 struct reverse_connid_matchparam rcm
;
731 rcm
.conn_id
= conn_id
;
733 return (struct conn
*) htable_get(&reverse_connid_table
,
734 rcm_to_key(&rcm
), &rcm
);
737 void insert_reverse_connid(struct conn
*trgt_out_ll
)
739 struct reverse_connid_matchparam rcm
;
741 BUG_ON(trgt_out_ll
->targettype
!= TARGET_OUT
);
743 rcm
.nb
= trgt_out_ll
->target
.out
.nb
;
744 rcm
.conn_id
= trgt_out_ll
->target
.out
.conn_id
;
745 htable_insert(&reverse_connid_table
, (char *) trgt_out_ll
,
749 static int matches_connid_in(void *htentry
, void *searcheditem
)
751 struct conn
*conn
= (struct conn
*) htentry
;
752 __u32 conn_id
= *((__u32
*) searcheditem
);
753 BUG_ON(conn
->sourcetype
!= SOURCE_IN
);
754 return (conn
->source
.in
.conn_id
== conn_id
);
757 struct conn
*get_conn(__u32 conn_id
)
759 return (struct conn
*) htable_get(&connid_table
, conn_id
, &conn_id
);
762 static void free_connid_reuse(struct kref
*ref
)
764 struct connid_reuse_item
*cir
= container_of(ref
,
765 struct connid_reuse_item
, ref
);
767 kmem_cache_free(connid_reuse_slab
, cir
);
770 static int matches_reuse_connid(void *htentry
, void *searcheditem
)
772 struct connid_reuse_item
*cir
= (struct connid_reuse_item
*) htentry
;
773 __u32 conn_id
= *((__u32
*) searcheditem
);
774 return (cir
->conn_id
== conn_id
);
777 void connid_used_pingsuccess(struct neighbor
*nb
)
779 unsigned long iflags
;
780 struct connid_reuse_item
*cri
;
782 spin_lock_irqsave(&(nb
->connid_reuse_lock
), iflags
);
784 nb
->connid_reuse_pingcnt
++;
785 while (list_empty(&(nb
->connid_reuse_list
)) == 0) {
786 cri
= container_of(nb
->connid_reuse_list
.next
,
787 struct connid_reuse_item
, lh
);
788 if ((cri
->pingcnt
+ CONNID_REUSE_RTTS
-
789 nb
->connid_reuse_pingcnt
) < 32768)
792 if (htable_delete(&connid_reuse_table
,
794 &(cri
->conn_id
), free_connid_reuse
)) {
795 printk(KERN_ERR
"error in connid_used_pingsuccess: "
796 "htable_delete failed");
799 list_del(&(cri
->lh
));
800 kref_put(&(cri
->ref
), free_connid_reuse
);
803 spin_unlock_irqrestore(&(nb
->connid_reuse_lock
), iflags
);
806 static int connid_used(__u32 conn_id
)
809 struct connid_reuse_item
*cir
;
811 cn
= get_conn(conn_id
);
812 if (unlikely(cn
!= 0)) {
813 kref_put(&(cn
->ref
), free_conn
);
817 cir
= (struct connid_reuse_item
*)
818 htable_get(&connid_reuse_table
, conn_id
, &conn_id
);
820 if (unlikely(cir
!= 0)) {
821 kref_put(&(cir
->ref
), free_connid_reuse
);
828 static int connid_alloc(struct conn
*src_in_ll
)
833 BUG_ON(src_in_ll
->sourcetype
!= SOURCE_IN
);
835 mutex_lock(&connid_gen
);
838 get_random_bytes((char *) &conn_id
, sizeof(conn_id
));
840 if (unlikely(conn_id
== 0))
843 if (unlikely(connid_used(conn_id
)))
848 mutex_unlock(&connid_gen
);
853 src_in_ll
->source
.in
.conn_id
= conn_id
;
854 htable_insert(&connid_table
, (char *) src_in_ll
, conn_id
);
855 mutex_unlock(&connid_gen
);
859 void _set_last_act(struct conn
*src_in_l
)
861 unsigned long iflags
;
862 spin_lock_irqsave(&(src_in_l
->source
.in
.nb
->conn_list_lock
), iflags
);
863 list_del(&(src_in_l
->source
.in
.nb_list
));
864 list_add_tail(&(src_in_l
->source
.in
.nb_list
),
865 &(src_in_l
->source
.in
.nb
->rcv_conn_list
));
866 spin_unlock_irqrestore(&(src_in_l
->source
.in
.nb
->conn_list_lock
),
870 void free_conn(struct kref
*ref
)
872 unsigned long iflags
;
873 struct conn
*cn
= container_of(ref
, struct conn
, ref
);
874 struct conn
*reversedir
= 0;
876 spin_lock_irqsave(&conn_free
, iflags
);
878 BUG_ON(cn
->isreset
== 0);
880 if (cn
->reversedir
!= 0)
881 cn
->reversedir
->isreset
= 3;
883 if (cn
->isreset
!= 3)
886 if (cn
->reversedir
!= 0) {
887 cn
->reversedir
->reversedir
= 0;
888 reversedir
= cn
->reversedir
;
892 if (cn
->sourcetype
== SOURCE_IN
) {
893 kref_put(&(cn
->source
.in
.nb
->ref
), neighbor_free
);
894 cn
->source
.in
.nb
= 0;
897 if (cn
->targettype
== TARGET_OUT
) {
898 kref_put(&(cn
->target
.out
.nb
->ref
), neighbor_free
);
899 cn
->target
.out
.nb
= 0;
902 BUG_ON(cn
->data_buf
.totalsize
!= 0);
903 BUG_ON(cn
->data_buf
.overhead
!= 0);
905 kmem_cache_free(conn_slab
, cn
);
908 spin_unlock_irqrestore(&conn_free
, iflags
);
911 free_conn(&(reversedir
->ref
));
916 * rc == 1 ==> connid_reuse or connid allocation failed
918 int conn_init_out(struct conn
*trgt_unconn_ll
, struct neighbor
*nb
)
920 unsigned long iflags
;
922 struct conn
*src_none_ll
= trgt_unconn_ll
->reversedir
;
924 BUG_ON(trgt_unconn_ll
->targettype
!= TARGET_UNCONNECTED
);
925 BUG_ON(src_none_ll
== 0);
926 BUG_ON(src_none_ll
->sourcetype
!= SOURCE_NONE
);
928 memset(&(trgt_unconn_ll
->target
.out
), 0,
929 sizeof(trgt_unconn_ll
->target
.out
));
930 memset(&(src_none_ll
->source
.in
), 0, sizeof(src_none_ll
->source
.in
));
932 trgt_unconn_ll
->targettype
= TARGET_OUT
;
933 src_none_ll
->sourcetype
= SOURCE_IN
;
936 src_none_ll
->source
.in
.cir
= kmem_cache_alloc(connid_reuse_slab
,
938 if (unlikely(src_none_ll
->source
.in
.cir
== 0)) {
942 memset(src_none_ll
->source
.in
.cir
, 0, sizeof(struct connid_reuse_item
));
945 if (unlikely(connid_alloc(src_none_ll
))) {
951 trgt_unconn_ll
->target
.out
.nb
= nb
;
952 src_none_ll
->source
.in
.nb
= nb
;
954 /* neighbor pointer */
955 kref_get(&(nb
->ref
));
956 kref_get(&(nb
->ref
));
958 skb_queue_head_init(&(src_none_ll
->source
.in
.reorder_queue
));
960 INIT_LIST_HEAD(&(src_none_ll
->source
.in
.acks_pending
));
962 INIT_LIST_HEAD(&(trgt_unconn_ll
->target
.out
.retrans_list
));
964 reset_seqno(trgt_unconn_ll
, 0);
965 get_random_bytes((char *) &(src_none_ll
->source
.in
.next_seqno
),
966 sizeof(src_none_ll
->source
.in
.next_seqno
));
968 get_random_bytes((char *) &(trgt_unconn_ll
->target
.out
.decaytime_seqno
),
970 trgt_unconn_ll
->target
.out
.decaytime_seqno
=
971 trgt_unconn_ll
->target
.out
.decaytime_seqno
% 64;
972 trgt_unconn_ll
->source
.in
.decaytime_seqno
= 255;
974 src_none_ll
->source
.in
.jiffies_last_act
= jiffies
;
976 spin_lock_irqsave(&(nb
->conn_list_lock
), iflags
);
977 list_add_tail(&(src_none_ll
->source
.in
.nb_list
), &(nb
->rcv_conn_list
));
978 spin_unlock_irqrestore(&(nb
->conn_list_lock
), iflags
);
981 kref_get(&(src_none_ll
->ref
));
983 atomic_inc(&num_conns
);
986 refresh_conn_credits(trgt_unconn_ll
, 0, 1);
990 kmem_cache_free(connid_reuse_slab
, src_none_ll
->source
.in
.cir
);
991 src_none_ll
->source
.in
.cir
= 0;
997 void conn_init_sock_source(struct conn
*cn
)
1000 cn
->sourcetype
= SOURCE_SOCK
;
1001 memset(&(cn
->source
.sock
), 0, sizeof(cn
->source
.sock
));
1002 init_waitqueue_head(&(cn
->source
.sock
.wait
));
1005 void conn_init_sock_target(struct conn
*cn
)
1008 cn
->targettype
= TARGET_SOCK
;
1009 memset(&(cn
->target
.sock
), 0, sizeof(cn
->target
.sock
));
1010 init_waitqueue_head(&(cn
->target
.sock
.wait
));
1014 #warning todo alloclimit (credits)
1015 struct conn
* alloc_conn(gfp_t allocflags
)
1017 struct conn
*cn1
= 0;
1018 struct conn
*cn2
= 0;
1020 cn1
= kmem_cache_alloc(conn_slab
, allocflags
);
1021 if (unlikely(cn1
== 0))
1024 cn2
= kmem_cache_alloc(conn_slab
, allocflags
);
1025 if (unlikely(cn2
== 0))
1028 memset(cn1
, 0, sizeof(struct conn
));
1029 memset(cn2
, 0, sizeof(struct conn
));
1031 cn1
->reversedir
= cn2
;
1032 cn2
->reversedir
= cn1
;
1034 kref_init(&(cn1
->ref
));
1035 kref_init(&(cn2
->ref
));
1037 cn1
->sockstate
= SOCKSTATE_CONN
;
1038 cn2
->sockstate
= SOCKSTATE_CONN
;
1040 cn1
->sourcetype
= SOURCE_NONE
;
1041 cn2
->sourcetype
= SOURCE_NONE
;
1042 cn1
->targettype
= TARGET_UNCONNECTED
;
1043 cn2
->targettype
= TARGET_UNCONNECTED
;
1048 mutex_init(&(cn1
->rcv_lock
));
1049 mutex_init(&(cn2
->rcv_lock
));
1051 cn1
->ktime_credit_update
= ktime_get();
1052 cn2
->ktime_credit_update
= cn1
->ktime_credit_update
;
1054 cn1
->crate_forward
= ((1 << 31) - (((__u32
) 1 << 31) / 10));
1055 cn2
->crate_forward
= ((1 << 31) - (((__u32
) 1 << 31) / 10));
1063 kmem_cache_free(conn_slab
, cn1
);
1068 static struct connlistener
*get_connlistener(__be64 port
)
1070 struct list_head
*curr
= openports
.next
;
1072 while (curr
!= &openports
) {
1073 struct bindnode
*currnode
= ((struct bindnode
*)
1074 (((char *)curr
) - offsetof(struct bindnode
, lh
)));
1075 if (currnode
->port
== port
) {
1076 BUG_ON(currnode
->owner
== 0);
1077 return currnode
->owner
;
1086 void close_port(struct connlistener
*listener
)
1088 mutex_lock(&cor_bindnodes
);
1090 if (listener
->bn
!= 0) {
1091 list_del(&(listener
->bn
->lh
));
1092 kmem_cache_free(bindnode_slab
, listener
->bn
);
1096 while (list_empty(&(listener
->conn_queue
)) == 0) {
1097 struct conn
*src_sock_o
= container_of(
1098 listener
->conn_queue
.next
,
1099 struct conn
, source
.sock
.cl_list
);
1100 list_del(&(src_sock_o
->source
.sock
.cl_list
));
1101 reset_conn(src_sock_o
);
1102 kref_put(&(src_sock_o
->ref
), free_conn
);
1105 kmem_cache_free(connlistener_slab
, listener
);
1107 mutex_unlock(&cor_bindnodes
);
1110 struct connlistener
*open_port(__be64 port
)
1113 struct bindnode
*bn
= 0;
1114 struct connlistener
*listener
= 0;
1116 mutex_lock(&cor_bindnodes
);
1117 if (get_connlistener(port
) != 0)
1121 bn
= kmem_cache_alloc(bindnode_slab
, GFP_KERNEL
);
1122 listener
= kmem_cache_alloc(connlistener_slab
, GFP_KERNEL
);
1124 memset(bn
, 0, sizeof(struct bindnode
));
1125 memset(listener
, 0, sizeof(struct connlistener
));
1127 bn
->owner
= listener
;
1130 /* kref is not actually used */
1131 listener
->sockstate
= SOCKSTATE_LISTENER
;
1133 mutex_init(&(listener
->lock
));
1134 INIT_LIST_HEAD(&(listener
->conn_queue
));
1135 init_waitqueue_head(&(listener
->wait
));
1137 list_add_tail((struct list_head
*) &(bn
->lh
), &openports
);
1140 mutex_unlock(&cor_bindnodes
);
1147 * rc == 2 port not open
1148 * rc == 3 listener queue full
1150 int connect_port(struct conn
*trtg_unconn_l
, __be64 port
)
1153 struct connlistener
*listener
;
1156 mutex_lock(&cor_bindnodes
);
1158 listener
= get_connlistener(port
);
1159 if (listener
== 0) {
1164 mutex_lock(&(listener
->lock
));
1166 if (unlikely(listener
->queue_len
>= listener
->queue_maxlen
)) {
1167 if (listener
->queue_maxlen
<= 0)
1175 kref_get(&(trtg_unconn_l
->reversedir
->ref
));
1177 BUG_ON(trtg_unconn_l
->is_client
!= 1);
1178 mutex_lock(&(trtg_unconn_l
->reversedir
->rcv_lock
));
1179 conn_init_sock_target(trtg_unconn_l
);
1180 conn_init_sock_source(trtg_unconn_l
->reversedir
);
1181 mutex_unlock(&(trtg_unconn_l
->reversedir
->rcv_lock
));
1183 list_add_tail(&(trtg_unconn_l
->reversedir
->source
.sock
.cl_list
),
1184 &(listener
->conn_queue
));
1185 listener
->queue_len
++;
1186 wake_up_interruptible(&(listener
->wait
));
1189 mutex_unlock(&(listener
->lock
));
1192 mutex_unlock(&cor_bindnodes
);
1198 * rc == 2 addrtype not found
1199 * rc == 3 addr not found
1200 * rc == 4 ==> connid allocation failed
1201 * rc == 4 ==> control msg alloc failed
1203 int connect_neigh(struct conn
*trtg_unconn_l
,
1204 __u16 addrtypelen
, __u8
*addrtype
,
1205 __u16 addrlen
, __u8
*addr
)
1209 struct control_msg_out
*cm
;
1210 struct neighbor
*nb
= 0;
1212 if (addrtype_known(addrtypelen
, addrtype
) == 0) {
1217 nb
= find_neigh(addrtypelen
, addrtype
, addrlen
, addr
);
1224 cm
= alloc_control_msg(nb
, ACM_PRIORITY_HIGH
);
1225 if (unlikely(cm
== 0)) {
1230 mutex_lock(&(trtg_unconn_l
->reversedir
->rcv_lock
));
1231 ciorc
= conn_init_out(trtg_unconn_l
, nb
);
1232 mutex_unlock(&(trtg_unconn_l
->reversedir
->rcv_lock
));
1233 if (unlikely(ciorc
)) {
1238 send_connect_nb(cm
, trtg_unconn_l
->reversedir
->source
.in
.conn_id
,
1239 trtg_unconn_l
->reversedir
->source
.in
.next_seqno
,
1240 trtg_unconn_l
->reversedir
);
1244 free_control_msg(cm
);
1246 trtg_unconn_l
->targettype
= TARGET_DISCARD
;
1250 kref_put(&(nb
->ref
), neighbor_free
);
1255 static int _reset_conn(struct conn
*cn
, int trgt_out_resetneeded
)
1258 * active conns have an additional ref to make sure that they are not
1259 * freed when only one direction is referenced by the connid hashtable
1263 /* lock sourcetype/targettype */
1264 mutex_lock(&(cn
->rcv_lock
));
1266 if (cn
->sourcetype
== SOURCE_IN
) {
1267 unsigned long iflags
;
1269 spin_lock_irqsave(&(cn
->source
.in
.nb
->conn_list_lock
), iflags
);
1270 list_del(&(cn
->source
.in
.nb_list
));
1271 spin_unlock_irqrestore(&(cn
->source
.in
.nb
->conn_list_lock
),
1274 set_busy_till(cn
->source
.in
.nb
, 0);
1278 if (cn
->source
.in
.conn_id
!= 0) {
1279 BUG_ON(cn
->source
.in
.cir
== 0);
1281 kref_init(&(cn
->source
.in
.cir
->ref
));
1282 cn
->source
.in
.cir
->conn_id
= cn
->source
.in
.conn_id
;
1283 cn
->source
.in
.cir
->pingcnt
=
1284 cn
->source
.in
.nb
->connid_reuse_pingcnt
;
1287 &(cn
->source
.in
.nb
->connid_reuse_lock
),
1289 htable_insert(&connid_reuse_table
,
1290 (char *) cn
->source
.in
.cir
,
1291 cn
->source
.in
.cir
->conn_id
);
1292 list_add_tail(&(cn
->source
.in
.cir
->lh
),
1293 &(cn
->source
.in
.nb
->connid_reuse_list
));
1294 spin_unlock_irqrestore(
1295 &(cn
->source
.in
.nb
->connid_reuse_lock
),
1298 cn
->source
.in
.cir
= 0;
1300 if (htable_delete(&connid_table
,
1301 cn
->source
.in
.conn_id
,
1302 &(cn
->source
.in
.conn_id
), free_conn
)) {
1303 printk(KERN_ERR
"error in _reset_conn: "
1304 "htable_delete src_in failed");
1307 cn
->source
.in
.conn_id
= 0;
1312 atomic_dec(&num_conns
);
1313 BUG_ON(atomic_read(&num_conns
) < 0);
1315 reset_ooo_queue(cn
);
1316 } else if (cn
->sourcetype
== SOURCE_SOCK
) {
1317 wake_up_interruptible(&(cn
->source
.sock
.wait
));
1320 if (cn
->targettype
== TARGET_UNCONNECTED
) {
1321 connreset_cpacket_buffer(cn
);
1322 } else if (cn
->targettype
== TARGET_OUT
) {
1323 if (trgt_out_resetneeded
&& cn
->target
.out
.conn_id
!= 0) {
1324 send_reset_conn(cn
->target
.out
.nb
,
1325 cn
->target
.out
.conn_id
,
1326 cn
->reversedir
->source
.in
.conn_id
, 0);
1329 if (cn
->target
.out
.conn_id
!= 0) {
1330 struct reverse_connid_matchparam rcm
;
1331 rcm
.nb
= cn
->target
.out
.nb
;
1332 rcm
.conn_id
= cn
->target
.out
.conn_id
;
1333 if (htable_delete(&reverse_connid_table
,
1336 printk(KERN_ERR
"error in _reset_conn: "
1337 "htable_delete target_out "
1342 cn
->target
.out
.conn_id
= 0;
1346 qos_remove_conn(cn
);
1347 } else if (cn
->targettype
== TARGET_SOCK
) {
1348 wake_up_interruptible(&(cn
->target
.sock
.wait
));
1351 databuf_ackdiscard(cn
);
1353 mutex_unlock(&(cn
->rcv_lock
));
1355 reset_bufferusage(cn
); /* source in only */
1356 connreset_credits(cn
);
1357 connreset_sbt(cn
); /* source sock only */
1362 /* warning: do not hold the rcv_lock while calling this! */
1363 void reset_conn(struct conn
*cn
)
1371 if (cn
->is_client
) {
1372 mutex_lock(&(cn
->rcv_lock
));
1373 mutex_lock(&(cn
->reversedir
->rcv_lock
));
1375 mutex_lock(&(cn
->reversedir
->rcv_lock
));
1376 mutex_lock(&(cn
->rcv_lock
));
1379 BUG_ON(cn
->isreset
<= 1 && cn
->reversedir
->isreset
>= 2);
1380 BUG_ON(cn
->isreset
>= 2 && cn
->reversedir
->isreset
<= 1);
1382 isreset1
= cn
->isreset
;
1383 if (cn
->isreset
<= 1)
1386 isreset2
= cn
->reversedir
->isreset
;
1387 if (cn
->reversedir
->isreset
<= 1)
1388 cn
->reversedir
->isreset
= 2;
1390 if (cn
->is_client
) {
1391 mutex_unlock(&(cn
->rcv_lock
));
1392 mutex_unlock(&(cn
->reversedir
->rcv_lock
));
1394 mutex_unlock(&(cn
->reversedir
->rcv_lock
));
1395 mutex_unlock(&(cn
->rcv_lock
));
1401 put1
= _reset_conn(cn
, isreset1
== 0);
1402 put2
= _reset_conn(cn
->reversedir
, isreset2
== 0);
1404 /* free_conn may not be called, before both _reset_conn have finished */
1406 kref_put(&(cn
->ref
), free_conn
);
1411 kref_put(&(cn
->reversedir
->ref
), free_conn
);
1416 static int __init
cor_common_init(void)
1422 check_log_64_11_table();
1423 check_log_300_24_table();
1425 printk(KERN_ERR
"sizeof conn: %d", sizeof(c
));
1426 printk(KERN_ERR
" conn.source: %d", sizeof(c
.source
));
1427 printk(KERN_ERR
" conn.target: %d", sizeof(c
.target
));
1428 printk(KERN_ERR
" conn.target.out: %d", sizeof(c
.target
.out
));
1429 printk(KERN_ERR
" conn.buf: %d", sizeof(c
.data_buf
));
1431 printk(KERN_ERR
" mutex: %d", sizeof(struct mutex
));
1432 printk(KERN_ERR
" spinlock: %d", sizeof(spinlock_t
));
1433 printk(KERN_ERR
" kref: %d", sizeof(struct kref
));
1435 conn_slab
= kmem_cache_create("cor_conn", sizeof(struct conn
), 8, 0, 0);
1436 connid_reuse_slab
= kmem_cache_create("cor_connid_reuse",
1437 sizeof(struct connid_reuse_item
), 8, 0, 0);
1439 htable_init(&connid_table
, matches_connid_in
,
1440 offsetof(struct conn
, source
.in
.htab_entry
),
1441 offsetof(struct conn
, ref
));
1443 htable_init(&reverse_connid_table
, matches_reverse_connid
,
1444 offsetof(struct conn
, target
.out
.htab_entry
),
1445 offsetof(struct conn
, ref
));
1447 htable_init(&connid_reuse_table
, matches_reuse_connid
,
1448 offsetof(struct connid_reuse_item
, htab_entry
),
1449 offsetof(struct connid_reuse_item
, ref
));
1452 bindnode_slab
= kmem_cache_create("cor_bindnode",
1453 sizeof(struct bindnode
), 8, 0, 0);
1454 connlistener_slab
= kmem_cache_create("cor_connlistener",
1455 sizeof(struct connlistener
), 8, 0, 0);
1457 atomic_set(&num_conns
, 0);
1464 rc
= cor_snd_init();
1465 if (unlikely(rc
!= 0))
1468 rc
= cor_neighbor_init();
1469 if (unlikely(rc
!= 0))
1472 rc
= cor_rcv_init();
1473 if (unlikely(rc
!= 0))
1479 module_init(cor_common_init
);
1480 MODULE_LICENSE("GPL");