PageRenderTime 110ms CodeModel.GetById 15ms app.highlight 81ms 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

Large files files are truncated, but you can 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
  37#include "core.h"
  38#include "subscr.h"
  39#include "link.h"
  40#include "bcast.h"
  41#include "socket.h"
  42#include "name_distr.h"
  43#include "discover.h"
  44#include "netlink.h"
  45#include "monitor.h"
  46#include "trace.h"
  47#include "crypto.h"
  48
  49#include <linux/pkt_sched.h>
  50
  51struct tipc_stats {
  52	u32 sent_pkts;
  53	u32 recv_pkts;
  54	u32 sent_states;
  55	u32 recv_states;
  56	u32 sent_probes;
  57	u32 recv_probes;
  58	u32 sent_nacks;
  59	u32 recv_nacks;
  60	u32 sent_acks;
  61	u32 sent_bundled;
  62	u32 sent_bundles;
  63	u32 recv_bundled;
  64	u32 recv_bundles;
  65	u32 retransmitted;
  66	u32 sent_fragmented;
  67	u32 sent_fragments;
  68	u32 recv_fragmented;
  69	u32 recv_fragments;
  70	u32 link_congs;		/* # port sends blocked by congestion */
  71	u32 deferred_recv;
  72	u32 duplicates;
  73	u32 max_queue_sz;	/* send queue size high water mark */
  74	u32 accu_queue_sz;	/* used for send queue size profiling */
  75	u32 queue_sz_counts;	/* used for send queue size profiling */
  76	u32 msg_length_counts;	/* used for message length profiling */
  77	u32 msg_lengths_total;	/* used for message length profiling */
  78	u32 msg_length_profile[7]; /* used for msg. length profiling */
  79};
  80
  81/**
  82 * struct tipc_link - TIPC link data structure
  83 * @addr: network address of link's peer node
  84 * @name: link name character string
  85 * @media_addr: media address to use when sending messages over link
  86 * @timer: link timer
  87 * @net: pointer to namespace struct
  88 * @refcnt: reference counter for permanent references (owner node & timer)
  89 * @peer_session: link session # being used by peer end of link
  90 * @peer_bearer_id: bearer id used by link's peer endpoint
  91 * @bearer_id: local bearer id used by link
  92 * @tolerance: minimum link continuity loss needed to reset link [in ms]
  93 * @abort_limit: # of unacknowledged continuity probes needed to reset link
  94 * @state: current state of link FSM
  95 * @peer_caps: bitmap describing capabilities of peer node
  96 * @silent_intv_cnt: # of timer intervals without any reception from peer
  97 * @proto_msg: template for control messages generated by link
  98 * @pmsg: convenience pointer to "proto_msg" field
  99 * @priority: current link priority
 100 * @net_plane: current link network plane ('A' through 'H')
 101 * @mon_state: cookie with information needed by link monitor
 102 * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
 103 * @exp_msg_count: # of tunnelled messages expected during link changeover
 104 * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
 105 * @mtu: current maximum packet size for this link
 106 * @advertised_mtu: advertised own mtu when link is being established
 107 * @transmitq: queue for sent, non-acked messages
 108 * @backlogq: queue for messages waiting to be sent
 109 * @snt_nxt: next sequence number to use for outbound messages
 110 * @ackers: # of peers that needs to ack each packet before it can be released
 111 * @acked: # last packet acked by a certain peer. Used for broadcast.
 112 * @rcv_nxt: next sequence number to expect for inbound messages
 113 * @deferred_queue: deferred queue saved OOS b'cast message received from node
 114 * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
 115 * @inputq: buffer queue for messages to be delivered upwards
 116 * @namedq: buffer queue for name table messages to be delivered upwards
 117 * @next_out: ptr to first unsent outbound message in queue
 118 * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
 119 * @long_msg_seq_no: next identifier to use for outbound fragmented messages
 120 * @reasm_buf: head of partially reassembled inbound message fragments
 121 * @bc_rcvr: marks that this is a broadcast receiver link
 122 * @stats: collects statistics regarding link activity
 123 */
 124struct tipc_link {
 125	u32 addr;
 126	char name[TIPC_MAX_LINK_NAME];
 127	struct net *net;
 128
 129	/* Management and link supervision data */
 130	u16 peer_session;
 131	u16 session;
 132	u16 snd_nxt_state;
 133	u16 rcv_nxt_state;
 134	u32 peer_bearer_id;
 135	u32 bearer_id;
 136	u32 tolerance;
 137	u32 abort_limit;
 138	u32 state;
 139	u16 peer_caps;
 140	bool in_session;
 141	bool active;
 142	u32 silent_intv_cnt;
 143	char if_name[TIPC_MAX_IF_NAME];
 144	u32 priority;
 145	char net_plane;
 146	struct tipc_mon_state mon_state;
 147	u16 rst_cnt;
 148
 149	/* Failover/synch */
 150	u16 drop_point;
 151	struct sk_buff *failover_reasm_skb;
 152	struct sk_buff_head failover_deferdq;
 153
 154	/* Max packet negotiation */
 155	u16 mtu;
 156	u16 advertised_mtu;
 157
 158	/* Sending */
 159	struct sk_buff_head transmq;
 160	struct sk_buff_head backlogq;
 161	struct {
 162		u16 len;
 163		u16 limit;
 164		struct sk_buff *target_bskb;
 165	} backlog[5];
 166	u16 snd_nxt;
 167
 168	/* Reception */
 169	u16 rcv_nxt;
 170	u32 rcv_unacked;
 171	struct sk_buff_head deferdq;
 172	struct sk_buff_head *inputq;
 173	struct sk_buff_head *namedq;
 174
 175	/* Congestion handling */
 176	struct sk_buff_head wakeupq;
 177	u16 window;
 178	u16 min_win;
 179	u16 ssthresh;
 180	u16 max_win;
 181	u16 cong_acks;
 182	u16 checkpoint;
 183
 184	/* Fragmentation/reassembly */
 185	struct sk_buff *reasm_buf;
 186	struct sk_buff *reasm_tnlmsg;
 187
 188	/* Broadcast */
 189	u16 ackers;
 190	u16 acked;
 191	struct tipc_link *bc_rcvlink;
 192	struct tipc_link *bc_sndlink;
 193	u8 nack_state;
 194	bool bc_peer_is_up;
 195
 196	/* Statistics */
 197	struct tipc_stats stats;
 198};
 199
 200/*
 201 * Error message prefixes
 202 */
 203static const char *link_co_err = "Link tunneling error, ";
 204static const char *link_rst_msg = "Resetting link ";
 205
 206/* Send states for broadcast NACKs
 207 */
 208enum {
 209	BC_NACK_SND_CONDITIONAL,
 210	BC_NACK_SND_UNCONDITIONAL,
 211	BC_NACK_SND_SUPPRESS,
 212};
 213
 214#define TIPC_BC_RETR_LIM  (jiffies + msecs_to_jiffies(10))
 215#define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1))
 216
 217/*
 218 * Interval between NACKs when packets arrive out of order
 219 */
 220#define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
 221
 222/* Link FSM states:
 223 */
 224enum {
 225	LINK_ESTABLISHED     = 0xe,
 226	LINK_ESTABLISHING    = 0xe  << 4,
 227	LINK_RESET           = 0x1  << 8,
 228	LINK_RESETTING       = 0x2  << 12,
 229	LINK_PEER_RESET      = 0xd  << 16,
 230	LINK_FAILINGOVER     = 0xf  << 20,
 231	LINK_SYNCHING        = 0xc  << 24
 232};
 233
 234/* Link FSM state checking routines
 235 */
 236static int link_is_up(struct tipc_link *l)
 237{
 238	return l->state & (LINK_ESTABLISHED | LINK_SYNCHING);
 239}
 240
 241static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
 242			       struct sk_buff_head *xmitq);
 243static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
 244				      bool probe_reply, u16 rcvgap,
 245				      int tolerance, int priority,
 246				      struct sk_buff_head *xmitq);
 247static void link_print(struct tipc_link *l, const char *str);
 248static int tipc_link_build_nack_msg(struct tipc_link *l,
 249				    struct sk_buff_head *xmitq);
 250static void tipc_link_build_bc_init_msg(struct tipc_link *l,
 251					struct sk_buff_head *xmitq);
 252static int tipc_link_release_pkts(struct tipc_link *l, u16 to);
 253static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data, u16 gap);
 254static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
 255				     struct tipc_gap_ack_blks *ga,
 256				     struct sk_buff_head *xmitq);
 257static void tipc_link_update_cwin(struct tipc_link *l, int released,
 258				  bool retransmitted);
 259/*
 260 *  Simple non-static link routines (i.e. referenced outside this file)
 261 */
 262bool tipc_link_is_up(struct tipc_link *l)
 263{
 264	return link_is_up(l);
 265}
 266
 267bool tipc_link_peer_is_down(struct tipc_link *l)
 268{
 269	return l->state == LINK_PEER_RESET;
 270}
 271
 272bool tipc_link_is_reset(struct tipc_link *l)
 273{
 274	return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
 275}
 276
 277bool tipc_link_is_establishing(struct tipc_link *l)
 278{
 279	return l->state == LINK_ESTABLISHING;
 280}
 281
 282bool tipc_link_is_synching(struct tipc_link *l)
 283{
 284	return l->state == LINK_SYNCHING;
 285}
 286
 287bool tipc_link_is_failingover(struct tipc_link *l)
 288{
 289	return l->state == LINK_FAILINGOVER;
 290}
 291
 292bool tipc_link_is_blocked(struct tipc_link *l)
 293{
 294	return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER);
 295}
 296
 297static bool link_is_bc_sndlink(struct tipc_link *l)
 298{
 299	return !l->bc_sndlink;
 300}
 301
 302static bool link_is_bc_rcvlink(struct tipc_link *l)
 303{
 304	return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l));
 305}
 306
 307void tipc_link_set_active(struct tipc_link *l, bool active)
 308{
 309	l->active = active;
 310}
 311
 312u32 tipc_link_id(struct tipc_link *l)
 313{
 314	return l->peer_bearer_id << 16 | l->bearer_id;
 315}
 316
 317int tipc_link_min_win(struct tipc_link *l)
 318{
 319	return l->min_win;
 320}
 321
 322int tipc_link_max_win(struct tipc_link *l)
 323{
 324	return l->max_win;
 325}
 326
 327int tipc_link_prio(struct tipc_link *l)
 328{
 329	return l->priority;
 330}
 331
 332unsigned long tipc_link_tolerance(struct tipc_link *l)
 333{
 334	return l->tolerance;
 335}
 336
 337struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
 338{
 339	return l->inputq;
 340}
 341
 342char tipc_link_plane(struct tipc_link *l)
 343{
 344	return l->net_plane;
 345}
 346
 347void tipc_link_update_caps(struct tipc_link *l, u16 capabilities)
 348{
 349	l->peer_caps = capabilities;
 350}
 351
 352void tipc_link_add_bc_peer(struct tipc_link *snd_l,
 353			   struct tipc_link *uc_l,
 354			   struct sk_buff_head *xmitq)
 355{
 356	struct tipc_link *rcv_l = uc_l->bc_rcvlink;
 357
 358	snd_l->ackers++;
 359	rcv_l->acked = snd_l->snd_nxt - 1;
 360	snd_l->state = LINK_ESTABLISHED;
 361	tipc_link_build_bc_init_msg(uc_l, xmitq);
 362}
 363
 364void tipc_link_remove_bc_peer(struct tipc_link *snd_l,
 365			      struct tipc_link *rcv_l,
 366			      struct sk_buff_head *xmitq)
 367{
 368	u16 ack = snd_l->snd_nxt - 1;
 369
 370	snd_l->ackers--;
 371	rcv_l->bc_peer_is_up = true;
 372	rcv_l->state = LINK_ESTABLISHED;
 373	tipc_link_bc_ack_rcv(rcv_l, ack, xmitq);
 374	trace_tipc_link_reset(rcv_l, TIPC_DUMP_ALL, "bclink removed!");
 375	tipc_link_reset(rcv_l);
 376	rcv_l->state = LINK_RESET;
 377	if (!snd_l->ackers) {
 378		trace_tipc_link_reset(snd_l, TIPC_DUMP_ALL, "zero ackers!");
 379		tipc_link_reset(snd_l);
 380		snd_l->state = LINK_RESET;
 381		__skb_queue_purge(xmitq);
 382	}
 383}
 384
 385int tipc_link_bc_peers(struct tipc_link *l)
 386{
 387	return l->ackers;
 388}
 389
 390static u16 link_bc_rcv_gap(struct tipc_link *l)
 391{
 392	struct sk_buff *skb = skb_peek(&l->deferdq);
 393	u16 gap = 0;
 394
 395	if (more(l->snd_nxt, l->rcv_nxt))
 396		gap = l->snd_nxt - l->rcv_nxt;
 397	if (skb)
 398		gap = buf_seqno(skb) - l->rcv_nxt;
 399	return gap;
 400}
 401
 402void tipc_link_set_mtu(struct tipc_link *l, int mtu)
 403{
 404	l->mtu = mtu;
 405}
 406
 407int tipc_link_mtu(struct tipc_link *l)
 408{
 409	return l->mtu;
 410}
 411
 412int tipc_link_mss(struct tipc_link *l)
 413{
 414#ifdef CONFIG_TIPC_CRYPTO
 415	return l->mtu - INT_H_SIZE - EMSG_OVERHEAD;
 416#else
 417	return l->mtu - INT_H_SIZE;
 418#endif
 419}
 420
 421u16 tipc_link_rcv_nxt(struct tipc_link *l)
 422{
 423	return l->rcv_nxt;
 424}
 425
 426u16 tipc_link_acked(struct tipc_link *l)
 427{
 428	return l->acked;
 429}
 430
 431char *tipc_link_name(struct tipc_link *l)
 432{
 433	return l->name;
 434}
 435
 436u32 tipc_link_state(struct tipc_link *l)
 437{
 438	return l->state;
 439}
 440
 441/**
 442 * tipc_link_create - create a new link
 443 * @n: pointer to associated node
 444 * @if_name: associated interface name
 445 * @bearer_id: id (index) of associated bearer
 446 * @tolerance: link tolerance to be used by link
 447 * @net_plane: network plane (A,B,c..) this link belongs to
 448 * @mtu: mtu to be advertised by link
 449 * @priority: priority to be used by link
 450 * @min_win: minimal send window to be used by link
 451 * @max_win: maximal send window to be used by link
 452 * @session: session to be used by link
 453 * @ownnode: identity of own node
 454 * @peer: node id of peer node
 455 * @peer_caps: bitmap describing peer node capabilities
 456 * @bc_sndlink: the namespace global link used for broadcast sending
 457 * @bc_rcvlink: the peer specific link used for broadcast reception
 458 * @inputq: queue to put messages ready for delivery
 459 * @namedq: queue to put binding table update messages ready for delivery
 460 * @link: return value, pointer to put the created link
 461 *
 462 * Returns true if link was created, otherwise false
 463 */
 464bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
 465		      int tolerance, char net_plane, u32 mtu, int priority,
 466		      u32 min_win, u32 max_win, u32 session, u32 self,
 467		      u32 peer, u8 *peer_id, u16 peer_caps,
 468		      struct tipc_link *bc_sndlink,
 469		      struct tipc_link *bc_rcvlink,
 470		      struct sk_buff_head *inputq,
 471		      struct sk_buff_head *namedq,
 472		      struct tipc_link **link)
 473{
 474	char peer_str[NODE_ID_STR_LEN] = {0,};
 475	char self_str[NODE_ID_STR_LEN] = {0,};
 476	struct tipc_link *l;
 477
 478	l = kzalloc(sizeof(*l), GFP_ATOMIC);
 479	if (!l)
 480		return false;
 481	*link = l;
 482	l->session = session;
 483
 484	/* Set link name for unicast links only */
 485	if (peer_id) {
 486		tipc_nodeid2string(self_str, tipc_own_id(net));
 487		if (strlen(self_str) > 16)
 488			sprintf(self_str, "%x", self);
 489		tipc_nodeid2string(peer_str, peer_id);
 490		if (strlen(peer_str) > 16)
 491			sprintf(peer_str, "%x", peer);
 492	}
 493	/* Peer i/f name will be completed by reset/activate message */
 494	snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
 495		 self_str, if_name, peer_str);
 496
 497	strcpy(l->if_name, if_name);
 498	l->addr = peer;
 499	l->peer_caps = peer_caps;
 500	l->net = net;
 501	l->in_session = false;
 502	l->bearer_id = bearer_id;
 503	l->tolerance = tolerance;
 504	if (bc_rcvlink)
 505		bc_rcvlink->tolerance = tolerance;
 506	l->net_plane = net_plane;
 507	l->advertised_mtu = mtu;
 508	l->mtu = mtu;
 509	l->priority = priority;
 510	tipc_link_set_queue_limits(l, min_win, max_win);
 511	l->ackers = 1;
 512	l->bc_sndlink = bc_sndlink;
 513	l->bc_rcvlink = bc_rcvlink;
 514	l->inputq = inputq;
 515	l->namedq = namedq;
 516	l->state = LINK_RESETTING;
 517	__skb_queue_head_init(&l->transmq);
 518	__skb_queue_head_init(&l->backlogq);
 519	__skb_queue_head_init(&l->deferdq);
 520	__skb_queue_head_init(&l->failover_deferdq);
 521	skb_queue_head_init(&l->wakeupq);
 522	skb_queue_head_init(l->inputq);
 523	return true;
 524}
 525
 526/**
 527 * tipc_link_bc_create - create new link to be used for broadcast
 528 * @n: pointer to associated node
 529 * @mtu: mtu to be used initially if no peers
 530 * @window: send window to be used
 531 * @inputq: queue to put messages ready for delivery
 532 * @namedq: queue to put binding table update messages ready for delivery
 533 * @link: return value, pointer to put the created link
 534 *
 535 * Returns true if link was created, otherwise false
 536 */
 537bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
 538			 int mtu, u32 min_win, u32 max_win, u16 peer_caps,
 539			 struct sk_buff_head *inputq,
 540			 struct sk_buff_head *namedq,
 541			 struct tipc_link *bc_sndlink,
 542			 struct tipc_link **link)
 543{
 544	struct tipc_link *l;
 545
 546	if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, min_win,
 547			      max_win, 0, ownnode, peer, NULL, peer_caps,
 548			      bc_sndlink, NULL, inputq, namedq, link))
 549		return false;
 550
 551	l = *link;
 552	strcpy(l->name, tipc_bclink_name);
 553	trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!");
 554	tipc_link_reset(l);
 555	l->state = LINK_RESET;
 556	l->ackers = 0;
 557	l->bc_rcvlink = l;
 558
 559	/* Broadcast send link is always up */
 560	if (link_is_bc_sndlink(l))
 561		l->state = LINK_ESTABLISHED;
 562
 563	/* Disable replicast if even a single peer doesn't support it */
 564	if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
 565		tipc_bcast_toggle_rcast(net, false);
 566
 567	return true;
 568}
 569
 570/**
 571 * tipc_link_fsm_evt - link finite state machine
 572 * @l: pointer to link
 573 * @evt: state machine event to be processed
 574 */
 575int tipc_link_fsm_evt(struct tipc_link *l, int evt)
 576{
 577	int rc = 0;
 578	int old_state = l->state;
 579
 580	switch (l->state) {
 581	case LINK_RESETTING:
 582		switch (evt) {
 583		case LINK_PEER_RESET_EVT:
 584			l->state = LINK_PEER_RESET;
 585			break;
 586		case LINK_RESET_EVT:
 587			l->state = LINK_RESET;
 588			break;
 589		case LINK_FAILURE_EVT:
 590		case LINK_FAILOVER_BEGIN_EVT:
 591		case LINK_ESTABLISH_EVT:
 592		case LINK_FAILOVER_END_EVT:
 593		case LINK_SYNCH_BEGIN_EVT:
 594		case LINK_SYNCH_END_EVT:
 595		default:
 596			goto illegal_evt;
 597		}
 598		break;
 599	case LINK_RESET:
 600		switch (evt) {
 601		case LINK_PEER_RESET_EVT:
 602			l->state = LINK_ESTABLISHING;
 603			break;
 604		case LINK_FAILOVER_BEGIN_EVT:
 605			l->state = LINK_FAILINGOVER;
 606		case LINK_FAILURE_EVT:
 607		case LINK_RESET_EVT:
 608		case LINK_ESTABLISH_EVT:
 609		case LINK_FAILOVER_END_EVT:
 610			break;
 611		case LINK_SYNCH_BEGIN_EVT:
 612		case LINK_SYNCH_END_EVT:
 613		default:
 614			goto illegal_evt;
 615		}
 616		break;
 617	case LINK_PEER_RESET:
 618		switch (evt) {
 619		case LINK_RESET_EVT:
 620			l->state = LINK_ESTABLISHING;
 621			break;
 622		case LINK_PEER_RESET_EVT:
 623		case LINK_ESTABLISH_EVT:
 624		case LINK_FAILURE_EVT:
 625			break;
 626		case LINK_SYNCH_BEGIN_EVT:
 627		case LINK_SYNCH_END_EVT:
 628		case LINK_FAILOVER_BEGIN_EVT:
 629		case LINK_FAILOVER_END_EVT:
 630		default:
 631			goto illegal_evt;
 632		}
 633		break;
 634	case LINK_FAILINGOVER:
 635		switch (evt) {
 636		case LINK_FAILOVER_END_EVT:
 637			l->state = LINK_RESET;
 638			break;
 639		case LINK_PEER_RESET_EVT:
 640		case LINK_RESET_EVT:
 641		case LINK_ESTABLISH_EVT:
 642		case LINK_FAILURE_EVT:
 643			break;
 644		case LINK_FAILOVER_BEGIN_EVT:
 645		case LINK_SYNCH_BEGIN_EVT:
 646		case LINK_SYNCH_END_EVT:
 647		default:
 648			goto illegal_evt;
 649		}
 650		break;
 651	case LINK_ESTABLISHING:
 652		switch (evt) {
 653		case LINK_ESTABLISH_EVT:
 654			l->state = LINK_ESTABLISHED;
 655			break;
 656		case LINK_FAILOVER_BEGIN_EVT:
 657			l->state = LINK_FAILINGOVER;
 658			break;
 659		case LINK_RESET_EVT:
 660			l->state = LINK_RESET;
 661			break;
 662		case LINK_FAILURE_EVT:
 663		case LINK_PEER_RESET_EVT:
 664		case LINK_SYNCH_BEGIN_EVT:
 665		case LINK_FAILOVER_END_EVT:
 666			break;
 667		case LINK_SYNCH_END_EVT:
 668		default:
 669			goto illegal_evt;
 670		}
 671		break;
 672	case LINK_ESTABLISHED:
 673		switch (evt) {
 674		case LINK_PEER_RESET_EVT:
 675			l->state = LINK_PEER_RESET;
 676			rc |= TIPC_LINK_DOWN_EVT;
 677			break;
 678		case LINK_FAILURE_EVT:
 679			l->state = LINK_RESETTING;
 680			rc |= TIPC_LINK_DOWN_EVT;
 681			break;
 682		case LINK_RESET_EVT:
 683			l->state = LINK_RESET;
 684			break;
 685		case LINK_ESTABLISH_EVT:
 686		case LINK_SYNCH_END_EVT:
 687			break;
 688		case LINK_SYNCH_BEGIN_EVT:
 689			l->state = LINK_SYNCHING;
 690			break;
 691		case LINK_FAILOVER_BEGIN_EVT:
 692		case LINK_FAILOVER_END_EVT:
 693		default:
 694			goto illegal_evt;
 695		}
 696		break;
 697	case LINK_SYNCHING:
 698		switch (evt) {
 699		case LINK_PEER_RESET_EVT:
 700			l->state = LINK_PEER_RESET;
 701			rc |= TIPC_LINK_DOWN_EVT;
 702			break;
 703		case LINK_FAILURE_EVT:
 704			l->state = LINK_RESETTING;
 705			rc |= TIPC_LINK_DOWN_EVT;
 706			break;
 707		case LINK_RESET_EVT:
 708			l->state = LINK_RESET;
 709			break;
 710		case LINK_ESTABLISH_EVT:
 711		case LINK_SYNCH_BEGIN_EVT:
 712			break;
 713		case LINK_SYNCH_END_EVT:
 714			l->state = LINK_ESTABLISHED;
 715			break;
 716		case LINK_FAILOVER_BEGIN_EVT:
 717		case LINK_FAILOVER_END_EVT:
 718		default:
 719			goto illegal_evt;
 720		}
 721		break;
 722	default:
 723		pr_err("Unknown FSM state %x in %s\n", l->state, l->name);
 724	}
 725	trace_tipc_link_fsm(l->name, old_state, l->state, evt);
 726	return rc;
 727illegal_evt:
 728	pr_err("Illegal FSM event %x in state %x on link %s\n",
 729	       evt, l->state, l->name);
 730	trace_tipc_link_fsm(l->name, old_state, l->state, evt);
 731	return rc;
 732}
 733
 734/* link_profile_stats - update statistical profiling of traffic
 735 */
 736static void link_profile_stats(struct tipc_link *l)
 737{
 738	struct sk_buff *skb;
 739	struct tipc_msg *msg;
 740	int length;
 741
 742	/* Update counters used in statistical profiling of send traffic */
 743	l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
 744	l->stats.queue_sz_counts++;
 745
 746	skb = skb_peek(&l->transmq);
 747	if (!skb)
 748		return;
 749	msg = buf_msg(skb);
 750	length = msg_size(msg);
 751
 752	if (msg_user(msg) == MSG_FRAGMENTER) {
 753		if (msg_type(msg) != FIRST_FRAGMENT)
 754			return;
 755		length = msg_size(msg_inner_hdr(msg));
 756	}
 757	l->stats.msg_lengths_total += length;
 758	l->stats.msg_length_counts++;
 759	if (length <= 64)
 760		l->stats.msg_length_profile[0]++;
 761	else if (length <= 256)
 762		l->stats.msg_length_profile[1]++;
 763	else if (length <= 1024)
 764		l->stats.msg_length_profile[2]++;
 765	else if (length <= 4096)
 766		l->stats.msg_length_profile[3]++;
 767	else if (length <= 16384)
 768		l->stats.msg_length_profile[4]++;
 769	else if (length <= 32768)
 770		l->stats.msg_length_profile[5]++;
 771	else
 772		l->stats.msg_length_profile[6]++;
 773}
 774
 775/**
 776 * tipc_link_too_silent - check if link is "too silent"
 777 * @l: tipc link to be checked
 778 *
 779 * Returns true if the link 'silent_intv_cnt' is about to reach the
 780 * 'abort_limit' value, otherwise false
 781 */
 782bool tipc_link_too_silent(struct tipc_link *l)
 783{
 784	return (l->silent_intv_cnt + 2 > l->abort_limit);
 785}
 786
 787static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r,
 788				u16 from, u16 to, struct sk_buff_head *xmitq);
 789/* tipc_link_timeout - perform periodic task as instructed from node timeout
 790 */
 791int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
 792{
 793	int mtyp = 0;
 794	int rc = 0;
 795	bool state = false;
 796	bool probe = false;
 797	bool setup = false;
 798	u16 bc_snt = l->bc_sndlink->snd_nxt - 1;
 799	u16 bc_acked = l->bc_rcvlink->acked;
 800	struct tipc_mon_state *mstate = &l->mon_state;
 801
 802	trace_tipc_link_timeout(l, TIPC_DUMP_NONE, " ");
 803	trace_tipc_link_too_silent(l, TIPC_DUMP_ALL, " ");
 804	switch (l->state) {
 805	case LINK_ESTABLISHED:
 806	case LINK_SYNCHING:
 807		mtyp = STATE_MSG;
 808		link_profile_stats(l);
 809		tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id);
 810		if (mstate->reset || (l->silent_intv_cnt > l->abort_limit))
 811			return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
 812		state = bc_acked != bc_snt;
 813		state |= l->bc_rcvlink->rcv_unacked;
 814		state |= l->rcv_unacked;
 815		state |= !skb_queue_empty(&l->transmq);
 816		state |= !skb_queue_empty(&l->deferdq);
 817		probe = mstate->probing;
 818		probe |= l->silent_intv_cnt;
 819		if (probe || mstate->monitoring)
 820			l->silent_intv_cnt++;
 821		if (l->snd_nxt == l->checkpoint) {
 822			tipc_link_update_cwin(l, 0, 0);
 823			probe = true;
 824		}
 825		l->checkpoint = l->snd_nxt;
 826		break;
 827	case LINK_RESET:
 828		setup = l->rst_cnt++ <= 4;
 829		setup |= !(l->rst_cnt % 16);
 830		mtyp = RESET_MSG;
 831		break;
 832	case LINK_ESTABLISHING:
 833		setup = true;
 834		mtyp = ACTIVATE_MSG;
 835		break;
 836	case LINK_PEER_RESET:
 837	case LINK_RESETTING:
 838	case LINK_FAILINGOVER:
 839		break;
 840	default:
 841		break;
 842	}
 843
 844	if (state || probe || setup)
 845		tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq);
 846
 847	return rc;
 848}
 849
 850/**
 851 * link_schedule_user - schedule a message sender for wakeup after congestion
 852 * @l: congested link
 853 * @hdr: header of message that is being sent
 854 * Create pseudo msg to send back to user when congestion abates
 855 */
 856static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr)
 857{
 858	u32 dnode = tipc_own_addr(l->net);
 859	u32 dport = msg_origport(hdr);
 860	struct sk_buff *skb;
 861
 862	/* Create and schedule wakeup pseudo message */
 863	skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
 864			      dnode, l->addr, dport, 0, 0);
 865	if (!skb)
 866		return -ENOBUFS;
 867	msg_set_dest_droppable(buf_msg(skb), true);
 868	TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr);
 869	skb_queue_tail(&l->wakeupq, skb);
 870	l->stats.link_congs++;
 871	trace_tipc_link_conges(l, TIPC_DUMP_ALL, "wakeup scheduled!");
 872	return -ELINKCONG;
 873}
 874
 875/**
 876 * link_prepare_wakeup - prepare users for wakeup after congestion
 877 * @l: congested link
 878 * Wake up a number of waiting users, as permitted by available space
 879 * in the send queue
 880 */
 881static void link_prepare_wakeup(struct tipc_link *l)
 882{
 883	struct sk_buff_head *wakeupq = &l->wakeupq;
 884	struct sk_buff_head *inputq = l->inputq;
 885	struct sk_buff *skb, *tmp;
 886	struct sk_buff_head tmpq;
 887	int avail[5] = {0,};
 888	int imp = 0;
 889
 890	__skb_queue_head_init(&tmpq);
 891
 892	for (; imp <= TIPC_SYSTEM_IMPORTANCE; imp++)
 893		avail[imp] = l->backlog[imp].limit - l->backlog[imp].len;
 894
 895	skb_queue_walk_safe(wakeupq, skb, tmp) {
 896		imp = TIPC_SKB_CB(skb)->chain_imp;
 897		if (avail[imp] <= 0)
 898			continue;
 899		avail[imp]--;
 900		__skb_unlink(skb, wakeupq);
 901		__skb_queue_tail(&tmpq, skb);
 902	}
 903
 904	spin_lock_bh(&inputq->lock);
 905	skb_queue_splice_tail(&tmpq, inputq);
 906	spin_unlock_bh(&inputq->lock);
 907
 908}
 909
 910void tipc_link_reset(struct tipc_link *l)
 911{
 912	struct sk_buff_head list;
 913	u32 imp;
 914
 915	__skb_queue_head_init(&list);
 916
 917	l->in_session = false;
 918	/* Force re-synch of peer session number before establishing */
 919	l->peer_session--;
 920	l->session++;
 921	l->mtu = l->advertised_mtu;
 922
 923	spin_lock_bh(&l->wakeupq.lock);
 924	skb_queue_splice_init(&l->wakeupq, &list);
 925	spin_unlock_bh(&l->wakeupq.lock);
 926
 927	spin_lock_bh(&l->inputq->lock);
 928	skb_queue_splice_init(&list, l->inputq);
 929	spin_unlock_bh(&l->inputq->lock);
 930
 931	__skb_queue_purge(&l->transmq);
 932	__skb_queue_purge(&l->deferdq);
 933	__skb_queue_purge(&l->backlogq);
 934	__skb_queue_purge(&l->failover_deferdq);
 935	for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) {
 936		l->backlog[imp].len = 0;
 937		l->backlog[imp].target_bskb = NULL;
 938	}
 939	kfree_skb(l->reasm_buf);
 940	kfree_skb(l->reasm_tnlmsg);
 941	kfree_skb(l->failover_reasm_skb);
 942	l->reasm_buf = NULL;
 943	l->reasm_tnlmsg = NULL;
 944	l->failover_reasm_skb = NULL;
 945	l->rcv_unacked = 0;
 946	l->snd_nxt = 1;
 947	l->rcv_nxt = 1;
 948	l->snd_nxt_state = 1;
 949	l->rcv_nxt_state = 1;
 950	l->acked = 0;
 951	l->silent_intv_cnt = 0;
 952	l->rst_cnt = 0;
 953	l->bc_peer_is_up = false;
 954	memset(&l->mon_state, 0, sizeof(l->mon_state));
 955	tipc_link_reset_stats(l);
 956}
 957
 958/**
 959 * tipc_link_xmit(): enqueue buffer list according to queue situation
 960 * @link: link to use
 961 * @list: chain of buffers containing message
 962 * @xmitq: returned list of packets to be sent by caller
 963 *
 964 * Consumes the buffer chain.
 965 * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
 966 * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
 967 */
 968int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
 969		   struct sk_buff_head *xmitq)
 970{
 971	struct tipc_msg *hdr = buf_msg(skb_peek(list));
 972	struct sk_buff_head *backlogq = &l->backlogq;
 973	struct sk_buff_head *transmq = &l->transmq;
 974	struct sk_buff *skb, *_skb;
 975	u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
 976	u16 ack = l->rcv_nxt - 1;
 977	u16 seqno = l->snd_nxt;
 978	int pkt_cnt = skb_queue_len(list);
 979	int imp = msg_importance(hdr);
 980	unsigned int mss = tipc_link_mss(l);
 981	unsigned int cwin = l->window;
 982	unsigned int mtu = l->mtu;
 983	bool new_bundle;
 984	int rc = 0;
 985
 986	if (unlikely(msg_size(hdr) > mtu)) {
 987		pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n",
 988			skb_queue_len(list), msg_user(hdr),
 989			msg_type(hdr), msg_size(hdr), mtu);
 990		__skb_queue_purge(list);
 991		return -EMSGSIZE;
 992	}
 993
 994	/* Allow oversubscription of one data msg per source at congestion */
 995	if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
 996		if (imp == TIPC_SYSTEM_IMPORTANCE) {
 997			pr_warn("%s<%s>, link overflow", link_rst_msg, l->name);
 998			return -ENOBUFS;
 999		}
