node.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435
  1. /*
  2. * net/tipc/node.c: TIPC node management routines
  3. *
  4. * Copyright (c) 2000-2006, 2012-2016, Ericsson AB
  5. * Copyright (c) 2005-2006, 2010-2014, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "link.h"
  38. #include "node.h"
  39. #include "name_distr.h"
  40. #include "socket.h"
  41. #include "bcast.h"
  42. #include "monitor.h"
  43. #include "discover.h"
  44. #include "netlink.h"
  45. #define INVALID_NODE_SIG 0x10000
  46. #define NODE_CLEANUP_AFTER 300000
  47. /* Flags used to take different actions according to flag type
  48. * TIPC_NOTIFY_NODE_DOWN: notify node is down
  49. * TIPC_NOTIFY_NODE_UP: notify node is up
  50. * TIPC_DISTRIBUTE_NAME: publish or withdraw link state name type
  51. */
  52. enum {
  53. TIPC_NOTIFY_NODE_DOWN = (1 << 3),
  54. TIPC_NOTIFY_NODE_UP = (1 << 4),
  55. TIPC_NOTIFY_LINK_UP = (1 << 6),
  56. TIPC_NOTIFY_LINK_DOWN = (1 << 7)
  57. };
  58. struct tipc_link_entry {
  59. struct tipc_link *link;
  60. spinlock_t lock; /* per link */
  61. u32 mtu;
  62. struct sk_buff_head inputq;
  63. struct tipc_media_addr maddr;
  64. };
  65. struct tipc_bclink_entry {
  66. struct tipc_link *link;
  67. struct sk_buff_head inputq1;
  68. struct sk_buff_head arrvq;
  69. struct sk_buff_head inputq2;
  70. struct sk_buff_head namedq;
  71. };
  72. /**
  73. * struct tipc_node - TIPC node structure
  74. * @addr: network address of node
  75. * @ref: reference counter to node object
  76. * @lock: rwlock governing access to structure
  77. * @net: the applicable net namespace
  78. * @hash: links to adjacent nodes in unsorted hash chain
  79. * @inputq: pointer to input queue containing messages for msg event
  80. * @namedq: pointer to name table input queue with name table messages
  81. * @active_links: bearer ids of active links, used as index into links[] array
  82. * @links: array containing references to all links to node
  83. * @action_flags: bit mask of different types of node actions
  84. * @state: connectivity state vs peer node
  85. * @sync_point: sequence number where synch/failover is finished
  86. * @list: links to adjacent nodes in sorted list of cluster's nodes
  87. * @working_links: number of working links to node (both active and standby)
  88. * @link_cnt: number of links to node
  89. * @capabilities: bitmap, indicating peer node's functional capabilities
  90. * @signature: node instance identifier
  91. * @link_id: local and remote bearer ids of changing link, if any
  92. * @publ_list: list of publications
  93. * @rcu: rcu struct for tipc_node
  94. * @delete_at: indicates the time for deleting a down node
  95. */
  96. struct tipc_node {
  97. u32 addr;
  98. struct kref kref;
  99. rwlock_t lock;
  100. struct net *net;
  101. struct hlist_node hash;
  102. int active_links[2];
  103. struct tipc_link_entry links[MAX_BEARERS];
  104. struct tipc_bclink_entry bc_entry;
  105. int action_flags;
  106. struct list_head list;
  107. int state;
  108. bool failover_sent;
  109. u16 sync_point;
  110. int link_cnt;
  111. u16 working_links;
  112. u16 capabilities;
  113. u32 signature;
  114. u32 link_id;
  115. u8 peer_id[16];
  116. struct list_head publ_list;
  117. struct list_head conn_sks;
  118. unsigned long keepalive_intv;
  119. struct timer_list timer;
  120. struct rcu_head rcu;
  121. unsigned long delete_at;
  122. };
  123. /* Node FSM states and events:
  124. */
  125. enum {
  126. SELF_DOWN_PEER_DOWN = 0xdd,
  127. SELF_UP_PEER_UP = 0xaa,
  128. SELF_DOWN_PEER_LEAVING = 0xd1,
  129. SELF_UP_PEER_COMING = 0xac,
  130. SELF_COMING_PEER_UP = 0xca,
  131. SELF_LEAVING_PEER_DOWN = 0x1d,
  132. NODE_FAILINGOVER = 0xf0,
  133. NODE_SYNCHING = 0xcc
  134. };
  135. enum {
  136. SELF_ESTABL_CONTACT_EVT = 0xece,
  137. SELF_LOST_CONTACT_EVT = 0x1ce,
  138. PEER_ESTABL_CONTACT_EVT = 0x9ece,
  139. PEER_LOST_CONTACT_EVT = 0x91ce,
  140. NODE_FAILOVER_BEGIN_EVT = 0xfbe,
  141. NODE_FAILOVER_END_EVT = 0xfee,
  142. NODE_SYNCH_BEGIN_EVT = 0xcbe,
  143. NODE_SYNCH_END_EVT = 0xcee
  144. };
  145. static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
  146. struct sk_buff_head *xmitq,
  147. struct tipc_media_addr **maddr);
  148. static void tipc_node_link_down(struct tipc_node *n, int bearer_id,
  149. bool delete);
  150. static void node_lost_contact(struct tipc_node *n, struct sk_buff_head *inputq);
  151. static void tipc_node_delete(struct tipc_node *node);
  152. static void tipc_node_timeout(struct timer_list *t);
  153. static void tipc_node_fsm_evt(struct tipc_node *n, int evt);
  154. static struct tipc_node *tipc_node_find(struct net *net, u32 addr);
  155. static struct tipc_node *tipc_node_find_by_id(struct net *net, u8 *id);
  156. static void tipc_node_put(struct tipc_node *node);
  157. static bool node_is_up(struct tipc_node *n);
  158. static void tipc_node_delete_from_list(struct tipc_node *node);
  159. struct tipc_sock_conn {
  160. u32 port;
  161. u32 peer_port;
  162. u32 peer_node;
  163. struct list_head list;
  164. };
  165. static struct tipc_link *node_active_link(struct tipc_node *n, int sel)
  166. {
  167. int bearer_id = n->active_links[sel & 1];
  168. if (unlikely(bearer_id == INVALID_BEARER_ID))
  169. return NULL;
  170. return n->links[bearer_id].link;
  171. }
  172. int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel)
  173. {
  174. struct tipc_node *n;
  175. int bearer_id;
  176. unsigned int mtu = MAX_MSG_SIZE;
  177. n = tipc_node_find(net, addr);
  178. if (unlikely(!n))
  179. return mtu;
  180. bearer_id = n->active_links[sel & 1];
  181. if (likely(bearer_id != INVALID_BEARER_ID))
  182. mtu = n->links[bearer_id].mtu;
  183. tipc_node_put(n);
  184. return mtu;
  185. }
  186. bool tipc_node_get_id(struct net *net, u32 addr, u8 *id)
  187. {
  188. u8 *own_id = tipc_own_id(net);
  189. struct tipc_node *n;
  190. if (!own_id)
  191. return true;
  192. if (addr == tipc_own_addr(net)) {
  193. memcpy(id, own_id, TIPC_NODEID_LEN);
  194. return true;
  195. }
  196. n = tipc_node_find(net, addr);
  197. if (!n)
  198. return false;
  199. memcpy(id, &n->peer_id, TIPC_NODEID_LEN);
  200. tipc_node_put(n);
  201. return true;
  202. }
  203. u16 tipc_node_get_capabilities(struct net *net, u32 addr)
  204. {
  205. struct tipc_node *n;
  206. u16 caps;
  207. n = tipc_node_find(net, addr);
  208. if (unlikely(!n))
  209. return TIPC_NODE_CAPABILITIES;
  210. caps = n->capabilities;
  211. tipc_node_put(n);
  212. return caps;
  213. }
  214. static void tipc_node_kref_release(struct kref *kref)
  215. {
  216. struct tipc_node *n = container_of(kref, struct tipc_node, kref);
  217. kfree(n->bc_entry.link);
  218. kfree_rcu(n, rcu);
  219. }
  220. static void tipc_node_put(struct tipc_node *node)
  221. {
  222. kref_put(&node->kref, tipc_node_kref_release);
  223. }
  224. static void tipc_node_get(struct tipc_node *node)
  225. {
  226. kref_get(&node->kref);
  227. }
  228. /*
  229. * tipc_node_find - locate specified node object, if it exists
  230. */
  231. static struct tipc_node *tipc_node_find(struct net *net, u32 addr)
  232. {
  233. struct tipc_net *tn = tipc_net(net);
  234. struct tipc_node *node;
  235. unsigned int thash = tipc_hashfn(addr);
  236. rcu_read_lock();
  237. hlist_for_each_entry_rcu(node, &tn->node_htable[thash], hash) {
  238. if (node->addr != addr)
  239. continue;
  240. if (!kref_get_unless_zero(&node->kref))
  241. node = NULL;
  242. break;
  243. }
  244. rcu_read_unlock();
  245. return node;
  246. }
  247. /* tipc_node_find_by_id - locate specified node object by its 128-bit id
  248. * Note: this function is called only when a discovery request failed
  249. * to find the node by its 32-bit id, and is not time critical
  250. */
  251. static struct tipc_node *tipc_node_find_by_id(struct net *net, u8 *id)
  252. {
  253. struct tipc_net *tn = tipc_net(net);
  254. struct tipc_node *n;
  255. bool found = false;
  256. rcu_read_lock();
  257. list_for_each_entry_rcu(n, &tn->node_list, list) {
  258. read_lock_bh(&n->lock);
  259. if (!memcmp(id, n->peer_id, 16) &&
  260. kref_get_unless_zero(&n->kref))
  261. found = true;
  262. read_unlock_bh(&n->lock);
  263. if (found)
  264. break;
  265. }
  266. rcu_read_unlock();
  267. return found ? n : NULL;
  268. }
  269. static void tipc_node_read_lock(struct tipc_node *n)
  270. {
  271. read_lock_bh(&n->lock);
  272. }
  273. static void tipc_node_read_unlock(struct tipc_node *n)
  274. {
  275. read_unlock_bh(&n->lock);
  276. }
  277. static void tipc_node_write_lock(struct tipc_node *n)
  278. {
  279. write_lock_bh(&n->lock);
  280. }
  281. static void tipc_node_write_unlock_fast(struct tipc_node *n)
  282. {
  283. write_unlock_bh(&n->lock);
  284. }
  285. static void tipc_node_write_unlock(struct tipc_node *n)
  286. {
  287. struct net *net = n->net;
  288. u32 addr = 0;
  289. u32 flags = n->action_flags;
  290. u32 link_id = 0;
  291. u32 bearer_id;
  292. struct list_head *publ_list;
  293. if (likely(!flags)) {
  294. write_unlock_bh(&n->lock);
  295. return;
  296. }
  297. addr = n->addr;
  298. link_id = n->link_id;
  299. bearer_id = link_id & 0xffff;
  300. publ_list = &n->publ_list;
  301. n->action_flags &= ~(TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP |
  302. TIPC_NOTIFY_LINK_DOWN | TIPC_NOTIFY_LINK_UP);
  303. write_unlock_bh(&n->lock);
  304. if (flags & TIPC_NOTIFY_NODE_DOWN)
  305. tipc_publ_notify(net, publ_list, addr);
  306. if (flags & TIPC_NOTIFY_NODE_UP)
  307. tipc_named_node_up(net, addr);
  308. if (flags & TIPC_NOTIFY_LINK_UP) {
  309. tipc_mon_peer_up(net, addr, bearer_id);
  310. tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr,
  311. TIPC_NODE_SCOPE, link_id, link_id);
  312. }
  313. if (flags & TIPC_NOTIFY_LINK_DOWN) {
  314. tipc_mon_peer_down(net, addr, bearer_id);
  315. tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr,
  316. addr, link_id);
  317. }
  318. }
  319. static struct tipc_node *tipc_node_create(struct net *net, u32 addr,
  320. u8 *peer_id, u16 capabilities)
  321. {
  322. struct tipc_net *tn = net_generic(net, tipc_net_id);
  323. struct tipc_node *n, *temp_node;
  324. struct tipc_link *l;
  325. int bearer_id;
  326. int i;
  327. spin_lock_bh(&tn->node_list_lock);
  328. n = tipc_node_find(net, addr);
  329. if (n) {
  330. if (n->capabilities == capabilities)
  331. goto exit;
  332. /* Same node may come back with new capabilities */
  333. write_lock_bh(&n->lock);
  334. n->capabilities = capabilities;
  335. for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) {
  336. l = n->links[bearer_id].link;
  337. if (l)
  338. tipc_link_update_caps(l, capabilities);
  339. }
  340. write_unlock_bh(&n->lock);
  341. goto exit;
  342. }
  343. n = kzalloc(sizeof(*n), GFP_ATOMIC);
  344. if (!n) {
  345. pr_warn("Node creation failed, no memory\n");
  346. goto exit;
  347. }
  348. n->addr = addr;
  349. memcpy(&n->peer_id, peer_id, 16);
  350. n->net = net;
  351. n->capabilities = capabilities;
  352. kref_init(&n->kref);
  353. rwlock_init(&n->lock);
  354. INIT_HLIST_NODE(&n->hash);
  355. INIT_LIST_HEAD(&n->list);
  356. INIT_LIST_HEAD(&n->publ_list);
  357. INIT_LIST_HEAD(&n->conn_sks);
  358. skb_queue_head_init(&n->bc_entry.namedq);
  359. skb_queue_head_init(&n->bc_entry.inputq1);
  360. __skb_queue_head_init(&n->bc_entry.arrvq);
  361. skb_queue_head_init(&n->bc_entry.inputq2);
  362. for (i = 0; i < MAX_BEARERS; i++)
  363. spin_lock_init(&n->links[i].lock);
  364. n->state = SELF_DOWN_PEER_LEAVING;
  365. n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER);
  366. n->signature = INVALID_NODE_SIG;
  367. n->active_links[0] = INVALID_BEARER_ID;
  368. n->active_links[1] = INVALID_BEARER_ID;
  369. if (!tipc_link_bc_create(net, tipc_own_addr(net),
  370. addr, U16_MAX,
  371. tipc_link_window(tipc_bc_sndlink(net)),
  372. n->capabilities,
  373. &n->bc_entry.inputq1,
  374. &n->bc_entry.namedq,
  375. tipc_bc_sndlink(net),
  376. &n->bc_entry.link)) {
  377. pr_warn("Broadcast rcv link creation failed, no memory\n");
  378. kfree(n);
  379. n = NULL;
  380. goto exit;
  381. }
  382. tipc_node_get(n);
  383. timer_setup(&n->timer, tipc_node_timeout, 0);
  384. n->keepalive_intv = U32_MAX;
  385. hlist_add_head_rcu(&n->hash, &tn->node_htable[tipc_hashfn(addr)]);
  386. list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
  387. if (n->addr < temp_node->addr)
  388. break;
  389. }
  390. list_add_tail_rcu(&n->list, &temp_node->list);
  391. exit:
  392. spin_unlock_bh(&tn->node_list_lock);
  393. return n;
  394. }
  395. static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l)
  396. {
  397. unsigned long tol = tipc_link_tolerance(l);
  398. unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4;
  399. /* Link with lowest tolerance determines timer interval */
  400. if (intv < n->keepalive_intv)
  401. n->keepalive_intv = intv;
  402. /* Ensure link's abort limit corresponds to current tolerance */
  403. tipc_link_set_abort_limit(l, tol / n->keepalive_intv);
  404. }
  405. static void tipc_node_delete_from_list(struct tipc_node *node)
  406. {
  407. list_del_rcu(&node->list);
  408. hlist_del_rcu(&node->hash);
  409. tipc_node_put(node);
  410. }
  411. static void tipc_node_delete(struct tipc_node *node)
  412. {
  413. tipc_node_delete_from_list(node);
  414. del_timer_sync(&node->timer);
  415. tipc_node_put(node);
  416. }
  417. void tipc_node_stop(struct net *net)
  418. {
  419. struct tipc_net *tn = tipc_net(net);
  420. struct tipc_node *node, *t_node;
  421. spin_lock_bh(&tn->node_list_lock);
  422. list_for_each_entry_safe(node, t_node, &tn->node_list, list)
  423. tipc_node_delete(node);
  424. spin_unlock_bh(&tn->node_list_lock);
  425. }
  426. void tipc_node_subscribe(struct net *net, struct list_head *subscr, u32 addr)
  427. {
  428. struct tipc_node *n;
  429. if (in_own_node(net, addr))
  430. return;
  431. n = tipc_node_find(net, addr);
  432. if (!n) {
  433. pr_warn("Node subscribe rejected, unknown node 0x%x\n", addr);
  434. return;
  435. }
  436. tipc_node_write_lock(n);
  437. list_add_tail(subscr, &n->publ_list);
  438. tipc_node_write_unlock_fast(n);
  439. tipc_node_put(n);
  440. }
  441. void tipc_node_unsubscribe(struct net *net, struct list_head *subscr, u32 addr)
  442. {
  443. struct tipc_node *n;
  444. if (in_own_node(net, addr))
  445. return;
  446. n = tipc_node_find(net, addr);
  447. if (!n) {
  448. pr_warn("Node unsubscribe rejected, unknown node 0x%x\n", addr);
  449. return;
  450. }
  451. tipc_node_write_lock(n);
  452. list_del_init(subscr);
  453. tipc_node_write_unlock_fast(n);
  454. tipc_node_put(n);
  455. }
  456. int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port)
  457. {
  458. struct tipc_node *node;
  459. struct tipc_sock_conn *conn;
  460. int err = 0;
  461. if (in_own_node(net, dnode))
  462. return 0;
  463. node = tipc_node_find(net, dnode);
  464. if (!node) {
  465. pr_warn("Connecting sock to node 0x%x failed\n", dnode);
  466. return -EHOSTUNREACH;
  467. }
  468. conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
  469. if (!conn) {
  470. err = -EHOSTUNREACH;
  471. goto exit;
  472. }
  473. conn->peer_node = dnode;
  474. conn->port = port;
  475. conn->peer_port = peer_port;
  476. tipc_node_write_lock(node);
  477. list_add_tail(&conn->list, &node->conn_sks);
  478. tipc_node_write_unlock(node);
  479. exit:
  480. tipc_node_put(node);
  481. return err;
  482. }
  483. void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port)
  484. {
  485. struct tipc_node *node;
  486. struct tipc_sock_conn *conn, *safe;
  487. if (in_own_node(net, dnode))
  488. return;
  489. node = tipc_node_find(net, dnode);
  490. if (!node)
  491. return;
  492. tipc_node_write_lock(node);
  493. list_for_each_entry_safe(conn, safe, &node->conn_sks, list) {
  494. if (port != conn->port)
  495. continue;
  496. list_del(&conn->list);
  497. kfree(conn);
  498. }
  499. tipc_node_write_unlock(node);
  500. tipc_node_put(node);
  501. }
  502. static void tipc_node_clear_links(struct tipc_node *node)
  503. {
  504. int i;
  505. for (i = 0; i < MAX_BEARERS; i++) {
  506. struct tipc_link_entry *le = &node->links[i];
  507. if (le->link) {
  508. kfree(le->link);
  509. le->link = NULL;
  510. node->link_cnt--;
  511. }
  512. }
  513. }
  514. /* tipc_node_cleanup - delete nodes that does not
  515. * have active links for NODE_CLEANUP_AFTER time
  516. */
  517. static bool tipc_node_cleanup(struct tipc_node *peer)
  518. {
  519. struct tipc_net *tn = tipc_net(peer->net);
  520. bool deleted = false;
  521. /* If lock held by tipc_node_stop() the node will be deleted anyway */
  522. if (!spin_trylock_bh(&tn->node_list_lock))
  523. return false;
  524. tipc_node_write_lock(peer);
  525. if (!node_is_up(peer) && time_after(jiffies, peer->delete_at)) {
  526. tipc_node_clear_links(peer);
  527. tipc_node_delete_from_list(peer);
  528. deleted = true;
  529. }
  530. tipc_node_write_unlock(peer);
  531. spin_unlock_bh(&tn->node_list_lock);
  532. return deleted;
  533. }
  534. /* tipc_node_timeout - handle expiration of node timer
  535. */
  536. static void tipc_node_timeout(struct timer_list *t)
  537. {
  538. struct tipc_node *n = from_timer(n, t, timer);
  539. struct tipc_link_entry *le;
  540. struct sk_buff_head xmitq;
  541. int remains = n->link_cnt;
  542. int bearer_id;
  543. int rc = 0;
  544. if (!node_is_up(n) && tipc_node_cleanup(n)) {
  545. /*Removing the reference of Timer*/
  546. tipc_node_put(n);
  547. return;
  548. }
  549. __skb_queue_head_init(&xmitq);
  550. /* Initial node interval to value larger (10 seconds), then it will be
  551. * recalculated with link lowest tolerance
  552. */
  553. tipc_node_read_lock(n);
  554. n->keepalive_intv = 10000;
  555. tipc_node_read_unlock(n);
  556. for (bearer_id = 0; remains && (bearer_id < MAX_BEARERS); bearer_id++) {
  557. tipc_node_read_lock(n);
  558. le = &n->links[bearer_id];
  559. if (le->link) {
  560. spin_lock_bh(&le->lock);
  561. /* Link tolerance may change asynchronously: */
  562. tipc_node_calculate_timer(n, le->link);
  563. rc = tipc_link_timeout(le->link, &xmitq);
  564. spin_unlock_bh(&le->lock);
  565. remains--;
  566. }
  567. tipc_node_read_unlock(n);
  568. tipc_bearer_xmit(n->net, bearer_id, &xmitq, &le->maddr);
  569. if (rc & TIPC_LINK_DOWN_EVT)
  570. tipc_node_link_down(n, bearer_id, false);
  571. }
  572. mod_timer(&n->timer, jiffies + msecs_to_jiffies(n->keepalive_intv));
  573. }
  574. /**
  575. * __tipc_node_link_up - handle addition of link
  576. * Node lock must be held by caller
  577. * Link becomes active (alone or shared) or standby, depending on its priority.
  578. */
  579. static void __tipc_node_link_up(struct tipc_node *n, int bearer_id,
  580. struct sk_buff_head *xmitq)
  581. {
  582. int *slot0 = &n->active_links[0];
  583. int *slot1 = &n->active_links[1];
  584. struct tipc_link *ol = node_active_link(n, 0);
  585. struct tipc_link *nl = n->links[bearer_id].link;
  586. if (!nl || tipc_link_is_up(nl))
  587. return;
  588. tipc_link_fsm_evt(nl, LINK_ESTABLISH_EVT);
  589. if (!tipc_link_is_up(nl))
  590. return;
  591. n->working_links++;
  592. n->action_flags |= TIPC_NOTIFY_LINK_UP;
  593. n->link_id = tipc_link_id(nl);
  594. /* Leave room for tunnel header when returning 'mtu' to users: */
  595. n->links[bearer_id].mtu = tipc_link_mtu(nl) - INT_H_SIZE;
  596. tipc_bearer_add_dest(n->net, bearer_id, n->addr);
  597. tipc_bcast_inc_bearer_dst_cnt(n->net, bearer_id);
  598. pr_debug("Established link <%s> on network plane %c\n",
  599. tipc_link_name(nl), tipc_link_plane(nl));
  600. /* Ensure that a STATE message goes first */
  601. tipc_link_build_state_msg(nl, xmitq);
  602. /* First link? => give it both slots */
  603. if (!ol) {
  604. *slot0 = bearer_id;
  605. *slot1 = bearer_id;
  606. tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT);
  607. n->failover_sent = false;
  608. n->action_flags |= TIPC_NOTIFY_NODE_UP;
  609. tipc_link_set_active(nl, true);
  610. tipc_bcast_add_peer(n->net, nl, xmitq);
  611. return;
  612. }
  613. /* Second link => redistribute slots */
  614. if (tipc_link_prio(nl) > tipc_link_prio(ol)) {
  615. pr_debug("Old link <%s> becomes standby\n", tipc_link_name(ol));
  616. *slot0 = bearer_id;
  617. *slot1 = bearer_id;
  618. tipc_link_set_active(nl, true);
  619. tipc_link_set_active(ol, false);
  620. } else if (tipc_link_prio(nl) == tipc_link_prio(ol)) {
  621. tipc_link_set_active(nl, true);
  622. *slot1 = bearer_id;
  623. } else {
  624. pr_debug("New link <%s> is standby\n", tipc_link_name(nl));
  625. }
  626. /* Prepare synchronization with first link */
  627. tipc_link_tnl_prepare(ol, nl, SYNCH_MSG, xmitq);
  628. }
  629. /**
  630. * tipc_node_link_up - handle addition of link
  631. *
  632. * Link becomes active (alone or shared) or standby, depending on its priority.
  633. */
  634. static void tipc_node_link_up(struct tipc_node *n, int bearer_id,
  635. struct sk_buff_head *xmitq)
  636. {
  637. struct tipc_media_addr *maddr;
  638. tipc_node_write_lock(n);
  639. __tipc_node_link_up(n, bearer_id, xmitq);
  640. maddr = &n->links[bearer_id].maddr;
  641. tipc_bearer_xmit(n->net, bearer_id, xmitq, maddr);
  642. tipc_node_write_unlock(n);
  643. }
  644. /**
  645. * __tipc_node_link_down - handle loss of link
  646. */
  647. static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
  648. struct sk_buff_head *xmitq,
  649. struct tipc_media_addr **maddr)
  650. {
  651. struct tipc_link_entry *le = &n->links[*bearer_id];
  652. int *slot0 = &n->active_links[0];
  653. int *slot1 = &n->active_links[1];
  654. int i, highest = 0, prio;
  655. struct tipc_link *l, *_l, *tnl;
  656. l = n->links[*bearer_id].link;
  657. if (!l || tipc_link_is_reset(l))
  658. return;
  659. n->working_links--;
  660. n->action_flags |= TIPC_NOTIFY_LINK_DOWN;
  661. n->link_id = tipc_link_id(l);
  662. tipc_bearer_remove_dest(n->net, *bearer_id, n->addr);
  663. pr_debug("Lost link <%s> on network plane %c\n",
  664. tipc_link_name(l), tipc_link_plane(l));
  665. /* Select new active link if any available */
  666. *slot0 = INVALID_BEARER_ID;
  667. *slot1 = INVALID_BEARER_ID;
  668. for (i = 0; i < MAX_BEARERS; i++) {
  669. _l = n->links[i].link;
  670. if (!_l || !tipc_link_is_up(_l))
  671. continue;
  672. if (_l == l)
  673. continue;
  674. prio = tipc_link_prio(_l);
  675. if (prio < highest)
  676. continue;
  677. if (prio > highest) {
  678. highest = prio;
  679. *slot0 = i;
  680. *slot1 = i;
  681. continue;
  682. }
  683. *slot1 = i;
  684. }
  685. if (!node_is_up(n)) {
  686. if (tipc_link_peer_is_down(l))
  687. tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
  688. tipc_node_fsm_evt(n, SELF_LOST_CONTACT_EVT);
  689. tipc_link_fsm_evt(l, LINK_RESET_EVT);
  690. tipc_link_reset(l);
  691. tipc_link_build_reset_msg(l, xmitq);
  692. *maddr = &n->links[*bearer_id].maddr;
  693. node_lost_contact(n, &le->inputq);
  694. tipc_bcast_dec_bearer_dst_cnt(n->net, *bearer_id);
  695. return;
  696. }
  697. tipc_bcast_dec_bearer_dst_cnt(n->net, *bearer_id);
  698. /* There is still a working link => initiate failover */
  699. *bearer_id = n->active_links[0];
  700. tnl = n->links[*bearer_id].link;
  701. tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
  702. tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
  703. n->sync_point = tipc_link_rcv_nxt(tnl) + (U16_MAX / 2 - 1);
  704. tipc_link_tnl_prepare(l, tnl, FAILOVER_MSG, xmitq);
  705. tipc_link_reset(l);
  706. tipc_link_fsm_evt(l, LINK_RESET_EVT);
  707. tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
  708. tipc_node_fsm_evt(n, NODE_FAILOVER_BEGIN_EVT);
  709. *maddr = &n->links[*bearer_id].maddr;
  710. }
  711. static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete)
  712. {
  713. struct tipc_link_entry *le = &n->links[bearer_id];
  714. struct tipc_media_addr *maddr = NULL;
  715. struct tipc_link *l = le->link;
  716. int old_bearer_id = bearer_id;
  717. struct sk_buff_head xmitq;
  718. if (!l)
  719. return;
  720. __skb_queue_head_init(&xmitq);
  721. tipc_node_write_lock(n);
  722. if (!tipc_link_is_establishing(l)) {
  723. __tipc_node_link_down(n, &bearer_id, &xmitq, &maddr);
  724. if (delete) {
  725. kfree(l);
  726. le->link = NULL;
  727. n->link_cnt--;
  728. }
  729. } else {
  730. /* Defuse pending tipc_node_link_up() */
  731. tipc_link_fsm_evt(l, LINK_RESET_EVT);
  732. }
  733. tipc_node_write_unlock(n);
  734. if (delete)
  735. tipc_mon_remove_peer(n->net, n->addr, old_bearer_id);
  736. if (!skb_queue_empty(&xmitq))
  737. tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
  738. tipc_sk_rcv(n->net, &le->inputq);
  739. }
  740. static bool node_is_up(struct tipc_node *n)
  741. {
  742. return n->active_links[0] != INVALID_BEARER_ID;
  743. }
  744. bool tipc_node_is_up(struct net *net, u32 addr)
  745. {
  746. struct tipc_node *n;
  747. bool retval = false;
  748. if (in_own_node(net, addr))
  749. return true;
  750. n = tipc_node_find(net, addr);
  751. if (!n)
  752. return false;
  753. retval = node_is_up(n);
  754. tipc_node_put(n);
  755. return retval;
  756. }
  757. static u32 tipc_node_suggest_addr(struct net *net, u32 addr)
  758. {
  759. struct tipc_node *n;
  760. addr ^= tipc_net(net)->random;
  761. while ((n = tipc_node_find(net, addr))) {
  762. tipc_node_put(n);
  763. addr++;
  764. }
  765. return addr;
  766. }
  767. /* tipc_node_try_addr(): Check if addr can be used by peer, suggest other if not
  768. * Returns suggested address if any, otherwise 0
  769. */
  770. u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr)
  771. {
  772. struct tipc_net *tn = tipc_net(net);
  773. struct tipc_node *n;
  774. /* Suggest new address if some other peer is using this one */
  775. n = tipc_node_find(net, addr);
  776. if (n) {
  777. if (!memcmp(n->peer_id, id, NODE_ID_LEN))
  778. addr = 0;
  779. tipc_node_put(n);
  780. if (!addr)
  781. return 0;
  782. return tipc_node_suggest_addr(net, addr);
  783. }
  784. /* Suggest previously used address if peer is known */
  785. n = tipc_node_find_by_id(net, id);
  786. if (n) {
  787. addr = n->addr;
  788. tipc_node_put(n);
  789. return addr;
  790. }
  791. /* Even this node may be in conflict */
  792. if (tn->trial_addr == addr)
  793. return tipc_node_suggest_addr(net, addr);
  794. return 0;
  795. }
  796. void tipc_node_check_dest(struct net *net, u32 addr,
  797. u8 *peer_id, struct tipc_bearer *b,
  798. u16 capabilities, u32 signature,
  799. struct tipc_media_addr *maddr,
  800. bool *respond, bool *dupl_addr)
  801. {
  802. struct tipc_node *n;
  803. struct tipc_link *l;
  804. struct tipc_link_entry *le;
  805. bool addr_match = false;
  806. bool sign_match = false;
  807. bool link_up = false;
  808. bool accept_addr = false;
  809. bool reset = true;
  810. char *if_name;
  811. unsigned long intv;
  812. u16 session;
  813. *dupl_addr = false;
  814. *respond = false;
  815. n = tipc_node_create(net, addr, peer_id, capabilities);
  816. if (!n)
  817. return;
  818. tipc_node_write_lock(n);
  819. le = &n->links[b->identity];
  820. /* Prepare to validate requesting node's signature and media address */
  821. l = le->link;
  822. link_up = l && tipc_link_is_up(l);
  823. addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
  824. sign_match = (signature == n->signature);
  825. /* These three flags give us eight permutations: */
  826. if (sign_match && addr_match && link_up) {
  827. /* All is fine. Do nothing. */
  828. reset = false;
  829. } else if (sign_match && addr_match && !link_up) {
  830. /* Respond. The link will come up in due time */
  831. *respond = true;
  832. } else if (sign_match && !addr_match && link_up) {
  833. /* Peer has changed i/f address without rebooting.
  834. * If so, the link will reset soon, and the next
  835. * discovery will be accepted. So we can ignore it.
  836. * It may also be an cloned or malicious peer having
  837. * chosen the same node address and signature as an
  838. * existing one.
  839. * Ignore requests until the link goes down, if ever.
  840. */
  841. *dupl_addr = true;
  842. } else if (sign_match && !addr_match && !link_up) {
  843. /* Peer link has changed i/f address without rebooting.
  844. * It may also be a cloned or malicious peer; we can't
  845. * distinguish between the two.
  846. * The signature is correct, so we must accept.
  847. */
  848. accept_addr = true;
  849. *respond = true;
  850. } else if (!sign_match && addr_match && link_up) {
  851. /* Peer node rebooted. Two possibilities:
  852. * - Delayed re-discovery; this link endpoint has already
  853. * reset and re-established contact with the peer, before
  854. * receiving a discovery message from that node.
  855. * (The peer happened to receive one from this node first).
  856. * - The peer came back so fast that our side has not
  857. * discovered it yet. Probing from this side will soon
  858. * reset the link, since there can be no working link
  859. * endpoint at the peer end, and the link will re-establish.
  860. * Accept the signature, since it comes from a known peer.
  861. */
  862. n->signature = signature;
  863. } else if (!sign_match && addr_match && !link_up) {
  864. /* The peer node has rebooted.
  865. * Accept signature, since it is a known peer.
  866. */
  867. n->signature = signature;
  868. *respond = true;
  869. } else if (!sign_match && !addr_match && link_up) {
  870. /* Peer rebooted with new address, or a new/duplicate peer.
  871. * Ignore until the link goes down, if ever.
  872. */
  873. *dupl_addr = true;
  874. } else if (!sign_match && !addr_match && !link_up) {
  875. /* Peer rebooted with new address, or it is a new peer.
  876. * Accept signature and address.
  877. */
  878. n->signature = signature;
  879. accept_addr = true;
  880. *respond = true;
  881. }
  882. if (!accept_addr)
  883. goto exit;
  884. /* Now create new link if not already existing */
  885. if (!l) {
  886. if (n->link_cnt == 2)
  887. goto exit;
  888. if_name = strchr(b->name, ':') + 1;
  889. get_random_bytes(&session, sizeof(u16));
  890. if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
  891. b->net_plane, b->mtu, b->priority,
  892. b->window, session,
  893. tipc_own_addr(net), addr, peer_id,
  894. n->capabilities,
  895. tipc_bc_sndlink(n->net), n->bc_entry.link,
  896. &le->inputq,
  897. &n->bc_entry.namedq, &l)) {
  898. *respond = false;
  899. goto exit;
  900. }
  901. tipc_link_reset(l);
  902. tipc_link_fsm_evt(l, LINK_RESET_EVT);
  903. if (n->state == NODE_FAILINGOVER)
  904. tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
  905. le->link = l;
  906. n->link_cnt++;
  907. tipc_node_calculate_timer(n, l);
  908. if (n->link_cnt == 1) {
  909. intv = jiffies + msecs_to_jiffies(n->keepalive_intv);
  910. if (!mod_timer(&n->timer, intv))
  911. tipc_node_get(n);
  912. }
  913. }
  914. memcpy(&le->maddr, maddr, sizeof(*maddr));
  915. exit:
  916. tipc_node_write_unlock(n);
  917. if (reset && l && !tipc_link_is_reset(l))
  918. tipc_node_link_down(n, b->identity, false);
  919. tipc_node_put(n);
  920. }
  921. void tipc_node_delete_links(struct net *net, int bearer_id)
  922. {
  923. struct tipc_net *tn = net_generic(net, tipc_net_id);
  924. struct tipc_node *n;
  925. rcu_read_lock();
  926. list_for_each_entry_rcu(n, &tn->node_list, list) {
  927. tipc_node_link_down(n, bearer_id, true);
  928. }
  929. rcu_read_unlock();
  930. }
  931. static void tipc_node_reset_links(struct tipc_node *n)
  932. {
  933. int i;
  934. pr_warn("Resetting all links to %x\n", n->addr);
  935. for (i = 0; i < MAX_BEARERS; i++) {
  936. tipc_node_link_down(n, i, false);
  937. }
  938. }
  939. /* tipc_node_fsm_evt - node finite state machine
  940. * Determines when contact is allowed with peer node
  941. */
  942. static void tipc_node_fsm_evt(struct tipc_node *n, int evt)
  943. {
  944. int state = n->state;
  945. switch (state) {
  946. case SELF_DOWN_PEER_DOWN:
  947. switch (evt) {
  948. case SELF_ESTABL_CONTACT_EVT:
  949. state = SELF_UP_PEER_COMING;
  950. break;
  951. case PEER_ESTABL_CONTACT_EVT:
  952. state = SELF_COMING_PEER_UP;
  953. break;
  954. case SELF_LOST_CONTACT_EVT:
  955. case PEER_LOST_CONTACT_EVT:
  956. break;
  957. case NODE_SYNCH_END_EVT:
  958. case NODE_SYNCH_BEGIN_EVT:
  959. case NODE_FAILOVER_BEGIN_EVT:
  960. case NODE_FAILOVER_END_EVT:
  961. default:
  962. goto illegal_evt;
  963. }
  964. break;
  965. case SELF_UP_PEER_UP:
  966. switch (evt) {
  967. case SELF_LOST_CONTACT_EVT:
  968. state = SELF_DOWN_PEER_LEAVING;
  969. break;
  970. case PEER_LOST_CONTACT_EVT:
  971. state = SELF_LEAVING_PEER_DOWN;
  972. break;
  973. case NODE_SYNCH_BEGIN_EVT:
  974. state = NODE_SYNCHING;
  975. break;
  976. case NODE_FAILOVER_BEGIN_EVT:
  977. state = NODE_FAILINGOVER;
  978. break;
  979. case SELF_ESTABL_CONTACT_EVT:
  980. case PEER_ESTABL_CONTACT_EVT:
  981. case NODE_SYNCH_END_EVT:
  982. case NODE_FAILOVER_END_EVT:
  983. break;
  984. default:
  985. goto illegal_evt;
  986. }
  987. break;
  988. case SELF_DOWN_PEER_LEAVING:
  989. switch (evt) {
  990. case PEER_LOST_CONTACT_EVT:
  991. state = SELF_DOWN_PEER_DOWN;
  992. break;
  993. case SELF_ESTABL_CONTACT_EVT:
  994. case PEER_ESTABL_CONTACT_EVT:
  995. case SELF_LOST_CONTACT_EVT:
  996. break;
  997. case NODE_SYNCH_END_EVT:
  998. case NODE_SYNCH_BEGIN_EVT:
  999. case NODE_FAILOVER_BEGIN_EVT:
  1000. case NODE_FAILOVER_END_EVT:
  1001. default:
  1002. goto illegal_evt;
  1003. }
  1004. break;
  1005. case SELF_UP_PEER_COMING:
  1006. switch (evt) {
  1007. case PEER_ESTABL_CONTACT_EVT:
  1008. state = SELF_UP_PEER_UP;
  1009. break;
  1010. case SELF_LOST_CONTACT_EVT:
  1011. state = SELF_DOWN_PEER_DOWN;
  1012. break;
  1013. case SELF_ESTABL_CONTACT_EVT:
  1014. case PEER_LOST_CONTACT_EVT:
  1015. case NODE_SYNCH_END_EVT:
  1016. case NODE_FAILOVER_BEGIN_EVT:
  1017. break;
  1018. case NODE_SYNCH_BEGIN_EVT:
  1019. case NODE_FAILOVER_END_EVT:
  1020. default:
  1021. goto illegal_evt;
  1022. }
  1023. break;
  1024. case SELF_COMING_PEER_UP:
  1025. switch (evt) {
  1026. case SELF_ESTABL_CONTACT_EVT:
  1027. state = SELF_UP_PEER_UP;
  1028. break;
  1029. case PEER_LOST_CONTACT_EVT:
  1030. state = SELF_DOWN_PEER_DOWN;
  1031. break;
  1032. case SELF_LOST_CONTACT_EVT:
  1033. case PEER_ESTABL_CONTACT_EVT:
  1034. break;
  1035. case NODE_SYNCH_END_EVT:
  1036. case NODE_SYNCH_BEGIN_EVT:
  1037. case NODE_FAILOVER_BEGIN_EVT:
  1038. case NODE_FAILOVER_END_EVT:
  1039. default:
  1040. goto illegal_evt;
  1041. }
  1042. break;
  1043. case SELF_LEAVING_PEER_DOWN:
  1044. switch (evt) {
  1045. case SELF_LOST_CONTACT_EVT:
  1046. state = SELF_DOWN_PEER_DOWN;
  1047. break;
  1048. case SELF_ESTABL_CONTACT_EVT:
  1049. case PEER_ESTABL_CONTACT_EVT:
  1050. case PEER_LOST_CONTACT_EVT:
  1051. break;
  1052. case NODE_SYNCH_END_EVT:
  1053. case NODE_SYNCH_BEGIN_EVT:
  1054. case NODE_FAILOVER_BEGIN_EVT:
  1055. case NODE_FAILOVER_END_EVT:
  1056. default:
  1057. goto illegal_evt;
  1058. }
  1059. break;
  1060. case NODE_FAILINGOVER:
  1061. switch (evt) {
  1062. case SELF_LOST_CONTACT_EVT:
  1063. state = SELF_DOWN_PEER_LEAVING;
  1064. break;
  1065. case PEER_LOST_CONTACT_EVT:
  1066. state = SELF_LEAVING_PEER_DOWN;
  1067. break;
  1068. case NODE_FAILOVER_END_EVT:
  1069. state = SELF_UP_PEER_UP;
  1070. break;
  1071. case NODE_FAILOVER_BEGIN_EVT:
  1072. case SELF_ESTABL_CONTACT_EVT:
  1073. case PEER_ESTABL_CONTACT_EVT:
  1074. break;
  1075. case NODE_SYNCH_BEGIN_EVT:
  1076. case NODE_SYNCH_END_EVT:
  1077. default:
  1078. goto illegal_evt;
  1079. }
  1080. break;
  1081. case NODE_SYNCHING:
  1082. switch (evt) {
  1083. case SELF_LOST_CONTACT_EVT:
  1084. state = SELF_DOWN_PEER_LEAVING;
  1085. break;
  1086. case PEER_LOST_CONTACT_EVT:
  1087. state = SELF_LEAVING_PEER_DOWN;
  1088. break;
  1089. case NODE_SYNCH_END_EVT:
  1090. state = SELF_UP_PEER_UP;
  1091. break;
  1092. case NODE_FAILOVER_BEGIN_EVT:
  1093. state = NODE_FAILINGOVER;
  1094. break;
  1095. case NODE_SYNCH_BEGIN_EVT:
  1096. case SELF_ESTABL_CONTACT_EVT:
  1097. case PEER_ESTABL_CONTACT_EVT:
  1098. break;
  1099. case NODE_FAILOVER_END_EVT:
  1100. default:
  1101. goto illegal_evt;
  1102. }
  1103. break;
  1104. default:
  1105. pr_err("Unknown node fsm state %x\n", state);
  1106. break;
  1107. }
  1108. n->state = state;
  1109. return;
  1110. illegal_evt:
  1111. pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
  1112. }
  1113. static void node_lost_contact(struct tipc_node *n,
  1114. struct sk_buff_head *inputq)
  1115. {
  1116. struct tipc_sock_conn *conn, *safe;
  1117. struct tipc_link *l;
  1118. struct list_head *conns = &n->conn_sks;
  1119. struct sk_buff *skb;
  1120. uint i;
  1121. pr_debug("Lost contact with %x\n", n->addr);
  1122. n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER);
  1123. /* Clean up broadcast state */
  1124. tipc_bcast_remove_peer(n->net, n->bc_entry.link);
  1125. /* Abort any ongoing link failover */
  1126. for (i = 0; i < MAX_BEARERS; i++) {
  1127. l = n->links[i].link;
  1128. if (l)
  1129. tipc_link_fsm_evt(l, LINK_FAILOVER_END_EVT);
  1130. }
  1131. /* Notify publications from this node */
  1132. n->action_flags |= TIPC_NOTIFY_NODE_DOWN;
  1133. /* Notify sockets connected to node */
  1134. list_for_each_entry_safe(conn, safe, conns, list) {
  1135. skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
  1136. SHORT_H_SIZE, 0, tipc_own_addr(n->net),
  1137. conn->peer_node, conn->port,
  1138. conn->peer_port, TIPC_ERR_NO_NODE);
  1139. if (likely(skb))
  1140. skb_queue_tail(inputq, skb);
  1141. list_del(&conn->list);
  1142. kfree(conn);
  1143. }
  1144. }
  1145. /**
  1146. * tipc_node_get_linkname - get the name of a link
  1147. *
  1148. * @bearer_id: id of the bearer
  1149. * @node: peer node address
  1150. * @linkname: link name output buffer
  1151. *
  1152. * Returns 0 on success
  1153. */
  1154. int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,
  1155. char *linkname, size_t len)
  1156. {
  1157. struct tipc_link *link;
  1158. int err = -EINVAL;
  1159. struct tipc_node *node = tipc_node_find(net, addr);
  1160. if (!node)
  1161. return err;
  1162. if (bearer_id >= MAX_BEARERS)
  1163. goto exit;
  1164. tipc_node_read_lock(node);
  1165. link = node->links[bearer_id].link;
  1166. if (link) {
  1167. strncpy(linkname, tipc_link_name(link), len);
  1168. err = 0;
  1169. }
  1170. tipc_node_read_unlock(node);
  1171. exit:
  1172. tipc_node_put(node);
  1173. return err;
  1174. }
  1175. /* Caller should hold node lock for the passed node */
  1176. static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
  1177. {
  1178. void *hdr;
  1179. struct nlattr *attrs;
  1180. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1181. NLM_F_MULTI, TIPC_NL_NODE_GET);
  1182. if (!hdr)
  1183. return -EMSGSIZE;
  1184. attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
  1185. if (!attrs)
  1186. goto msg_full;
  1187. if (nla_put_u32(msg->skb, TIPC_NLA_NODE_ADDR, node->addr))
  1188. goto attr_msg_full;
  1189. if (node_is_up(node))
  1190. if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP))
  1191. goto attr_msg_full;
  1192. nla_nest_end(msg->skb, attrs);
  1193. genlmsg_end(msg->skb, hdr);
  1194. return 0;
  1195. attr_msg_full:
  1196. nla_nest_cancel(msg->skb, attrs);
  1197. msg_full:
  1198. genlmsg_cancel(msg->skb, hdr);
  1199. return -EMSGSIZE;
  1200. }
  1201. /**
  1202. * tipc_node_xmit() is the general link level function for message sending
  1203. * @net: the applicable net namespace
  1204. * @list: chain of buffers containing message
  1205. * @dnode: address of destination node
  1206. * @selector: a number used for deterministic link selection
  1207. * Consumes the buffer chain.
  1208. * Returns 0 if success, otherwise: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE,-ENOBUF
  1209. */
  1210. int tipc_node_xmit(struct net *net, struct sk_buff_head *list,
  1211. u32 dnode, int selector)
  1212. {
  1213. struct tipc_link_entry *le = NULL;
  1214. struct tipc_node *n;
  1215. struct sk_buff_head xmitq;
  1216. int bearer_id;
  1217. int rc;
  1218. if (in_own_node(net, dnode)) {
  1219. tipc_sk_rcv(net, list);
  1220. return 0;
  1221. }
  1222. n = tipc_node_find(net, dnode);
  1223. if (unlikely(!n)) {
  1224. skb_queue_purge(list);
  1225. return -EHOSTUNREACH;
  1226. }
  1227. tipc_node_read_lock(n);
  1228. bearer_id = n->active_links[selector & 1];
  1229. if (unlikely(bearer_id == INVALID_BEARER_ID)) {
  1230. tipc_node_read_unlock(n);
  1231. tipc_node_put(n);
  1232. skb_queue_purge(list);
  1233. return -EHOSTUNREACH;
  1234. }
  1235. __skb_queue_head_init(&xmitq);
  1236. le = &n->links[bearer_id];
  1237. spin_lock_bh(&le->lock);
  1238. rc = tipc_link_xmit(le->link, list, &xmitq);
  1239. spin_unlock_bh(&le->lock);
  1240. tipc_node_read_unlock(n);
  1241. if (unlikely(rc == -ENOBUFS))
  1242. tipc_node_link_down(n, bearer_id, false);
  1243. else
  1244. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1245. tipc_node_put(n);
  1246. return rc;
  1247. }
  1248. /* tipc_node_xmit_skb(): send single buffer to destination
  1249. * Buffers sent via this functon are generally TIPC_SYSTEM_IMPORTANCE
  1250. * messages, which will not be rejected
  1251. * The only exception is datagram messages rerouted after secondary
  1252. * lookup, which are rare and safe to dispose of anyway.
  1253. */
  1254. int tipc_node_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
  1255. u32 selector)
  1256. {
  1257. struct sk_buff_head head;
  1258. skb_queue_head_init(&head);
  1259. __skb_queue_tail(&head, skb);
  1260. tipc_node_xmit(net, &head, dnode, selector);
  1261. return 0;
  1262. }
  1263. /* tipc_node_distr_xmit(): send single buffer msgs to individual destinations
  1264. * Note: this is only for SYSTEM_IMPORTANCE messages, which cannot be rejected
  1265. */
  1266. int tipc_node_distr_xmit(struct net *net, struct sk_buff_head *xmitq)
  1267. {
  1268. struct sk_buff *skb;
  1269. u32 selector, dnode;
  1270. while ((skb = __skb_dequeue(xmitq))) {
  1271. selector = msg_origport(buf_msg(skb));
  1272. dnode = msg_destnode(buf_msg(skb));
  1273. tipc_node_xmit_skb(net, skb, dnode, selector);
  1274. }
  1275. return 0;
  1276. }
  1277. void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
  1278. {
  1279. struct sk_buff *txskb;
  1280. struct tipc_node *n;
  1281. u32 dst;
  1282. rcu_read_lock();
  1283. list_for_each_entry_rcu(n, tipc_nodes(net), list) {
  1284. dst = n->addr;
  1285. if (in_own_node(net, dst))
  1286. continue;
  1287. if (!node_is_up(n))
  1288. continue;
  1289. txskb = pskb_copy(skb, GFP_ATOMIC);
  1290. if (!txskb)
  1291. break;
  1292. msg_set_destnode(buf_msg(txskb), dst);
  1293. tipc_node_xmit_skb(net, txskb, dst, 0);
  1294. }
  1295. rcu_read_unlock();
  1296. kfree_skb(skb);
  1297. }
  1298. static void tipc_node_mcast_rcv(struct tipc_node *n)
  1299. {
  1300. struct tipc_bclink_entry *be = &n->bc_entry;
  1301. /* 'arrvq' is under inputq2's lock protection */
  1302. spin_lock_bh(&be->inputq2.lock);
  1303. spin_lock_bh(&be->inputq1.lock);
  1304. skb_queue_splice_tail_init(&be->inputq1, &be->arrvq);
  1305. spin_unlock_bh(&be->inputq1.lock);
  1306. spin_unlock_bh(&be->inputq2.lock);
  1307. tipc_sk_mcast_rcv(n->net, &be->arrvq, &be->inputq2);
  1308. }
  1309. static void tipc_node_bc_sync_rcv(struct tipc_node *n, struct tipc_msg *hdr,
  1310. int bearer_id, struct sk_buff_head *xmitq)
  1311. {
  1312. struct tipc_link *ucl;
  1313. int rc;
  1314. rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr);
  1315. if (rc & TIPC_LINK_DOWN_EVT) {
  1316. tipc_node_reset_links(n);
  1317. return;
  1318. }
  1319. if (!(rc & TIPC_LINK_SND_STATE))
  1320. return;
  1321. /* If probe message, a STATE response will be sent anyway */
  1322. if (msg_probe(hdr))
  1323. return;
  1324. /* Produce a STATE message carrying broadcast NACK */
  1325. tipc_node_read_lock(n);
  1326. ucl = n->links[bearer_id].link;
  1327. if (ucl)
  1328. tipc_link_build_state_msg(ucl, xmitq);
  1329. tipc_node_read_unlock(n);
  1330. }
  1331. /**
  1332. * tipc_node_bc_rcv - process TIPC broadcast packet arriving from off-node
  1333. * @net: the applicable net namespace
  1334. * @skb: TIPC packet
  1335. * @bearer_id: id of bearer message arrived on
  1336. *
  1337. * Invoked with no locks held.
  1338. */
  1339. static void tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id)
  1340. {
  1341. int rc;
  1342. struct sk_buff_head xmitq;
  1343. struct tipc_bclink_entry *be;
  1344. struct tipc_link_entry *le;
  1345. struct tipc_msg *hdr = buf_msg(skb);
  1346. int usr = msg_user(hdr);
  1347. u32 dnode = msg_destnode(hdr);
  1348. struct tipc_node *n;
  1349. __skb_queue_head_init(&xmitq);
  1350. /* If NACK for other node, let rcv link for that node peek into it */
  1351. if ((usr == BCAST_PROTOCOL) && (dnode != tipc_own_addr(net)))
  1352. n = tipc_node_find(net, dnode);
  1353. else
  1354. n = tipc_node_find(net, msg_prevnode(hdr));
  1355. if (!n) {
  1356. kfree_skb(skb);
  1357. return;
  1358. }
  1359. be = &n->bc_entry;
  1360. le = &n->links[bearer_id];
  1361. rc = tipc_bcast_rcv(net, be->link, skb);
  1362. /* Broadcast ACKs are sent on a unicast link */
  1363. if (rc & TIPC_LINK_SND_STATE) {
  1364. tipc_node_read_lock(n);
  1365. tipc_link_build_state_msg(le->link, &xmitq);
  1366. tipc_node_read_unlock(n);
  1367. }
  1368. if (!skb_queue_empty(&xmitq))
  1369. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1370. if (!skb_queue_empty(&be->inputq1))
  1371. tipc_node_mcast_rcv(n);
  1372. /* If reassembly or retransmission failure => reset all links to peer */
  1373. if (rc & TIPC_LINK_DOWN_EVT)
  1374. tipc_node_reset_links(n);
  1375. tipc_node_put(n);
  1376. }
  1377. /**
  1378. * tipc_node_check_state - check and if necessary update node state
  1379. * @skb: TIPC packet
  1380. * @bearer_id: identity of bearer delivering the packet
  1381. * Returns true if state and msg are ok, otherwise false
  1382. */
  1383. static bool tipc_node_check_state(struct tipc_node *n, struct sk_buff *skb,
  1384. int bearer_id, struct sk_buff_head *xmitq)
  1385. {
  1386. struct tipc_msg *hdr = buf_msg(skb);
  1387. int usr = msg_user(hdr);
  1388. int mtyp = msg_type(hdr);
  1389. u16 oseqno = msg_seqno(hdr);
  1390. u16 iseqno = msg_seqno(msg_get_wrapped(hdr));
  1391. u16 exp_pkts = msg_msgcnt(hdr);
  1392. u16 rcv_nxt, syncpt, dlv_nxt, inputq_len;
  1393. int state = n->state;
  1394. struct tipc_link *l, *tnl, *pl = NULL;
  1395. struct tipc_media_addr *maddr;
  1396. int pb_id;
  1397. l = n->links[bearer_id].link;
  1398. if (!l)
  1399. return false;
  1400. rcv_nxt = tipc_link_rcv_nxt(l);
  1401. if (likely((state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL)))
  1402. return true;
  1403. /* Find parallel link, if any */
  1404. for (pb_id = 0; pb_id < MAX_BEARERS; pb_id++) {
  1405. if ((pb_id != bearer_id) && n->links[pb_id].link) {
  1406. pl = n->links[pb_id].link;
  1407. break;
  1408. }
  1409. }
  1410. if (!tipc_link_validate_msg(l, hdr))
  1411. return false;
  1412. /* Check and update node accesibility if applicable */
  1413. if (state == SELF_UP_PEER_COMING) {
  1414. if (!tipc_link_is_up(l))
  1415. return true;
  1416. if (!msg_peer_link_is_up(hdr))
  1417. return true;
  1418. tipc_node_fsm_evt(n, PEER_ESTABL_CONTACT_EVT);
  1419. }
  1420. if (state == SELF_DOWN_PEER_LEAVING) {
  1421. if (msg_peer_node_is_up(hdr))
  1422. return false;
  1423. tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
  1424. return true;
  1425. }
  1426. if (state == SELF_LEAVING_PEER_DOWN)
  1427. return false;
  1428. /* Ignore duplicate packets */
  1429. if ((usr != LINK_PROTOCOL) && less(oseqno, rcv_nxt))
  1430. return true;
  1431. /* Initiate or update failover mode if applicable */
  1432. if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
  1433. syncpt = oseqno + exp_pkts - 1;
  1434. if (pl && tipc_link_is_up(pl)) {
  1435. __tipc_node_link_down(n, &pb_id, xmitq, &maddr);
  1436. tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
  1437. tipc_link_inputq(l));
  1438. }
  1439. /* If parallel link was already down, and this happened before
  1440. * the tunnel link came up, FAILOVER was never sent. Ensure that
  1441. * FAILOVER is sent to get peer out of NODE_FAILINGOVER state.
  1442. */
  1443. if (n->state != NODE_FAILINGOVER && !n->failover_sent) {
  1444. tipc_link_create_dummy_tnl_msg(l, xmitq);
  1445. n->failover_sent = true;
  1446. }
  1447. /* If pkts arrive out of order, use lowest calculated syncpt */
  1448. if (less(syncpt, n->sync_point))
  1449. n->sync_point = syncpt;
  1450. }
  1451. /* Open parallel link when tunnel link reaches synch point */
  1452. if ((n->state == NODE_FAILINGOVER) && tipc_link_is_up(l)) {
  1453. if (!more(rcv_nxt, n->sync_point))
  1454. return true;
  1455. tipc_node_fsm_evt(n, NODE_FAILOVER_END_EVT);
  1456. if (pl)
  1457. tipc_link_fsm_evt(pl, LINK_FAILOVER_END_EVT);
  1458. return true;
  1459. }
  1460. /* No synching needed if only one link */
  1461. if (!pl || !tipc_link_is_up(pl))
  1462. return true;
  1463. /* Initiate synch mode if applicable */
  1464. if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG) && (oseqno == 1)) {
  1465. syncpt = iseqno + exp_pkts - 1;
  1466. if (!tipc_link_is_up(l))
  1467. __tipc_node_link_up(n, bearer_id, xmitq);
  1468. if (n->state == SELF_UP_PEER_UP) {
  1469. n->sync_point = syncpt;
  1470. tipc_link_fsm_evt(l, LINK_SYNCH_BEGIN_EVT);
  1471. tipc_node_fsm_evt(n, NODE_SYNCH_BEGIN_EVT);
  1472. }
  1473. }
  1474. /* Open tunnel link when parallel link reaches synch point */
  1475. if (n->state == NODE_SYNCHING) {
  1476. if (tipc_link_is_synching(l)) {
  1477. tnl = l;
  1478. } else {
  1479. tnl = pl;
  1480. pl = l;
  1481. }
  1482. inputq_len = skb_queue_len(tipc_link_inputq(pl));
  1483. dlv_nxt = tipc_link_rcv_nxt(pl) - inputq_len;
  1484. if (more(dlv_nxt, n->sync_point)) {
  1485. tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
  1486. tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
  1487. return true;
  1488. }
  1489. if (l == pl)
  1490. return true;
  1491. if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG))
  1492. return true;
  1493. if (usr == LINK_PROTOCOL)
  1494. return true;
  1495. return false;
  1496. }
  1497. return true;
  1498. }
  1499. /**
  1500. * tipc_rcv - process TIPC packets/messages arriving from off-node
  1501. * @net: the applicable net namespace
  1502. * @skb: TIPC packet
  1503. * @bearer: pointer to bearer message arrived on
  1504. *
  1505. * Invoked with no locks held. Bearer pointer must point to a valid bearer
  1506. * structure (i.e. cannot be NULL), but bearer can be inactive.
  1507. */
  1508. void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
  1509. {
  1510. struct sk_buff_head xmitq;
  1511. struct tipc_node *n;
  1512. struct tipc_msg *hdr;
  1513. int bearer_id = b->identity;
  1514. struct tipc_link_entry *le;
  1515. u32 self = tipc_own_addr(net);
  1516. int usr, rc = 0;
  1517. u16 bc_ack;
  1518. __skb_queue_head_init(&xmitq);
  1519. /* Ensure message is well-formed before touching the header */
  1520. if (unlikely(!tipc_msg_validate(&skb)))
  1521. goto discard;
  1522. hdr = buf_msg(skb);
  1523. usr = msg_user(hdr);
  1524. bc_ack = msg_bcast_ack(hdr);
  1525. /* Handle arrival of discovery or broadcast packet */
  1526. if (unlikely(msg_non_seq(hdr))) {
  1527. if (unlikely(usr == LINK_CONFIG))
  1528. return tipc_disc_rcv(net, skb, b);
  1529. else
  1530. return tipc_node_bc_rcv(net, skb, bearer_id);
  1531. }
  1532. /* Discard unicast link messages destined for another node */
  1533. if (unlikely(!msg_short(hdr) && (msg_destnode(hdr) != self)))
  1534. goto discard;
  1535. /* Locate neighboring node that sent packet */
  1536. n = tipc_node_find(net, msg_prevnode(hdr));
  1537. if (unlikely(!n))
  1538. goto discard;
  1539. le = &n->links[bearer_id];
  1540. /* Ensure broadcast reception is in synch with peer's send state */
  1541. if (unlikely(usr == LINK_PROTOCOL))
  1542. tipc_node_bc_sync_rcv(n, hdr, bearer_id, &xmitq);
  1543. else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack))
  1544. tipc_bcast_ack_rcv(net, n->bc_entry.link, hdr);
  1545. /* Receive packet directly if conditions permit */
  1546. tipc_node_read_lock(n);
  1547. if (likely((n->state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL))) {
  1548. spin_lock_bh(&le->lock);
  1549. if (le->link) {
  1550. rc = tipc_link_rcv(le->link, skb, &xmitq);
  1551. skb = NULL;
  1552. }
  1553. spin_unlock_bh(&le->lock);
  1554. }
  1555. tipc_node_read_unlock(n);
  1556. /* Check/update node state before receiving */
  1557. if (unlikely(skb)) {
  1558. if (unlikely(skb_linearize(skb)))
  1559. goto discard;
  1560. tipc_node_write_lock(n);
  1561. if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
  1562. if (le->link) {
  1563. rc = tipc_link_rcv(le->link, skb, &xmitq);
  1564. skb = NULL;
  1565. }
  1566. }
  1567. tipc_node_write_unlock(n);
  1568. }
  1569. if (unlikely(rc & TIPC_LINK_UP_EVT))
  1570. tipc_node_link_up(n, bearer_id, &xmitq);
  1571. if (unlikely(rc & TIPC_LINK_DOWN_EVT))
  1572. tipc_node_link_down(n, bearer_id, false);
  1573. if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
  1574. tipc_named_rcv(net, &n->bc_entry.namedq);
  1575. if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1)))
  1576. tipc_node_mcast_rcv(n);
  1577. if (!skb_queue_empty(&le->inputq))
  1578. tipc_sk_rcv(net, &le->inputq);
  1579. if (!skb_queue_empty(&xmitq))
  1580. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1581. tipc_node_put(n);
  1582. discard:
  1583. kfree_skb(skb);
  1584. }
  1585. void tipc_node_apply_property(struct net *net, struct tipc_bearer *b,
  1586. int prop)
  1587. {
  1588. struct tipc_net *tn = tipc_net(net);
  1589. int bearer_id = b->identity;
  1590. struct sk_buff_head xmitq;
  1591. struct tipc_link_entry *e;
  1592. struct tipc_node *n;
  1593. __skb_queue_head_init(&xmitq);
  1594. rcu_read_lock();
  1595. list_for_each_entry_rcu(n, &tn->node_list, list) {
  1596. tipc_node_write_lock(n);
  1597. e = &n->links[bearer_id];
  1598. if (e->link) {
  1599. if (prop == TIPC_NLA_PROP_TOL)
  1600. tipc_link_set_tolerance(e->link, b->tolerance,
  1601. &xmitq);
  1602. else if (prop == TIPC_NLA_PROP_MTU)
  1603. tipc_link_set_mtu(e->link, b->mtu);
  1604. }
  1605. tipc_node_write_unlock(n);
  1606. tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr);
  1607. }
  1608. rcu_read_unlock();
  1609. }
  1610. int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
  1611. {
  1612. struct net *net = sock_net(skb->sk);
  1613. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1614. struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
  1615. struct tipc_node *peer;
  1616. u32 addr;
  1617. int err;
  1618. /* We identify the peer by its net */
  1619. if (!info->attrs[TIPC_NLA_NET])
  1620. return -EINVAL;
  1621. err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
  1622. info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
  1623. info->extack);
  1624. if (err)
  1625. return err;
  1626. if (!attrs[TIPC_NLA_NET_ADDR])
  1627. return -EINVAL;
  1628. addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
  1629. if (in_own_node(net, addr))
  1630. return -ENOTSUPP;
  1631. spin_lock_bh(&tn->node_list_lock);
  1632. peer = tipc_node_find(net, addr);
  1633. if (!peer) {
  1634. spin_unlock_bh(&tn->node_list_lock);
  1635. return -ENXIO;
  1636. }
  1637. tipc_node_write_lock(peer);
  1638. if (peer->state != SELF_DOWN_PEER_DOWN &&
  1639. peer->state != SELF_DOWN_PEER_LEAVING) {
  1640. tipc_node_write_unlock(peer);
  1641. err = -EBUSY;
  1642. goto err_out;
  1643. }
  1644. tipc_node_clear_links(peer);
  1645. tipc_node_write_unlock(peer);
  1646. tipc_node_delete(peer);
  1647. err = 0;
  1648. err_out:
  1649. tipc_node_put(peer);
  1650. spin_unlock_bh(&tn->node_list_lock);
  1651. return err;
  1652. }
  1653. int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
  1654. {
  1655. int err;
  1656. struct net *net = sock_net(skb->sk);
  1657. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1658. int done = cb->args[0];
  1659. int last_addr = cb->args[1];
  1660. struct tipc_node *node;
  1661. struct tipc_nl_msg msg;
  1662. if (done)
  1663. return 0;
  1664. msg.skb = skb;
  1665. msg.portid = NETLINK_CB(cb->skb).portid;
  1666. msg.seq = cb->nlh->nlmsg_seq;
  1667. rcu_read_lock();
  1668. if (last_addr) {
  1669. node = tipc_node_find(net, last_addr);
  1670. if (!node) {
  1671. rcu_read_unlock();
  1672. /* We never set seq or call nl_dump_check_consistent()
  1673. * this means that setting prev_seq here will cause the
  1674. * consistence check to fail in the netlink callback
  1675. * handler. Resulting in the NLMSG_DONE message having
  1676. * the NLM_F_DUMP_INTR flag set if the node state
  1677. * changed while we released the lock.
  1678. */
  1679. cb->prev_seq = 1;
  1680. return -EPIPE;
  1681. }
  1682. tipc_node_put(node);
  1683. }
  1684. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1685. if (last_addr) {
  1686. if (node->addr == last_addr)
  1687. last_addr = 0;
  1688. else
  1689. continue;
  1690. }
  1691. tipc_node_read_lock(node);
  1692. err = __tipc_nl_add_node(&msg, node);
  1693. if (err) {
  1694. last_addr = node->addr;
  1695. tipc_node_read_unlock(node);
  1696. goto out;
  1697. }
  1698. tipc_node_read_unlock(node);
  1699. }
  1700. done = 1;
  1701. out:
  1702. cb->args[0] = done;
  1703. cb->args[1] = last_addr;
  1704. rcu_read_unlock();
  1705. return skb->len;
  1706. }
  1707. /* tipc_node_find_by_name - locate owner node of link by link's name
  1708. * @net: the applicable net namespace
  1709. * @name: pointer to link name string
  1710. * @bearer_id: pointer to index in 'node->links' array where the link was found.
  1711. *
  1712. * Returns pointer to node owning the link, or 0 if no matching link is found.
  1713. */
  1714. static struct tipc_node *tipc_node_find_by_name(struct net *net,
  1715. const char *link_name,
  1716. unsigned int *bearer_id)
  1717. {
  1718. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1719. struct tipc_link *l;
  1720. struct tipc_node *n;
  1721. struct tipc_node *found_node = NULL;
  1722. int i;
  1723. *bearer_id = 0;
  1724. rcu_read_lock();
  1725. list_for_each_entry_rcu(n, &tn->node_list, list) {
  1726. tipc_node_read_lock(n);
  1727. for (i = 0; i < MAX_BEARERS; i++) {
  1728. l = n->links[i].link;
  1729. if (l && !strcmp(tipc_link_name(l), link_name)) {
  1730. *bearer_id = i;
  1731. found_node = n;
  1732. break;
  1733. }
  1734. }
  1735. tipc_node_read_unlock(n);
  1736. if (found_node)
  1737. break;
  1738. }
  1739. rcu_read_unlock();
  1740. return found_node;
  1741. }
  1742. int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)
  1743. {
  1744. int err;
  1745. int res = 0;
  1746. int bearer_id;
  1747. char *name;
  1748. struct tipc_link *link;
  1749. struct tipc_node *node;
  1750. struct sk_buff_head xmitq;
  1751. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1752. struct net *net = sock_net(skb->sk);
  1753. __skb_queue_head_init(&xmitq);
  1754. if (!info->attrs[TIPC_NLA_LINK])
  1755. return -EINVAL;
  1756. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1757. info->attrs[TIPC_NLA_LINK],
  1758. tipc_nl_link_policy, info->extack);
  1759. if (err)
  1760. return err;
  1761. if (!attrs[TIPC_NLA_LINK_NAME])
  1762. return -EINVAL;
  1763. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1764. if (strcmp(name, tipc_bclink_name) == 0)
  1765. return tipc_nl_bc_link_set(net, attrs);
  1766. node = tipc_node_find_by_name(net, name, &bearer_id);
  1767. if (!node)
  1768. return -EINVAL;
  1769. tipc_node_read_lock(node);
  1770. link = node->links[bearer_id].link;
  1771. if (!link) {
  1772. res = -EINVAL;
  1773. goto out;
  1774. }
  1775. if (attrs[TIPC_NLA_LINK_PROP]) {
  1776. struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
  1777. err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
  1778. props);
  1779. if (err) {
  1780. res = err;
  1781. goto out;
  1782. }
  1783. if (props[TIPC_NLA_PROP_TOL]) {
  1784. u32 tol;
  1785. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1786. tipc_link_set_tolerance(link, tol, &xmitq);
  1787. }
  1788. if (props[TIPC_NLA_PROP_PRIO]) {
  1789. u32 prio;
  1790. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1791. tipc_link_set_prio(link, prio, &xmitq);
  1792. }
  1793. if (props[TIPC_NLA_PROP_WIN]) {
  1794. u32 win;
  1795. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1796. tipc_link_set_queue_limits(link, win);
  1797. }
  1798. }
  1799. out:
  1800. tipc_node_read_unlock(node);
  1801. tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr);
  1802. return res;
  1803. }
  1804. int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
  1805. {
  1806. struct net *net = genl_info_net(info);
  1807. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1808. struct tipc_nl_msg msg;
  1809. char *name;
  1810. int err;
  1811. msg.portid = info->snd_portid;
  1812. msg.seq = info->snd_seq;
  1813. if (!info->attrs[TIPC_NLA_LINK])
  1814. return -EINVAL;
  1815. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1816. info->attrs[TIPC_NLA_LINK],
  1817. tipc_nl_link_policy, info->extack);
  1818. if (err)
  1819. return err;
  1820. if (!attrs[TIPC_NLA_LINK_NAME])
  1821. return -EINVAL;
  1822. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1823. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1824. if (!msg.skb)
  1825. return -ENOMEM;
  1826. if (strcmp(name, tipc_bclink_name) == 0) {
  1827. err = tipc_nl_add_bc_link(net, &msg);
  1828. if (err)
  1829. goto err_free;
  1830. } else {
  1831. int bearer_id;
  1832. struct tipc_node *node;
  1833. struct tipc_link *link;
  1834. node = tipc_node_find_by_name(net, name, &bearer_id);
  1835. if (!node) {
  1836. err = -EINVAL;
  1837. goto err_free;
  1838. }
  1839. tipc_node_read_lock(node);
  1840. link = node->links[bearer_id].link;
  1841. if (!link) {
  1842. tipc_node_read_unlock(node);
  1843. err = -EINVAL;
  1844. goto err_free;
  1845. }
  1846. err = __tipc_nl_add_link(net, &msg, link, 0);
  1847. tipc_node_read_unlock(node);
  1848. if (err)
  1849. goto err_free;
  1850. }
  1851. return genlmsg_reply(msg.skb, info);
  1852. err_free:
  1853. nlmsg_free(msg.skb);
  1854. return err;
  1855. }
  1856. int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)
  1857. {
  1858. int err;
  1859. char *link_name;
  1860. unsigned int bearer_id;
  1861. struct tipc_link *link;
  1862. struct tipc_node *node;
  1863. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1864. struct net *net = sock_net(skb->sk);
  1865. struct tipc_link_entry *le;
  1866. if (!info->attrs[TIPC_NLA_LINK])
  1867. return -EINVAL;
  1868. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1869. info->attrs[TIPC_NLA_LINK],
  1870. tipc_nl_link_policy, info->extack);
  1871. if (err)
  1872. return err;
  1873. if (!attrs[TIPC_NLA_LINK_NAME])
  1874. return -EINVAL;
  1875. link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1876. if (strcmp(link_name, tipc_bclink_name) == 0) {
  1877. err = tipc_bclink_reset_stats(net);
  1878. if (err)
  1879. return err;
  1880. return 0;
  1881. }
  1882. node = tipc_node_find_by_name(net, link_name, &bearer_id);
  1883. if (!node)
  1884. return -EINVAL;
  1885. le = &node->links[bearer_id];
  1886. tipc_node_read_lock(node);
  1887. spin_lock_bh(&le->lock);
  1888. link = node->links[bearer_id].link;
  1889. if (!link) {
  1890. spin_unlock_bh(&le->lock);
  1891. tipc_node_read_unlock(node);
  1892. return -EINVAL;
  1893. }
  1894. tipc_link_reset_stats(link);
  1895. spin_unlock_bh(&le->lock);
  1896. tipc_node_read_unlock(node);
  1897. return 0;
  1898. }
  1899. /* Caller should hold node lock */
  1900. static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
  1901. struct tipc_node *node, u32 *prev_link)
  1902. {
  1903. u32 i;
  1904. int err;
  1905. for (i = *prev_link; i < MAX_BEARERS; i++) {
  1906. *prev_link = i;
  1907. if (!node->links[i].link)
  1908. continue;
  1909. err = __tipc_nl_add_link(net, msg,
  1910. node->links[i].link, NLM_F_MULTI);
  1911. if (err)
  1912. return err;
  1913. }
  1914. *prev_link = 0;
  1915. return 0;
  1916. }
  1917. int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb)
  1918. {
  1919. struct net *net = sock_net(skb->sk);
  1920. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1921. struct tipc_node *node;
  1922. struct tipc_nl_msg msg;
  1923. u32 prev_node = cb->args[0];
  1924. u32 prev_link = cb->args[1];
  1925. int done = cb->args[2];
  1926. int err;
  1927. if (done)
  1928. return 0;
  1929. msg.skb = skb;
  1930. msg.portid = NETLINK_CB(cb->skb).portid;
  1931. msg.seq = cb->nlh->nlmsg_seq;
  1932. rcu_read_lock();
  1933. if (prev_node) {
  1934. node = tipc_node_find(net, prev_node);
  1935. if (!node) {
  1936. /* We never set seq or call nl_dump_check_consistent()
  1937. * this means that setting prev_seq here will cause the
  1938. * consistence check to fail in the netlink callback
  1939. * handler. Resulting in the last NLMSG_DONE message
  1940. * having the NLM_F_DUMP_INTR flag set.
  1941. */
  1942. cb->prev_seq = 1;
  1943. goto out;
  1944. }
  1945. tipc_node_put(node);
  1946. list_for_each_entry_continue_rcu(node, &tn->node_list,
  1947. list) {
  1948. tipc_node_read_lock(node);
  1949. err = __tipc_nl_add_node_links(net, &msg, node,
  1950. &prev_link);
  1951. tipc_node_read_unlock(node);
  1952. if (err)
  1953. goto out;
  1954. prev_node = node->addr;
  1955. }
  1956. } else {
  1957. err = tipc_nl_add_bc_link(net, &msg);
  1958. if (err)
  1959. goto out;
  1960. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1961. tipc_node_read_lock(node);
  1962. err = __tipc_nl_add_node_links(net, &msg, node,
  1963. &prev_link);
  1964. tipc_node_read_unlock(node);
  1965. if (err)
  1966. goto out;
  1967. prev_node = node->addr;
  1968. }
  1969. }
  1970. done = 1;
  1971. out:
  1972. rcu_read_unlock();
  1973. cb->args[0] = prev_node;
  1974. cb->args[1] = prev_link;
  1975. cb->args[2] = done;
  1976. return skb->len;
  1977. }
  1978. int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info)
  1979. {
  1980. struct nlattr *attrs[TIPC_NLA_MON_MAX + 1];
  1981. struct net *net = sock_net(skb->sk);
  1982. int err;
  1983. if (!info->attrs[TIPC_NLA_MON])
  1984. return -EINVAL;
  1985. err = nla_parse_nested(attrs, TIPC_NLA_MON_MAX,
  1986. info->attrs[TIPC_NLA_MON],
  1987. tipc_nl_monitor_policy, info->extack);
  1988. if (err)
  1989. return err;
  1990. if (attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]) {
  1991. u32 val;
  1992. val = nla_get_u32(attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]);
  1993. err = tipc_nl_monitor_set_threshold(net, val);
  1994. if (err)
  1995. return err;
  1996. }
  1997. return 0;
  1998. }
  1999. static int __tipc_nl_add_monitor_prop(struct net *net, struct tipc_nl_msg *msg)
  2000. {
  2001. struct nlattr *attrs;
  2002. void *hdr;
  2003. u32 val;
  2004. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  2005. 0, TIPC_NL_MON_GET);
  2006. if (!hdr)
  2007. return -EMSGSIZE;
  2008. attrs = nla_nest_start(msg->skb, TIPC_NLA_MON);
  2009. if (!attrs)
  2010. goto msg_full;
  2011. val = tipc_nl_monitor_get_threshold(net);
  2012. if (nla_put_u32(msg->skb, TIPC_NLA_MON_ACTIVATION_THRESHOLD, val))
  2013. goto attr_msg_full;
  2014. nla_nest_end(msg->skb, attrs);
  2015. genlmsg_end(msg->skb, hdr);
  2016. return 0;
  2017. attr_msg_full:
  2018. nla_nest_cancel(msg->skb, attrs);
  2019. msg_full:
  2020. genlmsg_cancel(msg->skb, hdr);
  2021. return -EMSGSIZE;
  2022. }
  2023. int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info)
  2024. {
  2025. struct net *net = sock_net(skb->sk);
  2026. struct tipc_nl_msg msg;
  2027. int err;
  2028. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  2029. if (!msg.skb)
  2030. return -ENOMEM;
  2031. msg.portid = info->snd_portid;
  2032. msg.seq = info->snd_seq;
  2033. err = __tipc_nl_add_monitor_prop(net, &msg);
  2034. if (err) {
  2035. nlmsg_free(msg.skb);
  2036. return err;
  2037. }
  2038. return genlmsg_reply(msg.skb, info);
  2039. }
  2040. int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
  2041. {
  2042. struct net *net = sock_net(skb->sk);
  2043. u32 prev_bearer = cb->args[0];
  2044. struct tipc_nl_msg msg;
  2045. int bearer_id;
  2046. int err;
  2047. if (prev_bearer == MAX_BEARERS)
  2048. return 0;
  2049. msg.skb = skb;
  2050. msg.portid = NETLINK_CB(cb->skb).portid;
  2051. msg.seq = cb->nlh->nlmsg_seq;
  2052. rtnl_lock();
  2053. for (bearer_id = prev_bearer; bearer_id < MAX_BEARERS; bearer_id++) {
  2054. err = __tipc_nl_add_monitor(net, &msg, bearer_id);
  2055. if (err)
  2056. break;
  2057. }
  2058. rtnl_unlock();
  2059. cb->args[0] = bearer_id;
  2060. return skb->len;
  2061. }
  2062. int tipc_nl_node_dump_monitor_peer(struct sk_buff *skb,
  2063. struct netlink_callback *cb)
  2064. {
  2065. struct net *net = sock_net(skb->sk);
  2066. u32 prev_node = cb->args[1];
  2067. u32 bearer_id = cb->args[2];
  2068. int done = cb->args[0];
  2069. struct tipc_nl_msg msg;
  2070. int err;
  2071. if (!prev_node) {
  2072. struct nlattr **attrs;
  2073. struct nlattr *mon[TIPC_NLA_MON_MAX + 1];
  2074. err = tipc_nlmsg_parse(cb->nlh, &attrs);
  2075. if (err)
  2076. return err;
  2077. if (!attrs[TIPC_NLA_MON])
  2078. return -EINVAL;
  2079. err = nla_parse_nested(mon, TIPC_NLA_MON_MAX,
  2080. attrs[TIPC_NLA_MON],
  2081. tipc_nl_monitor_policy, NULL);
  2082. if (err)
  2083. return err;
  2084. if (!mon[TIPC_NLA_MON_REF])
  2085. return -EINVAL;
  2086. bearer_id = nla_get_u32(mon[TIPC_NLA_MON_REF]);
  2087. if (bearer_id >= MAX_BEARERS)
  2088. return -EINVAL;
  2089. }
  2090. if (done)
  2091. return 0;
  2092. msg.skb = skb;
  2093. msg.portid = NETLINK_CB(cb->skb).portid;
  2094. msg.seq = cb->nlh->nlmsg_seq;
  2095. rtnl_lock();
  2096. err = tipc_nl_add_monitor_peer(net, &msg, bearer_id, &prev_node);
  2097. if (!err)
  2098. done = 1;
  2099. rtnl_unlock();
  2100. cb->args[0] = done;
  2101. cb->args[1] = prev_node;
  2102. cb->args[2] = bearer_id;
  2103. return skb->len;
  2104. }