blob: f628c84a8f61c75cb04f25d2edef535e9c425968 [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/**
Allan Stephens7ef43eb2008-05-12 15:42:28 -0700205 * tipc_createport_raw - 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 */
Allan Stephens0ea52242008-07-14 22:42:19 -0700209struct tipc_port *tipc_createport_raw(void *usr_handle,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100210 u32 (*dispatcher)(struct tipc_port *, struct sk_buff *),
211 void (*wakeup)(struct tipc_port *),
Allan Stephens0ea52242008-07-14 22:42:19 -0700212 const u32 importance)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100213{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500214 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100215 struct tipc_msg *msg;
216 u32 ref;
217
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700218 p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -0700219 if (!p_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400220 pr_warn("Port creation failed, no memory\n");
Allan Stephens0ea52242008-07-14 22:42:19 -0700221 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100222 }
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500223 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100224 if (!ref) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400225 pr_warn("Port creation failed, ref. table exhausted\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100226 kfree(p_ptr);
Allan Stephens0ea52242008-07-14 22:42:19 -0700227 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100228 }
229
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500230 p_ptr->usr_handle = usr_handle;
231 p_ptr->max_pkt = MAX_PKT_DEFAULT;
232 p_ptr->ref = ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100233 INIT_LIST_HEAD(&p_ptr->wait_list);
234 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100235 p_ptr->dispatcher = dispatcher;
236 p_ptr->wakeup = wakeup;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100237 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100238 INIT_LIST_HEAD(&p_ptr->publications);
239 INIT_LIST_HEAD(&p_ptr->port_list);
Allan Stephensf21536d2012-04-17 18:22:49 -0400240
241 /*
242 * Must hold port list lock while initializing message header template
243 * to ensure a change to node's own network address doesn't result
244 * in template containing out-dated network address information
245 */
Allan Stephensf21536d2012-04-17 18:22:49 -0400246 spin_lock_bh(&tipc_port_list_lock);
247 msg = &p_ptr->phdr;
248 tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
249 msg_set_origport(msg, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100250 list_add_tail(&p_ptr->port_list, &ports);
Per Liden4323add2006-01-18 00:38:21 +0100251 spin_unlock_bh(&tipc_port_list_lock);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500252 return p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100253}
254
255int tipc_deleteport(u32 ref)
256{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500257 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800258 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100259
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800260 tipc_withdraw(ref, 0, NULL);
Per Liden4323add2006-01-18 00:38:21 +0100261 p_ptr = tipc_port_lock(ref);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900262 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100263 return -EINVAL;
264
Per Liden4323add2006-01-18 00:38:21 +0100265 tipc_ref_discard(ref);
266 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100267
268 k_cancel_timer(&p_ptr->timer);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500269 if (p_ptr->connected) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100270 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
Per Liden4323add2006-01-18 00:38:21 +0100271 tipc_nodesub_unsubscribe(&p_ptr->subscription);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100272 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100273
Per Liden4323add2006-01-18 00:38:21 +0100274 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100275 list_del(&p_ptr->port_list);
276 list_del(&p_ptr->wait_list);
Per Liden4323add2006-01-18 00:38:21 +0100277 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100278 k_term_timer(&p_ptr->timer);
279 kfree(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100280 tipc_net_route_msg(buf);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700281 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100282}
283
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500284static int port_unreliable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500286 return msg_src_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100287}
288
289int tipc_portunreliable(u32 ref, unsigned int *isunreliable)
290{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500291 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900292
Per Liden4323add2006-01-18 00:38:21 +0100293 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100294 if (!p_ptr)
295 return -EINVAL;
296 *isunreliable = port_unreliable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800297 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700298 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100299}
300
301int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
302{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500303 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900304
Per Liden4323add2006-01-18 00:38:21 +0100305 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100306 if (!p_ptr)
307 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500308 msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100309 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700310 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100311}
312
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500313static int port_unreturnable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100314{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500315 return msg_dest_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100316}
317
318int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable)
319{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500320 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900321
Per Liden4323add2006-01-18 00:38:21 +0100322 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100323 if (!p_ptr)
324 return -EINVAL;
325 *isunrejectable = port_unreturnable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800326 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700327 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100328}
329
330int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
331{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500332 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900333
Per Liden4323add2006-01-18 00:38:21 +0100334 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100335 if (!p_ptr)
336 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500337 msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100338 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700339 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100340}
341
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900342/*
Allan Stephense4a0aee2011-06-01 16:21:12 -0400343 * port_build_proto_msg(): create connection protocol message for port
344 *
345 * On entry the port must be locked and connected.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100346 */
Allan Stephense4a0aee2011-06-01 16:21:12 -0400347static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr,
348 u32 type, u32 ack)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100349{
350 struct sk_buff *buf;
351 struct tipc_msg *msg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900352
Allan Stephens741d9eb2011-05-31 15:03:18 -0400353 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100354 if (buf) {
355 msg = buf_msg(buf);
Allan Stephense4a0aee2011-06-01 16:21:12 -0400356 tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE,
357 port_peernode(p_ptr));
358 msg_set_destport(msg, port_peerport(p_ptr));
359 msg_set_origport(msg, p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360 msg_set_msgcnt(msg, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100361 }
362 return buf;
363}
364
Per Lidenb97bf3f2006-01-02 19:04:38 +0100365int tipc_reject_msg(struct sk_buff *buf, u32 err)
366{
367 struct tipc_msg *msg = buf_msg(buf);
368 struct sk_buff *rbuf;
369 struct tipc_msg *rmsg;
370 int hdr_sz;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400371 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100372 u32 data_sz = msg_data_sz(msg);
Allan Stephens017dac32011-05-24 13:20:09 -0400373 u32 src_node;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400374 u32 rmsg_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100375
376 /* discard rejected message if it shouldn't be returned to sender */
Allan Stephens76d12522011-05-23 13:57:25 -0400377 if (WARN(!msg_isdata(msg),
378 "attempt to reject message with user=%u", msg_user(msg))) {
379 dump_stack();
380 goto exit;
381 }
Allan Stephensacc631b2011-05-23 13:47:44 -0400382 if (msg_errcode(msg) || msg_dest_droppable(msg))
383 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100384
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400385 /*
386 * construct returned message by copying rejected message header and
387 * data (or subset), then updating header fields that need adjusting
388 */
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400389 hdr_sz = msg_hdr_sz(msg);
390 rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE);
391
392 rbuf = tipc_buf_acquire(rmsg_sz);
Allan Stephensacc631b2011-05-23 13:47:44 -0400393 if (rbuf == NULL)
394 goto exit;
395
Per Lidenb97bf3f2006-01-02 19:04:38 +0100396 rmsg = buf_msg(rbuf);
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400397 skb_copy_to_linear_data(rbuf, msg, rmsg_sz);
398
399 if (msg_connected(rmsg)) {
400 imp = msg_importance(rmsg);
401 if (imp < TIPC_CRITICAL_IMPORTANCE)
402 msg_set_importance(rmsg, ++imp);
Allan Stephens99c14592008-06-04 17:48:25 -0700403 }
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400404 msg_set_non_seq(rmsg, 0);
405 msg_set_size(rmsg, rmsg_sz);
406 msg_set_errcode(rmsg, err);
407 msg_set_prevnode(rmsg, tipc_own_addr);
408 msg_swap_words(rmsg, 4, 5);
409 if (!msg_short(rmsg))
410 msg_swap_words(rmsg, 6, 7);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100411
412 /* send self-abort message when rejecting on a connected port */
413 if (msg_connected(msg)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500414 struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100415
416 if (p_ptr) {
Allan Stephensdff10e92011-11-02 10:32:14 -0400417 struct sk_buff *abuf = NULL;
418
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500419 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 abuf = port_build_self_abort_msg(p_ptr, err);
Per Liden4323add2006-01-18 00:38:21 +0100421 tipc_port_unlock(p_ptr);
Allan Stephensdff10e92011-11-02 10:32:14 -0400422 tipc_net_route_msg(abuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100423 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100424 }
425
Allan Stephensacc631b2011-05-23 13:47:44 -0400426 /* send returned message & dispose of rejected message */
Allan Stephens017dac32011-05-24 13:20:09 -0400427 src_node = msg_prevnode(msg);
Allan Stephens630d9202012-04-18 09:42:29 -0400428 if (in_own_node(src_node))
Allan Stephens017dac32011-05-24 13:20:09 -0400429 tipc_port_recv_msg(rbuf);
430 else
431 tipc_link_send(rbuf, src_node, msg_link_selector(rmsg));
Allan Stephensacc631b2011-05-23 13:47:44 -0400432exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400433 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100434 return data_sz;
435}
436
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500437int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr,
Per Liden4323add2006-01-18 00:38:21 +0100438 struct iovec const *msg_sect, u32 num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500439 unsigned int total_len, int err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100440{
441 struct sk_buff *buf;
442 int res;
443
Allan Stephens26896902011-04-21 10:42:07 -0500444 res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE,
Ying Xuef1733d72013-06-17 10:54:43 -0400445 &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100446 if (!buf)
447 return res;
448
449 return tipc_reject_msg(buf, err);
450}
451
452static void port_timeout(unsigned long ref)
453{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500454 struct tipc_port *p_ptr = tipc_port_lock(ref);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800455 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100456
Allan Stephens065fd172006-10-16 21:38:05 -0700457 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100458 return;
459
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500460 if (!p_ptr->connected) {
Allan Stephens065fd172006-10-16 21:38:05 -0700461 tipc_port_unlock(p_ptr);
462 return;
463 }
464
Per Lidenb97bf3f2006-01-02 19:04:38 +0100465 /* Last probe answered ? */
466 if (p_ptr->probing_state == PROBING) {
467 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
468 } else {
Allan Stephense4a0aee2011-06-01 16:21:12 -0400469 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100470 p_ptr->probing_state = PROBING;
471 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
472 }
Per Liden4323add2006-01-18 00:38:21 +0100473 tipc_port_unlock(p_ptr);
474 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100475}
476
477
478static void port_handle_node_down(unsigned long ref)
479{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500480 struct tipc_port *p_ptr = tipc_port_lock(ref);
Allan Stephens0e659672010-12-31 18:59:32 +0000481 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100482
483 if (!p_ptr)
484 return;
485 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE);
Per Liden4323add2006-01-18 00:38:21 +0100486 tipc_port_unlock(p_ptr);
487 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100488}
489
490
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500491static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100492{
Allan Stephense244a912011-05-31 16:10:08 -0400493 struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100494
Allan Stephense244a912011-05-31 16:10:08 -0400495 if (buf) {
496 struct tipc_msg *msg = buf_msg(buf);
497 msg_swap_words(msg, 4, 5);
498 msg_swap_words(msg, 6, 7);
499 }
500 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100501}
502
503
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500504static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100505{
Allan Stephense244a912011-05-31 16:10:08 -0400506 struct sk_buff *buf;
507 struct tipc_msg *msg;
508 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100509
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500510 if (!p_ptr->connected)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800511 return NULL;
Allan Stephense244a912011-05-31 16:10:08 -0400512
513 buf = tipc_buf_acquire(BASIC_H_SIZE);
514 if (buf) {
515 msg = buf_msg(buf);
516 memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE);
517 msg_set_hdr_sz(msg, BASIC_H_SIZE);
518 msg_set_size(msg, BASIC_H_SIZE);
519 imp = msg_importance(msg);
520 if (imp < TIPC_CRITICAL_IMPORTANCE)
521 msg_set_importance(msg, ++imp);
522 msg_set_errcode(msg, err);
523 }
524 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100525}
526
Per Liden4323add2006-01-18 00:38:21 +0100527void tipc_port_recv_proto_msg(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100528{
529 struct tipc_msg *msg = buf_msg(buf);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400530 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800531 struct sk_buff *r_buf = NULL;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400532 u32 destport = msg_destport(msg);
533 int wakeable;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100534
Allan Stephens1c1a5512011-06-01 15:08:10 -0400535 /* Validate connection */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400536 p_ptr = tipc_port_lock(destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400537 if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
Allan Stephensf55b5642011-06-01 15:48:42 -0400538 r_buf = tipc_buf_acquire(BASIC_H_SIZE);
539 if (r_buf) {
540 msg = buf_msg(r_buf);
541 tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG,
Allan Stephensf0712e862012-04-17 18:42:28 -0400542 BASIC_H_SIZE, msg_orignode(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400543 msg_set_errcode(msg, TIPC_ERR_NO_PORT);
544 msg_set_origport(msg, destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400545 msg_set_destport(msg, msg_origport(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400546 }
Allan Stephens1c1a5512011-06-01 15:08:10 -0400547 if (p_ptr)
548 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100549 goto exit;
550 }
551
Allan Stephens1c1a5512011-06-01 15:08:10 -0400552 /* Process protocol message sent by peer */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400553 switch (msg_type(msg)) {
554 case CONN_ACK:
555 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested &&
556 p_ptr->wakeup;
557 p_ptr->acked += msg_msgcnt(msg);
558 if (!tipc_port_congested(p_ptr)) {
559 p_ptr->congested = 0;
560 if (wakeable)
561 p_ptr->wakeup(p_ptr);
562 }
563 break;
564 case CONN_PROBE:
Allan Stephense4a0aee2011-06-01 16:21:12 -0400565 r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400566 break;
567 default:
568 /* CONN_PROBE_REPLY or unrecognized - no action required */
569 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100570 }
571 p_ptr->probing_state = CONFIRMED;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400572 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100573exit:
Per Liden4323add2006-01-18 00:38:21 +0100574 tipc_net_route_msg(r_buf);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400575 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100576}
577
Erik Hugnedc1aed32012-06-29 00:50:23 -0400578static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100579{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900580 struct publication *publ;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400581 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100582
583 if (full_id)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400584 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
585 tipc_zone(tipc_own_addr),
586 tipc_cluster(tipc_own_addr),
587 tipc_node(tipc_own_addr), p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100588 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400589 ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100590
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500591 if (p_ptr->connected) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900592 u32 dport = port_peerport(p_ptr);
593 u32 destnode = port_peernode(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100594
Erik Hugnedc1aed32012-06-29 00:50:23 -0400595 ret += tipc_snprintf(buf + ret, len - ret,
596 " connected to <%u.%u.%u:%u>",
597 tipc_zone(destnode),
598 tipc_cluster(destnode),
599 tipc_node(destnode), dport);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500600 if (p_ptr->conn_type != 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400601 ret += tipc_snprintf(buf + ret, len - ret,
602 " via {%u,%u}", p_ptr->conn_type,
603 p_ptr->conn_instance);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500604 } else if (p_ptr->published) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400605 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900606 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100607 if (publ->lower == publ->upper)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400608 ret += tipc_snprintf(buf + ret, len - ret,
609 " {%u,%u}", publ->type,
610 publ->lower);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100611 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400612 ret += tipc_snprintf(buf + ret, len - ret,
613 " {%u,%u,%u}", publ->type,
614 publ->lower, publ->upper);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900615 }
616 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400617 ret += tipc_snprintf(buf + ret, len - ret, "\n");
618 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100619}
620
Per Liden4323add2006-01-18 00:38:21 +0100621struct sk_buff *tipc_port_get_ports(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100622{
623 struct sk_buff *buf;
624 struct tlv_desc *rep_tlv;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400625 char *pb;
626 int pb_len;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500627 struct tipc_port *p_ptr;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400628 int str_len = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100629
Erik Hugnedc1aed32012-06-29 00:50:23 -0400630 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100631 if (!buf)
632 return NULL;
633 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400634 pb = TLV_DATA(rep_tlv);
635 pb_len = ULTRA_STRING_MAX_LEN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100636
Per Liden4323add2006-01-18 00:38:21 +0100637 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100638 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500639 spin_lock_bh(p_ptr->lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400640 str_len += port_print(p_ptr, pb, pb_len, 0);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500641 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100642 }
Per Liden4323add2006-01-18 00:38:21 +0100643 spin_unlock_bh(&tipc_port_list_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400644 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100645 skb_put(buf, TLV_SPACE(str_len));
646 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
647
648 return buf;
649}
650
Per Liden4323add2006-01-18 00:38:21 +0100651void tipc_port_reinit(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500653 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100654 struct tipc_msg *msg;
655
Per Liden4323add2006-01-18 00:38:21 +0100656 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100657 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500658 msg = &p_ptr->phdr;
Allan Stephens6d4a6672008-05-21 14:54:12 -0700659 msg_set_prevnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100660 msg_set_orignode(msg, tipc_own_addr);
661 }
Per Liden4323add2006-01-18 00:38:21 +0100662 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100663}
664
Per Lidenb97bf3f2006-01-02 19:04:38 +0100665void tipc_acknowledge(u32 ref, u32 ack)
666{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500667 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800668 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100669
Per Liden4323add2006-01-18 00:38:21 +0100670 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100671 if (!p_ptr)
672 return;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500673 if (p_ptr->connected) {
674 p_ptr->conn_unacked -= ack;
Allan Stephense4a0aee2011-06-01 16:21:12 -0400675 buf = port_build_proto_msg(p_ptr, CONN_ACK, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100676 }
Per Liden4323add2006-01-18 00:38:21 +0100677 tipc_port_unlock(p_ptr);
678 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100679}
680
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681int tipc_portimportance(u32 ref, unsigned int *importance)
682{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500683 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900684
Per Liden4323add2006-01-18 00:38:21 +0100685 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100686 if (!p_ptr)
687 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500688 *importance = (unsigned int)msg_importance(&p_ptr->phdr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800689 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700690 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100691}
692
693int tipc_set_portimportance(u32 ref, unsigned int imp)
694{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500695 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100696
697 if (imp > TIPC_CRITICAL_IMPORTANCE)
698 return -EINVAL;
699
Per Liden4323add2006-01-18 00:38:21 +0100700 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100701 if (!p_ptr)
702 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500703 msg_set_importance(&p_ptr->phdr, (u32)imp);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800704 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700705 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100706}
707
708
709int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
710{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500711 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100712 struct publication *publ;
713 u32 key;
714 int res = -EINVAL;
715
Per Liden4323add2006-01-18 00:38:21 +0100716 p_ptr = tipc_port_lock(ref);
Adrian Bunkd55b4c62006-10-31 16:59:35 -0800717 if (!p_ptr)
718 return -EINVAL;
719
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500720 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100721 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100722 key = ref + p_ptr->pub_count + 1;
723 if (key == ref) {
724 res = -EADDRINUSE;
725 goto exit;
726 }
Per Liden4323add2006-01-18 00:38:21 +0100727 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500728 scope, p_ptr->ref, key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100729 if (publ) {
730 list_add(&publ->pport_list, &p_ptr->publications);
731 p_ptr->pub_count++;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500732 p_ptr->published = 1;
Allan Stephens0e35fd52008-07-14 22:44:01 -0700733 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100734 }
735exit:
Per Liden4323add2006-01-18 00:38:21 +0100736 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100737 return res;
738}
739
740int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
741{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500742 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100743 struct publication *publ;
744 struct publication *tpubl;
745 int res = -EINVAL;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900746
Per Liden4323add2006-01-18 00:38:21 +0100747 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100748 if (!p_ptr)
749 return -EINVAL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100750 if (!seq) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900751 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100752 &p_ptr->publications, pport_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900753 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100754 publ->ref, publ->key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100755 }
Allan Stephens0e35fd52008-07-14 22:44:01 -0700756 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100757 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900758 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100759 &p_ptr->publications, pport_list) {
760 if (publ->scope != scope)
761 continue;
762 if (publ->type != seq->type)
763 continue;
764 if (publ->lower != seq->lower)
765 continue;
766 if (publ->upper != seq->upper)
767 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900768 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100769 publ->ref, publ->key);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700770 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100771 break;
772 }
773 }
774 if (list_empty(&p_ptr->publications))
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500775 p_ptr->published = 0;
Per Liden4323add2006-01-18 00:38:21 +0100776 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100777 return res;
778}
779
Paul Gortmakerbc879112012-11-29 13:48:40 -0500780int tipc_connect(u32 ref, struct tipc_portid const *peer)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100781{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500782 struct tipc_port *p_ptr;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500783 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100784
Per Liden4323add2006-01-18 00:38:21 +0100785 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100786 if (!p_ptr)
787 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500788 res = __tipc_connect(ref, p_ptr, peer);
789 tipc_port_unlock(p_ptr);
790 return res;
791}
792
793/*
794 * __tipc_connect - connect to a remote peer
795 *
796 * Port must be locked.
797 */
798int __tipc_connect(u32 ref, struct tipc_port *p_ptr,
799 struct tipc_portid const *peer)
800{
801 struct tipc_msg *msg;
802 int res = -EINVAL;
803
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500804 if (p_ptr->published || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100805 goto exit;
806 if (!peer->ref)
807 goto exit;
808
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500809 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100810 msg_set_destnode(msg, peer->node);
811 msg_set_destport(msg, peer->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100812 msg_set_type(msg, TIPC_CONN_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400813 msg_set_lookup_scope(msg, 0);
Allan Stephens08c80e92010-12-31 18:59:17 +0000814 msg_set_hdr_sz(msg, SHORT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100815
816 p_ptr->probing_interval = PROBING_INTERVAL;
817 p_ptr->probing_state = CONFIRMED;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500818 p_ptr->connected = 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100819 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
820
Allan Stephens0e659672010-12-31 18:59:32 +0000821 tipc_nodesub_subscribe(&p_ptr->subscription, peer->node,
David S. Miller880b0052006-01-12 13:22:32 -0800822 (void *)(unsigned long)ref,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100823 (net_ev_handler)port_handle_node_down);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700824 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100825exit:
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500826 p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100827 return res;
828}
829
Paul Gortmakerbc879112012-11-29 13:48:40 -0500830/*
831 * __tipc_disconnect - disconnect port from peer
Allan Stephens0c3141e2008-04-15 00:22:02 -0700832 *
833 * Port must be locked.
834 */
Paul Gortmakerbc879112012-11-29 13:48:40 -0500835int __tipc_disconnect(struct tipc_port *tp_ptr)
Allan Stephens0c3141e2008-04-15 00:22:02 -0700836{
837 int res;
838
839 if (tp_ptr->connected) {
840 tp_ptr->connected = 0;
841 /* let timer expire on it's own to avoid deadlock! */
Joe Perchese3192692012-06-03 17:41:40 +0000842 tipc_nodesub_unsubscribe(&tp_ptr->subscription);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700843 res = 0;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700844 } else {
845 res = -ENOTCONN;
846 }
847 return res;
848}
849
Per Lidenb97bf3f2006-01-02 19:04:38 +0100850/*
851 * tipc_disconnect(): Disconnect port form peer.
852 * This is a node local operation.
853 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100854int tipc_disconnect(u32 ref)
855{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500856 struct tipc_port *p_ptr;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700857 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100858
Per Liden4323add2006-01-18 00:38:21 +0100859 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100860 if (!p_ptr)
861 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500862 res = __tipc_disconnect(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100863 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100864 return res;
865}
866
867/*
868 * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect
869 */
870int tipc_shutdown(u32 ref)
871{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500872 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800873 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100874
Per Liden4323add2006-01-18 00:38:21 +0100875 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100876 if (!p_ptr)
877 return -EINVAL;
878
Allan Stephense244a912011-05-31 16:10:08 -0400879 buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN);
Per Liden4323add2006-01-18 00:38:21 +0100880 tipc_port_unlock(p_ptr);
881 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100882 return tipc_disconnect(ref);
883}
884
Allan Stephens9b641252011-11-09 13:29:18 -0500885/**
886 * tipc_port_recv_msg - receive message from lower layer and deliver to port user
887 */
Allan Stephens9b641252011-11-09 13:29:18 -0500888int tipc_port_recv_msg(struct sk_buff *buf)
889{
890 struct tipc_port *p_ptr;
891 struct tipc_msg *msg = buf_msg(buf);
892 u32 destport = msg_destport(msg);
893 u32 dsz = msg_data_sz(msg);
894 u32 err;
895
896 /* forward unresolved named message */
897 if (unlikely(!destport)) {
898 tipc_net_route_msg(buf);
899 return dsz;
900 }
901
902 /* validate destination & pass to port, otherwise reject message */
903 p_ptr = tipc_port_lock(destport);
904 if (likely(p_ptr)) {
Allan Stephens9b641252011-11-09 13:29:18 -0500905 err = p_ptr->dispatcher(p_ptr, buf);
906 tipc_port_unlock(p_ptr);
907 if (likely(!err))
908 return dsz;
909 } else {
910 err = TIPC_ERR_NO_PORT;
911 }
Allan Stephensf0712e862012-04-17 18:42:28 -0400912
Allan Stephens9b641252011-11-09 13:29:18 -0500913 return tipc_reject_msg(buf, err);
914}
915
Per Lidenb97bf3f2006-01-02 19:04:38 +0100916/*
Per Liden4323add2006-01-18 00:38:21 +0100917 * tipc_port_recv_sections(): Concatenate and deliver sectioned
Per Lidenb97bf3f2006-01-02 19:04:38 +0100918 * message for this node.
919 */
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500920static int tipc_port_recv_sections(struct tipc_port *sender, unsigned int num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500921 struct iovec const *msg_sect,
922 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100923{
924 struct sk_buff *buf;
925 int res;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900926
Allan Stephens26896902011-04-21 10:42:07 -0500927 res = tipc_msg_build(&sender->phdr, msg_sect, num_sect, total_len,
Ying Xuef1733d72013-06-17 10:54:43 -0400928 MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100929 if (likely(buf))
Per Liden4323add2006-01-18 00:38:21 +0100930 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100931 return res;
932}
933
934/**
935 * tipc_send - send message sections on connection
936 */
Allan Stephens26896902011-04-21 10:42:07 -0500937int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect,
938 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100939{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500940 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100941 u32 destnode;
942 int res;
943
Per Liden4323add2006-01-18 00:38:21 +0100944 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500945 if (!p_ptr || !p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100946 return -EINVAL;
947
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500948 p_ptr->congested = 1;
Per Liden4323add2006-01-18 00:38:21 +0100949 if (!tipc_port_congested(p_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100950 destnode = port_peernode(p_ptr);
Allan Stephens8a55fe72012-04-18 09:27:22 -0400951 if (likely(!in_own_node(destnode)))
Per Liden4323add2006-01-18 00:38:21 +0100952 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -0500953 total_len, destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100954 else
Allan Stephens26896902011-04-21 10:42:07 -0500955 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
956 total_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100957
958 if (likely(res != -ELINKCONG)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500959 p_ptr->congested = 0;
Allan Stephenscb7ce912011-01-24 15:02:14 -0500960 if (res > 0)
961 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100962 return res;
963 }
964 }
965 if (port_unreliable(p_ptr)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500966 p_ptr->congested = 0;
Allan Stephens26896902011-04-21 10:42:07 -0500967 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100968 }
969 return -ELINKCONG;
970}
971
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900972/**
Allan Stephens12bae472010-11-30 12:01:02 +0000973 * tipc_send2name - send message sections to port name
Per Lidenb97bf3f2006-01-02 19:04:38 +0100974 */
Allan Stephens12bae472010-11-30 12:01:02 +0000975int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
Allan Stephens26896902011-04-21 10:42:07 -0500976 unsigned int num_sect, struct iovec const *msg_sect,
977 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100978{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500979 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100980 struct tipc_msg *msg;
981 u32 destnode = domain;
Allan Stephens9ccc2eb2010-05-11 14:30:06 +0000982 u32 destport;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100983 int res;
984
Per Liden4323add2006-01-18 00:38:21 +0100985 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500986 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100987 return -EINVAL;
988
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500989 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100990 msg_set_type(msg, TIPC_NAMED_MSG);
Allan Stephens741d9eb2011-05-31 15:03:18 -0400991 msg_set_hdr_sz(msg, NAMED_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100992 msg_set_nametype(msg, name->type);
993 msg_set_nameinst(msg, name->instance);
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000994 msg_set_lookup_scope(msg, tipc_addr_scope(domain));
Per Liden4323add2006-01-18 00:38:21 +0100995 destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100996 msg_set_destnode(msg, destnode);
997 msg_set_destport(msg, destport);
998
Allan Stephensbc9f8142011-11-07 17:00:54 -0500999 if (likely(destport || destnode)) {
Allan Stephens8a55fe72012-04-18 09:27:22 -04001000 if (likely(in_own_node(destnode)))
Allan Stephenscb7ce912011-01-24 15:02:14 -05001001 res = tipc_port_recv_sections(p_ptr, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001002 msg_sect, total_len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001003 else if (tipc_own_addr)
Allan Stephenscb7ce912011-01-24 15:02:14 -05001004 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001005 num_sect, total_len,
1006 destnode);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001007 else
1008 res = tipc_port_reject_sections(p_ptr, msg, msg_sect,
1009 num_sect, total_len,
1010 TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001011 if (likely(res != -ELINKCONG)) {
1012 if (res > 0)
1013 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001014 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001015 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001016 if (port_unreliable(p_ptr)) {
Allan Stephens26896902011-04-21 10:42:07 -05001017 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001018 }
1019 return -ELINKCONG;
1020 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09001021 return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001022 total_len, TIPC_ERR_NO_NAME);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001023}
1024
1025/**
Allan Stephens12bae472010-11-30 12:01:02 +00001026 * tipc_send2port - send message sections to port identity
Per Lidenb97bf3f2006-01-02 19:04:38 +01001027 */
Allan Stephens12bae472010-11-30 12:01:02 +00001028int tipc_send2port(u32 ref, struct tipc_portid const *dest,
Allan Stephens26896902011-04-21 10:42:07 -05001029 unsigned int num_sect, struct iovec const *msg_sect,
1030 unsigned int total_len)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001031{
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001032 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001033 struct tipc_msg *msg;
1034 int res;
1035
Per Liden4323add2006-01-18 00:38:21 +01001036 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001037 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001038 return -EINVAL;
1039
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001040 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001041 msg_set_type(msg, TIPC_DIRECT_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -04001042 msg_set_lookup_scope(msg, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001043 msg_set_destnode(msg, dest->node);
1044 msg_set_destport(msg, dest->ref);
Allan Stephens741d9eb2011-05-31 15:03:18 -04001045 msg_set_hdr_sz(msg, BASIC_H_SIZE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001046
Allan Stephens8a55fe72012-04-18 09:27:22 -04001047 if (in_own_node(dest->node))
Allan Stephens26896902011-04-21 10:42:07 -05001048 res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect,
1049 total_len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001050 else if (tipc_own_addr)
Allan Stephenscb7ce912011-01-24 15:02:14 -05001051 res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect,
Allan Stephens26896902011-04-21 10:42:07 -05001052 total_len, dest->node);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001053 else
1054 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect,
1055 total_len, TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001056 if (likely(res != -ELINKCONG)) {
1057 if (res > 0)
1058 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001059 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001060 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001061 if (port_unreliable(p_ptr)) {
Allan Stephens26896902011-04-21 10:42:07 -05001062 return total_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001063 }
1064 return -ELINKCONG;
1065}