blob: 647f2ecfde50edb61759df7f830649accc4b9537 [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"
Per Lidenb97bf3f2006-01-02 19:04:38 +010038#include "link.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010039#include "port.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "name_distr.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041#include "discover.h"
42#include "config.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010043
44
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090045/*
Allan Stephensa686e682008-06-04 17:29:39 -070046 * Out-of-range value for link session numbers
47 */
48
49#define INVALID_SESSION 0x10000
50
51/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090052 * Link state events:
Per Lidenb97bf3f2006-01-02 19:04:38 +010053 */
54
55#define STARTING_EVT 856384768 /* link processing trigger */
56#define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
57#define TIMEOUT_EVT 560817u /* link timer expired */
58
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090059/*
60 * The following two 'message types' is really just implementation
61 * data conveniently stored in the message header.
Per Lidenb97bf3f2006-01-02 19:04:38 +010062 * They must not be considered part of the protocol
63 */
64#define OPEN_MSG 0
65#define CLOSED_MSG 1
66
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090067/*
Per Lidenb97bf3f2006-01-02 19:04:38 +010068 * State value stored in 'exp_msg_count'
69 */
70
71#define START_CHANGEOVER 100000u
72
73/**
74 * struct link_name - deconstructed link name
75 * @addr_local: network address of node at this end
76 * @if_local: name of interface at this end
77 * @addr_peer: network address of node at far end
78 * @if_peer: name of interface at far end
79 */
80
81struct link_name {
82 u32 addr_local;
83 char if_local[TIPC_MAX_IF_NAME];
84 u32 addr_peer;
85 char if_peer[TIPC_MAX_IF_NAME];
86};
87
Per Lidenb97bf3f2006-01-02 19:04:38 +010088static void link_handle_out_of_seq_msg(struct link *l_ptr,
89 struct sk_buff *buf);
90static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf);
91static int link_recv_changeover_msg(struct link **l_ptr, struct sk_buff **buf);
92static void link_set_supervision_props(struct link *l_ptr, u32 tolerance);
93static int link_send_sections_long(struct port *sender,
94 struct iovec const *msg_sect,
95 u32 num_sect, u32 destnode);
96static void link_check_defragm_bufs(struct link *l_ptr);
97static void link_state_event(struct link *l_ptr, u32 event);
98static void link_reset_statistics(struct link *l_ptr);
Allan Stephens8d64a5b2010-12-31 18:59:27 +000099static void link_print(struct link *l_ptr, const char *str);
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000100static void link_start(struct link *l_ptr);
101static int link_send_long_buf(struct link *l_ptr, struct sk_buff *buf);
102
Per Lidenb97bf3f2006-01-02 19:04:38 +0100103/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800104 * Simple link routines
Per Lidenb97bf3f2006-01-02 19:04:38 +0100105 */
106
Sam Ravnborg05790c62006-03-20 22:37:04 -0800107static unsigned int align(unsigned int i)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108{
109 return (i + 3) & ~3u;
110}
111
Sam Ravnborg05790c62006-03-20 22:37:04 -0800112static void link_init_max_pkt(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100113{
114 u32 max_pkt;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900115
Per Lidenb97bf3f2006-01-02 19:04:38 +0100116 max_pkt = (l_ptr->b_ptr->publ.mtu & ~3);
117 if (max_pkt > MAX_MSG_SIZE)
118 max_pkt = MAX_MSG_SIZE;
119
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900120 l_ptr->max_pkt_target = max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100121 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
122 l_ptr->max_pkt = l_ptr->max_pkt_target;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900123 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100124 l_ptr->max_pkt = MAX_PKT_DEFAULT;
125
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900126 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127}
128
Sam Ravnborg05790c62006-03-20 22:37:04 -0800129static u32 link_next_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100130{
131 if (l_ptr->next_out)
132 return msg_seqno(buf_msg(l_ptr->next_out));
133 return mod(l_ptr->next_out_no);
134}
135
Sam Ravnborg05790c62006-03-20 22:37:04 -0800136static u32 link_last_sent(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100137{
138 return mod(link_next_sent(l_ptr) - 1);
139}
140
141/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800142 * Simple non-static link routines (i.e. referenced outside this file)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100143 */
144
Per Liden4323add2006-01-18 00:38:21 +0100145int tipc_link_is_up(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146{
147 if (!l_ptr)
148 return 0;
Eric Dumazeta02cec22010-09-22 20:43:57 +0000149 return link_working_working(l_ptr) || link_working_unknown(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100150}
151
Per Liden4323add2006-01-18 00:38:21 +0100152int tipc_link_is_active(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100153{
Eric Dumazeta02cec22010-09-22 20:43:57 +0000154 return (l_ptr->owner->active_links[0] == l_ptr) ||
155 (l_ptr->owner->active_links[1] == l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100156}
157
158/**
159 * link_name_validate - validate & (optionally) deconstruct link name
160 * @name - ptr to link name string
161 * @name_parts - ptr to area for link name components (or NULL if not needed)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900162 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100163 * Returns 1 if link name is valid, otherwise 0.
164 */
165
166static int link_name_validate(const char *name, struct link_name *name_parts)
167{
168 char name_copy[TIPC_MAX_LINK_NAME];
169 char *addr_local;
170 char *if_local;
171 char *addr_peer;
172 char *if_peer;
173 char dummy;
174 u32 z_local, c_local, n_local;
175 u32 z_peer, c_peer, n_peer;
176 u32 if_local_len;
177 u32 if_peer_len;
178
179 /* copy link name & ensure length is OK */
180
181 name_copy[TIPC_MAX_LINK_NAME - 1] = 0;
182 /* need above in case non-Posix strncpy() doesn't pad with nulls */
183 strncpy(name_copy, name, TIPC_MAX_LINK_NAME);
184 if (name_copy[TIPC_MAX_LINK_NAME - 1] != 0)
185 return 0;
186
187 /* ensure all component parts of link name are present */
188
189 addr_local = name_copy;
190 if ((if_local = strchr(addr_local, ':')) == NULL)
191 return 0;
192 *(if_local++) = 0;
193 if ((addr_peer = strchr(if_local, '-')) == NULL)
194 return 0;
195 *(addr_peer++) = 0;
196 if_local_len = addr_peer - if_local;
197 if ((if_peer = strchr(addr_peer, ':')) == NULL)
198 return 0;
199 *(if_peer++) = 0;
200 if_peer_len = strlen(if_peer) + 1;
201
202 /* validate component parts of link name */
203
204 if ((sscanf(addr_local, "%u.%u.%u%c",
205 &z_local, &c_local, &n_local, &dummy) != 3) ||
206 (sscanf(addr_peer, "%u.%u.%u%c",
207 &z_peer, &c_peer, &n_peer, &dummy) != 3) ||
208 (z_local > 255) || (c_local > 4095) || (n_local > 4095) ||
209 (z_peer > 255) || (c_peer > 4095) || (n_peer > 4095) ||
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900210 (if_local_len <= 1) || (if_local_len > TIPC_MAX_IF_NAME) ||
211 (if_peer_len <= 1) || (if_peer_len > TIPC_MAX_IF_NAME) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100212 (strspn(if_local, tipc_alphabet) != (if_local_len - 1)) ||
213 (strspn(if_peer, tipc_alphabet) != (if_peer_len - 1)))
214 return 0;
215
216 /* return link name components, if necessary */
217
218 if (name_parts) {
219 name_parts->addr_local = tipc_addr(z_local, c_local, n_local);
220 strcpy(name_parts->if_local, if_local);
221 name_parts->addr_peer = tipc_addr(z_peer, c_peer, n_peer);
222 strcpy(name_parts->if_peer, if_peer);
223 }
224 return 1;
225}
226
227/**
228 * link_timeout - handle expiration of link timer
229 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900230 *
Per Liden4323add2006-01-18 00:38:21 +0100231 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
232 * with tipc_link_delete(). (There is no risk that the node will be deleted by
233 * another thread because tipc_link_delete() always cancels the link timer before
234 * tipc_node_delete() is called.)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100235 */
236
237static void link_timeout(struct link *l_ptr)
238{
Per Liden4323add2006-01-18 00:38:21 +0100239 tipc_node_lock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100240
241 /* update counters used in statistical profiling of send traffic */
242
243 l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
244 l_ptr->stats.queue_sz_counts++;
245
246 if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz)
247 l_ptr->stats.max_queue_sz = l_ptr->out_queue_size;
248
249 if (l_ptr->first_out) {
250 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
251 u32 length = msg_size(msg);
252
Joe Perchesf64f9e72009-11-29 16:55:45 -0800253 if ((msg_user(msg) == MSG_FRAGMENTER) &&
254 (msg_type(msg) == FIRST_FRAGMENT)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100255 length = msg_size(msg_get_wrapped(msg));
256 }
257 if (length) {
258 l_ptr->stats.msg_lengths_total += length;
259 l_ptr->stats.msg_length_counts++;
260 if (length <= 64)
261 l_ptr->stats.msg_length_profile[0]++;
262 else if (length <= 256)
263 l_ptr->stats.msg_length_profile[1]++;
264 else if (length <= 1024)
265 l_ptr->stats.msg_length_profile[2]++;
266 else if (length <= 4096)
267 l_ptr->stats.msg_length_profile[3]++;
268 else if (length <= 16384)
269 l_ptr->stats.msg_length_profile[4]++;
270 else if (length <= 32768)
271 l_ptr->stats.msg_length_profile[5]++;
272 else
273 l_ptr->stats.msg_length_profile[6]++;
274 }
275 }
276
277 /* do all other link processing performed on a periodic basis */
278
279 link_check_defragm_bufs(l_ptr);
280
281 link_state_event(l_ptr, TIMEOUT_EVT);
282
283 if (l_ptr->next_out)
Per Liden4323add2006-01-18 00:38:21 +0100284 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285
Per Liden4323add2006-01-18 00:38:21 +0100286 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100287}
288
Sam Ravnborg05790c62006-03-20 22:37:04 -0800289static void link_set_timer(struct link *l_ptr, u32 time)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100290{
291 k_start_timer(&l_ptr->timer, time);
292}
293
294/**
Per Liden4323add2006-01-18 00:38:21 +0100295 * tipc_link_create - create a new link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100296 * @b_ptr: pointer to associated bearer
297 * @peer: network address of node at other end of link
298 * @media_addr: media address to use when sending messages over link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900299 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300 * Returns pointer to link.
301 */
302
Per Liden4323add2006-01-18 00:38:21 +0100303struct link *tipc_link_create(struct bearer *b_ptr, const u32 peer,
304 const struct tipc_media_addr *media_addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100305{
306 struct link *l_ptr;
307 struct tipc_msg *msg;
308 char *if_name;
309
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700310 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100311 if (!l_ptr) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700312 warn("Link creation failed, no memory\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100313 return NULL;
314 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100315
316 l_ptr->addr = peer;
317 if_name = strchr(b_ptr->publ.name, ':') + 1;
318 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:",
319 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900320 tipc_node(tipc_own_addr),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100321 if_name,
322 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
323 /* note: peer i/f is appended to link name by reset/activate */
324 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100325 l_ptr->checkpoint = 1;
326 l_ptr->b_ptr = b_ptr;
327 link_set_supervision_props(l_ptr, b_ptr->media->tolerance);
328 l_ptr->state = RESET_UNKNOWN;
329
330 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
331 msg = l_ptr->pmsg;
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000332 tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333 msg_set_size(msg, sizeof(l_ptr->proto_msg));
Allan Stephensa686e682008-06-04 17:29:39 -0700334 msg_set_session(msg, (tipc_random & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100335 msg_set_bearer_id(msg, b_ptr->identity);
336 strcpy((char *)msg_data(msg), if_name);
337
338 l_ptr->priority = b_ptr->priority;
Per Liden4323add2006-01-18 00:38:21 +0100339 tipc_link_set_queue_limits(l_ptr, b_ptr->media->window);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100340
341 link_init_max_pkt(l_ptr);
342
343 l_ptr->next_out_no = 1;
344 INIT_LIST_HEAD(&l_ptr->waiting_ports);
345
346 link_reset_statistics(l_ptr);
347
Per Liden4323add2006-01-18 00:38:21 +0100348 l_ptr->owner = tipc_node_attach_link(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100349 if (!l_ptr->owner) {
350 kfree(l_ptr);
351 return NULL;
352 }
353
Florian Westphal945710652007-07-26 00:05:07 -0700354 k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr);
355 list_add_tail(&l_ptr->link_list, &b_ptr->links);
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000356 tipc_k_signal((Handler)link_start, (unsigned long)l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100357
Per Lidenb97bf3f2006-01-02 19:04:38 +0100358 return l_ptr;
359}
360
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900361/**
Per Liden4323add2006-01-18 00:38:21 +0100362 * tipc_link_delete - delete a link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100363 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900364 *
Per Liden4323add2006-01-18 00:38:21 +0100365 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100366 * This routine must not grab the node lock until after link timer cancellation
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900367 * to avoid a potential deadlock situation.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100368 */
369
Per Liden4323add2006-01-18 00:38:21 +0100370void tipc_link_delete(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100371{
372 if (!l_ptr) {
373 err("Attempt to delete non-existent link\n");
374 return;
375 }
376
Per Lidenb97bf3f2006-01-02 19:04:38 +0100377 k_cancel_timer(&l_ptr->timer);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900378
Per Liden4323add2006-01-18 00:38:21 +0100379 tipc_node_lock(l_ptr->owner);
380 tipc_link_reset(l_ptr);
381 tipc_node_detach_link(l_ptr->owner, l_ptr);
382 tipc_link_stop(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100383 list_del_init(&l_ptr->link_list);
Per Liden4323add2006-01-18 00:38:21 +0100384 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100385 k_term_timer(&l_ptr->timer);
386 kfree(l_ptr);
387}
388
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000389static void link_start(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100390{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100391 link_state_event(l_ptr, STARTING_EVT);
392}
393
394/**
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900395 * link_schedule_port - schedule port for deferred sending
Per Lidenb97bf3f2006-01-02 19:04:38 +0100396 * @l_ptr: pointer to link
397 * @origport: reference to sending port
398 * @sz: amount of data to be sent
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900399 *
400 * Schedules port for renewed sending of messages after link congestion
Per Lidenb97bf3f2006-01-02 19:04:38 +0100401 * has abated.
402 */
403
404static int link_schedule_port(struct link *l_ptr, u32 origport, u32 sz)
405{
406 struct port *p_ptr;
407
Per Liden4323add2006-01-18 00:38:21 +0100408 spin_lock_bh(&tipc_port_list_lock);
409 p_ptr = tipc_port_lock(origport);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410 if (p_ptr) {
411 if (!p_ptr->wakeup)
412 goto exit;
413 if (!list_empty(&p_ptr->wait_list))
414 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100415 p_ptr->publ.congested = 1;
Allan Stephens15e979d2010-05-11 14:30:10 +0000416 p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100417 list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
418 l_ptr->stats.link_congs++;
419exit:
Per Liden4323add2006-01-18 00:38:21 +0100420 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100421 }
Per Liden4323add2006-01-18 00:38:21 +0100422 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100423 return -ELINKCONG;
424}
425
Per Liden4323add2006-01-18 00:38:21 +0100426void tipc_link_wakeup_ports(struct link *l_ptr, int all)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100427{
428 struct port *p_ptr;
429 struct port *temp_p_ptr;
430 int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
431
432 if (all)
433 win = 100000;
434 if (win <= 0)
435 return;
Per Liden4323add2006-01-18 00:38:21 +0100436 if (!spin_trylock_bh(&tipc_port_list_lock))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100437 return;
438 if (link_congested(l_ptr))
439 goto exit;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900440 list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441 wait_list) {
442 if (win <= 0)
443 break;
444 list_del_init(&p_ptr->wait_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100445 spin_lock_bh(p_ptr->publ.lock);
446 p_ptr->publ.congested = 0;
447 p_ptr->wakeup(&p_ptr->publ);
448 win -= p_ptr->waiting_pkts;
449 spin_unlock_bh(p_ptr->publ.lock);
450 }
451
452exit:
Per Liden4323add2006-01-18 00:38:21 +0100453 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100454}
455
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900456/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100457 * link_release_outqueue - purge link's outbound message queue
458 * @l_ptr: pointer to link
459 */
460
461static void link_release_outqueue(struct link *l_ptr)
462{
463 struct sk_buff *buf = l_ptr->first_out;
464 struct sk_buff *next;
465
466 while (buf) {
467 next = buf->next;
468 buf_discard(buf);
469 buf = next;
470 }
471 l_ptr->first_out = NULL;
472 l_ptr->out_queue_size = 0;
473}
474
475/**
Per Liden4323add2006-01-18 00:38:21 +0100476 * tipc_link_reset_fragments - purge link's inbound message fragments queue
Per Lidenb97bf3f2006-01-02 19:04:38 +0100477 * @l_ptr: pointer to link
478 */
479
Per Liden4323add2006-01-18 00:38:21 +0100480void tipc_link_reset_fragments(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100481{
482 struct sk_buff *buf = l_ptr->defragm_buf;
483 struct sk_buff *next;
484
485 while (buf) {
486 next = buf->next;
487 buf_discard(buf);
488 buf = next;
489 }
490 l_ptr->defragm_buf = NULL;
491}
492
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900493/**
Per Liden4323add2006-01-18 00:38:21 +0100494 * tipc_link_stop - purge all inbound and outbound messages associated with link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100495 * @l_ptr: pointer to link
496 */
497
Per Liden4323add2006-01-18 00:38:21 +0100498void tipc_link_stop(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100499{
500 struct sk_buff *buf;
501 struct sk_buff *next;
502
503 buf = l_ptr->oldest_deferred_in;
504 while (buf) {
505 next = buf->next;
506 buf_discard(buf);
507 buf = next;
508 }
509
510 buf = l_ptr->first_out;
511 while (buf) {
512 next = buf->next;
513 buf_discard(buf);
514 buf = next;
515 }
516
Per Liden4323add2006-01-18 00:38:21 +0100517 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100518
519 buf_discard(l_ptr->proto_msg_queue);
520 l_ptr->proto_msg_queue = NULL;
521}
522
Per Lidenb97bf3f2006-01-02 19:04:38 +0100523/* LINK EVENT CODE IS NOT SUPPORTED AT PRESENT */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100524#define link_send_event(fcn, l_ptr, up) do { } while (0)
525
Per Liden4323add2006-01-18 00:38:21 +0100526void tipc_link_reset(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100527{
528 struct sk_buff *buf;
529 u32 prev_state = l_ptr->state;
530 u32 checkpoint = l_ptr->next_in_no;
Allan Stephens5392d642006-06-25 23:52:50 -0700531 int was_active_link = tipc_link_is_active(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900532
Allan Stephensa686e682008-06-04 17:29:39 -0700533 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100534
Allan Stephensa686e682008-06-04 17:29:39 -0700535 /* Link is down, accept any session */
536 l_ptr->peer_session = INVALID_SESSION;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100537
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900538 /* Prepare for max packet size negotiation */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100539 link_init_max_pkt(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900540
Per Lidenb97bf3f2006-01-02 19:04:38 +0100541 l_ptr->state = RESET_UNKNOWN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100542
543 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
544 return;
545
Per Liden4323add2006-01-18 00:38:21 +0100546 tipc_node_link_down(l_ptr->owner, l_ptr);
547 tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr);
Paul Gortmaker7368ddf2010-10-12 14:25:58 +0000548
Allan Stephens5392d642006-06-25 23:52:50 -0700549 if (was_active_link && tipc_node_has_active_links(l_ptr->owner) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100550 l_ptr->owner->permit_changeover) {
551 l_ptr->reset_checkpoint = checkpoint;
552 l_ptr->exp_msg_count = START_CHANGEOVER;
553 }
554
555 /* Clean up all queues: */
556
557 link_release_outqueue(l_ptr);
558 buf_discard(l_ptr->proto_msg_queue);
559 l_ptr->proto_msg_queue = NULL;
560 buf = l_ptr->oldest_deferred_in;
561 while (buf) {
562 struct sk_buff *next = buf->next;
563 buf_discard(buf);
564 buf = next;
565 }
566 if (!list_empty(&l_ptr->waiting_ports))
Per Liden4323add2006-01-18 00:38:21 +0100567 tipc_link_wakeup_ports(l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100568
569 l_ptr->retransm_queue_head = 0;
570 l_ptr->retransm_queue_size = 0;
571 l_ptr->last_out = NULL;
572 l_ptr->first_out = NULL;
573 l_ptr->next_out = NULL;
574 l_ptr->unacked_window = 0;
575 l_ptr->checkpoint = 1;
576 l_ptr->next_out_no = 1;
577 l_ptr->deferred_inqueue_sz = 0;
578 l_ptr->oldest_deferred_in = NULL;
579 l_ptr->newest_deferred_in = NULL;
580 l_ptr->fsm_msg_cnt = 0;
581 l_ptr->stale_count = 0;
582 link_reset_statistics(l_ptr);
583
Per Liden4323add2006-01-18 00:38:21 +0100584 link_send_event(tipc_cfg_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100585 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100586 link_send_event(tipc_disc_link_event, l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100587}
588
589
590static void link_activate(struct link *l_ptr)
591{
Allan Stephens5392d642006-06-25 23:52:50 -0700592 l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
Per Liden4323add2006-01-18 00:38:21 +0100593 tipc_node_link_up(l_ptr->owner, l_ptr);
594 tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr);
595 link_send_event(tipc_cfg_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100596 if (!in_own_cluster(l_ptr->addr))
Per Liden4323add2006-01-18 00:38:21 +0100597 link_send_event(tipc_disc_link_event, l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100598}
599
600/**
601 * link_state_event - link finite state machine
602 * @l_ptr: pointer to link
603 * @event: state machine event to process
604 */
605
606static void link_state_event(struct link *l_ptr, unsigned event)
607{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900608 struct link *other;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100609 u32 cont_intv = l_ptr->continuity_interval;
610
611 if (!l_ptr->started && (event != STARTING_EVT))
612 return; /* Not yet. */
613
614 if (link_blocked(l_ptr)) {
615 if (event == TIMEOUT_EVT) {
616 link_set_timer(l_ptr, cont_intv);
617 }
618 return; /* Changeover going on */
619 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100620
621 switch (l_ptr->state) {
622 case WORKING_WORKING:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100623 switch (event) {
624 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100625 case ACTIVATE_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100626 break;
627 case TIMEOUT_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100628 if (l_ptr->next_in_no != l_ptr->checkpoint) {
629 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100630 if (tipc_bclink_acks_missing(l_ptr->owner)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900631 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100632 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100633 l_ptr->fsm_msg_cnt++;
634 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900635 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100636 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100637 l_ptr->fsm_msg_cnt++;
638 }
639 link_set_timer(l_ptr, cont_intv);
640 break;
641 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100642 l_ptr->state = WORKING_UNKNOWN;
643 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100644 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100645 l_ptr->fsm_msg_cnt++;
646 link_set_timer(l_ptr, cont_intv / 4);
647 break;
648 case RESET_MSG:
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900649 info("Resetting link <%s>, requested by peer\n",
Allan Stephensa10bd922006-06-25 23:52:17 -0700650 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100651 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652 l_ptr->state = RESET_RESET;
653 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100654 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100655 l_ptr->fsm_msg_cnt++;
656 link_set_timer(l_ptr, cont_intv);
657 break;
658 default:
659 err("Unknown link event %u in WW state\n", event);
660 }
661 break;
662 case WORKING_UNKNOWN:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100663 switch (event) {
664 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100665 case ACTIVATE_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100666 l_ptr->state = WORKING_WORKING;
667 l_ptr->fsm_msg_cnt = 0;
668 link_set_timer(l_ptr, cont_intv);
669 break;
670 case RESET_MSG:
Allan Stephensa10bd922006-06-25 23:52:17 -0700671 info("Resetting link <%s>, requested by peer "
672 "while probing\n", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100673 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100674 l_ptr->state = RESET_RESET;
675 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100676 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100677 l_ptr->fsm_msg_cnt++;
678 link_set_timer(l_ptr, cont_intv);
679 break;
680 case TIMEOUT_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681 if (l_ptr->next_in_no != l_ptr->checkpoint) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100682 l_ptr->state = WORKING_WORKING;
683 l_ptr->fsm_msg_cnt = 0;
684 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100685 if (tipc_bclink_acks_missing(l_ptr->owner)) {
686 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
687 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100688 l_ptr->fsm_msg_cnt++;
689 }
690 link_set_timer(l_ptr, cont_intv);
691 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900692 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100693 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100694 l_ptr->fsm_msg_cnt++;
695 link_set_timer(l_ptr, cont_intv / 4);
696 } else { /* Link has failed */
Allan Stephensa10bd922006-06-25 23:52:17 -0700697 warn("Resetting link <%s>, peer not responding\n",
698 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100699 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100700 l_ptr->state = RESET_UNKNOWN;
701 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100702 tipc_link_send_proto_msg(l_ptr, RESET_MSG,
703 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100704 l_ptr->fsm_msg_cnt++;
705 link_set_timer(l_ptr, cont_intv);
706 }
707 break;
708 default:
709 err("Unknown link event %u in WU state\n", event);
710 }
711 break;
712 case RESET_UNKNOWN:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713 switch (event) {
714 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100715 break;
716 case ACTIVATE_MSG:
717 other = l_ptr->owner->active_links[0];
Allan Stephens8d64a5b2010-12-31 18:59:27 +0000718 if (other && link_working_unknown(other))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100719 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100720 l_ptr->state = WORKING_WORKING;
721 l_ptr->fsm_msg_cnt = 0;
722 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100723 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100724 l_ptr->fsm_msg_cnt++;
725 link_set_timer(l_ptr, cont_intv);
726 break;
727 case RESET_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100728 l_ptr->state = RESET_RESET;
729 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100730 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100731 l_ptr->fsm_msg_cnt++;
732 link_set_timer(l_ptr, cont_intv);
733 break;
734 case STARTING_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100735 l_ptr->started = 1;
736 /* fall through */
737 case TIMEOUT_EVT:
Per Liden4323add2006-01-18 00:38:21 +0100738 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100739 l_ptr->fsm_msg_cnt++;
740 link_set_timer(l_ptr, cont_intv);
741 break;
742 default:
743 err("Unknown link event %u in RU state\n", event);
744 }
745 break;
746 case RESET_RESET:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100747 switch (event) {
748 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100749 case ACTIVATE_MSG:
750 other = l_ptr->owner->active_links[0];
Allan Stephens8d64a5b2010-12-31 18:59:27 +0000751 if (other && link_working_unknown(other))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100752 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100753 l_ptr->state = WORKING_WORKING;
754 l_ptr->fsm_msg_cnt = 0;
755 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100756 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100757 l_ptr->fsm_msg_cnt++;
758 link_set_timer(l_ptr, cont_intv);
759 break;
760 case RESET_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100761 break;
762 case TIMEOUT_EVT:
Per Liden4323add2006-01-18 00:38:21 +0100763 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100764 l_ptr->fsm_msg_cnt++;
765 link_set_timer(l_ptr, cont_intv);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100766 break;
767 default:
768 err("Unknown link event %u in RR state\n", event);
769 }
770 break;
771 default:
772 err("Unknown link state %u/%u\n", l_ptr->state, event);
773 }
774}
775
776/*
777 * link_bundle_buf(): Append contents of a buffer to
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900778 * the tail of an existing one.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100779 */
780
781static int link_bundle_buf(struct link *l_ptr,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900782 struct sk_buff *bundler,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100783 struct sk_buff *buf)
784{
785 struct tipc_msg *bundler_msg = buf_msg(bundler);
786 struct tipc_msg *msg = buf_msg(buf);
787 u32 size = msg_size(msg);
Allan Stephense49060c2006-06-29 12:32:46 -0700788 u32 bundle_size = msg_size(bundler_msg);
789 u32 to_pos = align(bundle_size);
790 u32 pad = to_pos - bundle_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100791
792 if (msg_user(bundler_msg) != MSG_BUNDLER)
793 return 0;
794 if (msg_type(bundler_msg) != OPEN_MSG)
795 return 0;
Allan Stephense49060c2006-06-29 12:32:46 -0700796 if (skb_tailroom(bundler) < (pad + size))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100797 return 0;
Allan Stephens15e979d2010-05-11 14:30:10 +0000798 if (l_ptr->max_pkt < (to_pos + size))
Allan Stephens863fae62006-07-03 19:39:36 -0700799 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100800
Allan Stephense49060c2006-06-29 12:32:46 -0700801 skb_put(bundler, pad + size);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300802 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100803 msg_set_size(bundler_msg, to_pos + size);
804 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100805 buf_discard(buf);
806 l_ptr->stats.sent_bundled++;
807 return 1;
808}
809
Sam Ravnborg05790c62006-03-20 22:37:04 -0800810static void link_add_to_outqueue(struct link *l_ptr,
811 struct sk_buff *buf,
812 struct tipc_msg *msg)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100813{
814 u32 ack = mod(l_ptr->next_in_no - 1);
815 u32 seqno = mod(l_ptr->next_out_no++);
816
817 msg_set_word(msg, 2, ((ack << 16) | seqno));
818 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
819 buf->next = NULL;
820 if (l_ptr->first_out) {
821 l_ptr->last_out->next = buf;
822 l_ptr->last_out = buf;
823 } else
824 l_ptr->first_out = l_ptr->last_out = buf;
825 l_ptr->out_queue_size++;
826}
827
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900828/*
829 * tipc_link_send_buf() is the 'full path' for messages, called from
Per Lidenb97bf3f2006-01-02 19:04:38 +0100830 * inside TIPC when the 'fast path' in tipc_send_buf
831 * has failed, and from link_send()
832 */
833
Per Liden4323add2006-01-18 00:38:21 +0100834int tipc_link_send_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100835{
836 struct tipc_msg *msg = buf_msg(buf);
837 u32 size = msg_size(msg);
838 u32 dsz = msg_data_sz(msg);
839 u32 queue_size = l_ptr->out_queue_size;
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000840 u32 imp = tipc_msg_tot_importance(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100841 u32 queue_limit = l_ptr->queue_limit[imp];
Allan Stephens15e979d2010-05-11 14:30:10 +0000842 u32 max_packet = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100843
844 msg_set_prevnode(msg, tipc_own_addr); /* If routed message */
845
846 /* Match msg importance against queue limits: */
847
848 if (unlikely(queue_size >= queue_limit)) {
849 if (imp <= TIPC_CRITICAL_IMPORTANCE) {
850 return link_schedule_port(l_ptr, msg_origport(msg),
851 size);
852 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100853 buf_discard(buf);
854 if (imp > CONN_MANAGER) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700855 warn("Resetting link <%s>, send queue full", l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100856 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100857 }
858 return dsz;
859 }
860
861 /* Fragmentation needed ? */
862
863 if (size > max_packet)
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000864 return link_send_long_buf(l_ptr, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100865
866 /* Packet can be queued or sent: */
867
868 if (queue_size > l_ptr->stats.max_queue_sz)
869 l_ptr->stats.max_queue_sz = queue_size;
870
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900871 if (likely(!tipc_bearer_congested(l_ptr->b_ptr, l_ptr) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100872 !link_congested(l_ptr))) {
873 link_add_to_outqueue(l_ptr, buf, msg);
874
Per Liden4323add2006-01-18 00:38:21 +0100875 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100876 l_ptr->unacked_window = 0;
877 } else {
Per Liden4323add2006-01-18 00:38:21 +0100878 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100879 l_ptr->stats.bearer_congs++;
880 l_ptr->next_out = buf;
881 }
882 return dsz;
883 }
884 /* Congestion: can message be bundled ?: */
885
886 if ((msg_user(msg) != CHANGEOVER_PROTOCOL) &&
887 (msg_user(msg) != MSG_FRAGMENTER)) {
888
889 /* Try adding message to an existing bundle */
890
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900891 if (l_ptr->next_out &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100892 link_bundle_buf(l_ptr, l_ptr->last_out, buf)) {
Per Liden4323add2006-01-18 00:38:21 +0100893 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100894 return dsz;
895 }
896
897 /* Try creating a new bundle */
898
899 if (size <= max_packet * 2 / 3) {
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000900 struct sk_buff *bundler = tipc_buf_acquire(max_packet);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100901 struct tipc_msg bundler_hdr;
902
903 if (bundler) {
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000904 tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG,
Allan Stephens75715212008-06-04 17:37:34 -0700905 INT_H_SIZE, l_ptr->addr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300906 skb_copy_to_linear_data(bundler, &bundler_hdr,
907 INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100908 skb_trim(bundler, INT_H_SIZE);
909 link_bundle_buf(l_ptr, bundler, buf);
910 buf = bundler;
911 msg = buf_msg(buf);
912 l_ptr->stats.sent_bundles++;
913 }
914 }
915 }
916 if (!l_ptr->next_out)
917 l_ptr->next_out = buf;
918 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +0100919 tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100920 return dsz;
921}
922
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900923/*
924 * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has
Per Lidenb97bf3f2006-01-02 19:04:38 +0100925 * not been selected yet, and the the owner node is not locked
926 * Called by TIPC internal users, e.g. the name distributor
927 */
928
Per Liden4323add2006-01-18 00:38:21 +0100929int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100930{
931 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -0700932 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100933 int res = -ELINKCONG;
934
Per Liden4323add2006-01-18 00:38:21 +0100935 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000936 n_ptr = tipc_node_find(dest);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100937 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +0100938 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100939 l_ptr = n_ptr->active_links[selector & 1];
Per Lidenb97bf3f2006-01-02 19:04:38 +0100940 if (l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +0100941 res = tipc_link_send_buf(l_ptr, buf);
Allan Stephensc33d53b2006-06-25 23:50:30 -0700942 } else {
Allan Stephensc33d53b2006-06-25 23:50:30 -0700943 buf_discard(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100944 }
Per Liden4323add2006-01-18 00:38:21 +0100945 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100946 } else {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100947 buf_discard(buf);
948 }
Per Liden4323add2006-01-18 00:38:21 +0100949 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100950 return res;
951}
952
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900953/*
954 * link_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +0100955 * destination link is known and the header is complete,
956 * inclusive total message length. Very time critical.
957 * Link is locked. Returns user data length.
958 */
959
Sam Ravnborg05790c62006-03-20 22:37:04 -0800960static int link_send_buf_fast(struct link *l_ptr, struct sk_buff *buf,
961 u32 *used_max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100962{
963 struct tipc_msg *msg = buf_msg(buf);
964 int res = msg_data_sz(msg);
965
966 if (likely(!link_congested(l_ptr))) {
Allan Stephens15e979d2010-05-11 14:30:10 +0000967 if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100968 if (likely(list_empty(&l_ptr->b_ptr->cong_links))) {
969 link_add_to_outqueue(l_ptr, buf, msg);
Per Liden4323add2006-01-18 00:38:21 +0100970 if (likely(tipc_bearer_send(l_ptr->b_ptr, buf,
971 &l_ptr->media_addr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100972 l_ptr->unacked_window = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100973 return res;
974 }
Per Liden4323add2006-01-18 00:38:21 +0100975 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100976 l_ptr->stats.bearer_congs++;
977 l_ptr->next_out = buf;
978 return res;
979 }
980 }
981 else
Allan Stephens15e979d2010-05-11 14:30:10 +0000982 *used_max_pkt = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100983 }
Per Liden4323add2006-01-18 00:38:21 +0100984 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100985}
986
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900987/*
988 * tipc_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +0100989 * destination node is known and the header is complete,
990 * inclusive total message length.
991 * Returns user data length.
992 */
993int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode)
994{
995 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -0700996 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100997 int res;
998 u32 selector = msg_origport(buf_msg(buf)) & 1;
999 u32 dummy;
1000
1001 if (destnode == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +01001002 return tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001003
Per Liden4323add2006-01-18 00:38:21 +01001004 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001005 n_ptr = tipc_node_find(destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001006 if (likely(n_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001007 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001008 l_ptr = n_ptr->active_links[selector];
Per Lidenb97bf3f2006-01-02 19:04:38 +01001009 if (likely(l_ptr)) {
1010 res = link_send_buf_fast(l_ptr, buf, &dummy);
Per Liden4323add2006-01-18 00:38:21 +01001011 tipc_node_unlock(n_ptr);
1012 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001013 return res;
1014 }
Per Liden4323add2006-01-18 00:38:21 +01001015 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001016 }
Per Liden4323add2006-01-18 00:38:21 +01001017 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001018 res = msg_data_sz(buf_msg(buf));
1019 tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1020 return res;
1021}
1022
1023
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001024/*
1025 * tipc_link_send_sections_fast: Entry for messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001026 * destination processor is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001027 * except for total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001028 * Returns user data length or errno.
1029 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001030int tipc_link_send_sections_fast(struct port *sender,
Per Liden4323add2006-01-18 00:38:21 +01001031 struct iovec const *msg_sect,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001032 const u32 num_sect,
Per Liden4323add2006-01-18 00:38:21 +01001033 u32 destaddr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001034{
1035 struct tipc_msg *hdr = &sender->publ.phdr;
1036 struct link *l_ptr;
1037 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -07001038 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001039 int res;
1040 u32 selector = msg_origport(hdr) & 1;
1041
Per Lidenb97bf3f2006-01-02 19:04:38 +01001042again:
1043 /*
1044 * Try building message using port's max_pkt hint.
1045 * (Must not hold any locks while building message.)
1046 */
1047
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001048 res = tipc_msg_build(hdr, msg_sect, num_sect, sender->publ.max_pkt,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001049 !sender->user_port, &buf);
1050
Per Liden4323add2006-01-18 00:38:21 +01001051 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001052 node = tipc_node_find(destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001053 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001054 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001055 l_ptr = node->active_links[selector];
1056 if (likely(l_ptr)) {
1057 if (likely(buf)) {
1058 res = link_send_buf_fast(l_ptr, buf,
Allan Stephens05646c92007-06-10 17:25:24 -07001059 &sender->publ.max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001060 if (unlikely(res < 0))
1061 buf_discard(buf);
1062exit:
Per Liden4323add2006-01-18 00:38:21 +01001063 tipc_node_unlock(node);
1064 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001065 return res;
1066 }
1067
1068 /* Exit if build request was invalid */
1069
1070 if (unlikely(res < 0))
1071 goto exit;
1072
1073 /* Exit if link (or bearer) is congested */
1074
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001075 if (link_congested(l_ptr) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +01001076 !list_empty(&l_ptr->b_ptr->cong_links)) {
1077 res = link_schedule_port(l_ptr,
1078 sender->publ.ref, res);
1079 goto exit;
1080 }
1081
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001082 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001083 * Message size exceeds max_pkt hint; update hint,
1084 * then re-try fast path or fragment the message
1085 */
1086
Allan Stephens15e979d2010-05-11 14:30:10 +00001087 sender->publ.max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001088 tipc_node_unlock(node);
1089 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001090
1091
Allan Stephens05646c92007-06-10 17:25:24 -07001092 if ((msg_hdr_sz(hdr) + res) <= sender->publ.max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001093 goto again;
1094
1095 return link_send_sections_long(sender, msg_sect,
1096 num_sect, destaddr);
1097 }
Per Liden4323add2006-01-18 00:38:21 +01001098 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001099 }
Per Liden4323add2006-01-18 00:38:21 +01001100 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001101
1102 /* Couldn't find a link to the destination node */
1103
1104 if (buf)
1105 return tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1106 if (res >= 0)
Per Liden4323add2006-01-18 00:38:21 +01001107 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1108 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001109 return res;
1110}
1111
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001112/*
1113 * link_send_sections_long(): Entry for long messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001114 * destination node is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001115 * inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001116 * Link and bearer congestion status have been checked to be ok,
1117 * and are ignored if they change.
1118 *
1119 * Note that fragments do not use the full link MTU so that they won't have
1120 * to undergo refragmentation if link changeover causes them to be sent
1121 * over another link with an additional tunnel header added as prefix.
1122 * (Refragmentation will still occur if the other link has a smaller MTU.)
1123 *
1124 * Returns user data length or errno.
1125 */
1126static int link_send_sections_long(struct port *sender,
1127 struct iovec const *msg_sect,
1128 u32 num_sect,
1129 u32 destaddr)
1130{
1131 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001132 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001133 struct tipc_msg *hdr = &sender->publ.phdr;
1134 u32 dsz = msg_data_sz(hdr);
1135 u32 max_pkt,fragm_sz,rest;
1136 struct tipc_msg fragm_hdr;
1137 struct sk_buff *buf,*buf_chain,*prev;
1138 u32 fragm_crs,fragm_rest,hsz,sect_rest;
1139 const unchar *sect_crs;
1140 int curr_sect;
1141 u32 fragm_no;
1142
1143again:
1144 fragm_no = 1;
Allan Stephens05646c92007-06-10 17:25:24 -07001145 max_pkt = sender->publ.max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001146 /* leave room for tunnel header in case of link changeover */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001147 fragm_sz = max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001148 /* leave room for fragmentation header in each fragment */
1149 rest = dsz;
1150 fragm_crs = 0;
1151 fragm_rest = 0;
1152 sect_rest = 0;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001153 sect_crs = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001154 curr_sect = -1;
1155
1156 /* Prepare reusable fragment header: */
1157
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001158 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07001159 INT_H_SIZE, msg_destnode(hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001160 msg_set_link_selector(&fragm_hdr, sender->publ.ref);
1161 msg_set_size(&fragm_hdr, max_pkt);
1162 msg_set_fragm_no(&fragm_hdr, 1);
1163
1164 /* Prepare header of first fragment: */
1165
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001166 buf_chain = buf = tipc_buf_acquire(max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001167 if (!buf)
1168 return -ENOMEM;
1169 buf->next = NULL;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001170 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001171 hsz = msg_hdr_sz(hdr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001172 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001173
1174 /* Chop up message: */
1175
1176 fragm_crs = INT_H_SIZE + hsz;
1177 fragm_rest = fragm_sz - hsz;
1178
1179 do { /* For all sections */
1180 u32 sz;
1181
1182 if (!sect_rest) {
1183 sect_rest = msg_sect[++curr_sect].iov_len;
1184 sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
1185 }
1186
1187 if (sect_rest < fragm_rest)
1188 sz = sect_rest;
1189 else
1190 sz = fragm_rest;
1191
1192 if (likely(!sender->user_port)) {
1193 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
1194error:
1195 for (; buf_chain; buf_chain = buf) {
1196 buf = buf_chain->next;
1197 buf_discard(buf_chain);
1198 }
1199 return -EFAULT;
1200 }
1201 } else
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001202 skb_copy_to_linear_data_offset(buf, fragm_crs,
1203 sect_crs, sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001204 sect_crs += sz;
1205 sect_rest -= sz;
1206 fragm_crs += sz;
1207 fragm_rest -= sz;
1208 rest -= sz;
1209
1210 if (!fragm_rest && rest) {
1211
1212 /* Initiate new fragment: */
1213 if (rest <= fragm_sz) {
1214 fragm_sz = rest;
1215 msg_set_type(&fragm_hdr,LAST_FRAGMENT);
1216 } else {
1217 msg_set_type(&fragm_hdr, FRAGMENT);
1218 }
1219 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
1220 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
1221 prev = buf;
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001222 buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001223 if (!buf)
1224 goto error;
1225
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001226 buf->next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001227 prev->next = buf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001228 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001229 fragm_crs = INT_H_SIZE;
1230 fragm_rest = fragm_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001231 }
1232 }
1233 while (rest > 0);
1234
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001235 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001236 * Now we have a buffer chain. Select a link and check
1237 * that packet size is still OK
1238 */
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001239 node = tipc_node_find(destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001240 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001241 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001242 l_ptr = node->active_links[sender->publ.ref & 1];
1243 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001244 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001245 goto reject;
1246 }
Allan Stephens15e979d2010-05-11 14:30:10 +00001247 if (l_ptr->max_pkt < max_pkt) {
1248 sender->publ.max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001249 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001250 for (; buf_chain; buf_chain = buf) {
1251 buf = buf_chain->next;
1252 buf_discard(buf_chain);
1253 }
1254 goto again;
1255 }
1256 } else {
1257reject:
1258 for (; buf_chain; buf_chain = buf) {
1259 buf = buf_chain->next;
1260 buf_discard(buf_chain);
1261 }
Per Liden4323add2006-01-18 00:38:21 +01001262 return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect,
1263 TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001264 }
1265
1266 /* Append whole chain to send queue: */
1267
1268 buf = buf_chain;
1269 l_ptr->long_msg_seq_no = mod(l_ptr->long_msg_seq_no + 1);
1270 if (!l_ptr->next_out)
1271 l_ptr->next_out = buf_chain;
1272 l_ptr->stats.sent_fragmented++;
1273 while (buf) {
1274 struct sk_buff *next = buf->next;
1275 struct tipc_msg *msg = buf_msg(buf);
1276
1277 l_ptr->stats.sent_fragments++;
1278 msg_set_long_msgno(msg, l_ptr->long_msg_seq_no);
1279 link_add_to_outqueue(l_ptr, buf, msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001280 buf = next;
1281 }
1282
1283 /* Send it, if possible: */
1284
Per Liden4323add2006-01-18 00:38:21 +01001285 tipc_link_push_queue(l_ptr);
1286 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001287 return dsz;
1288}
1289
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001290/*
Per Liden4323add2006-01-18 00:38:21 +01001291 * tipc_link_push_packet: Push one unsent packet to the media
Per Lidenb97bf3f2006-01-02 19:04:38 +01001292 */
Per Liden4323add2006-01-18 00:38:21 +01001293u32 tipc_link_push_packet(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001294{
1295 struct sk_buff *buf = l_ptr->first_out;
1296 u32 r_q_size = l_ptr->retransm_queue_size;
1297 u32 r_q_head = l_ptr->retransm_queue_head;
1298
1299 /* Step to position where retransmission failed, if any, */
1300 /* consider that buffers may have been released in meantime */
1301
1302 if (r_q_size && buf) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001303 u32 last = lesser(mod(r_q_head + r_q_size),
Per Lidenb97bf3f2006-01-02 19:04:38 +01001304 link_last_sent(l_ptr));
1305 u32 first = msg_seqno(buf_msg(buf));
1306
1307 while (buf && less(first, r_q_head)) {
1308 first = mod(first + 1);
1309 buf = buf->next;
1310 }
1311 l_ptr->retransm_queue_head = r_q_head = first;
1312 l_ptr->retransm_queue_size = r_q_size = mod(last - first);
1313 }
1314
1315 /* Continue retransmission now, if there is anything: */
1316
Neil Hormanca509102010-03-15 07:58:45 +00001317 if (r_q_size && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001318 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001319 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001320 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001321 l_ptr->retransm_queue_head = mod(++r_q_head);
1322 l_ptr->retransm_queue_size = --r_q_size;
1323 l_ptr->stats.retransmitted++;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001324 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001325 } else {
1326 l_ptr->stats.bearer_congs++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001327 return PUSH_FAILED;
1328 }
1329 }
1330
1331 /* Send deferred protocol message, if any: */
1332
1333 buf = l_ptr->proto_msg_queue;
1334 if (buf) {
1335 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001336 msg_set_bcast_ack(buf_msg(buf),l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001337 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001338 l_ptr->unacked_window = 0;
1339 buf_discard(buf);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001340 l_ptr->proto_msg_queue = NULL;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001341 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001342 } else {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001343 l_ptr->stats.bearer_congs++;
1344 return PUSH_FAILED;
1345 }
1346 }
1347
1348 /* Send one deferred data message, if send window not full: */
1349
1350 buf = l_ptr->next_out;
1351 if (buf) {
1352 struct tipc_msg *msg = buf_msg(buf);
1353 u32 next = msg_seqno(msg);
1354 u32 first = msg_seqno(buf_msg(l_ptr->first_out));
1355
1356 if (mod(next - first) < l_ptr->queue_limit[0]) {
1357 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001358 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001359 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001360 if (msg_user(msg) == MSG_BUNDLER)
1361 msg_set_type(msg, CLOSED_MSG);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001362 l_ptr->next_out = buf->next;
Allan Stephens0e35fd52008-07-14 22:44:01 -07001363 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001364 } else {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001365 l_ptr->stats.bearer_congs++;
1366 return PUSH_FAILED;
1367 }
1368 }
1369 }
1370 return PUSH_FINISHED;
1371}
1372
1373/*
1374 * push_queue(): push out the unsent messages of a link where
1375 * congestion has abated. Node is locked
1376 */
Per Liden4323add2006-01-18 00:38:21 +01001377void tipc_link_push_queue(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001378{
1379 u32 res;
1380
Per Liden4323add2006-01-18 00:38:21 +01001381 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001382 return;
1383
1384 do {
Per Liden4323add2006-01-18 00:38:21 +01001385 res = tipc_link_push_packet(l_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -07001386 } while (!res);
1387
Per Lidenb97bf3f2006-01-02 19:04:38 +01001388 if (res == PUSH_FAILED)
Per Liden4323add2006-01-18 00:38:21 +01001389 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001390}
1391
Allan Stephensd356eeb2006-06-25 23:40:01 -07001392static void link_reset_all(unsigned long addr)
1393{
David S. Miller6c000552008-09-02 23:38:32 -07001394 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001395 char addr_string[16];
1396 u32 i;
1397
1398 read_lock_bh(&tipc_net_lock);
1399 n_ptr = tipc_node_find((u32)addr);
1400 if (!n_ptr) {
1401 read_unlock_bh(&tipc_net_lock);
1402 return; /* node no longer exists */
1403 }
1404
1405 tipc_node_lock(n_ptr);
1406
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001407 warn("Resetting all links to %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001408 tipc_addr_string_fill(addr_string, n_ptr->addr));
Allan Stephensd356eeb2006-06-25 23:40:01 -07001409
1410 for (i = 0; i < MAX_BEARERS; i++) {
1411 if (n_ptr->links[i]) {
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001412 link_print(n_ptr->links[i], "Resetting link\n");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001413 tipc_link_reset(n_ptr->links[i]);
1414 }
1415 }
1416
1417 tipc_node_unlock(n_ptr);
1418 read_unlock_bh(&tipc_net_lock);
1419}
1420
1421static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf)
1422{
1423 struct tipc_msg *msg = buf_msg(buf);
1424
1425 warn("Retransmission failure on link <%s>\n", l_ptr->name);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001426
1427 if (l_ptr->addr) {
1428
1429 /* Handle failure on standard link */
1430
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001431 link_print(l_ptr, "Resetting link\n");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001432 tipc_link_reset(l_ptr);
1433
1434 } else {
1435
1436 /* Handle failure on broadcast link */
1437
David S. Miller6c000552008-09-02 23:38:32 -07001438 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001439 char addr_string[16];
1440
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001441 info("Msg seq number: %u, ", msg_seqno(msg));
1442 info("Outstanding acks: %lu\n",
1443 (unsigned long) TIPC_SKB_CB(buf)->handle);
Jeff Garzik617dbea2006-10-03 16:25:34 -07001444
Allan Stephensd356eeb2006-06-25 23:40:01 -07001445 n_ptr = l_ptr->owner->next;
1446 tipc_node_lock(n_ptr);
1447
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001448 tipc_addr_string_fill(addr_string, n_ptr->addr);
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001449 info("Multicast link info for %s\n", addr_string);
1450 info("Supported: %d, ", n_ptr->bclink.supported);
1451 info("Acked: %u\n", n_ptr->bclink.acked);
1452 info("Last in: %u, ", n_ptr->bclink.last_in);
1453 info("Gap after: %u, ", n_ptr->bclink.gap_after);
1454 info("Gap to: %u\n", n_ptr->bclink.gap_to);
1455 info("Nack sync: %u\n\n", n_ptr->bclink.nack_sync);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001456
1457 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
1458
1459 tipc_node_unlock(n_ptr);
1460
1461 l_ptr->stale_count = 0;
1462 }
1463}
1464
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001465void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf,
Per Liden4323add2006-01-18 00:38:21 +01001466 u32 retransmits)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001467{
1468 struct tipc_msg *msg;
1469
Allan Stephensd356eeb2006-06-25 23:40:01 -07001470 if (!buf)
1471 return;
1472
1473 msg = buf_msg(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001474
Allan Stephensd356eeb2006-06-25 23:40:01 -07001475 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Neil Hormanca509102010-03-15 07:58:45 +00001476 if (l_ptr->retransm_queue_size == 0) {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001477 l_ptr->retransm_queue_head = msg_seqno(msg);
1478 l_ptr->retransm_queue_size = retransmits;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001479 } else {
Neil Hormanca509102010-03-15 07:58:45 +00001480 err("Unexpected retransmit on link %s (qsize=%d)\n",
1481 l_ptr->name, l_ptr->retransm_queue_size);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001482 }
Neil Hormanca509102010-03-15 07:58:45 +00001483 return;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001484 } else {
1485 /* Detect repeated retransmit failures on uncongested bearer */
1486
1487 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1488 if (++l_ptr->stale_count > 100) {
1489 link_retransmit_failure(l_ptr, buf);
1490 return;
1491 }
1492 } else {
1493 l_ptr->last_retransmitted = msg_seqno(msg);
1494 l_ptr->stale_count = 1;
1495 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001496 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001497
Neil Hormanca509102010-03-15 07:58:45 +00001498 while (retransmits && (buf != l_ptr->next_out) && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001499 msg = buf_msg(buf);
1500 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001501 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001502 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001503 buf = buf->next;
1504 retransmits--;
1505 l_ptr->stats.retransmitted++;
1506 } else {
Per Liden4323add2006-01-18 00:38:21 +01001507 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001508 l_ptr->stats.bearer_congs++;
1509 l_ptr->retransm_queue_head = msg_seqno(buf_msg(buf));
1510 l_ptr->retransm_queue_size = retransmits;
1511 return;
1512 }
1513 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001514
Per Lidenb97bf3f2006-01-02 19:04:38 +01001515 l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
1516}
1517
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001518/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01001519 * link_insert_deferred_queue - insert deferred messages back into receive chain
1520 */
1521
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001522static struct sk_buff *link_insert_deferred_queue(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001523 struct sk_buff *buf)
1524{
1525 u32 seq_no;
1526
1527 if (l_ptr->oldest_deferred_in == NULL)
1528 return buf;
1529
1530 seq_no = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
1531 if (seq_no == mod(l_ptr->next_in_no)) {
1532 l_ptr->newest_deferred_in->next = buf;
1533 buf = l_ptr->oldest_deferred_in;
1534 l_ptr->oldest_deferred_in = NULL;
1535 l_ptr->deferred_inqueue_sz = 0;
1536 }
1537 return buf;
1538}
1539
Allan Stephens85035562008-04-15 19:04:54 -07001540/**
1541 * link_recv_buf_validate - validate basic format of received message
1542 *
1543 * This routine ensures a TIPC message has an acceptable header, and at least
1544 * as much data as the header indicates it should. The routine also ensures
1545 * that the entire message header is stored in the main fragment of the message
1546 * buffer, to simplify future access to message header fields.
1547 *
1548 * Note: Having extra info present in the message header or data areas is OK.
1549 * TIPC will ignore the excess, under the assumption that it is optional info
1550 * introduced by a later release of the protocol.
1551 */
1552
1553static int link_recv_buf_validate(struct sk_buff *buf)
1554{
1555 static u32 min_data_hdr_size[8] = {
1556 SHORT_H_SIZE, MCAST_H_SIZE, LONG_H_SIZE, DIR_MSG_H_SIZE,
1557 MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
1558 };
1559
1560 struct tipc_msg *msg;
1561 u32 tipc_hdr[2];
1562 u32 size;
1563 u32 hdr_size;
1564 u32 min_hdr_size;
1565
1566 if (unlikely(buf->len < MIN_H_SIZE))
1567 return 0;
1568
1569 msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
1570 if (msg == NULL)
1571 return 0;
1572
1573 if (unlikely(msg_version(msg) != TIPC_VERSION))
1574 return 0;
1575
1576 size = msg_size(msg);
1577 hdr_size = msg_hdr_sz(msg);
1578 min_hdr_size = msg_isdata(msg) ?
1579 min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
1580
1581 if (unlikely((hdr_size < min_hdr_size) ||
1582 (size < hdr_size) ||
1583 (buf->len < size) ||
1584 (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
1585 return 0;
1586
1587 return pskb_may_pull(buf, hdr_size);
1588}
1589
Allan Stephensb02b69c2010-08-17 11:00:07 +00001590/**
1591 * tipc_recv_msg - process TIPC messages arriving from off-node
1592 * @head: pointer to message buffer chain
1593 * @tb_ptr: pointer to bearer message arrived on
1594 *
1595 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1596 * structure (i.e. cannot be NULL), but bearer can be inactive.
1597 */
1598
Per Lidenb97bf3f2006-01-02 19:04:38 +01001599void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *tb_ptr)
1600{
Per Liden4323add2006-01-18 00:38:21 +01001601 read_lock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001602 while (head) {
Allan Stephens1265a022008-06-04 17:32:35 -07001603 struct bearer *b_ptr = (struct bearer *)tb_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001604 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001605 struct link *l_ptr;
1606 struct sk_buff *crs;
1607 struct sk_buff *buf = head;
Allan Stephens85035562008-04-15 19:04:54 -07001608 struct tipc_msg *msg;
1609 u32 seq_no;
1610 u32 ackd;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001611 u32 released = 0;
1612 int type;
1613
Per Lidenb97bf3f2006-01-02 19:04:38 +01001614 head = head->next;
Allan Stephens85035562008-04-15 19:04:54 -07001615
Allan Stephensb02b69c2010-08-17 11:00:07 +00001616 /* Ensure bearer is still enabled */
1617
1618 if (unlikely(!b_ptr->active))
1619 goto cont;
1620
Allan Stephens85035562008-04-15 19:04:54 -07001621 /* Ensure message is well-formed */
1622
1623 if (unlikely(!link_recv_buf_validate(buf)))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001624 goto cont;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001625
Allan Stephensfe13dda2008-04-15 19:03:23 -07001626 /* Ensure message data is a single contiguous unit */
1627
1628 if (unlikely(buf_linearize(buf))) {
1629 goto cont;
1630 }
1631
Allan Stephens85035562008-04-15 19:04:54 -07001632 /* Handle arrival of a non-unicast link message */
1633
1634 msg = buf_msg(buf);
1635
Per Lidenb97bf3f2006-01-02 19:04:38 +01001636 if (unlikely(msg_non_seq(msg))) {
Allan Stephens1265a022008-06-04 17:32:35 -07001637 if (msg_user(msg) == LINK_CONFIG)
1638 tipc_disc_recv_msg(buf, b_ptr);
1639 else
1640 tipc_bclink_recv_pkt(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001641 continue;
1642 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001643
Allan Stephens26008242006-06-25 23:39:31 -07001644 if (unlikely(!msg_short(msg) &&
1645 (msg_destnode(msg) != tipc_own_addr)))
1646 goto cont;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001647
Neil Hormande586572010-03-08 12:43:56 -08001648 /* Discard non-routeable messages destined for another node */
1649
1650 if (unlikely(!msg_isdata(msg) &&
1651 (msg_destnode(msg) != tipc_own_addr))) {
1652 if ((msg_user(msg) != CONN_MANAGER) &&
1653 (msg_user(msg) != MSG_FRAGMENTER))
1654 goto cont;
1655 }
1656
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001657 /* Locate neighboring node that sent message */
Allan Stephens85035562008-04-15 19:04:54 -07001658
Per Liden4323add2006-01-18 00:38:21 +01001659 n_ptr = tipc_node_find(msg_prevnode(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001660 if (unlikely(!n_ptr))
1661 goto cont;
Per Liden4323add2006-01-18 00:38:21 +01001662 tipc_node_lock(n_ptr);
Allan Stephens85035562008-04-15 19:04:54 -07001663
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001664 /* Don't talk to neighbor during cleanup after last session */
1665
1666 if (n_ptr->cleanup_required) {
1667 tipc_node_unlock(n_ptr);
1668 goto cont;
1669 }
1670
1671 /* Locate unicast link endpoint that should handle message */
1672
Per Lidenb97bf3f2006-01-02 19:04:38 +01001673 l_ptr = n_ptr->links[b_ptr->identity];
1674 if (unlikely(!l_ptr)) {
Per Liden4323add2006-01-18 00:38:21 +01001675 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001676 goto cont;
1677 }
Allan Stephens85035562008-04-15 19:04:54 -07001678
1679 /* Validate message sequence number info */
1680
1681 seq_no = msg_seqno(msg);
1682 ackd = msg_ack(msg);
1683
1684 /* Release acked messages */
1685
Per Lidenb97bf3f2006-01-02 19:04:38 +01001686 if (less(n_ptr->bclink.acked, msg_bcast_ack(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001687 if (tipc_node_is_up(n_ptr) && n_ptr->bclink.supported)
1688 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001689 }
1690
1691 crs = l_ptr->first_out;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001692 while ((crs != l_ptr->next_out) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001693 less_eq(msg_seqno(buf_msg(crs)), ackd)) {
1694 struct sk_buff *next = crs->next;
1695
1696 buf_discard(crs);
1697 crs = next;
1698 released++;
1699 }
1700 if (released) {
1701 l_ptr->first_out = crs;
1702 l_ptr->out_queue_size -= released;
1703 }
Allan Stephens85035562008-04-15 19:04:54 -07001704
1705 /* Try sending any messages link endpoint has pending */
1706
Per Lidenb97bf3f2006-01-02 19:04:38 +01001707 if (unlikely(l_ptr->next_out))
Per Liden4323add2006-01-18 00:38:21 +01001708 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001709 if (unlikely(!list_empty(&l_ptr->waiting_ports)))
Per Liden4323add2006-01-18 00:38:21 +01001710 tipc_link_wakeup_ports(l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001711 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1712 l_ptr->stats.sent_acks++;
Per Liden4323add2006-01-18 00:38:21 +01001713 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001714 }
1715
Allan Stephens85035562008-04-15 19:04:54 -07001716 /* Now (finally!) process the incoming message */
1717
Per Lidenb97bf3f2006-01-02 19:04:38 +01001718protocol_check:
1719 if (likely(link_working_working(l_ptr))) {
1720 if (likely(seq_no == mod(l_ptr->next_in_no))) {
1721 l_ptr->next_in_no++;
1722 if (unlikely(l_ptr->oldest_deferred_in))
1723 head = link_insert_deferred_queue(l_ptr,
1724 head);
1725 if (likely(msg_is_dest(msg, tipc_own_addr))) {
1726deliver:
1727 if (likely(msg_isdata(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001728 tipc_node_unlock(n_ptr);
1729 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001730 continue;
1731 }
1732 switch (msg_user(msg)) {
1733 case MSG_BUNDLER:
1734 l_ptr->stats.recv_bundles++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001735 l_ptr->stats.recv_bundled +=
Per Lidenb97bf3f2006-01-02 19:04:38 +01001736 msg_msgcnt(msg);
Per Liden4323add2006-01-18 00:38:21 +01001737 tipc_node_unlock(n_ptr);
1738 tipc_link_recv_bundle(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001739 continue;
1740 case ROUTE_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001741 tipc_node_unlock(n_ptr);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001742 buf_discard(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001743 continue;
1744 case NAME_DISTRIBUTOR:
Per Liden4323add2006-01-18 00:38:21 +01001745 tipc_node_unlock(n_ptr);
1746 tipc_named_recv(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001747 continue;
1748 case CONN_MANAGER:
Per Liden4323add2006-01-18 00:38:21 +01001749 tipc_node_unlock(n_ptr);
1750 tipc_port_recv_proto_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001751 continue;
1752 case MSG_FRAGMENTER:
1753 l_ptr->stats.recv_fragments++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001754 if (tipc_link_recv_fragment(&l_ptr->defragm_buf,
Per Liden4323add2006-01-18 00:38:21 +01001755 &buf, &msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001756 l_ptr->stats.recv_fragmented++;
1757 goto deliver;
1758 }
1759 break;
1760 case CHANGEOVER_PROTOCOL:
1761 type = msg_type(msg);
Per Liden4323add2006-01-18 00:38:21 +01001762 if (link_recv_changeover_msg(&l_ptr, &buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001763 msg = buf_msg(buf);
1764 seq_no = msg_seqno(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001765 if (type == ORIGINAL_MSG)
1766 goto deliver;
1767 goto protocol_check;
1768 }
1769 break;
1770 }
1771 }
Per Liden4323add2006-01-18 00:38:21 +01001772 tipc_node_unlock(n_ptr);
1773 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001774 continue;
1775 }
1776 link_handle_out_of_seq_msg(l_ptr, buf);
1777 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01001778 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001779 continue;
1780 }
1781
1782 if (msg_user(msg) == LINK_PROTOCOL) {
1783 link_recv_proto_msg(l_ptr, buf);
1784 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01001785 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001786 continue;
1787 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001788 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1789
1790 if (link_working_working(l_ptr)) {
1791 /* Re-insert in front of queue */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001792 buf->next = head;
1793 head = buf;
Per Liden4323add2006-01-18 00:38:21 +01001794 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001795 continue;
1796 }
Per Liden4323add2006-01-18 00:38:21 +01001797 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001798cont:
1799 buf_discard(buf);
1800 }
Per Liden4323add2006-01-18 00:38:21 +01001801 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001802}
1803
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001804/*
1805 * link_defer_buf(): Sort a received out-of-sequence packet
Per Lidenb97bf3f2006-01-02 19:04:38 +01001806 * into the deferred reception queue.
1807 * Returns the increase of the queue length,i.e. 0 or 1
1808 */
1809
Per Liden4323add2006-01-18 00:38:21 +01001810u32 tipc_link_defer_pkt(struct sk_buff **head,
1811 struct sk_buff **tail,
1812 struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001813{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001814 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001815 struct sk_buff *crs = *head;
1816 u32 seq_no = msg_seqno(buf_msg(buf));
1817
1818 buf->next = NULL;
1819
1820 /* Empty queue ? */
1821 if (*head == NULL) {
1822 *head = *tail = buf;
1823 return 1;
1824 }
1825
1826 /* Last ? */
1827 if (less(msg_seqno(buf_msg(*tail)), seq_no)) {
1828 (*tail)->next = buf;
1829 *tail = buf;
1830 return 1;
1831 }
1832
1833 /* Scan through queue and sort it in */
1834 do {
1835 struct tipc_msg *msg = buf_msg(crs);
1836
1837 if (less(seq_no, msg_seqno(msg))) {
1838 buf->next = crs;
1839 if (prev)
1840 prev->next = buf;
1841 else
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001842 *head = buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001843 return 1;
1844 }
1845 if (seq_no == msg_seqno(msg)) {
1846 break;
1847 }
1848 prev = crs;
1849 crs = crs->next;
1850 }
1851 while (crs);
1852
1853 /* Message is a duplicate of an existing message */
1854
1855 buf_discard(buf);
1856 return 0;
1857}
1858
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001859/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01001860 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
1861 */
1862
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001863static void link_handle_out_of_seq_msg(struct link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001864 struct sk_buff *buf)
1865{
1866 u32 seq_no = msg_seqno(buf_msg(buf));
1867
1868 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
1869 link_recv_proto_msg(l_ptr, buf);
1870 return;
1871 }
1872
Per Lidenb97bf3f2006-01-02 19:04:38 +01001873 /* Record OOS packet arrival (force mismatch on next timeout) */
1874
1875 l_ptr->checkpoint--;
1876
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001877 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001878 * Discard packet if a duplicate; otherwise add it to deferred queue
1879 * and notify peer of gap as per protocol specification
1880 */
1881
1882 if (less(seq_no, mod(l_ptr->next_in_no))) {
1883 l_ptr->stats.duplicates++;
1884 buf_discard(buf);
1885 return;
1886 }
1887
Per Liden4323add2006-01-18 00:38:21 +01001888 if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
1889 &l_ptr->newest_deferred_in, buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001890 l_ptr->deferred_inqueue_sz++;
1891 l_ptr->stats.deferred_recv++;
1892 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
Per Liden4323add2006-01-18 00:38:21 +01001893 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001894 } else
1895 l_ptr->stats.duplicates++;
1896}
1897
1898/*
1899 * Send protocol message to the other endpoint.
1900 */
Per Liden4323add2006-01-18 00:38:21 +01001901void tipc_link_send_proto_msg(struct link *l_ptr, u32 msg_typ, int probe_msg,
1902 u32 gap, u32 tolerance, u32 priority, u32 ack_mtu)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001903{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001904 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001905 struct tipc_msg *msg = l_ptr->pmsg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001906 u32 msg_size = sizeof(l_ptr->proto_msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001907
1908 if (link_blocked(l_ptr))
1909 return;
1910 msg_set_type(msg, msg_typ);
1911 msg_set_net_plane(msg, l_ptr->b_ptr->net_plane);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001912 msg_set_bcast_ack(msg, mod(l_ptr->owner->bclink.last_in));
Per Liden4323add2006-01-18 00:38:21 +01001913 msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
Per Lidenb97bf3f2006-01-02 19:04:38 +01001914
1915 if (msg_typ == STATE_MSG) {
1916 u32 next_sent = mod(l_ptr->next_out_no);
1917
Per Liden4323add2006-01-18 00:38:21 +01001918 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001919 return;
1920 if (l_ptr->next_out)
1921 next_sent = msg_seqno(buf_msg(l_ptr->next_out));
1922 msg_set_next_sent(msg, next_sent);
1923 if (l_ptr->oldest_deferred_in) {
1924 u32 rec = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
1925 gap = mod(rec - mod(l_ptr->next_in_no));
1926 }
1927 msg_set_seq_gap(msg, gap);
1928 if (gap)
1929 l_ptr->stats.sent_nacks++;
1930 msg_set_link_tolerance(msg, tolerance);
1931 msg_set_linkprio(msg, priority);
1932 msg_set_max_pkt(msg, ack_mtu);
1933 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1934 msg_set_probe(msg, probe_msg != 0);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001935 if (probe_msg) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001936 u32 mtu = l_ptr->max_pkt;
1937
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001938 if ((mtu < l_ptr->max_pkt_target) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001939 link_working_working(l_ptr) &&
1940 l_ptr->fsm_msg_cnt) {
1941 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001942 if (l_ptr->max_pkt_probes == 10) {
1943 l_ptr->max_pkt_target = (msg_size - 4);
1944 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001945 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001946 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001947 l_ptr->max_pkt_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001948 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001949
1950 l_ptr->stats.sent_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001951 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001952 l_ptr->stats.sent_states++;
1953 } else { /* RESET_MSG or ACTIVATE_MSG */
1954 msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
1955 msg_set_seq_gap(msg, 0);
1956 msg_set_next_sent(msg, 1);
1957 msg_set_link_tolerance(msg, l_ptr->tolerance);
1958 msg_set_linkprio(msg, l_ptr->priority);
1959 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
1960 }
1961
Per Liden4323add2006-01-18 00:38:21 +01001962 if (tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001963 msg_set_redundant_link(msg);
1964 } else {
1965 msg_clear_redundant_link(msg);
1966 }
1967 msg_set_linkprio(msg, l_ptr->priority);
1968
1969 /* Ensure sequence number will not fit : */
1970
1971 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
1972
1973 /* Congestion? */
1974
Per Liden4323add2006-01-18 00:38:21 +01001975 if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001976 if (!l_ptr->proto_msg_queue) {
1977 l_ptr->proto_msg_queue =
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001978 tipc_buf_acquire(sizeof(l_ptr->proto_msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001979 }
1980 buf = l_ptr->proto_msg_queue;
1981 if (!buf)
1982 return;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001983 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001984 return;
1985 }
1986 msg_set_timestamp(msg, jiffies_to_msecs(jiffies));
1987
1988 /* Message can be sent */
1989
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001990 buf = tipc_buf_acquire(msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001991 if (!buf)
1992 return;
1993
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001994 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001995 msg_set_size(buf_msg(buf), msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001996
Per Liden4323add2006-01-18 00:38:21 +01001997 if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001998 l_ptr->unacked_window = 0;
1999 buf_discard(buf);
2000 return;
2001 }
2002
2003 /* New congestion */
Per Liden4323add2006-01-18 00:38:21 +01002004 tipc_bearer_schedule(l_ptr->b_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002005 l_ptr->proto_msg_queue = buf;
2006 l_ptr->stats.bearer_congs++;
2007}
2008
2009/*
2010 * Receive protocol message :
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002011 * Note that network plane id propagates through the network, and may
2012 * change at any time. The node with lowest address rules
Per Lidenb97bf3f2006-01-02 19:04:38 +01002013 */
2014
2015static void link_recv_proto_msg(struct link *l_ptr, struct sk_buff *buf)
2016{
2017 u32 rec_gap = 0;
2018 u32 max_pkt_info;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002019 u32 max_pkt_ack;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002020 u32 msg_tol;
2021 struct tipc_msg *msg = buf_msg(buf);
2022
Per Lidenb97bf3f2006-01-02 19:04:38 +01002023 if (link_blocked(l_ptr))
2024 goto exit;
2025
2026 /* record unnumbered packet arrival (force mismatch on next timeout) */
2027
2028 l_ptr->checkpoint--;
2029
2030 if (l_ptr->b_ptr->net_plane != msg_net_plane(msg))
2031 if (tipc_own_addr > msg_prevnode(msg))
2032 l_ptr->b_ptr->net_plane = msg_net_plane(msg);
2033
2034 l_ptr->owner->permit_changeover = msg_redundant_link(msg);
2035
2036 switch (msg_type(msg)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002037
Per Lidenb97bf3f2006-01-02 19:04:38 +01002038 case RESET_MSG:
Allan Stephensa686e682008-06-04 17:29:39 -07002039 if (!link_working_unknown(l_ptr) &&
2040 (l_ptr->peer_session != INVALID_SESSION)) {
Allan Stephensb29f1422010-12-31 18:59:25 +00002041 if (msg_session(msg) == l_ptr->peer_session)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002042 break; /* duplicate: ignore */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002043 }
2044 /* fall thru' */
2045 case ACTIVATE_MSG:
2046 /* Update link settings according other endpoint's values */
2047
2048 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
2049
2050 if ((msg_tol = msg_link_tolerance(msg)) &&
2051 (msg_tol > l_ptr->tolerance))
2052 link_set_supervision_props(l_ptr, msg_tol);
2053
2054 if (msg_linkprio(msg) > l_ptr->priority)
2055 l_ptr->priority = msg_linkprio(msg);
2056
2057 max_pkt_info = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002058 if (max_pkt_info) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002059 if (max_pkt_info < l_ptr->max_pkt_target)
2060 l_ptr->max_pkt_target = max_pkt_info;
2061 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
2062 l_ptr->max_pkt = l_ptr->max_pkt_target;
2063 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002064 l_ptr->max_pkt = l_ptr->max_pkt_target;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002065 }
2066 l_ptr->owner->bclink.supported = (max_pkt_info != 0);
2067
2068 link_state_event(l_ptr, msg_type(msg));
2069
2070 l_ptr->peer_session = msg_session(msg);
2071 l_ptr->peer_bearer_id = msg_bearer_id(msg);
2072
2073 /* Synchronize broadcast sequence numbers */
Per Liden4323add2006-01-18 00:38:21 +01002074 if (!tipc_node_has_redundant_links(l_ptr->owner)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002075 l_ptr->owner->bclink.last_in = mod(msg_last_bcast(msg));
2076 }
2077 break;
2078 case STATE_MSG:
2079
2080 if ((msg_tol = msg_link_tolerance(msg)))
2081 link_set_supervision_props(l_ptr, msg_tol);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002082
2083 if (msg_linkprio(msg) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002084 (msg_linkprio(msg) != l_ptr->priority)) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002085 warn("Resetting link <%s>, priority change %u->%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002086 l_ptr->name, l_ptr->priority, msg_linkprio(msg));
2087 l_ptr->priority = msg_linkprio(msg);
Per Liden4323add2006-01-18 00:38:21 +01002088 tipc_link_reset(l_ptr); /* Enforce change to take effect */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002089 break;
2090 }
2091 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
2092 l_ptr->stats.recv_states++;
2093 if (link_reset_unknown(l_ptr))
2094 break;
2095
2096 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002097 rec_gap = mod(msg_next_sent(msg) -
Per Lidenb97bf3f2006-01-02 19:04:38 +01002098 mod(l_ptr->next_in_no));
2099 }
2100
2101 max_pkt_ack = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002102 if (max_pkt_ack > l_ptr->max_pkt) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002103 l_ptr->max_pkt = max_pkt_ack;
2104 l_ptr->max_pkt_probes = 0;
2105 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002106
2107 max_pkt_ack = 0;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002108 if (msg_probe(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002109 l_ptr->stats.recv_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002110 if (msg_size(msg) > sizeof(l_ptr->proto_msg)) {
2111 max_pkt_ack = msg_size(msg);
2112 }
2113 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002114
2115 /* Protocol message before retransmits, reduce loss risk */
2116
Per Liden4323add2006-01-18 00:38:21 +01002117 tipc_bclink_check_gap(l_ptr->owner, msg_last_bcast(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002118
2119 if (rec_gap || (msg_probe(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01002120 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2121 0, rec_gap, 0, 0, max_pkt_ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002122 }
2123 if (msg_seq_gap(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002124 l_ptr->stats.recv_nacks++;
Per Liden4323add2006-01-18 00:38:21 +01002125 tipc_link_retransmit(l_ptr, l_ptr->first_out,
2126 msg_seq_gap(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002127 }
2128 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002129 }
2130exit:
2131 buf_discard(buf);
2132}
2133
2134
2135/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002136 * tipc_link_tunnel(): Send one message via a link belonging to
Per Lidenb97bf3f2006-01-02 19:04:38 +01002137 * another bearer. Owner node is locked.
2138 */
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002139static void tipc_link_tunnel(struct link *l_ptr,
2140 struct tipc_msg *tunnel_hdr,
2141 struct tipc_msg *msg,
2142 u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002143{
2144 struct link *tunnel;
2145 struct sk_buff *buf;
2146 u32 length = msg_size(msg);
2147
2148 tunnel = l_ptr->owner->active_links[selector & 1];
Allan Stephens5392d642006-06-25 23:52:50 -07002149 if (!tipc_link_is_up(tunnel)) {
2150 warn("Link changeover error, "
2151 "tunnel link no longer available\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002152 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002153 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002154 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002155 buf = tipc_buf_acquire(length + INT_H_SIZE);
Allan Stephens5392d642006-06-25 23:52:50 -07002156 if (!buf) {
2157 warn("Link changeover error, "
2158 "unable to send tunnel msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002159 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002160 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002161 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
2162 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
Per Liden4323add2006-01-18 00:38:21 +01002163 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002164}
2165
2166
2167
2168/*
2169 * changeover(): Send whole message queue via the remaining link
2170 * Owner node is locked.
2171 */
2172
Per Liden4323add2006-01-18 00:38:21 +01002173void tipc_link_changeover(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002174{
2175 u32 msgcount = l_ptr->out_queue_size;
2176 struct sk_buff *crs = l_ptr->first_out;
2177 struct link *tunnel = l_ptr->owner->active_links[0];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002178 struct tipc_msg tunnel_hdr;
Allan Stephens5392d642006-06-25 23:52:50 -07002179 int split_bundles;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002180
2181 if (!tunnel)
2182 return;
2183
Allan Stephens5392d642006-06-25 23:52:50 -07002184 if (!l_ptr->owner->permit_changeover) {
2185 warn("Link changeover error, "
2186 "peer did not permit changeover\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002187 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002188 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002189
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002190 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002191 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002192 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2193 msg_set_msgcnt(&tunnel_hdr, msgcount);
Allan Stephensf1310722006-06-25 23:51:37 -07002194
Per Lidenb97bf3f2006-01-02 19:04:38 +01002195 if (!l_ptr->first_out) {
2196 struct sk_buff *buf;
2197
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002198 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002199 if (buf) {
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002200 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002201 msg_set_size(&tunnel_hdr, INT_H_SIZE);
Per Liden4323add2006-01-18 00:38:21 +01002202 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002203 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002204 warn("Link changeover error, "
2205 "unable to send changeover msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002206 }
2207 return;
2208 }
Allan Stephensf1310722006-06-25 23:51:37 -07002209
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002210 split_bundles = (l_ptr->owner->active_links[0] !=
Allan Stephens5392d642006-06-25 23:52:50 -07002211 l_ptr->owner->active_links[1]);
2212
Per Lidenb97bf3f2006-01-02 19:04:38 +01002213 while (crs) {
2214 struct tipc_msg *msg = buf_msg(crs);
2215
2216 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002217 struct tipc_msg *m = msg_get_wrapped(msg);
2218 unchar* pos = (unchar*)m;
2219
Florian Westphald788d802007-08-02 19:28:06 -07002220 msgcount = msg_msgcnt(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002221 while (msgcount--) {
2222 msg_set_seqno(m,msg_seqno(msg));
Per Liden4323add2006-01-18 00:38:21 +01002223 tipc_link_tunnel(l_ptr, &tunnel_hdr, m,
2224 msg_link_selector(m));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002225 pos += align(msg_size(m));
2226 m = (struct tipc_msg *)pos;
2227 }
2228 } else {
Per Liden4323add2006-01-18 00:38:21 +01002229 tipc_link_tunnel(l_ptr, &tunnel_hdr, msg,
2230 msg_link_selector(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002231 }
2232 crs = crs->next;
2233 }
2234}
2235
Per Liden4323add2006-01-18 00:38:21 +01002236void tipc_link_send_duplicate(struct link *l_ptr, struct link *tunnel)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002237{
2238 struct sk_buff *iter;
2239 struct tipc_msg tunnel_hdr;
2240
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002241 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002242 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002243 msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
2244 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2245 iter = l_ptr->first_out;
2246 while (iter) {
2247 struct sk_buff *outbuf;
2248 struct tipc_msg *msg = buf_msg(iter);
2249 u32 length = msg_size(msg);
2250
2251 if (msg_user(msg) == MSG_BUNDLER)
2252 msg_set_type(msg, CLOSED_MSG);
2253 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002254 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002255 msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002256 outbuf = tipc_buf_acquire(length + INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002257 if (outbuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002258 warn("Link changeover error, "
2259 "unable to send duplicate msg\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002260 return;
2261 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002262 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2263 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
2264 length);
Per Liden4323add2006-01-18 00:38:21 +01002265 tipc_link_send_buf(tunnel, outbuf);
2266 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002267 return;
2268 iter = iter->next;
2269 }
2270}
2271
2272
2273
2274/**
2275 * buf_extract - extracts embedded TIPC message from another message
2276 * @skb: encapsulating message buffer
2277 * @from_pos: offset to extract from
2278 *
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002279 * Returns a new message buffer containing an embedded message. The
Per Lidenb97bf3f2006-01-02 19:04:38 +01002280 * encapsulating message itself is left unchanged.
2281 */
2282
2283static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
2284{
2285 struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
2286 u32 size = msg_size(msg);
2287 struct sk_buff *eb;
2288
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002289 eb = tipc_buf_acquire(size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002290 if (eb)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002291 skb_copy_to_linear_data(eb, msg, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002292 return eb;
2293}
2294
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002295/*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002296 * link_recv_changeover_msg(): Receive tunneled packet sent
2297 * via other link. Node is locked. Return extracted buffer.
2298 */
2299
2300static int link_recv_changeover_msg(struct link **l_ptr,
2301 struct sk_buff **buf)
2302{
2303 struct sk_buff *tunnel_buf = *buf;
2304 struct link *dest_link;
2305 struct tipc_msg *msg;
2306 struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf);
2307 u32 msg_typ = msg_type(tunnel_msg);
2308 u32 msg_count = msg_msgcnt(tunnel_msg);
2309
2310 dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)];
Allan Stephensb29f1422010-12-31 18:59:25 +00002311 if (!dest_link)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002312 goto exit;
Allan Stephensf1310722006-06-25 23:51:37 -07002313 if (dest_link == *l_ptr) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002314 err("Unexpected changeover message on link <%s>\n",
Allan Stephensf1310722006-06-25 23:51:37 -07002315 (*l_ptr)->name);
2316 goto exit;
2317 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002318 *l_ptr = dest_link;
2319 msg = msg_get_wrapped(tunnel_msg);
2320
2321 if (msg_typ == DUPLICATE_MSG) {
Allan Stephensb29f1422010-12-31 18:59:25 +00002322 if (less(msg_seqno(msg), mod(dest_link->next_in_no)))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002323 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002324 *buf = buf_extract(tunnel_buf,INT_H_SIZE);
2325 if (*buf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002326 warn("Link changeover error, duplicate msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002327 goto exit;
2328 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002329 buf_discard(tunnel_buf);
2330 return 1;
2331 }
2332
2333 /* First original message ?: */
2334
Per Liden4323add2006-01-18 00:38:21 +01002335 if (tipc_link_is_up(dest_link)) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002336 info("Resetting link <%s>, changeover initiated by peer\n",
2337 dest_link->name);
Per Liden4323add2006-01-18 00:38:21 +01002338 tipc_link_reset(dest_link);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002339 dest_link->exp_msg_count = msg_count;
2340 if (!msg_count)
2341 goto exit;
2342 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002343 dest_link->exp_msg_count = msg_count;
2344 if (!msg_count)
2345 goto exit;
2346 }
2347
2348 /* Receive original message */
2349
2350 if (dest_link->exp_msg_count == 0) {
Allan Stephens5392d642006-06-25 23:52:50 -07002351 warn("Link switchover error, "
2352 "got too many tunnelled messages\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002353 goto exit;
2354 }
2355 dest_link->exp_msg_count--;
2356 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002357 goto exit;
2358 } else {
2359 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2360 if (*buf != NULL) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002361 buf_discard(tunnel_buf);
2362 return 1;
2363 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002364 warn("Link changeover error, original msg dropped\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002365 }
2366 }
2367exit:
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002368 *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002369 buf_discard(tunnel_buf);
2370 return 0;
2371}
2372
2373/*
2374 * Bundler functionality:
2375 */
Per Liden4323add2006-01-18 00:38:21 +01002376void tipc_link_recv_bundle(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002377{
2378 u32 msgcount = msg_msgcnt(buf_msg(buf));
2379 u32 pos = INT_H_SIZE;
2380 struct sk_buff *obuf;
2381
Per Lidenb97bf3f2006-01-02 19:04:38 +01002382 while (msgcount--) {
2383 obuf = buf_extract(buf, pos);
2384 if (obuf == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002385 warn("Link unable to unbundle message(s)\n");
2386 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07002387 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002388 pos += align(msg_size(buf_msg(obuf)));
Per Liden4323add2006-01-18 00:38:21 +01002389 tipc_net_route_msg(obuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002390 }
2391 buf_discard(buf);
2392}
2393
2394/*
2395 * Fragmentation/defragmentation:
2396 */
2397
2398
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002399/*
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002400 * link_send_long_buf: Entry for buffers needing fragmentation.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002401 * The buffer is complete, inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01002402 * Returns user data length.
2403 */
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002404static int link_send_long_buf(struct link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002405{
2406 struct tipc_msg *inmsg = buf_msg(buf);
2407 struct tipc_msg fragm_hdr;
2408 u32 insize = msg_size(inmsg);
2409 u32 dsz = msg_data_sz(inmsg);
2410 unchar *crs = buf->data;
2411 u32 rest = insize;
Allan Stephens15e979d2010-05-11 14:30:10 +00002412 u32 pack_sz = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002413 u32 fragm_sz = pack_sz - INT_H_SIZE;
2414 u32 fragm_no = 1;
Allan Stephens9c396a72008-06-04 17:36:58 -07002415 u32 destaddr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002416
2417 if (msg_short(inmsg))
2418 destaddr = l_ptr->addr;
Allan Stephens9c396a72008-06-04 17:36:58 -07002419 else
2420 destaddr = msg_destnode(inmsg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002421
2422 if (msg_routed(inmsg))
2423 msg_set_prevnode(inmsg, tipc_own_addr);
2424
2425 /* Prepare reusable fragment header: */
2426
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002427 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07002428 INT_H_SIZE, destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002429 msg_set_link_selector(&fragm_hdr, msg_link_selector(inmsg));
2430 msg_set_long_msgno(&fragm_hdr, mod(l_ptr->long_msg_seq_no++));
2431 msg_set_fragm_no(&fragm_hdr, fragm_no);
2432 l_ptr->stats.sent_fragmented++;
2433
2434 /* Chop up message: */
2435
2436 while (rest > 0) {
2437 struct sk_buff *fragm;
2438
2439 if (rest <= fragm_sz) {
2440 fragm_sz = rest;
2441 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
2442 }
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002443 fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002444 if (fragm == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -07002445 warn("Link unable to fragment message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002446 dsz = -ENOMEM;
2447 goto exit;
2448 }
2449 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002450 skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE);
2451 skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs,
2452 fragm_sz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002453 /* Send queued messages first, if any: */
2454
2455 l_ptr->stats.sent_fragments++;
Per Liden4323add2006-01-18 00:38:21 +01002456 tipc_link_send_buf(l_ptr, fragm);
2457 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002458 return dsz;
2459 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
2460 rest -= fragm_sz;
2461 crs += fragm_sz;
2462 msg_set_type(&fragm_hdr, FRAGMENT);
2463 }
2464exit:
2465 buf_discard(buf);
2466 return dsz;
2467}
2468
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002469/*
2470 * A pending message being re-assembled must store certain values
2471 * to handle subsequent fragments correctly. The following functions
Per Lidenb97bf3f2006-01-02 19:04:38 +01002472 * help storing these values in unused, available fields in the
2473 * pending message. This makes dynamic memory allocation unecessary.
2474 */
2475
Sam Ravnborg05790c62006-03-20 22:37:04 -08002476static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002477{
2478 msg_set_seqno(buf_msg(buf), seqno);
2479}
2480
Sam Ravnborg05790c62006-03-20 22:37:04 -08002481static u32 get_fragm_size(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002482{
2483 return msg_ack(buf_msg(buf));
2484}
2485
Sam Ravnborg05790c62006-03-20 22:37:04 -08002486static void set_fragm_size(struct sk_buff *buf, u32 sz)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002487{
2488 msg_set_ack(buf_msg(buf), sz);
2489}
2490
Sam Ravnborg05790c62006-03-20 22:37:04 -08002491static u32 get_expected_frags(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002492{
2493 return msg_bcast_ack(buf_msg(buf));
2494}
2495
Sam Ravnborg05790c62006-03-20 22:37:04 -08002496static void set_expected_frags(struct sk_buff *buf, u32 exp)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002497{
2498 msg_set_bcast_ack(buf_msg(buf), exp);
2499}
2500
Sam Ravnborg05790c62006-03-20 22:37:04 -08002501static u32 get_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002502{
2503 return msg_reroute_cnt(buf_msg(buf));
2504}
2505
Sam Ravnborg05790c62006-03-20 22:37:04 -08002506static void incr_timer_cnt(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002507{
2508 msg_incr_reroute_cnt(buf_msg(buf));
2509}
2510
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002511/*
2512 * tipc_link_recv_fragment(): Called with node lock on. Returns
Per Lidenb97bf3f2006-01-02 19:04:38 +01002513 * the reassembled buffer if message is complete.
2514 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002515int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
Per Liden4323add2006-01-18 00:38:21 +01002516 struct tipc_msg **m)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002517{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002518 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002519 struct sk_buff *fbuf = *fb;
2520 struct tipc_msg *fragm = buf_msg(fbuf);
2521 struct sk_buff *pbuf = *pending;
2522 u32 long_msg_seq_no = msg_long_msgno(fragm);
2523
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002524 *fb = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002525
2526 /* Is there an incomplete message waiting for this fragment? */
2527
Joe Perchesf64f9e72009-11-29 16:55:45 -08002528 while (pbuf && ((msg_seqno(buf_msg(pbuf)) != long_msg_seq_no) ||
2529 (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002530 prev = pbuf;
2531 pbuf = pbuf->next;
2532 }
2533
2534 if (!pbuf && (msg_type(fragm) == FIRST_FRAGMENT)) {
2535 struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
2536 u32 msg_sz = msg_size(imsg);
2537 u32 fragm_sz = msg_data_sz(fragm);
2538 u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
2539 u32 max = TIPC_MAX_USER_MSG_SIZE + LONG_H_SIZE;
2540 if (msg_type(imsg) == TIPC_MCAST_MSG)
2541 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
2542 if (msg_size(imsg) > max) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002543 buf_discard(fbuf);
2544 return 0;
2545 }
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002546 pbuf = tipc_buf_acquire(msg_size(imsg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002547 if (pbuf != NULL) {
2548 pbuf->next = *pending;
2549 *pending = pbuf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002550 skb_copy_to_linear_data(pbuf, imsg,
2551 msg_data_sz(fragm));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002552 /* Prepare buffer for subsequent fragments. */
2553
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002554 set_long_msg_seqno(pbuf, long_msg_seq_no);
2555 set_fragm_size(pbuf,fragm_sz);
2556 set_expected_frags(pbuf,exp_fragm_cnt - 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002557 } else {
Allan Stephensa10bd922006-06-25 23:52:17 -07002558 warn("Link unable to reassemble fragmented message\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002559 }
2560 buf_discard(fbuf);
2561 return 0;
2562 } else if (pbuf && (msg_type(fragm) != FIRST_FRAGMENT)) {
2563 u32 dsz = msg_data_sz(fragm);
2564 u32 fsz = get_fragm_size(pbuf);
2565 u32 crs = ((msg_fragm_no(fragm) - 1) * fsz);
2566 u32 exp_frags = get_expected_frags(pbuf) - 1;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002567 skb_copy_to_linear_data_offset(pbuf, crs,
2568 msg_data(fragm), dsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002569 buf_discard(fbuf);
2570
2571 /* Is message complete? */
2572
2573 if (exp_frags == 0) {
2574 if (prev)
2575 prev->next = pbuf->next;
2576 else
2577 *pending = pbuf->next;
2578 msg_reset_reroute_cnt(buf_msg(pbuf));
2579 *fb = pbuf;
2580 *m = buf_msg(pbuf);
2581 return 1;
2582 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002583 set_expected_frags(pbuf,exp_frags);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002584 return 0;
2585 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002586 buf_discard(fbuf);
2587 return 0;
2588}
2589
2590/**
2591 * link_check_defragm_bufs - flush stale incoming message fragments
2592 * @l_ptr: pointer to link
2593 */
2594
2595static void link_check_defragm_bufs(struct link *l_ptr)
2596{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002597 struct sk_buff *prev = NULL;
2598 struct sk_buff *next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002599 struct sk_buff *buf = l_ptr->defragm_buf;
2600
2601 if (!buf)
2602 return;
2603 if (!link_working_working(l_ptr))
2604 return;
2605 while (buf) {
2606 u32 cnt = get_timer_cnt(buf);
2607
2608 next = buf->next;
2609 if (cnt < 4) {
2610 incr_timer_cnt(buf);
2611 prev = buf;
2612 } else {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002613 if (prev)
2614 prev->next = buf->next;
2615 else
2616 l_ptr->defragm_buf = buf->next;
2617 buf_discard(buf);
2618 }
2619 buf = next;
2620 }
2621}
2622
2623
2624
2625static void link_set_supervision_props(struct link *l_ptr, u32 tolerance)
2626{
2627 l_ptr->tolerance = tolerance;
2628 l_ptr->continuity_interval =
2629 ((tolerance / 4) > 500) ? 500 : tolerance / 4;
2630 l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
2631}
2632
2633
Per Liden4323add2006-01-18 00:38:21 +01002634void tipc_link_set_queue_limits(struct link *l_ptr, u32 window)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002635{
2636 /* Data messages from this node, inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002637 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
2638 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
2639 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
2640 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002641 /* Transiting data messages,inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002642 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
2643 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
2644 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
2645 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002646 l_ptr->queue_limit[CONN_MANAGER] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002647 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
2648 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
2649 /* FRAGMENT and LAST_FRAGMENT packets */
2650 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
2651}
2652
2653/**
2654 * link_find_link - locate link by name
2655 * @name - ptr to link name string
2656 * @node - ptr to area to be filled with ptr to associated node
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002657 *
Per Liden4323add2006-01-18 00:38:21 +01002658 * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002659 * this also prevents link deletion.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002660 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002661 * Returns pointer to link (or 0 if invalid link name).
2662 */
2663
David S. Miller6c000552008-09-02 23:38:32 -07002664static struct link *link_find_link(const char *name, struct tipc_node **node)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002665{
2666 struct link_name link_name_parts;
2667 struct bearer *b_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002668 struct link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002669
2670 if (!link_name_validate(name, &link_name_parts))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002671 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002672
Per Liden4323add2006-01-18 00:38:21 +01002673 b_ptr = tipc_bearer_find_interface(link_name_parts.if_local);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002674 if (!b_ptr)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002675 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002676
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002677 *node = tipc_node_find(link_name_parts.addr_peer);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002678 if (!*node)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002679 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002680
2681 l_ptr = (*node)->links[b_ptr->identity];
2682 if (!l_ptr || strcmp(l_ptr->name, name))
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002683 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002684
2685 return l_ptr;
2686}
2687
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002688struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Per Liden4323add2006-01-18 00:38:21 +01002689 u16 cmd)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002690{
2691 struct tipc_link_config *args;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002692 u32 new_value;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002693 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002694 struct tipc_node *node;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002695 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002696
2697 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +01002698 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002699
2700 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2701 new_value = ntohl(args->value);
2702
Per Liden4323add2006-01-18 00:38:21 +01002703 if (!strcmp(args->name, tipc_bclink_name)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002704 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
Per Liden4323add2006-01-18 00:38:21 +01002705 (tipc_bclink_set_queue_limits(new_value) == 0))
2706 return tipc_cfg_reply_none();
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002707 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Per Liden4323add2006-01-18 00:38:21 +01002708 " (cannot change setting on broadcast link)");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002709 }
2710
Per Liden4323add2006-01-18 00:38:21 +01002711 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002712 l_ptr = link_find_link(args->name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002713 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002714 read_unlock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002715 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002716 }
2717
Per Liden4323add2006-01-18 00:38:21 +01002718 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002719 res = -EINVAL;
2720 switch (cmd) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002721 case TIPC_CMD_SET_LINK_TOL:
2722 if ((new_value >= TIPC_MIN_LINK_TOL) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002723 (new_value <= TIPC_MAX_LINK_TOL)) {
2724 link_set_supervision_props(l_ptr, new_value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002725 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01002726 0, 0, new_value, 0, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07002727 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002728 }
2729 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002730 case TIPC_CMD_SET_LINK_PRI:
Per Liden16cb4b32006-01-13 22:22:22 +01002731 if ((new_value >= TIPC_MIN_LINK_PRI) &&
2732 (new_value <= TIPC_MAX_LINK_PRI)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002733 l_ptr->priority = new_value;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002734 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +01002735 0, 0, 0, new_value, 0);
Allan Stephens0e35fd52008-07-14 22:44:01 -07002736 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002737 }
2738 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002739 case TIPC_CMD_SET_LINK_WINDOW:
2740 if ((new_value >= TIPC_MIN_LINK_WIN) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01002741 (new_value <= TIPC_MAX_LINK_WIN)) {
Per Liden4323add2006-01-18 00:38:21 +01002742 tipc_link_set_queue_limits(l_ptr, new_value);
Allan Stephens0e35fd52008-07-14 22:44:01 -07002743 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002744 }
2745 break;
2746 }
Per Liden4323add2006-01-18 00:38:21 +01002747 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002748
Per Liden4323add2006-01-18 00:38:21 +01002749 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002750 if (res)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002751 return tipc_cfg_reply_error_string("cannot change link setting");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002752
Per Liden4323add2006-01-18 00:38:21 +01002753 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002754}
2755
2756/**
2757 * link_reset_statistics - reset link statistics
2758 * @l_ptr: pointer to link
2759 */
2760
2761static void link_reset_statistics(struct link *l_ptr)
2762{
2763 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
2764 l_ptr->stats.sent_info = l_ptr->next_out_no;
2765 l_ptr->stats.recv_info = l_ptr->next_in_no;
2766}
2767
Per Liden4323add2006-01-18 00:38:21 +01002768struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002769{
2770 char *link_name;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002771 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002772 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002773
2774 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01002775 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002776
2777 link_name = (char *)TLV_DATA(req_tlv_area);
Per Liden4323add2006-01-18 00:38:21 +01002778 if (!strcmp(link_name, tipc_bclink_name)) {
2779 if (tipc_bclink_reset_stats())
2780 return tipc_cfg_reply_error_string("link not found");
2781 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002782 }
2783
Per Liden4323add2006-01-18 00:38:21 +01002784 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002785 l_ptr = link_find_link(link_name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002786 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002787 read_unlock_bh(&tipc_net_lock);
2788 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002789 }
2790
Per Liden4323add2006-01-18 00:38:21 +01002791 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002792 link_reset_statistics(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01002793 tipc_node_unlock(node);
2794 read_unlock_bh(&tipc_net_lock);
2795 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002796}
2797
2798/**
2799 * percent - convert count to a percentage of total (rounding up or down)
2800 */
2801
2802static u32 percent(u32 count, u32 total)
2803{
2804 return (count * 100 + (total / 2)) / total;
2805}
2806
2807/**
Per Liden4323add2006-01-18 00:38:21 +01002808 * tipc_link_stats - print link statistics
Per Lidenb97bf3f2006-01-02 19:04:38 +01002809 * @name: link name
2810 * @buf: print buffer area
2811 * @buf_size: size of print buffer area
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002812 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002813 * Returns length of print buffer data string (or 0 if error)
2814 */
2815
Per Liden4323add2006-01-18 00:38:21 +01002816static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002817{
2818 struct print_buf pb;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002819 struct link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002820 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002821 char *status;
2822 u32 profile_total = 0;
2823
Per Liden4323add2006-01-18 00:38:21 +01002824 if (!strcmp(name, tipc_bclink_name))
2825 return tipc_bclink_stats(buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002826
Per Liden4323add2006-01-18 00:38:21 +01002827 tipc_printbuf_init(&pb, buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002828
Per Liden4323add2006-01-18 00:38:21 +01002829 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002830 l_ptr = link_find_link(name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002831 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002832 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002833 return 0;
2834 }
Per Liden4323add2006-01-18 00:38:21 +01002835 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002836
Per Liden4323add2006-01-18 00:38:21 +01002837 if (tipc_link_is_active(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002838 status = "ACTIVE";
Per Liden4323add2006-01-18 00:38:21 +01002839 else if (tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002840 status = "STANDBY";
2841 else
2842 status = "DEFUNCT";
2843 tipc_printf(&pb, "Link <%s>\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002844 " %s MTU:%u Priority:%u Tolerance:%u ms"
2845 " Window:%u packets\n",
Allan Stephens15e979d2010-05-11 14:30:10 +00002846 l_ptr->name, status, l_ptr->max_pkt,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002847 l_ptr->priority, l_ptr->tolerance, l_ptr->queue_limit[0]);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002848 tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002849 l_ptr->next_in_no - l_ptr->stats.recv_info,
2850 l_ptr->stats.recv_fragments,
2851 l_ptr->stats.recv_fragmented,
2852 l_ptr->stats.recv_bundles,
2853 l_ptr->stats.recv_bundled);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002854 tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002855 l_ptr->next_out_no - l_ptr->stats.sent_info,
2856 l_ptr->stats.sent_fragments,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002857 l_ptr->stats.sent_fragmented,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002858 l_ptr->stats.sent_bundles,
2859 l_ptr->stats.sent_bundled);
2860 profile_total = l_ptr->stats.msg_length_counts;
2861 if (!profile_total)
2862 profile_total = 1;
2863 tipc_printf(&pb, " TX profile sample:%u packets average:%u octets\n"
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002864 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
2865 "-16354:%u%% -32768:%u%% -66000:%u%%\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002866 l_ptr->stats.msg_length_counts,
2867 l_ptr->stats.msg_lengths_total / profile_total,
2868 percent(l_ptr->stats.msg_length_profile[0], profile_total),
2869 percent(l_ptr->stats.msg_length_profile[1], profile_total),
2870 percent(l_ptr->stats.msg_length_profile[2], profile_total),
2871 percent(l_ptr->stats.msg_length_profile[3], profile_total),
2872 percent(l_ptr->stats.msg_length_profile[4], profile_total),
2873 percent(l_ptr->stats.msg_length_profile[5], profile_total),
2874 percent(l_ptr->stats.msg_length_profile[6], profile_total));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002875 tipc_printf(&pb, " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
Per Lidenb97bf3f2006-01-02 19:04:38 +01002876 l_ptr->stats.recv_states,
2877 l_ptr->stats.recv_probes,
2878 l_ptr->stats.recv_nacks,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002879 l_ptr->stats.deferred_recv,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002880 l_ptr->stats.duplicates);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002881 tipc_printf(&pb, " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
2882 l_ptr->stats.sent_states,
2883 l_ptr->stats.sent_probes,
2884 l_ptr->stats.sent_nacks,
2885 l_ptr->stats.sent_acks,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002886 l_ptr->stats.retransmitted);
2887 tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
2888 l_ptr->stats.bearer_congs,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002889 l_ptr->stats.link_congs,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002890 l_ptr->stats.max_queue_sz,
2891 l_ptr->stats.queue_sz_counts
2892 ? (l_ptr->stats.accu_queue_sz / l_ptr->stats.queue_sz_counts)
2893 : 0);
2894
Per Liden4323add2006-01-18 00:38:21 +01002895 tipc_node_unlock(node);
2896 read_unlock_bh(&tipc_net_lock);
2897 return tipc_printbuf_validate(&pb);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002898}
2899
2900#define MAX_LINK_STATS_INFO 2000
2901
Per Liden4323add2006-01-18 00:38:21 +01002902struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002903{
2904 struct sk_buff *buf;
2905 struct tlv_desc *rep_tlv;
2906 int str_len;
2907
2908 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01002909 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002910
Per Liden4323add2006-01-18 00:38:21 +01002911 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_LINK_STATS_INFO));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002912 if (!buf)
2913 return NULL;
2914
2915 rep_tlv = (struct tlv_desc *)buf->data;
2916
Per Liden4323add2006-01-18 00:38:21 +01002917 str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
2918 (char *)TLV_DATA(rep_tlv), MAX_LINK_STATS_INFO);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002919 if (!str_len) {
2920 buf_discard(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002921 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002922 }
2923
2924 skb_put(buf, TLV_SPACE(str_len));
2925 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
2926
2927 return buf;
2928}
2929
Per Lidenb97bf3f2006-01-02 19:04:38 +01002930/**
Per Liden4323add2006-01-18 00:38:21 +01002931 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
Per Lidenb97bf3f2006-01-02 19:04:38 +01002932 * @dest: network address of destination node
2933 * @selector: used to select from set of active links
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002934 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002935 * If no active link can be found, uses default maximum packet size.
2936 */
2937
Per Liden4323add2006-01-18 00:38:21 +01002938u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002939{
David S. Miller6c000552008-09-02 23:38:32 -07002940 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002941 struct link *l_ptr;
2942 u32 res = MAX_PKT_DEFAULT;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002943
Per Lidenb97bf3f2006-01-02 19:04:38 +01002944 if (dest == tipc_own_addr)
2945 return MAX_MSG_SIZE;
2946
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002947 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00002948 n_ptr = tipc_node_find(dest);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002949 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002950 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002951 l_ptr = n_ptr->active_links[selector & 1];
2952 if (l_ptr)
Allan Stephens15e979d2010-05-11 14:30:10 +00002953 res = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01002954 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002955 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002956 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002957 return res;
2958}
2959
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002960static void link_print(struct link *l_ptr, const char *str)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002961{
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002962 char print_area[256];
2963 struct print_buf pb;
2964 struct print_buf *buf = &pb;
2965
2966 tipc_printbuf_init(buf, print_area, sizeof(print_area));
2967
Per Lidenb97bf3f2006-01-02 19:04:38 +01002968 tipc_printf(buf, str);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002969 tipc_printf(buf, "Link %x<%s>:",
2970 l_ptr->addr, l_ptr->b_ptr->publ.name);
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002971
2972#ifdef CONFIG_TIPC_DEBUG
2973 if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr))
2974 goto print_state;
2975
Per Lidenb97bf3f2006-01-02 19:04:38 +01002976 tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no));
2977 tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no));
2978 tipc_printf(buf, "SQUE");
2979 if (l_ptr->first_out) {
2980 tipc_printf(buf, "[%u..", msg_seqno(buf_msg(l_ptr->first_out)));
2981 if (l_ptr->next_out)
2982 tipc_printf(buf, "%u..",
2983 msg_seqno(buf_msg(l_ptr->next_out)));
Allan Stephensb82834e2010-05-11 14:30:04 +00002984 tipc_printf(buf, "%u]", msg_seqno(buf_msg(l_ptr->last_out)));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002985 if ((mod(msg_seqno(buf_msg(l_ptr->last_out)) -
2986 msg_seqno(buf_msg(l_ptr->first_out)))
Joe Perchesf64f9e72009-11-29 16:55:45 -08002987 != (l_ptr->out_queue_size - 1)) ||
2988 (l_ptr->last_out->next != NULL)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002989 tipc_printf(buf, "\nSend queue inconsistency\n");
2990 tipc_printf(buf, "first_out= %x ", l_ptr->first_out);
2991 tipc_printf(buf, "next_out= %x ", l_ptr->next_out);
2992 tipc_printf(buf, "last_out= %x ", l_ptr->last_out);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002993 }
2994 } else
2995 tipc_printf(buf, "[]");
2996 tipc_printf(buf, "SQSIZ(%u)", l_ptr->out_queue_size);
2997 if (l_ptr->oldest_deferred_in) {
2998 u32 o = msg_seqno(buf_msg(l_ptr->oldest_deferred_in));
2999 u32 n = msg_seqno(buf_msg(l_ptr->newest_deferred_in));
3000 tipc_printf(buf, ":RQUE[%u..%u]", o, n);
3001 if (l_ptr->deferred_inqueue_sz != mod((n + 1) - o)) {
3002 tipc_printf(buf, ":RQSIZ(%u)",
3003 l_ptr->deferred_inqueue_sz);
3004 }
3005 }
Allan Stephens8d64a5b2010-12-31 18:59:27 +00003006print_state:
3007#endif
3008
Per Lidenb97bf3f2006-01-02 19:04:38 +01003009 if (link_working_unknown(l_ptr))
3010 tipc_printf(buf, ":WU");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00003011 else if (link_reset_reset(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003012 tipc_printf(buf, ":RR");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00003013 else if (link_reset_unknown(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003014 tipc_printf(buf, ":RU");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00003015 else if (link_working_working(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01003016 tipc_printf(buf, ":WW");
3017 tipc_printf(buf, "\n");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00003018
3019 tipc_printbuf_validate(buf);
3020 info("%s", print_area);
Per Lidenb97bf3f2006-01-02 19:04:38 +01003021}
3022