link.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808
  1. /*
  2. * net/tipc/link.c: TIPC link code
  3. *
  4. * Copyright (c) 1996-2007, 2012-2014, Ericsson AB
  5. * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "link.h"
  38. #include "port.h"
  39. #include "name_distr.h"
  40. #include "discover.h"
  41. #include "config.h"
  42. #include <linux/pkt_sched.h>
  43. /*
  44. * Error message prefixes
  45. */
  46. static const char *link_co_err = "Link changeover error, ";
  47. static const char *link_rst_msg = "Resetting link ";
  48. static const char *link_unk_evt = "Unknown link event ";
  49. /*
  50. * Out-of-range value for link session numbers
  51. */
  52. #define INVALID_SESSION 0x10000
  53. /*
  54. * Link state events:
  55. */
  56. #define STARTING_EVT 856384768 /* link processing trigger */
  57. #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
  58. #define TIMEOUT_EVT 560817u /* link timer expired */
  59. /*
  60. * The following two 'message types' is really just implementation
  61. * data conveniently stored in the message header.
  62. * They must not be considered part of the protocol
  63. */
  64. #define OPEN_MSG 0
  65. #define CLOSED_MSG 1
  66. /*
  67. * State value stored in 'exp_msg_count'
  68. */
  69. #define START_CHANGEOVER 100000u
  70. static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
  71. struct sk_buff *buf);
  72. static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf);
  73. static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr,
  74. struct sk_buff **buf);
  75. static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance);
  76. static int tipc_link_iovec_long_xmit(struct tipc_port *sender,
  77. struct iovec const *msg_sect,
  78. unsigned int len, u32 destnode);
  79. static void link_state_event(struct tipc_link *l_ptr, u32 event);
  80. static void link_reset_statistics(struct tipc_link *l_ptr);
  81. static void link_print(struct tipc_link *l_ptr, const char *str);
  82. static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf);
  83. static void tipc_link_sync_xmit(struct tipc_link *l);
  84. static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf);
  85. /*
  86. * Simple link routines
  87. */
  88. static unsigned int align(unsigned int i)
  89. {
  90. return (i + 3) & ~3u;
  91. }
  92. static void link_init_max_pkt(struct tipc_link *l_ptr)
  93. {
  94. u32 max_pkt;
  95. max_pkt = (l_ptr->b_ptr->mtu & ~3);
  96. if (max_pkt > MAX_MSG_SIZE)
  97. max_pkt = MAX_MSG_SIZE;
  98. l_ptr->max_pkt_target = max_pkt;
  99. if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
  100. l_ptr->max_pkt = l_ptr->max_pkt_target;
  101. else
  102. l_ptr->max_pkt = MAX_PKT_DEFAULT;
  103. l_ptr->max_pkt_probes = 0;
  104. }
  105. static u32 link_next_sent(struct tipc_link *l_ptr)
  106. {
  107. if (l_ptr->next_out)
  108. return buf_seqno(l_ptr->next_out);
  109. return mod(l_ptr->next_out_no);
  110. }
  111. static u32 link_last_sent(struct tipc_link *l_ptr)
  112. {
  113. return mod(link_next_sent(l_ptr) - 1);
  114. }
  115. /*
  116. * Simple non-static link routines (i.e. referenced outside this file)
  117. */
  118. int tipc_link_is_up(struct tipc_link *l_ptr)
  119. {
  120. if (!l_ptr)
  121. return 0;
  122. return link_working_working(l_ptr) || link_working_unknown(l_ptr);
  123. }
  124. int tipc_link_is_active(struct tipc_link *l_ptr)
  125. {
  126. return (l_ptr->owner->active_links[0] == l_ptr) ||
  127. (l_ptr->owner->active_links[1] == l_ptr);
  128. }
  129. /**
  130. * link_timeout - handle expiration of link timer
  131. * @l_ptr: pointer to link
  132. */
  133. static void link_timeout(struct tipc_link *l_ptr)
  134. {
  135. tipc_node_lock(l_ptr->owner);
  136. /* update counters used in statistical profiling of send traffic */
  137. l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
  138. l_ptr->stats.queue_sz_counts++;
  139. if (l_ptr->first_out) {
  140. struct tipc_msg *msg = buf_msg(l_ptr->first_out);
  141. u32 length = msg_size(msg);
  142. if ((msg_user(msg) == MSG_FRAGMENTER) &&
  143. (msg_type(msg) == FIRST_FRAGMENT)) {
  144. length = msg_size(msg_get_wrapped(msg));
  145. }
  146. if (length) {
  147. l_ptr->stats.msg_lengths_total += length;
  148. l_ptr->stats.msg_length_counts++;
  149. if (length <= 64)
  150. l_ptr->stats.msg_length_profile[0]++;
  151. else if (length <= 256)
  152. l_ptr->stats.msg_length_profile[1]++;
  153. else if (length <= 1024)
  154. l_ptr->stats.msg_length_profile[2]++;
  155. else if (length <= 4096)
  156. l_ptr->stats.msg_length_profile[3]++;
  157. else if (length <= 16384)
  158. l_ptr->stats.msg_length_profile[4]++;
  159. else if (length <= 32768)
  160. l_ptr->stats.msg_length_profile[5]++;
  161. else
  162. l_ptr->stats.msg_length_profile[6]++;
  163. }
  164. }
  165. /* do all other link processing performed on a periodic basis */
  166. link_state_event(l_ptr, TIMEOUT_EVT);
  167. if (l_ptr->next_out)
  168. tipc_link_push_queue(l_ptr);
  169. tipc_node_unlock(l_ptr->owner);
  170. }
  171. static void link_set_timer(struct tipc_link *l_ptr, u32 time)
  172. {
  173. k_start_timer(&l_ptr->timer, time);
  174. }
  175. /**
  176. * tipc_link_create - create a new link
  177. * @n_ptr: pointer to associated node
  178. * @b_ptr: pointer to associated bearer
  179. * @media_addr: media address to use when sending messages over link
  180. *
  181. * Returns pointer to link.
  182. */
  183. struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
  184. struct tipc_bearer *b_ptr,
  185. const struct tipc_media_addr *media_addr)
  186. {
  187. struct tipc_link *l_ptr;
  188. struct tipc_msg *msg;
  189. char *if_name;
  190. char addr_string[16];
  191. u32 peer = n_ptr->addr;
  192. if (n_ptr->link_cnt >= 2) {
  193. tipc_addr_string_fill(addr_string, n_ptr->addr);
  194. pr_err("Attempt to establish third link to %s\n", addr_string);
  195. return NULL;
  196. }
  197. if (n_ptr->links[b_ptr->identity]) {
  198. tipc_addr_string_fill(addr_string, n_ptr->addr);
  199. pr_err("Attempt to establish second link on <%s> to %s\n",
  200. b_ptr->name, addr_string);
  201. return NULL;
  202. }
  203. l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
  204. if (!l_ptr) {
  205. pr_warn("Link creation failed, no memory\n");
  206. return NULL;
  207. }
  208. l_ptr->addr = peer;
  209. if_name = strchr(b_ptr->name, ':') + 1;
  210. sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
  211. tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
  212. tipc_node(tipc_own_addr),
  213. if_name,
  214. tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
  215. /* note: peer i/f name is updated by reset/activate message */
  216. memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
  217. l_ptr->owner = n_ptr;
  218. l_ptr->checkpoint = 1;
  219. l_ptr->peer_session = INVALID_SESSION;
  220. l_ptr->b_ptr = b_ptr;
  221. link_set_supervision_props(l_ptr, b_ptr->tolerance);
  222. l_ptr->state = RESET_UNKNOWN;
  223. l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
  224. msg = l_ptr->pmsg;
  225. tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
  226. msg_set_size(msg, sizeof(l_ptr->proto_msg));
  227. msg_set_session(msg, (tipc_random & 0xffff));
  228. msg_set_bearer_id(msg, b_ptr->identity);
  229. strcpy((char *)msg_data(msg), if_name);
  230. l_ptr->priority = b_ptr->priority;
  231. tipc_link_set_queue_limits(l_ptr, b_ptr->window);
  232. link_init_max_pkt(l_ptr);
  233. l_ptr->next_out_no = 1;
  234. INIT_LIST_HEAD(&l_ptr->waiting_ports);
  235. link_reset_statistics(l_ptr);
  236. tipc_node_attach_link(n_ptr, l_ptr);
  237. k_init_timer(&l_ptr->timer, (Handler)link_timeout,
  238. (unsigned long)l_ptr);
  239. link_state_event(l_ptr, STARTING_EVT);
  240. return l_ptr;
  241. }
  242. void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down)
  243. {
  244. struct tipc_link *l_ptr;
  245. struct tipc_node *n_ptr;
  246. rcu_read_lock();
  247. list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
  248. spin_lock_bh(&n_ptr->lock);
  249. l_ptr = n_ptr->links[bearer_id];
  250. if (l_ptr) {
  251. tipc_link_reset(l_ptr);
  252. if (shutting_down || !tipc_node_is_up(n_ptr)) {
  253. tipc_node_detach_link(l_ptr->owner, l_ptr);
  254. tipc_link_reset_fragments(l_ptr);
  255. spin_unlock_bh(&n_ptr->lock);
  256. /* Nobody else can access this link now: */
  257. del_timer_sync(&l_ptr->timer);
  258. kfree(l_ptr);
  259. } else {
  260. /* Detach/delete when failover is finished: */
  261. l_ptr->flags |= LINK_STOPPED;
  262. spin_unlock_bh(&n_ptr->lock);
  263. del_timer_sync(&l_ptr->timer);
  264. }
  265. continue;
  266. }
  267. spin_unlock_bh(&n_ptr->lock);
  268. }
  269. rcu_read_unlock();
  270. }
  271. /**
  272. * link_schedule_port - schedule port for deferred sending
  273. * @l_ptr: pointer to link
  274. * @origport: reference to sending port
  275. * @sz: amount of data to be sent
  276. *
  277. * Schedules port for renewed sending of messages after link congestion
  278. * has abated.
  279. */
  280. static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
  281. {
  282. struct tipc_port *p_ptr;
  283. spin_lock_bh(&tipc_port_list_lock);
  284. p_ptr = tipc_port_lock(origport);
  285. if (p_ptr) {
  286. if (!list_empty(&p_ptr->wait_list))
  287. goto exit;
  288. p_ptr->congested = 1;
  289. p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
  290. list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
  291. l_ptr->stats.link_congs++;
  292. exit:
  293. tipc_port_unlock(p_ptr);
  294. }
  295. spin_unlock_bh(&tipc_port_list_lock);
  296. return -ELINKCONG;
  297. }
  298. void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
  299. {
  300. struct tipc_port *p_ptr;
  301. struct tipc_port *temp_p_ptr;
  302. int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
  303. if (all)
  304. win = 100000;
  305. if (win <= 0)
  306. return;
  307. if (!spin_trylock_bh(&tipc_port_list_lock))
  308. return;
  309. if (link_congested(l_ptr))
  310. goto exit;
  311. list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
  312. wait_list) {
  313. if (win <= 0)
  314. break;
  315. list_del_init(&p_ptr->wait_list);
  316. spin_lock_bh(p_ptr->lock);
  317. p_ptr->congested = 0;
  318. tipc_port_wakeup(p_ptr);
  319. win -= p_ptr->waiting_pkts;
  320. spin_unlock_bh(p_ptr->lock);
  321. }
  322. exit:
  323. spin_unlock_bh(&tipc_port_list_lock);
  324. }
  325. /**
  326. * link_release_outqueue - purge link's outbound message queue
  327. * @l_ptr: pointer to link
  328. */
  329. static void link_release_outqueue(struct tipc_link *l_ptr)
  330. {
  331. kfree_skb_list(l_ptr->first_out);
  332. l_ptr->first_out = NULL;
  333. l_ptr->out_queue_size = 0;
  334. }
  335. /**
  336. * tipc_link_reset_fragments - purge link's inbound message fragments queue
  337. * @l_ptr: pointer to link
  338. */
  339. void tipc_link_reset_fragments(struct tipc_link *l_ptr)
  340. {
  341. kfree_skb(l_ptr->reasm_head);
  342. l_ptr->reasm_head = NULL;
  343. l_ptr->reasm_tail = NULL;
  344. }
  345. /**
  346. * tipc_link_purge_queues - purge all pkt queues associated with link
  347. * @l_ptr: pointer to link
  348. */
  349. void tipc_link_purge_queues(struct tipc_link *l_ptr)
  350. {
  351. kfree_skb_list(l_ptr->oldest_deferred_in);
  352. kfree_skb_list(l_ptr->first_out);
  353. tipc_link_reset_fragments(l_ptr);
  354. kfree_skb(l_ptr->proto_msg_queue);
  355. l_ptr->proto_msg_queue = NULL;
  356. }
  357. void tipc_link_reset(struct tipc_link *l_ptr)
  358. {
  359. u32 prev_state = l_ptr->state;
  360. u32 checkpoint = l_ptr->next_in_no;
  361. int was_active_link = tipc_link_is_active(l_ptr);
  362. msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
  363. /* Link is down, accept any session */
  364. l_ptr->peer_session = INVALID_SESSION;
  365. /* Prepare for max packet size negotiation */
  366. link_init_max_pkt(l_ptr);
  367. l_ptr->state = RESET_UNKNOWN;
  368. if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
  369. return;
  370. tipc_node_link_down(l_ptr->owner, l_ptr);
  371. tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr);
  372. if (was_active_link && tipc_node_active_links(l_ptr->owner)) {
  373. l_ptr->reset_checkpoint = checkpoint;
  374. l_ptr->exp_msg_count = START_CHANGEOVER;
  375. }
  376. /* Clean up all queues: */
  377. link_release_outqueue(l_ptr);
  378. kfree_skb(l_ptr->proto_msg_queue);
  379. l_ptr->proto_msg_queue = NULL;
  380. kfree_skb_list(l_ptr->oldest_deferred_in);
  381. if (!list_empty(&l_ptr->waiting_ports))
  382. tipc_link_wakeup_ports(l_ptr, 1);
  383. l_ptr->retransm_queue_head = 0;
  384. l_ptr->retransm_queue_size = 0;
  385. l_ptr->last_out = NULL;
  386. l_ptr->first_out = NULL;
  387. l_ptr->next_out = NULL;
  388. l_ptr->unacked_window = 0;
  389. l_ptr->checkpoint = 1;
  390. l_ptr->next_out_no = 1;
  391. l_ptr->deferred_inqueue_sz = 0;
  392. l_ptr->oldest_deferred_in = NULL;
  393. l_ptr->newest_deferred_in = NULL;
  394. l_ptr->fsm_msg_cnt = 0;
  395. l_ptr->stale_count = 0;
  396. link_reset_statistics(l_ptr);
  397. }
  398. void tipc_link_reset_list(unsigned int bearer_id)
  399. {
  400. struct tipc_link *l_ptr;
  401. struct tipc_node *n_ptr;
  402. rcu_read_lock();
  403. list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
  404. spin_lock_bh(&n_ptr->lock);
  405. l_ptr = n_ptr->links[bearer_id];
  406. if (l_ptr)
  407. tipc_link_reset(l_ptr);
  408. spin_unlock_bh(&n_ptr->lock);
  409. }
  410. rcu_read_unlock();
  411. }
  412. static void link_activate(struct tipc_link *l_ptr)
  413. {
  414. l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
  415. tipc_node_link_up(l_ptr->owner, l_ptr);
  416. tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr);
  417. }
  418. /**
  419. * link_state_event - link finite state machine
  420. * @l_ptr: pointer to link
  421. * @event: state machine event to process
  422. */
  423. static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
  424. {
  425. struct tipc_link *other;
  426. u32 cont_intv = l_ptr->continuity_interval;
  427. if (l_ptr->flags & LINK_STOPPED)
  428. return;
  429. if (!(l_ptr->flags & LINK_STARTED) && (event != STARTING_EVT))
  430. return; /* Not yet. */
  431. /* Check whether changeover is going on */
  432. if (l_ptr->exp_msg_count) {
  433. if (event == TIMEOUT_EVT)
  434. link_set_timer(l_ptr, cont_intv);
  435. return;
  436. }
  437. switch (l_ptr->state) {
  438. case WORKING_WORKING:
  439. switch (event) {
  440. case TRAFFIC_MSG_EVT:
  441. case ACTIVATE_MSG:
  442. break;
  443. case TIMEOUT_EVT:
  444. if (l_ptr->next_in_no != l_ptr->checkpoint) {
  445. l_ptr->checkpoint = l_ptr->next_in_no;
  446. if (tipc_bclink_acks_missing(l_ptr->owner)) {
  447. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  448. 0, 0, 0, 0, 0);
  449. l_ptr->fsm_msg_cnt++;
  450. } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
  451. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  452. 1, 0, 0, 0, 0);
  453. l_ptr->fsm_msg_cnt++;
  454. }
  455. link_set_timer(l_ptr, cont_intv);
  456. break;
  457. }
  458. l_ptr->state = WORKING_UNKNOWN;
  459. l_ptr->fsm_msg_cnt = 0;
  460. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
  461. l_ptr->fsm_msg_cnt++;
  462. link_set_timer(l_ptr, cont_intv / 4);
  463. break;
  464. case RESET_MSG:
  465. pr_info("%s<%s>, requested by peer\n", link_rst_msg,
  466. l_ptr->name);
  467. tipc_link_reset(l_ptr);
  468. l_ptr->state = RESET_RESET;
  469. l_ptr->fsm_msg_cnt = 0;
  470. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  471. 0, 0, 0, 0, 0);
  472. l_ptr->fsm_msg_cnt++;
  473. link_set_timer(l_ptr, cont_intv);
  474. break;
  475. default:
  476. pr_err("%s%u in WW state\n", link_unk_evt, event);
  477. }
  478. break;
  479. case WORKING_UNKNOWN:
  480. switch (event) {
  481. case TRAFFIC_MSG_EVT:
  482. case ACTIVATE_MSG:
  483. l_ptr->state = WORKING_WORKING;
  484. l_ptr->fsm_msg_cnt = 0;
  485. link_set_timer(l_ptr, cont_intv);
  486. break;
  487. case RESET_MSG:
  488. pr_info("%s<%s>, requested by peer while probing\n",
  489. link_rst_msg, l_ptr->name);
  490. tipc_link_reset(l_ptr);
  491. l_ptr->state = RESET_RESET;
  492. l_ptr->fsm_msg_cnt = 0;
  493. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  494. 0, 0, 0, 0, 0);
  495. l_ptr->fsm_msg_cnt++;
  496. link_set_timer(l_ptr, cont_intv);
  497. break;
  498. case TIMEOUT_EVT:
  499. if (l_ptr->next_in_no != l_ptr->checkpoint) {
  500. l_ptr->state = WORKING_WORKING;
  501. l_ptr->fsm_msg_cnt = 0;
  502. l_ptr->checkpoint = l_ptr->next_in_no;
  503. if (tipc_bclink_acks_missing(l_ptr->owner)) {
  504. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  505. 0, 0, 0, 0, 0);
  506. l_ptr->fsm_msg_cnt++;
  507. }
  508. link_set_timer(l_ptr, cont_intv);
  509. } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
  510. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  511. 1, 0, 0, 0, 0);
  512. l_ptr->fsm_msg_cnt++;
  513. link_set_timer(l_ptr, cont_intv / 4);
  514. } else { /* Link has failed */
  515. pr_warn("%s<%s>, peer not responding\n",
  516. link_rst_msg, l_ptr->name);
  517. tipc_link_reset(l_ptr);
  518. l_ptr->state = RESET_UNKNOWN;
  519. l_ptr->fsm_msg_cnt = 0;
  520. tipc_link_proto_xmit(l_ptr, RESET_MSG,
  521. 0, 0, 0, 0, 0);
  522. l_ptr->fsm_msg_cnt++;
  523. link_set_timer(l_ptr, cont_intv);
  524. }
  525. break;
  526. default:
  527. pr_err("%s%u in WU state\n", link_unk_evt, event);
  528. }
  529. break;
  530. case RESET_UNKNOWN:
  531. switch (event) {
  532. case TRAFFIC_MSG_EVT:
  533. break;
  534. case ACTIVATE_MSG:
  535. other = l_ptr->owner->active_links[0];
  536. if (other && link_working_unknown(other))
  537. break;
  538. l_ptr->state = WORKING_WORKING;
  539. l_ptr->fsm_msg_cnt = 0;
  540. link_activate(l_ptr);
  541. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
  542. l_ptr->fsm_msg_cnt++;
  543. if (l_ptr->owner->working_links == 1)
  544. tipc_link_sync_xmit(l_ptr);
  545. link_set_timer(l_ptr, cont_intv);
  546. break;
  547. case RESET_MSG:
  548. l_ptr->state = RESET_RESET;
  549. l_ptr->fsm_msg_cnt = 0;
  550. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  551. 1, 0, 0, 0, 0);
  552. l_ptr->fsm_msg_cnt++;
  553. link_set_timer(l_ptr, cont_intv);
  554. break;
  555. case STARTING_EVT:
  556. l_ptr->flags |= LINK_STARTED;
  557. /* fall through */
  558. case TIMEOUT_EVT:
  559. tipc_link_proto_xmit(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
  560. l_ptr->fsm_msg_cnt++;
  561. link_set_timer(l_ptr, cont_intv);
  562. break;
  563. default:
  564. pr_err("%s%u in RU state\n", link_unk_evt, event);
  565. }
  566. break;
  567. case RESET_RESET:
  568. switch (event) {
  569. case TRAFFIC_MSG_EVT:
  570. case ACTIVATE_MSG:
  571. other = l_ptr->owner->active_links[0];
  572. if (other && link_working_unknown(other))
  573. break;
  574. l_ptr->state = WORKING_WORKING;
  575. l_ptr->fsm_msg_cnt = 0;
  576. link_activate(l_ptr);
  577. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
  578. l_ptr->fsm_msg_cnt++;
  579. if (l_ptr->owner->working_links == 1)
  580. tipc_link_sync_xmit(l_ptr);
  581. link_set_timer(l_ptr, cont_intv);
  582. break;
  583. case RESET_MSG:
  584. break;
  585. case TIMEOUT_EVT:
  586. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  587. 0, 0, 0, 0, 0);
  588. l_ptr->fsm_msg_cnt++;
  589. link_set_timer(l_ptr, cont_intv);
  590. break;
  591. default:
  592. pr_err("%s%u in RR state\n", link_unk_evt, event);
  593. }
  594. break;
  595. default:
  596. pr_err("Unknown link state %u/%u\n", l_ptr->state, event);
  597. }
  598. }
  599. /*
  600. * link_bundle_buf(): Append contents of a buffer to
  601. * the tail of an existing one.
  602. */
  603. static int link_bundle_buf(struct tipc_link *l_ptr, struct sk_buff *bundler,
  604. struct sk_buff *buf)
  605. {
  606. struct tipc_msg *bundler_msg = buf_msg(bundler);
  607. struct tipc_msg *msg = buf_msg(buf);
  608. u32 size = msg_size(msg);
  609. u32 bundle_size = msg_size(bundler_msg);
  610. u32 to_pos = align(bundle_size);
  611. u32 pad = to_pos - bundle_size;
  612. if (msg_user(bundler_msg) != MSG_BUNDLER)
  613. return 0;
  614. if (msg_type(bundler_msg) != OPEN_MSG)
  615. return 0;
  616. if (skb_tailroom(bundler) < (pad + size))
  617. return 0;
  618. if (l_ptr->max_pkt < (to_pos + size))
  619. return 0;
  620. skb_put(bundler, pad + size);
  621. skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
  622. msg_set_size(bundler_msg, to_pos + size);
  623. msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
  624. kfree_skb(buf);
  625. l_ptr->stats.sent_bundled++;
  626. return 1;
  627. }
  628. static void link_add_to_outqueue(struct tipc_link *l_ptr,
  629. struct sk_buff *buf,
  630. struct tipc_msg *msg)
  631. {
  632. u32 ack = mod(l_ptr->next_in_no - 1);
  633. u32 seqno = mod(l_ptr->next_out_no++);
  634. msg_set_word(msg, 2, ((ack << 16) | seqno));
  635. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  636. buf->next = NULL;
  637. if (l_ptr->first_out) {
  638. l_ptr->last_out->next = buf;
  639. l_ptr->last_out = buf;
  640. } else
  641. l_ptr->first_out = l_ptr->last_out = buf;
  642. l_ptr->out_queue_size++;
  643. if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz)
  644. l_ptr->stats.max_queue_sz = l_ptr->out_queue_size;
  645. }
  646. static void link_add_chain_to_outqueue(struct tipc_link *l_ptr,
  647. struct sk_buff *buf_chain,
  648. u32 long_msgno)
  649. {
  650. struct sk_buff *buf;
  651. struct tipc_msg *msg;
  652. if (!l_ptr->next_out)
  653. l_ptr->next_out = buf_chain;
  654. while (buf_chain) {
  655. buf = buf_chain;
  656. buf_chain = buf_chain->next;
  657. msg = buf_msg(buf);
  658. msg_set_long_msgno(msg, long_msgno);
  659. link_add_to_outqueue(l_ptr, buf, msg);
  660. }
  661. }
  662. /*
  663. * tipc_link_xmit() is the 'full path' for messages, called from
  664. * inside TIPC when the 'fast path' in tipc_send_xmit
  665. * has failed, and from link_send()
  666. */
  667. int __tipc_link_xmit(struct tipc_link *l_ptr, struct sk_buff *buf)
  668. {
  669. struct tipc_msg *msg = buf_msg(buf);
  670. u32 size = msg_size(msg);
  671. u32 dsz = msg_data_sz(msg);
  672. u32 queue_size = l_ptr->out_queue_size;
  673. u32 imp = tipc_msg_tot_importance(msg);
  674. u32 queue_limit = l_ptr->queue_limit[imp];
  675. u32 max_packet = l_ptr->max_pkt;
  676. /* Match msg importance against queue limits: */
  677. if (unlikely(queue_size >= queue_limit)) {
  678. if (imp <= TIPC_CRITICAL_IMPORTANCE) {
  679. link_schedule_port(l_ptr, msg_origport(msg), size);
  680. kfree_skb(buf);
  681. return -ELINKCONG;
  682. }
  683. kfree_skb(buf);
  684. if (imp > CONN_MANAGER) {
  685. pr_warn("%s<%s>, send queue full", link_rst_msg,
  686. l_ptr->name);
  687. tipc_link_reset(l_ptr);
  688. }
  689. return dsz;
  690. }
  691. /* Fragmentation needed ? */
  692. if (size > max_packet)
  693. return tipc_link_frag_xmit(l_ptr, buf);
  694. /* Packet can be queued or sent. */
  695. if (likely(!link_congested(l_ptr))) {
  696. link_add_to_outqueue(l_ptr, buf, msg);
  697. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  698. l_ptr->unacked_window = 0;
  699. return dsz;
  700. }
  701. /* Congestion: can message be bundled ? */
  702. if ((msg_user(msg) != CHANGEOVER_PROTOCOL) &&
  703. (msg_user(msg) != MSG_FRAGMENTER)) {
  704. /* Try adding message to an existing bundle */
  705. if (l_ptr->next_out &&
  706. link_bundle_buf(l_ptr, l_ptr->last_out, buf))
  707. return dsz;
  708. /* Try creating a new bundle */
  709. if (size <= max_packet * 2 / 3) {
  710. struct sk_buff *bundler = tipc_buf_acquire(max_packet);
  711. struct tipc_msg bundler_hdr;
  712. if (bundler) {
  713. tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG,
  714. INT_H_SIZE, l_ptr->addr);
  715. skb_copy_to_linear_data(bundler, &bundler_hdr,
  716. INT_H_SIZE);
  717. skb_trim(bundler, INT_H_SIZE);
  718. link_bundle_buf(l_ptr, bundler, buf);
  719. buf = bundler;
  720. msg = buf_msg(buf);
  721. l_ptr->stats.sent_bundles++;
  722. }
  723. }
  724. }
  725. if (!l_ptr->next_out)
  726. l_ptr->next_out = buf;
  727. link_add_to_outqueue(l_ptr, buf, msg);
  728. return dsz;
  729. }
  730. /*
  731. * tipc_link_xmit(): same as __tipc_link_xmit(), but the link to use
  732. * has not been selected yet, and the the owner node is not locked
  733. * Called by TIPC internal users, e.g. the name distributor
  734. */
  735. int tipc_link_xmit(struct sk_buff *buf, u32 dest, u32 selector)
  736. {
  737. struct tipc_link *l_ptr;
  738. struct tipc_node *n_ptr;
  739. int res = -ELINKCONG;
  740. read_lock_bh(&tipc_net_lock);
  741. n_ptr = tipc_node_find(dest);
  742. if (n_ptr) {
  743. tipc_node_lock(n_ptr);
  744. l_ptr = n_ptr->active_links[selector & 1];
  745. if (l_ptr)
  746. res = __tipc_link_xmit(l_ptr, buf);
  747. else
  748. kfree_skb(buf);
  749. tipc_node_unlock(n_ptr);
  750. } else {
  751. kfree_skb(buf);
  752. }
  753. read_unlock_bh(&tipc_net_lock);
  754. return res;
  755. }
  756. /*
  757. * tipc_link_sync_xmit - synchronize broadcast link endpoints.
  758. *
  759. * Give a newly added peer node the sequence number where it should
  760. * start receiving and acking broadcast packets.
  761. *
  762. * Called with node locked
  763. */
  764. static void tipc_link_sync_xmit(struct tipc_link *l)
  765. {
  766. struct sk_buff *buf;
  767. struct tipc_msg *msg;
  768. buf = tipc_buf_acquire(INT_H_SIZE);
  769. if (!buf)
  770. return;
  771. msg = buf_msg(buf);
  772. tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, l->addr);
  773. msg_set_last_bcast(msg, l->owner->bclink.acked);
  774. link_add_chain_to_outqueue(l, buf, 0);
  775. tipc_link_push_queue(l);
  776. }
  777. /*
  778. * tipc_link_sync_rcv - synchronize broadcast link endpoints.
  779. * Receive the sequence number where we should start receiving and
  780. * acking broadcast packets from a newly added peer node, and open
  781. * up for reception of such packets.
  782. *
  783. * Called with node locked
  784. */
  785. static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf)
  786. {
  787. struct tipc_msg *msg = buf_msg(buf);
  788. n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg);
  789. n->bclink.recv_permitted = true;
  790. kfree_skb(buf);
  791. }
  792. /*
  793. * tipc_link_names_xmit - send name table entries to new neighbor
  794. *
  795. * Send routine for bulk delivery of name table messages when contact
  796. * with a new neighbor occurs. No link congestion checking is performed
  797. * because name table messages *must* be delivered. The messages must be
  798. * small enough not to require fragmentation.
  799. * Called without any locks held.
  800. */
  801. void tipc_link_names_xmit(struct list_head *message_list, u32 dest)
  802. {
  803. struct tipc_node *n_ptr;
  804. struct tipc_link *l_ptr;
  805. struct sk_buff *buf;
  806. struct sk_buff *temp_buf;
  807. if (list_empty(message_list))
  808. return;
  809. read_lock_bh(&tipc_net_lock);
  810. n_ptr = tipc_node_find(dest);
  811. if (n_ptr) {
  812. tipc_node_lock(n_ptr);
  813. l_ptr = n_ptr->active_links[0];
  814. if (l_ptr) {
  815. /* convert circular list to linear list */
  816. ((struct sk_buff *)message_list->prev)->next = NULL;
  817. link_add_chain_to_outqueue(l_ptr,
  818. (struct sk_buff *)message_list->next, 0);
  819. tipc_link_push_queue(l_ptr);
  820. INIT_LIST_HEAD(message_list);
  821. }
  822. tipc_node_unlock(n_ptr);
  823. }
  824. read_unlock_bh(&tipc_net_lock);
  825. /* discard the messages if they couldn't be sent */
  826. list_for_each_safe(buf, temp_buf, ((struct sk_buff *)message_list)) {
  827. list_del((struct list_head *)buf);
  828. kfree_skb(buf);
  829. }
  830. }
  831. /*
  832. * tipc_link_xmit_fast: Entry for data messages where the
  833. * destination link is known and the header is complete,
  834. * inclusive total message length. Very time critical.
  835. * Link is locked. Returns user data length.
  836. */
  837. static int tipc_link_xmit_fast(struct tipc_link *l_ptr, struct sk_buff *buf,
  838. u32 *used_max_pkt)
  839. {
  840. struct tipc_msg *msg = buf_msg(buf);
  841. int res = msg_data_sz(msg);
  842. if (likely(!link_congested(l_ptr))) {
  843. if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
  844. link_add_to_outqueue(l_ptr, buf, msg);
  845. tipc_bearer_send(l_ptr->b_ptr, buf,
  846. &l_ptr->media_addr);
  847. l_ptr->unacked_window = 0;
  848. return res;
  849. }
  850. else
  851. *used_max_pkt = l_ptr->max_pkt;
  852. }
  853. return __tipc_link_xmit(l_ptr, buf); /* All other cases */
  854. }
  855. /*
  856. * tipc_link_iovec_xmit_fast: Entry for messages where the
  857. * destination processor is known and the header is complete,
  858. * except for total message length.
  859. * Returns user data length or errno.
  860. */
  861. int tipc_link_iovec_xmit_fast(struct tipc_port *sender,
  862. struct iovec const *msg_sect,
  863. unsigned int len, u32 destaddr)
  864. {
  865. struct tipc_msg *hdr = &sender->phdr;
  866. struct tipc_link *l_ptr;
  867. struct sk_buff *buf;
  868. struct tipc_node *node;
  869. int res;
  870. u32 selector = msg_origport(hdr) & 1;
  871. again:
  872. /*
  873. * Try building message using port's max_pkt hint.
  874. * (Must not hold any locks while building message.)
  875. */
  876. res = tipc_msg_build(hdr, msg_sect, len, sender->max_pkt, &buf);
  877. /* Exit if build request was invalid */
  878. if (unlikely(res < 0))
  879. return res;
  880. read_lock_bh(&tipc_net_lock);
  881. node = tipc_node_find(destaddr);
  882. if (likely(node)) {
  883. tipc_node_lock(node);
  884. l_ptr = node->active_links[selector];
  885. if (likely(l_ptr)) {
  886. if (likely(buf)) {
  887. res = tipc_link_xmit_fast(l_ptr, buf,
  888. &sender->max_pkt);
  889. exit:
  890. tipc_node_unlock(node);
  891. read_unlock_bh(&tipc_net_lock);
  892. return res;
  893. }
  894. /* Exit if link (or bearer) is congested */
  895. if (link_congested(l_ptr)) {
  896. res = link_schedule_port(l_ptr,
  897. sender->ref, res);
  898. goto exit;
  899. }
  900. /*
  901. * Message size exceeds max_pkt hint; update hint,
  902. * then re-try fast path or fragment the message
  903. */
  904. sender->max_pkt = l_ptr->max_pkt;
  905. tipc_node_unlock(node);
  906. read_unlock_bh(&tipc_net_lock);
  907. if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt)
  908. goto again;
  909. return tipc_link_iovec_long_xmit(sender, msg_sect,
  910. len, destaddr);
  911. }
  912. tipc_node_unlock(node);
  913. }
  914. read_unlock_bh(&tipc_net_lock);
  915. /* Couldn't find a link to the destination node */
  916. kfree_skb(buf);
  917. tipc_port_iovec_reject(sender, hdr, msg_sect, len, TIPC_ERR_NO_NODE);
  918. return -ENETUNREACH;
  919. }
  920. /*
  921. * tipc_link_iovec_long_xmit(): Entry for long messages where the
  922. * destination node is known and the header is complete,
  923. * inclusive total message length.
  924. * Link and bearer congestion status have been checked to be ok,
  925. * and are ignored if they change.
  926. *
  927. * Note that fragments do not use the full link MTU so that they won't have
  928. * to undergo refragmentation if link changeover causes them to be sent
  929. * over another link with an additional tunnel header added as prefix.
  930. * (Refragmentation will still occur if the other link has a smaller MTU.)
  931. *
  932. * Returns user data length or errno.
  933. */
  934. static int tipc_link_iovec_long_xmit(struct tipc_port *sender,
  935. struct iovec const *msg_sect,
  936. unsigned int len, u32 destaddr)
  937. {
  938. struct tipc_link *l_ptr;
  939. struct tipc_node *node;
  940. struct tipc_msg *hdr = &sender->phdr;
  941. u32 dsz = len;
  942. u32 max_pkt, fragm_sz, rest;
  943. struct tipc_msg fragm_hdr;
  944. struct sk_buff *buf, *buf_chain, *prev;
  945. u32 fragm_crs, fragm_rest, hsz, sect_rest;
  946. const unchar __user *sect_crs;
  947. int curr_sect;
  948. u32 fragm_no;
  949. int res = 0;
  950. again:
  951. fragm_no = 1;
  952. max_pkt = sender->max_pkt - INT_H_SIZE;
  953. /* leave room for tunnel header in case of link changeover */
  954. fragm_sz = max_pkt - INT_H_SIZE;
  955. /* leave room for fragmentation header in each fragment */
  956. rest = dsz;
  957. fragm_crs = 0;
  958. fragm_rest = 0;
  959. sect_rest = 0;
  960. sect_crs = NULL;
  961. curr_sect = -1;
  962. /* Prepare reusable fragment header */
  963. tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
  964. INT_H_SIZE, msg_destnode(hdr));
  965. msg_set_size(&fragm_hdr, max_pkt);
  966. msg_set_fragm_no(&fragm_hdr, 1);
  967. /* Prepare header of first fragment */
  968. buf_chain = buf = tipc_buf_acquire(max_pkt);
  969. if (!buf)
  970. return -ENOMEM;
  971. buf->next = NULL;
  972. skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
  973. hsz = msg_hdr_sz(hdr);
  974. skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
  975. /* Chop up message */
  976. fragm_crs = INT_H_SIZE + hsz;
  977. fragm_rest = fragm_sz - hsz;
  978. do { /* For all sections */
  979. u32 sz;
  980. if (!sect_rest) {
  981. sect_rest = msg_sect[++curr_sect].iov_len;
  982. sect_crs = msg_sect[curr_sect].iov_base;
  983. }
  984. if (sect_rest < fragm_rest)
  985. sz = sect_rest;
  986. else
  987. sz = fragm_rest;
  988. if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
  989. res = -EFAULT;
  990. error:
  991. kfree_skb_list(buf_chain);
  992. return res;
  993. }
  994. sect_crs += sz;
  995. sect_rest -= sz;
  996. fragm_crs += sz;
  997. fragm_rest -= sz;
  998. rest -= sz;
  999. if (!fragm_rest && rest) {
  1000. /* Initiate new fragment: */
  1001. if (rest <= fragm_sz) {
  1002. fragm_sz = rest;
  1003. msg_set_type(&fragm_hdr, LAST_FRAGMENT);
  1004. } else {
  1005. msg_set_type(&fragm_hdr, FRAGMENT);
  1006. }
  1007. msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
  1008. msg_set_fragm_no(&fragm_hdr, ++fragm_no);
  1009. prev = buf;
  1010. buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
  1011. if (!buf) {
  1012. res = -ENOMEM;
  1013. goto error;
  1014. }
  1015. buf->next = NULL;
  1016. prev->next = buf;
  1017. skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
  1018. fragm_crs = INT_H_SIZE;
  1019. fragm_rest = fragm_sz;
  1020. }
  1021. } while (rest > 0);
  1022. /*
  1023. * Now we have a buffer chain. Select a link and check
  1024. * that packet size is still OK
  1025. */
  1026. node = tipc_node_find(destaddr);
  1027. if (likely(node)) {
  1028. tipc_node_lock(node);
  1029. l_ptr = node->active_links[sender->ref & 1];
  1030. if (!l_ptr) {
  1031. tipc_node_unlock(node);
  1032. goto reject;
  1033. }
  1034. if (l_ptr->max_pkt < max_pkt) {
  1035. sender->max_pkt = l_ptr->max_pkt;
  1036. tipc_node_unlock(node);
  1037. kfree_skb_list(buf_chain);
  1038. goto again;
  1039. }
  1040. } else {
  1041. reject:
  1042. kfree_skb_list(buf_chain);
  1043. tipc_port_iovec_reject(sender, hdr, msg_sect, len,
  1044. TIPC_ERR_NO_NODE);
  1045. return -ENETUNREACH;
  1046. }
  1047. /* Append chain of fragments to send queue & send them */
  1048. l_ptr->long_msg_seq_no++;
  1049. link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no);
  1050. l_ptr->stats.sent_fragments += fragm_no;
  1051. l_ptr->stats.sent_fragmented++;
  1052. tipc_link_push_queue(l_ptr);
  1053. tipc_node_unlock(node);
  1054. return dsz;
  1055. }
  1056. /*
  1057. * tipc_link_push_packet: Push one unsent packet to the media
  1058. */
  1059. static u32 tipc_link_push_packet(struct tipc_link *l_ptr)
  1060. {
  1061. struct sk_buff *buf = l_ptr->first_out;
  1062. u32 r_q_size = l_ptr->retransm_queue_size;
  1063. u32 r_q_head = l_ptr->retransm_queue_head;
  1064. /* Step to position where retransmission failed, if any, */
  1065. /* consider that buffers may have been released in meantime */
  1066. if (r_q_size && buf) {
  1067. u32 last = lesser(mod(r_q_head + r_q_size),
  1068. link_last_sent(l_ptr));
  1069. u32 first = buf_seqno(buf);
  1070. while (buf && less(first, r_q_head)) {
  1071. first = mod(first + 1);
  1072. buf = buf->next;
  1073. }
  1074. l_ptr->retransm_queue_head = r_q_head = first;
  1075. l_ptr->retransm_queue_size = r_q_size = mod(last - first);
  1076. }
  1077. /* Continue retransmission now, if there is anything: */
  1078. if (r_q_size && buf) {
  1079. msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
  1080. msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
  1081. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  1082. l_ptr->retransm_queue_head = mod(++r_q_head);
  1083. l_ptr->retransm_queue_size = --r_q_size;
  1084. l_ptr->stats.retransmitted++;
  1085. return 0;
  1086. }
  1087. /* Send deferred protocol message, if any: */
  1088. buf = l_ptr->proto_msg_queue;
  1089. if (buf) {
  1090. msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
  1091. msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
  1092. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  1093. l_ptr->unacked_window = 0;
  1094. kfree_skb(buf);
  1095. l_ptr->proto_msg_queue = NULL;
  1096. return 0;
  1097. }
  1098. /* Send one deferred data message, if send window not full: */
  1099. buf = l_ptr->next_out;
  1100. if (buf) {
  1101. struct tipc_msg *msg = buf_msg(buf);
  1102. u32 next = msg_seqno(msg);
  1103. u32 first = buf_seqno(l_ptr->first_out);
  1104. if (mod(next - first) < l_ptr->queue_limit[0]) {
  1105. msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
  1106. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  1107. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  1108. if (msg_user(msg) == MSG_BUNDLER)
  1109. msg_set_type(msg, CLOSED_MSG);
  1110. l_ptr->next_out = buf->next;
  1111. return 0;
  1112. }
  1113. }
  1114. return 1;
  1115. }
  1116. /*
  1117. * push_queue(): push out the unsent messages of a link where
  1118. * congestion has abated. Node is locked
  1119. */
  1120. void tipc_link_push_queue(struct tipc_link *l_ptr)
  1121. {
  1122. u32 res;
  1123. do {
  1124. res = tipc_link_push_packet(l_ptr);
  1125. } while (!res);
  1126. }
  1127. static void link_reset_all(unsigned long addr)
  1128. {
  1129. struct tipc_node *n_ptr;
  1130. char addr_string[16];
  1131. u32 i;
  1132. read_lock_bh(&tipc_net_lock);
  1133. n_ptr = tipc_node_find((u32)addr);
  1134. if (!n_ptr) {
  1135. read_unlock_bh(&tipc_net_lock);
  1136. return; /* node no longer exists */
  1137. }
  1138. tipc_node_lock(n_ptr);
  1139. pr_warn("Resetting all links to %s\n",
  1140. tipc_addr_string_fill(addr_string, n_ptr->addr));
  1141. for (i = 0; i < MAX_BEARERS; i++) {
  1142. if (n_ptr->links[i]) {
  1143. link_print(n_ptr->links[i], "Resetting link\n");
  1144. tipc_link_reset(n_ptr->links[i]);
  1145. }
  1146. }
  1147. tipc_node_unlock(n_ptr);
  1148. read_unlock_bh(&tipc_net_lock);
  1149. }
  1150. static void link_retransmit_failure(struct tipc_link *l_ptr,
  1151. struct sk_buff *buf)
  1152. {
  1153. struct tipc_msg *msg = buf_msg(buf);
  1154. pr_warn("Retransmission failure on link <%s>\n", l_ptr->name);
  1155. if (l_ptr->addr) {
  1156. /* Handle failure on standard link */
  1157. link_print(l_ptr, "Resetting link\n");
  1158. tipc_link_reset(l_ptr);
  1159. } else {
  1160. /* Handle failure on broadcast link */
  1161. struct tipc_node *n_ptr;
  1162. char addr_string[16];
  1163. pr_info("Msg seq number: %u, ", msg_seqno(msg));
  1164. pr_cont("Outstanding acks: %lu\n",
  1165. (unsigned long) TIPC_SKB_CB(buf)->handle);
  1166. n_ptr = tipc_bclink_retransmit_to();
  1167. tipc_node_lock(n_ptr);
  1168. tipc_addr_string_fill(addr_string, n_ptr->addr);
  1169. pr_info("Broadcast link info for %s\n", addr_string);
  1170. pr_info("Reception permitted: %d, Acked: %u\n",
  1171. n_ptr->bclink.recv_permitted,
  1172. n_ptr->bclink.acked);
  1173. pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
  1174. n_ptr->bclink.last_in,
  1175. n_ptr->bclink.oos_state,
  1176. n_ptr->bclink.last_sent);
  1177. tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
  1178. tipc_node_unlock(n_ptr);
  1179. l_ptr->stale_count = 0;
  1180. }
  1181. }
  1182. void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf,
  1183. u32 retransmits)
  1184. {
  1185. struct tipc_msg *msg;
  1186. if (!buf)
  1187. return;
  1188. msg = buf_msg(buf);
  1189. /* Detect repeated retransmit failures */
  1190. if (l_ptr->last_retransmitted == msg_seqno(msg)) {
  1191. if (++l_ptr->stale_count > 100) {
  1192. link_retransmit_failure(l_ptr, buf);
  1193. return;
  1194. }
  1195. } else {
  1196. l_ptr->last_retransmitted = msg_seqno(msg);
  1197. l_ptr->stale_count = 1;
  1198. }
  1199. while (retransmits && (buf != l_ptr->next_out) && buf) {
  1200. msg = buf_msg(buf);
  1201. msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
  1202. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  1203. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  1204. buf = buf->next;
  1205. retransmits--;
  1206. l_ptr->stats.retransmitted++;
  1207. }
  1208. l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
  1209. }
  1210. /**
  1211. * link_insert_deferred_queue - insert deferred messages back into receive chain
  1212. */
  1213. static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr,
  1214. struct sk_buff *buf)
  1215. {
  1216. u32 seq_no;
  1217. if (l_ptr->oldest_deferred_in == NULL)
  1218. return buf;
  1219. seq_no = buf_seqno(l_ptr->oldest_deferred_in);
  1220. if (seq_no == mod(l_ptr->next_in_no)) {
  1221. l_ptr->newest_deferred_in->next = buf;
  1222. buf = l_ptr->oldest_deferred_in;
  1223. l_ptr->oldest_deferred_in = NULL;
  1224. l_ptr->deferred_inqueue_sz = 0;
  1225. }
  1226. return buf;
  1227. }
  1228. /**
  1229. * link_recv_buf_validate - validate basic format of received message
  1230. *
  1231. * This routine ensures a TIPC message has an acceptable header, and at least
  1232. * as much data as the header indicates it should. The routine also ensures
  1233. * that the entire message header is stored in the main fragment of the message
  1234. * buffer, to simplify future access to message header fields.
  1235. *
  1236. * Note: Having extra info present in the message header or data areas is OK.
  1237. * TIPC will ignore the excess, under the assumption that it is optional info
  1238. * introduced by a later release of the protocol.
  1239. */
  1240. static int link_recv_buf_validate(struct sk_buff *buf)
  1241. {
  1242. static u32 min_data_hdr_size[8] = {
  1243. SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE,
  1244. MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
  1245. };
  1246. struct tipc_msg *msg;
  1247. u32 tipc_hdr[2];
  1248. u32 size;
  1249. u32 hdr_size;
  1250. u32 min_hdr_size;
  1251. /* If this packet comes from the defer queue, the skb has already
  1252. * been validated
  1253. */
  1254. if (unlikely(TIPC_SKB_CB(buf)->deferred))
  1255. return 1;
  1256. if (unlikely(buf->len < MIN_H_SIZE))
  1257. return 0;
  1258. msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
  1259. if (msg == NULL)
  1260. return 0;
  1261. if (unlikely(msg_version(msg) != TIPC_VERSION))
  1262. return 0;
  1263. size = msg_size(msg);
  1264. hdr_size = msg_hdr_sz(msg);
  1265. min_hdr_size = msg_isdata(msg) ?
  1266. min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
  1267. if (unlikely((hdr_size < min_hdr_size) ||
  1268. (size < hdr_size) ||
  1269. (buf->len < size) ||
  1270. (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
  1271. return 0;
  1272. return pskb_may_pull(buf, hdr_size);
  1273. }
  1274. /**
  1275. * tipc_rcv - process TIPC packets/messages arriving from off-node
  1276. * @head: pointer to message buffer chain
  1277. * @tb_ptr: pointer to bearer message arrived on
  1278. *
  1279. * Invoked with no locks held. Bearer pointer must point to a valid bearer
  1280. * structure (i.e. cannot be NULL), but bearer can be inactive.
  1281. */
  1282. void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
  1283. {
  1284. read_lock_bh(&tipc_net_lock);
  1285. while (head) {
  1286. struct tipc_node *n_ptr;
  1287. struct tipc_link *l_ptr;
  1288. struct sk_buff *crs;
  1289. struct sk_buff *buf = head;
  1290. struct tipc_msg *msg;
  1291. u32 seq_no;
  1292. u32 ackd;
  1293. u32 released = 0;
  1294. head = head->next;
  1295. buf->next = NULL;
  1296. /* Ensure message is well-formed */
  1297. if (unlikely(!link_recv_buf_validate(buf)))
  1298. goto discard;
  1299. /* Ensure message data is a single contiguous unit */
  1300. if (unlikely(skb_linearize(buf)))
  1301. goto discard;
  1302. /* Handle arrival of a non-unicast link message */
  1303. msg = buf_msg(buf);
  1304. if (unlikely(msg_non_seq(msg))) {
  1305. if (msg_user(msg) == LINK_CONFIG)
  1306. tipc_disc_rcv(buf, b_ptr);
  1307. else
  1308. tipc_bclink_rcv(buf);
  1309. continue;
  1310. }
  1311. /* Discard unicast link messages destined for another node */
  1312. if (unlikely(!msg_short(msg) &&
  1313. (msg_destnode(msg) != tipc_own_addr)))
  1314. goto discard;
  1315. /* Locate neighboring node that sent message */
  1316. n_ptr = tipc_node_find(msg_prevnode(msg));
  1317. if (unlikely(!n_ptr))
  1318. goto discard;
  1319. tipc_node_lock(n_ptr);
  1320. /* Locate unicast link endpoint that should handle message */
  1321. l_ptr = n_ptr->links[b_ptr->identity];
  1322. if (unlikely(!l_ptr))
  1323. goto unlock_discard;
  1324. /* Verify that communication with node is currently allowed */
  1325. if ((n_ptr->block_setup & WAIT_PEER_DOWN) &&
  1326. msg_user(msg) == LINK_PROTOCOL &&
  1327. (msg_type(msg) == RESET_MSG ||
  1328. msg_type(msg) == ACTIVATE_MSG) &&
  1329. !msg_redundant_link(msg))
  1330. n_ptr->block_setup &= ~WAIT_PEER_DOWN;
  1331. if (n_ptr->block_setup)
  1332. goto unlock_discard;
  1333. /* Validate message sequence number info */
  1334. seq_no = msg_seqno(msg);
  1335. ackd = msg_ack(msg);
  1336. /* Release acked messages */
  1337. if (n_ptr->bclink.recv_permitted)
  1338. tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
  1339. crs = l_ptr->first_out;
  1340. while ((crs != l_ptr->next_out) &&
  1341. less_eq(buf_seqno(crs), ackd)) {
  1342. struct sk_buff *next = crs->next;
  1343. kfree_skb(crs);
  1344. crs = next;
  1345. released++;
  1346. }
  1347. if (released) {
  1348. l_ptr->first_out = crs;
  1349. l_ptr->out_queue_size -= released;
  1350. }
  1351. /* Try sending any messages link endpoint has pending */
  1352. if (unlikely(l_ptr->next_out))
  1353. tipc_link_push_queue(l_ptr);
  1354. if (unlikely(!list_empty(&l_ptr->waiting_ports)))
  1355. tipc_link_wakeup_ports(l_ptr, 0);
  1356. if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
  1357. l_ptr->stats.sent_acks++;
  1358. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
  1359. }
  1360. /* Process the incoming packet */
  1361. if (unlikely(!link_working_working(l_ptr))) {
  1362. if (msg_user(msg) == LINK_PROTOCOL) {
  1363. tipc_link_proto_rcv(l_ptr, buf);
  1364. head = link_insert_deferred_queue(l_ptr, head);
  1365. tipc_node_unlock(n_ptr);
  1366. continue;
  1367. }
  1368. /* Traffic message. Conditionally activate link */
  1369. link_state_event(l_ptr, TRAFFIC_MSG_EVT);
  1370. if (link_working_working(l_ptr)) {
  1371. /* Re-insert buffer in front of queue */
  1372. buf->next = head;
  1373. head = buf;
  1374. tipc_node_unlock(n_ptr);
  1375. continue;
  1376. }
  1377. goto unlock_discard;
  1378. }
  1379. /* Link is now in state WORKING_WORKING */
  1380. if (unlikely(seq_no != mod(l_ptr->next_in_no))) {
  1381. link_handle_out_of_seq_msg(l_ptr, buf);
  1382. head = link_insert_deferred_queue(l_ptr, head);
  1383. tipc_node_unlock(n_ptr);
  1384. continue;
  1385. }
  1386. l_ptr->next_in_no++;
  1387. if (unlikely(l_ptr->oldest_deferred_in))
  1388. head = link_insert_deferred_queue(l_ptr, head);
  1389. /* Deliver packet/message to correct user: */
  1390. if (unlikely(msg_user(msg) == CHANGEOVER_PROTOCOL)) {
  1391. if (!tipc_link_tunnel_rcv(n_ptr, &buf)) {
  1392. tipc_node_unlock(n_ptr);
  1393. continue;
  1394. }
  1395. msg = buf_msg(buf);
  1396. } else if (msg_user(msg) == MSG_FRAGMENTER) {
  1397. int rc;
  1398. l_ptr->stats.recv_fragments++;
  1399. rc = tipc_link_frag_rcv(&l_ptr->reasm_head,
  1400. &l_ptr->reasm_tail,
  1401. &buf);
  1402. if (rc == LINK_REASM_COMPLETE) {
  1403. l_ptr->stats.recv_fragmented++;
  1404. msg = buf_msg(buf);
  1405. } else {
  1406. if (rc == LINK_REASM_ERROR)
  1407. tipc_link_reset(l_ptr);
  1408. tipc_node_unlock(n_ptr);
  1409. continue;
  1410. }
  1411. }
  1412. switch (msg_user(msg)) {
  1413. case TIPC_LOW_IMPORTANCE:
  1414. case TIPC_MEDIUM_IMPORTANCE:
  1415. case TIPC_HIGH_IMPORTANCE:
  1416. case TIPC_CRITICAL_IMPORTANCE:
  1417. tipc_node_unlock(n_ptr);
  1418. tipc_port_rcv(buf);
  1419. continue;
  1420. case MSG_BUNDLER:
  1421. l_ptr->stats.recv_bundles++;
  1422. l_ptr->stats.recv_bundled += msg_msgcnt(msg);
  1423. tipc_node_unlock(n_ptr);
  1424. tipc_link_bundle_rcv(buf);
  1425. continue;
  1426. case NAME_DISTRIBUTOR:
  1427. n_ptr->bclink.recv_permitted = true;
  1428. tipc_node_unlock(n_ptr);
  1429. tipc_named_rcv(buf);
  1430. continue;
  1431. case CONN_MANAGER:
  1432. tipc_node_unlock(n_ptr);
  1433. tipc_port_proto_rcv(buf);
  1434. continue;
  1435. case BCAST_PROTOCOL:
  1436. tipc_link_sync_rcv(n_ptr, buf);
  1437. break;
  1438. default:
  1439. kfree_skb(buf);
  1440. break;
  1441. }
  1442. tipc_node_unlock(n_ptr);
  1443. continue;
  1444. unlock_discard:
  1445. tipc_node_unlock(n_ptr);
  1446. discard:
  1447. kfree_skb(buf);
  1448. }
  1449. read_unlock_bh(&tipc_net_lock);
  1450. }
  1451. /**
  1452. * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
  1453. *
  1454. * Returns increase in queue length (i.e. 0 or 1)
  1455. */
  1456. u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail,
  1457. struct sk_buff *buf)
  1458. {
  1459. struct sk_buff *queue_buf;
  1460. struct sk_buff **prev;
  1461. u32 seq_no = buf_seqno(buf);
  1462. buf->next = NULL;
  1463. /* Empty queue ? */
  1464. if (*head == NULL) {
  1465. *head = *tail = buf;
  1466. return 1;
  1467. }
  1468. /* Last ? */
  1469. if (less(buf_seqno(*tail), seq_no)) {
  1470. (*tail)->next = buf;
  1471. *tail = buf;
  1472. return 1;
  1473. }
  1474. /* Locate insertion point in queue, then insert; discard if duplicate */
  1475. prev = head;
  1476. queue_buf = *head;
  1477. for (;;) {
  1478. u32 curr_seqno = buf_seqno(queue_buf);
  1479. if (seq_no == curr_seqno) {
  1480. kfree_skb(buf);
  1481. return 0;
  1482. }
  1483. if (less(seq_no, curr_seqno))
  1484. break;
  1485. prev = &queue_buf->next;
  1486. queue_buf = queue_buf->next;
  1487. }
  1488. buf->next = queue_buf;
  1489. *prev = buf;
  1490. return 1;
  1491. }
  1492. /*
  1493. * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
  1494. */
  1495. static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
  1496. struct sk_buff *buf)
  1497. {
  1498. u32 seq_no = buf_seqno(buf);
  1499. if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
  1500. tipc_link_proto_rcv(l_ptr, buf);
  1501. return;
  1502. }
  1503. /* Record OOS packet arrival (force mismatch on next timeout) */
  1504. l_ptr->checkpoint--;
  1505. /*
  1506. * Discard packet if a duplicate; otherwise add it to deferred queue
  1507. * and notify peer of gap as per protocol specification
  1508. */
  1509. if (less(seq_no, mod(l_ptr->next_in_no))) {
  1510. l_ptr->stats.duplicates++;
  1511. kfree_skb(buf);
  1512. return;
  1513. }
  1514. if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
  1515. &l_ptr->newest_deferred_in, buf)) {
  1516. l_ptr->deferred_inqueue_sz++;
  1517. l_ptr->stats.deferred_recv++;
  1518. TIPC_SKB_CB(buf)->deferred = true;
  1519. if ((l_ptr->deferred_inqueue_sz % 16) == 1)
  1520. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
  1521. } else
  1522. l_ptr->stats.duplicates++;
  1523. }
  1524. /*
  1525. * Send protocol message to the other endpoint.
  1526. */
  1527. void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
  1528. u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
  1529. {
  1530. struct sk_buff *buf = NULL;
  1531. struct tipc_msg *msg = l_ptr->pmsg;
  1532. u32 msg_size = sizeof(l_ptr->proto_msg);
  1533. int r_flag;
  1534. /* Discard any previous message that was deferred due to congestion */
  1535. if (l_ptr->proto_msg_queue) {
  1536. kfree_skb(l_ptr->proto_msg_queue);
  1537. l_ptr->proto_msg_queue = NULL;
  1538. }
  1539. /* Don't send protocol message during link changeover */
  1540. if (l_ptr->exp_msg_count)
  1541. return;
  1542. /* Abort non-RESET send if communication with node is prohibited */
  1543. if ((l_ptr->owner->block_setup) && (msg_typ != RESET_MSG))
  1544. return;
  1545. /* Create protocol message with "out-of-sequence" sequence number */
  1546. msg_set_type(msg, msg_typ);
  1547. msg_set_net_plane(msg, l_ptr->b_ptr->net_plane);
  1548. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  1549. msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
  1550. if (msg_typ == STATE_MSG) {
  1551. u32 next_sent = mod(l_ptr->next_out_no);
  1552. if (!tipc_link_is_up(l_ptr))
  1553. return;
  1554. if (l_ptr->next_out)
  1555. next_sent = buf_seqno(l_ptr->next_out);
  1556. msg_set_next_sent(msg, next_sent);
  1557. if (l_ptr->oldest_deferred_in) {
  1558. u32 rec = buf_seqno(l_ptr->oldest_deferred_in);
  1559. gap = mod(rec - mod(l_ptr->next_in_no));
  1560. }
  1561. msg_set_seq_gap(msg, gap);
  1562. if (gap)
  1563. l_ptr->stats.sent_nacks++;
  1564. msg_set_link_tolerance(msg, tolerance);
  1565. msg_set_linkprio(msg, priority);
  1566. msg_set_max_pkt(msg, ack_mtu);
  1567. msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
  1568. msg_set_probe(msg, probe_msg != 0);
  1569. if (probe_msg) {
  1570. u32 mtu = l_ptr->max_pkt;
  1571. if ((mtu < l_ptr->max_pkt_target) &&
  1572. link_working_working(l_ptr) &&
  1573. l_ptr->fsm_msg_cnt) {
  1574. msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
  1575. if (l_ptr->max_pkt_probes == 10) {
  1576. l_ptr->max_pkt_target = (msg_size - 4);
  1577. l_ptr->max_pkt_probes = 0;
  1578. msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
  1579. }
  1580. l_ptr->max_pkt_probes++;
  1581. }
  1582. l_ptr->stats.sent_probes++;
  1583. }
  1584. l_ptr->stats.sent_states++;
  1585. } else { /* RESET_MSG or ACTIVATE_MSG */
  1586. msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
  1587. msg_set_seq_gap(msg, 0);
  1588. msg_set_next_sent(msg, 1);
  1589. msg_set_probe(msg, 0);
  1590. msg_set_link_tolerance(msg, l_ptr->tolerance);
  1591. msg_set_linkprio(msg, l_ptr->priority);
  1592. msg_set_max_pkt(msg, l_ptr->max_pkt_target);
  1593. }
  1594. r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
  1595. msg_set_redundant_link(msg, r_flag);
  1596. msg_set_linkprio(msg, l_ptr->priority);
  1597. msg_set_size(msg, msg_size);
  1598. msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
  1599. buf = tipc_buf_acquire(msg_size);
  1600. if (!buf)
  1601. return;
  1602. skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
  1603. buf->priority = TC_PRIO_CONTROL;
  1604. tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
  1605. l_ptr->unacked_window = 0;
  1606. kfree_skb(buf);
  1607. }
  1608. /*
  1609. * Receive protocol message :
  1610. * Note that network plane id propagates through the network, and may
  1611. * change at any time. The node with lowest address rules
  1612. */
  1613. static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf)
  1614. {
  1615. u32 rec_gap = 0;
  1616. u32 max_pkt_info;
  1617. u32 max_pkt_ack;
  1618. u32 msg_tol;
  1619. struct tipc_msg *msg = buf_msg(buf);
  1620. /* Discard protocol message during link changeover */
  1621. if (l_ptr->exp_msg_count)
  1622. goto exit;
  1623. /* record unnumbered packet arrival (force mismatch on next timeout) */
  1624. l_ptr->checkpoint--;
  1625. if (l_ptr->b_ptr->net_plane != msg_net_plane(msg))
  1626. if (tipc_own_addr > msg_prevnode(msg))
  1627. l_ptr->b_ptr->net_plane = msg_net_plane(msg);
  1628. switch (msg_type(msg)) {
  1629. case RESET_MSG:
  1630. if (!link_working_unknown(l_ptr) &&
  1631. (l_ptr->peer_session != INVALID_SESSION)) {
  1632. if (less_eq(msg_session(msg), l_ptr->peer_session))
  1633. break; /* duplicate or old reset: ignore */
  1634. }
  1635. if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
  1636. link_working_unknown(l_ptr))) {
  1637. /*
  1638. * peer has lost contact -- don't allow peer's links
  1639. * to reactivate before we recognize loss & clean up
  1640. */
  1641. l_ptr->owner->block_setup = WAIT_NODE_DOWN;
  1642. }
  1643. link_state_event(l_ptr, RESET_MSG);
  1644. /* fall thru' */
  1645. case ACTIVATE_MSG:
  1646. /* Update link settings according other endpoint's values */
  1647. strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
  1648. msg_tol = msg_link_tolerance(msg);
  1649. if (msg_tol > l_ptr->tolerance)
  1650. link_set_supervision_props(l_ptr, msg_tol);
  1651. if (msg_linkprio(msg) > l_ptr->priority)
  1652. l_ptr->priority = msg_linkprio(msg);
  1653. max_pkt_info = msg_max_pkt(msg);
  1654. if (max_pkt_info) {
  1655. if (max_pkt_info < l_ptr->max_pkt_target)
  1656. l_ptr->max_pkt_target = max_pkt_info;
  1657. if (l_ptr->max_pkt > l_ptr->max_pkt_target)
  1658. l_ptr->max_pkt = l_ptr->max_pkt_target;
  1659. } else {
  1660. l_ptr->max_pkt = l_ptr->max_pkt_target;
  1661. }
  1662. /* Synchronize broadcast link info, if not done previously */
  1663. if (!tipc_node_is_up(l_ptr->owner)) {
  1664. l_ptr->owner->bclink.last_sent =
  1665. l_ptr->owner->bclink.last_in =
  1666. msg_last_bcast(msg);
  1667. l_ptr->owner->bclink.oos_state = 0;
  1668. }
  1669. l_ptr->peer_session = msg_session(msg);
  1670. l_ptr->peer_bearer_id = msg_bearer_id(msg);
  1671. if (msg_type(msg) == ACTIVATE_MSG)
  1672. link_state_event(l_ptr, ACTIVATE_MSG);
  1673. break;
  1674. case STATE_MSG:
  1675. msg_tol = msg_link_tolerance(msg);
  1676. if (msg_tol)
  1677. link_set_supervision_props(l_ptr, msg_tol);
  1678. if (msg_linkprio(msg) &&
  1679. (msg_linkprio(msg) != l_ptr->priority)) {
  1680. pr_warn("%s<%s>, priority change %u->%u\n",
  1681. link_rst_msg, l_ptr->name, l_ptr->priority,
  1682. msg_linkprio(msg));
  1683. l_ptr->priority = msg_linkprio(msg);
  1684. tipc_link_reset(l_ptr); /* Enforce change to take effect */
  1685. break;
  1686. }
  1687. link_state_event(l_ptr, TRAFFIC_MSG_EVT);
  1688. l_ptr->stats.recv_states++;
  1689. if (link_reset_unknown(l_ptr))
  1690. break;
  1691. if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
  1692. rec_gap = mod(msg_next_sent(msg) -
  1693. mod(l_ptr->next_in_no));
  1694. }
  1695. max_pkt_ack = msg_max_pkt(msg);
  1696. if (max_pkt_ack > l_ptr->max_pkt) {
  1697. l_ptr->max_pkt = max_pkt_ack;
  1698. l_ptr->max_pkt_probes = 0;
  1699. }
  1700. max_pkt_ack = 0;
  1701. if (msg_probe(msg)) {
  1702. l_ptr->stats.recv_probes++;
  1703. if (msg_size(msg) > sizeof(l_ptr->proto_msg))
  1704. max_pkt_ack = msg_size(msg);
  1705. }
  1706. /* Protocol message before retransmits, reduce loss risk */
  1707. if (l_ptr->owner->bclink.recv_permitted)
  1708. tipc_bclink_update_link_state(l_ptr->owner,
  1709. msg_last_bcast(msg));
  1710. if (rec_gap || (msg_probe(msg))) {
  1711. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, rec_gap, 0,
  1712. 0, max_pkt_ack);
  1713. }
  1714. if (msg_seq_gap(msg)) {
  1715. l_ptr->stats.recv_nacks++;
  1716. tipc_link_retransmit(l_ptr, l_ptr->first_out,
  1717. msg_seq_gap(msg));
  1718. }
  1719. break;
  1720. }
  1721. exit:
  1722. kfree_skb(buf);
  1723. }
  1724. /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
  1725. * a different bearer. Owner node is locked.
  1726. */
  1727. static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
  1728. struct tipc_msg *tunnel_hdr,
  1729. struct tipc_msg *msg,
  1730. u32 selector)
  1731. {
  1732. struct tipc_link *tunnel;
  1733. struct sk_buff *buf;
  1734. u32 length = msg_size(msg);
  1735. tunnel = l_ptr->owner->active_links[selector & 1];
  1736. if (!tipc_link_is_up(tunnel)) {
  1737. pr_warn("%stunnel link no longer available\n", link_co_err);
  1738. return;
  1739. }
  1740. msg_set_size(tunnel_hdr, length + INT_H_SIZE);
  1741. buf = tipc_buf_acquire(length + INT_H_SIZE);
  1742. if (!buf) {
  1743. pr_warn("%sunable to send tunnel msg\n", link_co_err);
  1744. return;
  1745. }
  1746. skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
  1747. skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
  1748. __tipc_link_xmit(tunnel, buf);
  1749. }
  1750. /* tipc_link_failover_send_queue(): A link has gone down, but a second
  1751. * link is still active. We can do failover. Tunnel the failing link's
  1752. * whole send queue via the remaining link. This way, we don't lose
  1753. * any packets, and sequence order is preserved for subsequent traffic
  1754. * sent over the remaining link. Owner node is locked.
  1755. */
  1756. void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
  1757. {
  1758. u32 msgcount = l_ptr->out_queue_size;
  1759. struct sk_buff *crs = l_ptr->first_out;
  1760. struct tipc_link *tunnel = l_ptr->owner->active_links[0];
  1761. struct tipc_msg tunnel_hdr;
  1762. int split_bundles;
  1763. if (!tunnel)
  1764. return;
  1765. tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
  1766. ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
  1767. msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
  1768. msg_set_msgcnt(&tunnel_hdr, msgcount);
  1769. if (!l_ptr->first_out) {
  1770. struct sk_buff *buf;
  1771. buf = tipc_buf_acquire(INT_H_SIZE);
  1772. if (buf) {
  1773. skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
  1774. msg_set_size(&tunnel_hdr, INT_H_SIZE);
  1775. __tipc_link_xmit(tunnel, buf);
  1776. } else {
  1777. pr_warn("%sunable to send changeover msg\n",
  1778. link_co_err);
  1779. }
  1780. return;
  1781. }
  1782. split_bundles = (l_ptr->owner->active_links[0] !=
  1783. l_ptr->owner->active_links[1]);
  1784. while (crs) {
  1785. struct tipc_msg *msg = buf_msg(crs);
  1786. if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
  1787. struct tipc_msg *m = msg_get_wrapped(msg);
  1788. unchar *pos = (unchar *)m;
  1789. msgcount = msg_msgcnt(msg);
  1790. while (msgcount--) {
  1791. msg_set_seqno(m, msg_seqno(msg));
  1792. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m,
  1793. msg_link_selector(m));
  1794. pos += align(msg_size(m));
  1795. m = (struct tipc_msg *)pos;
  1796. }
  1797. } else {
  1798. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg,
  1799. msg_link_selector(msg));
  1800. }
  1801. crs = crs->next;
  1802. }
  1803. }
  1804. /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
  1805. * duplicate of the first link's send queue via the new link. This way, we
  1806. * are guaranteed that currently queued packets from a socket are delivered
  1807. * before future traffic from the same socket, even if this is using the
  1808. * new link. The last arriving copy of each duplicate packet is dropped at
  1809. * the receiving end by the regular protocol check, so packet cardinality
  1810. * and sequence order is preserved per sender/receiver socket pair.
  1811. * Owner node is locked.
  1812. */
  1813. void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr,
  1814. struct tipc_link *tunnel)
  1815. {
  1816. struct sk_buff *iter;
  1817. struct tipc_msg tunnel_hdr;
  1818. tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
  1819. DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
  1820. msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
  1821. msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
  1822. iter = l_ptr->first_out;
  1823. while (iter) {
  1824. struct sk_buff *outbuf;
  1825. struct tipc_msg *msg = buf_msg(iter);
  1826. u32 length = msg_size(msg);
  1827. if (msg_user(msg) == MSG_BUNDLER)
  1828. msg_set_type(msg, CLOSED_MSG);
  1829. msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
  1830. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  1831. msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
  1832. outbuf = tipc_buf_acquire(length + INT_H_SIZE);
  1833. if (outbuf == NULL) {
  1834. pr_warn("%sunable to send duplicate msg\n",
  1835. link_co_err);
  1836. return;
  1837. }
  1838. skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
  1839. skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
  1840. length);
  1841. __tipc_link_xmit(tunnel, outbuf);
  1842. if (!tipc_link_is_up(l_ptr))
  1843. return;
  1844. iter = iter->next;
  1845. }
  1846. }
  1847. /**
  1848. * buf_extract - extracts embedded TIPC message from another message
  1849. * @skb: encapsulating message buffer
  1850. * @from_pos: offset to extract from
  1851. *
  1852. * Returns a new message buffer containing an embedded message. The
  1853. * encapsulating message itself is left unchanged.
  1854. */
  1855. static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
  1856. {
  1857. struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
  1858. u32 size = msg_size(msg);
  1859. struct sk_buff *eb;
  1860. eb = tipc_buf_acquire(size);
  1861. if (eb)
  1862. skb_copy_to_linear_data(eb, msg, size);
  1863. return eb;
  1864. }
  1865. /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet.
  1866. * Owner node is locked.
  1867. */
  1868. static void tipc_link_dup_rcv(struct tipc_link *l_ptr,
  1869. struct sk_buff *t_buf)
  1870. {
  1871. struct sk_buff *buf;
  1872. if (!tipc_link_is_up(l_ptr))
  1873. return;
  1874. buf = buf_extract(t_buf, INT_H_SIZE);
  1875. if (buf == NULL) {
  1876. pr_warn("%sfailed to extract inner dup pkt\n", link_co_err);
  1877. return;
  1878. }
  1879. /* Add buffer to deferred queue, if applicable: */
  1880. link_handle_out_of_seq_msg(l_ptr, buf);
  1881. }
  1882. /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet
  1883. * Owner node is locked.
  1884. */
  1885. static struct sk_buff *tipc_link_failover_rcv(struct tipc_link *l_ptr,
  1886. struct sk_buff *t_buf)
  1887. {
  1888. struct tipc_msg *t_msg = buf_msg(t_buf);
  1889. struct sk_buff *buf = NULL;
  1890. struct tipc_msg *msg;
  1891. if (tipc_link_is_up(l_ptr))
  1892. tipc_link_reset(l_ptr);
  1893. /* First failover packet? */
  1894. if (l_ptr->exp_msg_count == START_CHANGEOVER)
  1895. l_ptr->exp_msg_count = msg_msgcnt(t_msg);
  1896. /* Should there be an inner packet? */
  1897. if (l_ptr->exp_msg_count) {
  1898. l_ptr->exp_msg_count--;
  1899. buf = buf_extract(t_buf, INT_H_SIZE);
  1900. if (buf == NULL) {
  1901. pr_warn("%sno inner failover pkt\n", link_co_err);
  1902. goto exit;
  1903. }
  1904. msg = buf_msg(buf);
  1905. if (less(msg_seqno(msg), l_ptr->reset_checkpoint)) {
  1906. kfree_skb(buf);
  1907. buf = NULL;
  1908. goto exit;
  1909. }
  1910. if (msg_user(msg) == MSG_FRAGMENTER) {
  1911. l_ptr->stats.recv_fragments++;
  1912. tipc_link_frag_rcv(&l_ptr->reasm_head,
  1913. &l_ptr->reasm_tail,
  1914. &buf);
  1915. }
  1916. }
  1917. exit:
  1918. if ((l_ptr->exp_msg_count == 0) && (l_ptr->flags & LINK_STOPPED)) {
  1919. tipc_node_detach_link(l_ptr->owner, l_ptr);
  1920. kfree(l_ptr);
  1921. }
  1922. return buf;
  1923. }
  1924. /* tipc_link_tunnel_rcv(): Receive a tunnelled packet, sent
  1925. * via other link as result of a failover (ORIGINAL_MSG) or
  1926. * a new active link (DUPLICATE_MSG). Failover packets are
  1927. * returned to the active link for delivery upwards.
  1928. * Owner node is locked.
  1929. */
  1930. static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr,
  1931. struct sk_buff **buf)
  1932. {
  1933. struct sk_buff *t_buf = *buf;
  1934. struct tipc_link *l_ptr;
  1935. struct tipc_msg *t_msg = buf_msg(t_buf);
  1936. u32 bearer_id = msg_bearer_id(t_msg);
  1937. *buf = NULL;
  1938. if (bearer_id >= MAX_BEARERS)
  1939. goto exit;
  1940. l_ptr = n_ptr->links[bearer_id];
  1941. if (!l_ptr)
  1942. goto exit;
  1943. if (msg_type(t_msg) == DUPLICATE_MSG)
  1944. tipc_link_dup_rcv(l_ptr, t_buf);
  1945. else if (msg_type(t_msg) == ORIGINAL_MSG)
  1946. *buf = tipc_link_failover_rcv(l_ptr, t_buf);
  1947. else
  1948. pr_warn("%sunknown tunnel pkt received\n", link_co_err);
  1949. exit:
  1950. kfree_skb(t_buf);
  1951. return *buf != NULL;
  1952. }
  1953. /*
  1954. * Bundler functionality:
  1955. */
  1956. void tipc_link_bundle_rcv(struct sk_buff *buf)
  1957. {
  1958. u32 msgcount = msg_msgcnt(buf_msg(buf));
  1959. u32 pos = INT_H_SIZE;
  1960. struct sk_buff *obuf;
  1961. while (msgcount--) {
  1962. obuf = buf_extract(buf, pos);
  1963. if (obuf == NULL) {
  1964. pr_warn("Link unable to unbundle message(s)\n");
  1965. break;
  1966. }
  1967. pos += align(msg_size(buf_msg(obuf)));
  1968. tipc_net_route_msg(obuf);
  1969. }
  1970. kfree_skb(buf);
  1971. }
  1972. /*
  1973. * Fragmentation/defragmentation:
  1974. */
  1975. /*
  1976. * tipc_link_frag_xmit: Entry for buffers needing fragmentation.
  1977. * The buffer is complete, inclusive total message length.
  1978. * Returns user data length.
  1979. */
  1980. static int tipc_link_frag_xmit(struct tipc_link *l_ptr, struct sk_buff *buf)
  1981. {
  1982. struct sk_buff *buf_chain = NULL;
  1983. struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain;
  1984. struct tipc_msg *inmsg = buf_msg(buf);
  1985. struct tipc_msg fragm_hdr;
  1986. u32 insize = msg_size(inmsg);
  1987. u32 dsz = msg_data_sz(inmsg);
  1988. unchar *crs = buf->data;
  1989. u32 rest = insize;
  1990. u32 pack_sz = l_ptr->max_pkt;
  1991. u32 fragm_sz = pack_sz - INT_H_SIZE;
  1992. u32 fragm_no = 0;
  1993. u32 destaddr;
  1994. if (msg_short(inmsg))
  1995. destaddr = l_ptr->addr;
  1996. else
  1997. destaddr = msg_destnode(inmsg);
  1998. /* Prepare reusable fragment header: */
  1999. tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
  2000. INT_H_SIZE, destaddr);
  2001. /* Chop up message: */
  2002. while (rest > 0) {
  2003. struct sk_buff *fragm;
  2004. if (rest <= fragm_sz) {
  2005. fragm_sz = rest;
  2006. msg_set_type(&fragm_hdr, LAST_FRAGMENT);
  2007. }
  2008. fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
  2009. if (fragm == NULL) {
  2010. kfree_skb(buf);
  2011. kfree_skb_list(buf_chain);
  2012. return -ENOMEM;
  2013. }
  2014. msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
  2015. fragm_no++;
  2016. msg_set_fragm_no(&fragm_hdr, fragm_no);
  2017. skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE);
  2018. skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs,
  2019. fragm_sz);
  2020. buf_chain_tail->next = fragm;
  2021. buf_chain_tail = fragm;
  2022. rest -= fragm_sz;
  2023. crs += fragm_sz;
  2024. msg_set_type(&fragm_hdr, FRAGMENT);
  2025. }
  2026. kfree_skb(buf);
  2027. /* Append chain of fragments to send queue & send them */
  2028. l_ptr->long_msg_seq_no++;
  2029. link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no);
  2030. l_ptr->stats.sent_fragments += fragm_no;
  2031. l_ptr->stats.sent_fragmented++;
  2032. tipc_link_push_queue(l_ptr);
  2033. return dsz;
  2034. }
  2035. /* tipc_link_frag_rcv(): Called with node lock on. Returns
  2036. * the reassembled buffer if message is complete.
  2037. */
  2038. int tipc_link_frag_rcv(struct sk_buff **head, struct sk_buff **tail,
  2039. struct sk_buff **fbuf)
  2040. {
  2041. struct sk_buff *frag = *fbuf;
  2042. struct tipc_msg *msg = buf_msg(frag);
  2043. u32 fragid = msg_type(msg);
  2044. bool headstolen;
  2045. int delta;
  2046. skb_pull(frag, msg_hdr_sz(msg));
  2047. if (fragid == FIRST_FRAGMENT) {
  2048. if (*head || skb_unclone(frag, GFP_ATOMIC))
  2049. goto out_free;
  2050. *head = frag;
  2051. skb_frag_list_init(*head);
  2052. *fbuf = NULL;
  2053. return 0;
  2054. } else if (*head &&
  2055. skb_try_coalesce(*head, frag, &headstolen, &delta)) {
  2056. kfree_skb_partial(frag, headstolen);
  2057. } else {
  2058. if (!*head)
  2059. goto out_free;
  2060. if (!skb_has_frag_list(*head))
  2061. skb_shinfo(*head)->frag_list = frag;
  2062. else
  2063. (*tail)->next = frag;
  2064. *tail = frag;
  2065. (*head)->truesize += frag->truesize;
  2066. }
  2067. if (fragid == LAST_FRAGMENT) {
  2068. *fbuf = *head;
  2069. *tail = *head = NULL;
  2070. return LINK_REASM_COMPLETE;
  2071. }
  2072. *fbuf = NULL;
  2073. return 0;
  2074. out_free:
  2075. pr_warn_ratelimited("Link unable to reassemble fragmented message\n");
  2076. kfree_skb(*fbuf);
  2077. *fbuf = NULL;
  2078. return LINK_REASM_ERROR;
  2079. }
  2080. static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance)
  2081. {
  2082. if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL))
  2083. return;
  2084. l_ptr->tolerance = tolerance;
  2085. l_ptr->continuity_interval =
  2086. ((tolerance / 4) > 500) ? 500 : tolerance / 4;
  2087. l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
  2088. }
  2089. void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)
  2090. {
  2091. /* Data messages from this node, inclusive FIRST_FRAGM */
  2092. l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
  2093. l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
  2094. l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
  2095. l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
  2096. /* Transiting data messages,inclusive FIRST_FRAGM */
  2097. l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
  2098. l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
  2099. l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
  2100. l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
  2101. l_ptr->queue_limit[CONN_MANAGER] = 1200;
  2102. l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
  2103. l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
  2104. /* FRAGMENT and LAST_FRAGMENT packets */
  2105. l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
  2106. }
  2107. /* tipc_link_find_owner - locate owner node of link by link's name
  2108. * @name: pointer to link name string
  2109. * @bearer_id: pointer to index in 'node->links' array where the link was found.
  2110. * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
  2111. * this also prevents link deletion.
  2112. *
  2113. * Returns pointer to node owning the link, or 0 if no matching link is found.
  2114. */
  2115. static struct tipc_node *tipc_link_find_owner(const char *link_name,
  2116. unsigned int *bearer_id)
  2117. {
  2118. struct tipc_link *l_ptr;
  2119. struct tipc_node *n_ptr;
  2120. struct tipc_node *found_node = 0;
  2121. int i;
  2122. *bearer_id = 0;
  2123. rcu_read_lock();
  2124. list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) {
  2125. tipc_node_lock(n_ptr);
  2126. for (i = 0; i < MAX_BEARERS; i++) {
  2127. l_ptr = n_ptr->links[i];
  2128. if (l_ptr && !strcmp(l_ptr->name, link_name)) {
  2129. *bearer_id = i;
  2130. found_node = n_ptr;
  2131. break;
  2132. }
  2133. }
  2134. tipc_node_unlock(n_ptr);
  2135. if (found_node)
  2136. break;
  2137. }
  2138. rcu_read_unlock();
  2139. return found_node;
  2140. }
  2141. /**
  2142. * link_value_is_valid -- validate proposed link tolerance/priority/window
  2143. *
  2144. * @cmd: value type (TIPC_CMD_SET_LINK_*)
  2145. * @new_value: the new value
  2146. *
  2147. * Returns 1 if value is within range, 0 if not.
  2148. */
  2149. static int link_value_is_valid(u16 cmd, u32 new_value)
  2150. {
  2151. switch (cmd) {
  2152. case TIPC_CMD_SET_LINK_TOL:
  2153. return (new_value >= TIPC_MIN_LINK_TOL) &&
  2154. (new_value <= TIPC_MAX_LINK_TOL);
  2155. case TIPC_CMD_SET_LINK_PRI:
  2156. return (new_value <= TIPC_MAX_LINK_PRI);
  2157. case TIPC_CMD_SET_LINK_WINDOW:
  2158. return (new_value >= TIPC_MIN_LINK_WIN) &&
  2159. (new_value <= TIPC_MAX_LINK_WIN);
  2160. }
  2161. return 0;
  2162. }
  2163. /**
  2164. * link_cmd_set_value - change priority/tolerance/window for link/bearer/media
  2165. * @name: ptr to link, bearer, or media name
  2166. * @new_value: new value of link, bearer, or media setting
  2167. * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
  2168. *
  2169. * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted.
  2170. *
  2171. * Returns 0 if value updated and negative value on error.
  2172. */
  2173. static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)
  2174. {
  2175. struct tipc_node *node;
  2176. struct tipc_link *l_ptr;
  2177. struct tipc_bearer *b_ptr;
  2178. struct tipc_media *m_ptr;
  2179. int bearer_id;
  2180. int res = 0;
  2181. node = tipc_link_find_owner(name, &bearer_id);
  2182. if (node) {
  2183. tipc_node_lock(node);
  2184. l_ptr = node->links[bearer_id];
  2185. if (l_ptr) {
  2186. switch (cmd) {
  2187. case TIPC_CMD_SET_LINK_TOL:
  2188. link_set_supervision_props(l_ptr, new_value);
  2189. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
  2190. new_value, 0, 0);
  2191. break;
  2192. case TIPC_CMD_SET_LINK_PRI:
  2193. l_ptr->priority = new_value;
  2194. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0,
  2195. 0, new_value, 0);
  2196. break;
  2197. case TIPC_CMD_SET_LINK_WINDOW:
  2198. tipc_link_set_queue_limits(l_ptr, new_value);
  2199. break;
  2200. default:
  2201. res = -EINVAL;
  2202. break;
  2203. }
  2204. }
  2205. tipc_node_unlock(node);
  2206. return res;
  2207. }
  2208. b_ptr = tipc_bearer_find(name);
  2209. if (b_ptr) {
  2210. switch (cmd) {
  2211. case TIPC_CMD_SET_LINK_TOL:
  2212. b_ptr->tolerance = new_value;
  2213. break;
  2214. case TIPC_CMD_SET_LINK_PRI:
  2215. b_ptr->priority = new_value;
  2216. break;
  2217. case TIPC_CMD_SET_LINK_WINDOW:
  2218. b_ptr->window = new_value;
  2219. break;
  2220. default:
  2221. res = -EINVAL;
  2222. break;
  2223. }
  2224. return res;
  2225. }
  2226. m_ptr = tipc_media_find(name);
  2227. if (!m_ptr)
  2228. return -ENODEV;
  2229. switch (cmd) {
  2230. case TIPC_CMD_SET_LINK_TOL:
  2231. m_ptr->tolerance = new_value;
  2232. break;
  2233. case TIPC_CMD_SET_LINK_PRI:
  2234. m_ptr->priority = new_value;
  2235. break;
  2236. case TIPC_CMD_SET_LINK_WINDOW:
  2237. m_ptr->window = new_value;
  2238. break;
  2239. default:
  2240. res = -EINVAL;
  2241. break;
  2242. }
  2243. return res;
  2244. }
  2245. struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
  2246. u16 cmd)
  2247. {
  2248. struct tipc_link_config *args;
  2249. u32 new_value;
  2250. int res;
  2251. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
  2252. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  2253. args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
  2254. new_value = ntohl(args->value);
  2255. if (!link_value_is_valid(cmd, new_value))
  2256. return tipc_cfg_reply_error_string(
  2257. "cannot change, value invalid");
  2258. if (!strcmp(args->name, tipc_bclink_name)) {
  2259. if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
  2260. (tipc_bclink_set_queue_limits(new_value) == 0))
  2261. return tipc_cfg_reply_none();
  2262. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  2263. " (cannot change setting on broadcast link)");
  2264. }
  2265. read_lock_bh(&tipc_net_lock);
  2266. res = link_cmd_set_value(args->name, new_value, cmd);
  2267. read_unlock_bh(&tipc_net_lock);
  2268. if (res)
  2269. return tipc_cfg_reply_error_string("cannot change link setting");
  2270. return tipc_cfg_reply_none();
  2271. }
  2272. /**
  2273. * link_reset_statistics - reset link statistics
  2274. * @l_ptr: pointer to link
  2275. */
  2276. static void link_reset_statistics(struct tipc_link *l_ptr)
  2277. {
  2278. memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
  2279. l_ptr->stats.sent_info = l_ptr->next_out_no;
  2280. l_ptr->stats.recv_info = l_ptr->next_in_no;
  2281. }
  2282. struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
  2283. {
  2284. char *link_name;
  2285. struct tipc_link *l_ptr;
  2286. struct tipc_node *node;
  2287. unsigned int bearer_id;
  2288. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
  2289. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  2290. link_name = (char *)TLV_DATA(req_tlv_area);
  2291. if (!strcmp(link_name, tipc_bclink_name)) {
  2292. if (tipc_bclink_reset_stats())
  2293. return tipc_cfg_reply_error_string("link not found");
  2294. return tipc_cfg_reply_none();
  2295. }
  2296. read_lock_bh(&tipc_net_lock);
  2297. node = tipc_link_find_owner(link_name, &bearer_id);
  2298. if (!node) {
  2299. read_unlock_bh(&tipc_net_lock);
  2300. return tipc_cfg_reply_error_string("link not found");
  2301. }
  2302. tipc_node_lock(node);
  2303. l_ptr = node->links[bearer_id];
  2304. if (!l_ptr) {
  2305. tipc_node_unlock(node);
  2306. read_unlock_bh(&tipc_net_lock);
  2307. return tipc_cfg_reply_error_string("link not found");
  2308. }
  2309. link_reset_statistics(l_ptr);
  2310. tipc_node_unlock(node);
  2311. read_unlock_bh(&tipc_net_lock);
  2312. return tipc_cfg_reply_none();
  2313. }
  2314. /**
  2315. * percent - convert count to a percentage of total (rounding up or down)
  2316. */
  2317. static u32 percent(u32 count, u32 total)
  2318. {
  2319. return (count * 100 + (total / 2)) / total;
  2320. }
  2321. /**
  2322. * tipc_link_stats - print link statistics
  2323. * @name: link name
  2324. * @buf: print buffer area
  2325. * @buf_size: size of print buffer area
  2326. *
  2327. * Returns length of print buffer data string (or 0 if error)
  2328. */
  2329. static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
  2330. {
  2331. struct tipc_link *l;
  2332. struct tipc_stats *s;
  2333. struct tipc_node *node;
  2334. char *status;
  2335. u32 profile_total = 0;
  2336. unsigned int bearer_id;
  2337. int ret;
  2338. if (!strcmp(name, tipc_bclink_name))
  2339. return tipc_bclink_stats(buf, buf_size);
  2340. read_lock_bh(&tipc_net_lock);
  2341. node = tipc_link_find_owner(name, &bearer_id);
  2342. if (!node) {
  2343. read_unlock_bh(&tipc_net_lock);
  2344. return 0;
  2345. }
  2346. tipc_node_lock(node);
  2347. l = node->links[bearer_id];
  2348. if (!l) {
  2349. tipc_node_unlock(node);
  2350. read_unlock_bh(&tipc_net_lock);
  2351. return 0;
  2352. }
  2353. s = &l->stats;
  2354. if (tipc_link_is_active(l))
  2355. status = "ACTIVE";
  2356. else if (tipc_link_is_up(l))
  2357. status = "STANDBY";
  2358. else
  2359. status = "DEFUNCT";
  2360. ret = tipc_snprintf(buf, buf_size, "Link <%s>\n"
  2361. " %s MTU:%u Priority:%u Tolerance:%u ms"
  2362. " Window:%u packets\n",
  2363. l->name, status, l->max_pkt, l->priority,
  2364. l->tolerance, l->queue_limit[0]);
  2365. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2366. " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
  2367. l->next_in_no - s->recv_info, s->recv_fragments,
  2368. s->recv_fragmented, s->recv_bundles,
  2369. s->recv_bundled);
  2370. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2371. " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
  2372. l->next_out_no - s->sent_info, s->sent_fragments,
  2373. s->sent_fragmented, s->sent_bundles,
  2374. s->sent_bundled);
  2375. profile_total = s->msg_length_counts;
  2376. if (!profile_total)
  2377. profile_total = 1;
  2378. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2379. " TX profile sample:%u packets average:%u octets\n"
  2380. " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
  2381. "-16384:%u%% -32768:%u%% -66000:%u%%\n",
  2382. s->msg_length_counts,
  2383. s->msg_lengths_total / profile_total,
  2384. percent(s->msg_length_profile[0], profile_total),
  2385. percent(s->msg_length_profile[1], profile_total),
  2386. percent(s->msg_length_profile[2], profile_total),
  2387. percent(s->msg_length_profile[3], profile_total),
  2388. percent(s->msg_length_profile[4], profile_total),
  2389. percent(s->msg_length_profile[5], profile_total),
  2390. percent(s->msg_length_profile[6], profile_total));
  2391. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2392. " RX states:%u probes:%u naks:%u defs:%u"
  2393. " dups:%u\n", s->recv_states, s->recv_probes,
  2394. s->recv_nacks, s->deferred_recv, s->duplicates);
  2395. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2396. " TX states:%u probes:%u naks:%u acks:%u"
  2397. " dups:%u\n", s->sent_states, s->sent_probes,
  2398. s->sent_nacks, s->sent_acks, s->retransmitted);
  2399. ret += tipc_snprintf(buf + ret, buf_size - ret,
  2400. " Congestion link:%u Send queue"
  2401. " max:%u avg:%u\n", s->link_congs,
  2402. s->max_queue_sz, s->queue_sz_counts ?
  2403. (s->accu_queue_sz / s->queue_sz_counts) : 0);
  2404. tipc_node_unlock(node);
  2405. read_unlock_bh(&tipc_net_lock);
  2406. return ret;
  2407. }
  2408. struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
  2409. {
  2410. struct sk_buff *buf;
  2411. struct tlv_desc *rep_tlv;
  2412. int str_len;
  2413. int pb_len;
  2414. char *pb;
  2415. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
  2416. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  2417. buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
  2418. if (!buf)
  2419. return NULL;
  2420. rep_tlv = (struct tlv_desc *)buf->data;
  2421. pb = TLV_DATA(rep_tlv);
  2422. pb_len = ULTRA_STRING_MAX_LEN;
  2423. str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
  2424. pb, pb_len);
  2425. if (!str_len) {
  2426. kfree_skb(buf);
  2427. return tipc_cfg_reply_error_string("link not found");
  2428. }
  2429. str_len += 1; /* for "\0" */
  2430. skb_put(buf, TLV_SPACE(str_len));
  2431. TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
  2432. return buf;
  2433. }
  2434. /**
  2435. * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
  2436. * @dest: network address of destination node
  2437. * @selector: used to select from set of active links
  2438. *
  2439. * If no active link can be found, uses default maximum packet size.
  2440. */
  2441. u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
  2442. {
  2443. struct tipc_node *n_ptr;
  2444. struct tipc_link *l_ptr;
  2445. u32 res = MAX_PKT_DEFAULT;
  2446. if (dest == tipc_own_addr)
  2447. return MAX_MSG_SIZE;
  2448. read_lock_bh(&tipc_net_lock);
  2449. n_ptr = tipc_node_find(dest);
  2450. if (n_ptr) {
  2451. tipc_node_lock(n_ptr);
  2452. l_ptr = n_ptr->active_links[selector & 1];
  2453. if (l_ptr)
  2454. res = l_ptr->max_pkt;
  2455. tipc_node_unlock(n_ptr);
  2456. }
  2457. read_unlock_bh(&tipc_net_lock);
  2458. return res;
  2459. }
  2460. static void link_print(struct tipc_link *l_ptr, const char *str)
  2461. {
  2462. pr_info("%s Link %x<%s>:", str, l_ptr->addr, l_ptr->b_ptr->name);
  2463. if (link_working_unknown(l_ptr))
  2464. pr_cont(":WU\n");
  2465. else if (link_reset_reset(l_ptr))
  2466. pr_cont(":RR\n");
  2467. else if (link_reset_unknown(l_ptr))
  2468. pr_cont(":RU\n");
  2469. else if (link_working_working(l_ptr))
  2470. pr_cont(":WW\n");
  2471. else
  2472. pr_cont("\n");
  2473. }