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