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