Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/port.c: TIPC port code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 4 | * Copyright (c) 1992-2007, Ericsson AB |
Ying Xue | 198d73b | 2013-06-17 10:54:42 -0400 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, 2010-2013, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 11 | * 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 20 | * 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "config.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "port.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 40 | #include "name_table.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 41 | |
| 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 Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 49 | DEFINE_SPINLOCK(tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 50 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 51 | static LIST_HEAD(ports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 52 | static void port_handle_node_down(unsigned long ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 53 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err); |
| 54 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 55 | static void port_timeout(unsigned long ref); |
| 56 | |
| 57 | |
Paul Gortmaker | 872f24d | 2012-04-23 04:49:13 +0000 | [diff] [blame] | 58 | static u32 port_peernode(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 59 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 60 | return msg_destnode(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Paul Gortmaker | 872f24d | 2012-04-23 04:49:13 +0000 | [diff] [blame] | 63 | static u32 port_peerport(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 64 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 65 | return msg_destport(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 68 | /** |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 69 | * 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 Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 74 | int 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 89 | /** |
| 90 | * tipc_multicast - send a multicast message to local and remote destinations |
| 91 | */ |
Allan Stephens | 38f232e | 2010-11-30 12:00:59 +0000 | [diff] [blame] | 92 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 93 | struct iovec const *msg_sect, unsigned int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 94 | { |
| 95 | struct tipc_msg *hdr; |
| 96 | struct sk_buff *buf; |
| 97 | struct sk_buff *ibuf = NULL; |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 98 | struct tipc_port_list dports = {0, NULL, }; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 99 | struct tipc_port *oport = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 100 | int ext_targets; |
| 101 | int res; |
| 102 | |
| 103 | if (unlikely(!oport)) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | /* Create multicast message */ |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 107 | hdr = &oport->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 108 | msg_set_type(hdr, TIPC_MCAST_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 109 | msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE); |
Allan Stephens | 7462b9e | 2011-04-18 10:08:22 -0400 | [diff] [blame] | 110 | msg_set_destport(hdr, 0); |
| 111 | msg_set_destnode(hdr, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 112 | 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 Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 116 | res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 117 | if (unlikely(!buf)) |
| 118 | return res; |
| 119 | |
| 120 | /* Figure out where to send multicast message */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 121 | ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper, |
| 122 | TIPC_NODE_SCOPE, &dports); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 123 | |
| 124 | /* Send message to destinations (duplicate it only if necessary) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 125 | if (ext_targets) { |
| 126 | if (dports.count != 0) { |
| 127 | ibuf = skb_copy(buf, GFP_ATOMIC); |
| 128 | if (ibuf == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 129 | tipc_port_list_free(&dports); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 130 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 131 | return -ENOMEM; |
| 132 | } |
| 133 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 134 | res = tipc_bclink_send_msg(buf); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 135 | if ((res < 0) && (dports.count != 0)) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 136 | kfree_skb(ibuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 137 | } else { |
| 138 | ibuf = buf; |
| 139 | } |
| 140 | |
| 141 | if (res >= 0) { |
| 142 | if (ibuf) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 143 | tipc_port_recv_mcast(ibuf, &dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 144 | } else { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 145 | tipc_port_list_free(&dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 146 | } |
| 147 | return res; |
| 148 | } |
| 149 | |
| 150 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 151 | * tipc_port_recv_mcast - deliver multicast message to all destination ports |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 152 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 153 | * If there is no port list, perform a lookup to create one |
| 154 | */ |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 155 | void tipc_port_recv_mcast(struct sk_buff *buf, struct tipc_port_list *dp) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 156 | { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 157 | struct tipc_msg *msg; |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 158 | struct tipc_port_list dports = {0, NULL, }; |
| 159 | struct tipc_port_list *item = dp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | int cnt = 0; |
| 161 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 162 | msg = buf_msg(buf); |
| 163 | |
| 164 | /* Create destination port list, if one wasn't supplied */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 165 | if (dp == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 166 | tipc_nametbl_mc_translate(msg_nametype(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 167 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 175 | if (dp->count != 0) { |
Allan Stephens | 7f47f5c | 2011-04-18 10:14:26 -0400 | [diff] [blame] | 176 | msg_set_destnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 177 | if (dp->count == 1) { |
| 178 | msg_set_destport(msg, dp->ports[0]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 179 | tipc_port_recv_msg(buf); |
| 180 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 181 | 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 Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 188 | pr_warn("Unable to deliver multicast message(s)\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 189 | goto exit; |
| 190 | } |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 191 | if ((index == 0) && (cnt != 0)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 192 | item = item->next; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 193 | msg_set_destport(buf_msg(b), item->ports[index]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 194 | tipc_port_recv_msg(b); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | exit: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 198 | kfree_skb(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 199 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /** |
Ying Xue | 3c5db8e | 2013-06-17 10:54:44 -0400 | [diff] [blame] | 203 | * tipc_createport - create a generic TIPC port |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 204 | * |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 205 | * Returns pointer to (locked) TIPC port, or NULL if unable to create it |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 206 | */ |
Ying Xue | c0fee8a | 2013-06-17 10:54:46 -0400 | [diff] [blame] | 207 | struct tipc_port *tipc_createport(struct sock *sk, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 208 | u32 (*dispatcher)(struct tipc_port *, |
| 209 | struct sk_buff *), |
| 210 | void (*wakeup)(struct tipc_port *), |
| 211 | const u32 importance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 212 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 213 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 214 | struct tipc_msg *msg; |
| 215 | u32 ref; |
| 216 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 217 | p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 218 | if (!p_ptr) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 219 | pr_warn("Port creation failed, no memory\n"); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 220 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 221 | } |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 222 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 223 | if (!ref) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 224 | pr_warn("Port creation failed, ref. table exhausted\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 225 | kfree(p_ptr); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 226 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Ying Xue | c0fee8a | 2013-06-17 10:54:46 -0400 | [diff] [blame] | 229 | p_ptr->sk = sk; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 230 | p_ptr->max_pkt = MAX_PKT_DEFAULT; |
| 231 | p_ptr->ref = ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 232 | INIT_LIST_HEAD(&p_ptr->wait_list); |
| 233 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 234 | p_ptr->dispatcher = dispatcher; |
| 235 | p_ptr->wakeup = wakeup; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 236 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 237 | INIT_LIST_HEAD(&p_ptr->publications); |
| 238 | INIT_LIST_HEAD(&p_ptr->port_list); |
Allan Stephens | f21536d | 2012-04-17 18:22:49 -0400 | [diff] [blame] | 239 | |
| 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 Stephens | f21536d | 2012-04-17 18:22:49 -0400 | [diff] [blame] | 245 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 249 | list_add_tail(&p_ptr->port_list, &ports); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 250 | spin_unlock_bh(&tipc_port_list_lock); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 251 | return p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | int tipc_deleteport(u32 ref) |
| 255 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 256 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 257 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 259 | tipc_withdraw(ref, 0, NULL); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 260 | p_ptr = tipc_port_lock(ref); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 261 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 262 | return -EINVAL; |
| 263 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 264 | tipc_ref_discard(ref); |
| 265 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 266 | |
| 267 | k_cancel_timer(&p_ptr->timer); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 268 | if (p_ptr->connected) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 269 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 270 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 271 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 272 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 273 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 274 | list_del(&p_ptr->port_list); |
| 275 | list_del(&p_ptr->wait_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 276 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 277 | k_term_timer(&p_ptr->timer); |
| 278 | kfree(p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 279 | tipc_net_route_msg(buf); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 280 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 283 | static int port_unreliable(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 284 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 285 | return msg_src_droppable(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) |
| 289 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 290 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 291 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 292 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 293 | if (!p_ptr) |
| 294 | return -EINVAL; |
| 295 | *isunreliable = port_unreliable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 296 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 297 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) |
| 301 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 302 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 303 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 304 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 305 | if (!p_ptr) |
| 306 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 307 | msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 308 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 309 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 312 | static int port_unreturnable(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 313 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 314 | return msg_dest_droppable(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) |
| 318 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 319 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 320 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 321 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 322 | if (!p_ptr) |
| 323 | return -EINVAL; |
| 324 | *isunrejectable = port_unreturnable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 325 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 326 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) |
| 330 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 331 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 332 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 333 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 334 | if (!p_ptr) |
| 335 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 336 | msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 337 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 338 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | } |
| 340 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 341 | /* |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 342 | * port_build_proto_msg(): create connection protocol message for port |
| 343 | * |
| 344 | * On entry the port must be locked and connected. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 345 | */ |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 346 | static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr, |
| 347 | u32 type, u32 ack) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 348 | { |
| 349 | struct sk_buff *buf; |
| 350 | struct tipc_msg *msg; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 351 | |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 352 | buf = tipc_buf_acquire(INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 353 | if (buf) { |
| 354 | msg = buf_msg(buf); |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 355 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 359 | msg_set_msgcnt(msg, ack); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 360 | } |
| 361 | return buf; |
| 362 | } |
| 363 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 364 | int 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 Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 370 | u32 imp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 371 | u32 data_sz = msg_data_sz(msg); |
Allan Stephens | 017dac3 | 2011-05-24 13:20:09 -0400 | [diff] [blame] | 372 | u32 src_node; |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 373 | u32 rmsg_sz; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 374 | |
| 375 | /* discard rejected message if it shouldn't be returned to sender */ |
Allan Stephens | 76d1252 | 2011-05-23 13:57:25 -0400 | [diff] [blame] | 376 | if (WARN(!msg_isdata(msg), |
| 377 | "attempt to reject message with user=%u", msg_user(msg))) { |
| 378 | dump_stack(); |
| 379 | goto exit; |
| 380 | } |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 381 | if (msg_errcode(msg) || msg_dest_droppable(msg)) |
| 382 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 383 | |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 384 | /* |
| 385 | * construct returned message by copying rejected message header and |
| 386 | * data (or subset), then updating header fields that need adjusting |
| 387 | */ |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 388 | 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 Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 392 | if (rbuf == NULL) |
| 393 | goto exit; |
| 394 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 395 | rmsg = buf_msg(rbuf); |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 396 | 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 Stephens | 99c1459 | 2008-06-04 17:48:25 -0700 | [diff] [blame] | 402 | } |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 403 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 410 | |
| 411 | /* send self-abort message when rejecting on a connected port */ |
| 412 | if (msg_connected(msg)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 413 | struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 414 | |
| 415 | if (p_ptr) { |
Allan Stephens | dff10e9 | 2011-11-02 10:32:14 -0400 | [diff] [blame] | 416 | struct sk_buff *abuf = NULL; |
| 417 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 418 | if (p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 419 | abuf = port_build_self_abort_msg(p_ptr, err); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 420 | tipc_port_unlock(p_ptr); |
Allan Stephens | dff10e9 | 2011-11-02 10:32:14 -0400 | [diff] [blame] | 421 | tipc_net_route_msg(abuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 422 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 425 | /* send returned message & dispose of rejected message */ |
Allan Stephens | 017dac3 | 2011-05-24 13:20:09 -0400 | [diff] [blame] | 426 | src_node = msg_prevnode(msg); |
Allan Stephens | 630d920 | 2012-04-18 09:42:29 -0400 | [diff] [blame] | 427 | if (in_own_node(src_node)) |
Allan Stephens | 017dac3 | 2011-05-24 13:20:09 -0400 | [diff] [blame] | 428 | tipc_port_recv_msg(rbuf); |
| 429 | else |
| 430 | tipc_link_send(rbuf, src_node, msg_link_selector(rmsg)); |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 431 | exit: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 432 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 433 | return data_sz; |
| 434 | } |
| 435 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 436 | int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 437 | struct iovec const *msg_sect, unsigned int len, |
| 438 | int err) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 439 | { |
| 440 | struct sk_buff *buf; |
| 441 | int res; |
| 442 | |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 443 | res = tipc_msg_build(hdr, msg_sect, len, MAX_MSG_SIZE, &buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 444 | if (!buf) |
| 445 | return res; |
| 446 | |
| 447 | return tipc_reject_msg(buf, err); |
| 448 | } |
| 449 | |
| 450 | static void port_timeout(unsigned long ref) |
| 451 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 452 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 453 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 454 | |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 455 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 456 | return; |
| 457 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 458 | if (!p_ptr->connected) { |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 459 | tipc_port_unlock(p_ptr); |
| 460 | return; |
| 461 | } |
| 462 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 463 | /* 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 Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 467 | buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 468 | p_ptr->probing_state = PROBING; |
| 469 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 470 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 471 | tipc_port_unlock(p_ptr); |
| 472 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
| 476 | static void port_handle_node_down(unsigned long ref) |
| 477 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 478 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 479 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 480 | |
| 481 | if (!p_ptr) |
| 482 | return; |
| 483 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 484 | tipc_port_unlock(p_ptr); |
| 485 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 489 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 490 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 491 | struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 492 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 493 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 502 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 503 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 504 | struct sk_buff *buf; |
| 505 | struct tipc_msg *msg; |
| 506 | u32 imp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 507 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 508 | if (!p_ptr->connected) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 509 | return NULL; |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 510 | |
| 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 525 | void tipc_port_recv_proto_msg(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 526 | { |
| 527 | struct tipc_msg *msg = buf_msg(buf); |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 528 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 529 | struct sk_buff *r_buf = NULL; |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 530 | u32 destport = msg_destport(msg); |
| 531 | int wakeable; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 532 | |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 533 | /* Validate connection */ |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 534 | p_ptr = tipc_port_lock(destport); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 535 | if (!p_ptr || !p_ptr->connected || !tipc_port_peer_msg(p_ptr, msg)) { |
Allan Stephens | f55b564 | 2011-06-01 15:48:42 -0400 | [diff] [blame] | 536 | 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 Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 540 | BASIC_H_SIZE, msg_orignode(msg)); |
Allan Stephens | f55b564 | 2011-06-01 15:48:42 -0400 | [diff] [blame] | 541 | msg_set_errcode(msg, TIPC_ERR_NO_PORT); |
| 542 | msg_set_origport(msg, destport); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 543 | msg_set_destport(msg, msg_origport(msg)); |
Allan Stephens | f55b564 | 2011-06-01 15:48:42 -0400 | [diff] [blame] | 544 | } |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 545 | if (p_ptr) |
| 546 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 547 | goto exit; |
| 548 | } |
| 549 | |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 550 | /* Process protocol message sent by peer */ |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 551 | 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 Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 563 | r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0); |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 564 | break; |
| 565 | default: |
| 566 | /* CONN_PROBE_REPLY or unrecognized - no action required */ |
| 567 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 568 | } |
| 569 | p_ptr->probing_state = CONFIRMED; |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 570 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 571 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 572 | tipc_net_route_msg(r_buf); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 573 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 576 | static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 577 | { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 578 | struct publication *publ; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 579 | int ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 580 | |
| 581 | if (full_id) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 582 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 586 | else |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 587 | ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 588 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 589 | if (p_ptr->connected) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 590 | u32 dport = port_peerport(p_ptr); |
| 591 | u32 destnode = port_peernode(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 592 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 593 | 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 Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 598 | if (p_ptr->conn_type != 0) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 599 | ret += tipc_snprintf(buf + ret, len - ret, |
| 600 | " via {%u,%u}", p_ptr->conn_type, |
| 601 | p_ptr->conn_instance); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 602 | } else if (p_ptr->published) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 603 | ret += tipc_snprintf(buf + ret, len - ret, " bound to"); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 604 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 605 | if (publ->lower == publ->upper) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 606 | ret += tipc_snprintf(buf + ret, len - ret, |
| 607 | " {%u,%u}", publ->type, |
| 608 | publ->lower); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 609 | else |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 610 | ret += tipc_snprintf(buf + ret, len - ret, |
| 611 | " {%u,%u,%u}", publ->type, |
| 612 | publ->lower, publ->upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 613 | } |
| 614 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 615 | ret += tipc_snprintf(buf + ret, len - ret, "\n"); |
| 616 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 617 | } |
| 618 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 619 | struct sk_buff *tipc_port_get_ports(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 620 | { |
| 621 | struct sk_buff *buf; |
| 622 | struct tlv_desc *rep_tlv; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 623 | char *pb; |
| 624 | int pb_len; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 625 | struct tipc_port *p_ptr; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 626 | int str_len = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 627 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 628 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 629 | if (!buf) |
| 630 | return NULL; |
| 631 | rep_tlv = (struct tlv_desc *)buf->data; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 632 | pb = TLV_DATA(rep_tlv); |
| 633 | pb_len = ULTRA_STRING_MAX_LEN; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 634 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 635 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 636 | list_for_each_entry(p_ptr, &ports, port_list) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 637 | spin_lock_bh(p_ptr->lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 638 | str_len += port_print(p_ptr, pb, pb_len, 0); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 639 | spin_unlock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 640 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 641 | spin_unlock_bh(&tipc_port_list_lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 642 | str_len += 1; /* for "\0" */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 643 | 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 Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 649 | void tipc_port_reinit(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 650 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 651 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 652 | struct tipc_msg *msg; |
| 653 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 654 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 655 | list_for_each_entry(p_ptr, &ports, port_list) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 656 | msg = &p_ptr->phdr; |
Allan Stephens | 6d4a667 | 2008-05-21 14:54:12 -0700 | [diff] [blame] | 657 | msg_set_prevnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 658 | msg_set_orignode(msg, tipc_own_addr); |
| 659 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 660 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 663 | void tipc_acknowledge(u32 ref, u32 ack) |
| 664 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 665 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 666 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 667 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 668 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 669 | if (!p_ptr) |
| 670 | return; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 671 | if (p_ptr->connected) { |
| 672 | p_ptr->conn_unacked -= ack; |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 673 | buf = port_build_proto_msg(p_ptr, CONN_ACK, ack); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 674 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 675 | tipc_port_unlock(p_ptr); |
| 676 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 679 | int tipc_portimportance(u32 ref, unsigned int *importance) |
| 680 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 681 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 682 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 683 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 684 | if (!p_ptr) |
| 685 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 686 | *importance = (unsigned int)msg_importance(&p_ptr->phdr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 687 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 688 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | int tipc_set_portimportance(u32 ref, unsigned int imp) |
| 692 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 693 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 694 | |
| 695 | if (imp > TIPC_CRITICAL_IMPORTANCE) |
| 696 | return -EINVAL; |
| 697 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 698 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 699 | if (!p_ptr) |
| 700 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 701 | msg_set_importance(&p_ptr->phdr, (u32)imp); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 702 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 703 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 708 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 709 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 710 | struct publication *publ; |
| 711 | u32 key; |
| 712 | int res = -EINVAL; |
| 713 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 714 | p_ptr = tipc_port_lock(ref); |
Adrian Bunk | d55b4c6 | 2006-10-31 16:59:35 -0800 | [diff] [blame] | 715 | if (!p_ptr) |
| 716 | return -EINVAL; |
| 717 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 718 | if (p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 719 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 720 | key = ref + p_ptr->pub_count + 1; |
| 721 | if (key == ref) { |
| 722 | res = -EADDRINUSE; |
| 723 | goto exit; |
| 724 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 725 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 726 | scope, p_ptr->ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 727 | if (publ) { |
| 728 | list_add(&publ->pport_list, &p_ptr->publications); |
| 729 | p_ptr->pub_count++; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 730 | p_ptr->published = 1; |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 731 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 732 | } |
| 733 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 734 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 735 | return res; |
| 736 | } |
| 737 | |
| 738 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 739 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 740 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 741 | struct publication *publ; |
| 742 | struct publication *tpubl; |
| 743 | int res = -EINVAL; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 744 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 745 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 746 | if (!p_ptr) |
| 747 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 748 | if (!seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 749 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 750 | &p_ptr->publications, pport_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 751 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 752 | publ->ref, publ->key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 753 | } |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 754 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 755 | } else { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 756 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 757 | &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 Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 766 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 767 | publ->ref, publ->key); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 768 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | } |
| 772 | if (list_empty(&p_ptr->publications)) |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 773 | p_ptr->published = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 774 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 775 | return res; |
| 776 | } |
| 777 | |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 778 | int tipc_connect(u32 ref, struct tipc_portid const *peer) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 779 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 780 | struct tipc_port *p_ptr; |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 781 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 782 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 783 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 784 | if (!p_ptr) |
| 785 | return -EINVAL; |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 786 | 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 | */ |
| 796 | int __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 Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 802 | if (p_ptr->published || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 803 | goto exit; |
| 804 | if (!peer->ref) |
| 805 | goto exit; |
| 806 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 807 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 808 | msg_set_destnode(msg, peer->node); |
| 809 | msg_set_destport(msg, peer->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 810 | msg_set_type(msg, TIPC_CONN_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 811 | msg_set_lookup_scope(msg, 0); |
Allan Stephens | 08c80e9 | 2010-12-31 18:59:17 +0000 | [diff] [blame] | 812 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 813 | |
| 814 | p_ptr->probing_interval = PROBING_INTERVAL; |
| 815 | p_ptr->probing_state = CONFIRMED; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 816 | p_ptr->connected = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 817 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 818 | |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 819 | tipc_nodesub_subscribe(&p_ptr->subscription, peer->node, |
David S. Miller | 880b005 | 2006-01-12 13:22:32 -0800 | [diff] [blame] | 820 | (void *)(unsigned long)ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 821 | (net_ev_handler)port_handle_node_down); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 822 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 823 | exit: |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 824 | p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 825 | return res; |
| 826 | } |
| 827 | |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 828 | /* |
| 829 | * __tipc_disconnect - disconnect port from peer |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 830 | * |
| 831 | * Port must be locked. |
| 832 | */ |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 833 | int __tipc_disconnect(struct tipc_port *tp_ptr) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 834 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 835 | if (tp_ptr->connected) { |
| 836 | tp_ptr->connected = 0; |
| 837 | /* let timer expire on it's own to avoid deadlock! */ |
Joe Perches | e319269 | 2012-06-03 17:41:40 +0000 | [diff] [blame] | 838 | tipc_nodesub_unsubscribe(&tp_ptr->subscription); |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame^] | 839 | return 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 840 | } |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame^] | 841 | |
| 842 | return -ENOTCONN; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 845 | /* |
| 846 | * tipc_disconnect(): Disconnect port form peer. |
| 847 | * This is a node local operation. |
| 848 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 849 | int tipc_disconnect(u32 ref) |
| 850 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 851 | struct tipc_port *p_ptr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 852 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 853 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 854 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 855 | if (!p_ptr) |
| 856 | return -EINVAL; |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 857 | res = __tipc_disconnect(p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 858 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 859 | return res; |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect |
| 864 | */ |
| 865 | int tipc_shutdown(u32 ref) |
| 866 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 867 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 868 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 869 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 870 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 871 | if (!p_ptr) |
| 872 | return -EINVAL; |
| 873 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 874 | buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 875 | tipc_port_unlock(p_ptr); |
| 876 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 877 | return tipc_disconnect(ref); |
| 878 | } |
| 879 | |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 880 | /** |
| 881 | * tipc_port_recv_msg - receive message from lower layer and deliver to port user |
| 882 | */ |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 883 | int 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 Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 900 | 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 Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 907 | |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 908 | return tipc_reject_msg(buf, err); |
| 909 | } |
| 910 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 911 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 912 | * tipc_port_recv_sections(): Concatenate and deliver sectioned |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 913 | * message for this node. |
| 914 | */ |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 915 | static int tipc_port_recv_sections(struct tipc_port *sender, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 916 | struct iovec const *msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 917 | unsigned int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 918 | { |
| 919 | struct sk_buff *buf; |
| 920 | int res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 921 | |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 922 | res = tipc_msg_build(&sender->phdr, msg_sect, len, MAX_MSG_SIZE, &buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 923 | if (likely(buf)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 924 | tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 925 | return res; |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * tipc_send - send message sections on connection |
| 930 | */ |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 931 | int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 932 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 933 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 934 | u32 destnode; |
| 935 | int res; |
| 936 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 937 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 938 | if (!p_ptr || !p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 939 | return -EINVAL; |
| 940 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 941 | p_ptr->congested = 1; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 942 | if (!tipc_port_congested(p_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 943 | destnode = port_peernode(p_ptr); |
Allan Stephens | 8a55fe7 | 2012-04-18 09:27:22 -0400 | [diff] [blame] | 944 | if (likely(!in_own_node(destnode))) |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 945 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, |
| 946 | len, destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 947 | else |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 948 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 949 | |
| 950 | if (likely(res != -ELINKCONG)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 951 | p_ptr->congested = 0; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 952 | if (res > 0) |
| 953 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 954 | return res; |
| 955 | } |
| 956 | } |
| 957 | if (port_unreliable(p_ptr)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 958 | p_ptr->congested = 0; |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 959 | return len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 960 | } |
| 961 | return -ELINKCONG; |
| 962 | } |
| 963 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 964 | /** |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 965 | * tipc_send2name - send message sections to port name |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 966 | */ |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 967 | int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 968 | struct iovec const *msg_sect, unsigned int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 969 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 970 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 971 | struct tipc_msg *msg; |
| 972 | u32 destnode = domain; |
Allan Stephens | 9ccc2eb | 2010-05-11 14:30:06 +0000 | [diff] [blame] | 973 | u32 destport; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 974 | int res; |
| 975 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 976 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 977 | if (!p_ptr || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 978 | return -EINVAL; |
| 979 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 980 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 981 | msg_set_type(msg, TIPC_NAMED_MSG); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 982 | msg_set_hdr_sz(msg, NAMED_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 983 | msg_set_nametype(msg, name->type); |
| 984 | msg_set_nameinst(msg, name->instance); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 985 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 986 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 987 | msg_set_destnode(msg, destnode); |
| 988 | msg_set_destport(msg, destport); |
| 989 | |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 990 | if (likely(destport || destnode)) { |
Allan Stephens | 8a55fe7 | 2012-04-18 09:27:22 -0400 | [diff] [blame] | 991 | if (likely(in_own_node(destnode))) |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 992 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); |
Allan Stephens | b8f683d | 2012-04-18 09:22:56 -0400 | [diff] [blame] | 993 | else if (tipc_own_addr) |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 994 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 995 | len, destnode); |
Allan Stephens | b8f683d | 2012-04-18 09:22:56 -0400 | [diff] [blame] | 996 | else |
| 997 | res = tipc_port_reject_sections(p_ptr, msg, msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 998 | len, TIPC_ERR_NO_NODE); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 999 | if (likely(res != -ELINKCONG)) { |
| 1000 | if (res > 0) |
| 1001 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1002 | return res; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1003 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | if (port_unreliable(p_ptr)) { |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1005 | return len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1006 | } |
| 1007 | return -ELINKCONG; |
| 1008 | } |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1009 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, len, |
| 1010 | TIPC_ERR_NO_NAME); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /** |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1014 | * tipc_send2port - send message sections to port identity |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1015 | */ |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1016 | int tipc_send2port(u32 ref, struct tipc_portid const *dest, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1017 | struct iovec const *msg_sect, unsigned int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1018 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1019 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1020 | struct tipc_msg *msg; |
| 1021 | int res; |
| 1022 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1023 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1024 | if (!p_ptr || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1025 | return -EINVAL; |
| 1026 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1027 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1028 | msg_set_type(msg, TIPC_DIRECT_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 1029 | msg_set_lookup_scope(msg, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1030 | msg_set_destnode(msg, dest->node); |
| 1031 | msg_set_destport(msg, dest->ref); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1032 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1033 | |
Allan Stephens | 8a55fe7 | 2012-04-18 09:27:22 -0400 | [diff] [blame] | 1034 | if (in_own_node(dest->node)) |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1035 | res = tipc_port_recv_sections(p_ptr, msg_sect, len); |
Allan Stephens | b8f683d | 2012-04-18 09:22:56 -0400 | [diff] [blame] | 1036 | else if (tipc_own_addr) |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1037 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, len, |
| 1038 | dest->node); |
Allan Stephens | b8f683d | 2012-04-18 09:22:56 -0400 | [diff] [blame] | 1039 | else |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1040 | res = tipc_port_reject_sections(p_ptr, msg, msg_sect, len, |
| 1041 | TIPC_ERR_NO_NODE); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1042 | if (likely(res != -ELINKCONG)) { |
| 1043 | if (res > 0) |
| 1044 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1045 | return res; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1046 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1047 | if (port_unreliable(p_ptr)) { |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 1048 | return len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1049 | } |
| 1050 | return -ELINKCONG; |
| 1051 | } |