/net/tipc/link.c

http://github.com/mirrors/linux · C · 2855 lines · 2148 code · 312 blank · 395 comment · 376 complexity · 8e20a8e3c1b08ee70c2acc96714a19f1 MD5 · raw file

Large files are truncated click here to view the full file

  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_c