blob: c95038f42652ab7d760e412c2f5b40576cec9321 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/link.c: TIPC link code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Allan Stephens05646c92007-06-10 17:25:24 -07004 * Copyright (c) 1996-2007, Ericsson AB
5 * Copyright (c) 2004-2007, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
Per Liden9ea1fd32006-01-11 13:30:43 +01008 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +01009 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 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.
Per Lidenb97bf3f2006-01-02 19:04:38 +010019 *
Per Liden9ea1fd32006-01-11 13:30:43 +010020 * 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
Per Lidenb97bf3f2006-01-02 19:04:38 +010034 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "dbg.h"
39#include "link.h"
40#include "net.h"
41#include "node.h"
42#include "port.h"
43#include "addr.h"
44#include "node_subscr.h"
45#include "name_distr.h"
46#include "bearer.h"
47#include "name_table.h"
48#include "discover.h"
49#include "config.h"
50#include "bcast.h"
51
52
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090053/*
Allan Stephensa686e682008-06-04 17:29:39 -070054 * Out-of-range value for link session numbers
55 */
56
57#define INVALID_SESSION 0x10000
58
59/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090060 * Limit for deferred reception queue:
Per Lidenb97bf3f2006-01-02 19:04:38 +010061 */
62
63#define DEF_QUEUE_LIMIT 256u
64
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090065/*
66 * Link state events:
Per Lidenb97bf3f2006-01-02 19:04:38 +010067 */
68
69#define STARTING_EVT 856384768 /* link processing trigger */
70#define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
71#define TIMEOUT_EVT 560817u /* link timer expired */
72
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090073/*
74 * The following two 'message types' is really just implementation
75 * data conveniently stored in the message header.
Per Lidenb97bf3f2006-01-02 19:04:38 +010076 * They must not be considered part of the protocol
77 */
78#define OPEN_MSG 0
79#define CLOSED_MSG 1
80
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090081/*
Per Lidenb97bf3f2006-01-02 19:04:38 +010082 * State value stored in 'exp_msg_count'
83 */
84
85#define START_CHANGEOVER 100000u
86
87/**
88 * struct link_name - deconstructed link name
89 * @addr_local: network address of node at this end
90 * @if_local: name of interface at this end
91 * @addr_peer: network address of node at far end
92 * @if_peer: name of interface at far end
93 */
94
95struct link_name {
96 u32 addr_local;
97 char if_local[TIPC_MAX_IF_NAME];
98 u32 addr_peer;
99 char if_peer[TIPC_MAX_IF_NAME];
100};
101
102#if 0
103
104/* LINK EVENT CODE IS NOT SUPPORTED AT PRESENT */
105
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900106/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100107 * struct link_event - link up/down event notification
108 */
109
110struct link_event {
111 u32 addr;
112 int up;
113 void (*fcn)(u32, char *, int);
114 char name[TIPC_MAX_LINK_NAME];
115};
116
117#endif
118
119static void link_handle_out_of_seq_msg(struct link *l_ptr,
120 struct sk_buff *buf);
121static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf);
122static int link_recv_changeover_msg(struct link **l_ptr, struct sk_buff **buf);
123static void link_set_supervision_props(struct link *l_ptr, u32 tolerance);
124static int link_send_sections_long(struct port *sender,
125 struct iovec const *msg_sect,
126 u32 num_sect, u32 destnode);
127static void link_check_defragm_bufs(struct link *l_ptr);
128static void link_state_event(struct link *l_ptr, u32 event);
129static void link_reset_statistics(struct link *l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900130static void link_print(struct link *l_ptr, struct print_buf *buf,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100131 const char *str);
132
133/*
134 * Debugging code used by link routines only
135 *
136 * When debugging link problems on a system that has multiple links,
137 * the standard TIPC debugging routines may not be useful since they
138 * allow the output from multiple links to be intermixed. For this reason
139 * routines of the form "dbg_link_XXX()" have been created that will capture
140 * debug info into a link's personal print buffer, which can then be dumped
Allan Stephensa3df92c2006-10-16 21:49:03 -0700141 * into the TIPC system log (TIPC_LOG) upon request.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100142 *
143 * To enable per-link debugging, use LINK_LOG_BUF_SIZE to specify the size
144 * of the print buffer used by each link. If LINK_LOG_BUF_SIZE is set to 0,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900145 * the dbg_link_XXX() routines simply send their output to the standard
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146 * debug print buffer (DBG_OUTPUT), if it has been defined; this can be useful
147 * when there is only a single link in the system being debugged.
148 *
149 * Notes:
Allan Stephensa3df92c2006-10-16 21:49:03 -0700150 * - When enabled, LINK_LOG_BUF_SIZE should be set to at least TIPC_PB_MIN_SIZE
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900151 * - "l_ptr" must be valid when using dbg_link_XXX() macros
Per Lidenb97bf3f2006-01-02 19:04:38 +0100152 */
153
154#define LINK_LOG_BUF_SIZE 0
155
Allan Stephens48c97132008-05-05 01:24:06 -0700156#define dbg_link(fmt, arg...) \
157 do { \
158 if (LINK_LOG_BUF_SIZE) \
159 tipc_printf(&l_ptr->print_buf, fmt, ## arg); \
160 } while (0)
161#define dbg_link_msg(msg, txt) \
162 do { \
163 if (LINK_LOG_BUF_SIZE) \
164 tipc_msg_dbg(&l_ptr->print_buf, msg, txt); \
165 } while (0)
166#define dbg_link_state(txt) \
167 do { \
168 if (LINK_LOG_BUF_SIZE) \
169 link_print(l_ptr, &l_ptr->print_buf, txt); \
170 } while (0)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100171#define dbg_link_dump() do { \
172 if (LINK_LOG_BUF_SIZE) { \
173 tipc_printf(LOG, "\n\nDumping link <%s>:\n", l_ptr->name); \
Per Liden4323add2006-01-18 00:38:21 +0100174 tipc_printbuf_move(LOG, &l_ptr->print_buf); \
Per Lidenb97bf3f2006-01-02 19:04:38 +0100175 } \
176} while (0)
177
Sam Ravnborg05790c62006-03-20 22:37:04 -0800178static void dbg_print_link(struct link *l_ptr, const char *str)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100179{
Allan Stephensa3df92c2006-10-16 21:49:03 -0700180 if (DBG_OUTPUT != TIPC_NULL)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100181 link_print(l_ptr, DBG_OUTPUT, str);
182}
183
Sam Ravnborg05790c62006-03-20 22:37:04 -0800184static void dbg_print_buf_chain(struct sk_buff *root_buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100185{
Allan Stephensa3df92c2006-10-16 21:49:03 -0700186 if (DBG_OUTPUT != TIPC_NULL) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100187 struct sk_buff *buf = root_buf;
188
189 while (buf) {
190 msg_dbg(buf_msg(buf), "In chain: ");
191 buf = buf->next;
192 }
193 }
194}
195
196/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800197 * Simple link routines
Per Lidenb97bf3f2006-01-02 19:04:38 +0100198 */
199
Sam Ravnborg05790c62006-03-20 22:37:04 -0800200static unsigned int align(unsigned int i)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100201{
202 return (i + 3) & ~3u;
203}
204
Sam Ravnborg05790c62006-03-20 22:37:04 -0800205static int link_working_working(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100206{
207 return (l_ptr->state == WORKING_WORKING);
208}
209
Sam Ravnborg05790c62006-03-20 22:37:04 -0800210static int link_working_unknown(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100211{
212 return (l_ptr->state == WORKING_UNKNOWN);
213}
214
Sam Ravnborg05790c62006-03-20 22:37:04 -0800215static int link_reset_unknown(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100216{
217 return (l_ptr->state == RESET_UNKNOWN);
218}
219
Sam Ravnborg05790c62006-03-20 22:37:04 -0800220static int link_reset_reset(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221{
222 return (l_ptr->state == RESET_RESET);
223}
224
Sam Ravnborg05790c62006-03-20 22:37:04 -0800225static int link_blocked(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100226{
227 return (l_ptr->exp_msg_count || l_ptr->blocked);
228}
229
Sam Ravnborg05790c62006-03-20 22:37:04 -0800230static int link_congested(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100231{
232 return (l_ptr->out_queue_size >= l_ptr->queue_limit[0]);
233}
234
Sam Ravnborg05790c62006-03-20 22:37:04 -0800235static u32 link_max_pkt(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236{
237 return l_ptr->max_pkt;
238}
239
Sam Ravnborg05790c62006-03-20 22:37:04 -0800240static void link_init_max_pkt(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100241{
242 u32 max_pkt;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900243
Per Lidenb97bf3f2006-01-02 19:04:38 +0100244 max_pkt = (l_ptr->b_ptr->publ.mtu & ~3);
245 if (max_pkt > MAX_MSG_SIZE)
246 max_pkt = MAX_MSG_SIZE;
247
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900248 l_ptr->max_pkt_target = max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100249 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
250 l_ptr->max_pkt = l_ptr->max_pkt_target;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900251 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100252 l_ptr->max_pkt = MAX_PKT_DEFAULT;
253
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900254 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100255}
256
Sam Ravnborg05790c62006-03-20 22:37:04 -0800257static u32 link_next_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100258{
259 if (l_ptr->next_out)
260 return msg_seqno(buf_msg(l_ptr->next_out));
261 return mod(l_ptr->next_out_no);
262}
263
Sam Ravnborg05790c62006-03-20 22:37:04 -0800264static u32 link_last_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100265{
266 return mod(link_next_sent(l_ptr) - 1);
267}
268
269/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800270 * Simple non-static link routines (i.e. referenced outside this file)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100271 */
272
Per Liden4323add2006-01-18 00:38:21 +0100273int tipc_link_is_up(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100274{
275 if (!l_ptr)
276 return 0;
277 return (link_working_working(l_ptr) || link_working_unknown(l_ptr));
278}
279
Per Liden4323add2006-01-18 00:38:21 +0100280int tipc_link_is_active(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100281{
282 return ((l_ptr->owner->active_links[0] == l_ptr) ||
283 (l_ptr->owner->active_links[1] == l_ptr));
284}
285
286/**
287 * link_name_validate - validate & (optionally) deconstruct link name
288 * @name - ptr to link name string
289 * @name_parts - ptr to area for link name components (or NULL if not needed)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900290 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100291 * Returns 1 if link name is valid, otherwise 0.
292 */
293
294static int link_name_validate(const char *name, struct link_name *name_parts)
295{
296 char name_copy[TIPC_MAX_LINK_NAME];
297 char *addr_local;
298 char *if_local;
299 char *addr_peer;
300 char *if_peer;
301 char dummy;
302 u32 z_local, c_local, n_local;
303 u32 z_peer, c_peer, n_peer;
304 u32 if_local_len;
305 u32 if_peer_len;
306
307 /* copy link name & ensure length is OK */
308
309 name_copy[TIPC_MAX_LINK_NAME - 1] = 0;
310 /* need above in case non-Posix strncpy() doesn't pad with nulls */
311 strncpy(name_copy, name, TIPC_MAX_LINK_NAME);
312 if (name_copy[TIPC_MAX_LINK_NAME - 1] != 0)
313 return 0;
314
315 /* ensure all component parts of link name are present */
316
317 addr_local = name_copy;
318 if ((if_local = strchr(addr_local, ':')) == NULL)
319 return 0;
320 *(if_local++) = 0;
321 if ((addr_peer = strchr(if_local, '-')) == NULL)
322 return 0;
323 *(addr_peer++) = 0;
324 if_local_len = addr_peer - if_local;
325 if ((if_peer = strchr(addr_peer, ':')) == NULL)
326 return 0;
327 *(if_peer++) = 0;
328 if_peer_len = strlen(if_peer) + 1;
329
330 /* validate component parts of link name */
331
332 if ((sscanf(addr_local, "%u.%u.%u%c",
333 &z_local, &c_local, &n_local, &dummy) != 3) ||
334 (sscanf(addr_peer, "%u.%u.%u%c",
335 &z_peer, &c_peer, &n_peer, &dummy) != 3) ||
336 (z_local > 255) || (c_local > 4095) || (n_local > 4095) ||
337 (z_peer > 255) || (c_peer > 4095) || (n_peer > 4095) ||
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900338 (if_local_len <= 1) || (if_local_len > TIPC_MAX_IF_NAME) ||
339 (if_peer_len <= 1) || (if_peer_len > TIPC_MAX_IF_NAME) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100340 (strspn(if_local, tipc_alphabet) != (if_local_len - 1)) ||
341 (strspn(if_peer, tipc_alphabet) != (if_peer_len - 1)))
342 return 0;
343
344 /* return link name components, if necessary */
345
346 if (name_parts) {
347 name_parts->addr_local = tipc_addr(z_local, c_local, n_local);
348 strcpy(name_parts->if_local, if_local);
349 name_parts->addr_peer = tipc_addr(z_peer, c_peer, n_peer);
350 strcpy(name_parts->if_peer, if_peer);
351 }
352 return 1;
353}
354
355/**
356 * link_timeout - handle expiration of link timer
357 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900358 *
Per Liden4323add2006-01-18 00:38:21 +0100359 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
360 * with tipc_link_delete(). (There is no risk that the node will be deleted by
361 * another thread because tipc_link_delete() always cancels the link timer before
362 * tipc_node_delete() is called.)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100363 */
364
365static void link_timeout(struct link *l_ptr)
366{
Per Liden4323add2006-01-18 00:38:21 +0100367 tipc_node_lock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100368
369 /* update counters used in statistical profiling of send traffic */
370
371 l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
372 l_ptr->stats.queue_sz_counts++;
373
374 if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz)
375 l_ptr->stats.max_queue_sz = l_ptr->out_queue_size;
376
377 if (l_ptr->first_out) {
378 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
379 u32 length = msg_size(msg);
380
Joe Perchesf64f9e72009-11-29 16:55:45 -0800381 if ((msg_user(msg) == MSG_FRAGMENTER) &&
382 (msg_type(msg) == FIRST_FRAGMENT)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100383 length = msg_size(msg_get_wrapped(msg));
384 }
385 if (length) {
386 l_ptr->stats.msg_lengths_total += length;
387 l_ptr->stats.msg_length_counts++;
388 if (length <= 64)
389 l_ptr->stats.msg_length_profile[0]++;
390 else if (length <= 256)
391 l_ptr->stats.msg_length_profile[1]++;
392 else if (length <= 1024)
393 l_ptr->stats.msg_length_profile[2]++;
394 else if (length <= 4096)
395 l_ptr->stats.msg_length_profile[3]++;
396 else if (length <= 16384)
397 l_ptr->stats.msg_length_profile[4]++;
398 else if (length <= 32768)
399 l_ptr->stats.msg_length_profile[5]++;
400 else
401 l_ptr->stats.msg_length_profile[6]++;
402 }
403 }
404
405 /* do all other link processing performed on a periodic basis */
406
407 link_check_defragm_bufs(l_ptr);
408
409 link_state_event(l_ptr, TIMEOUT_EVT);
410
411 if (l_ptr->next_out)
Per Liden4323add2006-01-18 00:38:21 +0100412 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100413
Per Liden4323add2006-01-18 00:38:21 +0100414 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100415}
416
Sam Ravnborg05790c62006-03-20 22:37:04 -0800417static void link_set_timer(struct link *l_ptr, u32 time)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100418{
419 k_start_timer(&l_ptr->timer, time);
420}
421
422/**
Per Liden4323add2006-01-18 00:38:21 +0100423 * tipc_link_create - create a new link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100424 * @b_ptr: pointer to associated bearer
425 * @peer: network address of node at other end of link
426 * @media_addr: media address to use when sending messages over link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900427 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100428 * Returns pointer to link.
429 */
430
Per Liden4323add2006-01-18 00:38:21 +0100431struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
432 const struct tipc_media_addr *media_addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100433{
434 struct link *l_ptr;
435 struct tipc_msg *msg;
436 char *if_name;
437
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700438 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100439 if (!l_ptr) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700440 warn("Link creation failed, no memory\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441 return NULL;
442 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100443
Florian Westphal945710652007-07-26 00:05:07 -0700444 if (LINK_LOG_BUF_SIZE) {
445 char *pb = kmalloc(LINK_LOG_BUF_SIZE, GFP_ATOMIC);
446
447 if (!pb) {
448 kfree(l_ptr);
449 warn("Link creation failed, no memory for print buffer\n");
450 return NULL;
451 }
452 tipc_printbuf_init(&l_ptr->print_buf, pb, LINK_LOG_BUF_SIZE);
453 }
454
Per Lidenb97bf3f2006-01-02 19:04:38 +0100455 l_ptr->addr = peer;
456 if_name = strchr(b_ptr->publ.name, ':') + 1;
457 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:",
458 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900459 tipc_node(tipc_own_addr),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100460 if_name,
461 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
462 /* note: peer i/f is appended to link name by reset/activate */
463 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100464 l_ptr->checkpoint = 1;
465 l_ptr->b_ptr = b_ptr;
466 link_set_supervision_props(l_ptr, b_ptr->media->tolerance);
467 l_ptr->state = RESET_UNKNOWN;
468
469 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
470 msg = l_ptr->pmsg;
Allan Stephens75715212008-06-04 17:37:34 -0700471 msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100472 msg_set_size(msg, sizeof(l_ptr->proto_msg));
Allan Stephensa686e682008-06-04 17:29:39 -0700473 msg_set_session(msg, (tipc_random & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100474 msg_set_bearer_id(msg, b_ptr->identity);
475 strcpy((char *)msg_data(msg), if_name);
476
477 l_ptr->priority = b_ptr->priority;
Per Liden4323add2006-01-18 00:38:21 +0100478 tipc_link_set_queue_limits(l_ptr, b_ptr->media->window);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100479
480 link_init_max_pkt(l_ptr);
481
482 l_ptr->next_out_no = 1;
483 INIT_LIST_HEAD(&l_ptr->waiting_ports);
484
485 link_reset_statistics(l_ptr);
486
Per Liden4323add2006-01-18 00:38:21 +0100487 l_ptr->owner = tipc_node_attach_link(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100488 if (!l_ptr->owner) {
Florian Westphal945710652007-07-26 00:05:07 -0700489 if (LINK_LOG_BUF_SIZE)
490 kfree(l_ptr->print_buf.buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100491 kfree(l_ptr);
492 return NULL;
493 }
494
Florian Westphal945710652007-07-26 00:05:07 -0700495 k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr);
496 list_add_tail(&l_ptr->link_list, &b_ptr->links);
Per Liden4323add2006-01-18 00:38:21 +0100497 tipc_k_signal((Handler)tipc_link_start, (unsigned long)l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100498
Per Liden4323add2006-01-18 00:38:21 +0100499 dbg("tipc_link_create(): tolerance = %u,cont intv = %u, abort_limit = %u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +0100500 l_ptr->tolerance, l_ptr->continuity_interval, l_ptr->abort_limit);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900501
Per Lidenb97bf3f2006-01-02 19:04:38 +0100502 return l_ptr;
503}
504
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900505/**
Per Liden4323add2006-01-18 00:38:21 +0100506 * tipc_link_delete - delete a link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100507 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900508 *
Per Liden4323add2006-01-18 00:38:21 +0100509 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510 * This routine must not grab the node lock until after link timer cancellation
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900511 * to avoid a potential deadlock situation.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100512 */
513
Per Liden4323add2006-01-18 00:38:21 +0100514void tipc_link_delete(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100515{
516 if (!l_ptr) {
517 err("Attempt to delete non-existent link\n");
518 return;
519 }
520
Per Liden4323add2006-01-18 00:38:21 +0100521 dbg("tipc_link_delete()\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100522
523 k_cancel_timer(&l_ptr->timer);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900524
Per Liden4323add2006-01-18 00:38:21 +0100525 tipc_node_lock(l_ptr->owner);
526 tipc_link_reset(l_ptr);
527 tipc_node_detach_link(l_ptr->owner, l_ptr);
528 tipc_link_stop(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100529 list_del_init(&l_ptr->link_list);
530 if (LINK_LOG_BUF_SIZE)
531 kfree(l_ptr->print_buf.buf);
Per Liden4323add2006-01-18 00:38:21 +0100532 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100533 k_term_timer(&l_ptr->timer);
534 kfree(l_ptr);
535}
536
Per Liden4323add2006-01-18 00:38:21 +0100537void tipc_link_start(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100538{
Per Liden4323add2006-01-18 00:38:21 +0100539 dbg("tipc_link_start %x\n", l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100540 link_state_event(l_ptr, STARTING_EVT);
541}
542
543/**
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900544 * link_schedule_port - schedule port for deferred sending
Per Lidenb97bf3f2006-01-02 19:04:38 +0100545 * @l_ptr: pointer to link
546 * @origport: reference to sending port
547 * @sz: amount of data to be sent
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900548 *
549 * Schedules port for renewed sending of messages after link congestion
Per Lidenb97bf3f2006-01-02 19:04:38 +0100550 * has abated.
551 */
552
553static int link_schedule_port(struct link *l_ptr, u32 origport, u32 sz)
554{
555 struct port *p_ptr;
556
Per Liden4323add2006-01-18 00:38:21 +0100557 spin_lock_bh(&tipc_port_list_lock);
558 p_ptr = tipc_port_lock(origport);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100559 if (p_ptr) {
560 if (!p_ptr->wakeup)
561 goto exit;
562 if (!list_empty(&p_ptr->wait_list))
563 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100564 p_ptr->publ.congested = 1;
565 p_ptr->waiting_pkts = 1 + ((sz - 1) / link_max_pkt(l_ptr));
566 list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
567 l_ptr->stats.link_congs++;
568exit:
Per Liden4323add2006-01-18 00:38:21 +0100569 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100570 }
Per Liden4323add2006-01-18 00:38:21 +0100571 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100572 return -ELINKCONG;
573}
574
Per Liden4323add2006-01-18 00:38:21 +0100575void tipc_link_wakeup_ports(struct link *l_ptr, int all)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100576{
577 struct port *p_ptr;
578 struct port *temp_p_ptr;
579 int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
580
581 if (all)
582 win = 100000;
583 if (win <= 0)
584 return;
Per Liden4323add2006-01-18 00:38:21 +0100585 if (!spin_trylock_bh(&tipc_port_list_lock))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100586 return;
587 if (link_congested(l_ptr))
588 goto exit;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900589 list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100590 wait_list) {
591 if (win <= 0)
592 break;
593 list_del_init(&p_ptr->wait_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100594 spin_lock_bh(p_ptr->publ.lock);
595 p_ptr->publ.congested = 0;
596 p_ptr->wakeup(&p_ptr->publ);
597 win -= p_ptr->waiting_pkts;
598 spin_unlock_bh(p_ptr->publ.lock);
599 }
600
601exit:
Per Liden4323add2006-01-18 00:38:21 +0100602 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100603}
604
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900605/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100606 * link_release_outqueue - purge link's outbound message queue
607 * @l_ptr: pointer to link
608 */
609
610static void link_release_outqueue(struct link *l_ptr)
611{
612 struct sk_buff *buf = l_ptr->first_out;
613 struct sk_buff *next;
614
615 while (buf) {
616 next = buf->next;
617 buf_discard(buf);
618 buf = next;
619 }
620 l_ptr->first_out = NULL;
621 l_ptr->out_queue_size = 0;
622}
623
624/**
Per Liden4323add2006-01-18 00:38:21 +0100625 * tipc_link_reset_fragments - purge link's inbound message fragments queue
Per Lidenb97bf3f2006-01-02 19:04:38 +0100626 * @l_ptr: pointer to link
627 */
628
Per Liden4323add2006-01-18 00:38:21 +0100629void tipc_link_reset_fragments(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100630{
631 struct sk_buff *buf = l_ptr->defragm_buf;
632 struct sk_buff *next;
633
634 while (buf) {
635 next = buf->next;
636 buf_discard(buf);
637 buf = next;
638 }
639 l_ptr->defragm_buf = NULL;
640}
641
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900642/**
Per Liden4323add2006-01-18 00:38:21 +0100643 * tipc_link_stop - purge all inbound and outbound messages associated with link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100644 * @l_ptr: pointer to link
645 */
646
Per Liden4323add2006-01-18 00:38:21 +0100647void tipc_link_stop(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100648{
649 struct sk_buff *buf;
650 struct sk_buff *next;
651
652 buf = l_ptr->oldest_deferred_in;
653 while (buf) {
654 next = buf->next;
655 buf_discard(buf);
656 buf = next;
657 }
658
659 buf = l_ptr->first_out;
660 while (buf) {
661 next = buf->next;
662 buf_discard(buf);
663 buf = next;
664 }
665
Per Liden4323add2006-01-18 00:38:21 +0100666 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100667
668 buf_discard(l_ptr->proto_msg_queue);
669 l_ptr->proto_msg_queue = NULL;
670}
671
672#if 0
673
674/* LINK EVENT CODE IS NOT SUPPORTED AT PRESENT */
675
676static void link_recv_event(struct link_event *ev)
677{
678 ev->fcn(ev->addr, ev->name, ev->up);
679 kfree(ev);
680}
681
682static void link_send_event(void (*fcn)(u32 a, char *n, int up),
683 struct link *l_ptr, int up)
684{
685 struct link_event *ev;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900686
Per Lidenb97bf3f2006-01-02 19:04:38 +0100687 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
688 if (!ev) {
689 warn("Link event allocation failure\n");
690 return;
691 }
692 ev->addr = l_ptr->addr;
693 ev->up = up;
694 ev->fcn = fcn;
695 memcpy(ev->name, l_ptr->name, TIPC_MAX_LINK_NAME);
Per Liden4323add2006-01-18 00:38:21 +0100696 tipc_k_signal((Handler)link_recv_event, (unsigned long)ev);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100697}
698
699#else
700
701#define link_send_event(fcn, l_ptr, up) do { } while (0)
702
703#endif
704
Per Liden4323add2006-01-18 00:38:21 +0100705void tipc_link_reset(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100706{
707 struct sk_buff *buf;
708 u32 prev_state = l_ptr->state;
709 u32 checkpoint = l_ptr->next_in_no;
Allan Stephens5392d642006-06-25 23:52:50 -0700710 int was_active_link = tipc_link_is_active(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900711
Allan Stephensa686e682008-06-04 17:29:39 -0700712 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713
Allan Stephensa686e682008-06-04 17:29:39 -0700714 /* Link is down, accept any session */
715 l_ptr->peer_session = INVALID_SESSION;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100716
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900717 /* Prepare for max packet size negotiation */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100718 link_init_max_pkt(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900719
Per Lidenb97bf3f2006-01-02 19:04:38 +0100720 l_ptr->state = RESET_UNKNOWN;
721 dbg_link_state("Resetting Link\n");
722
723 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
724 return;
725
Per Liden4323add2006-01-18 00:38:21 +0100726 tipc_node_link_down(l_ptr->owner, l_ptr);
727 tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100728#if 0
Per Liden4323add2006-01-18 00:38:21 +0100729 tipc_printf(TIPC_CONS, "\nReset link <%s>\n", l_ptr->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100730 dbg_link_dump();
731#endif
Allan Stephens5392d642006-06-25 23:52:50 -0700732 if (was_active_link && tipc_node_has_active_links(l_ptr->owner) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100733 l_ptr->owner->permit_changeover) {
734 l_ptr->reset_checkpoint = checkpoint;
735 l_ptr->exp_msg_count = START_CHANGEOVER;
736 }
737
738 /* Clean up all queues: */
739
740 link_release_outqueue(l_ptr);
741 buf_discard(l_ptr->proto_msg_queue);
742 l_ptr->proto_msg_queue = NULL;
743 buf = l_ptr->oldest_deferred_in;
744 while (buf) {
745 struct sk_buff *next = buf->next;
746 buf_discard(buf);
747 buf = next;
748 }
749 if (!list_empty(&l_ptr->waiting_ports))
Per Liden4323add2006-01-18 00:38:21 +0100750 tipc_link_wakeup_ports(l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100751
752 l_ptr->retransm_queue_head = 0;
753 l_ptr->retransm_queue_size = 0;
754 l_ptr->last_out = NULL;
755 l_ptr->first_out = NULL;
756 l_ptr->next_out = NULL;
757 l_ptr->unacked_window = 0;
758 l_ptr->checkpoint = 1;
759 l_ptr->next_out_no = 1;
760 l_ptr->deferred_inqueue_sz = 0;
761 l_ptr->oldest_deferred_in = NULL;
762 l_ptr->newest_deferred_in = NULL;
763 l_ptr->fsm_msg_cnt = 0;
764 l_ptr->stale_count = 0;
765 link_reset_statistics(l_ptr);
766
Per Liden4323add2006-01-18 00:38:21 +0100767 link_send_event(tipc_cfg_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100768 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100769 link_send_event(tipc_disc_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100770}
771
772
773static void link_activate(struct link *l_ptr)
774{
Allan Stephens5392d642006-06-25 23:52:50 -0700775 l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
Per Liden4323add2006-01-18 00:38:21 +0100776 tipc_node_link_up(l_ptr->owner, l_ptr);
777 tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr);
778 link_send_event(tipc_cfg_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100779 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100780 link_send_event(tipc_disc_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100781}
782
783/**
784 * link_state_event - link finite state machine
785 * @l_ptr: pointer to link
786 * @event: state machine event to process
787 */
788
789static void link_state_event(struct link *l_ptr, unsigned event)
790{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900791 struct link *other;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100792 u32 cont_intv = l_ptr->continuity_interval;
793
794 if (!l_ptr->started && (event != STARTING_EVT))
795 return; /* Not yet. */
796
797 if (link_blocked(l_ptr)) {
798 if (event == TIMEOUT_EVT) {
799 link_set_timer(l_ptr, cont_intv);
800 }
801 return; /* Changeover going on */
802 }
803 dbg_link("STATE_EV: <%s> ", l_ptr->name);
804
805 switch (l_ptr->state) {
806 case WORKING_WORKING:
807 dbg_link("WW/");
808 switch (event) {
809 case TRAFFIC_MSG_EVT:
810 dbg_link("TRF-");
811 /* fall through */
812 case ACTIVATE_MSG:
813 dbg_link("ACT\n");
814 break;
815 case TIMEOUT_EVT:
816 dbg_link("TIM ");
817 if (l_ptr->next_in_no != l_ptr->checkpoint) {
818 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100819 if (tipc_bclink_acks_missing(l_ptr->owner)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900820 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100821 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100822 l_ptr->fsm_msg_cnt++;
823 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900824 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100825 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100826 l_ptr->fsm_msg_cnt++;
827 }
828 link_set_timer(l_ptr, cont_intv);
829 break;
830 }
831 dbg_link(" -> WU\n");
832 l_ptr->state = WORKING_UNKNOWN;
833 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100834 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100835 l_ptr->fsm_msg_cnt++;
836 link_set_timer(l_ptr, cont_intv / 4);
837 break;
838 case RESET_MSG:
839 dbg_link("RES -> RR\n");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900840 info("Resetting link <%s>, requested by peer\n",
Allan Stephensa10bd922006-06-25 23:52:17 -0700841 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100842 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100843 l_ptr->state = RESET_RESET;
844 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100845 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100846 l_ptr->fsm_msg_cnt++;
847 link_set_timer(l_ptr, cont_intv);
848 break;
849 default:
850 err("Unknown link event %u in WW state\n", event);
851 }
852 break;
853 case WORKING_UNKNOWN:
854 dbg_link("WU/");
855 switch (event) {
856 case TRAFFIC_MSG_EVT:
857 dbg_link("TRF-");
858 case ACTIVATE_MSG:
859 dbg_link("ACT -> WW\n");
860 l_ptr->state = WORKING_WORKING;
861 l_ptr->fsm_msg_cnt = 0;
862 link_set_timer(l_ptr, cont_intv);
863 break;
864 case RESET_MSG:
865 dbg_link("RES -> RR\n");
Allan Stephensa10bd922006-06-25 23:52:17 -0700866 info("Resetting link <%s>, requested by peer "
867 "while probing\n", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100868 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100869 l_ptr->state = RESET_RESET;
870 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100871 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100872 l_ptr->fsm_msg_cnt++;
873 link_set_timer(l_ptr, cont_intv);
874 break;
875 case TIMEOUT_EVT:
876 dbg_link("TIM ");
877 if (l_ptr->next_in_no != l_ptr->checkpoint) {
Frans Popa570f092010-03-24 07:57:29 +0000878 dbg_link("-> WW\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100879 l_ptr->state = WORKING_WORKING;
880 l_ptr->fsm_msg_cnt = 0;
881 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100882 if (tipc_bclink_acks_missing(l_ptr->owner)) {
883 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
884 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100885 l_ptr->fsm_msg_cnt++;
886 }
887 link_set_timer(l_ptr, cont_intv);
888 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
889 dbg_link("Probing %u/%u,timer = %u ms)\n",
890 l_ptr->fsm_msg_cnt, l_ptr->abort_limit,
891 cont_intv / 4);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900892 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100893 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100894 l_ptr->fsm_msg_cnt++;
895 link_set_timer(l_ptr, cont_intv / 4);
896 } else { /* Link has failed */
897 dbg_link("-> RU (%u probes unanswered)\n",
898 l_ptr->fsm_msg_cnt);
Allan Stephensa10bd922006-06-25 23:52:17 -0700899 warn("Resetting link <%s>, peer not responding\n",
900 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100901 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100902 l_ptr->state = RESET_UNKNOWN;
903 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100904 tipc_link_send_proto_msg(l_ptr, RESET_MSG,
905 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100906 l_ptr->fsm_msg_cnt++;
907 link_set_timer(l_ptr, cont_intv);
908 }
909 break;
910 default:
911 err("Unknown link event %u in WU state\n", event);
912 }
913 break;
914 case RESET_UNKNOWN:
915 dbg_link("RU/");
916 switch (event) {
917 case TRAFFIC_MSG_EVT:
918 dbg_link("TRF-\n");
919 break;
920 case ACTIVATE_MSG:
921 other = l_ptr->owner->active_links[0];
922 if (other && link_working_unknown(other)) {
923 dbg_link("ACT\n");
924 break;
925 }
926 dbg_link("ACT -> WW\n");
927 l_ptr->state = WORKING_WORKING;
928 l_ptr->fsm_msg_cnt = 0;
929 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100930 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100931 l_ptr->fsm_msg_cnt++;
932 link_set_timer(l_ptr, cont_intv);
933 break;
934 case RESET_MSG:
Frans Popa570f092010-03-24 07:57:29 +0000935 dbg_link("RES\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100936 dbg_link(" -> RR\n");
937 l_ptr->state = RESET_RESET;
938 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100939 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100940 l_ptr->fsm_msg_cnt++;
941 link_set_timer(l_ptr, cont_intv);
942 break;
943 case STARTING_EVT:
944 dbg_link("START-");
945 l_ptr->started = 1;
946 /* fall through */
947 case TIMEOUT_EVT:
Frans Popa570f092010-03-24 07:57:29 +0000948 dbg_link("TIM\n");
Per Liden4323add2006-01-18 00:38:21 +0100949 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100950 l_ptr->fsm_msg_cnt++;
951 link_set_timer(l_ptr, cont_intv);
952 break;
953 default:
954 err("Unknown link event %u in RU state\n", event);
955 }
956 break;
957 case RESET_RESET:
958 dbg_link("RR/ ");
959 switch (event) {
960 case TRAFFIC_MSG_EVT:
961 dbg_link("TRF-");
962 /* fall through */
963 case ACTIVATE_MSG:
964 other = l_ptr->owner->active_links[0];
965 if (other && link_working_unknown(other)) {
966 dbg_link("ACT\n");
967 break;
968 }
969 dbg_link("ACT -> WW\n");
970 l_ptr->state = WORKING_WORKING;
971 l_ptr->fsm_msg_cnt = 0;
972 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100973 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100974 l_ptr->fsm_msg_cnt++;
975 link_set_timer(l_ptr, cont_intv);
976 break;
977 case RESET_MSG:
978 dbg_link("RES\n");
979 break;
980 case TIMEOUT_EVT:
981 dbg_link("TIM\n");
Per Liden4323add2006-01-18 00:38:21 +0100982 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100983 l_ptr->fsm_msg_cnt++;
984 link_set_timer(l_ptr, cont_intv);
985 dbg_link("fsm_msg_cnt %u\n", l_ptr->fsm_msg_cnt);
986 break;
987 default:
988 err("Unknown link event %u in RR state\n", event);
989 }
990 break;
991 default:
992 err("Unknown link state %u/%u\n", l_ptr->state, event);
993 }
994}
995
996/*
997 * link_bundle_buf(): Append contents of a buffer to
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900998 * the tail of an existing one.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100999 */
1000
1001static int link_bundle_buf(struct link *l_ptr,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001002 struct sk_buff *bundler,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001003 struct sk_buff *buf)
1004{
1005 struct tipc_msg *bundler_msg = buf_msg(bundler);
1006 struct tipc_msg *msg = buf_msg(buf);
1007 u32 size = msg_size(msg);
Allan Stephense49060c2006-06-29 12:32:46 -07001008 u32 bundle_size = msg_size(bundler_msg);
1009 u32 to_pos = align(bundle_size);
1010 u32 pad = to_pos - bundle_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001011
1012 if (msg_user(bundler_msg) != MSG_BUNDLER)
1013 return 0;
1014 if (msg_type(bundler_msg) != OPEN_MSG)
1015 return 0;
Allan Stephense49060c2006-06-29 12:32:46 -07001016 if (skb_tailroom(bundler) < (pad + size))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001017 return 0;
Allan Stephens863fae62006-07-03 19:39:36 -07001018 if (link_max_pkt(l_ptr) < (to_pos + size))
1019 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001020
Allan Stephense49060c2006-06-29 12:32:46 -07001021 skb_put(bundler, pad + size);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001022 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001023 msg_set_size(bundler_msg, to_pos + size);
1024 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
1025 dbg("Packed msg # %u(%u octets) into pos %u in buf(#%u)\n",
1026 msg_msgcnt(bundler_msg), size, to_pos, msg_seqno(bundler_msg));
1027 msg_dbg(msg, "PACKD:");
1028 buf_discard(buf);
1029 l_ptr->stats.sent_bundled++;
1030 return 1;
1031}
1032
Sam Ravnborg05790c62006-03-20 22:37:04 -08001033static void link_add_to_outqueue(struct link *l_ptr,
1034 struct sk_buff *buf,
1035 struct tipc_msg *msg)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001036{
1037 u32 ack = mod(l_ptr->next_in_no - 1);
1038 u32 seqno = mod(l_ptr->next_out_no++);
1039
1040 msg_set_word(msg, 2, ((ack << 16) | seqno));
1041 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1042 buf->next = NULL;
1043 if (l_ptr->first_out) {
1044 l_ptr->last_out->next = buf;
1045 l_ptr->last_out = buf;
1046 } else
1047 l_ptr->first_out = l_ptr->last_out = buf;
1048 l_ptr->out_queue_size++;
1049}
1050
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001051/*
1052 * tipc_link_send_buf() is the 'full path' for messages, called from
Per Lidenb97bf3f2006-01-02 19:04:38 +01001053 * inside TIPC when the 'fast path' in tipc_send_buf
1054 * has failed, and from link_send()
1055 */
1056
Per Liden4323add2006-01-18 00:38:21 +01001057int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001058{
1059 struct tipc_msg *msg = buf_msg(buf);
1060 u32 size = msg_size(msg);
1061 u32 dsz = msg_data_sz(msg);
1062 u32 queue_size = l_ptr->out_queue_size;
1063 u32 imp = msg_tot_importance(msg);
1064 u32 queue_limit = l_ptr->queue_limit[imp];
1065 u32 max_packet = link_max_pkt(l_ptr);
1066
1067 msg_set_prevnode(msg, tipc_own_addr); /* If routed message */
1068
1069 /* Match msg importance against queue limits: */
1070
1071 if (unlikely(queue_size >= queue_limit)) {
1072 if (imp <= TIPC_CRITICAL_IMPORTANCE) {
1073 return link_schedule_port(l_ptr, msg_origport(msg),
1074 size);
1075 }
1076 msg_dbg(msg, "TIPC: Congestion, throwing away\n");
1077 buf_discard(buf);
1078 if (imp > CONN_MANAGER) {
Allan Stephensa10bd922006-06-25 23:52:17 -07001079 warn("Resetting link <%s>, send queue full", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +01001080 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001081 }
1082 return dsz;
1083 }
1084
1085 /* Fragmentation needed ? */
1086
1087 if (size > max_packet)
Per Liden4323add2006-01-18 00:38:21 +01001088 return tipc_link_send_long_buf(l_ptr, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001089
1090 /* Packet can be queued or sent: */
1091
1092 if (queue_size > l_ptr->stats.max_queue_sz)
1093 l_ptr->stats.max_queue_sz = queue_size;
1094
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001095 if (likely(!tipc_bearer_congested(l_ptr->b_ptr, l_ptr) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001096 !link_congested(l_ptr))) {
1097 link_add_to_outqueue(l_ptr, buf, msg);
1098
Per Liden4323add2006-01-18 00:38:21 +01001099 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001100 l_ptr->unacked_window = 0;
1101 } else {
Per Liden4323add2006-01-18 00:38:21 +01001102 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001103 l_ptr->stats.bearer_congs++;
1104 l_ptr->next_out = buf;
1105 }
1106 return dsz;
1107 }
1108 /* Congestion: can message be bundled ?: */
1109
1110 if ((msg_user(msg) != CHANGEOVER_PROTOCOL) &&
1111 (msg_user(msg) != MSG_FRAGMENTER)) {
1112
1113 /* Try adding message to an existing bundle */
1114
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001115 if (l_ptr->next_out &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001116 link_bundle_buf(l_ptr, l_ptr->last_out, buf)) {
Per Liden4323add2006-01-18 00:38:21 +01001117 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001118 return dsz;
1119 }
1120
1121 /* Try creating a new bundle */
1122
1123 if (size <= max_packet * 2 / 3) {
1124 struct sk_buff *bundler = buf_acquire(max_packet);
1125 struct tipc_msg bundler_hdr;
1126
1127 if (bundler) {
1128 msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG,
Allan Stephens75715212008-06-04 17:37:34 -07001129 INT_H_SIZE, l_ptr->addr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001130 skb_copy_to_linear_data(bundler, &bundler_hdr,
1131 INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001132 skb_trim(bundler, INT_H_SIZE);
1133 link_bundle_buf(l_ptr, bundler, buf);
1134 buf = bundler;
1135 msg = buf_msg(buf);
1136 l_ptr->stats.sent_bundles++;
1137 }
1138 }
1139 }
1140 if (!l_ptr->next_out)
1141 l_ptr->next_out = buf;
1142 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +01001143 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001144 return dsz;
1145}
1146
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001147/*
1148 * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has
Per Lidenb97bf3f2006-01-02 19:04:38 +01001149 * not been selected yet, and the the owner node is not locked
1150 * Called by TIPC internal users, e.g. the name distributor
1151 */
1152
Per Liden4323add2006-01-18 00:38:21 +01001153int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001154{
1155 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001156 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001157 int res = -ELINKCONG;
1158
Per Liden4323add2006-01-18 00:38:21 +01001159 read_lock_bh(&tipc_net_lock);
1160 n_ptr = tipc_node_select(dest, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001161 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001162 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001163 l_ptr = n_ptr->active_links[selector & 1];
Per Lidenb97bf3f2006-01-02 19:04:38 +01001164 if (l_ptr) {
Allan Stephensc33d53b2006-06-25 23:50:30 -07001165 dbg("tipc_link_send: found link %x for dest %x\n", l_ptr, dest);
Per Liden4323add2006-01-18 00:38:21 +01001166 res = tipc_link_send_buf(l_ptr, buf);
Allan Stephensc33d53b2006-06-25 23:50:30 -07001167 } else {
1168 dbg("Attempt to send msg to unreachable node:\n");
1169 msg_dbg(buf_msg(buf),">>>");
1170 buf_discard(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001171 }
Per Liden4323add2006-01-18 00:38:21 +01001172 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001173 } else {
1174 dbg("Attempt to send msg to unknown node:\n");
1175 msg_dbg(buf_msg(buf),">>>");
1176 buf_discard(buf);
1177 }
Per Liden4323add2006-01-18 00:38:21 +01001178 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001179 return res;
1180}
1181
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001182/*
1183 * link_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001184 * destination link is known and the header is complete,
1185 * inclusive total message length. Very time critical.
1186 * Link is locked. Returns user data length.
1187 */
1188
Sam Ravnborg05790c62006-03-20 22:37:04 -08001189static int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf,
1190 u32 *used_max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001191{
1192 struct tipc_msg *msg = buf_msg(buf);
1193 int res = msg_data_sz(msg);
1194
1195 if (likely(!link_congested(l_ptr))) {
1196 if (likely(msg_size(msg) <= link_max_pkt(l_ptr))) {
1197 if (likely(list_empty(&l_ptr->b_ptr->cong_links))) {
1198 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +01001199 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf,
1200 &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001201 l_ptr->unacked_window = 0;
1202 msg_dbg(msg,"SENT_FAST:");
1203 return res;
1204 }
1205 dbg("failed sent fast...\n");
Per Liden4323add2006-01-18 00:38:21 +01001206 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001207 l_ptr->stats.bearer_congs++;
1208 l_ptr->next_out = buf;
1209 return res;
1210 }
1211 }
1212 else
1213 *used_max_pkt = link_max_pkt(l_ptr);
1214 }
Per Liden4323add2006-01-18 00:38:21 +01001215 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001216}
1217
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001218/*
1219 * tipc_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001220 * destination node is known and the header is complete,
1221 * inclusive total message length.
1222 * Returns user data length.
1223 */
1224int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode)
1225{
1226 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001227 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001228 int res;
1229 u32 selector = msg_origport(buf_msg(buf)) & 1;
1230 u32 dummy;
1231
1232 if (destnode == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +01001233 return tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001234
Per Liden4323add2006-01-18 00:38:21 +01001235 read_lock_bh(&tipc_net_lock);
1236 n_ptr = tipc_node_select(destnode, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001237 if (likely(n_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001238 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001239 l_ptr = n_ptr->active_links[selector];
1240 dbg("send_fast: buf %x selected %x, destnode = %x\n",
1241 buf, l_ptr, destnode);
1242 if (likely(l_ptr)) {
1243 res = link_send_buf_fast(l_ptr, buf, &dummy);
Per Liden4323add2006-01-18 00:38:21 +01001244 tipc_node_unlock(n_ptr);
1245 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001246 return res;
1247 }
Per Liden4323add2006-01-18 00:38:21 +01001248 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001249 }
Per Liden4323add2006-01-18 00:38:21 +01001250 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001251 res = msg_data_sz(buf_msg(buf));
1252 tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1253 return res;
1254}
1255
1256
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001257/*
1258 * tipc_link_send_sections_fast: Entry for messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001259 * destination processor is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001260 * except for total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001261 * Returns user data length or errno.
1262 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001263int tipc_link_send_sections_fast(struct port *sender,
Per Liden4323add2006-01-18 00:38:21 +01001264 struct iovec const *msg_sect,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001265 const u32 num_sect,
Per Liden4323add2006-01-18 00:38:21 +01001266 u32 destaddr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001267{
1268 struct tipc_msg *hdr = &sender->publ.phdr;
1269 struct link *l_ptr;
1270 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -07001271 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001272 int res;
1273 u32 selector = msg_origport(hdr) & 1;
1274
Per Lidenb97bf3f2006-01-02 19:04:38 +01001275again:
1276 /*
1277 * Try building message using port's max_pkt hint.
1278 * (Must not hold any locks while building message.)
1279 */
1280
Allan Stephens05646c92007-06-10 17:25:24 -07001281 res = msg_build(hdr, msg_sect, num_sect, sender->publ.max_pkt,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001282 !sender->user_port, &buf);
1283
Per Liden4323add2006-01-18 00:38:21 +01001284 read_lock_bh(&tipc_net_lock);
1285 node = tipc_node_select(destaddr, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001286 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001287 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001288 l_ptr = node->active_links[selector];
1289 if (likely(l_ptr)) {
1290 if (likely(buf)) {
1291 res = link_send_buf_fast(l_ptr, buf,
Allan Stephens05646c92007-06-10 17:25:24 -07001292 &sender->publ.max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001293 if (unlikely(res < 0))
1294 buf_discard(buf);
1295exit:
Per Liden4323add2006-01-18 00:38:21 +01001296 tipc_node_unlock(node);
1297 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001298 return res;
1299 }
1300
1301 /* Exit if build request was invalid */
1302
1303 if (unlikely(res < 0))
1304 goto exit;
1305
1306 /* Exit if link (or bearer) is congested */
1307
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001308 if (link_congested(l_ptr) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +01001309 !list_empty(&l_ptr->b_ptr->cong_links)) {
1310 res = link_schedule_port(l_ptr,
1311 sender->publ.ref, res);
1312 goto exit;
1313 }
1314
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001315 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001316 * Message size exceeds max_pkt hint; update hint,
1317 * then re-try fast path or fragment the message
1318 */
1319
Allan Stephens05646c92007-06-10 17:25:24 -07001320 sender->publ.max_pkt = link_max_pkt(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01001321 tipc_node_unlock(node);
1322 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001323
1324
Allan Stephens05646c92007-06-10 17:25:24 -07001325 if ((msg_hdr_sz(hdr) + res) <= sender->publ.max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001326 goto again;
1327
1328 return link_send_sections_long(sender, msg_sect,
1329 num_sect, destaddr);
1330 }
Per Liden4323add2006-01-18 00:38:21 +01001331 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001332 }
Per Liden4323add2006-01-18 00:38:21 +01001333 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001334
1335 /* Couldn't find a link to the destination node */
1336
1337 if (buf)
1338 return tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1339 if (res >= 0)
Per Liden4323add2006-01-18 00:38:21 +01001340 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1341 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001342 return res;
1343}
1344
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001345/*
1346 * link_send_sections_long(): Entry for long messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001347 * destination node is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001348 * inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001349 * Link and bearer congestion status have been checked to be ok,
1350 * and are ignored if they change.
1351 *
1352 * Note that fragments do not use the full link MTU so that they won't have
1353 * to undergo refragmentation if link changeover causes them to be sent
1354 * over another link with an additional tunnel header added as prefix.
1355 * (Refragmentation will still occur if the other link has a smaller MTU.)
1356 *
1357 * Returns user data length or errno.
1358 */
1359static int link_send_sections_long(struct port *sender,
1360 struct iovec const *msg_sect,
1361 u32 num_sect,
1362 u32 destaddr)
1363{
1364 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001365 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001366 struct tipc_msg *hdr = &sender->publ.phdr;
1367 u32 dsz = msg_data_sz(hdr);
1368 u32 max_pkt,fragm_sz,rest;
1369 struct tipc_msg fragm_hdr;
1370 struct sk_buff *buf,*buf_chain,*prev;
1371 u32 fragm_crs,fragm_rest,hsz,sect_rest;
1372 const unchar *sect_crs;
1373 int curr_sect;
1374 u32 fragm_no;
1375
1376again:
1377 fragm_no = 1;
Allan Stephens05646c92007-06-10 17:25:24 -07001378 max_pkt = sender->publ.max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001379 /* leave room for tunnel header in case of link changeover */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001380 fragm_sz = max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001381 /* leave room for fragmentation header in each fragment */
1382 rest = dsz;
1383 fragm_crs = 0;
1384 fragm_rest = 0;
1385 sect_rest = 0;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001386 sect_crs = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001387 curr_sect = -1;
1388
1389 /* Prepare reusable fragment header: */
1390
1391 msg_dbg(hdr, ">FRAGMENTING>");
1392 msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07001393 INT_H_SIZE, msg_destnode(hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001394 msg_set_link_selector(&fragm_hdr, sender->publ.ref);
1395 msg_set_size(&fragm_hdr, max_pkt);
1396 msg_set_fragm_no(&fragm_hdr, 1);
1397
1398 /* Prepare header of first fragment: */
1399
1400 buf_chain = buf = buf_acquire(max_pkt);
1401 if (!buf)
1402 return -ENOMEM;
1403 buf->next = NULL;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001404 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001405 hsz = msg_hdr_sz(hdr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001406 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001407 msg_dbg(buf_msg(buf), ">BUILD>");
1408
1409 /* Chop up message: */
1410
1411 fragm_crs = INT_H_SIZE + hsz;
1412 fragm_rest = fragm_sz - hsz;
1413
1414 do { /* For all sections */
1415 u32 sz;
1416
1417 if (!sect_rest) {
1418 sect_rest = msg_sect[++curr_sect].iov_len;
1419 sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
1420 }
1421
1422 if (sect_rest < fragm_rest)
1423 sz = sect_rest;
1424 else
1425 sz = fragm_rest;
1426
1427 if (likely(!sender->user_port)) {
1428 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
1429error:
1430 for (; buf_chain; buf_chain = buf) {
1431 buf = buf_chain->next;
1432 buf_discard(buf_chain);
1433 }
1434 return -EFAULT;
1435 }
1436 } else
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001437 skb_copy_to_linear_data_offset(buf, fragm_crs,
1438 sect_crs, sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001439 sect_crs += sz;
1440 sect_rest -= sz;
1441 fragm_crs += sz;
1442 fragm_rest -= sz;
1443 rest -= sz;
1444
1445 if (!fragm_rest && rest) {
1446
1447 /* Initiate new fragment: */
1448 if (rest <= fragm_sz) {
1449 fragm_sz = rest;
1450 msg_set_type(&fragm_hdr,LAST_FRAGMENT);
1451 } else {
1452 msg_set_type(&fragm_hdr, FRAGMENT);
1453 }
1454 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
1455 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
1456 prev = buf;
1457 buf = buf_acquire(fragm_sz + INT_H_SIZE);
1458 if (!buf)
1459 goto error;
1460
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001461 buf->next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001462 prev->next = buf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001463 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001464 fragm_crs = INT_H_SIZE;
1465 fragm_rest = fragm_sz;
1466 msg_dbg(buf_msg(buf)," >BUILD>");
1467 }
1468 }
1469 while (rest > 0);
1470
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001471 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001472 * Now we have a buffer chain. Select a link and check
1473 * that packet size is still OK
1474 */
Per Liden4323add2006-01-18 00:38:21 +01001475 node = tipc_node_select(destaddr, sender->publ.ref & 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001476 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001477 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001478 l_ptr = node->active_links[sender->publ.ref & 1];
1479 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001480 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001481 goto reject;
1482 }
1483 if (link_max_pkt(l_ptr) < max_pkt) {
Allan Stephens05646c92007-06-10 17:25:24 -07001484 sender->publ.max_pkt = link_max_pkt(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01001485 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001486 for (; buf_chain; buf_chain = buf) {
1487 buf = buf_chain->next;
1488 buf_discard(buf_chain);
1489 }
1490 goto again;
1491 }
1492 } else {
1493reject:
1494 for (; buf_chain; buf_chain = buf) {
1495 buf = buf_chain->next;
1496 buf_discard(buf_chain);
1497 }
Per Liden4323add2006-01-18 00:38:21 +01001498 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1499 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001500 }
1501
1502 /* Append whole chain to send queue: */
1503
1504 buf = buf_chain;
1505 l_ptr->long_msg_seq_no = mod(l_ptr->long_msg_seq_no + 1);
1506 if (!l_ptr->next_out)
1507 l_ptr->next_out = buf_chain;
1508 l_ptr->stats.sent_fragmented++;
1509 while (buf) {
1510 struct sk_buff *next = buf->next;
1511 struct tipc_msg *msg = buf_msg(buf);
1512
1513 l_ptr->stats.sent_fragments++;
1514 msg_set_long_msgno(msg, l_ptr->long_msg_seq_no);
1515 link_add_to_outqueue(l_ptr, buf, msg);
1516 msg_dbg(msg, ">ADD>");
1517 buf = next;
1518 }
1519
1520 /* Send it, if possible: */
1521
Per Liden4323add2006-01-18 00:38:21 +01001522 tipc_link_push_queue(l_ptr);
1523 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001524 return dsz;
1525}
1526
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001527/*
Per Liden4323add2006-01-18 00:38:21 +01001528 * tipc_link_push_packet: Push one unsent packet to the media
Per Lidenb97bf3f2006-01-02 19:04:38 +01001529 */
Per Liden4323add2006-01-18 00:38:21 +01001530u32 tipc_link_push_packet(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001531{
1532 struct sk_buff *buf = l_ptr->first_out;
1533 u32 r_q_size = l_ptr->retransm_queue_size;
1534 u32 r_q_head = l_ptr->retransm_queue_head;
1535
1536 /* Step to position where retransmission failed, if any, */
1537 /* consider that buffers may have been released in meantime */
1538
1539 if (r_q_size && buf) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001540 u32 last = lesser(mod(r_q_head + r_q_size),
Per Lidenb97bf3f2006-01-02 19:04:38 +01001541 link_last_sent(l_ptr));
1542 u32 first = msg_seqno(buf_msg(buf));
1543
1544 while (buf && less(first, r_q_head)) {
1545 first = mod(first + 1);
1546 buf = buf->next;
1547 }
1548 l_ptr->retransm_queue_head = r_q_head = first;
1549 l_ptr->retransm_queue_size = r_q_size = mod(last - first);
1550 }
1551
1552 /* Continue retransmission now, if there is anything: */
1553
Neil Hormanca509102010-03-15 07:58:45 +00001554 if (r_q_size && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001555 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001556 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001557 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001558 msg_dbg(buf_msg(buf), ">DEF-RETR>");
1559 l_ptr->retransm_queue_head = mod(++r_q_head);
1560 l_ptr->retransm_queue_size = --r_q_size;
1561 l_ptr->stats.retransmitted++;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001562 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001563 } else {
1564 l_ptr->stats.bearer_congs++;
1565 msg_dbg(buf_msg(buf), "|>DEF-RETR>");
1566 return PUSH_FAILED;
1567 }
1568 }
1569
1570 /* Send deferred protocol message, if any: */
1571
1572 buf = l_ptr->proto_msg_queue;
1573 if (buf) {
1574 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001575 msg_set_bcast_ack(buf_msg(buf),l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001576 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001577 msg_dbg(buf_msg(buf), ">DEF-PROT>");
1578 l_ptr->unacked_window = 0;
1579 buf_discard(buf);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001580 l_ptr->proto_msg_queue = NULL;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001581 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001582 } else {
1583 msg_dbg(buf_msg(buf), "|>DEF-PROT>");
1584 l_ptr->stats.bearer_congs++;
1585 return PUSH_FAILED;
1586 }
1587 }
1588
1589 /* Send one deferred data message, if send window not full: */
1590
1591 buf = l_ptr->next_out;
1592 if (buf) {
1593 struct tipc_msg *msg = buf_msg(buf);
1594 u32 next = msg_seqno(msg);
1595 u32 first = msg_seqno(buf_msg(l_ptr->first_out));
1596
1597 if (mod(next - first) < l_ptr->queue_limit[0]) {
1598 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001599 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001600 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001601 if (msg_user(msg) == MSG_BUNDLER)
1602 msg_set_type(msg, CLOSED_MSG);
1603 msg_dbg(msg, ">PUSH-DATA>");
1604 l_ptr->next_out = buf->next;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001605 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001606 } else {
1607 msg_dbg(msg, "|PUSH-DATA|");
1608 l_ptr->stats.bearer_congs++;
1609 return PUSH_FAILED;
1610 }
1611 }
1612 }
1613 return PUSH_FINISHED;
1614}
1615
1616/*
1617 * push_queue(): push out the unsent messages of a link where
1618 * congestion has abated. Node is locked
1619 */
Per Liden4323add2006-01-18 00:38:21 +01001620void tipc_link_push_queue(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001621{
1622 u32 res;
1623
Per Liden4323add2006-01-18 00:38:21 +01001624 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001625 return;
1626
1627 do {
Per Liden4323add2006-01-18 00:38:21 +01001628 res = tipc_link_push_packet(l_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -07001629 } while (!res);
1630
Per Lidenb97bf3f2006-01-02 19:04:38 +01001631 if (res == PUSH_FAILED)
Per Liden4323add2006-01-18 00:38:21 +01001632 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001633}
1634
Allan Stephensd356eeb2006-06-25 23:40:01 -07001635static void link_reset_all(unsigned long addr)
1636{
David S. Miller6c000552008-09-02 23:38:32 -07001637 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001638 char addr_string[16];
1639 u32 i;
1640
1641 read_lock_bh(&tipc_net_lock);
1642 n_ptr = tipc_node_find((u32)addr);
1643 if (!n_ptr) {
1644 read_unlock_bh(&tipc_net_lock);
1645 return; /* node no longer exists */
1646 }
1647
1648 tipc_node_lock(n_ptr);
1649
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001650 warn("Resetting all links to %s\n",
Allan Stephensd356eeb2006-06-25 23:40:01 -07001651 addr_string_fill(addr_string, n_ptr->addr));
1652
1653 for (i = 0; i < MAX_BEARERS; i++) {
1654 if (n_ptr->links[i]) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001655 link_print(n_ptr->links[i], TIPC_OUTPUT,
Allan Stephensd356eeb2006-06-25 23:40:01 -07001656 "Resetting link\n");
1657 tipc_link_reset(n_ptr->links[i]);
1658 }
1659 }
1660
1661 tipc_node_unlock(n_ptr);
1662 read_unlock_bh(&tipc_net_lock);
1663}
1664
1665static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf)
1666{
1667 struct tipc_msg *msg = buf_msg(buf);
1668
1669 warn("Retransmission failure on link <%s>\n", l_ptr->name);
Allan Stephens48c97132008-05-05 01:24:06 -07001670 tipc_msg_dbg(TIPC_OUTPUT, msg, ">RETR-FAIL>");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001671
1672 if (l_ptr->addr) {
1673
1674 /* Handle failure on standard link */
1675
1676 link_print(l_ptr, TIPC_OUTPUT, "Resetting link\n");
1677 tipc_link_reset(l_ptr);
1678
1679 } else {
1680
1681 /* Handle failure on broadcast link */
1682
David S. Miller6c000552008-09-02 23:38:32 -07001683 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001684 char addr_string[16];
1685
1686 tipc_printf(TIPC_OUTPUT, "Msg seq number: %u, ", msg_seqno(msg));
Jeff Garzik617dbea2006-10-03 16:25:34 -07001687 tipc_printf(TIPC_OUTPUT, "Outstanding acks: %lu\n",
1688 (unsigned long) TIPC_SKB_CB(buf)->handle);
1689
Allan Stephensd356eeb2006-06-25 23:40:01 -07001690 n_ptr = l_ptr->owner->next;
1691 tipc_node_lock(n_ptr);
1692
1693 addr_string_fill(addr_string, n_ptr->addr);
1694 tipc_printf(TIPC_OUTPUT, "Multicast link info for %s\n", addr_string);
1695 tipc_printf(TIPC_OUTPUT, "Supported: %d, ", n_ptr->bclink.supported);
1696 tipc_printf(TIPC_OUTPUT, "Acked: %u\n", n_ptr->bclink.acked);
1697 tipc_printf(TIPC_OUTPUT, "Last in: %u, ", n_ptr->bclink.last_in);
1698 tipc_printf(TIPC_OUTPUT, "Gap after: %u, ", n_ptr->bclink.gap_after);
1699 tipc_printf(TIPC_OUTPUT, "Gap to: %u\n", n_ptr->bclink.gap_to);
1700 tipc_printf(TIPC_OUTPUT, "Nack sync: %u\n\n", n_ptr->bclink.nack_sync);
1701
1702 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
1703
1704 tipc_node_unlock(n_ptr);
1705
1706 l_ptr->stale_count = 0;
1707 }
1708}
1709
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001710void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf,
Per Liden4323add2006-01-18 00:38:21 +01001711 u32 retransmits)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001712{
1713 struct tipc_msg *msg;
1714
Allan Stephensd356eeb2006-06-25 23:40:01 -07001715 if (!buf)
1716 return;
1717
1718 msg = buf_msg(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001719
Per Lidenb97bf3f2006-01-02 19:04:38 +01001720 dbg("Retransmitting %u in link %x\n", retransmits, l_ptr);
1721
Allan Stephensd356eeb2006-06-25 23:40:01 -07001722 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Neil Hormanca509102010-03-15 07:58:45 +00001723 if (l_ptr->retransm_queue_size == 0) {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001724 msg_dbg(msg, ">NO_RETR->BCONG>");
1725 dbg_print_link(l_ptr, " ");
1726 l_ptr->retransm_queue_head = msg_seqno(msg);
1727 l_ptr->retransm_queue_size = retransmits;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001728 } else {
Neil Hormanca509102010-03-15 07:58:45 +00001729 err("Unexpected retransmit on link %s (qsize=%d)\n",
1730 l_ptr->name, l_ptr->retransm_queue_size);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001731 }
Neil Hormanca509102010-03-15 07:58:45 +00001732 return;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001733 } else {
1734 /* Detect repeated retransmit failures on uncongested bearer */
1735
1736 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1737 if (++l_ptr->stale_count > 100) {
1738 link_retransmit_failure(l_ptr, buf);
1739 return;
1740 }
1741 } else {
1742 l_ptr->last_retransmitted = msg_seqno(msg);
1743 l_ptr->stale_count = 1;
1744 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001745 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001746
Neil Hormanca509102010-03-15 07:58:45 +00001747 while (retransmits && (buf != l_ptr->next_out) && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001748 msg = buf_msg(buf);
1749 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001750 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001751 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001752 msg_dbg(buf_msg(buf), ">RETR>");
1753 buf = buf->next;
1754 retransmits--;
1755 l_ptr->stats.retransmitted++;
1756 } else {
Per Liden4323add2006-01-18 00:38:21 +01001757 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001758 l_ptr->stats.bearer_congs++;
1759 l_ptr->retransm_queue_head = msg_seqno(buf_msg(buf));
1760 l_ptr->retransm_queue_size = retransmits;
1761 return;
1762 }
1763 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001764
Per Lidenb97bf3f2006-01-02 19:04:38 +01001765 l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
1766}
1767
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001768/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01001769 * link_insert_deferred_queue - insert deferred messages back into receive chain
1770 */
1771
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001772static struct sk_buff *link_insert_deferred_queue(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001773 struct sk_buff *buf)
1774{
1775 u32 seq_no;
1776
1777 if (l_ptr->oldest_deferred_in == NULL)
1778 return buf;
1779
1780 seq_no = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
1781 if (seq_no == mod(l_ptr->next_in_no)) {
1782 l_ptr->newest_deferred_in->next = buf;
1783 buf = l_ptr->oldest_deferred_in;
1784 l_ptr->oldest_deferred_in = NULL;
1785 l_ptr->deferred_inqueue_sz = 0;
1786 }
1787 return buf;
1788}
1789
Allan Stephens85035562008-04-15 19:04:54 -07001790/**
1791 * link_recv_buf_validate - validate basic format of received message
1792 *
1793 * This routine ensures a TIPC message has an acceptable header, and at least
1794 * as much data as the header indicates it should. The routine also ensures
1795 * that the entire message header is stored in the main fragment of the message
1796 * buffer, to simplify future access to message header fields.
1797 *
1798 * Note: Having extra info present in the message header or data areas is OK.
1799 * TIPC will ignore the excess, under the assumption that it is optional info
1800 * introduced by a later release of the protocol.
1801 */
1802
1803static int link_recv_buf_validate(struct sk_buff *buf)
1804{
1805 static u32 min_data_hdr_size[8] = {
1806 SHORT_H_SIZE, MCAST_H_SIZE, LONG_H_SIZE, DIR_MSG_H_SIZE,
1807 MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
1808 };
1809
1810 struct tipc_msg *msg;
1811 u32 tipc_hdr[2];
1812 u32 size;
1813 u32 hdr_size;
1814 u32 min_hdr_size;
1815
1816 if (unlikely(buf->len < MIN_H_SIZE))
1817 return 0;
1818
1819 msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
1820 if (msg == NULL)
1821 return 0;
1822
1823 if (unlikely(msg_version(msg) != TIPC_VERSION))
1824 return 0;
1825
1826 size = msg_size(msg);
1827 hdr_size = msg_hdr_sz(msg);
1828 min_hdr_size = msg_isdata(msg) ?
1829 min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
1830
1831 if (unlikely((hdr_size < min_hdr_size) ||
1832 (size < hdr_size) ||
1833 (buf->len < size) ||
1834 (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
1835 return 0;
1836
1837 return pskb_may_pull(buf, hdr_size);
1838}
1839
Per Lidenb97bf3f2006-01-02 19:04:38 +01001840void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *tb_ptr)
1841{
Per Liden4323add2006-01-18 00:38:21 +01001842 read_lock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001843 while (head) {
Allan Stephens1265a022008-06-04 17:32:35 -07001844 struct bearer *b_ptr = (struct bearer *)tb_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001845 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001846 struct link *l_ptr;
1847 struct sk_buff *crs;
1848 struct sk_buff *buf = head;
Allan Stephens85035562008-04-15 19:04:54 -07001849 struct tipc_msg *msg;
1850 u32 seq_no;
1851 u32 ackd;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001852 u32 released = 0;
1853 int type;
1854
Per Lidenb97bf3f2006-01-02 19:04:38 +01001855 head = head->next;
Allan Stephens85035562008-04-15 19:04:54 -07001856
1857 /* Ensure message is well-formed */
1858
1859 if (unlikely(!link_recv_buf_validate(buf)))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001860 goto cont;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001861
Allan Stephensfe13dda2008-04-15 19:03:23 -07001862 /* Ensure message data is a single contiguous unit */
1863
1864 if (unlikely(buf_linearize(buf))) {
1865 goto cont;
1866 }
1867
Allan Stephens85035562008-04-15 19:04:54 -07001868 /* Handle arrival of a non-unicast link message */
1869
1870 msg = buf_msg(buf);
1871
Per Lidenb97bf3f2006-01-02 19:04:38 +01001872 if (unlikely(msg_non_seq(msg))) {
Allan Stephens1265a022008-06-04 17:32:35 -07001873 if (msg_user(msg) == LINK_CONFIG)
1874 tipc_disc_recv_msg(buf, b_ptr);
1875 else
1876 tipc_bclink_recv_pkt(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001877 continue;
1878 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001879
Allan Stephens26008242006-06-25 23:39:31 -07001880 if (unlikely(!msg_short(msg) &&
1881 (msg_destnode(msg) != tipc_own_addr)))
1882 goto cont;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001883
Neil Hormande586572010-03-08 12:43:56 -08001884 /* Discard non-routeable messages destined for another node */
1885
1886 if (unlikely(!msg_isdata(msg) &&
1887 (msg_destnode(msg) != tipc_own_addr))) {
1888 if ((msg_user(msg) != CONN_MANAGER) &&
1889 (msg_user(msg) != MSG_FRAGMENTER))
1890 goto cont;
1891 }
1892
Allan Stephens85035562008-04-15 19:04:54 -07001893 /* Locate unicast link endpoint that should handle message */
1894
Per Liden4323add2006-01-18 00:38:21 +01001895 n_ptr = tipc_node_find(msg_prevnode(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001896 if (unlikely(!n_ptr))
1897 goto cont;
Per Liden4323add2006-01-18 00:38:21 +01001898 tipc_node_lock(n_ptr);
Allan Stephens85035562008-04-15 19:04:54 -07001899
Per Lidenb97bf3f2006-01-02 19:04:38 +01001900 l_ptr = n_ptr->links[b_ptr->identity];
1901 if (unlikely(!l_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001902 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001903 goto cont;
1904 }
Allan Stephens85035562008-04-15 19:04:54 -07001905
1906 /* Validate message sequence number info */
1907
1908 seq_no = msg_seqno(msg);
1909 ackd = msg_ack(msg);
1910
1911 /* Release acked messages */
1912
Per Lidenb97bf3f2006-01-02 19:04:38 +01001913 if (less(n_ptr->bclink.acked, msg_bcast_ack(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001914 if (tipc_node_is_up(n_ptr) && n_ptr->bclink.supported)
1915 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001916 }
1917
1918 crs = l_ptr->first_out;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001919 while ((crs != l_ptr->next_out) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001920 less_eq(msg_seqno(buf_msg(crs)), ackd)) {
1921 struct sk_buff *next = crs->next;
1922
1923 buf_discard(crs);
1924 crs = next;
1925 released++;
1926 }
1927 if (released) {
1928 l_ptr->first_out = crs;
1929 l_ptr->out_queue_size -= released;
1930 }
Allan Stephens85035562008-04-15 19:04:54 -07001931
1932 /* Try sending any messages link endpoint has pending */
1933
Per Lidenb97bf3f2006-01-02 19:04:38 +01001934 if (unlikely(l_ptr->next_out))
Per Liden4323add2006-01-18 00:38:21 +01001935 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001936 if (unlikely(!list_empty(&l_ptr->waiting_ports)))
Per Liden4323add2006-01-18 00:38:21 +01001937 tipc_link_wakeup_ports(l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001938 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1939 l_ptr->stats.sent_acks++;
Per Liden4323add2006-01-18 00:38:21 +01001940 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001941 }
1942
Allan Stephens85035562008-04-15 19:04:54 -07001943 /* Now (finally!) process the incoming message */
1944
Per Lidenb97bf3f2006-01-02 19:04:38 +01001945protocol_check:
1946 if (likely(link_working_working(l_ptr))) {
1947 if (likely(seq_no == mod(l_ptr->next_in_no))) {
1948 l_ptr->next_in_no++;
1949 if (unlikely(l_ptr->oldest_deferred_in))
1950 head = link_insert_deferred_queue(l_ptr,
1951 head);
1952 if (likely(msg_is_dest(msg, tipc_own_addr))) {
1953deliver:
1954 if (likely(msg_isdata(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001955 tipc_node_unlock(n_ptr);
1956 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001957 continue;
1958 }
1959 switch (msg_user(msg)) {
1960 case MSG_BUNDLER:
1961 l_ptr->stats.recv_bundles++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001962 l_ptr->stats.recv_bundled +=
Per Lidenb97bf3f2006-01-02 19:04:38 +01001963 msg_msgcnt(msg);
Per Liden4323add2006-01-18 00:38:21 +01001964 tipc_node_unlock(n_ptr);
1965 tipc_link_recv_bundle(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001966 continue;
1967 case ROUTE_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001968 tipc_node_unlock(n_ptr);
1969 tipc_cltr_recv_routing_table(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001970 continue;
1971 case NAME_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001972 tipc_node_unlock(n_ptr);
1973 tipc_named_recv(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001974 continue;
1975 case CONN_MANAGER:
Per Liden4323add2006-01-18 00:38:21 +01001976 tipc_node_unlock(n_ptr);
1977 tipc_port_recv_proto_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001978 continue;
1979 case MSG_FRAGMENTER:
1980 l_ptr->stats.recv_fragments++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001981 if (tipc_link_recv_fragment(&l_ptr->defragm_buf,
Per Liden4323add2006-01-18 00:38:21 +01001982 &buf, &msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001983 l_ptr->stats.recv_fragmented++;
1984 goto deliver;
1985 }
1986 break;
1987 case CHANGEOVER_PROTOCOL:
1988 type = msg_type(msg);
Per Liden4323add2006-01-18 00:38:21 +01001989 if (link_recv_changeover_msg(&l_ptr, &buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001990 msg = buf_msg(buf);
1991 seq_no = msg_seqno(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001992 if (type == ORIGINAL_MSG)
1993 goto deliver;
1994 goto protocol_check;
1995 }
1996 break;
1997 }
1998 }
Per Liden4323add2006-01-18 00:38:21 +01001999 tipc_node_unlock(n_ptr);
2000 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002001 continue;
2002 }
2003 link_handle_out_of_seq_msg(l_ptr, buf);
2004 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01002005 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002006 continue;
2007 }
2008
2009 if (msg_user(msg) == LINK_PROTOCOL) {
2010 link_recv_proto_msg(l_ptr, buf);
2011 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01002012 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002013 continue;
2014 }
2015 msg_dbg(msg,"NSEQ<REC<");
2016 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
2017
2018 if (link_working_working(l_ptr)) {
2019 /* Re-insert in front of queue */
2020 msg_dbg(msg,"RECV-REINS:");
2021 buf->next = head;
2022 head = buf;
Per Liden4323add2006-01-18 00:38:21 +01002023 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002024 continue;
2025 }
Per Liden4323add2006-01-18 00:38:21 +01002026 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002027cont:
2028 buf_discard(buf);
2029 }
Per Liden4323add2006-01-18 00:38:21 +01002030 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002031}
2032
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002033/*
2034 * link_defer_buf(): Sort a received out-of-sequence packet
Per Lidenb97bf3f2006-01-02 19:04:38 +01002035 * into the deferred reception queue.
2036 * Returns the increase of the queue length,i.e. 0 or 1
2037 */
2038
Per Liden4323add2006-01-18 00:38:21 +01002039u32 tipc_link_defer_pkt(struct sk_buff **head,
2040 struct sk_buff **tail,
2041 struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002042{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002043 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002044 struct sk_buff *crs = *head;
2045 u32 seq_no = msg_seqno(buf_msg(buf));
2046
2047 buf->next = NULL;
2048
2049 /* Empty queue ? */
2050 if (*head == NULL) {
2051 *head = *tail = buf;
2052 return 1;
2053 }
2054
2055 /* Last ? */
2056 if (less(msg_seqno(buf_msg(*tail)), seq_no)) {
2057 (*tail)->next = buf;
2058 *tail = buf;
2059 return 1;
2060 }
2061
2062 /* Scan through queue and sort it in */
2063 do {
2064 struct tipc_msg *msg = buf_msg(crs);
2065
2066 if (less(seq_no, msg_seqno(msg))) {
2067 buf->next = crs;
2068 if (prev)
2069 prev->next = buf;
2070 else
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002071 *head = buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002072 return 1;
2073 }
2074 if (seq_no == msg_seqno(msg)) {
2075 break;
2076 }
2077 prev = crs;
2078 crs = crs->next;
2079 }
2080 while (crs);
2081
2082 /* Message is a duplicate of an existing message */
2083
2084 buf_discard(buf);
2085 return 0;
2086}
2087
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002088/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01002089 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
2090 */
2091
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002092static void link_handle_out_of_seq_msg(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002093 struct sk_buff *buf)
2094{
2095 u32 seq_no = msg_seqno(buf_msg(buf));
2096
2097 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
2098 link_recv_proto_msg(l_ptr, buf);
2099 return;
2100 }
2101
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002102 dbg("rx OOS msg: seq_no %u, expecting %u (%u)\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002103 seq_no, mod(l_ptr->next_in_no), l_ptr->next_in_no);
2104
2105 /* Record OOS packet arrival (force mismatch on next timeout) */
2106
2107 l_ptr->checkpoint--;
2108
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002109 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002110 * Discard packet if a duplicate; otherwise add it to deferred queue
2111 * and notify peer of gap as per protocol specification
2112 */
2113
2114 if (less(seq_no, mod(l_ptr->next_in_no))) {
2115 l_ptr->stats.duplicates++;
2116 buf_discard(buf);
2117 return;
2118 }
2119
Per Liden4323add2006-01-18 00:38:21 +01002120 if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
2121 &l_ptr->newest_deferred_in, buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002122 l_ptr->deferred_inqueue_sz++;
2123 l_ptr->stats.deferred_recv++;
2124 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
Per Liden4323add2006-01-18 00:38:21 +01002125 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002126 } else
2127 l_ptr->stats.duplicates++;
2128}
2129
2130/*
2131 * Send protocol message to the other endpoint.
2132 */
Per Liden4323add2006-01-18 00:38:21 +01002133void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
2134 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002135{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002136 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002137 struct tipc_msg *msg = l_ptr->pmsg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002138 u32 msg_size = sizeof(l_ptr->proto_msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002139
2140 if (link_blocked(l_ptr))
2141 return;
2142 msg_set_type(msg, msg_typ);
2143 msg_set_net_plane(msg, l_ptr->b_ptr->net_plane);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002144 msg_set_bcast_ack(msg, mod(l_ptr->owner->bclink.last_in));
Per Liden4323add2006-01-18 00:38:21 +01002145 msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
Per Lidenb97bf3f2006-01-02 19:04:38 +01002146
2147 if (msg_typ == STATE_MSG) {
2148 u32 next_sent = mod(l_ptr->next_out_no);
2149
Per Liden4323add2006-01-18 00:38:21 +01002150 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002151 return;
2152 if (l_ptr->next_out)
2153 next_sent = msg_seqno(buf_msg(l_ptr->next_out));
2154 msg_set_next_sent(msg, next_sent);
2155 if (l_ptr->oldest_deferred_in) {
2156 u32 rec = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
2157 gap = mod(rec - mod(l_ptr->next_in_no));
2158 }
2159 msg_set_seq_gap(msg, gap);
2160 if (gap)
2161 l_ptr->stats.sent_nacks++;
2162 msg_set_link_tolerance(msg, tolerance);
2163 msg_set_linkprio(msg, priority);
2164 msg_set_max_pkt(msg, ack_mtu);
2165 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
2166 msg_set_probe(msg, probe_msg != 0);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002167 if (probe_msg) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002168 u32 mtu = l_ptr->max_pkt;
2169
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002170 if ((mtu < l_ptr->max_pkt_target) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002171 link_working_working(l_ptr) &&
2172 l_ptr->fsm_msg_cnt) {
2173 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002174 if (l_ptr->max_pkt_probes == 10) {
2175 l_ptr->max_pkt_target = (msg_size - 4);
2176 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002177 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002178 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002179 l_ptr->max_pkt_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002180 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002181
2182 l_ptr->stats.sent_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002183 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002184 l_ptr->stats.sent_states++;
2185 } else { /* RESET_MSG or ACTIVATE_MSG */
2186 msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
2187 msg_set_seq_gap(msg, 0);
2188 msg_set_next_sent(msg, 1);
2189 msg_set_link_tolerance(msg, l_ptr->tolerance);
2190 msg_set_linkprio(msg, l_ptr->priority);
2191 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
2192 }
2193
Per Liden4323add2006-01-18 00:38:21 +01002194 if (tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002195 msg_set_redundant_link(msg);
2196 } else {
2197 msg_clear_redundant_link(msg);
2198 }
2199 msg_set_linkprio(msg, l_ptr->priority);
2200
2201 /* Ensure sequence number will not fit : */
2202
2203 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
2204
2205 /* Congestion? */
2206
Per Liden4323add2006-01-18 00:38:21 +01002207 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002208 if (!l_ptr->proto_msg_queue) {
2209 l_ptr->proto_msg_queue =
2210 buf_acquire(sizeof(l_ptr->proto_msg));
2211 }
2212 buf = l_ptr->proto_msg_queue;
2213 if (!buf)
2214 return;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002215 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002216 return;
2217 }
2218 msg_set_timestamp(msg, jiffies_to_msecs(jiffies));
2219
2220 /* Message can be sent */
2221
2222 msg_dbg(msg, ">>");
2223
2224 buf = buf_acquire(msg_size);
2225 if (!buf)
2226 return;
2227
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002228 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002229 msg_set_size(buf_msg(buf), msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002230
Per Liden4323add2006-01-18 00:38:21 +01002231 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002232 l_ptr->unacked_window = 0;
2233 buf_discard(buf);
2234 return;
2235 }
2236
2237 /* New congestion */
Per Liden4323add2006-01-18 00:38:21 +01002238 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002239 l_ptr->proto_msg_queue = buf;
2240 l_ptr->stats.bearer_congs++;
2241}
2242
2243/*
2244 * Receive protocol message :
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002245 * Note that network plane id propagates through the network, and may
2246 * change at any time. The node with lowest address rules
Per Lidenb97bf3f2006-01-02 19:04:38 +01002247 */
2248
2249static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2250{
2251 u32 rec_gap = 0;
2252 u32 max_pkt_info;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002253 u32 max_pkt_ack;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002254 u32 msg_tol;
2255 struct tipc_msg *msg = buf_msg(buf);
2256
2257 dbg("AT(%u):", jiffies_to_msecs(jiffies));
2258 msg_dbg(msg, "<<");
2259 if (link_blocked(l_ptr))
2260 goto exit;
2261
2262 /* record unnumbered packet arrival (force mismatch on next timeout) */
2263
2264 l_ptr->checkpoint--;
2265
2266 if (l_ptr->b_ptr->net_plane != msg_net_plane(msg))
2267 if (tipc_own_addr > msg_prevnode(msg))
2268 l_ptr->b_ptr->net_plane = msg_net_plane(msg);
2269
2270 l_ptr->owner->permit_changeover = msg_redundant_link(msg);
2271
2272 switch (msg_type(msg)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002273
Per Lidenb97bf3f2006-01-02 19:04:38 +01002274 case RESET_MSG:
Allan Stephensa686e682008-06-04 17:29:39 -07002275 if (!link_working_unknown(l_ptr) &&
2276 (l_ptr->peer_session != INVALID_SESSION)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002277 if (msg_session(msg) == l_ptr->peer_session) {
2278 dbg("Duplicate RESET: %u<->%u\n",
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002279 msg_session(msg), l_ptr->peer_session);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002280 break; /* duplicate: ignore */
2281 }
2282 }
2283 /* fall thru' */
2284 case ACTIVATE_MSG:
2285 /* Update link settings according other endpoint's values */
2286
2287 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
2288
2289 if ((msg_tol = msg_link_tolerance(msg)) &&
2290 (msg_tol > l_ptr->tolerance))
2291 link_set_supervision_props(l_ptr, msg_tol);
2292
2293 if (msg_linkprio(msg) > l_ptr->priority)
2294 l_ptr->priority = msg_linkprio(msg);
2295
2296 max_pkt_info = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002297 if (max_pkt_info) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002298 if (max_pkt_info < l_ptr->max_pkt_target)
2299 l_ptr->max_pkt_target = max_pkt_info;
2300 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
2301 l_ptr->max_pkt = l_ptr->max_pkt_target;
2302 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002303 l_ptr->max_pkt = l_ptr->max_pkt_target;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002304 }
2305 l_ptr->owner->bclink.supported = (max_pkt_info != 0);
2306
2307 link_state_event(l_ptr, msg_type(msg));
2308
2309 l_ptr->peer_session = msg_session(msg);
2310 l_ptr->peer_bearer_id = msg_bearer_id(msg);
2311
2312 /* Synchronize broadcast sequence numbers */
Per Liden4323add2006-01-18 00:38:21 +01002313 if (!tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002314 l_ptr->owner->bclink.last_in = mod(msg_last_bcast(msg));
2315 }
2316 break;
2317 case STATE_MSG:
2318
2319 if ((msg_tol = msg_link_tolerance(msg)))
2320 link_set_supervision_props(l_ptr, msg_tol);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002321
2322 if (msg_linkprio(msg) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002323 (msg_linkprio(msg) != l_ptr->priority)) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002324 warn("Resetting link <%s>, priority change %u->%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002325 l_ptr->name, l_ptr->priority, msg_linkprio(msg));
2326 l_ptr->priority = msg_linkprio(msg);
Per Liden4323add2006-01-18 00:38:21 +01002327 tipc_link_reset(l_ptr); /* Enforce change to take effect */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002328 break;
2329 }
2330 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
2331 l_ptr->stats.recv_states++;
2332 if (link_reset_unknown(l_ptr))
2333 break;
2334
2335 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002336 rec_gap = mod(msg_next_sent(msg) -
Per Lidenb97bf3f2006-01-02 19:04:38 +01002337 mod(l_ptr->next_in_no));
2338 }
2339
2340 max_pkt_ack = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002341 if (max_pkt_ack > l_ptr->max_pkt) {
2342 dbg("Link <%s> updated MTU %u -> %u\n",
2343 l_ptr->name, l_ptr->max_pkt, max_pkt_ack);
2344 l_ptr->max_pkt = max_pkt_ack;
2345 l_ptr->max_pkt_probes = 0;
2346 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002347
2348 max_pkt_ack = 0;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002349 if (msg_probe(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002350 l_ptr->stats.recv_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002351 if (msg_size(msg) > sizeof(l_ptr->proto_msg)) {
2352 max_pkt_ack = msg_size(msg);
2353 }
2354 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002355
2356 /* Protocol message before retransmits, reduce loss risk */
2357
Per Liden4323add2006-01-18 00:38:21 +01002358 tipc_bclink_check_gap(l_ptr->owner, msg_last_bcast(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002359
2360 if (rec_gap || (msg_probe(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01002361 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2362 0, rec_gap, 0, 0, max_pkt_ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002363 }
2364 if (msg_seq_gap(msg)) {
2365 msg_dbg(msg, "With Gap:");
2366 l_ptr->stats.recv_nacks++;
Per Liden4323add2006-01-18 00:38:21 +01002367 tipc_link_retransmit(l_ptr, l_ptr->first_out,
2368 msg_seq_gap(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002369 }
2370 break;
2371 default:
2372 msg_dbg(buf_msg(buf), "<DISCARDING UNKNOWN<");
2373 }
2374exit:
2375 buf_discard(buf);
2376}
2377
2378
2379/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002380 * tipc_link_tunnel(): Send one message via a link belonging to
Per Lidenb97bf3f2006-01-02 19:04:38 +01002381 * another bearer. Owner node is locked.
2382 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002383void tipc_link_tunnel(struct link *l_ptr,
2384 struct tipc_msg *tunnel_hdr,
Per Liden4323add2006-01-18 00:38:21 +01002385 struct tipc_msg *msg,
2386 u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002387{
2388 struct link *tunnel;
2389 struct sk_buff *buf;
2390 u32 length = msg_size(msg);
2391
2392 tunnel = l_ptr->owner->active_links[selector & 1];
Allan Stephens5392d642006-06-25 23:52:50 -07002393 if (!tipc_link_is_up(tunnel)) {
2394 warn("Link changeover error, "
2395 "tunnel link no longer available\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002396 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002397 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002398 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
2399 buf = buf_acquire(length + INT_H_SIZE);
Allan Stephens5392d642006-06-25 23:52:50 -07002400 if (!buf) {
2401 warn("Link changeover error, "
2402 "unable to send tunnel msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002403 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002404 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002405 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
2406 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002407 dbg("%c->%c:", l_ptr->b_ptr->net_plane, tunnel->b_ptr->net_plane);
2408 msg_dbg(buf_msg(buf), ">SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002409 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002410}
2411
2412
2413
2414/*
2415 * changeover(): Send whole message queue via the remaining link
2416 * Owner node is locked.
2417 */
2418
Per Liden4323add2006-01-18 00:38:21 +01002419void tipc_link_changeover(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002420{
2421 u32 msgcount = l_ptr->out_queue_size;
2422 struct sk_buff *crs = l_ptr->first_out;
2423 struct link *tunnel = l_ptr->owner->active_links[0];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002424 struct tipc_msg tunnel_hdr;
Allan Stephens5392d642006-06-25 23:52:50 -07002425 int split_bundles;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002426
2427 if (!tunnel)
2428 return;
2429
Allan Stephens5392d642006-06-25 23:52:50 -07002430 if (!l_ptr->owner->permit_changeover) {
2431 warn("Link changeover error, "
2432 "peer did not permit changeover\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002433 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002434 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002435
2436 msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002437 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002438 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2439 msg_set_msgcnt(&tunnel_hdr, msgcount);
Allan Stephens5392d642006-06-25 23:52:50 -07002440 dbg("Link changeover requires %u tunnel messages\n", msgcount);
Allan Stephensf1310722006-06-25 23:51:37 -07002441
Per Lidenb97bf3f2006-01-02 19:04:38 +01002442 if (!l_ptr->first_out) {
2443 struct sk_buff *buf;
2444
Per Lidenb97bf3f2006-01-02 19:04:38 +01002445 buf = buf_acquire(INT_H_SIZE);
2446 if (buf) {
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002447 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002448 msg_set_size(&tunnel_hdr, INT_H_SIZE);
2449 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2450 tunnel->b_ptr->net_plane);
2451 msg_dbg(&tunnel_hdr, "EMPTY>SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002452 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002453 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002454 warn("Link changeover error, "
2455 "unable to send changeover msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002456 }
2457 return;
2458 }
Allan Stephensf1310722006-06-25 23:51:37 -07002459
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002460 split_bundles = (l_ptr->owner->active_links[0] !=
Allan Stephens5392d642006-06-25 23:52:50 -07002461 l_ptr->owner->active_links[1]);
2462
Per Lidenb97bf3f2006-01-02 19:04:38 +01002463 while (crs) {
2464 struct tipc_msg *msg = buf_msg(crs);
2465
2466 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002467 struct tipc_msg *m = msg_get_wrapped(msg);
2468 unchar* pos = (unchar*)m;
2469
Florian Westphald788d802007-08-02 19:28:06 -07002470 msgcount = msg_msgcnt(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002471 while (msgcount--) {
2472 msg_set_seqno(m,msg_seqno(msg));
Per Liden4323add2006-01-18 00:38:21 +01002473 tipc_link_tunnel(l_ptr, &tunnel_hdr, m,
2474 msg_link_selector(m));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002475 pos += align(msg_size(m));
2476 m = (struct tipc_msg *)pos;
2477 }
2478 } else {
Per Liden4323add2006-01-18 00:38:21 +01002479 tipc_link_tunnel(l_ptr, &tunnel_hdr, msg,
2480 msg_link_selector(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002481 }
2482 crs = crs->next;
2483 }
2484}
2485
Per Liden4323add2006-01-18 00:38:21 +01002486void tipc_link_send_duplicate(struct link *l_ptr, struct link *tunnel)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002487{
2488 struct sk_buff *iter;
2489 struct tipc_msg tunnel_hdr;
2490
2491 msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002492 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002493 msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
2494 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2495 iter = l_ptr->first_out;
2496 while (iter) {
2497 struct sk_buff *outbuf;
2498 struct tipc_msg *msg = buf_msg(iter);
2499 u32 length = msg_size(msg);
2500
2501 if (msg_user(msg) == MSG_BUNDLER)
2502 msg_set_type(msg, CLOSED_MSG);
2503 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002504 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002505 msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
2506 outbuf = buf_acquire(length + INT_H_SIZE);
2507 if (outbuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002508 warn("Link changeover error, "
2509 "unable to send duplicate msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002510 return;
2511 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002512 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2513 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
2514 length);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002515 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2516 tunnel->b_ptr->net_plane);
2517 msg_dbg(buf_msg(outbuf), ">SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002518 tipc_link_send_buf(tunnel, outbuf);
2519 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002520 return;
2521 iter = iter->next;
2522 }
2523}
2524
2525
2526
2527/**
2528 * buf_extract - extracts embedded TIPC message from another message
2529 * @skb: encapsulating message buffer
2530 * @from_pos: offset to extract from
2531 *
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002532 * Returns a new message buffer containing an embedded message. The
Per Lidenb97bf3f2006-01-02 19:04:38 +01002533 * encapsulating message itself is left unchanged.
2534 */
2535
2536static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
2537{
2538 struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
2539 u32 size = msg_size(msg);
2540 struct sk_buff *eb;
2541
2542 eb = buf_acquire(size);
2543 if (eb)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002544 skb_copy_to_linear_data(eb, msg, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002545 return eb;
2546}
2547
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002548/*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002549 * link_recv_changeover_msg(): Receive tunneled packet sent
2550 * via other link. Node is locked. Return extracted buffer.
2551 */
2552
2553static int link_recv_changeover_msg(struct link **l_ptr,
2554 struct sk_buff **buf)
2555{
2556 struct sk_buff *tunnel_buf = *buf;
2557 struct link *dest_link;
2558 struct tipc_msg *msg;
2559 struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf);
2560 u32 msg_typ = msg_type(tunnel_msg);
2561 u32 msg_count = msg_msgcnt(tunnel_msg);
2562
2563 dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002564 if (!dest_link) {
2565 msg_dbg(tunnel_msg, "NOLINK/<REC<");
2566 goto exit;
2567 }
Allan Stephensf1310722006-06-25 23:51:37 -07002568 if (dest_link == *l_ptr) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002569 err("Unexpected changeover message on link <%s>\n",
Allan Stephensf1310722006-06-25 23:51:37 -07002570 (*l_ptr)->name);
2571 goto exit;
2572 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002573 dbg("%c<-%c:", dest_link->b_ptr->net_plane,
2574 (*l_ptr)->b_ptr->net_plane);
2575 *l_ptr = dest_link;
2576 msg = msg_get_wrapped(tunnel_msg);
2577
2578 if (msg_typ == DUPLICATE_MSG) {
2579 if (less(msg_seqno(msg), mod(dest_link->next_in_no))) {
2580 msg_dbg(tunnel_msg, "DROP/<REC<");
2581 goto exit;
2582 }
2583 *buf = buf_extract(tunnel_buf,INT_H_SIZE);
2584 if (*buf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002585 warn("Link changeover error, duplicate msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002586 goto exit;
2587 }
2588 msg_dbg(tunnel_msg, "TNL<REC<");
2589 buf_discard(tunnel_buf);
2590 return 1;
2591 }
2592
2593 /* First original message ?: */
2594
Per Liden4323add2006-01-18 00:38:21 +01002595 if (tipc_link_is_up(dest_link)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002596 msg_dbg(tunnel_msg, "UP/FIRST/<REC<");
Allan Stephensa10bd922006-06-25 23:52:17 -07002597 info("Resetting link <%s>, changeover initiated by peer\n",
2598 dest_link->name);
Per Liden4323add2006-01-18 00:38:21 +01002599 tipc_link_reset(dest_link);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002600 dest_link->exp_msg_count = msg_count;
Allan Stephens5392d642006-06-25 23:52:50 -07002601 dbg("Expecting %u tunnelled messages\n", msg_count);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002602 if (!msg_count)
2603 goto exit;
2604 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
2605 msg_dbg(tunnel_msg, "BLK/FIRST/<REC<");
2606 dest_link->exp_msg_count = msg_count;
Allan Stephens5392d642006-06-25 23:52:50 -07002607 dbg("Expecting %u tunnelled messages\n", msg_count);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002608 if (!msg_count)
2609 goto exit;
2610 }
2611
2612 /* Receive original message */
2613
2614 if (dest_link->exp_msg_count == 0) {
Allan Stephens5392d642006-06-25 23:52:50 -07002615 warn("Link switchover error, "
2616 "got too many tunnelled messages\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002617 msg_dbg(tunnel_msg, "OVERDUE/DROP/<REC<");
2618 dbg_print_link(dest_link, "LINK:");
2619 goto exit;
2620 }
2621 dest_link->exp_msg_count--;
2622 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) {
2623 msg_dbg(tunnel_msg, "DROP/DUPL/<REC<");
2624 goto exit;
2625 } else {
2626 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2627 if (*buf != NULL) {
2628 msg_dbg(tunnel_msg, "TNL<REC<");
2629 buf_discard(tunnel_buf);
2630 return 1;
2631 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002632 warn("Link changeover error, original msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002633 }
2634 }
2635exit:
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002636 *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002637 buf_discard(tunnel_buf);
2638 return 0;
2639}
2640
2641/*
2642 * Bundler functionality:
2643 */
Per Liden4323add2006-01-18 00:38:21 +01002644void tipc_link_recv_bundle(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002645{
2646 u32 msgcount = msg_msgcnt(buf_msg(buf));
2647 u32 pos = INT_H_SIZE;
2648 struct sk_buff *obuf;
2649
2650 msg_dbg(buf_msg(buf), "<BNDL<: ");
2651 while (msgcount--) {
2652 obuf = buf_extract(buf, pos);
2653 if (obuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002654 warn("Link unable to unbundle message(s)\n");
2655 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07002656 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002657 pos += align(msg_size(buf_msg(obuf)));
2658 msg_dbg(buf_msg(obuf), " /");
Per Liden4323add2006-01-18 00:38:21 +01002659 tipc_net_route_msg(obuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002660 }
2661 buf_discard(buf);
2662}
2663
2664/*
2665 * Fragmentation/defragmentation:
2666 */
2667
2668
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002669/*
Per Liden4323add2006-01-18 00:38:21 +01002670 * tipc_link_send_long_buf: Entry for buffers needing fragmentation.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002671 * The buffer is complete, inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01002672 * Returns user data length.
2673 */
Per Liden4323add2006-01-18 00:38:21 +01002674int tipc_link_send_long_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002675{
2676 struct tipc_msg *inmsg = buf_msg(buf);
2677 struct tipc_msg fragm_hdr;
2678 u32 insize = msg_size(inmsg);
2679 u32 dsz = msg_data_sz(inmsg);
2680 unchar *crs = buf->data;
2681 u32 rest = insize;
2682 u32 pack_sz = link_max_pkt(l_ptr);
2683 u32 fragm_sz = pack_sz - INT_H_SIZE;
2684 u32 fragm_no = 1;
Allan Stephens9c396a72008-06-04 17:36:58 -07002685 u32 destaddr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002686
2687 if (msg_short(inmsg))
2688 destaddr = l_ptr->addr;
Allan Stephens9c396a72008-06-04 17:36:58 -07002689 else
2690 destaddr = msg_destnode(inmsg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002691
2692 if (msg_routed(inmsg))
2693 msg_set_prevnode(inmsg, tipc_own_addr);
2694
2695 /* Prepare reusable fragment header: */
2696
2697 msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07002698 INT_H_SIZE, destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002699 msg_set_link_selector(&fragm_hdr, msg_link_selector(inmsg));
2700 msg_set_long_msgno(&fragm_hdr, mod(l_ptr->long_msg_seq_no++));
2701 msg_set_fragm_no(&fragm_hdr, fragm_no);
2702 l_ptr->stats.sent_fragmented++;
2703
2704 /* Chop up message: */
2705
2706 while (rest > 0) {
2707 struct sk_buff *fragm;
2708
2709 if (rest <= fragm_sz) {
2710 fragm_sz = rest;
2711 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
2712 }
2713 fragm = buf_acquire(fragm_sz + INT_H_SIZE);
2714 if (fragm == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002715 warn("Link unable to fragment message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002716 dsz = -ENOMEM;
2717 goto exit;
2718 }
2719 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002720 skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE);
2721 skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs,
2722 fragm_sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002723 /* Send queued messages first, if any: */
2724
2725 l_ptr->stats.sent_fragments++;
Per Liden4323add2006-01-18 00:38:21 +01002726 tipc_link_send_buf(l_ptr, fragm);
2727 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002728 return dsz;
2729 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
2730 rest -= fragm_sz;
2731 crs += fragm_sz;
2732 msg_set_type(&fragm_hdr, FRAGMENT);
2733 }
2734exit:
2735 buf_discard(buf);
2736 return dsz;
2737}
2738
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002739/*
2740 * A pending message being re-assembled must store certain values
2741 * to handle subsequent fragments correctly. The following functions
Per Lidenb97bf3f2006-01-02 19:04:38 +01002742 * help storing these values in unused, available fields in the
2743 * pending message. This makes dynamic memory allocation unecessary.
2744 */
2745
Sam Ravnborg05790c62006-03-20 22:37:04 -08002746static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002747{
2748 msg_set_seqno(buf_msg(buf), seqno);
2749}
2750
Sam Ravnborg05790c62006-03-20 22:37:04 -08002751static u32 get_fragm_size(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002752{
2753 return msg_ack(buf_msg(buf));
2754}
2755
Sam Ravnborg05790c62006-03-20 22:37:04 -08002756static void set_fragm_size(struct sk_buff *buf, u32 sz)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002757{
2758 msg_set_ack(buf_msg(buf), sz);
2759}
2760
Sam Ravnborg05790c62006-03-20 22:37:04 -08002761static u32 get_expected_frags(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002762{
2763 return msg_bcast_ack(buf_msg(buf));
2764}
2765
Sam Ravnborg05790c62006-03-20 22:37:04 -08002766static void set_expected_frags(struct sk_buff *buf, u32 exp)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002767{
2768 msg_set_bcast_ack(buf_msg(buf), exp);
2769}
2770
Sam Ravnborg05790c62006-03-20 22:37:04 -08002771static u32 get_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002772{
2773 return msg_reroute_cnt(buf_msg(buf));
2774}
2775
Sam Ravnborg05790c62006-03-20 22:37:04 -08002776static void incr_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002777{
2778 msg_incr_reroute_cnt(buf_msg(buf));
2779}
2780
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002781/*
2782 * tipc_link_recv_fragment(): Called with node lock on. Returns
Per Lidenb97bf3f2006-01-02 19:04:38 +01002783 * the reassembled buffer if message is complete.
2784 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002785int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
Per Liden4323add2006-01-18 00:38:21 +01002786 struct tipc_msg **m)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002787{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002788 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002789 struct sk_buff *fbuf = *fb;
2790 struct tipc_msg *fragm = buf_msg(fbuf);
2791 struct sk_buff *pbuf = *pending;
2792 u32 long_msg_seq_no = msg_long_msgno(fragm);
2793
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002794 *fb = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002795 msg_dbg(fragm,"FRG<REC<");
2796
2797 /* Is there an incomplete message waiting for this fragment? */
2798
Joe Perchesf64f9e72009-11-29 16:55:45 -08002799 while (pbuf && ((msg_seqno(buf_msg(pbuf)) != long_msg_seq_no) ||
2800 (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002801 prev = pbuf;
2802 pbuf = pbuf->next;
2803 }
2804
2805 if (!pbuf && (msg_type(fragm) == FIRST_FRAGMENT)) {
2806 struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
2807 u32 msg_sz = msg_size(imsg);
2808 u32 fragm_sz = msg_data_sz(fragm);
2809 u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
2810 u32 max = TIPC_MAX_USER_MSG_SIZE + LONG_H_SIZE;
2811 if (msg_type(imsg) == TIPC_MCAST_MSG)
2812 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
2813 if (msg_size(imsg) > max) {
2814 msg_dbg(fragm,"<REC<Oversized: ");
2815 buf_discard(fbuf);
2816 return 0;
2817 }
2818 pbuf = buf_acquire(msg_size(imsg));
2819 if (pbuf != NULL) {
2820 pbuf->next = *pending;
2821 *pending = pbuf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002822 skb_copy_to_linear_data(pbuf, imsg,
2823 msg_data_sz(fragm));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002824 /* Prepare buffer for subsequent fragments. */
2825
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002826 set_long_msg_seqno(pbuf, long_msg_seq_no);
2827 set_fragm_size(pbuf,fragm_sz);
2828 set_expected_frags(pbuf,exp_fragm_cnt - 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002829 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002830 warn("Link unable to reassemble fragmented message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002831 }
2832 buf_discard(fbuf);
2833 return 0;
2834 } else if (pbuf && (msg_type(fragm) != FIRST_FRAGMENT)) {
2835 u32 dsz = msg_data_sz(fragm);
2836 u32 fsz = get_fragm_size(pbuf);
2837 u32 crs = ((msg_fragm_no(fragm) - 1) * fsz);
2838 u32 exp_frags = get_expected_frags(pbuf) - 1;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002839 skb_copy_to_linear_data_offset(pbuf, crs,
2840 msg_data(fragm), dsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002841 buf_discard(fbuf);
2842
2843 /* Is message complete? */
2844
2845 if (exp_frags == 0) {
2846 if (prev)
2847 prev->next = pbuf->next;
2848 else
2849 *pending = pbuf->next;
2850 msg_reset_reroute_cnt(buf_msg(pbuf));
2851 *fb = pbuf;
2852 *m = buf_msg(pbuf);
2853 return 1;
2854 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002855 set_expected_frags(pbuf,exp_frags);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002856 return 0;
2857 }
2858 dbg(" Discarding orphan fragment %x\n",fbuf);
2859 msg_dbg(fragm,"ORPHAN:");
2860 dbg("Pending long buffers:\n");
2861 dbg_print_buf_chain(*pending);
2862 buf_discard(fbuf);
2863 return 0;
2864}
2865
2866/**
2867 * link_check_defragm_bufs - flush stale incoming message fragments
2868 * @l_ptr: pointer to link
2869 */
2870
2871static void link_check_defragm_bufs(struct link *l_ptr)
2872{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002873 struct sk_buff *prev = NULL;
2874 struct sk_buff *next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002875 struct sk_buff *buf = l_ptr->defragm_buf;
2876
2877 if (!buf)
2878 return;
2879 if (!link_working_working(l_ptr))
2880 return;
2881 while (buf) {
2882 u32 cnt = get_timer_cnt(buf);
2883
2884 next = buf->next;
2885 if (cnt < 4) {
2886 incr_timer_cnt(buf);
2887 prev = buf;
2888 } else {
2889 dbg(" Discarding incomplete long buffer\n");
2890 msg_dbg(buf_msg(buf), "LONG:");
2891 dbg_print_link(l_ptr, "curr:");
2892 dbg("Pending long buffers:\n");
2893 dbg_print_buf_chain(l_ptr->defragm_buf);
2894 if (prev)
2895 prev->next = buf->next;
2896 else
2897 l_ptr->defragm_buf = buf->next;
2898 buf_discard(buf);
2899 }
2900 buf = next;
2901 }
2902}
2903
2904
2905
2906static void link_set_supervision_props(struct link *l_ptr, u32 tolerance)
2907{
2908 l_ptr->tolerance = tolerance;
2909 l_ptr->continuity_interval =
2910 ((tolerance / 4) > 500) ? 500 : tolerance / 4;
2911 l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
2912}
2913
2914
Per Liden4323add2006-01-18 00:38:21 +01002915void tipc_link_set_queue_limits(struct link *l_ptr, u32 window)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002916{
2917 /* Data messages from this node, inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002918 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
2919 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
2920 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
2921 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002922 /* Transiting data messages,inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002923 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
2924 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
2925 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
2926 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002927 l_ptr->queue_limit[CONN_MANAGER] = 1200;
2928 l_ptr->queue_limit[ROUTE_DISTRIBUTOR] = 1200;
2929 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
2930 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
2931 /* FRAGMENT and LAST_FRAGMENT packets */
2932 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
2933}
2934
2935/**
2936 * link_find_link - locate link by name
2937 * @name - ptr to link name string
2938 * @node - ptr to area to be filled with ptr to associated node
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002939 *
Per Liden4323add2006-01-18 00:38:21 +01002940 * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002941 * this also prevents link deletion.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002942 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002943 * Returns pointer to link (or 0 if invalid link name).
2944 */
2945
David S. Miller6c000552008-09-02 23:38:32 -07002946static struct link *link_find_link(const char *name, struct tipc_node **node)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002947{
2948 struct link_name link_name_parts;
2949 struct bearer *b_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002950 struct link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002951
2952 if (!link_name_validate(name, &link_name_parts))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002953 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002954
Per Liden4323add2006-01-18 00:38:21 +01002955 b_ptr = tipc_bearer_find_interface(link_name_parts.if_local);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002956 if (!b_ptr)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002957 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002958
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002959 *node = tipc_node_find(link_name_parts.addr_peer);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002960 if (!*node)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002961 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002962
2963 l_ptr = (*node)->links[b_ptr->identity];
2964 if (!l_ptr || strcmp(l_ptr->name, name))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002965 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002966
2967 return l_ptr;
2968}
2969
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002970struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Per Liden4323add2006-01-18 00:38:21 +01002971 u16 cmd)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002972{
2973 struct tipc_link_config *args;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002974 u32 new_value;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002975 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002976 struct tipc_node *node;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002977 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002978
2979 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +01002980 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002981
2982 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2983 new_value = ntohl(args->value);
2984
Per Liden4323add2006-01-18 00:38:21 +01002985 if (!strcmp(args->name, tipc_bclink_name)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002986 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
Per Liden4323add2006-01-18 00:38:21 +01002987 (tipc_bclink_set_queue_limits(new_value) == 0))
2988 return tipc_cfg_reply_none();
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002989 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Per Liden4323add2006-01-18 00:38:21 +01002990 " (cannot change setting on broadcast link)");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002991 }
2992
Per Liden4323add2006-01-18 00:38:21 +01002993 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002994 l_ptr = link_find_link(args->name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002995 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002996 read_unlock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002997 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002998 }
2999
Per Liden4323add2006-01-18 00:38:21 +01003000 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003001 res = -EINVAL;
3002 switch (cmd) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003003 case TIPC_CMD_SET_LINK_TOL:
3004 if ((new_value >= TIPC_MIN_LINK_TOL) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01003005 (new_value <= TIPC_MAX_LINK_TOL)) {
3006 link_set_supervision_props(l_ptr, new_value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003007 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01003008 0, 0, new_value, 0, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07003009 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003010 }
3011 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003012 case TIPC_CMD_SET_LINK_PRI:
Per Liden16cb4b32006-01-13 22:22:22 +01003013 if ((new_value >= TIPC_MIN_LINK_PRI) &&
3014 (new_value <= TIPC_MAX_LINK_PRI)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01003015 l_ptr->priority = new_value;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003016 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01003017 0, 0, 0, new_value, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07003018 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003019 }
3020 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003021 case TIPC_CMD_SET_LINK_WINDOW:
3022 if ((new_value >= TIPC_MIN_LINK_WIN) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01003023 (new_value <= TIPC_MAX_LINK_WIN)) {
Per Liden4323add2006-01-18 00:38:21 +01003024 tipc_link_set_queue_limits(l_ptr, new_value);
Allan Stephens0e35fd52008-07-14 22:44:01 -07003025 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003026 }
3027 break;
3028 }
Per Liden4323add2006-01-18 00:38:21 +01003029 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003030
Per Liden4323add2006-01-18 00:38:21 +01003031 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003032 if (res)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003033 return tipc_cfg_reply_error_string("cannot change link setting");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003034
Per Liden4323add2006-01-18 00:38:21 +01003035 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003036}
3037
3038/**
3039 * link_reset_statistics - reset link statistics
3040 * @l_ptr: pointer to link
3041 */
3042
3043static void link_reset_statistics(struct link *l_ptr)
3044{
3045 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
3046 l_ptr->stats.sent_info = l_ptr->next_out_no;
3047 l_ptr->stats.recv_info = l_ptr->next_in_no;
3048}
3049
Per Liden4323add2006-01-18 00:38:21 +01003050struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003051{
3052 char *link_name;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003053 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07003054 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003055
3056 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01003057 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003058
3059 link_name = (char *)TLV_DATA(req_tlv_area);
Per Liden4323add2006-01-18 00:38:21 +01003060 if (!strcmp(link_name, tipc_bclink_name)) {
3061 if (tipc_bclink_reset_stats())
3062 return tipc_cfg_reply_error_string("link not found");
3063 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003064 }
3065
Per Liden4323add2006-01-18 00:38:21 +01003066 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003067 l_ptr = link_find_link(link_name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003068 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003069 read_unlock_bh(&tipc_net_lock);
3070 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003071 }
3072
Per Liden4323add2006-01-18 00:38:21 +01003073 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003074 link_reset_statistics(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01003075 tipc_node_unlock(node);
3076 read_unlock_bh(&tipc_net_lock);
3077 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003078}
3079
3080/**
3081 * percent - convert count to a percentage of total (rounding up or down)
3082 */
3083
3084static u32 percent(u32 count, u32 total)
3085{
3086 return (count * 100 + (total / 2)) / total;
3087}
3088
3089/**
Per Liden4323add2006-01-18 00:38:21 +01003090 * tipc_link_stats - print link statistics
Per Lidenb97bf3f2006-01-02 19:04:38 +01003091 * @name: link name
3092 * @buf: print buffer area
3093 * @buf_size: size of print buffer area
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003094 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01003095 * Returns length of print buffer data string (or 0 if error)
3096 */
3097
Per Liden4323add2006-01-18 00:38:21 +01003098static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003099{
3100 struct print_buf pb;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003101 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07003102 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003103 char *status;
3104 u32 profile_total = 0;
3105
Per Liden4323add2006-01-18 00:38:21 +01003106 if (!strcmp(name, tipc_bclink_name))
3107 return tipc_bclink_stats(buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003108
Per Liden4323add2006-01-18 00:38:21 +01003109 tipc_printbuf_init(&pb, buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003110
Per Liden4323add2006-01-18 00:38:21 +01003111 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003112 l_ptr = link_find_link(name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003113 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003114 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003115 return 0;
3116 }
Per Liden4323add2006-01-18 00:38:21 +01003117 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003118
Per Liden4323add2006-01-18 00:38:21 +01003119 if (tipc_link_is_active(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003120 status = "ACTIVE";
Per Liden4323add2006-01-18 00:38:21 +01003121 else if (tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003122 status = "STANDBY";
3123 else
3124 status = "DEFUNCT";
3125 tipc_printf(&pb, "Link <%s>\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003126 " %s MTU:%u Priority:%u Tolerance:%u ms"
3127 " Window:%u packets\n",
3128 l_ptr->name, status, link_max_pkt(l_ptr),
Per Lidenb97bf3f2006-01-02 19:04:38 +01003129 l_ptr->priority, l_ptr->tolerance, l_ptr->queue_limit[0]);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003130 tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003131 l_ptr->next_in_no - l_ptr->stats.recv_info,
3132 l_ptr->stats.recv_fragments,
3133 l_ptr->stats.recv_fragmented,
3134 l_ptr->stats.recv_bundles,
3135 l_ptr->stats.recv_bundled);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003136 tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003137 l_ptr->next_out_no - l_ptr->stats.sent_info,
3138 l_ptr->stats.sent_fragments,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003139 l_ptr->stats.sent_fragmented,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003140 l_ptr->stats.sent_bundles,
3141 l_ptr->stats.sent_bundled);
3142 profile_total = l_ptr->stats.msg_length_counts;
3143 if (!profile_total)
3144 profile_total = 1;
3145 tipc_printf(&pb, " TX profile sample:%u packets average:%u octets\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003146 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
3147 "-16354:%u%% -32768:%u%% -66000:%u%%\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003148 l_ptr->stats.msg_length_counts,
3149 l_ptr->stats.msg_lengths_total / profile_total,
3150 percent(l_ptr->stats.msg_length_profile[0], profile_total),
3151 percent(l_ptr->stats.msg_length_profile[1], profile_total),
3152 percent(l_ptr->stats.msg_length_profile[2], profile_total),
3153 percent(l_ptr->stats.msg_length_profile[3], profile_total),
3154 percent(l_ptr->stats.msg_length_profile[4], profile_total),
3155 percent(l_ptr->stats.msg_length_profile[5], profile_total),
3156 percent(l_ptr->stats.msg_length_profile[6], profile_total));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003157 tipc_printf(&pb, " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003158 l_ptr->stats.recv_states,
3159 l_ptr->stats.recv_probes,
3160 l_ptr->stats.recv_nacks,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003161 l_ptr->stats.deferred_recv,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003162 l_ptr->stats.duplicates);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003163 tipc_printf(&pb, " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
3164 l_ptr->stats.sent_states,
3165 l_ptr->stats.sent_probes,
3166 l_ptr->stats.sent_nacks,
3167 l_ptr->stats.sent_acks,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003168 l_ptr->stats.retransmitted);
3169 tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
3170 l_ptr->stats.bearer_congs,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003171 l_ptr->stats.link_congs,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003172 l_ptr->stats.max_queue_sz,
3173 l_ptr->stats.queue_sz_counts
3174 ? (l_ptr->stats.accu_queue_sz / l_ptr->stats.queue_sz_counts)
3175 : 0);
3176
Per Liden4323add2006-01-18 00:38:21 +01003177 tipc_node_unlock(node);
3178 read_unlock_bh(&tipc_net_lock);
3179 return tipc_printbuf_validate(&pb);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003180}
3181
3182#define MAX_LINK_STATS_INFO 2000
3183
Per Liden4323add2006-01-18 00:38:21 +01003184struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003185{
3186 struct sk_buff *buf;
3187 struct tlv_desc *rep_tlv;
3188 int str_len;
3189
3190 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01003191 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003192
Per Liden4323add2006-01-18 00:38:21 +01003193 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_LINK_STATS_INFO));
Per Lidenb97bf3f2006-01-02 19:04:38 +01003194 if (!buf)
3195 return NULL;
3196
3197 rep_tlv = (struct tlv_desc *)buf->data;
3198
Per Liden4323add2006-01-18 00:38:21 +01003199 str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
3200 (char *)TLV_DATA(rep_tlv), MAX_LINK_STATS_INFO);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003201 if (!str_len) {
3202 buf_discard(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003203 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003204 }
3205
3206 skb_put(buf, TLV_SPACE(str_len));
3207 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
3208
3209 return buf;
3210}
3211
3212#if 0
3213int link_control(const char *name, u32 op, u32 val)
3214{
3215 int res = -EINVAL;
3216 struct link *l_ptr;
3217 u32 bearer_id;
David S. Miller6c000552008-09-02 23:38:32 -07003218 struct tipc_node * node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003219 u32 a;
3220
3221 a = link_name2addr(name, &bearer_id);
Per Liden4323add2006-01-18 00:38:21 +01003222 read_lock_bh(&tipc_net_lock);
3223 node = tipc_node_find(a);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003224 if (node) {
Per Liden4323add2006-01-18 00:38:21 +01003225 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003226 l_ptr = node->links[bearer_id];
3227 if (l_ptr) {
3228 if (op == TIPC_REMOVE_LINK) {
3229 struct bearer *b_ptr = l_ptr->b_ptr;
3230 spin_lock_bh(&b_ptr->publ.lock);
Per Liden4323add2006-01-18 00:38:21 +01003231 tipc_link_delete(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003232 spin_unlock_bh(&b_ptr->publ.lock);
3233 }
3234 if (op == TIPC_CMD_BLOCK_LINK) {
Per Liden4323add2006-01-18 00:38:21 +01003235 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003236 l_ptr->blocked = 1;
3237 }
3238 if (op == TIPC_CMD_UNBLOCK_LINK) {
3239 l_ptr->blocked = 0;
3240 }
Allan Stephens0e35fd52008-07-14 22:44:01 -07003241 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003242 }
Per Liden4323add2006-01-18 00:38:21 +01003243 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003244 }
Per Liden4323add2006-01-18 00:38:21 +01003245 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003246 return res;
3247}
3248#endif
3249
3250/**
Per Liden4323add2006-01-18 00:38:21 +01003251 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
Per Lidenb97bf3f2006-01-02 19:04:38 +01003252 * @dest: network address of destination node
3253 * @selector: used to select from set of active links
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003254 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01003255 * If no active link can be found, uses default maximum packet size.
3256 */
3257
Per Liden4323add2006-01-18 00:38:21 +01003258u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003259{
David S. Miller6c000552008-09-02 23:38:32 -07003260 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003261 struct link *l_ptr;
3262 u32 res = MAX_PKT_DEFAULT;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003263
Per Lidenb97bf3f2006-01-02 19:04:38 +01003264 if (dest == tipc_own_addr)
3265 return MAX_MSG_SIZE;
3266
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003267 read_lock_bh(&tipc_net_lock);
Per Liden4323add2006-01-18 00:38:21 +01003268 n_ptr = tipc_node_select(dest, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003269 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003270 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003271 l_ptr = n_ptr->active_links[selector & 1];
3272 if (l_ptr)
3273 res = link_max_pkt(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01003274 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003275 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003276 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003277 return res;
3278}
3279
3280#if 0
3281static void link_dump_rec_queue(struct link *l_ptr)
3282{
3283 struct sk_buff *crs;
3284
3285 if (!l_ptr->oldest_deferred_in) {
3286 info("Reception queue empty\n");
3287 return;
3288 }
3289 info("Contents of Reception queue:\n");
3290 crs = l_ptr->oldest_deferred_in;
3291 while (crs) {
3292 if (crs->data == (void *)0x0000a3a3) {
3293 info("buffer %x invalid\n", crs);
3294 return;
3295 }
Frans Popa570f092010-03-24 07:57:29 +00003296 msg_dbg(buf_msg(crs), "In rec queue:\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003297 crs = crs->next;
3298 }
3299}
3300#endif
3301
3302static void link_dump_send_queue(struct link *l_ptr)
3303{
3304 if (l_ptr->next_out) {
3305 info("\nContents of unsent queue:\n");
3306 dbg_print_buf_chain(l_ptr->next_out);
3307 }
3308 info("\nContents of send queue:\n");
3309 if (l_ptr->first_out) {
3310 dbg_print_buf_chain(l_ptr->first_out);
3311 }
3312 info("Empty send queue\n");
3313}
3314
3315static void link_print(struct link *l_ptr, struct print_buf *buf,
3316 const char *str)
3317{
3318 tipc_printf(buf, str);
3319 if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr))
3320 return;
3321 tipc_printf(buf, "Link %x<%s>:",
3322 l_ptr->addr, l_ptr->b_ptr->publ.name);
3323 tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no));
3324 tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no));
3325 tipc_printf(buf, "SQUE");
3326 if (l_ptr->first_out) {
3327 tipc_printf(buf, "[%u..", msg_seqno(buf_msg(l_ptr->first_out)));
3328 if (l_ptr->next_out)
3329 tipc_printf(buf, "%u..",
3330 msg_seqno(buf_msg(l_ptr->next_out)));
Allan Stephensb82834e2010-05-11 14:30:04 +00003331 tipc_printf(buf, "%u]", msg_seqno(buf_msg(l_ptr->last_out)));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003332 if ((mod(msg_seqno(buf_msg(l_ptr->last_out)) -
3333 msg_seqno(buf_msg(l_ptr->first_out)))
Joe Perchesf64f9e72009-11-29 16:55:45 -08003334 != (l_ptr->out_queue_size - 1)) ||
3335 (l_ptr->last_out->next != NULL)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01003336 tipc_printf(buf, "\nSend queue inconsistency\n");
3337 tipc_printf(buf, "first_out= %x ", l_ptr->first_out);
3338 tipc_printf(buf, "next_out= %x ", l_ptr->next_out);
3339 tipc_printf(buf, "last_out= %x ", l_ptr->last_out);
3340 link_dump_send_queue(l_ptr);
3341 }
3342 } else
3343 tipc_printf(buf, "[]");
3344 tipc_printf(buf, "SQSIZ(%u)", l_ptr->out_queue_size);
3345 if (l_ptr->oldest_deferred_in) {
3346 u32 o = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
3347 u32 n = msg_seqno(buf_msg(l_ptr->newest_deferred_in));
3348 tipc_printf(buf, ":RQUE[%u..%u]", o, n);
3349 if (l_ptr->deferred_inqueue_sz != mod((n + 1) - o)) {
3350 tipc_printf(buf, ":RQSIZ(%u)",
3351 l_ptr->deferred_inqueue_sz);
3352 }
3353 }
3354 if (link_working_unknown(l_ptr))
3355 tipc_printf(buf, ":WU");
3356 if (link_reset_reset(l_ptr))
3357 tipc_printf(buf, ":RR");
3358 if (link_reset_unknown(l_ptr))
3359 tipc_printf(buf, ":RU");
3360 if (link_working_working(l_ptr))
3361 tipc_printf(buf, ":WW");
3362 tipc_printf(buf, "\n");
3363}
3364