link.c 74 KB

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