blob: b3ed2fcab4fbd3a947b6419856641c9a7b315872 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/port.c: TIPC port code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Allan Stephens05646c92007-06-10 17:25:24 -07004 * Copyright (c) 1992-2007, Ericsson AB
Ying Xue198d73b2013-06-17 10:54:42 -04005 * Copyright (c) 2004-2008, 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"
38#include "config.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010039#include "port.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "name_table.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041
42/* Connection management: */
43#define PROBING_INTERVAL 3600000 /* [ms] => 1 h */
44#define CONFIRMED 0
45#define PROBING 1
46
47#define MAX_REJECT_SIZE 1024
48
Ingo Molnar34af9462006-06-27 02:53:55 -070049DEFINE_SPINLOCK(tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +010050
Per Liden4323add2006-01-18 00:38:21 +010051static LIST_HEAD(ports);
Per Lidenb97bf3f2006-01-02 19:04:38 +010052static void port_handle_node_down(unsigned long ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -050053static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err);
54static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err);
Per Lidenb97bf3f2006-01-02 19:04:38 +010055static void port_timeout(unsigned long ref);
56
57
Paul Gortmaker872f24d2012-04-23 04:49:13 +000058static u32 port_peernode(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010059{
Allan Stephens23dd4cc2011-01-07 11:43:40 -050060 return msg_destnode(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +010061}
62
Paul Gortmaker872f24d2012-04-23 04:49:13 +000063static u32 port_peerport(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010064{
Allan Stephens23dd4cc2011-01-07 11:43:40 -050065 return msg_destport(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +010066}
67
Ben Hutchings2c530402012-07-10 10:55:09 +000068/**
Allan Stephensf0712e862012-04-17 18:42:28 -040069 * tipc_port_peer_msg - verify message was sent by connected port's peer
70 *
71 * Handles cases where the node's network address has changed from
72 * the default of <0.0.0> to its configured setting.
73 */
Allan Stephensf0712e862012-04-17 18:42:28 -040074int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
75{
76 u32 peernode;
77 u32 orignode;
78
79 if (msg_origport(msg) != port_peerport(p_ptr))
80 return 0;
81
82 orignode = msg_orignode(msg);
83 peernode = port_peernode(p_ptr);
84 return (orignode == peernode) ||
85 (!orignode && (peernode == tipc_own_addr)) ||
86 (!peernode && (orignode == tipc_own_addr));
87}
88
Per Lidenb97bf3f2006-01-02 19:04:38 +010089/**
90 * tipc_multicast - send a multicast message to local and remote destinations
91 */
Allan Stephens38f232e2010-11-30 12:00:59 +000092int tipc_multicast(u32 ref, struct tipc_name_seq const *seq,
Allan Stephens26896902011-04-21 10:42:07 -050093 u32 num_sect, struct iovec const *msg_sect,
94 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +010095{
96 struct tipc_msg *hdr;
97 struct sk_buff *buf;
98 struct sk_buff *ibuf = NULL;
Paul Gortmaker45843102011-12-29 20:33:30 -050099 struct tipc_port_list dports = {0, NULL, };
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500100 struct tipc_port *oport = tipc_port_deref(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100101 int ext_targets;
102 int res;
103
104 if (unlikely(!oport))
105 return -EINVAL;
106
107 /* Create multicast message */
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500108 hdr = &oport->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100109 msg_set_type(hdr, TIPC_MCAST_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400110 msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE);
Allan Stephens7462b9e2011-04-18 10:08:22 -0400111 msg_set_destport(hdr, 0);
112 msg_set_destnode(hdr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100113 msg_set_nametype(hdr, seq->type);
114 msg_set_namelower(hdr, seq->lower);
115 msg_set_nameupper(hdr, seq->upper);
116 msg_set_hdr_sz(hdr, MCAST_H_SIZE);
Allan Stephens26896902011-04-21 10:42:07 -0500117 res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE,
Ying Xuef1733d72013-06-17 10:54:43 -0400118 &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100119 if (unlikely(!buf))
120 return res;
121
122 /* Figure out where to send multicast message */
Per Liden4323add2006-01-18 00:38:21 +0100123 ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper,
124 TIPC_NODE_SCOPE, &dports);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900125
126 /* Send message to destinations (duplicate it only if necessary) */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127 if (ext_targets) {
128 if (dports.count != 0) {
129 ibuf = skb_copy(buf, GFP_ATOMIC);
130 if (ibuf == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100131 tipc_port_list_free(&dports);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400132 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100133 return -ENOMEM;
134 }
135 }
Per Liden4323add2006-01-18 00:38:21 +0100136 res = tipc_bclink_send_msg(buf);
Allan Stephensa0168922010-12-31 18:59:35 +0000137 if ((res < 0) && (dports.count != 0))
Allan Stephens5f6d9122011-11-04 13:24:29 -0400138 kfree_skb(ibuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100139 } else {
140 ibuf = buf;
141 }
142
143 if (res >= 0) {
144 if (ibuf)
Per Liden4323add2006-01-18 00:38:21 +0100145 tipc_port_recv_mcast(ibuf, &dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146 } else {
Per Liden4323add2006-01-18 00:38:21 +0100147 tipc_port_list_free(&dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100148 }
149 return res;
150}
151
152/**
Per Liden4323add2006-01-18 00:38:21 +0100153 * tipc_port_recv_mcast - deliver multicast message to all destination ports
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900154 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100155 * If there is no port list, perform a lookup to create one
156 */
Paul Gortmaker45843102011-12-29 20:33:30 -0500157void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100158{
Allan Stephens0e659672010-12-31 18:59:32 +0000159 struct tipc_msg *msg;
Paul Gortmaker45843102011-12-29 20:33:30 -0500160 struct tipc_port_list dports = {0, NULL, };
161 struct tipc_port_list *item = dp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100162 int cnt = 0;
163
Per Lidenb97bf3f2006-01-02 19:04:38 +0100164 msg = buf_msg(buf);
165
166 /* Create destination port list, if one wasn't supplied */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100167 if (dp == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100168 tipc_nametbl_mc_translate(msg_nametype(msg),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100169 msg_namelower(msg),
170 msg_nameupper(msg),
171 TIPC_CLUSTER_SCOPE,
172 &dports);
173 item = dp = &dports;
174 }
175
176 /* Deliver a copy of message to each destination port */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100177 if (dp->count != 0) {
Allan Stephens7f47f5c2011-04-18 10:14:26 -0400178 msg_set_destnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100179 if (dp->count == 1) {
180 msg_set_destport(msg, dp->ports[0]);
Per Liden4323add2006-01-18 00:38:21 +0100181 tipc_port_recv_msg(buf);
182 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100183 return;
184 }
185 for (; cnt < dp->count; cnt++) {
186 int index = cnt % PLSIZE;
187 struct sk_buff *b = skb_clone(buf, GFP_ATOMIC);
188
189 if (b == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400190 pr_warn("Unable to deliver multicast message(s)\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100191 goto exit;
192 }
Allan Stephensa0168922010-12-31 18:59:35 +0000193 if ((index == 0) && (cnt != 0))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100194 item = item->next;
Allan Stephens0e659672010-12-31 18:59:32 +0000195 msg_set_destport(buf_msg(b), item->ports[index]);
Per Liden4323add2006-01-18 00:38:21 +0100196 tipc_port_recv_msg(b);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100197 }
198 }
199exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400200 kfree_skb(buf);
Per Liden4323add2006-01-18 00:38:21 +0100201 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100202}
203
204/**
Ying Xue3c5db8e2013-06-17 10:54:44 -0400205 * tipc_createport - create a generic TIPC port
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900206 *
Allan Stephens0ea52242008-07-14 22:42:19 -0700207 * Returns pointer to (locked) TIPC port, or NULL if unable to create it
Per Lidenb97bf3f2006-01-02 19:04:38 +0100208 */
Ying Xuec0fee8a2013-06-17 10:54:46 -0400209struct tipc_port *tipc_createport(struct sock *sk,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400210 u32 (*dispatcher)(struct tipc_port *,
211 struct sk_buff *),
212 void (*wakeup)(struct tipc_port *),
213 const u32 importance)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100214{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500215 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100216 struct tipc_msg *msg;
217 u32 ref;
218
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700219 p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -0700220 if (!p_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400221 pr_warn("Port creation failed, no memory\n");
Allan Stephens0ea52242008-07-14 22:42:19 -0700222 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100223 }
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500224 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100225 if (!ref) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400226 pr_warn("Port creation failed, ref. table exhausted\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100227 kfree(p_ptr);
Allan Stephens0ea52242008-07-14 22:42:19 -0700228 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100229 }
230
Ying Xuec0fee8a2013-06-17 10:54:46 -0400231 p_ptr->sk = sk;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500232 p_ptr->max_pkt = MAX_PKT_DEFAULT;
233 p_ptr->ref = ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100234 INIT_LIST_HEAD(&p_ptr->wait_list);
235 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236 p_ptr->dispatcher = dispatcher;
237 p_ptr->wakeup = wakeup;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100238 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100239 INIT_LIST_HEAD(&p_ptr->publications);
240 INIT_LIST_HEAD(&p_ptr->port_list);
Allan Stephensf21536d2012-04-17 18:22:49 -0400241
242 /*
243 * Must hold port list lock while initializing message header template
244 * to ensure a change to node's own network address doesn't result
245 * in template containing out-dated network address information
246 */
Allan Stephensf21536d2012-04-17 18:22:49 -0400247 spin_lock_bh(&tipc_port_list_lock);
248 msg = &p_ptr->phdr;
249 tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
250 msg_set_origport(msg, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100251 list_add_tail(&p_ptr->port_list, &ports);
Per Liden4323add2006-01-18 00:38:21 +0100252 spin_unlock_bh(&tipc_port_list_lock);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500253 return p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100254}
255
256int tipc_deleteport(u32 ref)
257{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500258 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800259 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100260
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800261 tipc_withdraw(ref, 0, NULL);
Per Liden4323add2006-01-18 00:38:21 +0100262 p_ptr = tipc_port_lock(ref);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900263 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264 return -EINVAL;
265
Per Liden4323add2006-01-18 00:38:21 +0100266 tipc_ref_discard(ref);
267 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100268
269 k_cancel_timer(&p_ptr->timer);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500270 if (p_ptr->connected) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100271 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
Per Liden4323add2006-01-18 00:38:21 +0100272 tipc_nodesub_unsubscribe(&p_ptr->subscription);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100273 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100274
Per Liden4323add2006-01-18 00:38:21 +0100275 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100276 list_del(&p_ptr->port_list);
277 list_del(&p_ptr->wait_list);
Per Liden4323add2006-01-18 00:38:21 +0100278 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100279 k_term_timer(&p_ptr->timer);
280 kfree(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100281 tipc_net_route_msg(buf);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700282 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100283}
284
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500285static int port_unreliable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100286{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500287 return msg_src_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100288}
289
290int tipc_portunreliable(u32 ref, unsigned int *isunreliable)
291{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500292 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900293
Per Liden4323add2006-01-18 00:38:21 +0100294 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100295 if (!p_ptr)
296 return -EINVAL;
297 *isunreliable = port_unreliable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800298 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700299 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300}
301
302int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
303{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500304 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900305
Per Liden4323add2006-01-18 00:38:21 +0100306 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100307 if (!p_ptr)
308 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500309 msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100310 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700311 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100312}
313
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500314static int port_unreturnable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100315{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500316 return msg_dest_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100317}
318
319int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable)
320{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500321 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900322
Per Liden4323add2006-01-18 00:38:21 +0100323 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100324 if (!p_ptr)
325 return -EINVAL;
326 *isunrejectable = port_unreturnable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800327 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700328 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100329}
330
331int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
332{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500333 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900334
Per Liden4323add2006-01-18 00:38:21 +0100335 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100336 if (!p_ptr)
337 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500338 msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100339 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700340 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100341}
342
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900343/*
Allan Stephense4a0aee2011-06-01 16:21:12 -0400344 * port_build_proto_msg(): create connection protocol message for port
345 *
346 * On entry the port must be locked and connected.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100347 */
Allan Stephense4a0aee2011-06-01 16:21:12 -0400348static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr,
349 u32 type, u32 ack)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100350{
351 struct sk_buff *buf;
352 struct tipc_msg *msg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900353
Allan Stephens741d9eb2011-05-31 15:03:18 -0400354 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100355 if (buf) {
356 msg = buf_msg(buf);
Allan Stephense4a0aee2011-06-01 16:21:12 -0400357 tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE,
358 port_peernode(p_ptr));
359 msg_set_destport(msg, port_peerport(p_ptr));
360 msg_set_origport(msg, p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100361 msg_set_msgcnt(msg, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100362 }
363 return buf;
364}
365
Per Lidenb97bf3f2006-01-02 19:04:38 +0100366int tipc_reject_msg(struct sk_buff *buf, u32 err)
367{
368 struct tipc_msg *msg = buf_msg(buf);
369 struct sk_buff *rbuf;
370 struct tipc_msg *rmsg;
371 int hdr_sz;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400372 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100373 u32 data_sz = msg_data_sz(msg);
Allan Stephens017dac32011-05-24 13:20:09 -0400374 u32 src_node;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400375 u32 rmsg_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100376
377 /* discard rejected message if it shouldn't be returned to sender */
Allan Stephens76d12522011-05-23 13:57:25 -0400378 if (WARN(!msg_isdata(msg),
379 "attempt to reject message with user=%u", msg_user(msg))) {
380 dump_stack();
381 goto exit;
382 }
Allan Stephensacc631b2011-05-23 13:47:44 -0400383 if (msg_errcode(msg) || msg_dest_droppable(msg))
384 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100385
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400386 /*
387 * construct returned message by copying rejected message header and
388 * data (or subset), then updating header fields that need adjusting
389 */
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400390 hdr_sz = msg_hdr_sz(msg);
391 rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE);
392
393 rbuf = tipc_buf_acquire(rmsg_sz);
Allan Stephensacc631b2011-05-23 13:47:44 -0400394 if (rbuf == NULL)
395 goto exit;
396
Per Lidenb97bf3f2006-01-02 19:04:38 +0100397 rmsg = buf_msg(rbuf);
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400398 skb_copy_to_linear_data(rbuf, msg, rmsg_sz);
399
400 if (msg_connected(rmsg)) {
401 imp = msg_importance(rmsg);
402 if (imp < TIPC_CRITICAL_IMPORTANCE)
403 msg_set_importance(rmsg, ++imp);
Allan Stephens99c14592008-06-04 17:48:25 -0700404 }
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400405 msg_set_non_seq(rmsg, 0);
406 msg_set_size(rmsg, rmsg_sz);
407 msg_set_errcode(rmsg, err);
408 msg_set_prevnode(rmsg, tipc_own_addr);
409 msg_swap_words(rmsg, 4, 5);
410 if (!msg_short(rmsg))
411 msg_swap_words(rmsg, 6, 7);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100412
413 /* send self-abort message when rejecting on a connected port */
414 if (msg_connected(msg)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500415 struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100416
417 if (p_ptr) {
Allan Stephensdff10e92011-11-02 10:32:14 -0400418 struct sk_buff *abuf = NULL;
419
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500420 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100421 abuf = port_build_self_abort_msg(p_ptr, err);
Per Liden4323add2006-01-18 00:38:21 +0100422 tipc_port_unlock(p_ptr);
Allan Stephensdff10e92011-11-02 10:32:14 -0400423 tipc_net_route_msg(abuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100424 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100425 }
426
Allan Stephensacc631b2011-05-23 13:47:44 -0400427 /* send returned message & dispose of rejected message */
Allan Stephens017dac32011-05-24 13:20:09 -0400428 src_node = msg_prevnode(msg);
Allan Stephens630d9202012-04-18 09:42:29 -0400429 if (in_own_node(src_node))
Allan Stephens017dac32011-05-24 13:20:09 -0400430 tipc_port_recv_msg(rbuf);
431 else
432 tipc_link_send(rbuf, src_node, msg_link_selector(rmsg));
Allan Stephensacc631b2011-05-23 13:47:44 -0400433exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400434 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100435 return data_sz;
436}
437
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500438int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr,
Per Liden4323add2006-01-18 00:38:21 +0100439 struct iovec const *msg_sect, u32 num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500440 unsigned int total_len, int err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441{
442 struct sk_buff *buf;
443 int res;
444
Allan Stephens26896902011-04-21 10:42:07 -0500445 res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE,
Ying Xuef1733d72013-06-17 10:54:43 -0400446 &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100447 if (!buf)
448 return res;
449
450 return tipc_reject_msg(buf, err);
451}
452
453static void port_timeout(unsigned long ref)
454{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500455 struct tipc_port *p_ptr = tipc_port_lock(ref);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800456 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100457
Allan Stephens065fd172006-10-16 21:38:05 -0700458 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100459 return;
460
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500461 if (!p_ptr->connected) {
Allan Stephens065fd172006-10-16 21:38:05 -0700462 tipc_port_unlock(p_ptr);
463 return;
464 }
465
Per Lidenb97bf3f2006-01-02 19:04:38 +0100466 /* Last probe answered ? */
467 if (p_ptr->probing_state == PROBING) {
468 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
469 } else {
Allan Stephense4a0aee2011-06-01 16:21:12 -0400470 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100471 p_ptr->probing_state = PROBING;
472 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
473 }
Per Liden4323add2006-01-18 00:38:21 +0100474 tipc_port_unlock(p_ptr);
475 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100476}
477
478
479static void port_handle_node_down(unsigned long ref)
480{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500481 struct tipc_port *p_ptr = tipc_port_lock(ref);
Allan Stephens0e659672010-12-31 18:59:32 +0000482 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100483
484 if (!p_ptr)
485 return;
486 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE);
Per Liden4323add2006-01-18 00:38:21 +0100487 tipc_port_unlock(p_ptr);
488 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100489}
490
491
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500492static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100493{
Allan Stephense244a912011-05-31 16:10:08 -0400494 struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100495
Allan Stephense244a912011-05-31 16:10:08 -0400496 if (buf) {
497 struct tipc_msg *msg = buf_msg(buf);
498 msg_swap_words(msg, 4, 5);
499 msg_swap_words(msg, 6, 7);
500 }
501 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100502}
503
504
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500505static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100506{
Allan Stephense244a912011-05-31 16:10:08 -0400507 struct sk_buff *buf;
508 struct tipc_msg *msg;
509 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500511 if (!p_ptr->connected)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800512 return NULL;
Allan Stephense244a912011-05-31 16:10:08 -0400513
514 buf = tipc_buf_acquire(BASIC_H_SIZE);
515 if (buf) {
516 msg = buf_msg(buf);
517 memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE);
518 msg_set_hdr_sz(msg, BASIC_H_SIZE);
519 msg_set_size(msg, BASIC_H_SIZE);
520 imp = msg_importance(msg);
521 if (imp < TIPC_CRITICAL_IMPORTANCE)
522 msg_set_importance(msg, ++imp);
523 msg_set_errcode(msg, err);
524 }
525 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100526}
527
Per Liden4323add2006-01-18 00:38:21 +0100528void tipc_port_recv_proto_msg(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100529{
530 struct tipc_msg *msg = buf_msg(buf);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400531 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800532 struct sk_buff *r_buf = NULL;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400533 u32 destport = msg_destport(msg);
534 int wakeable;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100535
Allan Stephens1c1a5512011-06-01 15:08:10 -0400536 /* Validate connection */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400537 p_ptr = tipc_port_lock(destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400538 if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
Allan Stephensf55b5642011-06-01 15:48:42 -0400539 r_buf = tipc_buf_acquire(BASIC_H_SIZE);
540 if (r_buf) {
541 msg = buf_msg(r_buf);
542 tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG,
Allan Stephensf0712e862012-04-17 18:42:28 -0400543 BASIC_H_SIZE, msg_orignode(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400544 msg_set_errcode(msg, TIPC_ERR_NO_PORT);
545 msg_set_origport(msg, destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400546 msg_set_destport(msg, msg_origport(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400547 }
Allan Stephens1c1a5512011-06-01 15:08:10 -0400548 if (p_ptr)
549 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100550 goto exit;
551 }
552
Allan Stephens1c1a5512011-06-01 15:08:10 -0400553 /* Process protocol message sent by peer */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400554 switch (msg_type(msg)) {
555 case CONN_ACK:
556 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested &&
557 p_ptr->wakeup;
558 p_ptr->acked += msg_msgcnt(msg);
559 if (!tipc_port_congested(p_ptr)) {
560 p_ptr->congested = 0;
561 if (wakeable)
562 p_ptr->wakeup(p_ptr);
563 }
564 break;
565 case CONN_PROBE:
Allan Stephense4a0aee2011-06-01 16:21:12 -0400566 r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400567 break;
568 default:
569 /* CONN_PROBE_REPLY or unrecognized - no action required */
570 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100571 }
572 p_ptr->probing_state = CONFIRMED;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400573 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100574exit:
Per Liden4323add2006-01-18 00:38:21 +0100575 tipc_net_route_msg(r_buf);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400576 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100577}
578
Erik Hugnedc1aed32012-06-29 00:50:23 -0400579static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100580{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900581 struct publication *publ;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400582 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100583
584 if (full_id)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400585 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
586 tipc_zone(tipc_own_addr),
587 tipc_cluster(tipc_own_addr),
588 tipc_node(tipc_own_addr), p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100589 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400590 ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100591
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500592 if (p_ptr->connected) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900593 u32 dport = port_peerport(p_ptr);
594 u32 destnode = port_peernode(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100595
Erik Hugnedc1aed32012-06-29 00:50:23 -0400596 ret += tipc_snprintf(buf + ret, len - ret,
597 " connected to <%u.%u.%u:%u>",
598 tipc_zone(destnode),
599 tipc_cluster(destnode),
600 tipc_node(destnode), dport);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500601 if (p_ptr->conn_type != 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400602 ret += tipc_snprintf(buf + ret, len - ret,
603 " via {%u,%u}", p_ptr->conn_type,
604 p_ptr->conn_instance);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500605 } else if (p_ptr->published) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400606 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900607 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100608 if (publ->lower == publ->upper)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400609 ret += tipc_snprintf(buf + ret, len - ret,
610 " {%u,%u}", publ->type,
611 publ->lower);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100612 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400613 ret += tipc_snprintf(buf + ret, len - ret,
614 " {%u,%u,%u}", publ->type,
615 publ->lower, publ->upper);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900616 }
617 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400618 ret += tipc_snprintf(buf + ret, len - ret, "\n");
619 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100620}
621
Per Liden4323add2006-01-18 00:38:21 +0100622struct sk_buff *tipc_port_get_ports(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100623{
624 struct sk_buff *buf;
625 struct tlv_desc *rep_tlv;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400626 char *pb;
627 int pb_len;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500628 struct tipc_port *p_ptr;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400629 int str_len = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100630
Erik Hugnedc1aed32012-06-29 00:50:23 -0400631 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100632 if (!buf)
633 return NULL;
634 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400635 pb = TLV_DATA(rep_tlv);
636 pb_len = ULTRA_STRING_MAX_LEN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100637
Per Liden4323add2006-01-18 00:38:21 +0100638 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100639 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500640 spin_lock_bh(p_ptr->lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400641 str_len += port_print(p_ptr, pb, pb_len, 0);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500642 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100643 }
Per Liden4323add2006-01-18 00:38:21 +0100644 spin_unlock_bh(&tipc_port_list_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400645 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100646 skb_put(buf, TLV_SPACE(str_len));
647 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
648
649 return buf;
650}
651
Per Liden4323add2006-01-18 00:38:21 +0100652void tipc_port_reinit(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100653{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500654 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100655 struct tipc_msg *msg;
656
Per Liden4323add2006-01-18 00:38:21 +0100657 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100658 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500659 msg = &p_ptr->phdr;
Allan Stephens6d4a6672008-05-21 14:54:12 -0700660 msg_set_prevnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100661 msg_set_orignode(msg, tipc_own_addr);
662 }
Per Liden4323add2006-01-18 00:38:21 +0100663 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100664}
665
Per Lidenb97bf3f2006-01-02 19:04:38 +0100666void tipc_acknowledge(u32 ref, u32 ack)
667{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500668 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800669 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100670
Per Liden4323add2006-01-18 00:38:21 +0100671 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100672 if (!p_ptr)
673 return;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500674 if (p_ptr->connected) {
675 p_ptr->conn_unacked -= ack;
Allan Stephense4a0aee2011-06-01 16:21:12 -0400676 buf = port_build_proto_msg(p_ptr, CONN_ACK, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100677 }
Per Liden4323add2006-01-18 00:38:21 +0100678 tipc_port_unlock(p_ptr);
679 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100680}
681
Per Lidenb97bf3f2006-01-02 19:04:38 +0100682int tipc_portimportance(u32 ref, unsigned int *importance)
683{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500684 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900685
Per Liden4323add2006-01-18 00:38:21 +0100686 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100687 if (!p_ptr)
688 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500689 *importance = (unsigned int)msg_importance(&p_ptr->phdr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800690 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700691 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100692}
693
694int tipc_set_portimportance(u32 ref, unsigned int imp)
695{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500696 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100697
698 if (imp > TIPC_CRITICAL_IMPORTANCE)
699 return -EINVAL;
700
Per Liden4323add2006-01-18 00:38:21 +0100701 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100702 if (!p_ptr)
703 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500704 msg_set_importance(&p_ptr->phdr, (u32)imp);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800705 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700706 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100707}
708
709
710int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
711{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500712 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713 struct publication *publ;
714 u32 key;
715 int res = -EINVAL;
716
Per Liden4323add2006-01-18 00:38:21 +0100717 p_ptr = tipc_port_lock(ref);
Adrian Bunkd55b4c62006-10-31 16:59:35 -0800718 if (!p_ptr)
719 return -EINVAL;
720
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500721 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100722 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100723 key = ref + p_ptr->pub_count + 1;
724 if (key == ref) {
725 res = -EADDRINUSE;
726 goto exit;
727 }
Per Liden4323add2006-01-18 00:38:21 +0100728 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500729 scope, p_ptr->ref, key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100730 if (publ) {
731 list_add(&publ->pport_list, &p_ptr->publications);
732 p_ptr->pub_count++;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500733 p_ptr->published = 1;
Allan Stephens0e35fd52008-07-14 22:44:01 -0700734 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100735 }
736exit:
Per Liden4323add2006-01-18 00:38:21 +0100737 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100738 return res;
739}
740
741int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
742{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500743 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100744 struct publication *publ;
745 struct publication *tpubl;
746 int res = -EINVAL;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900747
Per Liden4323add2006-01-18 00:38:21 +0100748 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100749 if (!p_ptr)
750 return -EINVAL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100751 if (!seq) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900752 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100753 &p_ptr->publications, pport_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900754 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100755 publ->ref, publ->key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100756 }
Allan Stephens0e35fd52008-07-14 22:44:01 -0700757 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100758 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900759 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100760 &p_ptr->publications, pport_list) {
761 if (publ->scope != scope)
762 continue;
763 if (publ->type != seq->type)
764 continue;
765 if (publ->lower != seq->lower)
766 continue;
767 if (publ->upper != seq->upper)
768 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900769 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100770 publ->ref, publ->key);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700771 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100772 break;
773 }
774 }
775 if (list_empty(&p_ptr->publications))
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500776 p_ptr->published = 0;
Per Liden4323add2006-01-18 00:38:21 +0100777 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100778 return res;
779}
780
Paul Gortmakerbc879112012-11-29 13:48:40 -0500781int tipc_connect(u32 ref, struct tipc_portid const *peer)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100782{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500783 struct tipc_port *p_ptr;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500784 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100785
Per Liden4323add2006-01-18 00:38:21 +0100786 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100787 if (!p_ptr)
788 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500789 res = __tipc_connect(ref, p_ptr, peer);
790 tipc_port_unlock(p_ptr);
791 return res;
792}
793
794/*
795 * __tipc_connect - connect to a remote peer
796 *
797 * Port must be locked.
798 */
799int __tipc_connect(u32 ref, struct tipc_port *p_ptr,
800 struct tipc_portid const *peer)
801{
802 struct tipc_msg *msg;
803 int res = -EINVAL;
804
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500805 if (p_ptr->published || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100806 goto exit;
807 if (!peer->ref)
808 goto exit;
809
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500810 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100811 msg_set_destnode(msg, peer->node);
812 msg_set_destport(msg, peer->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100813 msg_set_type(msg, TIPC_CONN_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400814 msg_set_lookup_scope(msg, 0);
Allan Stephens08c80e92010-12-31 18:59:17 +0000815 msg_set_hdr_sz(msg, SHORT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100816
817 p_ptr->probing_interval = PROBING_INTERVAL;
818 p_ptr->probing_state = CONFIRMED;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500819 p_ptr->connected = 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100820 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
821
Allan Stephens0e659672010-12-31 18:59:32 +0000822 tipc_nodesub_subscribe(&p_ptr->subscription, peer->node,
David S. Miller880b0052006-01-12 13:22:32 -0800823 (void *)(unsigned long)ref,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100824 (net_ev_handler)port_handle_node_down);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700825 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100826exit:
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500827 p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100828 return res;
829}
830
Paul Gortmakerbc879112012-11-29 13:48:40 -0500831/*
832 * __tipc_disconnect - disconnect port from peer
Allan Stephens0c3141e2008-04-15 00:22:02 -0700833 *
834 * Port must be locked.
835 */
Paul Gortmakerbc879112012-11-29 13:48:40 -0500836int __tipc_disconnect(struct tipc_port *tp_ptr)
Allan Stephens0c3141e2008-04-15 00:22:02 -0700837{
838 int res;
839
840 if (tp_ptr->connected) {
841 tp_ptr->connected = 0;
842 /* let timer expire on it's own to avoid deadlock! */
Joe Perchese3192692012-06-03 17:41:40 +0000843 tipc_nodesub_unsubscribe(&tp_ptr->subscription);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700844 res = 0;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700845 } else {
846 res = -ENOTCONN;
847 }
848 return res;
849}
850
Per Lidenb97bf3f2006-01-02 19:04:38 +0100851/*
852 * tipc_disconnect(): Disconnect port form peer.
853 * This is a node local operation.
854 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100855int tipc_disconnect(u32 ref)
856{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500857 struct tipc_port *p_ptr;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700858 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100859
Per Liden4323add2006-01-18 00:38:21 +0100860 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100861 if (!p_ptr)
862 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500863 res = __tipc_disconnect(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100864 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100865 return res;
866}
867
868/*
869 * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect
870 */
871int tipc_shutdown(u32 ref)
872{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500873 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800874 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100875
Per Liden4323add2006-01-18 00:38:21 +0100876 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100877 if (!p_ptr)
878 return -EINVAL;
879
Allan Stephense244a912011-05-31 16:10:08 -0400880 buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN);
Per Liden4323add2006-01-18 00:38:21 +0100881 tipc_port_unlock(p_ptr);
882 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100883 return tipc_disconnect(ref);
884}
885
Allan Stephens9b641252011-11-09 13:29:18 -0500886/**
887 * tipc_port_recv_msg - receive message from lower layer and deliver to port user
888 */
Allan Stephens9b641252011-11-09 13:29:18 -0500889int tipc_port_recv_msg(struct sk_buff *buf)
890{
891 struct tipc_port *p_ptr;
892 struct tipc_msg *msg = buf_msg(buf);
893 u32 destport = msg_destport(msg);
894 u32 dsz = msg_data_sz(msg);
895 u32 err;
896
897 /* forward unresolved named message */
898 if (unlikely(!destport)) {
899 tipc_net_route_msg(buf);
900 return dsz;
901 }
902
903 /* validate destination & pass to port, otherwise reject message */
904 p_ptr = tipc_port_lock(destport);
905 if (likely(p_ptr)) {
Allan Stephens9b641252011-11-09 13:29:18 -0500906 err = p_ptr->dispatcher(p_ptr, buf);
907 tipc_port_unlock(p_ptr);
908 if (likely(!err))
909 return dsz;
910 } else {
911 err = TIPC_ERR_NO_PORT;
912 }
Allan Stephensf0712e862012-04-17 18:42:28 -0400913
Allan Stephens9b641252011-11-09 13:29:18 -0500914 return tipc_reject_msg(buf, err);
915}
916
Per Lidenb97bf3f2006-01-02 19:04:38 +0100917/*
Per Liden4323add2006-01-18 00:38:21 +0100918 * tipc_port_recv_sections(): Concatenate and deliver sectioned
Per Lidenb97bf3f2006-01-02 19:04:38 +0100919 * message for this node.
920 */
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500921static int tipc_port_recv_sections(struct tipc_port *sender, unsigned int num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500922 struct iovec const *msg_sect,
923 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100924{
925 struct sk_buff *buf;
926 int res;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900927
Allan Stephens26896902011-04-21 10:42:07 -0500928 res = tipc_msg_build(&sender->phdr, msg_sect, num_sect, total_len,
Ying Xuef1733d72013-06-17 10:54:43 -0400929 MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100930 if (likely(buf))
Per Liden4323add2006-01-18 00:38:21 +0100931 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100932 return res;
933}
934
935/**
936 * tipc_send - send message sections on connection
937 */
Allan Stephens26896902011-04-21 10:42:07 -0500938int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect,
939 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100940{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500941 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100942 u32 destnode;
943 int res;
944
Per Liden4323add2006-01-18 00:38:21 +0100945 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500946 if (!p_ptr || !p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100947 return -EINVAL;
948
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500949 p_ptr->congested = 1;
Per Liden4323add2006-01-18 00:38:21 +0100950 if (!tipc_port_congested(p_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100951 destnode = port_peernode(p_ptr);
Allan Stephens8a55fe72012-04-18 09:27:22 -0400952 if (likely(!in_own_node(destnode)))
Per Liden4323add2006-01-18 00:38:21 +0100953 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500954 total_len, destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100955 else
Allan Stephens26896902011-04-21 10:42:07 -0500956 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
957 total_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100958
959 if (likely(res != -ELINKCONG)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500960 p_ptr->congested = 0;
Allan Stephenscb7ce912011-01-24 15:02:14 -0500961 if (res > 0)
962 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100963 return res;
964 }
965 }
966 if (port_unreliable(p_ptr)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500967 p_ptr->congested = 0;
Allan Stephens26896902011-04-21 10:42:07 -0500968 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100969 }
970 return -ELINKCONG;
971}
972
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900973/**
Allan Stephens12bae472010-11-30 12:01:02 +0000974 * tipc_send2name - send message sections to port name
Per Lidenb97bf3f2006-01-02 19:04:38 +0100975 */
Allan Stephens12bae472010-11-30 12:01:02 +0000976int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
Allan Stephens26896902011-04-21 10:42:07 -0500977 unsigned int num_sect, struct iovec const *msg_sect,
978 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100979{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500980 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100981 struct tipc_msg *msg;
982 u32 destnode = domain;
Allan Stephens9ccc2eb2010-05-11 14:30:06 +0000983 u32 destport;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100984 int res;
985
Per Liden4323add2006-01-18 00:38:21 +0100986 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500987 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100988 return -EINVAL;
989
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500990 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100991 msg_set_type(msg, TIPC_NAMED_MSG);
Allan Stephens741d9eb2011-05-31 15:03:18 -0400992 msg_set_hdr_sz(msg, NAMED_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100993 msg_set_nametype(msg, name->type);
994 msg_set_nameinst(msg, name->instance);
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000995 msg_set_lookup_scope(msg, tipc_addr_scope(domain));
Per Liden4323add2006-01-18 00:38:21 +0100996 destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100997 msg_set_destnode(msg, destnode);
998 msg_set_destport(msg, destport);
999
Allan Stephensbc9f8142011-11-07 17:00:54 -05001000 if (likely(destport || destnode)) {
Allan Stephens8a55fe72012-04-18 09:27:22 -04001001 if (likely(in_own_node(destnode)))
Allan Stephenscb7ce912011-01-24 15:02:14 -05001002 res = tipc_port_recv_sections(p_ptr, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001003 msg_sect, total_len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001004 else if (tipc_own_addr)
Allan Stephenscb7ce912011-01-24 15:02:14 -05001005 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001006 num_sect, total_len,
1007 destnode);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001008 else
1009 res = tipc_port_reject_sections(p_ptr, msg, msg_sect,
1010 num_sect, total_len,
1011 TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001012 if (likely(res != -ELINKCONG)) {
1013 if (res > 0)
1014 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001015 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001016 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001017 if (port_unreliable(p_ptr)) {
Allan Stephens26896902011-04-21 10:42:07 -05001018 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001019 }
1020 return -ELINKCONG;
1021 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001022 return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001023 total_len, TIPC_ERR_NO_NAME);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001024}
1025
1026/**
Allan Stephens12bae472010-11-30 12:01:02 +00001027 * tipc_send2port - send message sections to port identity
Per Lidenb97bf3f2006-01-02 19:04:38 +01001028 */
Allan Stephens12bae472010-11-30 12:01:02 +00001029int tipc_send2port(u32 ref, struct tipc_portid const *dest,
Allan Stephens26896902011-04-21 10:42:07 -05001030 unsigned int num_sect, struct iovec const *msg_sect,
1031 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001032{
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001033 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001034 struct tipc_msg *msg;
1035 int res;
1036
Per Liden4323add2006-01-18 00:38:21 +01001037 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001038 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001039 return -EINVAL;
1040
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001041 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001042 msg_set_type(msg, TIPC_DIRECT_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -04001043 msg_set_lookup_scope(msg, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001044 msg_set_destnode(msg, dest->node);
1045 msg_set_destport(msg, dest->ref);
Allan Stephens741d9eb2011-05-31 15:03:18 -04001046 msg_set_hdr_sz(msg, BASIC_H_SIZE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001047
Allan Stephens8a55fe72012-04-18 09:27:22 -04001048 if (in_own_node(dest->node))
Allan Stephens26896902011-04-21 10:42:07 -05001049 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
1050 total_len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001051 else if (tipc_own_addr)
Allan Stephenscb7ce912011-01-24 15:02:14 -05001052 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001053 total_len, dest->node);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001054 else
1055 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect,
1056 total_len, TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001057 if (likely(res != -ELINKCONG)) {
1058 if (res > 0)
1059 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001060 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001061 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001062 if (port_unreliable(p_ptr)) {
Allan Stephens26896902011-04-21 10:42:07 -05001063 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001064 }
1065 return -ELINKCONG;
1066}