1b97bf3fdSPer Liden /*
2b97bf3fdSPer Liden * net/tipc/link.c: TIPC link code
3b97bf3fdSPer Liden *
4e74a386dSJon Paul Maloy * Copyright (c) 1996-2007, 2012-2016, Ericsson AB
5198d73b8SYing Xue * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
6b97bf3fdSPer Liden * All rights reserved.
7b97bf3fdSPer Liden *
8b97bf3fdSPer Liden * Redistribution and use in source and binary forms, with or without
9b97bf3fdSPer Liden * modification, are permitted provided that the following conditions are met:
10b97bf3fdSPer Liden *
119ea1fd3cSPer Liden * 1. Redistributions of source code must retain the above copyright
129ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer.
139ea1fd3cSPer Liden * 2. Redistributions in binary form must reproduce the above copyright
149ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer in the
159ea1fd3cSPer Liden * documentation and/or other materials provided with the distribution.
169ea1fd3cSPer Liden * 3. Neither the names of the copyright holders nor the names of its
179ea1fd3cSPer Liden * contributors may be used to endorse or promote products derived from
189ea1fd3cSPer Liden * this software without specific prior written permission.
199ea1fd3cSPer Liden *
209ea1fd3cSPer Liden * Alternatively, this software may be distributed under the terms of the
219ea1fd3cSPer Liden * GNU General Public License ("GPL") version 2 as published by the Free
229ea1fd3cSPer Liden * Software Foundation.
23b97bf3fdSPer Liden *
24b97bf3fdSPer Liden * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25b97bf3fdSPer Liden * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26b97bf3fdSPer Liden * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27b97bf3fdSPer Liden * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28b97bf3fdSPer Liden * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29b97bf3fdSPer Liden * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30b97bf3fdSPer Liden * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31b97bf3fdSPer Liden * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32b97bf3fdSPer Liden * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33b97bf3fdSPer Liden * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34b97bf3fdSPer Liden * POSSIBILITY OF SUCH DAMAGE.
35b97bf3fdSPer Liden */
36b97bf3fdSPer Liden
37b97bf3fdSPer Liden #include "core.h"
38e3eea1ebSJon Paul Maloy #include "subscr.h"
39b97bf3fdSPer Liden #include "link.h"
407be57fc6SRichard Alpe #include "bcast.h"
419816f061SJon Paul Maloy #include "socket.h"
42b97bf3fdSPer Liden #include "name_distr.h"
43b97bf3fdSPer Liden #include "discover.h"
440655f6a8SRichard Alpe #include "netlink.h"
4535c55c98SJon Paul Maloy #include "monitor.h"
46b4b9771bSTuong Lien #include "trace.h"
47fc1b6d6dSTuong Lien #include "crypto.h"
48b97bf3fdSPer Liden
49796c75d0SYing Xue #include <linux/pkt_sched.h>
50796c75d0SYing Xue
5138206d59SJon Paul Maloy struct tipc_stats {
5295901122SJon Paul Maloy u32 sent_pkts;
5395901122SJon Paul Maloy u32 recv_pkts;
5438206d59SJon Paul Maloy u32 sent_states;
5538206d59SJon Paul Maloy u32 recv_states;
5638206d59SJon Paul Maloy u32 sent_probes;
5738206d59SJon Paul Maloy u32 recv_probes;
5838206d59SJon Paul Maloy u32 sent_nacks;
5938206d59SJon Paul Maloy u32 recv_nacks;
6038206d59SJon Paul Maloy u32 sent_acks;
6138206d59SJon Paul Maloy u32 sent_bundled;
6238206d59SJon Paul Maloy u32 sent_bundles;
6338206d59SJon Paul Maloy u32 recv_bundled;
6438206d59SJon Paul Maloy u32 recv_bundles;
6538206d59SJon Paul Maloy u32 retransmitted;
6638206d59SJon Paul Maloy u32 sent_fragmented;
6738206d59SJon Paul Maloy u32 sent_fragments;
6838206d59SJon Paul Maloy u32 recv_fragmented;
6938206d59SJon Paul Maloy u32 recv_fragments;
7038206d59SJon Paul Maloy u32 link_congs; /* # port sends blocked by congestion */
7138206d59SJon Paul Maloy u32 deferred_recv;
7238206d59SJon Paul Maloy u32 duplicates;
7338206d59SJon Paul Maloy u32 max_queue_sz; /* send queue size high water mark */
7438206d59SJon Paul Maloy u32 accu_queue_sz; /* used for send queue size profiling */
7538206d59SJon Paul Maloy u32 queue_sz_counts; /* used for send queue size profiling */
7638206d59SJon Paul Maloy u32 msg_length_counts; /* used for message length profiling */
7738206d59SJon Paul Maloy u32 msg_lengths_total; /* used for message length profiling */
7838206d59SJon Paul Maloy u32 msg_length_profile[7]; /* used for msg. length profiling */
7938206d59SJon Paul Maloy };
8038206d59SJon Paul Maloy
8138206d59SJon Paul Maloy /**
8238206d59SJon Paul Maloy * struct tipc_link - TIPC link data structure
8338206d59SJon Paul Maloy * @addr: network address of link's peer node
8438206d59SJon Paul Maloy * @name: link name character string
8538206d59SJon Paul Maloy * @media_addr: media address to use when sending messages over link
8638206d59SJon Paul Maloy * @timer: link timer
8738206d59SJon Paul Maloy * @net: pointer to namespace struct
8838206d59SJon Paul Maloy * @refcnt: reference counter for permanent references (owner node & timer)
8938206d59SJon Paul Maloy * @peer_session: link session # being used by peer end of link
9038206d59SJon Paul Maloy * @peer_bearer_id: bearer id used by link's peer endpoint
9138206d59SJon Paul Maloy * @bearer_id: local bearer id used by link
9238206d59SJon Paul Maloy * @tolerance: minimum link continuity loss needed to reset link [in ms]
9338206d59SJon Paul Maloy * @abort_limit: # of unacknowledged continuity probes needed to reset link
9438206d59SJon Paul Maloy * @state: current state of link FSM
9538206d59SJon Paul Maloy * @peer_caps: bitmap describing capabilities of peer node
9638206d59SJon Paul Maloy * @silent_intv_cnt: # of timer intervals without any reception from peer
9738206d59SJon Paul Maloy * @proto_msg: template for control messages generated by link
9838206d59SJon Paul Maloy * @pmsg: convenience pointer to "proto_msg" field
9938206d59SJon Paul Maloy * @priority: current link priority
10038206d59SJon Paul Maloy * @net_plane: current link network plane ('A' through 'H')
10135c55c98SJon Paul Maloy * @mon_state: cookie with information needed by link monitor
10238206d59SJon Paul Maloy * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
10338206d59SJon Paul Maloy * @exp_msg_count: # of tunnelled messages expected during link changeover
10438206d59SJon Paul Maloy * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
10538206d59SJon Paul Maloy * @mtu: current maximum packet size for this link
10638206d59SJon Paul Maloy * @advertised_mtu: advertised own mtu when link is being established
10738206d59SJon Paul Maloy * @transmitq: queue for sent, non-acked messages
10838206d59SJon Paul Maloy * @backlogq: queue for messages waiting to be sent
10938206d59SJon Paul Maloy * @snt_nxt: next sequence number to use for outbound messages
11038206d59SJon Paul Maloy * @ackers: # of peers that needs to ack each packet before it can be released
11138206d59SJon Paul Maloy * @acked: # last packet acked by a certain peer. Used for broadcast.
11238206d59SJon Paul Maloy * @rcv_nxt: next sequence number to expect for inbound messages
11338206d59SJon Paul Maloy * @deferred_queue: deferred queue saved OOS b'cast message received from node
11438206d59SJon Paul Maloy * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
11538206d59SJon Paul Maloy * @inputq: buffer queue for messages to be delivered upwards
11638206d59SJon Paul Maloy * @namedq: buffer queue for name table messages to be delivered upwards
11738206d59SJon Paul Maloy * @next_out: ptr to first unsent outbound message in queue
11838206d59SJon Paul Maloy * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
11938206d59SJon Paul Maloy * @long_msg_seq_no: next identifier to use for outbound fragmented messages
12038206d59SJon Paul Maloy * @reasm_buf: head of partially reassembled inbound message fragments
12138206d59SJon Paul Maloy * @bc_rcvr: marks that this is a broadcast receiver link
12238206d59SJon Paul Maloy * @stats: collects statistics regarding link activity
123a99df449SRandy Dunlap * @session: session to be used by link
124a99df449SRandy Dunlap * @snd_nxt_state: next send seq number
125a99df449SRandy Dunlap * @rcv_nxt_state: next rcv seq number
126a99df449SRandy Dunlap * @in_session: have received ACTIVATE_MSG from peer
127a99df449SRandy Dunlap * @active: link is active
128a99df449SRandy Dunlap * @if_name: associated interface name
129a99df449SRandy Dunlap * @rst_cnt: link reset counter
130a99df449SRandy Dunlap * @drop_point: seq number for failover handling (FIXME)
131a99df449SRandy Dunlap * @failover_reasm_skb: saved failover msg ptr (FIXME)
132a99df449SRandy Dunlap * @failover_deferdq: deferred message queue for failover processing (FIXME)
133a99df449SRandy Dunlap * @transmq: the link's transmit queue
134a99df449SRandy Dunlap * @backlog: link's backlog by priority (importance)
135a99df449SRandy Dunlap * @snd_nxt: next sequence number to be used
136a99df449SRandy Dunlap * @rcv_unacked: # messages read by user, but not yet acked back to peer
137a99df449SRandy Dunlap * @deferdq: deferred receive queue
138a99df449SRandy Dunlap * @window: sliding window size for congestion handling
139a99df449SRandy Dunlap * @min_win: minimal send window to be used by link
140a99df449SRandy Dunlap * @ssthresh: slow start threshold for congestion handling
141a99df449SRandy Dunlap * @max_win: maximal send window to be used by link
142a99df449SRandy Dunlap * @cong_acks: congestion acks for congestion avoidance (FIXME)
143a99df449SRandy Dunlap * @checkpoint: seq number for congestion window size handling
144a99df449SRandy Dunlap * @reasm_tnlmsg: fragmentation/reassembly area for tunnel protocol message
145a99df449SRandy Dunlap * @last_gap: last gap ack blocks for bcast (FIXME)
146a99df449SRandy Dunlap * @last_ga: ptr to gap ack blocks
147a99df449SRandy Dunlap * @bc_rcvlink: the peer specific link used for broadcast reception
148a99df449SRandy Dunlap * @bc_sndlink: the namespace global link used for broadcast sending
149a99df449SRandy Dunlap * @nack_state: bcast nack state
150a99df449SRandy Dunlap * @bc_peer_is_up: peer has acked the bcast init msg
15138206d59SJon Paul Maloy */
15238206d59SJon Paul Maloy struct tipc_link {
15338206d59SJon Paul Maloy u32 addr;
15438206d59SJon Paul Maloy char name[TIPC_MAX_LINK_NAME];
15538206d59SJon Paul Maloy struct net *net;
15638206d59SJon Paul Maloy
15738206d59SJon Paul Maloy /* Management and link supervision data */
1587ea817f4SJon Maloy u16 peer_session;
1597ea817f4SJon Maloy u16 session;
1609012de50SJon Maloy u16 snd_nxt_state;
1619012de50SJon Maloy u16 rcv_nxt_state;
16238206d59SJon Paul Maloy u32 peer_bearer_id;
16338206d59SJon Paul Maloy u32 bearer_id;
16438206d59SJon Paul Maloy u32 tolerance;
16538206d59SJon Paul Maloy u32 abort_limit;
16638206d59SJon Paul Maloy u32 state;
16738206d59SJon Paul Maloy u16 peer_caps;
1687ea817f4SJon Maloy bool in_session;
16938206d59SJon Paul Maloy bool active;
17038206d59SJon Paul Maloy u32 silent_intv_cnt;
171e74a386dSJon Paul Maloy char if_name[TIPC_MAX_IF_NAME];
17238206d59SJon Paul Maloy u32 priority;
17338206d59SJon Paul Maloy char net_plane;
17435c55c98SJon Paul Maloy struct tipc_mon_state mon_state;
17588e8ac70SJon Paul Maloy u16 rst_cnt;
17638206d59SJon Paul Maloy
17738206d59SJon Paul Maloy /* Failover/synch */
17838206d59SJon Paul Maloy u16 drop_point;
17938206d59SJon Paul Maloy struct sk_buff *failover_reasm_skb;
18058ee86b8STuong Lien struct sk_buff_head failover_deferdq;
18138206d59SJon Paul Maloy
18238206d59SJon Paul Maloy /* Max packet negotiation */
18338206d59SJon Paul Maloy u16 mtu;
18438206d59SJon Paul Maloy u16 advertised_mtu;
18538206d59SJon Paul Maloy
18638206d59SJon Paul Maloy /* Sending */
18738206d59SJon Paul Maloy struct sk_buff_head transmq;
18838206d59SJon Paul Maloy struct sk_buff_head backlogq;
18938206d59SJon Paul Maloy struct {
19038206d59SJon Paul Maloy u16 len;
19138206d59SJon Paul Maloy u16 limit;
192e95584a8STuong Lien struct sk_buff *target_bskb;
19338206d59SJon Paul Maloy } backlog[5];
19438206d59SJon Paul Maloy u16 snd_nxt;
19538206d59SJon Paul Maloy
19638206d59SJon Paul Maloy /* Reception */
19738206d59SJon Paul Maloy u16 rcv_nxt;
19838206d59SJon Paul Maloy u32 rcv_unacked;
19938206d59SJon Paul Maloy struct sk_buff_head deferdq;
20038206d59SJon Paul Maloy struct sk_buff_head *inputq;
20138206d59SJon Paul Maloy struct sk_buff_head *namedq;
20238206d59SJon Paul Maloy
20338206d59SJon Paul Maloy /* Congestion handling */
20438206d59SJon Paul Maloy struct sk_buff_head wakeupq;
20516ad3f40SJon Maloy u16 window;
20616ad3f40SJon Maloy u16 min_win;
20716ad3f40SJon Maloy u16 ssthresh;
20816ad3f40SJon Maloy u16 max_win;
20916ad3f40SJon Maloy u16 cong_acks;
21016ad3f40SJon Maloy u16 checkpoint;
21138206d59SJon Paul Maloy
21238206d59SJon Paul Maloy /* Fragmentation/reassembly */
21338206d59SJon Paul Maloy struct sk_buff *reasm_buf;
2142320bcdaSTuong Lien struct sk_buff *reasm_tnlmsg;
21538206d59SJon Paul Maloy
21638206d59SJon Paul Maloy /* Broadcast */
21738206d59SJon Paul Maloy u16 ackers;
21838206d59SJon Paul Maloy u16 acked;
219d7626b5aSTuong Lien u16 last_gap;
220d7626b5aSTuong Lien struct tipc_gap_ack_blks *last_ga;
22138206d59SJon Paul Maloy struct tipc_link *bc_rcvlink;
22238206d59SJon Paul Maloy struct tipc_link *bc_sndlink;
2237c4a54b9SJon Paul Maloy u8 nack_state;
22438206d59SJon Paul Maloy bool bc_peer_is_up;
22538206d59SJon Paul Maloy
22638206d59SJon Paul Maloy /* Statistics */
22738206d59SJon Paul Maloy struct tipc_stats stats;
22838206d59SJon Paul Maloy };
22938206d59SJon Paul Maloy
2302cf8aa19SErik Hugne /*
2312cf8aa19SErik Hugne * Error message prefixes
2322cf8aa19SErik Hugne */
2336e498158SJon Paul Maloy static const char *link_co_err = "Link tunneling error, ";
2342cf8aa19SErik Hugne static const char *link_rst_msg = "Resetting link ";
2357be57fc6SRichard Alpe
23652666986SJon Paul Maloy /* Send states for broadcast NACKs
23752666986SJon Paul Maloy */
23852666986SJon Paul Maloy enum {
23952666986SJon Paul Maloy BC_NACK_SND_CONDITIONAL,
24052666986SJon Paul Maloy BC_NACK_SND_UNCONDITIONAL,
24152666986SJon Paul Maloy BC_NACK_SND_SUPPRESS,
24252666986SJon Paul Maloy };
24352666986SJon Paul Maloy
24453962bceSJon Maloy #define TIPC_BC_RETR_LIM (jiffies + msecs_to_jiffies(10))
245382f598fSTuong Lien #define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1))
2467c4a54b9SJon Paul Maloy
247662921cdSJon Paul Maloy /* Link FSM states:
248d3504c34SJon Paul Maloy */
249d3504c34SJon Paul Maloy enum {
250662921cdSJon Paul Maloy LINK_ESTABLISHED = 0xe,
251662921cdSJon Paul Maloy LINK_ESTABLISHING = 0xe << 4,
252662921cdSJon Paul Maloy LINK_RESET = 0x1 << 8,
253662921cdSJon Paul Maloy LINK_RESETTING = 0x2 << 12,
254662921cdSJon Paul Maloy LINK_PEER_RESET = 0xd << 16,
255662921cdSJon Paul Maloy LINK_FAILINGOVER = 0xf << 20,
256662921cdSJon Paul Maloy LINK_SYNCHING = 0xc << 24
257d3504c34SJon Paul Maloy };
258d3504c34SJon Paul Maloy
259d3504c34SJon Paul Maloy /* Link FSM state checking routines
260d3504c34SJon Paul Maloy */
link_is_up(struct tipc_link * l)261662921cdSJon Paul Maloy static int link_is_up(struct tipc_link *l)
262d3504c34SJon Paul Maloy {
263662921cdSJon Paul Maloy return l->state & (LINK_ESTABLISHED | LINK_SYNCHING);
264d3504c34SJon Paul Maloy }
265d3504c34SJon Paul Maloy
266d999297cSJon Paul Maloy static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
267d999297cSJon Paul Maloy struct sk_buff_head *xmitq);
268426cc2b8SJon Paul Maloy static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
2698d6e79d3SJon Maloy bool probe_reply, u16 rcvgap,
2708d6e79d3SJon Maloy int tolerance, int priority,
271426cc2b8SJon Paul Maloy struct sk_buff_head *xmitq);
2721a90632dSJon Paul Maloy static void link_print(struct tipc_link *l, const char *str);
273e0a05ebeSJon Paul Maloy static int tipc_link_build_nack_msg(struct tipc_link *l,
27452666986SJon Paul Maloy struct sk_buff_head *xmitq);
27552666986SJon Paul Maloy static void tipc_link_build_bc_init_msg(struct tipc_link *l,
27652666986SJon Paul Maloy struct sk_buff_head *xmitq);
277d7626b5aSTuong Lien static u8 __tipc_build_gap_ack_blks(struct tipc_gap_ack_blks *ga,
278d7626b5aSTuong Lien struct tipc_link *l, u8 start_index);
279d7626b5aSTuong Lien static u16 tipc_build_gap_ack_blks(struct tipc_link *l, struct tipc_msg *hdr);
280d7626b5aSTuong Lien static int tipc_link_advance_transmq(struct tipc_link *l, struct tipc_link *r,
281d7626b5aSTuong Lien u16 acked, u16 gap,
2829195948fSTuong Lien struct tipc_gap_ack_blks *ga,
283d7626b5aSTuong Lien struct sk_buff_head *xmitq,
284d7626b5aSTuong Lien bool *retransmitted, int *rc);
28516ad3f40SJon Maloy static void tipc_link_update_cwin(struct tipc_link *l, int released,
28616ad3f40SJon Maloy bool retransmitted);
287b97bf3fdSPer Liden /*
28805790c64SSam Ravnborg * Simple non-static link routines (i.e. referenced outside this file)
289b97bf3fdSPer Liden */
tipc_link_is_up(struct tipc_link * l)290662921cdSJon Paul Maloy bool tipc_link_is_up(struct tipc_link *l)
291b97bf3fdSPer Liden {
292662921cdSJon Paul Maloy return link_is_up(l);
293662921cdSJon Paul Maloy }
294662921cdSJon Paul Maloy
tipc_link_peer_is_down(struct tipc_link * l)295c8199300SJon Paul Maloy bool tipc_link_peer_is_down(struct tipc_link *l)
296c8199300SJon Paul Maloy {
297c8199300SJon Paul Maloy return l->state == LINK_PEER_RESET;
298c8199300SJon Paul Maloy }
299c8199300SJon Paul Maloy
tipc_link_is_reset(struct tipc_link * l)300662921cdSJon Paul Maloy bool tipc_link_is_reset(struct tipc_link *l)
301662921cdSJon Paul Maloy {
302662921cdSJon Paul Maloy return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
303662921cdSJon Paul Maloy }
304662921cdSJon Paul Maloy
tipc_link_is_establishing(struct tipc_link * l)30573f646ceSJon Paul Maloy bool tipc_link_is_establishing(struct tipc_link *l)
30673f646ceSJon Paul Maloy {
30773f646ceSJon Paul Maloy return l->state == LINK_ESTABLISHING;
30873f646ceSJon Paul Maloy }
30973f646ceSJon Paul Maloy
tipc_link_is_synching(struct tipc_link * l)310662921cdSJon Paul Maloy bool tipc_link_is_synching(struct tipc_link *l)
311662921cdSJon Paul Maloy {
312662921cdSJon Paul Maloy return l->state == LINK_SYNCHING;
313662921cdSJon Paul Maloy }
314662921cdSJon Paul Maloy
tipc_link_is_failingover(struct tipc_link * l)315662921cdSJon Paul Maloy bool tipc_link_is_failingover(struct tipc_link *l)
316662921cdSJon Paul Maloy {
317662921cdSJon Paul Maloy return l->state == LINK_FAILINGOVER;
318662921cdSJon Paul Maloy }
319662921cdSJon Paul Maloy
tipc_link_is_blocked(struct tipc_link * l)320662921cdSJon Paul Maloy bool tipc_link_is_blocked(struct tipc_link *l)
321662921cdSJon Paul Maloy {
322662921cdSJon Paul Maloy return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER);
323b97bf3fdSPer Liden }
324b97bf3fdSPer Liden
link_is_bc_sndlink(struct tipc_link * l)325742e0383SWu Fengguang static bool link_is_bc_sndlink(struct tipc_link *l)
32652666986SJon Paul Maloy {
32752666986SJon Paul Maloy return !l->bc_sndlink;
32852666986SJon Paul Maloy }
32952666986SJon Paul Maloy
link_is_bc_rcvlink(struct tipc_link * l)330742e0383SWu Fengguang static bool link_is_bc_rcvlink(struct tipc_link *l)
33152666986SJon Paul Maloy {
33252666986SJon Paul Maloy return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l));
33352666986SJon Paul Maloy }
33452666986SJon Paul Maloy
tipc_link_set_active(struct tipc_link * l,bool active)335c72fa872SJon Paul Maloy void tipc_link_set_active(struct tipc_link *l, bool active)
336c72fa872SJon Paul Maloy {
337c72fa872SJon Paul Maloy l->active = active;
338b97bf3fdSPer Liden }
339b97bf3fdSPer Liden
tipc_link_id(struct tipc_link * l)34038206d59SJon Paul Maloy u32 tipc_link_id(struct tipc_link *l)
34138206d59SJon Paul Maloy {
34238206d59SJon Paul Maloy return l->peer_bearer_id << 16 | l->bearer_id;
34338206d59SJon Paul Maloy }
34438206d59SJon Paul Maloy
tipc_link_min_win(struct tipc_link * l)34516ad3f40SJon Maloy int tipc_link_min_win(struct tipc_link *l)
34638206d59SJon Paul Maloy {
34716ad3f40SJon Maloy return l->min_win;
34816ad3f40SJon Maloy }
34916ad3f40SJon Maloy
tipc_link_max_win(struct tipc_link * l)35016ad3f40SJon Maloy int tipc_link_max_win(struct tipc_link *l)
35116ad3f40SJon Maloy {
35216ad3f40SJon Maloy return l->max_win;
35338206d59SJon Paul Maloy }
35438206d59SJon Paul Maloy
tipc_link_prio(struct tipc_link * l)35538206d59SJon Paul Maloy int tipc_link_prio(struct tipc_link *l)
35638206d59SJon Paul Maloy {
35738206d59SJon Paul Maloy return l->priority;
35838206d59SJon Paul Maloy }
35938206d59SJon Paul Maloy
tipc_link_tolerance(struct tipc_link * l)36038206d59SJon Paul Maloy unsigned long tipc_link_tolerance(struct tipc_link *l)
36138206d59SJon Paul Maloy {
36238206d59SJon Paul Maloy return l->tolerance;
36338206d59SJon Paul Maloy }
36438206d59SJon Paul Maloy
tipc_link_inputq(struct tipc_link * l)36538206d59SJon Paul Maloy struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
36638206d59SJon Paul Maloy {
36738206d59SJon Paul Maloy return l->inputq;
36838206d59SJon Paul Maloy }
36938206d59SJon Paul Maloy
tipc_link_plane(struct tipc_link * l)37038206d59SJon Paul Maloy char tipc_link_plane(struct tipc_link *l)
37138206d59SJon Paul Maloy {
37238206d59SJon Paul Maloy return l->net_plane;
37338206d59SJon Paul Maloy }
37438206d59SJon Paul Maloy
tipc_link_net(struct tipc_link * l)375be07f056SXin Long struct net *tipc_link_net(struct tipc_link *l)
376be07f056SXin Long {
377be07f056SXin Long return l->net;
378be07f056SXin Long }
379be07f056SXin Long
tipc_link_update_caps(struct tipc_link * l,u16 capabilities)3809012de50SJon Maloy void tipc_link_update_caps(struct tipc_link *l, u16 capabilities)
3819012de50SJon Maloy {
3829012de50SJon Maloy l->peer_caps = capabilities;
3839012de50SJon Maloy }
3849012de50SJon Maloy
tipc_link_add_bc_peer(struct tipc_link * snd_l,struct tipc_link * uc_l,struct sk_buff_head * xmitq)38552666986SJon Paul Maloy void tipc_link_add_bc_peer(struct tipc_link *snd_l,
38652666986SJon Paul Maloy struct tipc_link *uc_l,
38752666986SJon Paul Maloy struct sk_buff_head *xmitq)
3882f566124SJon Paul Maloy {
38952666986SJon Paul Maloy struct tipc_link *rcv_l = uc_l->bc_rcvlink;
39052666986SJon Paul Maloy
39152666986SJon Paul Maloy snd_l->ackers++;
39252666986SJon Paul Maloy rcv_l->acked = snd_l->snd_nxt - 1;
3939a650838SJon Paul Maloy snd_l->state = LINK_ESTABLISHED;
39452666986SJon Paul Maloy tipc_link_build_bc_init_msg(uc_l, xmitq);
3952f566124SJon Paul Maloy }
3962f566124SJon Paul Maloy
tipc_link_remove_bc_peer(struct tipc_link * snd_l,struct tipc_link * rcv_l,struct sk_buff_head * xmitq)39752666986SJon Paul Maloy void tipc_link_remove_bc_peer(struct tipc_link *snd_l,
39852666986SJon Paul Maloy struct tipc_link *rcv_l,
39952666986SJon Paul Maloy struct sk_buff_head *xmitq)
4002f566124SJon Paul Maloy {
40152666986SJon Paul Maloy u16 ack = snd_l->snd_nxt - 1;
40252666986SJon Paul Maloy
40352666986SJon Paul Maloy snd_l->ackers--;
404a71eb720SJon Paul Maloy rcv_l->bc_peer_is_up = true;
405a71eb720SJon Paul Maloy rcv_l->state = LINK_ESTABLISHED;
406a91d55d1STuong Lien tipc_link_bc_ack_rcv(rcv_l, ack, 0, NULL, xmitq, NULL);
40726574db0STuong Lien trace_tipc_link_reset(rcv_l, TIPC_DUMP_ALL, "bclink removed!");
40852666986SJon Paul Maloy tipc_link_reset(rcv_l);
40952666986SJon Paul Maloy rcv_l->state = LINK_RESET;
41052666986SJon Paul Maloy if (!snd_l->ackers) {
41126574db0STuong Lien trace_tipc_link_reset(snd_l, TIPC_DUMP_ALL, "zero ackers!");
41252666986SJon Paul Maloy tipc_link_reset(snd_l);
4139a650838SJon Paul Maloy snd_l->state = LINK_RESET;
41452666986SJon Paul Maloy __skb_queue_purge(xmitq);
41552666986SJon Paul Maloy }
4162f566124SJon Paul Maloy }
4172f566124SJon Paul Maloy
tipc_link_bc_peers(struct tipc_link * l)4182f566124SJon Paul Maloy int tipc_link_bc_peers(struct tipc_link *l)
4192f566124SJon Paul Maloy {
4202f566124SJon Paul Maloy return l->ackers;
4212f566124SJon Paul Maloy }
4222f566124SJon Paul Maloy
link_bc_rcv_gap(struct tipc_link * l)423e064cce1SYueHaibing static u16 link_bc_rcv_gap(struct tipc_link *l)
42402d11ca2SJon Paul Maloy {
42502d11ca2SJon Paul Maloy struct sk_buff *skb = skb_peek(&l->deferdq);
42602d11ca2SJon Paul Maloy u16 gap = 0;
42702d11ca2SJon Paul Maloy
42802d11ca2SJon Paul Maloy if (more(l->snd_nxt, l->rcv_nxt))
42902d11ca2SJon Paul Maloy gap = l->snd_nxt - l->rcv_nxt;
43002d11ca2SJon Paul Maloy if (skb)
43102d11ca2SJon Paul Maloy gap = buf_seqno(skb) - l->rcv_nxt;
43202d11ca2SJon Paul Maloy return gap;
43302d11ca2SJon Paul Maloy }
43402d11ca2SJon Paul Maloy
tipc_link_set_mtu(struct tipc_link * l,int mtu)435959e1781SJon Paul Maloy void tipc_link_set_mtu(struct tipc_link *l, int mtu)
436959e1781SJon Paul Maloy {
437959e1781SJon Paul Maloy l->mtu = mtu;
438959e1781SJon Paul Maloy }
439959e1781SJon Paul Maloy
tipc_link_mtu(struct tipc_link * l)440959e1781SJon Paul Maloy int tipc_link_mtu(struct tipc_link *l)
441959e1781SJon Paul Maloy {
442959e1781SJon Paul Maloy return l->mtu;
443959e1781SJon Paul Maloy }
444959e1781SJon Paul Maloy
tipc_link_mss(struct tipc_link * l)445fc1b6d6dSTuong Lien int tipc_link_mss(struct tipc_link *l)
446fc1b6d6dSTuong Lien {
447fc1b6d6dSTuong Lien #ifdef CONFIG_TIPC_CRYPTO
448fc1b6d6dSTuong Lien return l->mtu - INT_H_SIZE - EMSG_OVERHEAD;
449fc1b6d6dSTuong Lien #else
450fc1b6d6dSTuong Lien return l->mtu - INT_H_SIZE;
451fc1b6d6dSTuong Lien #endif
452fc1b6d6dSTuong Lien }
453fc1b6d6dSTuong Lien
tipc_link_rcv_nxt(struct tipc_link * l)45438206d59SJon Paul Maloy u16 tipc_link_rcv_nxt(struct tipc_link *l)
45538206d59SJon Paul Maloy {
45638206d59SJon Paul Maloy return l->rcv_nxt;
45738206d59SJon Paul Maloy }
45838206d59SJon Paul Maloy
tipc_link_acked(struct tipc_link * l)45938206d59SJon Paul Maloy u16 tipc_link_acked(struct tipc_link *l)
46038206d59SJon Paul Maloy {
46138206d59SJon Paul Maloy return l->acked;
46238206d59SJon Paul Maloy }
46338206d59SJon Paul Maloy
tipc_link_name(struct tipc_link * l)46438206d59SJon Paul Maloy char *tipc_link_name(struct tipc_link *l)
46538206d59SJon Paul Maloy {
46638206d59SJon Paul Maloy return l->name;
46738206d59SJon Paul Maloy }
46838206d59SJon Paul Maloy
tipc_link_state(struct tipc_link * l)469c140eb16SLUU Duc Canh u32 tipc_link_state(struct tipc_link *l)
470c140eb16SLUU Duc Canh {
471c140eb16SLUU Duc Canh return l->state;
472c140eb16SLUU Duc Canh }
473c140eb16SLUU Duc Canh
474b97bf3fdSPer Liden /**
4754323add6SPer Liden * tipc_link_create - create a new link
476d8141208SAndrew Lunn * @net: pointer to associated network namespace
4770e05498eSJon Paul Maloy * @if_name: associated interface name
4780e05498eSJon Paul Maloy * @bearer_id: id (index) of associated bearer
4790e05498eSJon Paul Maloy * @tolerance: link tolerance to be used by link
4800e05498eSJon Paul Maloy * @net_plane: network plane (A,B,c..) this link belongs to
4810e05498eSJon Paul Maloy * @mtu: mtu to be advertised by link
4820e05498eSJon Paul Maloy * @priority: priority to be used by link
48316ad3f40SJon Maloy * @min_win: minimal send window to be used by link
48416ad3f40SJon Maloy * @max_win: maximal send window to be used by link
4850e05498eSJon Paul Maloy * @session: session to be used by link
4860e05498eSJon Paul Maloy * @peer: node id of peer node
487fd556f20SJon Paul Maloy * @peer_caps: bitmap describing peer node capabilities
48852666986SJon Paul Maloy * @bc_sndlink: the namespace global link used for broadcast sending
48952666986SJon Paul Maloy * @bc_rcvlink: the peer specific link used for broadcast reception
490440d8963SJon Paul Maloy * @inputq: queue to put messages ready for delivery
491440d8963SJon Paul Maloy * @namedq: queue to put binding table update messages ready for delivery
492440d8963SJon Paul Maloy * @link: return value, pointer to put the created link
493a99df449SRandy Dunlap * @self: local unicast link id
494a99df449SRandy Dunlap * @peer_id: 128-bit ID of peer
495b97bf3fdSPer Liden *
496637b77fdSRandy Dunlap * Return: true if link was created, otherwise false
497b97bf3fdSPer Liden */
tipc_link_create(struct net * net,char * if_name,int bearer_id,int tolerance,char net_plane,u32 mtu,int priority,u32 min_win,u32 max_win,u32 session,u32 self,u32 peer,u8 * peer_id,u16 peer_caps,struct tipc_link * bc_sndlink,struct tipc_link * bc_rcvlink,struct sk_buff_head * inputq,struct sk_buff_head * namedq,struct tipc_link ** link)498c72fa872SJon Paul Maloy bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
4990e05498eSJon Paul Maloy int tolerance, char net_plane, u32 mtu, int priority,
50016ad3f40SJon Maloy u32 min_win, u32 max_win, u32 session, u32 self,
50125b0b9c4SJon Maloy u32 peer, u8 *peer_id, u16 peer_caps,
50252666986SJon Paul Maloy struct tipc_link *bc_sndlink,
50352666986SJon Paul Maloy struct tipc_link *bc_rcvlink,
50452666986SJon Paul Maloy struct sk_buff_head *inputq,
50552666986SJon Paul Maloy struct sk_buff_head *namedq,
506440d8963SJon Paul Maloy struct tipc_link **link)
507b97bf3fdSPer Liden {
50825b0b9c4SJon Maloy char peer_str[NODE_ID_STR_LEN] = {0,};
50925b0b9c4SJon Maloy char self_str[NODE_ID_STR_LEN] = {0,};
510440d8963SJon Paul Maloy struct tipc_link *l;
51137b9c08aSAllan Stephens
512440d8963SJon Paul Maloy l = kzalloc(sizeof(*l), GFP_ATOMIC);
513440d8963SJon Paul Maloy if (!l)
514440d8963SJon Paul Maloy return false;
515440d8963SJon Paul Maloy *link = l;
516e74a386dSJon Paul Maloy l->session = session;
5170e05498eSJon Paul Maloy
51825b0b9c4SJon Maloy /* Set link name for unicast links only */
51925b0b9c4SJon Maloy if (peer_id) {
52025b0b9c4SJon Maloy tipc_nodeid2string(self_str, tipc_own_id(net));
521d50ccc2dSJon Maloy if (strlen(self_str) > 16)
52225b0b9c4SJon Maloy sprintf(self_str, "%x", self);
52325b0b9c4SJon Maloy tipc_nodeid2string(peer_str, peer_id);
52425b0b9c4SJon Maloy if (strlen(peer_str) > 16)
52525b0b9c4SJon Maloy sprintf(peer_str, "%x", peer);
52625b0b9c4SJon Maloy }
52725b0b9c4SJon Maloy /* Peer i/f name will be completed by reset/activate message */
5287494cfa6SJon Maloy snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
5297494cfa6SJon Maloy self_str, if_name, peer_str);
53025b0b9c4SJon Maloy
531e74a386dSJon Paul Maloy strcpy(l->if_name, if_name);
5320e05498eSJon Paul Maloy l->addr = peer;
533fd556f20SJon Paul Maloy l->peer_caps = peer_caps;
534c72fa872SJon Paul Maloy l->net = net;
5357ea817f4SJon Maloy l->in_session = false;
5360e05498eSJon Paul Maloy l->bearer_id = bearer_id;
5370e05498eSJon Paul Maloy l->tolerance = tolerance;
538047491eaSJon Maloy if (bc_rcvlink)
539047491eaSJon Maloy bc_rcvlink->tolerance = tolerance;
5400e05498eSJon Paul Maloy l->net_plane = net_plane;
5410e05498eSJon Paul Maloy l->advertised_mtu = mtu;
5420e05498eSJon Paul Maloy l->mtu = mtu;
5430e05498eSJon Paul Maloy l->priority = priority;
54416ad3f40SJon Maloy tipc_link_set_queue_limits(l, min_win, max_win);
545c1ab3f1dSJon Paul Maloy l->ackers = 1;
54652666986SJon Paul Maloy l->bc_sndlink = bc_sndlink;
54752666986SJon Paul Maloy l->bc_rcvlink = bc_rcvlink;
5480e05498eSJon Paul Maloy l->inputq = inputq;
5490e05498eSJon Paul Maloy l->namedq = namedq;
5500e05498eSJon Paul Maloy l->state = LINK_RESETTING;
551440d8963SJon Paul Maloy __skb_queue_head_init(&l->transmq);
552440d8963SJon Paul Maloy __skb_queue_head_init(&l->backlogq);
553440d8963SJon Paul Maloy __skb_queue_head_init(&l->deferdq);
55458ee86b8STuong Lien __skb_queue_head_init(&l->failover_deferdq);
555440d8963SJon Paul Maloy skb_queue_head_init(&l->wakeupq);
556440d8963SJon Paul Maloy skb_queue_head_init(l->inputq);
557440d8963SJon Paul Maloy return true;
558b97bf3fdSPer Liden }
559b97bf3fdSPer Liden
56032301906SJon Paul Maloy /**
56132301906SJon Paul Maloy * tipc_link_bc_create - create new link to be used for broadcast
562d8141208SAndrew Lunn * @net: pointer to associated network namespace
5634c94cc2dSJon Maloy * @mtu: mtu to be used initially if no peers
5642e5117baSLu Wei * @min_win: minimal send window to be used by link
5652e5117baSLu Wei * @max_win: maximal send window to be used by link
56632301906SJon Paul Maloy * @inputq: queue to put messages ready for delivery
56732301906SJon Paul Maloy * @namedq: queue to put binding table update messages ready for delivery
56832301906SJon Paul Maloy * @link: return value, pointer to put the created link
569a99df449SRandy Dunlap * @ownnode: identity of own node
570a99df449SRandy Dunlap * @peer: node id of peer node
571a99df449SRandy Dunlap * @peer_id: 128-bit ID of peer
572a99df449SRandy Dunlap * @peer_caps: bitmap describing peer node capabilities
573a99df449SRandy Dunlap * @bc_sndlink: the namespace global link used for broadcast sending
57432301906SJon Paul Maloy *
575637b77fdSRandy Dunlap * Return: true if link was created, otherwise false
57632301906SJon Paul Maloy */
tipc_link_bc_create(struct net * net,u32 ownnode,u32 peer,u8 * peer_id,int mtu,u32 min_win,u32 max_win,u16 peer_caps,struct sk_buff_head * inputq,struct sk_buff_head * namedq,struct tipc_link * bc_sndlink,struct tipc_link ** link)57703b6fefdSTuong Lien bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer, u8 *peer_id,
57816ad3f40SJon Maloy int mtu, u32 min_win, u32 max_win, u16 peer_caps,
57932301906SJon Paul Maloy struct sk_buff_head *inputq,
58032301906SJon Paul Maloy struct sk_buff_head *namedq,
58152666986SJon Paul Maloy struct tipc_link *bc_sndlink,
58232301906SJon Paul Maloy struct tipc_link **link)
58332301906SJon Paul Maloy {
58432301906SJon Paul Maloy struct tipc_link *l;
58532301906SJon Paul Maloy
58616ad3f40SJon Maloy if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, min_win,
58716ad3f40SJon Maloy max_win, 0, ownnode, peer, NULL, peer_caps,
58816ad3f40SJon Maloy bc_sndlink, NULL, inputq, namedq, link))
58932301906SJon Paul Maloy return false;
59032301906SJon Paul Maloy
59132301906SJon Paul Maloy l = *link;
59203b6fefdSTuong Lien if (peer_id) {
59303b6fefdSTuong Lien char peer_str[NODE_ID_STR_LEN] = {0,};
59403b6fefdSTuong Lien
59503b6fefdSTuong Lien tipc_nodeid2string(peer_str, peer_id);
59603b6fefdSTuong Lien if (strlen(peer_str) > 16)
59703b6fefdSTuong Lien sprintf(peer_str, "%x", peer);
59803b6fefdSTuong Lien /* Broadcast receiver link name: "broadcast-link:<peer>" */
59903b6fefdSTuong Lien snprintf(l->name, sizeof(l->name), "%s:%s", tipc_bclink_name,
60003b6fefdSTuong Lien peer_str);
60103b6fefdSTuong Lien } else {
60232301906SJon Paul Maloy strcpy(l->name, tipc_bclink_name);
60303b6fefdSTuong Lien }
60426574db0STuong Lien trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!");
60532301906SJon Paul Maloy tipc_link_reset(l);
60652666986SJon Paul Maloy l->state = LINK_RESET;
6072f566124SJon Paul Maloy l->ackers = 0;
60852666986SJon Paul Maloy l->bc_rcvlink = l;
60952666986SJon Paul Maloy
61052666986SJon Paul Maloy /* Broadcast send link is always up */
61152666986SJon Paul Maloy if (link_is_bc_sndlink(l))
61252666986SJon Paul Maloy l->state = LINK_ESTABLISHED;
61352666986SJon Paul Maloy
61401fd12bbSJon Paul Maloy /* Disable replicast if even a single peer doesn't support it */
61501fd12bbSJon Paul Maloy if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
616ba5f6a86SHoang Le tipc_bcast_toggle_rcast(net, false);
61701fd12bbSJon Paul Maloy
61832301906SJon Paul Maloy return true;
61932301906SJon Paul Maloy }
62032301906SJon Paul Maloy
621b97bf3fdSPer Liden /**
6226ab30f9cSJon Paul Maloy * tipc_link_fsm_evt - link finite state machine
6236ab30f9cSJon Paul Maloy * @l: pointer to link
6246ab30f9cSJon Paul Maloy * @evt: state machine event to be processed
6256ab30f9cSJon Paul Maloy */
tipc_link_fsm_evt(struct tipc_link * l,int evt)626662921cdSJon Paul Maloy int tipc_link_fsm_evt(struct tipc_link *l, int evt)
6276ab30f9cSJon Paul Maloy {
6285045f7b9SJon Paul Maloy int rc = 0;
62926574db0STuong Lien int old_state = l->state;
6306ab30f9cSJon Paul Maloy
6316ab30f9cSJon Paul Maloy switch (l->state) {
632662921cdSJon Paul Maloy case LINK_RESETTING:
6336ab30f9cSJon Paul Maloy switch (evt) {
634662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
635662921cdSJon Paul Maloy l->state = LINK_PEER_RESET;
6366ab30f9cSJon Paul Maloy break;
637662921cdSJon Paul Maloy case LINK_RESET_EVT:
638662921cdSJon Paul Maloy l->state = LINK_RESET;
6396ab30f9cSJon Paul Maloy break;
640662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
641662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
642662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
643662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
644662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
645662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
6466ab30f9cSJon Paul Maloy default:
647662921cdSJon Paul Maloy goto illegal_evt;
6486ab30f9cSJon Paul Maloy }
6496ab30f9cSJon Paul Maloy break;
650662921cdSJon Paul Maloy case LINK_RESET:
6516ab30f9cSJon Paul Maloy switch (evt) {
652662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
653662921cdSJon Paul Maloy l->state = LINK_ESTABLISHING;
6546ab30f9cSJon Paul Maloy break;
655662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
656662921cdSJon Paul Maloy l->state = LINK_FAILINGOVER;
6571c78ba49SGustavo A. R. Silva break;
658662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
659662921cdSJon Paul Maloy case LINK_RESET_EVT:
660662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
661662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
6626ab30f9cSJon Paul Maloy break;
663662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
664662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
6656ab30f9cSJon Paul Maloy default:
666662921cdSJon Paul Maloy goto illegal_evt;
6676ab30f9cSJon Paul Maloy }
6686ab30f9cSJon Paul Maloy break;
669662921cdSJon Paul Maloy case LINK_PEER_RESET:
6706ab30f9cSJon Paul Maloy switch (evt) {
671662921cdSJon Paul Maloy case LINK_RESET_EVT:
672662921cdSJon Paul Maloy l->state = LINK_ESTABLISHING;
6736ab30f9cSJon Paul Maloy break;
674662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
675662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
676662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
6776ab30f9cSJon Paul Maloy break;
678662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
679662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
680662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
681662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
6826ab30f9cSJon Paul Maloy default:
683662921cdSJon Paul Maloy goto illegal_evt;
6846ab30f9cSJon Paul Maloy }
6856ab30f9cSJon Paul Maloy break;
686662921cdSJon Paul Maloy case LINK_FAILINGOVER:
6876ab30f9cSJon Paul Maloy switch (evt) {
688662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
689662921cdSJon Paul Maloy l->state = LINK_RESET;
6906ab30f9cSJon Paul Maloy break;
691662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
692662921cdSJon Paul Maloy case LINK_RESET_EVT:
693662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
694662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
6956ab30f9cSJon Paul Maloy break;
696662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
697662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
698662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
6996ab30f9cSJon Paul Maloy default:
700662921cdSJon Paul Maloy goto illegal_evt;
701662921cdSJon Paul Maloy }
702662921cdSJon Paul Maloy break;
703662921cdSJon Paul Maloy case LINK_ESTABLISHING:
704662921cdSJon Paul Maloy switch (evt) {
705662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
706662921cdSJon Paul Maloy l->state = LINK_ESTABLISHED;
707662921cdSJon Paul Maloy break;
708662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
709662921cdSJon Paul Maloy l->state = LINK_FAILINGOVER;
710662921cdSJon Paul Maloy break;
711662921cdSJon Paul Maloy case LINK_RESET_EVT:
71273f646ceSJon Paul Maloy l->state = LINK_RESET;
71373f646ceSJon Paul Maloy break;
714662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
71573f646ceSJon Paul Maloy case LINK_PEER_RESET_EVT:
716662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
717662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
718662921cdSJon Paul Maloy break;
719662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
720662921cdSJon Paul Maloy default:
721662921cdSJon Paul Maloy goto illegal_evt;
722662921cdSJon Paul Maloy }
723662921cdSJon Paul Maloy break;
724662921cdSJon Paul Maloy case LINK_ESTABLISHED:
725662921cdSJon Paul Maloy switch (evt) {
726662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
727662921cdSJon Paul Maloy l->state = LINK_PEER_RESET;
728662921cdSJon Paul Maloy rc |= TIPC_LINK_DOWN_EVT;
729662921cdSJon Paul Maloy break;
730662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
731662921cdSJon Paul Maloy l->state = LINK_RESETTING;
732662921cdSJon Paul Maloy rc |= TIPC_LINK_DOWN_EVT;
733662921cdSJon Paul Maloy break;
734662921cdSJon Paul Maloy case LINK_RESET_EVT:
735662921cdSJon Paul Maloy l->state = LINK_RESET;
736662921cdSJon Paul Maloy break;
737662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
7385ae2f8e6SJon Paul Maloy case LINK_SYNCH_END_EVT:
739662921cdSJon Paul Maloy break;
740662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
741662921cdSJon Paul Maloy l->state = LINK_SYNCHING;
742662921cdSJon Paul Maloy break;
743662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
744662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
745662921cdSJon Paul Maloy default:
746662921cdSJon Paul Maloy goto illegal_evt;
747662921cdSJon Paul Maloy }
748662921cdSJon Paul Maloy break;
749662921cdSJon Paul Maloy case LINK_SYNCHING:
750662921cdSJon Paul Maloy switch (evt) {
751662921cdSJon Paul Maloy case LINK_PEER_RESET_EVT:
752662921cdSJon Paul Maloy l->state = LINK_PEER_RESET;
753662921cdSJon Paul Maloy rc |= TIPC_LINK_DOWN_EVT;
754662921cdSJon Paul Maloy break;
755662921cdSJon Paul Maloy case LINK_FAILURE_EVT:
756662921cdSJon Paul Maloy l->state = LINK_RESETTING;
757662921cdSJon Paul Maloy rc |= TIPC_LINK_DOWN_EVT;
758662921cdSJon Paul Maloy break;
759662921cdSJon Paul Maloy case LINK_RESET_EVT:
760662921cdSJon Paul Maloy l->state = LINK_RESET;
761662921cdSJon Paul Maloy break;
762662921cdSJon Paul Maloy case LINK_ESTABLISH_EVT:
763662921cdSJon Paul Maloy case LINK_SYNCH_BEGIN_EVT:
764662921cdSJon Paul Maloy break;
765662921cdSJon Paul Maloy case LINK_SYNCH_END_EVT:
766662921cdSJon Paul Maloy l->state = LINK_ESTABLISHED;
767662921cdSJon Paul Maloy break;
768662921cdSJon Paul Maloy case LINK_FAILOVER_BEGIN_EVT:
769662921cdSJon Paul Maloy case LINK_FAILOVER_END_EVT:
770662921cdSJon Paul Maloy default:
771662921cdSJon Paul Maloy goto illegal_evt;
7726ab30f9cSJon Paul Maloy }
7736ab30f9cSJon Paul Maloy break;
7746ab30f9cSJon Paul Maloy default:
775662921cdSJon Paul Maloy pr_err("Unknown FSM state %x in %s\n", l->state, l->name);
7766ab30f9cSJon Paul Maloy }
77726574db0STuong Lien trace_tipc_link_fsm(l->name, old_state, l->state, evt);
778662921cdSJon Paul Maloy return rc;
779662921cdSJon Paul Maloy illegal_evt:
780662921cdSJon Paul Maloy pr_err("Illegal FSM event %x in state %x on link %s\n",
781662921cdSJon Paul Maloy evt, l->state, l->name);
78226574db0STuong Lien trace_tipc_link_fsm(l->name, old_state, l->state, evt);
7836ab30f9cSJon Paul Maloy return rc;
7846ab30f9cSJon Paul Maloy }
7856ab30f9cSJon Paul Maloy
786333ef69eSJon Paul Maloy /* link_profile_stats - update statistical profiling of traffic
787333ef69eSJon Paul Maloy */
link_profile_stats(struct tipc_link * l)788333ef69eSJon Paul Maloy static void link_profile_stats(struct tipc_link *l)
789333ef69eSJon Paul Maloy {
790333ef69eSJon Paul Maloy struct sk_buff *skb;
791333ef69eSJon Paul Maloy struct tipc_msg *msg;
792333ef69eSJon Paul Maloy int length;
793333ef69eSJon Paul Maloy
794333ef69eSJon Paul Maloy /* Update counters used in statistical profiling of send traffic */
795333ef69eSJon Paul Maloy l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
796333ef69eSJon Paul Maloy l->stats.queue_sz_counts++;
797333ef69eSJon Paul Maloy
798333ef69eSJon Paul Maloy skb = skb_peek(&l->transmq);
799333ef69eSJon Paul Maloy if (!skb)
800333ef69eSJon Paul Maloy return;
801333ef69eSJon Paul Maloy msg = buf_msg(skb);
802333ef69eSJon Paul Maloy length = msg_size(msg);
803333ef69eSJon Paul Maloy
804333ef69eSJon Paul Maloy if (msg_user(msg) == MSG_FRAGMENTER) {
805333ef69eSJon Paul Maloy if (msg_type(msg) != FIRST_FRAGMENT)
806333ef69eSJon Paul Maloy return;
807a7dc51adSJon Maloy length = msg_size(msg_inner_hdr(msg));
808333ef69eSJon Paul Maloy }
809333ef69eSJon Paul Maloy l->stats.msg_lengths_total += length;
810333ef69eSJon Paul Maloy l->stats.msg_length_counts++;
811333ef69eSJon Paul Maloy if (length <= 64)
812333ef69eSJon Paul Maloy l->stats.msg_length_profile[0]++;
813333ef69eSJon Paul Maloy else if (length <= 256)
814333ef69eSJon Paul Maloy l->stats.msg_length_profile[1]++;
815333ef69eSJon Paul Maloy else if (length <= 1024)
816333ef69eSJon Paul Maloy l->stats.msg_length_profile[2]++;
817333ef69eSJon Paul Maloy else if (length <= 4096)
818333ef69eSJon Paul Maloy l->stats.msg_length_profile[3]++;
819333ef69eSJon Paul Maloy else if (length <= 16384)
820333ef69eSJon Paul Maloy l->stats.msg_length_profile[4]++;
821333ef69eSJon Paul Maloy else if (length <= 32768)
822333ef69eSJon Paul Maloy l->stats.msg_length_profile[5]++;
823333ef69eSJon Paul Maloy else
824333ef69eSJon Paul Maloy l->stats.msg_length_profile[6]++;
825333ef69eSJon Paul Maloy }
826333ef69eSJon Paul Maloy
82726574db0STuong Lien /**
82826574db0STuong Lien * tipc_link_too_silent - check if link is "too silent"
82926574db0STuong Lien * @l: tipc link to be checked
83026574db0STuong Lien *
831637b77fdSRandy Dunlap * Return: true if the link 'silent_intv_cnt' is about to reach the
83226574db0STuong Lien * 'abort_limit' value, otherwise false
83326574db0STuong Lien */
tipc_link_too_silent(struct tipc_link * l)83426574db0STuong Lien bool tipc_link_too_silent(struct tipc_link *l)
83526574db0STuong Lien {
83626574db0STuong Lien return (l->silent_intv_cnt + 2 > l->abort_limit);
83726574db0STuong Lien }
83826574db0STuong Lien
839333ef69eSJon Paul Maloy /* tipc_link_timeout - perform periodic task as instructed from node timeout
840333ef69eSJon Paul Maloy */
tipc_link_timeout(struct tipc_link * l,struct sk_buff_head * xmitq)841333ef69eSJon Paul Maloy int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
842333ef69eSJon Paul Maloy {
843c91522f8SYing Xue int mtyp = 0;
844c91522f8SYing Xue int rc = 0;
84542b18f60SJon Paul Maloy bool state = false;
84642b18f60SJon Paul Maloy bool probe = false;
84742b18f60SJon Paul Maloy bool setup = false;
84852666986SJon Paul Maloy u16 bc_snt = l->bc_sndlink->snd_nxt - 1;
84952666986SJon Paul Maloy u16 bc_acked = l->bc_rcvlink->acked;
85035c55c98SJon Paul Maloy struct tipc_mon_state *mstate = &l->mon_state;
8515045f7b9SJon Paul Maloy
85226574db0STuong Lien trace_tipc_link_timeout(l, TIPC_DUMP_NONE, " ");
85326574db0STuong Lien trace_tipc_link_too_silent(l, TIPC_DUMP_ALL, " ");
854662921cdSJon Paul Maloy switch (l->state) {
855662921cdSJon Paul Maloy case LINK_ESTABLISHED:
856662921cdSJon Paul Maloy case LINK_SYNCHING:
85742b18f60SJon Paul Maloy mtyp = STATE_MSG;
85835c55c98SJon Paul Maloy link_profile_stats(l);
85935c55c98SJon Paul Maloy tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id);
86035c55c98SJon Paul Maloy if (mstate->reset || (l->silent_intv_cnt > l->abort_limit))
86135c55c98SJon Paul Maloy return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
86242b18f60SJon Paul Maloy state = bc_acked != bc_snt;
86335c55c98SJon Paul Maloy state |= l->bc_rcvlink->rcv_unacked;
86435c55c98SJon Paul Maloy state |= l->rcv_unacked;
86535c55c98SJon Paul Maloy state |= !skb_queue_empty(&l->transmq);
86635c55c98SJon Paul Maloy probe = mstate->probing;
86735c55c98SJon Paul Maloy probe |= l->silent_intv_cnt;
86835c55c98SJon Paul Maloy if (probe || mstate->monitoring)
869333ef69eSJon Paul Maloy l->silent_intv_cnt++;
8706ef9dcb7STung Nguyen probe |= !skb_queue_empty(&l->deferdq);
87116ad3f40SJon Maloy if (l->snd_nxt == l->checkpoint) {
87216ad3f40SJon Maloy tipc_link_update_cwin(l, 0, 0);
87316ad3f40SJon Maloy probe = true;
87416ad3f40SJon Maloy }
87516ad3f40SJon Maloy l->checkpoint = l->snd_nxt;
876662921cdSJon Paul Maloy break;
877662921cdSJon Paul Maloy case LINK_RESET:
87842b18f60SJon Paul Maloy setup = l->rst_cnt++ <= 4;
87942b18f60SJon Paul Maloy setup |= !(l->rst_cnt % 16);
8805045f7b9SJon Paul Maloy mtyp = RESET_MSG;
881662921cdSJon Paul Maloy break;
882662921cdSJon Paul Maloy case LINK_ESTABLISHING:
88342b18f60SJon Paul Maloy setup = true;
8845045f7b9SJon Paul Maloy mtyp = ACTIVATE_MSG;
885662921cdSJon Paul Maloy break;
886662921cdSJon Paul Maloy case LINK_PEER_RESET:
887598411d7SJon Paul Maloy case LINK_RESETTING:
888662921cdSJon Paul Maloy case LINK_FAILINGOVER:
889662921cdSJon Paul Maloy break;
890662921cdSJon Paul Maloy default:
891662921cdSJon Paul Maloy break;
8925045f7b9SJon Paul Maloy }
893662921cdSJon Paul Maloy
89442b18f60SJon Paul Maloy if (state || probe || setup)
8958d6e79d3SJon Maloy tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq);
8965045f7b9SJon Paul Maloy
897333ef69eSJon Paul Maloy return rc;
898333ef69eSJon Paul Maloy }
899333ef69eSJon Paul Maloy
9006ab30f9cSJon Paul Maloy /**
9013127a020SJon Paul Maloy * link_schedule_user - schedule a message sender for wakeup after congestion
902365ad353SJon Paul Maloy * @l: congested link
903365ad353SJon Paul Maloy * @hdr: header of message that is being sent
90450100a5eSJon Paul Maloy * Create pseudo msg to send back to user when congestion abates
905b97bf3fdSPer Liden */
link_schedule_user(struct tipc_link * l,struct tipc_msg * hdr)906365ad353SJon Paul Maloy static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr)
907b97bf3fdSPer Liden {
908365ad353SJon Paul Maloy u32 dnode = tipc_own_addr(l->net);
909365ad353SJon Paul Maloy u32 dport = msg_origport(hdr);
9103127a020SJon Paul Maloy struct sk_buff *skb;
911b97bf3fdSPer Liden
9123127a020SJon Paul Maloy /* Create and schedule wakeup pseudo message */
9133127a020SJon Paul Maloy skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
914365ad353SJon Paul Maloy dnode, l->addr, dport, 0, 0);
9153127a020SJon Paul Maloy if (!skb)
91686704993SHoang Le return -ENOBUFS;
917365ad353SJon Paul Maloy msg_set_dest_droppable(buf_msg(skb), true);
918365ad353SJon Paul Maloy TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr);
919365ad353SJon Paul Maloy skb_queue_tail(&l->wakeupq, skb);
920365ad353SJon Paul Maloy l->stats.link_congs++;
92126574db0STuong Lien trace_tipc_link_conges(l, TIPC_DUMP_ALL, "wakeup scheduled!");
9223127a020SJon Paul Maloy return -ELINKCONG;
923b97bf3fdSPer Liden }
924b97bf3fdSPer Liden
92550100a5eSJon Paul Maloy /**
92650100a5eSJon Paul Maloy * link_prepare_wakeup - prepare users for wakeup after congestion
927365ad353SJon Paul Maloy * @l: congested link
928365ad353SJon Paul Maloy * Wake up a number of waiting users, as permitted by available space
929365ad353SJon Paul Maloy * in the send queue
93050100a5eSJon Paul Maloy */
link_prepare_wakeup(struct tipc_link * l)931e064cce1SYueHaibing static void link_prepare_wakeup(struct tipc_link *l)
932b97bf3fdSPer Liden {
9337c5b4205SJon Maloy struct sk_buff_head *wakeupq = &l->wakeupq;
9347c5b4205SJon Maloy struct sk_buff_head *inputq = l->inputq;
93558d78b32SYing Xue struct sk_buff *skb, *tmp;
9367c5b4205SJon Maloy struct sk_buff_head tmpq;
9377c5b4205SJon Maloy int avail[5] = {0,};
9387c5b4205SJon Maloy int imp = 0;
939b97bf3fdSPer Liden
9407c5b4205SJon Maloy __skb_queue_head_init(&tmpq);
9417c5b4205SJon Maloy
9427c5b4205SJon Maloy for (; imp <= TIPC_SYSTEM_IMPORTANCE; imp++)
9437c5b4205SJon Maloy avail[imp] = l->backlog[imp].limit - l->backlog[imp].len;
9447c5b4205SJon Maloy
9457c5b4205SJon Maloy skb_queue_walk_safe(wakeupq, skb, tmp) {
9461f66d161SJon Paul Maloy imp = TIPC_SKB_CB(skb)->chain_imp;
9477c5b4205SJon Maloy if (avail[imp] <= 0)
9487c5b4205SJon Maloy continue;
9497c5b4205SJon Maloy avail[imp]--;
9507c5b4205SJon Maloy __skb_unlink(skb, wakeupq);
9517c5b4205SJon Maloy __skb_queue_tail(&tmpq, skb);
952365ad353SJon Paul Maloy }
9537c5b4205SJon Maloy
9547c5b4205SJon Maloy spin_lock_bh(&inputq->lock);
9557c5b4205SJon Maloy skb_queue_splice_tail(&tmpq, inputq);
9567c5b4205SJon Maloy spin_unlock_bh(&inputq->lock);
9577c5b4205SJon Maloy
958b97bf3fdSPer Liden }
959b97bf3fdSPer Liden
960a34f8291SHamish Martin /**
961a34f8291SHamish Martin * tipc_link_set_skb_retransmit_time - set the time at which retransmission of
962a34f8291SHamish Martin * the given skb should be next attempted
963a34f8291SHamish Martin * @skb: skb to set a future retransmission time for
964a34f8291SHamish Martin * @l: link the skb will be transmitted on
965a34f8291SHamish Martin */
tipc_link_set_skb_retransmit_time(struct sk_buff * skb,struct tipc_link * l)966a34f8291SHamish Martin static void tipc_link_set_skb_retransmit_time(struct sk_buff *skb,
967a34f8291SHamish Martin struct tipc_link *l)
968a34f8291SHamish Martin {
969a34f8291SHamish Martin if (link_is_bc_sndlink(l))
970a34f8291SHamish Martin TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
971a34f8291SHamish Martin else
972a34f8291SHamish Martin TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME;
973a34f8291SHamish Martin }
974a34f8291SHamish Martin
tipc_link_reset(struct tipc_link * l)9756e498158SJon Paul Maloy void tipc_link_reset(struct tipc_link *l)
976b97bf3fdSPer Liden {
977a1f8dd34SYing Xue struct sk_buff_head list;
978e95584a8STuong Lien u32 imp;
979a1f8dd34SYing Xue
980a1f8dd34SYing Xue __skb_queue_head_init(&list);
981a1f8dd34SYing Xue
9827ea817f4SJon Maloy l->in_session = false;
983f7a93780STuong Lien /* Force re-synch of peer session number before establishing */
984f7a93780STuong Lien l->peer_session--;
985e74a386dSJon Paul Maloy l->session++;
9866e498158SJon Paul Maloy l->mtu = l->advertised_mtu;
987a1f8dd34SYing Xue
9883f32d0beSParthasarathy Bhuvaragan spin_lock_bh(&l->wakeupq.lock);
989a1f8dd34SYing Xue skb_queue_splice_init(&l->wakeupq, &list);
9903f32d0beSParthasarathy Bhuvaragan spin_unlock_bh(&l->wakeupq.lock);
9913f32d0beSParthasarathy Bhuvaragan
992a1f8dd34SYing Xue spin_lock_bh(&l->inputq->lock);
993a1f8dd34SYing Xue skb_queue_splice_init(&list, l->inputq);
994a1f8dd34SYing Xue spin_unlock_bh(&l->inputq->lock);
995a1f8dd34SYing Xue
9966e498158SJon Paul Maloy __skb_queue_purge(&l->transmq);
9976e498158SJon Paul Maloy __skb_queue_purge(&l->deferdq);
9982af5ae37SJon Paul Maloy __skb_queue_purge(&l->backlogq);
99958ee86b8STuong Lien __skb_queue_purge(&l->failover_deferdq);
1000e95584a8STuong Lien for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) {
1001e95584a8STuong Lien l->backlog[imp].len = 0;
1002e95584a8STuong Lien l->backlog[imp].target_bskb = NULL;
1003e95584a8STuong Lien }
10046e498158SJon Paul Maloy kfree_skb(l->reasm_buf);
10052320bcdaSTuong Lien kfree_skb(l->reasm_tnlmsg);
10066e498158SJon Paul Maloy kfree_skb(l->failover_reasm_skb);
10076e498158SJon Paul Maloy l->reasm_buf = NULL;
10082320bcdaSTuong Lien l->reasm_tnlmsg = NULL;
10096e498158SJon Paul Maloy l->failover_reasm_skb = NULL;
10106e498158SJon Paul Maloy l->rcv_unacked = 0;
10116e498158SJon Paul Maloy l->snd_nxt = 1;
10126e498158SJon Paul Maloy l->rcv_nxt = 1;
10139012de50SJon Maloy l->snd_nxt_state = 1;
10149012de50SJon Maloy l->rcv_nxt_state = 1;
1015c1ab3f1dSJon Paul Maloy l->acked = 0;
1016d7626b5aSTuong Lien l->last_gap = 0;
1017d7626b5aSTuong Lien kfree(l->last_ga);
1018d7626b5aSTuong Lien l->last_ga = NULL;
10196e498158SJon Paul Maloy l->silent_intv_cnt = 0;
102088e8ac70SJon Paul Maloy l->rst_cnt = 0;
102152666986SJon Paul Maloy l->bc_peer_is_up = false;
102235c55c98SJon Paul Maloy memset(&l->mon_state, 0, sizeof(l->mon_state));
102338206d59SJon Paul Maloy tipc_link_reset_stats(l);
1024b97bf3fdSPer Liden }
1025b97bf3fdSPer Liden
1026b97bf3fdSPer Liden /**
1027af9b028eSJon Paul Maloy * tipc_link_xmit(): enqueue buffer list according to queue situation
1028d8141208SAndrew Lunn * @l: link to use
1029af9b028eSJon Paul Maloy * @list: chain of buffers containing message
1030af9b028eSJon Paul Maloy * @xmitq: returned list of packets to be sent by caller
1031af9b028eSJon Paul Maloy *
1032365ad353SJon Paul Maloy * Consumes the buffer chain.
1033af9b028eSJon Paul Maloy * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
103486704993SHoang Le * Return: 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
1035af9b028eSJon Paul Maloy */
tipc_link_xmit(struct tipc_link * l,struct sk_buff_head * list,struct sk_buff_head * xmitq)1036af9b028eSJon Paul Maloy int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
1037af9b028eSJon Paul Maloy struct sk_buff_head *xmitq)
1038af9b028eSJon Paul Maloy {
103906e7c70cSTuong Lien struct sk_buff_head *backlogq = &l->backlogq;
104006e7c70cSTuong Lien struct sk_buff_head *transmq = &l->transmq;
104106e7c70cSTuong Lien struct sk_buff *skb, *_skb;
104206e7c70cSTuong Lien u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1043af9b028eSJon Paul Maloy u16 ack = l->rcv_nxt - 1;
1044af9b028eSJon Paul Maloy u16 seqno = l->snd_nxt;
104595901122SJon Paul Maloy int pkt_cnt = skb_queue_len(list);
1046fc1b6d6dSTuong Lien unsigned int mss = tipc_link_mss(l);
104716ad3f40SJon Maloy unsigned int cwin = l->window;
104806e7c70cSTuong Lien unsigned int mtu = l->mtu;
1049b7741344SHoang Le struct tipc_msg *hdr;
105006e7c70cSTuong Lien bool new_bundle;
1051365ad353SJon Paul Maloy int rc = 0;
1052b7741344SHoang Le int imp;
1053af9b028eSJon Paul Maloy
1054b7741344SHoang Le if (pkt_cnt <= 0)
1055b7741344SHoang Le return 0;
1056b7741344SHoang Le
1057b7741344SHoang Le hdr = buf_msg(skb_peek(list));
10584952cd3eSRichard Alpe if (unlikely(msg_size(hdr) > mtu)) {
10592320bcdaSTuong Lien pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n",
10602320bcdaSTuong Lien skb_queue_len(list), msg_user(hdr),
10612320bcdaSTuong Lien msg_type(hdr), msg_size(hdr), mtu);
1062e654f9f5SJon Maloy __skb_queue_purge(list);
1063af9b028eSJon Paul Maloy return -EMSGSIZE;
10644952cd3eSRichard Alpe }
1065af9b028eSJon Paul Maloy
1066b7741344SHoang Le imp = msg_importance(hdr);
1067365ad353SJon Paul Maloy /* Allow oversubscription of one data msg per source at congestion */
1068365ad353SJon Paul Maloy if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
1069365ad353SJon Paul Maloy if (imp == TIPC_SYSTEM_IMPORTANCE) {
1070365ad353SJon Paul Maloy pr_warn("%s<%s>, link overflow", link_rst_msg, l->name);
1071365ad353SJon Paul Maloy return -ENOBUFS;
1072365ad353SJon Paul Maloy }
1073365ad353SJon Paul Maloy rc = link_schedule_user(l, hdr);
1074365ad353SJon Paul Maloy }
1075365ad353SJon Paul Maloy
107695901122SJon Paul Maloy if (pkt_cnt > 1) {
107795901122SJon Paul Maloy l->stats.sent_fragmented++;
107895901122SJon Paul Maloy l->stats.sent_fragments += pkt_cnt;
107995901122SJon Paul Maloy }
108095901122SJon Paul Maloy
1081af9b028eSJon Paul Maloy /* Prepare each packet for sending, and add to relevant queue: */
108206e7c70cSTuong Lien while ((skb = __skb_dequeue(list))) {
108316ad3f40SJon Maloy if (likely(skb_queue_len(transmq) < cwin)) {
1084af9b028eSJon Paul Maloy hdr = buf_msg(skb);
1085af9b028eSJon Paul Maloy msg_set_seqno(hdr, seqno);
1086af9b028eSJon Paul Maloy msg_set_ack(hdr, ack);
108752666986SJon Paul Maloy msg_set_bcast_ack(hdr, bc_ack);
1088af9b028eSJon Paul Maloy _skb = skb_clone(skb, GFP_ATOMIC);
10894952cd3eSRichard Alpe if (!_skb) {
109006e7c70cSTuong Lien kfree_skb(skb);
1091e654f9f5SJon Maloy __skb_queue_purge(list);
109286704993SHoang Le return -ENOBUFS;
10934952cd3eSRichard Alpe }
1094af9b028eSJon Paul Maloy __skb_queue_tail(transmq, skb);
1095a34f8291SHamish Martin tipc_link_set_skb_retransmit_time(skb, l);
1096af9b028eSJon Paul Maloy __skb_queue_tail(xmitq, _skb);
1097c1ab3f1dSJon Paul Maloy TIPC_SKB_CB(skb)->ackers = l->ackers;
1098af9b028eSJon Paul Maloy l->rcv_unacked = 0;
109995901122SJon Paul Maloy l->stats.sent_pkts++;
1100af9b028eSJon Paul Maloy seqno++;
1101af9b028eSJon Paul Maloy continue;
1102af9b028eSJon Paul Maloy }
110306e7c70cSTuong Lien if (tipc_msg_try_bundle(l->backlog[imp].target_bskb, &skb,
1104fc1b6d6dSTuong Lien mss, l->addr, &new_bundle)) {
110506e7c70cSTuong Lien if (skb) {
110606e7c70cSTuong Lien /* Keep a ref. to the skb for next try */
110706e7c70cSTuong Lien l->backlog[imp].target_bskb = skb;
1108e95584a8STuong Lien l->backlog[imp].len++;
110906e7c70cSTuong Lien __skb_queue_tail(backlogq, skb);
111006e7c70cSTuong Lien } else {
111106e7c70cSTuong Lien if (new_bundle) {
1112af9b028eSJon Paul Maloy l->stats.sent_bundles++;
111306e7c70cSTuong Lien l->stats.sent_bundled++;
111406e7c70cSTuong Lien }
111506e7c70cSTuong Lien l->stats.sent_bundled++;
111606e7c70cSTuong Lien }
1117af9b028eSJon Paul Maloy continue;
1118af9b028eSJon Paul Maloy }
1119e95584a8STuong Lien l->backlog[imp].target_bskb = NULL;
112006e7c70cSTuong Lien l->backlog[imp].len += (1 + skb_queue_len(list));
112106e7c70cSTuong Lien __skb_queue_tail(backlogq, skb);
1122af9b028eSJon Paul Maloy skb_queue_splice_tail_init(list, backlogq);
1123af9b028eSJon Paul Maloy }
1124af9b028eSJon Paul Maloy l->snd_nxt = seqno;
1125365ad353SJon Paul Maloy return rc;
1126af9b028eSJon Paul Maloy }
1127af9b028eSJon Paul Maloy
tipc_link_update_cwin(struct tipc_link * l,int released,bool retransmitted)112816ad3f40SJon Maloy static void tipc_link_update_cwin(struct tipc_link *l, int released,
112916ad3f40SJon Maloy bool retransmitted)
113016ad3f40SJon Maloy {
113116ad3f40SJon Maloy int bklog_len = skb_queue_len(&l->backlogq);
113216ad3f40SJon Maloy struct sk_buff_head *txq = &l->transmq;
113316ad3f40SJon Maloy int txq_len = skb_queue_len(txq);
113416ad3f40SJon Maloy u16 cwin = l->window;
113516ad3f40SJon Maloy
113616ad3f40SJon Maloy /* Enter fast recovery */
113716ad3f40SJon Maloy if (unlikely(retransmitted)) {
113816ad3f40SJon Maloy l->ssthresh = max_t(u16, l->window / 2, 300);
1139edadedf1STuong Lien l->window = min_t(u16, l->ssthresh, l->window);
114016ad3f40SJon Maloy return;
114116ad3f40SJon Maloy }
114216ad3f40SJon Maloy /* Enter slow start */
114316ad3f40SJon Maloy if (unlikely(!released)) {
114416ad3f40SJon Maloy l->ssthresh = max_t(u16, l->window / 2, 300);
114516ad3f40SJon Maloy l->window = l->min_win;
114616ad3f40SJon Maloy return;
114716ad3f40SJon Maloy }
114816ad3f40SJon Maloy /* Don't increase window if no pressure on the transmit queue */
114916ad3f40SJon Maloy if (txq_len + bklog_len < cwin)
115016ad3f40SJon Maloy return;
115116ad3f40SJon Maloy
115216ad3f40SJon Maloy /* Don't increase window if there are holes the transmit queue */
115316ad3f40SJon Maloy if (txq_len && l->snd_nxt - buf_seqno(skb_peek(txq)) != txq_len)
115416ad3f40SJon Maloy return;
115516ad3f40SJon Maloy
115616ad3f40SJon Maloy l->cong_acks += released;
115716ad3f40SJon Maloy
115816ad3f40SJon Maloy /* Slow start */
115916ad3f40SJon Maloy if (cwin <= l->ssthresh) {
116016ad3f40SJon Maloy l->window = min_t(u16, cwin + released, l->max_win);
116116ad3f40SJon Maloy return;
116216ad3f40SJon Maloy }
116316ad3f40SJon Maloy /* Congestion avoidance */
116416ad3f40SJon Maloy if (l->cong_acks < cwin)
116516ad3f40SJon Maloy return;
116616ad3f40SJon Maloy l->window = min_t(u16, ++cwin, l->max_win);
116716ad3f40SJon Maloy l->cong_acks = 0;
116816ad3f40SJon Maloy }
116916ad3f40SJon Maloy
tipc_link_advance_backlog(struct tipc_link * l,struct sk_buff_head * xmitq)1170e064cce1SYueHaibing static void tipc_link_advance_backlog(struct tipc_link *l,
1171e064cce1SYueHaibing struct sk_buff_head *xmitq)
1172d999297cSJon Paul Maloy {
117352666986SJon Paul Maloy u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
117416ad3f40SJon Maloy struct sk_buff_head *txq = &l->transmq;
117516ad3f40SJon Maloy struct sk_buff *skb, *_skb;
117616ad3f40SJon Maloy u16 ack = l->rcv_nxt - 1;
117716ad3f40SJon Maloy u16 seqno = l->snd_nxt;
117816ad3f40SJon Maloy struct tipc_msg *hdr;
117916ad3f40SJon Maloy u16 cwin = l->window;
1180e95584a8STuong Lien u32 imp;
1181d999297cSJon Paul Maloy
118216ad3f40SJon Maloy while (skb_queue_len(txq) < cwin) {
1183d999297cSJon Paul Maloy skb = skb_peek(&l->backlogq);
1184d999297cSJon Paul Maloy if (!skb)
1185d999297cSJon Paul Maloy break;
1186d999297cSJon Paul Maloy _skb = skb_clone(skb, GFP_ATOMIC);
1187d999297cSJon Paul Maloy if (!_skb)
1188d999297cSJon Paul Maloy break;
1189d999297cSJon Paul Maloy __skb_dequeue(&l->backlogq);
1190d999297cSJon Paul Maloy hdr = buf_msg(skb);
1191e95584a8STuong Lien imp = msg_importance(hdr);
1192e95584a8STuong Lien l->backlog[imp].len--;
1193e95584a8STuong Lien if (unlikely(skb == l->backlog[imp].target_bskb))
1194e95584a8STuong Lien l->backlog[imp].target_bskb = NULL;
1195d999297cSJon Paul Maloy __skb_queue_tail(&l->transmq, skb);
1196a34f8291SHamish Martin tipc_link_set_skb_retransmit_time(skb, l);
119705572271SHoang Le
1198d999297cSJon Paul Maloy __skb_queue_tail(xmitq, _skb);
1199c1ab3f1dSJon Paul Maloy TIPC_SKB_CB(skb)->ackers = l->ackers;
1200d999297cSJon Paul Maloy msg_set_seqno(hdr, seqno);
120152666986SJon Paul Maloy msg_set_ack(hdr, ack);
120252666986SJon Paul Maloy msg_set_bcast_ack(hdr, bc_ack);
1203d999297cSJon Paul Maloy l->rcv_unacked = 0;
120495901122SJon Paul Maloy l->stats.sent_pkts++;
1205d999297cSJon Paul Maloy seqno++;
1206d999297cSJon Paul Maloy }
1207d999297cSJon Paul Maloy l->snd_nxt = seqno;
1208d999297cSJon Paul Maloy }
1209d999297cSJon Paul Maloy
12106a6b5c8bSTuong Lien /**
12116a6b5c8bSTuong Lien * link_retransmit_failure() - Detect repeated retransmit failures
12126a6b5c8bSTuong Lien * @l: tipc link sender
12136a6b5c8bSTuong Lien * @r: tipc link receiver (= l in case of unicast)
12146a6b5c8bSTuong Lien * @rc: returned code
12156a6b5c8bSTuong Lien *
12166a6b5c8bSTuong Lien * Return: true if the repeated retransmit failures happens, otherwise
12176a6b5c8bSTuong Lien * false
12186a6b5c8bSTuong Lien */
link_retransmit_failure(struct tipc_link * l,struct tipc_link * r,int * rc)12196a6b5c8bSTuong Lien static bool link_retransmit_failure(struct tipc_link *l, struct tipc_link *r,
122071204231STuong Lien int *rc)
1221d356eebaSAllan Stephens {
12226a6b5c8bSTuong Lien struct sk_buff *skb = skb_peek(&l->transmq);
12236a6b5c8bSTuong Lien struct tipc_msg *hdr;
1224d356eebaSAllan Stephens
12256a6b5c8bSTuong Lien if (!skb)
12266a6b5c8bSTuong Lien return false;
12276a6b5c8bSTuong Lien
122871204231STuong Lien if (!TIPC_SKB_CB(skb)->retr_cnt)
122971204231STuong Lien return false;
123071204231STuong Lien
123171204231STuong Lien if (!time_after(jiffies, TIPC_SKB_CB(skb)->retr_stamp +
1232426071f1SHoang Le msecs_to_jiffies(r->tolerance * 10)))
123371204231STuong Lien return false;
123471204231STuong Lien
123571204231STuong Lien hdr = buf_msg(skb);
123671204231STuong Lien if (link_is_bc_sndlink(l) && !less(r->acked, msg_seqno(hdr)))
123771204231STuong Lien return false;
123871204231STuong Lien
123952666986SJon Paul Maloy pr_warn("Retransmission failure on link <%s>\n", l->name);
124040501f90SJon Paul Maloy link_print(l, "State of link ");
12411a20cc25SJon Paul Maloy pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n",
124271204231STuong Lien msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr));
124371204231STuong Lien pr_info("sqno %u, prev: %x, dest: %x\n",
124471204231STuong Lien msg_seqno(hdr), msg_prevnode(hdr), msg_destnode(hdr));
124571204231STuong Lien pr_info("retr_stamp %d, retr_cnt %d\n",
124671204231STuong Lien jiffies_to_msecs(TIPC_SKB_CB(skb)->retr_stamp),
124771204231STuong Lien TIPC_SKB_CB(skb)->retr_cnt);
12486a6b5c8bSTuong Lien
12496a6b5c8bSTuong Lien trace_tipc_list_dump(&l->transmq, true, "retrans failure!");
12506a6b5c8bSTuong Lien trace_tipc_link_dump(l, TIPC_DUMP_NONE, "retrans failure!");
12516a6b5c8bSTuong Lien trace_tipc_link_dump(r, TIPC_DUMP_NONE, "retrans failure!");
12526a6b5c8bSTuong Lien
125371204231STuong Lien if (link_is_bc_sndlink(l)) {
125471204231STuong Lien r->state = LINK_RESET;
1255d7626b5aSTuong Lien *rc |= TIPC_LINK_DOWN_EVT;
125671204231STuong Lien } else {
1257d7626b5aSTuong Lien *rc |= tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1258d356eebaSAllan Stephens }
1259d356eebaSAllan Stephens
126071204231STuong Lien return true;
12616a6b5c8bSTuong Lien }
12626a6b5c8bSTuong Lien
1263c637c103SJon Paul Maloy /* tipc_data_input - deliver data and name distr msgs to upper layer
12647ae934beSErik Hugne *
1265c637c103SJon Paul Maloy * Consumes buffer if message is of right type
12667ae934beSErik Hugne * Node lock must be held
12677ae934beSErik Hugne */
tipc_data_input(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * inputq)126852666986SJon Paul Maloy static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
12699073fb8bSJon Paul Maloy struct sk_buff_head *inputq)
12707ae934beSErik Hugne {
1271399574d4SJon Maloy struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq;
1272a853e4c6SJon Paul Maloy struct tipc_msg *hdr = buf_msg(skb);
1273a853e4c6SJon Paul Maloy
1274a853e4c6SJon Paul Maloy switch (msg_user(hdr)) {
1275a5377831SJon Paul Maloy case TIPC_LOW_IMPORTANCE:
1276a5377831SJon Paul Maloy case TIPC_MEDIUM_IMPORTANCE:
1277a5377831SJon Paul Maloy case TIPC_HIGH_IMPORTANCE:
1278a5377831SJon Paul Maloy case TIPC_CRITICAL_IMPORTANCE:
12792f487712SJon Maloy if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) {
1280399574d4SJon Maloy skb_queue_tail(mc_inputq, skb);
1281a853e4c6SJon Paul Maloy return true;
1282a853e4c6SJon Paul Maloy }
12837f8901b7SMiaohe Lin fallthrough;
12842f487712SJon Maloy case CONN_MANAGER:
128536c0a9dfSJon Maloy skb_queue_tail(inputq, skb);
1286c637c103SJon Paul Maloy return true;
1287399574d4SJon Maloy case GROUP_PROTOCOL:
1288399574d4SJon Maloy skb_queue_tail(mc_inputq, skb);
1289399574d4SJon Maloy return true;
1290b97bf3fdSPer Liden case NAME_DISTRIBUTOR:
129152666986SJon Paul Maloy l->bc_rcvlink->state = LINK_ESTABLISHED;
129252666986SJon Paul Maloy skb_queue_tail(l->namedq, skb);
1293c637c103SJon Paul Maloy return true;
12947ae934beSErik Hugne case MSG_BUNDLER:
1295dff29b1aSJon Paul Maloy case TUNNEL_PROTOCOL:
1296c637c103SJon Paul Maloy case MSG_FRAGMENTER:
1297c637c103SJon Paul Maloy case BCAST_PROTOCOL:
1298c637c103SJon Paul Maloy return false;
12991ef6f7c9STuong Lien #ifdef CONFIG_TIPC_CRYPTO
13001ef6f7c9STuong Lien case MSG_CRYPTO:
13016180c780SXin Long if (sysctl_tipc_key_exchange_enabled &&
13026180c780SXin Long TIPC_SKB_CB(skb)->decrypted) {
13031ef6f7c9STuong Lien tipc_crypto_msg_rcv(l->net, skb);
13041ef6f7c9STuong Lien return true;
1305271351d2SXin Long }
1306271351d2SXin Long fallthrough;
13071ef6f7c9STuong Lien #endif
1308c637c103SJon Paul Maloy default:
1309c637c103SJon Paul Maloy pr_warn("Dropping received illegal msg type\n");
1310c637c103SJon Paul Maloy kfree_skb(skb);
13117384b538SHoang Le return true;
1312f2219c32STom Rix }
1313c637c103SJon Paul Maloy }
1314c637c103SJon Paul Maloy
1315c637c103SJon Paul Maloy /* tipc_link_input - process packet that has passed link protocol check
1316c637c103SJon Paul Maloy *
1317c637c103SJon Paul Maloy * Consumes buffer
1318c637c103SJon Paul Maloy */
tipc_link_input(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * inputq,struct sk_buff ** reasm_skb)13199073fb8bSJon Paul Maloy static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
132058ee86b8STuong Lien struct sk_buff_head *inputq,
132158ee86b8STuong Lien struct sk_buff **reasm_skb)
1322c637c103SJon Paul Maloy {
13236e498158SJon Paul Maloy struct tipc_msg *hdr = buf_msg(skb);
1324c637c103SJon Paul Maloy struct sk_buff *iskb;
13259945e804SJon Paul Maloy struct sk_buff_head tmpq;
13266e498158SJon Paul Maloy int usr = msg_user(hdr);
13276e498158SJon Paul Maloy int pos = 0;
1328c637c103SJon Paul Maloy
13296e498158SJon Paul Maloy if (usr == MSG_BUNDLER) {
13309945e804SJon Paul Maloy skb_queue_head_init(&tmpq);
13316e498158SJon Paul Maloy l->stats.recv_bundles++;
13326e498158SJon Paul Maloy l->stats.recv_bundled += msg_msgcnt(hdr);
1333c637c103SJon Paul Maloy while (tipc_msg_extract(skb, &iskb, &pos))
13349945e804SJon Paul Maloy tipc_data_input(l, iskb, &tmpq);
13359945e804SJon Paul Maloy tipc_skb_queue_splice_tail(&tmpq, inputq);
1336662921cdSJon Paul Maloy return 0;
13376e498158SJon Paul Maloy } else if (usr == MSG_FRAGMENTER) {
13386e498158SJon Paul Maloy l->stats.recv_fragments++;
13396e498158SJon Paul Maloy if (tipc_buf_append(reasm_skb, &skb)) {
13406e498158SJon Paul Maloy l->stats.recv_fragmented++;
13419073fb8bSJon Paul Maloy tipc_data_input(l, skb, inputq);
134252666986SJon Paul Maloy } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) {
134352666986SJon Paul Maloy pr_warn_ratelimited("Unable to build fragment list\n");
1344662921cdSJon Paul Maloy return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1345c637c103SJon Paul Maloy }
1346662921cdSJon Paul Maloy return 0;
13476e498158SJon Paul Maloy } else if (usr == BCAST_PROTOCOL) {
1348c72fa872SJon Paul Maloy tipc_bcast_lock(l->net);
134952666986SJon Paul Maloy tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
1350c72fa872SJon Paul Maloy tipc_bcast_unlock(l->net);
13516e498158SJon Paul Maloy }
135258ee86b8STuong Lien
13536e498158SJon Paul Maloy kfree_skb(skb);
1354662921cdSJon Paul Maloy return 0;
1355b97bf3fdSPer Liden }
1356b97bf3fdSPer Liden
135758ee86b8STuong Lien /* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the
135858ee86b8STuong Lien * inner message along with the ones in the old link's
135958ee86b8STuong Lien * deferdq
136058ee86b8STuong Lien * @l: tunnel link
136158ee86b8STuong Lien * @skb: TUNNEL_PROTOCOL message
136258ee86b8STuong Lien * @inputq: queue to put messages ready for delivery
136358ee86b8STuong Lien */
tipc_link_tnl_rcv(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * inputq)136458ee86b8STuong Lien static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
136558ee86b8STuong Lien struct sk_buff_head *inputq)
136658ee86b8STuong Lien {
136758ee86b8STuong Lien struct sk_buff **reasm_skb = &l->failover_reasm_skb;
13682320bcdaSTuong Lien struct sk_buff **reasm_tnlmsg = &l->reasm_tnlmsg;
136958ee86b8STuong Lien struct sk_buff_head *fdefq = &l->failover_deferdq;
137058ee86b8STuong Lien struct tipc_msg *hdr = buf_msg(skb);
137158ee86b8STuong Lien struct sk_buff *iskb;
137258ee86b8STuong Lien int ipos = 0;
137358ee86b8STuong Lien int rc = 0;
137458ee86b8STuong Lien u16 seqno;
137558ee86b8STuong Lien
13762320bcdaSTuong Lien if (msg_type(hdr) == SYNCH_MSG) {
13772320bcdaSTuong Lien kfree_skb(skb);
13782320bcdaSTuong Lien return 0;
13792320bcdaSTuong Lien }
138058ee86b8STuong Lien
13812320bcdaSTuong Lien /* Not a fragment? */
13822320bcdaSTuong Lien if (likely(!msg_nof_fragms(hdr))) {
13832320bcdaSTuong Lien if (unlikely(!tipc_msg_extract(skb, &iskb, &ipos))) {
13842320bcdaSTuong Lien pr_warn_ratelimited("Unable to extract msg, defq: %d\n",
138558ee86b8STuong Lien skb_queue_len(fdefq));
13862320bcdaSTuong Lien return 0;
13872320bcdaSTuong Lien }
13882320bcdaSTuong Lien kfree_skb(skb);
13892320bcdaSTuong Lien } else {
13902320bcdaSTuong Lien /* Set fragment type for buf_append */
13912320bcdaSTuong Lien if (msg_fragm_no(hdr) == 1)
13922320bcdaSTuong Lien msg_set_type(hdr, FIRST_FRAGMENT);
13932320bcdaSTuong Lien else if (msg_fragm_no(hdr) < msg_nof_fragms(hdr))
13942320bcdaSTuong Lien msg_set_type(hdr, FRAGMENT);
13952320bcdaSTuong Lien else
13962320bcdaSTuong Lien msg_set_type(hdr, LAST_FRAGMENT);
13972320bcdaSTuong Lien
13982320bcdaSTuong Lien if (!tipc_buf_append(reasm_tnlmsg, &skb)) {
13992320bcdaSTuong Lien /* Successful but non-complete reassembly? */
14002320bcdaSTuong Lien if (*reasm_tnlmsg || link_is_bc_rcvlink(l))
14012320bcdaSTuong Lien return 0;
14022320bcdaSTuong Lien pr_warn_ratelimited("Unable to reassemble tunnel msg\n");
14032320bcdaSTuong Lien return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
14042320bcdaSTuong Lien }
14052320bcdaSTuong Lien iskb = skb;
140658ee86b8STuong Lien }
140758ee86b8STuong Lien
140858ee86b8STuong Lien do {
140958ee86b8STuong Lien seqno = buf_seqno(iskb);
141058ee86b8STuong Lien if (unlikely(less(seqno, l->drop_point))) {
141158ee86b8STuong Lien kfree_skb(iskb);
141258ee86b8STuong Lien continue;
141358ee86b8STuong Lien }
141458ee86b8STuong Lien if (unlikely(seqno != l->drop_point)) {
141558ee86b8STuong Lien __tipc_skb_queue_sorted(fdefq, seqno, iskb);
141658ee86b8STuong Lien continue;
141758ee86b8STuong Lien }
141858ee86b8STuong Lien
141958ee86b8STuong Lien l->drop_point++;
142058ee86b8STuong Lien if (!tipc_data_input(l, iskb, inputq))
142158ee86b8STuong Lien rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
142258ee86b8STuong Lien if (unlikely(rc))
142358ee86b8STuong Lien break;
142458ee86b8STuong Lien } while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
142558ee86b8STuong Lien
142658ee86b8STuong Lien return rc;
142758ee86b8STuong Lien }
142858ee86b8STuong Lien
1429d7626b5aSTuong Lien /**
1430d7626b5aSTuong Lien * tipc_get_gap_ack_blks - get Gap ACK blocks from PROTOCOL/STATE_MSG
1431d7626b5aSTuong Lien * @ga: returned pointer to the Gap ACK blocks if any
1432d7626b5aSTuong Lien * @l: the tipc link
1433d7626b5aSTuong Lien * @hdr: the PROTOCOL/STATE_MSG header
1434d7626b5aSTuong Lien * @uc: desired Gap ACK blocks type, i.e. unicast (= 1) or broadcast (= 0)
14359195948fSTuong Lien *
1436d7626b5aSTuong Lien * Return: the total Gap ACK blocks size
14379195948fSTuong Lien */
tipc_get_gap_ack_blks(struct tipc_gap_ack_blks ** ga,struct tipc_link * l,struct tipc_msg * hdr,bool uc)1438d7626b5aSTuong Lien u16 tipc_get_gap_ack_blks(struct tipc_gap_ack_blks **ga, struct tipc_link *l,
1439d7626b5aSTuong Lien struct tipc_msg *hdr, bool uc)
14409195948fSTuong Lien {
1441d7626b5aSTuong Lien struct tipc_gap_ack_blks *p;
1442d7626b5aSTuong Lien u16 sz = 0;
1443d7626b5aSTuong Lien
1444d7626b5aSTuong Lien /* Does peer support the Gap ACK blocks feature? */
1445d7626b5aSTuong Lien if (l->peer_caps & TIPC_GAP_ACK_BLOCK) {
1446d7626b5aSTuong Lien p = (struct tipc_gap_ack_blks *)msg_data(hdr);
1447d7626b5aSTuong Lien sz = ntohs(p->len);
1448d7626b5aSTuong Lien /* Sanity check */
1449*85572d9dSGustavo A. R. Silva if (sz == struct_size(p, gacks, size_add(p->ugack_cnt, p->bgack_cnt))) {
1450d7626b5aSTuong Lien /* Good, check if the desired type exists */
1451d7626b5aSTuong Lien if ((uc && p->ugack_cnt) || (!uc && p->bgack_cnt))
1452d7626b5aSTuong Lien goto ok;
1453d7626b5aSTuong Lien /* Backward compatible: peer might not support bc, but uc? */
1454e034c6d2SGustavo A. R. Silva } else if (uc && sz == struct_size(p, gacks, p->ugack_cnt)) {
1455d7626b5aSTuong Lien if (p->ugack_cnt) {
1456d7626b5aSTuong Lien p->bgack_cnt = 0;
1457d7626b5aSTuong Lien goto ok;
1458d7626b5aSTuong Lien }
1459d7626b5aSTuong Lien }
1460d7626b5aSTuong Lien }
1461d7626b5aSTuong Lien /* Other cases: ignore! */
1462d7626b5aSTuong Lien p = NULL;
1463d7626b5aSTuong Lien
1464d7626b5aSTuong Lien ok:
1465d7626b5aSTuong Lien *ga = p;
1466d7626b5aSTuong Lien return sz;
1467d7626b5aSTuong Lien }
1468d7626b5aSTuong Lien
__tipc_build_gap_ack_blks(struct tipc_gap_ack_blks * ga,struct tipc_link * l,u8 start_index)1469d7626b5aSTuong Lien static u8 __tipc_build_gap_ack_blks(struct tipc_gap_ack_blks *ga,
1470d7626b5aSTuong Lien struct tipc_link *l, u8 start_index)
1471d7626b5aSTuong Lien {
1472d7626b5aSTuong Lien struct tipc_gap_ack *gacks = &ga->gacks[start_index];
14739195948fSTuong Lien struct sk_buff *skb = skb_peek(&l->deferdq);
1474d7626b5aSTuong Lien u16 expect, seqno = 0;
14759195948fSTuong Lien u8 n = 0;
14769195948fSTuong Lien
1477d7626b5aSTuong Lien if (!skb)
1478d7626b5aSTuong Lien return 0;
14799195948fSTuong Lien
14809195948fSTuong Lien expect = buf_seqno(skb);
14819195948fSTuong Lien skb_queue_walk(&l->deferdq, skb) {
14829195948fSTuong Lien seqno = buf_seqno(skb);
14839195948fSTuong Lien if (unlikely(more(seqno, expect))) {
1484d7626b5aSTuong Lien gacks[n].ack = htons(expect - 1);
1485d7626b5aSTuong Lien gacks[n].gap = htons(seqno - expect);
1486d7626b5aSTuong Lien if (++n >= MAX_GAP_ACK_BLKS / 2) {
1487d7626b5aSTuong Lien pr_info_ratelimited("Gacks on %s: %d, ql: %d!\n",
148803b6fefdSTuong Lien l->name, n,
1489d7626b5aSTuong Lien skb_queue_len(&l->deferdq));
1490d7626b5aSTuong Lien return n;
14919195948fSTuong Lien }
14929195948fSTuong Lien } else if (unlikely(less(seqno, expect))) {
14939195948fSTuong Lien pr_warn("Unexpected skb in deferdq!\n");
14949195948fSTuong Lien continue;
14959195948fSTuong Lien }
14969195948fSTuong Lien expect = seqno + 1;
14979195948fSTuong Lien }
14989195948fSTuong Lien
14999195948fSTuong Lien /* last block */
1500d7626b5aSTuong Lien gacks[n].ack = htons(seqno);
1501d7626b5aSTuong Lien gacks[n].gap = 0;
15029195948fSTuong Lien n++;
1503d7626b5aSTuong Lien return n;
1504d7626b5aSTuong Lien }
15059195948fSTuong Lien
1506d7626b5aSTuong Lien /* tipc_build_gap_ack_blks - build Gap ACK blocks
1507d7626b5aSTuong Lien * @l: tipc unicast link
1508d7626b5aSTuong Lien * @hdr: the tipc message buffer to store the Gap ACK blocks after built
1509d7626b5aSTuong Lien *
1510d7626b5aSTuong Lien * The function builds Gap ACK blocks for both the unicast & broadcast receiver
1511d7626b5aSTuong Lien * links of a certain peer, the buffer after built has the network data format
1512d7626b5aSTuong Lien * as found at the struct tipc_gap_ack_blks definition.
1513d7626b5aSTuong Lien *
1514d7626b5aSTuong Lien * returns the actual allocated memory size
1515d7626b5aSTuong Lien */
tipc_build_gap_ack_blks(struct tipc_link * l,struct tipc_msg * hdr)1516d7626b5aSTuong Lien static u16 tipc_build_gap_ack_blks(struct tipc_link *l, struct tipc_msg *hdr)
1517d7626b5aSTuong Lien {
1518d7626b5aSTuong Lien struct tipc_link *bcl = l->bc_rcvlink;
1519d7626b5aSTuong Lien struct tipc_gap_ack_blks *ga;
1520d7626b5aSTuong Lien u16 len;
1521d7626b5aSTuong Lien
1522d7626b5aSTuong Lien ga = (struct tipc_gap_ack_blks *)msg_data(hdr);
1523d7626b5aSTuong Lien
1524d7626b5aSTuong Lien /* Start with broadcast link first */
1525d7626b5aSTuong Lien tipc_bcast_lock(bcl->net);
1526d7626b5aSTuong Lien msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
1527d7626b5aSTuong Lien msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
1528d7626b5aSTuong Lien ga->bgack_cnt = __tipc_build_gap_ack_blks(ga, bcl, 0);
1529d7626b5aSTuong Lien tipc_bcast_unlock(bcl->net);
1530d7626b5aSTuong Lien
1531d7626b5aSTuong Lien /* Now for unicast link, but an explicit NACK only (???) */
1532d7626b5aSTuong Lien ga->ugack_cnt = (msg_seq_gap(hdr)) ?
1533d7626b5aSTuong Lien __tipc_build_gap_ack_blks(ga, l, ga->bgack_cnt) : 0;
1534d7626b5aSTuong Lien
1535d7626b5aSTuong Lien /* Total len */
1536*85572d9dSGustavo A. R. Silva len = struct_size(ga, gacks, size_add(ga->bgack_cnt, ga->ugack_cnt));
15379195948fSTuong Lien ga->len = htons(len);
15389195948fSTuong Lien return len;
15399195948fSTuong Lien }
15409195948fSTuong Lien
15419195948fSTuong Lien /* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing
15429195948fSTuong Lien * acked packets, also doing retransmissions if
15439195948fSTuong Lien * gaps found
15449195948fSTuong Lien * @l: tipc link with transmq queue to be advanced
1545d7626b5aSTuong Lien * @r: tipc link "receiver" i.e. in case of broadcast (= "l" if unicast)
15469195948fSTuong Lien * @acked: seqno of last packet acked by peer without any gaps before
15479195948fSTuong Lien * @gap: # of gap packets
15489195948fSTuong Lien * @ga: buffer pointer to Gap ACK blocks from peer
15499195948fSTuong Lien * @xmitq: queue for accumulating the retransmitted packets if any
1550d7626b5aSTuong Lien * @retransmitted: returned boolean value if a retransmission is really issued
1551d7626b5aSTuong Lien * @rc: returned code e.g. TIPC_LINK_DOWN_EVT if a repeated retransmit failures
1552d7626b5aSTuong Lien * happens (- unlikely case)
15536a6b5c8bSTuong Lien *
1554d7626b5aSTuong Lien * Return: the number of packets released from the link transmq
15559195948fSTuong Lien */
tipc_link_advance_transmq(struct tipc_link * l,struct tipc_link * r,u16 acked,u16 gap,struct tipc_gap_ack_blks * ga,struct sk_buff_head * xmitq,bool * retransmitted,int * rc)1556d7626b5aSTuong Lien static int tipc_link_advance_transmq(struct tipc_link *l, struct tipc_link *r,
1557d7626b5aSTuong Lien u16 acked, u16 gap,
15589195948fSTuong Lien struct tipc_gap_ack_blks *ga,
1559d7626b5aSTuong Lien struct sk_buff_head *xmitq,
1560d7626b5aSTuong Lien bool *retransmitted, int *rc)
15619195948fSTuong Lien {
1562d7626b5aSTuong Lien struct tipc_gap_ack_blks *last_ga = r->last_ga, *this_ga = NULL;
1563d7626b5aSTuong Lien struct tipc_gap_ack *gacks = NULL;
15649195948fSTuong Lien struct sk_buff *skb, *_skb, *tmp;
15659195948fSTuong Lien struct tipc_msg *hdr;
1566d7626b5aSTuong Lien u32 qlen = skb_queue_len(&l->transmq);
1567d7626b5aSTuong Lien u16 nacked = acked, ngap = gap, gack_cnt = 0;
15689195948fSTuong Lien u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
15699195948fSTuong Lien u16 ack = l->rcv_nxt - 1;
15706a6b5c8bSTuong Lien u16 seqno, n = 0;
1571d7626b5aSTuong Lien u16 end = r->acked, start = end, offset = r->last_gap;
1572d7626b5aSTuong Lien u16 si = (last_ga) ? last_ga->start_index : 0;
1573d7626b5aSTuong Lien bool is_uc = !link_is_bc_sndlink(l);
1574d7626b5aSTuong Lien bool bc_has_acked = false;
15756a6b5c8bSTuong Lien
1576c6ed7a5cSTuong Lien trace_tipc_link_retrans(r, acked + 1, acked + gap, &l->transmq);
1577c6ed7a5cSTuong Lien
1578d7626b5aSTuong Lien /* Determine Gap ACK blocks if any for the particular link */
1579d7626b5aSTuong Lien if (ga && is_uc) {
1580d7626b5aSTuong Lien /* Get the Gap ACKs, uc part */
1581d7626b5aSTuong Lien gack_cnt = ga->ugack_cnt;
1582d7626b5aSTuong Lien gacks = &ga->gacks[ga->bgack_cnt];
1583d7626b5aSTuong Lien } else if (ga) {
1584d7626b5aSTuong Lien /* Copy the Gap ACKs, bc part, for later renewal if needed */
1585e034c6d2SGustavo A. R. Silva this_ga = kmemdup(ga, struct_size(ga, gacks, ga->bgack_cnt),
1586d7626b5aSTuong Lien GFP_ATOMIC);
1587d7626b5aSTuong Lien if (likely(this_ga)) {
1588d7626b5aSTuong Lien this_ga->start_index = 0;
1589d7626b5aSTuong Lien /* Start with the bc Gap ACKs */
1590d7626b5aSTuong Lien gack_cnt = this_ga->bgack_cnt;
1591d7626b5aSTuong Lien gacks = &this_ga->gacks[0];
1592d7626b5aSTuong Lien } else {
1593d7626b5aSTuong Lien /* Hmm, we can get in trouble..., simply ignore it */
1594d7626b5aSTuong Lien pr_warn_ratelimited("Ignoring bc Gap ACKs, no memory\n");
1595d7626b5aSTuong Lien }
1596d7626b5aSTuong Lien }
1597d7626b5aSTuong Lien
1598d7626b5aSTuong Lien /* Advance the link transmq */
15999195948fSTuong Lien skb_queue_walk_safe(&l->transmq, skb, tmp) {
16009195948fSTuong Lien seqno = buf_seqno(skb);
16019195948fSTuong Lien
16029195948fSTuong Lien next_gap_ack:
1603d7626b5aSTuong Lien if (less_eq(seqno, nacked)) {
1604d7626b5aSTuong Lien if (is_uc)
1605d7626b5aSTuong Lien goto release;
1606d7626b5aSTuong Lien /* Skip packets peer has already acked */
1607d7626b5aSTuong Lien if (!more(seqno, r->acked))
1608d7626b5aSTuong Lien continue;
1609d7626b5aSTuong Lien /* Get the next of last Gap ACK blocks */
1610d7626b5aSTuong Lien while (more(seqno, end)) {
1611d7626b5aSTuong Lien if (!last_ga || si >= last_ga->bgack_cnt)
1612d7626b5aSTuong Lien break;
1613d7626b5aSTuong Lien start = end + offset + 1;
1614d7626b5aSTuong Lien end = ntohs(last_ga->gacks[si].ack);
1615d7626b5aSTuong Lien offset = ntohs(last_ga->gacks[si].gap);
1616d7626b5aSTuong Lien si++;
1617d7626b5aSTuong Lien WARN_ONCE(more(start, end) ||
1618d7626b5aSTuong Lien (!offset &&
1619d7626b5aSTuong Lien si < last_ga->bgack_cnt) ||
1620d7626b5aSTuong Lien si > MAX_GAP_ACK_BLKS,
1621d7626b5aSTuong Lien "Corrupted Gap ACK: %d %d %d %d %d\n",
1622d7626b5aSTuong Lien start, end, offset, si,
1623d7626b5aSTuong Lien last_ga->bgack_cnt);
1624d7626b5aSTuong Lien }
1625d7626b5aSTuong Lien /* Check against the last Gap ACK block */
1626f9bff0e3SMatthew Wilcox (Oracle) if (tipc_in_range(seqno, start, end))
1627d7626b5aSTuong Lien continue;
1628d7626b5aSTuong Lien /* Update/release the packet peer is acking */
1629d7626b5aSTuong Lien bc_has_acked = true;
1630d7626b5aSTuong Lien if (--TIPC_SKB_CB(skb)->ackers)
1631d7626b5aSTuong Lien continue;
1632d7626b5aSTuong Lien release:
16339195948fSTuong Lien /* release skb */
16349195948fSTuong Lien __skb_unlink(skb, &l->transmq);
16359195948fSTuong Lien kfree_skb(skb);
1636d7626b5aSTuong Lien } else if (less_eq(seqno, nacked + ngap)) {
1637d7626b5aSTuong Lien /* First gap: check if repeated retrans failures? */
1638d7626b5aSTuong Lien if (unlikely(seqno == acked + 1 &&
1639d7626b5aSTuong Lien link_retransmit_failure(l, r, rc))) {
1640d7626b5aSTuong Lien /* Ignore this bc Gap ACKs if any */
1641d7626b5aSTuong Lien kfree(this_ga);
1642d7626b5aSTuong Lien this_ga = NULL;
1643d7626b5aSTuong Lien break;
1644d7626b5aSTuong Lien }
164571204231STuong Lien /* retransmit skb if unrestricted*/
1646382f598fSTuong Lien if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
1647382f598fSTuong Lien continue;
1648a34f8291SHamish Martin tipc_link_set_skb_retransmit_time(skb, l);
1649fc1b6d6dSTuong Lien _skb = pskb_copy(skb, GFP_ATOMIC);
16509195948fSTuong Lien if (!_skb)
16519195948fSTuong Lien continue;
16529195948fSTuong Lien hdr = buf_msg(_skb);
16539195948fSTuong Lien msg_set_ack(hdr, ack);
16549195948fSTuong Lien msg_set_bcast_ack(hdr, bc_ack);
16559195948fSTuong Lien _skb->priority = TC_PRIO_CONTROL;
16569195948fSTuong Lien __skb_queue_tail(xmitq, _skb);
16579195948fSTuong Lien l->stats.retransmitted++;
165803b6fefdSTuong Lien if (!is_uc)
165903b6fefdSTuong Lien r->stats.retransmitted++;
1660d7626b5aSTuong Lien *retransmitted = true;
166171204231STuong Lien /* Increase actual retrans counter & mark first time */
166271204231STuong Lien if (!TIPC_SKB_CB(skb)->retr_cnt++)
166371204231STuong Lien TIPC_SKB_CB(skb)->retr_stamp = jiffies;
16649195948fSTuong Lien } else {
16659195948fSTuong Lien /* retry with Gap ACK blocks if any */
1666d7626b5aSTuong Lien if (n >= gack_cnt)
16679195948fSTuong Lien break;
1668d7626b5aSTuong Lien nacked = ntohs(gacks[n].ack);
1669d7626b5aSTuong Lien ngap = ntohs(gacks[n].gap);
16709195948fSTuong Lien n++;
16719195948fSTuong Lien goto next_gap_ack;
16729195948fSTuong Lien }
16739195948fSTuong Lien }
1674d7626b5aSTuong Lien
1675d7626b5aSTuong Lien /* Renew last Gap ACK blocks for bc if needed */
1676d7626b5aSTuong Lien if (bc_has_acked) {
1677d7626b5aSTuong Lien if (this_ga) {
1678d7626b5aSTuong Lien kfree(last_ga);
1679d7626b5aSTuong Lien r->last_ga = this_ga;
1680d7626b5aSTuong Lien r->last_gap = gap;
1681d7626b5aSTuong Lien } else if (last_ga) {
1682d7626b5aSTuong Lien if (less(acked, start)) {
1683d7626b5aSTuong Lien si--;
1684d7626b5aSTuong Lien offset = start - acked - 1;
1685d7626b5aSTuong Lien } else if (less(acked, end)) {
1686d7626b5aSTuong Lien acked = end;
1687d7626b5aSTuong Lien }
1688d7626b5aSTuong Lien if (si < last_ga->bgack_cnt) {
1689d7626b5aSTuong Lien last_ga->start_index = si;
1690d7626b5aSTuong Lien r->last_gap = offset;
1691d7626b5aSTuong Lien } else {
1692d7626b5aSTuong Lien kfree(last_ga);
1693d7626b5aSTuong Lien r->last_ga = NULL;
1694d7626b5aSTuong Lien r->last_gap = 0;
1695d7626b5aSTuong Lien }
1696d7626b5aSTuong Lien } else {
1697d7626b5aSTuong Lien r->last_gap = 0;
1698d7626b5aSTuong Lien }
1699d7626b5aSTuong Lien r->acked = acked;
1700d7626b5aSTuong Lien } else {
1701d7626b5aSTuong Lien kfree(this_ga);
1702d7626b5aSTuong Lien }
1703d7626b5aSTuong Lien
1704d7626b5aSTuong Lien return qlen - skb_queue_len(&l->transmq);
17059195948fSTuong Lien }
17069195948fSTuong Lien
170734b9cd64SJon Paul Maloy /* tipc_link_build_state_msg: prepare link state message for transmission
170852666986SJon Paul Maloy *
170952666986SJon Paul Maloy * Note that sending of broadcast ack is coordinated among nodes, to reduce
171052666986SJon Paul Maloy * risk of ack storms towards the sender
1711f9aa358aSJon Paul Maloy */
tipc_link_build_state_msg(struct tipc_link * l,struct sk_buff_head * xmitq)171234b9cd64SJon Paul Maloy int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1713f9aa358aSJon Paul Maloy {
171452666986SJon Paul Maloy if (!l)
171552666986SJon Paul Maloy return 0;
171652666986SJon Paul Maloy
171752666986SJon Paul Maloy /* Broadcast ACK must be sent via a unicast link => defer to caller */
171852666986SJon Paul Maloy if (link_is_bc_rcvlink(l)) {
1719e74a386dSJon Paul Maloy if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
172052666986SJon Paul Maloy return 0;
172152666986SJon Paul Maloy l->rcv_unacked = 0;
172202d11ca2SJon Paul Maloy
172302d11ca2SJon Paul Maloy /* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */
172402d11ca2SJon Paul Maloy l->snd_nxt = l->rcv_nxt;
172502d11ca2SJon Paul Maloy return TIPC_LINK_SND_STATE;
172652666986SJon Paul Maloy }
172752666986SJon Paul Maloy /* Unicast ACK */
1728f9aa358aSJon Paul Maloy l->rcv_unacked = 0;
1729f9aa358aSJon Paul Maloy l->stats.sent_acks++;
17308d6e79d3SJon Maloy tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
173152666986SJon Paul Maloy return 0;
1732f9aa358aSJon Paul Maloy }
1733f9aa358aSJon Paul Maloy
1734282b3a05SJon Paul Maloy /* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message
1735282b3a05SJon Paul Maloy */
tipc_link_build_reset_msg(struct tipc_link * l,struct sk_buff_head * xmitq)1736282b3a05SJon Paul Maloy void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1737282b3a05SJon Paul Maloy {
1738282b3a05SJon Paul Maloy int mtyp = RESET_MSG;
1739634696b1SJon Paul Maloy struct sk_buff *skb;
1740282b3a05SJon Paul Maloy
1741282b3a05SJon Paul Maloy if (l->state == LINK_ESTABLISHING)
1742282b3a05SJon Paul Maloy mtyp = ACTIVATE_MSG;
1743282b3a05SJon Paul Maloy
17448d6e79d3SJon Maloy tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq);
1745634696b1SJon Paul Maloy
1746634696b1SJon Paul Maloy /* Inform peer that this endpoint is going down if applicable */
1747634696b1SJon Paul Maloy skb = skb_peek_tail(xmitq);
1748634696b1SJon Paul Maloy if (skb && (l->state == LINK_RESET))
1749634696b1SJon Paul Maloy msg_set_peer_stopping(buf_msg(skb), 1);
1750282b3a05SJon Paul Maloy }
1751282b3a05SJon Paul Maloy
1752f9aa358aSJon Paul Maloy /* tipc_link_build_nack_msg: prepare link nack message for transmission
1753e0a05ebeSJon Paul Maloy * Note that sending of broadcast NACK is coordinated among nodes, to
1754e0a05ebeSJon Paul Maloy * reduce the risk of NACK storms towards the sender
1755f9aa358aSJon Paul Maloy */
tipc_link_build_nack_msg(struct tipc_link * l,struct sk_buff_head * xmitq)1756e0a05ebeSJon Paul Maloy static int tipc_link_build_nack_msg(struct tipc_link *l,
1757f9aa358aSJon Paul Maloy struct sk_buff_head *xmitq)
1758f9aa358aSJon Paul Maloy {
1759f9aa358aSJon Paul Maloy u32 def_cnt = ++l->stats.deferred_recv;
176002288248SJon Maloy struct sk_buff_head *dfq = &l->deferdq;
176102288248SJon Maloy u32 defq_len = skb_queue_len(dfq);
1762e0a05ebeSJon Paul Maloy int match1, match2;
1763f9aa358aSJon Paul Maloy
1764e0a05ebeSJon Paul Maloy if (link_is_bc_rcvlink(l)) {
1765e0a05ebeSJon Paul Maloy match1 = def_cnt & 0xf;
1766e0a05ebeSJon Paul Maloy match2 = tipc_own_addr(l->net) & 0xf;
1767e0a05ebeSJon Paul Maloy if (match1 == match2)
1768e0a05ebeSJon Paul Maloy return TIPC_LINK_SND_STATE;
1769e0a05ebeSJon Paul Maloy return 0;
1770e0a05ebeSJon Paul Maloy }
177152666986SJon Paul Maloy
177202288248SJon Maloy if (defq_len >= 3 && !((defq_len - 3) % 16)) {
177302288248SJon Maloy u16 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
177402288248SJon Maloy
177502288248SJon Maloy tipc_link_build_proto_msg(l, STATE_MSG, 0, 0,
177602288248SJon Maloy rcvgap, 0, 0, xmitq);
177702288248SJon Maloy }
1778e0a05ebeSJon Paul Maloy return 0;
1779f9aa358aSJon Paul Maloy }
1780f9aa358aSJon Paul Maloy
1781d999297cSJon Paul Maloy /* tipc_link_rcv - process TIPC packets/messages arriving from off-node
1782f9aa358aSJon Paul Maloy * @l: the link that should handle the message
1783d999297cSJon Paul Maloy * @skb: TIPC packet
1784d999297cSJon Paul Maloy * @xmitq: queue to place packets to be sent after this call
1785d999297cSJon Paul Maloy */
tipc_link_rcv(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * xmitq)1786d999297cSJon Paul Maloy int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
1787d999297cSJon Paul Maloy struct sk_buff_head *xmitq)
1788d999297cSJon Paul Maloy {
1789f9aa358aSJon Paul Maloy struct sk_buff_head *defq = &l->deferdq;
1790382f598fSTuong Lien struct tipc_msg *hdr = buf_msg(skb);
179181204c49SJon Paul Maloy u16 seqno, rcv_nxt, win_lim;
179216ad3f40SJon Maloy int released = 0;
1793d999297cSJon Paul Maloy int rc = 0;
1794d999297cSJon Paul Maloy
1795382f598fSTuong Lien /* Verify and update link state */
1796382f598fSTuong Lien if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
1797382f598fSTuong Lien return tipc_link_proto_rcv(l, skb, xmitq);
1798382f598fSTuong Lien
1799382f598fSTuong Lien /* Don't send probe at next timeout expiration */
1800382f598fSTuong Lien l->silent_intv_cnt = 0;
1801382f598fSTuong Lien
1802f9aa358aSJon Paul Maloy do {
1803d999297cSJon Paul Maloy hdr = buf_msg(skb);
1804f9aa358aSJon Paul Maloy seqno = msg_seqno(hdr);
1805f9aa358aSJon Paul Maloy rcv_nxt = l->rcv_nxt;
180681204c49SJon Paul Maloy win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
1807d999297cSJon Paul Maloy
1808662921cdSJon Paul Maloy if (unlikely(!link_is_up(l))) {
180973f646ceSJon Paul Maloy if (l->state == LINK_ESTABLISHING)
181073f646ceSJon Paul Maloy rc = TIPC_LINK_UP_EVT;
181116ad3f40SJon Maloy kfree_skb(skb);
181216ad3f40SJon Maloy break;
1813d999297cSJon Paul Maloy }
1814d999297cSJon Paul Maloy
181581204c49SJon Paul Maloy /* Drop if outside receive window */
181681204c49SJon Paul Maloy if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
181781204c49SJon Paul Maloy l->stats.duplicates++;
181816ad3f40SJon Maloy kfree_skb(skb);
181916ad3f40SJon Maloy break;
182081204c49SJon Paul Maloy }
1821d7626b5aSTuong Lien released += tipc_link_advance_transmq(l, l, msg_ack(hdr), 0,
1822d7626b5aSTuong Lien NULL, NULL, NULL, NULL);
1823d999297cSJon Paul Maloy
182481204c49SJon Paul Maloy /* Defer delivery if sequence gap */
182581204c49SJon Paul Maloy if (unlikely(seqno != rcv_nxt)) {
182603b6fefdSTuong Lien if (!__tipc_skb_queue_sorted(defq, seqno, skb))
182703b6fefdSTuong Lien l->stats.duplicates++;
1828e0a05ebeSJon Paul Maloy rc |= tipc_link_build_nack_msg(l, xmitq);
1829f9aa358aSJon Paul Maloy break;
1830d999297cSJon Paul Maloy }
1831d999297cSJon Paul Maloy
183281204c49SJon Paul Maloy /* Deliver packet */
1833d999297cSJon Paul Maloy l->rcv_nxt++;
183495901122SJon Paul Maloy l->stats.recv_pkts++;
183558ee86b8STuong Lien
183658ee86b8STuong Lien if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL))
183758ee86b8STuong Lien rc |= tipc_link_tnl_rcv(l, skb, l->inputq);
183858ee86b8STuong Lien else if (!tipc_data_input(l, skb, l->inputq))
183958ee86b8STuong Lien rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf);
1840f9aa358aSJon Paul Maloy if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
184134b9cd64SJon Paul Maloy rc |= tipc_link_build_state_msg(l, xmitq);
184202d11ca2SJon Paul Maloy if (unlikely(rc & ~TIPC_LINK_SND_STATE))
184352666986SJon Paul Maloy break;
1844382f598fSTuong Lien } while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt)));
1845f9aa358aSJon Paul Maloy
184616ad3f40SJon Maloy /* Forward queues and wake up waiting users */
184716ad3f40SJon Maloy if (released) {
184816ad3f40SJon Maloy tipc_link_update_cwin(l, released, 0);
184916ad3f40SJon Maloy tipc_link_advance_backlog(l, xmitq);
185016ad3f40SJon Maloy if (unlikely(!skb_queue_empty(&l->wakeupq)))
185116ad3f40SJon Maloy link_prepare_wakeup(l);
185216ad3f40SJon Maloy }
1853d999297cSJon Paul Maloy return rc;
1854d999297cSJon Paul Maloy }
1855d999297cSJon Paul Maloy
tipc_link_build_proto_msg(struct tipc_link * l,int mtyp,bool probe,bool probe_reply,u16 rcvgap,int tolerance,int priority,struct sk_buff_head * xmitq)1856426cc2b8SJon Paul Maloy static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
18578d6e79d3SJon Maloy bool probe_reply, u16 rcvgap,
18588d6e79d3SJon Maloy int tolerance, int priority,
1859426cc2b8SJon Paul Maloy struct sk_buff_head *xmitq)
1860426cc2b8SJon Paul Maloy {
186135c55c98SJon Paul Maloy struct tipc_mon_state *mstate = &l->mon_state;
186203b6fefdSTuong Lien struct sk_buff_head *dfq = &l->deferdq;
186303b6fefdSTuong Lien struct tipc_link *bcl = l->bc_rcvlink;
186403b6fefdSTuong Lien struct tipc_msg *hdr;
186503b6fefdSTuong Lien struct sk_buff *skb;
186603b6fefdSTuong Lien bool node_up = link_is_up(bcl);
186703b6fefdSTuong Lien u16 glen = 0, bc_rcvgap = 0;
186835c55c98SJon Paul Maloy int dlen = 0;
186935c55c98SJon Paul Maloy void *data;
1870426cc2b8SJon Paul Maloy
1871426cc2b8SJon Paul Maloy /* Don't send protocol message during reset or link failover */
1872662921cdSJon Paul Maloy if (tipc_link_is_blocked(l))
1873426cc2b8SJon Paul Maloy return;
1874426cc2b8SJon Paul Maloy
1875e74a386dSJon Paul Maloy if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
1876e74a386dSJon Paul Maloy return;
1877e74a386dSJon Paul Maloy
187802288248SJon Maloy if ((probe || probe_reply) && !skb_queue_empty(dfq))
1879e74a386dSJon Paul Maloy rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1880e74a386dSJon Paul Maloy
1881e74a386dSJon Paul Maloy skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
18829195948fSTuong Lien tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ,
18839195948fSTuong Lien l->addr, tipc_own_addr(l->net), 0, 0, 0);
1884e74a386dSJon Paul Maloy if (!skb)
1885e74a386dSJon Paul Maloy return;
1886e74a386dSJon Paul Maloy
1887e74a386dSJon Paul Maloy hdr = buf_msg(skb);
188835c55c98SJon Paul Maloy data = msg_data(hdr);
1889e74a386dSJon Paul Maloy msg_set_session(hdr, l->session);
1890e74a386dSJon Paul Maloy msg_set_bearer_id(hdr, l->bearer_id);
1891426cc2b8SJon Paul Maloy msg_set_net_plane(hdr, l->net_plane);
189252666986SJon Paul Maloy msg_set_next_sent(hdr, l->snd_nxt);
189352666986SJon Paul Maloy msg_set_ack(hdr, l->rcv_nxt - 1);
189402d11ca2SJon Paul Maloy msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
189506bd2b1eSJon Paul Maloy msg_set_bc_ack_invalid(hdr, !node_up);
189652666986SJon Paul Maloy msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
1897426cc2b8SJon Paul Maloy msg_set_link_tolerance(hdr, tolerance);
1898426cc2b8SJon Paul Maloy msg_set_linkprio(hdr, priority);
1899426cc2b8SJon Paul Maloy msg_set_redundant_link(hdr, node_up);
1900426cc2b8SJon Paul Maloy msg_set_seq_gap(hdr, 0);
190152666986SJon Paul Maloy msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
1902426cc2b8SJon Paul Maloy
1903426cc2b8SJon Paul Maloy if (mtyp == STATE_MSG) {
19049012de50SJon Maloy if (l->peer_caps & TIPC_LINK_PROTO_SEQNO)
19059012de50SJon Maloy msg_set_seqno(hdr, l->snd_nxt_state++);
1906426cc2b8SJon Paul Maloy msg_set_seq_gap(hdr, rcvgap);
190703b6fefdSTuong Lien bc_rcvgap = link_bc_rcv_gap(bcl);
190803b6fefdSTuong Lien msg_set_bc_gap(hdr, bc_rcvgap);
1909426cc2b8SJon Paul Maloy msg_set_probe(hdr, probe);
19108d6e79d3SJon Maloy msg_set_is_keepalive(hdr, probe || probe_reply);
19119195948fSTuong Lien if (l->peer_caps & TIPC_GAP_ACK_BLOCK)
1912d7626b5aSTuong Lien glen = tipc_build_gap_ack_blks(l, hdr);
19139195948fSTuong Lien tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id);
19149195948fSTuong Lien msg_set_size(hdr, INT_H_SIZE + glen + dlen);
19159195948fSTuong Lien skb_trim(skb, INT_H_SIZE + glen + dlen);
1916426cc2b8SJon Paul Maloy l->stats.sent_states++;
191752666986SJon Paul Maloy l->rcv_unacked = 0;
1918426cc2b8SJon Paul Maloy } else {
1919426cc2b8SJon Paul Maloy /* RESET_MSG or ACTIVATE_MSG */
192091986ee1STuong Lien if (mtyp == ACTIVATE_MSG) {
192191986ee1STuong Lien msg_set_dest_session_valid(hdr, 1);
192291986ee1STuong Lien msg_set_dest_session(hdr, l->peer_session);
192391986ee1STuong Lien }
1924426cc2b8SJon Paul Maloy msg_set_max_pkt(hdr, l->advertised_mtu);
192535c55c98SJon Paul Maloy strcpy(data, l->if_name);
192635c55c98SJon Paul Maloy msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
192735c55c98SJon Paul Maloy skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
1928426cc2b8SJon Paul Maloy }
1929e74a386dSJon Paul Maloy if (probe)
1930e74a386dSJon Paul Maloy l->stats.sent_probes++;
1931e74a386dSJon Paul Maloy if (rcvgap)
1932e74a386dSJon Paul Maloy l->stats.sent_nacks++;
193303b6fefdSTuong Lien if (bc_rcvgap)
193403b6fefdSTuong Lien bcl->stats.sent_nacks++;
1935426cc2b8SJon Paul Maloy skb->priority = TC_PRIO_CONTROL;
19366e498158SJon Paul Maloy __skb_queue_tail(xmitq, skb);
193726574db0STuong Lien trace_tipc_proto_build(skb, false, l->name);
1938426cc2b8SJon Paul Maloy }
1939b97bf3fdSPer Liden
tipc_link_create_dummy_tnl_msg(struct tipc_link * l,struct sk_buff_head * xmitq)1940c140eb16SLUU Duc Canh void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
1941c140eb16SLUU Duc Canh struct sk_buff_head *xmitq)
1942c140eb16SLUU Duc Canh {
1943c140eb16SLUU Duc Canh u32 onode = tipc_own_addr(l->net);
1944c140eb16SLUU Duc Canh struct tipc_msg *hdr, *ihdr;
1945c140eb16SLUU Duc Canh struct sk_buff_head tnlq;
1946c140eb16SLUU Duc Canh struct sk_buff *skb;
1947c140eb16SLUU Duc Canh u32 dnode = l->addr;
1948c140eb16SLUU Duc Canh
1949e654f9f5SJon Maloy __skb_queue_head_init(&tnlq);
1950c140eb16SLUU Duc Canh skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG,
1951c140eb16SLUU Duc Canh INT_H_SIZE, BASIC_H_SIZE,
1952c140eb16SLUU Duc Canh dnode, onode, 0, 0, 0);
1953c140eb16SLUU Duc Canh if (!skb) {
1954c140eb16SLUU Duc Canh pr_warn("%sunable to create tunnel packet\n", link_co_err);
1955c140eb16SLUU Duc Canh return;
1956c140eb16SLUU Duc Canh }
1957c140eb16SLUU Duc Canh
1958c140eb16SLUU Duc Canh hdr = buf_msg(skb);
1959c140eb16SLUU Duc Canh msg_set_msgcnt(hdr, 1);
1960c140eb16SLUU Duc Canh msg_set_bearer_id(hdr, l->peer_bearer_id);
1961c140eb16SLUU Duc Canh
1962c140eb16SLUU Duc Canh ihdr = (struct tipc_msg *)msg_data(hdr);
1963c140eb16SLUU Duc Canh tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
1964c140eb16SLUU Duc Canh BASIC_H_SIZE, dnode);
1965c140eb16SLUU Duc Canh msg_set_errcode(ihdr, TIPC_ERR_NO_PORT);
1966c140eb16SLUU Duc Canh __skb_queue_tail(&tnlq, skb);
1967c140eb16SLUU Duc Canh tipc_link_xmit(l, &tnlq, xmitq);
1968c140eb16SLUU Duc Canh }
1969c140eb16SLUU Duc Canh
19706e498158SJon Paul Maloy /* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets
1971f9aa358aSJon Paul Maloy * with contents of the link's transmit and backlog queues.
1972b97bf3fdSPer Liden */
tipc_link_tnl_prepare(struct tipc_link * l,struct tipc_link * tnl,int mtyp,struct sk_buff_head * xmitq)19736e498158SJon Paul Maloy void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
19746e498158SJon Paul Maloy int mtyp, struct sk_buff_head *xmitq)
1975b97bf3fdSPer Liden {
197658ee86b8STuong Lien struct sk_buff_head *fdefq = &tnl->failover_deferdq;
19776e498158SJon Paul Maloy struct sk_buff *skb, *tnlskb;
19786e498158SJon Paul Maloy struct tipc_msg *hdr, tnlhdr;
19796e498158SJon Paul Maloy struct sk_buff_head *queue = &l->transmq;
19802320bcdaSTuong Lien struct sk_buff_head tmpxq, tnlq, frags;
19816e498158SJon Paul Maloy u16 pktlen, pktcnt, seqno = l->snd_nxt;
19822320bcdaSTuong Lien bool pktcnt_need_update = false;
19834929a932STuong Lien u16 syncpt;
19842320bcdaSTuong Lien int rc;
1985b97bf3fdSPer Liden
19866e498158SJon Paul Maloy if (!tnl)
1987b97bf3fdSPer Liden return;
19886e498158SJon Paul Maloy
1989e654f9f5SJon Maloy __skb_queue_head_init(&tnlq);
19904929a932STuong Lien /* Link Synching:
19914929a932STuong Lien * From now on, send only one single ("dummy") SYNCH message
19924929a932STuong Lien * to peer. The SYNCH message does not contain any data, just
19934929a932STuong Lien * a header conveying the synch point to the peer.
19944929a932STuong Lien */
19954929a932STuong Lien if (mtyp == SYNCH_MSG && (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
19964929a932STuong Lien tnlskb = tipc_msg_create(TUNNEL_PROTOCOL, SYNCH_MSG,
19974929a932STuong Lien INT_H_SIZE, 0, l->addr,
19984929a932STuong Lien tipc_own_addr(l->net),
19994929a932STuong Lien 0, 0, 0);
20004929a932STuong Lien if (!tnlskb) {
20014929a932STuong Lien pr_warn("%sunable to create dummy SYNCH_MSG\n",
20024929a932STuong Lien link_co_err);
20034929a932STuong Lien return;
20044929a932STuong Lien }
20054929a932STuong Lien
20064929a932STuong Lien hdr = buf_msg(tnlskb);
20074929a932STuong Lien syncpt = l->snd_nxt + skb_queue_len(&l->backlogq) - 1;
20084929a932STuong Lien msg_set_syncpt(hdr, syncpt);
20094929a932STuong Lien msg_set_bearer_id(hdr, l->peer_bearer_id);
20104929a932STuong Lien __skb_queue_tail(&tnlq, tnlskb);
20114929a932STuong Lien tipc_link_xmit(tnl, &tnlq, xmitq);
20124929a932STuong Lien return;
20134929a932STuong Lien }
20144929a932STuong Lien
2015d0d605c5STuong Lien __skb_queue_head_init(&tmpxq);
2016d0d605c5STuong Lien __skb_queue_head_init(&frags);
2017d0d605c5STuong Lien /* At least one packet required for safe algorithm => add dummy */
2018d0d605c5STuong Lien skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
2019d0d605c5STuong Lien BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net),
2020d0d605c5STuong Lien 0, 0, TIPC_ERR_NO_PORT);
2021d0d605c5STuong Lien if (!skb) {
2022d0d605c5STuong Lien pr_warn("%sunable to create tunnel packet\n", link_co_err);
2023d0d605c5STuong Lien return;
2024d0d605c5STuong Lien }
2025d0d605c5STuong Lien __skb_queue_tail(&tnlq, skb);
2026d0d605c5STuong Lien tipc_link_xmit(l, &tnlq, &tmpxq);
2027d0d605c5STuong Lien __skb_queue_purge(&tmpxq);
2028d0d605c5STuong Lien
20296e498158SJon Paul Maloy /* Initialize reusable tunnel packet header */
2030e74a386dSJon Paul Maloy tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
20316e498158SJon Paul Maloy mtyp, INT_H_SIZE, l->addr);
203258ee86b8STuong Lien if (mtyp == SYNCH_MSG)
203358ee86b8STuong Lien pktcnt = l->snd_nxt - buf_seqno(skb_peek(&l->transmq));
203458ee86b8STuong Lien else
203558ee86b8STuong Lien pktcnt = skb_queue_len(&l->transmq);
203658ee86b8STuong Lien pktcnt += skb_queue_len(&l->backlogq);
20376e498158SJon Paul Maloy msg_set_msgcnt(&tnlhdr, pktcnt);
20386e498158SJon Paul Maloy msg_set_bearer_id(&tnlhdr, l->peer_bearer_id);
20396e498158SJon Paul Maloy tnl:
20406e498158SJon Paul Maloy /* Wrap each packet into a tunnel packet */
204105dcc5aaSJon Paul Maloy skb_queue_walk(queue, skb) {
20426e498158SJon Paul Maloy hdr = buf_msg(skb);
20436e498158SJon Paul Maloy if (queue == &l->backlogq)
20446e498158SJon Paul Maloy msg_set_seqno(hdr, seqno++);
20456e498158SJon Paul Maloy pktlen = msg_size(hdr);
20462320bcdaSTuong Lien
20472320bcdaSTuong Lien /* Tunnel link MTU is not large enough? This could be
20482320bcdaSTuong Lien * due to:
20492320bcdaSTuong Lien * 1) Link MTU has just changed or set differently;
20502320bcdaSTuong Lien * 2) Or FAILOVER on the top of a SYNCH message
20512320bcdaSTuong Lien *
20522320bcdaSTuong Lien * The 2nd case should not happen if peer supports
20532320bcdaSTuong Lien * TIPC_TUNNEL_ENHANCED
20542320bcdaSTuong Lien */
20552320bcdaSTuong Lien if (pktlen > tnl->mtu - INT_H_SIZE) {
20562320bcdaSTuong Lien if (mtyp == FAILOVER_MSG &&
20572320bcdaSTuong Lien (tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
20582320bcdaSTuong Lien rc = tipc_msg_fragment(skb, &tnlhdr, tnl->mtu,
20592320bcdaSTuong Lien &frags);
20602320bcdaSTuong Lien if (rc) {
20612320bcdaSTuong Lien pr_warn("%sunable to frag msg: rc %d\n",
20622320bcdaSTuong Lien link_co_err, rc);
20632320bcdaSTuong Lien return;
20642320bcdaSTuong Lien }
20652320bcdaSTuong Lien pktcnt += skb_queue_len(&frags) - 1;
20662320bcdaSTuong Lien pktcnt_need_update = true;
20672320bcdaSTuong Lien skb_queue_splice_tail_init(&frags, &tnlq);
20682320bcdaSTuong Lien continue;
20692320bcdaSTuong Lien }
20702320bcdaSTuong Lien /* Unluckily, peer doesn't have TIPC_TUNNEL_ENHANCED
20712320bcdaSTuong Lien * => Just warn it and return!
20722320bcdaSTuong Lien */
20732320bcdaSTuong Lien pr_warn_ratelimited("%stoo large msg <%d, %d>: %d!\n",
20742320bcdaSTuong Lien link_co_err, msg_user(hdr),
20752320bcdaSTuong Lien msg_type(hdr), msg_size(hdr));
20762320bcdaSTuong Lien return;
20772320bcdaSTuong Lien }
20782320bcdaSTuong Lien
20796e498158SJon Paul Maloy msg_set_size(&tnlhdr, pktlen + INT_H_SIZE);
208057d5f64dSParthasarathy Bhuvaragan tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC);
20816e498158SJon Paul Maloy if (!tnlskb) {
20826e498158SJon Paul Maloy pr_warn("%sunable to send packet\n", link_co_err);
2083b97bf3fdSPer Liden return;
2084b97bf3fdSPer Liden }
20856e498158SJon Paul Maloy skb_copy_to_linear_data(tnlskb, &tnlhdr, INT_H_SIZE);
20866e498158SJon Paul Maloy skb_copy_to_linear_data_offset(tnlskb, INT_H_SIZE, hdr, pktlen);
20876e498158SJon Paul Maloy __skb_queue_tail(&tnlq, tnlskb);
2088b97bf3fdSPer Liden }
20896e498158SJon Paul Maloy if (queue != &l->backlogq) {
20906e498158SJon Paul Maloy queue = &l->backlogq;
20916e498158SJon Paul Maloy goto tnl;
2092b97bf3fdSPer Liden }
2093b97bf3fdSPer Liden
20942320bcdaSTuong Lien if (pktcnt_need_update)
20952320bcdaSTuong Lien skb_queue_walk(&tnlq, skb) {
20962320bcdaSTuong Lien hdr = buf_msg(skb);
20972320bcdaSTuong Lien msg_set_msgcnt(hdr, pktcnt);
20982320bcdaSTuong Lien }
20992320bcdaSTuong Lien
21006e498158SJon Paul Maloy tipc_link_xmit(tnl, &tnlq, xmitq);
2101f006c9c7SJon Paul Maloy
21026e498158SJon Paul Maloy if (mtyp == FAILOVER_MSG) {
21036e498158SJon Paul Maloy tnl->drop_point = l->rcv_nxt;
21046e498158SJon Paul Maloy tnl->failover_reasm_skb = l->reasm_buf;
21056e498158SJon Paul Maloy l->reasm_buf = NULL;
210658ee86b8STuong Lien
210758ee86b8STuong Lien /* Failover the link's deferdq */
210858ee86b8STuong Lien if (unlikely(!skb_queue_empty(fdefq))) {
210958ee86b8STuong Lien pr_warn("Link failover deferdq not empty: %d!\n",
211058ee86b8STuong Lien skb_queue_len(fdefq));
211158ee86b8STuong Lien __skb_queue_purge(fdefq);
211258ee86b8STuong Lien }
211358ee86b8STuong Lien skb_queue_splice_init(&l->deferdq, fdefq);
2114f006c9c7SJon Paul Maloy }
2115b97bf3fdSPer Liden }
2116b97bf3fdSPer Liden
2117c0b14a08STuong Lien /**
2118c0b14a08STuong Lien * tipc_link_failover_prepare() - prepare tnl for link failover
2119c0b14a08STuong Lien *
2120c0b14a08STuong Lien * This is a special version of the precursor - tipc_link_tnl_prepare(),
2121c0b14a08STuong Lien * see the tipc_node_link_failover() for details
2122c0b14a08STuong Lien *
2123c0b14a08STuong Lien * @l: failover link
2124c0b14a08STuong Lien * @tnl: tunnel link
2125c0b14a08STuong Lien * @xmitq: queue for messages to be xmited
2126c0b14a08STuong Lien */
tipc_link_failover_prepare(struct tipc_link * l,struct tipc_link * tnl,struct sk_buff_head * xmitq)2127c0b14a08STuong Lien void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl,
2128c0b14a08STuong Lien struct sk_buff_head *xmitq)
2129c0b14a08STuong Lien {
2130c0b14a08STuong Lien struct sk_buff_head *fdefq = &tnl->failover_deferdq;
2131c0b14a08STuong Lien
2132c0b14a08STuong Lien tipc_link_create_dummy_tnl_msg(tnl, xmitq);
2133c0b14a08STuong Lien
21348ebed8aeSGeert Uytterhoeven /* This failover link endpoint was never established before,
2135c0b14a08STuong Lien * so it has not received anything from peer.
2136c0b14a08STuong Lien * Otherwise, it must be a normal failover situation or the
2137c0b14a08STuong Lien * node has entered SELF_DOWN_PEER_LEAVING and both peer nodes
2138c0b14a08STuong Lien * would have to start over from scratch instead.
2139c0b14a08STuong Lien */
2140c0b14a08STuong Lien tnl->drop_point = 1;
2141c0b14a08STuong Lien tnl->failover_reasm_skb = NULL;
2142c0b14a08STuong Lien
2143c0b14a08STuong Lien /* Initiate the link's failover deferdq */
2144c0b14a08STuong Lien if (unlikely(!skb_queue_empty(fdefq))) {
2145c0b14a08STuong Lien pr_warn("Link failover deferdq not empty: %d!\n",
2146c0b14a08STuong Lien skb_queue_len(fdefq));
2147c0b14a08STuong Lien __skb_queue_purge(fdefq);
2148c0b14a08STuong Lien }
2149c0b14a08STuong Lien }
2150c0b14a08STuong Lien
21517ea817f4SJon Maloy /* tipc_link_validate_msg(): validate message against current link state
21527ea817f4SJon Maloy * Returns true if message should be accepted, otherwise false
21537ea817f4SJon Maloy */
tipc_link_validate_msg(struct tipc_link * l,struct tipc_msg * hdr)21547ea817f4SJon Maloy bool tipc_link_validate_msg(struct tipc_link *l, struct tipc_msg *hdr)
21557ea817f4SJon Maloy {
21567ea817f4SJon Maloy u16 curr_session = l->peer_session;
21577ea817f4SJon Maloy u16 session = msg_session(hdr);
21587ea817f4SJon Maloy int mtyp = msg_type(hdr);
21597ea817f4SJon Maloy
21607ea817f4SJon Maloy if (msg_user(hdr) != LINK_PROTOCOL)
21617ea817f4SJon Maloy return true;
21627ea817f4SJon Maloy
21637ea817f4SJon Maloy switch (mtyp) {
21647ea817f4SJon Maloy case RESET_MSG:
21657ea817f4SJon Maloy if (!l->in_session)
21667ea817f4SJon Maloy return true;
21677ea817f4SJon Maloy /* Accept only RESET with new session number */
21687ea817f4SJon Maloy return more(session, curr_session);
21697ea817f4SJon Maloy case ACTIVATE_MSG:
21707ea817f4SJon Maloy if (!l->in_session)
21717ea817f4SJon Maloy return true;
21727ea817f4SJon Maloy /* Accept only ACTIVATE with new or current session number */
21737ea817f4SJon Maloy return !less(session, curr_session);
21747ea817f4SJon Maloy case STATE_MSG:
21757ea817f4SJon Maloy /* Accept only STATE with current session number */
21767ea817f4SJon Maloy if (!l->in_session)
21777ea817f4SJon Maloy return false;
21787ea817f4SJon Maloy if (session != curr_session)
21797ea817f4SJon Maloy return false;
2180d949cfedSLUU Duc Canh /* Extra sanity check */
2181d949cfedSLUU Duc Canh if (!link_is_up(l) && msg_ack(hdr))
2182d949cfedSLUU Duc Canh return false;
21837ea817f4SJon Maloy if (!(l->peer_caps & TIPC_LINK_PROTO_SEQNO))
21847ea817f4SJon Maloy return true;
21857ea817f4SJon Maloy /* Accept only STATE with new sequence number */
21867ea817f4SJon Maloy return !less(msg_seqno(hdr), l->rcv_nxt_state);
21877ea817f4SJon Maloy default:
21887ea817f4SJon Maloy return false;
21897ea817f4SJon Maloy }
21907ea817f4SJon Maloy }
21917ea817f4SJon Maloy
2192d999297cSJon Paul Maloy /* tipc_link_proto_rcv(): receive link level protocol message :
2193d999297cSJon Paul Maloy * Note that network plane id propagates through the network, and may
2194d999297cSJon Paul Maloy * change at any time. The node with lowest numerical id determines
2195d999297cSJon Paul Maloy * network plane
2196d999297cSJon Paul Maloy */
tipc_link_proto_rcv(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * xmitq)2197d999297cSJon Paul Maloy static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
2198d999297cSJon Paul Maloy struct sk_buff_head *xmitq)
2199d999297cSJon Paul Maloy {
2200d999297cSJon Paul Maloy struct tipc_msg *hdr = buf_msg(skb);
22019195948fSTuong Lien struct tipc_gap_ack_blks *ga = NULL;
2202d7626b5aSTuong Lien bool reply = msg_probe(hdr), retransmitted = false;
220356077b56SXin Long u32 dlen = msg_data_sz(hdr), glen = 0, msg_max;
2204d999297cSJon Paul Maloy u16 peers_snd_nxt = msg_next_sent(hdr);
2205d999297cSJon Paul Maloy u16 peers_tol = msg_link_tolerance(hdr);
2206d999297cSJon Paul Maloy u16 peers_prio = msg_linkprio(hdr);
2207d7626b5aSTuong Lien u16 gap = msg_seq_gap(hdr);
2208d7626b5aSTuong Lien u16 ack = msg_ack(hdr);
22092be80c2dSJon Paul Maloy u16 rcv_nxt = l->rcv_nxt;
2210d7626b5aSTuong Lien u16 rcvgap = 0;
221173f646ceSJon Paul Maloy int mtyp = msg_type(hdr);
2212d7626b5aSTuong Lien int rc = 0, released;
2213d999297cSJon Paul Maloy char *if_name;
2214d7626b5aSTuong Lien void *data;
2215d999297cSJon Paul Maloy
221626574db0STuong Lien trace_tipc_proto_rcv(skb, false, l->name);
22179aa422adSJon Maloy
22189aa422adSJon Maloy if (dlen > U16_MAX)
22199aa422adSJon Maloy goto exit;
22209aa422adSJon Maloy
222152666986SJon Paul Maloy if (tipc_link_is_blocked(l) || !xmitq)
2222d999297cSJon Paul Maloy goto exit;
2223d999297cSJon Paul Maloy
2224e74a386dSJon Paul Maloy if (tipc_own_addr(l->net) > msg_prevnode(hdr))
2225d999297cSJon Paul Maloy l->net_plane = msg_net_plane(hdr);
2226d999297cSJon Paul Maloy
2227743117a9SYueHaibing if (skb_linearize(skb))
2228743117a9SYueHaibing goto exit;
2229743117a9SYueHaibing
223035c55c98SJon Paul Maloy hdr = buf_msg(skb);
223135c55c98SJon Paul Maloy data = msg_data(hdr);
223235c55c98SJon Paul Maloy
223326574db0STuong Lien if (!tipc_link_validate_msg(l, hdr)) {
223426574db0STuong Lien trace_tipc_skb_dump(skb, false, "PROTO invalid (1)!");
223526574db0STuong Lien trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (1)!");
22367ea817f4SJon Maloy goto exit;
223726574db0STuong Lien }
22387ea817f4SJon Maloy
223973f646ceSJon Paul Maloy switch (mtyp) {
2240d999297cSJon Paul Maloy case RESET_MSG:
2241d999297cSJon Paul Maloy case ACTIVATE_MSG:
224256077b56SXin Long msg_max = msg_max_pkt(hdr);
224356077b56SXin Long if (msg_max < tipc_bearer_min_mtu(l->net, l->bearer_id))
224456077b56SXin Long break;
2245d999297cSJon Paul Maloy /* Complete own link name with peer's interface name */
2246d999297cSJon Paul Maloy if_name = strrchr(l->name, ':') + 1;
2247d999297cSJon Paul Maloy if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME)
2248d999297cSJon Paul Maloy break;
2249d999297cSJon Paul Maloy if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME)
2250d999297cSJon Paul Maloy break;
225135c55c98SJon Paul Maloy strncpy(if_name, data, TIPC_MAX_IF_NAME);
2252d999297cSJon Paul Maloy
2253d999297cSJon Paul Maloy /* Update own tolerance if peer indicates a non-zero value */
2254f9bff0e3SMatthew Wilcox (Oracle) if (tipc_in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
2255d999297cSJon Paul Maloy l->tolerance = peers_tol;
2256047491eaSJon Maloy l->bc_rcvlink->tolerance = peers_tol;
2257047491eaSJon Maloy }
2258d999297cSJon Paul Maloy /* Update own priority if peer's priority is higher */
2259f9bff0e3SMatthew Wilcox (Oracle) if (tipc_in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI))
2260d999297cSJon Paul Maloy l->priority = peers_prio;
2261d999297cSJon Paul Maloy
22627ab412d3SJon Maloy /* If peer is going down we want full re-establish cycle */
22637ab412d3SJon Maloy if (msg_peer_stopping(hdr)) {
2264634696b1SJon Paul Maloy rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
22657ab412d3SJon Maloy break;
22667ab412d3SJon Maloy }
226791986ee1STuong Lien
226891986ee1STuong Lien /* If this endpoint was re-created while peer was ESTABLISHING
226991986ee1STuong Lien * it doesn't know current session number. Force re-synch.
227091986ee1STuong Lien */
227191986ee1STuong Lien if (mtyp == ACTIVATE_MSG && msg_dest_session_valid(hdr) &&
227291986ee1STuong Lien l->session != msg_dest_session(hdr)) {
227391986ee1STuong Lien if (less(l->session, msg_dest_session(hdr)))
227491986ee1STuong Lien l->session = msg_dest_session(hdr) + 1;
227591986ee1STuong Lien break;
227691986ee1STuong Lien }
227791986ee1STuong Lien
22787ab412d3SJon Maloy /* ACTIVATE_MSG serves as PEER_RESET if link is already down */
22797ab412d3SJon Maloy if (mtyp == RESET_MSG || !link_is_up(l))
228073f646ceSJon Paul Maloy rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
228173f646ceSJon Paul Maloy
228273f646ceSJon Paul Maloy /* ACTIVATE_MSG takes up link if it was already locally reset */
22837ab412d3SJon Maloy if (mtyp == ACTIVATE_MSG && l->state == LINK_ESTABLISHING)
228473f646ceSJon Paul Maloy rc = TIPC_LINK_UP_EVT;
228573f646ceSJon Paul Maloy
2286d999297cSJon Paul Maloy l->peer_session = msg_session(hdr);
22877ea817f4SJon Maloy l->in_session = true;
2288d999297cSJon Paul Maloy l->peer_bearer_id = msg_bearer_id(hdr);
228956077b56SXin Long if (l->mtu > msg_max)
229056077b56SXin Long l->mtu = msg_max;
2291d999297cSJon Paul Maloy break;
2292662921cdSJon Paul Maloy
2293d999297cSJon Paul Maloy case STATE_MSG:
2294c79fcc27STung Nguyen /* Validate Gap ACK blocks, drop if invalid */
2295c79fcc27STung Nguyen glen = tipc_get_gap_ack_blks(&ga, l, hdr, true);
2296c79fcc27STung Nguyen if (glen > dlen)
2297c79fcc27STung Nguyen break;
2298c79fcc27STung Nguyen
22999012de50SJon Maloy l->rcv_nxt_state = msg_seqno(hdr) + 1;
23009012de50SJon Maloy
2301d999297cSJon Paul Maloy /* Update own tolerance if peer indicates a non-zero value */
2302f9bff0e3SMatthew Wilcox (Oracle) if (tipc_in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
2303d999297cSJon Paul Maloy l->tolerance = peers_tol;
2304047491eaSJon Maloy l->bc_rcvlink->tolerance = peers_tol;
2305047491eaSJon Maloy }
2306f7967556SJon Paul Maloy /* Update own prio if peer indicates a different value */
2307f7967556SJon Paul Maloy if ((peers_prio != l->priority) &&
2308f9bff0e3SMatthew Wilcox (Oracle) tipc_in_range(peers_prio, 1, TIPC_MAX_LINK_PRI)) {
230981729810SRichard Alpe l->priority = peers_prio;
231081729810SRichard Alpe rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
231181729810SRichard Alpe }
231281729810SRichard Alpe
2313d999297cSJon Paul Maloy l->silent_intv_cnt = 0;
2314d999297cSJon Paul Maloy l->stats.recv_states++;
2315d999297cSJon Paul Maloy if (msg_probe(hdr))
2316d999297cSJon Paul Maloy l->stats.recv_probes++;
231773f646ceSJon Paul Maloy
231873f646ceSJon Paul Maloy if (!link_is_up(l)) {
231973f646ceSJon Paul Maloy if (l->state == LINK_ESTABLISHING)
232073f646ceSJon Paul Maloy rc = TIPC_LINK_UP_EVT;
2321d999297cSJon Paul Maloy break;
232273f646ceSJon Paul Maloy }
23239195948fSTuong Lien
23249195948fSTuong Lien tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr,
232535c55c98SJon Paul Maloy &l->mon_state, l->bearer_id);
2326d999297cSJon Paul Maloy
2327662921cdSJon Paul Maloy /* Send NACK if peer has sent pkts we haven't received yet */
2328d3b09995SJon Maloy if ((reply || msg_is_keepalive(hdr)) &&
2329d3b09995SJon Maloy more(peers_snd_nxt, rcv_nxt) &&
2330d3b09995SJon Maloy !tipc_link_is_synching(l) &&
2331d3b09995SJon Maloy skb_queue_empty(&l->deferdq))
2332d999297cSJon Paul Maloy rcvgap = peers_snd_nxt - l->rcv_nxt;
23338d6e79d3SJon Maloy if (rcvgap || reply)
23348d6e79d3SJon Maloy tipc_link_build_proto_msg(l, STATE_MSG, 0, reply,
23358d6e79d3SJon Maloy rcvgap, 0, 0, xmitq);
2336d999297cSJon Paul Maloy
2337d7626b5aSTuong Lien released = tipc_link_advance_transmq(l, l, ack, gap, ga, xmitq,
2338d7626b5aSTuong Lien &retransmitted, &rc);
23399195948fSTuong Lien if (gap)
2340d999297cSJon Paul Maloy l->stats.recv_nacks++;
2341d7626b5aSTuong Lien if (released || retransmitted)
2342d7626b5aSTuong Lien tipc_link_update_cwin(l, released, retransmitted);
2343d7626b5aSTuong Lien if (released)
2344d7626b5aSTuong Lien tipc_link_advance_backlog(l, xmitq);
2345d999297cSJon Paul Maloy if (unlikely(!skb_queue_empty(&l->wakeupq)))
2346d999297cSJon Paul Maloy link_prepare_wakeup(l);
2347d999297cSJon Paul Maloy }
2348d999297cSJon Paul Maloy exit:
2349d999297cSJon Paul Maloy kfree_skb(skb);
2350d999297cSJon Paul Maloy return rc;
2351d999297cSJon Paul Maloy }
2352d999297cSJon Paul Maloy
235352666986SJon Paul Maloy /* tipc_link_build_bc_proto_msg() - create broadcast protocol message
235452666986SJon Paul Maloy */
tipc_link_build_bc_proto_msg(struct tipc_link * l,bool bcast,u16 peers_snd_nxt,struct sk_buff_head * xmitq)235552666986SJon Paul Maloy static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
235652666986SJon Paul Maloy u16 peers_snd_nxt,
235752666986SJon Paul Maloy struct sk_buff_head *xmitq)
235852666986SJon Paul Maloy {
235952666986SJon Paul Maloy struct sk_buff *skb;
236052666986SJon Paul Maloy struct tipc_msg *hdr;
236152666986SJon Paul Maloy struct sk_buff *dfrd_skb = skb_peek(&l->deferdq);
236252666986SJon Paul Maloy u16 ack = l->rcv_nxt - 1;
236352666986SJon Paul Maloy u16 gap_to = peers_snd_nxt - 1;
236452666986SJon Paul Maloy
236552666986SJon Paul Maloy skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE,
2366e74a386dSJon Paul Maloy 0, l->addr, tipc_own_addr(l->net), 0, 0, 0);
236752666986SJon Paul Maloy if (!skb)
236852666986SJon Paul Maloy return false;
236952666986SJon Paul Maloy hdr = buf_msg(skb);
237052666986SJon Paul Maloy msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
237152666986SJon Paul Maloy msg_set_bcast_ack(hdr, ack);
237252666986SJon Paul Maloy msg_set_bcgap_after(hdr, ack);
237352666986SJon Paul Maloy if (dfrd_skb)
237452666986SJon Paul Maloy gap_to = buf_seqno(dfrd_skb) - 1;
237552666986SJon Paul Maloy msg_set_bcgap_to(hdr, gap_to);
237652666986SJon Paul Maloy msg_set_non_seq(hdr, bcast);
237752666986SJon Paul Maloy __skb_queue_tail(xmitq, skb);
237852666986SJon Paul Maloy return true;
237952666986SJon Paul Maloy }
238052666986SJon Paul Maloy
238152666986SJon Paul Maloy /* tipc_link_build_bc_init_msg() - synchronize broadcast link endpoints.
238252666986SJon Paul Maloy *
238352666986SJon Paul Maloy * Give a newly added peer node the sequence number where it should
238452666986SJon Paul Maloy * start receiving and acking broadcast packets.
238552666986SJon Paul Maloy */
tipc_link_build_bc_init_msg(struct tipc_link * l,struct sk_buff_head * xmitq)2386742e0383SWu Fengguang static void tipc_link_build_bc_init_msg(struct tipc_link *l,
238752666986SJon Paul Maloy struct sk_buff_head *xmitq)
238852666986SJon Paul Maloy {
238952666986SJon Paul Maloy struct sk_buff_head list;
239052666986SJon Paul Maloy
239152666986SJon Paul Maloy __skb_queue_head_init(&list);
239252666986SJon Paul Maloy if (!tipc_link_build_bc_proto_msg(l->bc_rcvlink, false, 0, &list))
239352666986SJon Paul Maloy return;
239406bd2b1eSJon Paul Maloy msg_set_bc_ack_invalid(buf_msg(skb_peek(&list)), true);
239552666986SJon Paul Maloy tipc_link_xmit(l, &list, xmitq);
239652666986SJon Paul Maloy }
239752666986SJon Paul Maloy
239852666986SJon Paul Maloy /* tipc_link_bc_init_rcv - receive initial broadcast synch data from peer
239952666986SJon Paul Maloy */
tipc_link_bc_init_rcv(struct tipc_link * l,struct tipc_msg * hdr)240052666986SJon Paul Maloy void tipc_link_bc_init_rcv(struct tipc_link *l, struct tipc_msg *hdr)
240152666986SJon Paul Maloy {
240252666986SJon Paul Maloy int mtyp = msg_type(hdr);
240352666986SJon Paul Maloy u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
240452666986SJon Paul Maloy
240552666986SJon Paul Maloy if (link_is_up(l))
240652666986SJon Paul Maloy return;
240752666986SJon Paul Maloy
240852666986SJon Paul Maloy if (msg_user(hdr) == BCAST_PROTOCOL) {
240952666986SJon Paul Maloy l->rcv_nxt = peers_snd_nxt;
241052666986SJon Paul Maloy l->state = LINK_ESTABLISHED;
241152666986SJon Paul Maloy return;
241252666986SJon Paul Maloy }
241352666986SJon Paul Maloy
241452666986SJon Paul Maloy if (l->peer_caps & TIPC_BCAST_SYNCH)
241552666986SJon Paul Maloy return;
241652666986SJon Paul Maloy
241752666986SJon Paul Maloy if (msg_peer_node_is_up(hdr))
241852666986SJon Paul Maloy return;
241952666986SJon Paul Maloy
242052666986SJon Paul Maloy /* Compatibility: accept older, less safe initial synch data */
242152666986SJon Paul Maloy if ((mtyp == RESET_MSG) || (mtyp == ACTIVATE_MSG))
242252666986SJon Paul Maloy l->rcv_nxt = peers_snd_nxt;
242352666986SJon Paul Maloy }
242452666986SJon Paul Maloy
242552666986SJon Paul Maloy /* tipc_link_bc_sync_rcv - update rcv link according to peer's send state
242652666986SJon Paul Maloy */
tipc_link_bc_sync_rcv(struct tipc_link * l,struct tipc_msg * hdr,struct sk_buff_head * xmitq)242702d11ca2SJon Paul Maloy int tipc_link_bc_sync_rcv(struct tipc_link *l, struct tipc_msg *hdr,
242852666986SJon Paul Maloy struct sk_buff_head *xmitq)
242952666986SJon Paul Maloy {
243052666986SJon Paul Maloy u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
243102d11ca2SJon Paul Maloy int rc = 0;
243252666986SJon Paul Maloy
243352666986SJon Paul Maloy if (!link_is_up(l))
243402d11ca2SJon Paul Maloy return rc;
243552666986SJon Paul Maloy
243652666986SJon Paul Maloy if (!msg_peer_node_is_up(hdr))
243702d11ca2SJon Paul Maloy return rc;
243852666986SJon Paul Maloy
2439a99df449SRandy Dunlap /* Open when peer acknowledges our bcast init msg (pkt #1) */
24402d18ac4bSJon Paul Maloy if (msg_ack(hdr))
244152666986SJon Paul Maloy l->bc_peer_is_up = true;
244252666986SJon Paul Maloy
24432d18ac4bSJon Paul Maloy if (!l->bc_peer_is_up)
244402d11ca2SJon Paul Maloy return rc;
24452d18ac4bSJon Paul Maloy
244652666986SJon Paul Maloy /* Ignore if peers_snd_nxt goes beyond receive window */
244752666986SJon Paul Maloy if (more(peers_snd_nxt, l->rcv_nxt + l->window))
244802d11ca2SJon Paul Maloy return rc;
244902d11ca2SJon Paul Maloy
245002d11ca2SJon Paul Maloy l->snd_nxt = peers_snd_nxt;
245102d11ca2SJon Paul Maloy if (link_bc_rcv_gap(l))
245202d11ca2SJon Paul Maloy rc |= TIPC_LINK_SND_STATE;
245302d11ca2SJon Paul Maloy
245402d11ca2SJon Paul Maloy /* Return now if sender supports nack via STATE messages */
245502d11ca2SJon Paul Maloy if (l->peer_caps & TIPC_BCAST_STATE_NACK)
245602d11ca2SJon Paul Maloy return rc;
245702d11ca2SJon Paul Maloy
245802d11ca2SJon Paul Maloy /* Otherwise, be backwards compatible */
245952666986SJon Paul Maloy
246052666986SJon Paul Maloy if (!more(peers_snd_nxt, l->rcv_nxt)) {
246152666986SJon Paul Maloy l->nack_state = BC_NACK_SND_CONDITIONAL;
246202d11ca2SJon Paul Maloy return 0;
246352666986SJon Paul Maloy }
246452666986SJon Paul Maloy
246552666986SJon Paul Maloy /* Don't NACK if one was recently sent or peeked */
246652666986SJon Paul Maloy if (l->nack_state == BC_NACK_SND_SUPPRESS) {
246752666986SJon Paul Maloy l->nack_state = BC_NACK_SND_UNCONDITIONAL;
246802d11ca2SJon Paul Maloy return 0;
246952666986SJon Paul Maloy }
247052666986SJon Paul Maloy
247152666986SJon Paul Maloy /* Conditionally delay NACK sending until next synch rcv */
247252666986SJon Paul Maloy if (l->nack_state == BC_NACK_SND_CONDITIONAL) {
247352666986SJon Paul Maloy l->nack_state = BC_NACK_SND_UNCONDITIONAL;
247452666986SJon Paul Maloy if ((peers_snd_nxt - l->rcv_nxt) < TIPC_MIN_LINK_WIN)
247502d11ca2SJon Paul Maloy return 0;
247652666986SJon Paul Maloy }
247752666986SJon Paul Maloy
247852666986SJon Paul Maloy /* Send NACK now but suppress next one */
247952666986SJon Paul Maloy tipc_link_build_bc_proto_msg(l, true, peers_snd_nxt, xmitq);
248052666986SJon Paul Maloy l->nack_state = BC_NACK_SND_SUPPRESS;
248102d11ca2SJon Paul Maloy return 0;
248252666986SJon Paul Maloy }
248352666986SJon Paul Maloy
tipc_link_bc_ack_rcv(struct tipc_link * r,u16 acked,u16 gap,struct tipc_gap_ack_blks * ga,struct sk_buff_head * xmitq,struct sk_buff_head * retrq)2484d7626b5aSTuong Lien int tipc_link_bc_ack_rcv(struct tipc_link *r, u16 acked, u16 gap,
2485d7626b5aSTuong Lien struct tipc_gap_ack_blks *ga,
2486a91d55d1STuong Lien struct sk_buff_head *xmitq,
2487a91d55d1STuong Lien struct sk_buff_head *retrq)
248852666986SJon Paul Maloy {
2489d7626b5aSTuong Lien struct tipc_link *l = r->bc_sndlink;
2490d7626b5aSTuong Lien bool unused = false;
2491d7626b5aSTuong Lien int rc = 0;
249252666986SJon Paul Maloy
2493d7626b5aSTuong Lien if (!link_is_up(r) || !r->bc_peer_is_up)
2494d7626b5aSTuong Lien return 0;
249552666986SJon Paul Maloy
249603b6fefdSTuong Lien if (gap) {
249703b6fefdSTuong Lien l->stats.recv_nacks++;
249803b6fefdSTuong Lien r->stats.recv_nacks++;
249903b6fefdSTuong Lien }
250003b6fefdSTuong Lien
2501d7626b5aSTuong Lien if (less(acked, r->acked) || (acked == r->acked && !gap && !ga))
2502d7626b5aSTuong Lien return 0;
250352666986SJon Paul Maloy
2504c6ed7a5cSTuong Lien trace_tipc_link_bc_ack(r, acked, gap, &l->transmq);
2505a91d55d1STuong Lien tipc_link_advance_transmq(l, r, acked, gap, ga, retrq, &unused, &rc);
250652666986SJon Paul Maloy
2507d7626b5aSTuong Lien tipc_link_advance_backlog(l, xmitq);
2508d7626b5aSTuong Lien if (unlikely(!skb_queue_empty(&l->wakeupq)))
2509d7626b5aSTuong Lien link_prepare_wakeup(l);
2510d7626b5aSTuong Lien
2511d7626b5aSTuong Lien return rc;
251252666986SJon Paul Maloy }
251352666986SJon Paul Maloy
251452666986SJon Paul Maloy /* tipc_link_bc_nack_rcv(): receive broadcast nack message
251502d11ca2SJon Paul Maloy * This function is here for backwards compatibility, since
251602d11ca2SJon Paul Maloy * no BCAST_PROTOCOL/STATE messages occur from TIPC v2.5.
251752666986SJon Paul Maloy */
tipc_link_bc_nack_rcv(struct tipc_link * l,struct sk_buff * skb,struct sk_buff_head * xmitq)251852666986SJon Paul Maloy int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
251952666986SJon Paul Maloy struct sk_buff_head *xmitq)
252052666986SJon Paul Maloy {
252152666986SJon Paul Maloy struct tipc_msg *hdr = buf_msg(skb);
252252666986SJon Paul Maloy u32 dnode = msg_destnode(hdr);
252352666986SJon Paul Maloy int mtyp = msg_type(hdr);
252452666986SJon Paul Maloy u16 acked = msg_bcast_ack(hdr);
252552666986SJon Paul Maloy u16 from = acked + 1;
252652666986SJon Paul Maloy u16 to = msg_bcgap_to(hdr);
252752666986SJon Paul Maloy u16 peers_snd_nxt = to + 1;
252852666986SJon Paul Maloy int rc = 0;
252952666986SJon Paul Maloy
253052666986SJon Paul Maloy kfree_skb(skb);
253152666986SJon Paul Maloy
253252666986SJon Paul Maloy if (!tipc_link_is_up(l) || !l->bc_peer_is_up)
253352666986SJon Paul Maloy return 0;
253452666986SJon Paul Maloy
253552666986SJon Paul Maloy if (mtyp != STATE_MSG)
253652666986SJon Paul Maloy return 0;
253752666986SJon Paul Maloy
2538e74a386dSJon Paul Maloy if (dnode == tipc_own_addr(l->net)) {
2539a91d55d1STuong Lien rc = tipc_link_bc_ack_rcv(l, acked, to - acked, NULL, xmitq,
2540a91d55d1STuong Lien xmitq);
254152666986SJon Paul Maloy l->stats.recv_nacks++;
254252666986SJon Paul Maloy return rc;
254352666986SJon Paul Maloy }
254452666986SJon Paul Maloy
254552666986SJon Paul Maloy /* Msg for other node => suppress own NACK at next sync if applicable */
254652666986SJon Paul Maloy if (more(peers_snd_nxt, l->rcv_nxt) && !less(l->rcv_nxt, from))
254752666986SJon Paul Maloy l->nack_state = BC_NACK_SND_SUPPRESS;
254852666986SJon Paul Maloy
254952666986SJon Paul Maloy return 0;
255052666986SJon Paul Maloy }
255152666986SJon Paul Maloy
tipc_link_set_queue_limits(struct tipc_link * l,u32 min_win,u32 max_win)255216ad3f40SJon Maloy void tipc_link_set_queue_limits(struct tipc_link *l, u32 min_win, u32 max_win)
2553b97bf3fdSPer Liden {
2554218527feSJon Maloy int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE);
255505dcc5aaSJon Paul Maloy
255616ad3f40SJon Maloy l->min_win = min_win;
255716ad3f40SJon Maloy l->ssthresh = max_win;
255816ad3f40SJon Maloy l->max_win = max_win;
255916ad3f40SJon Maloy l->window = min_win;
256016ad3f40SJon Maloy l->backlog[TIPC_LOW_IMPORTANCE].limit = min_win * 2;
256116ad3f40SJon Maloy l->backlog[TIPC_MEDIUM_IMPORTANCE].limit = min_win * 4;
256216ad3f40SJon Maloy l->backlog[TIPC_HIGH_IMPORTANCE].limit = min_win * 6;
256316ad3f40SJon Maloy l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = min_win * 8;
25641f66d161SJon Paul Maloy l->backlog[TIPC_SYSTEM_IMPORTANCE].limit = max_bulk;
2565b97bf3fdSPer Liden }
2566b97bf3fdSPer Liden
25675c216e1dSAllan Stephens /**
256825764779SMauro Carvalho Chehab * tipc_link_reset_stats - reset link statistics
25691a90632dSJon Paul Maloy * @l: pointer to link
2570b97bf3fdSPer Liden */
tipc_link_reset_stats(struct tipc_link * l)257138206d59SJon Paul Maloy void tipc_link_reset_stats(struct tipc_link *l)
2572b97bf3fdSPer Liden {
257338206d59SJon Paul Maloy memset(&l->stats, 0, sizeof(l->stats));
2574b97bf3fdSPer Liden }
2575b97bf3fdSPer Liden
link_print(struct tipc_link * l,const char * str)25761a20cc25SJon Paul Maloy static void link_print(struct tipc_link *l, const char *str)
2577b97bf3fdSPer Liden {
25781a20cc25SJon Paul Maloy struct sk_buff *hskb = skb_peek(&l->transmq);
2579c1ab3f1dSJon Paul Maloy u16 head = hskb ? msg_seqno(buf_msg(hskb)) : l->snd_nxt - 1;
25801a20cc25SJon Paul Maloy u16 tail = l->snd_nxt - 1;
25817a2f7d18SYing Xue
2582662921cdSJon Paul Maloy pr_info("%s Link <%s> state %x\n", str, l->name, l->state);
25831a20cc25SJon Paul Maloy pr_info("XMTQ: %u [%u-%u], BKLGQ: %u, SNDNX: %u, RCVNX: %u\n",
25841a20cc25SJon Paul Maloy skb_queue_len(&l->transmq), head, tail,
25851a20cc25SJon Paul Maloy skb_queue_len(&l->backlogq), l->snd_nxt, l->rcv_nxt);
2586b97bf3fdSPer Liden }
25870655f6a8SRichard Alpe
25880655f6a8SRichard Alpe /* Parse and validate nested (link) properties valid for media, bearer and link
25890655f6a8SRichard Alpe */
tipc_nl_parse_link_prop(struct nlattr * prop,struct nlattr * props[])25900655f6a8SRichard Alpe int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
25910655f6a8SRichard Alpe {
25920655f6a8SRichard Alpe int err;
25930655f6a8SRichard Alpe
25948cb08174SJohannes Berg err = nla_parse_nested_deprecated(props, TIPC_NLA_PROP_MAX, prop,
2595fceb6435SJohannes Berg tipc_nl_prop_policy, NULL);
25960655f6a8SRichard Alpe if (err)
25970655f6a8SRichard Alpe return err;
25980655f6a8SRichard Alpe
25990655f6a8SRichard Alpe if (props[TIPC_NLA_PROP_PRIO]) {
26000655f6a8SRichard Alpe u32 prio;
26010655f6a8SRichard Alpe
26020655f6a8SRichard Alpe prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
26030655f6a8SRichard Alpe if (prio > TIPC_MAX_LINK_PRI)
26040655f6a8SRichard Alpe return -EINVAL;
26050655f6a8SRichard Alpe }
26060655f6a8SRichard Alpe
26070655f6a8SRichard Alpe if (props[TIPC_NLA_PROP_TOL]) {
26080655f6a8SRichard Alpe u32 tol;
26090655f6a8SRichard Alpe
26100655f6a8SRichard Alpe tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
26110655f6a8SRichard Alpe if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
26120655f6a8SRichard Alpe return -EINVAL;
26130655f6a8SRichard Alpe }
26140655f6a8SRichard Alpe
26150655f6a8SRichard Alpe if (props[TIPC_NLA_PROP_WIN]) {
261616ad3f40SJon Maloy u32 max_win;
26170655f6a8SRichard Alpe
261816ad3f40SJon Maloy max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
261916ad3f40SJon Maloy if (max_win < TIPC_DEF_LINK_WIN || max_win > TIPC_MAX_LINK_WIN)
26200655f6a8SRichard Alpe return -EINVAL;
26210655f6a8SRichard Alpe }
26220655f6a8SRichard Alpe
26230655f6a8SRichard Alpe return 0;
26240655f6a8SRichard Alpe }
26257be57fc6SRichard Alpe
__tipc_nl_add_stats(struct sk_buff * skb,struct tipc_stats * s)2626d8182804SRichard Alpe static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
26277be57fc6SRichard Alpe {
26287be57fc6SRichard Alpe int i;
26297be57fc6SRichard Alpe struct nlattr *stats;
26307be57fc6SRichard Alpe
26317be57fc6SRichard Alpe struct nla_map {
26327be57fc6SRichard Alpe u32 key;
26337be57fc6SRichard Alpe u32 val;
26347be57fc6SRichard Alpe };
26357be57fc6SRichard Alpe
26367be57fc6SRichard Alpe struct nla_map map[] = {
263795901122SJon Paul Maloy {TIPC_NLA_STATS_RX_INFO, 0},
26387be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
26397be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
26407be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
26417be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
264295901122SJon Paul Maloy {TIPC_NLA_STATS_TX_INFO, 0},
26437be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
26447be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
26457be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
26467be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
26477be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
26487be57fc6SRichard Alpe s->msg_length_counts : 1},
26497be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
26507be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
26517be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
26527be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
26537be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
26547be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
26557be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
26567be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
26577be57fc6SRichard Alpe {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
26587be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_STATES, s->recv_states},
26597be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
26607be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
26617be57fc6SRichard Alpe {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
26627be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_STATES, s->sent_states},
26637be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
26647be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
26657be57fc6SRichard Alpe {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
26667be57fc6SRichard Alpe {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
26677be57fc6SRichard Alpe {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
26687be57fc6SRichard Alpe {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
26697be57fc6SRichard Alpe {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
26707be57fc6SRichard Alpe {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
26717be57fc6SRichard Alpe (s->accu_queue_sz / s->queue_sz_counts) : 0}
26727be57fc6SRichard Alpe };
26737be57fc6SRichard Alpe
2674ae0be8deSMichal Kubecek stats = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
26757be57fc6SRichard Alpe if (!stats)
26767be57fc6SRichard Alpe return -EMSGSIZE;
26777be57fc6SRichard Alpe
26787be57fc6SRichard Alpe for (i = 0; i < ARRAY_SIZE(map); i++)
26797be57fc6SRichard Alpe if (nla_put_u32(skb, map[i].key, map[i].val))
26807be57fc6SRichard Alpe goto msg_full;
26817be57fc6SRichard Alpe
26827be57fc6SRichard Alpe nla_nest_end(skb, stats);
26837be57fc6SRichard Alpe
26847be57fc6SRichard Alpe return 0;
26857be57fc6SRichard Alpe msg_full:
26867be57fc6SRichard Alpe nla_nest_cancel(skb, stats);
26877be57fc6SRichard Alpe
26887be57fc6SRichard Alpe return -EMSGSIZE;
26897be57fc6SRichard Alpe }
26907be57fc6SRichard Alpe
26917be57fc6SRichard Alpe /* Caller should hold appropriate locks to protect the link */
__tipc_nl_add_link(struct net * net,struct tipc_nl_msg * msg,struct tipc_link * link,int nlflags)26925be9c086SJon Paul Maloy int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2693f2f67390SNicolas Dichtel struct tipc_link *link, int nlflags)
26947be57fc6SRichard Alpe {
269523fd3eacSJon Maloy u32 self = tipc_own_addr(net);
26967be57fc6SRichard Alpe struct nlattr *attrs;
26977be57fc6SRichard Alpe struct nlattr *prop;
269823fd3eacSJon Maloy void *hdr;
269923fd3eacSJon Maloy int err;
27007be57fc6SRichard Alpe
2701bfb3e5ddSRichard Alpe hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
2702f2f67390SNicolas Dichtel nlflags, TIPC_NL_LINK_GET);
27037be57fc6SRichard Alpe if (!hdr)
27047be57fc6SRichard Alpe return -EMSGSIZE;
27057be57fc6SRichard Alpe
2706ae0be8deSMichal Kubecek attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
27077be57fc6SRichard Alpe if (!attrs)
27087be57fc6SRichard Alpe goto msg_full;
27097be57fc6SRichard Alpe
27107be57fc6SRichard Alpe if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
27117be57fc6SRichard Alpe goto attr_msg_full;
271223fd3eacSJon Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
27137be57fc6SRichard Alpe goto attr_msg_full;
2714ed193eceSJon Paul Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
27157be57fc6SRichard Alpe goto attr_msg_full;
271695901122SJon Paul Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->stats.recv_pkts))
27177be57fc6SRichard Alpe goto attr_msg_full;
271895901122SJon Paul Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->stats.sent_pkts))
27197be57fc6SRichard Alpe goto attr_msg_full;
27207be57fc6SRichard Alpe
27217be57fc6SRichard Alpe if (tipc_link_is_up(link))
27227be57fc6SRichard Alpe if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
27237be57fc6SRichard Alpe goto attr_msg_full;
2724c72fa872SJon Paul Maloy if (link->active)
27257be57fc6SRichard Alpe if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
27267be57fc6SRichard Alpe goto attr_msg_full;
27277be57fc6SRichard Alpe
2728ae0be8deSMichal Kubecek prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
27297be57fc6SRichard Alpe if (!prop)
27307be57fc6SRichard Alpe goto attr_msg_full;
27317be57fc6SRichard Alpe if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
27327be57fc6SRichard Alpe goto prop_msg_full;
27337be57fc6SRichard Alpe if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
27347be57fc6SRichard Alpe goto prop_msg_full;
27357be57fc6SRichard Alpe if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
27361f66d161SJon Paul Maloy link->window))
27377be57fc6SRichard Alpe goto prop_msg_full;
27387be57fc6SRichard Alpe if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
27397be57fc6SRichard Alpe goto prop_msg_full;
27407be57fc6SRichard Alpe nla_nest_end(msg->skb, prop);
27417be57fc6SRichard Alpe
27427be57fc6SRichard Alpe err = __tipc_nl_add_stats(msg->skb, &link->stats);
27437be57fc6SRichard Alpe if (err)
27447be57fc6SRichard Alpe goto attr_msg_full;
27457be57fc6SRichard Alpe
27467be57fc6SRichard Alpe nla_nest_end(msg->skb, attrs);
27477be57fc6SRichard Alpe genlmsg_end(msg->skb, hdr);
27487be57fc6SRichard Alpe
27497be57fc6SRichard Alpe return 0;
27507be57fc6SRichard Alpe
27517be57fc6SRichard Alpe prop_msg_full:
27527be57fc6SRichard Alpe nla_nest_cancel(msg->skb, prop);
27537be57fc6SRichard Alpe attr_msg_full:
27547be57fc6SRichard Alpe nla_nest_cancel(msg->skb, attrs);
27557be57fc6SRichard Alpe msg_full:
27567be57fc6SRichard Alpe genlmsg_cancel(msg->skb, hdr);
27577be57fc6SRichard Alpe
27587be57fc6SRichard Alpe return -EMSGSIZE;
27597be57fc6SRichard Alpe }
276038206d59SJon Paul Maloy
__tipc_nl_add_bc_link_stat(struct sk_buff * skb,struct tipc_stats * stats)276138206d59SJon Paul Maloy static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
276238206d59SJon Paul Maloy struct tipc_stats *stats)
276338206d59SJon Paul Maloy {
276438206d59SJon Paul Maloy int i;
276538206d59SJon Paul Maloy struct nlattr *nest;
276638206d59SJon Paul Maloy
276738206d59SJon Paul Maloy struct nla_map {
276838206d59SJon Paul Maloy __u32 key;
276938206d59SJon Paul Maloy __u32 val;
277038206d59SJon Paul Maloy };
277138206d59SJon Paul Maloy
277238206d59SJon Paul Maloy struct nla_map map[] = {
277395901122SJon Paul Maloy {TIPC_NLA_STATS_RX_INFO, stats->recv_pkts},
277438206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
277538206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
277638206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
277738206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
277895901122SJon Paul Maloy {TIPC_NLA_STATS_TX_INFO, stats->sent_pkts},
277938206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
278038206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
278138206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
278238206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
278338206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
278438206d59SJon Paul Maloy {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
278538206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
278638206d59SJon Paul Maloy {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
278738206d59SJon Paul Maloy {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
278838206d59SJon Paul Maloy {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
278938206d59SJon Paul Maloy {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
279038206d59SJon Paul Maloy {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
279138206d59SJon Paul Maloy {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
279238206d59SJon Paul Maloy (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
279338206d59SJon Paul Maloy };
279438206d59SJon Paul Maloy
2795ae0be8deSMichal Kubecek nest = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
279638206d59SJon Paul Maloy if (!nest)
279738206d59SJon Paul Maloy return -EMSGSIZE;
279838206d59SJon Paul Maloy
279938206d59SJon Paul Maloy for (i = 0; i < ARRAY_SIZE(map); i++)
280038206d59SJon Paul Maloy if (nla_put_u32(skb, map[i].key, map[i].val))
280138206d59SJon Paul Maloy goto msg_full;
280238206d59SJon Paul Maloy
280338206d59SJon Paul Maloy nla_nest_end(skb, nest);
280438206d59SJon Paul Maloy
280538206d59SJon Paul Maloy return 0;
280638206d59SJon Paul Maloy msg_full:
280738206d59SJon Paul Maloy nla_nest_cancel(skb, nest);
280838206d59SJon Paul Maloy
280938206d59SJon Paul Maloy return -EMSGSIZE;
281038206d59SJon Paul Maloy }
281138206d59SJon Paul Maloy
tipc_nl_add_bc_link(struct net * net,struct tipc_nl_msg * msg,struct tipc_link * bcl)281203b6fefdSTuong Lien int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg,
281303b6fefdSTuong Lien struct tipc_link *bcl)
281438206d59SJon Paul Maloy {
281538206d59SJon Paul Maloy int err;
281638206d59SJon Paul Maloy void *hdr;
281738206d59SJon Paul Maloy struct nlattr *attrs;
281838206d59SJon Paul Maloy struct nlattr *prop;
2819cad2929dSHoang Huu Le u32 bc_mode = tipc_bcast_get_mode(net);
282002ec6cafSHoang Le u32 bc_ratio = tipc_bcast_get_broadcast_ratio(net);
282138206d59SJon Paul Maloy
282238206d59SJon Paul Maloy if (!bcl)
282338206d59SJon Paul Maloy return 0;
282438206d59SJon Paul Maloy
282538206d59SJon Paul Maloy tipc_bcast_lock(net);
282638206d59SJon Paul Maloy
282738206d59SJon Paul Maloy hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
282838206d59SJon Paul Maloy NLM_F_MULTI, TIPC_NL_LINK_GET);
2829b53ce3e7SInsu Yun if (!hdr) {
2830b53ce3e7SInsu Yun tipc_bcast_unlock(net);
283138206d59SJon Paul Maloy return -EMSGSIZE;
2832b53ce3e7SInsu Yun }
283338206d59SJon Paul Maloy
2834ae0be8deSMichal Kubecek attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
283538206d59SJon Paul Maloy if (!attrs)
283638206d59SJon Paul Maloy goto msg_full;
283738206d59SJon Paul Maloy
283838206d59SJon Paul Maloy /* The broadcast link is always up */
283938206d59SJon Paul Maloy if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
284038206d59SJon Paul Maloy goto attr_msg_full;
284138206d59SJon Paul Maloy
284238206d59SJon Paul Maloy if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
284338206d59SJon Paul Maloy goto attr_msg_full;
284438206d59SJon Paul Maloy if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
284538206d59SJon Paul Maloy goto attr_msg_full;
284695901122SJon Paul Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, 0))
284738206d59SJon Paul Maloy goto attr_msg_full;
284895901122SJon Paul Maloy if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0))
284938206d59SJon Paul Maloy goto attr_msg_full;
285038206d59SJon Paul Maloy
2851ae0be8deSMichal Kubecek prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
285238206d59SJon Paul Maloy if (!prop)
285338206d59SJon Paul Maloy goto attr_msg_full;
285416ad3f40SJon Maloy if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->max_win))
285538206d59SJon Paul Maloy goto prop_msg_full;
285602ec6cafSHoang Le if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST, bc_mode))
285702ec6cafSHoang Le goto prop_msg_full;
285802ec6cafSHoang Le if (bc_mode & BCLINK_MODE_SEL)
285902ec6cafSHoang Le if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST_RATIO,
286002ec6cafSHoang Le bc_ratio))
286102ec6cafSHoang Le goto prop_msg_full;
286238206d59SJon Paul Maloy nla_nest_end(msg->skb, prop);
286338206d59SJon Paul Maloy
286438206d59SJon Paul Maloy err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
286538206d59SJon Paul Maloy if (err)
286638206d59SJon Paul Maloy goto attr_msg_full;
286738206d59SJon Paul Maloy
286838206d59SJon Paul Maloy tipc_bcast_unlock(net);
286938206d59SJon Paul Maloy nla_nest_end(msg->skb, attrs);
287038206d59SJon Paul Maloy genlmsg_end(msg->skb, hdr);
287138206d59SJon Paul Maloy
287238206d59SJon Paul Maloy return 0;
287338206d59SJon Paul Maloy
287438206d59SJon Paul Maloy prop_msg_full:
287538206d59SJon Paul Maloy nla_nest_cancel(msg->skb, prop);
287638206d59SJon Paul Maloy attr_msg_full:
287738206d59SJon Paul Maloy nla_nest_cancel(msg->skb, attrs);
287838206d59SJon Paul Maloy msg_full:
287938206d59SJon Paul Maloy tipc_bcast_unlock(net);
288038206d59SJon Paul Maloy genlmsg_cancel(msg->skb, hdr);
288138206d59SJon Paul Maloy
288238206d59SJon Paul Maloy return -EMSGSIZE;
288338206d59SJon Paul Maloy }
288438206d59SJon Paul Maloy
tipc_link_set_tolerance(struct tipc_link * l,u32 tol,struct sk_buff_head * xmitq)2885d01332f1SRichard Alpe void tipc_link_set_tolerance(struct tipc_link *l, u32 tol,
2886d01332f1SRichard Alpe struct sk_buff_head *xmitq)
288738206d59SJon Paul Maloy {
288838206d59SJon Paul Maloy l->tolerance = tol;
2889047491eaSJon Maloy if (l->bc_rcvlink)
2890047491eaSJon Maloy l->bc_rcvlink->tolerance = tol;
289137c64cf6SJon Maloy if (link_is_up(l))
28928d6e79d3SJon Maloy tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, tol, 0, xmitq);
289338206d59SJon Paul Maloy }
289438206d59SJon Paul Maloy
tipc_link_set_prio(struct tipc_link * l,u32 prio,struct sk_buff_head * xmitq)2895d01332f1SRichard Alpe void tipc_link_set_prio(struct tipc_link *l, u32 prio,
2896d01332f1SRichard Alpe struct sk_buff_head *xmitq)
289738206d59SJon Paul Maloy {
289838206d59SJon Paul Maloy l->priority = prio;
28998d6e79d3SJon Maloy tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, prio, xmitq);
290038206d59SJon Paul Maloy }
290138206d59SJon Paul Maloy
tipc_link_set_abort_limit(struct tipc_link * l,u32 limit)290238206d59SJon Paul Maloy void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit)
290338206d59SJon Paul Maloy {
290438206d59SJon Paul Maloy l->abort_limit = limit;
290538206d59SJon Paul Maloy }
2906b4b9771bSTuong Lien
2907b4b9771bSTuong Lien /**
2908b4b9771bSTuong Lien * tipc_link_dump - dump TIPC link data
2909b4b9771bSTuong Lien * @l: tipc link to be dumped
2910b4b9771bSTuong Lien * @dqueues: bitmask to decide if any link queue to be dumped?
2911b4b9771bSTuong Lien * - TIPC_DUMP_NONE: don't dump link queues
2912b4b9771bSTuong Lien * - TIPC_DUMP_TRANSMQ: dump link transmq queue
2913b4b9771bSTuong Lien * - TIPC_DUMP_BACKLOGQ: dump link backlog queue
2914b4b9771bSTuong Lien * - TIPC_DUMP_DEFERDQ: dump link deferd queue
2915b4b9771bSTuong Lien * - TIPC_DUMP_INPUTQ: dump link input queue
2916b4b9771bSTuong Lien * - TIPC_DUMP_WAKEUP: dump link wakeup queue
2917b4b9771bSTuong Lien * - TIPC_DUMP_ALL: dump all the link queues above
2918b4b9771bSTuong Lien * @buf: returned buffer of dump data in format
2919b4b9771bSTuong Lien */
tipc_link_dump(struct tipc_link * l,u16 dqueues,char * buf)2920b4b9771bSTuong Lien int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf)
2921b4b9771bSTuong Lien {
2922b4b9771bSTuong Lien int i = 0;
2923b4b9771bSTuong Lien size_t sz = (dqueues) ? LINK_LMAX : LINK_LMIN;
2924b4b9771bSTuong Lien struct sk_buff_head *list;
2925b4b9771bSTuong Lien struct sk_buff *hskb, *tskb;
2926b4b9771bSTuong Lien u32 len;
2927b4b9771bSTuong Lien
2928b4b9771bSTuong Lien if (!l) {
2929b4b9771bSTuong Lien i += scnprintf(buf, sz, "link data: (null)\n");
2930b4b9771bSTuong Lien return i;
2931b4b9771bSTuong Lien }
2932b4b9771bSTuong Lien
2933b4b9771bSTuong Lien i += scnprintf(buf, sz, "link data: %x", l->addr);
2934b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %x", l->state);
2935b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->in_session);
2936b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->session);
2937b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->peer_session);
2938b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt);
2939b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt);
2940b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt_state);
2941b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt_state);
2942b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %x", l->peer_caps);
2943b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->silent_intv_cnt);
2944b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->rst_cnt);
294571204231STuong Lien i += scnprintf(buf + i, sz - i, " %u", 0);
294677cf8edbSJon Maloy i += scnprintf(buf + i, sz - i, " %u", 0);
2947b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " %u", l->acked);
2948b4b9771bSTuong Lien
2949b4b9771bSTuong Lien list = &l->transmq;
2950b4b9771bSTuong Lien len = skb_queue_len(list);
2951b4b9771bSTuong Lien hskb = skb_peek(list);
2952b4b9771bSTuong Lien tskb = skb_peek_tail(list);
2953b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2954b4b9771bSTuong Lien (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2955b4b9771bSTuong Lien (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2956b4b9771bSTuong Lien
2957b4b9771bSTuong Lien list = &l->deferdq;
2958b4b9771bSTuong Lien len = skb_queue_len(list);
2959b4b9771bSTuong Lien hskb = skb_peek(list);
2960b4b9771bSTuong Lien tskb = skb_peek_tail(list);
2961b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2962b4b9771bSTuong Lien (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2963b4b9771bSTuong Lien (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2964b4b9771bSTuong Lien
2965b4b9771bSTuong Lien list = &l->backlogq;
2966b4b9771bSTuong Lien len = skb_queue_len(list);
2967b4b9771bSTuong Lien hskb = skb_peek(list);
2968b4b9771bSTuong Lien tskb = skb_peek_tail(list);
2969b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2970b4b9771bSTuong Lien (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2971b4b9771bSTuong Lien (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2972b4b9771bSTuong Lien
2973b4b9771bSTuong Lien list = l->inputq;
2974b4b9771bSTuong Lien len = skb_queue_len(list);
2975b4b9771bSTuong Lien hskb = skb_peek(list);
2976b4b9771bSTuong Lien tskb = skb_peek_tail(list);
2977b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, " | %u %u %u\n", len,
2978b4b9771bSTuong Lien (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2979b4b9771bSTuong Lien (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2980b4b9771bSTuong Lien
2981b4b9771bSTuong Lien if (dqueues & TIPC_DUMP_TRANSMQ) {
2982b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, "transmq: ");
2983b4b9771bSTuong Lien i += tipc_list_dump(&l->transmq, false, buf + i);
2984b4b9771bSTuong Lien }
2985b4b9771bSTuong Lien if (dqueues & TIPC_DUMP_BACKLOGQ) {
2986b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i,
2987b4b9771bSTuong Lien "backlogq: <%u %u %u %u %u>, ",
2988b4b9771bSTuong Lien l->backlog[TIPC_LOW_IMPORTANCE].len,
2989b4b9771bSTuong Lien l->backlog[TIPC_MEDIUM_IMPORTANCE].len,
2990b4b9771bSTuong Lien l->backlog[TIPC_HIGH_IMPORTANCE].len,
2991b4b9771bSTuong Lien l->backlog[TIPC_CRITICAL_IMPORTANCE].len,
2992b4b9771bSTuong Lien l->backlog[TIPC_SYSTEM_IMPORTANCE].len);
2993b4b9771bSTuong Lien i += tipc_list_dump(&l->backlogq, false, buf + i);
2994b4b9771bSTuong Lien }
2995b4b9771bSTuong Lien if (dqueues & TIPC_DUMP_DEFERDQ) {
2996b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, "deferdq: ");
2997b4b9771bSTuong Lien i += tipc_list_dump(&l->deferdq, false, buf + i);
2998b4b9771bSTuong Lien }
2999b4b9771bSTuong Lien if (dqueues & TIPC_DUMP_INPUTQ) {
3000b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, "inputq: ");
3001b4b9771bSTuong Lien i += tipc_list_dump(l->inputq, false, buf + i);
3002b4b9771bSTuong Lien }
3003b4b9771bSTuong Lien if (dqueues & TIPC_DUMP_WAKEUP) {
3004b4b9771bSTuong Lien i += scnprintf(buf + i, sz - i, "wakeup: ");
3005b4b9771bSTuong Lien i += tipc_list_dump(&l->wakeupq, false, buf + i);
3006b4b9771bSTuong Lien }
3007b4b9771bSTuong Lien
3008b4b9771bSTuong Lien return i;
3009b4b9771bSTuong Lien }
3010