link.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243
  1. /*
  2. * net/tipc/link.c: TIPC link code
  3. *
  4. * Copyright (c) 1996-2007, 2012-2015, 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 "subscr.h"
  38. #include "link.h"
  39. #include "bcast.h"
  40. #include "socket.h"
  41. #include "name_distr.h"
  42. #include "discover.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 SILENCE_EVT 560817u /* timer dicovered silence from peer */
  83. /*
  84. * State value stored in 'failover_pkts'
  85. */
  86. #define FIRST_FAILOVER 0xffffu
  87. static void link_handle_out_of_seq_msg(struct tipc_link *link,
  88. struct sk_buff *skb);
  89. static void tipc_link_proto_rcv(struct tipc_link *link,
  90. struct sk_buff *skb);
  91. static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol);
  92. static void link_state_event(struct tipc_link *l_ptr, u32 event);
  93. static void link_reset_statistics(struct tipc_link *l_ptr);
  94. static void link_print(struct tipc_link *l_ptr, const char *str);
  95. static void tipc_link_sync_xmit(struct tipc_link *l);
  96. static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf);
  97. static void tipc_link_input(struct tipc_link *l, struct sk_buff *skb);
  98. static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb);
  99. static bool tipc_link_failover_rcv(struct tipc_link *l, struct sk_buff **skb);
  100. static void link_set_timer(struct tipc_link *link, unsigned long time);
  101. /*
  102. * Simple link routines
  103. */
  104. static unsigned int align(unsigned int i)
  105. {
  106. return (i + 3) & ~3u;
  107. }
  108. static void tipc_link_release(struct kref *kref)
  109. {
  110. kfree(container_of(kref, struct tipc_link, ref));
  111. }
  112. static void tipc_link_get(struct tipc_link *l_ptr)
  113. {
  114. kref_get(&l_ptr->ref);
  115. }
  116. static void tipc_link_put(struct tipc_link *l_ptr)
  117. {
  118. kref_put(&l_ptr->ref, tipc_link_release);
  119. }
  120. static struct tipc_link *tipc_parallel_link(struct tipc_link *l)
  121. {
  122. if (l->owner->active_links[0] != l)
  123. return l->owner->active_links[0];
  124. return l->owner->active_links[1];
  125. }
  126. /*
  127. * Simple non-static link routines (i.e. referenced outside this file)
  128. */
  129. int tipc_link_is_up(struct tipc_link *l_ptr)
  130. {
  131. if (!l_ptr)
  132. return 0;
  133. return link_working_working(l_ptr) || link_working_unknown(l_ptr);
  134. }
  135. int tipc_link_is_active(struct tipc_link *l_ptr)
  136. {
  137. return (l_ptr->owner->active_links[0] == l_ptr) ||
  138. (l_ptr->owner->active_links[1] == l_ptr);
  139. }
  140. /**
  141. * link_timeout - handle expiration of link timer
  142. * @l_ptr: pointer to link
  143. */
  144. static void link_timeout(unsigned long data)
  145. {
  146. struct tipc_link *l_ptr = (struct tipc_link *)data;
  147. struct sk_buff *skb;
  148. tipc_node_lock(l_ptr->owner);
  149. /* update counters used in statistical profiling of send traffic */
  150. l_ptr->stats.accu_queue_sz += skb_queue_len(&l_ptr->transmq);
  151. l_ptr->stats.queue_sz_counts++;
  152. skb = skb_peek(&l_ptr->transmq);
  153. if (skb) {
  154. struct tipc_msg *msg = buf_msg(skb);
  155. u32 length = msg_size(msg);
  156. if ((msg_user(msg) == MSG_FRAGMENTER) &&
  157. (msg_type(msg) == FIRST_FRAGMENT)) {
  158. length = msg_size(msg_get_wrapped(msg));
  159. }
  160. if (length) {
  161. l_ptr->stats.msg_lengths_total += length;
  162. l_ptr->stats.msg_length_counts++;
  163. if (length <= 64)
  164. l_ptr->stats.msg_length_profile[0]++;
  165. else if (length <= 256)
  166. l_ptr->stats.msg_length_profile[1]++;
  167. else if (length <= 1024)
  168. l_ptr->stats.msg_length_profile[2]++;
  169. else if (length <= 4096)
  170. l_ptr->stats.msg_length_profile[3]++;
  171. else if (length <= 16384)
  172. l_ptr->stats.msg_length_profile[4]++;
  173. else if (length <= 32768)
  174. l_ptr->stats.msg_length_profile[5]++;
  175. else
  176. l_ptr->stats.msg_length_profile[6]++;
  177. }
  178. }
  179. /* do all other link processing performed on a periodic basis */
  180. if (l_ptr->silent_intv_cnt || tipc_bclink_acks_missing(l_ptr->owner))
  181. link_state_event(l_ptr, SILENCE_EVT);
  182. l_ptr->silent_intv_cnt++;
  183. if (skb_queue_len(&l_ptr->backlogq))
  184. tipc_link_push_packets(l_ptr);
  185. link_set_timer(l_ptr, l_ptr->keepalive_intv);
  186. tipc_node_unlock(l_ptr->owner);
  187. tipc_link_put(l_ptr);
  188. }
  189. static void link_set_timer(struct tipc_link *link, unsigned long time)
  190. {
  191. if (!mod_timer(&link->timer, jiffies + time))
  192. tipc_link_get(link);
  193. }
  194. /**
  195. * tipc_link_create - create a new link
  196. * @n_ptr: pointer to associated node
  197. * @b_ptr: pointer to associated bearer
  198. * @media_addr: media address to use when sending messages over link
  199. *
  200. * Returns pointer to link.
  201. */
  202. struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
  203. struct tipc_bearer *b_ptr,
  204. const struct tipc_media_addr *media_addr)
  205. {
  206. struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
  207. struct tipc_link *l_ptr;
  208. struct tipc_msg *msg;
  209. char *if_name;
  210. char addr_string[16];
  211. u32 peer = n_ptr->addr;
  212. if (n_ptr->link_cnt >= MAX_BEARERS) {
  213. tipc_addr_string_fill(addr_string, n_ptr->addr);
  214. pr_err("Cannot establish %uth link to %s. Max %u allowed.\n",
  215. n_ptr->link_cnt, addr_string, MAX_BEARERS);
  216. return NULL;
  217. }
  218. if (n_ptr->links[b_ptr->identity]) {
  219. tipc_addr_string_fill(addr_string, n_ptr->addr);
  220. pr_err("Attempt to establish second link on <%s> to %s\n",
  221. b_ptr->name, addr_string);
  222. return NULL;
  223. }
  224. l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
  225. if (!l_ptr) {
  226. pr_warn("Link creation failed, no memory\n");
  227. return NULL;
  228. }
  229. kref_init(&l_ptr->ref);
  230. l_ptr->addr = peer;
  231. if_name = strchr(b_ptr->name, ':') + 1;
  232. sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
  233. tipc_zone(tn->own_addr), tipc_cluster(tn->own_addr),
  234. tipc_node(tn->own_addr),
  235. if_name,
  236. tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
  237. /* note: peer i/f name is updated by reset/activate message */
  238. memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
  239. l_ptr->owner = n_ptr;
  240. l_ptr->peer_session = INVALID_SESSION;
  241. l_ptr->bearer_id = b_ptr->identity;
  242. link_set_supervision_props(l_ptr, b_ptr->tolerance);
  243. l_ptr->state = RESET_UNKNOWN;
  244. l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
  245. msg = l_ptr->pmsg;
  246. tipc_msg_init(tn->own_addr, msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE,
  247. l_ptr->addr);
  248. msg_set_size(msg, sizeof(l_ptr->proto_msg));
  249. msg_set_session(msg, (tn->random & 0xffff));
  250. msg_set_bearer_id(msg, b_ptr->identity);
  251. strcpy((char *)msg_data(msg), if_name);
  252. l_ptr->net_plane = b_ptr->net_plane;
  253. l_ptr->advertised_mtu = b_ptr->mtu;
  254. l_ptr->mtu = l_ptr->advertised_mtu;
  255. l_ptr->priority = b_ptr->priority;
  256. tipc_link_set_queue_limits(l_ptr, b_ptr->window);
  257. l_ptr->snd_nxt = 1;
  258. __skb_queue_head_init(&l_ptr->transmq);
  259. __skb_queue_head_init(&l_ptr->backlogq);
  260. __skb_queue_head_init(&l_ptr->deferdq);
  261. skb_queue_head_init(&l_ptr->wakeupq);
  262. skb_queue_head_init(&l_ptr->inputq);
  263. skb_queue_head_init(&l_ptr->namedq);
  264. link_reset_statistics(l_ptr);
  265. tipc_node_attach_link(n_ptr, l_ptr);
  266. setup_timer(&l_ptr->timer, link_timeout, (unsigned long)l_ptr);
  267. link_state_event(l_ptr, STARTING_EVT);
  268. return l_ptr;
  269. }
  270. /**
  271. * tipc_link_delete - Delete a link
  272. * @l: link to be deleted
  273. */
  274. void tipc_link_delete(struct tipc_link *l)
  275. {
  276. tipc_link_reset(l);
  277. if (del_timer(&l->timer))
  278. tipc_link_put(l);
  279. l->flags |= LINK_STOPPED;
  280. /* Delete link now, or when timer is finished: */
  281. tipc_link_reset_fragments(l);
  282. tipc_node_detach_link(l->owner, l);
  283. tipc_link_put(l);
  284. }
  285. void tipc_link_delete_list(struct net *net, unsigned int bearer_id)
  286. {
  287. struct tipc_net *tn = net_generic(net, tipc_net_id);
  288. struct tipc_link *link;
  289. struct tipc_node *node;
  290. rcu_read_lock();
  291. list_for_each_entry_rcu(node, &tn->node_list, list) {
  292. tipc_node_lock(node);
  293. link = node->links[bearer_id];
  294. if (link)
  295. tipc_link_delete(link);
  296. tipc_node_unlock(node);
  297. }
  298. rcu_read_unlock();
  299. }
  300. /**
  301. * link_schedule_user - schedule a message sender for wakeup after congestion
  302. * @link: congested link
  303. * @list: message that was attempted sent
  304. * Create pseudo msg to send back to user when congestion abates
  305. * Only consumes message if there is an error
  306. */
  307. static int link_schedule_user(struct tipc_link *link, struct sk_buff_head *list)
  308. {
  309. struct tipc_msg *msg = buf_msg(skb_peek(list));
  310. int imp = msg_importance(msg);
  311. u32 oport = msg_origport(msg);
  312. u32 addr = link_own_addr(link);
  313. struct sk_buff *skb;
  314. /* This really cannot happen... */
  315. if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
  316. pr_warn("%s<%s>, send queue full", link_rst_msg, link->name);
  317. tipc_link_reset(link);
  318. goto err;
  319. }
  320. /* Non-blocking sender: */
  321. if (TIPC_SKB_CB(skb_peek(list))->wakeup_pending)
  322. return -ELINKCONG;
  323. /* Create and schedule wakeup pseudo message */
  324. skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
  325. addr, addr, oport, 0, 0);
  326. if (!skb)
  327. goto err;
  328. TIPC_SKB_CB(skb)->chain_sz = skb_queue_len(list);
  329. TIPC_SKB_CB(skb)->chain_imp = imp;
  330. skb_queue_tail(&link->wakeupq, skb);
  331. link->stats.link_congs++;
  332. return -ELINKCONG;
  333. err:
  334. __skb_queue_purge(list);
  335. return -ENOBUFS;
  336. }
  337. /**
  338. * link_prepare_wakeup - prepare users for wakeup after congestion
  339. * @link: congested link
  340. * Move a number of waiting users, as permitted by available space in
  341. * the send queue, from link wait queue to node wait queue for wakeup
  342. */
  343. void link_prepare_wakeup(struct tipc_link *l)
  344. {
  345. int pnd[TIPC_SYSTEM_IMPORTANCE + 1] = {0,};
  346. int imp, lim;
  347. struct sk_buff *skb, *tmp;
  348. skb_queue_walk_safe(&l->wakeupq, skb, tmp) {
  349. imp = TIPC_SKB_CB(skb)->chain_imp;
  350. lim = l->window + l->backlog[imp].limit;
  351. pnd[imp] += TIPC_SKB_CB(skb)->chain_sz;
  352. if ((pnd[imp] + l->backlog[imp].len) >= lim)
  353. break;
  354. skb_unlink(skb, &l->wakeupq);
  355. skb_queue_tail(&l->inputq, skb);
  356. l->owner->inputq = &l->inputq;
  357. l->owner->action_flags |= TIPC_MSG_EVT;
  358. }
  359. }
  360. /**
  361. * tipc_link_reset_fragments - purge link's inbound message fragments queue
  362. * @l_ptr: pointer to link
  363. */
  364. void tipc_link_reset_fragments(struct tipc_link *l_ptr)
  365. {
  366. kfree_skb(l_ptr->reasm_buf);
  367. l_ptr->reasm_buf = NULL;
  368. }
  369. static void tipc_link_purge_backlog(struct tipc_link *l)
  370. {
  371. __skb_queue_purge(&l->backlogq);
  372. l->backlog[TIPC_LOW_IMPORTANCE].len = 0;
  373. l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0;
  374. l->backlog[TIPC_HIGH_IMPORTANCE].len = 0;
  375. l->backlog[TIPC_CRITICAL_IMPORTANCE].len = 0;
  376. l->backlog[TIPC_SYSTEM_IMPORTANCE].len = 0;
  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->deferdq);
  385. __skb_queue_purge(&l_ptr->transmq);
  386. tipc_link_purge_backlog(l_ptr);
  387. tipc_link_reset_fragments(l_ptr);
  388. }
  389. void tipc_link_reset(struct tipc_link *l_ptr)
  390. {
  391. u32 prev_state = l_ptr->state;
  392. int was_active_link = tipc_link_is_active(l_ptr);
  393. struct tipc_node *owner = l_ptr->owner;
  394. struct tipc_link *pl = tipc_parallel_link(l_ptr);
  395. msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
  396. /* Link is down, accept any session */
  397. l_ptr->peer_session = INVALID_SESSION;
  398. /* Prepare for renewed mtu size negotiation */
  399. l_ptr->mtu = l_ptr->advertised_mtu;
  400. l_ptr->state = RESET_UNKNOWN;
  401. if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
  402. return;
  403. tipc_node_link_down(l_ptr->owner, l_ptr);
  404. tipc_bearer_remove_dest(owner->net, l_ptr->bearer_id, l_ptr->addr);
  405. if (was_active_link && tipc_node_is_up(l_ptr->owner) && (pl != l_ptr)) {
  406. l_ptr->flags |= LINK_FAILINGOVER;
  407. l_ptr->failover_checkpt = l_ptr->rcv_nxt;
  408. pl->failover_pkts = FIRST_FAILOVER;
  409. pl->failover_checkpt = l_ptr->rcv_nxt;
  410. pl->failover_skb = l_ptr->reasm_buf;
  411. } else {
  412. kfree_skb(l_ptr->reasm_buf);
  413. }
  414. /* Clean up all queues, except inputq: */
  415. __skb_queue_purge(&l_ptr->transmq);
  416. __skb_queue_purge(&l_ptr->deferdq);
  417. if (!owner->inputq)
  418. owner->inputq = &l_ptr->inputq;
  419. skb_queue_splice_init(&l_ptr->wakeupq, owner->inputq);
  420. if (!skb_queue_empty(owner->inputq))
  421. owner->action_flags |= TIPC_MSG_EVT;
  422. tipc_link_purge_backlog(l_ptr);
  423. l_ptr->reasm_buf = NULL;
  424. l_ptr->rcv_unacked = 0;
  425. l_ptr->snd_nxt = 1;
  426. l_ptr->silent_intv_cnt = 0;
  427. l_ptr->stale_count = 0;
  428. link_reset_statistics(l_ptr);
  429. }
  430. static void link_activate(struct tipc_link *link)
  431. {
  432. struct tipc_node *node = link->owner;
  433. link->rcv_nxt = 1;
  434. link->stats.recv_info = 1;
  435. link->silent_intv_cnt = 0;
  436. tipc_node_link_up(node, link);
  437. tipc_bearer_add_dest(node->net, link->bearer_id, link->addr);
  438. }
  439. /**
  440. * link_state_event - link finite state machine
  441. * @l_ptr: pointer to link
  442. * @event: state machine event to process
  443. */
  444. static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
  445. {
  446. struct tipc_link *other;
  447. unsigned long timer_intv = l_ptr->keepalive_intv;
  448. if (l_ptr->flags & LINK_STOPPED)
  449. return;
  450. if (!(l_ptr->flags & LINK_STARTED) && (event != STARTING_EVT))
  451. return; /* Not yet. */
  452. if (l_ptr->flags & LINK_FAILINGOVER)
  453. return;
  454. switch (l_ptr->state) {
  455. case WORKING_WORKING:
  456. switch (event) {
  457. case TRAFFIC_MSG_EVT:
  458. case ACTIVATE_MSG:
  459. l_ptr->silent_intv_cnt = 0;
  460. break;
  461. case SILENCE_EVT:
  462. if (!l_ptr->silent_intv_cnt) {
  463. if (tipc_bclink_acks_missing(l_ptr->owner))
  464. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  465. 0, 0, 0, 0);
  466. break;
  467. }
  468. l_ptr->state = WORKING_UNKNOWN;
  469. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0);
  470. break;
  471. case RESET_MSG:
  472. pr_debug("%s<%s>, requested by peer\n",
  473. link_rst_msg, l_ptr->name);
  474. tipc_link_reset(l_ptr);
  475. l_ptr->state = RESET_RESET;
  476. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  477. 0, 0, 0, 0);
  478. break;
  479. default:
  480. pr_debug("%s%u in WW state\n", link_unk_evt, event);
  481. }
  482. break;
  483. case WORKING_UNKNOWN:
  484. switch (event) {
  485. case TRAFFIC_MSG_EVT:
  486. case ACTIVATE_MSG:
  487. l_ptr->state = WORKING_WORKING;
  488. l_ptr->silent_intv_cnt = 0;
  489. break;
  490. case RESET_MSG:
  491. pr_debug("%s<%s>, requested by peer while probing\n",
  492. link_rst_msg, l_ptr->name);
  493. tipc_link_reset(l_ptr);
  494. l_ptr->state = RESET_RESET;
  495. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  496. 0, 0, 0, 0);
  497. break;
  498. case SILENCE_EVT:
  499. if (!l_ptr->silent_intv_cnt) {
  500. l_ptr->state = WORKING_WORKING;
  501. if (tipc_bclink_acks_missing(l_ptr->owner))
  502. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  503. 0, 0, 0, 0);
  504. } else if (l_ptr->silent_intv_cnt <
  505. l_ptr->abort_limit) {
  506. tipc_link_proto_xmit(l_ptr, STATE_MSG,
  507. 1, 0, 0, 0);
  508. } else { /* Link has failed */
  509. pr_debug("%s<%s>, peer not responding\n",
  510. link_rst_msg, l_ptr->name);
  511. tipc_link_reset(l_ptr);
  512. l_ptr->state = RESET_UNKNOWN;
  513. tipc_link_proto_xmit(l_ptr, RESET_MSG,
  514. 0, 0, 0, 0);
  515. }
  516. break;
  517. default:
  518. pr_err("%s%u in WU state\n", link_unk_evt, event);
  519. }
  520. break;
  521. case RESET_UNKNOWN:
  522. switch (event) {
  523. case TRAFFIC_MSG_EVT:
  524. break;
  525. case ACTIVATE_MSG:
  526. other = l_ptr->owner->active_links[0];
  527. if (other && link_working_unknown(other))
  528. break;
  529. l_ptr->state = WORKING_WORKING;
  530. link_activate(l_ptr);
  531. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0);
  532. if (l_ptr->owner->working_links == 1)
  533. tipc_link_sync_xmit(l_ptr);
  534. break;
  535. case RESET_MSG:
  536. l_ptr->state = RESET_RESET;
  537. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  538. 1, 0, 0, 0);
  539. break;
  540. case STARTING_EVT:
  541. l_ptr->flags |= LINK_STARTED;
  542. link_set_timer(l_ptr, timer_intv);
  543. break;
  544. case SILENCE_EVT:
  545. tipc_link_proto_xmit(l_ptr, RESET_MSG, 0, 0, 0, 0);
  546. break;
  547. default:
  548. pr_err("%s%u in RU state\n", link_unk_evt, event);
  549. }
  550. break;
  551. case RESET_RESET:
  552. switch (event) {
  553. case TRAFFIC_MSG_EVT:
  554. case ACTIVATE_MSG:
  555. other = l_ptr->owner->active_links[0];
  556. if (other && link_working_unknown(other))
  557. break;
  558. l_ptr->state = WORKING_WORKING;
  559. link_activate(l_ptr);
  560. tipc_link_proto_xmit(l_ptr, STATE_MSG, 1, 0, 0, 0);
  561. if (l_ptr->owner->working_links == 1)
  562. tipc_link_sync_xmit(l_ptr);
  563. break;
  564. case RESET_MSG:
  565. break;
  566. case SILENCE_EVT:
  567. tipc_link_proto_xmit(l_ptr, ACTIVATE_MSG,
  568. 0, 0, 0, 0);
  569. break;
  570. default:
  571. pr_err("%s%u in RR state\n", link_unk_evt, event);
  572. }
  573. break;
  574. default:
  575. pr_err("Unknown link state %u/%u\n", l_ptr->state, event);
  576. }
  577. }
  578. /**
  579. * __tipc_link_xmit(): same as tipc_link_xmit, but destlink is known & locked
  580. * @link: link to use
  581. * @list: chain of buffers containing message
  582. *
  583. * Consumes the buffer chain, except when returning -ELINKCONG,
  584. * since the caller then may want to make more send attempts.
  585. * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
  586. * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
  587. */
  588. int __tipc_link_xmit(struct net *net, struct tipc_link *link,
  589. struct sk_buff_head *list)
  590. {
  591. struct tipc_msg *msg = buf_msg(skb_peek(list));
  592. unsigned int maxwin = link->window;
  593. unsigned int i, imp = msg_importance(msg);
  594. uint mtu = link->mtu;
  595. u16 ack = mod(link->rcv_nxt - 1);
  596. u16 seqno = link->snd_nxt;
  597. u16 bc_last_in = link->owner->bclink.last_in;
  598. struct tipc_media_addr *addr = &link->media_addr;
  599. struct sk_buff_head *transmq = &link->transmq;
  600. struct sk_buff_head *backlogq = &link->backlogq;
  601. struct sk_buff *skb, *bskb;
  602. /* Match msg importance against this and all higher backlog limits: */
  603. for (i = imp; i <= TIPC_SYSTEM_IMPORTANCE; i++) {
  604. if (unlikely(link->backlog[i].len >= link->backlog[i].limit))
  605. return link_schedule_user(link, list);
  606. }
  607. if (unlikely(msg_size(msg) > mtu)) {
  608. __skb_queue_purge(list);
  609. return -EMSGSIZE;
  610. }
  611. /* Prepare each packet for sending, and add to relevant queue: */
  612. while (skb_queue_len(list)) {
  613. skb = skb_peek(list);
  614. msg = buf_msg(skb);
  615. msg_set_seqno(msg, seqno);
  616. msg_set_ack(msg, ack);
  617. msg_set_bcast_ack(msg, bc_last_in);
  618. if (likely(skb_queue_len(transmq) < maxwin)) {
  619. __skb_dequeue(list);
  620. __skb_queue_tail(transmq, skb);
  621. tipc_bearer_send(net, link->bearer_id, skb, addr);
  622. link->rcv_unacked = 0;
  623. seqno++;
  624. continue;
  625. }
  626. if (tipc_msg_bundle(skb_peek_tail(backlogq), msg, mtu)) {
  627. kfree_skb(__skb_dequeue(list));
  628. link->stats.sent_bundled++;
  629. continue;
  630. }
  631. if (tipc_msg_make_bundle(&bskb, msg, mtu, link->addr)) {
  632. kfree_skb(__skb_dequeue(list));
  633. __skb_queue_tail(backlogq, bskb);
  634. link->backlog[msg_importance(buf_msg(bskb))].len++;
  635. link->stats.sent_bundled++;
  636. link->stats.sent_bundles++;
  637. continue;
  638. }
  639. link->backlog[imp].len += skb_queue_len(list);
  640. skb_queue_splice_tail_init(list, backlogq);
  641. }
  642. link->snd_nxt = seqno;
  643. return 0;
  644. }
  645. static void skb2list(struct sk_buff *skb, struct sk_buff_head *list)
  646. {
  647. skb_queue_head_init(list);
  648. __skb_queue_tail(list, skb);
  649. }
  650. static int __tipc_link_xmit_skb(struct tipc_link *link, struct sk_buff *skb)
  651. {
  652. struct sk_buff_head head;
  653. skb2list(skb, &head);
  654. return __tipc_link_xmit(link->owner->net, link, &head);
  655. }
  656. /* tipc_link_xmit_skb(): send single buffer to destination
  657. * Buffers sent via this functon are generally TIPC_SYSTEM_IMPORTANCE
  658. * messages, which will not be rejected
  659. * The only exception is datagram messages rerouted after secondary
  660. * lookup, which are rare and safe to dispose of anyway.
  661. * TODO: Return real return value, and let callers use
  662. * tipc_wait_for_sendpkt() where applicable
  663. */
  664. int tipc_link_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
  665. u32 selector)
  666. {
  667. struct sk_buff_head head;
  668. int rc;
  669. skb2list(skb, &head);
  670. rc = tipc_link_xmit(net, &head, dnode, selector);
  671. if (rc == -ELINKCONG)
  672. kfree_skb(skb);
  673. return 0;
  674. }
  675. /**
  676. * tipc_link_xmit() is the general link level function for message sending
  677. * @net: the applicable net namespace
  678. * @list: chain of buffers containing message
  679. * @dsz: amount of user data to be sent
  680. * @dnode: address of destination node
  681. * @selector: a number used for deterministic link selection
  682. * Consumes the buffer chain, except when returning -ELINKCONG
  683. * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
  684. */
  685. int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dnode,
  686. u32 selector)
  687. {
  688. struct tipc_link *link = NULL;
  689. struct tipc_node *node;
  690. int rc = -EHOSTUNREACH;
  691. node = tipc_node_find(net, dnode);
  692. if (node) {
  693. tipc_node_lock(node);
  694. link = node->active_links[selector & 1];
  695. if (link)
  696. rc = __tipc_link_xmit(net, link, list);
  697. tipc_node_unlock(node);
  698. tipc_node_put(node);
  699. }
  700. if (link)
  701. return rc;
  702. if (likely(in_own_node(net, dnode))) {
  703. tipc_sk_rcv(net, list);
  704. return 0;
  705. }
  706. __skb_queue_purge(list);
  707. return rc;
  708. }
  709. /*
  710. * tipc_link_sync_xmit - synchronize broadcast link endpoints.
  711. *
  712. * Give a newly added peer node the sequence number where it should
  713. * start receiving and acking broadcast packets.
  714. *
  715. * Called with node locked
  716. */
  717. static void tipc_link_sync_xmit(struct tipc_link *link)
  718. {
  719. struct sk_buff *skb;
  720. struct tipc_msg *msg;
  721. skb = tipc_buf_acquire(INT_H_SIZE);
  722. if (!skb)
  723. return;
  724. msg = buf_msg(skb);
  725. tipc_msg_init(link_own_addr(link), msg, BCAST_PROTOCOL, STATE_MSG,
  726. INT_H_SIZE, link->addr);
  727. msg_set_last_bcast(msg, link->owner->bclink.acked);
  728. __tipc_link_xmit_skb(link, skb);
  729. }
  730. /*
  731. * tipc_link_sync_rcv - synchronize broadcast link endpoints.
  732. * Receive the sequence number where we should start receiving and
  733. * acking broadcast packets from a newly added peer node, and open
  734. * up for reception of such packets.
  735. *
  736. * Called with node locked
  737. */
  738. static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf)
  739. {
  740. struct tipc_msg *msg = buf_msg(buf);
  741. n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg);
  742. n->bclink.recv_permitted = true;
  743. kfree_skb(buf);
  744. }
  745. /*
  746. * tipc_link_push_packets - push unsent packets to bearer
  747. *
  748. * Push out the unsent messages of a link where congestion
  749. * has abated. Node is locked.
  750. *
  751. * Called with node locked
  752. */
  753. void tipc_link_push_packets(struct tipc_link *link)
  754. {
  755. struct sk_buff *skb;
  756. struct tipc_msg *msg;
  757. u16 seqno = link->snd_nxt;
  758. u16 ack = mod(link->rcv_nxt - 1);
  759. while (skb_queue_len(&link->transmq) < link->window) {
  760. skb = __skb_dequeue(&link->backlogq);
  761. if (!skb)
  762. break;
  763. msg = buf_msg(skb);
  764. link->backlog[msg_importance(msg)].len--;
  765. msg_set_ack(msg, ack);
  766. msg_set_seqno(msg, seqno);
  767. seqno = mod(seqno + 1);
  768. msg_set_bcast_ack(msg, link->owner->bclink.last_in);
  769. link->rcv_unacked = 0;
  770. __skb_queue_tail(&link->transmq, skb);
  771. tipc_bearer_send(link->owner->net, link->bearer_id,
  772. skb, &link->media_addr);
  773. }
  774. link->snd_nxt = seqno;
  775. }
  776. void tipc_link_reset_all(struct tipc_node *node)
  777. {
  778. char addr_string[16];
  779. u32 i;
  780. tipc_node_lock(node);
  781. pr_warn("Resetting all links to %s\n",
  782. tipc_addr_string_fill(addr_string, node->addr));
  783. for (i = 0; i < MAX_BEARERS; i++) {
  784. if (node->links[i]) {
  785. link_print(node->links[i], "Resetting link\n");
  786. tipc_link_reset(node->links[i]);
  787. }
  788. }
  789. tipc_node_unlock(node);
  790. }
  791. static void link_retransmit_failure(struct tipc_link *l_ptr,
  792. struct sk_buff *buf)
  793. {
  794. struct tipc_msg *msg = buf_msg(buf);
  795. struct net *net = l_ptr->owner->net;
  796. pr_warn("Retransmission failure on link <%s>\n", l_ptr->name);
  797. if (l_ptr->addr) {
  798. /* Handle failure on standard link */
  799. link_print(l_ptr, "Resetting link\n");
  800. tipc_link_reset(l_ptr);
  801. } else {
  802. /* Handle failure on broadcast link */
  803. struct tipc_node *n_ptr;
  804. char addr_string[16];
  805. pr_info("Msg seq number: %u, ", msg_seqno(msg));
  806. pr_cont("Outstanding acks: %lu\n",
  807. (unsigned long) TIPC_SKB_CB(buf)->handle);
  808. n_ptr = tipc_bclink_retransmit_to(net);
  809. tipc_addr_string_fill(addr_string, n_ptr->addr);
  810. pr_info("Broadcast link info for %s\n", addr_string);
  811. pr_info("Reception permitted: %d, Acked: %u\n",
  812. n_ptr->bclink.recv_permitted,
  813. n_ptr->bclink.acked);
  814. pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
  815. n_ptr->bclink.last_in,
  816. n_ptr->bclink.oos_state,
  817. n_ptr->bclink.last_sent);
  818. n_ptr->action_flags |= TIPC_BCAST_RESET;
  819. l_ptr->stale_count = 0;
  820. }
  821. }
  822. void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *skb,
  823. u32 retransmits)
  824. {
  825. struct tipc_msg *msg;
  826. if (!skb)
  827. return;
  828. msg = buf_msg(skb);
  829. /* Detect repeated retransmit failures */
  830. if (l_ptr->last_retransm == msg_seqno(msg)) {
  831. if (++l_ptr->stale_count > 100) {
  832. link_retransmit_failure(l_ptr, skb);
  833. return;
  834. }
  835. } else {
  836. l_ptr->last_retransm = msg_seqno(msg);
  837. l_ptr->stale_count = 1;
  838. }
  839. skb_queue_walk_from(&l_ptr->transmq, skb) {
  840. if (!retransmits)
  841. break;
  842. msg = buf_msg(skb);
  843. msg_set_ack(msg, mod(l_ptr->rcv_nxt - 1));
  844. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  845. tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, skb,
  846. &l_ptr->media_addr);
  847. retransmits--;
  848. l_ptr->stats.retransmitted++;
  849. }
  850. }
  851. /* link_synch(): check if all packets arrived before the synch
  852. * point have been consumed
  853. * Returns true if the parallel links are synched, otherwise false
  854. */
  855. static bool link_synch(struct tipc_link *l)
  856. {
  857. unsigned int post_synch;
  858. struct tipc_link *pl;
  859. pl = tipc_parallel_link(l);
  860. if (pl == l)
  861. goto synched;
  862. /* Was last pre-synch packet added to input queue ? */
  863. if (less_eq(pl->rcv_nxt, l->synch_point))
  864. return false;
  865. /* Is it still in the input queue ? */
  866. post_synch = mod(pl->rcv_nxt - l->synch_point) - 1;
  867. if (skb_queue_len(&pl->inputq) > post_synch)
  868. return false;
  869. synched:
  870. l->flags &= ~LINK_SYNCHING;
  871. return true;
  872. }
  873. static void link_retrieve_defq(struct tipc_link *link,
  874. struct sk_buff_head *list)
  875. {
  876. u16 seq_no;
  877. if (skb_queue_empty(&link->deferdq))
  878. return;
  879. seq_no = buf_seqno(skb_peek(&link->deferdq));
  880. if (seq_no == link->rcv_nxt)
  881. skb_queue_splice_tail_init(&link->deferdq, list);
  882. }
  883. /**
  884. * tipc_rcv - process TIPC packets/messages arriving from off-node
  885. * @net: the applicable net namespace
  886. * @skb: TIPC packet
  887. * @b_ptr: pointer to bearer message arrived on
  888. *
  889. * Invoked with no locks held. Bearer pointer must point to a valid bearer
  890. * structure (i.e. cannot be NULL), but bearer can be inactive.
  891. */
  892. void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
  893. {
  894. struct tipc_net *tn = net_generic(net, tipc_net_id);
  895. struct sk_buff_head head;
  896. struct tipc_node *n_ptr;
  897. struct tipc_link *l_ptr;
  898. struct sk_buff *skb1, *tmp;
  899. struct tipc_msg *msg;
  900. u16 seq_no;
  901. u16 ackd;
  902. u32 released;
  903. skb2list(skb, &head);
  904. while ((skb = __skb_dequeue(&head))) {
  905. /* Ensure message is well-formed */
  906. if (unlikely(!tipc_msg_validate(skb)))
  907. goto discard;
  908. /* Handle arrival of a non-unicast link message */
  909. msg = buf_msg(skb);
  910. if (unlikely(msg_non_seq(msg))) {
  911. if (msg_user(msg) == LINK_CONFIG)
  912. tipc_disc_rcv(net, skb, b_ptr);
  913. else
  914. tipc_bclink_rcv(net, skb);
  915. continue;
  916. }
  917. /* Discard unicast link messages destined for another node */
  918. if (unlikely(!msg_short(msg) &&
  919. (msg_destnode(msg) != tn->own_addr)))
  920. goto discard;
  921. /* Locate neighboring node that sent message */
  922. n_ptr = tipc_node_find(net, msg_prevnode(msg));
  923. if (unlikely(!n_ptr))
  924. goto discard;
  925. tipc_node_lock(n_ptr);
  926. /* Locate unicast link endpoint that should handle message */
  927. l_ptr = n_ptr->links[b_ptr->identity];
  928. if (unlikely(!l_ptr))
  929. goto unlock;
  930. /* Verify that communication with node is currently allowed */
  931. if ((n_ptr->action_flags & TIPC_WAIT_PEER_LINKS_DOWN) &&
  932. msg_user(msg) == LINK_PROTOCOL &&
  933. (msg_type(msg) == RESET_MSG ||
  934. msg_type(msg) == ACTIVATE_MSG) &&
  935. !msg_redundant_link(msg))
  936. n_ptr->action_flags &= ~TIPC_WAIT_PEER_LINKS_DOWN;
  937. if (tipc_node_blocked(n_ptr))
  938. goto unlock;
  939. /* Validate message sequence number info */
  940. seq_no = msg_seqno(msg);
  941. ackd = msg_ack(msg);
  942. /* Release acked messages */
  943. if (unlikely(n_ptr->bclink.acked != msg_bcast_ack(msg)))
  944. tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
  945. released = 0;
  946. skb_queue_walk_safe(&l_ptr->transmq, skb1, tmp) {
  947. if (more(buf_seqno(skb1), ackd))
  948. break;
  949. __skb_unlink(skb1, &l_ptr->transmq);
  950. kfree_skb(skb1);
  951. released = 1;
  952. }
  953. /* Try sending any messages link endpoint has pending */
  954. if (unlikely(skb_queue_len(&l_ptr->backlogq)))
  955. tipc_link_push_packets(l_ptr);
  956. if (released && !skb_queue_empty(&l_ptr->wakeupq))
  957. link_prepare_wakeup(l_ptr);
  958. /* Process the incoming packet */
  959. if (unlikely(!link_working_working(l_ptr))) {
  960. if (msg_user(msg) == LINK_PROTOCOL) {
  961. tipc_link_proto_rcv(l_ptr, skb);
  962. link_retrieve_defq(l_ptr, &head);
  963. skb = NULL;
  964. goto unlock;
  965. }
  966. /* Traffic message. Conditionally activate link */
  967. link_state_event(l_ptr, TRAFFIC_MSG_EVT);
  968. if (link_working_working(l_ptr)) {
  969. /* Re-insert buffer in front of queue */
  970. __skb_queue_head(&head, skb);
  971. skb = NULL;
  972. goto unlock;
  973. }
  974. goto unlock;
  975. }
  976. /* Link is now in state WORKING_WORKING */
  977. if (unlikely(seq_no != l_ptr->rcv_nxt)) {
  978. link_handle_out_of_seq_msg(l_ptr, skb);
  979. link_retrieve_defq(l_ptr, &head);
  980. skb = NULL;
  981. goto unlock;
  982. }
  983. l_ptr->silent_intv_cnt = 0;
  984. /* Synchronize with parallel link if applicable */
  985. if (unlikely((l_ptr->flags & LINK_SYNCHING) && !msg_dup(msg))) {
  986. if (!link_synch(l_ptr))
  987. goto unlock;
  988. }
  989. l_ptr->rcv_nxt++;
  990. if (unlikely(!skb_queue_empty(&l_ptr->deferdq)))
  991. link_retrieve_defq(l_ptr, &head);
  992. if (unlikely(++l_ptr->rcv_unacked >= TIPC_MIN_LINK_WIN)) {
  993. l_ptr->stats.sent_acks++;
  994. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0);
  995. }
  996. tipc_link_input(l_ptr, skb);
  997. skb = NULL;
  998. unlock:
  999. tipc_node_unlock(n_ptr);
  1000. tipc_node_put(n_ptr);
  1001. discard:
  1002. if (unlikely(skb))
  1003. kfree_skb(skb);
  1004. }
  1005. }
  1006. /* tipc_data_input - deliver data and name distr msgs to upper layer
  1007. *
  1008. * Consumes buffer if message is of right type
  1009. * Node lock must be held
  1010. */
  1011. static bool tipc_data_input(struct tipc_link *link, struct sk_buff *skb)
  1012. {
  1013. struct tipc_node *node = link->owner;
  1014. struct tipc_msg *msg = buf_msg(skb);
  1015. u32 dport = msg_destport(msg);
  1016. switch (msg_user(msg)) {
  1017. case TIPC_LOW_IMPORTANCE:
  1018. case TIPC_MEDIUM_IMPORTANCE:
  1019. case TIPC_HIGH_IMPORTANCE:
  1020. case TIPC_CRITICAL_IMPORTANCE:
  1021. case CONN_MANAGER:
  1022. if (tipc_skb_queue_tail(&link->inputq, skb, dport)) {
  1023. node->inputq = &link->inputq;
  1024. node->action_flags |= TIPC_MSG_EVT;
  1025. }
  1026. return true;
  1027. case NAME_DISTRIBUTOR:
  1028. node->bclink.recv_permitted = true;
  1029. node->namedq = &link->namedq;
  1030. skb_queue_tail(&link->namedq, skb);
  1031. if (skb_queue_len(&link->namedq) == 1)
  1032. node->action_flags |= TIPC_NAMED_MSG_EVT;
  1033. return true;
  1034. case MSG_BUNDLER:
  1035. case TUNNEL_PROTOCOL:
  1036. case MSG_FRAGMENTER:
  1037. case BCAST_PROTOCOL:
  1038. return false;
  1039. default:
  1040. pr_warn("Dropping received illegal msg type\n");
  1041. kfree_skb(skb);
  1042. return false;
  1043. };
  1044. }
  1045. /* tipc_link_input - process packet that has passed link protocol check
  1046. *
  1047. * Consumes buffer
  1048. * Node lock must be held
  1049. */
  1050. static void tipc_link_input(struct tipc_link *link, struct sk_buff *skb)
  1051. {
  1052. struct tipc_node *node = link->owner;
  1053. struct tipc_msg *msg = buf_msg(skb);
  1054. struct sk_buff *iskb;
  1055. int pos = 0;
  1056. if (likely(tipc_data_input(link, skb)))
  1057. return;
  1058. switch (msg_user(msg)) {
  1059. case TUNNEL_PROTOCOL:
  1060. if (msg_dup(msg)) {
  1061. link->flags |= LINK_SYNCHING;
  1062. link->synch_point = msg_seqno(msg_get_wrapped(msg));
  1063. kfree_skb(skb);
  1064. break;
  1065. }
  1066. if (!tipc_link_failover_rcv(link, &skb))
  1067. break;
  1068. if (msg_user(buf_msg(skb)) != MSG_BUNDLER) {
  1069. tipc_data_input(link, skb);
  1070. break;
  1071. }
  1072. case MSG_BUNDLER:
  1073. link->stats.recv_bundles++;
  1074. link->stats.recv_bundled += msg_msgcnt(msg);
  1075. while (tipc_msg_extract(skb, &iskb, &pos))
  1076. tipc_data_input(link, iskb);
  1077. break;
  1078. case MSG_FRAGMENTER:
  1079. link->stats.recv_fragments++;
  1080. if (tipc_buf_append(&link->reasm_buf, &skb)) {
  1081. link->stats.recv_fragmented++;
  1082. tipc_data_input(link, skb);
  1083. } else if (!link->reasm_buf) {
  1084. tipc_link_reset(link);
  1085. }
  1086. break;
  1087. case BCAST_PROTOCOL:
  1088. tipc_link_sync_rcv(node, skb);
  1089. break;
  1090. default:
  1091. break;
  1092. };
  1093. }
  1094. /**
  1095. * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
  1096. *
  1097. * Returns increase in queue length (i.e. 0 or 1)
  1098. */
  1099. u32 tipc_link_defer_pkt(struct sk_buff_head *list, struct sk_buff *skb)
  1100. {
  1101. struct sk_buff *skb1;
  1102. u16 seq_no = buf_seqno(skb);
  1103. /* Empty queue ? */
  1104. if (skb_queue_empty(list)) {
  1105. __skb_queue_tail(list, skb);
  1106. return 1;
  1107. }
  1108. /* Last ? */
  1109. if (less(buf_seqno(skb_peek_tail(list)), seq_no)) {
  1110. __skb_queue_tail(list, skb);
  1111. return 1;
  1112. }
  1113. /* Locate insertion point in queue, then insert; discard if duplicate */
  1114. skb_queue_walk(list, skb1) {
  1115. u16 curr_seqno = buf_seqno(skb1);
  1116. if (seq_no == curr_seqno) {
  1117. kfree_skb(skb);
  1118. return 0;
  1119. }
  1120. if (less(seq_no, curr_seqno))
  1121. break;
  1122. }
  1123. __skb_queue_before(list, skb1, skb);
  1124. return 1;
  1125. }
  1126. /*
  1127. * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
  1128. */
  1129. static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
  1130. struct sk_buff *buf)
  1131. {
  1132. u32 seq_no = buf_seqno(buf);
  1133. if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
  1134. tipc_link_proto_rcv(l_ptr, buf);
  1135. return;
  1136. }
  1137. /* Record OOS packet arrival */
  1138. l_ptr->silent_intv_cnt = 0;
  1139. /*
  1140. * Discard packet if a duplicate; otherwise add it to deferred queue
  1141. * and notify peer of gap as per protocol specification
  1142. */
  1143. if (less(seq_no, l_ptr->rcv_nxt)) {
  1144. l_ptr->stats.duplicates++;
  1145. kfree_skb(buf);
  1146. return;
  1147. }
  1148. if (tipc_link_defer_pkt(&l_ptr->deferdq, buf)) {
  1149. l_ptr->stats.deferred_recv++;
  1150. if ((skb_queue_len(&l_ptr->deferdq) % TIPC_MIN_LINK_WIN) == 1)
  1151. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0);
  1152. } else {
  1153. l_ptr->stats.duplicates++;
  1154. }
  1155. }
  1156. /*
  1157. * Send protocol message to the other endpoint.
  1158. */
  1159. void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg,
  1160. u32 gap, u32 tolerance, u32 priority)
  1161. {
  1162. struct sk_buff *buf = NULL;
  1163. struct tipc_msg *msg = l_ptr->pmsg;
  1164. u32 msg_size = sizeof(l_ptr->proto_msg);
  1165. int r_flag;
  1166. u16 last_rcv;
  1167. /* Don't send protocol message during link failover */
  1168. if (l_ptr->flags & LINK_FAILINGOVER)
  1169. return;
  1170. /* Abort non-RESET send if communication with node is prohibited */
  1171. if ((tipc_node_blocked(l_ptr->owner)) && (msg_typ != RESET_MSG))
  1172. return;
  1173. /* Create protocol message with "out-of-sequence" sequence number */
  1174. msg_set_type(msg, msg_typ);
  1175. msg_set_net_plane(msg, l_ptr->net_plane);
  1176. msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
  1177. msg_set_last_bcast(msg, tipc_bclink_get_last_sent(l_ptr->owner->net));
  1178. if (msg_typ == STATE_MSG) {
  1179. u16 next_sent = l_ptr->snd_nxt;
  1180. if (!tipc_link_is_up(l_ptr))
  1181. return;
  1182. if (skb_queue_len(&l_ptr->backlogq))
  1183. next_sent = buf_seqno(skb_peek(&l_ptr->backlogq));
  1184. msg_set_next_sent(msg, next_sent);
  1185. if (!skb_queue_empty(&l_ptr->deferdq)) {
  1186. last_rcv = buf_seqno(skb_peek(&l_ptr->deferdq));
  1187. gap = mod(last_rcv - l_ptr->rcv_nxt);
  1188. }
  1189. msg_set_seq_gap(msg, gap);
  1190. if (gap)
  1191. l_ptr->stats.sent_nacks++;
  1192. msg_set_link_tolerance(msg, tolerance);
  1193. msg_set_linkprio(msg, priority);
  1194. msg_set_max_pkt(msg, l_ptr->mtu);
  1195. msg_set_ack(msg, mod(l_ptr->rcv_nxt - 1));
  1196. msg_set_probe(msg, probe_msg != 0);
  1197. if (probe_msg)
  1198. l_ptr->stats.sent_probes++;
  1199. l_ptr->stats.sent_states++;
  1200. } else { /* RESET_MSG or ACTIVATE_MSG */
  1201. msg_set_ack(msg, mod(l_ptr->failover_checkpt - 1));
  1202. msg_set_seq_gap(msg, 0);
  1203. msg_set_next_sent(msg, 1);
  1204. msg_set_probe(msg, 0);
  1205. msg_set_link_tolerance(msg, l_ptr->tolerance);
  1206. msg_set_linkprio(msg, l_ptr->priority);
  1207. msg_set_max_pkt(msg, l_ptr->advertised_mtu);
  1208. }
  1209. r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
  1210. msg_set_redundant_link(msg, r_flag);
  1211. msg_set_linkprio(msg, l_ptr->priority);
  1212. msg_set_size(msg, msg_size);
  1213. msg_set_seqno(msg, mod(l_ptr->snd_nxt + (0xffff / 2)));
  1214. buf = tipc_buf_acquire(msg_size);
  1215. if (!buf)
  1216. return;
  1217. skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
  1218. buf->priority = TC_PRIO_CONTROL;
  1219. tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, buf,
  1220. &l_ptr->media_addr);
  1221. l_ptr->rcv_unacked = 0;
  1222. kfree_skb(buf);
  1223. }
  1224. /*
  1225. * Receive protocol message :
  1226. * Note that network plane id propagates through the network, and may
  1227. * change at any time. The node with lowest address rules
  1228. */
  1229. static void tipc_link_proto_rcv(struct tipc_link *l_ptr,
  1230. struct sk_buff *buf)
  1231. {
  1232. u32 rec_gap = 0;
  1233. u32 msg_tol;
  1234. struct tipc_msg *msg = buf_msg(buf);
  1235. if (l_ptr->flags & LINK_FAILINGOVER)
  1236. goto exit;
  1237. if (l_ptr->net_plane != msg_net_plane(msg))
  1238. if (link_own_addr(l_ptr) > msg_prevnode(msg))
  1239. l_ptr->net_plane = msg_net_plane(msg);
  1240. switch (msg_type(msg)) {
  1241. case RESET_MSG:
  1242. if (!link_working_unknown(l_ptr) &&
  1243. (l_ptr->peer_session != INVALID_SESSION)) {
  1244. if (less_eq(msg_session(msg), l_ptr->peer_session))
  1245. break; /* duplicate or old reset: ignore */
  1246. }
  1247. if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
  1248. link_working_unknown(l_ptr))) {
  1249. /*
  1250. * peer has lost contact -- don't allow peer's links
  1251. * to reactivate before we recognize loss & clean up
  1252. */
  1253. l_ptr->owner->action_flags |= TIPC_WAIT_OWN_LINKS_DOWN;
  1254. }
  1255. link_state_event(l_ptr, RESET_MSG);
  1256. /* fall thru' */
  1257. case ACTIVATE_MSG:
  1258. /* Update link settings according other endpoint's values */
  1259. strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
  1260. msg_tol = msg_link_tolerance(msg);
  1261. if (msg_tol > l_ptr->tolerance)
  1262. link_set_supervision_props(l_ptr, msg_tol);
  1263. if (msg_linkprio(msg) > l_ptr->priority)
  1264. l_ptr->priority = msg_linkprio(msg);
  1265. if (l_ptr->mtu > msg_max_pkt(msg))
  1266. l_ptr->mtu = msg_max_pkt(msg);
  1267. /* Synchronize broadcast link info, if not done previously */
  1268. if (!tipc_node_is_up(l_ptr->owner)) {
  1269. l_ptr->owner->bclink.last_sent =
  1270. l_ptr->owner->bclink.last_in =
  1271. msg_last_bcast(msg);
  1272. l_ptr->owner->bclink.oos_state = 0;
  1273. }
  1274. l_ptr->peer_session = msg_session(msg);
  1275. l_ptr->peer_bearer_id = msg_bearer_id(msg);
  1276. if (msg_type(msg) == ACTIVATE_MSG)
  1277. link_state_event(l_ptr, ACTIVATE_MSG);
  1278. break;
  1279. case STATE_MSG:
  1280. msg_tol = msg_link_tolerance(msg);
  1281. if (msg_tol)
  1282. link_set_supervision_props(l_ptr, msg_tol);
  1283. if (msg_linkprio(msg) &&
  1284. (msg_linkprio(msg) != l_ptr->priority)) {
  1285. pr_debug("%s<%s>, priority change %u->%u\n",
  1286. link_rst_msg, l_ptr->name,
  1287. l_ptr->priority, msg_linkprio(msg));
  1288. l_ptr->priority = msg_linkprio(msg);
  1289. tipc_link_reset(l_ptr); /* Enforce change to take effect */
  1290. break;
  1291. }
  1292. /* Record reception; force mismatch at next timeout: */
  1293. l_ptr->silent_intv_cnt = 0;
  1294. link_state_event(l_ptr, TRAFFIC_MSG_EVT);
  1295. l_ptr->stats.recv_states++;
  1296. if (link_reset_unknown(l_ptr))
  1297. break;
  1298. if (less_eq(l_ptr->rcv_nxt, msg_next_sent(msg)))
  1299. rec_gap = mod(msg_next_sent(msg) - l_ptr->rcv_nxt);
  1300. if (msg_probe(msg))
  1301. l_ptr->stats.recv_probes++;
  1302. /* Protocol message before retransmits, reduce loss risk */
  1303. if (l_ptr->owner->bclink.recv_permitted)
  1304. tipc_bclink_update_link_state(l_ptr->owner,
  1305. msg_last_bcast(msg));
  1306. if (rec_gap || (msg_probe(msg))) {
  1307. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0,
  1308. rec_gap, 0, 0);
  1309. }
  1310. if (msg_seq_gap(msg)) {
  1311. l_ptr->stats.recv_nacks++;
  1312. tipc_link_retransmit(l_ptr, skb_peek(&l_ptr->transmq),
  1313. msg_seq_gap(msg));
  1314. }
  1315. break;
  1316. }
  1317. exit:
  1318. kfree_skb(buf);
  1319. }
  1320. /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
  1321. * a different bearer. Owner node is locked.
  1322. */
  1323. static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
  1324. struct tipc_msg *tunnel_hdr,
  1325. struct tipc_msg *msg,
  1326. u32 selector)
  1327. {
  1328. struct tipc_link *tunnel;
  1329. struct sk_buff *skb;
  1330. u32 length = msg_size(msg);
  1331. tunnel = l_ptr->owner->active_links[selector & 1];
  1332. if (!tipc_link_is_up(tunnel)) {
  1333. pr_warn("%stunnel link no longer available\n", link_co_err);
  1334. return;
  1335. }
  1336. msg_set_size(tunnel_hdr, length + INT_H_SIZE);
  1337. skb = tipc_buf_acquire(length + INT_H_SIZE);
  1338. if (!skb) {
  1339. pr_warn("%sunable to send tunnel msg\n", link_co_err);
  1340. return;
  1341. }
  1342. skb_copy_to_linear_data(skb, tunnel_hdr, INT_H_SIZE);
  1343. skb_copy_to_linear_data_offset(skb, INT_H_SIZE, msg, length);
  1344. __tipc_link_xmit_skb(tunnel, skb);
  1345. }
  1346. /* tipc_link_failover_send_queue(): A link has gone down, but a second
  1347. * link is still active. We can do failover. Tunnel the failing link's
  1348. * whole send queue via the remaining link. This way, we don't lose
  1349. * any packets, and sequence order is preserved for subsequent traffic
  1350. * sent over the remaining link. Owner node is locked.
  1351. */
  1352. void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
  1353. {
  1354. int msgcount;
  1355. struct tipc_link *tunnel = l_ptr->owner->active_links[0];
  1356. struct tipc_msg tunnel_hdr;
  1357. struct sk_buff *skb;
  1358. int split_bundles;
  1359. if (!tunnel)
  1360. return;
  1361. tipc_msg_init(link_own_addr(l_ptr), &tunnel_hdr, TUNNEL_PROTOCOL,
  1362. FAILOVER_MSG, INT_H_SIZE, l_ptr->addr);
  1363. skb_queue_walk(&l_ptr->backlogq, skb) {
  1364. msg_set_seqno(buf_msg(skb), l_ptr->snd_nxt);
  1365. l_ptr->snd_nxt = mod(l_ptr->snd_nxt + 1);
  1366. }
  1367. skb_queue_splice_tail_init(&l_ptr->backlogq, &l_ptr->transmq);
  1368. tipc_link_purge_backlog(l_ptr);
  1369. msgcount = skb_queue_len(&l_ptr->transmq);
  1370. msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
  1371. msg_set_msgcnt(&tunnel_hdr, msgcount);
  1372. if (skb_queue_empty(&l_ptr->transmq)) {
  1373. skb = tipc_buf_acquire(INT_H_SIZE);
  1374. if (skb) {
  1375. skb_copy_to_linear_data(skb, &tunnel_hdr, INT_H_SIZE);
  1376. msg_set_size(&tunnel_hdr, INT_H_SIZE);
  1377. __tipc_link_xmit_skb(tunnel, skb);
  1378. } else {
  1379. pr_warn("%sunable to send changeover msg\n",
  1380. link_co_err);
  1381. }
  1382. return;
  1383. }
  1384. split_bundles = (l_ptr->owner->active_links[0] !=
  1385. l_ptr->owner->active_links[1]);
  1386. skb_queue_walk(&l_ptr->transmq, skb) {
  1387. struct tipc_msg *msg = buf_msg(skb);
  1388. if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
  1389. struct tipc_msg *m = msg_get_wrapped(msg);
  1390. unchar *pos = (unchar *)m;
  1391. msgcount = msg_msgcnt(msg);
  1392. while (msgcount--) {
  1393. msg_set_seqno(m, msg_seqno(msg));
  1394. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m,
  1395. msg_link_selector(m));
  1396. pos += align(msg_size(m));
  1397. m = (struct tipc_msg *)pos;
  1398. }
  1399. } else {
  1400. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg,
  1401. msg_link_selector(msg));
  1402. }
  1403. }
  1404. }
  1405. /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
  1406. * duplicate of the first link's send queue via the new link. This way, we
  1407. * are guaranteed that currently queued packets from a socket are delivered
  1408. * before future traffic from the same socket, even if this is using the
  1409. * new link. The last arriving copy of each duplicate packet is dropped at
  1410. * the receiving end by the regular protocol check, so packet cardinality
  1411. * and sequence order is preserved per sender/receiver socket pair.
  1412. * Owner node is locked.
  1413. */
  1414. void tipc_link_dup_queue_xmit(struct tipc_link *link,
  1415. struct tipc_link *tnl)
  1416. {
  1417. struct sk_buff *skb;
  1418. struct tipc_msg tnl_hdr;
  1419. struct sk_buff_head *queue = &link->transmq;
  1420. int mcnt;
  1421. u16 seqno;
  1422. tipc_msg_init(link_own_addr(link), &tnl_hdr, TUNNEL_PROTOCOL,
  1423. SYNCH_MSG, INT_H_SIZE, link->addr);
  1424. mcnt = skb_queue_len(&link->transmq) + skb_queue_len(&link->backlogq);
  1425. msg_set_msgcnt(&tnl_hdr, mcnt);
  1426. msg_set_bearer_id(&tnl_hdr, link->peer_bearer_id);
  1427. tunnel_queue:
  1428. skb_queue_walk(queue, skb) {
  1429. struct sk_buff *outskb;
  1430. struct tipc_msg *msg = buf_msg(skb);
  1431. u32 len = msg_size(msg);
  1432. msg_set_ack(msg, mod(link->rcv_nxt - 1));
  1433. msg_set_bcast_ack(msg, link->owner->bclink.last_in);
  1434. msg_set_size(&tnl_hdr, len + INT_H_SIZE);
  1435. outskb = tipc_buf_acquire(len + INT_H_SIZE);
  1436. if (outskb == NULL) {
  1437. pr_warn("%sunable to send duplicate msg\n",
  1438. link_co_err);
  1439. return;
  1440. }
  1441. skb_copy_to_linear_data(outskb, &tnl_hdr, INT_H_SIZE);
  1442. skb_copy_to_linear_data_offset(outskb, INT_H_SIZE,
  1443. skb->data, len);
  1444. __tipc_link_xmit_skb(tnl, outskb);
  1445. if (!tipc_link_is_up(link))
  1446. return;
  1447. }
  1448. if (queue == &link->backlogq)
  1449. return;
  1450. seqno = link->snd_nxt;
  1451. skb_queue_walk(&link->backlogq, skb) {
  1452. msg_set_seqno(buf_msg(skb), seqno);
  1453. seqno = mod(seqno + 1);
  1454. }
  1455. queue = &link->backlogq;
  1456. goto tunnel_queue;
  1457. }
  1458. /* tipc_link_failover_rcv(): Receive a tunnelled FAILOVER_MSG packet
  1459. * Owner node is locked.
  1460. */
  1461. static bool tipc_link_failover_rcv(struct tipc_link *link,
  1462. struct sk_buff **skb)
  1463. {
  1464. struct tipc_msg *msg = buf_msg(*skb);
  1465. struct sk_buff *iskb = NULL;
  1466. struct tipc_link *pl = NULL;
  1467. int bearer_id = msg_bearer_id(msg);
  1468. int pos = 0;
  1469. if (msg_type(msg) != FAILOVER_MSG) {
  1470. pr_warn("%sunknown tunnel pkt received\n", link_co_err);
  1471. goto exit;
  1472. }
  1473. if (bearer_id >= MAX_BEARERS)
  1474. goto exit;
  1475. if (bearer_id == link->bearer_id)
  1476. goto exit;
  1477. pl = link->owner->links[bearer_id];
  1478. if (pl && tipc_link_is_up(pl))
  1479. tipc_link_reset(pl);
  1480. if (link->failover_pkts == FIRST_FAILOVER)
  1481. link->failover_pkts = msg_msgcnt(msg);
  1482. /* Should we expect an inner packet? */
  1483. if (!link->failover_pkts)
  1484. goto exit;
  1485. if (!tipc_msg_extract(*skb, &iskb, &pos)) {
  1486. pr_warn("%sno inner failover pkt\n", link_co_err);
  1487. *skb = NULL;
  1488. goto exit;
  1489. }
  1490. link->failover_pkts--;
  1491. *skb = NULL;
  1492. /* Was this packet already delivered? */
  1493. if (less(buf_seqno(iskb), link->failover_checkpt)) {
  1494. kfree_skb(iskb);
  1495. iskb = NULL;
  1496. goto exit;
  1497. }
  1498. if (msg_user(buf_msg(iskb)) == MSG_FRAGMENTER) {
  1499. link->stats.recv_fragments++;
  1500. tipc_buf_append(&link->failover_skb, &iskb);
  1501. }
  1502. exit:
  1503. if (!link->failover_pkts && pl)
  1504. pl->flags &= ~LINK_FAILINGOVER;
  1505. kfree_skb(*skb);
  1506. *skb = iskb;
  1507. return *skb;
  1508. }
  1509. static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol)
  1510. {
  1511. unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4;
  1512. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  1513. return;
  1514. l_ptr->tolerance = tol;
  1515. l_ptr->keepalive_intv = msecs_to_jiffies(intv);
  1516. l_ptr->abort_limit = tol / (jiffies_to_msecs(l_ptr->keepalive_intv));
  1517. }
  1518. void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
  1519. {
  1520. int max_bulk = TIPC_MAX_PUBLICATIONS / (l->mtu / ITEM_SIZE);
  1521. l->window = win;
  1522. l->backlog[TIPC_LOW_IMPORTANCE].limit = win / 2;
  1523. l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = win;
  1524. l->backlog[TIPC_HIGH_IMPORTANCE].limit = win / 2 * 3;
  1525. l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = win * 2;
  1526. l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
  1527. }
  1528. /* tipc_link_find_owner - locate owner node of link by link's name
  1529. * @net: the applicable net namespace
  1530. * @name: pointer to link name string
  1531. * @bearer_id: pointer to index in 'node->links' array where the link was found.
  1532. *
  1533. * Returns pointer to node owning the link, or 0 if no matching link is found.
  1534. */
  1535. static struct tipc_node *tipc_link_find_owner(struct net *net,
  1536. const char *link_name,
  1537. unsigned int *bearer_id)
  1538. {
  1539. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1540. struct tipc_link *l_ptr;
  1541. struct tipc_node *n_ptr;
  1542. struct tipc_node *found_node = NULL;
  1543. int i;
  1544. *bearer_id = 0;
  1545. rcu_read_lock();
  1546. list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
  1547. tipc_node_lock(n_ptr);
  1548. for (i = 0; i < MAX_BEARERS; i++) {
  1549. l_ptr = n_ptr->links[i];
  1550. if (l_ptr && !strcmp(l_ptr->name, link_name)) {
  1551. *bearer_id = i;
  1552. found_node = n_ptr;
  1553. break;
  1554. }
  1555. }
  1556. tipc_node_unlock(n_ptr);
  1557. if (found_node)
  1558. break;
  1559. }
  1560. rcu_read_unlock();
  1561. return found_node;
  1562. }
  1563. /**
  1564. * link_reset_statistics - reset link statistics
  1565. * @l_ptr: pointer to link
  1566. */
  1567. static void link_reset_statistics(struct tipc_link *l_ptr)
  1568. {
  1569. memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
  1570. l_ptr->stats.sent_info = l_ptr->snd_nxt;
  1571. l_ptr->stats.recv_info = l_ptr->rcv_nxt;
  1572. }
  1573. static void link_print(struct tipc_link *l_ptr, const char *str)
  1574. {
  1575. struct tipc_net *tn = net_generic(l_ptr->owner->net, tipc_net_id);
  1576. struct tipc_bearer *b_ptr;
  1577. rcu_read_lock();
  1578. b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]);
  1579. if (b_ptr)
  1580. pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name);
  1581. rcu_read_unlock();
  1582. if (link_working_unknown(l_ptr))
  1583. pr_cont(":WU\n");
  1584. else if (link_reset_reset(l_ptr))
  1585. pr_cont(":RR\n");
  1586. else if (link_reset_unknown(l_ptr))
  1587. pr_cont(":RU\n");
  1588. else if (link_working_working(l_ptr))
  1589. pr_cont(":WW\n");
  1590. else
  1591. pr_cont("\n");
  1592. }
  1593. /* Parse and validate nested (link) properties valid for media, bearer and link
  1594. */
  1595. int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
  1596. {
  1597. int err;
  1598. err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop,
  1599. tipc_nl_prop_policy);
  1600. if (err)
  1601. return err;
  1602. if (props[TIPC_NLA_PROP_PRIO]) {
  1603. u32 prio;
  1604. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1605. if (prio > TIPC_MAX_LINK_PRI)
  1606. return -EINVAL;
  1607. }
  1608. if (props[TIPC_NLA_PROP_TOL]) {
  1609. u32 tol;
  1610. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1611. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  1612. return -EINVAL;
  1613. }
  1614. if (props[TIPC_NLA_PROP_WIN]) {
  1615. u32 win;
  1616. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1617. if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))
  1618. return -EINVAL;
  1619. }
  1620. return 0;
  1621. }
  1622. int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info)
  1623. {
  1624. int err;
  1625. int res = 0;
  1626. int bearer_id;
  1627. char *name;
  1628. struct tipc_link *link;
  1629. struct tipc_node *node;
  1630. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1631. struct net *net = sock_net(skb->sk);
  1632. if (!info->attrs[TIPC_NLA_LINK])
  1633. return -EINVAL;
  1634. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1635. info->attrs[TIPC_NLA_LINK],
  1636. tipc_nl_link_policy);
  1637. if (err)
  1638. return err;
  1639. if (!attrs[TIPC_NLA_LINK_NAME])
  1640. return -EINVAL;
  1641. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1642. if (strcmp(name, tipc_bclink_name) == 0)
  1643. return tipc_nl_bc_link_set(net, attrs);
  1644. node = tipc_link_find_owner(net, name, &bearer_id);
  1645. if (!node)
  1646. return -EINVAL;
  1647. tipc_node_lock(node);
  1648. link = node->links[bearer_id];
  1649. if (!link) {
  1650. res = -EINVAL;
  1651. goto out;
  1652. }
  1653. if (attrs[TIPC_NLA_LINK_PROP]) {
  1654. struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
  1655. err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
  1656. props);
  1657. if (err) {
  1658. res = err;
  1659. goto out;
  1660. }
  1661. if (props[TIPC_NLA_PROP_TOL]) {
  1662. u32 tol;
  1663. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1664. link_set_supervision_props(link, tol);
  1665. tipc_link_proto_xmit(link, STATE_MSG, 0, 0, tol, 0);
  1666. }
  1667. if (props[TIPC_NLA_PROP_PRIO]) {
  1668. u32 prio;
  1669. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1670. link->priority = prio;
  1671. tipc_link_proto_xmit(link, STATE_MSG, 0, 0, 0, prio);
  1672. }
  1673. if (props[TIPC_NLA_PROP_WIN]) {
  1674. u32 win;
  1675. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1676. tipc_link_set_queue_limits(link, win);
  1677. }
  1678. }
  1679. out:
  1680. tipc_node_unlock(node);
  1681. return res;
  1682. }
  1683. static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
  1684. {
  1685. int i;
  1686. struct nlattr *stats;
  1687. struct nla_map {
  1688. u32 key;
  1689. u32 val;
  1690. };
  1691. struct nla_map map[] = {
  1692. {TIPC_NLA_STATS_RX_INFO, s->recv_info},
  1693. {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
  1694. {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
  1695. {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
  1696. {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
  1697. {TIPC_NLA_STATS_TX_INFO, s->sent_info},
  1698. {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
  1699. {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
  1700. {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
  1701. {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
  1702. {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
  1703. s->msg_length_counts : 1},
  1704. {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
  1705. {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
  1706. {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
  1707. {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
  1708. {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
  1709. {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
  1710. {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
  1711. {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
  1712. {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
  1713. {TIPC_NLA_STATS_RX_STATES, s->recv_states},
  1714. {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
  1715. {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
  1716. {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
  1717. {TIPC_NLA_STATS_TX_STATES, s->sent_states},
  1718. {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
  1719. {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
  1720. {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
  1721. {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
  1722. {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
  1723. {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
  1724. {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
  1725. {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
  1726. (s->accu_queue_sz / s->queue_sz_counts) : 0}
  1727. };
  1728. stats = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
  1729. if (!stats)
  1730. return -EMSGSIZE;
  1731. for (i = 0; i < ARRAY_SIZE(map); i++)
  1732. if (nla_put_u32(skb, map[i].key, map[i].val))
  1733. goto msg_full;
  1734. nla_nest_end(skb, stats);
  1735. return 0;
  1736. msg_full:
  1737. nla_nest_cancel(skb, stats);
  1738. return -EMSGSIZE;
  1739. }
  1740. /* Caller should hold appropriate locks to protect the link */
  1741. static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
  1742. struct tipc_link *link, int nlflags)
  1743. {
  1744. int err;
  1745. void *hdr;
  1746. struct nlattr *attrs;
  1747. struct nlattr *prop;
  1748. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1749. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1750. nlflags, TIPC_NL_LINK_GET);
  1751. if (!hdr)
  1752. return -EMSGSIZE;
  1753. attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
  1754. if (!attrs)
  1755. goto msg_full;
  1756. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
  1757. goto attr_msg_full;
  1758. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST,
  1759. tipc_cluster_mask(tn->own_addr)))
  1760. goto attr_msg_full;
  1761. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
  1762. goto attr_msg_full;
  1763. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->rcv_nxt))
  1764. goto attr_msg_full;
  1765. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->snd_nxt))
  1766. goto attr_msg_full;
  1767. if (tipc_link_is_up(link))
  1768. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  1769. goto attr_msg_full;
  1770. if (tipc_link_is_active(link))
  1771. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
  1772. goto attr_msg_full;
  1773. prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
  1774. if (!prop)
  1775. goto attr_msg_full;
  1776. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1777. goto prop_msg_full;
  1778. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
  1779. goto prop_msg_full;
  1780. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
  1781. link->window))
  1782. goto prop_msg_full;
  1783. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1784. goto prop_msg_full;
  1785. nla_nest_end(msg->skb, prop);
  1786. err = __tipc_nl_add_stats(msg->skb, &link->stats);
  1787. if (err)
  1788. goto attr_msg_full;
  1789. nla_nest_end(msg->skb, attrs);
  1790. genlmsg_end(msg->skb, hdr);
  1791. return 0;
  1792. prop_msg_full:
  1793. nla_nest_cancel(msg->skb, prop);
  1794. attr_msg_full:
  1795. nla_nest_cancel(msg->skb, attrs);
  1796. msg_full:
  1797. genlmsg_cancel(msg->skb, hdr);
  1798. return -EMSGSIZE;
  1799. }
  1800. /* Caller should hold node lock */
  1801. static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
  1802. struct tipc_node *node, u32 *prev_link)
  1803. {
  1804. u32 i;
  1805. int err;
  1806. for (i = *prev_link; i < MAX_BEARERS; i++) {
  1807. *prev_link = i;
  1808. if (!node->links[i])
  1809. continue;
  1810. err = __tipc_nl_add_link(net, msg, node->links[i], NLM_F_MULTI);
  1811. if (err)
  1812. return err;
  1813. }
  1814. *prev_link = 0;
  1815. return 0;
  1816. }
  1817. int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
  1818. {
  1819. struct net *net = sock_net(skb->sk);
  1820. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1821. struct tipc_node *node;
  1822. struct tipc_nl_msg msg;
  1823. u32 prev_node = cb->args[0];
  1824. u32 prev_link = cb->args[1];
  1825. int done = cb->args[2];
  1826. int err;
  1827. if (done)
  1828. return 0;
  1829. msg.skb = skb;
  1830. msg.portid = NETLINK_CB(cb->skb).portid;
  1831. msg.seq = cb->nlh->nlmsg_seq;
  1832. rcu_read_lock();
  1833. if (prev_node) {
  1834. node = tipc_node_find(net, prev_node);
  1835. if (!node) {
  1836. /* We never set seq or call nl_dump_check_consistent()
  1837. * this means that setting prev_seq here will cause the
  1838. * consistence check to fail in the netlink callback
  1839. * handler. Resulting in the last NLMSG_DONE message
  1840. * having the NLM_F_DUMP_INTR flag set.
  1841. */
  1842. cb->prev_seq = 1;
  1843. goto out;
  1844. }
  1845. tipc_node_put(node);
  1846. list_for_each_entry_continue_rcu(node, &tn->node_list,
  1847. list) {
  1848. tipc_node_lock(node);
  1849. err = __tipc_nl_add_node_links(net, &msg, node,
  1850. &prev_link);
  1851. tipc_node_unlock(node);
  1852. if (err)
  1853. goto out;
  1854. prev_node = node->addr;
  1855. }
  1856. } else {
  1857. err = tipc_nl_add_bc_link(net, &msg);
  1858. if (err)
  1859. goto out;
  1860. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1861. tipc_node_lock(node);
  1862. err = __tipc_nl_add_node_links(net, &msg, node,
  1863. &prev_link);
  1864. tipc_node_unlock(node);
  1865. if (err)
  1866. goto out;
  1867. prev_node = node->addr;
  1868. }
  1869. }
  1870. done = 1;
  1871. out:
  1872. rcu_read_unlock();
  1873. cb->args[0] = prev_node;
  1874. cb->args[1] = prev_link;
  1875. cb->args[2] = done;
  1876. return skb->len;
  1877. }
  1878. int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
  1879. {
  1880. struct net *net = genl_info_net(info);
  1881. struct tipc_nl_msg msg;
  1882. char *name;
  1883. int err;
  1884. msg.portid = info->snd_portid;
  1885. msg.seq = info->snd_seq;
  1886. if (!info->attrs[TIPC_NLA_LINK_NAME])
  1887. return -EINVAL;
  1888. name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]);
  1889. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1890. if (!msg.skb)
  1891. return -ENOMEM;
  1892. if (strcmp(name, tipc_bclink_name) == 0) {
  1893. err = tipc_nl_add_bc_link(net, &msg);
  1894. if (err) {
  1895. nlmsg_free(msg.skb);
  1896. return err;
  1897. }
  1898. } else {
  1899. int bearer_id;
  1900. struct tipc_node *node;
  1901. struct tipc_link *link;
  1902. node = tipc_link_find_owner(net, name, &bearer_id);
  1903. if (!node)
  1904. return -EINVAL;
  1905. tipc_node_lock(node);
  1906. link = node->links[bearer_id];
  1907. if (!link) {
  1908. tipc_node_unlock(node);
  1909. nlmsg_free(msg.skb);
  1910. return -EINVAL;
  1911. }
  1912. err = __tipc_nl_add_link(net, &msg, link, 0);
  1913. tipc_node_unlock(node);
  1914. if (err) {
  1915. nlmsg_free(msg.skb);
  1916. return err;
  1917. }
  1918. }
  1919. return genlmsg_reply(msg.skb, info);
  1920. }
  1921. int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info)
  1922. {
  1923. int err;
  1924. char *link_name;
  1925. unsigned int bearer_id;
  1926. struct tipc_link *link;
  1927. struct tipc_node *node;
  1928. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1929. struct net *net = sock_net(skb->sk);
  1930. if (!info->attrs[TIPC_NLA_LINK])
  1931. return -EINVAL;
  1932. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1933. info->attrs[TIPC_NLA_LINK],
  1934. tipc_nl_link_policy);
  1935. if (err)
  1936. return err;
  1937. if (!attrs[TIPC_NLA_LINK_NAME])
  1938. return -EINVAL;
  1939. link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1940. if (strcmp(link_name, tipc_bclink_name) == 0) {
  1941. err = tipc_bclink_reset_stats(net);
  1942. if (err)
  1943. return err;
  1944. return 0;
  1945. }
  1946. node = tipc_link_find_owner(net, link_name, &bearer_id);
  1947. if (!node)
  1948. return -EINVAL;
  1949. tipc_node_lock(node);
  1950. link = node->links[bearer_id];
  1951. if (!link) {
  1952. tipc_node_unlock(node);
  1953. return -EINVAL;
  1954. }
  1955. link_reset_statistics(link);
  1956. tipc_node_unlock(node);
  1957. return 0;
  1958. }