~ [ 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-4.19.323)


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

~ [ 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