~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/tipc/link.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/tipc/link.c (Version linux-6.12-rc7) and /net/tipc/link.c (Version linux-5.3.18)


  1 /*                                                  1 /*
  2  * net/tipc/link.c: TIPC link code                  2  * net/tipc/link.c: TIPC link code
  3  *                                                  3  *
  4  * Copyright (c) 1996-2007, 2012-2016, Ericsso      4  * Copyright (c) 1996-2007, 2012-2016, Ericsson AB
  5  * Copyright (c) 2004-2007, 2010-2013, Wind Ri      5  * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
  6  * All rights reserved.                             6  * All rights reserved.
  7  *                                                  7  *
  8  * Redistribution and use in source and binary      8  * Redistribution and use in source and binary forms, with or without
  9  * modification, are permitted provided that t      9  * modification, are permitted provided that the following conditions are met:
 10  *                                                 10  *
 11  * 1. Redistributions of source code must reta     11  * 1. Redistributions of source code must retain the above copyright
 12  *    notice, this list of conditions and the      12  *    notice, this list of conditions and the following disclaimer.
 13  * 2. Redistributions in binary form must repr     13  * 2. Redistributions in binary form must reproduce the above copyright
 14  *    notice, this list of conditions and the      14  *    notice, this list of conditions and the following disclaimer in the
 15  *    documentation and/or other materials pro     15  *    documentation and/or other materials provided with the distribution.
 16  * 3. Neither the names of the copyright holde     16  * 3. Neither the names of the copyright holders nor the names of its
 17  *    contributors may be used to endorse or p     17  *    contributors may be used to endorse or promote products derived from
 18  *    this software without specific prior wri     18  *    this software without specific prior written permission.
 19  *                                                 19  *
 20  * Alternatively, this software may be distrib     20  * Alternatively, this software may be distributed under the terms of the
 21  * GNU General Public License ("GPL") version      21  * GNU General Public License ("GPL") version 2 as published by the Free
 22  * Software Foundation.                            22  * Software Foundation.
 23  *                                                 23  *
 24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT      24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCL     25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND F     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYR     27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL     28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT L     29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,      30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THE     31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUD     32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 33  * ARISING IN ANY WAY OUT OF THE USE OF THIS S     33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 34  * POSSIBILITY OF SUCH DAMAGE.                     34  * POSSIBILITY OF SUCH DAMAGE.
 35  */                                                35  */
 36                                                    36 
 37 #include "core.h"                                  37 #include "core.h"
 38 #include "subscr.h"                                38 #include "subscr.h"
 39 #include "link.h"                                  39 #include "link.h"
 40 #include "bcast.h"                                 40 #include "bcast.h"
 41 #include "socket.h"                                41 #include "socket.h"
 42 #include "name_distr.h"                            42 #include "name_distr.h"
 43 #include "discover.h"                              43 #include "discover.h"
 44 #include "netlink.h"                               44 #include "netlink.h"
 45 #include "monitor.h"                               45 #include "monitor.h"
 46 #include "trace.h"                                 46 #include "trace.h"
 47 #include "crypto.h"                            << 
 48                                                    47 
 49 #include <linux/pkt_sched.h>                       48 #include <linux/pkt_sched.h>
 50                                                    49 
 51 struct tipc_stats {                                50 struct tipc_stats {
 52         u32 sent_pkts;                             51         u32 sent_pkts;
 53         u32 recv_pkts;                             52         u32 recv_pkts;
 54         u32 sent_states;                           53         u32 sent_states;
 55         u32 recv_states;                           54         u32 recv_states;
 56         u32 sent_probes;                           55         u32 sent_probes;
 57         u32 recv_probes;                           56         u32 recv_probes;
 58         u32 sent_nacks;                            57         u32 sent_nacks;
 59         u32 recv_nacks;                            58         u32 recv_nacks;
 60         u32 sent_acks;                             59         u32 sent_acks;
 61         u32 sent_bundled;                          60         u32 sent_bundled;
 62         u32 sent_bundles;                          61         u32 sent_bundles;
 63         u32 recv_bundled;                          62         u32 recv_bundled;
 64         u32 recv_bundles;                          63         u32 recv_bundles;
 65         u32 retransmitted;                         64         u32 retransmitted;
 66         u32 sent_fragmented;                       65         u32 sent_fragmented;
 67         u32 sent_fragments;                        66         u32 sent_fragments;
 68         u32 recv_fragmented;                       67         u32 recv_fragmented;
 69         u32 recv_fragments;                        68         u32 recv_fragments;
 70         u32 link_congs;         /* # port send     69         u32 link_congs;         /* # port sends blocked by congestion */
 71         u32 deferred_recv;                         70         u32 deferred_recv;
 72         u32 duplicates;                            71         u32 duplicates;
 73         u32 max_queue_sz;       /* send queue      72         u32 max_queue_sz;       /* send queue size high water mark */
 74         u32 accu_queue_sz;      /* used for se     73         u32 accu_queue_sz;      /* used for send queue size profiling */
 75         u32 queue_sz_counts;    /* used for se     74         u32 queue_sz_counts;    /* used for send queue size profiling */
 76         u32 msg_length_counts;  /* used for me     75         u32 msg_length_counts;  /* used for message length profiling */
 77         u32 msg_lengths_total;  /* used for me     76         u32 msg_lengths_total;  /* used for message length profiling */
 78         u32 msg_length_profile[7]; /* used for     77         u32 msg_length_profile[7]; /* used for msg. length profiling */
 79 };                                                 78 };
 80                                                    79 
 81 /**                                                80 /**
 82  * struct tipc_link - TIPC link data structure     81  * struct tipc_link - TIPC link data structure
 83  * @addr: network address of link's peer node      82  * @addr: network address of link's peer node
 84  * @name: link name character string               83  * @name: link name character string
                                                   >>  84  * @media_addr: media address to use when sending messages over link
                                                   >>  85  * @timer: link timer
 85  * @net: pointer to namespace struct               86  * @net: pointer to namespace struct
                                                   >>  87  * @refcnt: reference counter for permanent references (owner node & timer)
 86  * @peer_session: link session # being used by     88  * @peer_session: link session # being used by peer end of link
 87  * @peer_bearer_id: bearer id used by link's p     89  * @peer_bearer_id: bearer id used by link's peer endpoint
 88  * @bearer_id: local bearer id used by link        90  * @bearer_id: local bearer id used by link
 89  * @tolerance: minimum link continuity loss ne     91  * @tolerance: minimum link continuity loss needed to reset link [in ms]
 90  * @abort_limit: # of unacknowledged continuit     92  * @abort_limit: # of unacknowledged continuity probes needed to reset link
 91  * @state: current state of link FSM               93  * @state: current state of link FSM
 92  * @peer_caps: bitmap describing capabilities      94  * @peer_caps: bitmap describing capabilities of peer node
 93  * @silent_intv_cnt: # of timer intervals with     95  * @silent_intv_cnt: # of timer intervals without any reception from peer
                                                   >>  96  * @proto_msg: template for control messages generated by link
                                                   >>  97  * @pmsg: convenience pointer to "proto_msg" field
 94  * @priority: current link priority                98  * @priority: current link priority
 95  * @net_plane: current link network plane ('A'     99  * @net_plane: current link network plane ('A' through 'H')
 96  * @mon_state: cookie with information needed     100  * @mon_state: cookie with information needed by link monitor
                                                   >> 101  * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
                                                   >> 102  * @exp_msg_count: # of tunnelled messages expected during link changeover
                                                   >> 103  * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
 97  * @mtu: current maximum packet size for this     104  * @mtu: current maximum packet size for this link
 98  * @advertised_mtu: advertised own mtu when li    105  * @advertised_mtu: advertised own mtu when link is being established
                                                   >> 106  * @transmitq: queue for sent, non-acked messages
 99  * @backlogq: queue for messages waiting to be    107  * @backlogq: queue for messages waiting to be sent
                                                   >> 108  * @snt_nxt: next sequence number to use for outbound messages
100  * @ackers: # of peers that needs to ack each     109  * @ackers: # of peers that needs to ack each packet before it can be released
101  * @acked: # last packet acked by a certain pe    110  * @acked: # last packet acked by a certain peer. Used for broadcast.
102  * @rcv_nxt: next sequence number to expect fo    111  * @rcv_nxt: next sequence number to expect for inbound messages
                                                   >> 112  * @deferred_queue: deferred queue saved OOS b'cast message received from node
                                                   >> 113  * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
103  * @inputq: buffer queue for messages to be de    114  * @inputq: buffer queue for messages to be delivered upwards
104  * @namedq: buffer queue for name table messag    115  * @namedq: buffer queue for name table messages to be delivered upwards
                                                   >> 116  * @next_out: ptr to first unsent outbound message in queue
105  * @wakeupq: linked list of wakeup msgs waitin    117  * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
                                                   >> 118  * @long_msg_seq_no: next identifier to use for outbound fragmented messages
106  * @reasm_buf: head of partially reassembled i    119  * @reasm_buf: head of partially reassembled inbound message fragments
                                                   >> 120  * @bc_rcvr: marks that this is a broadcast receiver link
107  * @stats: collects statistics regarding link     121  * @stats: collects statistics regarding link activity
108  * @session: session to be used by link        << 
109  * @snd_nxt_state: next send seq number        << 
110  * @rcv_nxt_state: next rcv seq number         << 
111  * @in_session: have received ACTIVATE_MSG fro << 
112  * @active: link is active                     << 
113  * @if_name: associated interface name         << 
114  * @rst_cnt: link reset counter                << 
115  * @drop_point: seq number for failover handli << 
116  * @failover_reasm_skb: saved failover msg ptr << 
117  * @failover_deferdq: deferred message queue f << 
118  * @transmq: the link's transmit queue         << 
119  * @backlog: link's backlog by priority (impor << 
120  * @snd_nxt: next sequence number to be used   << 
121  * @rcv_unacked: # messages read by user, but  << 
122  * @deferdq: deferred receive queue            << 
123  * @window: sliding window size for congestion << 
124  * @min_win: minimal send window to be used by << 
125  * @ssthresh: slow start threshold for congest << 
126  * @max_win: maximal send window to be used by << 
127  * @cong_acks: congestion acks for congestion  << 
128  * @checkpoint: seq number for congestion wind << 
129  * @reasm_tnlmsg: fragmentation/reassembly are << 
130  * @last_gap: last gap ack blocks for bcast (F << 
131  * @last_ga: ptr to gap ack blocks             << 
132  * @bc_rcvlink: the peer specific link used fo << 
133  * @bc_sndlink: the namespace global link used << 
134  * @nack_state: bcast nack state               << 
135  * @bc_peer_is_up: peer has acked the bcast in << 
136  */                                               122  */
137 struct tipc_link {                                123 struct tipc_link {
138         u32 addr;                                 124         u32 addr;
139         char name[TIPC_MAX_LINK_NAME];            125         char name[TIPC_MAX_LINK_NAME];
140         struct net *net;                          126         struct net *net;
141                                                   127 
142         /* Management and link supervision dat    128         /* Management and link supervision data */
143         u16 peer_session;                         129         u16 peer_session;
144         u16 session;                              130         u16 session;
145         u16 snd_nxt_state;                        131         u16 snd_nxt_state;
146         u16 rcv_nxt_state;                        132         u16 rcv_nxt_state;
147         u32 peer_bearer_id;                       133         u32 peer_bearer_id;
148         u32 bearer_id;                            134         u32 bearer_id;
149         u32 tolerance;                            135         u32 tolerance;
150         u32 abort_limit;                          136         u32 abort_limit;
151         u32 state;                                137         u32 state;
152         u16 peer_caps;                            138         u16 peer_caps;
153         bool in_session;                          139         bool in_session;
154         bool active;                              140         bool active;
155         u32 silent_intv_cnt;                      141         u32 silent_intv_cnt;
156         char if_name[TIPC_MAX_IF_NAME];           142         char if_name[TIPC_MAX_IF_NAME];
157         u32 priority;                             143         u32 priority;
158         char net_plane;                           144         char net_plane;
159         struct tipc_mon_state mon_state;          145         struct tipc_mon_state mon_state;
160         u16 rst_cnt;                              146         u16 rst_cnt;
161                                                   147 
162         /* Failover/synch */                      148         /* Failover/synch */
163         u16 drop_point;                           149         u16 drop_point;
164         struct sk_buff *failover_reasm_skb;       150         struct sk_buff *failover_reasm_skb;
165         struct sk_buff_head failover_deferdq;     151         struct sk_buff_head failover_deferdq;
166                                                   152 
167         /* Max packet negotiation */              153         /* Max packet negotiation */
168         u16 mtu;                                  154         u16 mtu;
169         u16 advertised_mtu;                       155         u16 advertised_mtu;
170                                                   156 
171         /* Sending */                             157         /* Sending */
172         struct sk_buff_head transmq;              158         struct sk_buff_head transmq;
173         struct sk_buff_head backlogq;             159         struct sk_buff_head backlogq;
174         struct {                                  160         struct {
175                 u16 len;                          161                 u16 len;
176                 u16 limit;                        162                 u16 limit;
177                 struct sk_buff *target_bskb;      163                 struct sk_buff *target_bskb;
178         } backlog[5];                             164         } backlog[5];
179         u16 snd_nxt;                              165         u16 snd_nxt;
                                                   >> 166         u16 window;
180                                                   167 
181         /* Reception */                           168         /* Reception */
182         u16 rcv_nxt;                              169         u16 rcv_nxt;
183         u32 rcv_unacked;                          170         u32 rcv_unacked;
184         struct sk_buff_head deferdq;              171         struct sk_buff_head deferdq;
185         struct sk_buff_head *inputq;              172         struct sk_buff_head *inputq;
186         struct sk_buff_head *namedq;              173         struct sk_buff_head *namedq;
187                                                   174 
188         /* Congestion handling */                 175         /* Congestion handling */
189         struct sk_buff_head wakeupq;              176         struct sk_buff_head wakeupq;
190         u16 window;                            << 
191         u16 min_win;                           << 
192         u16 ssthresh;                          << 
193         u16 max_win;                           << 
194         u16 cong_acks;                         << 
195         u16 checkpoint;                        << 
196                                                   177 
197         /* Fragmentation/reassembly */            178         /* Fragmentation/reassembly */
198         struct sk_buff *reasm_buf;                179         struct sk_buff *reasm_buf;
199         struct sk_buff *reasm_tnlmsg;          << 
200                                                   180 
201         /* Broadcast */                           181         /* Broadcast */
202         u16 ackers;                               182         u16 ackers;
203         u16 acked;                                183         u16 acked;
204         u16 last_gap;                          << 
205         struct tipc_gap_ack_blks *last_ga;     << 
206         struct tipc_link *bc_rcvlink;             184         struct tipc_link *bc_rcvlink;
207         struct tipc_link *bc_sndlink;             185         struct tipc_link *bc_sndlink;
208         u8 nack_state;                            186         u8 nack_state;
209         bool bc_peer_is_up;                       187         bool bc_peer_is_up;
210                                                   188 
211         /* Statistics */                          189         /* Statistics */
212         struct tipc_stats stats;                  190         struct tipc_stats stats;
213 };                                                191 };
214                                                   192 
215 /*                                                193 /*
216  * Error message prefixes                         194  * Error message prefixes
217  */                                               195  */
218 static const char *link_co_err = "Link tunneli    196 static const char *link_co_err = "Link tunneling error, ";
219 static const char *link_rst_msg = "Resetting l    197 static const char *link_rst_msg = "Resetting link ";
220                                                   198 
221 /* Send states for broadcast NACKs                199 /* Send states for broadcast NACKs
222  */                                               200  */
223 enum {                                            201 enum {
224         BC_NACK_SND_CONDITIONAL,                  202         BC_NACK_SND_CONDITIONAL,
225         BC_NACK_SND_UNCONDITIONAL,                203         BC_NACK_SND_UNCONDITIONAL,
226         BC_NACK_SND_SUPPRESS,                     204         BC_NACK_SND_SUPPRESS,
227 };                                                205 };
228                                                   206 
229 #define TIPC_BC_RETR_LIM  (jiffies + msecs_to_    207 #define TIPC_BC_RETR_LIM  (jiffies + msecs_to_jiffies(10))
230 #define TIPC_UC_RETR_TIME (jiffies + msecs_to_    208 #define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1))
231                                                   209 
                                                   >> 210 /*
                                                   >> 211  * Interval between NACKs when packets arrive out of order
                                                   >> 212  */
                                                   >> 213 #define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
                                                   >> 214 
232 /* Link FSM states:                               215 /* Link FSM states:
233  */                                               216  */
234 enum {                                            217 enum {
235         LINK_ESTABLISHED     = 0xe,               218         LINK_ESTABLISHED     = 0xe,
236         LINK_ESTABLISHING    = 0xe  << 4,         219         LINK_ESTABLISHING    = 0xe  << 4,
237         LINK_RESET           = 0x1  << 8,         220         LINK_RESET           = 0x1  << 8,
238         LINK_RESETTING       = 0x2  << 12,        221         LINK_RESETTING       = 0x2  << 12,
239         LINK_PEER_RESET      = 0xd  << 16,        222         LINK_PEER_RESET      = 0xd  << 16,
240         LINK_FAILINGOVER     = 0xf  << 20,        223         LINK_FAILINGOVER     = 0xf  << 20,
241         LINK_SYNCHING        = 0xc  << 24         224         LINK_SYNCHING        = 0xc  << 24
242 };                                                225 };
243                                                   226 
                                                   >> 227 /* Link FSM state checking routines
                                                   >> 228  */
                                                   >> 229 static int link_is_up(struct tipc_link *l)
                                                   >> 230 {
                                                   >> 231         return l->state & (LINK_ESTABLISHED | LINK_SYNCHING);
                                                   >> 232 }
                                                   >> 233 