1000		rc = link_schedule_user(l, hdr);
1001	}
1002
1003	if (pkt_cnt > 1) {
1004		l->stats.sent_fragmented++;
1005		l->stats.sent_fragments += pkt_cnt;
1006	}
1007
1008	/* Prepare each packet for sending, and add to relevant queue: */
1009	while ((skb = __skb_dequeue(list))) {
1010		if (likely(skb_queue_len(transmq) < cwin)) {
1011			hdr = buf_msg(skb);
1012			msg_set_seqno(hdr, seqno);
1013			msg_set_ack(hdr, ack);
1014			msg_set_bcast_ack(hdr, bc_ack);
1015			_skb = skb_clone(skb, GFP_ATOMIC);
1016			if (!_skb) {
1017				kfree_skb(skb);
1018				__skb_queue_purge(list);
1019				return -ENOBUFS;
1020			}
1021			__skb_queue_tail(transmq, skb);
1022			/* next retransmit attempt */
1023			if (link_is_bc_sndlink(l))
1024				TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
1025			__skb_queue_tail(xmitq, _skb);
1026			TIPC_SKB_CB(skb)->ackers = l->ackers;
1027			l->rcv_unacked = 0;
1028			l->stats.sent_pkts++;
1029			seqno++;
1030			continue;
1031		}
1032		if (tipc_msg_try_bundle(l->backlog[imp].target_bskb, &skb,
1033					mss, l->addr, &new_bundle)) {
1034			if (skb) {
1035				/* Keep a ref. to the skb for next try */
1036				l->backlog[imp].target_bskb = skb;
1037				l->backlog[imp].len++;
1038				__skb_queue_tail(backlogq, skb);
1039			} else {
1040				if (new_bundle) {
1041					l->stats.sent_bundles++;
1042					l->stats.sent_bundled++;
1043				}
1044				l->stats.sent_bundled++;
1045			}
1046			continue;
1047		}
1048		l->backlog[imp].target_bskb = NULL;
1049		l->backlog[imp].len += (1 + skb_queue_len(list));
1050		__skb_queue_tail(backlogq, skb);
1051		skb_queue_splice_tail_init(list, backlogq);
1052	}
1053	l->snd_nxt = seqno;
1054	return rc;
1055}
1056
1057static void tipc_link_update_cwin(struct tipc_link *l, int released,
1058				  bool retransmitted)
1059{
1060	int bklog_len = skb_queue_len(&l->backlogq);
1061	struct sk_buff_head *txq = &l->transmq;
1062	int txq_len = skb_queue_len(txq);
1063	u16 cwin = l->window;
1064
1065	/* Enter fast recovery */
1066	if (unlikely(retransmitted)) {
1067		l->ssthresh = max_t(u16, l->window / 2, 300);
1068		l->window = min_t(u16, l->ssthresh, l->window);
1069		return;
1070	}
1071	/* Enter slow start */
1072	if (unlikely(!released)) {
1073		l->ssthresh = max_t(u16, l->window / 2, 300);
1074		l->window = l->min_win;
1075		return;
1076	}
1077	/* Don't increase window if no pressure on the transmit queue */
1078	if (txq_len + bklog_len < cwin)
1079		return;
1080
1081	/* Don't increase window if there are holes the transmit queue */
1082	if (txq_len && l->snd_nxt - buf_seqno(skb_peek(txq)) != txq_len)
1083		return;
1084
1085	l->cong_acks += released;
1086
1087	/* Slow start  */
1088	if (cwin <= l->ssthresh) {
1089		l->window = min_t(u16, cwin + released, l->max_win);
1090		return;
1091	}
1092	/* Congestion avoidance */
1093	if (l->cong_acks < cwin)
1094		return;
1095	l->window = min_t(u16, ++cwin, l->max_win);
1096	l->cong_acks = 0;
1097}
1098
1099static void tipc_link_advance_backlog(struct tipc_link *l,
1100				      struct sk_buff_head *xmitq)
1101{
1102	u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1103	struct sk_buff_head *txq = &l->transmq;
1104	struct sk_buff *skb, *_skb;
1105	u16 ack = l->rcv_nxt - 1;
1106	u16 seqno = l->snd_nxt;
1107	struct tipc_msg *hdr;
1108	u16 cwin = l->window;
1109	u32 imp;
1110
1111	while (skb_queue_len(txq) < cwin) {
1112		skb = skb_peek(&l->backlogq);
1113		if (!skb)
1114			break;
1115		_skb = skb_clone(skb, GFP_ATOMIC);
1116		if (!_skb)
1117			break;
1118		__skb_dequeue(&l->backlogq);
1119		hdr = buf_msg(skb);
1120		imp = msg_importance(hdr);
1121		l->backlog[imp].len--;
1122		if (unlikely(skb == l->backlog[imp].target_bskb))
1123			l->backlog[imp].target_bskb = NULL;
1124		__skb_queue_tail(&l->transmq, skb);
1125		/* next retransmit attempt */
1126		if (link_is_bc_sndlink(l))
1127			TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
1128
1129		__skb_queue_tail(xmitq, _skb);
1130		TIPC_SKB_CB(skb)->ackers = l->ackers;
1131		msg_set_seqno(hdr, seqno);
1132		msg_set_ack(hdr, ack);
1133		msg_set_bcast_ack(hdr, bc_ack);
1134		l->rcv_unacked = 0;
1135		l->stats.sent_pkts++;
1136		seqno++;
1137	}
1138	l->snd_nxt = seqno;
1139}
1140
1141/**
1142 * link_retransmit_failure() - Detect repeated retransmit failures
1143 * @l: tipc link sender
1144 * @r: tipc link receiver (= l in case of unicast)
1145 * @rc: returned code
1146 *
1147 * Return: true if the repeated retransmit failures happens, otherwise
1148 * false
1149 */
1150static bool link_retransmit_failure(struct tipc_link *l, struct tipc_link *r,
1151				    int *rc)
1152{
1153	struct sk_buff *skb = skb_peek(&l->transmq);
1154	struct tipc_msg *hdr;
1155
1156	if (!skb)
1157		return false;
1158
1159	if (!TIPC_SKB_CB(skb)->retr_cnt)
1160		return false;
1161
1162	if (!time_after(jiffies, TIPC_SKB_CB(skb)->retr_stamp +
1163			msecs_to_jiffies(r->tolerance * 10)))
1164		return false;
1165
1166	hdr = buf_msg(skb);
1167	if (link_is_bc_sndlink(l) && !less(r->acked, msg_seqno(hdr)))
1168		return false;
1169
1170	pr_warn("Retransmission failure on link <%s>\n", l->name);
1171	link_print(l, "State of link ");
1172	pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n",
1173		msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr));
1174	pr_info("sqno %u, prev: %x, dest: %x\n",
1175		msg_seqno(hdr), msg_prevnode(hdr), msg_destnode(hdr));
1176	pr_info("retr_stamp %d, retr_cnt %d\n",
1177		jiffies_to_msecs(TIPC_SKB_CB(skb)->retr_stamp),
1178		TIPC_SKB_CB(skb)->retr_cnt);
1179
1180	trace_tipc_list_dump(&l->transmq, true, "retrans failure!");
1181	trace_tipc_link_dump(l, TIPC_DUMP_NONE, "retrans failure!");
1182	trace_tipc_link_dump(r, TIPC_DUMP_NONE, "retrans failure!");
1183
1184	if (link_is_bc_sndlink(l)) {
1185		r->state = LINK_RESET;
1186		*rc = TIPC_LINK_DOWN_EVT;
1187	} else {
1188		*rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1189	}
1190
1191	return true;
1192}
1193
1194/* tipc_link_bc_retrans() - retransmit zero or more packets
1195 * @l: the link to transmit on
1196 * @r: the receiving link ordering the retransmit. Same as l if unicast
1197 * @from: retransmit from (inclusive) this sequence number
1198 * @to: retransmit to (inclusive) this sequence number
1199 * xmitq: queue for accumulating the retransmitted packets
1200 */
1201static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r,
1202				u16 from, u16 to, struct sk_buff_head *xmitq)
1203{
1204	struct sk_buff *_skb, *skb = skb_peek(&l->transmq);
1205	u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1206	u16 ack = l->rcv_nxt - 1;
1207	int retransmitted = 0;
1208	struct tipc_msg *hdr;
1209	int rc = 0;
1210
1211	if (!skb)
1212		return 0;
1213	if (less(to, from))
1214		return 0;
1215
1216	trace_tipc_link_retrans(r, from, to, &l->transmq);
1217
1218	if (link_retransmit_failure(l, r, &rc))
1219		return rc;
1220
1221	skb_queue_walk(&l->transmq, skb) {
1222		hdr = buf_msg(skb);
1223		if (less(msg_seqno(hdr), from))
1224			continue;
1225		if (more(msg_seqno(hdr), to))
1226			break;
1227		if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
1228			continue;
1229		TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
1230		_skb = pskb_copy(skb, GFP_ATOMIC);
1231		if (!_skb)
1232			return 0;
1233		hdr = buf_msg(_skb);
1234		msg_set_ack(hdr, ack);
1235		msg_set_bcast_ack(hdr, bc_ack);
1236		_skb->priority = TC_PRIO_CONTROL;
1237		__skb_queue_tail(xmitq, _skb);
1238		l->stats.retransmitted++;
1239		retransmitted++;
1240		/* Increase actual retrans counter & mark first time */
1241		if (!TIPC_SKB_CB(skb)->retr_cnt++)
1242			TIPC_SKB_CB(skb)->retr_stamp = jiffies;
1243	}
1244	tipc_link_update_cwin(l, 0, retransmitted);
1245	return 0;
1246}
1247
1248/* tipc_data_input - deliver data and name distr msgs to upper layer
1249 *
1250 * Consumes buffer if message is of right type
1251 * Node lock must be held
1252 */
1253static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
1254			    struct sk_buff_head *inputq)
1255{
1256	struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq;
1257	struct tipc_msg *hdr = buf_msg(skb);
1258
1259	switch (msg_user(hdr)) {
1260	case TIPC_LOW_IMPORTANCE:
1261	case TIPC_MEDIUM_IMPORTANCE:
1262	case TIPC_HIGH_IMPORTANCE:
1263	case TIPC_CRITICAL_IMPORTANCE:
1264		if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) {
1265			skb_queue_tail(mc_inputq, skb);
1266			return true;
1267		}
1268		/* fall through */
1269	case CONN_MANAGER:
1270		skb_queue_tail(inputq, skb);
1271		return true;
1272	case GROUP_PROTOCOL:
1273		skb_queue_tail(mc_inputq, skb);
1274		return true;
1275	case NAME_DISTRIBUTOR:
1276		l->bc_rcvlink->state = LINK_ESTABLISHED;
1277		skb_queue_tail(l->namedq, skb);
1278		return true;
1279	case MSG_BUNDLER:
1280	case TUNNEL_PROTOCOL:
1281	case MSG_FRAGMENTER:
1282	case BCAST_PROTOCOL:
1283		return false;
1284	default:
1285		pr_warn("Dropping received illegal msg type\n");
1286		kfree_skb(skb);
1287		return true;
1288	};
1289}
1290
1291/* tipc_link_input - process packet that has passed link protocol check
1292 *
1293 * Consumes buffer
1294 */
1295static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
1296			   struct sk_buff_head *inputq,
1297			   struct sk_buff **reasm_skb)
1298{
1299	struct tipc_msg *hdr = buf_msg(skb);
1300	struct sk_buff *iskb;
1301	struct sk_buff_head tmpq;
1302	int usr = msg_user(hdr);
1303	int pos = 0;
1304
1305	if (usr == MSG_BUNDLER) {
1306		skb_queue_head_init(&tmpq);
1307		l->stats.recv_bundles++;
1308		l->stats.recv_bundled += msg_msgcnt(hdr);
1309		while (tipc_msg_extract(skb, &iskb, &pos))
1310			tipc_data_input(l, iskb, &tmpq);
1311		tipc_skb_queue_splice_tail(&tmpq, inputq);
1312		return 0;
1313	} else if (usr == MSG_FRAGMENTER) {
1314		l->stats.recv_fragments++;
1315		if (tipc_buf_append(reasm_skb, &skb)) {
1316			l->stats.recv_fragmented++;
1317			tipc_data_input(l, skb, inputq);
1318		} else if (!*reasm_skb && !link_is_bc_rcvlink(l)) {
1319			pr_warn_ratelimited("Unable to build fragment list\n");
1320			return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1321		}
1322		return 0;
1323	} else if (usr == BCAST_PROTOCOL) {
1324		tipc_bcast_lock(l->net);
1325		tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
1326		tipc_bcast_unlock(l->net);
1327	}
1328
1329	kfree_skb(skb);
1330	return 0;
1331}
1332
1333/* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the
1334 *			 inner message along with the ones in the old link's
1335 *			 deferdq
1336 * @l: tunnel link
1337 * @skb: TUNNEL_PROTOCOL message
1338 * @inputq: queue to put messages ready for delivery
1339 */
1340static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
1341			     struct sk_buff_head *inputq)
1342{
1343	struct sk_buff **reasm_skb = &l->failover_reasm_skb;
1344	struct sk_buff **reasm_tnlmsg = &l->reasm_tnlmsg;
1345	struct sk_buff_head *fdefq = &l->failover_deferdq;
1346	struct tipc_msg *hdr = buf_msg(skb);
1347	struct sk_buff *iskb;
1348	int ipos = 0;
1349	int rc = 0;
1350	u16 seqno;
1351
1352	if (msg_type(hdr) == SYNCH_MSG) {
1353		kfree_skb(skb);
1354		return 0;
1355	}
1356
1357	/* Not a fragment? */
1358	if (likely(!msg_nof_fragms(hdr))) {
1359		if (unlikely(!tipc_msg_extract(skb, &iskb, &ipos))) {
1360			pr_warn_ratelimited("Unable to extract msg, defq: %d\n",
1361					    skb_queue_len(fdefq));
1362			return 0;
1363		}
1364		kfree_skb(skb);
1365	} else {
1366		/* Set fragment type for buf_append */
1367		if (msg_fragm_no(hdr) == 1)
1368			msg_set_type(hdr, FIRST_FRAGMENT);
1369		else if (msg_fragm_no(hdr) < msg_nof_fragms(hdr))
1370			msg_set_type(hdr, FRAGMENT);
1371		else
1372			msg_set_type(hdr, LAST_FRAGMENT);
1373
1374		if (!tipc_buf_append(reasm_tnlmsg, &skb)) {
1375			/* Successful but non-complete reassembly? */
1376			if (*reasm_tnlmsg || link_is_bc_rcvlink(l))
1377				return 0;
1378			pr_warn_ratelimited("Unable to reassemble tunnel msg\n");
1379			return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1380		}
1381		iskb = skb;
1382	}
1383
1384	do {
1385		seqno = buf_seqno(iskb);
1386		if (unlikely(less(seqno, l->drop_point))) {
1387			kfree_skb(iskb);
1388			continue;
1389		}
1390		if (unlikely(seqno != l->drop_point)) {
1391			__tipc_skb_queue_sorted(fdefq, seqno, iskb);
1392			continue;
1393		}
1394
1395		l->drop_point++;
1396		if (!tipc_data_input(l, iskb, inputq))
1397			rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
1398		if (unlikely(rc))
1399			break;
1400	} while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
1401
1402	return rc;
1403}
1404
1405static int tipc_link_release_pkts(struct tipc_link *l, u16 acked)
1406{
1407	int released = 0;
1408	struct sk_buff *skb, *tmp;
1409
1410	skb_queue_walk_safe(&l->transmq, skb, tmp) {
1411		if (more(buf_seqno(skb), acked))
1412			break;
1413		__skb_unlink(skb, &l->transmq);
1414		kfree_skb(skb);
1415		released++;
1416	}
1417	return released;
1418}
1419
1420/* tipc_build_gap_ack_blks - build Gap ACK blocks
1421 * @l: tipc link that data have come with gaps in sequence if any
1422 * @data: data buffer to store the Gap ACK blocks after built
1423 *
1424 * returns the actual allocated memory size
1425 */
1426static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data, u16 gap)
1427{
1428	struct sk_buff *skb = skb_peek(&l->deferdq);
1429	struct tipc_gap_ack_blks *ga = data;
1430	u16 len, expect, seqno = 0;
1431	u8 n = 0;
1432
1433	if (!skb || !gap)
1434		goto exit;
1435
1436	expect = buf_seqno(skb);
1437	skb_queue_walk(&l->deferdq, skb) {
1438		seqno = buf_seqno(skb);
1439		if (unlikely(more(seqno, expect))) {
1440			ga->gacks[n].ack = htons(expect - 1);
1441			ga->gacks[n].gap = htons(seqno - expect);
1442			if (++n >= MAX_GAP_ACK_BLKS) {
1443				pr_info_ratelimited("Too few Gap ACK blocks!\n");
1444				goto exit;
1445			}
1446		} else if (unlikely(less(seqno, expect))) {
1447			pr_warn("Unexpected skb in deferdq!\n");
1448			continue;
1449		}
1450		expect = seqno + 1;
1451	}
1452
1453	/* last block */
1454	ga->gacks[n].ack = htons(seqno);
1455	ga->gacks[n].gap = 0;
1456	n++;
1457
1458exit:
1459	len = tipc_gap_ack_blks_sz(n);
1460	ga->len = htons(len);
1461	ga->gack_cnt = n;
1462	return len;
1463}
1464
1465/* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing
1466 *			       acked packets, also doing retransmissions if
1467 *			       gaps found
1468 * @l: tipc link with transmq queue to be advanced
1469 * @acked: seqno of last packet acked by peer without any gaps before
1470 * @gap: # of gap packets
1471 * @ga: buffer pointer to Gap ACK blocks from peer
1472 * @xmitq: queue for accumulating the retransmitted packets if any
1473 *
1474 * In case of a repeated retransmit failures, the call will return shortly
1475 * with a returned code (e.g. TIPC_LINK_DOWN_EVT)
1476 */
1477static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
1478				     struct tipc_gap_ack_blks *ga,
1479				     struct sk_buff_head *xmitq)
1480{
1481	struct sk_buff *skb, *_skb, *tmp;
1482	struct tipc_msg *hdr;
1483	u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1484	bool retransmitted = false;
1485	u16 ack = l->rcv_nxt - 1;
1486	bool passed = false;
1487	u16 released = 0;
1488	u16 seqno, n = 0;
1489	int rc = 0;
1490
1491	skb_queue_walk_safe(&l->transmq, skb, tmp) {
1492		seqno = buf_seqno(skb);
1493
1494next_gap_ack:
1495		if (less_eq(seqno, acked)) {
1496			/* release skb */
1497			__skb_unlink(skb, &l->transmq);
1498			kfree_skb(skb);
1499			released++;
1500		} else if (less_eq(seqno, acked + gap)) {
1501			/* First, check if repeated retrans failures occurs? */
1502			if (!passed && link_retransmit_failure(l, l, &rc))
1503				return rc;
1504			passed = true;
1505
1506			/* retransmit skb if unrestricted*/
1507			if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
1508				continue;
1509			TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME;
1510			_skb = pskb_copy(skb, GFP_ATOMIC);
1511			if (!_skb)
1512				continue;
1513			hdr = buf_msg(_skb);
1514			msg_set_ack(hdr, ack);
1515			msg_set_bcast_ack(hdr, bc_ack);
1516			_skb->priority = TC_PRIO_CONTROL;
1517			__skb_queue_tail(xmitq, _skb);
1518			l->stats.retransmitted++;
1519			retransmitted = true;
1520			/* Increase actual retrans counter & mark first time */
1521			if (!TIPC_SKB_CB(skb)->retr_cnt++)
1522				TIPC_SKB_CB(skb)->retr_stamp = jiffies;
1523		} else {
1524			/* retry with Gap ACK blocks if any */
1525			if (!ga || n >= ga->gack_cnt)
1526				break;
1527			acked = ntohs(ga->gacks[n].ack);
1528			gap = ntohs(ga->gacks[n].gap);
1529			n++;
1530			goto next_gap_ack;
1531		}
1532	}
1533	if (released || retransmitted)
1534		tipc_link_update_cwin(l, released, retransmitted);
1535	if (released)
1536		tipc_link_advance_backlog(l, xmitq);
1537	return 0;
1538}
1539
1540/* tipc_link_build_state_msg: prepare link state message for transmission
1541 *
1542 * Note that sending of broadcast ack is coordinated among nodes, to reduce
1543 * risk of ack storms towards the sender
1544 */
1545int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1546{
1547	if (!l)
1548		return 0;
1549
1550	/* Broadcast ACK must be sent via a unicast link => defer to caller */
1551	if (link_is_bc_rcvlink(l)) {
1552		if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
1553			return 0;
1554		l->rcv_unacked = 0;
1555
1556		/* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */
1557		l->snd_nxt = l->rcv_nxt;
1558		return TIPC_LINK_SND_STATE;
1559	}
1560	/* Unicast ACK */
1561	l->rcv_unacked = 0;
1562	l->stats.sent_acks++;
1563	tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
1564	return 0;
1565}
1566
1567/* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message
1568 */
1569void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1570{
1571	int mtyp = RESET_MSG;
1572	struct sk_buff *skb;
1573
1574	if (l->state == LINK_ESTABLISHING)
1575		mtyp = ACTIVATE_MSG;
1576
1577	tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq);
1578
1579	/* Inform peer that this endpoint is going down if applicable */
1580	skb = skb_peek_tail(xmitq);
1581	if (skb && (l->state == LINK_RESET))
1582		msg_set_peer_stopping(buf_msg(skb), 1);
1583}
1584
1585/* tipc_link_build_nack_msg: prepare link nack message for transmission
1586 * Note that sending of broadcast NACK is coordinated among nodes, to
1587 * reduce the risk of NACK storms towards the sender
1588 */
1589static int tipc_link_build_nack_msg(struct tipc_link *l,
1590				    struct sk_buff_head *xmitq)
1591{
1592	u32 def_cnt = ++l->stats.deferred_recv;
1593	struct sk_buff_head *dfq = &l->deferdq;
1594	u32 defq_len = skb_queue_len(dfq);
1595	int match1, match2;
1596
1597	if (link_is_bc_rcvlink(l)) {
1598		match1 = def_cnt & 0xf;
1599		match2 = tipc_own_addr(l->net) & 0xf;
1600		if (match1 == match2)
1601			return TIPC_LINK_SND_STATE;
1602		return 0;
1603	}
1604
1605	if (defq_len >= 3 && !((defq_len - 3) % 16)) {
1606		u16 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1607
1608		tipc_link_build_proto_msg(l, STATE_MSG, 0, 0,
1609					  rcvgap, 0, 0, xmitq);
1610	}
1611	return 0;
1612}
1613
1614/* tipc_link_rcv - process TIPC packets/messages arriving from off-node
1615 * @l: the link that should handle the message
1616 * @skb: TIPC packet
1617 * @xmitq: queue to place packets to be sent after this call
1618 */
1619int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
1620		  struct sk_buff_head *xmitq)
1621{
1622	struct sk_buff_head *defq = &l->deferdq;
1623	struct tipc_msg *hdr = buf_msg(skb);
1624	u16 seqno, rcv_nxt, win_lim;
1625	int released = 0;
1626	int rc = 0;
1627
1628	/* Verify and update link state */
1629	if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
1630		return tipc_link_proto_rcv(l, skb, xmitq);
1631
1632	/* Don't send probe at next timeout expiration */
1633	l->silent_intv_cnt = 0;
1634
1635	do {
1636		hdr = buf_msg(skb);
1637		seqno = msg_seqno(hdr);
1638		rcv_nxt = l->rcv_nxt;
1639		win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
1640
1641		if (unlikely(!link_is_up(l))) {
1642			if (l->state == LINK_ESTABLISHING)
1643				rc = TIPC_LINK_UP_EVT;
1644			kfree_skb(skb);
1645			break;
1646		}
1647
1648		/* Drop if outside receive window */
1649		if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
1650			l->stats.duplicates++;
1651			kfree_skb(skb);
1652			break;
1653		}
1654		released += tipc_link_release_pkts(l, msg_ack(hdr));
1655
1656		/* Defer delivery if sequence gap */
1657		if (unlikely(seqno != rcv_nxt)) {
1658			__tipc_skb_queue_sorted(defq, seqno, skb);
1659			rc |= tipc_link_build_nack_msg(l, xmitq);
1660			break;
1661		}
1662
1663		/* Deliver packet */
1664		l->rcv_nxt++;
1665		l->stats.recv_pkts++;
1666
1667		if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL))
1668			rc |= tipc_link_tnl_rcv(l, skb, l->inputq);
1669		else if (!tipc_data_input(l, skb, l->inputq))
1670			rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf);
1671		if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
1672			rc |= tipc_link_build_state_msg(l, xmitq);
1673		if (unlikely(rc & ~TIPC_LINK_SND_STATE))
1674			break;
1675	} while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt)));
1676
1677	/* Forward queues and wake up waiting users */
1678	if (released) {
1679		tipc_link_update_cwin(l, released, 0);
1680		tipc_link_advance_backlog(l, xmitq);
1681		if (unlikely(!skb_queue_empty(&l->wakeupq)))
1682			link_prepare_wakeup(l);
1683	}
1684	return rc;
1685}
1686
1687static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1688				      bool probe_reply, u16 rcvgap,
1689				      int tolerance, int priority,
1690				      struct sk_buff_head *xmitq)
1691{
1692	struct tipc_link *bcl = l->bc_rcvlink;
1693	struct sk_buff *skb;
1694	struct tipc_msg *hdr;
1695	struct sk_buff_head *dfq = &l->deferdq;
1696	bool node_up = link_is_up(bcl);
1697	struct tipc_mon_state *mstate = &l->mon_state;
1698	int dlen = 0;
1699	void *data;
1700	u16 glen = 0;
1701
1702	/* Don't send protocol message during reset or link failover */
1703	if (tipc_link_is_blocked(l))
1704		return;
1705
1706	if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
1707		return;
1708
1709	if ((probe || probe_reply) && !skb_queue_empty(dfq))
1710		rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1711
1712	skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
1713			      tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ,
1714			      l->addr, tipc_own_addr(l->net), 0, 0, 0);
1715	if (!skb)
1716		return;
1717
1718	hdr = buf_msg(skb);
1719	data = msg_data(hdr);
1720	msg_set_session(hdr, l->session);
1721	msg_set_bearer_id(hdr, l->bearer_id);
1722	msg_set_net_plane(hdr, l->net_plane);
1723	msg_set_next_sent(hdr, l->snd_nxt);
1724	msg_set_ack(hdr, l->rcv_nxt - 1);
1725	msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
1726	msg_set_bc_ack_invalid(hdr, !node_up);
1727	msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
1728	msg_set_link_tolerance(hdr, tolerance);
1729	msg_set_linkprio(hdr, priority);
1730	msg_set_redundant_link(hdr, node_up);
1731	msg_set_seq_gap(hdr, 0);
1732	msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
1733
1734	if (mtyp == STATE_MSG) {
1735		if (l->peer_caps & TIPC_LINK_PROTO_SEQNO)
1736			msg_set_seqno(hdr, l->snd_nxt_state++);
1737		msg_set_seq_gap(hdr, rcvgap);
1738		msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
1739		msg_set_probe(hdr, probe);
1740		msg_set_is_keepalive(hdr, probe || probe_reply);
1741		if (l->peer_caps & TIPC_GAP_ACK_BLOCK)
1742			glen = tipc_build_gap_ack_blks(l, data, rcvgap);
1743		tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id);
1744		msg_set_size(hdr, INT_H_SIZE + glen + dlen);
1745		skb_trim(skb, INT_H_SIZE + glen + dlen);
1746		l->stats.sent_states++;
1747		l->rcv_unacked = 0;
1748	} else {
1749		/* RESET_MSG or ACTIVATE_MSG */
1750		if (mtyp == ACTIVATE_MSG) {
1751			msg_set_dest_session_valid(hdr, 1);
1752			msg_set_dest_session(hdr, l->peer_session);
1753		}
1754		msg_set_max_pkt(hdr, l->advertised_mtu);
1755		strcpy(data, l->if_name);
1756		msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
1757		skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
1758	}
1759	if (probe)
1760		l->stats.sent_probes++;
1761	if (rcvgap)
1762		l->stats.sent_nacks++;
1763	skb->priority = TC_PRIO_CONTROL;
1764	__skb_queue_tail(xmitq, skb);
1765	trace_tipc_proto_build(skb, false, l->name);
1766}
1767
1768void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
1769				    struct sk_buff_head *xmitq)
1770{
1771	u32 onode = tipc_own_addr(l->net);
1772	struct tipc_msg *hdr, *ihdr;
1773	struct sk_buff_head tnlq;
1774	struct sk_buff *skb;
1775	u32 dnode = l->addr;
1776
1777	__skb_queue_head_init(&tnlq);
1778	skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG,
1779			      INT_H_SIZE, BASIC_H_SIZE,
1780			      dnode, onode, 0, 0, 0);
1781	if (!skb) {
1782		pr_warn("%sunable to create tunnel packet\n", link_co_err);
1783		return;
1784	}
1785
1786	hdr = buf_msg(skb);
1787	msg_set_msgcnt(hdr, 1);
1788	msg_set_bearer_id(hdr, l->peer_bearer_id);
1789
1790	ihdr = (struct tipc_msg *)msg_data(hdr);
1791	tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
1792		      BASIC_H_SIZE, dnode);
1793	msg_set_errcode(ihdr, TIPC_ERR_NO_PORT);
1794	__skb_queue_tail(&tnlq, skb);
1795	tipc_link_xmit(l, &tnlq, xmitq);
1796}
1797
1798/* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets
1799 * with contents of the link's transmit and backlog queues.
1800 */
1801void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1802			   int mtyp, struct sk_buff_head *xmitq)
1803{
1804	struct sk_buff_head *fdefq = &tnl->failover_deferdq;
1805	struct sk_buff *skb, *tnlskb;
1806	struct tipc_msg *hdr, tnlhdr;
1807	struct sk_buff_head *queue = &l->transmq;
1808	struct sk_buff_head tmpxq, tnlq, frags;
1809	u16 pktlen, pktcnt, seqno = l->snd_nxt;
1810	bool pktcnt_need_update = false;
1811	u16 syncpt;
1812	int rc;
1813
1814	if (!tnl)
1815		return;
1816
1817	__skb_queue_head_init(&tnlq);
1818	/* Link Synching:
1819	 * From now on, send only one single ("dummy") SYNCH message
1820	 * to peer. The SYNCH message does not contain any data, just
1821	 * a header conveying the synch point to the peer.
1822	 */
1823	if (mtyp == SYNCH_MSG && (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
1824		tnlskb = tipc_msg_c

Large files files are truncated, but you can click here to view the full file