link.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253
  1. /*
  2. * net/tipc/link.c: TIPC link code
  3. *
  4. * Copyright (c) 1996-2007, 2012-2016, Ericsson AB
  5. * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "subscr.h"
  38. #include "link.h"
  39. #include "bcast.h"
  40. #include "socket.h"
  41. #include "name_distr.h"
  42. #include "discover.h"
  43. #include "netlink.h"
  44. #include "monitor.h"
  45. #include <linux/pkt_sched.h>
  46. struct tipc_stats {
  47. u32 sent_pkts;
  48. u32 recv_pkts;
  49. u32 sent_states;
  50. u32 recv_states;
  51. u32 sent_probes;
  52. u32 recv_probes;
  53. u32 sent_nacks;
  54. u32 recv_nacks;
  55. u32 sent_acks;
  56. u32 sent_bundled;
  57. u32 sent_bundles;
  58. u32 recv_bundled;
  59. u32 recv_bundles;
  60. u32 retransmitted;
  61. u32 sent_fragmented;
  62. u32 sent_fragments;
  63. u32 recv_fragmented;
  64. u32 recv_fragments;
  65. u32 link_congs; /* # port sends blocked by congestion */
  66. u32 deferred_recv;
  67. u32 duplicates;
  68. u32 max_queue_sz; /* send queue size high water mark */
  69. u32 accu_queue_sz; /* used for send queue size profiling */
  70. u32 queue_sz_counts; /* used for send queue size profiling */
  71. u32 msg_length_counts; /* used for message length profiling */
  72. u32 msg_lengths_total; /* used for message length profiling */
  73. u32 msg_length_profile[7]; /* used for msg. length profiling */
  74. };
  75. /**
  76. * struct tipc_link - TIPC link data structure
  77. * @addr: network address of link's peer node
  78. * @name: link name character string
  79. * @media_addr: media address to use when sending messages over link
  80. * @timer: link timer
  81. * @net: pointer to namespace struct
  82. * @refcnt: reference counter for permanent references (owner node & timer)
  83. * @peer_session: link session # being used by peer end of link
  84. * @peer_bearer_id: bearer id used by link's peer endpoint
  85. * @bearer_id: local bearer id used by link
  86. * @tolerance: minimum link continuity loss needed to reset link [in ms]
  87. * @abort_limit: # of unacknowledged continuity probes needed to reset link
  88. * @state: current state of link FSM
  89. * @peer_caps: bitmap describing capabilities of peer node
  90. * @silent_intv_cnt: # of timer intervals without any reception from peer
  91. * @proto_msg: template for control messages generated by link
  92. * @pmsg: convenience pointer to "proto_msg" field
  93. * @priority: current link priority
  94. * @net_plane: current link network plane ('A' through 'H')
  95. * @mon_state: cookie with information needed by link monitor
  96. * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
  97. * @exp_msg_count: # of tunnelled messages expected during link changeover
  98. * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
  99. * @mtu: current maximum packet size for this link
  100. * @advertised_mtu: advertised own mtu when link is being established
  101. * @transmitq: queue for sent, non-acked messages
  102. * @backlogq: queue for messages waiting to be sent
  103. * @snt_nxt: next sequence number to use for outbound messages
  104. * @last_retransmitted: sequence number of most recently retransmitted message
  105. * @stale_cnt: counter for number of identical retransmit attempts
  106. * @stale_limit: time when repeated identical retransmits must force link reset
  107. * @ackers: # of peers that needs to ack each packet before it can be released
  108. * @acked: # last packet acked by a certain peer. Used for broadcast.
  109. * @rcv_nxt: next sequence number to expect for inbound messages
  110. * @deferred_queue: deferred queue saved OOS b'cast message received from node
  111. * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
  112. * @inputq: buffer queue for messages to be delivered upwards
  113. * @namedq: buffer queue for name table messages to be delivered upwards
  114. * @next_out: ptr to first unsent outbound message in queue
  115. * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
  116. * @long_msg_seq_no: next identifier to use for outbound fragmented messages
  117. * @reasm_buf: head of partially reassembled inbound message fragments
  118. * @bc_rcvr: marks that this is a broadcast receiver link
  119. * @stats: collects statistics regarding link activity
  120. */
  121. struct tipc_link {
  122. u32 addr;
  123. char name[TIPC_MAX_LINK_NAME];
  124. struct net *net;
  125. /* Management and link supervision data */
  126. u16 peer_session;
  127. u16 session;
  128. u16 snd_nxt_state;
  129. u16 rcv_nxt_state;
  130. u32 peer_bearer_id;
  131. u32 bearer_id;
  132. u32 tolerance;
  133. u32 abort_limit;
  134. u32 state;
  135. u16 peer_caps;
  136. bool in_session;
  137. bool active;
  138. u32 silent_intv_cnt;
  139. char if_name[TIPC_MAX_IF_NAME];
  140. u32 priority;
  141. char net_plane;
  142. struct tipc_mon_state mon_state;
  143. u16 rst_cnt;
  144. /* Failover/synch */
  145. u16 drop_point;
  146. struct sk_buff *failover_reasm_skb;
  147. /* Max packet negotiation */
  148. u16 mtu;
  149. u16 advertised_mtu;
  150. /* Sending */
  151. struct sk_buff_head transmq;
  152. struct sk_buff_head backlogq;
  153. struct {
  154. u16 len;
  155. u16 limit;
  156. } backlog[5];
  157. u16 snd_nxt;
  158. u16 last_retransm;
  159. u16 window;
  160. u16 stale_cnt;
  161. unsigned long stale_limit;
  162. /* Reception */
  163. u16 rcv_nxt;
  164. u32 rcv_unacked;
  165. struct sk_buff_head deferdq;
  166. struct sk_buff_head *inputq;
  167. struct sk_buff_head *namedq;
  168. /* Congestion handling */
  169. struct sk_buff_head wakeupq;
  170. /* Fragmentation/reassembly */
  171. struct sk_buff *reasm_buf;
  172. /* Broadcast */
  173. u16 ackers;
  174. u16 acked;
  175. struct tipc_link *bc_rcvlink;
  176. struct tipc_link *bc_sndlink;
  177. unsigned long prev_retr;
  178. u16 prev_from;
  179. u16 prev_to;
  180. u8 nack_state;
  181. bool bc_peer_is_up;
  182. /* Statistics */
  183. struct tipc_stats stats;
  184. };
  185. /*
  186. * Error message prefixes
  187. */
  188. static const char *link_co_err = "Link tunneling error, ";
  189. static const char *link_rst_msg = "Resetting link ";
  190. /* Send states for broadcast NACKs
  191. */
  192. enum {
  193. BC_NACK_SND_CONDITIONAL,
  194. BC_NACK_SND_UNCONDITIONAL,
  195. BC_NACK_SND_SUPPRESS,
  196. };
  197. #define TIPC_BC_RETR_LIMIT 10 /* [ms] */
  198. /*
  199. * Interval between NACKs when packets arrive out of order
  200. */
  201. #define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
  202. /* Link FSM states:
  203. */
  204. enum {
  205. LINK_ESTABLISHED = 0xe,
  206. LINK_ESTABLISHING = 0xe << 4,
  207. LINK_RESET = 0x1 << 8,
  208. LINK_RESETTING = 0x2 << 12,
  209. LINK_PEER_RESET = 0xd << 16,
  210. LINK_FAILINGOVER = 0xf << 20,
  211. LINK_SYNCHING = 0xc << 24
  212. };
  213. /* Link FSM state checking routines
  214. */
  215. static int link_is_up(struct tipc_link *l)
  216. {
  217. return l->state & (LINK_ESTABLISHED | LINK_SYNCHING);
  218. }
  219. static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
  220. struct sk_buff_head *xmitq);
  221. static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
  222. bool probe_reply, u16 rcvgap,
  223. int tolerance, int priority,
  224. struct sk_buff_head *xmitq);
  225. static void link_print(struct tipc_link *l, const char *str);
  226. static int tipc_link_build_nack_msg(struct tipc_link *l,
  227. struct sk_buff_head *xmitq);
  228. static void tipc_link_build_bc_init_msg(struct tipc_link *l,
  229. struct sk_buff_head *xmitq);
  230. static bool tipc_link_release_pkts(struct tipc_link *l, u16 to);
  231. /*
  232. * Simple non-static link routines (i.e. referenced outside this file)
  233. */
  234. bool tipc_link_is_up(struct tipc_link *l)
  235. {
  236. return link_is_up(l);
  237. }
  238. bool tipc_link_peer_is_down(struct tipc_link *l)
  239. {
  240. return l->state == LINK_PEER_RESET;
  241. }
  242. bool tipc_link_is_reset(struct tipc_link *l)
  243. {
  244. return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
  245. }
  246. bool tipc_link_is_establishing(struct tipc_link *l)
  247. {
  248. return l->state == LINK_ESTABLISHING;
  249. }
  250. bool tipc_link_is_synching(struct tipc_link *l)
  251. {
  252. return l->state == LINK_SYNCHING;
  253. }
  254. bool tipc_link_is_failingover(struct tipc_link *l)
  255. {
  256. return l->state == LINK_FAILINGOVER;
  257. }
  258. bool tipc_link_is_blocked(struct tipc_link *l)
  259. {
  260. return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER);
  261. }
  262. static bool link_is_bc_sndlink(struct tipc_link *l)
  263. {
  264. return !l->bc_sndlink;
  265. }
  266. static bool link_is_bc_rcvlink(struct tipc_link *l)
  267. {
  268. return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l));
  269. }
  270. void tipc_link_set_active(struct tipc_link *l, bool active)
  271. {
  272. l->active = active;
  273. }
  274. u32 tipc_link_id(struct tipc_link *l)
  275. {
  276. return l->peer_bearer_id << 16 | l->bearer_id;
  277. }
  278. int tipc_link_window(struct tipc_link *l)
  279. {
  280. return l->window;
  281. }
  282. int tipc_link_prio(struct tipc_link *l)
  283. {
  284. return l->priority;
  285. }
  286. unsigned long tipc_link_tolerance(struct tipc_link *l)
  287. {
  288. return l->tolerance;
  289. }
  290. struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
  291. {
  292. return l->inputq;
  293. }
  294. char tipc_link_plane(struct tipc_link *l)
  295. {
  296. return l->net_plane;
  297. }
  298. void tipc_link_update_caps(struct tipc_link *l, u16 capabilities)
  299. {
  300. l->peer_caps = capabilities;
  301. }
  302. void tipc_link_add_bc_peer(struct tipc_link *snd_l,
  303. struct tipc_link *uc_l,
  304. struct sk_buff_head *xmitq)
  305. {
  306. struct tipc_link *rcv_l = uc_l->bc_rcvlink;
  307. snd_l->ackers++;
  308. rcv_l->acked = snd_l->snd_nxt - 1;
  309. snd_l->state = LINK_ESTABLISHED;
  310. tipc_link_build_bc_init_msg(uc_l, xmitq);
  311. }
  312. void tipc_link_remove_bc_peer(struct tipc_link *snd_l,
  313. struct tipc_link *rcv_l,
  314. struct sk_buff_head *xmitq)
  315. {
  316. u16 ack = snd_l->snd_nxt - 1;
  317. snd_l->ackers--;
  318. rcv_l->bc_peer_is_up = true;
  319. rcv_l->state = LINK_ESTABLISHED;
  320. tipc_link_bc_ack_rcv(rcv_l, ack, xmitq);
  321. tipc_link_reset(rcv_l);
  322. rcv_l->state = LINK_RESET;
  323. if (!snd_l->ackers) {
  324. tipc_link_reset(snd_l);
  325. snd_l->state = LINK_RESET;
  326. __skb_queue_purge(xmitq);
  327. }
  328. }
  329. int tipc_link_bc_peers(struct tipc_link *l)
  330. {
  331. return l->ackers;
  332. }
  333. static u16 link_bc_rcv_gap(struct tipc_link *l)
  334. {
  335. struct sk_buff *skb = skb_peek(&l->deferdq);
  336. u16 gap = 0;
  337. if (more(l->snd_nxt, l->rcv_nxt))
  338. gap = l->snd_nxt - l->rcv_nxt;
  339. if (skb)
  340. gap = buf_seqno(skb) - l->rcv_nxt;
  341. return gap;
  342. }
  343. void tipc_link_set_mtu(struct tipc_link *l, int mtu)
  344. {
  345. l->mtu = mtu;
  346. }
  347. int tipc_link_mtu(struct tipc_link *l)
  348. {
  349. return l->mtu;
  350. }
  351. u16 tipc_link_rcv_nxt(struct tipc_link *l)
  352. {
  353. return l->rcv_nxt;
  354. }
  355. u16 tipc_link_acked(struct tipc_link *l)
  356. {
  357. return l->acked;
  358. }
  359. char *tipc_link_name(struct tipc_link *l)
  360. {
  361. return l->name;
  362. }
  363. u32 tipc_link_state(struct tipc_link *l)
  364. {
  365. return l->state;
  366. }
  367. /**
  368. * tipc_link_create - create a new link
  369. * @n: pointer to associated node
  370. * @if_name: associated interface name
  371. * @bearer_id: id (index) of associated bearer
  372. * @tolerance: link tolerance to be used by link
  373. * @net_plane: network plane (A,B,c..) this link belongs to
  374. * @mtu: mtu to be advertised by link
  375. * @priority: priority to be used by link
  376. * @window: send window to be used by link
  377. * @session: session to be used by link
  378. * @ownnode: identity of own node
  379. * @peer: node id of peer node
  380. * @peer_caps: bitmap describing peer node capabilities
  381. * @bc_sndlink: the namespace global link used for broadcast sending
  382. * @bc_rcvlink: the peer specific link used for broadcast reception
  383. * @inputq: queue to put messages ready for delivery
  384. * @namedq: queue to put binding table update messages ready for delivery
  385. * @link: return value, pointer to put the created link
  386. *
  387. * Returns true if link was created, otherwise false
  388. */
  389. bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
  390. int tolerance, char net_plane, u32 mtu, int priority,
  391. int window, u32 session, u32 self,
  392. u32 peer, u8 *peer_id, u16 peer_caps,
  393. struct tipc_link *bc_sndlink,
  394. struct tipc_link *bc_rcvlink,
  395. struct sk_buff_head *inputq,
  396. struct sk_buff_head *namedq,
  397. struct tipc_link **link)
  398. {
  399. char peer_str[NODE_ID_STR_LEN] = {0,};
  400. char self_str[NODE_ID_STR_LEN] = {0,};
  401. struct tipc_link *l;
  402. l = kzalloc(sizeof(*l), GFP_ATOMIC);
  403. if (!l)
  404. return false;
  405. *link = l;
  406. l->session = session;
  407. /* Set link name for unicast links only */
  408. if (peer_id) {
  409. tipc_nodeid2string(self_str, tipc_own_id(net));
  410. if (strlen(self_str) > 16)
  411. sprintf(self_str, "%x", self);
  412. tipc_nodeid2string(peer_str, peer_id);
  413. if (strlen(peer_str) > 16)
  414. sprintf(peer_str, "%x", peer);
  415. }
  416. /* Peer i/f name will be completed by reset/activate message */
  417. snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
  418. self_str, if_name, peer_str);
  419. strcpy(l->if_name, if_name);
  420. l->addr = peer;
  421. l->peer_caps = peer_caps;
  422. l->net = net;
  423. l->in_session = false;
  424. l->bearer_id = bearer_id;
  425. l->tolerance = tolerance;
  426. if (bc_rcvlink)
  427. bc_rcvlink->tolerance = tolerance;
  428. l->net_plane = net_plane;
  429. l->advertised_mtu = mtu;
  430. l->mtu = mtu;
  431. l->priority = priority;
  432. tipc_link_set_queue_limits(l, window);
  433. l->ackers = 1;
  434. l->bc_sndlink = bc_sndlink;
  435. l->bc_rcvlink = bc_rcvlink;
  436. l->inputq = inputq;
  437. l->namedq = namedq;
  438. l->state = LINK_RESETTING;
  439. __skb_queue_head_init(&l->transmq);
  440. __skb_queue_head_init(&l->backlogq);
  441. __skb_queue_head_init(&l->deferdq);
  442. skb_queue_head_init(&l->wakeupq);
  443. skb_queue_head_init(l->inputq);
  444. return true;
  445. }
  446. /**
  447. * tipc_link_bc_create - create new link to be used for broadcast
  448. * @n: pointer to associated node
  449. * @mtu: mtu to be used initially if no peers
  450. * @window: send window to be used
  451. * @inputq: queue to put messages ready for delivery
  452. * @namedq: queue to put binding table update messages ready for delivery
  453. * @link: return value, pointer to put the created link
  454. *
  455. * Returns true if link was created, otherwise false
  456. */
  457. bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
  458. int mtu, int window, u16 peer_caps,
  459. struct sk_buff_head *inputq,
  460. struct sk_buff_head *namedq,
  461. struct tipc_link *bc_sndlink,
  462. struct tipc_link **link)
  463. {
  464. struct tipc_link *l;
  465. if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, window,
  466. 0, ownnode, peer, NULL, peer_caps, bc_sndlink,
  467. NULL, inputq, namedq, link))
  468. return false;
  469. l = *link;
  470. strcpy(l->name, tipc_bclink_name);
  471. tipc_link_reset(l);
  472. l->state = LINK_RESET;
  473. l->ackers = 0;
  474. l->bc_rcvlink = l;
  475. /* Broadcast send link is always up */
  476. if (link_is_bc_sndlink(l))
  477. l->state = LINK_ESTABLISHED;
  478. /* Disable replicast if even a single peer doesn't support it */
  479. if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
  480. tipc_bcast_disable_rcast(net);
  481. return true;
  482. }
  483. /**
  484. * tipc_link_fsm_evt - link finite state machine
  485. * @l: pointer to link
  486. * @evt: state machine event to be processed
  487. */
  488. int tipc_link_fsm_evt(struct tipc_link *l, int evt)
  489. {
  490. int rc = 0;
  491. switch (l->state) {
  492. case LINK_RESETTING:
  493. switch (evt) {
  494. case LINK_PEER_RESET_EVT:
  495. l->state = LINK_PEER_RESET;
  496. break;
  497. case LINK_RESET_EVT:
  498. l->state = LINK_RESET;
  499. break;
  500. case LINK_FAILURE_EVT:
  501. case LINK_FAILOVER_BEGIN_EVT:
  502. case LINK_ESTABLISH_EVT:
  503. case LINK_FAILOVER_END_EVT:
  504. case LINK_SYNCH_BEGIN_EVT:
  505. case LINK_SYNCH_END_EVT:
  506. default:
  507. goto illegal_evt;
  508. }
  509. break;
  510. case LINK_RESET:
  511. switch (evt) {
  512. case LINK_PEER_RESET_EVT:
  513. l->state = LINK_ESTABLISHING;
  514. break;
  515. case LINK_FAILOVER_BEGIN_EVT:
  516. l->state = LINK_FAILINGOVER;
  517. case LINK_FAILURE_EVT:
  518. case LINK_RESET_EVT:
  519. case LINK_ESTABLISH_EVT:
  520. case LINK_FAILOVER_END_EVT:
  521. break;
  522. case LINK_SYNCH_BEGIN_EVT:
  523. case LINK_SYNCH_END_EVT:
  524. default:
  525. goto illegal_evt;
  526. }
  527. break;
  528. case LINK_PEER_RESET:
  529. switch (evt) {
  530. case LINK_RESET_EVT:
  531. l->state = LINK_ESTABLISHING;
  532. break;
  533. case LINK_PEER_RESET_EVT:
  534. case LINK_ESTABLISH_EVT:
  535. case LINK_FAILURE_EVT:
  536. break;
  537. case LINK_SYNCH_BEGIN_EVT:
  538. case LINK_SYNCH_END_EVT:
  539. case LINK_FAILOVER_BEGIN_EVT:
  540. case LINK_FAILOVER_END_EVT:
  541. default:
  542. goto illegal_evt;
  543. }
  544. break;
  545. case LINK_FAILINGOVER:
  546. switch (evt) {
  547. case LINK_FAILOVER_END_EVT:
  548. l->state = LINK_RESET;
  549. break;
  550. case LINK_PEER_RESET_EVT:
  551. case LINK_RESET_EVT:
  552. case LINK_ESTABLISH_EVT:
  553. case LINK_FAILURE_EVT:
  554. break;
  555. case LINK_FAILOVER_BEGIN_EVT:
  556. case LINK_SYNCH_BEGIN_EVT:
  557. case LINK_SYNCH_END_EVT:
  558. default:
  559. goto illegal_evt;
  560. }
  561. break;
  562. case LINK_ESTABLISHING:
  563. switch (evt) {
  564. case LINK_ESTABLISH_EVT:
  565. l->state = LINK_ESTABLISHED;
  566. break;
  567. case LINK_FAILOVER_BEGIN_EVT:
  568. l->state = LINK_FAILINGOVER;
  569. break;
  570. case LINK_RESET_EVT:
  571. l->state = LINK_RESET;
  572. break;
  573. case LINK_FAILURE_EVT:
  574. case LINK_PEER_RESET_EVT:
  575. case LINK_SYNCH_BEGIN_EVT:
  576. case LINK_FAILOVER_END_EVT:
  577. break;
  578. case LINK_SYNCH_END_EVT:
  579. default:
  580. goto illegal_evt;
  581. }
  582. break;
  583. case LINK_ESTABLISHED:
  584. switch (evt) {
  585. case LINK_PEER_RESET_EVT:
  586. l->state = LINK_PEER_RESET;
  587. rc |= TIPC_LINK_DOWN_EVT;
  588. break;
  589. case LINK_FAILURE_EVT:
  590. l->state = LINK_RESETTING;
  591. rc |= TIPC_LINK_DOWN_EVT;
  592. break;
  593. case LINK_RESET_EVT:
  594. l->state = LINK_RESET;
  595. break;
  596. case LINK_ESTABLISH_EVT:
  597. case LINK_SYNCH_END_EVT:
  598. break;
  599. case LINK_SYNCH_BEGIN_EVT:
  600. l->state = LINK_SYNCHING;
  601. break;
  602. case LINK_FAILOVER_BEGIN_EVT:
  603. case LINK_FAILOVER_END_EVT:
  604. default:
  605. goto illegal_evt;
  606. }
  607. break;
  608. case LINK_SYNCHING:
  609. switch (evt) {
  610. case LINK_PEER_RESET_EVT:
  611. l->state = LINK_PEER_RESET;
  612. rc |= TIPC_LINK_DOWN_EVT;
  613. break;
  614. case LINK_FAILURE_EVT:
  615. l->state = LINK_RESETTING;
  616. rc |= TIPC_LINK_DOWN_EVT;
  617. break;
  618. case LINK_RESET_EVT:
  619. l->state = LINK_RESET;
  620. break;
  621. case LINK_ESTABLISH_EVT:
  622. case LINK_SYNCH_BEGIN_EVT:
  623. break;
  624. case LINK_SYNCH_END_EVT:
  625. l->state = LINK_ESTABLISHED;
  626. break;
  627. case LINK_FAILOVER_BEGIN_EVT:
  628. case LINK_FAILOVER_END_EVT:
  629. default:
  630. goto illegal_evt;
  631. }
  632. break;
  633. default:
  634. pr_err("Unknown FSM state %x in %s\n", l->state, l->name);
  635. }
  636. return rc;
  637. illegal_evt:
  638. pr_err("Illegal FSM event %x in state %x on link %s\n",
  639. evt, l->state, l->name);
  640. return rc;
  641. }
  642. /* link_profile_stats - update statistical profiling of traffic
  643. */
  644. static void link_profile_stats(struct tipc_link *l)
  645. {
  646. struct sk_buff *skb;
  647. struct tipc_msg *msg;
  648. int length;
  649. /* Update counters used in statistical profiling of send traffic */
  650. l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
  651. l->stats.queue_sz_counts++;
  652. skb = skb_peek(&l->transmq);
  653. if (!skb)
  654. return;
  655. msg = buf_msg(skb);
  656. length = msg_size(msg);
  657. if (msg_user(msg) == MSG_FRAGMENTER) {
  658. if (msg_type(msg) != FIRST_FRAGMENT)
  659. return;
  660. length = msg_size(msg_get_wrapped(msg));
  661. }
  662. l->stats.msg_lengths_total += length;
  663. l->stats.msg_length_counts++;
  664. if (length <= 64)
  665. l->stats.msg_length_profile[0]++;
  666. else if (length <= 256)
  667. l->stats.msg_length_profile[1]++;
  668. else if (length <= 1024)
  669. l->stats.msg_length_profile[2]++;
  670. else if (length <= 4096)
  671. l->stats.msg_length_profile[3]++;
  672. else if (length <= 16384)
  673. l->stats.msg_length_profile[4]++;
  674. else if (length <= 32768)
  675. l->stats.msg_length_profile[5]++;
  676. else
  677. l->stats.msg_length_profile[6]++;
  678. }
  679. /* tipc_link_timeout - perform periodic task as instructed from node timeout
  680. */
  681. int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
  682. {
  683. int mtyp = 0;
  684. int rc = 0;
  685. bool state = false;
  686. bool probe = false;
  687. bool setup = false;
  688. u16 bc_snt = l->bc_sndlink->snd_nxt - 1;
  689. u16 bc_acked = l->bc_rcvlink->acked;
  690. struct tipc_mon_state *mstate = &l->mon_state;
  691. switch (l->state) {
  692. case LINK_ESTABLISHED:
  693. case LINK_SYNCHING:
  694. mtyp = STATE_MSG;
  695. link_profile_stats(l);
  696. tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id);
  697. if (mstate->reset || (l->silent_intv_cnt > l->abort_limit))
  698. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  699. state = bc_acked != bc_snt;
  700. state |= l->bc_rcvlink->rcv_unacked;
  701. state |= l->rcv_unacked;
  702. state |= !skb_queue_empty(&l->transmq);
  703. state |= !skb_queue_empty(&l->deferdq);
  704. probe = mstate->probing;
  705. probe |= l->silent_intv_cnt;
  706. if (probe || mstate->monitoring)
  707. l->silent_intv_cnt++;
  708. break;
  709. case LINK_RESET:
  710. setup = l->rst_cnt++ <= 4;
  711. setup |= !(l->rst_cnt % 16);
  712. mtyp = RESET_MSG;
  713. break;
  714. case LINK_ESTABLISHING:
  715. setup = true;
  716. mtyp = ACTIVATE_MSG;
  717. break;
  718. case LINK_PEER_RESET:
  719. case LINK_RESETTING:
  720. case LINK_FAILINGOVER:
  721. break;
  722. default:
  723. break;
  724. }
  725. if (state || probe || setup)
  726. tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq);
  727. return rc;
  728. }
  729. /**
  730. * link_schedule_user - schedule a message sender for wakeup after congestion
  731. * @l: congested link
  732. * @hdr: header of message that is being sent
  733. * Create pseudo msg to send back to user when congestion abates
  734. */
  735. static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr)
  736. {
  737. u32 dnode = tipc_own_addr(l->net);
  738. u32 dport = msg_origport(hdr);
  739. struct sk_buff *skb;
  740. /* Create and schedule wakeup pseudo message */
  741. skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
  742. dnode, l->addr, dport, 0, 0);
  743. if (!skb)
  744. return -ENOBUFS;
  745. msg_set_dest_droppable(buf_msg(skb), true);
  746. TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr);
  747. skb_queue_tail(&l->wakeupq, skb);
  748. l->stats.link_congs++;
  749. return -ELINKCONG;
  750. }
  751. /**
  752. * link_prepare_wakeup - prepare users for wakeup after congestion
  753. * @l: congested link
  754. * Wake up a number of waiting users, as permitted by available space
  755. * in the send queue
  756. */
  757. static void link_prepare_wakeup(struct tipc_link *l)
  758. {
  759. struct sk_buff *skb, *tmp;
  760. int imp, i = 0;
  761. skb_queue_walk_safe(&l->wakeupq, skb, tmp) {
  762. imp = TIPC_SKB_CB(skb)->chain_imp;
  763. if (l->backlog[imp].len < l->backlog[imp].limit) {
  764. skb_unlink(skb, &l->wakeupq);
  765. skb_queue_tail(l->inputq, skb);
  766. } else if (i++ > 10) {
  767. break;
  768. }
  769. }
  770. }
  771. void tipc_link_reset(struct tipc_link *l)
  772. {
  773. struct sk_buff_head list;
  774. __skb_queue_head_init(&list);
  775. l->in_session = false;
  776. l->session++;
  777. l->mtu = l->advertised_mtu;
  778. spin_lock_bh(&l->wakeupq.lock);
  779. skb_queue_splice_init(&l->wakeupq, &list);
  780. spin_unlock_bh(&l->wakeupq.lock);
  781. spin_lock_bh(&l->inputq->lock);
  782. skb_queue_splice_init(&list, l->inputq);
  783. spin_unlock_bh(&l->inputq->lock);
  784. __skb_queue_purge(&l->transmq);
  785. __skb_queue_purge(&l->deferdq);
  786. __skb_queue_purge(&l->backlogq);
  787. l->backlog[TIPC_LOW_IMPORTANCE].len = 0;
  788. l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0;
  789. l->backlog[TIPC_HIGH_IMPORTANCE].len = 0;
  790. l->backlog[TIPC_CRITICAL_IMPORTANCE].len = 0;
  791. l->backlog[TIPC_SYSTEM_IMPORTANCE].len = 0;
  792. kfree_skb(l->reasm_buf);
  793. kfree_skb(l->failover_reasm_skb);
  794. l->reasm_buf = NULL;
  795. l->failover_reasm_skb = NULL;
  796. l->rcv_unacked = 0;
  797. l->snd_nxt = 1;
  798. l->rcv_nxt = 1;
  799. l->snd_nxt_state = 1;
  800. l->rcv_nxt_state = 1;
  801. l->acked = 0;
  802. l->silent_intv_cnt = 0;
  803. l->rst_cnt = 0;
  804. l->stale_cnt = 0;
  805. l->bc_peer_is_up = false;
  806. memset(&l->mon_state, 0, sizeof(l->mon_state));
  807. tipc_link_reset_stats(l);
  808. }
  809. /**
  810. * tipc_link_xmit(): enqueue buffer list according to queue situation
  811. * @link: link to use
  812. * @list: chain of buffers containing message
  813. * @xmitq: returned list of packets to be sent by caller
  814. *
  815. * Consumes the buffer chain.
  816. * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
  817. * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
  818. */
  819. int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
  820. struct sk_buff_head *xmitq)
  821. {
  822. struct tipc_msg *hdr = buf_msg(skb_peek(list));
  823. unsigned int maxwin = l->window;
  824. int imp = msg_importance(hdr);
  825. unsigned int mtu = l->mtu;
  826. u16 ack = l->rcv_nxt - 1;
  827. u16 seqno = l->snd_nxt;
  828. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  829. struct sk_buff_head *transmq = &l->transmq;
  830. struct sk_buff_head *backlogq = &l->backlogq;
  831. struct sk_buff *skb, *_skb, *bskb;
  832. int pkt_cnt = skb_queue_len(list);
  833. int rc = 0;
  834. if (unlikely(msg_size(hdr) > mtu)) {
  835. skb_queue_purge(list);
  836. return -EMSGSIZE;
  837. }
  838. /* Allow oversubscription of one data msg per source at congestion */
  839. if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
  840. if (imp == TIPC_SYSTEM_IMPORTANCE) {
  841. pr_warn("%s<%s>, link overflow", link_rst_msg, l->name);
  842. return -ENOBUFS;
  843. }
  844. rc = link_schedule_user(l, hdr);
  845. }
  846. if (pkt_cnt > 1) {
  847. l->stats.sent_fragmented++;
  848. l->stats.sent_fragments += pkt_cnt;
  849. }
  850. /* Prepare each packet for sending, and add to relevant queue: */
  851. while (skb_queue_len(list)) {
  852. skb = skb_peek(list);
  853. hdr = buf_msg(skb);
  854. msg_set_seqno(hdr, seqno);
  855. msg_set_ack(hdr, ack);
  856. msg_set_bcast_ack(hdr, bc_ack);
  857. if (likely(skb_queue_len(transmq) < maxwin)) {
  858. _skb = skb_clone(skb, GFP_ATOMIC);
  859. if (!_skb) {
  860. skb_queue_purge(list);
  861. return -ENOBUFS;
  862. }
  863. __skb_dequeue(list);
  864. __skb_queue_tail(transmq, skb);
  865. __skb_queue_tail(xmitq, _skb);
  866. TIPC_SKB_CB(skb)->ackers = l->ackers;
  867. l->rcv_unacked = 0;
  868. l->stats.sent_pkts++;
  869. seqno++;
  870. continue;
  871. }
  872. if (tipc_msg_bundle(skb_peek_tail(backlogq), hdr, mtu)) {
  873. kfree_skb(__skb_dequeue(list));
  874. l->stats.sent_bundled++;
  875. continue;
  876. }
  877. if (tipc_msg_make_bundle(&bskb, hdr, mtu, l->addr)) {
  878. kfree_skb(__skb_dequeue(list));
  879. __skb_queue_tail(backlogq, bskb);
  880. l->backlog[msg_importance(buf_msg(bskb))].len++;
  881. l->stats.sent_bundled++;
  882. l->stats.sent_bundles++;
  883. continue;
  884. }
  885. l->backlog[imp].len += skb_queue_len(list);
  886. skb_queue_splice_tail_init(list, backlogq);
  887. }
  888. l->snd_nxt = seqno;
  889. return rc;
  890. }
  891. static void tipc_link_advance_backlog(struct tipc_link *l,
  892. struct sk_buff_head *xmitq)
  893. {
  894. struct sk_buff *skb, *_skb;
  895. struct tipc_msg *hdr;
  896. u16 seqno = l->snd_nxt;
  897. u16 ack = l->rcv_nxt - 1;
  898. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  899. while (skb_queue_len(&l->transmq) < l->window) {
  900. skb = skb_peek(&l->backlogq);
  901. if (!skb)
  902. break;
  903. _skb = skb_clone(skb, GFP_ATOMIC);
  904. if (!_skb)
  905. break;
  906. __skb_dequeue(&l->backlogq);
  907. hdr = buf_msg(skb);
  908. l->backlog[msg_importance(hdr)].len--;
  909. __skb_queue_tail(&l->transmq, skb);
  910. __skb_queue_tail(xmitq, _skb);
  911. TIPC_SKB_CB(skb)->ackers = l->ackers;
  912. msg_set_seqno(hdr, seqno);
  913. msg_set_ack(hdr, ack);
  914. msg_set_bcast_ack(hdr, bc_ack);
  915. l->rcv_unacked = 0;
  916. l->stats.sent_pkts++;
  917. seqno++;
  918. }
  919. l->snd_nxt = seqno;
  920. }
  921. static void link_retransmit_failure(struct tipc_link *l, struct sk_buff *skb)
  922. {
  923. struct tipc_msg *hdr = buf_msg(skb);
  924. pr_warn("Retransmission failure on link <%s>\n", l->name);
  925. link_print(l, "State of link ");
  926. pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n",
  927. msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr));
  928. pr_info("sqno %u, prev: %x, src: %x\n",
  929. msg_seqno(hdr), msg_prevnode(hdr), msg_orignode(hdr));
  930. }
  931. /* tipc_link_retrans() - retransmit one or more packets
  932. * @l: the link to transmit on
  933. * @r: the receiving link ordering the retransmit. Same as l if unicast
  934. * @from: retransmit from (inclusive) this sequence number
  935. * @to: retransmit to (inclusive) this sequence number
  936. * xmitq: queue for accumulating the retransmitted packets
  937. */
  938. static int tipc_link_retrans(struct tipc_link *l, struct tipc_link *r,
  939. u16 from, u16 to, struct sk_buff_head *xmitq)
  940. {
  941. struct sk_buff *_skb, *skb = skb_peek(&l->transmq);
  942. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  943. u16 ack = l->rcv_nxt - 1;
  944. struct tipc_msg *hdr;
  945. if (!skb)
  946. return 0;
  947. /* Detect repeated retransmit failures on same packet */
  948. if (r->last_retransm != buf_seqno(skb)) {
  949. r->last_retransm = buf_seqno(skb);
  950. r->stale_limit = jiffies + msecs_to_jiffies(r->tolerance);
  951. } else if (++r->stale_cnt > 99 && time_after(jiffies, r->stale_limit)) {
  952. link_retransmit_failure(l, skb);
  953. if (link_is_bc_sndlink(l))
  954. return TIPC_LINK_DOWN_EVT;
  955. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  956. }
  957. skb_queue_walk(&l->transmq, skb) {
  958. hdr = buf_msg(skb);
  959. if (less(msg_seqno(hdr), from))
  960. continue;
  961. if (more(msg_seqno(hdr), to))
  962. break;
  963. _skb = __pskb_copy(skb, MIN_H_SIZE, GFP_ATOMIC);
  964. if (!_skb)
  965. return 0;
  966. hdr = buf_msg(_skb);
  967. msg_set_ack(hdr, ack);
  968. msg_set_bcast_ack(hdr, bc_ack);
  969. _skb->priority = TC_PRIO_CONTROL;
  970. __skb_queue_tail(xmitq, _skb);
  971. l->stats.retransmitted++;
  972. }
  973. return 0;
  974. }
  975. /* tipc_data_input - deliver data and name distr msgs to upper layer
  976. *
  977. * Consumes buffer if message is of right type
  978. * Node lock must be held
  979. */
  980. static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
  981. struct sk_buff_head *inputq)
  982. {
  983. struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq;
  984. struct tipc_msg *hdr = buf_msg(skb);
  985. switch (msg_user(hdr)) {
  986. case TIPC_LOW_IMPORTANCE:
  987. case TIPC_MEDIUM_IMPORTANCE:
  988. case TIPC_HIGH_IMPORTANCE:
  989. case TIPC_CRITICAL_IMPORTANCE:
  990. if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) {
  991. skb_queue_tail(mc_inputq, skb);
  992. return true;
  993. }
  994. /* else: fall through */
  995. case CONN_MANAGER:
  996. skb_queue_tail(inputq, skb);
  997. return true;
  998. case GROUP_PROTOCOL:
  999. skb_queue_tail(mc_inputq, skb);
  1000. return true;
  1001. case NAME_DISTRIBUTOR:
  1002. l->bc_rcvlink->state = LINK_ESTABLISHED;
  1003. skb_queue_tail(l->namedq, skb);
  1004. return true;
  1005. case MSG_BUNDLER:
  1006. case TUNNEL_PROTOCOL:
  1007. case MSG_FRAGMENTER:
  1008. case BCAST_PROTOCOL:
  1009. return false;
  1010. default:
  1011. pr_warn("Dropping received illegal msg type\n");
  1012. kfree_skb(skb);
  1013. return false;
  1014. };
  1015. }
  1016. /* tipc_link_input - process packet that has passed link protocol check
  1017. *
  1018. * Consumes buffer
  1019. */
  1020. static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
  1021. struct sk_buff_head *inputq)
  1022. {
  1023. struct tipc_msg *hdr = buf_msg(skb);
  1024. struct sk_buff **reasm_skb = &l->reasm_buf;
  1025. struct sk_buff *iskb;
  1026. struct sk_buff_head tmpq;
  1027. int usr = msg_user(hdr);
  1028. int rc = 0;
  1029. int pos = 0;
  1030. int ipos = 0;
  1031. if (unlikely(usr == TUNNEL_PROTOCOL)) {
  1032. if (msg_type(hdr) == SYNCH_MSG) {
  1033. __skb_queue_purge(&l->deferdq);
  1034. goto drop;
  1035. }
  1036. if (!tipc_msg_extract(skb, &iskb, &ipos))
  1037. return rc;
  1038. kfree_skb(skb);
  1039. skb = iskb;
  1040. hdr = buf_msg(skb);
  1041. if (less(msg_seqno(hdr), l->drop_point))
  1042. goto drop;
  1043. if (tipc_data_input(l, skb, inputq))
  1044. return rc;
  1045. usr = msg_user(hdr);
  1046. reasm_skb = &l->failover_reasm_skb;
  1047. }
  1048. if (usr == MSG_BUNDLER) {
  1049. skb_queue_head_init(&tmpq);
  1050. l->stats.recv_bundles++;
  1051. l->stats.recv_bundled += msg_msgcnt(hdr);
  1052. while (tipc_msg_extract(skb, &iskb, &pos))
  1053. tipc_data_input(l, iskb, &tmpq);
  1054. tipc_skb_queue_splice_tail(&tmpq, inputq);
  1055. return 0;
  1056. } else if (usr == MSG_FRAGMENTER) {
  1057. l->stats.recv_fragments++;
  1058. if (tipc_buf_append(reasm_skb, &skb)) {
  1059. l->stats.recv_fragmented++;
  1060. tipc_data_input(l, skb, inputq);
  1061. } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) {
  1062. pr_warn_ratelimited("Unable to build fragment list\n");
  1063. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1064. }
  1065. return 0;
  1066. } else if (usr == BCAST_PROTOCOL) {
  1067. tipc_bcast_lock(l->net);
  1068. tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
  1069. tipc_bcast_unlock(l->net);
  1070. }
  1071. drop:
  1072. kfree_skb(skb);
  1073. return 0;
  1074. }
  1075. static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked)
  1076. {
  1077. bool released = false;
  1078. struct sk_buff *skb, *tmp;
  1079. skb_queue_walk_safe(&l->transmq, skb, tmp) {
  1080. if (more(buf_seqno(skb), acked))
  1081. break;
  1082. __skb_unlink(skb, &l->transmq);
  1083. kfree_skb(skb);
  1084. released = true;
  1085. }
  1086. return released;
  1087. }
  1088. /* tipc_link_build_state_msg: prepare link state message for transmission
  1089. *
  1090. * Note that sending of broadcast ack is coordinated among nodes, to reduce
  1091. * risk of ack storms towards the sender
  1092. */
  1093. int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
  1094. {
  1095. if (!l)
  1096. return 0;
  1097. /* Broadcast ACK must be sent via a unicast link => defer to caller */
  1098. if (link_is_bc_rcvlink(l)) {
  1099. if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
  1100. return 0;
  1101. l->rcv_unacked = 0;
  1102. /* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */
  1103. l->snd_nxt = l->rcv_nxt;
  1104. return TIPC_LINK_SND_STATE;
  1105. }
  1106. /* Unicast ACK */
  1107. l->rcv_unacked = 0;
  1108. l->stats.sent_acks++;
  1109. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
  1110. return 0;
  1111. }
  1112. /* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message
  1113. */
  1114. void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
  1115. {
  1116. int mtyp = RESET_MSG;
  1117. struct sk_buff *skb;
  1118. if (l->state == LINK_ESTABLISHING)
  1119. mtyp = ACTIVATE_MSG;
  1120. tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq);
  1121. /* Inform peer that this endpoint is going down if applicable */
  1122. skb = skb_peek_tail(xmitq);
  1123. if (skb && (l->state == LINK_RESET))
  1124. msg_set_peer_stopping(buf_msg(skb), 1);
  1125. }
  1126. /* tipc_link_build_nack_msg: prepare link nack message for transmission
  1127. * Note that sending of broadcast NACK is coordinated among nodes, to
  1128. * reduce the risk of NACK storms towards the sender
  1129. */
  1130. static int tipc_link_build_nack_msg(struct tipc_link *l,
  1131. struct sk_buff_head *xmitq)
  1132. {
  1133. u32 def_cnt = ++l->stats.deferred_recv;
  1134. int match1, match2;
  1135. if (link_is_bc_rcvlink(l)) {
  1136. match1 = def_cnt & 0xf;
  1137. match2 = tipc_own_addr(l->net) & 0xf;
  1138. if (match1 == match2)
  1139. return TIPC_LINK_SND_STATE;
  1140. return 0;
  1141. }
  1142. if ((skb_queue_len(&l->deferdq) == 1) || !(def_cnt % TIPC_NACK_INTV))
  1143. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
  1144. return 0;
  1145. }
  1146. /* tipc_link_rcv - process TIPC packets/messages arriving from off-node
  1147. * @l: the link that should handle the message
  1148. * @skb: TIPC packet
  1149. * @xmitq: queue to place packets to be sent after this call
  1150. */
  1151. int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
  1152. struct sk_buff_head *xmitq)
  1153. {
  1154. struct sk_buff_head *defq = &l->deferdq;
  1155. struct tipc_msg *hdr;
  1156. u16 seqno, rcv_nxt, win_lim;
  1157. int rc = 0;
  1158. do {
  1159. hdr = buf_msg(skb);
  1160. seqno = msg_seqno(hdr);
  1161. rcv_nxt = l->rcv_nxt;
  1162. win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
  1163. /* Verify and update link state */
  1164. if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
  1165. return tipc_link_proto_rcv(l, skb, xmitq);
  1166. if (unlikely(!link_is_up(l))) {
  1167. if (l->state == LINK_ESTABLISHING)
  1168. rc = TIPC_LINK_UP_EVT;
  1169. goto drop;
  1170. }
  1171. /* Don't send probe at next timeout expiration */
  1172. l->silent_intv_cnt = 0;
  1173. /* Drop if outside receive window */
  1174. if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
  1175. l->stats.duplicates++;
  1176. goto drop;
  1177. }
  1178. /* Forward queues and wake up waiting users */
  1179. if (likely(tipc_link_release_pkts(l, msg_ack(hdr)))) {
  1180. l->stale_cnt = 0;
  1181. tipc_link_advance_backlog(l, xmitq);
  1182. if (unlikely(!skb_queue_empty(&l->wakeupq)))
  1183. link_prepare_wakeup(l);
  1184. }
  1185. /* Defer delivery if sequence gap */
  1186. if (unlikely(seqno != rcv_nxt)) {
  1187. __tipc_skb_queue_sorted(defq, seqno, skb);
  1188. rc |= tipc_link_build_nack_msg(l, xmitq);
  1189. break;
  1190. }
  1191. /* Deliver packet */
  1192. l->rcv_nxt++;
  1193. l->stats.recv_pkts++;
  1194. if (!tipc_data_input(l, skb, l->inputq))
  1195. rc |= tipc_link_input(l, skb, l->inputq);
  1196. if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
  1197. rc |= tipc_link_build_state_msg(l, xmitq);
  1198. if (unlikely(rc & ~TIPC_LINK_SND_STATE))
  1199. break;
  1200. } while ((skb = __skb_dequeue(defq)));
  1201. return rc;
  1202. drop:
  1203. kfree_skb(skb);
  1204. return rc;
  1205. }
  1206. static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
  1207. bool probe_reply, u16 rcvgap,
  1208. int tolerance, int priority,
  1209. struct sk_buff_head *xmitq)
  1210. {
  1211. struct tipc_link *bcl = l->bc_rcvlink;
  1212. struct sk_buff *skb;
  1213. struct tipc_msg *hdr;
  1214. struct sk_buff_head *dfq = &l->deferdq;
  1215. bool node_up = link_is_up(bcl);
  1216. struct tipc_mon_state *mstate = &l->mon_state;
  1217. int dlen = 0;
  1218. void *data;
  1219. /* Don't send protocol message during reset or link failover */
  1220. if (tipc_link_is_blocked(l))
  1221. return;
  1222. if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
  1223. return;
  1224. if (!skb_queue_empty(dfq))
  1225. rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
  1226. skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
  1227. tipc_max_domain_size, l->addr,
  1228. tipc_own_addr(l->net), 0, 0, 0);
  1229. if (!skb)
  1230. return;
  1231. hdr = buf_msg(skb);
  1232. data = msg_data(hdr);
  1233. msg_set_session(hdr, l->session);
  1234. msg_set_bearer_id(hdr, l->bearer_id);
  1235. msg_set_net_plane(hdr, l->net_plane);
  1236. msg_set_next_sent(hdr, l->snd_nxt);
  1237. msg_set_ack(hdr, l->rcv_nxt - 1);
  1238. msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
  1239. msg_set_bc_ack_invalid(hdr, !node_up);
  1240. msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
  1241. msg_set_link_tolerance(hdr, tolerance);
  1242. msg_set_linkprio(hdr, priority);
  1243. msg_set_redundant_link(hdr, node_up);
  1244. msg_set_seq_gap(hdr, 0);
  1245. msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
  1246. if (mtyp == STATE_MSG) {
  1247. if (l->peer_caps & TIPC_LINK_PROTO_SEQNO)
  1248. msg_set_seqno(hdr, l->snd_nxt_state++);
  1249. msg_set_seq_gap(hdr, rcvgap);
  1250. msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
  1251. msg_set_probe(hdr, probe);
  1252. msg_set_is_keepalive(hdr, probe || probe_reply);
  1253. tipc_mon_prep(l->net, data, &dlen, mstate, l->bearer_id);
  1254. msg_set_size(hdr, INT_H_SIZE + dlen);
  1255. skb_trim(skb, INT_H_SIZE + dlen);
  1256. l->stats.sent_states++;
  1257. l->rcv_unacked = 0;
  1258. } else {
  1259. /* RESET_MSG or ACTIVATE_MSG */
  1260. msg_set_max_pkt(hdr, l->advertised_mtu);
  1261. strcpy(data, l->if_name);
  1262. msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
  1263. skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
  1264. }
  1265. if (probe)
  1266. l->stats.sent_probes++;
  1267. if (rcvgap)
  1268. l->stats.sent_nacks++;
  1269. skb->priority = TC_PRIO_CONTROL;
  1270. __skb_queue_tail(xmitq, skb);
  1271. }
  1272. void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
  1273. struct sk_buff_head *xmitq)
  1274. {
  1275. u32 onode = tipc_own_addr(l->net);
  1276. struct tipc_msg *hdr, *ihdr;
  1277. struct sk_buff_head tnlq;
  1278. struct sk_buff *skb;
  1279. u32 dnode = l->addr;
  1280. skb_queue_head_init(&tnlq);
  1281. skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG,
  1282. INT_H_SIZE, BASIC_H_SIZE,
  1283. dnode, onode, 0, 0, 0);
  1284. if (!skb) {
  1285. pr_warn("%sunable to create tunnel packet\n", link_co_err);
  1286. return;
  1287. }
  1288. hdr = buf_msg(skb);
  1289. msg_set_msgcnt(hdr, 1);
  1290. msg_set_bearer_id(hdr, l->peer_bearer_id);
  1291. ihdr = (struct tipc_msg *)msg_data(hdr);
  1292. tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
  1293. BASIC_H_SIZE, dnode);
  1294. msg_set_errcode(ihdr, TIPC_ERR_NO_PORT);
  1295. __skb_queue_tail(&tnlq, skb);
  1296. tipc_link_xmit(l, &tnlq, xmitq);
  1297. }
  1298. /* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets
  1299. * with contents of the link's transmit and backlog queues.
  1300. */
  1301. void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
  1302. int mtyp, struct sk_buff_head *xmitq)
  1303. {
  1304. struct sk_buff *skb, *tnlskb;
  1305. struct tipc_msg *hdr, tnlhdr;
  1306. struct sk_buff_head *queue = &l->transmq;
  1307. struct sk_buff_head tmpxq, tnlq;
  1308. u16 pktlen, pktcnt, seqno = l->snd_nxt;
  1309. if (!tnl)
  1310. return;
  1311. skb_queue_head_init(&tnlq);
  1312. skb_queue_head_init(&tmpxq);
  1313. /* At least one packet required for safe algorithm => add dummy */
  1314. skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
  1315. BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net),
  1316. 0, 0, TIPC_ERR_NO_PORT);
  1317. if (!skb) {
  1318. pr_warn("%sunable to create tunnel packet\n", link_co_err);
  1319. return;
  1320. }
  1321. skb_queue_tail(&tnlq, skb);
  1322. tipc_link_xmit(l, &tnlq, &tmpxq);
  1323. __skb_queue_purge(&tmpxq);
  1324. /* Initialize reusable tunnel packet header */
  1325. tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
  1326. mtyp, INT_H_SIZE, l->addr);
  1327. pktcnt = skb_queue_len(&l->transmq) + skb_queue_len(&l->backlogq);
  1328. msg_set_msgcnt(&tnlhdr, pktcnt);
  1329. msg_set_bearer_id(&tnlhdr, l->peer_bearer_id);
  1330. tnl:
  1331. /* Wrap each packet into a tunnel packet */
  1332. skb_queue_walk(queue, skb) {
  1333. hdr = buf_msg(skb);
  1334. if (queue == &l->backlogq)
  1335. msg_set_seqno(hdr, seqno++);
  1336. pktlen = msg_size(hdr);
  1337. msg_set_size(&tnlhdr, pktlen + INT_H_SIZE);
  1338. tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC);
  1339. if (!tnlskb) {
  1340. pr_warn("%sunable to send packet\n", link_co_err);
  1341. return;
  1342. }
  1343. skb_copy_to_linear_data(tnlskb, &tnlhdr, INT_H_SIZE);
  1344. skb_copy_to_linear_data_offset(tnlskb, INT_H_SIZE, hdr, pktlen);
  1345. __skb_queue_tail(&tnlq, tnlskb);
  1346. }
  1347. if (queue != &l->backlogq) {
  1348. queue = &l->backlogq;
  1349. goto tnl;
  1350. }
  1351. tipc_link_xmit(tnl, &tnlq, xmitq);
  1352. if (mtyp == FAILOVER_MSG) {
  1353. tnl->drop_point = l->rcv_nxt;
  1354. tnl->failover_reasm_skb = l->reasm_buf;
  1355. l->reasm_buf = NULL;
  1356. }
  1357. }
  1358. /* tipc_link_validate_msg(): validate message against current link state
  1359. * Returns true if message should be accepted, otherwise false
  1360. */
  1361. bool tipc_link_validate_msg(struct tipc_link *l, struct tipc_msg *hdr)
  1362. {
  1363. u16 curr_session = l->peer_session;
  1364. u16 session = msg_session(hdr);
  1365. int mtyp = msg_type(hdr);
  1366. if (msg_user(hdr) != LINK_PROTOCOL)
  1367. return true;
  1368. switch (mtyp) {
  1369. case RESET_MSG:
  1370. if (!l->in_session)
  1371. return true;
  1372. /* Accept only RESET with new session number */
  1373. return more(session, curr_session);
  1374. case ACTIVATE_MSG:
  1375. if (!l->in_session)
  1376. return true;
  1377. /* Accept only ACTIVATE with new or current session number */
  1378. return !less(session, curr_session);
  1379. case STATE_MSG:
  1380. /* Accept only STATE with current session number */
  1381. if (!l->in_session)
  1382. return false;
  1383. if (session != curr_session)
  1384. return false;
  1385. /* Extra sanity check */
  1386. if (!link_is_up(l) && msg_ack(hdr))
  1387. return false;
  1388. if (!(l->peer_caps & TIPC_LINK_PROTO_SEQNO))
  1389. return true;
  1390. /* Accept only STATE with new sequence number */
  1391. return !less(msg_seqno(hdr), l->rcv_nxt_state);
  1392. default:
  1393. return false;
  1394. }
  1395. }
  1396. /* tipc_link_proto_rcv(): receive link level protocol message :
  1397. * Note that network plane id propagates through the network, and may
  1398. * change at any time. The node with lowest numerical id determines
  1399. * network plane
  1400. */
  1401. static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
  1402. struct sk_buff_head *xmitq)
  1403. {
  1404. struct tipc_msg *hdr = buf_msg(skb);
  1405. u16 rcvgap = 0;
  1406. u16 ack = msg_ack(hdr);
  1407. u16 gap = msg_seq_gap(hdr);
  1408. u16 peers_snd_nxt = msg_next_sent(hdr);
  1409. u16 peers_tol = msg_link_tolerance(hdr);
  1410. u16 peers_prio = msg_linkprio(hdr);
  1411. u16 rcv_nxt = l->rcv_nxt;
  1412. u16 dlen = msg_data_sz(hdr);
  1413. int mtyp = msg_type(hdr);
  1414. bool reply = msg_probe(hdr);
  1415. void *data;
  1416. char *if_name;
  1417. int rc = 0;
  1418. if (tipc_link_is_blocked(l) || !xmitq)
  1419. goto exit;
  1420. if (tipc_own_addr(l->net) > msg_prevnode(hdr))
  1421. l->net_plane = msg_net_plane(hdr);
  1422. skb_linearize(skb);
  1423. hdr = buf_msg(skb);
  1424. data = msg_data(hdr);
  1425. if (!tipc_link_validate_msg(l, hdr))
  1426. goto exit;
  1427. switch (mtyp) {
  1428. case RESET_MSG:
  1429. case ACTIVATE_MSG:
  1430. /* Complete own link name with peer's interface name */
  1431. if_name = strrchr(l->name, ':') + 1;
  1432. if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME)
  1433. break;
  1434. if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME)
  1435. break;
  1436. strncpy(if_name, data, TIPC_MAX_IF_NAME);
  1437. /* Update own tolerance if peer indicates a non-zero value */
  1438. if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
  1439. l->tolerance = peers_tol;
  1440. l->bc_rcvlink->tolerance = peers_tol;
  1441. }
  1442. /* Update own priority if peer's priority is higher */
  1443. if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI))
  1444. l->priority = peers_prio;
  1445. /* ACTIVATE_MSG serves as PEER_RESET if link is already down */
  1446. if (msg_peer_stopping(hdr))
  1447. rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1448. else if ((mtyp == RESET_MSG) || !link_is_up(l))
  1449. rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
  1450. /* ACTIVATE_MSG takes up link if it was already locally reset */
  1451. if ((mtyp == ACTIVATE_MSG) && (l->state == LINK_ESTABLISHING))
  1452. rc = TIPC_LINK_UP_EVT;
  1453. l->peer_session = msg_session(hdr);
  1454. l->in_session = true;
  1455. l->peer_bearer_id = msg_bearer_id(hdr);
  1456. if (l->mtu > msg_max_pkt(hdr))
  1457. l->mtu = msg_max_pkt(hdr);
  1458. break;
  1459. case STATE_MSG:
  1460. l->rcv_nxt_state = msg_seqno(hdr) + 1;
  1461. /* Update own tolerance if peer indicates a non-zero value */
  1462. if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
  1463. l->tolerance = peers_tol;
  1464. l->bc_rcvlink->tolerance = peers_tol;
  1465. }
  1466. /* Update own prio if peer indicates a different value */
  1467. if ((peers_prio != l->priority) &&
  1468. in_range(peers_prio, 1, TIPC_MAX_LINK_PRI)) {
  1469. l->priority = peers_prio;
  1470. rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1471. }
  1472. l->silent_intv_cnt = 0;
  1473. l->stats.recv_states++;
  1474. if (msg_probe(hdr))
  1475. l->stats.recv_probes++;
  1476. if (!link_is_up(l)) {
  1477. if (l->state == LINK_ESTABLISHING)
  1478. rc = TIPC_LINK_UP_EVT;
  1479. break;
  1480. }
  1481. tipc_mon_rcv(l->net, data, dlen, l->addr,
  1482. &l->mon_state, l->bearer_id);
  1483. /* Send NACK if peer has sent pkts we haven't received yet */
  1484. if (more(peers_snd_nxt, rcv_nxt) && !tipc_link_is_synching(l))
  1485. rcvgap = peers_snd_nxt - l->rcv_nxt;
  1486. if (rcvgap || reply)
  1487. tipc_link_build_proto_msg(l, STATE_MSG, 0, reply,
  1488. rcvgap, 0, 0, xmitq);
  1489. tipc_link_release_pkts(l, ack);
  1490. /* If NACK, retransmit will now start at right position */
  1491. if (gap) {
  1492. rc = tipc_link_retrans(l, l, ack + 1, ack + gap, xmitq);
  1493. l->stats.recv_nacks++;
  1494. }
  1495. tipc_link_advance_backlog(l, xmitq);
  1496. if (unlikely(!skb_queue_empty(&l->wakeupq)))
  1497. link_prepare_wakeup(l);
  1498. }
  1499. exit:
  1500. kfree_skb(skb);
  1501. return rc;
  1502. }
  1503. /* tipc_link_build_bc_proto_msg() - create broadcast protocol message
  1504. */
  1505. static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
  1506. u16 peers_snd_nxt,
  1507. struct sk_buff_head *xmitq)
  1508. {
  1509. struct sk_buff *skb;
  1510. struct tipc_msg *hdr;
  1511. struct sk_buff *dfrd_skb = skb_peek(&l->deferdq);
  1512. u16 ack = l->rcv_nxt - 1;
  1513. u16 gap_to = peers_snd_nxt - 1;
  1514. skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE,
  1515. 0, l->addr, tipc_own_addr(l->net), 0, 0, 0);
  1516. if (!skb)
  1517. return false;
  1518. hdr = buf_msg(skb);
  1519. msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
  1520. msg_set_bcast_ack(hdr, ack);
  1521. msg_set_bcgap_after(hdr, ack);
  1522. if (dfrd_skb)
  1523. gap_to = buf_seqno(dfrd_skb) - 1;
  1524. msg_set_bcgap_to(hdr, gap_to);
  1525. msg_set_non_seq(hdr, bcast);
  1526. __skb_queue_tail(xmitq, skb);
  1527. return true;
  1528. }
  1529. /* tipc_link_build_bc_init_msg() - synchronize broadcast link endpoints.
  1530. *
  1531. * Give a newly added peer node the sequence number where it should
  1532. * start receiving and acking broadcast packets.
  1533. */
  1534. static void tipc_link_build_bc_init_msg(struct tipc_link *l,
  1535. struct sk_buff_head *xmitq)
  1536. {
  1537. struct sk_buff_head list;
  1538. __skb_queue_head_init(&list);
  1539. if (!tipc_link_build_bc_proto_msg(l->bc_rcvlink, false, 0, &list))
  1540. return;
  1541. msg_set_bc_ack_invalid(buf_msg(skb_peek(&list)), true);
  1542. tipc_link_xmit(l, &list, xmitq);
  1543. }
  1544. /* tipc_link_bc_init_rcv - receive initial broadcast synch data from peer
  1545. */
  1546. void tipc_link_bc_init_rcv(struct tipc_link *l, struct tipc_msg *hdr)
  1547. {
  1548. int mtyp = msg_type(hdr);
  1549. u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
  1550. if (link_is_up(l))
  1551. return;
  1552. if (msg_user(hdr) == BCAST_PROTOCOL) {
  1553. l->rcv_nxt = peers_snd_nxt;
  1554. l->state = LINK_ESTABLISHED;
  1555. return;
  1556. }
  1557. if (l->peer_caps & TIPC_BCAST_SYNCH)
  1558. return;
  1559. if (msg_peer_node_is_up(hdr))
  1560. return;
  1561. /* Compatibility: accept older, less safe initial synch data */
  1562. if ((mtyp == RESET_MSG) || (mtyp == ACTIVATE_MSG))
  1563. l->rcv_nxt = peers_snd_nxt;
  1564. }
  1565. /* link_bc_retr eval()- check if the indicated range can be retransmitted now
  1566. * - Adjust permitted range if there is overlap with previous retransmission
  1567. */
  1568. static bool link_bc_retr_eval(struct tipc_link *l, u16 *from, u16 *to)
  1569. {
  1570. unsigned long elapsed = jiffies_to_msecs(jiffies - l->prev_retr);
  1571. if (less(*to, *from))
  1572. return false;
  1573. /* New retransmission request */
  1574. if ((elapsed > TIPC_BC_RETR_LIMIT) ||
  1575. less(*to, l->prev_from) || more(*from, l->prev_to)) {
  1576. l->prev_from = *from;
  1577. l->prev_to = *to;
  1578. l->prev_retr = jiffies;
  1579. return true;
  1580. }
  1581. /* Inside range of previous retransmit */
  1582. if (!less(*from, l->prev_from) && !more(*to, l->prev_to))
  1583. return false;
  1584. /* Fully or partially outside previous range => exclude overlap */
  1585. if (less(*from, l->prev_from)) {
  1586. *to = l->prev_from - 1;
  1587. l->prev_from = *from;
  1588. }
  1589. if (more(*to, l->prev_to)) {
  1590. *from = l->prev_to + 1;
  1591. l->prev_to = *to;
  1592. }
  1593. l->prev_retr = jiffies;
  1594. return true;
  1595. }
  1596. /* tipc_link_bc_sync_rcv - update rcv link according to peer's send state
  1597. */
  1598. int tipc_link_bc_sync_rcv(struct tipc_link *l, struct tipc_msg *hdr,
  1599. struct sk_buff_head *xmitq)
  1600. {
  1601. struct tipc_link *snd_l = l->bc_sndlink;
  1602. u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
  1603. u16 from = msg_bcast_ack(hdr) + 1;
  1604. u16 to = from + msg_bc_gap(hdr) - 1;
  1605. int rc = 0;
  1606. if (!link_is_up(l))
  1607. return rc;
  1608. if (!msg_peer_node_is_up(hdr))
  1609. return rc;
  1610. /* Open when peer ackowledges our bcast init msg (pkt #1) */
  1611. if (msg_ack(hdr))
  1612. l->bc_peer_is_up = true;
  1613. if (!l->bc_peer_is_up)
  1614. return rc;
  1615. l->stats.recv_nacks++;
  1616. /* Ignore if peers_snd_nxt goes beyond receive window */
  1617. if (more(peers_snd_nxt, l->rcv_nxt + l->window))
  1618. return rc;
  1619. if (link_bc_retr_eval(snd_l, &from, &to))
  1620. rc = tipc_link_retrans(snd_l, l, from, to, xmitq);
  1621. l->snd_nxt = peers_snd_nxt;
  1622. if (link_bc_rcv_gap(l))
  1623. rc |= TIPC_LINK_SND_STATE;
  1624. /* Return now if sender supports nack via STATE messages */
  1625. if (l->peer_caps & TIPC_BCAST_STATE_NACK)
  1626. return rc;
  1627. /* Otherwise, be backwards compatible */
  1628. if (!more(peers_snd_nxt, l->rcv_nxt)) {
  1629. l->nack_state = BC_NACK_SND_CONDITIONAL;
  1630. return 0;
  1631. }
  1632. /* Don't NACK if one was recently sent or peeked */
  1633. if (l->nack_state == BC_NACK_SND_SUPPRESS) {
  1634. l->nack_state = BC_NACK_SND_UNCONDITIONAL;
  1635. return 0;
  1636. }
  1637. /* Conditionally delay NACK sending until next synch rcv */
  1638. if (l->nack_state == BC_NACK_SND_CONDITIONAL) {
  1639. l->nack_state = BC_NACK_SND_UNCONDITIONAL;
  1640. if ((peers_snd_nxt - l->rcv_nxt) < TIPC_MIN_LINK_WIN)
  1641. return 0;
  1642. }
  1643. /* Send NACK now but suppress next one */
  1644. tipc_link_build_bc_proto_msg(l, true, peers_snd_nxt, xmitq);
  1645. l->nack_state = BC_NACK_SND_SUPPRESS;
  1646. return 0;
  1647. }
  1648. void tipc_link_bc_ack_rcv(struct tipc_link *l, u16 acked,
  1649. struct sk_buff_head *xmitq)
  1650. {
  1651. struct sk_buff *skb, *tmp;
  1652. struct tipc_link *snd_l = l->bc_sndlink;
  1653. if (!link_is_up(l) || !l->bc_peer_is_up)
  1654. return;
  1655. if (!more(acked, l->acked))
  1656. return;
  1657. /* Skip over packets peer has already acked */
  1658. skb_queue_walk(&snd_l->transmq, skb) {
  1659. if (more(buf_seqno(skb), l->acked))
  1660. break;
  1661. }
  1662. /* Update/release the packets peer is acking now */
  1663. skb_queue_walk_from_safe(&snd_l->transmq, skb, tmp) {
  1664. if (more(buf_seqno(skb), acked))
  1665. break;
  1666. if (!--TIPC_SKB_CB(skb)->ackers) {
  1667. __skb_unlink(skb, &snd_l->transmq);
  1668. kfree_skb(skb);
  1669. }
  1670. }
  1671. l->acked = acked;
  1672. tipc_link_advance_backlog(snd_l, xmitq);
  1673. if (unlikely(!skb_queue_empty(&snd_l->wakeupq)))
  1674. link_prepare_wakeup(snd_l);
  1675. }
  1676. /* tipc_link_bc_nack_rcv(): receive broadcast nack message
  1677. * This function is here for backwards compatibility, since
  1678. * no BCAST_PROTOCOL/STATE messages occur from TIPC v2.5.
  1679. */
  1680. int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
  1681. struct sk_buff_head *xmitq)
  1682. {
  1683. struct tipc_msg *hdr = buf_msg(skb);
  1684. u32 dnode = msg_destnode(hdr);
  1685. int mtyp = msg_type(hdr);
  1686. u16 acked = msg_bcast_ack(hdr);
  1687. u16 from = acked + 1;
  1688. u16 to = msg_bcgap_to(hdr);
  1689. u16 peers_snd_nxt = to + 1;
  1690. int rc = 0;
  1691. kfree_skb(skb);
  1692. if (!tipc_link_is_up(l) || !l->bc_peer_is_up)
  1693. return 0;
  1694. if (mtyp != STATE_MSG)
  1695. return 0;
  1696. if (dnode == tipc_own_addr(l->net)) {
  1697. tipc_link_bc_ack_rcv(l, acked, xmitq);
  1698. rc = tipc_link_retrans(l->bc_sndlink, l, from, to, xmitq);
  1699. l->stats.recv_nacks++;
  1700. return rc;
  1701. }
  1702. /* Msg for other node => suppress own NACK at next sync if applicable */
  1703. if (more(peers_snd_nxt, l->rcv_nxt) && !less(l->rcv_nxt, from))
  1704. l->nack_state = BC_NACK_SND_SUPPRESS;
  1705. return 0;
  1706. }
  1707. void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
  1708. {
  1709. int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE);
  1710. l->window = win;
  1711. l->backlog[TIPC_LOW_IMPORTANCE].limit = max_t(u16, 50, win);
  1712. l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = max_t(u16, 100, win * 2);
  1713. l->backlog[TIPC_HIGH_IMPORTANCE].limit = max_t(u16, 150, win * 3);
  1714. l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = max_t(u16, 200, win * 4);
  1715. l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
  1716. }
  1717. /**
  1718. * link_reset_stats - reset link statistics
  1719. * @l: pointer to link
  1720. */
  1721. void tipc_link_reset_stats(struct tipc_link *l)
  1722. {
  1723. memset(&l->stats, 0, sizeof(l->stats));
  1724. }
  1725. static void link_print(struct tipc_link *l, const char *str)
  1726. {
  1727. struct sk_buff *hskb = skb_peek(&l->transmq);
  1728. u16 head = hskb ? msg_seqno(buf_msg(hskb)) : l->snd_nxt - 1;
  1729. u16 tail = l->snd_nxt - 1;
  1730. pr_info("%s Link <%s> state %x\n", str, l->name, l->state);
  1731. pr_info("XMTQ: %u [%u-%u], BKLGQ: %u, SNDNX: %u, RCVNX: %u\n",
  1732. skb_queue_len(&l->transmq), head, tail,
  1733. skb_queue_len(&l->backlogq), l->snd_nxt, l->rcv_nxt);
  1734. }
  1735. /* Parse and validate nested (link) properties valid for media, bearer and link
  1736. */
  1737. int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
  1738. {
  1739. int err;
  1740. err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop,
  1741. tipc_nl_prop_policy, NULL);
  1742. if (err)
  1743. return err;
  1744. if (props[TIPC_NLA_PROP_PRIO]) {
  1745. u32 prio;
  1746. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  1747. if (prio > TIPC_MAX_LINK_PRI)
  1748. return -EINVAL;
  1749. }
  1750. if (props[TIPC_NLA_PROP_TOL]) {
  1751. u32 tol;
  1752. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  1753. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  1754. return -EINVAL;
  1755. }
  1756. if (props[TIPC_NLA_PROP_WIN]) {
  1757. u32 win;
  1758. win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  1759. if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))
  1760. return -EINVAL;
  1761. }
  1762. return 0;
  1763. }
  1764. static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
  1765. {
  1766. int i;
  1767. struct nlattr *stats;
  1768. struct nla_map {
  1769. u32 key;
  1770. u32 val;
  1771. };
  1772. struct nla_map map[] = {
  1773. {TIPC_NLA_STATS_RX_INFO, 0},
  1774. {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
  1775. {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
  1776. {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
  1777. {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
  1778. {TIPC_NLA_STATS_TX_INFO, 0},
  1779. {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
  1780. {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
  1781. {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
  1782. {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
  1783. {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
  1784. s->msg_length_counts : 1},
  1785. {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
  1786. {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
  1787. {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
  1788. {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
  1789. {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
  1790. {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
  1791. {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
  1792. {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
  1793. {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
  1794. {TIPC_NLA_STATS_RX_STATES, s->recv_states},
  1795. {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
  1796. {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
  1797. {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
  1798. {TIPC_NLA_STATS_TX_STATES, s->sent_states},
  1799. {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
  1800. {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
  1801. {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
  1802. {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
  1803. {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
  1804. {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
  1805. {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
  1806. {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
  1807. (s->accu_queue_sz / s->queue_sz_counts) : 0}
  1808. };
  1809. stats = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
  1810. if (!stats)
  1811. return -EMSGSIZE;
  1812. for (i = 0; i < ARRAY_SIZE(map); i++)
  1813. if (nla_put_u32(skb, map[i].key, map[i].val))
  1814. goto msg_full;
  1815. nla_nest_end(skb, stats);
  1816. return 0;
  1817. msg_full:
  1818. nla_nest_cancel(skb, stats);
  1819. return -EMSGSIZE;
  1820. }
  1821. /* Caller should hold appropriate locks to protect the link */
  1822. int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
  1823. struct tipc_link *link, int nlflags)
  1824. {
  1825. u32 self = tipc_own_addr(net);
  1826. struct nlattr *attrs;
  1827. struct nlattr *prop;
  1828. void *hdr;
  1829. int err;
  1830. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1831. nlflags, TIPC_NL_LINK_GET);
  1832. if (!hdr)
  1833. return -EMSGSIZE;
  1834. attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
  1835. if (!attrs)
  1836. goto msg_full;
  1837. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
  1838. goto attr_msg_full;
  1839. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
  1840. goto attr_msg_full;
  1841. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
  1842. goto attr_msg_full;
  1843. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->stats.recv_pkts))
  1844. goto attr_msg_full;
  1845. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->stats.sent_pkts))
  1846. goto attr_msg_full;
  1847. if (tipc_link_is_up(link))
  1848. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  1849. goto attr_msg_full;
  1850. if (link->active)
  1851. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
  1852. goto attr_msg_full;
  1853. prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
  1854. if (!prop)
  1855. goto attr_msg_full;
  1856. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1857. goto prop_msg_full;
  1858. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
  1859. goto prop_msg_full;
  1860. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
  1861. link->window))
  1862. goto prop_msg_full;
  1863. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  1864. goto prop_msg_full;
  1865. nla_nest_end(msg->skb, prop);
  1866. err = __tipc_nl_add_stats(msg->skb, &link->stats);
  1867. if (err)
  1868. goto attr_msg_full;
  1869. nla_nest_end(msg->skb, attrs);
  1870. genlmsg_end(msg->skb, hdr);
  1871. return 0;
  1872. prop_msg_full:
  1873. nla_nest_cancel(msg->skb, prop);
  1874. attr_msg_full:
  1875. nla_nest_cancel(msg->skb, attrs);
  1876. msg_full:
  1877. genlmsg_cancel(msg->skb, hdr);
  1878. return -EMSGSIZE;
  1879. }
  1880. static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
  1881. struct tipc_stats *stats)
  1882. {
  1883. int i;
  1884. struct nlattr *nest;
  1885. struct nla_map {
  1886. __u32 key;
  1887. __u32 val;
  1888. };
  1889. struct nla_map map[] = {
  1890. {TIPC_NLA_STATS_RX_INFO, stats->recv_pkts},
  1891. {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
  1892. {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
  1893. {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
  1894. {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
  1895. {TIPC_NLA_STATS_TX_INFO, stats->sent_pkts},
  1896. {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
  1897. {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
  1898. {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
  1899. {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
  1900. {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
  1901. {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
  1902. {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
  1903. {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
  1904. {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
  1905. {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
  1906. {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
  1907. {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
  1908. {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
  1909. (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
  1910. };
  1911. nest = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
  1912. if (!nest)
  1913. return -EMSGSIZE;
  1914. for (i = 0; i < ARRAY_SIZE(map); i++)
  1915. if (nla_put_u32(skb, map[i].key, map[i].val))
  1916. goto msg_full;
  1917. nla_nest_end(skb, nest);
  1918. return 0;
  1919. msg_full:
  1920. nla_nest_cancel(skb, nest);
  1921. return -EMSGSIZE;
  1922. }
  1923. int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
  1924. {
  1925. int err;
  1926. void *hdr;
  1927. struct nlattr *attrs;
  1928. struct nlattr *prop;
  1929. struct tipc_net *tn = net_generic(net, tipc_net_id);
  1930. struct tipc_link *bcl = tn->bcl;
  1931. if (!bcl)
  1932. return 0;
  1933. tipc_bcast_lock(net);
  1934. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  1935. NLM_F_MULTI, TIPC_NL_LINK_GET);
  1936. if (!hdr) {
  1937. tipc_bcast_unlock(net);
  1938. return -EMSGSIZE;
  1939. }
  1940. attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
  1941. if (!attrs)
  1942. goto msg_full;
  1943. /* The broadcast link is always up */
  1944. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  1945. goto attr_msg_full;
  1946. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
  1947. goto attr_msg_full;
  1948. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
  1949. goto attr_msg_full;
  1950. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, 0))
  1951. goto attr_msg_full;
  1952. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0))
  1953. goto attr_msg_full;
  1954. prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
  1955. if (!prop)
  1956. goto attr_msg_full;
  1957. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window))
  1958. goto prop_msg_full;
  1959. nla_nest_end(msg->skb, prop);
  1960. err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
  1961. if (err)
  1962. goto attr_msg_full;
  1963. tipc_bcast_unlock(net);
  1964. nla_nest_end(msg->skb, attrs);
  1965. genlmsg_end(msg->skb, hdr);
  1966. return 0;
  1967. prop_msg_full:
  1968. nla_nest_cancel(msg->skb, prop);
  1969. attr_msg_full:
  1970. nla_nest_cancel(msg->skb, attrs);
  1971. msg_full:
  1972. tipc_bcast_unlock(net);
  1973. genlmsg_cancel(msg->skb, hdr);
  1974. return -EMSGSIZE;
  1975. }
  1976. void tipc_link_set_tolerance(struct tipc_link *l, u32 tol,
  1977. struct sk_buff_head *xmitq)
  1978. {
  1979. l->tolerance = tol;
  1980. if (l->bc_rcvlink)
  1981. l->bc_rcvlink->tolerance = tol;
  1982. if (link_is_up(l))
  1983. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, tol, 0, xmitq);
  1984. }
  1985. void tipc_link_set_prio(struct tipc_link *l, u32 prio,
  1986. struct sk_buff_head *xmitq)
  1987. {
  1988. l->priority = prio;
  1989. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, prio, xmitq);
  1990. }
  1991. void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit)
  1992. {
  1993. l->abort_limit = limit;
  1994. }