blob: 54163f91b8ae9a43ed1362e7e838b265d65bd598 [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 *
Jon Maloyc64f7a62012-11-16 13:51:31 +08004 * Copyright (c) 1996-2007, 2012, Ericsson AB
Ying Xue198d73b2013-06-17 10:54:42 -04005 * Copyright (c) 2004-2007, 2010-2013, 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
Ying Xue796c75d2013-06-17 10:54:48 -040044#include <linux/pkt_sched.h>
45
Erik Hugne2cf8aa12012-06-29 00:16:37 -040046/*
47 * Error message prefixes
48 */
49static const char *link_co_err = "Link changeover error, ";
50static const char *link_rst_msg = "Resetting link ";
51static const char *link_unk_evt = "Unknown link event ";
Per Lidenb97bf3f2006-01-02 19:04:38 +010052
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090053/*
Allan Stephensa686e682008-06-04 17:29:39 -070054 * Out-of-range value for link session numbers
55 */
Allan Stephensa686e682008-06-04 17:29:39 -070056#define INVALID_SESSION 0x10000
57
58/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090059 * Link state events:
Per Lidenb97bf3f2006-01-02 19:04:38 +010060 */
Per Lidenb97bf3f2006-01-02 19:04:38 +010061#define STARTING_EVT 856384768 /* link processing trigger */
62#define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */
63#define TIMEOUT_EVT 560817u /* link timer expired */
64
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090065/*
66 * The following two 'message types' is really just implementation
67 * data conveniently stored in the message header.
Per Lidenb97bf3f2006-01-02 19:04:38 +010068 * They must not be considered part of the protocol
69 */
70#define OPEN_MSG 0
71#define CLOSED_MSG 1
72
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090073/*
Per Lidenb97bf3f2006-01-02 19:04:38 +010074 * State value stored in 'exp_msg_count'
75 */
Per Lidenb97bf3f2006-01-02 19:04:38 +010076#define START_CHANGEOVER 100000u
77
Paul Gortmakera18c4bc2011-12-29 20:58:42 -050078static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +010079 struct sk_buff *buf);
Paul Gortmakera18c4bc2011-12-29 20:58:42 -050080static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf);
81static int link_recv_changeover_msg(struct tipc_link **l_ptr,
82 struct sk_buff **buf);
83static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance);
Allan Stephens23dd4cc2011-01-07 11:43:40 -050084static int link_send_sections_long(struct tipc_port *sender,
Per Lidenb97bf3f2006-01-02 19:04:38 +010085 struct iovec const *msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +020086 unsigned int len, u32 destnode);
Paul Gortmakera18c4bc2011-12-29 20:58:42 -050087static void link_state_event(struct tipc_link *l_ptr, u32 event);
88static void link_reset_statistics(struct tipc_link *l_ptr);
89static void link_print(struct tipc_link *l_ptr, const char *str);
90static void link_start(struct tipc_link *l_ptr);
91static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf);
Jon Maloyc64f7a62012-11-16 13:51:31 +080092static void tipc_link_send_sync(struct tipc_link *l);
93static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf);
stephen hemminger31e3c3f2010-10-13 13:20:35 +000094
Per Lidenb97bf3f2006-01-02 19:04:38 +010095/*
Sam Ravnborg05790c62006-03-20 22:37:04 -080096 * Simple link routines
Per Lidenb97bf3f2006-01-02 19:04:38 +010097 */
Sam Ravnborg05790c62006-03-20 22:37:04 -080098static unsigned int align(unsigned int i)
Per Lidenb97bf3f2006-01-02 19:04:38 +010099{
100 return (i + 3) & ~3u;
101}
102
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500103static void link_init_max_pkt(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100104{
105 u32 max_pkt;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900106
Allan Stephens2d627b92011-01-07 13:00:11 -0500107 max_pkt = (l_ptr->b_ptr->mtu & ~3);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108 if (max_pkt > MAX_MSG_SIZE)
109 max_pkt = MAX_MSG_SIZE;
110
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900111 l_ptr->max_pkt_target = max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100112 if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT)
113 l_ptr->max_pkt = l_ptr->max_pkt_target;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900114 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100115 l_ptr->max_pkt = MAX_PKT_DEFAULT;
116
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900117 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100118}
119
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500120static u32 link_next_sent(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100121{
122 if (l_ptr->next_out)
Allan Stephensf9057302011-10-24 16:03:12 -0400123 return buf_seqno(l_ptr->next_out);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100124 return mod(l_ptr->next_out_no);
125}
126
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500127static u32 link_last_sent(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100128{
129 return mod(link_next_sent(l_ptr) - 1);
130}
131
132/*
Sam Ravnborg05790c62006-03-20 22:37:04 -0800133 * Simple non-static link routines (i.e. referenced outside this file)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100134 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500135int tipc_link_is_up(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100136{
137 if (!l_ptr)
138 return 0;
Eric Dumazeta02cec22010-09-22 20:43:57 +0000139 return link_working_working(l_ptr) || link_working_unknown(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100140}
141
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500142int tipc_link_is_active(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100143{
Eric Dumazeta02cec22010-09-22 20:43:57 +0000144 return (l_ptr->owner->active_links[0] == l_ptr) ||
145 (l_ptr->owner->active_links[1] == l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146}
147
148/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100149 * link_timeout - handle expiration of link timer
150 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900151 *
Per Liden4323add2006-01-18 00:38:21 +0100152 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
153 * with tipc_link_delete(). (There is no risk that the node will be deleted by
154 * another thread because tipc_link_delete() always cancels the link timer before
155 * tipc_node_delete() is called.)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100156 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500157static void link_timeout(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100158{
Per Liden4323add2006-01-18 00:38:21 +0100159 tipc_node_lock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100160
161 /* update counters used in statistical profiling of send traffic */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100162 l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size;
163 l_ptr->stats.queue_sz_counts++;
164
Per Lidenb97bf3f2006-01-02 19:04:38 +0100165 if (l_ptr->first_out) {
166 struct tipc_msg *msg = buf_msg(l_ptr->first_out);
167 u32 length = msg_size(msg);
168
Joe Perchesf64f9e72009-11-29 16:55:45 -0800169 if ((msg_user(msg) == MSG_FRAGMENTER) &&
170 (msg_type(msg) == FIRST_FRAGMENT)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100171 length = msg_size(msg_get_wrapped(msg));
172 }
173 if (length) {
174 l_ptr->stats.msg_lengths_total += length;
175 l_ptr->stats.msg_length_counts++;
176 if (length <= 64)
177 l_ptr->stats.msg_length_profile[0]++;
178 else if (length <= 256)
179 l_ptr->stats.msg_length_profile[1]++;
180 else if (length <= 1024)
181 l_ptr->stats.msg_length_profile[2]++;
182 else if (length <= 4096)
183 l_ptr->stats.msg_length_profile[3]++;
184 else if (length <= 16384)
185 l_ptr->stats.msg_length_profile[4]++;
186 else if (length <= 32768)
187 l_ptr->stats.msg_length_profile[5]++;
188 else
189 l_ptr->stats.msg_length_profile[6]++;
190 }
191 }
192
193 /* do all other link processing performed on a periodic basis */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100194
195 link_state_event(l_ptr, TIMEOUT_EVT);
196
197 if (l_ptr->next_out)
Per Liden4323add2006-01-18 00:38:21 +0100198 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100199
Per Liden4323add2006-01-18 00:38:21 +0100200 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100201}
202
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500203static void link_set_timer(struct tipc_link *l_ptr, u32 time)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100204{
205 k_start_timer(&l_ptr->timer, time);
206}
207
208/**
Per Liden4323add2006-01-18 00:38:21 +0100209 * tipc_link_create - create a new link
Allan Stephens37b9c082011-02-28 11:32:27 -0500210 * @n_ptr: pointer to associated node
Per Lidenb97bf3f2006-01-02 19:04:38 +0100211 * @b_ptr: pointer to associated bearer
Per Lidenb97bf3f2006-01-02 19:04:38 +0100212 * @media_addr: media address to use when sending messages over link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900213 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100214 * Returns pointer to link.
215 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500216struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
Allan Stephens37b9c082011-02-28 11:32:27 -0500217 struct tipc_bearer *b_ptr,
Per Liden4323add2006-01-18 00:38:21 +0100218 const struct tipc_media_addr *media_addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100219{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500220 struct tipc_link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221 struct tipc_msg *msg;
222 char *if_name;
Allan Stephens37b9c082011-02-28 11:32:27 -0500223 char addr_string[16];
224 u32 peer = n_ptr->addr;
225
226 if (n_ptr->link_cnt >= 2) {
227 tipc_addr_string_fill(addr_string, n_ptr->addr);
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400228 pr_err("Attempt to establish third link to %s\n", addr_string);
Allan Stephens37b9c082011-02-28 11:32:27 -0500229 return NULL;
230 }
231
232 if (n_ptr->links[b_ptr->identity]) {
233 tipc_addr_string_fill(addr_string, n_ptr->addr);
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400234 pr_err("Attempt to establish second link on <%s> to %s\n",
235 b_ptr->name, addr_string);
Allan Stephens37b9c082011-02-28 11:32:27 -0500236 return NULL;
237 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100238
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700239 l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100240 if (!l_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400241 pr_warn("Link creation failed, no memory\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100242 return NULL;
243 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100244
245 l_ptr->addr = peer;
Allan Stephens2d627b92011-01-07 13:00:11 -0500246 if_name = strchr(b_ptr->name, ':') + 1;
Allan Stephens062b4c92011-04-07 09:28:47 -0400247 sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
Per Lidenb97bf3f2006-01-02 19:04:38 +0100248 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900249 tipc_node(tipc_own_addr),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100250 if_name,
251 tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
Allan Stephens062b4c92011-04-07 09:28:47 -0400252 /* note: peer i/f name is updated by reset/activate message */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100253 memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr));
Allan Stephens37b9c082011-02-28 11:32:27 -0500254 l_ptr->owner = n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100255 l_ptr->checkpoint = 1;
Allan Stephensf882cb72011-04-07 09:43:27 -0400256 l_ptr->peer_session = INVALID_SESSION;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100257 l_ptr->b_ptr = b_ptr;
Allan Stephens5c216e12011-10-18 11:34:29 -0400258 link_set_supervision_props(l_ptr, b_ptr->tolerance);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100259 l_ptr->state = RESET_UNKNOWN;
260
261 l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg;
262 msg = l_ptr->pmsg;
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000263 tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264 msg_set_size(msg, sizeof(l_ptr->proto_msg));
Allan Stephensa686e682008-06-04 17:29:39 -0700265 msg_set_session(msg, (tipc_random & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100266 msg_set_bearer_id(msg, b_ptr->identity);
267 strcpy((char *)msg_data(msg), if_name);
268
269 l_ptr->priority = b_ptr->priority;
Allan Stephens5c216e12011-10-18 11:34:29 -0400270 tipc_link_set_queue_limits(l_ptr, b_ptr->window);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100271
272 link_init_max_pkt(l_ptr);
273
274 l_ptr->next_out_no = 1;
275 INIT_LIST_HEAD(&l_ptr->waiting_ports);
276
277 link_reset_statistics(l_ptr);
278
Allan Stephens37b9c082011-02-28 11:32:27 -0500279 tipc_node_attach_link(n_ptr, l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100280
Florian Westphal945710652007-07-26 00:05:07 -0700281 k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr);
282 list_add_tail(&l_ptr->link_list, &b_ptr->links);
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000283 tipc_k_signal((Handler)link_start, (unsigned long)l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100284
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285 return l_ptr;
286}
287
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900288/**
Per Liden4323add2006-01-18 00:38:21 +0100289 * tipc_link_delete - delete a link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100290 * @l_ptr: pointer to link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900291 *
Per Liden4323add2006-01-18 00:38:21 +0100292 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100293 * This routine must not grab the node lock until after link timer cancellation
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900294 * to avoid a potential deadlock situation.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100295 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500296void tipc_link_delete(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100297{
298 if (!l_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400299 pr_err("Attempt to delete non-existent link\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300 return;
301 }
302
Per Lidenb97bf3f2006-01-02 19:04:38 +0100303 k_cancel_timer(&l_ptr->timer);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900304
Per Liden4323add2006-01-18 00:38:21 +0100305 tipc_node_lock(l_ptr->owner);
306 tipc_link_reset(l_ptr);
307 tipc_node_detach_link(l_ptr->owner, l_ptr);
308 tipc_link_stop(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100309 list_del_init(&l_ptr->link_list);
Per Liden4323add2006-01-18 00:38:21 +0100310 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100311 k_term_timer(&l_ptr->timer);
312 kfree(l_ptr);
313}
314
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500315static void link_start(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100316{
Allan Stephens214dda42011-01-24 16:22:43 -0500317 tipc_node_lock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100318 link_state_event(l_ptr, STARTING_EVT);
Allan Stephens214dda42011-01-24 16:22:43 -0500319 tipc_node_unlock(l_ptr->owner);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100320}
321
322/**
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900323 * link_schedule_port - schedule port for deferred sending
Per Lidenb97bf3f2006-01-02 19:04:38 +0100324 * @l_ptr: pointer to link
325 * @origport: reference to sending port
326 * @sz: amount of data to be sent
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900327 *
328 * Schedules port for renewed sending of messages after link congestion
Per Lidenb97bf3f2006-01-02 19:04:38 +0100329 * has abated.
330 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500331static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100332{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500333 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100334
Per Liden4323add2006-01-18 00:38:21 +0100335 spin_lock_bh(&tipc_port_list_lock);
336 p_ptr = tipc_port_lock(origport);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100337 if (p_ptr) {
338 if (!p_ptr->wakeup)
339 goto exit;
340 if (!list_empty(&p_ptr->wait_list))
341 goto exit;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500342 p_ptr->congested = 1;
Allan Stephens15e979d2010-05-11 14:30:10 +0000343 p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100344 list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
345 l_ptr->stats.link_congs++;
346exit:
Per Liden4323add2006-01-18 00:38:21 +0100347 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100348 }
Per Liden4323add2006-01-18 00:38:21 +0100349 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100350 return -ELINKCONG;
351}
352
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500353void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100354{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500355 struct tipc_port *p_ptr;
356 struct tipc_port *temp_p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100357 int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;
358
359 if (all)
360 win = 100000;
361 if (win <= 0)
362 return;
Per Liden4323add2006-01-18 00:38:21 +0100363 if (!spin_trylock_bh(&tipc_port_list_lock))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100364 return;
365 if (link_congested(l_ptr))
366 goto exit;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900367 list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100368 wait_list) {
369 if (win <= 0)
370 break;
371 list_del_init(&p_ptr->wait_list);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500372 spin_lock_bh(p_ptr->lock);
373 p_ptr->congested = 0;
374 p_ptr->wakeup(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100375 win -= p_ptr->waiting_pkts;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500376 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100377 }
378
379exit:
Per Liden4323add2006-01-18 00:38:21 +0100380 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100381}
382
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900383/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100384 * link_release_outqueue - purge link's outbound message queue
385 * @l_ptr: pointer to link
386 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500387static void link_release_outqueue(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100388{
389 struct sk_buff *buf = l_ptr->first_out;
390 struct sk_buff *next;
391
392 while (buf) {
393 next = buf->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -0400394 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100395 buf = next;
396 }
397 l_ptr->first_out = NULL;
398 l_ptr->out_queue_size = 0;
399}
400
401/**
Per Liden4323add2006-01-18 00:38:21 +0100402 * tipc_link_reset_fragments - purge link's inbound message fragments queue
Per Lidenb97bf3f2006-01-02 19:04:38 +0100403 * @l_ptr: pointer to link
404 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500405void tipc_link_reset_fragments(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100406{
407 struct sk_buff *buf = l_ptr->defragm_buf;
408 struct sk_buff *next;
409
410 while (buf) {
411 next = buf->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -0400412 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100413 buf = next;
414 }
415 l_ptr->defragm_buf = NULL;
416}
417
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900418/**
Per Liden4323add2006-01-18 00:38:21 +0100419 * tipc_link_stop - purge all inbound and outbound messages associated with link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 * @l_ptr: pointer to link
421 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500422void tipc_link_stop(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100423{
424 struct sk_buff *buf;
425 struct sk_buff *next;
426
427 buf = l_ptr->oldest_deferred_in;
428 while (buf) {
429 next = buf->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -0400430 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100431 buf = next;
432 }
433
434 buf = l_ptr->first_out;
435 while (buf) {
436 next = buf->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -0400437 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100438 buf = next;
439 }
440
Per Liden4323add2006-01-18 00:38:21 +0100441 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100442
Allan Stephens5f6d9122011-11-04 13:24:29 -0400443 kfree_skb(l_ptr->proto_msg_queue);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100444 l_ptr->proto_msg_queue = NULL;
445}
446
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500447void tipc_link_reset(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100448{
449 struct sk_buff *buf;
450 u32 prev_state = l_ptr->state;
451 u32 checkpoint = l_ptr->next_in_no;
Allan Stephens5392d642006-06-25 23:52:50 -0700452 int was_active_link = tipc_link_is_active(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900453
Allan Stephensa686e682008-06-04 17:29:39 -0700454 msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100455
Allan Stephensa686e682008-06-04 17:29:39 -0700456 /* Link is down, accept any session */
457 l_ptr->peer_session = INVALID_SESSION;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100458
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900459 /* Prepare for max packet size negotiation */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100460 link_init_max_pkt(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900461
Per Lidenb97bf3f2006-01-02 19:04:38 +0100462 l_ptr->state = RESET_UNKNOWN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100463
464 if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET))
465 return;
466
Per Liden4323add2006-01-18 00:38:21 +0100467 tipc_node_link_down(l_ptr->owner, l_ptr);
468 tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr);
Paul Gortmaker7368ddf2010-10-12 14:25:58 +0000469
Paul Gortmaker8f19afb2011-02-28 11:36:21 -0400470 if (was_active_link && tipc_node_active_links(l_ptr->owner) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100471 l_ptr->owner->permit_changeover) {
472 l_ptr->reset_checkpoint = checkpoint;
473 l_ptr->exp_msg_count = START_CHANGEOVER;
474 }
475
476 /* Clean up all queues: */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100477 link_release_outqueue(l_ptr);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400478 kfree_skb(l_ptr->proto_msg_queue);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100479 l_ptr->proto_msg_queue = NULL;
480 buf = l_ptr->oldest_deferred_in;
481 while (buf) {
482 struct sk_buff *next = buf->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -0400483 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100484 buf = next;
485 }
486 if (!list_empty(&l_ptr->waiting_ports))
Per Liden4323add2006-01-18 00:38:21 +0100487 tipc_link_wakeup_ports(l_ptr, 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100488
489 l_ptr->retransm_queue_head = 0;
490 l_ptr->retransm_queue_size = 0;
491 l_ptr->last_out = NULL;
492 l_ptr->first_out = NULL;
493 l_ptr->next_out = NULL;
494 l_ptr->unacked_window = 0;
495 l_ptr->checkpoint = 1;
496 l_ptr->next_out_no = 1;
497 l_ptr->deferred_inqueue_sz = 0;
498 l_ptr->oldest_deferred_in = NULL;
499 l_ptr->newest_deferred_in = NULL;
500 l_ptr->fsm_msg_cnt = 0;
501 l_ptr->stale_count = 0;
502 link_reset_statistics(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100503}
504
505
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500506static void link_activate(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100507{
Allan Stephens5392d642006-06-25 23:52:50 -0700508 l_ptr->next_in_no = l_ptr->stats.recv_info = 1;
Per Liden4323add2006-01-18 00:38:21 +0100509 tipc_node_link_up(l_ptr->owner, l_ptr);
510 tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100511}
512
513/**
514 * link_state_event - link finite state machine
515 * @l_ptr: pointer to link
516 * @event: state machine event to process
517 */
Eric Dumazet95c96172012-04-15 05:58:06 +0000518static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100519{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500520 struct tipc_link *other;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100521 u32 cont_intv = l_ptr->continuity_interval;
522
523 if (!l_ptr->started && (event != STARTING_EVT))
524 return; /* Not yet. */
525
526 if (link_blocked(l_ptr)) {
Allan Stephensa0168922010-12-31 18:59:35 +0000527 if (event == TIMEOUT_EVT)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100528 link_set_timer(l_ptr, cont_intv);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100529 return; /* Changeover going on */
530 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100531
532 switch (l_ptr->state) {
533 case WORKING_WORKING:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100534 switch (event) {
535 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100536 case ACTIVATE_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100537 break;
538 case TIMEOUT_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100539 if (l_ptr->next_in_no != l_ptr->checkpoint) {
540 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100541 if (tipc_bclink_acks_missing(l_ptr->owner)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900542 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100543 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100544 l_ptr->fsm_msg_cnt++;
545 } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900546 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100547 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100548 l_ptr->fsm_msg_cnt++;
549 }
550 link_set_timer(l_ptr, cont_intv);
551 break;
552 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100553 l_ptr->state = WORKING_UNKNOWN;
554 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100555 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100556 l_ptr->fsm_msg_cnt++;
557 link_set_timer(l_ptr, cont_intv / 4);
558 break;
559 case RESET_MSG:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400560 pr_info("%s<%s>, requested by peer\n", link_rst_msg,
561 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100562 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100563 l_ptr->state = RESET_RESET;
564 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100565 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100566 l_ptr->fsm_msg_cnt++;
567 link_set_timer(l_ptr, cont_intv);
568 break;
569 default:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400570 pr_err("%s%u in WW state\n", link_unk_evt, event);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100571 }
572 break;
573 case WORKING_UNKNOWN:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100574 switch (event) {
575 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100576 case ACTIVATE_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100577 l_ptr->state = WORKING_WORKING;
578 l_ptr->fsm_msg_cnt = 0;
579 link_set_timer(l_ptr, cont_intv);
580 break;
581 case RESET_MSG:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400582 pr_info("%s<%s>, requested by peer while probing\n",
583 link_rst_msg, l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100584 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100585 l_ptr->state = RESET_RESET;
586 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100587 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100588 l_ptr->fsm_msg_cnt++;
589 link_set_timer(l_ptr, cont_intv);
590 break;
591 case TIMEOUT_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100592 if (l_ptr->next_in_no != l_ptr->checkpoint) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100593 l_ptr->state = WORKING_WORKING;
594 l_ptr->fsm_msg_cnt = 0;
595 l_ptr->checkpoint = l_ptr->next_in_no;
Per Liden4323add2006-01-18 00:38:21 +0100596 if (tipc_bclink_acks_missing(l_ptr->owner)) {
597 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
598 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100599 l_ptr->fsm_msg_cnt++;
600 }
601 link_set_timer(l_ptr, cont_intv);
602 } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900603 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
Per Liden4323add2006-01-18 00:38:21 +0100604 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100605 l_ptr->fsm_msg_cnt++;
606 link_set_timer(l_ptr, cont_intv / 4);
607 } else { /* Link has failed */
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400608 pr_warn("%s<%s>, peer not responding\n",
609 link_rst_msg, l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100610 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100611 l_ptr->state = RESET_UNKNOWN;
612 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100613 tipc_link_send_proto_msg(l_ptr, RESET_MSG,
614 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100615 l_ptr->fsm_msg_cnt++;
616 link_set_timer(l_ptr, cont_intv);
617 }
618 break;
619 default:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400620 pr_err("%s%u in WU state\n", link_unk_evt, event);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100621 }
622 break;
623 case RESET_UNKNOWN:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100624 switch (event) {
625 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100626 break;
627 case ACTIVATE_MSG:
628 other = l_ptr->owner->active_links[0];
Allan Stephens8d64a5b2010-12-31 18:59:27 +0000629 if (other && link_working_unknown(other))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100630 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100631 l_ptr->state = WORKING_WORKING;
632 l_ptr->fsm_msg_cnt = 0;
633 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100634 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100635 l_ptr->fsm_msg_cnt++;
Jon Maloyc64f7a62012-11-16 13:51:31 +0800636 if (l_ptr->owner->working_links == 1)
637 tipc_link_send_sync(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100638 link_set_timer(l_ptr, cont_intv);
639 break;
640 case RESET_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100641 l_ptr->state = RESET_RESET;
642 l_ptr->fsm_msg_cnt = 0;
Per Liden4323add2006-01-18 00:38:21 +0100643 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100644 l_ptr->fsm_msg_cnt++;
645 link_set_timer(l_ptr, cont_intv);
646 break;
647 case STARTING_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100648 l_ptr->started = 1;
649 /* fall through */
650 case TIMEOUT_EVT:
Per Liden4323add2006-01-18 00:38:21 +0100651 tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652 l_ptr->fsm_msg_cnt++;
653 link_set_timer(l_ptr, cont_intv);
654 break;
655 default:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400656 pr_err("%s%u in RU state\n", link_unk_evt, event);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100657 }
658 break;
659 case RESET_RESET:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100660 switch (event) {
661 case TRAFFIC_MSG_EVT:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100662 case ACTIVATE_MSG:
663 other = l_ptr->owner->active_links[0];
Allan Stephens8d64a5b2010-12-31 18:59:27 +0000664 if (other && link_working_unknown(other))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100665 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100666 l_ptr->state = WORKING_WORKING;
667 l_ptr->fsm_msg_cnt = 0;
668 link_activate(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100669 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100670 l_ptr->fsm_msg_cnt++;
Jon Maloyc64f7a62012-11-16 13:51:31 +0800671 if (l_ptr->owner->working_links == 1)
672 tipc_link_send_sync(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100673 link_set_timer(l_ptr, cont_intv);
674 break;
675 case RESET_MSG:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100676 break;
677 case TIMEOUT_EVT:
Per Liden4323add2006-01-18 00:38:21 +0100678 tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100679 l_ptr->fsm_msg_cnt++;
680 link_set_timer(l_ptr, cont_intv);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681 break;
682 default:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400683 pr_err("%s%u in RR state\n", link_unk_evt, event);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100684 }
685 break;
686 default:
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400687 pr_err("Unknown link state %u/%u\n", l_ptr->state, event);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100688 }
689}
690
691/*
692 * link_bundle_buf(): Append contents of a buffer to
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900693 * the tail of an existing one.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100694 */
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400695static int link_bundle_buf(struct tipc_link *l_ptr, struct sk_buff *bundler,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100696 struct sk_buff *buf)
697{
698 struct tipc_msg *bundler_msg = buf_msg(bundler);
699 struct tipc_msg *msg = buf_msg(buf);
700 u32 size = msg_size(msg);
Allan Stephense49060c2006-06-29 12:32:46 -0700701 u32 bundle_size = msg_size(bundler_msg);
702 u32 to_pos = align(bundle_size);
703 u32 pad = to_pos - bundle_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100704
705 if (msg_user(bundler_msg) != MSG_BUNDLER)
706 return 0;
707 if (msg_type(bundler_msg) != OPEN_MSG)
708 return 0;
Allan Stephense49060c2006-06-29 12:32:46 -0700709 if (skb_tailroom(bundler) < (pad + size))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100710 return 0;
Allan Stephens15e979d2010-05-11 14:30:10 +0000711 if (l_ptr->max_pkt < (to_pos + size))
Allan Stephens863fae62006-07-03 19:39:36 -0700712 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713
Allan Stephense49060c2006-06-29 12:32:46 -0700714 skb_put(bundler, pad + size);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300715 skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100716 msg_set_size(bundler_msg, to_pos + size);
717 msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400718 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100719 l_ptr->stats.sent_bundled++;
720 return 1;
721}
722
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500723static void link_add_to_outqueue(struct tipc_link *l_ptr,
Sam Ravnborg05790c62006-03-20 22:37:04 -0800724 struct sk_buff *buf,
725 struct tipc_msg *msg)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100726{
727 u32 ack = mod(l_ptr->next_in_no - 1);
728 u32 seqno = mod(l_ptr->next_out_no++);
729
730 msg_set_word(msg, 2, ((ack << 16) | seqno));
731 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
732 buf->next = NULL;
733 if (l_ptr->first_out) {
734 l_ptr->last_out->next = buf;
735 l_ptr->last_out = buf;
736 } else
737 l_ptr->first_out = l_ptr->last_out = buf;
Allan Stephens9bd80b62011-01-18 15:02:50 -0500738
Per Lidenb97bf3f2006-01-02 19:04:38 +0100739 l_ptr->out_queue_size++;
Allan Stephens9bd80b62011-01-18 15:02:50 -0500740 if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz)
741 l_ptr->stats.max_queue_sz = l_ptr->out_queue_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100742}
743
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500744static void link_add_chain_to_outqueue(struct tipc_link *l_ptr,
Allan Stephensdc63d912011-04-21 11:50:42 -0400745 struct sk_buff *buf_chain,
746 u32 long_msgno)
747{
748 struct sk_buff *buf;
749 struct tipc_msg *msg;
750
751 if (!l_ptr->next_out)
752 l_ptr->next_out = buf_chain;
753 while (buf_chain) {
754 buf = buf_chain;
755 buf_chain = buf_chain->next;
756
757 msg = buf_msg(buf);
758 msg_set_long_msgno(msg, long_msgno);
759 link_add_to_outqueue(l_ptr, buf, msg);
760 }
761}
762
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900763/*
764 * tipc_link_send_buf() is the 'full path' for messages, called from
Per Lidenb97bf3f2006-01-02 19:04:38 +0100765 * inside TIPC when the 'fast path' in tipc_send_buf
766 * has failed, and from link_send()
767 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500768int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100769{
770 struct tipc_msg *msg = buf_msg(buf);
771 u32 size = msg_size(msg);
772 u32 dsz = msg_data_sz(msg);
773 u32 queue_size = l_ptr->out_queue_size;
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000774 u32 imp = tipc_msg_tot_importance(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100775 u32 queue_limit = l_ptr->queue_limit[imp];
Allan Stephens15e979d2010-05-11 14:30:10 +0000776 u32 max_packet = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100777
Per Lidenb97bf3f2006-01-02 19:04:38 +0100778 /* Match msg importance against queue limits: */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100779 if (unlikely(queue_size >= queue_limit)) {
780 if (imp <= TIPC_CRITICAL_IMPORTANCE) {
Allan Stephensbebc55a2011-04-19 10:17:58 -0400781 link_schedule_port(l_ptr, msg_origport(msg), size);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400782 kfree_skb(buf);
Allan Stephensbebc55a2011-04-19 10:17:58 -0400783 return -ELINKCONG;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100784 }
Allan Stephens5f6d9122011-11-04 13:24:29 -0400785 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100786 if (imp > CONN_MANAGER) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400787 pr_warn("%s<%s>, send queue full", link_rst_msg,
788 l_ptr->name);
Per Liden4323add2006-01-18 00:38:21 +0100789 tipc_link_reset(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100790 }
791 return dsz;
792 }
793
794 /* Fragmentation needed ? */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100795 if (size > max_packet)
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000796 return link_send_long_buf(l_ptr, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100797
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400798 /* Packet can be queued or sent. */
Ying Xue3c294cb2012-11-15 11:34:45 +0800799 if (likely(!tipc_bearer_blocked(l_ptr->b_ptr) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +0100800 !link_congested(l_ptr))) {
801 link_add_to_outqueue(l_ptr, buf, msg);
802
Ying Xue3c294cb2012-11-15 11:34:45 +0800803 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
804 l_ptr->unacked_window = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100805 return dsz;
806 }
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400807 /* Congestion: can message be bundled ? */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100808 if ((msg_user(msg) != CHANGEOVER_PROTOCOL) &&
809 (msg_user(msg) != MSG_FRAGMENTER)) {
810
811 /* Try adding message to an existing bundle */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900812 if (l_ptr->next_out &&
Ying Xue3c294cb2012-11-15 11:34:45 +0800813 link_bundle_buf(l_ptr, l_ptr->last_out, buf))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100814 return dsz;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100815
816 /* Try creating a new bundle */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100817 if (size <= max_packet * 2 / 3) {
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000818 struct sk_buff *bundler = tipc_buf_acquire(max_packet);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100819 struct tipc_msg bundler_hdr;
820
821 if (bundler) {
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000822 tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG,
Allan Stephens75715212008-06-04 17:37:34 -0700823 INT_H_SIZE, l_ptr->addr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300824 skb_copy_to_linear_data(bundler, &bundler_hdr,
825 INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100826 skb_trim(bundler, INT_H_SIZE);
827 link_bundle_buf(l_ptr, bundler, buf);
828 buf = bundler;
829 msg = buf_msg(buf);
830 l_ptr->stats.sent_bundles++;
831 }
832 }
833 }
834 if (!l_ptr->next_out)
835 l_ptr->next_out = buf;
836 link_add_to_outqueue(l_ptr, buf, msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100837 return dsz;
838}
839
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900840/*
841 * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has
Per Lidenb97bf3f2006-01-02 19:04:38 +0100842 * not been selected yet, and the the owner node is not locked
843 * Called by TIPC internal users, e.g. the name distributor
844 */
Per Liden4323add2006-01-18 00:38:21 +0100845int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100846{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500847 struct tipc_link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -0700848 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100849 int res = -ELINKCONG;
850
Per Liden4323add2006-01-18 00:38:21 +0100851 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000852 n_ptr = tipc_node_find(dest);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100853 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +0100854 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100855 l_ptr = n_ptr->active_links[selector & 1];
Allan Stephensa0168922010-12-31 18:59:35 +0000856 if (l_ptr)
Per Liden4323add2006-01-18 00:38:21 +0100857 res = tipc_link_send_buf(l_ptr, buf);
Allan Stephensa0168922010-12-31 18:59:35 +0000858 else
Allan Stephens5f6d9122011-11-04 13:24:29 -0400859 kfree_skb(buf);
Per Liden4323add2006-01-18 00:38:21 +0100860 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100861 } else {
Allan Stephens5f6d9122011-11-04 13:24:29 -0400862 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100863 }
Per Liden4323add2006-01-18 00:38:21 +0100864 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100865 return res;
866}
867
Jon Maloyc64f7a62012-11-16 13:51:31 +0800868/*
869 * tipc_link_send_sync - synchronize broadcast link endpoints.
870 *
871 * Give a newly added peer node the sequence number where it should
872 * start receiving and acking broadcast packets.
873 *
874 * Called with node locked
875 */
876static void tipc_link_send_sync(struct tipc_link *l)
877{
878 struct sk_buff *buf;
879 struct tipc_msg *msg;
880
881 buf = tipc_buf_acquire(INT_H_SIZE);
882 if (!buf)
883 return;
884
885 msg = buf_msg(buf);
886 tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, l->addr);
887 msg_set_last_bcast(msg, l->owner->bclink.acked);
888 link_add_chain_to_outqueue(l, buf, 0);
889 tipc_link_push_queue(l);
890}
891
892/*
893 * tipc_link_recv_sync - synchronize broadcast link endpoints.
894 * Receive the sequence number where we should start receiving and
895 * acking broadcast packets from a newly added peer node, and open
896 * up for reception of such packets.
897 *
898 * Called with node locked
899 */
900static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf)
901{
902 struct tipc_msg *msg = buf_msg(buf);
903
904 n->bclink.last_sent = n->bclink.last_in = msg_last_bcast(msg);
905 n->bclink.recv_permitted = true;
906 kfree_skb(buf);
907}
908
909/*
Allan Stephens9aa88c22011-05-31 13:38:02 -0400910 * tipc_link_send_names - send name table entries to new neighbor
911 *
912 * Send routine for bulk delivery of name table messages when contact
913 * with a new neighbor occurs. No link congestion checking is performed
914 * because name table messages *must* be delivered. The messages must be
915 * small enough not to require fragmentation.
916 * Called without any locks held.
917 */
Allan Stephens9aa88c22011-05-31 13:38:02 -0400918void tipc_link_send_names(struct list_head *message_list, u32 dest)
919{
920 struct tipc_node *n_ptr;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500921 struct tipc_link *l_ptr;
Allan Stephens9aa88c22011-05-31 13:38:02 -0400922 struct sk_buff *buf;
923 struct sk_buff *temp_buf;
924
925 if (list_empty(message_list))
926 return;
927
928 read_lock_bh(&tipc_net_lock);
929 n_ptr = tipc_node_find(dest);
930 if (n_ptr) {
931 tipc_node_lock(n_ptr);
932 l_ptr = n_ptr->active_links[0];
933 if (l_ptr) {
934 /* convert circular list to linear list */
935 ((struct sk_buff *)message_list->prev)->next = NULL;
936 link_add_chain_to_outqueue(l_ptr,
937 (struct sk_buff *)message_list->next, 0);
938 tipc_link_push_queue(l_ptr);
939 INIT_LIST_HEAD(message_list);
940 }
941 tipc_node_unlock(n_ptr);
942 }
943 read_unlock_bh(&tipc_net_lock);
944
945 /* discard the messages if they couldn't be sent */
Allan Stephens9aa88c22011-05-31 13:38:02 -0400946 list_for_each_safe(buf, temp_buf, ((struct sk_buff *)message_list)) {
947 list_del((struct list_head *)buf);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400948 kfree_skb(buf);
Allan Stephens9aa88c22011-05-31 13:38:02 -0400949 }
950}
951
952/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900953 * link_send_buf_fast: Entry for data messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +0100954 * destination link is known and the header is complete,
955 * inclusive total message length. Very time critical.
956 * Link is locked. Returns user data length.
957 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500958static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf,
Sam Ravnborg05790c62006-03-20 22:37:04 -0800959 u32 *used_max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100960{
961 struct tipc_msg *msg = buf_msg(buf);
962 int res = msg_data_sz(msg);
963
964 if (likely(!link_congested(l_ptr))) {
Allan Stephens15e979d2010-05-11 14:30:10 +0000965 if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
Ying Xue3c294cb2012-11-15 11:34:45 +0800966 if (likely(!tipc_bearer_blocked(l_ptr->b_ptr))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100967 link_add_to_outqueue(l_ptr, buf, msg);
Ying Xue3c294cb2012-11-15 11:34:45 +0800968 tipc_bearer_send(l_ptr->b_ptr, buf,
969 &l_ptr->media_addr);
970 l_ptr->unacked_window = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100971 return res;
972 }
Allan Stephens0e659672010-12-31 18:59:32 +0000973 } else
Allan Stephens15e979d2010-05-11 14:30:10 +0000974 *used_max_pkt = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100975 }
Per Liden4323add2006-01-18 00:38:21 +0100976 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100977}
978
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900979/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900980 * tipc_link_send_sections_fast: Entry for messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +0100981 * destination processor is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900982 * except for total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100983 * Returns user data length or errno.
984 */
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500985int tipc_link_send_sections_fast(struct tipc_port *sender,
Per Liden4323add2006-01-18 00:38:21 +0100986 struct iovec const *msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +0200987 unsigned int len, u32 destaddr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100988{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500989 struct tipc_msg *hdr = &sender->phdr;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -0500990 struct tipc_link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100991 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -0700992 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100993 int res;
994 u32 selector = msg_origport(hdr) & 1;
995
Per Lidenb97bf3f2006-01-02 19:04:38 +0100996again:
997 /*
998 * Try building message using port's max_pkt hint.
999 * (Must not hold any locks while building message.)
1000 */
Ying Xue9446b872013-10-18 07:23:15 +02001001 res = tipc_msg_build(hdr, msg_sect, len, sender->max_pkt, &buf);
Ying Xue7410f962013-06-17 10:54:49 -04001002 /* Exit if build request was invalid */
1003 if (unlikely(res < 0))
1004 return res;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001005
Per Liden4323add2006-01-18 00:38:21 +01001006 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001007 node = tipc_node_find(destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001008 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001009 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001010 l_ptr = node->active_links[selector];
1011 if (likely(l_ptr)) {
1012 if (likely(buf)) {
1013 res = link_send_buf_fast(l_ptr, buf,
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001014 &sender->max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001015exit:
Per Liden4323add2006-01-18 00:38:21 +01001016 tipc_node_unlock(node);
1017 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001018 return res;
1019 }
1020
Per Lidenb97bf3f2006-01-02 19:04:38 +01001021 /* Exit if link (or bearer) is congested */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001022 if (link_congested(l_ptr) ||
Ying Xue3c294cb2012-11-15 11:34:45 +08001023 tipc_bearer_blocked(l_ptr->b_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001024 res = link_schedule_port(l_ptr,
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001025 sender->ref, res);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001026 goto exit;
1027 }
1028
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001029 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001030 * Message size exceeds max_pkt hint; update hint,
1031 * then re-try fast path or fragment the message
1032 */
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001033 sender->max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001034 tipc_node_unlock(node);
1035 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001036
1037
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001038 if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001039 goto again;
1040
Ying Xue9446b872013-10-18 07:23:15 +02001041 return link_send_sections_long(sender, msg_sect, len,
Allan Stephens26896902011-04-21 10:42:07 -05001042 destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001043 }
Per Liden4323add2006-01-18 00:38:21 +01001044 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001045 }
Per Liden4323add2006-01-18 00:38:21 +01001046 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001047
1048 /* Couldn't find a link to the destination node */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001049 if (buf)
1050 return tipc_reject_msg(buf, TIPC_ERR_NO_NODE);
1051 if (res >= 0)
Ying Xue9446b872013-10-18 07:23:15 +02001052 return tipc_port_reject_sections(sender, hdr, msg_sect,
1053 len, TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001054 return res;
1055}
1056
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001057/*
1058 * link_send_sections_long(): Entry for long messages where the
Per Lidenb97bf3f2006-01-02 19:04:38 +01001059 * destination node is known and the header is complete,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001060 * inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01001061 * Link and bearer congestion status have been checked to be ok,
1062 * and are ignored if they change.
1063 *
1064 * Note that fragments do not use the full link MTU so that they won't have
1065 * to undergo refragmentation if link changeover causes them to be sent
1066 * over another link with an additional tunnel header added as prefix.
1067 * (Refragmentation will still occur if the other link has a smaller MTU.)
1068 *
1069 * Returns user data length or errno.
1070 */
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001071static int link_send_sections_long(struct tipc_port *sender,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001072 struct iovec const *msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +02001073 unsigned int len, u32 destaddr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001074{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001075 struct tipc_link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07001076 struct tipc_node *node;
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001077 struct tipc_msg *hdr = &sender->phdr;
Ying Xue9446b872013-10-18 07:23:15 +02001078 u32 dsz = len;
Allan Stephens0e659672010-12-31 18:59:32 +00001079 u32 max_pkt, fragm_sz, rest;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001080 struct tipc_msg fragm_hdr;
Allan Stephens0e659672010-12-31 18:59:32 +00001081 struct sk_buff *buf, *buf_chain, *prev;
1082 u32 fragm_crs, fragm_rest, hsz, sect_rest;
Ying Xue40682432013-10-18 07:23:16 +02001083 const unchar __user *sect_crs;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001084 int curr_sect;
1085 u32 fragm_no;
Ying Xue126c0522013-06-17 10:54:50 -04001086 int res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001087
1088again:
1089 fragm_no = 1;
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001090 max_pkt = sender->max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001091 /* leave room for tunnel header in case of link changeover */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001092 fragm_sz = max_pkt - INT_H_SIZE;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001093 /* leave room for fragmentation header in each fragment */
1094 rest = dsz;
1095 fragm_crs = 0;
1096 fragm_rest = 0;
1097 sect_rest = 0;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001098 sect_crs = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001099 curr_sect = -1;
1100
Paul Gortmaker617d3c72012-04-30 15:29:02 -04001101 /* Prepare reusable fragment header */
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001102 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07001103 INT_H_SIZE, msg_destnode(hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001104 msg_set_size(&fragm_hdr, max_pkt);
1105 msg_set_fragm_no(&fragm_hdr, 1);
1106
Paul Gortmaker617d3c72012-04-30 15:29:02 -04001107 /* Prepare header of first fragment */
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001108 buf_chain = buf = tipc_buf_acquire(max_pkt);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001109 if (!buf)
1110 return -ENOMEM;
1111 buf->next = NULL;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001112 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001113 hsz = msg_hdr_sz(hdr);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001114 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001115
Paul Gortmaker617d3c72012-04-30 15:29:02 -04001116 /* Chop up message */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001117 fragm_crs = INT_H_SIZE + hsz;
1118 fragm_rest = fragm_sz - hsz;
1119
1120 do { /* For all sections */
1121 u32 sz;
1122
1123 if (!sect_rest) {
1124 sect_rest = msg_sect[++curr_sect].iov_len;
Ying Xue40682432013-10-18 07:23:16 +02001125 sect_crs = msg_sect[curr_sect].iov_base;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001126 }
1127
1128 if (sect_rest < fragm_rest)
1129 sz = sect_rest;
1130 else
1131 sz = fragm_rest;
1132
Ying Xuef1733d72013-06-17 10:54:43 -04001133 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
Ying Xue126c0522013-06-17 10:54:50 -04001134 res = -EFAULT;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001135error:
Ying Xuef1733d72013-06-17 10:54:43 -04001136 for (; buf_chain; buf_chain = buf) {
1137 buf = buf_chain->next;
1138 kfree_skb(buf_chain);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001139 }
Ying Xue126c0522013-06-17 10:54:50 -04001140 return res;
Ying Xuef1733d72013-06-17 10:54:43 -04001141 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001142 sect_crs += sz;
1143 sect_rest -= sz;
1144 fragm_crs += sz;
1145 fragm_rest -= sz;
1146 rest -= sz;
1147
1148 if (!fragm_rest && rest) {
1149
1150 /* Initiate new fragment: */
1151 if (rest <= fragm_sz) {
1152 fragm_sz = rest;
Allan Stephens0e659672010-12-31 18:59:32 +00001153 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001154 } else {
1155 msg_set_type(&fragm_hdr, FRAGMENT);
1156 }
1157 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
1158 msg_set_fragm_no(&fragm_hdr, ++fragm_no);
1159 prev = buf;
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001160 buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
Ying Xue126c0522013-06-17 10:54:50 -04001161 if (!buf) {
1162 res = -ENOMEM;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001163 goto error;
Ying Xue126c0522013-06-17 10:54:50 -04001164 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001165
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001166 buf->next = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001167 prev->next = buf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001168 skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001169 fragm_crs = INT_H_SIZE;
1170 fragm_rest = fragm_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001171 }
Allan Stephens0e659672010-12-31 18:59:32 +00001172 } while (rest > 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001173
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001174 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001175 * Now we have a buffer chain. Select a link and check
1176 * that packet size is still OK
1177 */
Allan Stephens51a8e4d2010-12-31 18:59:18 +00001178 node = tipc_node_find(destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001179 if (likely(node)) {
Per Liden4323add2006-01-18 00:38:21 +01001180 tipc_node_lock(node);
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001181 l_ptr = node->active_links[sender->ref & 1];
Per Lidenb97bf3f2006-01-02 19:04:38 +01001182 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01001183 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001184 goto reject;
1185 }
Allan Stephens15e979d2010-05-11 14:30:10 +00001186 if (l_ptr->max_pkt < max_pkt) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001187 sender->max_pkt = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01001188 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001189 for (; buf_chain; buf_chain = buf) {
1190 buf = buf_chain->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -04001191 kfree_skb(buf_chain);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001192 }
1193 goto again;
1194 }
1195 } else {
1196reject:
1197 for (; buf_chain; buf_chain = buf) {
1198 buf = buf_chain->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -04001199 kfree_skb(buf_chain);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001200 }
Ying Xue9446b872013-10-18 07:23:15 +02001201 return tipc_port_reject_sections(sender, hdr, msg_sect,
1202 len, TIPC_ERR_NO_NODE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001203 }
1204
Allan Stephensdc63d912011-04-21 11:50:42 -04001205 /* Append chain of fragments to send queue & send them */
Allan Stephense0f08592011-04-17 11:44:24 -04001206 l_ptr->long_msg_seq_no++;
Allan Stephensdc63d912011-04-21 11:50:42 -04001207 link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no);
1208 l_ptr->stats.sent_fragments += fragm_no;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001209 l_ptr->stats.sent_fragmented++;
Per Liden4323add2006-01-18 00:38:21 +01001210 tipc_link_push_queue(l_ptr);
1211 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001212 return dsz;
1213}
1214
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001215/*
Per Liden4323add2006-01-18 00:38:21 +01001216 * tipc_link_push_packet: Push one unsent packet to the media
Per Lidenb97bf3f2006-01-02 19:04:38 +01001217 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001218u32 tipc_link_push_packet(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001219{
1220 struct sk_buff *buf = l_ptr->first_out;
1221 u32 r_q_size = l_ptr->retransm_queue_size;
1222 u32 r_q_head = l_ptr->retransm_queue_head;
1223
1224 /* Step to position where retransmission failed, if any, */
1225 /* consider that buffers may have been released in meantime */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001226 if (r_q_size && buf) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001227 u32 last = lesser(mod(r_q_head + r_q_size),
Per Lidenb97bf3f2006-01-02 19:04:38 +01001228 link_last_sent(l_ptr));
Allan Stephensf9057302011-10-24 16:03:12 -04001229 u32 first = buf_seqno(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001230
1231 while (buf && less(first, r_q_head)) {
1232 first = mod(first + 1);
1233 buf = buf->next;
1234 }
1235 l_ptr->retransm_queue_head = r_q_head = first;
1236 l_ptr->retransm_queue_size = r_q_size = mod(last - first);
1237 }
1238
1239 /* Continue retransmission now, if there is anything: */
Neil Hormanca509102010-03-15 07:58:45 +00001240 if (r_q_size && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001241 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001242 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
Ying Xue3c294cb2012-11-15 11:34:45 +08001243 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
1244 l_ptr->retransm_queue_head = mod(++r_q_head);
1245 l_ptr->retransm_queue_size = --r_q_size;
1246 l_ptr->stats.retransmitted++;
1247 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001248 }
1249
1250 /* Send deferred protocol message, if any: */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001251 buf = l_ptr->proto_msg_queue;
1252 if (buf) {
1253 msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1));
Allan Stephens0e659672010-12-31 18:59:32 +00001254 msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in);
Ying Xue3c294cb2012-11-15 11:34:45 +08001255 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
1256 l_ptr->unacked_window = 0;
1257 kfree_skb(buf);
1258 l_ptr->proto_msg_queue = NULL;
1259 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001260 }
1261
1262 /* Send one deferred data message, if send window not full: */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001263 buf = l_ptr->next_out;
1264 if (buf) {
1265 struct tipc_msg *msg = buf_msg(buf);
1266 u32 next = msg_seqno(msg);
Allan Stephensf9057302011-10-24 16:03:12 -04001267 u32 first = buf_seqno(l_ptr->first_out);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001268
1269 if (mod(next - first) < l_ptr->queue_limit[0]) {
1270 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001271 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Ying Xue3c294cb2012-11-15 11:34:45 +08001272 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
1273 if (msg_user(msg) == MSG_BUNDLER)
1274 msg_set_type(msg, CLOSED_MSG);
1275 l_ptr->next_out = buf->next;
1276 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001277 }
1278 }
Ying Xue3c294cb2012-11-15 11:34:45 +08001279 return 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001280}
1281
1282/*
1283 * push_queue(): push out the unsent messages of a link where
1284 * congestion has abated. Node is locked
1285 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001286void tipc_link_push_queue(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001287{
1288 u32 res;
1289
Ying Xue3c294cb2012-11-15 11:34:45 +08001290 if (tipc_bearer_blocked(l_ptr->b_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001291 return;
1292
1293 do {
Per Liden4323add2006-01-18 00:38:21 +01001294 res = tipc_link_push_packet(l_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -07001295 } while (!res);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001296}
1297
Allan Stephensd356eeb2006-06-25 23:40:01 -07001298static void link_reset_all(unsigned long addr)
1299{
David S. Miller6c000552008-09-02 23:38:32 -07001300 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001301 char addr_string[16];
1302 u32 i;
1303
1304 read_lock_bh(&tipc_net_lock);
1305 n_ptr = tipc_node_find((u32)addr);
1306 if (!n_ptr) {
1307 read_unlock_bh(&tipc_net_lock);
1308 return; /* node no longer exists */
1309 }
1310
1311 tipc_node_lock(n_ptr);
1312
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001313 pr_warn("Resetting all links to %s\n",
1314 tipc_addr_string_fill(addr_string, n_ptr->addr));
Allan Stephensd356eeb2006-06-25 23:40:01 -07001315
1316 for (i = 0; i < MAX_BEARERS; i++) {
1317 if (n_ptr->links[i]) {
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001318 link_print(n_ptr->links[i], "Resetting link\n");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001319 tipc_link_reset(n_ptr->links[i]);
1320 }
1321 }
1322
1323 tipc_node_unlock(n_ptr);
1324 read_unlock_bh(&tipc_net_lock);
1325}
1326
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001327static void link_retransmit_failure(struct tipc_link *l_ptr,
Paul Gortmakerae8509c2013-06-17 10:54:47 -04001328 struct sk_buff *buf)
Allan Stephensd356eeb2006-06-25 23:40:01 -07001329{
1330 struct tipc_msg *msg = buf_msg(buf);
1331
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001332 pr_warn("Retransmission failure on link <%s>\n", l_ptr->name);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001333
1334 if (l_ptr->addr) {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001335 /* Handle failure on standard link */
Allan Stephens8d64a5b2010-12-31 18:59:27 +00001336 link_print(l_ptr, "Resetting link\n");
Allan Stephensd356eeb2006-06-25 23:40:01 -07001337 tipc_link_reset(l_ptr);
1338
1339 } else {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001340 /* Handle failure on broadcast link */
David S. Miller6c000552008-09-02 23:38:32 -07001341 struct tipc_node *n_ptr;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001342 char addr_string[16];
1343
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001344 pr_info("Msg seq number: %u, ", msg_seqno(msg));
1345 pr_cont("Outstanding acks: %lu\n",
1346 (unsigned long) TIPC_SKB_CB(buf)->handle);
Jeff Garzik617dbea2006-10-03 16:25:34 -07001347
Allan Stephens01d83ed2011-01-18 13:53:16 -05001348 n_ptr = tipc_bclink_retransmit_to();
Allan Stephensd356eeb2006-06-25 23:40:01 -07001349 tipc_node_lock(n_ptr);
1350
Allan Stephensc68ca7b2010-05-11 14:30:12 +00001351 tipc_addr_string_fill(addr_string, n_ptr->addr);
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001352 pr_info("Broadcast link info for %s\n", addr_string);
Ying Xue389dd9b2012-11-16 13:51:30 +08001353 pr_info("Reception permitted: %d, Acked: %u\n",
1354 n_ptr->bclink.recv_permitted,
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001355 n_ptr->bclink.acked);
1356 pr_info("Last in: %u, Oos state: %u, Last sent: %u\n",
1357 n_ptr->bclink.last_in,
1358 n_ptr->bclink.oos_state,
1359 n_ptr->bclink.last_sent);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001360
1361 tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr);
1362
1363 tipc_node_unlock(n_ptr);
1364
1365 l_ptr->stale_count = 0;
1366 }
1367}
1368
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001369void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf,
Per Liden4323add2006-01-18 00:38:21 +01001370 u32 retransmits)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001371{
1372 struct tipc_msg *msg;
1373
Allan Stephensd356eeb2006-06-25 23:40:01 -07001374 if (!buf)
1375 return;
1376
1377 msg = buf_msg(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001378
Ying Xue3c294cb2012-11-15 11:34:45 +08001379 if (tipc_bearer_blocked(l_ptr->b_ptr)) {
Neil Hormanca509102010-03-15 07:58:45 +00001380 if (l_ptr->retransm_queue_size == 0) {
Allan Stephensd356eeb2006-06-25 23:40:01 -07001381 l_ptr->retransm_queue_head = msg_seqno(msg);
1382 l_ptr->retransm_queue_size = retransmits;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001383 } else {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001384 pr_err("Unexpected retransmit on link %s (qsize=%d)\n",
1385 l_ptr->name, l_ptr->retransm_queue_size);
Allan Stephensd356eeb2006-06-25 23:40:01 -07001386 }
Neil Hormanca509102010-03-15 07:58:45 +00001387 return;
Allan Stephensd356eeb2006-06-25 23:40:01 -07001388 } else {
Ying Xue3c294cb2012-11-15 11:34:45 +08001389 /* Detect repeated retransmit failures on unblocked bearer */
Allan Stephensd356eeb2006-06-25 23:40:01 -07001390 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1391 if (++l_ptr->stale_count > 100) {
1392 link_retransmit_failure(l_ptr, buf);
1393 return;
1394 }
1395 } else {
1396 l_ptr->last_retransmitted = msg_seqno(msg);
1397 l_ptr->stale_count = 1;
1398 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001399 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001400
Neil Hormanca509102010-03-15 07:58:45 +00001401 while (retransmits && (buf != l_ptr->next_out) && buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001402 msg = buf_msg(buf);
1403 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001404 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Ying Xue3c294cb2012-11-15 11:34:45 +08001405 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
1406 buf = buf->next;
1407 retransmits--;
1408 l_ptr->stats.retransmitted++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001409 }
Allan Stephensd356eeb2006-06-25 23:40:01 -07001410
Per Lidenb97bf3f2006-01-02 19:04:38 +01001411 l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0;
1412}
1413
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001414/**
Per Lidenb97bf3f2006-01-02 19:04:38 +01001415 * link_insert_deferred_queue - insert deferred messages back into receive chain
1416 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001417static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001418 struct sk_buff *buf)
1419{
1420 u32 seq_no;
1421
1422 if (l_ptr->oldest_deferred_in == NULL)
1423 return buf;
1424
Allan Stephensf9057302011-10-24 16:03:12 -04001425 seq_no = buf_seqno(l_ptr->oldest_deferred_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001426 if (seq_no == mod(l_ptr->next_in_no)) {
1427 l_ptr->newest_deferred_in->next = buf;
1428 buf = l_ptr->oldest_deferred_in;
1429 l_ptr->oldest_deferred_in = NULL;
1430 l_ptr->deferred_inqueue_sz = 0;
1431 }
1432 return buf;
1433}
1434
Allan Stephens85035562008-04-15 19:04:54 -07001435/**
1436 * link_recv_buf_validate - validate basic format of received message
1437 *
1438 * This routine ensures a TIPC message has an acceptable header, and at least
1439 * as much data as the header indicates it should. The routine also ensures
1440 * that the entire message header is stored in the main fragment of the message
1441 * buffer, to simplify future access to message header fields.
1442 *
1443 * Note: Having extra info present in the message header or data areas is OK.
1444 * TIPC will ignore the excess, under the assumption that it is optional info
1445 * introduced by a later release of the protocol.
1446 */
Allan Stephens85035562008-04-15 19:04:54 -07001447static int link_recv_buf_validate(struct sk_buff *buf)
1448{
1449 static u32 min_data_hdr_size[8] = {
Allan Stephens741d9eb2011-05-31 15:03:18 -04001450 SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE,
Allan Stephens85035562008-04-15 19:04:54 -07001451 MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE
1452 };
1453
1454 struct tipc_msg *msg;
1455 u32 tipc_hdr[2];
1456 u32 size;
1457 u32 hdr_size;
1458 u32 min_hdr_size;
1459
1460 if (unlikely(buf->len < MIN_H_SIZE))
1461 return 0;
1462
1463 msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr);
1464 if (msg == NULL)
1465 return 0;
1466
1467 if (unlikely(msg_version(msg) != TIPC_VERSION))
1468 return 0;
1469
1470 size = msg_size(msg);
1471 hdr_size = msg_hdr_sz(msg);
1472 min_hdr_size = msg_isdata(msg) ?
1473 min_data_hdr_size[msg_type(msg)] : INT_H_SIZE;
1474
1475 if (unlikely((hdr_size < min_hdr_size) ||
1476 (size < hdr_size) ||
1477 (buf->len < size) ||
1478 (size - hdr_size > TIPC_MAX_USER_MSG_SIZE)))
1479 return 0;
1480
1481 return pskb_may_pull(buf, hdr_size);
1482}
1483
Allan Stephensb02b69c2010-08-17 11:00:07 +00001484/**
1485 * tipc_recv_msg - process TIPC messages arriving from off-node
1486 * @head: pointer to message buffer chain
1487 * @tb_ptr: pointer to bearer message arrived on
1488 *
1489 * Invoked with no locks held. Bearer pointer must point to a valid bearer
1490 * structure (i.e. cannot be NULL), but bearer can be inactive.
1491 */
Allan Stephens2d627b92011-01-07 13:00:11 -05001492void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *b_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001493{
Per Liden4323add2006-01-18 00:38:21 +01001494 read_lock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001495 while (head) {
David S. Miller6c000552008-09-02 23:38:32 -07001496 struct tipc_node *n_ptr;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001497 struct tipc_link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001498 struct sk_buff *crs;
1499 struct sk_buff *buf = head;
Allan Stephens85035562008-04-15 19:04:54 -07001500 struct tipc_msg *msg;
1501 u32 seq_no;
1502 u32 ackd;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001503 u32 released = 0;
1504 int type;
1505
Per Lidenb97bf3f2006-01-02 19:04:38 +01001506 head = head->next;
Allan Stephens85035562008-04-15 19:04:54 -07001507
Allan Stephensb02b69c2010-08-17 11:00:07 +00001508 /* Ensure bearer is still enabled */
Allan Stephensb02b69c2010-08-17 11:00:07 +00001509 if (unlikely(!b_ptr->active))
Ying Xue3af390e2013-10-30 11:26:57 +08001510 goto discard;
Allan Stephensb02b69c2010-08-17 11:00:07 +00001511
Allan Stephens85035562008-04-15 19:04:54 -07001512 /* Ensure message is well-formed */
Allan Stephens85035562008-04-15 19:04:54 -07001513 if (unlikely(!link_recv_buf_validate(buf)))
Ying Xue3af390e2013-10-30 11:26:57 +08001514 goto discard;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001515
Allan Stephensfe13dda2008-04-15 19:03:23 -07001516 /* Ensure message data is a single contiguous unit */
Allan Stephens5f6d9122011-11-04 13:24:29 -04001517 if (unlikely(skb_linearize(buf)))
Ying Xue3af390e2013-10-30 11:26:57 +08001518 goto discard;
Allan Stephensfe13dda2008-04-15 19:03:23 -07001519
Allan Stephens85035562008-04-15 19:04:54 -07001520 /* Handle arrival of a non-unicast link message */
Allan Stephens85035562008-04-15 19:04:54 -07001521 msg = buf_msg(buf);
1522
Per Lidenb97bf3f2006-01-02 19:04:38 +01001523 if (unlikely(msg_non_seq(msg))) {
Allan Stephens1265a022008-06-04 17:32:35 -07001524 if (msg_user(msg) == LINK_CONFIG)
1525 tipc_disc_recv_msg(buf, b_ptr);
1526 else
1527 tipc_bclink_recv_pkt(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001528 continue;
1529 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001530
Allan Stephensed33a9c2011-04-05 15:15:04 -04001531 /* Discard unicast link messages destined for another node */
Allan Stephens26008242006-06-25 23:39:31 -07001532 if (unlikely(!msg_short(msg) &&
1533 (msg_destnode(msg) != tipc_own_addr)))
Ying Xue3af390e2013-10-30 11:26:57 +08001534 goto discard;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001535
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001536 /* Locate neighboring node that sent message */
Per Liden4323add2006-01-18 00:38:21 +01001537 n_ptr = tipc_node_find(msg_prevnode(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001538 if (unlikely(!n_ptr))
Ying Xue3af390e2013-10-30 11:26:57 +08001539 goto discard;
Per Liden4323add2006-01-18 00:38:21 +01001540 tipc_node_lock(n_ptr);
Allan Stephens85035562008-04-15 19:04:54 -07001541
Allan Stephens5a68d5e2010-08-17 11:00:16 +00001542 /* Locate unicast link endpoint that should handle message */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001543 l_ptr = n_ptr->links[b_ptr->identity];
Ying Xue3af390e2013-10-30 11:26:57 +08001544 if (unlikely(!l_ptr))
1545 goto unlock_discard;
Allan Stephens85035562008-04-15 19:04:54 -07001546
Allan Stephensb4b56102011-05-27 11:00:51 -04001547 /* Verify that communication with node is currently allowed */
Allan Stephensb4b56102011-05-27 11:00:51 -04001548 if ((n_ptr->block_setup & WAIT_PEER_DOWN) &&
1549 msg_user(msg) == LINK_PROTOCOL &&
1550 (msg_type(msg) == RESET_MSG ||
1551 msg_type(msg) == ACTIVATE_MSG) &&
1552 !msg_redundant_link(msg))
1553 n_ptr->block_setup &= ~WAIT_PEER_DOWN;
1554
Ying Xue3af390e2013-10-30 11:26:57 +08001555 if (n_ptr->block_setup)
1556 goto unlock_discard;
Allan Stephensb4b56102011-05-27 11:00:51 -04001557
Allan Stephens85035562008-04-15 19:04:54 -07001558 /* Validate message sequence number info */
Allan Stephens85035562008-04-15 19:04:54 -07001559 seq_no = msg_seqno(msg);
1560 ackd = msg_ack(msg);
1561
1562 /* Release acked messages */
Ying Xue389dd9b2012-11-16 13:51:30 +08001563 if (n_ptr->bclink.recv_permitted)
Allan Stephens365595912011-10-24 15:26:24 -04001564 tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001565
1566 crs = l_ptr->first_out;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001567 while ((crs != l_ptr->next_out) &&
Allan Stephensf9057302011-10-24 16:03:12 -04001568 less_eq(buf_seqno(crs), ackd)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001569 struct sk_buff *next = crs->next;
1570
Allan Stephens5f6d9122011-11-04 13:24:29 -04001571 kfree_skb(crs);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001572 crs = next;
1573 released++;
1574 }
1575 if (released) {
1576 l_ptr->first_out = crs;
1577 l_ptr->out_queue_size -= released;
1578 }
Allan Stephens85035562008-04-15 19:04:54 -07001579
1580 /* Try sending any messages link endpoint has pending */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001581 if (unlikely(l_ptr->next_out))
Per Liden4323add2006-01-18 00:38:21 +01001582 tipc_link_push_queue(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001583 if (unlikely(!list_empty(&l_ptr->waiting_ports)))
Per Liden4323add2006-01-18 00:38:21 +01001584 tipc_link_wakeup_ports(l_ptr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001585 if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) {
1586 l_ptr->stats.sent_acks++;
Per Liden4323add2006-01-18 00:38:21 +01001587 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001588 }
1589
Allan Stephens85035562008-04-15 19:04:54 -07001590 /* Now (finally!) process the incoming message */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001591protocol_check:
Ying Xue3af390e2013-10-30 11:26:57 +08001592 if (unlikely(!link_working_working(l_ptr))) {
1593 if (msg_user(msg) == LINK_PROTOCOL) {
1594 link_recv_proto_msg(l_ptr, buf);
1595 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01001596 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001597 continue;
1598 }
Ying Xue3af390e2013-10-30 11:26:57 +08001599
1600 /* Traffic message. Conditionally activate link */
1601 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1602
1603 if (link_working_working(l_ptr)) {
1604 /* Re-insert buffer in front of queue */
1605 buf->next = head;
1606 head = buf;
1607 tipc_node_unlock(n_ptr);
1608 continue;
1609 }
1610 goto unlock_discard;
1611 }
1612
1613 /* Link is now in state WORKING_WORKING */
1614 if (unlikely(seq_no != mod(l_ptr->next_in_no))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001615 link_handle_out_of_seq_msg(l_ptr, buf);
1616 head = link_insert_deferred_queue(l_ptr, head);
Per Liden4323add2006-01-18 00:38:21 +01001617 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001618 continue;
1619 }
Ying Xue3af390e2013-10-30 11:26:57 +08001620 l_ptr->next_in_no++;
1621 if (unlikely(l_ptr->oldest_deferred_in))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001622 head = link_insert_deferred_queue(l_ptr, head);
Ying Xue3af390e2013-10-30 11:26:57 +08001623deliver:
1624 if (likely(msg_isdata(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01001625 tipc_node_unlock(n_ptr);
Ying Xue3af390e2013-10-30 11:26:57 +08001626 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001627 continue;
1628 }
Ying Xue3af390e2013-10-30 11:26:57 +08001629 switch (msg_user(msg)) {
1630 int ret;
1631 case MSG_BUNDLER:
1632 l_ptr->stats.recv_bundles++;
1633 l_ptr->stats.recv_bundled += msg_msgcnt(msg);
1634 tipc_node_unlock(n_ptr);
1635 tipc_link_recv_bundle(buf);
1636 continue;
1637 case NAME_DISTRIBUTOR:
1638 n_ptr->bclink.recv_permitted = true;
1639 tipc_node_unlock(n_ptr);
1640 tipc_named_recv(buf);
1641 continue;
1642 case BCAST_PROTOCOL:
1643 tipc_link_recv_sync(n_ptr, buf);
Per Liden4323add2006-01-18 00:38:21 +01001644 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001645 continue;
Ying Xue3af390e2013-10-30 11:26:57 +08001646 case CONN_MANAGER:
1647 tipc_node_unlock(n_ptr);
1648 tipc_port_recv_proto_msg(buf);
1649 continue;
1650 case MSG_FRAGMENTER:
1651 l_ptr->stats.recv_fragments++;
1652 ret = tipc_link_recv_fragment(&l_ptr->defragm_buf,
1653 &buf, &msg);
1654 if (ret == 1) {
1655 l_ptr->stats.recv_fragmented++;
1656 goto deliver;
1657 }
1658 if (ret == -1)
1659 l_ptr->next_in_no--;
1660 break;
1661 case CHANGEOVER_PROTOCOL:
1662 type = msg_type(msg);
1663 if (link_recv_changeover_msg(&l_ptr, &buf)) {
1664 msg = buf_msg(buf);
1665 seq_no = msg_seqno(msg);
1666 if (type == ORIGINAL_MSG)
1667 goto deliver;
1668 goto protocol_check;
1669 }
1670 break;
1671 default:
1672 kfree_skb(buf);
1673 buf = NULL;
1674 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001675 }
Per Liden4323add2006-01-18 00:38:21 +01001676 tipc_node_unlock(n_ptr);
Ying Xue3af390e2013-10-30 11:26:57 +08001677 tipc_net_route_msg(buf);
1678 continue;
1679unlock_discard:
1680
1681 tipc_node_unlock(n_ptr);
1682discard:
Allan Stephens5f6d9122011-11-04 13:24:29 -04001683 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001684 }
Per Liden4323add2006-01-18 00:38:21 +01001685 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001686}
1687
Ben Hutchings2c530402012-07-10 10:55:09 +00001688/**
Allan Stephens8809b252011-10-25 10:44:35 -04001689 * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue
1690 *
1691 * Returns increase in queue length (i.e. 0 or 1)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001692 */
Allan Stephens8809b252011-10-25 10:44:35 -04001693u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail,
Per Liden4323add2006-01-18 00:38:21 +01001694 struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001695{
Allan Stephens8809b252011-10-25 10:44:35 -04001696 struct sk_buff *queue_buf;
1697 struct sk_buff **prev;
Allan Stephensf9057302011-10-24 16:03:12 -04001698 u32 seq_no = buf_seqno(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001699
1700 buf->next = NULL;
1701
1702 /* Empty queue ? */
1703 if (*head == NULL) {
1704 *head = *tail = buf;
1705 return 1;
1706 }
1707
1708 /* Last ? */
Allan Stephensf9057302011-10-24 16:03:12 -04001709 if (less(buf_seqno(*tail), seq_no)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001710 (*tail)->next = buf;
1711 *tail = buf;
1712 return 1;
1713 }
1714
Allan Stephens8809b252011-10-25 10:44:35 -04001715 /* Locate insertion point in queue, then insert; discard if duplicate */
1716 prev = head;
1717 queue_buf = *head;
1718 for (;;) {
1719 u32 curr_seqno = buf_seqno(queue_buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001720
Allan Stephens8809b252011-10-25 10:44:35 -04001721 if (seq_no == curr_seqno) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04001722 kfree_skb(buf);
Allan Stephens8809b252011-10-25 10:44:35 -04001723 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001724 }
Allan Stephens8809b252011-10-25 10:44:35 -04001725
1726 if (less(seq_no, curr_seqno))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001727 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001728
Allan Stephens8809b252011-10-25 10:44:35 -04001729 prev = &queue_buf->next;
1730 queue_buf = queue_buf->next;
1731 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001732
Allan Stephens8809b252011-10-25 10:44:35 -04001733 buf->next = queue_buf;
1734 *prev = buf;
1735 return 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001736}
1737
Allan Stephens8809b252011-10-25 10:44:35 -04001738/*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001739 * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet
1740 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001741static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01001742 struct sk_buff *buf)
1743{
Allan Stephensf9057302011-10-24 16:03:12 -04001744 u32 seq_no = buf_seqno(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001745
1746 if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) {
1747 link_recv_proto_msg(l_ptr, buf);
1748 return;
1749 }
1750
Per Lidenb97bf3f2006-01-02 19:04:38 +01001751 /* Record OOS packet arrival (force mismatch on next timeout) */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001752 l_ptr->checkpoint--;
1753
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001754 /*
Per Lidenb97bf3f2006-01-02 19:04:38 +01001755 * Discard packet if a duplicate; otherwise add it to deferred queue
1756 * and notify peer of gap as per protocol specification
1757 */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001758 if (less(seq_no, mod(l_ptr->next_in_no))) {
1759 l_ptr->stats.duplicates++;
Allan Stephens5f6d9122011-11-04 13:24:29 -04001760 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001761 return;
1762 }
1763
Per Liden4323add2006-01-18 00:38:21 +01001764 if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in,
1765 &l_ptr->newest_deferred_in, buf)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001766 l_ptr->deferred_inqueue_sz++;
1767 l_ptr->stats.deferred_recv++;
1768 if ((l_ptr->deferred_inqueue_sz % 16) == 1)
Per Liden4323add2006-01-18 00:38:21 +01001769 tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001770 } else
1771 l_ptr->stats.duplicates++;
1772}
1773
1774/*
1775 * Send protocol message to the other endpoint.
1776 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001777void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ,
Paul Gortmakerae8509c2013-06-17 10:54:47 -04001778 int probe_msg, u32 gap, u32 tolerance,
1779 u32 priority, u32 ack_mtu)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001780{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08001781 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001782 struct tipc_msg *msg = l_ptr->pmsg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001783 u32 msg_size = sizeof(l_ptr->proto_msg);
Allan Stephens75f0aa42011-02-28 15:30:20 -05001784 int r_flag;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001785
Allan Stephens92d2c902011-10-25 11:20:26 -04001786 /* Discard any previous message that was deferred due to congestion */
Allan Stephens92d2c902011-10-25 11:20:26 -04001787 if (l_ptr->proto_msg_queue) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04001788 kfree_skb(l_ptr->proto_msg_queue);
Allan Stephens92d2c902011-10-25 11:20:26 -04001789 l_ptr->proto_msg_queue = NULL;
1790 }
1791
Per Lidenb97bf3f2006-01-02 19:04:38 +01001792 if (link_blocked(l_ptr))
1793 return;
Allan Stephensb4b56102011-05-27 11:00:51 -04001794
1795 /* Abort non-RESET send if communication with node is prohibited */
Allan Stephensb4b56102011-05-27 11:00:51 -04001796 if ((l_ptr->owner->block_setup) && (msg_typ != RESET_MSG))
1797 return;
1798
Allan Stephens92d2c902011-10-25 11:20:26 -04001799 /* Create protocol message with "out-of-sequence" sequence number */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001800 msg_set_type(msg, msg_typ);
1801 msg_set_net_plane(msg, l_ptr->b_ptr->net_plane);
Allan Stephens7a54d4a2011-10-27 14:17:53 -04001802 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Liden4323add2006-01-18 00:38:21 +01001803 msg_set_last_bcast(msg, tipc_bclink_get_last_sent());
Per Lidenb97bf3f2006-01-02 19:04:38 +01001804
1805 if (msg_typ == STATE_MSG) {
1806 u32 next_sent = mod(l_ptr->next_out_no);
1807
Per Liden4323add2006-01-18 00:38:21 +01001808 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01001809 return;
1810 if (l_ptr->next_out)
Allan Stephensf9057302011-10-24 16:03:12 -04001811 next_sent = buf_seqno(l_ptr->next_out);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001812 msg_set_next_sent(msg, next_sent);
1813 if (l_ptr->oldest_deferred_in) {
Allan Stephensf9057302011-10-24 16:03:12 -04001814 u32 rec = buf_seqno(l_ptr->oldest_deferred_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001815 gap = mod(rec - mod(l_ptr->next_in_no));
1816 }
1817 msg_set_seq_gap(msg, gap);
1818 if (gap)
1819 l_ptr->stats.sent_nacks++;
1820 msg_set_link_tolerance(msg, tolerance);
1821 msg_set_linkprio(msg, priority);
1822 msg_set_max_pkt(msg, ack_mtu);
1823 msg_set_ack(msg, mod(l_ptr->next_in_no - 1));
1824 msg_set_probe(msg, probe_msg != 0);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001825 if (probe_msg) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001826 u32 mtu = l_ptr->max_pkt;
1827
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001828 if ((mtu < l_ptr->max_pkt_target) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001829 link_working_working(l_ptr) &&
1830 l_ptr->fsm_msg_cnt) {
1831 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001832 if (l_ptr->max_pkt_probes == 10) {
1833 l_ptr->max_pkt_target = (msg_size - 4);
1834 l_ptr->max_pkt_probes = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001835 msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001836 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001837 l_ptr->max_pkt_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001838 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001839
1840 l_ptr->stats.sent_probes++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001841 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001842 l_ptr->stats.sent_states++;
1843 } else { /* RESET_MSG or ACTIVATE_MSG */
1844 msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1));
1845 msg_set_seq_gap(msg, 0);
1846 msg_set_next_sent(msg, 1);
Allan Stephensf23d9bf2011-01-18 15:15:34 -05001847 msg_set_probe(msg, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001848 msg_set_link_tolerance(msg, l_ptr->tolerance);
1849 msg_set_linkprio(msg, l_ptr->priority);
1850 msg_set_max_pkt(msg, l_ptr->max_pkt_target);
1851 }
1852
Allan Stephens75f0aa42011-02-28 15:30:20 -05001853 r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr));
1854 msg_set_redundant_link(msg, r_flag);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001855 msg_set_linkprio(msg, l_ptr->priority);
Allan Stephens92d2c902011-10-25 11:20:26 -04001856 msg_set_size(msg, msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001857
1858 msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2)));
1859
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001860 buf = tipc_buf_acquire(msg_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001861 if (!buf)
1862 return;
1863
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001864 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
Ying Xue796c75d2013-06-17 10:54:48 -04001865 buf->priority = TC_PRIO_CONTROL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001866
Ying Xue3c294cb2012-11-15 11:34:45 +08001867 /* Defer message if bearer is already blocked */
1868 if (tipc_bearer_blocked(l_ptr->b_ptr)) {
Allan Stephens92d2c902011-10-25 11:20:26 -04001869 l_ptr->proto_msg_queue = buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001870 return;
1871 }
1872
Ying Xue3c294cb2012-11-15 11:34:45 +08001873 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
Allan Stephens92d2c902011-10-25 11:20:26 -04001874 l_ptr->unacked_window = 0;
Allan Stephens5f6d9122011-11-04 13:24:29 -04001875 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001876}
1877
1878/*
1879 * Receive protocol message :
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001880 * Note that network plane id propagates through the network, and may
1881 * change at any time. The node with lowest address rules
Per Lidenb97bf3f2006-01-02 19:04:38 +01001882 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05001883static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001884{
1885 u32 rec_gap = 0;
1886 u32 max_pkt_info;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001887 u32 max_pkt_ack;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001888 u32 msg_tol;
1889 struct tipc_msg *msg = buf_msg(buf);
1890
Per Lidenb97bf3f2006-01-02 19:04:38 +01001891 if (link_blocked(l_ptr))
1892 goto exit;
1893
1894 /* record unnumbered packet arrival (force mismatch on next timeout) */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001895 l_ptr->checkpoint--;
1896
1897 if (l_ptr->b_ptr->net_plane != msg_net_plane(msg))
1898 if (tipc_own_addr > msg_prevnode(msg))
1899 l_ptr->b_ptr->net_plane = msg_net_plane(msg);
1900
1901 l_ptr->owner->permit_changeover = msg_redundant_link(msg);
1902
1903 switch (msg_type(msg)) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001904
Per Lidenb97bf3f2006-01-02 19:04:38 +01001905 case RESET_MSG:
Allan Stephensa686e682008-06-04 17:29:39 -07001906 if (!link_working_unknown(l_ptr) &&
1907 (l_ptr->peer_session != INVALID_SESSION)) {
Allan Stephens641c2182011-04-07 09:54:43 -04001908 if (less_eq(msg_session(msg), l_ptr->peer_session))
1909 break; /* duplicate or old reset: ignore */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001910 }
Allan Stephensb4b56102011-05-27 11:00:51 -04001911
1912 if (!msg_redundant_link(msg) && (link_working_working(l_ptr) ||
1913 link_working_unknown(l_ptr))) {
1914 /*
1915 * peer has lost contact -- don't allow peer's links
1916 * to reactivate before we recognize loss & clean up
1917 */
1918 l_ptr->owner->block_setup = WAIT_NODE_DOWN;
1919 }
1920
Allan Stephens47361c82011-10-26 10:55:16 -04001921 link_state_event(l_ptr, RESET_MSG);
1922
Per Lidenb97bf3f2006-01-02 19:04:38 +01001923 /* fall thru' */
1924 case ACTIVATE_MSG:
1925 /* Update link settings according other endpoint's values */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001926 strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg));
1927
Allan Stephens2db99832010-12-31 18:59:33 +00001928 msg_tol = msg_link_tolerance(msg);
1929 if (msg_tol > l_ptr->tolerance)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001930 link_set_supervision_props(l_ptr, msg_tol);
1931
1932 if (msg_linkprio(msg) > l_ptr->priority)
1933 l_ptr->priority = msg_linkprio(msg);
1934
1935 max_pkt_info = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001936 if (max_pkt_info) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001937 if (max_pkt_info < l_ptr->max_pkt_target)
1938 l_ptr->max_pkt_target = max_pkt_info;
1939 if (l_ptr->max_pkt > l_ptr->max_pkt_target)
1940 l_ptr->max_pkt = l_ptr->max_pkt_target;
1941 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001942 l_ptr->max_pkt = l_ptr->max_pkt_target;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001943 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001944
Allan Stephens4d753132011-10-25 12:19:05 -04001945 /* Synchronize broadcast link info, if not done previously */
Allan Stephens7a54d4a2011-10-27 14:17:53 -04001946 if (!tipc_node_is_up(l_ptr->owner)) {
1947 l_ptr->owner->bclink.last_sent =
1948 l_ptr->owner->bclink.last_in =
1949 msg_last_bcast(msg);
1950 l_ptr->owner->bclink.oos_state = 0;
1951 }
Allan Stephens4d753132011-10-25 12:19:05 -04001952
Per Lidenb97bf3f2006-01-02 19:04:38 +01001953 l_ptr->peer_session = msg_session(msg);
1954 l_ptr->peer_bearer_id = msg_bearer_id(msg);
Allan Stephens47361c82011-10-26 10:55:16 -04001955
1956 if (msg_type(msg) == ACTIVATE_MSG)
1957 link_state_event(l_ptr, ACTIVATE_MSG);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001958 break;
1959 case STATE_MSG:
1960
Allan Stephens2db99832010-12-31 18:59:33 +00001961 msg_tol = msg_link_tolerance(msg);
1962 if (msg_tol)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001963 link_set_supervision_props(l_ptr, msg_tol);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001964
1965 if (msg_linkprio(msg) &&
Per Lidenb97bf3f2006-01-02 19:04:38 +01001966 (msg_linkprio(msg) != l_ptr->priority)) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04001967 pr_warn("%s<%s>, priority change %u->%u\n",
1968 link_rst_msg, l_ptr->name, l_ptr->priority,
1969 msg_linkprio(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01001970 l_ptr->priority = msg_linkprio(msg);
Per Liden4323add2006-01-18 00:38:21 +01001971 tipc_link_reset(l_ptr); /* Enforce change to take effect */
Per Lidenb97bf3f2006-01-02 19:04:38 +01001972 break;
1973 }
1974 link_state_event(l_ptr, TRAFFIC_MSG_EVT);
1975 l_ptr->stats.recv_states++;
1976 if (link_reset_unknown(l_ptr))
1977 break;
1978
1979 if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001980 rec_gap = mod(msg_next_sent(msg) -
Per Lidenb97bf3f2006-01-02 19:04:38 +01001981 mod(l_ptr->next_in_no));
1982 }
1983
1984 max_pkt_ack = msg_max_pkt(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001985 if (max_pkt_ack > l_ptr->max_pkt) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001986 l_ptr->max_pkt = max_pkt_ack;
1987 l_ptr->max_pkt_probes = 0;
1988 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001989
1990 max_pkt_ack = 0;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001991 if (msg_probe(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01001992 l_ptr->stats.recv_probes++;
Allan Stephensa0168922010-12-31 18:59:35 +00001993 if (msg_size(msg) > sizeof(l_ptr->proto_msg))
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001994 max_pkt_ack = msg_size(msg);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001995 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001996
1997 /* Protocol message before retransmits, reduce loss risk */
Ying Xue389dd9b2012-11-16 13:51:30 +08001998 if (l_ptr->owner->bclink.recv_permitted)
Allan Stephens7a54d4a2011-10-27 14:17:53 -04001999 tipc_bclink_update_link_state(l_ptr->owner,
2000 msg_last_bcast(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002001
2002 if (rec_gap || (msg_probe(msg))) {
Per Liden4323add2006-01-18 00:38:21 +01002003 tipc_link_send_proto_msg(l_ptr, STATE_MSG,
2004 0, rec_gap, 0, 0, max_pkt_ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002005 }
2006 if (msg_seq_gap(msg)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002007 l_ptr->stats.recv_nacks++;
Per Liden4323add2006-01-18 00:38:21 +01002008 tipc_link_retransmit(l_ptr, l_ptr->first_out,
2009 msg_seq_gap(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002010 }
2011 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002012 }
2013exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -04002014 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002015}
2016
2017
2018/*
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002019 * tipc_link_tunnel(): Send one message via a link belonging to
Per Lidenb97bf3f2006-01-02 19:04:38 +01002020 * another bearer. Owner node is locked.
2021 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002022static void tipc_link_tunnel(struct tipc_link *l_ptr,
Paul Gortmakerae8509c2013-06-17 10:54:47 -04002023 struct tipc_msg *tunnel_hdr, struct tipc_msg *msg,
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002024 u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002025{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002026 struct tipc_link *tunnel;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002027 struct sk_buff *buf;
2028 u32 length = msg_size(msg);
2029
2030 tunnel = l_ptr->owner->active_links[selector & 1];
Allan Stephens5392d642006-06-25 23:52:50 -07002031 if (!tipc_link_is_up(tunnel)) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002032 pr_warn("%stunnel link no longer available\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002033 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002034 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002035 msg_set_size(tunnel_hdr, length + INT_H_SIZE);
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002036 buf = tipc_buf_acquire(length + INT_H_SIZE);
Allan Stephens5392d642006-06-25 23:52:50 -07002037 if (!buf) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002038 pr_warn("%sunable to send tunnel msg\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002039 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002040 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002041 skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE);
2042 skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length);
Per Liden4323add2006-01-18 00:38:21 +01002043 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002044}
2045
2046
2047
2048/*
2049 * changeover(): Send whole message queue via the remaining link
2050 * Owner node is locked.
2051 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002052void tipc_link_changeover(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002053{
2054 u32 msgcount = l_ptr->out_queue_size;
2055 struct sk_buff *crs = l_ptr->first_out;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002056 struct tipc_link *tunnel = l_ptr->owner->active_links[0];
Per Lidenb97bf3f2006-01-02 19:04:38 +01002057 struct tipc_msg tunnel_hdr;
Allan Stephens5392d642006-06-25 23:52:50 -07002058 int split_bundles;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002059
2060 if (!tunnel)
2061 return;
2062
Allan Stephens5392d642006-06-25 23:52:50 -07002063 if (!l_ptr->owner->permit_changeover) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002064 pr_warn("%speer did not permit changeover\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002065 return;
Allan Stephens5392d642006-06-25 23:52:50 -07002066 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002067
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002068 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002069 ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002070 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2071 msg_set_msgcnt(&tunnel_hdr, msgcount);
Allan Stephensf1310722006-06-25 23:51:37 -07002072
Per Lidenb97bf3f2006-01-02 19:04:38 +01002073 if (!l_ptr->first_out) {
2074 struct sk_buff *buf;
2075
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002076 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002077 if (buf) {
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002078 skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002079 msg_set_size(&tunnel_hdr, INT_H_SIZE);
Per Liden4323add2006-01-18 00:38:21 +01002080 tipc_link_send_buf(tunnel, buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002081 } else {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002082 pr_warn("%sunable to send changeover msg\n",
2083 link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002084 }
2085 return;
2086 }
Allan Stephensf1310722006-06-25 23:51:37 -07002087
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002088 split_bundles = (l_ptr->owner->active_links[0] !=
Allan Stephens5392d642006-06-25 23:52:50 -07002089 l_ptr->owner->active_links[1]);
2090
Per Lidenb97bf3f2006-01-02 19:04:38 +01002091 while (crs) {
2092 struct tipc_msg *msg = buf_msg(crs);
2093
2094 if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002095 struct tipc_msg *m = msg_get_wrapped(msg);
Allan Stephens0e659672010-12-31 18:59:32 +00002096 unchar *pos = (unchar *)m;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002097
Florian Westphald788d802007-08-02 19:28:06 -07002098 msgcount = msg_msgcnt(msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002099 while (msgcount--) {
Allan Stephens0e659672010-12-31 18:59:32 +00002100 msg_set_seqno(m, msg_seqno(msg));
Per Liden4323add2006-01-18 00:38:21 +01002101 tipc_link_tunnel(l_ptr, &tunnel_hdr, m,
2102 msg_link_selector(m));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002103 pos += align(msg_size(m));
2104 m = (struct tipc_msg *)pos;
2105 }
2106 } else {
Per Liden4323add2006-01-18 00:38:21 +01002107 tipc_link_tunnel(l_ptr, &tunnel_hdr, msg,
2108 msg_link_selector(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002109 }
2110 crs = crs->next;
2111 }
2112}
2113
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002114void tipc_link_send_duplicate(struct tipc_link *l_ptr, struct tipc_link *tunnel)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002115{
2116 struct sk_buff *iter;
2117 struct tipc_msg tunnel_hdr;
2118
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002119 tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL,
Allan Stephens75715212008-06-04 17:37:34 -07002120 DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002121 msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size);
2122 msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id);
2123 iter = l_ptr->first_out;
2124 while (iter) {
2125 struct sk_buff *outbuf;
2126 struct tipc_msg *msg = buf_msg(iter);
2127 u32 length = msg_size(msg);
2128
2129 if (msg_user(msg) == MSG_BUNDLER)
2130 msg_set_type(msg, CLOSED_MSG);
2131 msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002132 msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002133 msg_set_size(&tunnel_hdr, length + INT_H_SIZE);
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002134 outbuf = tipc_buf_acquire(length + INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002135 if (outbuf == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002136 pr_warn("%sunable to send duplicate msg\n",
2137 link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002138 return;
2139 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002140 skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE);
2141 skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data,
2142 length);
Per Liden4323add2006-01-18 00:38:21 +01002143 tipc_link_send_buf(tunnel, outbuf);
2144 if (!tipc_link_is_up(l_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002145 return;
2146 iter = iter->next;
2147 }
2148}
2149
Per Lidenb97bf3f2006-01-02 19:04:38 +01002150/**
2151 * buf_extract - extracts embedded TIPC message from another message
2152 * @skb: encapsulating message buffer
2153 * @from_pos: offset to extract from
2154 *
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002155 * Returns a new message buffer containing an embedded message. The
Per Lidenb97bf3f2006-01-02 19:04:38 +01002156 * encapsulating message itself is left unchanged.
2157 */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002158static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos)
2159{
2160 struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos);
2161 u32 size = msg_size(msg);
2162 struct sk_buff *eb;
2163
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002164 eb = tipc_buf_acquire(size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002165 if (eb)
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002166 skb_copy_to_linear_data(eb, msg, size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002167 return eb;
2168}
2169
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002170/*
Per Lidenb97bf3f2006-01-02 19:04:38 +01002171 * link_recv_changeover_msg(): Receive tunneled packet sent
2172 * via other link. Node is locked. Return extracted buffer.
2173 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002174static int link_recv_changeover_msg(struct tipc_link **l_ptr,
Per Lidenb97bf3f2006-01-02 19:04:38 +01002175 struct sk_buff **buf)
2176{
2177 struct sk_buff *tunnel_buf = *buf;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002178 struct tipc_link *dest_link;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002179 struct tipc_msg *msg;
2180 struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf);
2181 u32 msg_typ = msg_type(tunnel_msg);
2182 u32 msg_count = msg_msgcnt(tunnel_msg);
Dan Carpentercb4b102f2013-05-06 08:28:41 +00002183 u32 bearer_id = msg_bearer_id(tunnel_msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002184
Dan Carpentercb4b102f2013-05-06 08:28:41 +00002185 if (bearer_id >= MAX_BEARERS)
2186 goto exit;
2187 dest_link = (*l_ptr)->owner->links[bearer_id];
Allan Stephensb29f1422010-12-31 18:59:25 +00002188 if (!dest_link)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002189 goto exit;
Allan Stephensf1310722006-06-25 23:51:37 -07002190 if (dest_link == *l_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002191 pr_err("Unexpected changeover message on link <%s>\n",
2192 (*l_ptr)->name);
Allan Stephensf1310722006-06-25 23:51:37 -07002193 goto exit;
2194 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002195 *l_ptr = dest_link;
2196 msg = msg_get_wrapped(tunnel_msg);
2197
2198 if (msg_typ == DUPLICATE_MSG) {
Allan Stephensb29f1422010-12-31 18:59:25 +00002199 if (less(msg_seqno(msg), mod(dest_link->next_in_no)))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002200 goto exit;
Allan Stephens0e659672010-12-31 18:59:32 +00002201 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002202 if (*buf == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002203 pr_warn("%sduplicate msg dropped\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002204 goto exit;
2205 }
Allan Stephens5f6d9122011-11-04 13:24:29 -04002206 kfree_skb(tunnel_buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002207 return 1;
2208 }
2209
2210 /* First original message ?: */
Per Liden4323add2006-01-18 00:38:21 +01002211 if (tipc_link_is_up(dest_link)) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002212 pr_info("%s<%s>, changeover initiated by peer\n", link_rst_msg,
2213 dest_link->name);
Per Liden4323add2006-01-18 00:38:21 +01002214 tipc_link_reset(dest_link);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002215 dest_link->exp_msg_count = msg_count;
2216 if (!msg_count)
2217 goto exit;
2218 } else if (dest_link->exp_msg_count == START_CHANGEOVER) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002219 dest_link->exp_msg_count = msg_count;
2220 if (!msg_count)
2221 goto exit;
2222 }
2223
2224 /* Receive original message */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002225 if (dest_link->exp_msg_count == 0) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002226 pr_warn("%sgot too many tunnelled messages\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002227 goto exit;
2228 }
2229 dest_link->exp_msg_count--;
2230 if (less(msg_seqno(msg), dest_link->reset_checkpoint)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002231 goto exit;
2232 } else {
2233 *buf = buf_extract(tunnel_buf, INT_H_SIZE);
2234 if (*buf != NULL) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04002235 kfree_skb(tunnel_buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002236 return 1;
2237 } else {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002238 pr_warn("%soriginal msg dropped\n", link_co_err);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002239 }
2240 }
2241exit:
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002242 *buf = NULL;
Allan Stephens5f6d9122011-11-04 13:24:29 -04002243 kfree_skb(tunnel_buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002244 return 0;
2245}
2246
2247/*
2248 * Bundler functionality:
2249 */
Per Liden4323add2006-01-18 00:38:21 +01002250void tipc_link_recv_bundle(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002251{
2252 u32 msgcount = msg_msgcnt(buf_msg(buf));
2253 u32 pos = INT_H_SIZE;
2254 struct sk_buff *obuf;
2255
Per Lidenb97bf3f2006-01-02 19:04:38 +01002256 while (msgcount--) {
2257 obuf = buf_extract(buf, pos);
2258 if (obuf == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002259 pr_warn("Link unable to unbundle message(s)\n");
Allan Stephensa10bd922006-06-25 23:52:17 -07002260 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07002261 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01002262 pos += align(msg_size(buf_msg(obuf)));
Per Liden4323add2006-01-18 00:38:21 +01002263 tipc_net_route_msg(obuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002264 }
Allan Stephens5f6d9122011-11-04 13:24:29 -04002265 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002266}
2267
2268/*
2269 * Fragmentation/defragmentation:
2270 */
2271
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002272/*
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002273 * link_send_long_buf: Entry for buffers needing fragmentation.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002274 * The buffer is complete, inclusive total message length.
Per Lidenb97bf3f2006-01-02 19:04:38 +01002275 * Returns user data length.
2276 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002277static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002278{
Allan Stephens77561552011-04-17 13:06:23 -04002279 struct sk_buff *buf_chain = NULL;
2280 struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002281 struct tipc_msg *inmsg = buf_msg(buf);
2282 struct tipc_msg fragm_hdr;
2283 u32 insize = msg_size(inmsg);
2284 u32 dsz = msg_data_sz(inmsg);
2285 unchar *crs = buf->data;
2286 u32 rest = insize;
Allan Stephens15e979d2010-05-11 14:30:10 +00002287 u32 pack_sz = l_ptr->max_pkt;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002288 u32 fragm_sz = pack_sz - INT_H_SIZE;
Allan Stephens77561552011-04-17 13:06:23 -04002289 u32 fragm_no = 0;
Allan Stephens9c396a72008-06-04 17:36:58 -07002290 u32 destaddr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002291
2292 if (msg_short(inmsg))
2293 destaddr = l_ptr->addr;
Allan Stephens9c396a72008-06-04 17:36:58 -07002294 else
2295 destaddr = msg_destnode(inmsg);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002296
Per Lidenb97bf3f2006-01-02 19:04:38 +01002297 /* Prepare reusable fragment header: */
Allan Stephensc68ca7b2010-05-11 14:30:12 +00002298 tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT,
Allan Stephens75715212008-06-04 17:37:34 -07002299 INT_H_SIZE, destaddr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002300
2301 /* Chop up message: */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002302 while (rest > 0) {
2303 struct sk_buff *fragm;
2304
2305 if (rest <= fragm_sz) {
2306 fragm_sz = rest;
2307 msg_set_type(&fragm_hdr, LAST_FRAGMENT);
2308 }
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002309 fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002310 if (fragm == NULL) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04002311 kfree_skb(buf);
Allan Stephens77561552011-04-17 13:06:23 -04002312 while (buf_chain) {
2313 buf = buf_chain;
2314 buf_chain = buf_chain->next;
Allan Stephens5f6d9122011-11-04 13:24:29 -04002315 kfree_skb(buf);
Allan Stephens77561552011-04-17 13:06:23 -04002316 }
2317 return -ENOMEM;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002318 }
2319 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
Allan Stephens77561552011-04-17 13:06:23 -04002320 fragm_no++;
2321 msg_set_fragm_no(&fragm_hdr, fragm_no);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002322 skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE);
2323 skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs,
2324 fragm_sz);
Allan Stephens77561552011-04-17 13:06:23 -04002325 buf_chain_tail->next = fragm;
2326 buf_chain_tail = fragm;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002327
Per Lidenb97bf3f2006-01-02 19:04:38 +01002328 rest -= fragm_sz;
2329 crs += fragm_sz;
2330 msg_set_type(&fragm_hdr, FRAGMENT);
2331 }
Allan Stephens5f6d9122011-11-04 13:24:29 -04002332 kfree_skb(buf);
Allan Stephens77561552011-04-17 13:06:23 -04002333
2334 /* Append chain of fragments to send queue & send them */
Allan Stephens77561552011-04-17 13:06:23 -04002335 l_ptr->long_msg_seq_no++;
2336 link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no);
2337 l_ptr->stats.sent_fragments += fragm_no;
2338 l_ptr->stats.sent_fragmented++;
2339 tipc_link_push_queue(l_ptr);
2340
Per Lidenb97bf3f2006-01-02 19:04:38 +01002341 return dsz;
2342}
2343
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002344/*
2345 * A pending message being re-assembled must store certain values
2346 * to handle subsequent fragments correctly. The following functions
Per Lidenb97bf3f2006-01-02 19:04:38 +01002347 * help storing these values in unused, available fields in the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002348 * pending message. This makes dynamic memory allocation unnecessary.
Per Lidenb97bf3f2006-01-02 19:04:38 +01002349 */
Sam Ravnborg05790c62006-03-20 22:37:04 -08002350static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002351{
2352 msg_set_seqno(buf_msg(buf), seqno);
2353}
2354
Sam Ravnborg05790c62006-03-20 22:37:04 -08002355static u32 get_fragm_size(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002356{
2357 return msg_ack(buf_msg(buf));
2358}
2359
Sam Ravnborg05790c62006-03-20 22:37:04 -08002360static void set_fragm_size(struct sk_buff *buf, u32 sz)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002361{
2362 msg_set_ack(buf_msg(buf), sz);
2363}
2364
Sam Ravnborg05790c62006-03-20 22:37:04 -08002365static u32 get_expected_frags(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002366{
2367 return msg_bcast_ack(buf_msg(buf));
2368}
2369
Sam Ravnborg05790c62006-03-20 22:37:04 -08002370static void set_expected_frags(struct sk_buff *buf, u32 exp)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002371{
2372 msg_set_bcast_ack(buf_msg(buf), exp);
2373}
2374
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002375/*
2376 * tipc_link_recv_fragment(): Called with node lock on. Returns
Per Lidenb97bf3f2006-01-02 19:04:38 +01002377 * the reassembled buffer if message is complete.
2378 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002379int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
Per Liden4323add2006-01-18 00:38:21 +01002380 struct tipc_msg **m)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002381{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002382 struct sk_buff *prev = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002383 struct sk_buff *fbuf = *fb;
2384 struct tipc_msg *fragm = buf_msg(fbuf);
2385 struct sk_buff *pbuf = *pending;
2386 u32 long_msg_seq_no = msg_long_msgno(fragm);
2387
Sam Ravnborg1fc54d82006-03-20 22:36:47 -08002388 *fb = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002389
2390 /* Is there an incomplete message waiting for this fragment? */
Allan Stephensf9057302011-10-24 16:03:12 -04002391 while (pbuf && ((buf_seqno(pbuf) != long_msg_seq_no) ||
Joe Perchesf64f9e72009-11-29 16:55:45 -08002392 (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002393 prev = pbuf;
2394 pbuf = pbuf->next;
2395 }
2396
2397 if (!pbuf && (msg_type(fragm) == FIRST_FRAGMENT)) {
2398 struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
2399 u32 msg_sz = msg_size(imsg);
2400 u32 fragm_sz = msg_data_sz(fragm);
Dan Carpenter6bf15192013-05-06 09:31:17 +00002401 u32 exp_fragm_cnt;
Allan Stephens741d9eb2011-05-31 15:03:18 -04002402 u32 max = TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE;
Dan Carpenter6bf15192013-05-06 09:31:17 +00002403
Per Lidenb97bf3f2006-01-02 19:04:38 +01002404 if (msg_type(imsg) == TIPC_MCAST_MSG)
2405 max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
Dan Carpenter6bf15192013-05-06 09:31:17 +00002406 if (fragm_sz == 0 || msg_size(imsg) > max) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04002407 kfree_skb(fbuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002408 return 0;
2409 }
Dan Carpenter6bf15192013-05-06 09:31:17 +00002410 exp_fragm_cnt = msg_sz / fragm_sz + !!(msg_sz % fragm_sz);
stephen hemminger31e3c3f2010-10-13 13:20:35 +00002411 pbuf = tipc_buf_acquire(msg_size(imsg));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002412 if (pbuf != NULL) {
2413 pbuf->next = *pending;
2414 *pending = pbuf;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002415 skb_copy_to_linear_data(pbuf, imsg,
2416 msg_data_sz(fragm));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002417 /* Prepare buffer for subsequent fragments. */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002418 set_long_msg_seqno(pbuf, long_msg_seq_no);
Allan Stephens0e659672010-12-31 18:59:32 +00002419 set_fragm_size(pbuf, fragm_sz);
2420 set_expected_frags(pbuf, exp_fragm_cnt - 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002421 } else {
Erik Hugne2cf8aa12012-06-29 00:16:37 -04002422 pr_debug("Link unable to reassemble fragmented message\n");
Allan Stephens5f6d9122011-11-04 13:24:29 -04002423 kfree_skb(fbuf);
Allan Stephensb76b27c2011-10-27 16:31:26 -04002424 return -1;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002425 }
Allan Stephens5f6d9122011-11-04 13:24:29 -04002426 kfree_skb(fbuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002427 return 0;
2428 } else if (pbuf && (msg_type(fragm) != FIRST_FRAGMENT)) {
2429 u32 dsz = msg_data_sz(fragm);
2430 u32 fsz = get_fragm_size(pbuf);
2431 u32 crs = ((msg_fragm_no(fragm) - 1) * fsz);
2432 u32 exp_frags = get_expected_frags(pbuf) - 1;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002433 skb_copy_to_linear_data_offset(pbuf, crs,
2434 msg_data(fragm), dsz);
Allan Stephens5f6d9122011-11-04 13:24:29 -04002435 kfree_skb(fbuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002436
2437 /* Is message complete? */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002438 if (exp_frags == 0) {
2439 if (prev)
2440 prev->next = pbuf->next;
2441 else
2442 *pending = pbuf->next;
2443 msg_reset_reroute_cnt(buf_msg(pbuf));
2444 *fb = pbuf;
2445 *m = buf_msg(pbuf);
2446 return 1;
2447 }
Allan Stephens0e659672010-12-31 18:59:32 +00002448 set_expected_frags(pbuf, exp_frags);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002449 return 0;
2450 }
Allan Stephens5f6d9122011-11-04 13:24:29 -04002451 kfree_skb(fbuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002452 return 0;
2453}
2454
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002455static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002456{
Allan Stephens5413b4c2011-01-18 13:24:55 -05002457 if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL))
2458 return;
2459
Per Lidenb97bf3f2006-01-02 19:04:38 +01002460 l_ptr->tolerance = tolerance;
2461 l_ptr->continuity_interval =
2462 ((tolerance / 4) > 500) ? 500 : tolerance / 4;
2463 l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4);
2464}
2465
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002466void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002467{
2468 /* Data messages from this node, inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002469 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window;
2470 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4;
2471 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5;
2472 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002473 /* Transiting data messages,inclusive FIRST_FRAGM */
Allan Stephens06d82c92008-03-06 15:06:55 -08002474 l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300;
2475 l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600;
2476 l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900;
2477 l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002478 l_ptr->queue_limit[CONN_MANAGER] = 1200;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002479 l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500;
2480 l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000;
2481 /* FRAGMENT and LAST_FRAGMENT packets */
2482 l_ptr->queue_limit[MSG_FRAGMENTER] = 4000;
2483}
2484
2485/**
2486 * link_find_link - locate link by name
Ben Hutchings2c530402012-07-10 10:55:09 +00002487 * @name: ptr to link name string
2488 * @node: ptr to area to be filled with ptr to associated node
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002489 *
Per Liden4323add2006-01-18 00:38:21 +01002490 * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002491 * this also prevents link deletion.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002492 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002493 * Returns pointer to link (or 0 if invalid link name).
2494 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002495static struct tipc_link *link_find_link(const char *name,
2496 struct tipc_node **node)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002497{
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002498 struct tipc_link *l_ptr;
Erik Hugnebbfbe472013-10-18 07:23:21 +02002499 struct tipc_node *n_ptr;
2500 int i;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002501
Erik Hugnebbfbe472013-10-18 07:23:21 +02002502 list_for_each_entry(n_ptr, &tipc_node_list, list) {
2503 for (i = 0; i < MAX_BEARERS; i++) {
2504 l_ptr = n_ptr->links[i];
2505 if (l_ptr && !strcmp(l_ptr->name, name))
2506 goto found;
2507 }
2508 }
2509 l_ptr = NULL;
2510 n_ptr = NULL;
2511found:
2512 *node = n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002513 return l_ptr;
2514}
2515
Allan Stephens5c216e12011-10-18 11:34:29 -04002516/**
2517 * link_value_is_valid -- validate proposed link tolerance/priority/window
2518 *
Ben Hutchings2c530402012-07-10 10:55:09 +00002519 * @cmd: value type (TIPC_CMD_SET_LINK_*)
2520 * @new_value: the new value
Allan Stephens5c216e12011-10-18 11:34:29 -04002521 *
2522 * Returns 1 if value is within range, 0 if not.
2523 */
Allan Stephens5c216e12011-10-18 11:34:29 -04002524static int link_value_is_valid(u16 cmd, u32 new_value)
2525{
2526 switch (cmd) {
2527 case TIPC_CMD_SET_LINK_TOL:
2528 return (new_value >= TIPC_MIN_LINK_TOL) &&
2529 (new_value <= TIPC_MAX_LINK_TOL);
2530 case TIPC_CMD_SET_LINK_PRI:
2531 return (new_value <= TIPC_MAX_LINK_PRI);
2532 case TIPC_CMD_SET_LINK_WINDOW:
2533 return (new_value >= TIPC_MIN_LINK_WIN) &&
2534 (new_value <= TIPC_MAX_LINK_WIN);
2535 }
2536 return 0;
2537}
2538
Allan Stephens5c216e12011-10-18 11:34:29 -04002539/**
2540 * link_cmd_set_value - change priority/tolerance/window for link/bearer/media
Ben Hutchings2c530402012-07-10 10:55:09 +00002541 * @name: ptr to link, bearer, or media name
2542 * @new_value: new value of link, bearer, or media setting
2543 * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*)
Allan Stephens5c216e12011-10-18 11:34:29 -04002544 *
2545 * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted.
2546 *
2547 * Returns 0 if value updated and negative value on error.
2548 */
Allan Stephens5c216e12011-10-18 11:34:29 -04002549static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)
2550{
2551 struct tipc_node *node;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002552 struct tipc_link *l_ptr;
Allan Stephens5c216e12011-10-18 11:34:29 -04002553 struct tipc_bearer *b_ptr;
Paul Gortmaker358a0d12011-12-29 20:19:42 -05002554 struct tipc_media *m_ptr;
Ying Xue636c0372013-10-18 07:23:20 +02002555 int res = 0;
Allan Stephens5c216e12011-10-18 11:34:29 -04002556
2557 l_ptr = link_find_link(name, &node);
2558 if (l_ptr) {
2559 /*
2560 * acquire node lock for tipc_link_send_proto_msg().
2561 * see "TIPC locking policy" in net.c.
2562 */
2563 tipc_node_lock(node);
2564 switch (cmd) {
2565 case TIPC_CMD_SET_LINK_TOL:
2566 link_set_supervision_props(l_ptr, new_value);
2567 tipc_link_send_proto_msg(l_ptr,
2568 STATE_MSG, 0, 0, new_value, 0, 0);
2569 break;
2570 case TIPC_CMD_SET_LINK_PRI:
2571 l_ptr->priority = new_value;
2572 tipc_link_send_proto_msg(l_ptr,
2573 STATE_MSG, 0, 0, 0, new_value, 0);
2574 break;
2575 case TIPC_CMD_SET_LINK_WINDOW:
2576 tipc_link_set_queue_limits(l_ptr, new_value);
2577 break;
Ying Xue636c0372013-10-18 07:23:20 +02002578 default:
2579 res = -EINVAL;
2580 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002581 }
2582 tipc_node_unlock(node);
Ying Xue636c0372013-10-18 07:23:20 +02002583 return res;
Allan Stephens5c216e12011-10-18 11:34:29 -04002584 }
2585
2586 b_ptr = tipc_bearer_find(name);
2587 if (b_ptr) {
2588 switch (cmd) {
2589 case TIPC_CMD_SET_LINK_TOL:
2590 b_ptr->tolerance = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002591 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002592 case TIPC_CMD_SET_LINK_PRI:
2593 b_ptr->priority = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002594 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002595 case TIPC_CMD_SET_LINK_WINDOW:
2596 b_ptr->window = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002597 break;
2598 default:
2599 res = -EINVAL;
2600 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002601 }
Ying Xue636c0372013-10-18 07:23:20 +02002602 return res;
Allan Stephens5c216e12011-10-18 11:34:29 -04002603 }
2604
2605 m_ptr = tipc_media_find(name);
2606 if (!m_ptr)
2607 return -ENODEV;
2608 switch (cmd) {
2609 case TIPC_CMD_SET_LINK_TOL:
2610 m_ptr->tolerance = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002611 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002612 case TIPC_CMD_SET_LINK_PRI:
2613 m_ptr->priority = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002614 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002615 case TIPC_CMD_SET_LINK_WINDOW:
2616 m_ptr->window = new_value;
Ying Xue636c0372013-10-18 07:23:20 +02002617 break;
2618 default:
2619 res = -EINVAL;
2620 break;
Allan Stephens5c216e12011-10-18 11:34:29 -04002621 }
Ying Xue636c0372013-10-18 07:23:20 +02002622 return res;
Allan Stephens5c216e12011-10-18 11:34:29 -04002623}
2624
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002625struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Per Liden4323add2006-01-18 00:38:21 +01002626 u16 cmd)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002627{
2628 struct tipc_link_config *args;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002629 u32 new_value;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002630 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002631
2632 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +01002633 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002634
2635 args = (struct tipc_link_config *)TLV_DATA(req_tlv_area);
2636 new_value = ntohl(args->value);
2637
Allan Stephens5c216e12011-10-18 11:34:29 -04002638 if (!link_value_is_valid(cmd, new_value))
2639 return tipc_cfg_reply_error_string(
2640 "cannot change, value invalid");
2641
Per Liden4323add2006-01-18 00:38:21 +01002642 if (!strcmp(args->name, tipc_bclink_name)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +01002643 if ((cmd == TIPC_CMD_SET_LINK_WINDOW) &&
Per Liden4323add2006-01-18 00:38:21 +01002644 (tipc_bclink_set_queue_limits(new_value) == 0))
2645 return tipc_cfg_reply_none();
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002646 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Per Liden4323add2006-01-18 00:38:21 +01002647 " (cannot change setting on broadcast link)");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002648 }
2649
Per Liden4323add2006-01-18 00:38:21 +01002650 read_lock_bh(&tipc_net_lock);
Allan Stephens5c216e12011-10-18 11:34:29 -04002651 res = link_cmd_set_value(args->name, new_value, cmd);
Per Liden4323add2006-01-18 00:38:21 +01002652 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002653 if (res)
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002654 return tipc_cfg_reply_error_string("cannot change link setting");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002655
Per Liden4323add2006-01-18 00:38:21 +01002656 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002657}
2658
2659/**
2660 * link_reset_statistics - reset link statistics
2661 * @l_ptr: pointer to link
2662 */
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002663static void link_reset_statistics(struct tipc_link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002664{
2665 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats));
2666 l_ptr->stats.sent_info = l_ptr->next_out_no;
2667 l_ptr->stats.recv_info = l_ptr->next_in_no;
2668}
2669
Per Liden4323add2006-01-18 00:38:21 +01002670struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002671{
2672 char *link_name;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002673 struct tipc_link *l_ptr;
David S. Miller6c000552008-09-02 23:38:32 -07002674 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002675
2676 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01002677 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002678
2679 link_name = (char *)TLV_DATA(req_tlv_area);
Per Liden4323add2006-01-18 00:38:21 +01002680 if (!strcmp(link_name, tipc_bclink_name)) {
2681 if (tipc_bclink_reset_stats())
2682 return tipc_cfg_reply_error_string("link not found");
2683 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002684 }
2685
Per Liden4323add2006-01-18 00:38:21 +01002686 read_lock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002687 l_ptr = link_find_link(link_name, &node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002688 if (!l_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002689 read_unlock_bh(&tipc_net_lock);
2690 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002691 }
2692
Per Liden4323add2006-01-18 00:38:21 +01002693 tipc_node_lock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002694 link_reset_statistics(l_ptr);
Per Liden4323add2006-01-18 00:38:21 +01002695 tipc_node_unlock(node);
2696 read_unlock_bh(&tipc_net_lock);
2697 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +01002698}
2699
2700/**
2701 * percent - convert count to a percentage of total (rounding up or down)
2702 */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002703static u32 percent(u32 count, u32 total)
2704{
2705 return (count * 100 + (total / 2)) / total;
2706}
2707
2708/**
Per Liden4323add2006-01-18 00:38:21 +01002709 * tipc_link_stats - print link statistics
Per Lidenb97bf3f2006-01-02 19:04:38 +01002710 * @name: link name
2711 * @buf: print buffer area
2712 * @buf_size: size of print buffer area
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002713 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002714 * Returns length of print buffer data string (or 0 if error)
2715 */
Per Liden4323add2006-01-18 00:38:21 +01002716static int tipc_link_stats(const char *name, char *buf, const u32 buf_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002717{
Erik Hugnedc1aed32012-06-29 00:50:23 -04002718 struct tipc_link *l;
2719 struct tipc_stats *s;
David S. Miller6c000552008-09-02 23:38:32 -07002720 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002721 char *status;
2722 u32 profile_total = 0;
Erik Hugnedc1aed32012-06-29 00:50:23 -04002723 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002724
Per Liden4323add2006-01-18 00:38:21 +01002725 if (!strcmp(name, tipc_bclink_name))
2726 return tipc_bclink_stats(buf, buf_size);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002727
Per Liden4323add2006-01-18 00:38:21 +01002728 read_lock_bh(&tipc_net_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -04002729 l = link_find_link(name, &node);
2730 if (!l) {
Per Liden4323add2006-01-18 00:38:21 +01002731 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002732 return 0;
2733 }
Per Liden4323add2006-01-18 00:38:21 +01002734 tipc_node_lock(node);
Erik Hugnedc1aed32012-06-29 00:50:23 -04002735 s = &l->stats;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002736
Erik Hugnedc1aed32012-06-29 00:50:23 -04002737 if (tipc_link_is_active(l))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002738 status = "ACTIVE";
Erik Hugnedc1aed32012-06-29 00:50:23 -04002739 else if (tipc_link_is_up(l))
Per Lidenb97bf3f2006-01-02 19:04:38 +01002740 status = "STANDBY";
2741 else
2742 status = "DEFUNCT";
Erik Hugnedc1aed32012-06-29 00:50:23 -04002743
2744 ret = tipc_snprintf(buf, buf_size, "Link <%s>\n"
2745 " %s MTU:%u Priority:%u Tolerance:%u ms"
2746 " Window:%u packets\n",
2747 l->name, status, l->max_pkt, l->priority,
2748 l->tolerance, l->queue_limit[0]);
2749
2750 ret += tipc_snprintf(buf + ret, buf_size - ret,
2751 " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
2752 l->next_in_no - s->recv_info, s->recv_fragments,
2753 s->recv_fragmented, s->recv_bundles,
2754 s->recv_bundled);
2755
2756 ret += tipc_snprintf(buf + ret, buf_size - ret,
2757 " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
2758 l->next_out_no - s->sent_info, s->sent_fragments,
2759 s->sent_fragmented, s->sent_bundles,
2760 s->sent_bundled);
2761
2762 profile_total = s->msg_length_counts;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002763 if (!profile_total)
2764 profile_total = 1;
Erik Hugnedc1aed32012-06-29 00:50:23 -04002765
2766 ret += tipc_snprintf(buf + ret, buf_size - ret,
2767 " TX profile sample:%u packets average:%u octets\n"
2768 " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% "
2769 "-16384:%u%% -32768:%u%% -66000:%u%%\n",
2770 s->msg_length_counts,
2771 s->msg_lengths_total / profile_total,
2772 percent(s->msg_length_profile[0], profile_total),
2773 percent(s->msg_length_profile[1], profile_total),
2774 percent(s->msg_length_profile[2], profile_total),
2775 percent(s->msg_length_profile[3], profile_total),
2776 percent(s->msg_length_profile[4], profile_total),
2777 percent(s->msg_length_profile[5], profile_total),
2778 percent(s->msg_length_profile[6], profile_total));
2779
2780 ret += tipc_snprintf(buf + ret, buf_size - ret,
2781 " RX states:%u probes:%u naks:%u defs:%u"
2782 " dups:%u\n", s->recv_states, s->recv_probes,
2783 s->recv_nacks, s->deferred_recv, s->duplicates);
2784
2785 ret += tipc_snprintf(buf + ret, buf_size - ret,
2786 " TX states:%u probes:%u naks:%u acks:%u"
2787 " dups:%u\n", s->sent_states, s->sent_probes,
2788 s->sent_nacks, s->sent_acks, s->retransmitted);
2789
2790 ret += tipc_snprintf(buf + ret, buf_size - ret,
Ying Xue3c294cb2012-11-15 11:34:45 +08002791 " Congestion link:%u Send queue"
2792 " max:%u avg:%u\n", s->link_congs,
Erik Hugnedc1aed32012-06-29 00:50:23 -04002793 s->max_queue_sz, s->queue_sz_counts ?
2794 (s->accu_queue_sz / s->queue_sz_counts) : 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002795
Per Liden4323add2006-01-18 00:38:21 +01002796 tipc_node_unlock(node);
2797 read_unlock_bh(&tipc_net_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -04002798 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002799}
2800
Per Liden4323add2006-01-18 00:38:21 +01002801struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002802{
2803 struct sk_buff *buf;
2804 struct tlv_desc *rep_tlv;
2805 int str_len;
Erik Hugnedc1aed32012-06-29 00:50:23 -04002806 int pb_len;
2807 char *pb;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002808
2809 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME))
Per Liden4323add2006-01-18 00:38:21 +01002810 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002811
Erik Hugnedc1aed32012-06-29 00:50:23 -04002812 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +01002813 if (!buf)
2814 return NULL;
2815
2816 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -04002817 pb = TLV_DATA(rep_tlv);
2818 pb_len = ULTRA_STRING_MAX_LEN;
Per Liden4323add2006-01-18 00:38:21 +01002819 str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area),
Erik Hugnedc1aed32012-06-29 00:50:23 -04002820 pb, pb_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002821 if (!str_len) {
Allan Stephens5f6d9122011-11-04 13:24:29 -04002822 kfree_skb(buf);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002823 return tipc_cfg_reply_error_string("link not found");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002824 }
Erik Hugnedc1aed32012-06-29 00:50:23 -04002825 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +01002826 skb_put(buf, TLV_SPACE(str_len));
2827 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
2828
2829 return buf;
2830}
2831
Per Lidenb97bf3f2006-01-02 19:04:38 +01002832/**
Per Liden4323add2006-01-18 00:38:21 +01002833 * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination
Per Lidenb97bf3f2006-01-02 19:04:38 +01002834 * @dest: network address of destination node
2835 * @selector: used to select from set of active links
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002836 *
Per Lidenb97bf3f2006-01-02 19:04:38 +01002837 * If no active link can be found, uses default maximum packet size.
2838 */
Per Liden4323add2006-01-18 00:38:21 +01002839u32 tipc_link_get_max_pkt(u32 dest, u32 selector)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002840{
David S. Miller6c000552008-09-02 23:38:32 -07002841 struct tipc_node *n_ptr;
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002842 struct tipc_link *l_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01002843 u32 res = MAX_PKT_DEFAULT;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002844
Per Lidenb97bf3f2006-01-02 19:04:38 +01002845 if (dest == tipc_own_addr)
2846 return MAX_MSG_SIZE;
2847
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002848 read_lock_bh(&tipc_net_lock);
Allan Stephens51a8e4d2010-12-31 18:59:18 +00002849 n_ptr = tipc_node_find(dest);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002850 if (n_ptr) {
Per Liden4323add2006-01-18 00:38:21 +01002851 tipc_node_lock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002852 l_ptr = n_ptr->active_links[selector & 1];
2853 if (l_ptr)
Allan Stephens15e979d2010-05-11 14:30:10 +00002854 res = l_ptr->max_pkt;
Per Liden4323add2006-01-18 00:38:21 +01002855 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002856 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09002857 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +01002858 return res;
2859}
2860
Paul Gortmakera18c4bc2011-12-29 20:58:42 -05002861static void link_print(struct tipc_link *l_ptr, const char *str)
Per Lidenb97bf3f2006-01-02 19:04:38 +01002862{
Paul Gortmaker5deedde2012-07-11 19:27:56 -04002863 pr_info("%s Link %x<%s>:", str, l_ptr->addr, l_ptr->b_ptr->name);
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002864
Per Lidenb97bf3f2006-01-02 19:04:38 +01002865 if (link_working_unknown(l_ptr))
Paul Gortmaker5deedde2012-07-11 19:27:56 -04002866 pr_cont(":WU\n");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002867 else if (link_reset_reset(l_ptr))
Paul Gortmaker5deedde2012-07-11 19:27:56 -04002868 pr_cont(":RR\n");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002869 else if (link_reset_unknown(l_ptr))
Paul Gortmaker5deedde2012-07-11 19:27:56 -04002870 pr_cont(":RU\n");
Allan Stephens8d64a5b2010-12-31 18:59:27 +00002871 else if (link_working_working(l_ptr))
Paul Gortmaker5deedde2012-07-11 19:27:56 -04002872 pr_cont(":WW\n");
2873 else
2874 pr_cont("\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +01002875}