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