blob: 5fd4c8cec08e083ed3ee04abd30695cd5811d78d [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,
Ying Xue9446b872013-10-18 07:23:15 +020093 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +010094{
95 struct tipc_msg *hdr;
96 struct sk_buff *buf;
97 struct sk_buff *ibuf = NULL;
Paul Gortmaker45843102011-12-29 20:33:30 -050098 struct tipc_port_list dports = {0, NULL, };
Allan Stephens23dd4cc2011-01-07 11:43:40 -050099 struct tipc_port *oport = tipc_port_deref(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100100 int ext_targets;
101 int res;
102
103 if (unlikely(!oport))
104 return -EINVAL;
105
106 /* Create multicast message */
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500107 hdr = &oport->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108 msg_set_type(hdr, TIPC_MCAST_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400109 msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE);
Allan Stephens7462b9e2011-04-18 10:08:22 -0400110 msg_set_destport(hdr, 0);
111 msg_set_destnode(hdr, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100112 msg_set_nametype(hdr, seq->type);
113 msg_set_namelower(hdr, seq->lower);
114 msg_set_nameupper(hdr, seq->upper);
115 msg_set_hdr_sz(hdr, MCAST_H_SIZE);
Ying Xue9446b872013-10-18 07:23:15 +0200116 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100117 if (unlikely(!buf))
118 return res;
119
120 /* Figure out where to send multicast message */
Per Liden4323add2006-01-18 00:38:21 +0100121 ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper,
122 TIPC_NODE_SCOPE, &dports);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900123
124 /* Send message to destinations (duplicate it only if necessary) */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100125 if (ext_targets) {
126 if (dports.count != 0) {
127 ibuf = skb_copy(buf, GFP_ATOMIC);
128 if (ibuf == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100129 tipc_port_list_free(&dports);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400130 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100131 return -ENOMEM;
132 }
133 }
Per Liden4323add2006-01-18 00:38:21 +0100134 res = tipc_bclink_send_msg(buf);
Allan Stephensa0168922010-12-31 18:59:35 +0000135 if ((res < 0) && (dports.count != 0))
Allan Stephens5f6d9122011-11-04 13:24:29 -0400136 kfree_skb(ibuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100137 } else {
138 ibuf = buf;
139 }
140
141 if (res >= 0) {
142 if (ibuf)
Per Liden4323add2006-01-18 00:38:21 +0100143 tipc_port_recv_mcast(ibuf, &dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100144 } else {
Per Liden4323add2006-01-18 00:38:21 +0100145 tipc_port_list_free(&dports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146 }
147 return res;
148}
149
150/**
Per Liden4323add2006-01-18 00:38:21 +0100151 * tipc_port_recv_mcast - deliver multicast message to all destination ports
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900152 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100153 * If there is no port list, perform a lookup to create one
154 */
Paul Gortmaker45843102011-12-29 20:33:30 -0500155void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100156{
Allan Stephens0e659672010-12-31 18:59:32 +0000157 struct tipc_msg *msg;
Paul Gortmaker45843102011-12-29 20:33:30 -0500158 struct tipc_port_list dports = {0, NULL, };
159 struct tipc_port_list *item = dp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100160 int cnt = 0;
161
Per Lidenb97bf3f2006-01-02 19:04:38 +0100162 msg = buf_msg(buf);
163
164 /* Create destination port list, if one wasn't supplied */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100165 if (dp == NULL) {
Per Liden4323add2006-01-18 00:38:21 +0100166 tipc_nametbl_mc_translate(msg_nametype(msg),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100167 msg_namelower(msg),
168 msg_nameupper(msg),
169 TIPC_CLUSTER_SCOPE,
170 &dports);
171 item = dp = &dports;
172 }
173
174 /* Deliver a copy of message to each destination port */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100175 if (dp->count != 0) {
Allan Stephens7f47f5c2011-04-18 10:14:26 -0400176 msg_set_destnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100177 if (dp->count == 1) {
178 msg_set_destport(msg, dp->ports[0]);
Per Liden4323add2006-01-18 00:38:21 +0100179 tipc_port_recv_msg(buf);
180 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100181 return;
182 }
183 for (; cnt < dp->count; cnt++) {
184 int index = cnt % PLSIZE;
185 struct sk_buff *b = skb_clone(buf, GFP_ATOMIC);
186
187 if (b == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400188 pr_warn("Unable to deliver multicast message(s)\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100189 goto exit;
190 }
Allan Stephensa0168922010-12-31 18:59:35 +0000191 if ((index == 0) && (cnt != 0))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100192 item = item->next;
Allan Stephens0e659672010-12-31 18:59:32 +0000193 msg_set_destport(buf_msg(b), item->ports[index]);
Per Liden4323add2006-01-18 00:38:21 +0100194 tipc_port_recv_msg(b);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100195 }
196 }
197exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400198 kfree_skb(buf);
Per Liden4323add2006-01-18 00:38:21 +0100199 tipc_port_list_free(dp);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100200}
201
202/**
Ying Xue3c5db8e2013-06-17 10:54:44 -0400203 * tipc_createport - create a generic TIPC port
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900204 *
Allan Stephens0ea52242008-07-14 22:42:19 -0700205 * Returns pointer to (locked) TIPC port, or NULL if unable to create it
Per Lidenb97bf3f2006-01-02 19:04:38 +0100206 */
Ying Xuec0fee8a2013-06-17 10:54:46 -0400207struct tipc_port *tipc_createport(struct sock *sk,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400208 u32 (*dispatcher)(struct tipc_port *,
209 struct sk_buff *),
210 void (*wakeup)(struct tipc_port *),
211 const u32 importance)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100212{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500213 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100214 struct tipc_msg *msg;
215 u32 ref;
216
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700217 p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -0700218 if (!p_ptr) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400219 pr_warn("Port creation failed, no memory\n");
Allan Stephens0ea52242008-07-14 22:42:19 -0700220 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221 }
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500222 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100223 if (!ref) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400224 pr_warn("Port creation failed, ref. table exhausted\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100225 kfree(p_ptr);
Allan Stephens0ea52242008-07-14 22:42:19 -0700226 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100227 }
228
Ying Xuec0fee8a2013-06-17 10:54:46 -0400229 p_ptr->sk = sk;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500230 p_ptr->max_pkt = MAX_PKT_DEFAULT;
231 p_ptr->ref = ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100232 INIT_LIST_HEAD(&p_ptr->wait_list);
233 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100234 p_ptr->dispatcher = dispatcher;
235 p_ptr->wakeup = wakeup;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100237 INIT_LIST_HEAD(&p_ptr->publications);
238 INIT_LIST_HEAD(&p_ptr->port_list);
Allan Stephensf21536d2012-04-17 18:22:49 -0400239
240 /*
241 * Must hold port list lock while initializing message header template
242 * to ensure a change to node's own network address doesn't result
243 * in template containing out-dated network address information
244 */
Allan Stephensf21536d2012-04-17 18:22:49 -0400245 spin_lock_bh(&tipc_port_list_lock);
246 msg = &p_ptr->phdr;
247 tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
248 msg_set_origport(msg, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100249 list_add_tail(&p_ptr->port_list, &ports);
Per Liden4323add2006-01-18 00:38:21 +0100250 spin_unlock_bh(&tipc_port_list_lock);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500251 return p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100252}
253
254int tipc_deleteport(u32 ref)
255{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500256 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800257 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100258
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800259 tipc_withdraw(ref, 0, NULL);
Per Liden4323add2006-01-18 00:38:21 +0100260 p_ptr = tipc_port_lock(ref);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900261 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100262 return -EINVAL;
263
Per Liden4323add2006-01-18 00:38:21 +0100264 tipc_ref_discard(ref);
265 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100266
267 k_cancel_timer(&p_ptr->timer);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500268 if (p_ptr->connected) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100269 buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
Per Liden4323add2006-01-18 00:38:21 +0100270 tipc_nodesub_unsubscribe(&p_ptr->subscription);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100271 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100272
Per Liden4323add2006-01-18 00:38:21 +0100273 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100274 list_del(&p_ptr->port_list);
275 list_del(&p_ptr->wait_list);
Per Liden4323add2006-01-18 00:38:21 +0100276 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100277 k_term_timer(&p_ptr->timer);
278 kfree(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100279 tipc_net_route_msg(buf);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700280 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100281}
282
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500283static int port_unreliable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100284{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500285 return msg_src_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100286}
287
288int tipc_portunreliable(u32 ref, unsigned int *isunreliable)
289{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500290 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900291
Per Liden4323add2006-01-18 00:38:21 +0100292 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100293 if (!p_ptr)
294 return -EINVAL;
295 *isunreliable = port_unreliable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800296 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700297 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100298}
299
300int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
301{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500302 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900303
Per Liden4323add2006-01-18 00:38:21 +0100304 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100305 if (!p_ptr)
306 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500307 msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100308 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700309 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100310}
311
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500312static int port_unreturnable(struct tipc_port *p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100313{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500314 return msg_dest_droppable(&p_ptr->phdr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100315}
316
317int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable)
318{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500319 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900320
Per Liden4323add2006-01-18 00:38:21 +0100321 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100322 if (!p_ptr)
323 return -EINVAL;
324 *isunrejectable = port_unreturnable(p_ptr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800325 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700326 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100327}
328
329int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
330{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500331 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900332
Per Liden4323add2006-01-18 00:38:21 +0100333 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100334 if (!p_ptr)
335 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500336 msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0));
Per Liden4323add2006-01-18 00:38:21 +0100337 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700338 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100339}
340
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900341/*
Allan Stephense4a0aee2011-06-01 16:21:12 -0400342 * port_build_proto_msg(): create connection protocol message for port
343 *
344 * On entry the port must be locked and connected.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100345 */
Allan Stephense4a0aee2011-06-01 16:21:12 -0400346static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr,
347 u32 type, u32 ack)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100348{
349 struct sk_buff *buf;
350 struct tipc_msg *msg;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900351
Allan Stephens741d9eb2011-05-31 15:03:18 -0400352 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100353 if (buf) {
354 msg = buf_msg(buf);
Allan Stephense4a0aee2011-06-01 16:21:12 -0400355 tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE,
356 port_peernode(p_ptr));
357 msg_set_destport(msg, port_peerport(p_ptr));
358 msg_set_origport(msg, p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100359 msg_set_msgcnt(msg, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360 }
361 return buf;
362}
363
Per Lidenb97bf3f2006-01-02 19:04:38 +0100364int tipc_reject_msg(struct sk_buff *buf, u32 err)
365{
366 struct tipc_msg *msg = buf_msg(buf);
367 struct sk_buff *rbuf;
368 struct tipc_msg *rmsg;
369 int hdr_sz;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400370 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100371 u32 data_sz = msg_data_sz(msg);
Allan Stephens017dac32011-05-24 13:20:09 -0400372 u32 src_node;
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400373 u32 rmsg_sz;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100374
375 /* discard rejected message if it shouldn't be returned to sender */
Allan Stephens76d12522011-05-23 13:57:25 -0400376 if (WARN(!msg_isdata(msg),
377 "attempt to reject message with user=%u", msg_user(msg))) {
378 dump_stack();
379 goto exit;
380 }
Allan Stephensacc631b2011-05-23 13:47:44 -0400381 if (msg_errcode(msg) || msg_dest_droppable(msg))
382 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100383
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400384 /*
385 * construct returned message by copying rejected message header and
386 * data (or subset), then updating header fields that need adjusting
387 */
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400388 hdr_sz = msg_hdr_sz(msg);
389 rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE);
390
391 rbuf = tipc_buf_acquire(rmsg_sz);
Allan Stephensacc631b2011-05-23 13:47:44 -0400392 if (rbuf == NULL)
393 goto exit;
394
Per Lidenb97bf3f2006-01-02 19:04:38 +0100395 rmsg = buf_msg(rbuf);
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400396 skb_copy_to_linear_data(rbuf, msg, rmsg_sz);
397
398 if (msg_connected(rmsg)) {
399 imp = msg_importance(rmsg);
400 if (imp < TIPC_CRITICAL_IMPORTANCE)
401 msg_set_importance(rmsg, ++imp);
Allan Stephens99c14592008-06-04 17:48:25 -0700402 }
Allan Stephens7dd1bf22011-05-23 16:23:32 -0400403 msg_set_non_seq(rmsg, 0);
404 msg_set_size(rmsg, rmsg_sz);
405 msg_set_errcode(rmsg, err);
406 msg_set_prevnode(rmsg, tipc_own_addr);
407 msg_swap_words(rmsg, 4, 5);
408 if (!msg_short(rmsg))
409 msg_swap_words(rmsg, 6, 7);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410
411 /* send self-abort message when rejecting on a connected port */
412 if (msg_connected(msg)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500413 struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100414
415 if (p_ptr) {
Allan Stephensdff10e92011-11-02 10:32:14 -0400416 struct sk_buff *abuf = NULL;
417
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500418 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100419 abuf = port_build_self_abort_msg(p_ptr, err);
Per Liden4323add2006-01-18 00:38:21 +0100420 tipc_port_unlock(p_ptr);
Allan Stephensdff10e92011-11-02 10:32:14 -0400421 tipc_net_route_msg(abuf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100422 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100423 }
424
Allan Stephensacc631b2011-05-23 13:47:44 -0400425 /* send returned message & dispose of rejected message */
Allan Stephens017dac32011-05-24 13:20:09 -0400426 src_node = msg_prevnode(msg);
Allan Stephens630d9202012-04-18 09:42:29 -0400427 if (in_own_node(src_node))
Allan Stephens017dac32011-05-24 13:20:09 -0400428 tipc_port_recv_msg(rbuf);
429 else
430 tipc_link_send(rbuf, src_node, msg_link_selector(rmsg));
Allan Stephensacc631b2011-05-23 13:47:44 -0400431exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400432 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100433 return data_sz;
434}
435
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500436int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr,
Ying Xue9446b872013-10-18 07:23:15 +0200437 struct iovec const *msg_sect, unsigned int len,
438 int err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100439{
440 struct sk_buff *buf;
441 int res;
442
Ying Xue9446b872013-10-18 07:23:15 +0200443 res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100444 if (!buf)
445 return res;
446
447 return tipc_reject_msg(buf, err);
448}
449
450static void port_timeout(unsigned long ref)
451{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500452 struct tipc_port *p_ptr = tipc_port_lock(ref);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800453 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100454
Allan Stephens065fd172006-10-16 21:38:05 -0700455 if (!p_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100456 return;
457
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500458 if (!p_ptr->connected) {
Allan Stephens065fd172006-10-16 21:38:05 -0700459 tipc_port_unlock(p_ptr);
460 return;
461 }
462
Per Lidenb97bf3f2006-01-02 19:04:38 +0100463 /* Last probe answered ? */
464 if (p_ptr->probing_state == PROBING) {
465 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
466 } else {
Allan Stephense4a0aee2011-06-01 16:21:12 -0400467 buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100468 p_ptr->probing_state = PROBING;
469 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
470 }
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
476static void port_handle_node_down(unsigned long ref)
477{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500478 struct tipc_port *p_ptr = tipc_port_lock(ref);
Allan Stephens0e659672010-12-31 18:59:32 +0000479 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100480
481 if (!p_ptr)
482 return;
483 buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE);
Per Liden4323add2006-01-18 00:38:21 +0100484 tipc_port_unlock(p_ptr);
485 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100486}
487
488
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500489static struct sk_buff *port_build_self_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 = port_build_peer_abort_msg(p_ptr, err);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100492
Allan Stephense244a912011-05-31 16:10:08 -0400493 if (buf) {
494 struct tipc_msg *msg = buf_msg(buf);
495 msg_swap_words(msg, 4, 5);
496 msg_swap_words(msg, 6, 7);
497 }
498 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100499}
500
501
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500502static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100503{
Allan Stephense244a912011-05-31 16:10:08 -0400504 struct sk_buff *buf;
505 struct tipc_msg *msg;
506 u32 imp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100507
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500508 if (!p_ptr->connected)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800509 return NULL;
Allan Stephense244a912011-05-31 16:10:08 -0400510
511 buf = tipc_buf_acquire(BASIC_H_SIZE);
512 if (buf) {
513 msg = buf_msg(buf);
514 memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE);
515 msg_set_hdr_sz(msg, BASIC_H_SIZE);
516 msg_set_size(msg, BASIC_H_SIZE);
517 imp = msg_importance(msg);
518 if (imp < TIPC_CRITICAL_IMPORTANCE)
519 msg_set_importance(msg, ++imp);
520 msg_set_errcode(msg, err);
521 }
522 return buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100523}
524
Per Liden4323add2006-01-18 00:38:21 +0100525void tipc_port_recv_proto_msg(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100526{
527 struct tipc_msg *msg = buf_msg(buf);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400528 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800529 struct sk_buff *r_buf = NULL;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400530 u32 destport = msg_destport(msg);
531 int wakeable;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100532
Allan Stephens1c1a5512011-06-01 15:08:10 -0400533 /* Validate connection */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400534 p_ptr = tipc_port_lock(destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400535 if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) {
Allan Stephensf55b5642011-06-01 15:48:42 -0400536 r_buf = tipc_buf_acquire(BASIC_H_SIZE);
537 if (r_buf) {
538 msg = buf_msg(r_buf);
539 tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG,
Allan Stephensf0712e862012-04-17 18:42:28 -0400540 BASIC_H_SIZE, msg_orignode(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400541 msg_set_errcode(msg, TIPC_ERR_NO_PORT);
542 msg_set_origport(msg, destport);
Allan Stephensf0712e862012-04-17 18:42:28 -0400543 msg_set_destport(msg, msg_origport(msg));
Allan Stephensf55b5642011-06-01 15:48:42 -0400544 }
Allan Stephens1c1a5512011-06-01 15:08:10 -0400545 if (p_ptr)
546 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100547 goto exit;
548 }
549
Allan Stephens1c1a5512011-06-01 15:08:10 -0400550 /* Process protocol message sent by peer */
Allan Stephens1c1a5512011-06-01 15:08:10 -0400551 switch (msg_type(msg)) {
552 case CONN_ACK:
553 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested &&
554 p_ptr->wakeup;
555 p_ptr->acked += msg_msgcnt(msg);
556 if (!tipc_port_congested(p_ptr)) {
557 p_ptr->congested = 0;
558 if (wakeable)
559 p_ptr->wakeup(p_ptr);
560 }
561 break;
562 case CONN_PROBE:
Allan Stephense4a0aee2011-06-01 16:21:12 -0400563 r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0);
Allan Stephens1c1a5512011-06-01 15:08:10 -0400564 break;
565 default:
566 /* CONN_PROBE_REPLY or unrecognized - no action required */
567 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100568 }
569 p_ptr->probing_state = CONFIRMED;
Allan Stephens1c1a5512011-06-01 15:08:10 -0400570 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100571exit:
Per Liden4323add2006-01-18 00:38:21 +0100572 tipc_net_route_msg(r_buf);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400573 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100574}
575
Erik Hugnedc1aed32012-06-29 00:50:23 -0400576static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100577{
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900578 struct publication *publ;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400579 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100580
581 if (full_id)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400582 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
583 tipc_zone(tipc_own_addr),
584 tipc_cluster(tipc_own_addr),
585 tipc_node(tipc_own_addr), p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100586 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400587 ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100588
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500589 if (p_ptr->connected) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900590 u32 dport = port_peerport(p_ptr);
591 u32 destnode = port_peernode(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100592
Erik Hugnedc1aed32012-06-29 00:50:23 -0400593 ret += tipc_snprintf(buf + ret, len - ret,
594 " connected to <%u.%u.%u:%u>",
595 tipc_zone(destnode),
596 tipc_cluster(destnode),
597 tipc_node(destnode), dport);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500598 if (p_ptr->conn_type != 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400599 ret += tipc_snprintf(buf + ret, len - ret,
600 " via {%u,%u}", p_ptr->conn_type,
601 p_ptr->conn_instance);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500602 } else if (p_ptr->published) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400603 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900604 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100605 if (publ->lower == publ->upper)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400606 ret += tipc_snprintf(buf + ret, len - ret,
607 " {%u,%u}", publ->type,
608 publ->lower);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100609 else
Erik Hugnedc1aed32012-06-29 00:50:23 -0400610 ret += tipc_snprintf(buf + ret, len - ret,
611 " {%u,%u,%u}", publ->type,
612 publ->lower, publ->upper);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900613 }
614 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400615 ret += tipc_snprintf(buf + ret, len - ret, "\n");
616 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100617}
618
Per Liden4323add2006-01-18 00:38:21 +0100619struct sk_buff *tipc_port_get_ports(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100620{
621 struct sk_buff *buf;
622 struct tlv_desc *rep_tlv;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400623 char *pb;
624 int pb_len;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500625 struct tipc_port *p_ptr;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400626 int str_len = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100627
Erik Hugnedc1aed32012-06-29 00:50:23 -0400628 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100629 if (!buf)
630 return NULL;
631 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400632 pb = TLV_DATA(rep_tlv);
633 pb_len = ULTRA_STRING_MAX_LEN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100634
Per Liden4323add2006-01-18 00:38:21 +0100635 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100636 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500637 spin_lock_bh(p_ptr->lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400638 str_len += port_print(p_ptr, pb, pb_len, 0);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500639 spin_unlock_bh(p_ptr->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100640 }
Per Liden4323add2006-01-18 00:38:21 +0100641 spin_unlock_bh(&tipc_port_list_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400642 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100643 skb_put(buf, TLV_SPACE(str_len));
644 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
645
646 return buf;
647}
648
Per Liden4323add2006-01-18 00:38:21 +0100649void tipc_port_reinit(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100650{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500651 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652 struct tipc_msg *msg;
653
Per Liden4323add2006-01-18 00:38:21 +0100654 spin_lock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100655 list_for_each_entry(p_ptr, &ports, port_list) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500656 msg = &p_ptr->phdr;
Allan Stephens6d4a6672008-05-21 14:54:12 -0700657 msg_set_prevnode(msg, tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100658 msg_set_orignode(msg, tipc_own_addr);
659 }
Per Liden4323add2006-01-18 00:38:21 +0100660 spin_unlock_bh(&tipc_port_list_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100661}
662
Per Lidenb97bf3f2006-01-02 19:04:38 +0100663void tipc_acknowledge(u32 ref, u32 ack)
664{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500665 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800666 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100667
Per Liden4323add2006-01-18 00:38:21 +0100668 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100669 if (!p_ptr)
670 return;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500671 if (p_ptr->connected) {
672 p_ptr->conn_unacked -= ack;
Allan Stephense4a0aee2011-06-01 16:21:12 -0400673 buf = port_build_proto_msg(p_ptr, CONN_ACK, ack);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100674 }
Per Liden4323add2006-01-18 00:38:21 +0100675 tipc_port_unlock(p_ptr);
676 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100677}
678
Per Lidenb97bf3f2006-01-02 19:04:38 +0100679int tipc_portimportance(u32 ref, unsigned int *importance)
680{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500681 struct tipc_port *p_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900682
Per Liden4323add2006-01-18 00:38:21 +0100683 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100684 if (!p_ptr)
685 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500686 *importance = (unsigned int)msg_importance(&p_ptr->phdr);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800687 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700688 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100689}
690
691int tipc_set_portimportance(u32 ref, unsigned int imp)
692{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500693 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100694
695 if (imp > TIPC_CRITICAL_IMPORTANCE)
696 return -EINVAL;
697
Per Liden4323add2006-01-18 00:38:21 +0100698 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100699 if (!p_ptr)
700 return -EINVAL;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500701 msg_set_importance(&p_ptr->phdr, (u32)imp);
Julia Lawall4cec72c2008-01-08 23:48:20 -0800702 tipc_port_unlock(p_ptr);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700703 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100704}
705
706
707int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
708{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500709 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100710 struct publication *publ;
711 u32 key;
712 int res = -EINVAL;
713
Per Liden4323add2006-01-18 00:38:21 +0100714 p_ptr = tipc_port_lock(ref);
Adrian Bunkd55b4c62006-10-31 16:59:35 -0800715 if (!p_ptr)
716 return -EINVAL;
717
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500718 if (p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100719 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100720 key = ref + p_ptr->pub_count + 1;
721 if (key == ref) {
722 res = -EADDRINUSE;
723 goto exit;
724 }
Per Liden4323add2006-01-18 00:38:21 +0100725 publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500726 scope, p_ptr->ref, key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100727 if (publ) {
728 list_add(&publ->pport_list, &p_ptr->publications);
729 p_ptr->pub_count++;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500730 p_ptr->published = 1;
Allan Stephens0e35fd52008-07-14 22:44:01 -0700731 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100732 }
733exit:
Per Liden4323add2006-01-18 00:38:21 +0100734 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100735 return res;
736}
737
738int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
739{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500740 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100741 struct publication *publ;
742 struct publication *tpubl;
743 int res = -EINVAL;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900744
Per Liden4323add2006-01-18 00:38:21 +0100745 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100746 if (!p_ptr)
747 return -EINVAL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100748 if (!seq) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900749 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100750 &p_ptr->publications, pport_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900751 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100752 publ->ref, publ->key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100753 }
Allan Stephens0e35fd52008-07-14 22:44:01 -0700754 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100755 } else {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900756 list_for_each_entry_safe(publ, tpubl,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100757 &p_ptr->publications, pport_list) {
758 if (publ->scope != scope)
759 continue;
760 if (publ->type != seq->type)
761 continue;
762 if (publ->lower != seq->lower)
763 continue;
764 if (publ->upper != seq->upper)
765 break;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900766 tipc_nametbl_withdraw(publ->type, publ->lower,
Per Liden4323add2006-01-18 00:38:21 +0100767 publ->ref, publ->key);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700768 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100769 break;
770 }
771 }
772 if (list_empty(&p_ptr->publications))
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500773 p_ptr->published = 0;
Per Liden4323add2006-01-18 00:38:21 +0100774 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100775 return res;
776}
777
Paul Gortmakerbc879112012-11-29 13:48:40 -0500778int tipc_connect(u32 ref, struct tipc_portid const *peer)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100779{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500780 struct tipc_port *p_ptr;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500781 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100782
Per Liden4323add2006-01-18 00:38:21 +0100783 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100784 if (!p_ptr)
785 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500786 res = __tipc_connect(ref, p_ptr, peer);
787 tipc_port_unlock(p_ptr);
788 return res;
789}
790
791/*
792 * __tipc_connect - connect to a remote peer
793 *
794 * Port must be locked.
795 */
796int __tipc_connect(u32 ref, struct tipc_port *p_ptr,
797 struct tipc_portid const *peer)
798{
799 struct tipc_msg *msg;
800 int res = -EINVAL;
801
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500802 if (p_ptr->published || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100803 goto exit;
804 if (!peer->ref)
805 goto exit;
806
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500807 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100808 msg_set_destnode(msg, peer->node);
809 msg_set_destport(msg, peer->ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100810 msg_set_type(msg, TIPC_CONN_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -0400811 msg_set_lookup_scope(msg, 0);
Allan Stephens08c80e92010-12-31 18:59:17 +0000812 msg_set_hdr_sz(msg, SHORT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100813
814 p_ptr->probing_interval = PROBING_INTERVAL;
815 p_ptr->probing_state = CONFIRMED;
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500816 p_ptr->connected = 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100817 k_start_timer(&p_ptr->timer, p_ptr->probing_interval);
818
Allan Stephens0e659672010-12-31 18:59:32 +0000819 tipc_nodesub_subscribe(&p_ptr->subscription, peer->node,
David S. Miller880b0052006-01-12 13:22:32 -0800820 (void *)(unsigned long)ref,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100821 (net_ev_handler)port_handle_node_down);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700822 res = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100823exit:
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500824 p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100825 return res;
826}
827
Paul Gortmakerbc879112012-11-29 13:48:40 -0500828/*
829 * __tipc_disconnect - disconnect port from peer
Allan Stephens0c3141e2008-04-15 00:22:02 -0700830 *
831 * Port must be locked.
832 */
Paul Gortmakerbc879112012-11-29 13:48:40 -0500833int __tipc_disconnect(struct tipc_port *tp_ptr)
Allan Stephens0c3141e2008-04-15 00:22:02 -0700834{
Allan Stephens0c3141e2008-04-15 00:22:02 -0700835 if (tp_ptr->connected) {
836 tp_ptr->connected = 0;
837 /* let timer expire on it's own to avoid deadlock! */
Joe Perchese3192692012-06-03 17:41:40 +0000838 tipc_nodesub_unsubscribe(&tp_ptr->subscription);
wangweidong0cee6bb2013-12-12 09:36:39 +0800839 return 0;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700840 }
wangweidong0cee6bb2013-12-12 09:36:39 +0800841
842 return -ENOTCONN;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700843}
844
Per Lidenb97bf3f2006-01-02 19:04:38 +0100845/*
846 * tipc_disconnect(): Disconnect port form peer.
847 * This is a node local operation.
848 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100849int tipc_disconnect(u32 ref)
850{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500851 struct tipc_port *p_ptr;
Allan Stephens0c3141e2008-04-15 00:22:02 -0700852 int res;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100853
Per Liden4323add2006-01-18 00:38:21 +0100854 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100855 if (!p_ptr)
856 return -EINVAL;
Paul Gortmakerbc879112012-11-29 13:48:40 -0500857 res = __tipc_disconnect(p_ptr);
Per Liden4323add2006-01-18 00:38:21 +0100858 tipc_port_unlock(p_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100859 return res;
860}
861
862/*
863 * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect
864 */
865int tipc_shutdown(u32 ref)
866{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500867 struct tipc_port *p_ptr;
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800868 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100869
Per Liden4323add2006-01-18 00:38:21 +0100870 p_ptr = tipc_port_lock(ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100871 if (!p_ptr)
872 return -EINVAL;
873
Allan Stephense244a912011-05-31 16:10:08 -0400874 buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN);
Per Liden4323add2006-01-18 00:38:21 +0100875 tipc_port_unlock(p_ptr);
876 tipc_net_route_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100877 return tipc_disconnect(ref);
878}
879
Allan Stephens9b641252011-11-09 13:29:18 -0500880/**
881 * tipc_port_recv_msg - receive message from lower layer and deliver to port user
882 */
Allan Stephens9b641252011-11-09 13:29:18 -0500883int tipc_port_recv_msg(struct sk_buff *buf)
884{
885 struct tipc_port *p_ptr;
886 struct tipc_msg *msg = buf_msg(buf);
887 u32 destport = msg_destport(msg);
888 u32 dsz = msg_data_sz(msg);
889 u32 err;
890
891 /* forward unresolved named message */
892 if (unlikely(!destport)) {
893 tipc_net_route_msg(buf);
894 return dsz;
895 }
896
897 /* validate destination & pass to port, otherwise reject message */
898 p_ptr = tipc_port_lock(destport);
899 if (likely(p_ptr)) {
Allan Stephens9b641252011-11-09 13:29:18 -0500900 err = p_ptr->dispatcher(p_ptr, buf);
901 tipc_port_unlock(p_ptr);
902 if (likely(!err))
903 return dsz;
904 } else {
905 err = TIPC_ERR_NO_PORT;
906 }
Allan Stephensf0712e862012-04-17 18:42:28 -0400907
Allan Stephens9b641252011-11-09 13:29:18 -0500908 return tipc_reject_msg(buf, err);
909}
910
Per Lidenb97bf3f2006-01-02 19:04:38 +0100911/*
Per Liden4323add2006-01-18 00:38:21 +0100912 * tipc_port_recv_sections(): Concatenate and deliver sectioned
Per Lidenb97bf3f2006-01-02 19:04:38 +0100913 * message for this node.
914 */
Ying Xue9446b872013-10-18 07:23:15 +0200915static int tipc_port_recv_sections(struct tipc_port *sender,
Allan Stephens26896902011-04-21 10:42:07 -0500916 struct iovec const *msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +0200917 unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100918{
919 struct sk_buff *buf;
920 int res;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900921
Ying Xue9446b872013-10-18 07:23:15 +0200922 res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100923 if (likely(buf))
Per Liden4323add2006-01-18 00:38:21 +0100924 tipc_port_recv_msg(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100925 return res;
926}
927
928/**
929 * tipc_send - send message sections on connection
930 */
Ying Xue9446b872013-10-18 07:23:15 +0200931int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100932{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500933 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100934 u32 destnode;
935 int res;
936
Per Liden4323add2006-01-18 00:38:21 +0100937 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500938 if (!p_ptr || !p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100939 return -EINVAL;
940
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500941 p_ptr->congested = 1;
Per Liden4323add2006-01-18 00:38:21 +0100942 if (!tipc_port_congested(p_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100943 destnode = port_peernode(p_ptr);
Allan Stephens8a55fe72012-04-18 09:27:22 -0400944 if (likely(!in_own_node(destnode)))
Ying Xue9446b872013-10-18 07:23:15 +0200945 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
946 len, destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100947 else
Ying Xue9446b872013-10-18 07:23:15 +0200948 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100949
950 if (likely(res != -ELINKCONG)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500951 p_ptr->congested = 0;
Allan Stephenscb7ce912011-01-24 15:02:14 -0500952 if (res > 0)
953 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100954 return res;
955 }
956 }
957 if (port_unreliable(p_ptr)) {
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500958 p_ptr->congested = 0;
Ying Xue9446b872013-10-18 07:23:15 +0200959 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100960 }
961 return -ELINKCONG;
962}
963
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900964/**
Allan Stephens12bae472010-11-30 12:01:02 +0000965 * tipc_send2name - send message sections to port name
Per Lidenb97bf3f2006-01-02 19:04:38 +0100966 */
Allan Stephens12bae472010-11-30 12:01:02 +0000967int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain,
Ying Xue9446b872013-10-18 07:23:15 +0200968 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100969{
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500970 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100971 struct tipc_msg *msg;
972 u32 destnode = domain;
Allan Stephens9ccc2eb2010-05-11 14:30:06 +0000973 u32 destport;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100974 int res;
975
Per Liden4323add2006-01-18 00:38:21 +0100976 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500977 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100978 return -EINVAL;
979
Allan Stephens23dd4cc2011-01-07 11:43:40 -0500980 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100981 msg_set_type(msg, TIPC_NAMED_MSG);
Allan Stephens741d9eb2011-05-31 15:03:18 -0400982 msg_set_hdr_sz(msg, NAMED_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100983 msg_set_nametype(msg, name->type);
984 msg_set_nameinst(msg, name->instance);
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000985 msg_set_lookup_scope(msg, tipc_addr_scope(domain));
Per Liden4323add2006-01-18 00:38:21 +0100986 destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100987 msg_set_destnode(msg, destnode);
988 msg_set_destport(msg, destport);
989
Allan Stephensbc9f8142011-11-07 17:00:54 -0500990 if (likely(destport || destnode)) {
Allan Stephens8a55fe72012-04-18 09:27:22 -0400991 if (likely(in_own_node(destnode)))
Ying Xue9446b872013-10-18 07:23:15 +0200992 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
Allan Stephensb8f683d2012-04-18 09:22:56 -0400993 else if (tipc_own_addr)
Allan Stephenscb7ce912011-01-24 15:02:14 -0500994 res = tipc_link_send_sections_fast(p_ptr, msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +0200995 len, destnode);
Allan Stephensb8f683d2012-04-18 09:22:56 -0400996 else
997 res = tipc_port_reject_sections(p_ptr, msg, msg_sect,
Ying Xue9446b872013-10-18 07:23:15 +0200998 len, TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -0500999 if (likely(res != -ELINKCONG)) {
1000 if (res > 0)
1001 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001002 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001003 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001004 if (port_unreliable(p_ptr)) {
Ying Xue9446b872013-10-18 07:23:15 +02001005 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001006 }
1007 return -ELINKCONG;
1008 }
Ying Xue9446b872013-10-18 07:23:15 +02001009 return tipc_port_reject_sections(p_ptr, msg, msg_sect, len,
1010 TIPC_ERR_NO_NAME);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001011}
1012
1013/**
Allan Stephens12bae472010-11-30 12:01:02 +00001014 * tipc_send2port - send message sections to port identity
Per Lidenb97bf3f2006-01-02 19:04:38 +01001015 */
Allan Stephens12bae472010-11-30 12:01:02 +00001016int tipc_send2port(u32 ref, struct tipc_portid const *dest,
Ying Xue9446b872013-10-18 07:23:15 +02001017 struct iovec const *msg_sect, unsigned int len)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001018{
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001019 struct tipc_port *p_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001020 struct tipc_msg *msg;
1021 int res;
1022
Per Liden4323add2006-01-18 00:38:21 +01001023 p_ptr = tipc_port_deref(ref);
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001024 if (!p_ptr || p_ptr->connected)
Per Lidenb97bf3f2006-01-02 19:04:38 +01001025 return -EINVAL;
1026
Allan Stephens23dd4cc2011-01-07 11:43:40 -05001027 msg = &p_ptr->phdr;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001028 msg_set_type(msg, TIPC_DIRECT_MSG);
Allan Stephens53b94362011-04-17 16:02:11 -04001029 msg_set_lookup_scope(msg, 0);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001030 msg_set_destnode(msg, dest->node);
1031 msg_set_destport(msg, dest->ref);
Allan Stephens741d9eb2011-05-31 15:03:18 -04001032 msg_set_hdr_sz(msg, BASIC_H_SIZE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001033
Allan Stephens8a55fe72012-04-18 09:27:22 -04001034 if (in_own_node(dest->node))
Ying Xue9446b872013-10-18 07:23:15 +02001035 res = tipc_port_recv_sections(p_ptr, msg_sect, len);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001036 else if (tipc_own_addr)
Ying Xue9446b872013-10-18 07:23:15 +02001037 res = tipc_link_send_sections_fast(p_ptr, msg_sect, len,
1038 dest->node);
Allan Stephensb8f683d2012-04-18 09:22:56 -04001039 else
Ying Xue9446b872013-10-18 07:23:15 +02001040 res = tipc_port_reject_sections(p_ptr, msg, msg_sect, len,
1041 TIPC_ERR_NO_NODE);
Allan Stephenscb7ce912011-01-24 15:02:14 -05001042 if (likely(res != -ELINKCONG)) {
1043 if (res > 0)
1044 p_ptr->sent++;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001045 return res;
Allan Stephenscb7ce912011-01-24 15:02:14 -05001046 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001047 if (port_unreliable(p_ptr)) {
Ying Xue9446b872013-10-18 07:23:15 +02001048 return len;
Per Lidenb97bf3f2006-01-02 19:04:38 +01001049 }
1050 return -ELINKCONG;
1051}