link.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  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. 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. msg_set_next_sent(msg, next_sent);
  1183. if (!skb_queue_empty(&l_ptr->deferdq)) {
  1184. last_rcv = buf_seqno(skb_peek(&l_ptr->deferdq));
  1185. gap = mod(last_rcv - l_ptr->rcv_nxt);
  1186. }
  1187. msg_set_seq_gap(msg, gap);
  1188. if (gap)
  1189. l_ptr->stats.sent_nacks++;
  1190. msg_set_link_tolerance(msg, tolerance);
  1191. msg_set_linkprio(msg, priority);
  1192. msg_set_max_pkt(msg, l_ptr->mtu);
  1193. msg_set_ack(msg, mod(l_ptr->rcv_nxt - 1));
  1194. msg_set_probe(msg, probe_msg != 0);
  1195. if (probe_msg)
  1196. l_ptr->stats.sent_probes++;
  1197. l_ptr->stats.sent_states++;
  1198. } else { /* RESET_MSG or ACTIVATE_MSG */
  1199. msg_set_ack(msg, mod(l_ptr->failover_checkpt - 1));
  1200. msg_set_seq_gap(msg, 0);
  1201. msg_set_next_sent(msg, 1);
  1202. msg_set_probe(msg, 0);
  1203. msg_set_link_tolerance(msg, l_ptr->tolerance);
  1204. msg_set_linkprio(msg, l_ptr->priority);
  1205. msg_set_max_pkt(msg, l_ptr->advertised_mtu);
  1206. }
  1207. r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
  1208. msg_set_redundant_link(msg, r_flag);
  1209. msg_set_linkprio(msg, l_ptr->priority);
  1210. msg_set_size(msg, msg_size);
  1211. msg_set_seqno(msg, mod(l_ptr->snd_nxt + (0xffff / 2)));
  1212. buf = tipc_buf_acquire(msg_size);
  1213. if (!buf)
  1214. return;
  1215. skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
  1216. buf->priority = TC_PRIO_CONTROL;
  1217. tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, buf,
  1218. &l_ptr->media_addr);
  1219. l_ptr->rcv_unacked = 0;
  1220. kfree_skb(buf);
  1221. }
  1222. /*
  1223. * Receive protocol message :
  1224. * Note that network plane id propagates through the network, and may
  1225. * change at any time. The node with lowest address rules
  1226. */
  1227. static void tipc_link_proto_rcv(struct tipc_link *l_ptr,
  1228. struct sk_buff *buf)
  1229. {
  1230. u32 rec_gap = 0;
  1231. u32 msg_tol;
  1232. struct tipc_msg *msg = buf_msg(buf);
  1233. if (l_ptr->flags & LINK_FAILINGOVER)
  1234. goto exit;
  1235. if (l_ptr->net_plane != msg_net_plane(msg))
  1236. if (link_own_addr(l_ptr) > msg_prevnode(msg))
  1237. l_ptr->net_plane = msg_net_plane(msg);
  1238. switch (msg_type(msg)) {
  1239. case RESET_MSG:
  1240. if (!link_working_unknown(l_ptr) &&
  1241. (l_ptr->peer_session != INVALID_SESSION)) {
  1242. if (less_eq(msg_session(msg), l_ptr->peer_session))
  1243. break; /* duplicate or old reset: ignore */
  1244. }
  1245. if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
  1246. link_working_unknown(l_ptr))) {
  1247. /*
  1248. * peer has lost contact -- don't allow peer's links
  1249. * to reactivate before we recognize loss & clean up
  1250. */
  1251. l_ptr->owner->action_flags |= TIPC_WAIT_OWN_LINKS_DOWN;
  1252. }
  1253. link_state_event(l_ptr, RESET_MSG);
  1254. /* fall thru' */
  1255. case ACTIVATE_MSG:
  1256. /* Update link settings according other endpoint's values */
  1257. strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
  1258. msg_tol = msg_link_tolerance(msg);
  1259. if (msg_tol > l_ptr->tolerance)
  1260. link_set_supervision_props(l_ptr, msg_tol);
  1261. if (msg_linkprio(msg) > l_ptr->priority)
  1262. l_ptr->priority = msg_linkprio(msg);
  1263. if (l_ptr->mtu > msg_max_pkt(msg))
  1264. l_ptr->mtu = msg_max_pkt(msg);
  1265. /* Synchronize broadcast link info, if not done previously */
  1266. if (!tipc_node_is_up(l_ptr->owner)) {
  1267. l_ptr->owner->bclink.last_sent =
  1268. l_ptr->owner->bclink.last_in =
  1269. msg_last_bcast(msg);
  1270. l_ptr->owner->bclink.oos_state = 0;
  1271. }
  1272. l_ptr->peer_session = msg_session(msg);
  1273. l_ptr->peer_bearer_id = msg_bearer_id(msg);
  1274. if (msg_type(msg) == ACTIVATE_MSG)
  1275. link_state_event(l_ptr, ACTIVATE_MSG);
  1276. break;
  1277. case STATE_MSG:
  1278. msg_tol = msg_link_tolerance(msg);
  1279. if (msg_tol)
  1280. link_set_supervision_props(l_ptr, msg_tol);
  1281. if (msg_linkprio(msg) &&
  1282. (msg_linkprio(msg) != l_ptr->priority)) {
  1283. pr_debug("%s<%s>, priority change %u->%u\n",
  1284. link_rst_msg, l_ptr->name,
  1285. l_ptr->priority, msg_linkprio(msg));
  1286. l_ptr->priority = msg_linkprio(msg);
  1287. tipc_link_reset(l_ptr); /* Enforce change to take effect */
  1288. break;
  1289. }
  1290. /* Record reception; force mismatch at next timeout: */
  1291. l_ptr->silent_intv_cnt = 0;
  1292. link_state_event(l_ptr, TRAFFIC_MSG_EVT);
  1293. l_ptr->stats.recv_states++;
  1294. if (link_reset_unknown(l_ptr))
  1295. break;
  1296. if (less_eq(l_ptr->rcv_nxt, msg_next_sent(msg)))
  1297. rec_gap = mod(msg_next_sent(msg) - l_ptr->rcv_nxt);
  1298. if (msg_probe(msg))
  1299. l_ptr->stats.recv_probes++;
  1300. /* Protocol message before retransmits, reduce loss risk */
  1301. if (l_ptr->owner->bclink.recv_permitted)
  1302. tipc_bclink_update_link_state(l_ptr->owner,
  1303. msg_last_bcast(msg));
  1304. if (rec_gap || (msg_probe(msg))) {
  1305. tipc_link_proto_xmit(l_ptr, STATE_MSG, 0,
  1306. rec_gap, 0, 0);
  1307. }
  1308. if (msg_seq_gap(msg)) {
  1309. l_ptr->stats.recv_nacks++;
  1310. tipc_link_retransmit(l_ptr, skb_peek(&l_ptr->transmq),
  1311. msg_seq_gap(msg));
  1312. }
  1313. break;
  1314. }
  1315. exit:
  1316. kfree_skb(buf);
  1317. }
  1318. /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to
  1319. * a different bearer. Owner node is locked.
  1320. */
  1321. static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr,
  1322. struct tipc_msg *tunnel_hdr,
  1323. struct tipc_msg *msg,
  1324. u32 selector)
  1325. {
  1326. struct tipc_link *tunnel;
  1327. struct sk_buff *skb;
  1328. u32 length = msg_size(msg);
  1329. tunnel = l_ptr->owner->active_links[selector & 1];
  1330. if (!tipc_link_is_up(tunnel)) {
  1331. pr_warn("%stunnel link no longer available\n", link_co_err);
  1332. return;
  1333. }
  1334. msg_set_size(tunnel_hdr, length + INT_H_SIZE);
  1335. skb = tipc_buf_acquire(length + INT_H_SIZE);
  1336. if (!skb) {
  1337. pr_warn("%sunable to send tunnel msg\n", link_co_err);
  1338. return;
  1339. }
  1340. skb_copy_to_linear_data(skb, tunnel_hdr, INT_H_SIZE);
  1341. skb_copy_to_linear_data_offset(skb, INT_H_SIZE, msg, length);
  1342. __tipc_link_xmit_skb(tunnel, skb);
  1343. }
  1344. /* tipc_link_failover_send_queue(): A link has gone down, but a second
  1345. * link is still active. We can do failover. Tunnel the failing link's
  1346. * whole send queue via the remaining link. This way, we don't lose
  1347. * any packets, and sequence order is preserved for subsequent traffic
  1348. * sent over the remaining link. Owner node is locked.
  1349. */
  1350. void tipc_link_failover_send_queue(struct tipc_link *l_ptr)
  1351. {
  1352. int msgcount;
  1353. struct tipc_link *tunnel = l_ptr->owner->active_links[0];
  1354. struct tipc_msg tunnel_hdr;
  1355. struct sk_buff *skb;
  1356. int split_bundles;
  1357. if (!tunnel)
  1358. return;
  1359. tipc_msg_init(link_own_addr(l_ptr), &tunnel_hdr, TUNNEL_PROTOCOL,
  1360. FAILOVER_MSG, INT_H_SIZE, l_ptr->addr);
  1361. skb_queue_walk(&l_ptr->backlogq, skb) {
  1362. msg_set_seqno(buf_msg(skb), l_ptr->snd_nxt);
  1363. l_ptr->snd_nxt = mod(l_ptr->snd_nxt + 1);
  1364. }
  1365. skb_queue_splice_tail_init(&l_ptr->backlogq, &l_ptr->transmq);
  1366. tipc_link_purge_backlog(l_ptr);
  1367. msgcount = skb_queue_len(&l_ptr->transmq);
  1368. msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
  1369. msg_set_msgcnt(&tunnel_hdr, msgcount);
  1370. if (skb_queue_empty(&l_ptr->transmq)) {
  1371. skb = tipc_buf_acquire(INT_H_SIZE);
  1372. if (skb) {
  1373. skb_copy_to_linear_data(skb, &tunnel_hdr, INT_H_SIZE);
  1374. msg_set_size(&tunnel_hdr, INT_H_SIZE);
  1375. __tipc_link_xmit_skb(tunnel, skb);
  1376. } else {
  1377. pr_warn("%sunable to send changeover msg\n",
  1378. link_co_err);
  1379. }
  1380. return;
  1381. }
  1382. split_bundles = (l_ptr->owner->active_links[0] !=
  1383. l_ptr->owner->active_links[1]);
  1384. skb_queue_walk(&l_ptr->transmq, skb) {
  1385. struct tipc_msg *msg = buf_msg(skb);
  1386. if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
  1387. struct tipc_msg *m = msg_get_wrapped(msg);
  1388. unchar *pos = (unchar *)m;
  1389. msgcount = msg_msgcnt(msg);
  1390. while (msgcount--) {
  1391. msg_set_seqno(m, msg_seqno(msg));
  1392. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m,
  1393. msg_link_selector(m));
  1394. pos += align(msg_size(m));
  1395. m = (struct tipc_msg *)pos;
  1396. }
  1397. } else {
  1398. tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg,
  1399. msg_link_selector(msg));
  1400. }
  1401. }
  1402. }
  1403. /* tipc_link_dup_queue_xmit(): A second link has become active. Tunnel a
  1404. * duplicate of the first link's send queue via the new link. This way, we
  1405. * are guaranteed that currently queued packets from a socket are delivered
  1406. * before future traffic from the same socket, even if this is using the
  1407. * new link. The last arriving copy of each duplicate packet is dropped at
  1408. * the receiving end by the regular protocol check, so packet cardinality
  1409. * and sequence order is preserved per sender/receiver socket pair.
  1410. * Owner node is locked.
  1411. */
  1412. void tipc_link_dup_queue_xmit(struct tipc_link *link,
  1413. struct tipc_link *tnl)
  1414. {
  1415. struct sk_buff *skb;
  1416. struct tipc_msg tnl_hdr;
  1417. struct sk_buff_head *queue = &link->transmq;
  1418. int mcnt;
  1419. u16 seqno;
  1420. tipc_msg_init(link_own_addr(link), &tnl_hdr, TUNNEL_PROTOCOL,
  1421. SYNCH_MSG, INT_H_SIZE, link->addr);
  1422. mcnt = skb_queue_len(&link->transmq) + skb_queue_len(&link->backlogq);
  1423. msg_set_msgcnt(&tnl_hdr, mcnt);
  1424. msg_set_bearer_id(&tnl_hdr, link->peer_bearer_id);
  1425. tunnel_queue:
  1426. skb_queue_walk(queue, skb) {
  1427. struct sk_buff *outskb;
  1428. struct tipc_msg *msg = buf_msg(skb);
  1429. u32 len = msg_size(msg);
  1430. msg_set_ack(msg, mod(link->rcv_nxt - 1));
  1431. msg_set_bcast_ack(msg, link->owner->bclink.last_in);
  1432. msg_set_size(&tnl_hdr, len + INT_H_SIZE);
  1433. outskb = tipc_buf_acquire(len + INT_H_SIZE);
  1434. if (outskb == NULL) {
  1435. pr_warn("%sunable to send duplicate msg\n",
  1436. link_co_err);
  1437. return;
  1438. }
  1439. skb_copy_to_linear_data(outskb, &tnl_hdr, INT_H_SIZE);
  1440. skb_copy_to_linear_data_offset(outskb, INT_H_SIZE,
  1441. skb->data, len);
  1442. __tipc_link_xmit_skb(tnl, outskb);
  1443. if (!tipc_link_is_up(link))
  1444. return;
  1445. }
  1446. if (queue == &link->backlogq)
  1447. return;
  1448. seqno = link->snd_nxt;
  1449. skb_queue_walk(&link->backlogq, skb) {
  1450. msg_set_seqno(buf_msg(skb), seqno);
  1451. seqno = mod(seqno + 1);
  1452. }
  1453. queue = &link->backlogq;
  1454. goto tunnel_queue;
  1455. }
  1456. /* tipc_link_failover_rcv(): Receive a tunnelled FAILOVER_MSG packet
  1457. * Owner node is locked.
  1458. */
  1459. static bool tipc_link_failover_rcv(struct tipc_link *link,
  1460. struct sk_buff **skb)
  1461. {
  1462. struct tipc_msg *msg = buf_msg(*skb);
  1463. struct sk_buff *iskb = NULL;
  1464. struct tipc_link *pl = NULL;
  1465. int bearer_id = msg_bearer_id(msg);
  1466. int pos = 0;
  1467. if (msg_type(msg) != FAILOVER_MSG) {
  1468. pr_warn("%sunknown tunnel pkt received\n", link_co_err);
  1469. goto exit;
  1470. }
  1471. if (bearer_id >= MAX_BEARERS)
  1472. goto exit;
  1473. if (bearer_id == link->bearer_id)
  1474. goto exit;
  1475. pl = link->owner->links[bearer_id];
  1476. if (pl && tipc_link_is_up(pl))
  1477. tipc_link_reset(pl);
  1478. if (link->failover_pkts == FIRST_FAILOVER)
  1479. link->failover_pkts = msg_msgcnt(msg);
  1480. /* Should we expect an inner packet? */
  1481. if (!link->failover_pkts)
  1482. goto exit;
  1483. if (!tipc_msg_extract(*skb, &iskb, &pos)) {
  1484. pr_warn("%sno inner failover pkt\n", link_co_err);
  1485. *skb = NULL;
  1486. goto exit;
  1487. }
  1488. link->failover_pkts--;
  1489. *skb = NULL;
  1490. /* Was this packet already delivered? */
  1491. if (less(buf_seqno(iskb), link->failover_checkpt)) {
  1492. kfree_skb(iskb);
  1493. iskb = NULL;
  1494. goto exit;
  1495. }
  1496. if (msg_user(buf_msg(iskb)) == MSG_FRAGMENTER) {
  1497. link->stats.recv_fragments++;
  1498. tipc_buf_append(&link->failover_skb, &iskb);
  1499. }
  1500. exit:
  1501. if (!link->failover_pkts && pl)
  1502. pl->flags &= ~LINK_FAILINGOVER;
  1503. kfree_skb(*skb);
  1504. *skb = iskb;
  1505. return *skb;
  1506. }
  1507. static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol)
  1508. {
  1509. unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4;
  1510. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  1511. return;
  1512. l_ptr->tolerance = tol;
  1513. l_ptr->keepalive_intv = msecs_to_jiffies(intv);
  1514. l_ptr->abort_limit = tol / (jiffies_to_msecs(l_ptr->keepalive_intv));
  1515. }
  1516. void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
  1517. {
  1518. int max_bulk = TIPC_MAX_PUBLICATIONS / (l->mtu / ITEM_SIZE);
  1519. l->window = win;
  1520. l->backlog[TIPC_LOW_IMPORTANCE].limit = win / 2;
  1521. l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = win;
  1522. l->backlog[TIPC_HIGH_IMPORTANCE].limit = win / 2 * 3;
  1523. l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = win * 2;
  1524. l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
  1525. }
  1526. /* tipc_link_find_owner - locate owner node of link by link's name
  1527. * @net: the applicable net namespace
  1528. * @name: pointer to link name string
  1529. * @bearer_id: pointer to index in 'node->links' array where the link was found.
  1530. *
  1531. * Returns pointer to node owning the link, or 0 if no matching link is found.
  1532. */
  1533. static struct tipc_node *tipc_link_find_owner(struct net *net,
  1534. const char *link_name,
  1535. unsigned int *bearer_id)
  1536. {
  1537. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1538. struct tipc_link *l_ptr;
  1539. struct tipc_node *n_ptr;
  1540. struct tipc_node *found_node = NULL;
  1541. int i;
  1542. *bearer_id = 0;
  1543. rcu_read_lock();
  1544. list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
  1545. tipc_node_lock(n_ptr);
  1546. for (i = 0; i < MAX_BEARERS; i++) {
  1547. l_ptr = n_ptr->links[i];
  1548. if (l_ptr && !strcmp(l_ptr->name, link_name)) {
  1549. *bearer_id = i;
  1550. found_node = n_ptr;
  1551. break;
  1552. }
  1553. }
  1554. tipc_node_unlock(n_ptr);
  1555. if (found_node)
  1556. break;
  1557. }
  1558. rcu_read_unlock();
  1559. return found_node;
  1560. }
  1561. /**
  1562. * link_reset_statistics - reset link statistics
  1563. * @l_ptr: pointer to link
  1564. */
  1565. static void link_reset_statistics(struct tipc_link *l_ptr)
  1566. {
  1567. memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
  1568. l_ptr->stats.sent_info = l_ptr->snd_nxt;
  1569. l_ptr->stats.recv_info = l_ptr->rcv_nxt;
  1570. }
  1571. static void link_print(struct tipc_link *l_ptr, const char *str)
  1572. {
  1573. struct tipc_net *tn = net_generic(l_ptr->owner->net, tipc_net_id);
  1574. struct tipc_bearer *b_ptr;
  1575. rcu_read_lock();
  1576. b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]);
  1577. if (b_ptr)
  1578. pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name);
  1579. rcu_read_unlock();
  1580. if (link_working_unknown(l_ptr))
  1581. pr_cont(":WU\n");
  1582. else if (link_reset_reset(l_ptr))
  1583. pr_cont(":RR\n");
  1584. else if (link_reset_unknown(l_ptr))
  1585. pr_cont(":RU\n");
  1586. else if (link_working_working(l_ptr))
  1587. pr_cont(":WW\n");
  1588. else
  1589. pr_cont("\n");
  1590. }
  1591. /* Parse and validate nested (link) properties valid for media, bearer and link
  1592. */
  1593. int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
  1594. {
  1595. int err;
  1596. err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop,
  1597. tipc_nl_prop_policy);
  1598. if (err)
  1599. return err;
  1600. if (props[TIPC_NLA_PROP_PRIO]) {
  1601. u32 prio;
  1602. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1603. if (prio > TIPC_MAX_LINK_PRI)
  1604. return -EINVAL;
  1605. }
  1606. if (props[TIPC_NLA_PROP_TOL]) {
  1607. u32 tol;
  1608. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1609. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  1610. return -EINVAL;
  1611. }
  1612. if (props[TIPC_NLA_PROP_WIN]) {
  1613. u32 win;
  1614. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1615. if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))
  1616. return -EINVAL;
  1617. }
  1618. return 0;
  1619. }
  1620. int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info)
  1621. {
  1622. int err;
  1623. int res = 0;
  1624. int bearer_id;
  1625. char *name;
  1626. struct tipc_link *link;
  1627. struct tipc_node *node;
  1628. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1629. struct net *net = sock_net(skb->sk);
  1630. if (!info->attrs[TIPC_NLA_LINK])
  1631. return -EINVAL;
  1632. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1633. info->attrs[TIPC_NLA_LINK],
  1634. tipc_nl_link_policy);
  1635. if (err)
  1636. return err;
  1637. if (!attrs[TIPC_NLA_LINK_NAME])
  1638. return -EINVAL;
  1639. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1640. if (strcmp(name, tipc_bclink_name) == 0)
  1641. return tipc_nl_bc_link_set(net, attrs);
  1642. node = tipc_link_find_owner(net, name, &bearer_id);
  1643. if (!node)
  1644. return -EINVAL;
  1645. tipc_node_lock(node);
  1646. link = node->links[bearer_id];
  1647. if (!link) {
  1648. res = -EINVAL;
  1649. goto out;
  1650. }
  1651. if (attrs[TIPC_NLA_LINK_PROP]) {
  1652. struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
  1653. err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
  1654. props);
  1655. if (err) {
  1656. res = err;
  1657. goto out;
  1658. }
  1659. if (props[TIPC_NLA_PROP_TOL]) {
  1660. u32 tol;
  1661. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1662. link_set_supervision_props(link, tol);
  1663. tipc_link_proto_xmit(link, STATE_MSG, 0, 0, tol, 0);
  1664. }
  1665. if (props[TIPC_NLA_PROP_PRIO]) {
  1666. u32 prio;
  1667. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1668. link->priority = prio;
  1669. tipc_link_proto_xmit(link, STATE_MSG, 0, 0, 0, prio);
  1670. }
  1671. if (props[TIPC_NLA_PROP_WIN]) {
  1672. u32 win;
  1673. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1674. tipc_link_set_queue_limits(link, win);
  1675. }
  1676. }
  1677. out:
  1678. tipc_node_unlock(node);
  1679. return res;
  1680. }
  1681. static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
  1682. {
  1683. int i;
  1684. struct nlattr *stats;
  1685. struct nla_map {
  1686. u32 key;
  1687. u32 val;
  1688. };
  1689. struct nla_map map[] = {
  1690. {TIPC_NLA_STATS_RX_INFO, s->recv_info},
  1691. {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
  1692. {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
  1693. {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
  1694. {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
  1695. {TIPC_NLA_STATS_TX_INFO, s->sent_info},
  1696. {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
  1697. {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
  1698. {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
  1699. {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
  1700. {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
  1701. s->msg_length_counts : 1},
  1702. {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
  1703. {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
  1704. {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
  1705. {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
  1706. {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
  1707. {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
  1708. {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
  1709. {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
  1710. {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
  1711. {TIPC_NLA_STATS_RX_STATES, s->recv_states},
  1712. {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
  1713. {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
  1714. {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
  1715. {TIPC_NLA_STATS_TX_STATES, s->sent_states},
  1716. {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
  1717. {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
  1718. {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
  1719. {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
  1720. {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
  1721. {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
  1722. {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
  1723. {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
  1724. (s->accu_queue_sz / s->queue_sz_counts) : 0}
  1725. };
  1726. stats = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
  1727. if (!stats)
  1728. return -EMSGSIZE;
  1729. for (i = 0; i < ARRAY_SIZE(map); i++)
  1730. if (nla_put_u32(skb, map[i].key, map[i].val))
  1731. goto msg_full;
  1732. nla_nest_end(skb, stats);
  1733. return 0;
  1734. msg_full:
  1735. nla_nest_cancel(skb, stats);
  1736. return -EMSGSIZE;
  1737. }
  1738. /* Caller should hold appropriate locks to protect the link */
  1739. static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
  1740. struct tipc_link *link, int nlflags)
  1741. {
  1742. int err;
  1743. void *hdr;
  1744. struct nlattr *attrs;
  1745. struct nlattr *prop;
  1746. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1747. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1748. nlflags, TIPC_NL_LINK_GET);
  1749. if (!hdr)
  1750. return -EMSGSIZE;
  1751. attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
  1752. if (!attrs)
  1753. goto msg_full;
  1754. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
  1755. goto attr_msg_full;
  1756. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST,
  1757. tipc_cluster_mask(tn->own_addr)))
  1758. goto attr_msg_full;
  1759. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
  1760. goto attr_msg_full;
  1761. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->rcv_nxt))
  1762. goto attr_msg_full;
  1763. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->snd_nxt))
  1764. goto attr_msg_full;
  1765. if (tipc_link_is_up(link))
  1766. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  1767. goto attr_msg_full;
  1768. if (tipc_link_is_active(link))
  1769. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
  1770. goto attr_msg_full;
  1771. prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
  1772. if (!prop)
  1773. goto attr_msg_full;
  1774. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1775. goto prop_msg_full;
  1776. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
  1777. goto prop_msg_full;
  1778. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
  1779. link->window))
  1780. goto prop_msg_full;
  1781. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1782. goto prop_msg_full;
  1783. nla_nest_end(msg->skb, prop);
  1784. err = __tipc_nl_add_stats(msg->skb, &link->stats);
  1785. if (err)
  1786. goto attr_msg_full;
  1787. nla_nest_end(msg->skb, attrs);
  1788. genlmsg_end(msg->skb, hdr);
  1789. return 0;
  1790. prop_msg_full:
  1791. nla_nest_cancel(msg->skb, prop);
  1792. attr_msg_full:
  1793. nla_nest_cancel(msg->skb, attrs);
  1794. msg_full:
  1795. genlmsg_cancel(msg->skb, hdr);
  1796. return -EMSGSIZE;
  1797. }
  1798. /* Caller should hold node lock */
  1799. static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
  1800. struct tipc_node *node, u32 *prev_link)
  1801. {
  1802. u32 i;
  1803. int err;
  1804. for (i = *prev_link; i < MAX_BEARERS; i++) {
  1805. *prev_link = i;
  1806. if (!node->links[i])
  1807. continue;
  1808. err = __tipc_nl_add_link(net, msg, node->links[i], NLM_F_MULTI);
  1809. if (err)
  1810. return err;
  1811. }
  1812. *prev_link = 0;
  1813. return 0;
  1814. }
  1815. int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
  1816. {
  1817. struct net *net = sock_net(skb->sk);
  1818. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1819. struct tipc_node *node;
  1820. struct tipc_nl_msg msg;
  1821. u32 prev_node = cb->args[0];
  1822. u32 prev_link = cb->args[1];
  1823. int done = cb->args[2];
  1824. int err;
  1825. if (done)
  1826. return 0;
  1827. msg.skb = skb;
  1828. msg.portid = NETLINK_CB(cb->skb).portid;
  1829. msg.seq = cb->nlh->nlmsg_seq;
  1830. rcu_read_lock();
  1831. if (prev_node) {
  1832. node = tipc_node_find(net, prev_node);
  1833. if (!node) {
  1834. /* We never set seq or call nl_dump_check_consistent()
  1835. * this means that setting prev_seq here will cause the
  1836. * consistence check to fail in the netlink callback
  1837. * handler. Resulting in the last NLMSG_DONE message
  1838. * having the NLM_F_DUMP_INTR flag set.
  1839. */
  1840. cb->prev_seq = 1;
  1841. goto out;
  1842. }
  1843. tipc_node_put(node);
  1844. list_for_each_entry_continue_rcu(node, &tn->node_list,
  1845. list) {
  1846. tipc_node_lock(node);
  1847. err = __tipc_nl_add_node_links(net, &msg, node,
  1848. &prev_link);
  1849. tipc_node_unlock(node);
  1850. if (err)
  1851. goto out;
  1852. prev_node = node->addr;
  1853. }
  1854. } else {
  1855. err = tipc_nl_add_bc_link(net, &msg);
  1856. if (err)
  1857. goto out;
  1858. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1859. tipc_node_lock(node);
  1860. err = __tipc_nl_add_node_links(net, &msg, node,
  1861. &prev_link);
  1862. tipc_node_unlock(node);
  1863. if (err)
  1864. goto out;
  1865. prev_node = node->addr;
  1866. }
  1867. }
  1868. done = 1;
  1869. out:
  1870. rcu_read_unlock();
  1871. cb->args[0] = prev_node;
  1872. cb->args[1] = prev_link;
  1873. cb->args[2] = done;
  1874. return skb->len;
  1875. }
  1876. int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
  1877. {
  1878. struct net *net = genl_info_net(info);
  1879. struct tipc_nl_msg msg;
  1880. char *name;
  1881. int err;
  1882. msg.portid = info->snd_portid;
  1883. msg.seq = info->snd_seq;
  1884. if (!info->attrs[TIPC_NLA_LINK_NAME])
  1885. return -EINVAL;
  1886. name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]);
  1887. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1888. if (!msg.skb)
  1889. return -ENOMEM;
  1890. if (strcmp(name, tipc_bclink_name) == 0) {
  1891. err = tipc_nl_add_bc_link(net, &msg);
  1892. if (err) {
  1893. nlmsg_free(msg.skb);
  1894. return err;
  1895. }
  1896. } else {
  1897. int bearer_id;
  1898. struct tipc_node *node;
  1899. struct tipc_link *link;
  1900. node = tipc_link_find_owner(net, name, &bearer_id);
  1901. if (!node)
  1902. return -EINVAL;
  1903. tipc_node_lock(node);
  1904. link = node->links[bearer_id];
  1905. if (!link) {
  1906. tipc_node_unlock(node);
  1907. nlmsg_free(msg.skb);
  1908. return -EINVAL;
  1909. }
  1910. err = __tipc_nl_add_link(net, &msg, link, 0);
  1911. tipc_node_unlock(node);
  1912. if (err) {
  1913. nlmsg_free(msg.skb);
  1914. return err;
  1915. }
  1916. }
  1917. return genlmsg_reply(msg.skb, info);
  1918. }
  1919. int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info)
  1920. {
  1921. int err;
  1922. char *link_name;
  1923. unsigned int bearer_id;
  1924. struct tipc_link *link;
  1925. struct tipc_node *node;
  1926. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1927. struct net *net = sock_net(skb->sk);
  1928. if (!info->attrs[TIPC_NLA_LINK])
  1929. return -EINVAL;
  1930. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1931. info->attrs[TIPC_NLA_LINK],
  1932. tipc_nl_link_policy);
  1933. if (err)
  1934. return err;
  1935. if (!attrs[TIPC_NLA_LINK_NAME])
  1936. return -EINVAL;
  1937. link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1938. if (strcmp(link_name, tipc_bclink_name) == 0) {
  1939. err = tipc_bclink_reset_stats(net);
  1940. if (err)
  1941. return err;
  1942. return 0;
  1943. }
  1944. node = tipc_link_find_owner(net, link_name, &bearer_id);
  1945. if (!node)
  1946. return -EINVAL;
  1947. tipc_node_lock(node);
  1948. link = node->links[bearer_id];
  1949. if (!link) {
  1950. tipc_node_unlock(node);
  1951. return -EINVAL;
  1952. }
  1953. link_reset_statistics(link);
  1954. tipc_node_unlock(node);
  1955. return 0;
  1956. }