link.c 74 KB

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