PageRenderTime 62ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/net/tipc/link.c

http://github.com/mirrors/linux
C | 2855 lines | 2148 code | 312 blank | 395 comment | 376 complexity | 8e20a8e3c1b08ee70c2acc96714a19f1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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 "trace.h"
  46. #include "crypto.h"
  47. #include <linux/pkt_sched.h>
  48. struct tipc_stats {
  49. u32 sent_pkts;
  50. u32 recv_pkts;
  51. u32 sent_states;
  52. u32 recv_states;
  53. u32 sent_probes;
  54. u32 recv_probes;
  55. u32 sent_nacks;
  56. u32 recv_nacks;
  57. u32 sent_acks;
  58. u32 sent_bundled;
  59. u32 sent_bundles;
  60. u32 recv_bundled;
  61. u32 recv_bundles;
  62. u32 retransmitted;
  63. u32 sent_fragmented;
  64. u32 sent_fragments;
  65. u32 recv_fragmented;
  66. u32 recv_fragments;
  67. u32 link_congs; /* # port sends blocked by congestion */
  68. u32 deferred_recv;
  69. u32 duplicates;
  70. u32 max_queue_sz; /* send queue size high water mark */
  71. u32 accu_queue_sz; /* used for send queue size profiling */
  72. u32 queue_sz_counts; /* used for send queue size profiling */
  73. u32 msg_length_counts; /* used for message length profiling */
  74. u32 msg_lengths_total; /* used for message length profiling */
  75. u32 msg_length_profile[7]; /* used for msg. length profiling */
  76. };
  77. /**
  78. * struct tipc_link - TIPC link data structure
  79. * @addr: network address of link's peer node
  80. * @name: link name character string
  81. * @media_addr: media address to use when sending messages over link
  82. * @timer: link timer
  83. * @net: pointer to namespace struct
  84. * @refcnt: reference counter for permanent references (owner node & timer)
  85. * @peer_session: link session # being used by peer end of link
  86. * @peer_bearer_id: bearer id used by link's peer endpoint
  87. * @bearer_id: local bearer id used by link
  88. * @tolerance: minimum link continuity loss needed to reset link [in ms]
  89. * @abort_limit: # of unacknowledged continuity probes needed to reset link
  90. * @state: current state of link FSM
  91. * @peer_caps: bitmap describing capabilities of peer node
  92. * @silent_intv_cnt: # of timer intervals without any reception from peer
  93. * @proto_msg: template for control messages generated by link
  94. * @pmsg: convenience pointer to "proto_msg" field
  95. * @priority: current link priority
  96. * @net_plane: current link network plane ('A' through 'H')
  97. * @mon_state: cookie with information needed by link monitor
  98. * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
  99. * @exp_msg_count: # of tunnelled messages expected during link changeover
  100. * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
  101. * @mtu: current maximum packet size for this link
  102. * @advertised_mtu: advertised own mtu when link is being established
  103. * @transmitq: queue for sent, non-acked messages
  104. * @backlogq: queue for messages waiting to be sent
  105. * @snt_nxt: next sequence number to use for outbound messages
  106. * @ackers: # of peers that needs to ack each packet before it can be released
  107. * @acked: # last packet acked by a certain peer. Used for broadcast.
  108. * @rcv_nxt: next sequence number to expect for inbound messages
  109. * @deferred_queue: deferred queue saved OOS b'cast message received from node
  110. * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
  111. * @inputq: buffer queue for messages to be delivered upwards
  112. * @namedq: buffer queue for name table messages to be delivered upwards
  113. * @next_out: ptr to first unsent outbound message in queue
  114. * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
  115. * @long_msg_seq_no: next identifier to use for outbound fragmented messages
  116. * @reasm_buf: head of partially reassembled inbound message fragments
  117. * @bc_rcvr: marks that this is a broadcast receiver link
  118. * @stats: collects statistics regarding link activity
  119. */
  120. struct tipc_link {
  121. u32 addr;
  122. char name[TIPC_MAX_LINK_NAME];
  123. struct net *net;
  124. /* Management and link supervision data */
  125. u16 peer_session;
  126. u16 session;
  127. u16 snd_nxt_state;
  128. u16 rcv_nxt_state;
  129. u32 peer_bearer_id;
  130. u32 bearer_id;
  131. u32 tolerance;
  132. u32 abort_limit;
  133. u32 state;
  134. u16 peer_caps;
  135. bool in_session;
  136. bool active;
  137. u32 silent_intv_cnt;
  138. char if_name[TIPC_MAX_IF_NAME];
  139. u32 priority;
  140. char net_plane;
  141. struct tipc_mon_state mon_state;
  142. u16 rst_cnt;
  143. /* Failover/synch */
  144. u16 drop_point;
  145. struct sk_buff *failover_reasm_skb;
  146. struct sk_buff_head failover_deferdq;
  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. struct sk_buff *target_bskb;
  157. } backlog[5];
  158. u16 snd_nxt;
  159. /* Reception */
  160. u16 rcv_nxt;
  161. u32 rcv_unacked;
  162. struct sk_buff_head deferdq;
  163. struct sk_buff_head *inputq;
  164. struct sk_buff_head *namedq;
  165. /* Congestion handling */
  166. struct sk_buff_head wakeupq;
  167. u16 window;
  168. u16 min_win;
  169. u16 ssthresh;
  170. u16 max_win;
  171. u16 cong_acks;
  172. u16 checkpoint;
  173. /* Fragmentation/reassembly */
  174. struct sk_buff *reasm_buf;
  175. struct sk_buff *reasm_tnlmsg;
  176. /* Broadcast */
  177. u16 ackers;
  178. u16 acked;
  179. struct tipc_link *bc_rcvlink;
  180. struct tipc_link *bc_sndlink;
  181. u8 nack_state;
  182. bool bc_peer_is_up;
  183. /* Statistics */
  184. struct tipc_stats stats;
  185. };
  186. /*
  187. * Error message prefixes
  188. */
  189. static const char *link_co_err = "Link tunneling error, ";
  190. static const char *link_rst_msg = "Resetting link ";
  191. /* Send states for broadcast NACKs
  192. */
  193. enum {
  194. BC_NACK_SND_CONDITIONAL,
  195. BC_NACK_SND_UNCONDITIONAL,
  196. BC_NACK_SND_SUPPRESS,
  197. };
  198. #define TIPC_BC_RETR_LIM (jiffies + msecs_to_jiffies(10))
  199. #define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1))
  200. /*
  201. * Interval between NACKs when packets arrive out of order
  202. */
  203. #define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
  204. /* Link FSM states:
  205. */
  206. enum {
  207. LINK_ESTABLISHED = 0xe,
  208. LINK_ESTABLISHING = 0xe << 4,
  209. LINK_RESET = 0x1 << 8,
  210. LINK_RESETTING = 0x2 << 12,
  211. LINK_PEER_RESET = 0xd << 16,
  212. LINK_FAILINGOVER = 0xf << 20,
  213. LINK_SYNCHING = 0xc << 24
  214. };
  215. /* Link FSM state checking routines
  216. */
  217. static int link_is_up(struct tipc_link *l)
  218. {
  219. return l->state & (LINK_ESTABLISHED | LINK_SYNCHING);
  220. }
  221. static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
  222. struct sk_buff_head *xmitq);
  223. static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
  224. bool probe_reply, u16 rcvgap,
  225. int tolerance, int priority,
  226. struct sk_buff_head *xmitq);
  227. static void link_print(struct tipc_link *l, const char *str);
  228. static int tipc_link_build_nack_msg(struct tipc_link *l,
  229. struct sk_buff_head *xmitq);
  230. static void tipc_link_build_bc_init_msg(struct tipc_link *l,
  231. struct sk_buff_head *xmitq);
  232. static int tipc_link_release_pkts(struct tipc_link *l, u16 to);
  233. static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data, u16 gap);
  234. static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
  235. struct tipc_gap_ack_blks *ga,
  236. struct sk_buff_head *xmitq);
  237. static void tipc_link_update_cwin(struct tipc_link *l, int released,
  238. bool retransmitted);
  239. /*
  240. * Simple non-static link routines (i.e. referenced outside this file)
  241. */
  242. bool tipc_link_is_up(struct tipc_link *l)
  243. {
  244. return link_is_up(l);
  245. }
  246. bool tipc_link_peer_is_down(struct tipc_link *l)
  247. {
  248. return l->state == LINK_PEER_RESET;
  249. }
  250. bool tipc_link_is_reset(struct tipc_link *l)
  251. {
  252. return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
  253. }
  254. bool tipc_link_is_establishing(struct tipc_link *l)
  255. {
  256. return l->state == LINK_ESTABLISHING;
  257. }
  258. bool tipc_link_is_synching(struct tipc_link *l)
  259. {
  260. return l->state == LINK_SYNCHING;
  261. }
  262. bool tipc_link_is_failingover(struct tipc_link *l)
  263. {
  264. return l->state == LINK_FAILINGOVER;
  265. }
  266. bool tipc_link_is_blocked(struct tipc_link *l)
  267. {
  268. return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER);
  269. }
  270. static bool link_is_bc_sndlink(struct tipc_link *l)
  271. {
  272. return !l->bc_sndlink;
  273. }
  274. static bool link_is_bc_rcvlink(struct tipc_link *l)
  275. {
  276. return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l));
  277. }
  278. void tipc_link_set_active(struct tipc_link *l, bool active)
  279. {
  280. l->active = active;
  281. }
  282. u32 tipc_link_id(struct tipc_link *l)
  283. {
  284. return l->peer_bearer_id << 16 | l->bearer_id;
  285. }
  286. int tipc_link_min_win(struct tipc_link *l)
  287. {
  288. return l->min_win;
  289. }
  290. int tipc_link_max_win(struct tipc_link *l)
  291. {
  292. return l->max_win;
  293. }
  294. int tipc_link_prio(struct tipc_link *l)
  295. {
  296. return l->priority;
  297. }
  298. unsigned long tipc_link_tolerance(struct tipc_link *l)
  299. {
  300. return l->tolerance;
  301. }
  302. struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
  303. {
  304. return l->inputq;
  305. }
  306. char tipc_link_plane(struct tipc_link *l)
  307. {
  308. return l->net_plane;
  309. }
  310. void tipc_link_update_caps(struct tipc_link *l, u16 capabilities)
  311. {
  312. l->peer_caps = capabilities;
  313. }
  314. void tipc_link_add_bc_peer(struct tipc_link *snd_l,
  315. struct tipc_link *uc_l,
  316. struct sk_buff_head *xmitq)
  317. {
  318. struct tipc_link *rcv_l = uc_l->bc_rcvlink;
  319. snd_l->ackers++;
  320. rcv_l->acked = snd_l->snd_nxt - 1;
  321. snd_l->state = LINK_ESTABLISHED;
  322. tipc_link_build_bc_init_msg(uc_l, xmitq);
  323. }
  324. void tipc_link_remove_bc_peer(struct tipc_link *snd_l,
  325. struct tipc_link *rcv_l,
  326. struct sk_buff_head *xmitq)
  327. {
  328. u16 ack = snd_l->snd_nxt - 1;
  329. snd_l->ackers--;
  330. rcv_l->bc_peer_is_up = true;
  331. rcv_l->state = LINK_ESTABLISHED;
  332. tipc_link_bc_ack_rcv(rcv_l, ack, xmitq);
  333. trace_tipc_link_reset(rcv_l, TIPC_DUMP_ALL, "bclink removed!");
  334. tipc_link_reset(rcv_l);
  335. rcv_l->state = LINK_RESET;
  336. if (!snd_l->ackers) {
  337. trace_tipc_link_reset(snd_l, TIPC_DUMP_ALL, "zero ackers!");
  338. tipc_link_reset(snd_l);
  339. snd_l->state = LINK_RESET;
  340. __skb_queue_purge(xmitq);
  341. }
  342. }
  343. int tipc_link_bc_peers(struct tipc_link *l)
  344. {
  345. return l->ackers;
  346. }
  347. static u16 link_bc_rcv_gap(struct tipc_link *l)
  348. {
  349. struct sk_buff *skb = skb_peek(&l->deferdq);
  350. u16 gap = 0;
  351. if (more(l->snd_nxt, l->rcv_nxt))
  352. gap = l->snd_nxt - l->rcv_nxt;
  353. if (skb)
  354. gap = buf_seqno(skb) - l->rcv_nxt;
  355. return gap;
  356. }
  357. void tipc_link_set_mtu(struct tipc_link *l, int mtu)
  358. {
  359. l->mtu = mtu;
  360. }
  361. int tipc_link_mtu(struct tipc_link *l)
  362. {
  363. return l->mtu;
  364. }
  365. int tipc_link_mss(struct tipc_link *l)
  366. {
  367. #ifdef CONFIG_TIPC_CRYPTO
  368. return l->mtu - INT_H_SIZE - EMSG_OVERHEAD;
  369. #else
  370. return l->mtu - INT_H_SIZE;
  371. #endif
  372. }
  373. u16 tipc_link_rcv_nxt(struct tipc_link *l)
  374. {
  375. return l->rcv_nxt;
  376. }
  377. u16 tipc_link_acked(struct tipc_link *l)
  378. {
  379. return l->acked;
  380. }
  381. char *tipc_link_name(struct tipc_link *l)
  382. {
  383. return l->name;
  384. }
  385. u32 tipc_link_state(struct tipc_link *l)
  386. {
  387. return l->state;
  388. }
  389. /**
  390. * tipc_link_create - create a new link
  391. * @n: pointer to associated node
  392. * @if_name: associated interface name
  393. * @bearer_id: id (index) of associated bearer
  394. * @tolerance: link tolerance to be used by link
  395. * @net_plane: network plane (A,B,c..) this link belongs to
  396. * @mtu: mtu to be advertised by link
  397. * @priority: priority to be used by link
  398. * @min_win: minimal send window to be used by link
  399. * @max_win: maximal send window to be used by link
  400. * @session: session to be used by link
  401. * @ownnode: identity of own node
  402. * @peer: node id of peer node
  403. * @peer_caps: bitmap describing peer node capabilities
  404. * @bc_sndlink: the namespace global link used for broadcast sending
  405. * @bc_rcvlink: the peer specific link used for broadcast reception
  406. * @inputq: queue to put messages ready for delivery
  407. * @namedq: queue to put binding table update messages ready for delivery
  408. * @link: return value, pointer to put the created link
  409. *
  410. * Returns true if link was created, otherwise false
  411. */
  412. bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
  413. int tolerance, char net_plane, u32 mtu, int priority,
  414. u32 min_win, u32 max_win, u32 session, u32 self,
  415. u32 peer, u8 *peer_id, u16 peer_caps,
  416. struct tipc_link *bc_sndlink,
  417. struct tipc_link *bc_rcvlink,
  418. struct sk_buff_head *inputq,
  419. struct sk_buff_head *namedq,
  420. struct tipc_link **link)
  421. {
  422. char peer_str[NODE_ID_STR_LEN] = {0,};
  423. char self_str[NODE_ID_STR_LEN] = {0,};
  424. struct tipc_link *l;
  425. l = kzalloc(sizeof(*l), GFP_ATOMIC);
  426. if (!l)
  427. return false;
  428. *link = l;
  429. l->session = session;
  430. /* Set link name for unicast links only */
  431. if (peer_id) {
  432. tipc_nodeid2string(self_str, tipc_own_id(net));
  433. if (strlen(self_str) > 16)
  434. sprintf(self_str, "%x", self);
  435. tipc_nodeid2string(peer_str, peer_id);
  436. if (strlen(peer_str) > 16)
  437. sprintf(peer_str, "%x", peer);
  438. }
  439. /* Peer i/f name will be completed by reset/activate message */
  440. snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
  441. self_str, if_name, peer_str);
  442. strcpy(l->if_name, if_name);
  443. l->addr = peer;
  444. l->peer_caps = peer_caps;
  445. l->net = net;
  446. l->in_session = false;
  447. l->bearer_id = bearer_id;
  448. l->tolerance = tolerance;
  449. if (bc_rcvlink)
  450. bc_rcvlink->tolerance = tolerance;
  451. l->net_plane = net_plane;
  452. l->advertised_mtu = mtu;
  453. l->mtu = mtu;
  454. l->priority = priority;
  455. tipc_link_set_queue_limits(l, min_win, max_win);
  456. l->ackers = 1;
  457. l->bc_sndlink = bc_sndlink;
  458. l->bc_rcvlink = bc_rcvlink;
  459. l->inputq = inputq;
  460. l->namedq = namedq;
  461. l->state = LINK_RESETTING;
  462. __skb_queue_head_init(&l->transmq);
  463. __skb_queue_head_init(&l->backlogq);
  464. __skb_queue_head_init(&l->deferdq);
  465. __skb_queue_head_init(&l->failover_deferdq);
  466. skb_queue_head_init(&l->wakeupq);
  467. skb_queue_head_init(l->inputq);
  468. return true;
  469. }
  470. /**
  471. * tipc_link_bc_create - create new link to be used for broadcast
  472. * @n: pointer to associated node
  473. * @mtu: mtu to be used initially if no peers
  474. * @window: send window to be used
  475. * @inputq: queue to put messages ready for delivery
  476. * @namedq: queue to put binding table update messages ready for delivery
  477. * @link: return value, pointer to put the created link
  478. *
  479. * Returns true if link was created, otherwise false
  480. */
  481. bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
  482. int mtu, u32 min_win, u32 max_win, u16 peer_caps,
  483. struct sk_buff_head *inputq,
  484. struct sk_buff_head *namedq,
  485. struct tipc_link *bc_sndlink,
  486. struct tipc_link **link)
  487. {
  488. struct tipc_link *l;
  489. if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, min_win,
  490. max_win, 0, ownnode, peer, NULL, peer_caps,
  491. bc_sndlink, NULL, inputq, namedq, link))
  492. return false;
  493. l = *link;
  494. strcpy(l->name, tipc_bclink_name);
  495. trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!");
  496. tipc_link_reset(l);
  497. l->state = LINK_RESET;
  498. l->ackers = 0;
  499. l->bc_rcvlink = l;
  500. /* Broadcast send link is always up */
  501. if (link_is_bc_sndlink(l))
  502. l->state = LINK_ESTABLISHED;
  503. /* Disable replicast if even a single peer doesn't support it */
  504. if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
  505. tipc_bcast_toggle_rcast(net, false);
  506. return true;
  507. }
  508. /**
  509. * tipc_link_fsm_evt - link finite state machine
  510. * @l: pointer to link
  511. * @evt: state machine event to be processed
  512. */
  513. int tipc_link_fsm_evt(struct tipc_link *l, int evt)
  514. {
  515. int rc = 0;
  516. int old_state = l->state;
  517. switch (l->state) {
  518. case LINK_RESETTING:
  519. switch (evt) {
  520. case LINK_PEER_RESET_EVT:
  521. l->state = LINK_PEER_RESET;
  522. break;
  523. case LINK_RESET_EVT:
  524. l->state = LINK_RESET;
  525. break;
  526. case LINK_FAILURE_EVT:
  527. case LINK_FAILOVER_BEGIN_EVT:
  528. case LINK_ESTABLISH_EVT:
  529. case LINK_FAILOVER_END_EVT:
  530. case LINK_SYNCH_BEGIN_EVT:
  531. case LINK_SYNCH_END_EVT:
  532. default:
  533. goto illegal_evt;
  534. }
  535. break;
  536. case LINK_RESET:
  537. switch (evt) {
  538. case LINK_PEER_RESET_EVT:
  539. l->state = LINK_ESTABLISHING;
  540. break;
  541. case LINK_FAILOVER_BEGIN_EVT:
  542. l->state = LINK_FAILINGOVER;
  543. case LINK_FAILURE_EVT:
  544. case LINK_RESET_EVT:
  545. case LINK_ESTABLISH_EVT:
  546. case LINK_FAILOVER_END_EVT:
  547. break;
  548. case LINK_SYNCH_BEGIN_EVT:
  549. case LINK_SYNCH_END_EVT:
  550. default:
  551. goto illegal_evt;
  552. }
  553. break;
  554. case LINK_PEER_RESET:
  555. switch (evt) {
  556. case LINK_RESET_EVT:
  557. l->state = LINK_ESTABLISHING;
  558. break;
  559. case LINK_PEER_RESET_EVT:
  560. case LINK_ESTABLISH_EVT:
  561. case LINK_FAILURE_EVT:
  562. break;
  563. case LINK_SYNCH_BEGIN_EVT:
  564. case LINK_SYNCH_END_EVT:
  565. case LINK_FAILOVER_BEGIN_EVT:
  566. case LINK_FAILOVER_END_EVT:
  567. default:
  568. goto illegal_evt;
  569. }
  570. break;
  571. case LINK_FAILINGOVER:
  572. switch (evt) {
  573. case LINK_FAILOVER_END_EVT:
  574. l->state = LINK_RESET;
  575. break;
  576. case LINK_PEER_RESET_EVT:
  577. case LINK_RESET_EVT:
  578. case LINK_ESTABLISH_EVT:
  579. case LINK_FAILURE_EVT:
  580. break;
  581. case LINK_FAILOVER_BEGIN_EVT:
  582. case LINK_SYNCH_BEGIN_EVT:
  583. case LINK_SYNCH_END_EVT:
  584. default:
  585. goto illegal_evt;
  586. }
  587. break;
  588. case LINK_ESTABLISHING:
  589. switch (evt) {
  590. case LINK_ESTABLISH_EVT:
  591. l->state = LINK_ESTABLISHED;
  592. break;
  593. case LINK_FAILOVER_BEGIN_EVT:
  594. l->state = LINK_FAILINGOVER;
  595. break;
  596. case LINK_RESET_EVT:
  597. l->state = LINK_RESET;
  598. break;
  599. case LINK_FAILURE_EVT:
  600. case LINK_PEER_RESET_EVT:
  601. case LINK_SYNCH_BEGIN_EVT:
  602. case LINK_FAILOVER_END_EVT:
  603. break;
  604. case LINK_SYNCH_END_EVT:
  605. default:
  606. goto illegal_evt;
  607. }
  608. break;
  609. case LINK_ESTABLISHED:
  610. switch (evt) {
  611. case LINK_PEER_RESET_EVT:
  612. l->state = LINK_PEER_RESET;
  613. rc |= TIPC_LINK_DOWN_EVT;
  614. break;
  615. case LINK_FAILURE_EVT:
  616. l->state = LINK_RESETTING;
  617. rc |= TIPC_LINK_DOWN_EVT;
  618. break;
  619. case LINK_RESET_EVT:
  620. l->state = LINK_RESET;
  621. break;
  622. case LINK_ESTABLISH_EVT:
  623. case LINK_SYNCH_END_EVT:
  624. break;
  625. case LINK_SYNCH_BEGIN_EVT:
  626. l->state = LINK_SYNCHING;
  627. break;
  628. case LINK_FAILOVER_BEGIN_EVT:
  629. case LINK_FAILOVER_END_EVT:
  630. default:
  631. goto illegal_evt;
  632. }
  633. break;
  634. case LINK_SYNCHING:
  635. switch (evt) {
  636. case LINK_PEER_RESET_EVT:
  637. l->state = LINK_PEER_RESET;
  638. rc |= TIPC_LINK_DOWN_EVT;
  639. break;
  640. case LINK_FAILURE_EVT:
  641. l->state = LINK_RESETTING;
  642. rc |= TIPC_LINK_DOWN_EVT;
  643. break;
  644. case LINK_RESET_EVT:
  645. l->state = LINK_RESET;
  646. break;
  647. case LINK_ESTABLISH_EVT:
  648. case LINK_SYNCH_BEGIN_EVT:
  649. break;
  650. case LINK_SYNCH_END_EVT:
  651. l->state = LINK_ESTABLISHED;
  652. break;
  653. case LINK_FAILOVER_BEGIN_EVT:
  654. case LINK_FAILOVER_END_EVT:
  655. default:
  656. goto illegal_evt;
  657. }
  658. break;
  659. default:
  660. pr_err("Unknown FSM state %x in %s\n", l->state, l->name);
  661. }
  662. trace_tipc_link_fsm(l->name, old_state, l->state, evt);
  663. return rc;
  664. illegal_evt:
  665. pr_err("Illegal FSM event %x in state %x on link %s\n",
  666. evt, l->state, l->name);
  667. trace_tipc_link_fsm(l->name, old_state, l->state, evt);
  668. return rc;
  669. }
  670. /* link_profile_stats - update statistical profiling of traffic
  671. */
  672. static void link_profile_stats(struct tipc_link *l)
  673. {
  674. struct sk_buff *skb;
  675. struct tipc_msg *msg;
  676. int length;
  677. /* Update counters used in statistical profiling of send traffic */
  678. l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
  679. l->stats.queue_sz_counts++;
  680. skb = skb_peek(&l->transmq);
  681. if (!skb)
  682. return;
  683. msg = buf_msg(skb);
  684. length = msg_size(msg);
  685. if (msg_user(msg) == MSG_FRAGMENTER) {
  686. if (msg_type(msg) != FIRST_FRAGMENT)
  687. return;
  688. length = msg_size(msg_inner_hdr(msg));
  689. }
  690. l->stats.msg_lengths_total += length;
  691. l->stats.msg_length_counts++;
  692. if (length <= 64)
  693. l->stats.msg_length_profile[0]++;
  694. else if (length <= 256)
  695. l->stats.msg_length_profile[1]++;
  696. else if (length <= 1024)
  697. l->stats.msg_length_profile[2]++;
  698. else if (length <= 4096)
  699. l->stats.msg_length_profile[3]++;
  700. else if (length <= 16384)
  701. l->stats.msg_length_profile[4]++;
  702. else if (length <= 32768)
  703. l->stats.msg_length_profile[5]++;
  704. else
  705. l->stats.msg_length_profile[6]++;
  706. }
  707. /**
  708. * tipc_link_too_silent - check if link is "too silent"
  709. * @l: tipc link to be checked
  710. *
  711. * Returns true if the link 'silent_intv_cnt' is about to reach the
  712. * 'abort_limit' value, otherwise false
  713. */
  714. bool tipc_link_too_silent(struct tipc_link *l)
  715. {
  716. return (l->silent_intv_cnt + 2 > l->abort_limit);
  717. }
  718. static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r,
  719. u16 from, u16 to, struct sk_buff_head *xmitq);
  720. /* tipc_link_timeout - perform periodic task as instructed from node timeout
  721. */
  722. int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
  723. {
  724. int mtyp = 0;
  725. int rc = 0;
  726. bool state = false;
  727. bool probe = false;
  728. bool setup = false;
  729. u16 bc_snt = l->bc_sndlink->snd_nxt - 1;
  730. u16 bc_acked = l->bc_rcvlink->acked;
  731. struct tipc_mon_state *mstate = &l->mon_state;
  732. trace_tipc_link_timeout(l, TIPC_DUMP_NONE, " ");
  733. trace_tipc_link_too_silent(l, TIPC_DUMP_ALL, " ");
  734. switch (l->state) {
  735. case LINK_ESTABLISHED:
  736. case LINK_SYNCHING:
  737. mtyp = STATE_MSG;
  738. link_profile_stats(l);
  739. tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id);
  740. if (mstate->reset || (l->silent_intv_cnt > l->abort_limit))
  741. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  742. state = bc_acked != bc_snt;
  743. state |= l->bc_rcvlink->rcv_unacked;
  744. state |= l->rcv_unacked;
  745. state |= !skb_queue_empty(&l->transmq);
  746. state |= !skb_queue_empty(&l->deferdq);
  747. probe = mstate->probing;
  748. probe |= l->silent_intv_cnt;
  749. if (probe || mstate->monitoring)
  750. l->silent_intv_cnt++;
  751. if (l->snd_nxt == l->checkpoint) {
  752. tipc_link_update_cwin(l, 0, 0);
  753. probe = true;
  754. }
  755. l->checkpoint = l->snd_nxt;
  756. break;
  757. case LINK_RESET:
  758. setup = l->rst_cnt++ <= 4;
  759. setup |= !(l->rst_cnt % 16);
  760. mtyp = RESET_MSG;
  761. break;
  762. case LINK_ESTABLISHING:
  763. setup = true;
  764. mtyp = ACTIVATE_MSG;
  765. break;
  766. case LINK_PEER_RESET:
  767. case LINK_RESETTING:
  768. case LINK_FAILINGOVER:
  769. break;
  770. default:
  771. break;
  772. }
  773. if (state || probe || setup)
  774. tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq);
  775. return rc;
  776. }
  777. /**
  778. * link_schedule_user - schedule a message sender for wakeup after congestion
  779. * @l: congested link
  780. * @hdr: header of message that is being sent
  781. * Create pseudo msg to send back to user when congestion abates
  782. */
  783. static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr)
  784. {
  785. u32 dnode = tipc_own_addr(l->net);
  786. u32 dport = msg_origport(hdr);
  787. struct sk_buff *skb;
  788. /* Create and schedule wakeup pseudo message */
  789. skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
  790. dnode, l->addr, dport, 0, 0);
  791. if (!skb)
  792. return -ENOBUFS;
  793. msg_set_dest_droppable(buf_msg(skb), true);
  794. TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr);
  795. skb_queue_tail(&l->wakeupq, skb);
  796. l->stats.link_congs++;
  797. trace_tipc_link_conges(l, TIPC_DUMP_ALL, "wakeup scheduled!");
  798. return -ELINKCONG;
  799. }
  800. /**
  801. * link_prepare_wakeup - prepare users for wakeup after congestion
  802. * @l: congested link
  803. * Wake up a number of waiting users, as permitted by available space
  804. * in the send queue
  805. */
  806. static void link_prepare_wakeup(struct tipc_link *l)
  807. {
  808. struct sk_buff_head *wakeupq = &l->wakeupq;
  809. struct sk_buff_head *inputq = l->inputq;
  810. struct sk_buff *skb, *tmp;
  811. struct sk_buff_head tmpq;
  812. int avail[5] = {0,};
  813. int imp = 0;
  814. __skb_queue_head_init(&tmpq);
  815. for (; imp <= TIPC_SYSTEM_IMPORTANCE; imp++)
  816. avail[imp] = l->backlog[imp].limit - l->backlog[imp].len;
  817. skb_queue_walk_safe(wakeupq, skb, tmp) {
  818. imp = TIPC_SKB_CB(skb)->chain_imp;
  819. if (avail[imp] <= 0)
  820. continue;
  821. avail[imp]--;
  822. __skb_unlink(skb, wakeupq);
  823. __skb_queue_tail(&tmpq, skb);
  824. }
  825. spin_lock_bh(&inputq->lock);
  826. skb_queue_splice_tail(&tmpq, inputq);
  827. spin_unlock_bh(&inputq->lock);
  828. }
  829. void tipc_link_reset(struct tipc_link *l)
  830. {
  831. struct sk_buff_head list;
  832. u32 imp;
  833. __skb_queue_head_init(&list);
  834. l->in_session = false;
  835. /* Force re-synch of peer session number before establishing */
  836. l->peer_session--;
  837. l->session++;
  838. l->mtu = l->advertised_mtu;
  839. spin_lock_bh(&l->wakeupq.lock);
  840. skb_queue_splice_init(&l->wakeupq, &list);
  841. spin_unlock_bh(&l->wakeupq.lock);
  842. spin_lock_bh(&l->inputq->lock);
  843. skb_queue_splice_init(&list, l->inputq);
  844. spin_unlock_bh(&l->inputq->lock);
  845. __skb_queue_purge(&l->transmq);
  846. __skb_queue_purge(&l->deferdq);
  847. __skb_queue_purge(&l->backlogq);
  848. __skb_queue_purge(&l->failover_deferdq);
  849. for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) {
  850. l->backlog[imp].len = 0;
  851. l->backlog[imp].target_bskb = NULL;
  852. }
  853. kfree_skb(l->reasm_buf);
  854. kfree_skb(l->reasm_tnlmsg);
  855. kfree_skb(l->failover_reasm_skb);
  856. l->reasm_buf = NULL;
  857. l->reasm_tnlmsg = NULL;
  858. l->failover_reasm_skb = NULL;
  859. l->rcv_unacked = 0;
  860. l->snd_nxt = 1;
  861. l->rcv_nxt = 1;
  862. l->snd_nxt_state = 1;
  863. l->rcv_nxt_state = 1;
  864. l->acked = 0;
  865. l->silent_intv_cnt = 0;
  866. l->rst_cnt = 0;
  867. l->bc_peer_is_up = false;
  868. memset(&l->mon_state, 0, sizeof(l->mon_state));
  869. tipc_link_reset_stats(l);
  870. }
  871. /**
  872. * tipc_link_xmit(): enqueue buffer list according to queue situation
  873. * @link: link to use
  874. * @list: chain of buffers containing message
  875. * @xmitq: returned list of packets to be sent by caller
  876. *
  877. * Consumes the buffer chain.
  878. * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
  879. * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
  880. */
  881. int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
  882. struct sk_buff_head *xmitq)
  883. {
  884. struct tipc_msg *hdr = buf_msg(skb_peek(list));
  885. struct sk_buff_head *backlogq = &l->backlogq;
  886. struct sk_buff_head *transmq = &l->transmq;
  887. struct sk_buff *skb, *_skb;
  888. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  889. u16 ack = l->rcv_nxt - 1;
  890. u16 seqno = l->snd_nxt;
  891. int pkt_cnt = skb_queue_len(list);
  892. int imp = msg_importance(hdr);
  893. unsigned int mss = tipc_link_mss(l);
  894. unsigned int cwin = l->window;
  895. unsigned int mtu = l->mtu;
  896. bool new_bundle;
  897. int rc = 0;
  898. if (unlikely(msg_size(hdr) > mtu)) {
  899. pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n",
  900. skb_queue_len(list), msg_user(hdr),
  901. msg_type(hdr), msg_size(hdr), mtu);
  902. __skb_queue_purge(list);
  903. return -EMSGSIZE;
  904. }
  905. /* Allow oversubscription of one data msg per source at congestion */
  906. if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
  907. if (imp == TIPC_SYSTEM_IMPORTANCE) {
  908. pr_warn("%s<%s>, link overflow", link_rst_msg, l->name);
  909. return -ENOBUFS;
  910. }
  911. rc = link_schedule_user(l, hdr);
  912. }
  913. if (pkt_cnt > 1) {
  914. l->stats.sent_fragmented++;
  915. l->stats.sent_fragments += pkt_cnt;
  916. }
  917. /* Prepare each packet for sending, and add to relevant queue: */
  918. while ((skb = __skb_dequeue(list))) {
  919. if (likely(skb_queue_len(transmq) < cwin)) {
  920. hdr = buf_msg(skb);
  921. msg_set_seqno(hdr, seqno);
  922. msg_set_ack(hdr, ack);
  923. msg_set_bcast_ack(hdr, bc_ack);
  924. _skb = skb_clone(skb, GFP_ATOMIC);
  925. if (!_skb) {
  926. kfree_skb(skb);
  927. __skb_queue_purge(list);
  928. return -ENOBUFS;
  929. }
  930. __skb_queue_tail(transmq, skb);
  931. /* next retransmit attempt */
  932. if (link_is_bc_sndlink(l))
  933. TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
  934. __skb_queue_tail(xmitq, _skb);
  935. TIPC_SKB_CB(skb)->ackers = l->ackers;
  936. l->rcv_unacked = 0;
  937. l->stats.sent_pkts++;
  938. seqno++;
  939. continue;
  940. }
  941. if (tipc_msg_try_bundle(l->backlog[imp].target_bskb, &skb,
  942. mss, l->addr, &new_bundle)) {
  943. if (skb) {
  944. /* Keep a ref. to the skb for next try */
  945. l->backlog[imp].target_bskb = skb;
  946. l->backlog[imp].len++;
  947. __skb_queue_tail(backlogq, skb);
  948. } else {
  949. if (new_bundle) {
  950. l->stats.sent_bundles++;
  951. l->stats.sent_bundled++;
  952. }
  953. l->stats.sent_bundled++;
  954. }
  955. continue;
  956. }
  957. l->backlog[imp].target_bskb = NULL;
  958. l->backlog[imp].len += (1 + skb_queue_len(list));
  959. __skb_queue_tail(backlogq, skb);
  960. skb_queue_splice_tail_init(list, backlogq);
  961. }
  962. l->snd_nxt = seqno;
  963. return rc;
  964. }
  965. static void tipc_link_update_cwin(struct tipc_link *l, int released,
  966. bool retransmitted)
  967. {
  968. int bklog_len = skb_queue_len(&l->backlogq);
  969. struct sk_buff_head *txq = &l->transmq;
  970. int txq_len = skb_queue_len(txq);
  971. u16 cwin = l->window;
  972. /* Enter fast recovery */
  973. if (unlikely(retransmitted)) {
  974. l->ssthresh = max_t(u16, l->window / 2, 300);
  975. l->window = min_t(u16, l->ssthresh, l->window);
  976. return;
  977. }
  978. /* Enter slow start */
  979. if (unlikely(!released)) {
  980. l->ssthresh = max_t(u16, l->window / 2, 300);
  981. l->window = l->min_win;
  982. return;
  983. }
  984. /* Don't increase window if no pressure on the transmit queue */
  985. if (txq_len + bklog_len < cwin)
  986. return;
  987. /* Don't increase window if there are holes the transmit queue */
  988. if (txq_len && l->snd_nxt - buf_seqno(skb_peek(txq)) != txq_len)
  989. return;
  990. l->cong_acks += released;
  991. /* Slow start */
  992. if (cwin <= l->ssthresh) {
  993. l->window = min_t(u16, cwin + released, l->max_win);
  994. return;
  995. }
  996. /* Congestion avoidance */
  997. if (l->cong_acks < cwin)
  998. return;
  999. l->window = min_t(u16, ++cwin, l->max_win);
  1000. l->cong_acks = 0;
  1001. }
  1002. static void tipc_link_advance_backlog(struct tipc_link *l,
  1003. struct sk_buff_head *xmitq)
  1004. {
  1005. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  1006. struct sk_buff_head *txq = &l->transmq;
  1007. struct sk_buff *skb, *_skb;
  1008. u16 ack = l->rcv_nxt - 1;
  1009. u16 seqno = l->snd_nxt;
  1010. struct tipc_msg *hdr;
  1011. u16 cwin = l->window;
  1012. u32 imp;
  1013. while (skb_queue_len(txq) < cwin) {
  1014. skb = skb_peek(&l->backlogq);
  1015. if (!skb)
  1016. break;
  1017. _skb = skb_clone(skb, GFP_ATOMIC);
  1018. if (!_skb)
  1019. break;
  1020. __skb_dequeue(&l->backlogq);
  1021. hdr = buf_msg(skb);
  1022. imp = msg_importance(hdr);
  1023. l->backlog[imp].len--;
  1024. if (unlikely(skb == l->backlog[imp].target_bskb))
  1025. l->backlog[imp].target_bskb = NULL;
  1026. __skb_queue_tail(&l->transmq, skb);
  1027. /* next retransmit attempt */
  1028. if (link_is_bc_sndlink(l))
  1029. TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
  1030. __skb_queue_tail(xmitq, _skb);
  1031. TIPC_SKB_CB(skb)->ackers = l->ackers;
  1032. msg_set_seqno(hdr, seqno);
  1033. msg_set_ack(hdr, ack);
  1034. msg_set_bcast_ack(hdr, bc_ack);
  1035. l->rcv_unacked = 0;
  1036. l->stats.sent_pkts++;
  1037. seqno++;
  1038. }
  1039. l->snd_nxt = seqno;
  1040. }
  1041. /**
  1042. * link_retransmit_failure() - Detect repeated retransmit failures
  1043. * @l: tipc link sender
  1044. * @r: tipc link receiver (= l in case of unicast)
  1045. * @rc: returned code
  1046. *
  1047. * Return: true if the repeated retransmit failures happens, otherwise
  1048. * false
  1049. */
  1050. static bool link_retransmit_failure(struct tipc_link *l, struct tipc_link *r,
  1051. int *rc)
  1052. {
  1053. struct sk_buff *skb = skb_peek(&l->transmq);
  1054. struct tipc_msg *hdr;
  1055. if (!skb)
  1056. return false;
  1057. if (!TIPC_SKB_CB(skb)->retr_cnt)
  1058. return false;
  1059. if (!time_after(jiffies, TIPC_SKB_CB(skb)->retr_stamp +
  1060. msecs_to_jiffies(r->tolerance * 10)))
  1061. return false;
  1062. hdr = buf_msg(skb);
  1063. if (link_is_bc_sndlink(l) && !less(r->acked, msg_seqno(hdr)))
  1064. return false;
  1065. pr_warn("Retransmission failure on link <%s>\n", l->name);
  1066. link_print(l, "State of link ");
  1067. pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n",
  1068. msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr));
  1069. pr_info("sqno %u, prev: %x, dest: %x\n",
  1070. msg_seqno(hdr), msg_prevnode(hdr), msg_destnode(hdr));
  1071. pr_info("retr_stamp %d, retr_cnt %d\n",
  1072. jiffies_to_msecs(TIPC_SKB_CB(skb)->retr_stamp),
  1073. TIPC_SKB_CB(skb)->retr_cnt);
  1074. trace_tipc_list_dump(&l->transmq, true, "retrans failure!");
  1075. trace_tipc_link_dump(l, TIPC_DUMP_NONE, "retrans failure!");
  1076. trace_tipc_link_dump(r, TIPC_DUMP_NONE, "retrans failure!");
  1077. if (link_is_bc_sndlink(l)) {
  1078. r->state = LINK_RESET;
  1079. *rc = TIPC_LINK_DOWN_EVT;
  1080. } else {
  1081. *rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1082. }
  1083. return true;
  1084. }
  1085. /* tipc_link_bc_retrans() - retransmit zero or more packets
  1086. * @l: the link to transmit on
  1087. * @r: the receiving link ordering the retransmit. Same as l if unicast
  1088. * @from: retransmit from (inclusive) this sequence number
  1089. * @to: retransmit to (inclusive) this sequence number
  1090. * xmitq: queue for accumulating the retransmitted packets
  1091. */
  1092. static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r,
  1093. u16 from, u16 to, struct sk_buff_head *xmitq)
  1094. {
  1095. struct sk_buff *_skb, *skb = skb_peek(&l->transmq);
  1096. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  1097. u16 ack = l->rcv_nxt - 1;
  1098. int retransmitted = 0;
  1099. struct tipc_msg *hdr;
  1100. int rc = 0;
  1101. if (!skb)
  1102. return 0;
  1103. if (less(to, from))
  1104. return 0;
  1105. trace_tipc_link_retrans(r, from, to, &l->transmq);
  1106. if (link_retransmit_failure(l, r, &rc))
  1107. return rc;
  1108. skb_queue_walk(&l->transmq, skb) {
  1109. hdr = buf_msg(skb);
  1110. if (less(msg_seqno(hdr), from))
  1111. continue;
  1112. if (more(msg_seqno(hdr), to))
  1113. break;
  1114. if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
  1115. continue;
  1116. TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
  1117. _skb = pskb_copy(skb, GFP_ATOMIC);
  1118. if (!_skb)
  1119. return 0;
  1120. hdr = buf_msg(_skb);
  1121. msg_set_ack(hdr, ack);
  1122. msg_set_bcast_ack(hdr, bc_ack);
  1123. _skb->priority = TC_PRIO_CONTROL;
  1124. __skb_queue_tail(xmitq, _skb);
  1125. l->stats.retransmitted++;
  1126. retransmitted++;
  1127. /* Increase actual retrans counter & mark first time */
  1128. if (!TIPC_SKB_CB(skb)->retr_cnt++)
  1129. TIPC_SKB_CB(skb)->retr_stamp = jiffies;
  1130. }
  1131. tipc_link_update_cwin(l, 0, retransmitted);
  1132. return 0;
  1133. }
  1134. /* tipc_data_input - deliver data and name distr msgs to upper layer
  1135. *
  1136. * Consumes buffer if message is of right type
  1137. * Node lock must be held
  1138. */
  1139. static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
  1140. struct sk_buff_head *inputq)
  1141. {
  1142. struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq;
  1143. struct tipc_msg *hdr = buf_msg(skb);
  1144. switch (msg_user(hdr)) {
  1145. case TIPC_LOW_IMPORTANCE:
  1146. case TIPC_MEDIUM_IMPORTANCE:
  1147. case TIPC_HIGH_IMPORTANCE:
  1148. case TIPC_CRITICAL_IMPORTANCE:
  1149. if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) {
  1150. skb_queue_tail(mc_inputq, skb);
  1151. return true;
  1152. }
  1153. /* fall through */
  1154. case CONN_MANAGER:
  1155. skb_queue_tail(inputq, skb);
  1156. return true;
  1157. case GROUP_PROTOCOL:
  1158. skb_queue_tail(mc_inputq, skb);
  1159. return true;
  1160. case NAME_DISTRIBUTOR:
  1161. l->bc_rcvlink->state = LINK_ESTABLISHED;
  1162. skb_queue_tail(l->namedq, skb);
  1163. return true;
  1164. case MSG_BUNDLER:
  1165. case TUNNEL_PROTOCOL:
  1166. case MSG_FRAGMENTER:
  1167. case BCAST_PROTOCOL:
  1168. return false;
  1169. default:
  1170. pr_warn("Dropping received illegal msg type\n");
  1171. kfree_skb(skb);
  1172. return true;
  1173. };
  1174. }
  1175. /* tipc_link_input - process packet that has passed link protocol check
  1176. *
  1177. * Consumes buffer
  1178. */
  1179. static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
  1180. struct sk_buff_head *inputq,
  1181. struct sk_buff **reasm_skb)
  1182. {
  1183. struct tipc_msg *hdr = buf_msg(skb);
  1184. struct sk_buff *iskb;
  1185. struct sk_buff_head tmpq;
  1186. int usr = msg_user(hdr);
  1187. int pos = 0;
  1188. if (usr == MSG_BUNDLER) {
  1189. skb_queue_head_init(&tmpq);
  1190. l->stats.recv_bundles++;
  1191. l->stats.recv_bundled += msg_msgcnt(hdr);
  1192. while (tipc_msg_extract(skb, &iskb, &pos))
  1193. tipc_data_input(l, iskb, &tmpq);
  1194. tipc_skb_queue_splice_tail(&tmpq, inputq);
  1195. return 0;
  1196. } else if (usr == MSG_FRAGMENTER) {
  1197. l->stats.recv_fragments++;
  1198. if (tipc_buf_append(reasm_skb, &skb)) {
  1199. l->stats.recv_fragmented++;
  1200. tipc_data_input(l, skb, inputq);
  1201. } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) {
  1202. pr_warn_ratelimited("Unable to build fragment list\n");
  1203. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1204. }
  1205. return 0;
  1206. } else if (usr == BCAST_PROTOCOL) {
  1207. tipc_bcast_lock(l->net);
  1208. tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
  1209. tipc_bcast_unlock(l->net);
  1210. }
  1211. kfree_skb(skb);
  1212. return 0;
  1213. }
  1214. /* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the
  1215. * inner message along with the ones in the old link's
  1216. * deferdq
  1217. * @l: tunnel link
  1218. * @skb: TUNNEL_PROTOCOL message
  1219. * @inputq: queue to put messages ready for delivery
  1220. */
  1221. static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
  1222. struct sk_buff_head *inputq)
  1223. {
  1224. struct sk_buff **reasm_skb = &l->failover_reasm_skb;
  1225. struct sk_buff **reasm_tnlmsg = &l->reasm_tnlmsg;
  1226. struct sk_buff_head *fdefq = &l->failover_deferdq;
  1227. struct tipc_msg *hdr = buf_msg(skb);
  1228. struct sk_buff *iskb;
  1229. int ipos = 0;
  1230. int rc = 0;
  1231. u16 seqno;
  1232. if (msg_type(hdr) == SYNCH_MSG) {
  1233. kfree_skb(skb);
  1234. return 0;
  1235. }
  1236. /* Not a fragment? */
  1237. if (likely(!msg_nof_fragms(hdr))) {
  1238. if (unlikely(!tipc_msg_extract(skb, &iskb, &ipos))) {
  1239. pr_warn_ratelimited("Unable to extract msg, defq: %d\n",
  1240. skb_queue_len(fdefq));
  1241. return 0;
  1242. }
  1243. kfree_skb(skb);
  1244. } else {
  1245. /* Set fragment type for buf_append */
  1246. if (msg_fragm_no(hdr) == 1)
  1247. msg_set_type(hdr, FIRST_FRAGMENT);
  1248. else if (msg_fragm_no(hdr) < msg_nof_fragms(hdr))
  1249. msg_set_type(hdr, FRAGMENT);
  1250. else
  1251. msg_set_type(hdr, LAST_FRAGMENT);
  1252. if (!tipc_buf_append(reasm_tnlmsg, &skb)) {
  1253. /* Successful but non-complete reassembly? */
  1254. if (*reasm_tnlmsg || link_is_bc_rcvlink(l))
  1255. return 0;
  1256. pr_warn_ratelimited("Unable to reassemble tunnel msg\n");
  1257. return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1258. }
  1259. iskb = skb;
  1260. }
  1261. do {
  1262. seqno = buf_seqno(iskb);
  1263. if (unlikely(less(seqno, l->drop_point))) {
  1264. kfree_skb(iskb);
  1265. continue;
  1266. }
  1267. if (unlikely(seqno != l->drop_point)) {
  1268. __tipc_skb_queue_sorted(fdefq, seqno, iskb);
  1269. continue;
  1270. }
  1271. l->drop_point++;
  1272. if (!tipc_data_input(l, iskb, inputq))
  1273. rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
  1274. if (unlikely(rc))
  1275. break;
  1276. } while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
  1277. return rc;
  1278. }
  1279. static int tipc_link_release_pkts(struct tipc_link *l, u16 acked)
  1280. {
  1281. int released = 0;
  1282. struct sk_buff *skb, *tmp;
  1283. skb_queue_walk_safe(&l->transmq, skb, tmp) {
  1284. if (more(buf_seqno(skb), acked))
  1285. break;
  1286. __skb_unlink(skb, &l->transmq);
  1287. kfree_skb(skb);
  1288. released++;
  1289. }
  1290. return released;
  1291. }
  1292. /* tipc_build_gap_ack_blks - build Gap ACK blocks
  1293. * @l: tipc link that data have come with gaps in sequence if any
  1294. * @data: data buffer to store the Gap ACK blocks after built
  1295. *
  1296. * returns the actual allocated memory size
  1297. */
  1298. static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data, u16 gap)
  1299. {
  1300. struct sk_buff *skb = skb_peek(&l->deferdq);
  1301. struct tipc_gap_ack_blks *ga = data;
  1302. u16 len, expect, seqno = 0;
  1303. u8 n = 0;
  1304. if (!skb || !gap)
  1305. goto exit;
  1306. expect = buf_seqno(skb);
  1307. skb_queue_walk(&l->deferdq, skb) {
  1308. seqno = buf_seqno(skb);
  1309. if (unlikely(more(seqno, expect))) {
  1310. ga->gacks[n].ack = htons(expect - 1);
  1311. ga->gacks[n].gap = htons(seqno - expect);
  1312. if (++n >= MAX_GAP_ACK_BLKS) {
  1313. pr_info_ratelimited("Too few Gap ACK blocks!\n");
  1314. goto exit;
  1315. }
  1316. } else if (unlikely(less(seqno, expect))) {
  1317. pr_warn("Unexpected skb in deferdq!\n");
  1318. continue;
  1319. }
  1320. expect = seqno + 1;
  1321. }
  1322. /* last block */
  1323. ga->gacks[n].ack = htons(seqno);
  1324. ga->gacks[n].gap = 0;
  1325. n++;
  1326. exit:
  1327. len = tipc_gap_ack_blks_sz(n);
  1328. ga->len = htons(len);
  1329. ga->gack_cnt = n;
  1330. return len;
  1331. }
  1332. /* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing
  1333. * acked packets, also doing retransmissions if
  1334. * gaps found
  1335. * @l: tipc link with transmq queue to be advanced
  1336. * @acked: seqno of last packet acked by peer without any gaps before
  1337. * @gap: # of gap packets
  1338. * @ga: buffer pointer to Gap ACK blocks from peer
  1339. * @xmitq: queue for accumulating the retransmitted packets if any
  1340. *
  1341. * In case of a repeated retransmit failures, the call will return shortly
  1342. * with a returned code (e.g. TIPC_LINK_DOWN_EVT)
  1343. */
  1344. static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
  1345. struct tipc_gap_ack_blks *ga,
  1346. struct sk_buff_head *xmitq)
  1347. {
  1348. struct sk_buff *skb, *_skb, *tmp;
  1349. struct tipc_msg *hdr;
  1350. u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
  1351. bool retransmitted = false;
  1352. u16 ack = l->rcv_nxt - 1;
  1353. bool passed = false;
  1354. u16 released = 0;
  1355. u16 seqno, n = 0;
  1356. int rc = 0;
  1357. skb_queue_walk_safe(&l->transmq, skb, tmp) {
  1358. seqno = buf_seqno(skb);
  1359. next_gap_ack:
  1360. if (less_eq(seqno, acked)) {
  1361. /* release skb */
  1362. __skb_unlink(skb, &l->transmq);
  1363. kfree_skb(skb);
  1364. released++;
  1365. } else if (less_eq(seqno, acked + gap)) {
  1366. /* First, check if repeated retrans failures occurs? */
  1367. if (!passed && link_retransmit_failure(l, l, &rc))
  1368. return rc;
  1369. passed = true;
  1370. /* retransmit skb if unrestricted*/
  1371. if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
  1372. continue;
  1373. TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME;
  1374. _skb = pskb_copy(skb, GFP_ATOMIC);
  1375. if (!_skb)
  1376. continue;
  1377. hdr = buf_msg(_skb);
  1378. msg_set_ack(hdr, ack);
  1379. msg_set_bcast_ack(hdr, bc_ack);
  1380. _skb->priority = TC_PRIO_CONTROL;
  1381. __skb_queue_tail(xmitq, _skb);
  1382. l->stats.retransmitted++;
  1383. retransmitted = true;
  1384. /* Increase actual retrans counter & mark first time */
  1385. if (!TIPC_SKB_CB(skb)->retr_cnt++)
  1386. TIPC_SKB_CB(skb)->retr_stamp = jiffies;
  1387. } else {
  1388. /* retry with Gap ACK blocks if any */
  1389. if (!ga || n >= ga->gack_cnt)
  1390. break;
  1391. acked = ntohs(ga->gacks[n].ack);
  1392. gap = ntohs(ga->gacks[n].gap);
  1393. n++;
  1394. goto next_gap_ack;
  1395. }
  1396. }
  1397. if (released || retransmitted)
  1398. tipc_link_update_cwin(l, released, retransmitted);
  1399. if (released)
  1400. tipc_link_advance_backlog(l, xmitq);
  1401. return 0;
  1402. }
  1403. /* tipc_link_build_state_msg: prepare link state message for transmission
  1404. *
  1405. * Note that sending of broadcast ack is coordinated among nodes, to reduce
  1406. * risk of ack storms towards the sender
  1407. */
  1408. int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
  1409. {
  1410. if (!l)
  1411. return 0;
  1412. /* Broadcast ACK must be sent via a unicast link => defer to caller */
  1413. if (link_is_bc_rcvlink(l)) {
  1414. if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
  1415. return 0;
  1416. l->rcv_unacked = 0;
  1417. /* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */
  1418. l->snd_nxt = l->rcv_nxt;
  1419. return TIPC_LINK_SND_STATE;
  1420. }
  1421. /* Unicast ACK */
  1422. l->rcv_unacked = 0;
  1423. l->stats.sent_acks++;
  1424. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
  1425. return 0;
  1426. }
  1427. /* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message
  1428. */
  1429. void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
  1430. {
  1431. int mtyp = RESET_MSG;
  1432. struct sk_buff *skb;
  1433. if (l->state == LINK_ESTABLISHING)
  1434. mtyp = ACTIVATE_MSG;
  1435. tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq);
  1436. /* Inform peer that this endpoint is going down if applicable */
  1437. skb = skb_peek_tail(xmitq);
  1438. if (skb && (l->state == LINK_RESET))
  1439. msg_set_peer_stopping(buf_msg(skb), 1);
  1440. }
  1441. /* tipc_link_build_nack_msg: prepare link nack message for transmission
  1442. * Note that sending of broadcast NACK is coordinated among nodes, to
  1443. * reduce the risk of NACK storms towards the sender
  1444. */
  1445. static int tipc_link_build_nack_msg(struct tipc_link *l,
  1446. struct sk_buff_head *xmitq)
  1447. {
  1448. u32 def_cnt = ++l->stats.deferred_recv;
  1449. struct sk_buff_head *dfq = &l->deferdq;
  1450. u32 defq_len = skb_queue_len(dfq);
  1451. int match1, match2;
  1452. if (link_is_bc_rcvlink(l)) {
  1453. match1 = def_cnt & 0xf;
  1454. match2 = tipc_own_addr(l->net) & 0xf;
  1455. if (match1 == match2)
  1456. return TIPC_LINK_SND_STATE;
  1457. return 0;
  1458. }
  1459. if (defq_len >= 3 && !((defq_len - 3) % 16)) {
  1460. u16 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
  1461. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0,
  1462. rcvgap, 0, 0, xmitq);
  1463. }
  1464. return 0;
  1465. }
  1466. /* tipc_link_rcv - process TIPC packets/messages arriving from off-node
  1467. * @l: the link that should handle the message
  1468. * @skb: TIPC packet
  1469. * @xmitq: queue to place packets to be sent after this call
  1470. */
  1471. int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
  1472. struct sk_buff_head *xmitq)
  1473. {
  1474. struct sk_buff_head *defq = &l->deferdq;
  1475. struct tipc_msg *hdr = buf_msg(skb);
  1476. u16 seqno, rcv_nxt, win_lim;
  1477. int released = 0;
  1478. int rc = 0;
  1479. /* Verify and update link state */
  1480. if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
  1481. return tipc_link_proto_rcv(l, skb, xmitq);
  1482. /* Don't send probe at next timeout expiration */
  1483. l->silent_intv_cnt = 0;
  1484. do {
  1485. hdr = buf_msg(skb);
  1486. seqno = msg_seqno(hdr);
  1487. rcv_nxt = l->rcv_nxt;
  1488. win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
  1489. if (unlikely(!link_is_up(l))) {
  1490. if (l->state == LINK_ESTABLISHING)
  1491. rc = TIPC_LINK_UP_EVT;
  1492. kfree_skb(skb);
  1493. break;
  1494. }
  1495. /* Drop if outside receive window */
  1496. if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
  1497. l->stats.duplicates++;
  1498. kfree_skb(skb);
  1499. break;
  1500. }
  1501. released += tipc_link_release_pkts(l, msg_ack(hdr));
  1502. /* Defer delivery if sequence gap */
  1503. if (unlikely(seqno != rcv_nxt)) {
  1504. __tipc_skb_queue_sorted(defq, seqno, skb);
  1505. rc |= tipc_link_build_nack_msg(l, xmitq);
  1506. break;
  1507. }
  1508. /* Deliver packet */
  1509. l->rcv_nxt++;
  1510. l->stats.recv_pkts++;
  1511. if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL))
  1512. rc |= tipc_link_tnl_rcv(l, skb, l->inputq);
  1513. else if (!tipc_data_input(l, skb, l->inputq))
  1514. rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf);
  1515. if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
  1516. rc |= tipc_link_build_state_msg(l, xmitq);
  1517. if (unlikely(rc & ~TIPC_LINK_SND_STATE))
  1518. break;
  1519. } while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt)));
  1520. /* Forward queues and wake up waiting users */
  1521. if (released) {
  1522. tipc_link_update_cwin(l, released, 0);
  1523. tipc_link_advance_backlog(l, xmitq);
  1524. if (unlikely(!skb_queue_empty(&l->wakeupq)))
  1525. link_prepare_wakeup(l);
  1526. }
  1527. return rc;
  1528. }
  1529. static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
  1530. bool probe_reply, u16 rcvgap,
  1531. int tolerance, int priority,
  1532. struct sk_buff_head *xmitq)
  1533. {
  1534. struct tipc_link *bcl = l->bc_rcvlink;
  1535. struct sk_buff *skb;
  1536. struct tipc_msg *hdr;
  1537. struct sk_buff_head *dfq = &l->deferdq;
  1538. bool node_up = link_is_up(bcl);
  1539. struct tipc_mon_state *mstate = &l->mon_state;
  1540. int dlen = 0;
  1541. void *data;
  1542. u16 glen = 0;
  1543. /* Don't send protocol message during reset or link failover */
  1544. if (tipc_link_is_blocked(l))
  1545. return;
  1546. if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
  1547. return;
  1548. if ((probe || probe_reply) && !skb_queue_empty(dfq))
  1549. rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
  1550. skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
  1551. tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ,
  1552. l->addr, tipc_own_addr(l->net), 0, 0, 0);
  1553. if (!skb)
  1554. return;
  1555. hdr = buf_msg(skb);
  1556. data = msg_data(hdr);
  1557. msg_set_session(hdr, l->session);
  1558. msg_set_bearer_id(hdr, l->bearer_id);
  1559. msg_set_net_plane(hdr, l->net_plane);
  1560. msg_set_next_sent(hdr, l->snd_nxt);
  1561. msg_set_ack(hdr, l->rcv_nxt - 1);
  1562. msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
  1563. msg_set_bc_ack_invalid(hdr, !node_up);
  1564. msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
  1565. msg_set_link_tolerance(hdr, tolerance);
  1566. msg_set_linkprio(hdr, priority);
  1567. msg_set_redundant_link(hdr, node_up);
  1568. msg_set_seq_gap(hdr, 0);
  1569. msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
  1570. if (mtyp == STATE_MSG) {
  1571. if (l->peer_caps & TIPC_LINK_PROTO_SEQNO)
  1572. msg_set_seqno(hdr, l->snd_nxt_state++);
  1573. msg_set_seq_gap(hdr, rcvgap);
  1574. msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
  1575. msg_set_probe(hdr, probe);
  1576. msg_set_is_keepalive(hdr, probe || probe_reply);
  1577. if (l->peer_caps & TIPC_GAP_ACK_BLOCK)
  1578. glen = tipc_build_gap_ack_blks(l, data, rcvgap);
  1579. tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id);
  1580. msg_set_size(hdr, INT_H_SIZE + glen + dlen);
  1581. skb_trim(skb, INT_H_SIZE + glen + dlen);
  1582. l->stats.sent_states++;
  1583. l->rcv_unacked = 0;
  1584. } else {
  1585. /* RESET_MSG or ACTIVATE_MSG */
  1586. if (mtyp == ACTIVATE_MSG) {
  1587. msg_set_dest_session_valid(hdr, 1);
  1588. msg_set_dest_session(hdr, l->peer_session);
  1589. }
  1590. msg_set_max_pkt(hdr, l->advertised_mtu);
  1591. strcpy(data, l->if_name);
  1592. msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
  1593. skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
  1594. }
  1595. if (probe)
  1596. l->stats.sent_probes++;
  1597. if (rcvgap)
  1598. l->stats.sent_nacks++;
  1599. skb->priority = TC_PRIO_CONTROL;
  1600. __skb_queue_tail(xmitq, skb);
  1601. trace_tipc_proto_build(skb, false, l->name);
  1602. }
  1603. void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
  1604. struct sk_buff_head *xmitq)
  1605. {
  1606. u32 onode = tipc_own_addr(l->net);
  1607. struct tipc_msg *hdr, *ihdr;
  1608. struct sk_buff_head tnlq;
  1609. struct sk_buff *skb;
  1610. u32 dnode = l->addr;
  1611. __skb_queue_head_init(&tnlq);
  1612. skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG,
  1613. INT_H_SIZE, BASIC_H_SIZE,
  1614. dnode, onode, 0, 0, 0);
  1615. if (!skb) {
  1616. pr_warn("%sunable to create tunnel packet\n", link_co_err);
  1617. return;
  1618. }
  1619. hdr = buf_msg(skb);
  1620. msg_set_msgcnt(hdr, 1);
  1621. msg_set_bearer_id(hdr, l->peer_bearer_id);
  1622. ihdr = (struct tipc_msg *)msg_data(hdr);
  1623. tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
  1624. BASIC_H_SIZE, dnode);
  1625. msg_set_errcode(ihdr, TIPC_ERR_NO_PORT);
  1626. __skb_queue_tail(&tnlq, skb);
  1627. tipc_link_xmit(l, &tnlq, xmitq);
  1628. }
  1629. /* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets
  1630. * with contents of the link's transmit and backlog queues.
  1631. */
  1632. void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
  1633. int mtyp, struct sk_buff_head *xmitq)
  1634. {
  1635. struct sk_buff_head *fdefq = &tnl->failover_deferdq;
  1636. struct sk_buff *skb, *tnlskb;
  1637. struct tipc_msg *hdr, tnlhdr;
  1638. struct sk_buff_head *queue = &l->transmq;
  1639. struct sk_buff_head tmpxq, tnlq, frags;
  1640. u16 pktlen, pktcnt, seqno = l->snd_nxt;
  1641. bool pktcnt_need_update = false;
  1642. u16 syncpt;
  1643. int rc;
  1644. if (!tnl)
  1645. return;
  1646. __skb_queue_head_init(&tnlq);
  1647. /* Link Synching:
  1648. * From now on, send only one single ("dummy") SYNCH message
  1649. * to peer. The SYNCH message does not contain any data, just
  1650. * a header conveying the synch point to the peer.
  1651. */
  1652. if (mtyp == SYNCH_MSG && (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
  1653. tnlskb = tipc_msg_create(TUNNEL_PROTOCOL, SYNCH_MSG,
  1654. INT_H_SIZE, 0, l->addr,
  1655. tipc_own_addr(l->net),
  1656. 0, 0, 0);
  1657. if (!tnlskb) {
  1658. pr_warn("%sunable to create dummy SYNCH_MSG\n",
  1659. link_co_err);
  1660. return;
  1661. }
  1662. hdr = buf_msg(tnlskb);
  1663. syncpt = l->snd_nxt + skb_queue_len(&l->backlogq) - 1;
  1664. msg_set_syncpt(hdr, syncpt);
  1665. msg_set_bearer_id(hdr, l->peer_bearer_id);
  1666. __skb_queue_tail(&tnlq, tnlskb);
  1667. tipc_link_xmit(tnl, &tnlq, xmitq);
  1668. return;
  1669. }
  1670. __skb_queue_head_init(&tmpxq);
  1671. __skb_queue_head_init(&frags);
  1672. /* At least one packet required for safe algorithm => add dummy */
  1673. skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
  1674. BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net),
  1675. 0, 0, TIPC_ERR_NO_PORT);
  1676. if (!skb) {
  1677. pr_warn("%sunable to create tunnel packet\n", link_co_err);
  1678. return;
  1679. }
  1680. __skb_queue_tail(&tnlq, skb);
  1681. tipc_link_xmit(l, &tnlq, &tmpxq);
  1682. __skb_queue_purge(&tmpxq);
  1683. /* Initialize reusable tunnel packet header */
  1684. tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
  1685. mtyp, INT_H_SIZE, l->addr);
  1686. if (mtyp == SYNCH_MSG)
  1687. pktcnt = l->snd_nxt - buf_seqno(skb_peek(&l->transmq));
  1688. else
  1689. pktcnt = skb_queue_len(&l->transmq);
  1690. pktcnt += skb_queue_len(&l->backlogq);
  1691. msg_set_msgcnt(&tnlhdr, pktcnt);
  1692. msg_set_bearer_id(&tnlhdr, l->peer_bearer_id);
  1693. tnl:
  1694. /* Wrap each packet into a tunnel packet */
  1695. skb_queue_walk(queue, skb) {
  1696. hdr = buf_msg(skb);
  1697. if (queue == &l->backlogq)
  1698. msg_set_seqno(hdr, seqno++);
  1699. pktlen = msg_size(hdr);
  1700. /* Tunnel link MTU is not large enough? This could be
  1701. * due to:
  1702. * 1) Link MTU has just changed or set differently;
  1703. * 2) Or FAILOVER on the top of a SYNCH message
  1704. *
  1705. * The 2nd case should not happen if peer supports
  1706. * TIPC_TUNNEL_ENHANCED
  1707. */
  1708. if (pktlen > tnl->mtu - INT_H_SIZE) {
  1709. if (mtyp == FAILOVER_MSG &&
  1710. (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
  1711. rc = tipc_msg_fragment(skb, &tnlhdr, tnl->mtu,
  1712. &frags);
  1713. if (rc) {
  1714. pr_warn("%sunable to frag msg: rc %d\n",
  1715. link_co_err, rc);
  1716. return;
  1717. }
  1718. pktcnt += skb_queue_len(&frags) - 1;
  1719. pktcnt_need_update = true;
  1720. skb_queue_splice_tail_init(&frags, &tnlq);
  1721. continue;
  1722. }
  1723. /* Unluckily, peer doesn't have TIPC_TUNNEL_ENHANCED
  1724. * => Just warn it and return!
  1725. */
  1726. pr_warn_ratelimited("%stoo large msg <%d, %d>: %d!\n",
  1727. link_co_err, msg_user(hdr),
  1728. msg_type(hdr), msg_size(hdr));
  1729. return;
  1730. }
  1731. msg_set_size(&tnlhdr, pktlen + INT_H_SIZE);
  1732. tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC);
  1733. if (!tnlskb) {
  1734. pr_warn("%sunable to send packet\n", link_co_err);
  1735. return;
  1736. }
  1737. skb_copy_to_linear_data(tnlskb, &tnlhdr, INT_H_SIZE);
  1738. skb_copy_to_linear_data_offset(tnlskb, INT_H_SIZE, hdr, pktlen);
  1739. __skb_queue_tail(&tnlq, tnlskb);
  1740. }
  1741. if (queue != &l->backlogq) {
  1742. queue = &l->backlogq;
  1743. goto tnl;
  1744. }
  1745. if (pktcnt_need_update)
  1746. skb_queue_walk(&tnlq, skb) {
  1747. hdr = buf_msg(skb);
  1748. msg_set_msgcnt(hdr, pktcnt);
  1749. }
  1750. tipc_link_xmit(tnl, &tnlq, xmitq);
  1751. if (mtyp == FAILOVER_MSG) {
  1752. tnl->drop_point = l->rcv_nxt;
  1753. tnl->failover_reasm_skb = l->reasm_buf;
  1754. l->reasm_buf = NULL;
  1755. /* Failover the link's deferdq */
  1756. if (unlikely(!skb_queue_empty(fdefq))) {
  1757. pr_warn("Link failover deferdq not empty: %d!\n",
  1758. skb_queue_len(fdefq));
  1759. __skb_queue_purge(fdefq);
  1760. }
  1761. skb_queue_splice_init(&l->deferdq, fdefq);
  1762. }
  1763. }
  1764. /**
  1765. * tipc_link_failover_prepare() - prepare tnl for link failover
  1766. *
  1767. * This is a special version of the precursor - tipc_link_tnl_prepare(),
  1768. * see the tipc_node_link_failover() for details
  1769. *
  1770. * @l: failover link
  1771. * @tnl: tunnel link
  1772. * @xmitq: queue for messages to be xmited
  1773. */
  1774. void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl,
  1775. struct sk_buff_head *xmitq)
  1776. {
  1777. struct sk_buff_head *fdefq = &tnl->failover_deferdq;
  1778. tipc_link_create_dummy_tnl_msg(tnl, xmitq);
  1779. /* This failover link endpoint was never established before,
  1780. * so it has not received anything from peer.
  1781. * Otherwise, it must be a normal failover situation or the
  1782. * node has entered SELF_DOWN_PEER_LEAVING and both peer nodes
  1783. * would have to start over from scratch instead.
  1784. */
  1785. tnl->drop_point = 1;
  1786. tnl->failover_reasm_skb = NULL;
  1787. /* Initiate the link's failover deferdq */
  1788. if (unlikely(!skb_queue_empty(fdefq))) {
  1789. pr_warn("Link failover deferdq not empty: %d!\n",
  1790. skb_queue_len(fdefq));
  1791. __skb_queue_purge(fdefq);
  1792. }
  1793. }
  1794. /* tipc_link_validate_msg(): validate message against current link state
  1795. * Returns true if message should be accepted, otherwise false
  1796. */
  1797. bool tipc_link_validate_msg(struct tipc_link *l, struct tipc_msg *hdr)
  1798. {
  1799. u16 curr_session = l->peer_session;
  1800. u16 session = msg_session(hdr);
  1801. int mtyp = msg_type(hdr);
  1802. if (msg_user(hdr) != LINK_PROTOCOL)
  1803. return true;
  1804. switch (mtyp) {
  1805. case RESET_MSG:
  1806. if (!l->in_session)
  1807. return true;
  1808. /* Accept only RESET with new session number */
  1809. return more(session, curr_session);
  1810. case ACTIVATE_MSG:
  1811. if (!l->in_session)
  1812. return true;
  1813. /* Accept only ACTIVATE with new or current session number */
  1814. return !less(session, curr_session);
  1815. case STATE_MSG:
  1816. /* Accept only STATE with current session number */
  1817. if (!l->in_session)
  1818. return false;
  1819. if (session != curr_session)
  1820. return false;
  1821. /* Extra sanity check */
  1822. if (!link_is_up(l) && msg_ack(hdr))
  1823. return false;
  1824. if (!(l->peer_caps & TIPC_LINK_PROTO_SEQNO))
  1825. return true;
  1826. /* Accept only STATE with new sequence number */
  1827. return !less(msg_seqno(hdr), l->rcv_nxt_state);
  1828. default:
  1829. return false;
  1830. }
  1831. }
  1832. /* tipc_link_proto_rcv(): receive link level protocol message :
  1833. * Note that network plane id propagates through the network, and may
  1834. * change at any time. The node with lowest numerical id determines
  1835. * network plane
  1836. */
  1837. static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
  1838. struct sk_buff_head *xmitq)
  1839. {
  1840. struct tipc_msg *hdr = buf_msg(skb);
  1841. struct tipc_gap_ack_blks *ga = NULL;
  1842. u16 rcvgap = 0;
  1843. u16 ack = msg_ack(hdr);
  1844. u16 gap = msg_seq_gap(hdr);
  1845. u16 peers_snd_nxt = msg_next_sent(hdr);
  1846. u16 peers_tol = msg_link_tolerance(hdr);
  1847. u16 peers_prio = msg_linkprio(hdr);
  1848. u16 rcv_nxt = l->rcv_nxt;
  1849. u16 dlen = msg_data_sz(hdr);
  1850. int mtyp = msg_type(hdr);
  1851. bool reply = msg_probe(hdr);
  1852. u16 glen = 0;
  1853. void *data;
  1854. char *if_name;
  1855. int rc = 0;
  1856. trace_tipc_proto_rcv(skb, false, l->name);
  1857. if (tipc_link_is_blocked(l) || !xmitq)
  1858. goto exit;
  1859. if (tipc_own_addr(l->net) > msg_prevnode(hdr))
  1860. l->net_plane = msg_net_plane(hdr);
  1861. skb_linearize(skb);
  1862. hdr = buf_msg(skb);
  1863. data = msg_data(hdr);
  1864. if (!tipc_link_validate_msg(l, hdr)) {
  1865. trace_tipc_skb_dump(skb, false, "PROTO invalid (1)!");
  1866. trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (1)!");
  1867. goto exit;
  1868. }
  1869. switch (mtyp) {
  1870. case RESET_MSG:
  1871. case ACTIVATE_MSG:
  1872. /* Complete own link name with peer's interface name */
  1873. if_name = strrchr(l->name, ':') + 1;
  1874. if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME)
  1875. break;
  1876. if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME)
  1877. break;
  1878. strncpy(if_name, data, TIPC_MAX_IF_NAME);
  1879. /* Update own tolerance if peer indicates a non-zero value */
  1880. if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
  1881. l->tolerance = peers_tol;
  1882. l->bc_rcvlink->tolerance = peers_tol;
  1883. }
  1884. /* Update own priority if peer's priority is higher */
  1885. if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI))
  1886. l->priority = peers_prio;
  1887. /* If peer is going down we want full re-establish cycle */
  1888. if (msg_peer_stopping(hdr)) {
  1889. rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1890. break;
  1891. }
  1892. /* If this endpoint was re-created while peer was ESTABLISHING
  1893. * it doesn't know current session number. Force re-synch.
  1894. */
  1895. if (mtyp == ACTIVATE_MSG && msg_dest_session_valid(hdr) &&
  1896. l->session != msg_dest_session(hdr)) {
  1897. if (less(l->session, msg_dest_session(hdr)))
  1898. l->session = msg_dest_session(hdr) + 1;
  1899. break;
  1900. }
  1901. /* ACTIVATE_MSG serves as PEER_RESET if link is already down */
  1902. if (mtyp == RESET_MSG || !link_is_up(l))
  1903. rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
  1904. /* ACTIVATE_MSG takes up link if it was already locally reset */
  1905. if (mtyp == ACTIVATE_MSG && l->state == LINK_ESTABLISHING)
  1906. rc = TIPC_LINK_UP_EVT;
  1907. l->peer_session = msg_session(hdr);
  1908. l->in_session = true;
  1909. l->peer_bearer_id = msg_bearer_id(hdr);
  1910. if (l->mtu > msg_max_pkt(hdr))
  1911. l->mtu = msg_max_pkt(hdr);
  1912. break;
  1913. case STATE_MSG:
  1914. l->rcv_nxt_state = msg_seqno(hdr) + 1;
  1915. /* Update own tolerance if peer indicates a non-zero value */
  1916. if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
  1917. l->tolerance = peers_tol;
  1918. l->bc_rcvlink->tolerance = peers_tol;
  1919. }
  1920. /* Update own prio if peer indicates a different value */
  1921. if ((peers_prio != l->priority) &&
  1922. in_range(peers_prio, 1, TIPC_MAX_LINK_PRI)) {
  1923. l->priority = peers_prio;
  1924. rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
  1925. }
  1926. l->silent_intv_cnt = 0;
  1927. l->stats.recv_states++;
  1928. if (msg_probe(hdr))
  1929. l->stats.recv_probes++;
  1930. if (!link_is_up(l)) {
  1931. if (l->state == LINK_ESTABLISHING)
  1932. rc = TIPC_LINK_UP_EVT;
  1933. break;
  1934. }
  1935. /* Receive Gap ACK blocks from peer if any */
  1936. if (l->peer_caps & TIPC_GAP_ACK_BLOCK) {
  1937. ga = (struct tipc_gap_ack_blks *)data;
  1938. glen = ntohs(ga->len);
  1939. /* sanity check: if failed, ignore Gap ACK blocks */
  1940. if (glen != tipc_gap_ack_blks_sz(ga->gack_cnt))
  1941. ga = NULL;
  1942. }
  1943. tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr,
  1944. &l->mon_state, l->bearer_id);
  1945. /* Send NACK if peer has sent pkts we haven't received yet */
  1946. if ((reply || msg_is_keepalive(hdr)) &&
  1947. more(peers_snd_nxt, rcv_nxt) &&
  1948. !tipc_link_is_synching(l) &&
  1949. skb_queue_empty(&l->deferdq))
  1950. rcvgap = peers_snd_nxt - l->rcv_nxt;
  1951. if (rcvgap || reply)
  1952. tipc_link_build_proto_msg(l, STATE_MSG, 0, reply,
  1953. rcvgap, 0, 0, xmitq);
  1954. rc |= tipc_link_advance_transmq(l, ack, gap, ga, xmitq);
  1955. if (gap)
  1956. l->stats.recv_nacks++;
  1957. if (unlikely(!skb_queue_empty(&l->wakeupq)))
  1958. link_prepare_wakeup(l);
  1959. }
  1960. exit:
  1961. kfree_skb(skb);
  1962. return rc;
  1963. }
  1964. /* tipc_link_build_bc_proto_msg() - create broadcast protocol message
  1965. */
  1966. static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
  1967. u16 peers_snd_nxt,
  1968. struct sk_buff_head *xmitq)
  1969. {
  1970. struct sk_buff *skb;
  1971. struct tipc_msg *hdr;
  1972. struct sk_buff *dfrd_skb = skb_peek(&l->deferdq);
  1973. u16 ack = l->rcv_nxt - 1;
  1974. u16 gap_to = peers_snd_nxt - 1;
  1975. skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE,
  1976. 0, l->addr, tipc_own_addr(l->net), 0, 0, 0);
  1977. if (!skb)
  1978. return false;
  1979. hdr = buf_msg(skb);
  1980. msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
  1981. msg_set_bcast_ack(hdr, ack);
  1982. msg_set_bcgap_after(hdr, ack);
  1983. if (dfrd_skb)
  1984. gap_to = buf_seqno(dfrd_skb) - 1;
  1985. msg_set_bcgap_to(hdr, gap_to);
  1986. msg_set_non_seq(hdr, bcast);
  1987. __skb_queue_tail(xmitq, skb);
  1988. return true;
  1989. }
  1990. /* tipc_link_build_bc_init_msg() - synchronize broadcast link endpoints.
  1991. *
  1992. * Give a newly added peer node the sequence number where it should
  1993. * start receiving and acking broadcast packets.
  1994. */
  1995. static void tipc_link_build_bc_init_msg(struct tipc_link *l,
  1996. struct sk_buff_head *xmitq)
  1997. {
  1998. struct sk_buff_head list;
  1999. __skb_queue_head_init(&list);
  2000. if (!tipc_link_build_bc_proto_msg(l->bc_rcvlink, false, 0, &list))
  2001. return;
  2002. msg_set_bc_ack_invalid(buf_msg(skb_peek(&list)), true);
  2003. tipc_link_xmit(l, &list, xmitq);
  2004. }
  2005. /* tipc_link_bc_init_rcv - receive initial broadcast synch data from peer
  2006. */
  2007. void tipc_link_bc_init_rcv(struct tipc_link *l, struct tipc_msg *hdr)
  2008. {
  2009. int mtyp = msg_type(hdr);
  2010. u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
  2011. if (link_is_up(l))
  2012. return;
  2013. if (msg_user(hdr) == BCAST_PROTOCOL) {
  2014. l->rcv_nxt = peers_snd_nxt;
  2015. l->state = LINK_ESTABLISHED;
  2016. return;
  2017. }
  2018. if (l->peer_caps & TIPC_BCAST_SYNCH)
  2019. return;
  2020. if (msg_peer_node_is_up(hdr))
  2021. return;
  2022. /* Compatibility: accept older, less safe initial synch data */
  2023. if ((mtyp == RESET_MSG) || (mtyp == ACTIVATE_MSG))
  2024. l->rcv_nxt = peers_snd_nxt;
  2025. }
  2026. /* tipc_link_bc_sync_rcv - update rcv link according to peer's send state
  2027. */
  2028. int tipc_link_bc_sync_rcv(struct tipc_link *l, struct tipc_msg *hdr,
  2029. struct sk_buff_head *xmitq)
  2030. {
  2031. struct tipc_link *snd_l = l->bc_sndlink;
  2032. u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
  2033. u16 from = msg_bcast_ack(hdr) + 1;
  2034. u16 to = from + msg_bc_gap(hdr) - 1;
  2035. int rc = 0;
  2036. if (!link_is_up(l))
  2037. return rc;
  2038. if (!msg_peer_node_is_up(hdr))
  2039. return rc;
  2040. /* Open when peer ackowledges our bcast init msg (pkt #1) */
  2041. if (msg_ack(hdr))
  2042. l->bc_peer_is_up = true;
  2043. if (!l->bc_peer_is_up)
  2044. return rc;
  2045. l->stats.recv_nacks++;
  2046. /* Ignore if peers_snd_nxt goes beyond receive window */
  2047. if (more(peers_snd_nxt, l->rcv_nxt + l->window))
  2048. return rc;
  2049. rc = tipc_link_bc_retrans(snd_l, l, from, to, xmitq);
  2050. l->snd_nxt = peers_snd_nxt;
  2051. if (link_bc_rcv_gap(l))
  2052. rc |= TIPC_LINK_SND_STATE;
  2053. /* Return now if sender supports nack via STATE messages */
  2054. if (l->peer_caps & TIPC_BCAST_STATE_NACK)
  2055. return rc;
  2056. /* Otherwise, be backwards compatible */
  2057. if (!more(peers_snd_nxt, l->rcv_nxt)) {
  2058. l->nack_state = BC_NACK_SND_CONDITIONAL;
  2059. return 0;
  2060. }
  2061. /* Don't NACK if one was recently sent or peeked */
  2062. if (l->nack_state == BC_NACK_SND_SUPPRESS) {
  2063. l->nack_state = BC_NACK_SND_UNCONDITIONAL;
  2064. return 0;
  2065. }
  2066. /* Conditionally delay NACK sending until next synch rcv */
  2067. if (l->nack_state == BC_NACK_SND_CONDITIONAL) {
  2068. l->nack_state = BC_NACK_SND_UNCONDITIONAL;
  2069. if ((peers_snd_nxt - l->rcv_nxt) < TIPC_MIN_LINK_WIN)
  2070. return 0;
  2071. }
  2072. /* Send NACK now but suppress next one */
  2073. tipc_link_build_bc_proto_msg(l, true, peers_snd_nxt, xmitq);
  2074. l->nack_state = BC_NACK_SND_SUPPRESS;
  2075. return 0;
  2076. }
  2077. void tipc_link_bc_ack_rcv(struct tipc_link *l, u16 acked,
  2078. struct sk_buff_head *xmitq)
  2079. {
  2080. struct sk_buff *skb, *tmp;
  2081. struct tipc_link *snd_l = l->bc_sndlink;
  2082. if (!link_is_up(l) || !l->bc_peer_is_up)
  2083. return;
  2084. if (!more(acked, l->acked))
  2085. return;
  2086. trace_tipc_link_bc_ack(l, l->acked, acked, &snd_l->transmq);
  2087. /* Skip over packets peer has already acked */
  2088. skb_queue_walk(&snd_l->transmq, skb) {
  2089. if (more(buf_seqno(skb), l->acked))
  2090. break;
  2091. }
  2092. /* Update/release the packets peer is acking now */
  2093. skb_queue_walk_from_safe(&snd_l->transmq, skb, tmp) {
  2094. if (more(buf_seqno(skb), acked))
  2095. break;
  2096. if (!--TIPC_SKB_CB(skb)->ackers) {
  2097. __skb_unlink(skb, &snd_l->transmq);
  2098. kfree_skb(skb);
  2099. }
  2100. }
  2101. l->acked = acked;
  2102. tipc_link_advance_backlog(snd_l, xmitq);
  2103. if (unlikely(!skb_queue_empty(&snd_l->wakeupq)))
  2104. link_prepare_wakeup(snd_l);
  2105. }
  2106. /* tipc_link_bc_nack_rcv(): receive broadcast nack message
  2107. * This function is here for backwards compatibility, since
  2108. * no BCAST_PROTOCOL/STATE messages occur from TIPC v2.5.
  2109. */
  2110. int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
  2111. struct sk_buff_head *xmitq)
  2112. {
  2113. struct tipc_msg *hdr = buf_msg(skb);
  2114. u32 dnode = msg_destnode(hdr);
  2115. int mtyp = msg_type(hdr);
  2116. u16 acked = msg_bcast_ack(hdr);
  2117. u16 from = acked + 1;
  2118. u16 to = msg_bcgap_to(hdr);
  2119. u16 peers_snd_nxt = to + 1;
  2120. int rc = 0;
  2121. kfree_skb(skb);
  2122. if (!tipc_link_is_up(l) || !l->bc_peer_is_up)
  2123. return 0;
  2124. if (mtyp != STATE_MSG)
  2125. return 0;
  2126. if (dnode == tipc_own_addr(l->net)) {
  2127. tipc_link_bc_ack_rcv(l, acked, xmitq);
  2128. rc = tipc_link_bc_retrans(l->bc_sndlink, l, from, to, xmitq);
  2129. l->stats.recv_nacks++;
  2130. return rc;
  2131. }
  2132. /* Msg for other node => suppress own NACK at next sync if applicable */
  2133. if (more(peers_snd_nxt, l->rcv_nxt) && !less(l->rcv_nxt, from))
  2134. l->nack_state = BC_NACK_SND_SUPPRESS;
  2135. return 0;
  2136. }
  2137. void tipc_link_set_queue_limits(struct tipc_link *l, u32 min_win, u32 max_win)
  2138. {
  2139. int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE);
  2140. l->min_win = min_win;
  2141. l->ssthresh = max_win;
  2142. l->max_win = max_win;
  2143. l->window = min_win;
  2144. l->backlog[TIPC_LOW_IMPORTANCE].limit = min_win * 2;
  2145. l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = min_win * 4;
  2146. l->backlog[TIPC_HIGH_IMPORTANCE].limit = min_win * 6;
  2147. l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = min_win * 8;
  2148. l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
  2149. }
  2150. /**
  2151. * link_reset_stats - reset link statistics
  2152. * @l: pointer to link
  2153. */
  2154. void tipc_link_reset_stats(struct tipc_link *l)
  2155. {
  2156. memset(&l->stats, 0, sizeof(l->stats));
  2157. }
  2158. static void link_print(struct tipc_link *l, const char *str)
  2159. {
  2160. struct sk_buff *hskb = skb_peek(&l->transmq);
  2161. u16 head = hskb ? msg_seqno(buf_msg(hskb)) : l->snd_nxt - 1;
  2162. u16 tail = l->snd_nxt - 1;
  2163. pr_info("%s Link <%s> state %x\n", str, l->name, l->state);
  2164. pr_info("XMTQ: %u [%u-%u], BKLGQ: %u, SNDNX: %u, RCVNX: %u\n",
  2165. skb_queue_len(&l->transmq), head, tail,
  2166. skb_queue_len(&l->backlogq), l->snd_nxt, l->rcv_nxt);
  2167. }
  2168. /* Parse and validate nested (link) properties valid for media, bearer and link
  2169. */
  2170. int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
  2171. {
  2172. int err;
  2173. err = nla_parse_nested_deprecated(props, TIPC_NLA_PROP_MAX, prop,
  2174. tipc_nl_prop_policy, NULL);
  2175. if (err)
  2176. return err;
  2177. if (props[TIPC_NLA_PROP_PRIO]) {
  2178. u32 prio;
  2179. prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
  2180. if (prio > TIPC_MAX_LINK_PRI)
  2181. return -EINVAL;
  2182. }
  2183. if (props[TIPC_NLA_PROP_TOL]) {
  2184. u32 tol;
  2185. tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
  2186. if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
  2187. return -EINVAL;
  2188. }
  2189. if (props[TIPC_NLA_PROP_WIN]) {
  2190. u32 max_win;
  2191. max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
  2192. if (max_win < TIPC_DEF_LINK_WIN || max_win > TIPC_MAX_LINK_WIN)
  2193. return -EINVAL;
  2194. }
  2195. return 0;
  2196. }
  2197. static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
  2198. {
  2199. int i;
  2200. struct nlattr *stats;
  2201. struct nla_map {
  2202. u32 key;
  2203. u32 val;
  2204. };
  2205. struct nla_map map[] = {
  2206. {TIPC_NLA_STATS_RX_INFO, 0},
  2207. {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
  2208. {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
  2209. {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
  2210. {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
  2211. {TIPC_NLA_STATS_TX_INFO, 0},
  2212. {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
  2213. {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
  2214. {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
  2215. {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
  2216. {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
  2217. s->msg_length_counts : 1},
  2218. {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
  2219. {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
  2220. {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
  2221. {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
  2222. {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
  2223. {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
  2224. {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
  2225. {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
  2226. {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
  2227. {TIPC_NLA_STATS_RX_STATES, s->recv_states},
  2228. {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
  2229. {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
  2230. {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
  2231. {TIPC_NLA_STATS_TX_STATES, s->sent_states},
  2232. {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
  2233. {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
  2234. {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
  2235. {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
  2236. {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
  2237. {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
  2238. {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
  2239. {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
  2240. (s->accu_queue_sz / s->queue_sz_counts) : 0}
  2241. };
  2242. stats = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
  2243. if (!stats)
  2244. return -EMSGSIZE;
  2245. for (i = 0; i < ARRAY_SIZE(map); i++)
  2246. if (nla_put_u32(skb, map[i].key, map[i].val))
  2247. goto msg_full;
  2248. nla_nest_end(skb, stats);
  2249. return 0;
  2250. msg_full:
  2251. nla_nest_cancel(skb, stats);
  2252. return -EMSGSIZE;
  2253. }
  2254. /* Caller should hold appropriate locks to protect the link */
  2255. int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
  2256. struct tipc_link *link, int nlflags)
  2257. {
  2258. u32 self = tipc_own_addr(net);
  2259. struct nlattr *attrs;
  2260. struct nlattr *prop;
  2261. void *hdr;
  2262. int err;
  2263. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  2264. nlflags, TIPC_NL_LINK_GET);
  2265. if (!hdr)
  2266. return -EMSGSIZE;
  2267. attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
  2268. if (!attrs)
  2269. goto msg_full;
  2270. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
  2271. goto attr_msg_full;
  2272. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
  2273. goto attr_msg_full;
  2274. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
  2275. goto attr_msg_full;
  2276. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->stats.recv_pkts))
  2277. goto attr_msg_full;
  2278. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->stats.sent_pkts))
  2279. goto attr_msg_full;
  2280. if (tipc_link_is_up(link))
  2281. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  2282. goto attr_msg_full;
  2283. if (link->active)
  2284. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
  2285. goto attr_msg_full;
  2286. prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
  2287. if (!prop)
  2288. goto attr_msg_full;
  2289. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  2290. goto prop_msg_full;
  2291. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
  2292. goto prop_msg_full;
  2293. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
  2294. link->window))
  2295. goto prop_msg_full;
  2296. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
  2297. goto prop_msg_full;
  2298. nla_nest_end(msg->skb, prop);
  2299. err = __tipc_nl_add_stats(msg->skb, &link->stats);
  2300. if (err)
  2301. goto attr_msg_full;
  2302. nla_nest_end(msg->skb, attrs);
  2303. genlmsg_end(msg->skb, hdr);
  2304. return 0;
  2305. prop_msg_full:
  2306. nla_nest_cancel(msg->skb, prop);
  2307. attr_msg_full:
  2308. nla_nest_cancel(msg->skb, attrs);
  2309. msg_full:
  2310. genlmsg_cancel(msg->skb, hdr);
  2311. return -EMSGSIZE;
  2312. }
  2313. static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
  2314. struct tipc_stats *stats)
  2315. {
  2316. int i;
  2317. struct nlattr *nest;
  2318. struct nla_map {
  2319. __u32 key;
  2320. __u32 val;
  2321. };
  2322. struct nla_map map[] = {
  2323. {TIPC_NLA_STATS_RX_INFO, stats->recv_pkts},
  2324. {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
  2325. {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
  2326. {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
  2327. {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
  2328. {TIPC_NLA_STATS_TX_INFO, stats->sent_pkts},
  2329. {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
  2330. {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
  2331. {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
  2332. {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
  2333. {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
  2334. {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
  2335. {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
  2336. {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
  2337. {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
  2338. {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
  2339. {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
  2340. {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
  2341. {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
  2342. (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
  2343. };
  2344. nest = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
  2345. if (!nest)
  2346. return -EMSGSIZE;
  2347. for (i = 0; i < ARRAY_SIZE(map); i++)
  2348. if (nla_put_u32(skb, map[i].key, map[i].val))
  2349. goto msg_full;
  2350. nla_nest_end(skb, nest);
  2351. return 0;
  2352. msg_full:
  2353. nla_nest_cancel(skb, nest);
  2354. return -EMSGSIZE;
  2355. }
  2356. int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
  2357. {
  2358. int err;
  2359. void *hdr;
  2360. struct nlattr *attrs;
  2361. struct nlattr *prop;
  2362. struct tipc_net *tn = net_generic(net, tipc_net_id);
  2363. u32 bc_mode = tipc_bcast_get_broadcast_mode(net);
  2364. u32 bc_ratio = tipc_bcast_get_broadcast_ratio(net);
  2365. struct tipc_link *bcl = tn->bcl;
  2366. if (!bcl)
  2367. return 0;
  2368. tipc_bcast_lock(net);
  2369. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  2370. NLM_F_MULTI, TIPC_NL_LINK_GET);
  2371. if (!hdr) {
  2372. tipc_bcast_unlock(net);
  2373. return -EMSGSIZE;
  2374. }
  2375. attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
  2376. if (!attrs)
  2377. goto msg_full;
  2378. /* The broadcast link is always up */
  2379. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
  2380. goto attr_msg_full;
  2381. if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
  2382. goto attr_msg_full;
  2383. if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
  2384. goto attr_msg_full;
  2385. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, 0))
  2386. goto attr_msg_full;
  2387. if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0))
  2388. goto attr_msg_full;
  2389. prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
  2390. if (!prop)
  2391. goto attr_msg_full;
  2392. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->max_win))
  2393. goto prop_msg_full;
  2394. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST, bc_mode))
  2395. goto prop_msg_full;
  2396. if (bc_mode & BCLINK_MODE_SEL)
  2397. if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST_RATIO,
  2398. bc_ratio))
  2399. goto prop_msg_full;
  2400. nla_nest_end(msg->skb, prop);
  2401. err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
  2402. if (err)
  2403. goto attr_msg_full;
  2404. tipc_bcast_unlock(net);
  2405. nla_nest_end(msg->skb, attrs);
  2406. genlmsg_end(msg->skb, hdr);
  2407. return 0;
  2408. prop_msg_full:
  2409. nla_nest_cancel(msg->skb, prop);
  2410. attr_msg_full:
  2411. nla_nest_cancel(msg->skb, attrs);
  2412. msg_full:
  2413. tipc_bcast_unlock(net);
  2414. genlmsg_cancel(msg->skb, hdr);
  2415. return -EMSGSIZE;
  2416. }
  2417. void tipc_link_set_tolerance(struct tipc_link *l, u32 tol,
  2418. struct sk_buff_head *xmitq)
  2419. {
  2420. l->tolerance = tol;
  2421. if (l->bc_rcvlink)
  2422. l->bc_rcvlink->tolerance = tol;
  2423. if (link_is_up(l))
  2424. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, tol, 0, xmitq);
  2425. }
  2426. void tipc_link_set_prio(struct tipc_link *l, u32 prio,
  2427. struct sk_buff_head *xmitq)
  2428. {
  2429. l->priority = prio;
  2430. tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, prio, xmitq);
  2431. }
  2432. void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit)
  2433. {
  2434. l->abort_limit = limit;
  2435. }
  2436. char *tipc_link_name_ext(struct tipc_link *l, char *buf)
  2437. {
  2438. if (!l)
  2439. scnprintf(buf, TIPC_MAX_LINK_NAME, "null");
  2440. else if (link_is_bc_sndlink(l))
  2441. scnprintf(buf, TIPC_MAX_LINK_NAME, "broadcast-sender");
  2442. else if (link_is_bc_rcvlink(l))
  2443. scnprintf(buf, TIPC_MAX_LINK_NAME,
  2444. "broadcast-receiver, peer %x", l->addr);
  2445. else
  2446. memcpy(buf, l->name, TIPC_MAX_LINK_NAME);
  2447. return buf;
  2448. }
  2449. /**
  2450. * tipc_link_dump - dump TIPC link data
  2451. * @l: tipc link to be dumped
  2452. * @dqueues: bitmask to decide if any link queue to be dumped?
  2453. * - TIPC_DUMP_NONE: don't dump link queues
  2454. * - TIPC_DUMP_TRANSMQ: dump link transmq queue
  2455. * - TIPC_DUMP_BACKLOGQ: dump link backlog queue
  2456. * - TIPC_DUMP_DEFERDQ: dump link deferd queue
  2457. * - TIPC_DUMP_INPUTQ: dump link input queue
  2458. * - TIPC_DUMP_WAKEUP: dump link wakeup queue
  2459. * - TIPC_DUMP_ALL: dump all the link queues above
  2460. * @buf: returned buffer of dump data in format
  2461. */
  2462. int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf)
  2463. {
  2464. int i = 0;
  2465. size_t sz = (dqueues) ? LINK_LMAX : LINK_LMIN;
  2466. struct sk_buff_head *list;
  2467. struct sk_buff *hskb, *tskb;
  2468. u32 len;
  2469. if (!l) {
  2470. i += scnprintf(buf, sz, "link data: (null)\n");
  2471. return i;
  2472. }
  2473. i += scnprintf(buf, sz, "link data: %x", l->addr);
  2474. i += scnprintf(buf + i, sz - i, " %x", l->state);
  2475. i += scnprintf(buf + i, sz - i, " %u", l->in_session);
  2476. i += scnprintf(buf + i, sz - i, " %u", l->session);
  2477. i += scnprintf(buf + i, sz - i, " %u", l->peer_session);
  2478. i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt);
  2479. i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt);
  2480. i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt_state);
  2481. i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt_state);
  2482. i += scnprintf(buf + i, sz - i, " %x", l->peer_caps);
  2483. i += scnprintf(buf + i, sz - i, " %u", l->silent_intv_cnt);
  2484. i += scnprintf(buf + i, sz - i, " %u", l->rst_cnt);
  2485. i += scnprintf(buf + i, sz - i, " %u", 0);
  2486. i += scnprintf(buf + i, sz - i, " %u", 0);
  2487. i += scnprintf(buf + i, sz - i, " %u", l->acked);
  2488. list = &l->transmq;
  2489. len = skb_queue_len(list);
  2490. hskb = skb_peek(list);
  2491. tskb = skb_peek_tail(list);
  2492. i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
  2493. (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
  2494. (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
  2495. list = &l->deferdq;
  2496. len = skb_queue_len(list);
  2497. hskb = skb_peek(list);
  2498. tskb = skb_peek_tail(list);
  2499. i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
  2500. (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
  2501. (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
  2502. list = &l->backlogq;
  2503. len = skb_queue_len(list);
  2504. hskb = skb_peek(list);
  2505. tskb = skb_peek_tail(list);
  2506. i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
  2507. (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
  2508. (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
  2509. list = l->inputq;
  2510. len = skb_queue_len(list);
  2511. hskb = skb_peek(list);
  2512. tskb = skb_peek_tail(list);
  2513. i += scnprintf(buf + i, sz - i, " | %u %u %u\n", len,
  2514. (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
  2515. (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
  2516. if (dqueues & TIPC_DUMP_TRANSMQ) {
  2517. i += scnprintf(buf + i, sz - i, "transmq: ");
  2518. i += tipc_list_dump(&l->transmq, false, buf + i);
  2519. }
  2520. if (dqueues & TIPC_DUMP_BACKLOGQ) {
  2521. i += scnprintf(buf + i, sz - i,
  2522. "backlogq: <%u %u %u %u %u>, ",
  2523. l->backlog[TIPC_LOW_IMPORTANCE].len,
  2524. l->backlog[TIPC_MEDIUM_IMPORTANCE].len,
  2525. l->backlog[TIPC_HIGH_IMPORTANCE].len,
  2526. l->backlog[TIPC_CRITICAL_IMPORTANCE].len,
  2527. l->backlog[TIPC_SYSTEM_IMPORTANCE].len);
  2528. i += tipc_list_dump(&l->backlogq, false, buf + i);
  2529. }
  2530. if (dqueues & TIPC_DUMP_DEFERDQ) {
  2531. i += scnprintf(buf + i, sz - i, "deferdq: ");
  2532. i += tipc_list_dump(&l->deferdq, false, buf + i);
  2533. }
  2534. if (dqueues & TIPC_DUMP_INPUTQ) {
  2535. i += scnprintf(buf + i, sz - i, "inputq: ");
  2536. i += tipc_list_dump(l->inputq, false, buf + i);
  2537. }
  2538. if (dqueues & TIPC_DUMP_WAKEUP) {
  2539. i += scnprintf(buf + i, sz - i, "wakeup: ");
  2540. i += tipc_list_dump(&l->wakeupq, false, buf + i);
  2541. }
  2542. return i;
  2543. }