blob: d1abe11041209b7a20e35e7c3d65f1f4b0644b39 [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
Ben Hutchings2c530402012-07-10 10:55:09 +000057/**
Allan Stephensf0712e862012-04-17 18:42:28 -040058 * tipc_port_peer_msg - verify message was sent by connected port's peer
59 *
60 * Handles cases where the node's network address has changed from
61 * the default of <0.0.0> to its configured setting.
62 */
Allan Stephensf0712e862012-04-17 18:42:28 -040063int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg)
64{
65 u32 peernode;
66 u32 orignode;
67
Jon Paul Maloyf9fef182014-03-12 11:31:08 -040068 if (msg_origport(msg) != tipc_port_peerport(p_ptr))
Allan Stephensf0712e862012-04-17 18:42:28 -040069 return 0;
70
71 orignode = msg_orignode(msg);
Jon Paul Maloyf9fef182014-03-12 11:31:08 -040072 peernode = tipc_port_peernode(p_ptr);
Allan Stephensf0712e862012-04-17 18:42:28 -040073 return (orignode == peernode) ||
74 (!orignode && (peernode == tipc_own_addr)) ||
75 (!peernode && (orignode == tipc_own_addr));
76}
77
Per Lidenb97bf3f2006-01-02 19:04:38 +010078/**
Ying Xue247f0f32014-02-18 16:06:46 +080079 * tipc_port_mcast_xmit - send a multicast message to local and remote
80 * destinations
Per Lidenb97bf3f2006-01-02 19:04:38 +010081 */
Ying Xue247f0f32014-02-18 16:06:46 +080082int tipc_port_mcast_xmit(u32 ref, struct tipc_name_seq const *seq,
83 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +010084{
85 struct tipc_msg *hdr;
86 struct sk_buff *buf;
87 struct sk_buff *ibuf = NULL;
Paul Gortmaker45843102011-12-29 20:33:30 -050088 struct tipc_port_list dports = {0, NULL, };
Allan Stephens23dd4cc2011-01-07 11:43:40 -050089 struct tipc_port *oport = tipc_port_deref(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +010090 int ext_targets;
91 int res;
92
93 if (unlikely(!oport))
94 return -EINVAL;
95
96 /* Create multicast message */
Allan Stephens23dd4cc2011-01-07 11:43:40 -050097 hdr = &oport->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +010098 msg_set_type(hdr, TIPC_MCAST_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -040099 msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE);
Allan Stephens7462b9e2011-04-18 10:08:22 -0400100 msg_set_destport(hdr, 0);
101 msg_set_destnode(hdr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100102 msg_set_nametype(hdr, seq->type);
103 msg_set_namelower(hdr, seq->lower);
104 msg_set_nameupper(hdr, seq->upper);
105 msg_set_hdr_sz(hdr, MCAST_H_SIZE);
Ying Xue9446b872013-10-18 07:23:15 +0200106 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100107 if (unlikely(!buf))
108 return res;
109
110 /* Figure out where to send multicast message */
Per Liden4323add2006-01-18 00:38:21 +0100111 ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper,
112 TIPC_NODE_SCOPE, &dports);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900113
114 /* Send message to destinations (duplicate it only if necessary) */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100115 if (ext_targets) {
116 if (dports.count != 0) {
117 ibuf = skb_copy(buf, GFP_ATOMIC);
118 if (ibuf == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100119 tipc_port_list_free(&dports);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400120 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100121 return -ENOMEM;
122 }
123 }
Ying Xue247f0f32014-02-18 16:06:46 +0800124 res = tipc_bclink_xmit(buf);
Allan Stephensa0168922010-12-31 18:59:35 +0000125 if ((res < 0) && (dports.count != 0))
Allan Stephens5f6d9122011-11-04 13:24:29 -0400126 kfree_skb(ibuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127 } else {
128 ibuf = buf;
129 }
130
131 if (res >= 0) {
132 if (ibuf)
Ying Xue247f0f32014-02-18 16:06:46 +0800133 tipc_port_mcast_rcv(ibuf, &dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100134 } else {
Per Liden4323add2006-01-18 00:38:21 +0100135 tipc_port_list_free(&dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100136 }
137 return res;
138}
139
140/**
Ying Xue247f0f32014-02-18 16:06:46 +0800141 * tipc_port_mcast_rcv - deliver multicast message to all destination ports
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900142 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100143 * If there is no port list, perform a lookup to create one
144 */
Ying Xue247f0f32014-02-18 16:06:46 +0800145void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146{
Allan Stephens0e659672010-12-31 18:59:32 +0000147 struct tipc_msg *msg;
Paul Gortmaker45843102011-12-29 20:33:30 -0500148 struct tipc_port_list dports = {0, NULL, };
149 struct tipc_port_list *item = dp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100150 int cnt = 0;
151
Per Lidenb97bf3f2006-01-02 19:04:38 +0100152 msg = buf_msg(buf);
153
154 /* Create destination port list, if one wasn't supplied */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100155 if (dp == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100156 tipc_nametbl_mc_translate(msg_nametype(msg),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100157 msg_namelower(msg),
158 msg_nameupper(msg),
159 TIPC_CLUSTER_SCOPE,
160 &dports);
161 item = dp = &dports;
162 }
163
164 /* Deliver a copy of message to each destination port */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100165 if (dp->count != 0) {
Allan Stephens7f47f5c2011-04-18 10:14:26 -0400166 msg_set_destnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100167 if (dp->count == 1) {
168 msg_set_destport(msg, dp->ports[0]);
Ying Xue247f0f32014-02-18 16:06:46 +0800169 tipc_port_rcv(buf);
Per Liden4323add2006-01-18 00:38:21 +0100170 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100171 return;
172 }
173 for (; cnt < dp->count; cnt++) {
174 int index = cnt % PLSIZE;
175 struct sk_buff *b = skb_clone(buf, GFP_ATOMIC);
176
177 if (b == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400178 pr_warn("Unable to deliver multicast message(s)\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100179 goto exit;
180 }
Allan Stephensa0168922010-12-31 18:59:35 +0000181 if ((index == 0) && (cnt != 0))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100182 item = item->next;
Allan Stephens0e659672010-12-31 18:59:32 +0000183 msg_set_destport(buf_msg(b), item->ports[index]);
Ying Xue247f0f32014-02-18 16:06:46 +0800184 tipc_port_rcv(b);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100185 }
186 }
187exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400188 kfree_skb(buf);
Per Liden4323add2006-01-18 00:38:21 +0100189 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100190}
191
192/**
Ying Xue3c5db8e2013-06-17 10:54:44 -0400193 * tipc_createport - create a generic TIPC port
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900194 *
Allan Stephens0ea52242008-07-14 22:42:19 -0700195 * Returns pointer to (locked) TIPC port, or NULL if unable to create it
Per Lidenb97bf3f2006-01-02 19:04:38 +0100196 */
Ying Xuec0fee8a2013-06-17 10:54:46 -0400197struct tipc_port *tipc_createport(struct sock *sk,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400198 u32 (*dispatcher)(struct tipc_port *,
199 struct sk_buff *),
200 void (*wakeup)(struct tipc_port *),
201 const u32 importance)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100202{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500203 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100204 struct tipc_msg *msg;
205 u32 ref;
206
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700207 p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -0700208 if (!p_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400209 pr_warn("Port creation failed, no memory\n");
Allan Stephens0ea52242008-07-14 22:42:19 -0700210 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100211 }
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500212 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100213 if (!ref) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400214 pr_warn("Port creation failed, ref. table exhausted\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100215 kfree(p_ptr);
Allan Stephens0ea52242008-07-14 22:42:19 -0700216 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100217 }
218
Ying Xuec0fee8a2013-06-17 10:54:46 -0400219 p_ptr->sk = sk;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500220 p_ptr->max_pkt = MAX_PKT_DEFAULT;
221 p_ptr->ref = ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100222 INIT_LIST_HEAD(&p_ptr->wait_list);
223 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100224 p_ptr->dispatcher = dispatcher;
225 p_ptr->wakeup = wakeup;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100226 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100227 INIT_LIST_HEAD(&p_ptr->publications);
228 INIT_LIST_HEAD(&p_ptr->port_list);
Allan Stephensf21536d2012-04-17 18:22:49 -0400229
230 /*
231 * Must hold port list lock while initializing message header template
232 * to ensure a change to node's own network address doesn't result
233 * in template containing out-dated network address information
234 */
Allan Stephensf21536d2012-04-17 18:22:49 -0400235 spin_lock_bh(&tipc_port_list_lock);
236 msg = &p_ptr->phdr;
237 tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
238 msg_set_origport(msg, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100239 list_add_tail(&p_ptr->port_list, &ports);
Per Liden4323add2006-01-18 00:38:21 +0100240 spin_unlock_bh(&tipc_port_list_lock);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500241 return p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100242}
243
Ying Xue84602762013-12-27 10:18:28 +0800244int tipc_deleteport(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100245{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800246 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100247
Ying Xue84602762013-12-27 10:18:28 +0800248 tipc_withdraw(p_ptr, 0, NULL);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100249
Ying Xue84602762013-12-27 10:18:28 +0800250 spin_lock_bh(p_ptr->lock);
251 tipc_ref_discard(p_ptr->ref);
252 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100253
254 k_cancel_timer(&p_ptr->timer);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500255 if (p_ptr->connected) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100256 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
Per Liden4323add2006-01-18 00:38:21 +0100257 tipc_nodesub_unsubscribe(&p_ptr->subscription);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100258 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100259
Per Liden4323add2006-01-18 00:38:21 +0100260 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100261 list_del(&p_ptr->port_list);
262 list_del(&p_ptr->wait_list);
Per Liden4323add2006-01-18 00:38:21 +0100263 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264 k_term_timer(&p_ptr->timer);
265 kfree(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100266 tipc_net_route_msg(buf);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700267 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100268}
269
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500270static int port_unreliable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100271{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500272 return msg_src_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100273}
274
275int tipc_portunreliable(u32 ref, unsigned int *isunreliable)
276{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500277 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900278
Per Liden4323add2006-01-18 00:38:21 +0100279 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100280 if (!p_ptr)
281 return -EINVAL;
282 *isunreliable = port_unreliable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800283 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700284 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285}
286
287int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
288{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500289 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900290
Per Liden4323add2006-01-18 00:38:21 +0100291 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100292 if (!p_ptr)
293 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500294 msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100295 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700296 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100297}
298
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500299static int port_unreturnable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500301 return msg_dest_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100302}
303
304int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable)
305{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500306 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900307
Per Liden4323add2006-01-18 00:38:21 +0100308 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100309 if (!p_ptr)
310 return -EINVAL;
311 *isunrejectable = port_unreturnable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800312 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700313 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100314}
315
316int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
317{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500318 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900319
Per Liden4323add2006-01-18 00:38:21 +0100320 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100321 if (!p_ptr)
322 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500323 msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100324 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700325 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100326}
327
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900328/*
Allan Stephense4a0aee2011-06-01 16:21:12 -0400329 * port_build_proto_msg(): create connection protocol message for port
330 *
331 * On entry the port must be locked and connected.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100332 */
Allan Stephense4a0aee2011-06-01 16:21:12 -0400333static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr,
334 u32 type, u32 ack)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100335{
336 struct sk_buff *buf;
337 struct tipc_msg *msg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900338
Allan Stephens741d9eb2011-05-31 15:03:18 -0400339 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100340 if (buf) {
341 msg = buf_msg(buf);
Allan Stephense4a0aee2011-06-01 16:21:12 -0400342 tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE,
Jon Paul Maloyf9fef182014-03-12 11:31:08 -0400343 tipc_port_peernode(p_ptr));
344 msg_set_destport(msg, tipc_port_peerport(p_ptr));
Allan Stephense4a0aee2011-06-01 16:21:12 -0400345 msg_set_origport(msg, p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100346 msg_set_msgcnt(msg, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100347 }
348 return buf;
349}
350
Per Lidenb97bf3f2006-01-02 19:04:38 +0100351int tipc_reject_msg(struct sk_buff *buf, u32 err)
352{
353 struct tipc_msg *msg = buf_msg(buf);
354 struct sk_buff *rbuf;
355 struct tipc_msg *rmsg;
356 int hdr_sz;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400357 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100358 u32 data_sz = msg_data_sz(msg);
Allan Stephens017dac32011-05-24 13:20:09 -0400359 u32 src_node;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400360 u32 rmsg_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100361
362 /* discard rejected message if it shouldn't be returned to sender */
Allan Stephens76d12522011-05-23 13:57:25 -0400363 if (WARN(!msg_isdata(msg),
364 "attempt to reject message with user=%u", msg_user(msg))) {
365 dump_stack();
366 goto exit;
367 }
Allan Stephensacc631b2011-05-23 13:47:44 -0400368 if (msg_errcode(msg) || msg_dest_droppable(msg))
369 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100370
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400371 /*
372 * construct returned message by copying rejected message header and
373 * data (or subset), then updating header fields that need adjusting
374 */
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400375 hdr_sz = msg_hdr_sz(msg);
376 rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE);
377
378 rbuf = tipc_buf_acquire(rmsg_sz);
Allan Stephensacc631b2011-05-23 13:47:44 -0400379 if (rbuf == NULL)
380 goto exit;
381
Per Lidenb97bf3f2006-01-02 19:04:38 +0100382 rmsg = buf_msg(rbuf);
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400383 skb_copy_to_linear_data(rbuf, msg, rmsg_sz);
384
385 if (msg_connected(rmsg)) {
386 imp = msg_importance(rmsg);
387 if (imp < TIPC_CRITICAL_IMPORTANCE)
388 msg_set_importance(rmsg, ++imp);
Allan Stephens99c14592008-06-04 17:48:25 -0700389 }
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400390 msg_set_non_seq(rmsg, 0);
391 msg_set_size(rmsg, rmsg_sz);
392 msg_set_errcode(rmsg, err);
393 msg_set_prevnode(rmsg, tipc_own_addr);
394 msg_swap_words(rmsg, 4, 5);
395 if (!msg_short(rmsg))
396 msg_swap_words(rmsg, 6, 7);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100397
398 /* send self-abort message when rejecting on a connected port */
399 if (msg_connected(msg)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500400 struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100401
402 if (p_ptr) {
Allan Stephensdff10e92011-11-02 10:32:14 -0400403 struct sk_buff *abuf = NULL;
404
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500405 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100406 abuf = port_build_self_abort_msg(p_ptr, err);
Per Liden4323add2006-01-18 00:38:21 +0100407 tipc_port_unlock(p_ptr);
Allan Stephensdff10e92011-11-02 10:32:14 -0400408 tipc_net_route_msg(abuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100409 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410 }
411
Allan Stephensacc631b2011-05-23 13:47:44 -0400412 /* send returned message & dispose of rejected message */
Allan Stephens017dac32011-05-24 13:20:09 -0400413 src_node = msg_prevnode(msg);
Allan Stephens630d9202012-04-18 09:42:29 -0400414 if (in_own_node(src_node))
Ying Xue247f0f32014-02-18 16:06:46 +0800415 tipc_port_rcv(rbuf);
Allan Stephens017dac32011-05-24 13:20:09 -0400416 else
Ying Xue247f0f32014-02-18 16:06:46 +0800417 tipc_link_xmit(rbuf, src_node, msg_link_selector(rmsg));
Allan Stephensacc631b2011-05-23 13:47:44 -0400418exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400419 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 return data_sz;
421}
422
Ying Xue247f0f32014-02-18 16:06:46 +0800423int tipc_port_iovec_reject(struct tipc_port *p_ptr, struct tipc_msg *hdr,
424 struct iovec const *msg_sect, unsigned int len,
425 int err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100426{
427 struct sk_buff *buf;
428 int res;
429
Ying Xue9446b872013-10-18 07:23:15 +0200430 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100431 if (!buf)
432 return res;
433
434 return tipc_reject_msg(buf, err);
435}
436
437static void port_timeout(unsigned long ref)
438{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500439 struct tipc_port *p_ptr = tipc_port_lock(ref);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800440 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441
Allan Stephens065fd172006-10-16 21:38:05 -0700442 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100443 return;
444
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500445 if (!p_ptr->connected) {
Allan Stephens065fd172006-10-16 21:38:05 -0700446 tipc_port_unlock(p_ptr);
447 return;
448 }
449
Per Lidenb97bf3f2006-01-02 19:04:38 +0100450 /* Last probe answered ? */
451 if (p_ptr->probing_state == PROBING) {
452 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
453 } else {
Allan Stephense4a0aee2011-06-01 16:21:12 -0400454 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100455 p_ptr->probing_state = PROBING;
456 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
457 }
Per Liden4323add2006-01-18 00:38:21 +0100458 tipc_port_unlock(p_ptr);
459 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100460}
461
462
463static void port_handle_node_down(unsigned long ref)
464{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500465 struct tipc_port *p_ptr = tipc_port_lock(ref);
Allan Stephens0e659672010-12-31 18:59:32 +0000466 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100467
468 if (!p_ptr)
469 return;
470 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE);
Per Liden4323add2006-01-18 00:38:21 +0100471 tipc_port_unlock(p_ptr);
472 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100473}
474
475
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500476static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100477{
Allan Stephense244a912011-05-31 16:10:08 -0400478 struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100479
Allan Stephense244a912011-05-31 16:10:08 -0400480 if (buf) {
481 struct tipc_msg *msg = buf_msg(buf);
482 msg_swap_words(msg, 4, 5);
483 msg_swap_words(msg, 6, 7);
484 }
485 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100486}
487
488
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500489static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100490{
Allan Stephense244a912011-05-31 16:10:08 -0400491 struct sk_buff *buf;
492 struct tipc_msg *msg;
493 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100494
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500495 if (!p_ptr->connected)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800496 return NULL;
Allan Stephense244a912011-05-31 16:10:08 -0400497
498 buf = tipc_buf_acquire(BASIC_H_SIZE);
499 if (buf) {
500 msg = buf_msg(buf);
501 memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE);
502 msg_set_hdr_sz(msg, BASIC_H_SIZE);
503 msg_set_size(msg, BASIC_H_SIZE);
504 imp = msg_importance(msg);
505 if (imp < TIPC_CRITICAL_IMPORTANCE)
506 msg_set_importance(msg, ++imp);
507 msg_set_errcode(msg, err);
508 }
509 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510}
511
Ying Xue247f0f32014-02-18 16:06:46 +0800512void tipc_port_proto_rcv(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100513{
514 struct tipc_msg *msg = buf_msg(buf);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400515 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800516 struct sk_buff *r_buf = NULL;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400517 u32 destport = msg_destport(msg);
518 int wakeable;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100519
Allan Stephens1c1a5512011-06-01 15:08:10 -0400520 /* Validate connection */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400521 p_ptr = tipc_port_lock(destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400522 if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
Allan Stephensf55b5642011-06-01 15:48:42 -0400523 r_buf = tipc_buf_acquire(BASIC_H_SIZE);
524 if (r_buf) {
525 msg = buf_msg(r_buf);
526 tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG,
Allan Stephensf0712e862012-04-17 18:42:28 -0400527 BASIC_H_SIZE, msg_orignode(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400528 msg_set_errcode(msg, TIPC_ERR_NO_PORT);
529 msg_set_origport(msg, destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400530 msg_set_destport(msg, msg_origport(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400531 }
Allan Stephens1c1a5512011-06-01 15:08:10 -0400532 if (p_ptr)
533 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100534 goto exit;
535 }
536
Allan Stephens1c1a5512011-06-01 15:08:10 -0400537 /* Process protocol message sent by peer */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400538 switch (msg_type(msg)) {
539 case CONN_ACK:
540 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested &&
541 p_ptr->wakeup;
542 p_ptr->acked += msg_msgcnt(msg);
543 if (!tipc_port_congested(p_ptr)) {
544 p_ptr->congested = 0;
545 if (wakeable)
546 p_ptr->wakeup(p_ptr);
547 }
548 break;
549 case CONN_PROBE:
Allan Stephense4a0aee2011-06-01 16:21:12 -0400550 r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400551 break;
552 default:
553 /* CONN_PROBE_REPLY or unrecognized - no action required */
554 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100555 }
556 p_ptr->probing_state = CONFIRMED;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400557 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100558exit:
Per Liden4323add2006-01-18 00:38:21 +0100559 tipc_net_route_msg(r_buf);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400560 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100561}
562
Erik Hugnedc1aed32012-06-29 00:50:23 -0400563static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100564{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900565 struct publication *publ;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400566 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100567
568 if (full_id)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400569 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
570 tipc_zone(tipc_own_addr),
571 tipc_cluster(tipc_own_addr),
572 tipc_node(tipc_own_addr), p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100573 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400574 ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100575
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500576 if (p_ptr->connected) {
Jon Paul Maloyf9fef182014-03-12 11:31:08 -0400577 u32 dport = tipc_port_peerport(p_ptr);
578 u32 destnode = tipc_port_peernode(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100579
Erik Hugnedc1aed32012-06-29 00:50:23 -0400580 ret += tipc_snprintf(buf + ret, len - ret,
581 " connected to <%u.%u.%u:%u>",
582 tipc_zone(destnode),
583 tipc_cluster(destnode),
584 tipc_node(destnode), dport);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500585 if (p_ptr->conn_type != 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400586 ret += tipc_snprintf(buf + ret, len - ret,
587 " via {%u,%u}", p_ptr->conn_type,
588 p_ptr->conn_instance);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500589 } else if (p_ptr->published) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400590 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900591 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100592 if (publ->lower == publ->upper)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400593 ret += tipc_snprintf(buf + ret, len - ret,
594 " {%u,%u}", publ->type,
595 publ->lower);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100596 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400597 ret += tipc_snprintf(buf + ret, len - ret,
598 " {%u,%u,%u}", publ->type,
599 publ->lower, publ->upper);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900600 }
601 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400602 ret += tipc_snprintf(buf + ret, len - ret, "\n");
603 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100604}
605
Per Liden4323add2006-01-18 00:38:21 +0100606struct sk_buff *tipc_port_get_ports(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100607{
608 struct sk_buff *buf;
609 struct tlv_desc *rep_tlv;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400610 char *pb;
611 int pb_len;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500612 struct tipc_port *p_ptr;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400613 int str_len = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100614
Erik Hugnedc1aed32012-06-29 00:50:23 -0400615 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100616 if (!buf)
617 return NULL;
618 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400619 pb = TLV_DATA(rep_tlv);
620 pb_len = ULTRA_STRING_MAX_LEN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100621
Per Liden4323add2006-01-18 00:38:21 +0100622 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100623 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500624 spin_lock_bh(p_ptr->lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400625 str_len += port_print(p_ptr, pb, pb_len, 0);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500626 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100627 }
Per Liden4323add2006-01-18 00:38:21 +0100628 spin_unlock_bh(&tipc_port_list_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400629 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100630 skb_put(buf, TLV_SPACE(str_len));
631 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
632
633 return buf;
634}
635
Per Liden4323add2006-01-18 00:38:21 +0100636void tipc_port_reinit(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100637{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500638 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100639 struct tipc_msg *msg;
640
Per Liden4323add2006-01-18 00:38:21 +0100641 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100642 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500643 msg = &p_ptr->phdr;
Allan Stephens6d4a6672008-05-21 14:54:12 -0700644 msg_set_prevnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100645 msg_set_orignode(msg, tipc_own_addr);
646 }
Per Liden4323add2006-01-18 00:38:21 +0100647 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100648}
649
Per Lidenb97bf3f2006-01-02 19:04:38 +0100650void tipc_acknowledge(u32 ref, u32 ack)
651{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500652 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800653 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100654
Per Liden4323add2006-01-18 00:38:21 +0100655 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100656 if (!p_ptr)
657 return;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500658 if (p_ptr->connected) {
659 p_ptr->conn_unacked -= ack;
Allan Stephense4a0aee2011-06-01 16:21:12 -0400660 buf = port_build_proto_msg(p_ptr, CONN_ACK, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100661 }
Per Liden4323add2006-01-18 00:38:21 +0100662 tipc_port_unlock(p_ptr);
663 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100664}
665
Per Lidenb97bf3f2006-01-02 19:04:38 +0100666int tipc_portimportance(u32 ref, unsigned int *importance)
667{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500668 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900669
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 -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500673 *importance = (unsigned int)msg_importance(&p_ptr->phdr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800674 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700675 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100676}
677
678int tipc_set_portimportance(u32 ref, unsigned int imp)
679{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500680 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681
682 if (imp > TIPC_CRITICAL_IMPORTANCE)
683 return -EINVAL;
684
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 msg_set_importance(&p_ptr->phdr, (u32)imp);
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
693
Ying Xue84602762013-12-27 10:18:28 +0800694int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
695 struct tipc_name_seq const *seq)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100696{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100697 struct publication *publ;
698 u32 key;
Adrian Bunkd55b4c62006-10-31 16:59:35 -0800699
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500700 if (p_ptr->connected)
Ying Xue84602762013-12-27 10:18:28 +0800701 return -EINVAL;
702 key = p_ptr->ref + p_ptr->pub_count + 1;
703 if (key == p_ptr->ref)
704 return -EADDRINUSE;
705
Per Liden4323add2006-01-18 00:38:21 +0100706 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500707 scope, p_ptr->ref, key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100708 if (publ) {
709 list_add(&publ->pport_list, &p_ptr->publications);
710 p_ptr->pub_count++;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500711 p_ptr->published = 1;
Ying Xue84602762013-12-27 10:18:28 +0800712 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713 }
Ying Xue84602762013-12-27 10:18:28 +0800714 return -EINVAL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100715}
716
Ying Xue84602762013-12-27 10:18:28 +0800717int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,
718 struct tipc_name_seq const *seq)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100719{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100720 struct publication *publ;
721 struct publication *tpubl;
722 int res = -EINVAL;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900723
Per Lidenb97bf3f2006-01-02 19:04:38 +0100724 if (!seq) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900725 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100726 &p_ptr->publications, pport_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900727 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100728 publ->ref, publ->key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100729 }
Allan Stephens0e35fd52008-07-14 22:44:01 -0700730 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100731 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900732 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100733 &p_ptr->publications, pport_list) {
734 if (publ->scope != scope)
735 continue;
736 if (publ->type != seq->type)
737 continue;
738 if (publ->lower != seq->lower)
739 continue;
740 if (publ->upper != seq->upper)
741 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900742 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100743 publ->ref, publ->key);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700744 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100745 break;
746 }
747 }
748 if (list_empty(&p_ptr->publications))
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500749 p_ptr->published = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100750 return res;
751}
752
Ying Xue247f0f32014-02-18 16:06:46 +0800753int tipc_port_connect(u32 ref, struct tipc_portid const *peer)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100754{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500755 struct tipc_port *p_ptr;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500756 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100757
Per Liden4323add2006-01-18 00:38:21 +0100758 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100759 if (!p_ptr)
760 return -EINVAL;
Ying Xue247f0f32014-02-18 16:06:46 +0800761 res = __tipc_port_connect(ref, p_ptr, peer);
Paul Gortmakerbc879112012-11-29 13:48:40 -0500762 tipc_port_unlock(p_ptr);
763 return res;
764}
765
766/*
Ying Xue247f0f32014-02-18 16:06:46 +0800767 * __tipc_port_connect - connect to a remote peer
Paul Gortmakerbc879112012-11-29 13:48:40 -0500768 *
769 * Port must be locked.
770 */
Ying Xue247f0f32014-02-18 16:06:46 +0800771int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr,
Paul Gortmakerbc879112012-11-29 13:48:40 -0500772 struct tipc_portid const *peer)
773{
774 struct tipc_msg *msg;
775 int res = -EINVAL;
776
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500777 if (p_ptr->published || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100778 goto exit;
779 if (!peer->ref)
780 goto exit;
781
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500782 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100783 msg_set_destnode(msg, peer->node);
784 msg_set_destport(msg, peer->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100785 msg_set_type(msg, TIPC_CONN_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400786 msg_set_lookup_scope(msg, 0);
Allan Stephens08c80e92010-12-31 18:59:17 +0000787 msg_set_hdr_sz(msg, SHORT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100788
789 p_ptr->probing_interval = PROBING_INTERVAL;
790 p_ptr->probing_state = CONFIRMED;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500791 p_ptr->connected = 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100792 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
793
Allan Stephens0e659672010-12-31 18:59:32 +0000794 tipc_nodesub_subscribe(&p_ptr->subscription, peer->node,
David S. Miller880b0052006-01-12 13:22:32 -0800795 (void *)(unsigned long)ref,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100796 (net_ev_handler)port_handle_node_down);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700797 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100798exit:
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500799 p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100800 return res;
801}
802
Paul Gortmakerbc879112012-11-29 13:48:40 -0500803/*
804 * __tipc_disconnect - disconnect port from peer
Allan Stephens0c3141e2008-04-15 00:22:02 -0700805 *
806 * Port must be locked.
807 */
Ying Xue247f0f32014-02-18 16:06:46 +0800808int __tipc_port_disconnect(struct tipc_port *tp_ptr)
Allan Stephens0c3141e2008-04-15 00:22:02 -0700809{
Allan Stephens0c3141e2008-04-15 00:22:02 -0700810 if (tp_ptr->connected) {
811 tp_ptr->connected = 0;
812 /* let timer expire on it's own to avoid deadlock! */
Joe Perchese3192692012-06-03 17:41:40 +0000813 tipc_nodesub_unsubscribe(&tp_ptr->subscription);
wangweidong0cee6bb2013-12-12 09:36:39 +0800814 return 0;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700815 }
wangweidong0cee6bb2013-12-12 09:36:39 +0800816
817 return -ENOTCONN;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700818}
819
Per Lidenb97bf3f2006-01-02 19:04:38 +0100820/*
Ying Xue247f0f32014-02-18 16:06:46 +0800821 * tipc_port_disconnect(): Disconnect port form peer.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100822 * This is a node local operation.
823 */
Ying Xue247f0f32014-02-18 16:06:46 +0800824int tipc_port_disconnect(u32 ref)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100825{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500826 struct tipc_port *p_ptr;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700827 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100828
Per Liden4323add2006-01-18 00:38:21 +0100829 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100830 if (!p_ptr)
831 return -EINVAL;
Ying Xue247f0f32014-02-18 16:06:46 +0800832 res = __tipc_port_disconnect(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100833 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100834 return res;
835}
836
837/*
Ying Xue247f0f32014-02-18 16:06:46 +0800838 * tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect
Per Lidenb97bf3f2006-01-02 19:04:38 +0100839 */
Ying Xue247f0f32014-02-18 16:06:46 +0800840int tipc_port_shutdown(u32 ref)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100841{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500842 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800843 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100844
Per Liden4323add2006-01-18 00:38:21 +0100845 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100846 if (!p_ptr)
847 return -EINVAL;
848
Allan Stephense244a912011-05-31 16:10:08 -0400849 buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN);
Per Liden4323add2006-01-18 00:38:21 +0100850 tipc_port_unlock(p_ptr);
851 tipc_net_route_msg(buf);
Ying Xue247f0f32014-02-18 16:06:46 +0800852 return tipc_port_disconnect(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100853}
854
Allan Stephens9b641252011-11-09 13:29:18 -0500855/**
Ying Xue247f0f32014-02-18 16:06:46 +0800856 * tipc_port_rcv - receive message from lower layer and deliver to port user
Allan Stephens9b641252011-11-09 13:29:18 -0500857 */
Ying Xue247f0f32014-02-18 16:06:46 +0800858int tipc_port_rcv(struct sk_buff *buf)
Allan Stephens9b641252011-11-09 13:29:18 -0500859{
860 struct tipc_port *p_ptr;
861 struct tipc_msg *msg = buf_msg(buf);
862 u32 destport = msg_destport(msg);
863 u32 dsz = msg_data_sz(msg);
864 u32 err;
865
866 /* forward unresolved named message */
867 if (unlikely(!destport)) {
868 tipc_net_route_msg(buf);
869 return dsz;
870 }
871
872 /* validate destination & pass to port, otherwise reject message */
873 p_ptr = tipc_port_lock(destport);
874 if (likely(p_ptr)) {
Allan Stephens9b641252011-11-09 13:29:18 -0500875 err = p_ptr->dispatcher(p_ptr, buf);
876 tipc_port_unlock(p_ptr);
877 if (likely(!err))
878 return dsz;
879 } else {
880 err = TIPC_ERR_NO_PORT;
881 }
Allan Stephensf0712e862012-04-17 18:42:28 -0400882
Allan Stephens9b641252011-11-09 13:29:18 -0500883 return tipc_reject_msg(buf, err);
884}
885
Per Lidenb97bf3f2006-01-02 19:04:38 +0100886/*
Ying Xue247f0f32014-02-18 16:06:46 +0800887 * tipc_port_iovec_rcv: Concatenate and deliver sectioned
888 * message for this node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100889 */
Ying Xue247f0f32014-02-18 16:06:46 +0800890static int tipc_port_iovec_rcv(struct tipc_port *sender,
891 struct iovec const *msg_sect,
892 unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100893{
894 struct sk_buff *buf;
895 int res;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900896
Ying Xue9446b872013-10-18 07:23:15 +0200897 res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100898 if (likely(buf))
Ying Xue247f0f32014-02-18 16:06:46 +0800899 tipc_port_rcv(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100900 return res;
901}
902
903/**
904 * tipc_send - send message sections on connection
905 */
Ying Xue9446b872013-10-18 07:23:15 +0200906int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100907{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500908 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100909 u32 destnode;
910 int res;
911
Per Liden4323add2006-01-18 00:38:21 +0100912 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500913 if (!p_ptr || !p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100914 return -EINVAL;
915
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500916 p_ptr->congested = 1;
Per Liden4323add2006-01-18 00:38:21 +0100917 if (!tipc_port_congested(p_ptr)) {
Jon Paul Maloyf9fef182014-03-12 11:31:08 -0400918 destnode = tipc_port_peernode(p_ptr);
Allan Stephens8a55fe72012-04-18 09:27:22 -0400919 if (likely(!in_own_node(destnode)))
Ying Xue247f0f32014-02-18 16:06:46 +0800920 res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len,
921 destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100922 else
Ying Xue247f0f32014-02-18 16:06:46 +0800923 res = tipc_port_iovec_rcv(p_ptr, msg_sect, len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100924
925 if (likely(res != -ELINKCONG)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500926 p_ptr->congested = 0;
Allan Stephenscb7ce912011-01-24 15:02:14 -0500927 if (res > 0)
928 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100929 return res;
930 }
931 }
932 if (port_unreliable(p_ptr)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500933 p_ptr->congested = 0;
Ying Xue9446b872013-10-18 07:23:15 +0200934 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100935 }
936 return -ELINKCONG;
937}
938
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900939/**
Allan Stephens12bae4792010-11-30 12:01:02 +0000940 * tipc_send2name - send message sections to port name
Per Lidenb97bf3f2006-01-02 19:04:38 +0100941 */
Allan Stephens12bae4792010-11-30 12:01:02 +0000942int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
Ying Xue9446b872013-10-18 07:23:15 +0200943 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100944{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500945 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100946 struct tipc_msg *msg;
947 u32 destnode = domain;
Allan Stephens9ccc2eb2010-05-11 14:30:06 +0000948 u32 destport;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100949 int res;
950
Per Liden4323add2006-01-18 00:38:21 +0100951 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500952 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100953 return -EINVAL;
954
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500955 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100956 msg_set_type(msg, TIPC_NAMED_MSG);
Allan Stephens741d9eb2011-05-31 15:03:18 -0400957 msg_set_hdr_sz(msg, NAMED_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100958 msg_set_nametype(msg, name->type);
959 msg_set_nameinst(msg, name->instance);
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000960 msg_set_lookup_scope(msg, tipc_addr_scope(domain));
Per Liden4323add2006-01-18 00:38:21 +0100961 destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100962 msg_set_destnode(msg, destnode);
963 msg_set_destport(msg, destport);
964
Allan Stephensbc9f8142011-11-07 17:00:54 -0500965 if (likely(destport || destnode)) {
Allan Stephens8a55fe72012-04-18 09:27:22 -0400966 if (likely(in_own_node(destnode)))
Ying Xue247f0f32014-02-18 16:06:46 +0800967 res = tipc_port_iovec_rcv(p_ptr, msg_sect, len);
Allan Stephensb8f683d2012-04-18 09:22:56 -0400968 else if (tipc_own_addr)
Ying Xue247f0f32014-02-18 16:06:46 +0800969 res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len,
970 destnode);
Allan Stephensb8f683d2012-04-18 09:22:56 -0400971 else
Ying Xue247f0f32014-02-18 16:06:46 +0800972 res = tipc_port_iovec_reject(p_ptr, msg, msg_sect,
973 len, TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -0500974 if (likely(res != -ELINKCONG)) {
975 if (res > 0)
976 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100977 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -0500978 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100979 if (port_unreliable(p_ptr)) {
Ying Xue9446b872013-10-18 07:23:15 +0200980 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100981 }
982 return -ELINKCONG;
983 }
Ying Xue247f0f32014-02-18 16:06:46 +0800984 return tipc_port_iovec_reject(p_ptr, msg, msg_sect, len,
985 TIPC_ERR_NO_NAME);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100986}
987
988/**
Allan Stephens12bae4792010-11-30 12:01:02 +0000989 * tipc_send2port - send message sections to port identity
Per Lidenb97bf3f2006-01-02 19:04:38 +0100990 */
Allan Stephens12bae4792010-11-30 12:01:02 +0000991int tipc_send2port(u32 ref, struct tipc_portid const *dest,
Ying Xue9446b872013-10-18 07:23:15 +0200992 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100993{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500994 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100995 struct tipc_msg *msg;
996 int res;
997
Per Liden4323add2006-01-18 00:38:21 +0100998 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500999 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001000 return -EINVAL;
1001
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001002 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001003 msg_set_type(msg, TIPC_DIRECT_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -04001004 msg_set_lookup_scope(msg, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001005 msg_set_destnode(msg, dest->node);
1006 msg_set_destport(msg, dest->ref);
Allan Stephens741d9eb2011-05-31 15:03:18 -04001007 msg_set_hdr_sz(msg, BASIC_H_SIZE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001008
Allan Stephens8a55fe72012-04-18 09:27:22 -04001009 if (in_own_node(dest->node))
Ying Xue247f0f32014-02-18 16:06:46 +08001010 res = tipc_port_iovec_rcv(p_ptr, msg_sect, len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001011 else if (tipc_own_addr)
Ying Xue247f0f32014-02-18 16:06:46 +08001012 res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len,
1013 dest->node);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001014 else
Ying Xue247f0f32014-02-18 16:06:46 +08001015 res = tipc_port_iovec_reject(p_ptr, msg, msg_sect, len,
Ying Xue9446b872013-10-18 07:23:15 +02001016 TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001017 if (likely(res != -ELINKCONG)) {
1018 if (res > 0)
1019 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001020 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001021 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001022 if (port_unreliable(p_ptr)) {
Ying Xue9446b872013-10-18 07:23:15 +02001023 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001024 }
1025 return -ELINKCONG;
1026}