244 static int tipc_link_proto_rcv(struct tipc_lin    234 static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
245                                struct sk_buff_    235                                struct sk_buff_head *xmitq);
246 static void tipc_link_build_proto_msg(struct t    236 static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
247                                       bool pro    237                                       bool probe_reply, u16 rcvgap,
248                                       int tole    238                                       int tolerance, int priority,
249                                       struct s    239                                       struct sk_buff_head *xmitq);
250 static void link_print(struct tipc_link *l, co    240 static void link_print(struct tipc_link *l, const char *str);
251 static int tipc_link_build_nack_msg(struct tip    241 static int tipc_link_build_nack_msg(struct tipc_link *l,
252                                     struct sk_    242                                     struct sk_buff_head *xmitq);
253 static void tipc_link_build_bc_init_msg(struct    243 static void tipc_link_build_bc_init_msg(struct tipc_link *l,
254                                         struct    244                                         struct sk_buff_head *xmitq);
255 static u8 __tipc_build_gap_ack_blks(struct tip !! 245 static bool tipc_link_release_pkts(struct tipc_link *l, u16 to);
256                                     struct tip !! 246 static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data);
257 static u16 tipc_build_gap_ack_blks(struct tipc !! 247 static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
258 static int tipc_link_advance_transmq(struct ti << 
259                                      u16 acked << 
260                                      struct ti    248                                      struct tipc_gap_ack_blks *ga,
261                                      struct sk !! 249                                      struct sk_buff_head *xmitq);
262                                      bool *ret !! 250 
263 static void tipc_link_update_cwin(struct tipc_ << 
264                                   bool retrans << 
265 /*                                                251 /*
266  *  Simple non-static link routines (i.e. refe    252  *  Simple non-static link routines (i.e. referenced outside this file)
267  */                                               253  */
268 bool tipc_link_is_up(struct tipc_link *l)         254 bool tipc_link_is_up(struct tipc_link *l)
269 {                                                 255 {
270         return l->state & (LINK_ESTABLISHED |  !! 256         return link_is_up(l);
271 }                                                 257 }
272                                                   258 
273 bool tipc_link_peer_is_down(struct tipc_link *    259 bool tipc_link_peer_is_down(struct tipc_link *l)
274 {                                                 260 {
275         return l->state == LINK_PEER_RESET;       261         return l->state == LINK_PEER_RESET;
276 }                                                 262 }
277                                                   263 
278 bool tipc_link_is_reset(struct tipc_link *l)      264 bool tipc_link_is_reset(struct tipc_link *l)
279 {                                                 265 {
280         return l->state & (LINK_RESET | LINK_F    266         return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
281 }                                                 267 }
282                                                   268 
283 bool tipc_link_is_establishing(struct tipc_lin    269 bool tipc_link_is_establishing(struct tipc_link *l)
284 {                                                 270 {
285         return l->state == LINK_ESTABLISHING;     271         return l->state == LINK_ESTABLISHING;
286 }                                                 272 }
287                                                   273 
288 bool tipc_link_is_synching(struct tipc_link *l    274 bool tipc_link_is_synching(struct tipc_link *l)
289 {                                                 275 {
290         return l->state == LINK_SYNCHING;         276         return l->state == LINK_SYNCHING;
291 }                                                 277 }
292                                                   278 
293 bool tipc_link_is_failingover(struct tipc_link    279 bool tipc_link_is_failingover(struct tipc_link *l)
294 {                                                 280 {
295         return l->state == LINK_FAILINGOVER;      281         return l->state == LINK_FAILINGOVER;
296 }                                                 282 }
297                                                   283 
298 bool tipc_link_is_blocked(struct tipc_link *l)    284 bool tipc_link_is_blocked(struct tipc_link *l)
299 {                                                 285 {
300         return l->state & (LINK_RESETTING | LI    286         return l->state & (LINK_RESETTING | LINK_PEER_RESET | LINK_FAILINGOVER);
301 }                                                 287 }
302                                                   288 
303 static bool link_is_bc_sndlink(struct tipc_lin    289 static bool link_is_bc_sndlink(struct tipc_link *l)
304 {                                                 290 {
305         return !l->bc_sndlink;                    291         return !l->bc_sndlink;
306 }                                                 292 }
307                                                   293 
308 static bool link_is_bc_rcvlink(struct tipc_lin    294 static bool link_is_bc_rcvlink(struct tipc_link *l)
309 {                                                 295 {
310         return ((l->bc_rcvlink == l) && !link_    296         return ((l->bc_rcvlink == l) && !link_is_bc_sndlink(l));
311 }                                                 297 }
312                                                   298 
313 void tipc_link_set_active(struct tipc_link *l,    299 void tipc_link_set_active(struct tipc_link *l, bool active)
314 {                                                 300 {
315         l->active = active;                       301         l->active = active;
316 }                                                 302 }
317                                                   303 
318 u32 tipc_link_id(struct tipc_link *l)             304 u32 tipc_link_id(struct tipc_link *l)
319 {                                                 305 {
320         return l->peer_bearer_id << 16 | l->be    306         return l->peer_bearer_id << 16 | l->bearer_id;
321 }                                                 307 }
322                                                   308 
323 int tipc_link_min_win(struct tipc_link *l)     !! 309 int tipc_link_window(struct tipc_link *l)
324 {                                              << 
325         return l->min_win;                     << 
326 }                                              << 
327                                                << 
328 int tipc_link_max_win(struct tipc_link *l)     << 
329 {                                                 310 {
330         return l->max_win;                     !! 311         return l->window;
331 }                                                 312 }
332                                                   313 
333 int tipc_link_prio(struct tipc_link *l)           314 int tipc_link_prio(struct tipc_link *l)
334 {                                                 315 {
335         return l->priority;                       316         return l->priority;
336 }                                                 317 }
337                                                   318 
338 unsigned long tipc_link_tolerance(struct tipc_    319 unsigned long tipc_link_tolerance(struct tipc_link *l)
339 {                                                 320 {
340         return l->tolerance;                      321         return l->tolerance;
341 }                                                 322 }
342                                                   323 
343 struct sk_buff_head *tipc_link_inputq(struct t    324 struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
344 {                                                 325 {
345         return l->inputq;                         326         return l->inputq;
346 }                                                 327 }
347                                                   328 
348 char tipc_link_plane(struct tipc_link *l)         329 char tipc_link_plane(struct tipc_link *l)
349 {                                                 330 {
350         return l->net_plane;                      331         return l->net_plane;
351 }                                                 332 }
352                                                   333 
353 struct net *tipc_link_net(struct tipc_link *l) << 
354 {                                              << 
355         return l->net;                         << 
356 }                                              << 
357                                                << 
358 void tipc_link_update_caps(struct tipc_link *l    334 void tipc_link_update_caps(struct tipc_link *l, u16 capabilities)
359 {                                                 335 {
360         l->peer_caps = capabilities;              336         l->peer_caps = capabilities;
361 }                                                 337 }
362                                                   338 
363 void tipc_link_add_bc_peer(struct tipc_link *s    339 void tipc_link_add_bc_peer(struct tipc_link *snd_l,
364                            struct tipc_link *u    340                            struct tipc_link *uc_l,
365                            struct sk_buff_head    341                            struct sk_buff_head *xmitq)
366 {                                                 342 {
367         struct tipc_link *rcv_l = uc_l->bc_rcv    343         struct tipc_link *rcv_l = uc_l->bc_rcvlink;
368                                                   344 
369         snd_l->ackers++;                          345         snd_l->ackers++;
370         rcv_l->acked = snd_l->snd_nxt - 1;        346         rcv_l->acked = snd_l->snd_nxt - 1;
371         snd_l->state = LINK_ESTABLISHED;          347         snd_l->state = LINK_ESTABLISHED;
372         tipc_link_build_bc_init_msg(uc_l, xmit    348         tipc_link_build_bc_init_msg(uc_l, xmitq);
373 }                                                 349 }
374                                                   350 
375 void tipc_link_remove_bc_peer(struct tipc_link    351 void tipc_link_remove_bc_peer(struct tipc_link *snd_l,
376                               struct tipc_link    352                               struct tipc_link *rcv_l,
377                               struct sk_buff_h    353                               struct sk_buff_head *xmitq)
378 {                                                 354 {
379         u16 ack = snd_l->snd_nxt - 1;             355         u16 ack = snd_l->snd_nxt - 1;
380                                                   356 
381         snd_l->ackers--;                          357         snd_l->ackers--;
382         rcv_l->bc_peer_is_up = true;              358         rcv_l->bc_peer_is_up = true;
383         rcv_l->state = LINK_ESTABLISHED;          359         rcv_l->state = LINK_ESTABLISHED;
384         tipc_link_bc_ack_rcv(rcv_l, ack, 0, NU !! 360         tipc_link_bc_ack_rcv(rcv_l, ack, xmitq);
385         trace_tipc_link_reset(rcv_l, TIPC_DUMP    361         trace_tipc_link_reset(rcv_l, TIPC_DUMP_ALL, "bclink removed!");
386         tipc_link_reset(rcv_l);                   362         tipc_link_reset(rcv_l);
387         rcv_l->state = LINK_RESET;                363         rcv_l->state = LINK_RESET;
388         if (!snd_l->ackers) {                     364         if (!snd_l->ackers) {
389                 trace_tipc_link_reset(snd_l, T    365                 trace_tipc_link_reset(snd_l, TIPC_DUMP_ALL, "zero ackers!");
390                 tipc_link_reset(snd_l);           366                 tipc_link_reset(snd_l);
391                 snd_l->state = LINK_RESET;        367                 snd_l->state = LINK_RESET;
392                 __skb_queue_purge(xmitq);         368                 __skb_queue_purge(xmitq);
393         }                                         369         }
394 }                                                 370 }
395                                                   371 
396 int tipc_link_bc_peers(struct tipc_link *l)       372 int tipc_link_bc_peers(struct tipc_link *l)
397 {                                                 373 {
398         return l->ackers;                         374         return l->ackers;
399 }                                                 375 }
400                                                   376 
401 static u16 link_bc_rcv_gap(struct tipc_link *l    377 static u16 link_bc_rcv_gap(struct tipc_link *l)
402 {                                                 378 {
403         struct sk_buff *skb = skb_peek(&l->def    379         struct sk_buff *skb = skb_peek(&l->deferdq);
404         u16 gap = 0;                              380         u16 gap = 0;
405                                                   381 
406         if (more(l->snd_nxt, l->rcv_nxt))         382         if (more(l->snd_nxt, l->rcv_nxt))
407                 gap = l->snd_nxt - l->rcv_nxt;    383                 gap = l->snd_nxt - l->rcv_nxt;
408         if (skb)                                  384         if (skb)
409                 gap = buf_seqno(skb) - l->rcv_    385                 gap = buf_seqno(skb) - l->rcv_nxt;
410         return gap;                               386         return gap;
411 }                                                 387 }
412                                                   388 
413 void tipc_link_set_mtu(struct tipc_link *l, in    389 void tipc_link_set_mtu(struct tipc_link *l, int mtu)
414 {                                                 390 {
415         l->mtu = mtu;                             391         l->mtu = mtu;
416 }                                                 392 }
417                                                   393 
418 int tipc_link_mtu(struct tipc_link *l)            394 int tipc_link_mtu(struct tipc_link *l)
419 {                                                 395 {
420         return l->mtu;                            396         return l->mtu;
421 }                                                 397 }
422                                                   398 
423 int tipc_link_mss(struct tipc_link *l)         << 
424 {                                              << 
425 #ifdef CONFIG_TIPC_CRYPTO                      << 
426         return l->mtu - INT_H_SIZE - EMSG_OVER << 
427 #else                                          << 
428         return l->mtu - INT_H_SIZE;            << 
429 #endif                                         << 
430 }                                              << 
431                                                << 
432 u16 tipc_link_rcv_nxt(struct tipc_link *l)        399 u16 tipc_link_rcv_nxt(struct tipc_link *l)
433 {                                                 400 {
434         return l->rcv_nxt;                        401         return l->rcv_nxt;
435 }                                                 402 }
436                                                   403 
437 u16 tipc_link_acked(struct tipc_link *l)          404 u16 tipc_link_acked(struct tipc_link *l)
438 {                                                 405 {
439         return l->acked;                          406         return l->acked;
440 }                                                 407 }
441                                                   408 
442 char *tipc_link_name(struct tipc_link *l)         409 char *tipc_link_name(struct tipc_link *l)
443 {                                                 410 {
444         return l->name;                           411         return l->name;
445 }                                                 412 }
446                                                   413 
447 u32 tipc_link_state(struct tipc_link *l)          414 u32 tipc_link_state(struct tipc_link *l)
448 {                                                 415 {
449         return l->state;                          416         return l->state;
450 }                                                 417 }
451                                                   418 
452 /**                                               419 /**
453  * tipc_link_create - create a new link           420  * tipc_link_create - create a new link
454  * @net: pointer to associated network namespa !! 421  * @n: pointer to associated node
455  * @if_name: associated interface name            422  * @if_name: associated interface name
456  * @bearer_id: id (index) of associated bearer    423  * @bearer_id: id (index) of associated bearer
457  * @tolerance: link tolerance to be used by li    424  * @tolerance: link tolerance to be used by link
458  * @net_plane: network plane (A,B,c..) this li    425  * @net_plane: network plane (A,B,c..) this link belongs to
459  * @mtu: mtu to be advertised by link             426  * @mtu: mtu to be advertised by link
460  * @priority: priority to be used by link         427  * @priority: priority to be used by link
461  * @min_win: minimal send window to be used by !! 428  * @window: send window to be used by link
462  * @max_win: maximal send window to be used by << 
463  * @session: session to be used by link           429  * @session: session to be used by link
                                                   >> 430  * @ownnode: identity of own node
464  * @peer: node id of peer node                    431  * @peer: node id of peer node
465  * @peer_caps: bitmap describing peer node cap    432  * @peer_caps: bitmap describing peer node capabilities
466  * @bc_sndlink: the namespace global link used    433  * @bc_sndlink: the namespace global link used for broadcast sending
467  * @bc_rcvlink: the peer specific link used fo    434  * @bc_rcvlink: the peer specific link used for broadcast reception
468  * @inputq: queue to put messages ready for de    435  * @inputq: queue to put messages ready for delivery
469  * @namedq: queue to put binding table update     436  * @namedq: queue to put binding table update messages ready for delivery
470  * @link: return value, pointer to put the cre    437  * @link: return value, pointer to put the created link
471  * @self: local unicast link id                << 
472  * @peer_id: 128-bit ID of peer                << 
473  *                                                438  *
474  * Return: true if link was created, otherwise !! 439  * Returns true if link was created, otherwise false
475  */                                               440  */
476 bool tipc_link_create(struct net *net, char *i    441 bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
477                       int tolerance, char net_    442                       int tolerance, char net_plane, u32 mtu, int priority,
478                       u32 min_win, u32 max_win !! 443                       int window, u32 session, u32 self,
479                       u32 peer, u8 *peer_id, u    444                       u32 peer, u8 *peer_id, u16 peer_caps,
480                       struct tipc_link *bc_snd    445                       struct tipc_link *bc_sndlink,
481                       struct tipc_link *bc_rcv    446                       struct tipc_link *bc_rcvlink,
482                       struct sk_buff_head *inp    447                       struct sk_buff_head *inputq,
483                       struct sk_buff_head *nam    448                       struct sk_buff_head *namedq,
484                       struct tipc_link **link)    449                       struct tipc_link **link)
485 {                                                 450 {
486         char peer_str[NODE_ID_STR_LEN] = {0,};    451         char peer_str[NODE_ID_STR_LEN] = {0,};
487         char self_str[NODE_ID_STR_LEN] = {0,};    452         char self_str[NODE_ID_STR_LEN] = {0,};
488         struct tipc_link *l;                      453         struct tipc_link *l;
489                                                   454 
490         l = kzalloc(sizeof(*l), GFP_ATOMIC);      455         l = kzalloc(sizeof(*l), GFP_ATOMIC);
491         if (!l)                                   456         if (!l)
492                 return false;                     457                 return false;
493         *link = l;                                458         *link = l;
494         l->session = session;                     459         l->session = session;
495                                                   460 
496         /* Set link name for unicast links onl    461         /* Set link name for unicast links only */
497         if (peer_id) {                            462         if (peer_id) {
498                 tipc_nodeid2string(self_str, t    463                 tipc_nodeid2string(self_str, tipc_own_id(net));
499                 if (strlen(self_str) > 16)        464                 if (strlen(self_str) > 16)
500                         sprintf(self_str, "%x"    465                         sprintf(self_str, "%x", self);
501                 tipc_nodeid2string(peer_str, p    466                 tipc_nodeid2string(peer_str, peer_id);
502                 if (strlen(peer_str) > 16)        467                 if (strlen(peer_str) > 16)
503                         sprintf(peer_str, "%x"    468                         sprintf(peer_str, "%x", peer);
504         }                                         469         }
505         /* Peer i/f name will be completed by     470         /* Peer i/f name will be completed by reset/activate message */
506         snprintf(l->name, sizeof(l->name), "%s    471         snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
507                  self_str, if_name, peer_str);    472                  self_str, if_name, peer_str);
508                                                   473 
509         strcpy(l->if_name, if_name);              474         strcpy(l->if_name, if_name);
510         l->addr = peer;                           475         l->addr = peer;
511         l->peer_caps = peer_caps;                 476         l->peer_caps = peer_caps;
512         l->net = net;                             477         l->net = net;
513         l->in_session = false;                    478         l->in_session = false;
514         l->bearer_id = bearer_id;                 479         l->bearer_id = bearer_id;
515         l->tolerance = tolerance;                 480         l->tolerance = tolerance;
516         if (bc_rcvlink)                           481         if (bc_rcvlink)
517                 bc_rcvlink->tolerance = tolera    482                 bc_rcvlink->tolerance = tolerance;
518         l->net_plane = net_plane;                 483         l->net_plane = net_plane;
519         l->advertised_mtu = mtu;                  484         l->advertised_mtu = mtu;
520         l->mtu = mtu;                             485         l->mtu = mtu;
521         l->priority = priority;                   486         l->priority = priority;
522         tipc_link_set_queue_limits(l, min_win, !! 487         tipc_link_set_queue_limits(l, window);
523         l->ackers = 1;                            488         l->ackers = 1;
524         l->bc_sndlink = bc_sndlink;               489         l->bc_sndlink = bc_sndlink;
525         l->bc_rcvlink = bc_rcvlink;               490         l->bc_rcvlink = bc_rcvlink;
526         l->inputq = inputq;                       491         l->inputq = inputq;
527         l->namedq = namedq;                       492         l->namedq = namedq;
528         l->state = LINK_RESETTING;                493         l->state = LINK_RESETTING;
529         __skb_queue_head_init(&l->transmq);       494         __skb_queue_head_init(&l->transmq);
530         __skb_queue_head_init(&l->backlogq);      495         __skb_queue_head_init(&l->backlogq);
531         __skb_queue_head_init(&l->deferdq);       496         __skb_queue_head_init(&l->deferdq);
532         __skb_queue_head_init(&l->failover_def    497         __skb_queue_head_init(&l->failover_deferdq);
533         skb_queue_head_init(&l->wakeupq);         498         skb_queue_head_init(&l->wakeupq);
534         skb_queue_head_init(l->inputq);           499         skb_queue_head_init(l->inputq);
535         return true;                              500         return true;
536 }                                                 501 }
537                                                   502 
538 /**                                               503 /**
539  * tipc_link_bc_create - create new link to be    504  * tipc_link_bc_create - create new link to be used for broadcast
540  * @net: pointer to associated network namespa !! 505  * @n: pointer to associated node
541  * @mtu: mtu to be used initially if no peers     506  * @mtu: mtu to be used initially if no peers
542  * @min_win: minimal send window to be used by !! 507  * @window: send window to be used
543  * @max_win: maximal send window to be used by << 
544  * @inputq: queue to put messages ready for de    508  * @inputq: queue to put messages ready for delivery
545  * @namedq: queue to put binding table update     509  * @namedq: queue to put binding table update messages ready for delivery
546  * @link: return value, pointer to put the cre    510  * @link: return value, pointer to put the created link
547  * @ownnode: identity of own node              << 
548  * @peer: node id of peer node                 << 
549  * @peer_id: 128-bit ID of peer                << 
550  * @peer_caps: bitmap describing peer node cap << 
551  * @bc_sndlink: the namespace global link used << 
552  *                                                511  *
553  * Return: true if link was created, otherwise !! 512  * Returns true if link was created, otherwise false
554  */                                               513  */
555 bool tipc_link_bc_create(struct net *net, u32  !! 514 bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
556                          int mtu, u32 min_win, !! 515                          int mtu, int window, u16 peer_caps,
557                          struct sk_buff_head *    516                          struct sk_buff_head *inputq,
558                          struct sk_buff_head *    517                          struct sk_buff_head *namedq,
559                          struct tipc_link *bc_    518                          struct tipc_link *bc_sndlink,
560                          struct tipc_link **li    519                          struct tipc_link **link)
561 {                                                 520 {
562         struct tipc_link *l;                      521         struct tipc_link *l;
563                                                   522 
564         if (!tipc_link_create(net, "", MAX_BEA !! 523         if (!tipc_link_create(net, "", MAX_BEARERS, 0, 'Z', mtu, 0, window,
565                               max_win, 0, ownn !! 524                               0, ownnode, peer, NULL, peer_caps, bc_sndlink,
566                               bc_sndlink, NULL !! 525                               NULL, inputq, namedq, link))
567                 return false;                     526                 return false;
568                                                   527 
569         l = *link;                                528         l = *link;
570         if (peer_id) {                         !! 529         strcpy(l->name, tipc_bclink_name);
571                 char peer_str[NODE_ID_STR_LEN] << 
572                                                << 
573                 tipc_nodeid2string(peer_str, p << 
574                 if (strlen(peer_str) > 16)     << 
575                         sprintf(peer_str, "%x" << 
576                 /* Broadcast receiver link nam << 
577                 snprintf(l->name, sizeof(l->na << 
578                          peer_str);            << 
579         } else {                               << 
580                 strcpy(l->name, tipc_bclink_na << 
581         }                                      << 
582         trace_tipc_link_reset(l, TIPC_DUMP_ALL    530         trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!");
583         tipc_link_reset(l);                       531         tipc_link_reset(l);
584         l->state = LINK_RESET;                    532         l->state = LINK_RESET;
585         l->ackers = 0;                            533         l->ackers = 0;
586         l->bc_rcvlink = l;                        534         l->bc_rcvlink = l;
587                                                   535 
588         /* Broadcast send link is always up */    536         /* Broadcast send link is always up */
589         if (link_is_bc_sndlink(l))                537         if (link_is_bc_sndlink(l))
590                 l->state = LINK_ESTABLISHED;      538                 l->state = LINK_ESTABLISHED;
591                                                   539 
592         /* Disable replicast if even a single     540         /* Disable replicast if even a single peer doesn't support it */
593         if (link_is_bc_rcvlink(l) && !(peer_ca    541         if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
594                 tipc_bcast_toggle_rcast(net, f !! 542                 tipc_bcast_disable_rcast(net);
595                                                   543 
596         return true;                              544         return true;
597 }                                                 545 }
598                                                   546 
599 /**                                               547 /**
600  * tipc_link_fsm_evt - link finite state machi    548  * tipc_link_fsm_evt - link finite state machine
601  * @l: pointer to link                            549  * @l: pointer to link
602  * @evt: state machine event to be processed      550  * @evt: state machine event to be processed
603  */                                               551  */
604 int tipc_link_fsm_evt(struct tipc_link *l, int    552 int tipc_link_fsm_evt(struct tipc_link *l, int evt)
605 {                                                 553 {
606         int rc = 0;                               554         int rc = 0;
607         int old_state = l->state;                 555         int old_state = l->state;
608                                                   556 
609         switch (l->state) {                       557         switch (l->state) {
610         case LINK_RESETTING:                      558         case LINK_RESETTING:
611                 switch (evt) {                    559                 switch (evt) {
612                 case LINK_PEER_RESET_EVT:         560                 case LINK_PEER_RESET_EVT:
613                         l->state = LINK_PEER_R    561                         l->state = LINK_PEER_RESET;
614                         break;                    562                         break;
615                 case LINK_RESET_EVT:              563                 case LINK_RESET_EVT:
616                         l->state = LINK_RESET;    564                         l->state = LINK_RESET;
617                         break;                    565                         break;
618                 case LINK_FAILURE_EVT:            566                 case LINK_FAILURE_EVT:
619                 case LINK_FAILOVER_BEGIN_EVT:     567                 case LINK_FAILOVER_BEGIN_EVT:
620                 case LINK_ESTABLISH_EVT:          568                 case LINK_ESTABLISH_EVT:
621                 case LINK_FAILOVER_END_EVT:       569                 case LINK_FAILOVER_END_EVT:
622                 case LINK_SYNCH_BEGIN_EVT:        570                 case LINK_SYNCH_BEGIN_EVT:
623                 case LINK_SYNCH_END_EVT:          571                 case LINK_SYNCH_END_EVT:
624                 default:                          572                 default:
625                         goto illegal_evt;         573                         goto illegal_evt;
626                 }                                 574                 }
627                 break;                            575                 break;
628         case LINK_RESET:                          576         case LINK_RESET:
629                 switch (evt) {                    577                 switch (evt) {
630                 case LINK_PEER_RESET_EVT:         578                 case LINK_PEER_RESET_EVT:
631                         l->state = LINK_ESTABL    579                         l->state = LINK_ESTABLISHING;
632                         break;                    580                         break;
633                 case LINK_FAILOVER_BEGIN_EVT:     581                 case LINK_FAILOVER_BEGIN_EVT:
634                         l->state = LINK_FAILIN    582                         l->state = LINK_FAILINGOVER;
635                         break;                 << 
636                 case LINK_FAILURE_EVT:            583                 case LINK_FAILURE_EVT:
637                 case LINK_RESET_EVT:              584                 case LINK_RESET_EVT:
638                 case LINK_ESTABLISH_EVT:          585                 case LINK_ESTABLISH_EVT:
639                 case LINK_FAILOVER_END_EVT:       586                 case LINK_FAILOVER_END_EVT:
640                         break;                    587                         break;
641                 case LINK_SYNCH_BEGIN_EVT:        588                 case LINK_SYNCH_BEGIN_EVT:
642                 case LINK_SYNCH_END_EVT:          589                 case LINK_SYNCH_END_EVT:
643                 default:                          590                 default:
644                         goto illegal_evt;         591                         goto illegal_evt;
645                 }                                 592                 }
646                 break;                            593                 break;
647         case LINK_PEER_RESET:                     594         case LINK_PEER_RESET:
648                 switch (evt) {                    595                 switch (evt) {
649                 case LINK_RESET_EVT:              596                 case LINK_RESET_EVT:
650                         l->state = LINK_ESTABL    597                         l->state = LINK_ESTABLISHING;
651                         break;                    598                         break;
652                 case LINK_PEER_RESET_EVT:         599                 case LINK_PEER_RESET_EVT:
653                 case LINK_ESTABLISH_EVT:          600                 case LINK_ESTABLISH_EVT:
654                 case LINK_FAILURE_EVT:            601                 case LINK_FAILURE_EVT:
655                         break;                    602                         break;
656                 case LINK_SYNCH_BEGIN_EVT:        603                 case LINK_SYNCH_BEGIN_EVT:
657                 case LINK_SYNCH_END_EVT:          604                 case LINK_SYNCH_END_EVT:
658                 case LINK_FAILOVER_BEGIN_EVT:     605                 case LINK_FAILOVER_BEGIN_EVT:
659                 case LINK_FAILOVER_END_EVT:       606                 case LINK_FAILOVER_END_EVT:
660                 default:                          607                 default:
661                         goto illegal_evt;         608                         goto illegal_evt;
662                 }                                 609                 }
663                 break;                            610                 break;
664         case LINK_FAILINGOVER:                    611         case LINK_FAILINGOVER:
665                 switch (evt) {                    612                 switch (evt) {
666                 case LINK_FAILOVER_END_EVT:       613                 case LINK_FAILOVER_END_EVT:
667                         l->state = LINK_RESET;    614                         l->state = LINK_RESET;
668                         break;                    615                         break;
669                 case LINK_PEER_RESET_EVT:         616                 case LINK_PEER_RESET_EVT:
670                 case LINK_RESET_EVT:              617                 case LINK_RESET_EVT:
671                 case LINK_ESTABLISH_EVT:          618                 case LINK_ESTABLISH_EVT:
672                 case LINK_FAILURE_EVT:            619                 case LINK_FAILURE_EVT:
673                         break;                    620                         break;
674                 case LINK_FAILOVER_BEGIN_EVT:     621                 case LINK_FAILOVER_BEGIN_EVT:
675                 case LINK_SYNCH_BEGIN_EVT:        622                 case LINK_SYNCH_BEGIN_EVT:
676                 case LINK_SYNCH_END_EVT:          623                 case LINK_SYNCH_END_EVT:
677                 default:                          624                 default:
678                         goto illegal_evt;         625                         goto illegal_evt;
679                 }                                 626                 }
680                 break;                            627                 break;
681         case LINK_ESTABLISHING:                   628         case LINK_ESTABLISHING:
682                 switch (evt) {                    629                 switch (evt) {
683                 case LINK_ESTABLISH_EVT:          630                 case LINK_ESTABLISH_EVT:
684                         l->state = LINK_ESTABL    631                         l->state = LINK_ESTABLISHED;
685                         break;                    632                         break;
686                 case LINK_FAILOVER_BEGIN_EVT:     633                 case LINK_FAILOVER_BEGIN_EVT:
687                         l->state = LINK_FAILIN    634                         l->state = LINK_FAILINGOVER;
688                         break;                    635                         break;
689                 case LINK_RESET_EVT:              636                 case LINK_RESET_EVT:
690                         l->state = LINK_RESET;    637                         l->state = LINK_RESET;
691                         break;                    638                         break;
692                 case LINK_FAILURE_EVT:            639                 case LINK_FAILURE_EVT:
693                 case LINK_PEER_RESET_EVT:         640                 case LINK_PEER_RESET_EVT:
694                 case LINK_SYNCH_BEGIN_EVT:        641                 case LINK_SYNCH_BEGIN_EVT:
695                 case LINK_FAILOVER_END_EVT:       642                 case LINK_FAILOVER_END_EVT:
696                         break;                    643                         break;
697                 case LINK_SYNCH_END_EVT:          644                 case LINK_SYNCH_END_EVT:
698                 default:                          645                 default:
699                         goto illegal_evt;         646                         goto illegal_evt;
700                 }                                 647                 }
701                 break;                            648                 break;
702         case LINK_ESTABLISHED:                    649         case LINK_ESTABLISHED:
703                 switch (evt) {                    650                 switch (evt) {
704                 case LINK_PEER_RESET_EVT:         651                 case LINK_PEER_RESET_EVT:
705                         l->state = LINK_PEER_R    652                         l->state = LINK_PEER_RESET;
706                         rc |= TIPC_LINK_DOWN_E    653                         rc |= TIPC_LINK_DOWN_EVT;
707                         break;                    654                         break;
708                 case LINK_FAILURE_EVT:            655                 case LINK_FAILURE_EVT:
709                         l->state = LINK_RESETT    656                         l->state = LINK_RESETTING;
710                         rc |= TIPC_LINK_DOWN_E    657                         rc |= TIPC_LINK_DOWN_EVT;
711                         break;                    658                         break;
712                 case LINK_RESET_EVT:              659                 case LINK_RESET_EVT:
713                         l->state = LINK_RESET;    660                         l->state = LINK_RESET;
714                         break;                    661                         break;
715                 case LINK_ESTABLISH_EVT:          662                 case LINK_ESTABLISH_EVT:
716                 case LINK_SYNCH_END_EVT:          663                 case LINK_SYNCH_END_EVT:
717                         break;                    664                         break;
718                 case LINK_SYNCH_BEGIN_EVT:        665                 case LINK_SYNCH_BEGIN_EVT:
719                         l->state = LINK_SYNCHI    666                         l->state = LINK_SYNCHING;
720                         break;                    667                         break;
721                 case LINK_FAILOVER_BEGIN_EVT:     668                 case LINK_FAILOVER_BEGIN_EVT:
722                 case LINK_FAILOVER_END_EVT:       669                 case LINK_FAILOVER_END_EVT:
723                 default:                          670                 default:
724                         goto illegal_evt;         671                         goto illegal_evt;
725                 }                                 672                 }
726                 break;                            673                 break;
727         case LINK_SYNCHING:                       674         case LINK_SYNCHING:
728                 switch (evt) {                    675                 switch (evt) {
729                 case LINK_PEER_RESET_EVT:         676                 case LINK_PEER_RESET_EVT:
730                         l->state = LINK_PEER_R    677                         l->state = LINK_PEER_RESET;
731                         rc |= TIPC_LINK_DOWN_E    678                         rc |= TIPC_LINK_DOWN_EVT;
732                         break;                    679                         break;
733                 case LINK_FAILURE_EVT:            680                 case LINK_FAILURE_EVT:
734                         l->state = LINK_RESETT    681                         l->state = LINK_RESETTING;
735                         rc |= TIPC_LINK_DOWN_E    682                         rc |= TIPC_LINK_DOWN_EVT;
736                         break;                    683                         break;
737                 case LINK_RESET_EVT:              684                 case LINK_RESET_EVT:
738                         l->state = LINK_RESET;    685                         l->state = LINK_RESET;
739                         break;                    686                         break;
740                 case LINK_ESTABLISH_EVT:          687                 case LINK_ESTABLISH_EVT:
741                 case LINK_SYNCH_BEGIN_EVT:        688                 case LINK_SYNCH_BEGIN_EVT:
742                         break;                    689                         break;
743                 case LINK_SYNCH_END_EVT:          690                 case LINK_SYNCH_END_EVT:
744                         l->state = LINK_ESTABL    691                         l->state = LINK_ESTABLISHED;
745                         break;                    692                         break;
746                 case LINK_FAILOVER_BEGIN_EVT:     693                 case LINK_FAILOVER_BEGIN_EVT:
747                 case LINK_FAILOVER_END_EVT:       694                 case LINK_FAILOVER_END_EVT:
748                 default:                          695                 default:
749                         goto illegal_evt;         696                         goto illegal_evt;
750                 }                                 697                 }
751                 break;                            698                 break;
752         default:                                  699         default:
753                 pr_err("Unknown FSM state %x i    700                 pr_err("Unknown FSM state %x in %s\n", l->state, l->name);
754         }                                         701         }
755         trace_tipc_link_fsm(l->name, old_state    702         trace_tipc_link_fsm(l->name, old_state, l->state, evt);
756         return rc;                                703         return rc;
757 illegal_evt:                                      704 illegal_evt:
758         pr_err("Illegal FSM event %x in state     705         pr_err("Illegal FSM event %x in state %x on link %s\n",
759                evt, l->state, l->name);           706                evt, l->state, l->name);
760         trace_tipc_link_fsm(l->name, old_state    707         trace_tipc_link_fsm(l->name, old_state, l->state, evt);
761         return rc;                                708         return rc;
762 }                                                 709 }
763                                                   710 
764 /* link_profile_stats - update statistical pro    711 /* link_profile_stats - update statistical profiling of traffic
765  */                                               712  */
766 static void link_profile_stats(struct tipc_lin    713 static void link_profile_stats(struct tipc_link *l)
767 {                                                 714 {
768         struct sk_buff *skb;                      715         struct sk_buff *skb;
769         struct tipc_msg *msg;                     716         struct tipc_msg *msg;
770         int length;                               717         int length;
771                                                   718 
772         /* Update counters used in statistical    719         /* Update counters used in statistical profiling of send traffic */
773         l->stats.accu_queue_sz += skb_queue_le    720         l->stats.accu_queue_sz += skb_queue_len(&l->transmq);
774         l->stats.queue_sz_counts++;               721         l->stats.queue_sz_counts++;
775                                                   722 
776         skb = skb_peek(&l->transmq);              723         skb = skb_peek(&l->transmq);
777         if (!skb)                                 724         if (!skb)
778                 return;                           725                 return;
779         msg = buf_msg(skb);                       726         msg = buf_msg(skb);
780         length = msg_size(msg);                   727         length = msg_size(msg);
781                                                   728 
782         if (msg_user(msg) == MSG_FRAGMENTER) {    729         if (msg_user(msg) == MSG_FRAGMENTER) {
783                 if (msg_type(msg) != FIRST_FRA    730                 if (msg_type(msg) != FIRST_FRAGMENT)
784                         return;                   731                         return;
785                 length = msg_size(msg_inner_hd    732                 length = msg_size(msg_inner_hdr(msg));
786         }                                         733         }
787         l->stats.msg_lengths_total += length;     734         l->stats.msg_lengths_total += length;
788         l->stats.msg_length_counts++;             735         l->stats.msg_length_counts++;
789         if (length <= 64)                         736         if (length <= 64)
790                 l->stats.msg_length_profile[0]    737                 l->stats.msg_length_profile[0]++;
791         else if (length <= 256)                   738         else if (length <= 256)
792                 l->stats.msg_length_profile[1]    739                 l->stats.msg_length_profile[1]++;
793         else if (length <= 1024)                  740         else if (length <= 1024)
794                 l->stats.msg_length_profile[2]    741                 l->stats.msg_length_profile[2]++;
795         else if (length <= 4096)                  742         else if (length <= 4096)
796                 l->stats.msg_length_profile[3]    743                 l->stats.msg_length_profile[3]++;
797         else if (length <= 16384)                 744         else if (length <= 16384)
798                 l->stats.msg_length_profile[4]    745                 l->stats.msg_length_profile[4]++;
799         else if (length <= 32768)                 746         else if (length <= 32768)
800                 l->stats.msg_length_profile[5]    747                 l->stats.msg_length_profile[5]++;
801         else                                      748         else
802                 l->stats.msg_length_profile[6]    749                 l->stats.msg_length_profile[6]++;
803 }                                                 750 }
804                                                   751 
805 /**                                               752 /**
806  * tipc_link_too_silent - check if link is "to    753  * tipc_link_too_silent - check if link is "too silent"
807  * @l: tipc link to be checked                    754  * @l: tipc link to be checked
808  *                                                755  *
809  * Return: true if the link 'silent_intv_cnt'  !! 756  * Returns true if the link 'silent_intv_cnt' is about to reach the
810  * 'abort_limit' value, otherwise false           757  * 'abort_limit' value, otherwise false
811  */                                               758  */
812 bool tipc_link_too_silent(struct tipc_link *l)    759 bool tipc_link_too_silent(struct tipc_link *l)
813 {                                                 760 {
814         return (l->silent_intv_cnt + 2 > l->ab    761         return (l->silent_intv_cnt + 2 > l->abort_limit);
815 }                                                 762 }
816                                                   763 
817 /* tipc_link_timeout - perform periodic task a    764 /* tipc_link_timeout - perform periodic task as instructed from node timeout
818  */                                               765  */
819 int tipc_link_timeout(struct tipc_link *l, str    766 int tipc_link_timeout(struct tipc_link *l, struct sk_buff_head *xmitq)
820 {                                                 767 {
821         int mtyp = 0;                             768         int mtyp = 0;
822         int rc = 0;                               769         int rc = 0;
823         bool state = false;                       770         bool state = false;
824         bool probe = false;                       771         bool probe = false;
825         bool setup = false;                       772         bool setup = false;
826         u16 bc_snt = l->bc_sndlink->snd_nxt -     773         u16 bc_snt = l->bc_sndlink->snd_nxt - 1;
827         u16 bc_acked = l->bc_rcvlink->acked;      774         u16 bc_acked = l->bc_rcvlink->acked;
828         struct tipc_mon_state *mstate = &l->mo    775         struct tipc_mon_state *mstate = &l->mon_state;
829                                                   776 
830         trace_tipc_link_timeout(l, TIPC_DUMP_N    777         trace_tipc_link_timeout(l, TIPC_DUMP_NONE, " ");
831         trace_tipc_link_too_silent(l, TIPC_DUM    778         trace_tipc_link_too_silent(l, TIPC_DUMP_ALL, " ");
832         switch (l->state) {                       779         switch (l->state) {
833         case LINK_ESTABLISHED:                    780         case LINK_ESTABLISHED:
834         case LINK_SYNCHING:                       781         case LINK_SYNCHING:
835                 mtyp = STATE_MSG;                 782                 mtyp = STATE_MSG;
836                 link_profile_stats(l);            783                 link_profile_stats(l);
837                 tipc_mon_get_state(l->net, l->    784                 tipc_mon_get_state(l->net, l->addr, mstate, l->bearer_id);
838                 if (mstate->reset || (l->silen    785                 if (mstate->reset || (l->silent_intv_cnt > l->abort_limit))
839                         return tipc_link_fsm_e    786                         return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
840                 state = bc_acked != bc_snt;       787                 state = bc_acked != bc_snt;
841                 state |= l->bc_rcvlink->rcv_un    788                 state |= l->bc_rcvlink->rcv_unacked;
842                 state |= l->rcv_unacked;          789                 state |= l->rcv_unacked;
843                 state |= !skb_queue_empty(&l->    790                 state |= !skb_queue_empty(&l->transmq);
                                                   >> 791                 state |= !skb_queue_empty(&l->deferdq);
844                 probe = mstate->probing;          792                 probe = mstate->probing;
845                 probe |= l->silent_intv_cnt;      793                 probe |= l->silent_intv_cnt;
846                 if (probe || mstate->monitorin    794                 if (probe || mstate->monitoring)
847                         l->silent_intv_cnt++;     795                         l->silent_intv_cnt++;
848                 probe |= !skb_queue_empty(&l-> << 
849                 if (l->snd_nxt == l->checkpoin << 
850                         tipc_link_update_cwin( << 
851                         probe = true;          << 
852                 }                              << 
853                 l->checkpoint = l->snd_nxt;    << 
854                 break;                            796                 break;
855         case LINK_RESET:                          797         case LINK_RESET:
856                 setup = l->rst_cnt++ <= 4;        798                 setup = l->rst_cnt++ <= 4;
857                 setup |= !(l->rst_cnt % 16);      799                 setup |= !(l->rst_cnt % 16);
858                 mtyp = RESET_MSG;                 800                 mtyp = RESET_MSG;
859                 break;                            801                 break;
860         case LINK_ESTABLISHING:                   802         case LINK_ESTABLISHING:
861                 setup = true;                     803                 setup = true;
862                 mtyp = ACTIVATE_MSG;              804                 mtyp = ACTIVATE_MSG;
863                 break;                            805                 break;
864         case LINK_PEER_RESET:                     806         case LINK_PEER_RESET:
865         case LINK_RESETTING:                      807         case LINK_RESETTING:
866         case LINK_FAILINGOVER:                    808         case LINK_FAILINGOVER:
867                 break;                            809                 break;
868         default:                                  810         default:
869                 break;                            811                 break;
870         }                                         812         }
871                                                   813 
872         if (state || probe || setup)              814         if (state || probe || setup)
873                 tipc_link_build_proto_msg(l, m    815                 tipc_link_build_proto_msg(l, mtyp, probe, 0, 0, 0, 0, xmitq);
874                                                   816 
875         return rc;                                817         return rc;
876 }                                                 818 }
877                                                   819 
878 /**                                               820 /**
879  * link_schedule_user - schedule a message sen    821  * link_schedule_user - schedule a message sender for wakeup after congestion
880  * @l: congested link                             822  * @l: congested link
881  * @hdr: header of message that is being sent     823  * @hdr: header of message that is being sent
882  * Create pseudo msg to send back to user when    824  * Create pseudo msg to send back to user when congestion abates
883  */                                               825  */
884 static int link_schedule_user(struct tipc_link    826 static int link_schedule_user(struct tipc_link *l, struct tipc_msg *hdr)
885 {                                                 827 {
886         u32 dnode = tipc_own_addr(l->net);        828         u32 dnode = tipc_own_addr(l->net);
887         u32 dport = msg_origport(hdr);            829         u32 dport = msg_origport(hdr);
888         struct sk_buff *skb;                      830         struct sk_buff *skb;
889                                                   831 
890         /* Create and schedule wakeup pseudo m    832         /* Create and schedule wakeup pseudo message */
891         skb = tipc_msg_create(SOCK_WAKEUP, 0,     833         skb = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0,
892                               dnode, l->addr,     834                               dnode, l->addr, dport, 0, 0);
893         if (!skb)                                 835         if (!skb)
894                 return -ENOBUFS;                  836                 return -ENOBUFS;
895         msg_set_dest_droppable(buf_msg(skb), t    837         msg_set_dest_droppable(buf_msg(skb), true);
896         TIPC_SKB_CB(skb)->chain_imp = msg_impo    838         TIPC_SKB_CB(skb)->chain_imp = msg_importance(hdr);
897         skb_queue_tail(&l->wakeupq, skb);         839         skb_queue_tail(&l->wakeupq, skb);
898         l->stats.link_congs++;                    840         l->stats.link_congs++;
899         trace_tipc_link_conges(l, TIPC_DUMP_AL    841         trace_tipc_link_conges(l, TIPC_DUMP_ALL, "wakeup scheduled!");
900         return -ELINKCONG;                        842         return -ELINKCONG;
901 }                                                 843 }
902                                                   844 
903 /**                                               845 /**
904  * link_prepare_wakeup - prepare users for wak    846  * link_prepare_wakeup - prepare users for wakeup after congestion
905  * @l: congested link                             847  * @l: congested link
906  * Wake up a number of waiting users, as permi    848  * Wake up a number of waiting users, as permitted by available space
907  * in the send queue                              849  * in the send queue
908  */                                               850  */
909 static void link_prepare_wakeup(struct tipc_li    851 static void link_prepare_wakeup(struct tipc_link *l)
910 {                                                 852 {
911         struct sk_buff_head *wakeupq = &l->wak << 
912         struct sk_buff_head *inputq = l->input << 
913         struct sk_buff *skb, *tmp;                853         struct sk_buff *skb, *tmp;
914         struct sk_buff_head tmpq;              !! 854         int imp, i = 0;
915         int avail[5] = {0,};                   << 
916         int imp = 0;                           << 
917                                                << 
918         __skb_queue_head_init(&tmpq);          << 
919                                                   855 
920         for (; imp <= TIPC_SYSTEM_IMPORTANCE;  !! 856         skb_queue_walk_safe(&l->wakeupq, skb, tmp) {
921                 avail[imp] = l->backlog[imp].l << 
922                                                << 
923         skb_queue_walk_safe(wakeupq, skb, tmp) << 
924                 imp = TIPC_SKB_CB(skb)->chain_    857                 imp = TIPC_SKB_CB(skb)->chain_imp;
925                 if (avail[imp] <= 0)           !! 858                 if (l->backlog[imp].len < l->backlog[imp].limit) {
926                         continue;              !! 859                         skb_unlink(skb, &l->wakeupq);
927                 avail[imp]--;                  !! 860                         skb_queue_tail(l->inputq, skb);
928                 __skb_unlink(skb, wakeupq);    !! 861                 } else if (i++ > 10) {
929                 __skb_queue_tail(&tmpq, skb);  !! 862                         break;
                                                   >> 863                 }
930         }                                         864         }
931                                                << 
932         spin_lock_bh(&inputq->lock);           << 
933         skb_queue_splice_tail(&tmpq, inputq);  << 
934         spin_unlock_bh(&inputq->lock);         << 
935                                                << 
936 }                                              << 
937                                                << 
938 /**                                            << 
939  * tipc_link_set_skb_retransmit_time - set the << 
940  *                                     the giv << 
941  * @skb: skb to set a future retransmission ti << 
942  * @l: link the skb will be transmitted on     << 
943  */                                            << 
944 static void tipc_link_set_skb_retransmit_time( << 
945                                                << 
946 {                                              << 
947         if (link_is_bc_sndlink(l))             << 
948                 TIPC_SKB_CB(skb)->nxt_retr = T << 
949         else                                   << 
950                 TIPC_SKB_CB(skb)->nxt_retr = T << 
951 }                                                 865 }
952                                                   866 
953 void tipc_link_reset(struct tipc_link *l)         867 void tipc_link_reset(struct tipc_link *l)
954 {                                                 868 {
955         struct sk_buff_head list;                 869         struct sk_buff_head list;
956         u32 imp;                                  870         u32 imp;
957                                                   871 
958         __skb_queue_head_init(&list);             872         __skb_queue_head_init(&list);
959                                                   873 
960         l->in_session = false;                    874         l->in_session = false;
961         /* Force re-synch of peer session numb    875         /* Force re-synch of peer session number before establishing */
962         l->peer_session--;                        876         l->peer_session--;
963         l->session++;                             877         l->session++;
964         l->mtu = l->advertised_mtu;               878         l->mtu = l->advertised_mtu;
965                                                   879 
966         spin_lock_bh(&l->wakeupq.lock);           880         spin_lock_bh(&l->wakeupq.lock);
967         skb_queue_splice_init(&l->wakeupq, &li    881         skb_queue_splice_init(&l->wakeupq, &list);
968         spin_unlock_bh(&l->wakeupq.lock);         882         spin_unlock_bh(&l->wakeupq.lock);
969                                                   883 
970         spin_lock_bh(&l->inputq->lock);           884         spin_lock_bh(&l->inputq->lock);
971         skb_queue_splice_init(&list, l->inputq    885         skb_queue_splice_init(&list, l->inputq);
972         spin_unlock_bh(&l->inputq->lock);         886         spin_unlock_bh(&l->inputq->lock);
973                                                   887 
974         __skb_queue_purge(&l->transmq);           888         __skb_queue_purge(&l->transmq);
975         __skb_queue_purge(&l->deferdq);           889         __skb_queue_purge(&l->deferdq);
976         __skb_queue_purge(&l->backlogq);          890         __skb_queue_purge(&l->backlogq);
977         __skb_queue_purge(&l->failover_deferdq    891         __skb_queue_purge(&l->failover_deferdq);
978         for (imp = 0; imp <= TIPC_SYSTEM_IMPOR    892         for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) {
979                 l->backlog[imp].len = 0;          893                 l->backlog[imp].len = 0;
980                 l->backlog[imp].target_bskb =     894                 l->backlog[imp].target_bskb = NULL;
981         }                                         895         }
982         kfree_skb(l->reasm_buf);                  896         kfree_skb(l->reasm_buf);
983         kfree_skb(l->reasm_tnlmsg);            << 
984         kfree_skb(l->failover_reasm_skb);         897         kfree_skb(l->failover_reasm_skb);
985         l->reasm_buf = NULL;                      898         l->reasm_buf = NULL;
986         l->reasm_tnlmsg = NULL;                << 
987         l->failover_reasm_skb = NULL;             899         l->failover_reasm_skb = NULL;
988         l->rcv_unacked = 0;                       900         l->rcv_unacked = 0;
989         l->snd_nxt = 1;                           901         l->snd_nxt = 1;
990         l->rcv_nxt = 1;                           902         l->rcv_nxt = 1;
991         l->snd_nxt_state = 1;                     903         l->snd_nxt_state = 1;
992         l->rcv_nxt_state = 1;                     904         l->rcv_nxt_state = 1;
993         l->acked = 0;                             905         l->acked = 0;
994         l->last_gap = 0;                       << 
995         kfree(l->last_ga);                     << 
996         l->last_ga = NULL;                     << 
997         l->silent_intv_cnt = 0;                   906         l->silent_intv_cnt = 0;
998         l->rst_cnt = 0;                           907         l->rst_cnt = 0;
999         l->bc_peer_is_up = false;                 908         l->bc_peer_is_up = false;
1000         memset(&l->mon_state, 0, sizeof(l->mo    909         memset(&l->mon_state, 0, sizeof(l->mon_state));
1001         tipc_link_reset_stats(l);                910         tipc_link_reset_stats(l);
1002 }                                                911 }
1003                                                  912 
1004 /**                                              913 /**
1005  * tipc_link_xmit(): enqueue buffer list acco    914  * tipc_link_xmit(): enqueue buffer list according to queue situation
1006  * @l: link to use                            !! 915  * @link: link to use
1007  * @list: chain of buffers containing message    916  * @list: chain of buffers containing message
1008  * @xmitq: returned list of packets to be sen    917  * @xmitq: returned list of packets to be sent by caller
1009  *                                               918  *
1010  * Consumes the buffer chain.                    919  * Consumes the buffer chain.
                                                   >> 920  * Returns 0 if success, or errno: -ELINKCONG, -EMSGSIZE or -ENOBUFS
1011  * Messages at TIPC_SYSTEM_IMPORTANCE are alw    921  * Messages at TIPC_SYSTEM_IMPORTANCE are always accepted
1012  * Return: 0 if success, or errno: -ELINKCONG << 
1013  */                                              922  */
1014 int tipc_link_xmit(struct tipc_link *l, struc    923 int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
1015                    struct sk_buff_head *xmitq    924                    struct sk_buff_head *xmitq)
1016 {                                                925 {
1017         struct sk_buff_head *backlogq = &l->b !! 926         struct tipc_msg *hdr = buf_msg(skb_peek(list));
1018         struct sk_buff_head *transmq = &l->tr !! 927         unsigned int maxwin = l->window;
1019         struct sk_buff *skb, *_skb;           !! 928         int imp = msg_importance(hdr);
1020         u16 bc_ack = l->bc_rcvlink->rcv_nxt - !! 929         unsigned int mtu = l->mtu;
1021         u16 ack = l->rcv_nxt - 1;                930         u16 ack = l->rcv_nxt - 1;
1022         u16 seqno = l->snd_nxt;                  931         u16 seqno = l->snd_nxt;
                                                   >> 932         u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
                                                   >> 933         struct sk_buff_head *transmq = &l->transmq;
                                                   >> 934         struct sk_buff_head *backlogq = &l->backlogq;
                                                   >> 935         struct sk_buff *skb, *_skb, **tskb;
1023         int pkt_cnt = skb_queue_len(list);       936         int pkt_cnt = skb_queue_len(list);
1024         unsigned int mss = tipc_link_mss(l);  << 
1025         unsigned int cwin = l->window;        << 
1026         unsigned int mtu = l->mtu;            << 
1027         struct tipc_msg *hdr;                 << 
1028         bool new_bundle;                      << 
1029         int rc = 0;                              937         int rc = 0;
1030         int imp;                              << 
1031                                                  938 
1032         if (pkt_cnt <= 0)                     << 
1033                 return 0;                     << 
1034                                               << 
1035         hdr = buf_msg(skb_peek(list));        << 
1036         if (unlikely(msg_size(hdr) > mtu)) {     939         if (unlikely(msg_size(hdr) > mtu)) {
1037                 pr_warn("Too large msg, purgi !! 940                 skb_queue_purge(list);
1038                         skb_queue_len(list),  << 
1039                         msg_type(hdr), msg_si << 
1040                 __skb_queue_purge(list);      << 
1041                 return -EMSGSIZE;                941                 return -EMSGSIZE;
1042         }                                        942         }
1043                                                  943 
1044         imp = msg_importance(hdr);            << 
1045         /* Allow oversubscription of one data    944         /* Allow oversubscription of one data msg per source at congestion */
1046         if (unlikely(l->backlog[imp].len >= l    945         if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
1047                 if (imp == TIPC_SYSTEM_IMPORT    946                 if (imp == TIPC_SYSTEM_IMPORTANCE) {
1048                         pr_warn("%s<%s>, link    947                         pr_warn("%s<%s>, link overflow", link_rst_msg, l->name);
1049                         return -ENOBUFS;         948                         return -ENOBUFS;
1050                 }                                949                 }
1051                 rc = link_schedule_user(l, hd    950                 rc = link_schedule_user(l, hdr);
1052         }                                        951         }
1053                                                  952 
1054         if (pkt_cnt > 1) {                       953         if (pkt_cnt > 1) {
1055                 l->stats.sent_fragmented++;      954                 l->stats.sent_fragmented++;
1056                 l->stats.sent_fragments += pk    955                 l->stats.sent_fragments += pkt_cnt;
1057         }                                        956         }
1058                                                  957 
1059         /* Prepare each packet for sending, a    958         /* Prepare each packet for sending, and add to relevant queue: */
1060         while ((skb = __skb_dequeue(list))) { !! 959         while (skb_queue_len(list)) {
1061                 if (likely(skb_queue_len(tran !! 960                 skb = skb_peek(list);
1062                         hdr = buf_msg(skb);   !! 961                 hdr = buf_msg(skb);
1063                         msg_set_seqno(hdr, se !! 962                 msg_set_seqno(hdr, seqno);
1064                         msg_set_ack(hdr, ack) !! 963                 msg_set_ack(hdr, ack);
1065                         msg_set_bcast_ack(hdr !! 964                 msg_set_bcast_ack(hdr, bc_ack);
                                                   >> 965 
                                                   >> 966                 if (likely(skb_queue_len(transmq) < maxwin)) {
1066                         _skb = skb_clone(skb,    967                         _skb = skb_clone(skb, GFP_ATOMIC);
1067                         if (!_skb) {             968                         if (!_skb) {
1068                                 kfree_skb(skb !! 969                                 skb_queue_purge(list);
1069                                 __skb_queue_p << 
1070                                 return -ENOBU    970                                 return -ENOBUFS;
1071                         }                        971                         }
                                                   >> 972                         __skb_dequeue(list);
1072                         __skb_queue_tail(tran    973                         __skb_queue_tail(transmq, skb);
1073                         tipc_link_set_skb_ret !! 974                         /* next retransmit attempt */
                                                   >> 975                         if (link_is_bc_sndlink(l))
                                                   >> 976                                 TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
1074                         __skb_queue_tail(xmit    977                         __skb_queue_tail(xmitq, _skb);
1075                         TIPC_SKB_CB(skb)->ack    978                         TIPC_SKB_CB(skb)->ackers = l->ackers;
1076                         l->rcv_unacked = 0;      979                         l->rcv_unacked = 0;
1077                         l->stats.sent_pkts++;    980                         l->stats.sent_pkts++;
1078                         seqno++;                 981                         seqno++;
1079                         continue;                982                         continue;
1080                 }                                983                 }
1081                 if (tipc_msg_try_bundle(l->ba !! 984                 tskb = &l->backlog[imp].target_bskb;
1082                                         mss,  !! 985                 if (tipc_msg_bundle(*tskb, hdr, mtu)) {
1083                         if (skb) {            !! 986                         kfree_skb(__skb_dequeue(list));
1084                                 /* Keep a ref !! 987                         l->stats.sent_bundled++;
1085                                 l->backlog[im !! 988                         continue;
1086                                 l->backlog[im !! 989                 }
1087                                 __skb_queue_t !! 990                 if (tipc_msg_make_bundle(tskb, hdr, mtu, l->addr)) {
1088                         } else {              !! 991                         kfree_skb(__skb_dequeue(list));
1089                                 if (new_bundl !! 992                         __skb_queue_tail(backlogq, *tskb);
1090                                         l->st !! 993                         l->backlog[imp].len++;
1091                                         l->st !! 994                         l->stats.sent_bundled++;
1092                                 }             !! 995                         l->stats.sent_bundles++;
1093                                 l->stats.sent << 
1094                         }                     << 
1095                         continue;                996                         continue;
1096                 }                                997                 }
1097                 l->backlog[imp].target_bskb =    998                 l->backlog[imp].target_bskb = NULL;
1098                 l->backlog[imp].len += (1 + s !! 999                 l->backlog[imp].len += skb_queue_len(list);
1099                 __skb_queue_tail(backlogq, sk << 
1100                 skb_queue_splice_tail_init(li    1000                 skb_queue_splice_tail_init(list, backlogq);
1101         }                                        1001         }
1102         l->snd_nxt = seqno;                      1002         l->snd_nxt = seqno;
1103         return rc;                               1003         return rc;
1104 }                                                1004 }
1105                                                  1005 
1106 static void tipc_link_update_cwin(struct tipc << 
1107                                   bool retran << 
1108 {                                             << 
1109         int bklog_len = skb_queue_len(&l->bac << 
1110         struct sk_buff_head *txq = &l->transm << 
1111         int txq_len = skb_queue_len(txq);     << 
1112         u16 cwin = l->window;                 << 
1113                                               << 
1114         /* Enter fast recovery */             << 
1115         if (unlikely(retransmitted)) {        << 
1116                 l->ssthresh = max_t(u16, l->w << 
1117                 l->window = min_t(u16, l->sst << 
1118                 return;                       << 
1119         }                                     << 
1120         /* Enter slow start */                << 
1121         if (unlikely(!released)) {            << 
1122                 l->ssthresh = max_t(u16, l->w << 
1123                 l->window = l->min_win;       << 
1124                 return;                       << 
1125         }                                     << 
1126         /* Don't increase window if no pressu << 
1127         if (txq_len + bklog_len < cwin)       << 
1128                 return;                       << 
1129                                               << 
1130         /* Don't increase window if there are << 
1131         if (txq_len && l->snd_nxt - buf_seqno << 
1132                 return;                       << 
1133                                               << 
1134         l->cong_acks += released;             << 
1135                                               << 
1136         /* Slow start  */                     << 
1137         if (cwin <= l->ssthresh) {            << 
1138                 l->window = min_t(u16, cwin + << 
1139                 return;                       << 
1140         }                                     << 
1141         /* Congestion avoidance */            << 
1142         if (l->cong_acks < cwin)              << 
1143                 return;                       << 
1144         l->window = min_t(u16, ++cwin, l->max << 
1145         l->cong_acks = 0;                     << 
1146 }                                             << 
1147                                               << 
1148 static void tipc_link_advance_backlog(struct     1006 static void tipc_link_advance_backlog(struct tipc_link *l,
1149                                       struct     1007                                       struct sk_buff_head *xmitq)
1150 {                                                1008 {
1151         u16 bc_ack = l->bc_rcvlink->rcv_nxt - << 
1152         struct sk_buff_head *txq = &l->transm << 
1153         struct sk_buff *skb, *_skb;              1009         struct sk_buff *skb, *_skb;
1154         u16 ack = l->rcv_nxt - 1;             << 
1155         u16 seqno = l->snd_nxt;               << 
1156         struct tipc_msg *hdr;                    1010         struct tipc_msg *hdr;
1157         u16 cwin = l->window;                 !! 1011         u16 seqno = l->snd_nxt;
                                                   >> 1012         u16 ack = l->rcv_nxt - 1;
                                                   >> 1013         u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1158         u32 imp;                                 1014         u32 imp;
1159                                                  1015 
1160         while (skb_queue_len(txq) < cwin) {   !! 1016         while (skb_queue_len(&l->transmq) < l->window) {
1161                 skb = skb_peek(&l->backlogq);    1017                 skb = skb_peek(&l->backlogq);
1162                 if (!skb)                        1018                 if (!skb)
1163                         break;                   1019                         break;
1164                 _skb = skb_clone(skb, GFP_ATO    1020                 _skb = skb_clone(skb, GFP_ATOMIC);
1165                 if (!_skb)                       1021                 if (!_skb)
1166                         break;                   1022                         break;
1167                 __skb_dequeue(&l->backlogq);     1023                 __skb_dequeue(&l->backlogq);
1168                 hdr = buf_msg(skb);              1024                 hdr = buf_msg(skb);
1169                 imp = msg_importance(hdr);       1025                 imp = msg_importance(hdr);
1170                 l->backlog[imp].len--;           1026                 l->backlog[imp].len--;
1171                 if (unlikely(skb == l->backlo    1027                 if (unlikely(skb == l->backlog[imp].target_bskb))
1172                         l->backlog[imp].targe    1028                         l->backlog[imp].target_bskb = NULL;
1173                 __skb_queue_tail(&l->transmq,    1029                 __skb_queue_tail(&l->transmq, skb);
1174                 tipc_link_set_skb_retransmit_ !! 1030                 /* next retransmit attempt */
                                                   >> 1031                 if (link_is_bc_sndlink(l))
                                                   >> 1032                         TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
1175                                                  1033 
1176                 __skb_queue_tail(xmitq, _skb)    1034                 __skb_queue_tail(xmitq, _skb);
1177                 TIPC_SKB_CB(skb)->ackers = l-    1035                 TIPC_SKB_CB(skb)->ackers = l->ackers;
1178                 msg_set_seqno(hdr, seqno);       1036                 msg_set_seqno(hdr, seqno);
1179                 msg_set_ack(hdr, ack);           1037                 msg_set_ack(hdr, ack);
1180                 msg_set_bcast_ack(hdr, bc_ack    1038                 msg_set_bcast_ack(hdr, bc_ack);
1181                 l->rcv_unacked = 0;              1039                 l->rcv_unacked = 0;
1182                 l->stats.sent_pkts++;            1040                 l->stats.sent_pkts++;
1183                 seqno++;                         1041                 seqno++;
1184         }                                        1042         }
1185         l->snd_nxt = seqno;                      1043         l->snd_nxt = seqno;
1186 }                                                1044 }
1187                                                  1045 
1188 /**                                              1046 /**
1189  * link_retransmit_failure() - Detect repeate    1047  * link_retransmit_failure() - Detect repeated retransmit failures
1190  * @l: tipc link sender                          1048  * @l: tipc link sender
1191  * @r: tipc link receiver (= l in case of uni    1049  * @r: tipc link receiver (= l in case of unicast)
1192  * @rc: returned code                            1050  * @rc: returned code
1193  *                                               1051  *
1194  * Return: true if the repeated retransmit fa    1052  * Return: true if the repeated retransmit failures happens, otherwise
1195  * false                                         1053  * false
1196  */                                              1054  */
1197 static bool link_retransmit_failure(struct ti    1055 static bool link_retransmit_failure(struct tipc_link *l, struct tipc_link *r,
1198                                     int *rc)     1056                                     int *rc)
1199 {                                                1057 {
1200         struct sk_buff *skb = skb_peek(&l->tr    1058         struct sk_buff *skb = skb_peek(&l->transmq);
1201         struct tipc_msg *hdr;                    1059         struct tipc_msg *hdr;
1202                                                  1060 
1203         if (!skb)                                1061         if (!skb)
1204                 return false;                    1062                 return false;
1205                                                  1063 
1206         if (!TIPC_SKB_CB(skb)->retr_cnt)         1064         if (!TIPC_SKB_CB(skb)->retr_cnt)
1207                 return false;                    1065                 return false;
1208                                                  1066 
1209         if (!time_after(jiffies, TIPC_SKB_CB(    1067         if (!time_after(jiffies, TIPC_SKB_CB(skb)->retr_stamp +
1210                         msecs_to_jiffies(r->t !! 1068                         msecs_to_jiffies(r->tolerance)))
1211                 return false;                    1069                 return false;
1212                                                  1070 
1213         hdr = buf_msg(skb);                      1071         hdr = buf_msg(skb);
1214         if (link_is_bc_sndlink(l) && !less(r-    1072         if (link_is_bc_sndlink(l) && !less(r->acked, msg_seqno(hdr)))
1215                 return false;                    1073                 return false;
1216                                                  1074 
1217         pr_warn("Retransmission failure on li    1075         pr_warn("Retransmission failure on link <%s>\n", l->name);
1218         link_print(l, "State of link ");         1076         link_print(l, "State of link ");
1219         pr_info("Failed msg: usr %u, typ %u,     1077         pr_info("Failed msg: usr %u, typ %u, len %u, err %u\n",
1220                 msg_user(hdr), msg_type(hdr),    1078                 msg_user(hdr), msg_type(hdr), msg_size(hdr), msg_errcode(hdr));
1221         pr_info("sqno %u, prev: %x, dest: %x\    1079         pr_info("sqno %u, prev: %x, dest: %x\n",
1222                 msg_seqno(hdr), msg_prevnode(    1080                 msg_seqno(hdr), msg_prevnode(hdr), msg_destnode(hdr));
1223         pr_info("retr_stamp %d, retr_cnt %d\n    1081         pr_info("retr_stamp %d, retr_cnt %d\n",
1224                 jiffies_to_msecs(TIPC_SKB_CB(    1082                 jiffies_to_msecs(TIPC_SKB_CB(skb)->retr_stamp),
1225                 TIPC_SKB_CB(skb)->retr_cnt);     1083                 TIPC_SKB_CB(skb)->retr_cnt);
1226                                                  1084 
1227         trace_tipc_list_dump(&l->transmq, tru    1085         trace_tipc_list_dump(&l->transmq, true, "retrans failure!");
1228         trace_tipc_link_dump(l, TIPC_DUMP_NON    1086         trace_tipc_link_dump(l, TIPC_DUMP_NONE, "retrans failure!");
1229         trace_tipc_link_dump(r, TIPC_DUMP_NON    1087         trace_tipc_link_dump(r, TIPC_DUMP_NONE, "retrans failure!");
1230                                                  1088 
1231         if (link_is_bc_sndlink(l)) {             1089         if (link_is_bc_sndlink(l)) {
1232                 r->state = LINK_RESET;           1090                 r->state = LINK_RESET;
1233                 *rc |= TIPC_LINK_DOWN_EVT;    !! 1091                 *rc = TIPC_LINK_DOWN_EVT;
1234         } else {                                 1092         } else {
1235                 *rc |= tipc_link_fsm_evt(l, L !! 1093                 *rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1236         }                                        1094         }
1237                                                  1095 
1238         return true;                             1096         return true;
1239 }                                                1097 }
1240                                                  1098 
                                                   >> 1099 /* tipc_link_bc_retrans() - retransmit zero or more packets
                                                   >> 1100  * @l: the link to transmit on
                                                   >> 1101  * @r: the receiving link ordering the retransmit. Same as l if unicast
                                                   >> 1102  * @from: retransmit from (inclusive) this sequence number
                                                   >> 1103  * @to: retransmit to (inclusive) this sequence number
                                                   >> 1104  * xmitq: queue for accumulating the retransmitted packets
                                                   >> 1105  */
                                                   >> 1106 static int tipc_link_bc_retrans(struct tipc_link *l, struct tipc_link *r,
                                                   >> 1107                                 u16 from, u16 to, struct sk_buff_head *xmitq)
                                                   >> 1108 {
                                                   >> 1109         struct sk_buff *_skb, *skb = skb_peek(&l->transmq);
                                                   >> 1110         u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
                                                   >> 1111         u16 ack = l->rcv_nxt - 1;
                                                   >> 1112         struct tipc_msg *hdr;
                                                   >> 1113         int rc = 0;
                                                   >> 1114 
                                                   >> 1115         if (!skb)
                                                   >> 1116                 return 0;
                                                   >> 1117         if (less(to, from))
                                                   >> 1118                 return 0;
                                                   >> 1119 
                                                   >> 1120         trace_tipc_link_retrans(r, from, to, &l->transmq);
                                                   >> 1121 
                                                   >> 1122         if (link_retransmit_failure(l, r, &rc))
                                                   >> 1123                 return rc;
                                                   >> 1124 
                                                   >> 1125         skb_queue_walk(&l->transmq, skb) {
                                                   >> 1126                 hdr = buf_msg(skb);
                                                   >> 1127                 if (less(msg_seqno(hdr), from))
                                                   >> 1128                         continue;
                                                   >> 1129                 if (more(msg_seqno(hdr), to))
                                                   >> 1130                         break;
                                                   >> 1131 
                                                   >> 1132                 if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
                                                   >> 1133                         continue;
                                                   >> 1134                 TIPC_SKB_CB(skb)->nxt_retr = TIPC_BC_RETR_LIM;
                                                   >> 1135                 _skb = __pskb_copy(skb, LL_MAX_HEADER + MIN_H_SIZE, GFP_ATOMIC);
                                                   >> 1136                 if (!_skb)
                                                   >> 1137                         return 0;
                                                   >> 1138                 hdr = buf_msg(_skb);
                                                   >> 1139                 msg_set_ack(hdr, ack);
                                                   >> 1140                 msg_set_bcast_ack(hdr, bc_ack);
                                                   >> 1141                 _skb->priority = TC_PRIO_CONTROL;
                                                   >> 1142                 __skb_queue_tail(xmitq, _skb);
                                                   >> 1143                 l->stats.retransmitted++;
                                                   >> 1144 
                                                   >> 1145                 /* Increase actual retrans counter & mark first time */
                                                   >> 1146                 if (!TIPC_SKB_CB(skb)->retr_cnt++)
                                                   >> 1147                         TIPC_SKB_CB(skb)->retr_stamp = jiffies;
                                                   >> 1148         }
                                                   >> 1149         return 0;
                                                   >> 1150 }
                                                   >> 1151 
1241 /* tipc_data_input - deliver data and name di    1152 /* tipc_data_input - deliver data and name distr msgs to upper layer
1242  *                                               1153  *
1243  * Consumes buffer if message is of right typ    1154  * Consumes buffer if message is of right type
1244  * Node lock must be held                        1155  * Node lock must be held
1245  */                                              1156  */
1246 static bool tipc_data_input(struct tipc_link     1157 static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
1247                             struct sk_buff_he    1158                             struct sk_buff_head *inputq)
1248 {                                                1159 {
1249         struct sk_buff_head *mc_inputq = l->b    1160         struct sk_buff_head *mc_inputq = l->bc_rcvlink->inputq;
1250         struct tipc_msg *hdr = buf_msg(skb);     1161         struct tipc_msg *hdr = buf_msg(skb);
1251                                                  1162 
1252         switch (msg_user(hdr)) {                 1163         switch (msg_user(hdr)) {
1253         case TIPC_LOW_IMPORTANCE:                1164         case TIPC_LOW_IMPORTANCE:
1254         case TIPC_MEDIUM_IMPORTANCE:             1165         case TIPC_MEDIUM_IMPORTANCE:
1255         case TIPC_HIGH_IMPORTANCE:               1166         case TIPC_HIGH_IMPORTANCE:
1256         case TIPC_CRITICAL_IMPORTANCE:           1167         case TIPC_CRITICAL_IMPORTANCE:
1257                 if (unlikely(msg_in_group(hdr    1168                 if (unlikely(msg_in_group(hdr) || msg_mcast(hdr))) {
1258                         skb_queue_tail(mc_inp    1169                         skb_queue_tail(mc_inputq, skb);
1259                         return true;             1170                         return true;
1260                 }                                1171                 }
1261                 fallthrough;                  !! 1172                 /* fall through */
1262         case CONN_MANAGER:                       1173         case CONN_MANAGER:
1263                 skb_queue_tail(inputq, skb);     1174                 skb_queue_tail(inputq, skb);
1264                 return true;                     1175                 return true;
1265         case GROUP_PROTOCOL:                     1176         case GROUP_PROTOCOL:
1266                 skb_queue_tail(mc_inputq, skb    1177                 skb_queue_tail(mc_inputq, skb);
1267                 return true;                     1178                 return true;
1268         case NAME_DISTRIBUTOR:                   1179         case NAME_DISTRIBUTOR:
1269                 l->bc_rcvlink->state = LINK_E    1180                 l->bc_rcvlink->state = LINK_ESTABLISHED;
1270                 skb_queue_tail(l->namedq, skb    1181                 skb_queue_tail(l->namedq, skb);
1271                 return true;                     1182                 return true;
1272         case MSG_BUNDLER:                        1183         case MSG_BUNDLER:
1273         case TUNNEL_PROTOCOL:                    1184         case TUNNEL_PROTOCOL:
1274         case MSG_FRAGMENTER:                     1185         case MSG_FRAGMENTER:
1275         case BCAST_PROTOCOL:                     1186         case BCAST_PROTOCOL:
1276                 return false;                    1187                 return false;
1277 #ifdef CONFIG_TIPC_CRYPTO                     << 
1278         case MSG_CRYPTO:                      << 
1279                 if (sysctl_tipc_key_exchange_ << 
1280                     TIPC_SKB_CB(skb)->decrypt << 
1281                         tipc_crypto_msg_rcv(l << 
1282                         return true;          << 
1283                 }                             << 
1284                 fallthrough;                  << 
1285 #endif                                        << 
1286         default:                                 1188         default:
1287                 pr_warn("Dropping received il    1189                 pr_warn("Dropping received illegal msg type\n");
1288                 kfree_skb(skb);                  1190                 kfree_skb(skb);
1289                 return true;                     1191                 return true;
1290         }                                     !! 1192         };
1291 }                                                1193 }
1292                                                  1194 
1293 /* tipc_link_input - process packet that has     1195 /* tipc_link_input - process packet that has passed link protocol check
1294  *                                               1196  *
1295  * Consumes buffer                               1197  * Consumes buffer
1296  */                                              1198  */
1297 static int tipc_link_input(struct tipc_link *    1199 static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
1298                            struct sk_buff_hea    1200                            struct sk_buff_head *inputq,
1299                            struct sk_buff **r    1201                            struct sk_buff **reasm_skb)
1300 {                                                1202 {
1301         struct tipc_msg *hdr = buf_msg(skb);     1203         struct tipc_msg *hdr = buf_msg(skb);
1302         struct sk_buff *iskb;                    1204         struct sk_buff *iskb;
1303         struct sk_buff_head tmpq;                1205         struct sk_buff_head tmpq;
1304         int usr = msg_user(hdr);                 1206         int usr = msg_user(hdr);
1305         int pos = 0;                             1207         int pos = 0;
1306                                                  1208 
1307         if (usr == MSG_BUNDLER) {                1209         if (usr == MSG_BUNDLER) {
1308                 skb_queue_head_init(&tmpq);      1210                 skb_queue_head_init(&tmpq);
1309                 l->stats.recv_bundles++;         1211                 l->stats.recv_bundles++;
1310                 l->stats.recv_bundled += msg_    1212                 l->stats.recv_bundled += msg_msgcnt(hdr);
1311                 while (tipc_msg_extract(skb,     1213                 while (tipc_msg_extract(skb, &iskb, &pos))
1312                         tipc_data_input(l, is    1214                         tipc_data_input(l, iskb, &tmpq);
1313                 tipc_skb_queue_splice_tail(&t    1215                 tipc_skb_queue_splice_tail(&tmpq, inputq);
1314                 return 0;                        1216                 return 0;
1315         } else if (usr == MSG_FRAGMENTER) {      1217         } else if (usr == MSG_FRAGMENTER) {
1316                 l->stats.recv_fragments++;       1218                 l->stats.recv_fragments++;
1317                 if (tipc_buf_append(reasm_skb    1219                 if (tipc_buf_append(reasm_skb, &skb)) {
1318                         l->stats.recv_fragmen    1220                         l->stats.recv_fragmented++;
1319                         tipc_data_input(l, sk    1221                         tipc_data_input(l, skb, inputq);
1320                 } else if (!*reasm_skb && !li    1222                 } else if (!*reasm_skb && !link_is_bc_rcvlink(l)) {
1321                         pr_warn_ratelimited("    1223                         pr_warn_ratelimited("Unable to build fragment list\n");
1322                         return tipc_link_fsm_    1224                         return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1323                 }                                1225                 }
1324                 return 0;                        1226                 return 0;
1325         } else if (usr == BCAST_PROTOCOL) {      1227         } else if (usr == BCAST_PROTOCOL) {
1326                 tipc_bcast_lock(l->net);         1228                 tipc_bcast_lock(l->net);
1327                 tipc_link_bc_init_rcv(l->bc_r    1229                 tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
1328                 tipc_bcast_unlock(l->net);       1230                 tipc_bcast_unlock(l->net);
1329         }                                        1231         }
1330                                                  1232 
1331         kfree_skb(skb);                          1233         kfree_skb(skb);
1332         return 0;                                1234         return 0;
1333 }                                                1235 }
1334                                                  1236 
1335 /* tipc_link_tnl_rcv() - receive TUNNEL_PROTO    1237 /* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the
1336  *                       inner message along     1238  *                       inner message along with the ones in the old link's
1337  *                       deferdq                 1239  *                       deferdq
1338  * @l: tunnel link                               1240  * @l: tunnel link
1339  * @skb: TUNNEL_PROTOCOL message                 1241  * @skb: TUNNEL_PROTOCOL message
1340  * @inputq: queue to put messages ready for d    1242  * @inputq: queue to put messages ready for delivery
1341  */                                              1243  */
1342 static int tipc_link_tnl_rcv(struct tipc_link    1244 static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
1343                              struct sk_buff_h    1245                              struct sk_buff_head *inputq)
1344 {                                                1246 {
1345         struct sk_buff **reasm_skb = &l->fail    1247         struct sk_buff **reasm_skb = &l->failover_reasm_skb;
1346         struct sk_buff **reasm_tnlmsg = &l->r << 
1347         struct sk_buff_head *fdefq = &l->fail    1248         struct sk_buff_head *fdefq = &l->failover_deferdq;
1348         struct tipc_msg *hdr = buf_msg(skb);     1249         struct tipc_msg *hdr = buf_msg(skb);
1349         struct sk_buff *iskb;                    1250         struct sk_buff *iskb;
1350         int ipos = 0;                            1251         int ipos = 0;
1351         int rc = 0;                              1252         int rc = 0;
1352         u16 seqno;                               1253         u16 seqno;
1353                                                  1254 
1354         if (msg_type(hdr) == SYNCH_MSG) {     !! 1255         /* SYNCH_MSG */
1355                 kfree_skb(skb);               !! 1256         if (msg_type(hdr) == SYNCH_MSG)
1356                 return 0;                     !! 1257                 goto drop;
1357         }                                     !! 1258 
1358                                               !! 1259         /* FAILOVER_MSG */
1359         /* Not a fragment? */                 !! 1260         if (!tipc_msg_extract(skb, &iskb, &ipos)) {
1360         if (likely(!msg_nof_fragms(hdr))) {   !! 1261                 pr_warn_ratelimited("Cannot extract FAILOVER_MSG, defq: %d\n",
1361                 if (unlikely(!tipc_msg_extrac !! 1262                                     skb_queue_len(fdefq));
1362                         pr_warn_ratelimited(" !! 1263                 return rc;
1363                                             s << 
1364                         return 0;             << 
1365                 }                             << 
1366                 kfree_skb(skb);               << 
1367         } else {                              << 
1368                 /* Set fragment type for buf_ << 
1369                 if (msg_fragm_no(hdr) == 1)   << 
1370                         msg_set_type(hdr, FIR << 
1371                 else if (msg_fragm_no(hdr) <  << 
1372                         msg_set_type(hdr, FRA << 
1373                 else                          << 
1374                         msg_set_type(hdr, LAS << 
1375                                               << 
1376                 if (!tipc_buf_append(reasm_tn << 
1377                         /* Successful but non << 
1378                         if (*reasm_tnlmsg ||  << 
1379                                 return 0;     << 
1380                         pr_warn_ratelimited(" << 
1381                         return tipc_link_fsm_ << 
1382                 }                             << 
1383                 iskb = skb;                   << 
1384         }                                        1264         }
1385                                                  1265 
1386         do {                                     1266         do {
1387                 seqno = buf_seqno(iskb);         1267                 seqno = buf_seqno(iskb);
                                                   >> 1268 
1388                 if (unlikely(less(seqno, l->d    1269                 if (unlikely(less(seqno, l->drop_point))) {
1389                         kfree_skb(iskb);         1270                         kfree_skb(iskb);
1390                         continue;                1271                         continue;
1391                 }                                1272                 }
                                                   >> 1273 
1392                 if (unlikely(seqno != l->drop    1274                 if (unlikely(seqno != l->drop_point)) {
1393                         __tipc_skb_queue_sort    1275                         __tipc_skb_queue_sorted(fdefq, seqno, iskb);
1394                         continue;                1276                         continue;
1395                 }                                1277                 }
1396                                                  1278 
1397                 l->drop_point++;                 1279                 l->drop_point++;
                                                   >> 1280 
1398                 if (!tipc_data_input(l, iskb,    1281                 if (!tipc_data_input(l, iskb, inputq))
1399                         rc |= tipc_link_input    1282                         rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
1400                 if (unlikely(rc))                1283                 if (unlikely(rc))
1401                         break;                   1284                         break;
1402         } while ((iskb = __tipc_skb_dequeue(f    1285         } while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
1403                                                  1286 
                                                   >> 1287 drop:
                                                   >> 1288         kfree_skb(skb);
1404         return rc;                               1289         return rc;
1405 }                                                1290 }
1406                                                  1291 
1407 /**                                           !! 1292 static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked)
1408  * tipc_get_gap_ack_blks - get Gap ACK blocks << 
1409  * @ga: returned pointer to the Gap ACK block << 
1410  * @l: the tipc link                          << 
1411  * @hdr: the PROTOCOL/STATE_MSG header        << 
1412  * @uc: desired Gap ACK blocks type, i.e. uni << 
1413  *                                            << 
1414  * Return: the total Gap ACK blocks size      << 
1415  */                                           << 
1416 u16 tipc_get_gap_ack_blks(struct tipc_gap_ack << 
1417                           struct tipc_msg *hd << 
1418 {                                                1293 {
1419         struct tipc_gap_ack_blks *p;          !! 1294         bool released = false;
1420         u16 sz = 0;                           !! 1295         struct sk_buff *skb, *tmp;
1421                                                  1296 
1422         /* Does peer support the Gap ACK bloc !! 1297         skb_queue_walk_safe(&l->transmq, skb, tmp) {
1423         if (l->peer_caps & TIPC_GAP_ACK_BLOCK !! 1298                 if (more(buf_seqno(skb), acked))
1424                 p = (struct tipc_gap_ack_blks !! 1299                         break;
1425                 sz = ntohs(p->len);           !! 1300                 __skb_unlink(skb, &l->transmq);
1426                 /* Sanity check */            !! 1301                 kfree_skb(skb);
1427                 if (sz == struct_size(p, gack !! 1302                 released = true;
1428                         /* Good, check if the << 
1429                         if ((uc && p->ugack_c << 
1430                                 goto ok;      << 
1431                 /* Backward compatible: peer  << 
1432                 } else if (uc && sz == struct << 
1433                         if (p->ugack_cnt) {   << 
1434                                 p->bgack_cnt  << 
1435                                 goto ok;      << 
1436                         }                     << 
1437                 }                             << 
1438         }                                        1303         }
1439         /* Other cases: ignore! */            !! 1304         return released;
1440         p = NULL;                             << 
1441                                               << 
1442 ok:                                           << 
1443         *ga = p;                              << 
1444         return sz;                            << 
1445 }                                                1305 }
1446                                                  1306 
1447 static u8 __tipc_build_gap_ack_blks(struct ti !! 1307 /* tipc_build_gap_ack_blks - build Gap ACK blocks
1448                                     struct ti !! 1308  * @l: tipc link that data have come with gaps in sequence if any
                                                   >> 1309  * @data: data buffer to store the Gap ACK blocks after built
                                                   >> 1310  *
                                                   >> 1311  * returns the actual allocated memory size
                                                   >> 1312  */
                                                   >> 1313 static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data)
1449 {                                                1314 {
1450         struct tipc_gap_ack *gacks = &ga->gac << 
1451         struct sk_buff *skb = skb_peek(&l->de    1315         struct sk_buff *skb = skb_peek(&l->deferdq);
1452         u16 expect, seqno = 0;                !! 1316         struct tipc_gap_ack_blks *ga = data;
                                                   >> 1317         u16 len, expect, seqno = 0;
1453         u8 n = 0;                                1318         u8 n = 0;
1454                                                  1319 
1455         if (!skb)                                1320         if (!skb)
1456                 return 0;                     !! 1321                 goto exit;
1457                                                  1322 
1458         expect = buf_seqno(skb);                 1323         expect = buf_seqno(skb);
1459         skb_queue_walk(&l->deferdq, skb) {       1324         skb_queue_walk(&l->deferdq, skb) {
1460                 seqno = buf_seqno(skb);          1325                 seqno = buf_seqno(skb);
1461                 if (unlikely(more(seqno, expe    1326                 if (unlikely(more(seqno, expect))) {
1462                         gacks[n].ack = htons( !! 1327                         ga->gacks[n].ack = htons(expect - 1);
1463                         gacks[n].gap = htons( !! 1328                         ga->gacks[n].gap = htons(seqno - expect);
1464                         if (++n >= MAX_GAP_AC !! 1329                         if (++n >= MAX_GAP_ACK_BLKS) {
1465                                 pr_info_ratel !! 1330                                 pr_info_ratelimited("Too few Gap ACK blocks!\n");
1466                                               !! 1331                                 goto exit;
1467                                               << 
1468                                 return n;     << 
1469                         }                        1332                         }
1470                 } else if (unlikely(less(seqn    1333                 } else if (unlikely(less(seqno, expect))) {
1471                         pr_warn("Unexpected s    1334                         pr_warn("Unexpected skb in deferdq!\n");
1472                         continue;                1335                         continue;
1473                 }                                1336                 }
1474                 expect = seqno + 1;              1337                 expect = seqno + 1;
1475         }                                        1338         }
1476                                                  1339 
1477         /* last block */                         1340         /* last block */
1478         gacks[n].ack = htons(seqno);          !! 1341         ga->gacks[n].ack = htons(seqno);
1479         gacks[n].gap = 0;                     !! 1342         ga->gacks[n].gap = 0;
1480         n++;                                     1343         n++;
1481         return n;                             << 
1482 }                                             << 
1483                                               << 
1484 /* tipc_build_gap_ack_blks - build Gap ACK bl << 
1485  * @l: tipc unicast link                      << 
1486  * @hdr: the tipc message buffer to store the << 
1487  *                                            << 
1488  * The function builds Gap ACK blocks for bot << 
1489  * links of a certain peer, the buffer after  << 
1490  * as found at the struct tipc_gap_ack_blks d << 
1491  *                                            << 
1492  * returns the actual allocated memory size   << 
1493  */                                           << 
1494 static u16 tipc_build_gap_ack_blks(struct tip << 
1495 {                                             << 
1496         struct tipc_link *bcl = l->bc_rcvlink << 
1497         struct tipc_gap_ack_blks *ga;         << 
1498         u16 len;                              << 
1499                                               << 
1500         ga = (struct tipc_gap_ack_blks *)msg_ << 
1501                                               << 
1502         /* Start with broadcast link first */ << 
1503         tipc_bcast_lock(bcl->net);            << 
1504         msg_set_bcast_ack(hdr, bcl->rcv_nxt - << 
1505         msg_set_bc_gap(hdr, link_bc_rcv_gap(b << 
1506         ga->bgack_cnt = __tipc_build_gap_ack_ << 
1507         tipc_bcast_unlock(bcl->net);          << 
1508                                               << 
1509         /* Now for unicast link, but an expli << 
1510         ga->ugack_cnt = (msg_seq_gap(hdr)) ?  << 
1511                         __tipc_build_gap_ack_ << 
1512                                                  1344 
1513         /* Total len */                       !! 1345 exit:
1514         len = struct_size(ga, gacks, size_add !! 1346         len = tipc_gap_ack_blks_sz(n);
1515         ga->len = htons(len);                    1347         ga->len = htons(len);
                                                   >> 1348         ga->gack_cnt = n;
1516         return len;                              1349         return len;
1517 }                                                1350 }
1518                                                  1351 
1519 /* tipc_link_advance_transmq - advance TIPC l    1352 /* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing
1520  *                             acked packets,    1353  *                             acked packets, also doing retransmissions if
1521  *                             gaps found        1354  *                             gaps found
1522  * @l: tipc link with transmq queue to be adv    1355  * @l: tipc link with transmq queue to be advanced
1523  * @r: tipc link "receiver" i.e. in case of b << 
1524  * @acked: seqno of last packet acked by peer    1356  * @acked: seqno of last packet acked by peer without any gaps before
1525  * @gap: # of gap packets                        1357  * @gap: # of gap packets
1526  * @ga: buffer pointer to Gap ACK blocks from    1358  * @ga: buffer pointer to Gap ACK blocks from peer
1527  * @xmitq: queue for accumulating the retrans    1359  * @xmitq: queue for accumulating the retransmitted packets if any
1528  * @retransmitted: returned boolean value if  << 
1529  * @rc: returned code e.g. TIPC_LINK_DOWN_EVT << 
1530  *      happens (- unlikely case)             << 
1531  *                                               1360  *
1532  * Return: the number of packets released fro !! 1361  * In case of a repeated retransmit failures, the call will return shortly
                                                   >> 1362  * with a returned code (e.g. TIPC_LINK_DOWN_EVT)
1533  */                                              1363  */
1534 static int tipc_link_advance_transmq(struct t !! 1364 static int tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
1535                                      u16 acke << 
1536                                      struct t    1365                                      struct tipc_gap_ack_blks *ga,
1537                                      struct s !! 1366                                      struct sk_buff_head *xmitq)
1538                                      bool *re << 
1539 {                                                1367 {
1540         struct tipc_gap_ack_blks *last_ga = r << 
1541         struct tipc_gap_ack *gacks = NULL;    << 
1542         struct sk_buff *skb, *_skb, *tmp;        1368         struct sk_buff *skb, *_skb, *tmp;
1543         struct tipc_msg *hdr;                    1369         struct tipc_msg *hdr;
1544         u32 qlen = skb_queue_len(&l->transmq) << 
1545         u16 nacked = acked, ngap = gap, gack_ << 
1546         u16 bc_ack = l->bc_rcvlink->rcv_nxt -    1370         u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1547         u16 ack = l->rcv_nxt - 1;                1371         u16 ack = l->rcv_nxt - 1;
                                                   >> 1372         bool passed = false;
1548         u16 seqno, n = 0;                        1373         u16 seqno, n = 0;
1549         u16 end = r->acked, start = end, offs !! 1374         int rc = 0;
1550         u16 si = (last_ga) ? last_ga->start_i << 
1551         bool is_uc = !link_is_bc_sndlink(l);  << 
1552         bool bc_has_acked = false;            << 
1553                                               << 
1554         trace_tipc_link_retrans(r, acked + 1, << 
1555                                               << 
1556         /* Determine Gap ACK blocks if any fo << 
1557         if (ga && is_uc) {                    << 
1558                 /* Get the Gap ACKs, uc part  << 
1559                 gack_cnt = ga->ugack_cnt;     << 
1560                 gacks = &ga->gacks[ga->bgack_ << 
1561         } else if (ga) {                      << 
1562                 /* Copy the Gap ACKs, bc part << 
1563                 this_ga = kmemdup(ga, struct_ << 
1564                                   GFP_ATOMIC) << 
1565                 if (likely(this_ga)) {        << 
1566                         this_ga->start_index  << 
1567                         /* Start with the bc  << 
1568                         gack_cnt = this_ga->b << 
1569                         gacks = &this_ga->gac << 
1570                 } else {                      << 
1571                         /* Hmm, we can get in << 
1572                         pr_warn_ratelimited(" << 
1573                 }                             << 
1574         }                                     << 
1575                                                  1375 
1576         /* Advance the link transmq */        << 
1577         skb_queue_walk_safe(&l->transmq, skb,    1376         skb_queue_walk_safe(&l->transmq, skb, tmp) {
1578                 seqno = buf_seqno(skb);          1377                 seqno = buf_seqno(skb);
1579                                                  1378 
1580 next_gap_ack:                                    1379 next_gap_ack:
1581                 if (less_eq(seqno, nacked)) { !! 1380                 if (less_eq(seqno, acked)) {
1582                         if (is_uc)            << 
1583                                 goto release; << 
1584                         /* Skip packets peer  << 
1585                         if (!more(seqno, r->a << 
1586                                 continue;     << 
1587                         /* Get the next of la << 
1588                         while (more(seqno, en << 
1589                                 if (!last_ga  << 
1590                                         break << 
1591                                 start = end + << 
1592                                 end = ntohs(l << 
1593                                 offset = ntoh << 
1594                                 si++;         << 
1595                                 WARN_ONCE(mor << 
1596                                           (!o << 
1597                                            si << 
1598                                           si  << 
1599                                           "Co << 
1600                                           sta << 
1601                                           las << 
1602                         }                     << 
1603                         /* Check against the  << 
1604                         if (tipc_in_range(seq << 
1605                                 continue;     << 
1606                         /* Update/release the << 
1607                         bc_has_acked = true;  << 
1608                         if (--TIPC_SKB_CB(skb << 
1609                                 continue;     << 
1610 release:                                      << 
1611                         /* release skb */        1381                         /* release skb */
1612                         __skb_unlink(skb, &l-    1382                         __skb_unlink(skb, &l->transmq);
1613                         kfree_skb(skb);          1383                         kfree_skb(skb);
1614                 } else if (less_eq(seqno, nac !! 1384                 } else if (less_eq(seqno, acked + gap)) {
1615                         /* First gap: check i !! 1385                         /* First, check if repeated retrans failures occurs? */
1616                         if (unlikely(seqno == !! 1386                         if (!passed && link_retransmit_failure(l, l, &rc))
1617                                      link_ret !! 1387                                 return rc;
1618                                 /* Ignore thi !! 1388                         passed = true;
1619                                 kfree(this_ga !! 1389 
1620                                 this_ga = NUL << 
1621                                 break;        << 
1622                         }                     << 
1623                         /* retransmit skb if     1390                         /* retransmit skb if unrestricted*/
1624                         if (time_before(jiffi    1391                         if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
1625                                 continue;        1392                                 continue;
1626                         tipc_link_set_skb_ret !! 1393                         TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME;
1627                         _skb = pskb_copy(skb, !! 1394                         _skb = __pskb_copy(skb, LL_MAX_HEADER + MIN_H_SIZE,
                                                   >> 1395                                            GFP_ATOMIC);
1628                         if (!_skb)               1396                         if (!_skb)
1629                                 continue;        1397                                 continue;
1630                         hdr = buf_msg(_skb);     1398                         hdr = buf_msg(_skb);
1631                         msg_set_ack(hdr, ack)    1399                         msg_set_ack(hdr, ack);
1632                         msg_set_bcast_ack(hdr    1400                         msg_set_bcast_ack(hdr, bc_ack);
1633                         _skb->priority = TC_P    1401                         _skb->priority = TC_PRIO_CONTROL;
1634                         __skb_queue_tail(xmit    1402                         __skb_queue_tail(xmitq, _skb);
1635                         l->stats.retransmitte    1403                         l->stats.retransmitted++;
1636                         if (!is_uc)           !! 1404 
1637                                 r->stats.retr << 
1638                         *retransmitted = true << 
1639                         /* Increase actual re    1405                         /* Increase actual retrans counter & mark first time */
1640                         if (!TIPC_SKB_CB(skb)    1406                         if (!TIPC_SKB_CB(skb)->retr_cnt++)
1641                                 TIPC_SKB_CB(s    1407                                 TIPC_SKB_CB(skb)->retr_stamp = jiffies;
1642                 } else {                         1408                 } else {
1643                         /* retry with Gap ACK    1409                         /* retry with Gap ACK blocks if any */
1644                         if (n >= gack_cnt)    !! 1410                         if (!ga || n >= ga->gack_cnt)
1645                                 break;           1411                                 break;
1646                         nacked = ntohs(gacks[ !! 1412                         acked = ntohs(ga->gacks[n].ack);
1647                         ngap = ntohs(gacks[n] !! 1413                         gap = ntohs(ga->gacks[n].gap);
1648                         n++;                     1414                         n++;
1649                         goto next_gap_ack;       1415                         goto next_gap_ack;
1650                 }                                1416                 }
1651         }                                        1417         }
1652                                                  1418 
1653         /* Renew last Gap ACK blocks for bc i !! 1419         return 0;
1654         if (bc_has_acked) {                   << 
1655                 if (this_ga) {                << 
1656                         kfree(last_ga);       << 
1657                         r->last_ga = this_ga; << 
1658                         r->last_gap = gap;    << 
1659                 } else if (last_ga) {         << 
1660                         if (less(acked, start << 
1661                                 si--;         << 
1662                                 offset = star << 
1663                         } else if (less(acked << 
1664                                 acked = end;  << 
1665                         }                     << 
1666                         if (si < last_ga->bga << 
1667                                 last_ga->star << 
1668                                 r->last_gap = << 
1669                         } else {              << 
1670                                 kfree(last_ga << 
1671                                 r->last_ga =  << 
1672                                 r->last_gap = << 
1673                         }                     << 
1674                 } else {                      << 
1675                         r->last_gap = 0;      << 
1676                 }                             << 
1677                 r->acked = acked;             << 
1678         } else {                              << 
1679                 kfree(this_ga);               << 
1680         }                                     << 
1681                                               << 
1682         return qlen - skb_queue_len(&l->trans << 
1683 }                                                1420 }
1684                                                  1421 
1685 /* tipc_link_build_state_msg: prepare link st    1422 /* tipc_link_build_state_msg: prepare link state message for transmission
1686  *                                               1423  *
1687  * Note that sending of broadcast ack is coor    1424  * Note that sending of broadcast ack is coordinated among nodes, to reduce
1688  * risk of ack storms towards the sender         1425  * risk of ack storms towards the sender
1689  */                                              1426  */
1690 int tipc_link_build_state_msg(struct tipc_lin    1427 int tipc_link_build_state_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1691 {                                                1428 {
1692         if (!l)                                  1429         if (!l)
1693                 return 0;                        1430                 return 0;
1694                                                  1431 
1695         /* Broadcast ACK must be sent via a u    1432         /* Broadcast ACK must be sent via a unicast link => defer to caller */
1696         if (link_is_bc_rcvlink(l)) {             1433         if (link_is_bc_rcvlink(l)) {
1697                 if (((l->rcv_nxt ^ tipc_own_a    1434                 if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
1698                         return 0;                1435                         return 0;
1699                 l->rcv_unacked = 0;              1436                 l->rcv_unacked = 0;
1700                                                  1437 
1701                 /* Use snd_nxt to store peer'    1438                 /* Use snd_nxt to store peer's snd_nxt in broadcast rcv link */
1702                 l->snd_nxt = l->rcv_nxt;         1439                 l->snd_nxt = l->rcv_nxt;
1703                 return TIPC_LINK_SND_STATE;      1440                 return TIPC_LINK_SND_STATE;
1704         }                                        1441         }
                                                   >> 1442 
1705         /* Unicast ACK */                        1443         /* Unicast ACK */
1706         l->rcv_unacked = 0;                      1444         l->rcv_unacked = 0;
1707         l->stats.sent_acks++;                    1445         l->stats.sent_acks++;
1708         tipc_link_build_proto_msg(l, STATE_MS    1446         tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
1709         return 0;                                1447         return 0;
1710 }                                                1448 }
1711                                                  1449 
1712 /* tipc_link_build_reset_msg: prepare link RE    1450 /* tipc_link_build_reset_msg: prepare link RESET or ACTIVATE message
1713  */                                              1451  */
1714 void tipc_link_build_reset_msg(struct tipc_li    1452 void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1715 {                                                1453 {
1716         int mtyp = RESET_MSG;                    1454         int mtyp = RESET_MSG;
1717         struct sk_buff *skb;                     1455         struct sk_buff *skb;
1718                                                  1456 
1719         if (l->state == LINK_ESTABLISHING)       1457         if (l->state == LINK_ESTABLISHING)
1720                 mtyp = ACTIVATE_MSG;             1458                 mtyp = ACTIVATE_MSG;
1721                                                  1459 
1722         tipc_link_build_proto_msg(l, mtyp, 0,    1460         tipc_link_build_proto_msg(l, mtyp, 0, 0, 0, 0, 0, xmitq);
1723                                                  1461 
1724         /* Inform peer that this endpoint is     1462         /* Inform peer that this endpoint is going down if applicable */
1725         skb = skb_peek_tail(xmitq);              1463         skb = skb_peek_tail(xmitq);
1726         if (skb && (l->state == LINK_RESET))     1464         if (skb && (l->state == LINK_RESET))
1727                 msg_set_peer_stopping(buf_msg    1465                 msg_set_peer_stopping(buf_msg(skb), 1);
1728 }                                                1466 }
1729                                                  1467 
1730 /* tipc_link_build_nack_msg: prepare link nac    1468 /* tipc_link_build_nack_msg: prepare link nack message for transmission
1731  * Note that sending of broadcast NACK is coo    1469  * Note that sending of broadcast NACK is coordinated among nodes, to
1732  * reduce the risk of NACK storms towards the    1470  * reduce the risk of NACK storms towards the sender
1733  */                                              1471  */
1734 static int tipc_link_build_nack_msg(struct ti    1472 static int tipc_link_build_nack_msg(struct tipc_link *l,
1735                                     struct sk    1473                                     struct sk_buff_head *xmitq)
1736 {                                                1474 {
1737         u32 def_cnt = ++l->stats.deferred_rec    1475         u32 def_cnt = ++l->stats.deferred_recv;
1738         struct sk_buff_head *dfq = &l->deferd !! 1476         u32 defq_len = skb_queue_len(&l->deferdq);
1739         u32 defq_len = skb_queue_len(dfq);    << 
1740         int match1, match2;                      1477         int match1, match2;
1741                                                  1478 
1742         if (link_is_bc_rcvlink(l)) {             1479         if (link_is_bc_rcvlink(l)) {
1743                 match1 = def_cnt & 0xf;          1480                 match1 = def_cnt & 0xf;
1744                 match2 = tipc_own_addr(l->net    1481                 match2 = tipc_own_addr(l->net) & 0xf;
1745                 if (match1 == match2)            1482                 if (match1 == match2)
1746                         return TIPC_LINK_SND_    1483                         return TIPC_LINK_SND_STATE;
1747                 return 0;                        1484                 return 0;
1748         }                                        1485         }
1749                                                  1486 
1750         if (defq_len >= 3 && !((defq_len - 3) !! 1487         if (defq_len >= 3 && !((defq_len - 3) % 16))
1751                 u16 rcvgap = buf_seqno(skb_pe !! 1488                 tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
1752                                               << 
1753                 tipc_link_build_proto_msg(l,  << 
1754                                           rcv << 
1755         }                                     << 
1756         return 0;                                1489         return 0;
1757 }                                                1490 }
1758                                                  1491 
1759 /* tipc_link_rcv - process TIPC packets/messa    1492 /* tipc_link_rcv - process TIPC packets/messages arriving from off-node
1760  * @l: the link that should handle the messag    1493  * @l: the link that should handle the message
1761  * @skb: TIPC packet                             1494  * @skb: TIPC packet
1762  * @xmitq: queue to place packets to be sent     1495  * @xmitq: queue to place packets to be sent after this call
1763  */                                              1496  */
1764 int tipc_link_rcv(struct tipc_link *l, struct    1497 int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
1765                   struct sk_buff_head *xmitq)    1498                   struct sk_buff_head *xmitq)
1766 {                                                1499 {
1767         struct sk_buff_head *defq = &l->defer    1500         struct sk_buff_head *defq = &l->deferdq;
1768         struct tipc_msg *hdr = buf_msg(skb);     1501         struct tipc_msg *hdr = buf_msg(skb);
1769         u16 seqno, rcv_nxt, win_lim;             1502         u16 seqno, rcv_nxt, win_lim;
1770         int released = 0;                     << 
1771         int rc = 0;                              1503         int rc = 0;
1772                                                  1504 
1773         /* Verify and update link state */       1505         /* Verify and update link state */
1774         if (unlikely(msg_user(hdr) == LINK_PR    1506         if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
1775                 return tipc_link_proto_rcv(l,    1507                 return tipc_link_proto_rcv(l, skb, xmitq);
1776                                                  1508 
1777         /* Don't send probe at next timeout e    1509         /* Don't send probe at next timeout expiration */
1778         l->silent_intv_cnt = 0;                  1510         l->silent_intv_cnt = 0;
1779                                                  1511 
1780         do {                                     1512         do {
1781                 hdr = buf_msg(skb);              1513                 hdr = buf_msg(skb);
1782                 seqno = msg_seqno(hdr);          1514                 seqno = msg_seqno(hdr);
1783                 rcv_nxt = l->rcv_nxt;            1515                 rcv_nxt = l->rcv_nxt;
1784                 win_lim = rcv_nxt + TIPC_MAX_    1516                 win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
1785                                                  1517 
1786                 if (unlikely(!tipc_link_is_up !! 1518                 if (unlikely(!link_is_up(l))) {
1787                         if (l->state == LINK_    1519                         if (l->state == LINK_ESTABLISHING)
1788                                 rc = TIPC_LIN    1520                                 rc = TIPC_LINK_UP_EVT;
1789                         kfree_skb(skb);       !! 1521                         goto drop;
1790                         break;                << 
1791                 }                                1522                 }
1792                                                  1523 
1793                 /* Drop if outside receive wi    1524                 /* Drop if outside receive window */
1794                 if (unlikely(less(seqno, rcv_    1525                 if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
1795                         l->stats.duplicates++    1526                         l->stats.duplicates++;
1796                         kfree_skb(skb);       !! 1527                         goto drop;
1797                         break;                !! 1528                 }
                                                   >> 1529 
                                                   >> 1530                 /* Forward queues and wake up waiting users */
                                                   >> 1531                 if (likely(tipc_link_release_pkts(l, msg_ack(hdr)))) {
                                                   >> 1532                         tipc_link_advance_backlog(l, xmitq);
                                                   >> 1533                         if (unlikely(!skb_queue_empty(&l->wakeupq)))
                                                   >> 1534                                 link_prepare_wakeup(l);
1798                 }                                1535                 }
1799                 released += tipc_link_advance << 
1800                                               << 
1801                                                  1536 
1802                 /* Defer delivery if sequence    1537                 /* Defer delivery if sequence gap */
1803                 if (unlikely(seqno != rcv_nxt    1538                 if (unlikely(seqno != rcv_nxt)) {
1804                         if (!__tipc_skb_queue !! 1539                         __tipc_skb_queue_sorted(defq, seqno, skb);
1805                                 l->stats.dupl << 
1806                         rc |= tipc_link_build    1540                         rc |= tipc_link_build_nack_msg(l, xmitq);
1807                         break;                   1541                         break;
1808                 }                                1542                 }
1809                                                  1543 
1810                 /* Deliver packet */             1544                 /* Deliver packet */
1811                 l->rcv_nxt++;                    1545                 l->rcv_nxt++;
1812                 l->stats.recv_pkts++;            1546                 l->stats.recv_pkts++;
1813                                                  1547 
1814                 if (unlikely(msg_user(hdr) ==    1548                 if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL))
1815                         rc |= tipc_link_tnl_r    1549                         rc |= tipc_link_tnl_rcv(l, skb, l->inputq);
1816                 else if (!tipc_data_input(l,     1550                 else if (!tipc_data_input(l, skb, l->inputq))
1817                         rc |= tipc_link_input    1551                         rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf);
1818                 if (unlikely(++l->rcv_unacked    1552                 if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
1819                         rc |= tipc_link_build    1553                         rc |= tipc_link_build_state_msg(l, xmitq);
1820                 if (unlikely(rc & ~TIPC_LINK_    1554                 if (unlikely(rc & ~TIPC_LINK_SND_STATE))
1821                         break;                   1555                         break;
1822         } while ((skb = __tipc_skb_dequeue(de    1556         } while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt)));
1823                                                  1557 
1824         /* Forward queues and wake up waiting !! 1558         return rc;
1825         if (released) {                       !! 1559 drop:
1826                 tipc_link_update_cwin(l, rele !! 1560         kfree_skb(skb);
1827                 tipc_link_advance_backlog(l,  << 
1828                 if (unlikely(!skb_queue_empty << 
1829                         link_prepare_wakeup(l << 
1830         }                                     << 
1831         return rc;                               1561         return rc;
1832 }                                                1562 }
1833                                                  1563 
1834 static void tipc_link_build_proto_msg(struct     1564 static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1835                                       bool pr    1565                                       bool probe_reply, u16 rcvgap,
1836                                       int tol    1566                                       int tolerance, int priority,
1837                                       struct     1567                                       struct sk_buff_head *xmitq)
1838 {                                                1568 {
1839         struct tipc_mon_state *mstate = &l->m << 
1840         struct sk_buff_head *dfq = &l->deferd << 
1841         struct tipc_link *bcl = l->bc_rcvlink    1569         struct tipc_link *bcl = l->bc_rcvlink;
1842         struct tipc_msg *hdr;                 << 
1843         struct sk_buff *skb;                     1570         struct sk_buff *skb;
1844         bool node_up = tipc_link_is_up(bcl);  !! 1571         struct tipc_msg *hdr;
1845         u16 glen = 0, bc_rcvgap = 0;          !! 1572         struct sk_buff_head *dfq = &l->deferdq;
                                                   >> 1573         bool node_up = link_is_up(bcl);
                                                   >> 1574         struct tipc_mon_state *mstate = &l->mon_state;
1846         int dlen = 0;                            1575         int dlen = 0;
1847         void *data;                              1576         void *data;
                                                   >> 1577         u16 glen = 0;
1848                                                  1578 
1849         /* Don't send protocol message during    1579         /* Don't send protocol message during reset or link failover */
1850         if (tipc_link_is_blocked(l))             1580         if (tipc_link_is_blocked(l))
1851                 return;                          1581                 return;
1852                                                  1582 
1853         if (!tipc_link_is_up(l) && (mtyp == S    1583         if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
1854                 return;                          1584                 return;
1855                                                  1585 
1856         if ((probe || probe_reply) && !skb_qu !! 1586         if (!skb_queue_empty(dfq))
1857                 rcvgap = buf_seqno(skb_peek(d    1587                 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1858                                                  1588 
1859         skb = tipc_msg_create(LINK_PROTOCOL,     1589         skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
1860                               tipc_max_domain    1590                               tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ,
1861                               l->addr, tipc_o    1591                               l->addr, tipc_own_addr(l->net), 0, 0, 0);
1862         if (!skb)                                1592         if (!skb)
1863                 return;                          1593                 return;
1864                                                  1594 
1865         hdr = buf_msg(skb);                      1595         hdr = buf_msg(skb);
1866         data = msg_data(hdr);                    1596         data = msg_data(hdr);
1867         msg_set_session(hdr, l->session);        1597         msg_set_session(hdr, l->session);
1868         msg_set_bearer_id(hdr, l->bearer_id);    1598         msg_set_bearer_id(hdr, l->bearer_id);
1869         msg_set_net_plane(hdr, l->net_plane);    1599         msg_set_net_plane(hdr, l->net_plane);
1870         msg_set_next_sent(hdr, l->snd_nxt);      1600         msg_set_next_sent(hdr, l->snd_nxt);
1871         msg_set_ack(hdr, l->rcv_nxt - 1);        1601         msg_set_ack(hdr, l->rcv_nxt - 1);
1872         msg_set_bcast_ack(hdr, bcl->rcv_nxt -    1602         msg_set_bcast_ack(hdr, bcl->rcv_nxt - 1);
1873         msg_set_bc_ack_invalid(hdr, !node_up)    1603         msg_set_bc_ack_invalid(hdr, !node_up);
1874         msg_set_last_bcast(hdr, l->bc_sndlink    1604         msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
1875         msg_set_link_tolerance(hdr, tolerance    1605         msg_set_link_tolerance(hdr, tolerance);
1876         msg_set_linkprio(hdr, priority);         1606         msg_set_linkprio(hdr, priority);
1877         msg_set_redundant_link(hdr, node_up);    1607         msg_set_redundant_link(hdr, node_up);
1878         msg_set_seq_gap(hdr, 0);                 1608         msg_set_seq_gap(hdr, 0);
1879         msg_set_seqno(hdr, l->snd_nxt + U16_M    1609         msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
1880                                                  1610 
1881         if (mtyp == STATE_MSG) {                 1611         if (mtyp == STATE_MSG) {
1882                 if (l->peer_caps & TIPC_LINK_    1612                 if (l->peer_caps & TIPC_LINK_PROTO_SEQNO)
1883                         msg_set_seqno(hdr, l-    1613                         msg_set_seqno(hdr, l->snd_nxt_state++);
1884                 msg_set_seq_gap(hdr, rcvgap);    1614                 msg_set_seq_gap(hdr, rcvgap);
1885                 bc_rcvgap = link_bc_rcv_gap(b !! 1615                 msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
1886                 msg_set_bc_gap(hdr, bc_rcvgap << 
1887                 msg_set_probe(hdr, probe);       1616                 msg_set_probe(hdr, probe);
1888                 msg_set_is_keepalive(hdr, pro    1617                 msg_set_is_keepalive(hdr, probe || probe_reply);
1889                 if (l->peer_caps & TIPC_GAP_A    1618                 if (l->peer_caps & TIPC_GAP_ACK_BLOCK)
1890                         glen = tipc_build_gap !! 1619                         glen = tipc_build_gap_ack_blks(l, data);
1891                 tipc_mon_prep(l->net, data +     1620                 tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id);
1892                 msg_set_size(hdr, INT_H_SIZE     1621                 msg_set_size(hdr, INT_H_SIZE + glen + dlen);
1893                 skb_trim(skb, INT_H_SIZE + gl    1622                 skb_trim(skb, INT_H_SIZE + glen + dlen);
1894                 l->stats.sent_states++;          1623                 l->stats.sent_states++;
1895                 l->rcv_unacked = 0;              1624                 l->rcv_unacked = 0;
1896         } else {                                 1625         } else {
1897                 /* RESET_MSG or ACTIVATE_MSG     1626                 /* RESET_MSG or ACTIVATE_MSG */
1898                 if (mtyp == ACTIVATE_MSG) {      1627                 if (mtyp == ACTIVATE_MSG) {
1899                         msg_set_dest_session_    1628                         msg_set_dest_session_valid(hdr, 1);
1900                         msg_set_dest_session(    1629                         msg_set_dest_session(hdr, l->peer_session);
1901                 }                                1630                 }
1902                 msg_set_max_pkt(hdr, l->adver    1631                 msg_set_max_pkt(hdr, l->advertised_mtu);
1903                 strcpy(data, l->if_name);        1632                 strcpy(data, l->if_name);
1904                 msg_set_size(hdr, INT_H_SIZE     1633                 msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
1905                 skb_trim(skb, INT_H_SIZE + TI    1634                 skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
1906         }                                        1635         }
1907         if (probe)                               1636         if (probe)
1908                 l->stats.sent_probes++;          1637                 l->stats.sent_probes++;
1909         if (rcvgap)                              1638         if (rcvgap)
1910                 l->stats.sent_nacks++;           1639                 l->stats.sent_nacks++;
1911         if (bc_rcvgap)                        << 
1912                 bcl->stats.sent_nacks++;      << 
1913         skb->priority = TC_PRIO_CONTROL;         1640         skb->priority = TC_PRIO_CONTROL;
1914         __skb_queue_tail(xmitq, skb);            1641         __skb_queue_tail(xmitq, skb);
1915         trace_tipc_proto_build(skb, false, l-    1642         trace_tipc_proto_build(skb, false, l->name);
1916 }                                                1643 }
1917                                                  1644 
1918 void tipc_link_create_dummy_tnl_msg(struct ti    1645 void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
1919                                     struct sk    1646                                     struct sk_buff_head *xmitq)
1920 {                                                1647 {
1921         u32 onode = tipc_own_addr(l->net);       1648         u32 onode = tipc_own_addr(l->net);
1922         struct tipc_msg *hdr, *ihdr;             1649         struct tipc_msg *hdr, *ihdr;
1923         struct sk_buff_head tnlq;                1650         struct sk_buff_head tnlq;
1924         struct sk_buff *skb;                     1651         struct sk_buff *skb;
1925         u32 dnode = l->addr;                     1652         u32 dnode = l->addr;
1926                                                  1653 
1927         __skb_queue_head_init(&tnlq);         !! 1654         skb_queue_head_init(&tnlq);
1928         skb = tipc_msg_create(TUNNEL_PROTOCOL    1655         skb = tipc_msg_create(TUNNEL_PROTOCOL, FAILOVER_MSG,
1929                               INT_H_SIZE, BAS    1656                               INT_H_SIZE, BASIC_H_SIZE,
1930                               dnode, onode, 0    1657                               dnode, onode, 0, 0, 0);
1931         if (!skb) {                              1658         if (!skb) {
1932                 pr_warn("%sunable to create t    1659                 pr_warn("%sunable to create tunnel packet\n", link_co_err);
1933                 return;                          1660                 return;
1934         }                                        1661         }
1935                                                  1662 
1936         hdr = buf_msg(skb);                      1663         hdr = buf_msg(skb);
1937         msg_set_msgcnt(hdr, 1);                  1664         msg_set_msgcnt(hdr, 1);
1938         msg_set_bearer_id(hdr, l->peer_bearer    1665         msg_set_bearer_id(hdr, l->peer_bearer_id);
1939                                                  1666 
1940         ihdr = (struct tipc_msg *)msg_data(hd    1667         ihdr = (struct tipc_msg *)msg_data(hdr);
1941         tipc_msg_init(onode, ihdr, TIPC_LOW_I    1668         tipc_msg_init(onode, ihdr, TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
1942                       BASIC_H_SIZE, dnode);      1669                       BASIC_H_SIZE, dnode);
1943         msg_set_errcode(ihdr, TIPC_ERR_NO_POR    1670         msg_set_errcode(ihdr, TIPC_ERR_NO_PORT);
1944         __skb_queue_tail(&tnlq, skb);            1671         __skb_queue_tail(&tnlq, skb);
1945         tipc_link_xmit(l, &tnlq, xmitq);         1672         tipc_link_xmit(l, &tnlq, xmitq);
1946 }                                                1673 }
1947                                                  1674 
1948 /* tipc_link_tnl_prepare(): prepare and retur    1675 /* tipc_link_tnl_prepare(): prepare and return a list of tunnel packets
1949  * with contents of the link's transmit and b    1676  * with contents of the link's transmit and backlog queues.
1950  */                                              1677  */
1951 void tipc_link_tnl_prepare(struct tipc_link *    1678 void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1952                            int mtyp, struct s    1679                            int mtyp, struct sk_buff_head *xmitq)
1953 {                                                1680 {
1954         struct sk_buff_head *fdefq = &tnl->fa    1681         struct sk_buff_head *fdefq = &tnl->failover_deferdq;
1955         struct sk_buff *skb, *tnlskb;            1682         struct sk_buff *skb, *tnlskb;
1956         struct tipc_msg *hdr, tnlhdr;            1683         struct tipc_msg *hdr, tnlhdr;
1957         struct sk_buff_head *queue = &l->tran    1684         struct sk_buff_head *queue = &l->transmq;
1958         struct sk_buff_head tmpxq, tnlq, frag !! 1685         struct sk_buff_head tmpxq, tnlq;
1959         u16 pktlen, pktcnt, seqno = l->snd_nx    1686         u16 pktlen, pktcnt, seqno = l->snd_nxt;
1960         bool pktcnt_need_update = false;      << 
1961         u16 syncpt;                           << 
1962         int rc;                               << 
1963                                                  1687 
1964         if (!tnl)                                1688         if (!tnl)
1965                 return;                          1689                 return;
1966                                                  1690 
1967         __skb_queue_head_init(&tnlq);         !! 1691         skb_queue_head_init(&tnlq);
1968         /* Link Synching:                     !! 1692         skb_queue_head_init(&tmpxq);
1969          * From now on, send only one single  << 
1970          * to peer. The SYNCH message does no << 
1971          * a header conveying the synch point << 
1972          */                                   << 
1973         if (mtyp == SYNCH_MSG && (tnl->peer_c << 
1974                 tnlskb = tipc_msg_create(TUNN << 
1975                                          INT_ << 
1976                                          tipc << 
1977                                          0, 0 << 
1978                 if (!tnlskb) {                << 
1979                         pr_warn("%sunable to  << 
1980                                 link_co_err); << 
1981                         return;               << 
1982                 }                             << 
1983                                               << 
1984                 hdr = buf_msg(tnlskb);        << 
1985                 syncpt = l->snd_nxt + skb_que << 
1986                 msg_set_syncpt(hdr, syncpt);  << 
1987                 msg_set_bearer_id(hdr, l->pee << 
1988                 __skb_queue_tail(&tnlq, tnlsk << 
1989                 tipc_link_xmit(tnl, &tnlq, xm << 
1990                 return;                       << 
1991         }                                     << 
1992                                                  1693 
1993         __skb_queue_head_init(&tmpxq);        << 
1994         __skb_queue_head_init(&frags);        << 
1995         /* At least one packet required for s    1694         /* At least one packet required for safe algorithm => add dummy */
1996         skb = tipc_msg_create(TIPC_LOW_IMPORT    1695         skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
1997                               BASIC_H_SIZE, 0    1696                               BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net),
1998                               0, 0, TIPC_ERR_    1697                               0, 0, TIPC_ERR_NO_PORT);
1999         if (!skb) {                              1698         if (!skb) {
2000                 pr_warn("%sunable to create t    1699                 pr_warn("%sunable to create tunnel packet\n", link_co_err);
2001                 return;                          1700                 return;
2002         }                                        1701         }
2003         __skb_queue_tail(&tnlq, skb);         !! 1702         skb_queue_tail(&tnlq, skb);
2004         tipc_link_xmit(l, &tnlq, &tmpxq);        1703         tipc_link_xmit(l, &tnlq, &tmpxq);
2005         __skb_queue_purge(&tmpxq);               1704         __skb_queue_purge(&tmpxq);
2006                                                  1705 
2007         /* Initialize reusable tunnel packet     1706         /* Initialize reusable tunnel packet header */
2008         tipc_msg_init(tipc_own_addr(l->net),     1707         tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
2009                       mtyp, INT_H_SIZE, l->ad    1708                       mtyp, INT_H_SIZE, l->addr);
2010         if (mtyp == SYNCH_MSG)                   1709         if (mtyp == SYNCH_MSG)
2011                 pktcnt = l->snd_nxt - buf_seq    1710                 pktcnt = l->snd_nxt - buf_seqno(skb_peek(&l->transmq));
2012         else                                     1711         else
2013                 pktcnt = skb_queue_len(&l->tr    1712                 pktcnt = skb_queue_len(&l->transmq);
2014         pktcnt += skb_queue_len(&l->backlogq)    1713         pktcnt += skb_queue_len(&l->backlogq);
2015         msg_set_msgcnt(&tnlhdr, pktcnt);         1714         msg_set_msgcnt(&tnlhdr, pktcnt);
2016         msg_set_bearer_id(&tnlhdr, l->peer_be    1715         msg_set_bearer_id(&tnlhdr, l->peer_bearer_id);
2017 tnl:                                             1716 tnl:
2018         /* Wrap each packet into a tunnel pac    1717         /* Wrap each packet into a tunnel packet */
2019         skb_queue_walk(queue, skb) {             1718         skb_queue_walk(queue, skb) {
2020                 hdr = buf_msg(skb);              1719                 hdr = buf_msg(skb);
2021                 if (queue == &l->backlogq)       1720                 if (queue == &l->backlogq)
2022                         msg_set_seqno(hdr, se    1721                         msg_set_seqno(hdr, seqno++);
2023                 pktlen = msg_size(hdr);          1722                 pktlen = msg_size(hdr);
2024                                               << 
2025                 /* Tunnel link MTU is not lar << 
2026                  * due to:                    << 
2027                  * 1) Link MTU has just chang << 
2028                  * 2) Or FAILOVER on the top  << 
2029                  *                            << 
2030                  * The 2nd case should not ha << 
2031                  * TIPC_TUNNEL_ENHANCED       << 
2032                  */                           << 
2033                 if (pktlen > tnl->mtu - INT_H << 
2034                         if (mtyp == FAILOVER_ << 
2035                             (tnl->peer_caps & << 
2036                                 rc = tipc_msg << 
2037                                               << 
2038                                 if (rc) {     << 
2039                                         pr_wa << 
2040                                               << 
2041                                         retur << 
2042                                 }             << 
2043                                 pktcnt += skb << 
2044                                 pktcnt_need_u << 
2045                                 skb_queue_spl << 
2046                                 continue;     << 
2047                         }                     << 
2048                         /* Unluckily, peer do << 
2049                          * => Just warn it an << 
2050                          */                   << 
2051                         pr_warn_ratelimited(" << 
2052                                             l << 
2053                                             m << 
2054                         return;               << 
2055                 }                             << 
2056                                               << 
2057                 msg_set_size(&tnlhdr, pktlen     1723                 msg_set_size(&tnlhdr, pktlen + INT_H_SIZE);
2058                 tnlskb = tipc_buf_acquire(pkt    1724                 tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC);
2059                 if (!tnlskb) {                   1725                 if (!tnlskb) {
2060                         pr_warn("%sunable to     1726                         pr_warn("%sunable to send packet\n", link_co_err);
2061                         return;                  1727                         return;
2062                 }                                1728                 }
2063                 skb_copy_to_linear_data(tnlsk    1729                 skb_copy_to_linear_data(tnlskb, &tnlhdr, INT_H_SIZE);
2064                 skb_copy_to_linear_data_offse    1730                 skb_copy_to_linear_data_offset(tnlskb, INT_H_SIZE, hdr, pktlen);
2065                 __skb_queue_tail(&tnlq, tnlsk    1731                 __skb_queue_tail(&tnlq, tnlskb);
2066         }                                        1732         }
2067         if (queue != &l->backlogq) {             1733         if (queue != &l->backlogq) {
2068                 queue = &l->backlogq;            1734                 queue = &l->backlogq;
2069                 goto tnl;                        1735                 goto tnl;
2070         }                                        1736         }
2071                                                  1737 
2072         if (pktcnt_need_update)               << 
2073                 skb_queue_walk(&tnlq, skb) {  << 
2074                         hdr = buf_msg(skb);   << 
2075                         msg_set_msgcnt(hdr, p << 
2076                 }                             << 
2077                                               << 
2078         tipc_link_xmit(tnl, &tnlq, xmitq);       1738         tipc_link_xmit(tnl, &tnlq, xmitq);
2079                                                  1739 
2080         if (mtyp == FAILOVER_MSG) {              1740         if (mtyp == FAILOVER_MSG) {
2081                 tnl->drop_point = l->rcv_nxt;    1741                 tnl->drop_point = l->rcv_nxt;
2082                 tnl->failover_reasm_skb = l->    1742                 tnl->failover_reasm_skb = l->reasm_buf;
2083                 l->reasm_buf = NULL;             1743                 l->reasm_buf = NULL;
2084                                                  1744 
2085                 /* Failover the link's deferd    1745                 /* Failover the link's deferdq */
2086                 if (unlikely(!skb_queue_empty    1746                 if (unlikely(!skb_queue_empty(fdefq))) {
2087                         pr_warn("Link failove    1747                         pr_warn("Link failover deferdq not empty: %d!\n",
2088                                 skb_queue_len    1748                                 skb_queue_len(fdefq));
2089                         __skb_queue_purge(fde    1749                         __skb_queue_purge(fdefq);
2090                 }                                1750                 }
2091                 skb_queue_splice_init(&l->def    1751                 skb_queue_splice_init(&l->deferdq, fdefq);
2092         }                                        1752         }
2093 }                                                1753 }
2094                                                  1754 
2095 /**                                              1755 /**
2096  * tipc_link_failover_prepare() - prepare tnl    1756  * tipc_link_failover_prepare() - prepare tnl for link failover
2097  *                                               1757  *
2098  * This is a special version of the precursor    1758  * This is a special version of the precursor - tipc_link_tnl_prepare(),
2099  * see the tipc_node_link_failover() for deta    1759  * see the tipc_node_link_failover() for details
2100  *                                               1760  *
2101  * @l: failover link                             1761  * @l: failover link
2102  * @tnl: tunnel link                             1762  * @tnl: tunnel link
2103  * @xmitq: queue for messages to be xmited       1763  * @xmitq: queue for messages to be xmited
2104  */                                              1764  */
2105 void tipc_link_failover_prepare(struct tipc_l    1765 void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl,
2106                                 struct sk_buf    1766                                 struct sk_buff_head *xmitq)
2107 {                                                1767 {
2108         struct sk_buff_head *fdefq = &tnl->fa    1768         struct sk_buff_head *fdefq = &tnl->failover_deferdq;
2109                                                  1769 
2110         tipc_link_create_dummy_tnl_msg(tnl, x    1770         tipc_link_create_dummy_tnl_msg(tnl, xmitq);
2111                                                  1771 
2112         /* This failover link endpoint was ne !! 1772         /* This failover link enpoint was never established before,
2113          * so it has not received anything fr    1773          * so it has not received anything from peer.
2114          * Otherwise, it must be a normal fai    1774          * Otherwise, it must be a normal failover situation or the
2115          * node has entered SELF_DOWN_PEER_LE    1775          * node has entered SELF_DOWN_PEER_LEAVING and both peer nodes
2116          * would have to start over from scra    1776          * would have to start over from scratch instead.
2117          */                                      1777          */
2118         tnl->drop_point = 1;                     1778         tnl->drop_point = 1;
2119         tnl->failover_reasm_skb = NULL;          1779         tnl->failover_reasm_skb = NULL;
2120                                                  1780 
2121         /* Initiate the link's failover defer    1781         /* Initiate the link's failover deferdq */
2122         if (unlikely(!skb_queue_empty(fdefq))    1782         if (unlikely(!skb_queue_empty(fdefq))) {
2123                 pr_warn("Link failover deferd    1783                 pr_warn("Link failover deferdq not empty: %d!\n",
2124                         skb_queue_len(fdefq))    1784                         skb_queue_len(fdefq));
2125                 __skb_queue_purge(fdefq);        1785                 __skb_queue_purge(fdefq);
2126         }                                        1786         }
2127 }                                                1787 }
2128                                                  1788 
2129 /* tipc_link_validate_msg(): validate message    1789 /* tipc_link_validate_msg(): validate message against current link state
2130  * Returns true if message should be accepted    1790  * Returns true if message should be accepted, otherwise false
2131  */                                              1791  */
2132 bool tipc_link_validate_msg(struct tipc_link     1792 bool tipc_link_validate_msg(struct tipc_link *l, struct tipc_msg *hdr)
2133 {                                                1793 {
2134         u16 curr_session = l->peer_session;      1794         u16 curr_session = l->peer_session;
2135         u16 session = msg_session(hdr);          1795         u16 session = msg_session(hdr);
2136         int mtyp = msg_type(hdr);                1796         int mtyp = msg_type(hdr);
2137                                                  1797 
2138         if (msg_user(hdr) != LINK_PROTOCOL)      1798         if (msg_user(hdr) != LINK_PROTOCOL)
2139                 return true;                     1799                 return true;
2140                                                  1800 
2141         switch (mtyp) {                          1801         switch (mtyp) {
2142         case RESET_MSG:                          1802         case RESET_MSG:
2143                 if (!l->in_session)              1803                 if (!l->in_session)
2144                         return true;             1804                         return true;
2145                 /* Accept only RESET with new    1805                 /* Accept only RESET with new session number */
2146                 return more(session, curr_ses    1806                 return more(session, curr_session);
2147         case ACTIVATE_MSG:                       1807         case ACTIVATE_MSG:
2148                 if (!l->in_session)              1808                 if (!l->in_session)
2149                         return true;             1809                         return true;
2150                 /* Accept only ACTIVATE with     1810                 /* Accept only ACTIVATE with new or current session number */
2151                 return !less(session, curr_se    1811                 return !less(session, curr_session);
2152         case STATE_MSG:                          1812         case STATE_MSG:
2153                 /* Accept only STATE with cur    1813                 /* Accept only STATE with current session number */
2154                 if (!l->in_session)              1814                 if (!l->in_session)
2155                         return false;            1815                         return false;
2156                 if (session != curr_session)     1816                 if (session != curr_session)
2157                         return false;            1817                         return false;
2158                 /* Extra sanity check */         1818                 /* Extra sanity check */
2159                 if (!tipc_link_is_up(l) && ms !! 1819                 if (!link_is_up(l) && msg_ack(hdr))
2160                         return false;            1820                         return false;
2161                 if (!(l->peer_caps & TIPC_LIN    1821                 if (!(l->peer_caps & TIPC_LINK_PROTO_SEQNO))
2162                         return true;             1822                         return true;
2163                 /* Accept only STATE with new    1823                 /* Accept only STATE with new sequence number */
2164                 return !less(msg_seqno(hdr),     1824                 return !less(msg_seqno(hdr), l->rcv_nxt_state);
2165         default:                                 1825         default:
2166                 return false;                    1826                 return false;
2167         }                                        1827         }
2168 }                                                1828 }
2169                                                  1829 
2170 /* tipc_link_proto_rcv(): receive link level     1830 /* tipc_link_proto_rcv(): receive link level protocol message :
2171  * Note that network plane id propagates thro    1831  * Note that network plane id propagates through the network, and may
2172  * change at any time. The node with lowest n    1832  * change at any time. The node with lowest numerical id determines
2173  * network plane                                 1833  * network plane
2174  */                                              1834  */
2175 static int tipc_link_proto_rcv(struct tipc_li    1835 static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
2176                                struct sk_buff    1836                                struct sk_buff_head *xmitq)
2177 {                                                1837 {
2178         struct tipc_msg *hdr = buf_msg(skb);     1838         struct tipc_msg *hdr = buf_msg(skb);
2179         struct tipc_gap_ack_blks *ga = NULL;     1839         struct tipc_gap_ack_blks *ga = NULL;
2180         bool reply = msg_probe(hdr), retransm !! 1840         u16 rcvgap = 0;
2181         u32 dlen = msg_data_sz(hdr), glen = 0 !! 1841         u16 ack = msg_ack(hdr);
                                                   >> 1842         u16 gap = msg_seq_gap(hdr);
2182         u16 peers_snd_nxt =  msg_next_sent(hd    1843         u16 peers_snd_nxt =  msg_next_sent(hdr);
2183         u16 peers_tol = msg_link_tolerance(hd    1844         u16 peers_tol = msg_link_tolerance(hdr);
2184         u16 peers_prio = msg_linkprio(hdr);      1845         u16 peers_prio = msg_linkprio(hdr);
2185         u16 gap = msg_seq_gap(hdr);           << 
2186         u16 ack = msg_ack(hdr);               << 
2187         u16 rcv_nxt = l->rcv_nxt;                1846         u16 rcv_nxt = l->rcv_nxt;
2188         u16 rcvgap = 0;                       !! 1847         u16 dlen = msg_data_sz(hdr);
2189         int mtyp = msg_type(hdr);                1848         int mtyp = msg_type(hdr);
2190         int rc = 0, released;                 !! 1849         bool reply = msg_probe(hdr);
2191         char *if_name;                        !! 1850         u16 glen = 0;
2192         void *data;                              1851         void *data;
                                                   >> 1852         char *if_name;
                                                   >> 1853         int rc = 0;
2193                                                  1854 
2194         trace_tipc_proto_rcv(skb, false, l->n    1855         trace_tipc_proto_rcv(skb, false, l->name);
2195                                               << 
2196         if (dlen > U16_MAX)                   << 
2197                 goto exit;                    << 
2198                                               << 
2199         if (tipc_link_is_blocked(l) || !xmitq    1856         if (tipc_link_is_blocked(l) || !xmitq)
2200                 goto exit;                       1857                 goto exit;
2201                                                  1858 
2202         if (tipc_own_addr(l->net) > msg_prevn    1859         if (tipc_own_addr(l->net) > msg_prevnode(hdr))
2203                 l->net_plane = msg_net_plane(    1860                 l->net_plane = msg_net_plane(hdr);
2204                                                  1861 
2205         if (skb_linearize(skb))               !! 1862         skb_linearize(skb);
2206                 goto exit;                    << 
2207                                               << 
2208         hdr = buf_msg(skb);                      1863         hdr = buf_msg(skb);
2209         data = msg_data(hdr);                    1864         data = msg_data(hdr);
2210                                                  1865 
2211         if (!tipc_link_validate_msg(l, hdr))     1866         if (!tipc_link_validate_msg(l, hdr)) {
2212                 trace_tipc_skb_dump(skb, fals    1867                 trace_tipc_skb_dump(skb, false, "PROTO invalid (1)!");
2213                 trace_tipc_link_dump(l, TIPC_    1868                 trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (1)!");
2214                 goto exit;                       1869                 goto exit;
2215         }                                        1870         }
2216                                                  1871 
2217         switch (mtyp) {                          1872         switch (mtyp) {
2218         case RESET_MSG:                          1873         case RESET_MSG:
2219         case ACTIVATE_MSG:                       1874         case ACTIVATE_MSG:
2220                 msg_max = msg_max_pkt(hdr);   << 
2221                 if (msg_max < tipc_bearer_min << 
2222                         break;                << 
2223                 /* Complete own link name wit    1875                 /* Complete own link name with peer's interface name */
2224                 if_name =  strrchr(l->name, '    1876                 if_name =  strrchr(l->name, ':') + 1;
2225                 if (sizeof(l->name) - (if_nam    1877                 if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME)
2226                         break;                   1878                         break;
2227                 if (msg_data_sz(hdr) < TIPC_M    1879                 if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME)
2228                         break;                   1880                         break;
2229                 strncpy(if_name, data, TIPC_M    1881                 strncpy(if_name, data, TIPC_MAX_IF_NAME);
2230                                                  1882 
2231                 /* Update own tolerance if pe    1883                 /* Update own tolerance if peer indicates a non-zero value */
2232                 if (tipc_in_range(peers_tol,  !! 1884                 if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
2233                         l->tolerance = peers_    1885                         l->tolerance = peers_tol;
2234                         l->bc_rcvlink->tolera    1886                         l->bc_rcvlink->tolerance = peers_tol;
2235                 }                                1887                 }
2236                 /* Update own priority if pee    1888                 /* Update own priority if peer's priority is higher */
2237                 if (tipc_in_range(peers_prio, !! 1889                 if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI))
2238                         l->priority = peers_p    1890                         l->priority = peers_prio;
2239                                                  1891 
2240                 /* If peer is going down we w    1892                 /* If peer is going down we want full re-establish cycle */
2241                 if (msg_peer_stopping(hdr)) {    1893                 if (msg_peer_stopping(hdr)) {
2242                         rc = tipc_link_fsm_ev    1894                         rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
2243                         break;                   1895                         break;
2244                 }                                1896                 }
2245                                                  1897 
2246                 /* If this endpoint was re-cr    1898                 /* If this endpoint was re-created while peer was ESTABLISHING
2247                  * it doesn't know current se    1899                  * it doesn't know current session number. Force re-synch.
2248                  */                              1900                  */
2249                 if (mtyp == ACTIVATE_MSG && m    1901                 if (mtyp == ACTIVATE_MSG && msg_dest_session_valid(hdr) &&
2250                     l->session != msg_dest_se    1902                     l->session != msg_dest_session(hdr)) {
2251                         if (less(l->session,     1903                         if (less(l->session, msg_dest_session(hdr)))
2252                                 l->session =     1904                                 l->session = msg_dest_session(hdr) + 1;
2253                         break;                   1905                         break;
2254                 }                                1906                 }
2255                                                  1907 
2256                 /* ACTIVATE_MSG serves as PEE    1908                 /* ACTIVATE_MSG serves as PEER_RESET if link is already down */
2257                 if (mtyp == RESET_MSG || !tip !! 1909                 if (mtyp == RESET_MSG || !link_is_up(l))
2258                         rc = tipc_link_fsm_ev    1910                         rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
2259                                                  1911 
2260                 /* ACTIVATE_MSG takes up link    1912                 /* ACTIVATE_MSG takes up link if it was already locally reset */
2261                 if (mtyp == ACTIVATE_MSG && l    1913                 if (mtyp == ACTIVATE_MSG && l->state == LINK_ESTABLISHING)
2262                         rc = TIPC_LINK_UP_EVT    1914                         rc = TIPC_LINK_UP_EVT;
2263                                                  1915 
2264                 l->peer_session = msg_session    1916                 l->peer_session = msg_session(hdr);
2265                 l->in_session = true;            1917                 l->in_session = true;
2266                 l->peer_bearer_id = msg_beare    1918                 l->peer_bearer_id = msg_bearer_id(hdr);
2267                 if (l->mtu > msg_max)         !! 1919                 if (l->mtu > msg_max_pkt(hdr))
2268                         l->mtu = msg_max;     !! 1920                         l->mtu = msg_max_pkt(hdr);
2269                 break;                           1921                 break;
2270                                                  1922 
2271         case STATE_MSG:                          1923         case STATE_MSG:
2272                 /* Validate Gap ACK blocks, d << 
2273                 glen = tipc_get_gap_ack_blks( << 
2274                 if (glen > dlen)              << 
2275                         break;                << 
2276                                               << 
2277                 l->rcv_nxt_state = msg_seqno(    1924                 l->rcv_nxt_state = msg_seqno(hdr) + 1;
2278                                                  1925 
2279                 /* Update own tolerance if pe    1926                 /* Update own tolerance if peer indicates a non-zero value */
2280                 if (tipc_in_range(peers_tol,  !! 1927                 if (in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
2281                         l->tolerance = peers_    1928                         l->tolerance = peers_tol;
2282                         l->bc_rcvlink->tolera    1929                         l->bc_rcvlink->tolerance = peers_tol;
2283                 }                                1930                 }
2284                 /* Update own prio if peer in    1931                 /* Update own prio if peer indicates a different value */
2285                 if ((peers_prio != l->priorit    1932                 if ((peers_prio != l->priority) &&
2286                     tipc_in_range(peers_prio, !! 1933                     in_range(peers_prio, 1, TIPC_MAX_LINK_PRI)) {
2287                         l->priority = peers_p    1934                         l->priority = peers_prio;
2288                         rc = tipc_link_fsm_ev    1935                         rc = tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
2289                 }                                1936                 }
2290                                                  1937 
2291                 l->silent_intv_cnt = 0;          1938                 l->silent_intv_cnt = 0;
2292                 l->stats.recv_states++;          1939                 l->stats.recv_states++;
2293                 if (msg_probe(hdr))              1940                 if (msg_probe(hdr))
2294                         l->stats.recv_probes+    1941                         l->stats.recv_probes++;
2295                                                  1942 
2296                 if (!tipc_link_is_up(l)) {    !! 1943                 if (!link_is_up(l)) {
2297                         if (l->state == LINK_    1944                         if (l->state == LINK_ESTABLISHING)
2298                                 rc = TIPC_LIN    1945                                 rc = TIPC_LINK_UP_EVT;
2299                         break;                   1946                         break;
2300                 }                                1947                 }
2301                                                  1948 
                                                   >> 1949                 /* Receive Gap ACK blocks from peer if any */
                                                   >> 1950                 if (l->peer_caps & TIPC_GAP_ACK_BLOCK) {
                                                   >> 1951                         ga = (struct tipc_gap_ack_blks *)data;
                                                   >> 1952                         glen = ntohs(ga->len);
                                                   >> 1953                         /* sanity check: if failed, ignore Gap ACK blocks */
                                                   >> 1954                         if (glen != tipc_gap_ack_blks_sz(ga->gack_cnt))
                                                   >> 1955                                 ga = NULL;
                                                   >> 1956                 }
                                                   >> 1957 
2302                 tipc_mon_rcv(l->net, data + g    1958                 tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr,
2303                              &l->mon_state, l    1959                              &l->mon_state, l->bearer_id);
2304                                                  1960 
2305                 /* Send NACK if peer has sent    1961                 /* Send NACK if peer has sent pkts we haven't received yet */
2306                 if ((reply || msg_is_keepaliv !! 1962                 if (more(peers_snd_nxt, rcv_nxt) && !tipc_link_is_synching(l))
2307                     more(peers_snd_nxt, rcv_n << 
2308                     !tipc_link_is_synching(l) << 
2309                     skb_queue_empty(&l->defer << 
2310                         rcvgap = peers_snd_nx    1963                         rcvgap = peers_snd_nxt - l->rcv_nxt;
2311                 if (rcvgap || reply)             1964                 if (rcvgap || reply)
2312                         tipc_link_build_proto    1965                         tipc_link_build_proto_msg(l, STATE_MSG, 0, reply,
2313                                                  1966                                                   rcvgap, 0, 0, xmitq);
2314                                                  1967 
2315                 released = tipc_link_advance_ !! 1968                 rc |= tipc_link_advance_transmq(l, ack, gap, ga, xmitq);
2316                                               !! 1969 
                                                   >> 1970                 /* If NACK, retransmit will now start at right position */
2317                 if (gap)                         1971                 if (gap)
2318                         l->stats.recv_nacks++    1972                         l->stats.recv_nacks++;
2319                 if (released || retransmitted !! 1973 
2320                         tipc_link_update_cwin !! 1974                 tipc_link_advance_backlog(l, xmitq);
2321                 if (released)                 << 
2322                         tipc_link_advance_bac << 
2323                 if (unlikely(!skb_queue_empty    1975                 if (unlikely(!skb_queue_empty(&l->wakeupq)))
2324                         link_prepare_wakeup(l    1976                         link_prepare_wakeup(l);
2325         }                                        1977         }
2326 exit:                                            1978 exit:
2327         kfree_skb(skb);                          1979         kfree_skb(skb);
2328         return rc;                               1980         return rc;
2329 }                                                1981 }
2330                                                  1982 
2331 /* tipc_link_build_bc_proto_msg() - create br    1983 /* tipc_link_build_bc_proto_msg() - create broadcast protocol message
2332  */                                              1984  */
2333 static bool tipc_link_build_bc_proto_msg(stru    1985 static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
2334                                          u16     1986                                          u16 peers_snd_nxt,
2335                                          stru    1987                                          struct sk_buff_head *xmitq)
2336 {                                                1988 {
2337         struct sk_buff *skb;                     1989         struct sk_buff *skb;
2338         struct tipc_msg *hdr;                    1990         struct tipc_msg *hdr;
2339         struct sk_buff *dfrd_skb = skb_peek(&    1991         struct sk_buff *dfrd_skb = skb_peek(&l->deferdq);
2340         u16 ack = l->rcv_nxt - 1;                1992         u16 ack = l->rcv_nxt - 1;
2341         u16 gap_to = peers_snd_nxt - 1;          1993         u16 gap_to = peers_snd_nxt - 1;
2342                                                  1994 
2343         skb = tipc_msg_create(BCAST_PROTOCOL,    1995         skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE,
2344                               0, l->addr, tip    1996                               0, l->addr, tipc_own_addr(l->net), 0, 0, 0);
2345         if (!skb)                                1997         if (!skb)
2346                 return false;                    1998                 return false;
2347         hdr = buf_msg(skb);                      1999         hdr = buf_msg(skb);
2348         msg_set_last_bcast(hdr, l->bc_sndlink    2000         msg_set_last_bcast(hdr, l->bc_sndlink->snd_nxt - 1);
2349         msg_set_bcast_ack(hdr, ack);             2001         msg_set_bcast_ack(hdr, ack);
2350         msg_set_bcgap_after(hdr, ack);           2002         msg_set_bcgap_after(hdr, ack);
2351         if (dfrd_skb)                            2003         if (dfrd_skb)
2352                 gap_to = buf_seqno(dfrd_skb)     2004                 gap_to = buf_seqno(dfrd_skb) - 1;
2353         msg_set_bcgap_to(hdr, gap_to);           2005         msg_set_bcgap_to(hdr, gap_to);
2354         msg_set_non_seq(hdr, bcast);             2006         msg_set_non_seq(hdr, bcast);
2355         __skb_queue_tail(xmitq, skb);            2007         __skb_queue_tail(xmitq, skb);
2356         return true;                             2008         return true;
2357 }                                                2009 }
2358                                                  2010 
2359 /* tipc_link_build_bc_init_msg() - synchroniz    2011 /* tipc_link_build_bc_init_msg() - synchronize broadcast link endpoints.
2360  *                                               2012  *
2361  * Give a newly added peer node the sequence     2013  * Give a newly added peer node the sequence number where it should
2362  * start receiving and acking broadcast packe    2014  * start receiving and acking broadcast packets.
2363  */                                              2015  */
2364 static void tipc_link_build_bc_init_msg(struc    2016 static void tipc_link_build_bc_init_msg(struct tipc_link *l,
2365                                         struc    2017                                         struct sk_buff_head *xmitq)
2366 {                                                2018 {
2367         struct sk_buff_head list;                2019         struct sk_buff_head list;
2368                                                  2020 
2369         __skb_queue_head_init(&list);            2021         __skb_queue_head_init(&list);
2370         if (!tipc_link_build_bc_proto_msg(l->    2022         if (!tipc_link_build_bc_proto_msg(l->bc_rcvlink, false, 0, &list))
2371                 return;                          2023                 return;
2372         msg_set_bc_ack_invalid(buf_msg(skb_pe    2024         msg_set_bc_ack_invalid(buf_msg(skb_peek(&list)), true);
2373         tipc_link_xmit(l, &list, xmitq);         2025         tipc_link_xmit(l, &list, xmitq);
2374 }                                                2026 }
2375                                                  2027 
2376 /* tipc_link_bc_init_rcv - receive initial br    2028 /* tipc_link_bc_init_rcv - receive initial broadcast synch data from peer
2377  */                                              2029  */
2378 void tipc_link_bc_init_rcv(struct tipc_link *    2030 void tipc_link_bc_init_rcv(struct tipc_link *l, struct tipc_msg *hdr)
2379 {                                                2031 {
2380         int mtyp = msg_type(hdr);                2032         int mtyp = msg_type(hdr);
2381         u16 peers_snd_nxt = msg_bc_snd_nxt(hd    2033         u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
2382                                                  2034 
2383         if (tipc_link_is_up(l))               !! 2035         if (link_is_up(l))
2384                 return;                          2036                 return;
2385                                                  2037 
2386         if (msg_user(hdr) == BCAST_PROTOCOL)     2038         if (msg_user(hdr) == BCAST_PROTOCOL) {
2387                 l->rcv_nxt = peers_snd_nxt;      2039                 l->rcv_nxt = peers_snd_nxt;
2388                 l->state = LINK_ESTABLISHED;     2040                 l->state = LINK_ESTABLISHED;
2389                 return;                          2041                 return;
2390         }                                        2042         }
2391                                                  2043 
2392         if (l->peer_caps & TIPC_BCAST_SYNCH)     2044         if (l->peer_caps & TIPC_BCAST_SYNCH)
2393                 return;                          2045                 return;
2394                                                  2046 
2395         if (msg_peer_node_is_up(hdr))            2047         if (msg_peer_node_is_up(hdr))
2396                 return;                          2048                 return;
2397                                                  2049 
2398         /* Compatibility: accept older, less     2050         /* Compatibility: accept older, less safe initial synch data */
2399         if ((mtyp == RESET_MSG) || (mtyp == A    2051         if ((mtyp == RESET_MSG) || (mtyp == ACTIVATE_MSG))
2400                 l->rcv_nxt = peers_snd_nxt;      2052                 l->rcv_nxt = peers_snd_nxt;
2401 }                                                2053 }
2402                                                  2054 
2403 /* tipc_link_bc_sync_rcv - update rcv link ac    2055 /* tipc_link_bc_sync_rcv - update rcv link according to peer's send state
2404  */                                              2056  */
2405 int tipc_link_bc_sync_rcv(struct tipc_link *l    2057 int tipc_link_bc_sync_rcv(struct tipc_link *l, struct tipc_msg *hdr,
2406                           struct sk_buff_head    2058                           struct sk_buff_head *xmitq)
2407 {                                                2059 {
                                                   >> 2060         struct tipc_link *snd_l = l->bc_sndlink;
2408         u16 peers_snd_nxt = msg_bc_snd_nxt(hd    2061         u16 peers_snd_nxt = msg_bc_snd_nxt(hdr);
                                                   >> 2062         u16 from = msg_bcast_ack(hdr) + 1;
                                                   >> 2063         u16 to = from + msg_bc_gap(hdr) - 1;
2409         int rc = 0;                              2064         int rc = 0;
2410                                                  2065 
2411         if (!tipc_link_is_up(l))              !! 2066         if (!link_is_up(l))
2412                 return rc;                       2067                 return rc;
2413                                                  2068 
2414         if (!msg_peer_node_is_up(hdr))           2069         if (!msg_peer_node_is_up(hdr))
2415                 return rc;                       2070                 return rc;
2416                                                  2071 
2417         /* Open when peer acknowledges our bc !! 2072         /* Open when peer ackowledges our bcast init msg (pkt #1) */
2418         if (msg_ack(hdr))                        2073         if (msg_ack(hdr))
2419                 l->bc_peer_is_up = true;         2074                 l->bc_peer_is_up = true;
2420                                                  2075 
2421         if (!l->bc_peer_is_up)                   2076         if (!l->bc_peer_is_up)
2422                 return rc;                       2077                 return rc;
2423                                                  2078 
                                                   >> 2079         l->stats.recv_nacks++;
                                                   >> 2080 
2424         /* Ignore if peers_snd_nxt goes beyon    2081         /* Ignore if peers_snd_nxt goes beyond receive window */
2425         if (more(peers_snd_nxt, l->rcv_nxt +     2082         if (more(peers_snd_nxt, l->rcv_nxt + l->window))
2426                 return rc;                       2083                 return rc;
2427                                                  2084 
                                                   >> 2085         rc = tipc_link_bc_retrans(snd_l, l, from, to, xmitq);
                                                   >> 2086 
2428         l->snd_nxt = peers_snd_nxt;              2087         l->snd_nxt = peers_snd_nxt;
2429         if (link_bc_rcv_gap(l))                  2088         if (link_bc_rcv_gap(l))
2430                 rc |= TIPC_LINK_SND_STATE;       2089                 rc |= TIPC_LINK_SND_STATE;
2431                                                  2090 
2432         /* Return now if sender supports nack    2091         /* Return now if sender supports nack via STATE messages */
2433         if (l->peer_caps & TIPC_BCAST_STATE_N    2092         if (l->peer_caps & TIPC_BCAST_STATE_NACK)
2434                 return rc;                       2093                 return rc;
2435                                                  2094 
2436         /* Otherwise, be backwards compatible    2095         /* Otherwise, be backwards compatible */
2437                                                  2096 
2438         if (!more(peers_snd_nxt, l->rcv_nxt))    2097         if (!more(peers_snd_nxt, l->rcv_nxt)) {
2439                 l->nack_state = BC_NACK_SND_C    2098                 l->nack_state = BC_NACK_SND_CONDITIONAL;
2440                 return 0;                        2099                 return 0;
2441         }                                        2100         }
2442                                                  2101 
2443         /* Don't NACK if one was recently sen    2102         /* Don't NACK if one was recently sent or peeked */
2444         if (l->nack_state == BC_NACK_SND_SUPP    2103         if (l->nack_state == BC_NACK_SND_SUPPRESS) {
2445                 l->nack_state = BC_NACK_SND_U    2104                 l->nack_state = BC_NACK_SND_UNCONDITIONAL;
2446                 return 0;                        2105                 return 0;
2447         }                                        2106         }
2448                                                  2107 
2449         /* Conditionally delay NACK sending u    2108         /* Conditionally delay NACK sending until next synch rcv */
2450         if (l->nack_state == BC_NACK_SND_COND    2109         if (l->nack_state == BC_NACK_SND_CONDITIONAL) {
2451                 l->nack_state = BC_NACK_SND_U    2110                 l->nack_state = BC_NACK_SND_UNCONDITIONAL;
2452                 if ((peers_snd_nxt - l->rcv_n    2111                 if ((peers_snd_nxt - l->rcv_nxt) < TIPC_MIN_LINK_WIN)
2453                         return 0;                2112                         return 0;
2454         }                                        2113         }
2455                                                  2114 
2456         /* Send NACK now but suppress next on    2115         /* Send NACK now but suppress next one */
2457         tipc_link_build_bc_proto_msg(l, true,    2116         tipc_link_build_bc_proto_msg(l, true, peers_snd_nxt, xmitq);
2458         l->nack_state = BC_NACK_SND_SUPPRESS;    2117         l->nack_state = BC_NACK_SND_SUPPRESS;
2459         return 0;                                2118         return 0;
2460 }                                                2119 }
2461                                                  2120 
2462 int tipc_link_bc_ack_rcv(struct tipc_link *r, !! 2121 void tipc_link_bc_ack_rcv(struct tipc_link *l, u16 acked,
2463                          struct tipc_gap_ack_ !! 2122                           struct sk_buff_head *xmitq)
2464                          struct sk_buff_head  << 
2465                          struct sk_buff_head  << 
2466 {                                                2123 {
2467         struct tipc_link *l = r->bc_sndlink;  !! 2124         struct sk_buff *skb, *tmp;
2468         bool unused = false;                  !! 2125         struct tipc_link *snd_l = l->bc_sndlink;
2469         int rc = 0;                           << 
2470                                               << 
2471         if (!tipc_link_is_up(r) || !r->bc_pee << 
2472                 return 0;                     << 
2473                                               << 
2474         if (gap) {                            << 
2475                 l->stats.recv_nacks++;        << 
2476                 r->stats.recv_nacks++;        << 
2477         }                                     << 
2478                                                  2126 
2479         if (less(acked, r->acked) || (acked = !! 2127         if (!link_is_up(l) || !l->bc_peer_is_up)
2480                 return 0;                     !! 2128                 return;
2481                                                  2129 
2482         trace_tipc_link_bc_ack(r, acked, gap, !! 2130         if (!more(acked, l->acked))
2483         tipc_link_advance_transmq(l, r, acked !! 2131                 return;
2484                                                  2132 
2485         tipc_link_advance_backlog(l, xmitq);  !! 2133         trace_tipc_link_bc_ack(l, l->acked, acked, &snd_l->transmq);
2486         if (unlikely(!skb_queue_empty(&l->wak !! 2134         /* Skip over packets peer has already acked */
2487                 link_prepare_wakeup(l);       !! 2135         skb_queue_walk(&snd_l->transmq, skb) {
                                                   >> 2136                 if (more(buf_seqno(skb), l->acked))
                                                   >> 2137                         break;
                                                   >> 2138         }
2488                                                  2139 
2489         return rc;                            !! 2140         /* Update/release the packets peer is acking now */
                                                   >> 2141         skb_queue_walk_from_safe(&snd_l->transmq, skb, tmp) {
                                                   >> 2142                 if (more(buf_seqno(skb), acked))
                                                   >> 2143                         break;
                                                   >> 2144                 if (!--TIPC_SKB_CB(skb)->ackers) {
                                                   >> 2145                         __skb_unlink(skb, &snd_l->transmq);
                                                   >> 2146                         kfree_skb(skb);
                                                   >> 2147                 }
                                                   >> 2148         }
                                                   >> 2149         l->acked = acked;
                                                   >> 2150         tipc_link_advance_backlog(snd_l, xmitq);
                                                   >> 2151         if (unlikely(!skb_queue_empty(&snd_l->wakeupq)))
                                                   >> 2152                 link_prepare_wakeup(snd_l);
2490 }                                                2153 }
2491                                                  2154 
2492 /* tipc_link_bc_nack_rcv(): receive broadcast    2155 /* tipc_link_bc_nack_rcv(): receive broadcast nack message
2493  * This function is here for backwards compat    2156  * This function is here for backwards compatibility, since
2494  * no BCAST_PROTOCOL/STATE messages occur fro    2157  * no BCAST_PROTOCOL/STATE messages occur from TIPC v2.5.
2495  */                                              2158  */
2496 int tipc_link_bc_nack_rcv(struct tipc_link *l    2159 int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
2497                           struct sk_buff_head    2160                           struct sk_buff_head *xmitq)
2498 {                                                2161 {
2499         struct tipc_msg *hdr = buf_msg(skb);     2162         struct tipc_msg *hdr = buf_msg(skb);
2500         u32 dnode = msg_destnode(hdr);           2163         u32 dnode = msg_destnode(hdr);
2501         int mtyp = msg_type(hdr);                2164         int mtyp = msg_type(hdr);
2502         u16 acked = msg_bcast_ack(hdr);          2165         u16 acked = msg_bcast_ack(hdr);
2503         u16 from = acked + 1;                    2166         u16 from = acked + 1;
2504         u16 to = msg_bcgap_to(hdr);              2167         u16 to = msg_bcgap_to(hdr);
2505         u16 peers_snd_nxt = to + 1;              2168         u16 peers_snd_nxt = to + 1;
2506         int rc = 0;                              2169         int rc = 0;
2507                                                  2170 
2508         kfree_skb(skb);                          2171         kfree_skb(skb);
2509                                                  2172 
2510         if (!tipc_link_is_up(l) || !l->bc_pee    2173         if (!tipc_link_is_up(l) || !l->bc_peer_is_up)
2511                 return 0;                        2174                 return 0;
2512                                                  2175 
2513         if (mtyp != STATE_MSG)                   2176         if (mtyp != STATE_MSG)
2514                 return 0;                        2177                 return 0;
2515                                                  2178 
2516         if (dnode == tipc_own_addr(l->net)) {    2179         if (dnode == tipc_own_addr(l->net)) {
2517                 rc = tipc_link_bc_ack_rcv(l,  !! 2180                 tipc_link_bc_ack_rcv(l, acked, xmitq);
2518                                           xmi !! 2181                 rc = tipc_link_bc_retrans(l->bc_sndlink, l, from, to, xmitq);
2519                 l->stats.recv_nacks++;           2182                 l->stats.recv_nacks++;
2520                 return rc;                       2183                 return rc;
2521         }                                        2184         }
2522                                                  2185 
2523         /* Msg for other node => suppress own    2186         /* Msg for other node => suppress own NACK at next sync if applicable */
2524         if (more(peers_snd_nxt, l->rcv_nxt) &    2187         if (more(peers_snd_nxt, l->rcv_nxt) && !less(l->rcv_nxt, from))
2525                 l->nack_state = BC_NACK_SND_S    2188                 l->nack_state = BC_NACK_SND_SUPPRESS;
2526                                                  2189 
2527         return 0;                                2190         return 0;
2528 }                                                2191 }
2529                                                  2192 
2530 void tipc_link_set_queue_limits(struct tipc_l !! 2193 void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
2531 {                                                2194 {
2532         int max_bulk = TIPC_MAX_PUBL / (l->mt    2195         int max_bulk = TIPC_MAX_PUBL / (l->mtu / ITEM_SIZE);
2533                                                  2196 
2534         l->min_win = min_win;                 !! 2197         l->window = win;
2535         l->ssthresh = max_win;                !! 2198         l->backlog[TIPC_LOW_IMPORTANCE].limit      = max_t(u16, 50, win);
2536         l->max_win = max_win;                 !! 2199         l->backlog[TIPC_MEDIUM_IMPORTANCE].limit   = max_t(u16, 100, win * 2);
2537         l->window = min_win;                  !! 2200         l->backlog[TIPC_HIGH_IMPORTANCE].limit     = max_t(u16, 150, win * 3);
2538         l->backlog[TIPC_LOW_IMPORTANCE].limit !! 2201         l->backlog[TIPC_CRITICAL_IMPORTANCE].limit = max_t(u16, 200, win * 4);
2539         l->backlog[TIPC_MEDIUM_IMPORTANCE].li << 
2540         l->backlog[TIPC_HIGH_IMPORTANCE].limi << 
2541         l->backlog[TIPC_CRITICAL_IMPORTANCE]. << 
2542         l->backlog[TIPC_SYSTEM_IMPORTANCE].li    2202         l->backlog[TIPC_SYSTEM_IMPORTANCE].limit   = max_bulk;
2543 }                                                2203 }
2544                                                  2204 
2545 /**                                              2205 /**
2546  * tipc_link_reset_stats - reset link statist !! 2206  * link_reset_stats - reset link statistics
2547  * @l: pointer to link                           2207  * @l: pointer to link
2548  */                                              2208  */
2549 void tipc_link_reset_stats(struct tipc_link *    2209 void tipc_link_reset_stats(struct tipc_link *l)
2550 {                                                2210 {
2551         memset(&l->stats, 0, sizeof(l->stats)    2211         memset(&l->stats, 0, sizeof(l->stats));
2552 }                                                2212 }
2553                                                  2213 
2554 static void link_print(struct tipc_link *l, c    2214 static void link_print(struct tipc_link *l, const char *str)
2555 {                                                2215 {
2556         struct sk_buff *hskb = skb_peek(&l->t    2216         struct sk_buff *hskb = skb_peek(&l->transmq);
2557         u16 head = hskb ? msg_seqno(buf_msg(h    2217         u16 head = hskb ? msg_seqno(buf_msg(hskb)) : l->snd_nxt - 1;
2558         u16 tail = l->snd_nxt - 1;               2218         u16 tail = l->snd_nxt - 1;
2559                                                  2219 
2560         pr_info("%s Link <%s> state %x\n", st    2220         pr_info("%s Link <%s> state %x\n", str, l->name, l->state);
2561         pr_info("XMTQ: %u [%u-%u], BKLGQ: %u,    2221         pr_info("XMTQ: %u [%u-%u], BKLGQ: %u, SNDNX: %u, RCVNX: %u\n",
2562                 skb_queue_len(&l->transmq), h    2222                 skb_queue_len(&l->transmq), head, tail,
2563                 skb_queue_len(&l->backlogq),     2223                 skb_queue_len(&l->backlogq), l->snd_nxt, l->rcv_nxt);
2564 }                                                2224 }
2565                                                  2225 
2566 /* Parse and validate nested (link) propertie    2226 /* Parse and validate nested (link) properties valid for media, bearer and link
2567  */                                              2227  */
2568 int tipc_nl_parse_link_prop(struct nlattr *pr    2228 int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
2569 {                                                2229 {
2570         int err;                                 2230         int err;
2571                                                  2231 
2572         err = nla_parse_nested_deprecated(pro    2232         err = nla_parse_nested_deprecated(props, TIPC_NLA_PROP_MAX, prop,
2573                                           tip    2233                                           tipc_nl_prop_policy, NULL);
2574         if (err)                                 2234         if (err)
2575                 return err;                      2235                 return err;
2576                                                  2236 
2577         if (props[TIPC_NLA_PROP_PRIO]) {         2237         if (props[TIPC_NLA_PROP_PRIO]) {
2578                 u32 prio;                        2238                 u32 prio;
2579                                                  2239 
2580                 prio = nla_get_u32(props[TIPC    2240                 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
2581                 if (prio > TIPC_MAX_LINK_PRI)    2241                 if (prio > TIPC_MAX_LINK_PRI)
2582                         return -EINVAL;          2242                         return -EINVAL;
2583         }                                        2243         }
2584                                                  2244 
2585         if (props[TIPC_NLA_PROP_TOL]) {          2245         if (props[TIPC_NLA_PROP_TOL]) {
2586                 u32 tol;                         2246                 u32 tol;
2587                                                  2247 
2588                 tol = nla_get_u32(props[TIPC_    2248                 tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
2589                 if ((tol < TIPC_MIN_LINK_TOL)    2249                 if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL))
2590                         return -EINVAL;          2250                         return -EINVAL;
2591         }                                        2251         }
2592                                                  2252 
2593         if (props[TIPC_NLA_PROP_WIN]) {          2253         if (props[TIPC_NLA_PROP_WIN]) {
2594                 u32 max_win;                  !! 2254                 u32 win;
2595                                                  2255 
2596                 max_win = nla_get_u32(props[T !! 2256                 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2597                 if (max_win < TIPC_DEF_LINK_W !! 2257                 if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN))
2598                         return -EINVAL;          2258                         return -EINVAL;
2599         }                                        2259         }
2600                                                  2260 
2601         return 0;                                2261         return 0;
2602 }                                                2262 }
2603                                                  2263 
2604 static int __tipc_nl_add_stats(struct sk_buff    2264 static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
2605 {                                                2265 {
2606         int i;                                   2266         int i;
2607         struct nlattr *stats;                    2267         struct nlattr *stats;
2608                                                  2268 
2609         struct nla_map {                         2269         struct nla_map {
2610                 u32 key;                         2270                 u32 key;
2611                 u32 val;                         2271                 u32 val;
2612         };                                       2272         };
2613                                                  2273 
2614         struct nla_map map[] = {                 2274         struct nla_map map[] = {
2615                 {TIPC_NLA_STATS_RX_INFO, 0},     2275                 {TIPC_NLA_STATS_RX_INFO, 0},
2616                 {TIPC_NLA_STATS_RX_FRAGMENTS,    2276                 {TIPC_NLA_STATS_RX_FRAGMENTS, s->recv_fragments},
2617                 {TIPC_NLA_STATS_RX_FRAGMENTED    2277                 {TIPC_NLA_STATS_RX_FRAGMENTED, s->recv_fragmented},
2618                 {TIPC_NLA_STATS_RX_BUNDLES, s    2278                 {TIPC_NLA_STATS_RX_BUNDLES, s->recv_bundles},
2619                 {TIPC_NLA_STATS_RX_BUNDLED, s    2279                 {TIPC_NLA_STATS_RX_BUNDLED, s->recv_bundled},
2620                 {TIPC_NLA_STATS_TX_INFO, 0},     2280                 {TIPC_NLA_STATS_TX_INFO, 0},
2621                 {TIPC_NLA_STATS_TX_FRAGMENTS,    2281                 {TIPC_NLA_STATS_TX_FRAGMENTS, s->sent_fragments},
2622                 {TIPC_NLA_STATS_TX_FRAGMENTED    2282                 {TIPC_NLA_STATS_TX_FRAGMENTED, s->sent_fragmented},
2623                 {TIPC_NLA_STATS_TX_BUNDLES, s    2283                 {TIPC_NLA_STATS_TX_BUNDLES, s->sent_bundles},
2624                 {TIPC_NLA_STATS_TX_BUNDLED, s    2284                 {TIPC_NLA_STATS_TX_BUNDLED, s->sent_bundled},
2625                 {TIPC_NLA_STATS_MSG_PROF_TOT,    2285                 {TIPC_NLA_STATS_MSG_PROF_TOT, (s->msg_length_counts) ?
2626                         s->msg_length_counts     2286                         s->msg_length_counts : 1},
2627                 {TIPC_NLA_STATS_MSG_LEN_CNT,     2287                 {TIPC_NLA_STATS_MSG_LEN_CNT, s->msg_length_counts},
2628                 {TIPC_NLA_STATS_MSG_LEN_TOT,     2288                 {TIPC_NLA_STATS_MSG_LEN_TOT, s->msg_lengths_total},
2629                 {TIPC_NLA_STATS_MSG_LEN_P0, s    2289                 {TIPC_NLA_STATS_MSG_LEN_P0, s->msg_length_profile[0]},
2630                 {TIPC_NLA_STATS_MSG_LEN_P1, s    2290                 {TIPC_NLA_STATS_MSG_LEN_P1, s->msg_length_profile[1]},
2631                 {TIPC_NLA_STATS_MSG_LEN_P2, s    2291                 {TIPC_NLA_STATS_MSG_LEN_P2, s->msg_length_profile[2]},
2632                 {TIPC_NLA_STATS_MSG_LEN_P3, s    2292                 {TIPC_NLA_STATS_MSG_LEN_P3, s->msg_length_profile[3]},
2633                 {TIPC_NLA_STATS_MSG_LEN_P4, s    2293                 {TIPC_NLA_STATS_MSG_LEN_P4, s->msg_length_profile[4]},
2634                 {TIPC_NLA_STATS_MSG_LEN_P5, s    2294                 {TIPC_NLA_STATS_MSG_LEN_P5, s->msg_length_profile[5]},
2635                 {TIPC_NLA_STATS_MSG_LEN_P6, s    2295                 {TIPC_NLA_STATS_MSG_LEN_P6, s->msg_length_profile[6]},
2636                 {TIPC_NLA_STATS_RX_STATES, s-    2296                 {TIPC_NLA_STATS_RX_STATES, s->recv_states},
2637                 {TIPC_NLA_STATS_RX_PROBES, s-    2297                 {TIPC_NLA_STATS_RX_PROBES, s->recv_probes},
2638                 {TIPC_NLA_STATS_RX_NACKS, s->    2298                 {TIPC_NLA_STATS_RX_NACKS, s->recv_nacks},
2639                 {TIPC_NLA_STATS_RX_DEFERRED,     2299                 {TIPC_NLA_STATS_RX_DEFERRED, s->deferred_recv},
2640                 {TIPC_NLA_STATS_TX_STATES, s-    2300                 {TIPC_NLA_STATS_TX_STATES, s->sent_states},
2641                 {TIPC_NLA_STATS_TX_PROBES, s-    2301                 {TIPC_NLA_STATS_TX_PROBES, s->sent_probes},
2642                 {TIPC_NLA_STATS_TX_NACKS, s->    2302                 {TIPC_NLA_STATS_TX_NACKS, s->sent_nacks},
2643                 {TIPC_NLA_STATS_TX_ACKS, s->s    2303                 {TIPC_NLA_STATS_TX_ACKS, s->sent_acks},
2644                 {TIPC_NLA_STATS_RETRANSMITTED    2304                 {TIPC_NLA_STATS_RETRANSMITTED, s->retransmitted},
2645                 {TIPC_NLA_STATS_DUPLICATES, s    2305                 {TIPC_NLA_STATS_DUPLICATES, s->duplicates},
2646                 {TIPC_NLA_STATS_LINK_CONGS, s    2306                 {TIPC_NLA_STATS_LINK_CONGS, s->link_congs},
2647                 {TIPC_NLA_STATS_MAX_QUEUE, s-    2307                 {TIPC_NLA_STATS_MAX_QUEUE, s->max_queue_sz},
2648                 {TIPC_NLA_STATS_AVG_QUEUE, s-    2308                 {TIPC_NLA_STATS_AVG_QUEUE, s->queue_sz_counts ?
2649                         (s->accu_queue_sz / s    2309                         (s->accu_queue_sz / s->queue_sz_counts) : 0}
2650         };                                       2310         };
2651                                                  2311 
2652         stats = nla_nest_start_noflag(skb, TI    2312         stats = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
2653         if (!stats)                              2313         if (!stats)
2654                 return -EMSGSIZE;                2314                 return -EMSGSIZE;
2655                                                  2315 
2656         for (i = 0; i <  ARRAY_SIZE(map); i++    2316         for (i = 0; i <  ARRAY_SIZE(map); i++)
2657                 if (nla_put_u32(skb, map[i].k    2317                 if (nla_put_u32(skb, map[i].key, map[i].val))
2658                         goto msg_full;           2318                         goto msg_full;
2659                                                  2319 
2660         nla_nest_end(skb, stats);                2320         nla_nest_end(skb, stats);
2661                                                  2321 
2662         return 0;                                2322         return 0;
2663 msg_full:                                        2323 msg_full:
2664         nla_nest_cancel(skb, stats);             2324         nla_nest_cancel(skb, stats);
2665                                                  2325 
2666         return -EMSGSIZE;                        2326         return -EMSGSIZE;
2667 }                                                2327 }
2668                                                  2328 
2669 /* Caller should hold appropriate locks to pr    2329 /* Caller should hold appropriate locks to protect the link */
2670 int __tipc_nl_add_link(struct net *net, struc    2330 int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2671                        struct tipc_link *link    2331                        struct tipc_link *link, int nlflags)
2672 {                                                2332 {
2673         u32 self = tipc_own_addr(net);           2333         u32 self = tipc_own_addr(net);
2674         struct nlattr *attrs;                    2334         struct nlattr *attrs;
2675         struct nlattr *prop;                     2335         struct nlattr *prop;
2676         void *hdr;                               2336         void *hdr;
2677         int err;                                 2337         int err;
2678                                                  2338 
2679         hdr = genlmsg_put(msg->skb, msg->port    2339         hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
2680                           nlflags, TIPC_NL_LI    2340                           nlflags, TIPC_NL_LINK_GET);
2681         if (!hdr)                                2341         if (!hdr)
2682                 return -EMSGSIZE;                2342                 return -EMSGSIZE;
2683                                                  2343 
2684         attrs = nla_nest_start_noflag(msg->sk    2344         attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
2685         if (!attrs)                              2345         if (!attrs)
2686                 goto msg_full;                   2346                 goto msg_full;
2687                                                  2347 
2688         if (nla_put_string(msg->skb, TIPC_NLA    2348         if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
2689                 goto attr_msg_full;              2349                 goto attr_msg_full;
2690         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2350         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
2691                 goto attr_msg_full;              2351                 goto attr_msg_full;
2692         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2352         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
2693                 goto attr_msg_full;              2353                 goto attr_msg_full;
2694         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2354         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, link->stats.recv_pkts))
2695                 goto attr_msg_full;              2355                 goto attr_msg_full;
2696         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2356         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, link->stats.sent_pkts))
2697                 goto attr_msg_full;              2357                 goto attr_msg_full;
2698                                                  2358 
2699         if (tipc_link_is_up(link))               2359         if (tipc_link_is_up(link))
2700                 if (nla_put_flag(msg->skb, TI    2360                 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
2701                         goto attr_msg_full;      2361                         goto attr_msg_full;
2702         if (link->active)                        2362         if (link->active)
2703                 if (nla_put_flag(msg->skb, TI    2363                 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
2704                         goto attr_msg_full;      2364                         goto attr_msg_full;
2705                                                  2365 
2706         prop = nla_nest_start_noflag(msg->skb    2366         prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
2707         if (!prop)                               2367         if (!prop)
2708                 goto attr_msg_full;              2368                 goto attr_msg_full;
2709         if (nla_put_u32(msg->skb, TIPC_NLA_PR    2369         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
2710                 goto prop_msg_full;              2370                 goto prop_msg_full;
2711         if (nla_put_u32(msg->skb, TIPC_NLA_PR    2371         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, link->tolerance))
2712                 goto prop_msg_full;              2372                 goto prop_msg_full;
2713         if (nla_put_u32(msg->skb, TIPC_NLA_PR    2373         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN,
2714                         link->window))           2374                         link->window))
2715                 goto prop_msg_full;              2375                 goto prop_msg_full;
2716         if (nla_put_u32(msg->skb, TIPC_NLA_PR    2376         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
2717                 goto prop_msg_full;              2377                 goto prop_msg_full;
2718         nla_nest_end(msg->skb, prop);            2378         nla_nest_end(msg->skb, prop);
2719                                                  2379 
2720         err = __tipc_nl_add_stats(msg->skb, &    2380         err = __tipc_nl_add_stats(msg->skb, &link->stats);
2721         if (err)                                 2381         if (err)
2722                 goto attr_msg_full;              2382                 goto attr_msg_full;
2723                                                  2383 
2724         nla_nest_end(msg->skb, attrs);           2384         nla_nest_end(msg->skb, attrs);
2725         genlmsg_end(msg->skb, hdr);              2385         genlmsg_end(msg->skb, hdr);
2726                                                  2386 
2727         return 0;                                2387         return 0;
2728                                                  2388 
2729 prop_msg_full:                                   2389 prop_msg_full:
2730         nla_nest_cancel(msg->skb, prop);         2390         nla_nest_cancel(msg->skb, prop);
2731 attr_msg_full:                                   2391 attr_msg_full:
2732         nla_nest_cancel(msg->skb, attrs);        2392         nla_nest_cancel(msg->skb, attrs);
2733 msg_full:                                        2393 msg_full:
2734         genlmsg_cancel(msg->skb, hdr);           2394         genlmsg_cancel(msg->skb, hdr);
2735                                                  2395 
2736         return -EMSGSIZE;                        2396         return -EMSGSIZE;
2737 }                                                2397 }
2738                                                  2398 
2739 static int __tipc_nl_add_bc_link_stat(struct     2399 static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
2740                                       struct     2400                                       struct tipc_stats *stats)
2741 {                                                2401 {
2742         int i;                                   2402         int i;
2743         struct nlattr *nest;                     2403         struct nlattr *nest;
2744                                                  2404 
2745         struct nla_map {                         2405         struct nla_map {
2746                 __u32 key;                       2406                 __u32 key;
2747                 __u32 val;                       2407                 __u32 val;
2748         };                                       2408         };
2749                                                  2409 
2750         struct nla_map map[] = {                 2410         struct nla_map map[] = {
2751                 {TIPC_NLA_STATS_RX_INFO, stat    2411                 {TIPC_NLA_STATS_RX_INFO, stats->recv_pkts},
2752                 {TIPC_NLA_STATS_RX_FRAGMENTS,    2412                 {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
2753                 {TIPC_NLA_STATS_RX_FRAGMENTED    2413                 {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
2754                 {TIPC_NLA_STATS_RX_BUNDLES, s    2414                 {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
2755                 {TIPC_NLA_STATS_RX_BUNDLED, s    2415                 {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
2756                 {TIPC_NLA_STATS_TX_INFO, stat    2416                 {TIPC_NLA_STATS_TX_INFO, stats->sent_pkts},
2757                 {TIPC_NLA_STATS_TX_FRAGMENTS,    2417                 {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
2758                 {TIPC_NLA_STATS_TX_FRAGMENTED    2418                 {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
2759                 {TIPC_NLA_STATS_TX_BUNDLES, s    2419                 {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
2760                 {TIPC_NLA_STATS_TX_BUNDLED, s    2420                 {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
2761                 {TIPC_NLA_STATS_RX_NACKS, sta    2421                 {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
2762                 {TIPC_NLA_STATS_RX_DEFERRED,     2422                 {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
2763                 {TIPC_NLA_STATS_TX_NACKS, sta    2423                 {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
2764                 {TIPC_NLA_STATS_TX_ACKS, stat    2424                 {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
2765                 {TIPC_NLA_STATS_RETRANSMITTED    2425                 {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
2766                 {TIPC_NLA_STATS_DUPLICATES, s    2426                 {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
2767                 {TIPC_NLA_STATS_LINK_CONGS, s    2427                 {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
2768                 {TIPC_NLA_STATS_MAX_QUEUE, st    2428                 {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
2769                 {TIPC_NLA_STATS_AVG_QUEUE, st    2429                 {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
2770                         (stats->accu_queue_sz    2430                         (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
2771         };                                       2431         };
2772                                                  2432 
2773         nest = nla_nest_start_noflag(skb, TIP    2433         nest = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
2774         if (!nest)                               2434         if (!nest)
2775                 return -EMSGSIZE;                2435                 return -EMSGSIZE;
2776                                                  2436 
2777         for (i = 0; i <  ARRAY_SIZE(map); i++    2437         for (i = 0; i <  ARRAY_SIZE(map); i++)
2778                 if (nla_put_u32(skb, map[i].k    2438                 if (nla_put_u32(skb, map[i].key, map[i].val))
2779                         goto msg_full;           2439                         goto msg_full;
2780                                                  2440 
2781         nla_nest_end(skb, nest);                 2441         nla_nest_end(skb, nest);
2782                                                  2442 
2783         return 0;                                2443         return 0;
2784 msg_full:                                        2444 msg_full:
2785         nla_nest_cancel(skb, nest);              2445         nla_nest_cancel(skb, nest);
2786                                                  2446 
2787         return -EMSGSIZE;                        2447         return -EMSGSIZE;
2788 }                                                2448 }
2789                                                  2449 
2790 int tipc_nl_add_bc_link(struct net *net, stru !! 2450 int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
2791                         struct tipc_link *bcl << 
2792 {                                                2451 {
2793         int err;                                 2452         int err;
2794         void *hdr;                               2453         void *hdr;
2795         struct nlattr *attrs;                    2454         struct nlattr *attrs;
2796         struct nlattr *prop;                     2455         struct nlattr *prop;
2797         u32 bc_mode = tipc_bcast_get_mode(net !! 2456         struct tipc_net *tn = net_generic(net, tipc_net_id);
                                                   >> 2457         u32 bc_mode = tipc_bcast_get_broadcast_mode(net);
2798         u32 bc_ratio = tipc_bcast_get_broadca    2458         u32 bc_ratio = tipc_bcast_get_broadcast_ratio(net);
                                                   >> 2459         struct tipc_link *bcl = tn->bcl;
2799                                                  2460 
2800         if (!bcl)                                2461         if (!bcl)
2801                 return 0;                        2462                 return 0;
2802                                                  2463 
2803         tipc_bcast_lock(net);                    2464         tipc_bcast_lock(net);
2804                                                  2465 
2805         hdr = genlmsg_put(msg->skb, msg->port    2466         hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
2806                           NLM_F_MULTI, TIPC_N    2467                           NLM_F_MULTI, TIPC_NL_LINK_GET);
2807         if (!hdr) {                              2468         if (!hdr) {
2808                 tipc_bcast_unlock(net);          2469                 tipc_bcast_unlock(net);
2809                 return -EMSGSIZE;                2470                 return -EMSGSIZE;
2810         }                                        2471         }
2811                                                  2472 
2812         attrs = nla_nest_start_noflag(msg->sk    2473         attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
2813         if (!attrs)                              2474         if (!attrs)
2814                 goto msg_full;                   2475                 goto msg_full;
2815                                                  2476 
2816         /* The broadcast link is always up */    2477         /* The broadcast link is always up */
2817         if (nla_put_flag(msg->skb, TIPC_NLA_L    2478         if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
2818                 goto attr_msg_full;              2479                 goto attr_msg_full;
2819                                                  2480 
2820         if (nla_put_flag(msg->skb, TIPC_NLA_L    2481         if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
2821                 goto attr_msg_full;              2482                 goto attr_msg_full;
2822         if (nla_put_string(msg->skb, TIPC_NLA    2483         if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
2823                 goto attr_msg_full;              2484                 goto attr_msg_full;
2824         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2485         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, 0))
2825                 goto attr_msg_full;              2486                 goto attr_msg_full;
2826         if (nla_put_u32(msg->skb, TIPC_NLA_LI    2487         if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0))
2827                 goto attr_msg_full;              2488                 goto attr_msg_full;
2828                                                  2489 
2829         prop = nla_nest_start_noflag(msg->skb    2490         prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
2830         if (!prop)                               2491         if (!prop)
2831                 goto attr_msg_full;              2492                 goto attr_msg_full;
2832         if (nla_put_u32(msg->skb, TIPC_NLA_PR !! 2493         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window))
2833                 goto prop_msg_full;              2494                 goto prop_msg_full;
2834         if (nla_put_u32(msg->skb, TIPC_NLA_PR    2495         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST, bc_mode))
2835                 goto prop_msg_full;              2496                 goto prop_msg_full;
2836         if (bc_mode & BCLINK_MODE_SEL)           2497         if (bc_mode & BCLINK_MODE_SEL)
2837                 if (nla_put_u32(msg->skb, TIP    2498                 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST_RATIO,
2838                                 bc_ratio))       2499                                 bc_ratio))
2839                         goto prop_msg_full;      2500                         goto prop_msg_full;
2840         nla_nest_end(msg->skb, prop);            2501         nla_nest_end(msg->skb, prop);
2841                                                  2502 
2842         err = __tipc_nl_add_bc_link_stat(msg-    2503         err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
2843         if (err)                                 2504         if (err)
2844                 goto attr_msg_full;              2505                 goto attr_msg_full;
2845                                                  2506 
2846         tipc_bcast_unlock(net);                  2507         tipc_bcast_unlock(net);
2847         nla_nest_end(msg->skb, attrs);           2508         nla_nest_end(msg->skb, attrs);
2848         genlmsg_end(msg->skb, hdr);              2509         genlmsg_end(msg->skb, hdr);
2849                                                  2510 
2850         return 0;                                2511         return 0;
2851                                                  2512 
2852 prop_msg_full:                                   2513 prop_msg_full:
2853         nla_nest_cancel(msg->skb, prop);         2514         nla_nest_cancel(msg->skb, prop);
2854 attr_msg_full:                                   2515 attr_msg_full:
2855         nla_nest_cancel(msg->skb, attrs);        2516         nla_nest_cancel(msg->skb, attrs);
2856 msg_full:                                        2517 msg_full:
2857         tipc_bcast_unlock(net);                  2518         tipc_bcast_unlock(net);
2858         genlmsg_cancel(msg->skb, hdr);           2519         genlmsg_cancel(msg->skb, hdr);
2859                                                  2520 
2860         return -EMSGSIZE;                        2521         return -EMSGSIZE;
2861 }                                                2522 }
2862                                                  2523 
2863 void tipc_link_set_tolerance(struct tipc_link    2524 void tipc_link_set_tolerance(struct tipc_link *l, u32 tol,
2864                              struct sk_buff_h    2525                              struct sk_buff_head *xmitq)
2865 {                                                2526 {
2866         l->tolerance = tol;                      2527         l->tolerance = tol;
2867         if (l->bc_rcvlink)                       2528         if (l->bc_rcvlink)
2868                 l->bc_rcvlink->tolerance = to    2529                 l->bc_rcvlink->tolerance = tol;
2869         if (tipc_link_is_up(l))               !! 2530         if (link_is_up(l))
2870                 tipc_link_build_proto_msg(l,     2531                 tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, tol, 0, xmitq);
2871 }                                                2532 }
2872                                                  2533 
2873 void tipc_link_set_prio(struct tipc_link *l,     2534 void tipc_link_set_prio(struct tipc_link *l, u32 prio,
2874                         struct sk_buff_head *    2535                         struct sk_buff_head *xmitq)
2875 {                                                2536 {
2876         l->priority = prio;                      2537         l->priority = prio;
2877         tipc_link_build_proto_msg(l, STATE_MS    2538         tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, prio, xmitq);
2878 }                                                2539 }
2879                                                  2540 
2880 void tipc_link_set_abort_limit(struct tipc_li    2541 void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit)
2881 {                                                2542 {
2882         l->abort_limit = limit;                  2543         l->abort_limit = limit;
                                                   >> 2544 }
                                                   >> 2545 
                                                   >> 2546 char *tipc_link_name_ext(struct tipc_link *l, char *buf)
                                                   >> 2547 {
                                                   >> 2548         if (!l)
                                                   >> 2549                 scnprintf(buf, TIPC_MAX_LINK_NAME, "null");
                                                   >> 2550         else if (link_is_bc_sndlink(l))
                                                   >> 2551                 scnprintf(buf, TIPC_MAX_LINK_NAME, "broadcast-sender");
                                                   >> 2552         else if (link_is_bc_rcvlink(l))
                                                   >> 2553                 scnprintf(buf, TIPC_MAX_LINK_NAME,
                                                   >> 2554                           "broadcast-receiver, peer %x", l->addr);
                                                   >> 2555         else
                                                   >> 2556                 memcpy(buf, l->name, TIPC_MAX_LINK_NAME);
                                                   >> 2557 
                                                   >> 2558         return buf;
2883 }                                                2559 }
2884                                                  2560 
2885 /**                                              2561 /**
2886  * tipc_link_dump - dump TIPC link data          2562  * tipc_link_dump - dump TIPC link data
2887  * @l: tipc link to be dumped                    2563  * @l: tipc link to be dumped
2888  * @dqueues: bitmask to decide if any link qu    2564  * @dqueues: bitmask to decide if any link queue to be dumped?
2889  *           - TIPC_DUMP_NONE: don't dump lin    2565  *           - TIPC_DUMP_NONE: don't dump link queues
2890  *           - TIPC_DUMP_TRANSMQ: dump link t    2566  *           - TIPC_DUMP_TRANSMQ: dump link transmq queue
2891  *           - TIPC_DUMP_BACKLOGQ: dump link     2567  *           - TIPC_DUMP_BACKLOGQ: dump link backlog queue
2892  *           - TIPC_DUMP_DEFERDQ: dump link d    2568  *           - TIPC_DUMP_DEFERDQ: dump link deferd queue
2893  *           - TIPC_DUMP_INPUTQ: dump link in    2569  *           - TIPC_DUMP_INPUTQ: dump link input queue
2894  *           - TIPC_DUMP_WAKEUP: dump link wa    2570  *           - TIPC_DUMP_WAKEUP: dump link wakeup queue
2895  *           - TIPC_DUMP_ALL: dump all the li    2571  *           - TIPC_DUMP_ALL: dump all the link queues above
2896  * @buf: returned buffer of dump data in form    2572  * @buf: returned buffer of dump data in format
2897  */                                              2573  */
2898 int tipc_link_dump(struct tipc_link *l, u16 d    2574 int tipc_link_dump(struct tipc_link *l, u16 dqueues, char *buf)
2899 {                                                2575 {
2900         int i = 0;                               2576         int i = 0;
2901         size_t sz = (dqueues) ? LINK_LMAX : L    2577         size_t sz = (dqueues) ? LINK_LMAX : LINK_LMIN;
2902         struct sk_buff_head *list;               2578         struct sk_buff_head *list;
2903         struct sk_buff *hskb, *tskb;             2579         struct sk_buff *hskb, *tskb;
2904         u32 len;                                 2580         u32 len;
2905                                                  2581 
2906         if (!l) {                                2582         if (!l) {
2907                 i += scnprintf(buf, sz, "link    2583                 i += scnprintf(buf, sz, "link data: (null)\n");
2908                 return i;                        2584                 return i;
2909         }                                        2585         }
2910                                                  2586 
2911         i += scnprintf(buf, sz, "link data: %    2587         i += scnprintf(buf, sz, "link data: %x", l->addr);
2912         i += scnprintf(buf + i, sz - i, " %x"    2588         i += scnprintf(buf + i, sz - i, " %x", l->state);
2913         i += scnprintf(buf + i, sz - i, " %u"    2589         i += scnprintf(buf + i, sz - i, " %u", l->in_session);
2914         i += scnprintf(buf + i, sz - i, " %u"    2590         i += scnprintf(buf + i, sz - i, " %u", l->session);
2915         i += scnprintf(buf + i, sz - i, " %u"    2591         i += scnprintf(buf + i, sz - i, " %u", l->peer_session);
2916         i += scnprintf(buf + i, sz - i, " %u"    2592         i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt);
2917         i += scnprintf(buf + i, sz - i, " %u"    2593         i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt);
2918         i += scnprintf(buf + i, sz - i, " %u"    2594         i += scnprintf(buf + i, sz - i, " %u", l->snd_nxt_state);
2919         i += scnprintf(buf + i, sz - i, " %u"    2595         i += scnprintf(buf + i, sz - i, " %u", l->rcv_nxt_state);
2920         i += scnprintf(buf + i, sz - i, " %x"    2596         i += scnprintf(buf + i, sz - i, " %x", l->peer_caps);
2921         i += scnprintf(buf + i, sz - i, " %u"    2597         i += scnprintf(buf + i, sz - i, " %u", l->silent_intv_cnt);
2922         i += scnprintf(buf + i, sz - i, " %u"    2598         i += scnprintf(buf + i, sz - i, " %u", l->rst_cnt);
2923         i += scnprintf(buf + i, sz - i, " %u"    2599         i += scnprintf(buf + i, sz - i, " %u", 0);
2924         i += scnprintf(buf + i, sz - i, " %u"    2600         i += scnprintf(buf + i, sz - i, " %u", 0);
2925         i += scnprintf(buf + i, sz - i, " %u"    2601         i += scnprintf(buf + i, sz - i, " %u", l->acked);
2926                                                  2602 
2927         list = &l->transmq;                      2603         list = &l->transmq;
2928         len = skb_queue_len(list);               2604         len = skb_queue_len(list);
2929         hskb = skb_peek(list);                   2605         hskb = skb_peek(list);
2930         tskb = skb_peek_tail(list);              2606         tskb = skb_peek_tail(list);
2931         i += scnprintf(buf + i, sz - i, " | %    2607         i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2932                        (hskb) ? msg_seqno(buf    2608                        (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2933                        (tskb) ? msg_seqno(buf    2609                        (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2934                                                  2610 
2935         list = &l->deferdq;                      2611         list = &l->deferdq;
2936         len = skb_queue_len(list);               2612         len = skb_queue_len(list);
2937         hskb = skb_peek(list);                   2613         hskb = skb_peek(list);
2938         tskb = skb_peek_tail(list);              2614         tskb = skb_peek_tail(list);
2939         i += scnprintf(buf + i, sz - i, " | %    2615         i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2940                        (hskb) ? msg_seqno(buf    2616                        (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2941                        (tskb) ? msg_seqno(buf    2617                        (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2942                                                  2618 
2943         list = &l->backlogq;                     2619         list = &l->backlogq;
2944         len = skb_queue_len(list);               2620         len = skb_queue_len(list);
2945         hskb = skb_peek(list);                   2621         hskb = skb_peek(list);
2946         tskb = skb_peek_tail(list);              2622         tskb = skb_peek_tail(list);
2947         i += scnprintf(buf + i, sz - i, " | %    2623         i += scnprintf(buf + i, sz - i, " | %u %u %u", len,
2948                        (hskb) ? msg_seqno(buf    2624                        (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2949                        (tskb) ? msg_seqno(buf    2625                        (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2950                                                  2626 
2951         list = l->inputq;                        2627         list = l->inputq;
2952         len = skb_queue_len(list);               2628         len = skb_queue_len(list);
2953         hskb = skb_peek(list);                   2629         hskb = skb_peek(list);
2954         tskb = skb_peek_tail(list);              2630         tskb = skb_peek_tail(list);
2955         i += scnprintf(buf + i, sz - i, " | %    2631         i += scnprintf(buf + i, sz - i, " | %u %u %u\n", len,
2956                        (hskb) ? msg_seqno(buf    2632                        (hskb) ? msg_seqno(buf_msg(hskb)) : 0,
2957                        (tskb) ? msg_seqno(buf    2633                        (tskb) ? msg_seqno(buf_msg(tskb)) : 0);
2958                                                  2634 
2959         if (dqueues & TIPC_DUMP_TRANSMQ) {       2635         if (dqueues & TIPC_DUMP_TRANSMQ) {
2960                 i += scnprintf(buf + i, sz -     2636                 i += scnprintf(buf + i, sz - i, "transmq: ");
2961                 i += tipc_list_dump(&l->trans    2637                 i += tipc_list_dump(&l->transmq, false, buf + i);
2962         }                                        2638         }
2963         if (dqueues & TIPC_DUMP_BACKLOGQ) {      2639         if (dqueues & TIPC_DUMP_BACKLOGQ) {
2964                 i += scnprintf(buf + i, sz -     2640                 i += scnprintf(buf + i, sz - i,
2965                                "backlogq: <%u    2641                                "backlogq: <%u %u %u %u %u>, ",
2966                                l->backlog[TIP    2642                                l->backlog[TIPC_LOW_IMPORTANCE].len,
2967                                l->backlog[TIP    2643                                l->backlog[TIPC_MEDIUM_IMPORTANCE].len,
2968                                l->backlog[TIP    2644                                l->backlog[TIPC_HIGH_IMPORTANCE].len,
2969                                l->backlog[TIP    2645                                l->backlog[TIPC_CRITICAL_IMPORTANCE].len,
2970                                l->backlog[TIP    2646                                l->backlog[TIPC_SYSTEM_IMPORTANCE].len);
2971                 i += tipc_list_dump(&l->backl    2647                 i += tipc_list_dump(&l->backlogq, false, buf + i);
2972         }                                        2648         }
2973         if (dqueues & TIPC_DUMP_DEFERDQ) {       2649         if (dqueues & TIPC_DUMP_DEFERDQ) {
2974                 i += scnprintf(buf + i, sz -     2650                 i += scnprintf(buf + i, sz - i, "deferdq: ");
2975                 i += tipc_list_dump(&l->defer    2651                 i += tipc_list_dump(&l->deferdq, false, buf + i);
2976         }                                        2652         }
2977         if (dqueues & TIPC_DUMP_INPUTQ) {        2653         if (dqueues & TIPC_DUMP_INPUTQ) {
2978                 i += scnprintf(buf + i, sz -     2654                 i += scnprintf(buf + i, sz - i, "inputq: ");
2979                 i += tipc_list_dump(l->inputq    2655                 i += tipc_list_dump(l->inputq, false, buf + i);
2980         }                                        2656         }
2981         if (dqueues & TIPC_DUMP_WAKEUP) {        2657         if (dqueues & TIPC_DUMP_WAKEUP) {
2982                 i += scnprintf(buf + i, sz -     2658                 i += scnprintf(buf + i, sz - i, "wakeup: ");
2983                 i += tipc_list_dump(&l->wakeu    2659                 i += tipc_list_dump(&l->wakeupq, false, buf + i);
2984         }                                        2660         }
2985                                                  2661 
2986         return i;                                2662         return i;
2987 }                                                2663 }
2988                                                  2664 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php