blob: a6a3102bb4d6b9acb78d7e5a9dca11aca0ac5c54 [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 void link_init_max_pkt(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100206{
207 u32 max_pkt;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900208
Per Lidenb97bf3f2006-01-02 19:04:38 +0100209 max_pkt = (l_ptr->b_ptr->publ.mtu & ~3);
210 if (max_pkt > MAX_MSG_SIZE)
211 max_pkt = MAX_MSG_SIZE;
212
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900213 l_ptr->max_pkt_target = max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100214 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
215 l_ptr->max_pkt = l_ptr->max_pkt_target;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900216 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100217 l_ptr->max_pkt = MAX_PKT_DEFAULT;
218
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900219 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100220}
221
Sam Ravnborg05790c62006-03-20 22:37:04 -0800222static u32 link_next_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100223{
224 if (l_ptr->next_out)
225 return msg_seqno(buf_msg(l_ptr->next_out));
226 return mod(l_ptr->next_out_no);
227}
228
Sam Ravnborg05790c62006-03-20 22:37:04 -0800229static u32 link_last_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100230{
231 return mod(link_next_sent(l_ptr) - 1);
232}
233
234/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800235 * Simple non-static link routines (i.e. referenced outside this file)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236 */
237
Per Liden4323add2006-01-18 00:38:21 +0100238int tipc_link_is_up(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100239{
240 if (!l_ptr)
241 return 0;
242 return (link_working_working(l_ptr) || link_working_unknown(l_ptr));
243}
244
Per Liden4323add2006-01-18 00:38:21 +0100245int tipc_link_is_active(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100246{
247 return ((l_ptr->owner->active_links[0] == l_ptr) ||
248 (l_ptr->owner->active_links[1] == l_ptr));
249}
250
251/**
252 * link_name_validate - validate & (optionally) deconstruct link name
253 * @name - ptr to link name string
254 * @name_parts - ptr to area for link name components (or NULL if not needed)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900255 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100256 * Returns 1 if link name is valid, otherwise 0.
257 */
258
259static int link_name_validate(const char *name, struct link_name *name_parts)
260{
261 char name_copy[TIPC_MAX_LINK_NAME];
262 char *addr_local;
263 char *if_local;
264 char *addr_peer;
265 char *if_peer;
266 char dummy;
267 u32 z_local, c_local, n_local;
268 u32 z_peer, c_peer, n_peer;
269 u32 if_local_len;
270 u32 if_peer_len;
271
272 /* copy link name & ensure length is OK */
273
274 name_copy[TIPC_MAX_LINK_NAME - 1] = 0;
275 /* need above in case non-Posix strncpy() doesn't pad with nulls */
276 strncpy(name_copy, name, TIPC_MAX_LINK_NAME);
277 if (name_copy[TIPC_MAX_LINK_NAME - 1] != 0)
278 return 0;
279
280 /* ensure all component parts of link name are present */
281
282 addr_local = name_copy;
283 if ((if_local = strchr(addr_local, ':')) == NULL)
284 return 0;
285 *(if_local++) = 0;
286 if ((addr_peer = strchr(if_local, '-')) == NULL)
287 return 0;
288 *(addr_peer++) = 0;
289 if_local_len = addr_peer - if_local;
290 if ((if_peer = strchr(addr_peer, ':')) == NULL)
291 return 0;
292 *(if_peer++) = 0;
293 if_peer_len = strlen(if_peer) + 1;
294
295 /* validate component parts of link name */
296
297 if ((sscanf(addr_local, "%u.%u.%u%c",
298 &z_local, &c_local, &n_local, &dummy) != 3) ||
299 (sscanf(addr_peer, "%u.%u.%u%c",
300 &z_peer, &c_peer, &n_peer, &dummy) != 3) ||
301 (z_local > 255) || (c_local > 4095) || (n_local > 4095) ||
302 (z_peer > 255) || (c_peer > 4095) || (n_peer > 4095) ||
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900303 (if_local_len <= 1) || (if_local_len > TIPC_MAX_IF_NAME) ||
304 (if_peer_len <= 1) || (if_peer_len > TIPC_MAX_IF_NAME) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100305 (strspn(if_local, tipc_alphabet) != (if_local_len - 1)) ||
306 (strspn(if_peer, tipc_alphabet) != (if_peer_len - 1)))
307 return 0;
308
309 /* return link name components, if necessary */
310
311 if (name_parts) {
312 name_parts->addr_local = tipc_addr(z_local, c_local, n_local);
313 strcpy(name_parts->if_local, if_local);
314 name_parts->addr_peer = tipc_addr(z_peer, c_peer, n_peer);
315 strcpy(name_parts->if_peer, if_peer);
316 }
317 return 1;
318}
319
320/**
321 * link_timeout - handle expiration of link timer
322 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900323 *
Per Liden4323add2006-01-18 00:38:21 +0100324 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
325 * with tipc_link_delete(). (There is no risk that the node will be deleted by
326 * another thread because tipc_link_delete() always cancels the link timer before
327 * tipc_node_delete() is called.)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100328 */
329
330static void link_timeout(struct link *l_ptr)
331{
Per Liden4323add2006-01-18 00:38:21 +0100332 tipc_node_lock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333
334 /* update counters used in statistical profiling of send traffic */
335
336 l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
337 l_ptr->stats.queue_sz_counts++;
338
339 if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz)
340 l_ptr->stats.max_queue_sz = l_ptr->out_queue_size;
341
342 if (l_ptr->first_out) {
343 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
344 u32 length = msg_size(msg);
345
Joe Perchesf64f9e72009-11-29 16:55:45 -0800346 if ((msg_user(msg) == MSG_FRAGMENTER) &&
347 (msg_type(msg) == FIRST_FRAGMENT)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100348 length = msg_size(msg_get_wrapped(msg));
349 }
350 if (length) {
351 l_ptr->stats.msg_lengths_total += length;
352 l_ptr->stats.msg_length_counts++;
353 if (length <= 64)
354 l_ptr->stats.msg_length_profile[0]++;
355 else if (length <= 256)
356 l_ptr->stats.msg_length_profile[1]++;
357 else if (length <= 1024)
358 l_ptr->stats.msg_length_profile[2]++;
359 else if (length <= 4096)
360 l_ptr->stats.msg_length_profile[3]++;
361 else if (length <= 16384)
362 l_ptr->stats.msg_length_profile[4]++;
363 else if (length <= 32768)
364 l_ptr->stats.msg_length_profile[5]++;
365 else
366 l_ptr->stats.msg_length_profile[6]++;
367 }
368 }
369
370 /* do all other link processing performed on a periodic basis */
371
372 link_check_defragm_bufs(l_ptr);
373
374 link_state_event(l_ptr, TIMEOUT_EVT);
375
376 if (l_ptr->next_out)
Per Liden4323add2006-01-18 00:38:21 +0100377 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100378
Per Liden4323add2006-01-18 00:38:21 +0100379 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100380}
381
Sam Ravnborg05790c62006-03-20 22:37:04 -0800382static void link_set_timer(struct link *l_ptr, u32 time)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100383{
384 k_start_timer(&l_ptr->timer, time);
385}
386
387/**
Per Liden4323add2006-01-18 00:38:21 +0100388 * tipc_link_create - create a new link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100389 * @b_ptr: pointer to associated bearer
390 * @peer: network address of node at other end of link
391 * @media_addr: media address to use when sending messages over link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900392 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100393 * Returns pointer to link.
394 */
395
Per Liden4323add2006-01-18 00:38:21 +0100396struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
397 const struct tipc_media_addr *media_addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100398{
399 struct link *l_ptr;
400 struct tipc_msg *msg;
401 char *if_name;
402
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700403 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100404 if (!l_ptr) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700405 warn("Link creation failed, no memory\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100406 return NULL;
407 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100408
Florian Westphal945710652007-07-26 00:05:07 -0700409 if (LINK_LOG_BUF_SIZE) {
410 char *pb = kmalloc(LINK_LOG_BUF_SIZE, GFP_ATOMIC);
411
412 if (!pb) {
413 kfree(l_ptr);
414 warn("Link creation failed, no memory for print buffer\n");
415 return NULL;
416 }
417 tipc_printbuf_init(&l_ptr->print_buf, pb, LINK_LOG_BUF_SIZE);
418 }
419
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 l_ptr->addr = peer;
421 if_name = strchr(b_ptr->publ.name, ':') + 1;
422 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:",
423 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900424 tipc_node(tipc_own_addr),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100425 if_name,
426 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
427 /* note: peer i/f is appended to link name by reset/activate */
428 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100429 l_ptr->checkpoint = 1;
430 l_ptr->b_ptr = b_ptr;
431 link_set_supervision_props(l_ptr, b_ptr->media->tolerance);
432 l_ptr->state = RESET_UNKNOWN;
433
434 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
435 msg = l_ptr->pmsg;
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000436 tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100437 msg_set_size(msg, sizeof(l_ptr->proto_msg));
Allan Stephensa686e682008-06-04 17:29:39 -0700438 msg_set_session(msg, (tipc_random & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100439 msg_set_bearer_id(msg, b_ptr->identity);
440 strcpy((char *)msg_data(msg), if_name);
441
442 l_ptr->priority = b_ptr->priority;
Per Liden4323add2006-01-18 00:38:21 +0100443 tipc_link_set_queue_limits(l_ptr, b_ptr->media->window);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100444
445 link_init_max_pkt(l_ptr);
446
447 l_ptr->next_out_no = 1;
448 INIT_LIST_HEAD(&l_ptr->waiting_ports);
449
450 link_reset_statistics(l_ptr);
451
Per Liden4323add2006-01-18 00:38:21 +0100452 l_ptr->owner = tipc_node_attach_link(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100453 if (!l_ptr->owner) {
Florian Westphal945710652007-07-26 00:05:07 -0700454 if (LINK_LOG_BUF_SIZE)
455 kfree(l_ptr->print_buf.buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100456 kfree(l_ptr);
457 return NULL;
458 }
459
Florian Westphal945710652007-07-26 00:05:07 -0700460 k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr);
461 list_add_tail(&l_ptr->link_list, &b_ptr->links);
Per Liden4323add2006-01-18 00:38:21 +0100462 tipc_k_signal((Handler)tipc_link_start, (unsigned long)l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100463
Per Liden4323add2006-01-18 00:38:21 +0100464 dbg("tipc_link_create(): tolerance = %u,cont intv = %u, abort_limit = %u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +0100465 l_ptr->tolerance, l_ptr->continuity_interval, l_ptr->abort_limit);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900466
Per Lidenb97bf3f2006-01-02 19:04:38 +0100467 return l_ptr;
468}
469
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900470/**
Per Liden4323add2006-01-18 00:38:21 +0100471 * tipc_link_delete - delete a link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100472 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900473 *
Per Liden4323add2006-01-18 00:38:21 +0100474 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100475 * This routine must not grab the node lock until after link timer cancellation
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900476 * to avoid a potential deadlock situation.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100477 */
478
Per Liden4323add2006-01-18 00:38:21 +0100479void tipc_link_delete(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100480{
481 if (!l_ptr) {
482 err("Attempt to delete non-existent link\n");
483 return;
484 }
485
Per Liden4323add2006-01-18 00:38:21 +0100486 dbg("tipc_link_delete()\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100487
488 k_cancel_timer(&l_ptr->timer);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900489
Per Liden4323add2006-01-18 00:38:21 +0100490 tipc_node_lock(l_ptr->owner);
491 tipc_link_reset(l_ptr);
492 tipc_node_detach_link(l_ptr->owner, l_ptr);
493 tipc_link_stop(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100494 list_del_init(&l_ptr->link_list);
495 if (LINK_LOG_BUF_SIZE)
496 kfree(l_ptr->print_buf.buf);
Per Liden4323add2006-01-18 00:38:21 +0100497 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100498 k_term_timer(&l_ptr->timer);
499 kfree(l_ptr);
500}
501
Per Liden4323add2006-01-18 00:38:21 +0100502void tipc_link_start(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100503{
Per Liden4323add2006-01-18 00:38:21 +0100504 dbg("tipc_link_start %x\n", l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100505 link_state_event(l_ptr, STARTING_EVT);
506}
507
508/**
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900509 * link_schedule_port - schedule port for deferred sending
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510 * @l_ptr: pointer to link
511 * @origport: reference to sending port
512 * @sz: amount of data to be sent
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900513 *
514 * Schedules port for renewed sending of messages after link congestion
Per Lidenb97bf3f2006-01-02 19:04:38 +0100515 * has abated.
516 */
517
518static int link_schedule_port(struct link *l_ptr, u32 origport, u32 sz)
519{
520 struct port *p_ptr;
521
Per Liden4323add2006-01-18 00:38:21 +0100522 spin_lock_bh(&tipc_port_list_lock);
523 p_ptr = tipc_port_lock(origport);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100524 if (p_ptr) {
525 if (!p_ptr->wakeup)
526 goto exit;
527 if (!list_empty(&p_ptr->wait_list))
528 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100529 p_ptr->publ.congested = 1;
Allan Stephens15e979d2010-05-11 14:30:10 +0000530 p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100531 list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
532 l_ptr->stats.link_congs++;
533exit:
Per Liden4323add2006-01-18 00:38:21 +0100534 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100535 }
Per Liden4323add2006-01-18 00:38:21 +0100536 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100537 return -ELINKCONG;
538}
539
Per Liden4323add2006-01-18 00:38:21 +0100540void tipc_link_wakeup_ports(struct link *l_ptr, int all)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100541{
542 struct port *p_ptr;
543 struct port *temp_p_ptr;
544 int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
545
546 if (all)
547 win = 100000;
548 if (win <= 0)
549 return;
Per Liden4323add2006-01-18 00:38:21 +0100550 if (!spin_trylock_bh(&tipc_port_list_lock))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100551 return;
552 if (link_congested(l_ptr))
553 goto exit;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900554 list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100555 wait_list) {
556 if (win <= 0)
557 break;
558 list_del_init(&p_ptr->wait_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100559 spin_lock_bh(p_ptr->publ.lock);
560 p_ptr->publ.congested = 0;
561 p_ptr->wakeup(&p_ptr->publ);
562 win -= p_ptr->waiting_pkts;
563 spin_unlock_bh(p_ptr->publ.lock);
564 }
565
566exit:
Per Liden4323add2006-01-18 00:38:21 +0100567 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100568}
569
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900570/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100571 * link_release_outqueue - purge link's outbound message queue
572 * @l_ptr: pointer to link
573 */
574
575static void link_release_outqueue(struct link *l_ptr)
576{
577 struct sk_buff *buf = l_ptr->first_out;
578 struct sk_buff *next;
579
580 while (buf) {
581 next = buf->next;
582 buf_discard(buf);
583 buf = next;
584 }
585 l_ptr->first_out = NULL;
586 l_ptr->out_queue_size = 0;
587}
588
589/**
Per Liden4323add2006-01-18 00:38:21 +0100590 * tipc_link_reset_fragments - purge link's inbound message fragments queue
Per Lidenb97bf3f2006-01-02 19:04:38 +0100591 * @l_ptr: pointer to link
592 */
593
Per Liden4323add2006-01-18 00:38:21 +0100594void tipc_link_reset_fragments(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100595{
596 struct sk_buff *buf = l_ptr->defragm_buf;
597 struct sk_buff *next;
598
599 while (buf) {
600 next = buf->next;
601 buf_discard(buf);
602 buf = next;
603 }
604 l_ptr->defragm_buf = NULL;
605}
606
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900607/**
Per Liden4323add2006-01-18 00:38:21 +0100608 * tipc_link_stop - purge all inbound and outbound messages associated with link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100609 * @l_ptr: pointer to link
610 */
611
Per Liden4323add2006-01-18 00:38:21 +0100612void tipc_link_stop(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100613{
614 struct sk_buff *buf;
615 struct sk_buff *next;
616
617 buf = l_ptr->oldest_deferred_in;
618 while (buf) {
619 next = buf->next;
620 buf_discard(buf);
621 buf = next;
622 }
623
624 buf = l_ptr->first_out;
625 while (buf) {
626 next = buf->next;
627 buf_discard(buf);
628 buf = next;
629 }
630
Per Liden4323add2006-01-18 00:38:21 +0100631 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100632
633 buf_discard(l_ptr->proto_msg_queue);
634 l_ptr->proto_msg_queue = NULL;
635}
636
637#if 0
638
639/* LINK EVENT CODE IS NOT SUPPORTED AT PRESENT */
640
641static void link_recv_event(struct link_event *ev)
642{
643 ev->fcn(ev->addr, ev->name, ev->up);
644 kfree(ev);
645}
646
647static void link_send_event(void (*fcn)(u32 a, char *n, int up),
648 struct link *l_ptr, int up)
649{
650 struct link_event *ev;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900651
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
653 if (!ev) {
654 warn("Link event allocation failure\n");
655 return;
656 }
657 ev->addr = l_ptr->addr;
658 ev->up = up;
659 ev->fcn = fcn;
660 memcpy(ev->name, l_ptr->name, TIPC_MAX_LINK_NAME);
Per Liden4323add2006-01-18 00:38:21 +0100661 tipc_k_signal((Handler)link_recv_event, (unsigned long)ev);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100662}
663
664#else
665
666#define link_send_event(fcn, l_ptr, up) do { } while (0)
667
668#endif
669
Per Liden4323add2006-01-18 00:38:21 +0100670void tipc_link_reset(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100671{
672 struct sk_buff *buf;
673 u32 prev_state = l_ptr->state;
674 u32 checkpoint = l_ptr->next_in_no;
Allan Stephens5392d642006-06-25 23:52:50 -0700675 int was_active_link = tipc_link_is_active(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900676
Allan Stephensa686e682008-06-04 17:29:39 -0700677 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100678
Allan Stephensa686e682008-06-04 17:29:39 -0700679 /* Link is down, accept any session */
680 l_ptr->peer_session = INVALID_SESSION;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900682 /* Prepare for max packet size negotiation */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100683 link_init_max_pkt(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900684
Per Lidenb97bf3f2006-01-02 19:04:38 +0100685 l_ptr->state = RESET_UNKNOWN;
686 dbg_link_state("Resetting Link\n");
687
688 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
689 return;
690
Per Liden4323add2006-01-18 00:38:21 +0100691 tipc_node_link_down(l_ptr->owner, l_ptr);
692 tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100693#if 0
Per Liden4323add2006-01-18 00:38:21 +0100694 tipc_printf(TIPC_CONS, "\nReset link <%s>\n", l_ptr->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100695 dbg_link_dump();
696#endif
Allan Stephens5392d642006-06-25 23:52:50 -0700697 if (was_active_link && tipc_node_has_active_links(l_ptr->owner) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100698 l_ptr->owner->permit_changeover) {
699 l_ptr->reset_checkpoint = checkpoint;
700 l_ptr->exp_msg_count = START_CHANGEOVER;
701 }
702
703 /* Clean up all queues: */
704
705 link_release_outqueue(l_ptr);
706 buf_discard(l_ptr->proto_msg_queue);
707 l_ptr->proto_msg_queue = NULL;
708 buf = l_ptr->oldest_deferred_in;
709 while (buf) {
710 struct sk_buff *next = buf->next;
711 buf_discard(buf);
712 buf = next;
713 }
714 if (!list_empty(&l_ptr->waiting_ports))
Per Liden4323add2006-01-18 00:38:21 +0100715 tipc_link_wakeup_ports(l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100716
717 l_ptr->retransm_queue_head = 0;
718 l_ptr->retransm_queue_size = 0;
719 l_ptr->last_out = NULL;
720 l_ptr->first_out = NULL;
721 l_ptr->next_out = NULL;
722 l_ptr->unacked_window = 0;
723 l_ptr->checkpoint = 1;
724 l_ptr->next_out_no = 1;
725 l_ptr->deferred_inqueue_sz = 0;
726 l_ptr->oldest_deferred_in = NULL;
727 l_ptr->newest_deferred_in = NULL;
728 l_ptr->fsm_msg_cnt = 0;
729 l_ptr->stale_count = 0;
730 link_reset_statistics(l_ptr);
731
Per Liden4323add2006-01-18 00:38:21 +0100732 link_send_event(tipc_cfg_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100733 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100734 link_send_event(tipc_disc_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100735}
736
737
738static void link_activate(struct link *l_ptr)
739{
Allan Stephens5392d642006-06-25 23:52:50 -0700740 l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
Per Liden4323add2006-01-18 00:38:21 +0100741 tipc_node_link_up(l_ptr->owner, l_ptr);
742 tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr);
743 link_send_event(tipc_cfg_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100744 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100745 link_send_event(tipc_disc_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100746}
747
748/**
749 * link_state_event - link finite state machine
750 * @l_ptr: pointer to link
751 * @event: state machine event to process
752 */
753
754static void link_state_event(struct link *l_ptr, unsigned event)
755{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900756 struct link *other;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100757 u32 cont_intv = l_ptr->continuity_interval;
758
759 if (!l_ptr->started && (event != STARTING_EVT))
760 return; /* Not yet. */
761
762 if (link_blocked(l_ptr)) {
763 if (event == TIMEOUT_EVT) {
764 link_set_timer(l_ptr, cont_intv);
765 }
766 return; /* Changeover going on */
767 }
768 dbg_link("STATE_EV: <%s> ", l_ptr->name);
769
770 switch (l_ptr->state) {
771 case WORKING_WORKING:
772 dbg_link("WW/");
773 switch (event) {
774 case TRAFFIC_MSG_EVT:
775 dbg_link("TRF-");
776 /* fall through */
777 case ACTIVATE_MSG:
778 dbg_link("ACT\n");
779 break;
780 case TIMEOUT_EVT:
781 dbg_link("TIM ");
782 if (l_ptr->next_in_no != l_ptr->checkpoint) {
783 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100784 if (tipc_bclink_acks_missing(l_ptr->owner)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900785 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100786 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100787 l_ptr->fsm_msg_cnt++;
788 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900789 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100790 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100791 l_ptr->fsm_msg_cnt++;
792 }
793 link_set_timer(l_ptr, cont_intv);
794 break;
795 }
796 dbg_link(" -> WU\n");
797 l_ptr->state = WORKING_UNKNOWN;
798 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100799 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100800 l_ptr->fsm_msg_cnt++;
801 link_set_timer(l_ptr, cont_intv / 4);
802 break;
803 case RESET_MSG:
804 dbg_link("RES -> RR\n");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900805 info("Resetting link <%s>, requested by peer\n",
Allan Stephensa10bd922006-06-25 23:52:17 -0700806 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100807 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100808 l_ptr->state = RESET_RESET;
809 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100810 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100811 l_ptr->fsm_msg_cnt++;
812 link_set_timer(l_ptr, cont_intv);
813 break;
814 default:
815 err("Unknown link event %u in WW state\n", event);
816 }
817 break;
818 case WORKING_UNKNOWN:
819 dbg_link("WU/");
820 switch (event) {
821 case TRAFFIC_MSG_EVT:
822 dbg_link("TRF-");
823 case ACTIVATE_MSG:
824 dbg_link("ACT -> WW\n");
825 l_ptr->state = WORKING_WORKING;
826 l_ptr->fsm_msg_cnt = 0;
827 link_set_timer(l_ptr, cont_intv);
828 break;
829 case RESET_MSG:
830 dbg_link("RES -> RR\n");
Allan Stephensa10bd922006-06-25 23:52:17 -0700831 info("Resetting link <%s>, requested by peer "
832 "while probing\n", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100833 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100834 l_ptr->state = RESET_RESET;
835 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100836 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100837 l_ptr->fsm_msg_cnt++;
838 link_set_timer(l_ptr, cont_intv);
839 break;
840 case TIMEOUT_EVT:
841 dbg_link("TIM ");
842 if (l_ptr->next_in_no != l_ptr->checkpoint) {
Frans Popa570f092010-03-24 07:57:29 +0000843 dbg_link("-> WW\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100844 l_ptr->state = WORKING_WORKING;
845 l_ptr->fsm_msg_cnt = 0;
846 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100847 if (tipc_bclink_acks_missing(l_ptr->owner)) {
848 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
849 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100850 l_ptr->fsm_msg_cnt++;
851 }
852 link_set_timer(l_ptr, cont_intv);
853 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
854 dbg_link("Probing %u/%u,timer = %u ms)\n",
855 l_ptr->fsm_msg_cnt, l_ptr->abort_limit,
856 cont_intv / 4);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900857 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100858 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100859 l_ptr->fsm_msg_cnt++;
860 link_set_timer(l_ptr, cont_intv / 4);
861 } else { /* Link has failed */
862 dbg_link("-> RU (%u probes unanswered)\n",
863 l_ptr->fsm_msg_cnt);
Allan Stephensa10bd922006-06-25 23:52:17 -0700864 warn("Resetting link <%s>, peer not responding\n",
865 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100866 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100867 l_ptr->state = RESET_UNKNOWN;
868 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100869 tipc_link_send_proto_msg(l_ptr, RESET_MSG,
870 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100871 l_ptr->fsm_msg_cnt++;
872 link_set_timer(l_ptr, cont_intv);
873 }
874 break;
875 default:
876 err("Unknown link event %u in WU state\n", event);
877 }
878 break;
879 case RESET_UNKNOWN:
880 dbg_link("RU/");
881 switch (event) {
882 case TRAFFIC_MSG_EVT:
883 dbg_link("TRF-\n");
884 break;
885 case ACTIVATE_MSG:
886 other = l_ptr->owner->active_links[0];
887 if (other && link_working_unknown(other)) {
888 dbg_link("ACT\n");
889 break;
890 }
891 dbg_link("ACT -> WW\n");
892 l_ptr->state = WORKING_WORKING;
893 l_ptr->fsm_msg_cnt = 0;
894 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100895 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100896 l_ptr->fsm_msg_cnt++;
897 link_set_timer(l_ptr, cont_intv);
898 break;
899 case RESET_MSG:
Frans Popa570f092010-03-24 07:57:29 +0000900 dbg_link("RES\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100901 dbg_link(" -> RR\n");
902 l_ptr->state = RESET_RESET;
903 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100904 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100905 l_ptr->fsm_msg_cnt++;
906 link_set_timer(l_ptr, cont_intv);
907 break;
908 case STARTING_EVT:
909 dbg_link("START-");
910 l_ptr->started = 1;
911 /* fall through */
912 case TIMEOUT_EVT:
Frans Popa570f092010-03-24 07:57:29 +0000913 dbg_link("TIM\n");
Per Liden4323add2006-01-18 00:38:21 +0100914 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100915 l_ptr->fsm_msg_cnt++;
916 link_set_timer(l_ptr, cont_intv);
917 break;
918 default:
919 err("Unknown link event %u in RU state\n", event);
920 }
921 break;
922 case RESET_RESET:
923 dbg_link("RR/ ");
924 switch (event) {
925 case TRAFFIC_MSG_EVT:
926 dbg_link("TRF-");
927 /* fall through */
928 case ACTIVATE_MSG:
929 other = l_ptr->owner->active_links[0];
930 if (other && link_working_unknown(other)) {
931 dbg_link("ACT\n");
932 break;
933 }
934 dbg_link("ACT -> WW\n");
935 l_ptr->state = WORKING_WORKING;
936 l_ptr->fsm_msg_cnt = 0;
937 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100938 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100939 l_ptr->fsm_msg_cnt++;
940 link_set_timer(l_ptr, cont_intv);
941 break;
942 case RESET_MSG:
943 dbg_link("RES\n");
944 break;
945 case TIMEOUT_EVT:
946 dbg_link("TIM\n");
Per Liden4323add2006-01-18 00:38:21 +0100947 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100948 l_ptr->fsm_msg_cnt++;
949 link_set_timer(l_ptr, cont_intv);
950 dbg_link("fsm_msg_cnt %u\n", l_ptr->fsm_msg_cnt);
951 break;
952 default:
953 err("Unknown link event %u in RR state\n", event);
954 }
955 break;
956 default:
957 err("Unknown link state %u/%u\n", l_ptr->state, event);
958 }
959}
960
961/*
962 * link_bundle_buf(): Append contents of a buffer to
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900963 * the tail of an existing one.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100964 */
965
966static int link_bundle_buf(struct link *l_ptr,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900967 struct sk_buff *bundler,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100968 struct sk_buff *buf)
969{
970 struct tipc_msg *bundler_msg = buf_msg(bundler);
971 struct tipc_msg *msg = buf_msg(buf);
972 u32 size = msg_size(msg);
Allan Stephense49060c2006-06-29 12:32:46 -0700973 u32 bundle_size = msg_size(bundler_msg);
974 u32 to_pos = align(bundle_size);
975 u32 pad = to_pos - bundle_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100976
977 if (msg_user(bundler_msg) != MSG_BUNDLER)
978 return 0;
979 if (msg_type(bundler_msg) != OPEN_MSG)
980 return 0;
Allan Stephense49060c2006-06-29 12:32:46 -0700981 if (skb_tailroom(bundler) < (pad + size))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100982 return 0;
Allan Stephens15e979d2010-05-11 14:30:10 +0000983 if (l_ptr->max_pkt < (to_pos + size))
Allan Stephens863fae62006-07-03 19:39:36 -0700984 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100985
Allan Stephense49060c2006-06-29 12:32:46 -0700986 skb_put(bundler, pad + size);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300987 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100988 msg_set_size(bundler_msg, to_pos + size);
989 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
990 dbg("Packed msg # %u(%u octets) into pos %u in buf(#%u)\n",
991 msg_msgcnt(bundler_msg), size, to_pos, msg_seqno(bundler_msg));
992 msg_dbg(msg, "PACKD:");
993 buf_discard(buf);
994 l_ptr->stats.sent_bundled++;
995 return 1;
996}
997
Sam Ravnborg05790c62006-03-20 22:37:04 -0800998static void link_add_to_outqueue(struct link *l_ptr,
999 struct sk_buff *buf,
1000 struct tipc_msg *msg)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001001{
1002 u32 ack = mod(l_ptr->next_in_no - 1);
1003 u32 seqno = mod(l_ptr->next_out_no++);
1004
1005 msg_set_word(msg, 2, ((ack << 16) | seqno));
1006 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
1007 buf->next = NULL;
1008 if (l_ptr->first_out) {
1009 l_ptr->last_out->next = buf;
1010 l_ptr->last_out = buf;
1011 } else
1012 l_ptr->first_out = l_ptr->last_out = buf;
1013 l_ptr->out_queue_size++;
1014}
1015
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001016/*
1017 * tipc_link_send_buf() is the 'full path' for messages, called from
Per Lidenb97bf3f2006-01-02 19:04:38 +01001018 * inside TIPC when the 'fast path' in tipc_send_buf
1019 * has failed, and from link_send()
1020 */
1021
Per Liden4323add2006-01-18 00:38:21 +01001022int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001023{
1024 struct tipc_msg *msg = buf_msg(buf);
1025 u32 size = msg_size(msg);
1026 u32 dsz = msg_data_sz(msg);
1027 u32 queue_size = l_ptr->out_queue_size;
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001028 u32 imp = tipc_msg_tot_importance(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001029 u32 queue_limit = l_ptr->queue_limit[imp];
Allan Stephens15e979d2010-05-11 14:30:10 +00001030 u32 max_packet = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001031
1032 msg_set_prevnode(msg, tipc_own_addr); /* If routed message */
1033
1034 /* Match msg importance against queue limits: */
1035
1036 if (unlikely(queue_size >= queue_limit)) {
1037 if (imp <= TIPC_CRITICAL_IMPORTANCE) {
1038 return link_schedule_port(l_ptr, msg_origport(msg),
1039 size);
1040 }
1041 msg_dbg(msg, "TIPC: Congestion, throwing away\n");
1042 buf_discard(buf);
1043 if (imp > CONN_MANAGER) {
Allan Stephensa10bd922006-06-25 23:52:17 -07001044 warn("Resetting link <%s>, send queue full", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +01001045 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001046 }
1047 return dsz;
1048 }
1049
1050 /* Fragmentation needed ? */
1051
1052 if (size > max_packet)
Per Liden4323add2006-01-18 00:38:21 +01001053 return tipc_link_send_long_buf(l_ptr, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001054
1055 /* Packet can be queued or sent: */
1056
1057 if (queue_size > l_ptr->stats.max_queue_sz)
1058 l_ptr->stats.max_queue_sz = queue_size;
1059
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001060 if (likely(!tipc_bearer_congested(l_ptr->b_ptr, l_ptr) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001061 !link_congested(l_ptr))) {
1062 link_add_to_outqueue(l_ptr, buf, msg);
1063
Per Liden4323add2006-01-18 00:38:21 +01001064 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001065 l_ptr->unacked_window = 0;
1066 } else {
Per Liden4323add2006-01-18 00:38:21 +01001067 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001068 l_ptr->stats.bearer_congs++;
1069 l_ptr->next_out = buf;
1070 }
1071 return dsz;
1072 }
1073 /* Congestion: can message be bundled ?: */
1074
1075 if ((msg_user(msg) != CHANGEOVER_PROTOCOL) &&
1076 (msg_user(msg) != MSG_FRAGMENTER)) {
1077
1078 /* Try adding message to an existing bundle */
1079
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001080 if (l_ptr->next_out &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001081 link_bundle_buf(l_ptr, l_ptr->last_out, buf)) {
Per Liden4323add2006-01-18 00:38:21 +01001082 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001083 return dsz;
1084 }
1085
1086 /* Try creating a new bundle */
1087
1088 if (size <= max_packet * 2 / 3) {
1089 struct sk_buff *bundler = buf_acquire(max_packet);
1090 struct tipc_msg bundler_hdr;
1091
1092 if (bundler) {
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001093 tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG,
Allan Stephens75715212008-06-04 17:37:34 -07001094 INT_H_SIZE, l_ptr->addr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001095 skb_copy_to_linear_data(bundler, &bundler_hdr,
1096 INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001097 skb_trim(bundler, INT_H_SIZE);
1098 link_bundle_buf(l_ptr, bundler, buf);
1099 buf = bundler;
1100 msg = buf_msg(buf);
1101 l_ptr->stats.sent_bundles++;
1102 }
1103 }
1104 }
1105 if (!l_ptr->next_out)
1106 l_ptr->next_out = buf;
1107 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +01001108 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001109 return dsz;
1110}
1111
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001112/*
1113 * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has
Per Lidenb97bf3f2006-01-02 19:04:38 +01001114 * not been selected yet, and the the owner node is not locked
1115 * Called by TIPC internal users, e.g. the name distributor
1116 */
1117
Per Liden4323add2006-01-18 00:38:21 +01001118int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001119{
1120 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001121 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001122 int res = -ELINKCONG;
1123
Per Liden4323add2006-01-18 00:38:21 +01001124 read_lock_bh(&tipc_net_lock);
1125 n_ptr = tipc_node_select(dest, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001126 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001127 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001128 l_ptr = n_ptr->active_links[selector & 1];
Per Lidenb97bf3f2006-01-02 19:04:38 +01001129 if (l_ptr) {
Allan Stephensc33d53b2006-06-25 23:50:30 -07001130 dbg("tipc_link_send: found link %x for dest %x\n", l_ptr, dest);
Per Liden4323add2006-01-18 00:38:21 +01001131 res = tipc_link_send_buf(l_ptr, buf);
Allan Stephensc33d53b2006-06-25 23:50:30 -07001132 } else {
1133 dbg("Attempt to send msg to unreachable node:\n");
1134 msg_dbg(buf_msg(buf),">>>");
1135 buf_discard(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001136 }
Per Liden4323add2006-01-18 00:38:21 +01001137 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001138 } else {
1139 dbg("Attempt to send msg to unknown node:\n");
1140 msg_dbg(buf_msg(buf),">>>");
1141 buf_discard(buf);
1142 }
Per Liden4323add2006-01-18 00:38:21 +01001143 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001144 return res;
1145}
1146
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001147/*
1148 * link_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001149 * destination link is known and the header is complete,
1150 * inclusive total message length. Very time critical.
1151 * Link is locked. Returns user data length.
1152 */
1153
Sam Ravnborg05790c62006-03-20 22:37:04 -08001154static int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf,
1155 u32 *used_max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001156{
1157 struct tipc_msg *msg = buf_msg(buf);
1158 int res = msg_data_sz(msg);
1159
1160 if (likely(!link_congested(l_ptr))) {
Allan Stephens15e979d2010-05-11 14:30:10 +00001161 if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001162 if (likely(list_empty(&l_ptr->b_ptr->cong_links))) {
1163 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +01001164 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf,
1165 &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001166 l_ptr->unacked_window = 0;
1167 msg_dbg(msg,"SENT_FAST:");
1168 return res;
1169 }
1170 dbg("failed sent fast...\n");
Per Liden4323add2006-01-18 00:38:21 +01001171 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001172 l_ptr->stats.bearer_congs++;
1173 l_ptr->next_out = buf;
1174 return res;
1175 }
1176 }
1177 else
Allan Stephens15e979d2010-05-11 14:30:10 +00001178 *used_max_pkt = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001179 }
Per Liden4323add2006-01-18 00:38:21 +01001180 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001181}
1182
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001183/*
1184 * tipc_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001185 * destination node is known and the header is complete,
1186 * inclusive total message length.
1187 * Returns user data length.
1188 */
1189int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode)
1190{
1191 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001192 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001193 int res;
1194 u32 selector = msg_origport(buf_msg(buf)) & 1;
1195 u32 dummy;
1196
1197 if (destnode == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +01001198 return tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001199
Per Liden4323add2006-01-18 00:38:21 +01001200 read_lock_bh(&tipc_net_lock);
1201 n_ptr = tipc_node_select(destnode, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001202 if (likely(n_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001203 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001204 l_ptr = n_ptr->active_links[selector];
1205 dbg("send_fast: buf %x selected %x, destnode = %x\n",
1206 buf, l_ptr, destnode);
1207 if (likely(l_ptr)) {
1208 res = link_send_buf_fast(l_ptr, buf, &dummy);
Per Liden4323add2006-01-18 00:38:21 +01001209 tipc_node_unlock(n_ptr);
1210 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001211 return res;
1212 }
Per Liden4323add2006-01-18 00:38:21 +01001213 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001214 }
Per Liden4323add2006-01-18 00:38:21 +01001215 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001216 res = msg_data_sz(buf_msg(buf));
1217 tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1218 return res;
1219}
1220
1221
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001222/*
1223 * tipc_link_send_sections_fast: Entry for messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001224 * destination processor is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001225 * except for total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001226 * Returns user data length or errno.
1227 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001228int tipc_link_send_sections_fast(struct port *sender,
Per Liden4323add2006-01-18 00:38:21 +01001229 struct iovec const *msg_sect,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001230 const u32 num_sect,
Per Liden4323add2006-01-18 00:38:21 +01001231 u32 destaddr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001232{
1233 struct tipc_msg *hdr = &sender->publ.phdr;
1234 struct link *l_ptr;
1235 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -07001236 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001237 int res;
1238 u32 selector = msg_origport(hdr) & 1;
1239
Per Lidenb97bf3f2006-01-02 19:04:38 +01001240again:
1241 /*
1242 * Try building message using port's max_pkt hint.
1243 * (Must not hold any locks while building message.)
1244 */
1245
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001246 res = tipc_msg_build(hdr, msg_sect, num_sect, sender->publ.max_pkt,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001247 !sender->user_port, &buf);
1248
Per Liden4323add2006-01-18 00:38:21 +01001249 read_lock_bh(&tipc_net_lock);
1250 node = tipc_node_select(destaddr, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001251 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001252 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001253 l_ptr = node->active_links[selector];
1254 if (likely(l_ptr)) {
1255 if (likely(buf)) {
1256 res = link_send_buf_fast(l_ptr, buf,
Allan Stephens05646c92007-06-10 17:25:24 -07001257 &sender->publ.max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001258 if (unlikely(res < 0))
1259 buf_discard(buf);
1260exit:
Per Liden4323add2006-01-18 00:38:21 +01001261 tipc_node_unlock(node);
1262 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001263 return res;
1264 }
1265
1266 /* Exit if build request was invalid */
1267
1268 if (unlikely(res < 0))
1269 goto exit;
1270
1271 /* Exit if link (or bearer) is congested */
1272
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001273 if (link_congested(l_ptr) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +01001274 !list_empty(&l_ptr->b_ptr->cong_links)) {
1275 res = link_schedule_port(l_ptr,
1276 sender->publ.ref, res);
1277 goto exit;
1278 }
1279
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001280 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001281 * Message size exceeds max_pkt hint; update hint,
1282 * then re-try fast path or fragment the message
1283 */
1284
Allan Stephens15e979d2010-05-11 14:30:10 +00001285 sender->publ.max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001286 tipc_node_unlock(node);
1287 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001288
1289
Allan Stephens05646c92007-06-10 17:25:24 -07001290 if ((msg_hdr_sz(hdr) + res) <= sender->publ.max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001291 goto again;
1292
1293 return link_send_sections_long(sender, msg_sect,
1294 num_sect, destaddr);
1295 }
Per Liden4323add2006-01-18 00:38:21 +01001296 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001297 }
Per Liden4323add2006-01-18 00:38:21 +01001298 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001299
1300 /* Couldn't find a link to the destination node */
1301
1302 if (buf)
1303 return tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1304 if (res >= 0)
Per Liden4323add2006-01-18 00:38:21 +01001305 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1306 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001307 return res;
1308}
1309
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001310/*
1311 * link_send_sections_long(): Entry for long messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001312 * destination node is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001313 * inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001314 * Link and bearer congestion status have been checked to be ok,
1315 * and are ignored if they change.
1316 *
1317 * Note that fragments do not use the full link MTU so that they won't have
1318 * to undergo refragmentation if link changeover causes them to be sent
1319 * over another link with an additional tunnel header added as prefix.
1320 * (Refragmentation will still occur if the other link has a smaller MTU.)
1321 *
1322 * Returns user data length or errno.
1323 */
1324static int link_send_sections_long(struct port *sender,
1325 struct iovec const *msg_sect,
1326 u32 num_sect,
1327 u32 destaddr)
1328{
1329 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001330 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001331 struct tipc_msg *hdr = &sender->publ.phdr;
1332 u32 dsz = msg_data_sz(hdr);
1333 u32 max_pkt,fragm_sz,rest;
1334 struct tipc_msg fragm_hdr;
1335 struct sk_buff *buf,*buf_chain,*prev;
1336 u32 fragm_crs,fragm_rest,hsz,sect_rest;
1337 const unchar *sect_crs;
1338 int curr_sect;
1339 u32 fragm_no;
1340
1341again:
1342 fragm_no = 1;
Allan Stephens05646c92007-06-10 17:25:24 -07001343 max_pkt = sender->publ.max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001344 /* leave room for tunnel header in case of link changeover */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001345 fragm_sz = max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001346 /* leave room for fragmentation header in each fragment */
1347 rest = dsz;
1348 fragm_crs = 0;
1349 fragm_rest = 0;
1350 sect_rest = 0;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001351 sect_crs = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001352 curr_sect = -1;
1353
1354 /* Prepare reusable fragment header: */
1355
1356 msg_dbg(hdr, ">FRAGMENTING>");
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001357 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07001358 INT_H_SIZE, msg_destnode(hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001359 msg_set_link_selector(&fragm_hdr, sender->publ.ref);
1360 msg_set_size(&fragm_hdr, max_pkt);
1361 msg_set_fragm_no(&fragm_hdr, 1);
1362
1363 /* Prepare header of first fragment: */
1364
1365 buf_chain = buf = buf_acquire(max_pkt);
1366 if (!buf)
1367 return -ENOMEM;
1368 buf->next = NULL;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001369 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001370 hsz = msg_hdr_sz(hdr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001371 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001372 msg_dbg(buf_msg(buf), ">BUILD>");
1373
1374 /* Chop up message: */
1375
1376 fragm_crs = INT_H_SIZE + hsz;
1377 fragm_rest = fragm_sz - hsz;
1378
1379 do { /* For all sections */
1380 u32 sz;
1381
1382 if (!sect_rest) {
1383 sect_rest = msg_sect[++curr_sect].iov_len;
1384 sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
1385 }
1386
1387 if (sect_rest < fragm_rest)
1388 sz = sect_rest;
1389 else
1390 sz = fragm_rest;
1391
1392 if (likely(!sender->user_port)) {
1393 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
1394error:
1395 for (; buf_chain; buf_chain = buf) {
1396 buf = buf_chain->next;
1397 buf_discard(buf_chain);
1398 }
1399 return -EFAULT;
1400 }
1401 } else
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001402 skb_copy_to_linear_data_offset(buf, fragm_crs,
1403 sect_crs, sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001404 sect_crs += sz;
1405 sect_rest -= sz;
1406 fragm_crs += sz;
1407 fragm_rest -= sz;
1408 rest -= sz;
1409
1410 if (!fragm_rest && rest) {
1411
1412 /* Initiate new fragment: */
1413 if (rest <= fragm_sz) {
1414 fragm_sz = rest;
1415 msg_set_type(&fragm_hdr,LAST_FRAGMENT);
1416 } else {
1417 msg_set_type(&fragm_hdr, FRAGMENT);
1418 }
1419 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
1420 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
1421 prev = buf;
1422 buf = buf_acquire(fragm_sz + INT_H_SIZE);
1423 if (!buf)
1424 goto error;
1425
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001426 buf->next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001427 prev->next = buf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001428 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001429 fragm_crs = INT_H_SIZE;
1430 fragm_rest = fragm_sz;
1431 msg_dbg(buf_msg(buf)," >BUILD>");
1432 }
1433 }
1434 while (rest > 0);
1435
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001436 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001437 * Now we have a buffer chain. Select a link and check
1438 * that packet size is still OK
1439 */
Per Liden4323add2006-01-18 00:38:21 +01001440 node = tipc_node_select(destaddr, sender->publ.ref & 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001441 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001442 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001443 l_ptr = node->active_links[sender->publ.ref & 1];
1444 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001445 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001446 goto reject;
1447 }
Allan Stephens15e979d2010-05-11 14:30:10 +00001448 if (l_ptr->max_pkt < max_pkt) {
1449 sender->publ.max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001450 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001451 for (; buf_chain; buf_chain = buf) {
1452 buf = buf_chain->next;
1453 buf_discard(buf_chain);
1454 }
1455 goto again;
1456 }
1457 } else {
1458reject:
1459 for (; buf_chain; buf_chain = buf) {
1460 buf = buf_chain->next;
1461 buf_discard(buf_chain);
1462 }
Per Liden4323add2006-01-18 00:38:21 +01001463 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1464 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001465 }
1466
1467 /* Append whole chain to send queue: */
1468
1469 buf = buf_chain;
1470 l_ptr->long_msg_seq_no = mod(l_ptr->long_msg_seq_no + 1);
1471 if (!l_ptr->next_out)
1472 l_ptr->next_out = buf_chain;
1473 l_ptr->stats.sent_fragmented++;
1474 while (buf) {
1475 struct sk_buff *next = buf->next;
1476 struct tipc_msg *msg = buf_msg(buf);
1477
1478 l_ptr->stats.sent_fragments++;
1479 msg_set_long_msgno(msg, l_ptr->long_msg_seq_no);
1480 link_add_to_outqueue(l_ptr, buf, msg);
1481 msg_dbg(msg, ">ADD>");
1482 buf = next;
1483 }
1484
1485 /* Send it, if possible: */
1486
Per Liden4323add2006-01-18 00:38:21 +01001487 tipc_link_push_queue(l_ptr);
1488 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001489 return dsz;
1490}
1491
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001492/*
Per Liden4323add2006-01-18 00:38:21 +01001493 * tipc_link_push_packet: Push one unsent packet to the media
Per Lidenb97bf3f2006-01-02 19:04:38 +01001494 */
Per Liden4323add2006-01-18 00:38:21 +01001495u32 tipc_link_push_packet(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001496{
1497 struct sk_buff *buf = l_ptr->first_out;
1498 u32 r_q_size = l_ptr->retransm_queue_size;
1499 u32 r_q_head = l_ptr->retransm_queue_head;
1500
1501 /* Step to position where retransmission failed, if any, */
1502 /* consider that buffers may have been released in meantime */
1503
1504 if (r_q_size && buf) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001505 u32 last = lesser(mod(r_q_head + r_q_size),
Per Lidenb97bf3f2006-01-02 19:04:38 +01001506 link_last_sent(l_ptr));
1507 u32 first = msg_seqno(buf_msg(buf));
1508
1509 while (buf && less(first, r_q_head)) {
1510 first = mod(first + 1);
1511 buf = buf->next;
1512 }
1513 l_ptr->retransm_queue_head = r_q_head = first;
1514 l_ptr->retransm_queue_size = r_q_size = mod(last - first);
1515 }
1516
1517 /* Continue retransmission now, if there is anything: */
1518
Neil Hormanca509102010-03-15 07:58:45 +00001519 if (r_q_size && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001520 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001521 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001522 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001523 msg_dbg(buf_msg(buf), ">DEF-RETR>");
1524 l_ptr->retransm_queue_head = mod(++r_q_head);
1525 l_ptr->retransm_queue_size = --r_q_size;
1526 l_ptr->stats.retransmitted++;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001527 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001528 } else {
1529 l_ptr->stats.bearer_congs++;
1530 msg_dbg(buf_msg(buf), "|>DEF-RETR>");
1531 return PUSH_FAILED;
1532 }
1533 }
1534
1535 /* Send deferred protocol message, if any: */
1536
1537 buf = l_ptr->proto_msg_queue;
1538 if (buf) {
1539 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001540 msg_set_bcast_ack(buf_msg(buf),l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001541 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001542 msg_dbg(buf_msg(buf), ">DEF-PROT>");
1543 l_ptr->unacked_window = 0;
1544 buf_discard(buf);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001545 l_ptr->proto_msg_queue = NULL;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001546 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001547 } else {
1548 msg_dbg(buf_msg(buf), "|>DEF-PROT>");
1549 l_ptr->stats.bearer_congs++;
1550 return PUSH_FAILED;
1551 }
1552 }
1553
1554 /* Send one deferred data message, if send window not full: */
1555
1556 buf = l_ptr->next_out;
1557 if (buf) {
1558 struct tipc_msg *msg = buf_msg(buf);
1559 u32 next = msg_seqno(msg);
1560 u32 first = msg_seqno(buf_msg(l_ptr->first_out));
1561
1562 if (mod(next - first) < l_ptr->queue_limit[0]) {
1563 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001564 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001565 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001566 if (msg_user(msg) == MSG_BUNDLER)
1567 msg_set_type(msg, CLOSED_MSG);
1568 msg_dbg(msg, ">PUSH-DATA>");
1569 l_ptr->next_out = buf->next;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001570 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001571 } else {
1572 msg_dbg(msg, "|PUSH-DATA|");
1573 l_ptr->stats.bearer_congs++;
1574 return PUSH_FAILED;
1575 }
1576 }
1577 }
1578 return PUSH_FINISHED;
1579}
1580
1581/*
1582 * push_queue(): push out the unsent messages of a link where
1583 * congestion has abated. Node is locked
1584 */
Per Liden4323add2006-01-18 00:38:21 +01001585void tipc_link_push_queue(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001586{
1587 u32 res;
1588
Per Liden4323add2006-01-18 00:38:21 +01001589 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001590 return;
1591
1592 do {
Per Liden4323add2006-01-18 00:38:21 +01001593 res = tipc_link_push_packet(l_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -07001594 } while (!res);
1595
Per Lidenb97bf3f2006-01-02 19:04:38 +01001596 if (res == PUSH_FAILED)
Per Liden4323add2006-01-18 00:38:21 +01001597 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001598}
1599
Allan Stephensd356eeb2006-06-25 23:40:01 -07001600static void link_reset_all(unsigned long addr)
1601{
David S. Miller6c000552008-09-02 23:38:32 -07001602 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001603 char addr_string[16];
1604 u32 i;
1605
1606 read_lock_bh(&tipc_net_lock);
1607 n_ptr = tipc_node_find((u32)addr);
1608 if (!n_ptr) {
1609 read_unlock_bh(&tipc_net_lock);
1610 return; /* node no longer exists */
1611 }
1612
1613 tipc_node_lock(n_ptr);
1614
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001615 warn("Resetting all links to %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001616 tipc_addr_string_fill(addr_string, n_ptr->addr));
Allan Stephensd356eeb2006-06-25 23:40:01 -07001617
1618 for (i = 0; i < MAX_BEARERS; i++) {
1619 if (n_ptr->links[i]) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001620 link_print(n_ptr->links[i], TIPC_OUTPUT,
Allan Stephensd356eeb2006-06-25 23:40:01 -07001621 "Resetting link\n");
1622 tipc_link_reset(n_ptr->links[i]);
1623 }
1624 }
1625
1626 tipc_node_unlock(n_ptr);
1627 read_unlock_bh(&tipc_net_lock);
1628}
1629
1630static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf)
1631{
1632 struct tipc_msg *msg = buf_msg(buf);
1633
1634 warn("Retransmission failure on link <%s>\n", l_ptr->name);
Allan Stephens48c97132008-05-05 01:24:06 -07001635 tipc_msg_dbg(TIPC_OUTPUT, msg, ">RETR-FAIL>");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001636
1637 if (l_ptr->addr) {
1638
1639 /* Handle failure on standard link */
1640
1641 link_print(l_ptr, TIPC_OUTPUT, "Resetting link\n");
1642 tipc_link_reset(l_ptr);
1643
1644 } else {
1645
1646 /* Handle failure on broadcast link */
1647
David S. Miller6c000552008-09-02 23:38:32 -07001648 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001649 char addr_string[16];
1650
1651 tipc_printf(TIPC_OUTPUT, "Msg seq number: %u, ", msg_seqno(msg));
Jeff Garzik617dbea2006-10-03 16:25:34 -07001652 tipc_printf(TIPC_OUTPUT, "Outstanding acks: %lu\n",
1653 (unsigned long) TIPC_SKB_CB(buf)->handle);
1654
Allan Stephensd356eeb2006-06-25 23:40:01 -07001655 n_ptr = l_ptr->owner->next;
1656 tipc_node_lock(n_ptr);
1657
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001658 tipc_addr_string_fill(addr_string, n_ptr->addr);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001659 tipc_printf(TIPC_OUTPUT, "Multicast link info for %s\n", addr_string);
1660 tipc_printf(TIPC_OUTPUT, "Supported: %d, ", n_ptr->bclink.supported);
1661 tipc_printf(TIPC_OUTPUT, "Acked: %u\n", n_ptr->bclink.acked);
1662 tipc_printf(TIPC_OUTPUT, "Last in: %u, ", n_ptr->bclink.last_in);
1663 tipc_printf(TIPC_OUTPUT, "Gap after: %u, ", n_ptr->bclink.gap_after);
1664 tipc_printf(TIPC_OUTPUT, "Gap to: %u\n", n_ptr->bclink.gap_to);
1665 tipc_printf(TIPC_OUTPUT, "Nack sync: %u\n\n", n_ptr->bclink.nack_sync);
1666
1667 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
1668
1669 tipc_node_unlock(n_ptr);
1670
1671 l_ptr->stale_count = 0;
1672 }
1673}
1674
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001675void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf,
Per Liden4323add2006-01-18 00:38:21 +01001676 u32 retransmits)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001677{
1678 struct tipc_msg *msg;
1679
Allan Stephensd356eeb2006-06-25 23:40:01 -07001680 if (!buf)
1681 return;
1682
1683 msg = buf_msg(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001684
Per Lidenb97bf3f2006-01-02 19:04:38 +01001685 dbg("Retransmitting %u in link %x\n", retransmits, l_ptr);
1686
Allan Stephensd356eeb2006-06-25 23:40:01 -07001687 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Neil Hormanca509102010-03-15 07:58:45 +00001688 if (l_ptr->retransm_queue_size == 0) {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001689 msg_dbg(msg, ">NO_RETR->BCONG>");
1690 dbg_print_link(l_ptr, " ");
1691 l_ptr->retransm_queue_head = msg_seqno(msg);
1692 l_ptr->retransm_queue_size = retransmits;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001693 } else {
Neil Hormanca509102010-03-15 07:58:45 +00001694 err("Unexpected retransmit on link %s (qsize=%d)\n",
1695 l_ptr->name, l_ptr->retransm_queue_size);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001696 }
Neil Hormanca509102010-03-15 07:58:45 +00001697 return;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001698 } else {
1699 /* Detect repeated retransmit failures on uncongested bearer */
1700
1701 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1702 if (++l_ptr->stale_count > 100) {
1703 link_retransmit_failure(l_ptr, buf);
1704 return;
1705 }
1706 } else {
1707 l_ptr->last_retransmitted = msg_seqno(msg);
1708 l_ptr->stale_count = 1;
1709 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001710 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001711
Neil Hormanca509102010-03-15 07:58:45 +00001712 while (retransmits && (buf != l_ptr->next_out) && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001713 msg = buf_msg(buf);
1714 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001715 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001716 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001717 msg_dbg(buf_msg(buf), ">RETR>");
1718 buf = buf->next;
1719 retransmits--;
1720 l_ptr->stats.retransmitted++;
1721 } else {
Per Liden4323add2006-01-18 00:38:21 +01001722 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001723 l_ptr->stats.bearer_congs++;
1724 l_ptr->retransm_queue_head = msg_seqno(buf_msg(buf));
1725 l_ptr->retransm_queue_size = retransmits;
1726 return;
1727 }
1728 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001729
Per Lidenb97bf3f2006-01-02 19:04:38 +01001730 l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
1731}
1732
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001733/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01001734 * link_insert_deferred_queue - insert deferred messages back into receive chain
1735 */
1736
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001737static struct sk_buff *link_insert_deferred_queue(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001738 struct sk_buff *buf)
1739{
1740 u32 seq_no;
1741
1742 if (l_ptr->oldest_deferred_in == NULL)
1743 return buf;
1744
1745 seq_no = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
1746 if (seq_no == mod(l_ptr->next_in_no)) {
1747 l_ptr->newest_deferred_in->next = buf;
1748 buf = l_ptr->oldest_deferred_in;
1749 l_ptr->oldest_deferred_in = NULL;
1750 l_ptr->deferred_inqueue_sz = 0;
1751 }
1752 return buf;
1753}
1754
Allan Stephens85035562008-04-15 19:04:54 -07001755/**
1756 * link_recv_buf_validate - validate basic format of received message
1757 *
1758 * This routine ensures a TIPC message has an acceptable header, and at least
1759 * as much data as the header indicates it should. The routine also ensures
1760 * that the entire message header is stored in the main fragment of the message
1761 * buffer, to simplify future access to message header fields.
1762 *
1763 * Note: Having extra info present in the message header or data areas is OK.
1764 * TIPC will ignore the excess, under the assumption that it is optional info
1765 * introduced by a later release of the protocol.
1766 */
1767
1768static int link_recv_buf_validate(struct sk_buff *buf)
1769{
1770 static u32 min_data_hdr_size[8] = {
1771 SHORT_H_SIZE, MCAST_H_SIZE, LONG_H_SIZE, DIR_MSG_H_SIZE,
1772 MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
1773 };
1774
1775 struct tipc_msg *msg;
1776 u32 tipc_hdr[2];
1777 u32 size;
1778 u32 hdr_size;
1779 u32 min_hdr_size;
1780
1781 if (unlikely(buf->len < MIN_H_SIZE))
1782 return 0;
1783
1784 msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
1785 if (msg == NULL)
1786 return 0;
1787
1788 if (unlikely(msg_version(msg) != TIPC_VERSION))
1789 return 0;
1790
1791 size = msg_size(msg);
1792 hdr_size = msg_hdr_sz(msg);
1793 min_hdr_size = msg_isdata(msg) ?
1794 min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
1795
1796 if (unlikely((hdr_size < min_hdr_size) ||
1797 (size < hdr_size) ||
1798 (buf->len < size) ||
1799 (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
1800 return 0;
1801
1802 return pskb_may_pull(buf, hdr_size);
1803}
1804
Allan Stephensb02b69c2010-08-17 11:00:07 +00001805/**
1806 * tipc_recv_msg - process TIPC messages arriving from off-node
1807 * @head: pointer to message buffer chain
1808 * @tb_ptr: pointer to bearer message arrived on
1809 *
1810 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1811 * structure (i.e. cannot be NULL), but bearer can be inactive.
1812 */
1813
Per Lidenb97bf3f2006-01-02 19:04:38 +01001814void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *tb_ptr)
1815{
Per Liden4323add2006-01-18 00:38:21 +01001816 read_lock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001817 while (head) {
Allan Stephens1265a022008-06-04 17:32:35 -07001818 struct bearer *b_ptr = (struct bearer *)tb_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001819 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001820 struct link *l_ptr;
1821 struct sk_buff *crs;
1822 struct sk_buff *buf = head;
Allan Stephens85035562008-04-15 19:04:54 -07001823 struct tipc_msg *msg;
1824 u32 seq_no;
1825 u32 ackd;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001826 u32 released = 0;
1827 int type;
1828
Per Lidenb97bf3f2006-01-02 19:04:38 +01001829 head = head->next;
Allan Stephens85035562008-04-15 19:04:54 -07001830
Allan Stephensb02b69c2010-08-17 11:00:07 +00001831 /* Ensure bearer is still enabled */
1832
1833 if (unlikely(!b_ptr->active))
1834 goto cont;
1835
Allan Stephens85035562008-04-15 19:04:54 -07001836 /* Ensure message is well-formed */
1837
1838 if (unlikely(!link_recv_buf_validate(buf)))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001839 goto cont;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001840
Allan Stephensfe13dda2008-04-15 19:03:23 -07001841 /* Ensure message data is a single contiguous unit */
1842
1843 if (unlikely(buf_linearize(buf))) {
1844 goto cont;
1845 }
1846
Allan Stephens85035562008-04-15 19:04:54 -07001847 /* Handle arrival of a non-unicast link message */
1848
1849 msg = buf_msg(buf);
1850
Per Lidenb97bf3f2006-01-02 19:04:38 +01001851 if (unlikely(msg_non_seq(msg))) {
Allan Stephens1265a022008-06-04 17:32:35 -07001852 if (msg_user(msg) == LINK_CONFIG)
1853 tipc_disc_recv_msg(buf, b_ptr);
1854 else
1855 tipc_bclink_recv_pkt(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001856 continue;
1857 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001858
Allan Stephens26008242006-06-25 23:39:31 -07001859 if (unlikely(!msg_short(msg) &&
1860 (msg_destnode(msg) != tipc_own_addr)))
1861 goto cont;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001862
Neil Hormande586572010-03-08 12:43:56 -08001863 /* Discard non-routeable messages destined for another node */
1864
1865 if (unlikely(!msg_isdata(msg) &&
1866 (msg_destnode(msg) != tipc_own_addr))) {
1867 if ((msg_user(msg) != CONN_MANAGER) &&
1868 (msg_user(msg) != MSG_FRAGMENTER))
1869 goto cont;
1870 }
1871
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001872 /* Locate neighboring node that sent message */
Allan Stephens85035562008-04-15 19:04:54 -07001873
Per Liden4323add2006-01-18 00:38:21 +01001874 n_ptr = tipc_node_find(msg_prevnode(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001875 if (unlikely(!n_ptr))
1876 goto cont;
Per Liden4323add2006-01-18 00:38:21 +01001877 tipc_node_lock(n_ptr);
Allan Stephens85035562008-04-15 19:04:54 -07001878
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001879 /* Don't talk to neighbor during cleanup after last session */
1880
1881 if (n_ptr->cleanup_required) {
1882 tipc_node_unlock(n_ptr);
1883 goto cont;
1884 }
1885
1886 /* Locate unicast link endpoint that should handle message */
1887
Per Lidenb97bf3f2006-01-02 19:04:38 +01001888 l_ptr = n_ptr->links[b_ptr->identity];
1889 if (unlikely(!l_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001890 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001891 goto cont;
1892 }
Allan Stephens85035562008-04-15 19:04:54 -07001893
1894 /* Validate message sequence number info */
1895
1896 seq_no = msg_seqno(msg);
1897 ackd = msg_ack(msg);
1898
1899 /* Release acked messages */
1900
Per Lidenb97bf3f2006-01-02 19:04:38 +01001901 if (less(n_ptr->bclink.acked, msg_bcast_ack(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001902 if (tipc_node_is_up(n_ptr) && n_ptr->bclink.supported)
1903 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001904 }
1905
1906 crs = l_ptr->first_out;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001907 while ((crs != l_ptr->next_out) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001908 less_eq(msg_seqno(buf_msg(crs)), ackd)) {
1909 struct sk_buff *next = crs->next;
1910
1911 buf_discard(crs);
1912 crs = next;
1913 released++;
1914 }
1915 if (released) {
1916 l_ptr->first_out = crs;
1917 l_ptr->out_queue_size -= released;
1918 }
Allan Stephens85035562008-04-15 19:04:54 -07001919
1920 /* Try sending any messages link endpoint has pending */
1921
Per Lidenb97bf3f2006-01-02 19:04:38 +01001922 if (unlikely(l_ptr->next_out))
Per Liden4323add2006-01-18 00:38:21 +01001923 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001924 if (unlikely(!list_empty(&l_ptr->waiting_ports)))
Per Liden4323add2006-01-18 00:38:21 +01001925 tipc_link_wakeup_ports(l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001926 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1927 l_ptr->stats.sent_acks++;
Per Liden4323add2006-01-18 00:38:21 +01001928 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001929 }
1930
Allan Stephens85035562008-04-15 19:04:54 -07001931 /* Now (finally!) process the incoming message */
1932
Per Lidenb97bf3f2006-01-02 19:04:38 +01001933protocol_check:
1934 if (likely(link_working_working(l_ptr))) {
1935 if (likely(seq_no == mod(l_ptr->next_in_no))) {
1936 l_ptr->next_in_no++;
1937 if (unlikely(l_ptr->oldest_deferred_in))
1938 head = link_insert_deferred_queue(l_ptr,
1939 head);
1940 if (likely(msg_is_dest(msg, tipc_own_addr))) {
1941deliver:
1942 if (likely(msg_isdata(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001943 tipc_node_unlock(n_ptr);
1944 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001945 continue;
1946 }
1947 switch (msg_user(msg)) {
1948 case MSG_BUNDLER:
1949 l_ptr->stats.recv_bundles++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001950 l_ptr->stats.recv_bundled +=
Per Lidenb97bf3f2006-01-02 19:04:38 +01001951 msg_msgcnt(msg);
Per Liden4323add2006-01-18 00:38:21 +01001952 tipc_node_unlock(n_ptr);
1953 tipc_link_recv_bundle(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001954 continue;
1955 case ROUTE_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001956 tipc_node_unlock(n_ptr);
1957 tipc_cltr_recv_routing_table(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001958 continue;
1959 case NAME_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001960 tipc_node_unlock(n_ptr);
1961 tipc_named_recv(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001962 continue;
1963 case CONN_MANAGER:
Per Liden4323add2006-01-18 00:38:21 +01001964 tipc_node_unlock(n_ptr);
1965 tipc_port_recv_proto_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001966 continue;
1967 case MSG_FRAGMENTER:
1968 l_ptr->stats.recv_fragments++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001969 if (tipc_link_recv_fragment(&l_ptr->defragm_buf,
Per Liden4323add2006-01-18 00:38:21 +01001970 &buf, &msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001971 l_ptr->stats.recv_fragmented++;
1972 goto deliver;
1973 }
1974 break;
1975 case CHANGEOVER_PROTOCOL:
1976 type = msg_type(msg);
Per Liden4323add2006-01-18 00:38:21 +01001977 if (link_recv_changeover_msg(&l_ptr, &buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001978 msg = buf_msg(buf);
1979 seq_no = msg_seqno(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001980 if (type == ORIGINAL_MSG)
1981 goto deliver;
1982 goto protocol_check;
1983 }
1984 break;
1985 }
1986 }
Per Liden4323add2006-01-18 00:38:21 +01001987 tipc_node_unlock(n_ptr);
1988 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001989 continue;
1990 }
1991 link_handle_out_of_seq_msg(l_ptr, buf);
1992 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01001993 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001994 continue;
1995 }
1996
1997 if (msg_user(msg) == LINK_PROTOCOL) {
1998 link_recv_proto_msg(l_ptr, buf);
1999 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01002000 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002001 continue;
2002 }
2003 msg_dbg(msg,"NSEQ<REC<");
2004 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
2005
2006 if (link_working_working(l_ptr)) {
2007 /* Re-insert in front of queue */
2008 msg_dbg(msg,"RECV-REINS:");
2009 buf->next = head;
2010 head = buf;
Per Liden4323add2006-01-18 00:38:21 +01002011 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002012 continue;
2013 }
Per Liden4323add2006-01-18 00:38:21 +01002014 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002015cont:
2016 buf_discard(buf);
2017 }
Per Liden4323add2006-01-18 00:38:21 +01002018 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002019}
2020
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002021/*
2022 * link_defer_buf(): Sort a received out-of-sequence packet
Per Lidenb97bf3f2006-01-02 19:04:38 +01002023 * into the deferred reception queue.
2024 * Returns the increase of the queue length,i.e. 0 or 1
2025 */
2026
Per Liden4323add2006-01-18 00:38:21 +01002027u32 tipc_link_defer_pkt(struct sk_buff **head,
2028 struct sk_buff **tail,
2029 struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002030{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002031 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002032 struct sk_buff *crs = *head;
2033 u32 seq_no = msg_seqno(buf_msg(buf));
2034
2035 buf->next = NULL;
2036
2037 /* Empty queue ? */
2038 if (*head == NULL) {
2039 *head = *tail = buf;
2040 return 1;
2041 }
2042
2043 /* Last ? */
2044 if (less(msg_seqno(buf_msg(*tail)), seq_no)) {
2045 (*tail)->next = buf;
2046 *tail = buf;
2047 return 1;
2048 }
2049
2050 /* Scan through queue and sort it in */
2051 do {
2052 struct tipc_msg *msg = buf_msg(crs);
2053
2054 if (less(seq_no, msg_seqno(msg))) {
2055 buf->next = crs;
2056 if (prev)
2057 prev->next = buf;
2058 else
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002059 *head = buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002060 return 1;
2061 }
2062 if (seq_no == msg_seqno(msg)) {
2063 break;
2064 }
2065 prev = crs;
2066 crs = crs->next;
2067 }
2068 while (crs);
2069
2070 /* Message is a duplicate of an existing message */
2071
2072 buf_discard(buf);
2073 return 0;
2074}
2075
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002076/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01002077 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
2078 */
2079
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002080static void link_handle_out_of_seq_msg(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002081 struct sk_buff *buf)
2082{
2083 u32 seq_no = msg_seqno(buf_msg(buf));
2084
2085 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
2086 link_recv_proto_msg(l_ptr, buf);
2087 return;
2088 }
2089
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002090 dbg("rx OOS msg: seq_no %u, expecting %u (%u)\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002091 seq_no, mod(l_ptr->next_in_no), l_ptr->next_in_no);
2092
2093 /* Record OOS packet arrival (force mismatch on next timeout) */
2094
2095 l_ptr->checkpoint--;
2096
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002097 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002098 * Discard packet if a duplicate; otherwise add it to deferred queue
2099 * and notify peer of gap as per protocol specification
2100 */
2101
2102 if (less(seq_no, mod(l_ptr->next_in_no))) {
2103 l_ptr->stats.duplicates++;
2104 buf_discard(buf);
2105 return;
2106 }
2107
Per Liden4323add2006-01-18 00:38:21 +01002108 if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
2109 &l_ptr->newest_deferred_in, buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002110 l_ptr->deferred_inqueue_sz++;
2111 l_ptr->stats.deferred_recv++;
2112 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
Per Liden4323add2006-01-18 00:38:21 +01002113 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002114 } else
2115 l_ptr->stats.duplicates++;
2116}
2117
2118/*
2119 * Send protocol message to the other endpoint.
2120 */
Per Liden4323add2006-01-18 00:38:21 +01002121void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
2122 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002123{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002124 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002125 struct tipc_msg *msg = l_ptr->pmsg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002126 u32 msg_size = sizeof(l_ptr->proto_msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002127
2128 if (link_blocked(l_ptr))
2129 return;
2130 msg_set_type(msg, msg_typ);
2131 msg_set_net_plane(msg, l_ptr->b_ptr->net_plane);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002132 msg_set_bcast_ack(msg, mod(l_ptr->owner->bclink.last_in));
Per Liden4323add2006-01-18 00:38:21 +01002133 msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
Per Lidenb97bf3f2006-01-02 19:04:38 +01002134
2135 if (msg_typ == STATE_MSG) {
2136 u32 next_sent = mod(l_ptr->next_out_no);
2137
Per Liden4323add2006-01-18 00:38:21 +01002138 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002139 return;
2140 if (l_ptr->next_out)
2141 next_sent = msg_seqno(buf_msg(l_ptr->next_out));
2142 msg_set_next_sent(msg, next_sent);
2143 if (l_ptr->oldest_deferred_in) {
2144 u32 rec = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
2145 gap = mod(rec - mod(l_ptr->next_in_no));
2146 }
2147 msg_set_seq_gap(msg, gap);
2148 if (gap)
2149 l_ptr->stats.sent_nacks++;
2150 msg_set_link_tolerance(msg, tolerance);
2151 msg_set_linkprio(msg, priority);
2152 msg_set_max_pkt(msg, ack_mtu);
2153 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
2154 msg_set_probe(msg, probe_msg != 0);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002155 if (probe_msg) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002156 u32 mtu = l_ptr->max_pkt;
2157
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002158 if ((mtu < l_ptr->max_pkt_target) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002159 link_working_working(l_ptr) &&
2160 l_ptr->fsm_msg_cnt) {
2161 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002162 if (l_ptr->max_pkt_probes == 10) {
2163 l_ptr->max_pkt_target = (msg_size - 4);
2164 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002165 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002166 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002167 l_ptr->max_pkt_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002168 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002169
2170 l_ptr->stats.sent_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002171 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002172 l_ptr->stats.sent_states++;
2173 } else { /* RESET_MSG or ACTIVATE_MSG */
2174 msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
2175 msg_set_seq_gap(msg, 0);
2176 msg_set_next_sent(msg, 1);
2177 msg_set_link_tolerance(msg, l_ptr->tolerance);
2178 msg_set_linkprio(msg, l_ptr->priority);
2179 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
2180 }
2181
Per Liden4323add2006-01-18 00:38:21 +01002182 if (tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002183 msg_set_redundant_link(msg);
2184 } else {
2185 msg_clear_redundant_link(msg);
2186 }
2187 msg_set_linkprio(msg, l_ptr->priority);
2188
2189 /* Ensure sequence number will not fit : */
2190
2191 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
2192
2193 /* Congestion? */
2194
Per Liden4323add2006-01-18 00:38:21 +01002195 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002196 if (!l_ptr->proto_msg_queue) {
2197 l_ptr->proto_msg_queue =
2198 buf_acquire(sizeof(l_ptr->proto_msg));
2199 }
2200 buf = l_ptr->proto_msg_queue;
2201 if (!buf)
2202 return;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002203 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002204 return;
2205 }
2206 msg_set_timestamp(msg, jiffies_to_msecs(jiffies));
2207
2208 /* Message can be sent */
2209
2210 msg_dbg(msg, ">>");
2211
2212 buf = buf_acquire(msg_size);
2213 if (!buf)
2214 return;
2215
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002216 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002217 msg_set_size(buf_msg(buf), msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002218
Per Liden4323add2006-01-18 00:38:21 +01002219 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002220 l_ptr->unacked_window = 0;
2221 buf_discard(buf);
2222 return;
2223 }
2224
2225 /* New congestion */
Per Liden4323add2006-01-18 00:38:21 +01002226 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002227 l_ptr->proto_msg_queue = buf;
2228 l_ptr->stats.bearer_congs++;
2229}
2230
2231/*
2232 * Receive protocol message :
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002233 * Note that network plane id propagates through the network, and may
2234 * change at any time. The node with lowest address rules
Per Lidenb97bf3f2006-01-02 19:04:38 +01002235 */
2236
2237static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2238{
2239 u32 rec_gap = 0;
2240 u32 max_pkt_info;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002241 u32 max_pkt_ack;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002242 u32 msg_tol;
2243 struct tipc_msg *msg = buf_msg(buf);
2244
2245 dbg("AT(%u):", jiffies_to_msecs(jiffies));
2246 msg_dbg(msg, "<<");
2247 if (link_blocked(l_ptr))
2248 goto exit;
2249
2250 /* record unnumbered packet arrival (force mismatch on next timeout) */
2251
2252 l_ptr->checkpoint--;
2253
2254 if (l_ptr->b_ptr->net_plane != msg_net_plane(msg))
2255 if (tipc_own_addr > msg_prevnode(msg))
2256 l_ptr->b_ptr->net_plane = msg_net_plane(msg);
2257
2258 l_ptr->owner->permit_changeover = msg_redundant_link(msg);
2259
2260 switch (msg_type(msg)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002261
Per Lidenb97bf3f2006-01-02 19:04:38 +01002262 case RESET_MSG:
Allan Stephensa686e682008-06-04 17:29:39 -07002263 if (!link_working_unknown(l_ptr) &&
2264 (l_ptr->peer_session != INVALID_SESSION)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002265 if (msg_session(msg) == l_ptr->peer_session) {
2266 dbg("Duplicate RESET: %u<->%u\n",
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002267 msg_session(msg), l_ptr->peer_session);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002268 break; /* duplicate: ignore */
2269 }
2270 }
2271 /* fall thru' */
2272 case ACTIVATE_MSG:
2273 /* Update link settings according other endpoint's values */
2274
2275 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
2276
2277 if ((msg_tol = msg_link_tolerance(msg)) &&
2278 (msg_tol > l_ptr->tolerance))
2279 link_set_supervision_props(l_ptr, msg_tol);
2280
2281 if (msg_linkprio(msg) > l_ptr->priority)
2282 l_ptr->priority = msg_linkprio(msg);
2283
2284 max_pkt_info = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002285 if (max_pkt_info) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002286 if (max_pkt_info < l_ptr->max_pkt_target)
2287 l_ptr->max_pkt_target = max_pkt_info;
2288 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
2289 l_ptr->max_pkt = l_ptr->max_pkt_target;
2290 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002291 l_ptr->max_pkt = l_ptr->max_pkt_target;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002292 }
2293 l_ptr->owner->bclink.supported = (max_pkt_info != 0);
2294
2295 link_state_event(l_ptr, msg_type(msg));
2296
2297 l_ptr->peer_session = msg_session(msg);
2298 l_ptr->peer_bearer_id = msg_bearer_id(msg);
2299
2300 /* Synchronize broadcast sequence numbers */
Per Liden4323add2006-01-18 00:38:21 +01002301 if (!tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002302 l_ptr->owner->bclink.last_in = mod(msg_last_bcast(msg));
2303 }
2304 break;
2305 case STATE_MSG:
2306
2307 if ((msg_tol = msg_link_tolerance(msg)))
2308 link_set_supervision_props(l_ptr, msg_tol);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002309
2310 if (msg_linkprio(msg) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002311 (msg_linkprio(msg) != l_ptr->priority)) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002312 warn("Resetting link <%s>, priority change %u->%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002313 l_ptr->name, l_ptr->priority, msg_linkprio(msg));
2314 l_ptr->priority = msg_linkprio(msg);
Per Liden4323add2006-01-18 00:38:21 +01002315 tipc_link_reset(l_ptr); /* Enforce change to take effect */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002316 break;
2317 }
2318 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
2319 l_ptr->stats.recv_states++;
2320 if (link_reset_unknown(l_ptr))
2321 break;
2322
2323 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002324 rec_gap = mod(msg_next_sent(msg) -
Per Lidenb97bf3f2006-01-02 19:04:38 +01002325 mod(l_ptr->next_in_no));
2326 }
2327
2328 max_pkt_ack = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002329 if (max_pkt_ack > l_ptr->max_pkt) {
2330 dbg("Link <%s> updated MTU %u -> %u\n",
2331 l_ptr->name, l_ptr->max_pkt, max_pkt_ack);
2332 l_ptr->max_pkt = max_pkt_ack;
2333 l_ptr->max_pkt_probes = 0;
2334 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002335
2336 max_pkt_ack = 0;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002337 if (msg_probe(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002338 l_ptr->stats.recv_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002339 if (msg_size(msg) > sizeof(l_ptr->proto_msg)) {
2340 max_pkt_ack = msg_size(msg);
2341 }
2342 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002343
2344 /* Protocol message before retransmits, reduce loss risk */
2345
Per Liden4323add2006-01-18 00:38:21 +01002346 tipc_bclink_check_gap(l_ptr->owner, msg_last_bcast(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002347
2348 if (rec_gap || (msg_probe(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01002349 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2350 0, rec_gap, 0, 0, max_pkt_ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002351 }
2352 if (msg_seq_gap(msg)) {
2353 msg_dbg(msg, "With Gap:");
2354 l_ptr->stats.recv_nacks++;
Per Liden4323add2006-01-18 00:38:21 +01002355 tipc_link_retransmit(l_ptr, l_ptr->first_out,
2356 msg_seq_gap(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002357 }
2358 break;
2359 default:
2360 msg_dbg(buf_msg(buf), "<DISCARDING UNKNOWN<");
2361 }
2362exit:
2363 buf_discard(buf);
2364}
2365
2366
2367/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002368 * tipc_link_tunnel(): Send one message via a link belonging to
Per Lidenb97bf3f2006-01-02 19:04:38 +01002369 * another bearer. Owner node is locked.
2370 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002371void tipc_link_tunnel(struct link *l_ptr,
2372 struct tipc_msg *tunnel_hdr,
Per Liden4323add2006-01-18 00:38:21 +01002373 struct tipc_msg *msg,
2374 u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002375{
2376 struct link *tunnel;
2377 struct sk_buff *buf;
2378 u32 length = msg_size(msg);
2379
2380 tunnel = l_ptr->owner->active_links[selector & 1];
Allan Stephens5392d642006-06-25 23:52:50 -07002381 if (!tipc_link_is_up(tunnel)) {
2382 warn("Link changeover error, "
2383 "tunnel link no longer available\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002384 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002385 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002386 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
2387 buf = buf_acquire(length + INT_H_SIZE);
Allan Stephens5392d642006-06-25 23:52:50 -07002388 if (!buf) {
2389 warn("Link changeover error, "
2390 "unable to send tunnel msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002391 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002392 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002393 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
2394 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002395 dbg("%c->%c:", l_ptr->b_ptr->net_plane, tunnel->b_ptr->net_plane);
2396 msg_dbg(buf_msg(buf), ">SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002397 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002398}
2399
2400
2401
2402/*
2403 * changeover(): Send whole message queue via the remaining link
2404 * Owner node is locked.
2405 */
2406
Per Liden4323add2006-01-18 00:38:21 +01002407void tipc_link_changeover(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002408{
2409 u32 msgcount = l_ptr->out_queue_size;
2410 struct sk_buff *crs = l_ptr->first_out;
2411 struct link *tunnel = l_ptr->owner->active_links[0];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002412 struct tipc_msg tunnel_hdr;
Allan Stephens5392d642006-06-25 23:52:50 -07002413 int split_bundles;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002414
2415 if (!tunnel)
2416 return;
2417
Allan Stephens5392d642006-06-25 23:52:50 -07002418 if (!l_ptr->owner->permit_changeover) {
2419 warn("Link changeover error, "
2420 "peer did not permit changeover\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002421 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002422 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002423
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002424 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002425 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002426 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2427 msg_set_msgcnt(&tunnel_hdr, msgcount);
Allan Stephens5392d642006-06-25 23:52:50 -07002428 dbg("Link changeover requires %u tunnel messages\n", msgcount);
Allan Stephensf1310722006-06-25 23:51:37 -07002429
Per Lidenb97bf3f2006-01-02 19:04:38 +01002430 if (!l_ptr->first_out) {
2431 struct sk_buff *buf;
2432
Per Lidenb97bf3f2006-01-02 19:04:38 +01002433 buf = buf_acquire(INT_H_SIZE);
2434 if (buf) {
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002435 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002436 msg_set_size(&tunnel_hdr, INT_H_SIZE);
2437 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2438 tunnel->b_ptr->net_plane);
2439 msg_dbg(&tunnel_hdr, "EMPTY>SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002440 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002441 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002442 warn("Link changeover error, "
2443 "unable to send changeover msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002444 }
2445 return;
2446 }
Allan Stephensf1310722006-06-25 23:51:37 -07002447
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002448 split_bundles = (l_ptr->owner->active_links[0] !=
Allan Stephens5392d642006-06-25 23:52:50 -07002449 l_ptr->owner->active_links[1]);
2450
Per Lidenb97bf3f2006-01-02 19:04:38 +01002451 while (crs) {
2452 struct tipc_msg *msg = buf_msg(crs);
2453
2454 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002455 struct tipc_msg *m = msg_get_wrapped(msg);
2456 unchar* pos = (unchar*)m;
2457
Florian Westphald788d802007-08-02 19:28:06 -07002458 msgcount = msg_msgcnt(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002459 while (msgcount--) {
2460 msg_set_seqno(m,msg_seqno(msg));
Per Liden4323add2006-01-18 00:38:21 +01002461 tipc_link_tunnel(l_ptr, &tunnel_hdr, m,
2462 msg_link_selector(m));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002463 pos += align(msg_size(m));
2464 m = (struct tipc_msg *)pos;
2465 }
2466 } else {
Per Liden4323add2006-01-18 00:38:21 +01002467 tipc_link_tunnel(l_ptr, &tunnel_hdr, msg,
2468 msg_link_selector(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002469 }
2470 crs = crs->next;
2471 }
2472}
2473
Per Liden4323add2006-01-18 00:38:21 +01002474void tipc_link_send_duplicate(struct link *l_ptr, struct link *tunnel)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002475{
2476 struct sk_buff *iter;
2477 struct tipc_msg tunnel_hdr;
2478
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002479 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002480 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002481 msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
2482 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2483 iter = l_ptr->first_out;
2484 while (iter) {
2485 struct sk_buff *outbuf;
2486 struct tipc_msg *msg = buf_msg(iter);
2487 u32 length = msg_size(msg);
2488
2489 if (msg_user(msg) == MSG_BUNDLER)
2490 msg_set_type(msg, CLOSED_MSG);
2491 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002492 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002493 msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
2494 outbuf = buf_acquire(length + INT_H_SIZE);
2495 if (outbuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002496 warn("Link changeover error, "
2497 "unable to send duplicate msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002498 return;
2499 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002500 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2501 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
2502 length);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002503 dbg("%c->%c:", l_ptr->b_ptr->net_plane,
2504 tunnel->b_ptr->net_plane);
2505 msg_dbg(buf_msg(outbuf), ">SEND>");
Per Liden4323add2006-01-18 00:38:21 +01002506 tipc_link_send_buf(tunnel, outbuf);
2507 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002508 return;
2509 iter = iter->next;
2510 }
2511}
2512
2513
2514
2515/**
2516 * buf_extract - extracts embedded TIPC message from another message
2517 * @skb: encapsulating message buffer
2518 * @from_pos: offset to extract from
2519 *
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002520 * Returns a new message buffer containing an embedded message. The
Per Lidenb97bf3f2006-01-02 19:04:38 +01002521 * encapsulating message itself is left unchanged.
2522 */
2523
2524static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
2525{
2526 struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
2527 u32 size = msg_size(msg);
2528 struct sk_buff *eb;
2529
2530 eb = buf_acquire(size);
2531 if (eb)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002532 skb_copy_to_linear_data(eb, msg, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002533 return eb;
2534}
2535
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002536/*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002537 * link_recv_changeover_msg(): Receive tunneled packet sent
2538 * via other link. Node is locked. Return extracted buffer.
2539 */
2540
2541static int link_recv_changeover_msg(struct link **l_ptr,
2542 struct sk_buff **buf)
2543{
2544 struct sk_buff *tunnel_buf = *buf;
2545 struct link *dest_link;
2546 struct tipc_msg *msg;
2547 struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf);
2548 u32 msg_typ = msg_type(tunnel_msg);
2549 u32 msg_count = msg_msgcnt(tunnel_msg);
2550
2551 dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002552 if (!dest_link) {
2553 msg_dbg(tunnel_msg, "NOLINK/<REC<");
2554 goto exit;
2555 }
Allan Stephensf1310722006-06-25 23:51:37 -07002556 if (dest_link == *l_ptr) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002557 err("Unexpected changeover message on link <%s>\n",
Allan Stephensf1310722006-06-25 23:51:37 -07002558 (*l_ptr)->name);
2559 goto exit;
2560 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002561 dbg("%c<-%c:", dest_link->b_ptr->net_plane,
2562 (*l_ptr)->b_ptr->net_plane);
2563 *l_ptr = dest_link;
2564 msg = msg_get_wrapped(tunnel_msg);
2565
2566 if (msg_typ == DUPLICATE_MSG) {
2567 if (less(msg_seqno(msg), mod(dest_link->next_in_no))) {
2568 msg_dbg(tunnel_msg, "DROP/<REC<");
2569 goto exit;
2570 }
2571 *buf = buf_extract(tunnel_buf,INT_H_SIZE);
2572 if (*buf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002573 warn("Link changeover error, duplicate msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002574 goto exit;
2575 }
2576 msg_dbg(tunnel_msg, "TNL<REC<");
2577 buf_discard(tunnel_buf);
2578 return 1;
2579 }
2580
2581 /* First original message ?: */
2582
Per Liden4323add2006-01-18 00:38:21 +01002583 if (tipc_link_is_up(dest_link)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002584 msg_dbg(tunnel_msg, "UP/FIRST/<REC<");
Allan Stephensa10bd922006-06-25 23:52:17 -07002585 info("Resetting link <%s>, changeover initiated by peer\n",
2586 dest_link->name);
Per Liden4323add2006-01-18 00:38:21 +01002587 tipc_link_reset(dest_link);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002588 dest_link->exp_msg_count = msg_count;
Allan Stephens5392d642006-06-25 23:52:50 -07002589 dbg("Expecting %u tunnelled messages\n", msg_count);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002590 if (!msg_count)
2591 goto exit;
2592 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
2593 msg_dbg(tunnel_msg, "BLK/FIRST/<REC<");
2594 dest_link->exp_msg_count = msg_count;
Allan Stephens5392d642006-06-25 23:52:50 -07002595 dbg("Expecting %u tunnelled messages\n", msg_count);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002596 if (!msg_count)
2597 goto exit;
2598 }
2599
2600 /* Receive original message */
2601
2602 if (dest_link->exp_msg_count == 0) {
Allan Stephens5392d642006-06-25 23:52:50 -07002603 warn("Link switchover error, "
2604 "got too many tunnelled messages\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002605 msg_dbg(tunnel_msg, "OVERDUE/DROP/<REC<");
2606 dbg_print_link(dest_link, "LINK:");
2607 goto exit;
2608 }
2609 dest_link->exp_msg_count--;
2610 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) {
2611 msg_dbg(tunnel_msg, "DROP/DUPL/<REC<");
2612 goto exit;
2613 } else {
2614 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2615 if (*buf != NULL) {
2616 msg_dbg(tunnel_msg, "TNL<REC<");
2617 buf_discard(tunnel_buf);
2618 return 1;
2619 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002620 warn("Link changeover error, original msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002621 }
2622 }
2623exit:
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002624 *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002625 buf_discard(tunnel_buf);
2626 return 0;
2627}
2628
2629/*
2630 * Bundler functionality:
2631 */
Per Liden4323add2006-01-18 00:38:21 +01002632void tipc_link_recv_bundle(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002633{
2634 u32 msgcount = msg_msgcnt(buf_msg(buf));
2635 u32 pos = INT_H_SIZE;
2636 struct sk_buff *obuf;
2637
2638 msg_dbg(buf_msg(buf), "<BNDL<: ");
2639 while (msgcount--) {
2640 obuf = buf_extract(buf, pos);
2641 if (obuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002642 warn("Link unable to unbundle message(s)\n");
2643 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07002644 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002645 pos += align(msg_size(buf_msg(obuf)));
2646 msg_dbg(buf_msg(obuf), " /");
Per Liden4323add2006-01-18 00:38:21 +01002647 tipc_net_route_msg(obuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002648 }
2649 buf_discard(buf);
2650}
2651
2652/*
2653 * Fragmentation/defragmentation:
2654 */
2655
2656
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002657/*
Per Liden4323add2006-01-18 00:38:21 +01002658 * tipc_link_send_long_buf: Entry for buffers needing fragmentation.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002659 * The buffer is complete, inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01002660 * Returns user data length.
2661 */
Per Liden4323add2006-01-18 00:38:21 +01002662int tipc_link_send_long_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002663{
2664 struct tipc_msg *inmsg = buf_msg(buf);
2665 struct tipc_msg fragm_hdr;
2666 u32 insize = msg_size(inmsg);
2667 u32 dsz = msg_data_sz(inmsg);
2668 unchar *crs = buf->data;
2669 u32 rest = insize;
Allan Stephens15e979d2010-05-11 14:30:10 +00002670 u32 pack_sz = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002671 u32 fragm_sz = pack_sz - INT_H_SIZE;
2672 u32 fragm_no = 1;
Allan Stephens9c396a72008-06-04 17:36:58 -07002673 u32 destaddr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002674
2675 if (msg_short(inmsg))
2676 destaddr = l_ptr->addr;
Allan Stephens9c396a72008-06-04 17:36:58 -07002677 else
2678 destaddr = msg_destnode(inmsg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002679
2680 if (msg_routed(inmsg))
2681 msg_set_prevnode(inmsg, tipc_own_addr);
2682
2683 /* Prepare reusable fragment header: */
2684
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002685 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07002686 INT_H_SIZE, destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002687 msg_set_link_selector(&fragm_hdr, msg_link_selector(inmsg));
2688 msg_set_long_msgno(&fragm_hdr, mod(l_ptr->long_msg_seq_no++));
2689 msg_set_fragm_no(&fragm_hdr, fragm_no);
2690 l_ptr->stats.sent_fragmented++;
2691
2692 /* Chop up message: */
2693
2694 while (rest > 0) {
2695 struct sk_buff *fragm;
2696
2697 if (rest <= fragm_sz) {
2698 fragm_sz = rest;
2699 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
2700 }
2701 fragm = buf_acquire(fragm_sz + INT_H_SIZE);
2702 if (fragm == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002703 warn("Link unable to fragment message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002704 dsz = -ENOMEM;
2705 goto exit;
2706 }
2707 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002708 skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE);
2709 skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs,
2710 fragm_sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002711 /* Send queued messages first, if any: */
2712
2713 l_ptr->stats.sent_fragments++;
Per Liden4323add2006-01-18 00:38:21 +01002714 tipc_link_send_buf(l_ptr, fragm);
2715 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002716 return dsz;
2717 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
2718 rest -= fragm_sz;
2719 crs += fragm_sz;
2720 msg_set_type(&fragm_hdr, FRAGMENT);
2721 }
2722exit:
2723 buf_discard(buf);
2724 return dsz;
2725}
2726
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002727/*
2728 * A pending message being re-assembled must store certain values
2729 * to handle subsequent fragments correctly. The following functions
Per Lidenb97bf3f2006-01-02 19:04:38 +01002730 * help storing these values in unused, available fields in the
2731 * pending message. This makes dynamic memory allocation unecessary.
2732 */
2733
Sam Ravnborg05790c62006-03-20 22:37:04 -08002734static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002735{
2736 msg_set_seqno(buf_msg(buf), seqno);
2737}
2738
Sam Ravnborg05790c62006-03-20 22:37:04 -08002739static u32 get_fragm_size(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002740{
2741 return msg_ack(buf_msg(buf));
2742}
2743
Sam Ravnborg05790c62006-03-20 22:37:04 -08002744static void set_fragm_size(struct sk_buff *buf, u32 sz)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002745{
2746 msg_set_ack(buf_msg(buf), sz);
2747}
2748
Sam Ravnborg05790c62006-03-20 22:37:04 -08002749static u32 get_expected_frags(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002750{
2751 return msg_bcast_ack(buf_msg(buf));
2752}
2753
Sam Ravnborg05790c62006-03-20 22:37:04 -08002754static void set_expected_frags(struct sk_buff *buf, u32 exp)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002755{
2756 msg_set_bcast_ack(buf_msg(buf), exp);
2757}
2758
Sam Ravnborg05790c62006-03-20 22:37:04 -08002759static u32 get_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002760{
2761 return msg_reroute_cnt(buf_msg(buf));
2762}
2763
Sam Ravnborg05790c62006-03-20 22:37:04 -08002764static void incr_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002765{
2766 msg_incr_reroute_cnt(buf_msg(buf));
2767}
2768
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002769/*
2770 * tipc_link_recv_fragment(): Called with node lock on. Returns
Per Lidenb97bf3f2006-01-02 19:04:38 +01002771 * the reassembled buffer if message is complete.
2772 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002773int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
Per Liden4323add2006-01-18 00:38:21 +01002774 struct tipc_msg **m)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002775{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002776 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002777 struct sk_buff *fbuf = *fb;
2778 struct tipc_msg *fragm = buf_msg(fbuf);
2779 struct sk_buff *pbuf = *pending;
2780 u32 long_msg_seq_no = msg_long_msgno(fragm);
2781
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002782 *fb = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002783 msg_dbg(fragm,"FRG<REC<");
2784
2785 /* Is there an incomplete message waiting for this fragment? */
2786
Joe Perchesf64f9e72009-11-29 16:55:45 -08002787 while (pbuf && ((msg_seqno(buf_msg(pbuf)) != long_msg_seq_no) ||
2788 (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002789 prev = pbuf;
2790 pbuf = pbuf->next;
2791 }
2792
2793 if (!pbuf && (msg_type(fragm) == FIRST_FRAGMENT)) {
2794 struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
2795 u32 msg_sz = msg_size(imsg);
2796 u32 fragm_sz = msg_data_sz(fragm);
2797 u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
2798 u32 max = TIPC_MAX_USER_MSG_SIZE + LONG_H_SIZE;
2799 if (msg_type(imsg) == TIPC_MCAST_MSG)
2800 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
2801 if (msg_size(imsg) > max) {
2802 msg_dbg(fragm,"<REC<Oversized: ");
2803 buf_discard(fbuf);
2804 return 0;
2805 }
2806 pbuf = buf_acquire(msg_size(imsg));
2807 if (pbuf != NULL) {
2808 pbuf->next = *pending;
2809 *pending = pbuf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002810 skb_copy_to_linear_data(pbuf, imsg,
2811 msg_data_sz(fragm));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002812 /* Prepare buffer for subsequent fragments. */
2813
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002814 set_long_msg_seqno(pbuf, long_msg_seq_no);
2815 set_fragm_size(pbuf,fragm_sz);
2816 set_expected_frags(pbuf,exp_fragm_cnt - 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002817 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002818 warn("Link unable to reassemble fragmented message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002819 }
2820 buf_discard(fbuf);
2821 return 0;
2822 } else if (pbuf && (msg_type(fragm) != FIRST_FRAGMENT)) {
2823 u32 dsz = msg_data_sz(fragm);
2824 u32 fsz = get_fragm_size(pbuf);
2825 u32 crs = ((msg_fragm_no(fragm) - 1) * fsz);
2826 u32 exp_frags = get_expected_frags(pbuf) - 1;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002827 skb_copy_to_linear_data_offset(pbuf, crs,
2828 msg_data(fragm), dsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002829 buf_discard(fbuf);
2830
2831 /* Is message complete? */
2832
2833 if (exp_frags == 0) {
2834 if (prev)
2835 prev->next = pbuf->next;
2836 else
2837 *pending = pbuf->next;
2838 msg_reset_reroute_cnt(buf_msg(pbuf));
2839 *fb = pbuf;
2840 *m = buf_msg(pbuf);
2841 return 1;
2842 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002843 set_expected_frags(pbuf,exp_frags);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002844 return 0;
2845 }
2846 dbg(" Discarding orphan fragment %x\n",fbuf);
2847 msg_dbg(fragm,"ORPHAN:");
2848 dbg("Pending long buffers:\n");
2849 dbg_print_buf_chain(*pending);
2850 buf_discard(fbuf);
2851 return 0;
2852}
2853
2854/**
2855 * link_check_defragm_bufs - flush stale incoming message fragments
2856 * @l_ptr: pointer to link
2857 */
2858
2859static void link_check_defragm_bufs(struct link *l_ptr)
2860{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002861 struct sk_buff *prev = NULL;
2862 struct sk_buff *next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002863 struct sk_buff *buf = l_ptr->defragm_buf;
2864
2865 if (!buf)
2866 return;
2867 if (!link_working_working(l_ptr))
2868 return;
2869 while (buf) {
2870 u32 cnt = get_timer_cnt(buf);
2871
2872 next = buf->next;
2873 if (cnt < 4) {
2874 incr_timer_cnt(buf);
2875 prev = buf;
2876 } else {
2877 dbg(" Discarding incomplete long buffer\n");
2878 msg_dbg(buf_msg(buf), "LONG:");
2879 dbg_print_link(l_ptr, "curr:");
2880 dbg("Pending long buffers:\n");
2881 dbg_print_buf_chain(l_ptr->defragm_buf);
2882 if (prev)
2883 prev->next = buf->next;
2884 else
2885 l_ptr->defragm_buf = buf->next;
2886 buf_discard(buf);
2887 }
2888 buf = next;
2889 }
2890}
2891
2892
2893
2894static void link_set_supervision_props(struct link *l_ptr, u32 tolerance)
2895{
2896 l_ptr->tolerance = tolerance;
2897 l_ptr->continuity_interval =
2898 ((tolerance / 4) > 500) ? 500 : tolerance / 4;
2899 l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
2900}
2901
2902
Per Liden4323add2006-01-18 00:38:21 +01002903void tipc_link_set_queue_limits(struct link *l_ptr, u32 window)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002904{
2905 /* Data messages from this node, inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002906 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
2907 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
2908 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
2909 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002910 /* Transiting data messages,inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002911 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
2912 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
2913 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
2914 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002915 l_ptr->queue_limit[CONN_MANAGER] = 1200;
2916 l_ptr->queue_limit[ROUTE_DISTRIBUTOR] = 1200;
2917 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
2918 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
2919 /* FRAGMENT and LAST_FRAGMENT packets */
2920 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
2921}
2922
2923/**
2924 * link_find_link - locate link by name
2925 * @name - ptr to link name string
2926 * @node - ptr to area to be filled with ptr to associated node
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002927 *
Per Liden4323add2006-01-18 00:38:21 +01002928 * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002929 * this also prevents link deletion.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002930 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002931 * Returns pointer to link (or 0 if invalid link name).
2932 */
2933
David S. Miller6c000552008-09-02 23:38:32 -07002934static struct link *link_find_link(const char *name, struct tipc_node **node)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002935{
2936 struct link_name link_name_parts;
2937 struct bearer *b_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002938 struct link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002939
2940 if (!link_name_validate(name, &link_name_parts))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002941 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002942
Per Liden4323add2006-01-18 00:38:21 +01002943 b_ptr = tipc_bearer_find_interface(link_name_parts.if_local);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002944 if (!b_ptr)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002945 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002946
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002947 *node = tipc_node_find(link_name_parts.addr_peer);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002948 if (!*node)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002949 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002950
2951 l_ptr = (*node)->links[b_ptr->identity];
2952 if (!l_ptr || strcmp(l_ptr->name, name))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002953 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002954
2955 return l_ptr;
2956}
2957
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002958struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Per Liden4323add2006-01-18 00:38:21 +01002959 u16 cmd)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002960{
2961 struct tipc_link_config *args;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002962 u32 new_value;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002963 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002964 struct tipc_node *node;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002965 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002966
2967 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +01002968 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002969
2970 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2971 new_value = ntohl(args->value);
2972
Per Liden4323add2006-01-18 00:38:21 +01002973 if (!strcmp(args->name, tipc_bclink_name)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002974 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
Per Liden4323add2006-01-18 00:38:21 +01002975 (tipc_bclink_set_queue_limits(new_value) == 0))
2976 return tipc_cfg_reply_none();
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002977 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Per Liden4323add2006-01-18 00:38:21 +01002978 " (cannot change setting on broadcast link)");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002979 }
2980
Per Liden4323add2006-01-18 00:38:21 +01002981 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002982 l_ptr = link_find_link(args->name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002983 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002984 read_unlock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002985 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002986 }
2987
Per Liden4323add2006-01-18 00:38:21 +01002988 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002989 res = -EINVAL;
2990 switch (cmd) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002991 case TIPC_CMD_SET_LINK_TOL:
2992 if ((new_value >= TIPC_MIN_LINK_TOL) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002993 (new_value <= TIPC_MAX_LINK_TOL)) {
2994 link_set_supervision_props(l_ptr, new_value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002995 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01002996 0, 0, new_value, 0, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07002997 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002998 }
2999 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003000 case TIPC_CMD_SET_LINK_PRI:
Per Liden16cb4b32006-01-13 22:22:22 +01003001 if ((new_value >= TIPC_MIN_LINK_PRI) &&
3002 (new_value <= TIPC_MAX_LINK_PRI)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01003003 l_ptr->priority = new_value;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003004 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01003005 0, 0, 0, new_value, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07003006 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003007 }
3008 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003009 case TIPC_CMD_SET_LINK_WINDOW:
3010 if ((new_value >= TIPC_MIN_LINK_WIN) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01003011 (new_value <= TIPC_MAX_LINK_WIN)) {
Per Liden4323add2006-01-18 00:38:21 +01003012 tipc_link_set_queue_limits(l_ptr, new_value);
Allan Stephens0e35fd52008-07-14 22:44:01 -07003013 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003014 }
3015 break;
3016 }
Per Liden4323add2006-01-18 00:38:21 +01003017 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003018
Per Liden4323add2006-01-18 00:38:21 +01003019 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003020 if (res)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003021 return tipc_cfg_reply_error_string("cannot change link setting");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003022
Per Liden4323add2006-01-18 00:38:21 +01003023 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003024}
3025
3026/**
3027 * link_reset_statistics - reset link statistics
3028 * @l_ptr: pointer to link
3029 */
3030
3031static void link_reset_statistics(struct link *l_ptr)
3032{
3033 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
3034 l_ptr->stats.sent_info = l_ptr->next_out_no;
3035 l_ptr->stats.recv_info = l_ptr->next_in_no;
3036}
3037
Per Liden4323add2006-01-18 00:38:21 +01003038struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003039{
3040 char *link_name;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003041 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07003042 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003043
3044 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01003045 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003046
3047 link_name = (char *)TLV_DATA(req_tlv_area);
Per Liden4323add2006-01-18 00:38:21 +01003048 if (!strcmp(link_name, tipc_bclink_name)) {
3049 if (tipc_bclink_reset_stats())
3050 return tipc_cfg_reply_error_string("link not found");
3051 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003052 }
3053
Per Liden4323add2006-01-18 00:38:21 +01003054 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003055 l_ptr = link_find_link(link_name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003056 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003057 read_unlock_bh(&tipc_net_lock);
3058 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003059 }
3060
Per Liden4323add2006-01-18 00:38:21 +01003061 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003062 link_reset_statistics(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01003063 tipc_node_unlock(node);
3064 read_unlock_bh(&tipc_net_lock);
3065 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01003066}
3067
3068/**
3069 * percent - convert count to a percentage of total (rounding up or down)
3070 */
3071
3072static u32 percent(u32 count, u32 total)
3073{
3074 return (count * 100 + (total / 2)) / total;
3075}
3076
3077/**
Per Liden4323add2006-01-18 00:38:21 +01003078 * tipc_link_stats - print link statistics
Per Lidenb97bf3f2006-01-02 19:04:38 +01003079 * @name: link name
3080 * @buf: print buffer area
3081 * @buf_size: size of print buffer area
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003082 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01003083 * Returns length of print buffer data string (or 0 if error)
3084 */
3085
Per Liden4323add2006-01-18 00:38:21 +01003086static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003087{
3088 struct print_buf pb;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003089 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07003090 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003091 char *status;
3092 u32 profile_total = 0;
3093
Per Liden4323add2006-01-18 00:38:21 +01003094 if (!strcmp(name, tipc_bclink_name))
3095 return tipc_bclink_stats(buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003096
Per Liden4323add2006-01-18 00:38:21 +01003097 tipc_printbuf_init(&pb, buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003098
Per Liden4323add2006-01-18 00:38:21 +01003099 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003100 l_ptr = link_find_link(name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003101 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003102 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003103 return 0;
3104 }
Per Liden4323add2006-01-18 00:38:21 +01003105 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003106
Per Liden4323add2006-01-18 00:38:21 +01003107 if (tipc_link_is_active(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003108 status = "ACTIVE";
Per Liden4323add2006-01-18 00:38:21 +01003109 else if (tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003110 status = "STANDBY";
3111 else
3112 status = "DEFUNCT";
3113 tipc_printf(&pb, "Link <%s>\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003114 " %s MTU:%u Priority:%u Tolerance:%u ms"
3115 " Window:%u packets\n",
Allan Stephens15e979d2010-05-11 14:30:10 +00003116 l_ptr->name, status, l_ptr->max_pkt,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003117 l_ptr->priority, l_ptr->tolerance, l_ptr->queue_limit[0]);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003118 tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003119 l_ptr->next_in_no - l_ptr->stats.recv_info,
3120 l_ptr->stats.recv_fragments,
3121 l_ptr->stats.recv_fragmented,
3122 l_ptr->stats.recv_bundles,
3123 l_ptr->stats.recv_bundled);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003124 tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003125 l_ptr->next_out_no - l_ptr->stats.sent_info,
3126 l_ptr->stats.sent_fragments,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003127 l_ptr->stats.sent_fragmented,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003128 l_ptr->stats.sent_bundles,
3129 l_ptr->stats.sent_bundled);
3130 profile_total = l_ptr->stats.msg_length_counts;
3131 if (!profile_total)
3132 profile_total = 1;
3133 tipc_printf(&pb, " TX profile sample:%u packets average:%u octets\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003134 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
3135 "-16354:%u%% -32768:%u%% -66000:%u%%\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003136 l_ptr->stats.msg_length_counts,
3137 l_ptr->stats.msg_lengths_total / profile_total,
3138 percent(l_ptr->stats.msg_length_profile[0], profile_total),
3139 percent(l_ptr->stats.msg_length_profile[1], profile_total),
3140 percent(l_ptr->stats.msg_length_profile[2], profile_total),
3141 percent(l_ptr->stats.msg_length_profile[3], profile_total),
3142 percent(l_ptr->stats.msg_length_profile[4], profile_total),
3143 percent(l_ptr->stats.msg_length_profile[5], profile_total),
3144 percent(l_ptr->stats.msg_length_profile[6], profile_total));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003145 tipc_printf(&pb, " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01003146 l_ptr->stats.recv_states,
3147 l_ptr->stats.recv_probes,
3148 l_ptr->stats.recv_nacks,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003149 l_ptr->stats.deferred_recv,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003150 l_ptr->stats.duplicates);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003151 tipc_printf(&pb, " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
3152 l_ptr->stats.sent_states,
3153 l_ptr->stats.sent_probes,
3154 l_ptr->stats.sent_nacks,
3155 l_ptr->stats.sent_acks,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003156 l_ptr->stats.retransmitted);
3157 tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
3158 l_ptr->stats.bearer_congs,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003159 l_ptr->stats.link_congs,
Per Lidenb97bf3f2006-01-02 19:04:38 +01003160 l_ptr->stats.max_queue_sz,
3161 l_ptr->stats.queue_sz_counts
3162 ? (l_ptr->stats.accu_queue_sz / l_ptr->stats.queue_sz_counts)
3163 : 0);
3164
Per Liden4323add2006-01-18 00:38:21 +01003165 tipc_node_unlock(node);
3166 read_unlock_bh(&tipc_net_lock);
3167 return tipc_printbuf_validate(&pb);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003168}
3169
3170#define MAX_LINK_STATS_INFO 2000
3171
Per Liden4323add2006-01-18 00:38:21 +01003172struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003173{
3174 struct sk_buff *buf;
3175 struct tlv_desc *rep_tlv;
3176 int str_len;
3177
3178 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01003179 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003180
Per Liden4323add2006-01-18 00:38:21 +01003181 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_LINK_STATS_INFO));
Per Lidenb97bf3f2006-01-02 19:04:38 +01003182 if (!buf)
3183 return NULL;
3184
3185 rep_tlv = (struct tlv_desc *)buf->data;
3186
Per Liden4323add2006-01-18 00:38:21 +01003187 str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
3188 (char *)TLV_DATA(rep_tlv), MAX_LINK_STATS_INFO);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003189 if (!str_len) {
3190 buf_discard(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003191 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003192 }
3193
3194 skb_put(buf, TLV_SPACE(str_len));
3195 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
3196
3197 return buf;
3198}
3199
3200#if 0
3201int link_control(const char *name, u32 op, u32 val)
3202{
3203 int res = -EINVAL;
3204 struct link *l_ptr;
3205 u32 bearer_id;
David S. Miller6c000552008-09-02 23:38:32 -07003206 struct tipc_node * node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003207 u32 a;
3208
3209 a = link_name2addr(name, &bearer_id);
Per Liden4323add2006-01-18 00:38:21 +01003210 read_lock_bh(&tipc_net_lock);
3211 node = tipc_node_find(a);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003212 if (node) {
Per Liden4323add2006-01-18 00:38:21 +01003213 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003214 l_ptr = node->links[bearer_id];
3215 if (l_ptr) {
3216 if (op == TIPC_REMOVE_LINK) {
3217 struct bearer *b_ptr = l_ptr->b_ptr;
3218 spin_lock_bh(&b_ptr->publ.lock);
Per Liden4323add2006-01-18 00:38:21 +01003219 tipc_link_delete(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003220 spin_unlock_bh(&b_ptr->publ.lock);
3221 }
3222 if (op == TIPC_CMD_BLOCK_LINK) {
Per Liden4323add2006-01-18 00:38:21 +01003223 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003224 l_ptr->blocked = 1;
3225 }
3226 if (op == TIPC_CMD_UNBLOCK_LINK) {
3227 l_ptr->blocked = 0;
3228 }
Allan Stephens0e35fd52008-07-14 22:44:01 -07003229 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003230 }
Per Liden4323add2006-01-18 00:38:21 +01003231 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003232 }
Per Liden4323add2006-01-18 00:38:21 +01003233 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003234 return res;
3235}
3236#endif
3237
3238/**
Per Liden4323add2006-01-18 00:38:21 +01003239 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
Per Lidenb97bf3f2006-01-02 19:04:38 +01003240 * @dest: network address of destination node
3241 * @selector: used to select from set of active links
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003242 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01003243 * If no active link can be found, uses default maximum packet size.
3244 */
3245
Per Liden4323add2006-01-18 00:38:21 +01003246u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01003247{
David S. Miller6c000552008-09-02 23:38:32 -07003248 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01003249 struct link *l_ptr;
3250 u32 res = MAX_PKT_DEFAULT;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003251
Per Lidenb97bf3f2006-01-02 19:04:38 +01003252 if (dest == tipc_own_addr)
3253 return MAX_MSG_SIZE;
3254
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003255 read_lock_bh(&tipc_net_lock);
Per Liden4323add2006-01-18 00:38:21 +01003256 n_ptr = tipc_node_select(dest, selector);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003257 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01003258 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003259 l_ptr = n_ptr->active_links[selector & 1];
3260 if (l_ptr)
Allan Stephens15e979d2010-05-11 14:30:10 +00003261 res = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01003262 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003263 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003264 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003265 return res;
3266}
3267
3268#if 0
3269static void link_dump_rec_queue(struct link *l_ptr)
3270{
3271 struct sk_buff *crs;
3272
3273 if (!l_ptr->oldest_deferred_in) {
3274 info("Reception queue empty\n");
3275 return;
3276 }
3277 info("Contents of Reception queue:\n");
3278 crs = l_ptr->oldest_deferred_in;
3279 while (crs) {
3280 if (crs->data == (void *)0x0000a3a3) {
3281 info("buffer %x invalid\n", crs);
3282 return;
3283 }
Frans Popa570f092010-03-24 07:57:29 +00003284 msg_dbg(buf_msg(crs), "In rec queue:\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01003285 crs = crs->next;
3286 }
3287}
3288#endif
3289
3290static void link_dump_send_queue(struct link *l_ptr)
3291{
3292 if (l_ptr->next_out) {
3293 info("\nContents of unsent queue:\n");
3294 dbg_print_buf_chain(l_ptr->next_out);
3295 }
3296 info("\nContents of send queue:\n");
3297 if (l_ptr->first_out) {
3298 dbg_print_buf_chain(l_ptr->first_out);
3299 }
3300 info("Empty send queue\n");
3301}
3302
3303static void link_print(struct link *l_ptr, struct print_buf *buf,
3304 const char *str)
3305{
3306 tipc_printf(buf, str);
3307 if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr))
3308 return;
3309 tipc_printf(buf, "Link %x<%s>:",
3310 l_ptr->addr, l_ptr->b_ptr->publ.name);
3311 tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no));
3312 tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no));
3313 tipc_printf(buf, "SQUE");
3314 if (l_ptr->first_out) {
3315 tipc_printf(buf, "[%u..", msg_seqno(buf_msg(l_ptr->first_out)));
3316 if (l_ptr->next_out)
3317 tipc_printf(buf, "%u..",
3318 msg_seqno(buf_msg(l_ptr->next_out)));
Allan Stephensb82834e2010-05-11 14:30:04 +00003319 tipc_printf(buf, "%u]", msg_seqno(buf_msg(l_ptr->last_out)));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003320 if ((mod(msg_seqno(buf_msg(l_ptr->last_out)) -
3321 msg_seqno(buf_msg(l_ptr->first_out)))
Joe Perchesf64f9e72009-11-29 16:55:45 -08003322 != (l_ptr->out_queue_size - 1)) ||
3323 (l_ptr->last_out->next != NULL)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01003324 tipc_printf(buf, "\nSend queue inconsistency\n");
3325 tipc_printf(buf, "first_out= %x ", l_ptr->first_out);
3326 tipc_printf(buf, "next_out= %x ", l_ptr->next_out);
3327 tipc_printf(buf, "last_out= %x ", l_ptr->last_out);
3328 link_dump_send_queue(l_ptr);
3329 }
3330 } else
3331 tipc_printf(buf, "[]");
3332 tipc_printf(buf, "SQSIZ(%u)", l_ptr->out_queue_size);
3333 if (l_ptr->oldest_deferred_in) {
3334 u32 o = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
3335 u32 n = msg_seqno(buf_msg(l_ptr->newest_deferred_in));
3336 tipc_printf(buf, ":RQUE[%u..%u]", o, n);
3337 if (l_ptr->deferred_inqueue_sz != mod((n + 1) - o)) {
3338 tipc_printf(buf, ":RQSIZ(%u)",
3339 l_ptr->deferred_inqueue_sz);
3340 }
3341 }
3342 if (link_working_unknown(l_ptr))
3343 tipc_printf(buf, ":WU");
3344 if (link_reset_reset(l_ptr))
3345 tipc_printf(buf, ":RR");
3346 if (link_reset_unknown(l_ptr))
3347 tipc_printf(buf, ":RU");
3348 if (link_working_working(l_ptr))
3349 tipc_printf(buf, ":WW");
3350 tipc_printf(buf, "\n");
3351}
3352