node.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  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_link *l = le->link;
  715. struct tipc_media_addr *maddr;
  716. struct sk_buff_head xmitq;
  717. int old_bearer_id = bearer_id;
  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. tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
  737. tipc_sk_rcv(n->net, &le->inputq);
  738. }
  739. static bool node_is_up(struct tipc_node *n)
  740. {
  741. return n->active_links[0] != INVALID_BEARER_ID;
  742. }
  743. bool tipc_node_is_up(struct net *net, u32 addr)
  744. {
  745. struct tipc_node *n;
  746. bool retval = false;
  747. if (in_own_node(net, addr))
  748. return true;
  749. n = tipc_node_find(net, addr);
  750. if (!n)
  751. return false;
  752. retval = node_is_up(n);
  753. tipc_node_put(n);
  754. return retval;
  755. }
  756. static u32 tipc_node_suggest_addr(struct net *net, u32 addr)
  757. {
  758. struct tipc_node *n;
  759. addr ^= tipc_net(net)->random;
  760. while ((n = tipc_node_find(net, addr))) {
  761. tipc_node_put(n);
  762. addr++;
  763. }
  764. return addr;
  765. }
  766. /* tipc_node_try_addr(): Check if addr can be used by peer, suggest other if not
  767. * Returns suggested address if any, otherwise 0
  768. */
  769. u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr)
  770. {
  771. struct tipc_net *tn = tipc_net(net);
  772. struct tipc_node *n;
  773. /* Suggest new address if some other peer is using this one */
  774. n = tipc_node_find(net, addr);
  775. if (n) {
  776. if (!memcmp(n->peer_id, id, NODE_ID_LEN))
  777. addr = 0;
  778. tipc_node_put(n);
  779. if (!addr)
  780. return 0;
  781. return tipc_node_suggest_addr(net, addr);
  782. }
  783. /* Suggest previously used address if peer is known */
  784. n = tipc_node_find_by_id(net, id);
  785. if (n) {
  786. addr = n->addr;
  787. tipc_node_put(n);
  788. return addr;
  789. }
  790. /* Even this node may be in conflict */
  791. if (tn->trial_addr == addr)
  792. return tipc_node_suggest_addr(net, addr);
  793. return 0;
  794. }
  795. void tipc_node_check_dest(struct net *net, u32 addr,
  796. u8 *peer_id, struct tipc_bearer *b,
  797. u16 capabilities, u32 signature,
  798. struct tipc_media_addr *maddr,
  799. bool *respond, bool *dupl_addr)
  800. {
  801. struct tipc_node *n;
  802. struct tipc_link *l;
  803. struct tipc_link_entry *le;
  804. bool addr_match = false;
  805. bool sign_match = false;
  806. bool link_up = false;
  807. bool accept_addr = false;
  808. bool reset = true;
  809. char *if_name;
  810. unsigned long intv;
  811. u16 session;
  812. *dupl_addr = false;
  813. *respond = false;
  814. n = tipc_node_create(net, addr, peer_id, capabilities);
  815. if (!n)
  816. return;
  817. tipc_node_write_lock(n);
  818. le = &n->links[b->identity];
  819. /* Prepare to validate requesting node's signature and media address */
  820. l = le->link;
  821. link_up = l && tipc_link_is_up(l);
  822. addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
  823. sign_match = (signature == n->signature);
  824. /* These three flags give us eight permutations: */
  825. if (sign_match && addr_match && link_up) {
  826. /* All is fine. Do nothing. */
  827. reset = false;
  828. } else if (sign_match && addr_match && !link_up) {
  829. /* Respond. The link will come up in due time */
  830. *respond = true;
  831. } else if (sign_match && !addr_match && link_up) {
  832. /* Peer has changed i/f address without rebooting.
  833. * If so, the link will reset soon, and the next
  834. * discovery will be accepted. So we can ignore it.
  835. * It may also be an cloned or malicious peer having
  836. * chosen the same node address and signature as an
  837. * existing one.
  838. * Ignore requests until the link goes down, if ever.
  839. */
  840. *dupl_addr = true;
  841. } else if (sign_match && !addr_match && !link_up) {
  842. /* Peer link has changed i/f address without rebooting.
  843. * It may also be a cloned or malicious peer; we can't
  844. * distinguish between the two.
  845. * The signature is correct, so we must accept.
  846. */
  847. accept_addr = true;
  848. *respond = true;
  849. } else if (!sign_match && addr_match && link_up) {
  850. /* Peer node rebooted. Two possibilities:
  851. * - Delayed re-discovery; this link endpoint has already
  852. * reset and re-established contact with the peer, before
  853. * receiving a discovery message from that node.
  854. * (The peer happened to receive one from this node first).
  855. * - The peer came back so fast that our side has not
  856. * discovered it yet. Probing from this side will soon
  857. * reset the link, since there can be no working link
  858. * endpoint at the peer end, and the link will re-establish.
  859. * Accept the signature, since it comes from a known peer.
  860. */
  861. n->signature = signature;
  862. } else if (!sign_match && addr_match && !link_up) {
  863. /* The peer node has rebooted.
  864. * Accept signature, since it is a known peer.
  865. */
  866. n->signature = signature;
  867. *respond = true;
  868. } else if (!sign_match && !addr_match && link_up) {
  869. /* Peer rebooted with new address, or a new/duplicate peer.
  870. * Ignore until the link goes down, if ever.
  871. */
  872. *dupl_addr = true;
  873. } else if (!sign_match && !addr_match && !link_up) {
  874. /* Peer rebooted with new address, or it is a new peer.
  875. * Accept signature and address.
  876. */
  877. n->signature = signature;
  878. accept_addr = true;
  879. *respond = true;
  880. }
  881. if (!accept_addr)
  882. goto exit;
  883. /* Now create new link if not already existing */
  884. if (!l) {
  885. if (n->link_cnt == 2)
  886. goto exit;
  887. if_name = strchr(b->name, ':') + 1;
  888. get_random_bytes(&session, sizeof(u16));
  889. if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
  890. b->net_plane, b->mtu, b->priority,
  891. b->window, session,
  892. tipc_own_addr(net), addr, peer_id,
  893. n->capabilities,
  894. tipc_bc_sndlink(n->net), n->bc_entry.link,
  895. &le->inputq,
  896. &n->bc_entry.namedq, &l)) {
  897. *respond = false;
  898. goto exit;
  899. }
  900. tipc_link_reset(l);
  901. tipc_link_fsm_evt(l, LINK_RESET_EVT);
  902. if (n->state == NODE_FAILINGOVER)
  903. tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
  904. le->link = l;
  905. n->link_cnt++;
  906. tipc_node_calculate_timer(n, l);
  907. if (n->link_cnt == 1) {
  908. intv = jiffies + msecs_to_jiffies(n->keepalive_intv);
  909. if (!mod_timer(&n->timer, intv))
  910. tipc_node_get(n);
  911. }
  912. }
  913. memcpy(&le->maddr, maddr, sizeof(*maddr));
  914. exit:
  915. tipc_node_write_unlock(n);
  916. if (reset && l && !tipc_link_is_reset(l))
  917. tipc_node_link_down(n, b->identity, false);
  918. tipc_node_put(n);
  919. }
  920. void tipc_node_delete_links(struct net *net, int bearer_id)
  921. {
  922. struct tipc_net *tn = net_generic(net, tipc_net_id);
  923. struct tipc_node *n;
  924. rcu_read_lock();
  925. list_for_each_entry_rcu(n, &tn->node_list, list) {
  926. tipc_node_link_down(n, bearer_id, true);
  927. }
  928. rcu_read_unlock();
  929. }
  930. static void tipc_node_reset_links(struct tipc_node *n)
  931. {
  932. int i;
  933. pr_warn("Resetting all links to %x\n", n->addr);
  934. for (i = 0; i < MAX_BEARERS; i++) {
  935. tipc_node_link_down(n, i, false);
  936. }
  937. }
  938. /* tipc_node_fsm_evt - node finite state machine
  939. * Determines when contact is allowed with peer node
  940. */
  941. static void tipc_node_fsm_evt(struct tipc_node *n, int evt)
  942. {
  943. int state = n->state;
  944. switch (state) {
  945. case SELF_DOWN_PEER_DOWN:
  946. switch (evt) {
  947. case SELF_ESTABL_CONTACT_EVT:
  948. state = SELF_UP_PEER_COMING;
  949. break;
  950. case PEER_ESTABL_CONTACT_EVT:
  951. state = SELF_COMING_PEER_UP;
  952. break;
  953. case SELF_LOST_CONTACT_EVT:
  954. case PEER_LOST_CONTACT_EVT:
  955. break;
  956. case NODE_SYNCH_END_EVT:
  957. case NODE_SYNCH_BEGIN_EVT:
  958. case NODE_FAILOVER_BEGIN_EVT:
  959. case NODE_FAILOVER_END_EVT:
  960. default:
  961. goto illegal_evt;
  962. }
  963. break;
  964. case SELF_UP_PEER_UP:
  965. switch (evt) {
  966. case SELF_LOST_CONTACT_EVT:
  967. state = SELF_DOWN_PEER_LEAVING;
  968. break;
  969. case PEER_LOST_CONTACT_EVT:
  970. state = SELF_LEAVING_PEER_DOWN;
  971. break;
  972. case NODE_SYNCH_BEGIN_EVT:
  973. state = NODE_SYNCHING;
  974. break;
  975. case NODE_FAILOVER_BEGIN_EVT:
  976. state = NODE_FAILINGOVER;
  977. break;
  978. case SELF_ESTABL_CONTACT_EVT:
  979. case PEER_ESTABL_CONTACT_EVT:
  980. case NODE_SYNCH_END_EVT:
  981. case NODE_FAILOVER_END_EVT:
  982. break;
  983. default:
  984. goto illegal_evt;
  985. }
  986. break;
  987. case SELF_DOWN_PEER_LEAVING:
  988. switch (evt) {
  989. case PEER_LOST_CONTACT_EVT:
  990. state = SELF_DOWN_PEER_DOWN;
  991. break;
  992. case SELF_ESTABL_CONTACT_EVT:
  993. case PEER_ESTABL_CONTACT_EVT:
  994. case SELF_LOST_CONTACT_EVT:
  995. break;
  996. case NODE_SYNCH_END_EVT:
  997. case NODE_SYNCH_BEGIN_EVT:
  998. case NODE_FAILOVER_BEGIN_EVT:
  999. case NODE_FAILOVER_END_EVT:
  1000. default:
  1001. goto illegal_evt;
  1002. }
  1003. break;
  1004. case SELF_UP_PEER_COMING:
  1005. switch (evt) {
  1006. case PEER_ESTABL_CONTACT_EVT:
  1007. state = SELF_UP_PEER_UP;
  1008. break;
  1009. case SELF_LOST_CONTACT_EVT:
  1010. state = SELF_DOWN_PEER_DOWN;
  1011. break;
  1012. case SELF_ESTABL_CONTACT_EVT:
  1013. case PEER_LOST_CONTACT_EVT:
  1014. case NODE_SYNCH_END_EVT:
  1015. case NODE_FAILOVER_BEGIN_EVT:
  1016. break;
  1017. case NODE_SYNCH_BEGIN_EVT:
  1018. case NODE_FAILOVER_END_EVT:
  1019. default:
  1020. goto illegal_evt;
  1021. }
  1022. break;
  1023. case SELF_COMING_PEER_UP:
  1024. switch (evt) {
  1025. case SELF_ESTABL_CONTACT_EVT:
  1026. state = SELF_UP_PEER_UP;
  1027. break;
  1028. case PEER_LOST_CONTACT_EVT:
  1029. state = SELF_DOWN_PEER_DOWN;
  1030. break;
  1031. case SELF_LOST_CONTACT_EVT:
  1032. case PEER_ESTABL_CONTACT_EVT:
  1033. break;
  1034. case NODE_SYNCH_END_EVT:
  1035. case NODE_SYNCH_BEGIN_EVT:
  1036. case NODE_FAILOVER_BEGIN_EVT:
  1037. case NODE_FAILOVER_END_EVT:
  1038. default:
  1039. goto illegal_evt;
  1040. }
  1041. break;
  1042. case SELF_LEAVING_PEER_DOWN:
  1043. switch (evt) {
  1044. case SELF_LOST_CONTACT_EVT:
  1045. state = SELF_DOWN_PEER_DOWN;
  1046. break;
  1047. case SELF_ESTABL_CONTACT_EVT:
  1048. case PEER_ESTABL_CONTACT_EVT:
  1049. case PEER_LOST_CONTACT_EVT:
  1050. break;
  1051. case NODE_SYNCH_END_EVT:
  1052. case NODE_SYNCH_BEGIN_EVT:
  1053. case NODE_FAILOVER_BEGIN_EVT:
  1054. case NODE_FAILOVER_END_EVT:
  1055. default:
  1056. goto illegal_evt;
  1057. }
  1058. break;
  1059. case NODE_FAILINGOVER:
  1060. switch (evt) {
  1061. case SELF_LOST_CONTACT_EVT:
  1062. state = SELF_DOWN_PEER_LEAVING;
  1063. break;
  1064. case PEER_LOST_CONTACT_EVT:
  1065. state = SELF_LEAVING_PEER_DOWN;
  1066. break;
  1067. case NODE_FAILOVER_END_EVT:
  1068. state = SELF_UP_PEER_UP;
  1069. break;
  1070. case NODE_FAILOVER_BEGIN_EVT:
  1071. case SELF_ESTABL_CONTACT_EVT:
  1072. case PEER_ESTABL_CONTACT_EVT:
  1073. break;
  1074. case NODE_SYNCH_BEGIN_EVT:
  1075. case NODE_SYNCH_END_EVT:
  1076. default:
  1077. goto illegal_evt;
  1078. }
  1079. break;
  1080. case NODE_SYNCHING:
  1081. switch (evt) {
  1082. case SELF_LOST_CONTACT_EVT:
  1083. state = SELF_DOWN_PEER_LEAVING;
  1084. break;
  1085. case PEER_LOST_CONTACT_EVT:
  1086. state = SELF_LEAVING_PEER_DOWN;
  1087. break;
  1088. case NODE_SYNCH_END_EVT:
  1089. state = SELF_UP_PEER_UP;
  1090. break;
  1091. case NODE_FAILOVER_BEGIN_EVT:
  1092. state = NODE_FAILINGOVER;
  1093. break;
  1094. case NODE_SYNCH_BEGIN_EVT:
  1095. case SELF_ESTABL_CONTACT_EVT:
  1096. case PEER_ESTABL_CONTACT_EVT:
  1097. break;
  1098. case NODE_FAILOVER_END_EVT:
  1099. default:
  1100. goto illegal_evt;
  1101. }
  1102. break;
  1103. default:
  1104. pr_err("Unknown node fsm state %x\n", state);
  1105. break;
  1106. }
  1107. n->state = state;
  1108. return;
  1109. illegal_evt:
  1110. pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
  1111. }
  1112. static void node_lost_contact(struct tipc_node *n,
  1113. struct sk_buff_head *inputq)
  1114. {
  1115. struct tipc_sock_conn *conn, *safe;
  1116. struct tipc_link *l;
  1117. struct list_head *conns = &n->conn_sks;
  1118. struct sk_buff *skb;
  1119. uint i;
  1120. pr_debug("Lost contact with %x\n", n->addr);
  1121. n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER);
  1122. /* Clean up broadcast state */
  1123. tipc_bcast_remove_peer(n->net, n->bc_entry.link);
  1124. /* Abort any ongoing link failover */
  1125. for (i = 0; i < MAX_BEARERS; i++) {
  1126. l = n->links[i].link;
  1127. if (l)
  1128. tipc_link_fsm_evt(l, LINK_FAILOVER_END_EVT);
  1129. }
  1130. /* Notify publications from this node */
  1131. n->action_flags |= TIPC_NOTIFY_NODE_DOWN;
  1132. /* Notify sockets connected to node */
  1133. list_for_each_entry_safe(conn, safe, conns, list) {
  1134. skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
  1135. SHORT_H_SIZE, 0, tipc_own_addr(n->net),
  1136. conn->peer_node, conn->port,
  1137. conn->peer_port, TIPC_ERR_NO_NODE);
  1138. if (likely(skb))
  1139. skb_queue_tail(inputq, skb);
  1140. list_del(&conn->list);
  1141. kfree(conn);
  1142. }
  1143. }
  1144. /**
  1145. * tipc_node_get_linkname - get the name of a link
  1146. *
  1147. * @bearer_id: id of the bearer
  1148. * @node: peer node address
  1149. * @linkname: link name output buffer
  1150. *
  1151. * Returns 0 on success
  1152. */
  1153. int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,
  1154. char *linkname, size_t len)
  1155. {
  1156. struct tipc_link *link;
  1157. int err = -EINVAL;
  1158. struct tipc_node *node = tipc_node_find(net, addr);
  1159. if (!node)
  1160. return err;
  1161. if (bearer_id >= MAX_BEARERS)
  1162. goto exit;
  1163. tipc_node_read_lock(node);
  1164. link = node->links[bearer_id].link;
  1165. if (link) {
  1166. strncpy(linkname, tipc_link_name(link), len);
  1167. err = 0;
  1168. }
  1169. tipc_node_read_unlock(node);
  1170. exit:
  1171. tipc_node_put(node);
  1172. return err;
  1173. }
  1174. /* Caller should hold node lock for the passed node */
  1175. static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
  1176. {
  1177. void *hdr;
  1178. struct nlattr *attrs;
  1179. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1180. NLM_F_MULTI, TIPC_NL_NODE_GET);
  1181. if (!hdr)
  1182. return -EMSGSIZE;
  1183. attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
  1184. if (!attrs)
  1185. goto msg_full;
  1186. if (nla_put_u32(msg->skb, TIPC_NLA_NODE_ADDR, node->addr))
  1187. goto attr_msg_full;
  1188. if (node_is_up(node))
  1189. if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP))
  1190. goto attr_msg_full;
  1191. nla_nest_end(msg->skb, attrs);
  1192. genlmsg_end(msg->skb, hdr);
  1193. return 0;
  1194. attr_msg_full:
  1195. nla_nest_cancel(msg->skb, attrs);
  1196. msg_full:
  1197. genlmsg_cancel(msg->skb, hdr);
  1198. return -EMSGSIZE;
  1199. }
  1200. /**
  1201. * tipc_node_xmit() is the general link level function for message sending
  1202. * @net: the applicable net namespace
  1203. * @list: chain of buffers containing message
  1204. * @dnode: address of destination node
  1205. * @selector: a number used for deterministic link selection
  1206. * Consumes the buffer chain.
  1207. * Returns 0 if success, otherwise: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE,-ENOBUF
  1208. */
  1209. int tipc_node_xmit(struct net *net, struct sk_buff_head *list,
  1210. u32 dnode, int selector)
  1211. {
  1212. struct tipc_link_entry *le = NULL;
  1213. struct tipc_node *n;
  1214. struct sk_buff_head xmitq;
  1215. int bearer_id;
  1216. int rc;
  1217. if (in_own_node(net, dnode)) {
  1218. tipc_sk_rcv(net, list);
  1219. return 0;
  1220. }
  1221. n = tipc_node_find(net, dnode);
  1222. if (unlikely(!n)) {
  1223. skb_queue_purge(list);
  1224. return -EHOSTUNREACH;
  1225. }
  1226. tipc_node_read_lock(n);
  1227. bearer_id = n->active_links[selector & 1];
  1228. if (unlikely(bearer_id == INVALID_BEARER_ID)) {
  1229. tipc_node_read_unlock(n);
  1230. tipc_node_put(n);
  1231. skb_queue_purge(list);
  1232. return -EHOSTUNREACH;
  1233. }
  1234. __skb_queue_head_init(&xmitq);
  1235. le = &n->links[bearer_id];
  1236. spin_lock_bh(&le->lock);
  1237. rc = tipc_link_xmit(le->link, list, &xmitq);
  1238. spin_unlock_bh(&le->lock);
  1239. tipc_node_read_unlock(n);
  1240. if (unlikely(rc == -ENOBUFS))
  1241. tipc_node_link_down(n, bearer_id, false);
  1242. else
  1243. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1244. tipc_node_put(n);
  1245. return rc;
  1246. }
  1247. /* tipc_node_xmit_skb(): send single buffer to destination
  1248. * Buffers sent via this functon are generally TIPC_SYSTEM_IMPORTANCE
  1249. * messages, which will not be rejected
  1250. * The only exception is datagram messages rerouted after secondary
  1251. * lookup, which are rare and safe to dispose of anyway.
  1252. */
  1253. int tipc_node_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode,
  1254. u32 selector)
  1255. {
  1256. struct sk_buff_head head;
  1257. skb_queue_head_init(&head);
  1258. __skb_queue_tail(&head, skb);
  1259. tipc_node_xmit(net, &head, dnode, selector);
  1260. return 0;
  1261. }
  1262. /* tipc_node_distr_xmit(): send single buffer msgs to individual destinations
  1263. * Note: this is only for SYSTEM_IMPORTANCE messages, which cannot be rejected
  1264. */
  1265. int tipc_node_distr_xmit(struct net *net, struct sk_buff_head *xmitq)
  1266. {
  1267. struct sk_buff *skb;
  1268. u32 selector, dnode;
  1269. while ((skb = __skb_dequeue(xmitq))) {
  1270. selector = msg_origport(buf_msg(skb));
  1271. dnode = msg_destnode(buf_msg(skb));
  1272. tipc_node_xmit_skb(net, skb, dnode, selector);
  1273. }
  1274. return 0;
  1275. }
  1276. void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
  1277. {
  1278. struct sk_buff *txskb;
  1279. struct tipc_node *n;
  1280. u32 dst;
  1281. rcu_read_lock();
  1282. list_for_each_entry_rcu(n, tipc_nodes(net), list) {
  1283. dst = n->addr;
  1284. if (in_own_node(net, dst))
  1285. continue;
  1286. if (!node_is_up(n))
  1287. continue;
  1288. txskb = pskb_copy(skb, GFP_ATOMIC);
  1289. if (!txskb)
  1290. break;
  1291. msg_set_destnode(buf_msg(txskb), dst);
  1292. tipc_node_xmit_skb(net, txskb, dst, 0);
  1293. }
  1294. rcu_read_unlock();
  1295. kfree_skb(skb);
  1296. }
  1297. static void tipc_node_mcast_rcv(struct tipc_node *n)
  1298. {
  1299. struct tipc_bclink_entry *be = &n->bc_entry;
  1300. /* 'arrvq' is under inputq2's lock protection */
  1301. spin_lock_bh(&be->inputq2.lock);
  1302. spin_lock_bh(&be->inputq1.lock);
  1303. skb_queue_splice_tail_init(&be->inputq1, &be->arrvq);
  1304. spin_unlock_bh(&be->inputq1.lock);
  1305. spin_unlock_bh(&be->inputq2.lock);
  1306. tipc_sk_mcast_rcv(n->net, &be->arrvq, &be->inputq2);
  1307. }
  1308. static void tipc_node_bc_sync_rcv(struct tipc_node *n, struct tipc_msg *hdr,
  1309. int bearer_id, struct sk_buff_head *xmitq)
  1310. {
  1311. struct tipc_link *ucl;
  1312. int rc;
  1313. rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr);
  1314. if (rc & TIPC_LINK_DOWN_EVT) {
  1315. tipc_node_reset_links(n);
  1316. return;
  1317. }
  1318. if (!(rc & TIPC_LINK_SND_STATE))
  1319. return;
  1320. /* If probe message, a STATE response will be sent anyway */
  1321. if (msg_probe(hdr))
  1322. return;
  1323. /* Produce a STATE message carrying broadcast NACK */
  1324. tipc_node_read_lock(n);
  1325. ucl = n->links[bearer_id].link;
  1326. if (ucl)
  1327. tipc_link_build_state_msg(ucl, xmitq);
  1328. tipc_node_read_unlock(n);
  1329. }
  1330. /**
  1331. * tipc_node_bc_rcv - process TIPC broadcast packet arriving from off-node
  1332. * @net: the applicable net namespace
  1333. * @skb: TIPC packet
  1334. * @bearer_id: id of bearer message arrived on
  1335. *
  1336. * Invoked with no locks held.
  1337. */
  1338. static void tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id)
  1339. {
  1340. int rc;
  1341. struct sk_buff_head xmitq;
  1342. struct tipc_bclink_entry *be;
  1343. struct tipc_link_entry *le;
  1344. struct tipc_msg *hdr = buf_msg(skb);
  1345. int usr = msg_user(hdr);
  1346. u32 dnode = msg_destnode(hdr);
  1347. struct tipc_node *n;
  1348. __skb_queue_head_init(&xmitq);
  1349. /* If NACK for other node, let rcv link for that node peek into it */
  1350. if ((usr == BCAST_PROTOCOL) && (dnode != tipc_own_addr(net)))
  1351. n = tipc_node_find(net, dnode);
  1352. else
  1353. n = tipc_node_find(net, msg_prevnode(hdr));
  1354. if (!n) {
  1355. kfree_skb(skb);
  1356. return;
  1357. }
  1358. be = &n->bc_entry;
  1359. le = &n->links[bearer_id];
  1360. rc = tipc_bcast_rcv(net, be->link, skb);
  1361. /* Broadcast ACKs are sent on a unicast link */
  1362. if (rc & TIPC_LINK_SND_STATE) {
  1363. tipc_node_read_lock(n);
  1364. tipc_link_build_state_msg(le->link, &xmitq);
  1365. tipc_node_read_unlock(n);
  1366. }
  1367. if (!skb_queue_empty(&xmitq))
  1368. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1369. if (!skb_queue_empty(&be->inputq1))
  1370. tipc_node_mcast_rcv(n);
  1371. /* If reassembly or retransmission failure => reset all links to peer */
  1372. if (rc & TIPC_LINK_DOWN_EVT)
  1373. tipc_node_reset_links(n);
  1374. tipc_node_put(n);
  1375. }
  1376. /**
  1377. * tipc_node_check_state - check and if necessary update node state
  1378. * @skb: TIPC packet
  1379. * @bearer_id: identity of bearer delivering the packet
  1380. * Returns true if state and msg are ok, otherwise false
  1381. */
  1382. static bool tipc_node_check_state(struct tipc_node *n, struct sk_buff *skb,
  1383. int bearer_id, struct sk_buff_head *xmitq)
  1384. {
  1385. struct tipc_msg *hdr = buf_msg(skb);
  1386. int usr = msg_user(hdr);
  1387. int mtyp = msg_type(hdr);
  1388. u16 oseqno = msg_seqno(hdr);
  1389. u16 iseqno = msg_seqno(msg_get_wrapped(hdr));
  1390. u16 exp_pkts = msg_msgcnt(hdr);
  1391. u16 rcv_nxt, syncpt, dlv_nxt, inputq_len;
  1392. int state = n->state;
  1393. struct tipc_link *l, *tnl, *pl = NULL;
  1394. struct tipc_media_addr *maddr;
  1395. int pb_id;
  1396. l = n->links[bearer_id].link;
  1397. if (!l)
  1398. return false;
  1399. rcv_nxt = tipc_link_rcv_nxt(l);
  1400. if (likely((state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL)))
  1401. return true;
  1402. /* Find parallel link, if any */
  1403. for (pb_id = 0; pb_id < MAX_BEARERS; pb_id++) {
  1404. if ((pb_id != bearer_id) && n->links[pb_id].link) {
  1405. pl = n->links[pb_id].link;
  1406. break;
  1407. }
  1408. }
  1409. if (!tipc_link_validate_msg(l, hdr))
  1410. return false;
  1411. /* Check and update node accesibility if applicable */
  1412. if (state == SELF_UP_PEER_COMING) {
  1413. if (!tipc_link_is_up(l))
  1414. return true;
  1415. if (!msg_peer_link_is_up(hdr))
  1416. return true;
  1417. tipc_node_fsm_evt(n, PEER_ESTABL_CONTACT_EVT);
  1418. }
  1419. if (state == SELF_DOWN_PEER_LEAVING) {
  1420. if (msg_peer_node_is_up(hdr))
  1421. return false;
  1422. tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
  1423. return true;
  1424. }
  1425. if (state == SELF_LEAVING_PEER_DOWN)
  1426. return false;
  1427. /* Ignore duplicate packets */
  1428. if ((usr != LINK_PROTOCOL) && less(oseqno, rcv_nxt))
  1429. return true;
  1430. /* Initiate or update failover mode if applicable */
  1431. if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
  1432. syncpt = oseqno + exp_pkts - 1;
  1433. if (pl && tipc_link_is_up(pl)) {
  1434. __tipc_node_link_down(n, &pb_id, xmitq, &maddr);
  1435. tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
  1436. tipc_link_inputq(l));
  1437. }
  1438. /* If parallel link was already down, and this happened before
  1439. * the tunnel link came up, FAILOVER was never sent. Ensure that
  1440. * FAILOVER is sent to get peer out of NODE_FAILINGOVER state.
  1441. */
  1442. if (n->state != NODE_FAILINGOVER && !n->failover_sent) {
  1443. tipc_link_create_dummy_tnl_msg(l, xmitq);
  1444. n->failover_sent = true;
  1445. }
  1446. /* If pkts arrive out of order, use lowest calculated syncpt */
  1447. if (less(syncpt, n->sync_point))
  1448. n->sync_point = syncpt;
  1449. }
  1450. /* Open parallel link when tunnel link reaches synch point */
  1451. if ((n->state == NODE_FAILINGOVER) && tipc_link_is_up(l)) {
  1452. if (!more(rcv_nxt, n->sync_point))
  1453. return true;
  1454. tipc_node_fsm_evt(n, NODE_FAILOVER_END_EVT);
  1455. if (pl)
  1456. tipc_link_fsm_evt(pl, LINK_FAILOVER_END_EVT);
  1457. return true;
  1458. }
  1459. /* No synching needed if only one link */
  1460. if (!pl || !tipc_link_is_up(pl))
  1461. return true;
  1462. /* Initiate synch mode if applicable */
  1463. if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG) && (oseqno == 1)) {
  1464. syncpt = iseqno + exp_pkts - 1;
  1465. if (!tipc_link_is_up(l))
  1466. __tipc_node_link_up(n, bearer_id, xmitq);
  1467. if (n->state == SELF_UP_PEER_UP) {
  1468. n->sync_point = syncpt;
  1469. tipc_link_fsm_evt(l, LINK_SYNCH_BEGIN_EVT);
  1470. tipc_node_fsm_evt(n, NODE_SYNCH_BEGIN_EVT);
  1471. }
  1472. }
  1473. /* Open tunnel link when parallel link reaches synch point */
  1474. if (n->state == NODE_SYNCHING) {
  1475. if (tipc_link_is_synching(l)) {
  1476. tnl = l;
  1477. } else {
  1478. tnl = pl;
  1479. pl = l;
  1480. }
  1481. inputq_len = skb_queue_len(tipc_link_inputq(pl));
  1482. dlv_nxt = tipc_link_rcv_nxt(pl) - inputq_len;
  1483. if (more(dlv_nxt, n->sync_point)) {
  1484. tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
  1485. tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
  1486. return true;
  1487. }
  1488. if (l == pl)
  1489. return true;
  1490. if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG))
  1491. return true;
  1492. if (usr == LINK_PROTOCOL)
  1493. return true;
  1494. return false;
  1495. }
  1496. return true;
  1497. }
  1498. /**
  1499. * tipc_rcv - process TIPC packets/messages arriving from off-node
  1500. * @net: the applicable net namespace
  1501. * @skb: TIPC packet
  1502. * @bearer: pointer to bearer message arrived on
  1503. *
  1504. * Invoked with no locks held. Bearer pointer must point to a valid bearer
  1505. * structure (i.e. cannot be NULL), but bearer can be inactive.
  1506. */
  1507. void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
  1508. {
  1509. struct sk_buff_head xmitq;
  1510. struct tipc_node *n;
  1511. struct tipc_msg *hdr;
  1512. int bearer_id = b->identity;
  1513. struct tipc_link_entry *le;
  1514. u32 self = tipc_own_addr(net);
  1515. int usr, rc = 0;
  1516. u16 bc_ack;
  1517. __skb_queue_head_init(&xmitq);
  1518. /* Ensure message is well-formed before touching the header */
  1519. if (unlikely(!tipc_msg_validate(&skb)))
  1520. goto discard;
  1521. hdr = buf_msg(skb);
  1522. usr = msg_user(hdr);
  1523. bc_ack = msg_bcast_ack(hdr);
  1524. /* Handle arrival of discovery or broadcast packet */
  1525. if (unlikely(msg_non_seq(hdr))) {
  1526. if (unlikely(usr == LINK_CONFIG))
  1527. return tipc_disc_rcv(net, skb, b);
  1528. else
  1529. return tipc_node_bc_rcv(net, skb, bearer_id);
  1530. }
  1531. /* Discard unicast link messages destined for another node */
  1532. if (unlikely(!msg_short(hdr) && (msg_destnode(hdr) != self)))
  1533. goto discard;
  1534. /* Locate neighboring node that sent packet */
  1535. n = tipc_node_find(net, msg_prevnode(hdr));
  1536. if (unlikely(!n))
  1537. goto discard;
  1538. le = &n->links[bearer_id];
  1539. /* Ensure broadcast reception is in synch with peer's send state */
  1540. if (unlikely(usr == LINK_PROTOCOL))
  1541. tipc_node_bc_sync_rcv(n, hdr, bearer_id, &xmitq);
  1542. else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack))
  1543. tipc_bcast_ack_rcv(net, n->bc_entry.link, hdr);
  1544. /* Receive packet directly if conditions permit */
  1545. tipc_node_read_lock(n);
  1546. if (likely((n->state == SELF_UP_PEER_UP) && (usr != TUNNEL_PROTOCOL))) {
  1547. spin_lock_bh(&le->lock);
  1548. if (le->link) {
  1549. rc = tipc_link_rcv(le->link, skb, &xmitq);
  1550. skb = NULL;
  1551. }
  1552. spin_unlock_bh(&le->lock);
  1553. }
  1554. tipc_node_read_unlock(n);
  1555. /* Check/update node state before receiving */
  1556. if (unlikely(skb)) {
  1557. if (unlikely(skb_linearize(skb)))
  1558. goto discard;
  1559. tipc_node_write_lock(n);
  1560. if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
  1561. if (le->link) {
  1562. rc = tipc_link_rcv(le->link, skb, &xmitq);
  1563. skb = NULL;
  1564. }
  1565. }
  1566. tipc_node_write_unlock(n);
  1567. }
  1568. if (unlikely(rc & TIPC_LINK_UP_EVT))
  1569. tipc_node_link_up(n, bearer_id, &xmitq);
  1570. if (unlikely(rc & TIPC_LINK_DOWN_EVT))
  1571. tipc_node_link_down(n, bearer_id, false);
  1572. if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
  1573. tipc_named_rcv(net, &n->bc_entry.namedq);
  1574. if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1)))
  1575. tipc_node_mcast_rcv(n);
  1576. if (!skb_queue_empty(&le->inputq))
  1577. tipc_sk_rcv(net, &le->inputq);
  1578. if (!skb_queue_empty(&xmitq))
  1579. tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
  1580. tipc_node_put(n);
  1581. discard:
  1582. kfree_skb(skb);
  1583. }
  1584. void tipc_node_apply_property(struct net *net, struct tipc_bearer *b,
  1585. int prop)
  1586. {
  1587. struct tipc_net *tn = tipc_net(net);
  1588. int bearer_id = b->identity;
  1589. struct sk_buff_head xmitq;
  1590. struct tipc_link_entry *e;
  1591. struct tipc_node *n;
  1592. __skb_queue_head_init(&xmitq);
  1593. rcu_read_lock();
  1594. list_for_each_entry_rcu(n, &tn->node_list, list) {
  1595. tipc_node_write_lock(n);
  1596. e = &n->links[bearer_id];
  1597. if (e->link) {
  1598. if (prop == TIPC_NLA_PROP_TOL)
  1599. tipc_link_set_tolerance(e->link, b->tolerance,
  1600. &xmitq);
  1601. else if (prop == TIPC_NLA_PROP_MTU)
  1602. tipc_link_set_mtu(e->link, b->mtu);
  1603. }
  1604. tipc_node_write_unlock(n);
  1605. tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr);
  1606. }
  1607. rcu_read_unlock();
  1608. }
  1609. int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
  1610. {
  1611. struct net *net = sock_net(skb->sk);
  1612. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1613. struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
  1614. struct tipc_node *peer;
  1615. u32 addr;
  1616. int err;
  1617. /* We identify the peer by its net */
  1618. if (!info->attrs[TIPC_NLA_NET])
  1619. return -EINVAL;
  1620. err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
  1621. info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
  1622. info->extack);
  1623. if (err)
  1624. return err;
  1625. if (!attrs[TIPC_NLA_NET_ADDR])
  1626. return -EINVAL;
  1627. addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
  1628. if (in_own_node(net, addr))
  1629. return -ENOTSUPP;
  1630. spin_lock_bh(&tn->node_list_lock);
  1631. peer = tipc_node_find(net, addr);
  1632. if (!peer) {
  1633. spin_unlock_bh(&tn->node_list_lock);
  1634. return -ENXIO;
  1635. }
  1636. tipc_node_write_lock(peer);
  1637. if (peer->state != SELF_DOWN_PEER_DOWN &&
  1638. peer->state != SELF_DOWN_PEER_LEAVING) {
  1639. tipc_node_write_unlock(peer);
  1640. err = -EBUSY;
  1641. goto err_out;
  1642. }
  1643. tipc_node_clear_links(peer);
  1644. tipc_node_write_unlock(peer);
  1645. tipc_node_delete(peer);
  1646. err = 0;
  1647. err_out:
  1648. tipc_node_put(peer);
  1649. spin_unlock_bh(&tn->node_list_lock);
  1650. return err;
  1651. }
  1652. int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
  1653. {
  1654. int err;
  1655. struct net *net = sock_net(skb->sk);
  1656. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1657. int done = cb->args[0];
  1658. int last_addr = cb->args[1];
  1659. struct tipc_node *node;
  1660. struct tipc_nl_msg msg;
  1661. if (done)
  1662. return 0;
  1663. msg.skb = skb;
  1664. msg.portid = NETLINK_CB(cb->skb).portid;
  1665. msg.seq = cb->nlh->nlmsg_seq;
  1666. rcu_read_lock();
  1667. if (last_addr) {
  1668. node = tipc_node_find(net, last_addr);
  1669. if (!node) {
  1670. rcu_read_unlock();
  1671. /* We never set seq or call nl_dump_check_consistent()
  1672. * this means that setting prev_seq here will cause the
  1673. * consistence check to fail in the netlink callback
  1674. * handler. Resulting in the NLMSG_DONE message having
  1675. * the NLM_F_DUMP_INTR flag set if the node state
  1676. * changed while we released the lock.
  1677. */
  1678. cb->prev_seq = 1;
  1679. return -EPIPE;
  1680. }
  1681. tipc_node_put(node);
  1682. }
  1683. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1684. if (last_addr) {
  1685. if (node->addr == last_addr)
  1686. last_addr = 0;
  1687. else
  1688. continue;
  1689. }
  1690. tipc_node_read_lock(node);
  1691. err = __tipc_nl_add_node(&msg, node);
  1692. if (err) {
  1693. last_addr = node->addr;
  1694. tipc_node_read_unlock(node);
  1695. goto out;
  1696. }
  1697. tipc_node_read_unlock(node);
  1698. }
  1699. done = 1;
  1700. out:
  1701. cb->args[0] = done;
  1702. cb->args[1] = last_addr;
  1703. rcu_read_unlock();
  1704. return skb->len;
  1705. }
  1706. /* tipc_node_find_by_name - locate owner node of link by link's name
  1707. * @net: the applicable net namespace
  1708. * @name: pointer to link name string
  1709. * @bearer_id: pointer to index in 'node->links' array where the link was found.
  1710. *
  1711. * Returns pointer to node owning the link, or 0 if no matching link is found.
  1712. */
  1713. static struct tipc_node *tipc_node_find_by_name(struct net *net,
  1714. const char *link_name,
  1715. unsigned int *bearer_id)
  1716. {
  1717. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1718. struct tipc_link *l;
  1719. struct tipc_node *n;
  1720. struct tipc_node *found_node = NULL;
  1721. int i;
  1722. *bearer_id = 0;
  1723. rcu_read_lock();
  1724. list_for_each_entry_rcu(n, &tn->node_list, list) {
  1725. tipc_node_read_lock(n);
  1726. for (i = 0; i < MAX_BEARERS; i++) {
  1727. l = n->links[i].link;
  1728. if (l && !strcmp(tipc_link_name(l), link_name)) {
  1729. *bearer_id = i;
  1730. found_node = n;
  1731. break;
  1732. }
  1733. }
  1734. tipc_node_read_unlock(n);
  1735. if (found_node)
  1736. break;
  1737. }
  1738. rcu_read_unlock();
  1739. return found_node;
  1740. }
  1741. int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)
  1742. {
  1743. int err;
  1744. int res = 0;
  1745. int bearer_id;
  1746. char *name;
  1747. struct tipc_link *link;
  1748. struct tipc_node *node;
  1749. struct sk_buff_head xmitq;
  1750. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1751. struct net *net = sock_net(skb->sk);
  1752. __skb_queue_head_init(&xmitq);
  1753. if (!info->attrs[TIPC_NLA_LINK])
  1754. return -EINVAL;
  1755. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1756. info->attrs[TIPC_NLA_LINK],
  1757. tipc_nl_link_policy, info->extack);
  1758. if (err)
  1759. return err;
  1760. if (!attrs[TIPC_NLA_LINK_NAME])
  1761. return -EINVAL;
  1762. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1763. if (strcmp(name, tipc_bclink_name) == 0)
  1764. return tipc_nl_bc_link_set(net, attrs);
  1765. node = tipc_node_find_by_name(net, name, &bearer_id);
  1766. if (!node)
  1767. return -EINVAL;
  1768. tipc_node_read_lock(node);
  1769. link = node->links[bearer_id].link;
  1770. if (!link) {
  1771. res = -EINVAL;
  1772. goto out;
  1773. }
  1774. if (attrs[TIPC_NLA_LINK_PROP]) {
  1775. struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
  1776. err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
  1777. props);
  1778. if (err) {
  1779. res = err;
  1780. goto out;
  1781. }
  1782. if (props[TIPC_NLA_PROP_TOL]) {
  1783. u32 tol;
  1784. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1785. tipc_link_set_tolerance(link, tol, &xmitq);
  1786. }
  1787. if (props[TIPC_NLA_PROP_PRIO]) {
  1788. u32 prio;
  1789. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1790. tipc_link_set_prio(link, prio, &xmitq);
  1791. }
  1792. if (props[TIPC_NLA_PROP_WIN]) {
  1793. u32 win;
  1794. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1795. tipc_link_set_queue_limits(link, win);
  1796. }
  1797. }
  1798. out:
  1799. tipc_node_read_unlock(node);
  1800. tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr);
  1801. return res;
  1802. }
  1803. int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
  1804. {
  1805. struct net *net = genl_info_net(info);
  1806. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1807. struct tipc_nl_msg msg;
  1808. char *name;
  1809. int err;
  1810. msg.portid = info->snd_portid;
  1811. msg.seq = info->snd_seq;
  1812. if (!info->attrs[TIPC_NLA_LINK])
  1813. return -EINVAL;
  1814. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1815. info->attrs[TIPC_NLA_LINK],
  1816. tipc_nl_link_policy, info->extack);
  1817. if (err)
  1818. return err;
  1819. if (!attrs[TIPC_NLA_LINK_NAME])
  1820. return -EINVAL;
  1821. name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1822. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1823. if (!msg.skb)
  1824. return -ENOMEM;
  1825. if (strcmp(name, tipc_bclink_name) == 0) {
  1826. err = tipc_nl_add_bc_link(net, &msg);
  1827. if (err)
  1828. goto err_free;
  1829. } else {
  1830. int bearer_id;
  1831. struct tipc_node *node;
  1832. struct tipc_link *link;
  1833. node = tipc_node_find_by_name(net, name, &bearer_id);
  1834. if (!node) {
  1835. err = -EINVAL;
  1836. goto err_free;
  1837. }
  1838. tipc_node_read_lock(node);
  1839. link = node->links[bearer_id].link;
  1840. if (!link) {
  1841. tipc_node_read_unlock(node);
  1842. err = -EINVAL;
  1843. goto err_free;
  1844. }
  1845. err = __tipc_nl_add_link(net, &msg, link, 0);
  1846. tipc_node_read_unlock(node);
  1847. if (err)
  1848. goto err_free;
  1849. }
  1850. return genlmsg_reply(msg.skb, info);
  1851. err_free:
  1852. nlmsg_free(msg.skb);
  1853. return err;
  1854. }
  1855. int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)
  1856. {
  1857. int err;
  1858. char *link_name;
  1859. unsigned int bearer_id;
  1860. struct tipc_link *link;
  1861. struct tipc_node *node;
  1862. struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
  1863. struct net *net = sock_net(skb->sk);
  1864. struct tipc_link_entry *le;
  1865. if (!info->attrs[TIPC_NLA_LINK])
  1866. return -EINVAL;
  1867. err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
  1868. info->attrs[TIPC_NLA_LINK],
  1869. tipc_nl_link_policy, info->extack);
  1870. if (err)
  1871. return err;
  1872. if (!attrs[TIPC_NLA_LINK_NAME])
  1873. return -EINVAL;
  1874. link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
  1875. if (strcmp(link_name, tipc_bclink_name) == 0) {
  1876. err = tipc_bclink_reset_stats(net);
  1877. if (err)
  1878. return err;
  1879. return 0;
  1880. }
  1881. node = tipc_node_find_by_name(net, link_name, &bearer_id);
  1882. if (!node)
  1883. return -EINVAL;
  1884. le = &node->links[bearer_id];
  1885. tipc_node_read_lock(node);
  1886. spin_lock_bh(&le->lock);
  1887. link = node->links[bearer_id].link;
  1888. if (!link) {
  1889. spin_unlock_bh(&le->lock);
  1890. tipc_node_read_unlock(node);
  1891. return -EINVAL;
  1892. }
  1893. tipc_link_reset_stats(link);
  1894. spin_unlock_bh(&le->lock);
  1895. tipc_node_read_unlock(node);
  1896. return 0;
  1897. }
  1898. /* Caller should hold node lock */
  1899. static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
  1900. struct tipc_node *node, u32 *prev_link)
  1901. {
  1902. u32 i;
  1903. int err;
  1904. for (i = *prev_link; i < MAX_BEARERS; i++) {
  1905. *prev_link = i;
  1906. if (!node->links[i].link)
  1907. continue;
  1908. err = __tipc_nl_add_link(net, msg,
  1909. node->links[i].link, NLM_F_MULTI);
  1910. if (err)
  1911. return err;
  1912. }
  1913. *prev_link = 0;
  1914. return 0;
  1915. }
  1916. int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb)
  1917. {
  1918. struct net *net = sock_net(skb->sk);
  1919. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1920. struct tipc_node *node;
  1921. struct tipc_nl_msg msg;
  1922. u32 prev_node = cb->args[0];
  1923. u32 prev_link = cb->args[1];
  1924. int done = cb->args[2];
  1925. int err;
  1926. if (done)
  1927. return 0;
  1928. msg.skb = skb;
  1929. msg.portid = NETLINK_CB(cb->skb).portid;
  1930. msg.seq = cb->nlh->nlmsg_seq;
  1931. rcu_read_lock();
  1932. if (prev_node) {
  1933. node = tipc_node_find(net, prev_node);
  1934. if (!node) {
  1935. /* We never set seq or call nl_dump_check_consistent()
  1936. * this means that setting prev_seq here will cause the
  1937. * consistence check to fail in the netlink callback
  1938. * handler. Resulting in the last NLMSG_DONE message
  1939. * having the NLM_F_DUMP_INTR flag set.
  1940. */
  1941. cb->prev_seq = 1;
  1942. goto out;
  1943. }
  1944. tipc_node_put(node);
  1945. list_for_each_entry_continue_rcu(node, &tn->node_list,
  1946. list) {
  1947. tipc_node_read_lock(node);
  1948. err = __tipc_nl_add_node_links(net, &msg, node,
  1949. &prev_link);
  1950. tipc_node_read_unlock(node);
  1951. if (err)
  1952. goto out;
  1953. prev_node = node->addr;
  1954. }
  1955. } else {
  1956. err = tipc_nl_add_bc_link(net, &msg);
  1957. if (err)
  1958. goto out;
  1959. list_for_each_entry_rcu(node, &tn->node_list, list) {
  1960. tipc_node_read_lock(node);
  1961. err = __tipc_nl_add_node_links(net, &msg, node,
  1962. &prev_link);
  1963. tipc_node_read_unlock(node);
  1964. if (err)
  1965. goto out;
  1966. prev_node = node->addr;
  1967. }
  1968. }
  1969. done = 1;
  1970. out:
  1971. rcu_read_unlock();
  1972. cb->args[0] = prev_node;
  1973. cb->args[1] = prev_link;
  1974. cb->args[2] = done;
  1975. return skb->len;
  1976. }
  1977. int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info)
  1978. {
  1979. struct nlattr *attrs[TIPC_NLA_MON_MAX + 1];
  1980. struct net *net = sock_net(skb->sk);
  1981. int err;
  1982. if (!info->attrs[TIPC_NLA_MON])
  1983. return -EINVAL;
  1984. err = nla_parse_nested(attrs, TIPC_NLA_MON_MAX,
  1985. info->attrs[TIPC_NLA_MON],
  1986. tipc_nl_monitor_policy, info->extack);
  1987. if (err)
  1988. return err;
  1989. if (attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]) {
  1990. u32 val;
  1991. val = nla_get_u32(attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]);
  1992. err = tipc_nl_monitor_set_threshold(net, val);
  1993. if (err)
  1994. return err;
  1995. }
  1996. return 0;
  1997. }
  1998. static int __tipc_nl_add_monitor_prop(struct net *net, struct tipc_nl_msg *msg)
  1999. {
  2000. struct nlattr *attrs;
  2001. void *hdr;
  2002. u32 val;
  2003. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  2004. 0, TIPC_NL_MON_GET);
  2005. if (!hdr)
  2006. return -EMSGSIZE;
  2007. attrs = nla_nest_start(msg->skb, TIPC_NLA_MON);
  2008. if (!attrs)
  2009. goto msg_full;
  2010. val = tipc_nl_monitor_get_threshold(net);
  2011. if (nla_put_u32(msg->skb, TIPC_NLA_MON_ACTIVATION_THRESHOLD, val))
  2012. goto attr_msg_full;
  2013. nla_nest_end(msg->skb, attrs);
  2014. genlmsg_end(msg->skb, hdr);
  2015. return 0;
  2016. attr_msg_full:
  2017. nla_nest_cancel(msg->skb, attrs);
  2018. msg_full:
  2019. genlmsg_cancel(msg->skb, hdr);
  2020. return -EMSGSIZE;
  2021. }
  2022. int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info)
  2023. {
  2024. struct net *net = sock_net(skb->sk);
  2025. struct tipc_nl_msg msg;
  2026. int err;
  2027. msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  2028. if (!msg.skb)
  2029. return -ENOMEM;
  2030. msg.portid = info->snd_portid;
  2031. msg.seq = info->snd_seq;
  2032. err = __tipc_nl_add_monitor_prop(net, &msg);
  2033. if (err) {
  2034. nlmsg_free(msg.skb);
  2035. return err;
  2036. }
  2037. return genlmsg_reply(msg.skb, info);
  2038. }
  2039. int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
  2040. {
  2041. struct net *net = sock_net(skb->sk);
  2042. u32 prev_bearer = cb->args[0];
  2043. struct tipc_nl_msg msg;
  2044. int bearer_id;
  2045. int err;
  2046. if (prev_bearer == MAX_BEARERS)
  2047. return 0;
  2048. msg.skb = skb;
  2049. msg.portid = NETLINK_CB(cb->skb).portid;
  2050. msg.seq = cb->nlh->nlmsg_seq;
  2051. rtnl_lock();
  2052. for (bearer_id = prev_bearer; bearer_id < MAX_BEARERS; bearer_id++) {
  2053. err = __tipc_nl_add_monitor(net, &msg, bearer_id);
  2054. if (err)
  2055. break;
  2056. }
  2057. rtnl_unlock();
  2058. cb->args[0] = bearer_id;
  2059. return skb->len;
  2060. }
  2061. int tipc_nl_node_dump_monitor_peer(struct sk_buff *skb,
  2062. struct netlink_callback *cb)
  2063. {
  2064. struct net *net = sock_net(skb->sk);
  2065. u32 prev_node = cb->args[1];
  2066. u32 bearer_id = cb->args[2];
  2067. int done = cb->args[0];
  2068. struct tipc_nl_msg msg;
  2069. int err;
  2070. if (!prev_node) {
  2071. struct nlattr **attrs;
  2072. struct nlattr *mon[TIPC_NLA_MON_MAX + 1];
  2073. err = tipc_nlmsg_parse(cb->nlh, &attrs);
  2074. if (err)
  2075. return err;
  2076. if (!attrs[TIPC_NLA_MON])
  2077. return -EINVAL;
  2078. err = nla_parse_nested(mon, TIPC_NLA_MON_MAX,
  2079. attrs[TIPC_NLA_MON],
  2080. tipc_nl_monitor_policy, NULL);
  2081. if (err)
  2082. return err;
  2083. if (!mon[TIPC_NLA_MON_REF])
  2084. return -EINVAL;
  2085. bearer_id = nla_get_u32(mon[TIPC_NLA_MON_REF]);
  2086. if (bearer_id >= MAX_BEARERS)
  2087. return -EINVAL;
  2088. }
  2089. if (done)
  2090. return 0;
  2091. msg.skb = skb;
  2092. msg.portid = NETLINK_CB(cb->skb).portid;
  2093. msg.seq = cb->nlh->nlmsg_seq;
  2094. rtnl_lock();
  2095. err = tipc_nl_add_monitor_peer(net, &msg, bearer_id, &prev_node);
  2096. if (!err)
  2097. done = 1;
  2098. rtnl_unlock();
  2099. cb->args[0] = done;
  2100. cb->args[1] = prev_node;
  2101. cb->args[2] = bearer_id;
  2102. return skb->len;
  2103. }