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