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 |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, 2010-2011, 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 | |
Allan Stephens | e3ec9c7 | 2010-12-31 18:59:34 +0000 | [diff] [blame] | 49 | static struct sk_buff *msg_queue_head; |
| 50 | static struct sk_buff *msg_queue_tail; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 51 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 52 | DEFINE_SPINLOCK(tipc_port_list_lock); |
| 53 | static DEFINE_SPINLOCK(queue_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 54 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 55 | static LIST_HEAD(ports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 56 | static void port_handle_node_down(unsigned long ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 57 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err); |
| 58 | 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] | 59 | static void port_timeout(unsigned long ref); |
| 60 | |
| 61 | |
Allan Stephens | d0e17fe | 2012-04-17 18:36:42 -0400 | [diff] [blame] | 62 | static inline u32 port_peernode(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 63 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 64 | return msg_destnode(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Allan Stephens | d0e17fe | 2012-04-17 18:36:42 -0400 | [diff] [blame] | 67 | static inline u32 port_peerport(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 68 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 69 | return msg_destport(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 72 | /* |
| 73 | * tipc_port_peer_msg - verify message was sent by connected port's peer |
| 74 | * |
| 75 | * Handles cases where the node's network address has changed from |
| 76 | * the default of <0.0.0> to its configured setting. |
| 77 | */ |
| 78 | |
| 79 | int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg) |
| 80 | { |
| 81 | u32 peernode; |
| 82 | u32 orignode; |
| 83 | |
| 84 | if (msg_origport(msg) != port_peerport(p_ptr)) |
| 85 | return 0; |
| 86 | |
| 87 | orignode = msg_orignode(msg); |
| 88 | peernode = port_peernode(p_ptr); |
| 89 | return (orignode == peernode) || |
| 90 | (!orignode && (peernode == tipc_own_addr)) || |
| 91 | (!peernode && (orignode == tipc_own_addr)); |
| 92 | } |
| 93 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 94 | /** |
| 95 | * tipc_multicast - send a multicast message to local and remote destinations |
| 96 | */ |
| 97 | |
Allan Stephens | 38f232e | 2010-11-30 12:00:59 +0000 | [diff] [blame] | 98 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 99 | u32 num_sect, struct iovec const *msg_sect, |
| 100 | unsigned int total_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | { |
| 102 | struct tipc_msg *hdr; |
| 103 | struct sk_buff *buf; |
| 104 | struct sk_buff *ibuf = NULL; |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 105 | struct tipc_port_list dports = {0, NULL, }; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 106 | struct tipc_port *oport = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 107 | int ext_targets; |
| 108 | int res; |
| 109 | |
| 110 | if (unlikely(!oport)) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | /* Create multicast message */ |
| 114 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 115 | hdr = &oport->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 116 | msg_set_type(hdr, TIPC_MCAST_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 117 | msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE); |
Allan Stephens | 7462b9e | 2011-04-18 10:08:22 -0400 | [diff] [blame] | 118 | msg_set_destport(hdr, 0); |
| 119 | msg_set_destnode(hdr, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 120 | msg_set_nametype(hdr, seq->type); |
| 121 | msg_set_namelower(hdr, seq->lower); |
| 122 | msg_set_nameupper(hdr, seq->upper); |
| 123 | msg_set_hdr_sz(hdr, MCAST_H_SIZE); |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 124 | res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 125 | !oport->user_port, &buf); |
| 126 | if (unlikely(!buf)) |
| 127 | return res; |
| 128 | |
| 129 | /* Figure out where to send multicast message */ |
| 130 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 131 | ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper, |
| 132 | TIPC_NODE_SCOPE, &dports); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 133 | |
| 134 | /* Send message to destinations (duplicate it only if necessary) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 135 | |
| 136 | if (ext_targets) { |
| 137 | if (dports.count != 0) { |
| 138 | ibuf = skb_copy(buf, GFP_ATOMIC); |
| 139 | if (ibuf == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 140 | tipc_port_list_free(&dports); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 141 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 142 | return -ENOMEM; |
| 143 | } |
| 144 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 145 | res = tipc_bclink_send_msg(buf); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 146 | if ((res < 0) && (dports.count != 0)) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 147 | kfree_skb(ibuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 148 | } else { |
| 149 | ibuf = buf; |
| 150 | } |
| 151 | |
| 152 | if (res >= 0) { |
| 153 | if (ibuf) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 154 | tipc_port_recv_mcast(ibuf, &dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 155 | } else { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 156 | tipc_port_list_free(&dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 157 | } |
| 158 | return res; |
| 159 | } |
| 160 | |
| 161 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 162 | * tipc_port_recv_mcast - deliver multicast message to all destination ports |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 163 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 164 | * If there is no port list, perform a lookup to create one |
| 165 | */ |
| 166 | |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 167 | 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] | 168 | { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 169 | struct tipc_msg *msg; |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 170 | struct tipc_port_list dports = {0, NULL, }; |
| 171 | struct tipc_port_list *item = dp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 172 | int cnt = 0; |
| 173 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 174 | msg = buf_msg(buf); |
| 175 | |
| 176 | /* Create destination port list, if one wasn't supplied */ |
| 177 | |
| 178 | if (dp == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 179 | tipc_nametbl_mc_translate(msg_nametype(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 180 | msg_namelower(msg), |
| 181 | msg_nameupper(msg), |
| 182 | TIPC_CLUSTER_SCOPE, |
| 183 | &dports); |
| 184 | item = dp = &dports; |
| 185 | } |
| 186 | |
| 187 | /* Deliver a copy of message to each destination port */ |
| 188 | |
| 189 | if (dp->count != 0) { |
Allan Stephens | 7f47f5c | 2011-04-18 10:14:26 -0400 | [diff] [blame] | 190 | msg_set_destnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 191 | if (dp->count == 1) { |
| 192 | msg_set_destport(msg, dp->ports[0]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 193 | tipc_port_recv_msg(buf); |
| 194 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | for (; cnt < dp->count; cnt++) { |
| 198 | int index = cnt % PLSIZE; |
| 199 | struct sk_buff *b = skb_clone(buf, GFP_ATOMIC); |
| 200 | |
| 201 | if (b == NULL) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 202 | warn("Unable to deliver multicast message(s)\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 203 | goto exit; |
| 204 | } |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 205 | if ((index == 0) && (cnt != 0)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 206 | item = item->next; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 207 | msg_set_destport(buf_msg(b), item->ports[index]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 208 | tipc_port_recv_msg(b); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | exit: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 212 | kfree_skb(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 213 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
Allan Stephens | 7ef43eb | 2008-05-12 15:42:28 -0700 | [diff] [blame] | 217 | * tipc_createport_raw - create a generic TIPC port |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 218 | * |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 219 | * 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] | 220 | */ |
| 221 | |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 222 | struct tipc_port *tipc_createport_raw(void *usr_handle, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 223 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *), |
| 224 | void (*wakeup)(struct tipc_port *), |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 225 | const u32 importance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 226 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 227 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 228 | struct tipc_msg *msg; |
| 229 | u32 ref; |
| 230 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 231 | p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 232 | if (!p_ptr) { |
| 233 | warn("Port creation failed, no memory\n"); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 234 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 235 | } |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 236 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 237 | if (!ref) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 238 | warn("Port creation failed, reference table exhausted\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 239 | kfree(p_ptr); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 240 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 243 | p_ptr->usr_handle = usr_handle; |
| 244 | p_ptr->max_pkt = MAX_PKT_DEFAULT; |
| 245 | p_ptr->ref = ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | INIT_LIST_HEAD(&p_ptr->wait_list); |
| 247 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 248 | p_ptr->dispatcher = dispatcher; |
| 249 | p_ptr->wakeup = wakeup; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 250 | p_ptr->user_port = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 251 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 252 | INIT_LIST_HEAD(&p_ptr->publications); |
| 253 | INIT_LIST_HEAD(&p_ptr->port_list); |
Allan Stephens | f21536d | 2012-04-17 18:22:49 -0400 | [diff] [blame] | 254 | |
| 255 | /* |
| 256 | * Must hold port list lock while initializing message header template |
| 257 | * to ensure a change to node's own network address doesn't result |
| 258 | * in template containing out-dated network address information |
| 259 | */ |
| 260 | |
| 261 | spin_lock_bh(&tipc_port_list_lock); |
| 262 | msg = &p_ptr->phdr; |
| 263 | tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0); |
| 264 | msg_set_origport(msg, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 265 | list_add_tail(&p_ptr->port_list, &ports); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 266 | spin_unlock_bh(&tipc_port_list_lock); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 267 | return p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | int tipc_deleteport(u32 ref) |
| 271 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 272 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 273 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 274 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 275 | tipc_withdraw(ref, 0, NULL); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 276 | p_ptr = tipc_port_lock(ref); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 277 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 278 | return -EINVAL; |
| 279 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 280 | tipc_ref_discard(ref); |
| 281 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 282 | |
| 283 | k_cancel_timer(&p_ptr->timer); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 284 | if (p_ptr->connected) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 285 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 286 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 287 | } |
Allan Stephens | e83504f | 2010-12-31 18:59:30 +0000 | [diff] [blame] | 288 | kfree(p_ptr->user_port); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 289 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 290 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 291 | list_del(&p_ptr->port_list); |
| 292 | list_del(&p_ptr->wait_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 293 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 294 | k_term_timer(&p_ptr->timer); |
| 295 | kfree(p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 296 | tipc_net_route_msg(buf); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 297 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 300 | static int port_unreliable(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 301 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 302 | return msg_src_droppable(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) |
| 306 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 307 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 308 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 309 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 310 | if (!p_ptr) |
| 311 | return -EINVAL; |
| 312 | *isunreliable = port_unreliable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 313 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 314 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) |
| 318 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 319 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 320 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 321 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 322 | if (!p_ptr) |
| 323 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 324 | msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 325 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 326 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 329 | static int port_unreturnable(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 330 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 331 | return msg_dest_droppable(&p_ptr->phdr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) |
| 335 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 336 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 337 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 338 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | if (!p_ptr) |
| 340 | return -EINVAL; |
| 341 | *isunrejectable = port_unreturnable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 342 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 343 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) |
| 347 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 348 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 349 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 350 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | if (!p_ptr) |
| 352 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 353 | msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 354 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 355 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 356 | } |
| 357 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 358 | /* |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 359 | * port_build_proto_msg(): create connection protocol message for port |
| 360 | * |
| 361 | * On entry the port must be locked and connected. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 362 | */ |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 363 | static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr, |
| 364 | u32 type, u32 ack) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 365 | { |
| 366 | struct sk_buff *buf; |
| 367 | struct tipc_msg *msg; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 368 | |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 369 | buf = tipc_buf_acquire(INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 370 | if (buf) { |
| 371 | msg = buf_msg(buf); |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 372 | tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE, |
| 373 | port_peernode(p_ptr)); |
| 374 | msg_set_destport(msg, port_peerport(p_ptr)); |
| 375 | msg_set_origport(msg, p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 376 | msg_set_msgcnt(msg, ack); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 377 | } |
| 378 | return buf; |
| 379 | } |
| 380 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 381 | int tipc_reject_msg(struct sk_buff *buf, u32 err) |
| 382 | { |
| 383 | struct tipc_msg *msg = buf_msg(buf); |
| 384 | struct sk_buff *rbuf; |
| 385 | struct tipc_msg *rmsg; |
| 386 | int hdr_sz; |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 387 | u32 imp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 388 | u32 data_sz = msg_data_sz(msg); |
Allan Stephens | 017dac3 | 2011-05-24 13:20:09 -0400 | [diff] [blame] | 389 | u32 src_node; |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 390 | u32 rmsg_sz; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 391 | |
| 392 | /* discard rejected message if it shouldn't be returned to sender */ |
Allan Stephens | 76d1252 | 2011-05-23 13:57:25 -0400 | [diff] [blame] | 393 | |
| 394 | if (WARN(!msg_isdata(msg), |
| 395 | "attempt to reject message with user=%u", msg_user(msg))) { |
| 396 | dump_stack(); |
| 397 | goto exit; |
| 398 | } |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 399 | if (msg_errcode(msg) || msg_dest_droppable(msg)) |
| 400 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 401 | |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 402 | /* |
| 403 | * construct returned message by copying rejected message header and |
| 404 | * data (or subset), then updating header fields that need adjusting |
| 405 | */ |
| 406 | |
| 407 | hdr_sz = msg_hdr_sz(msg); |
| 408 | rmsg_sz = hdr_sz + min_t(u32, data_sz, MAX_REJECT_SIZE); |
| 409 | |
| 410 | rbuf = tipc_buf_acquire(rmsg_sz); |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 411 | if (rbuf == NULL) |
| 412 | goto exit; |
| 413 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 414 | rmsg = buf_msg(rbuf); |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 415 | skb_copy_to_linear_data(rbuf, msg, rmsg_sz); |
| 416 | |
| 417 | if (msg_connected(rmsg)) { |
| 418 | imp = msg_importance(rmsg); |
| 419 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 420 | msg_set_importance(rmsg, ++imp); |
Allan Stephens | 99c1459 | 2008-06-04 17:48:25 -0700 | [diff] [blame] | 421 | } |
Allan Stephens | 7dd1bf2 | 2011-05-23 16:23:32 -0400 | [diff] [blame] | 422 | msg_set_non_seq(rmsg, 0); |
| 423 | msg_set_size(rmsg, rmsg_sz); |
| 424 | msg_set_errcode(rmsg, err); |
| 425 | msg_set_prevnode(rmsg, tipc_own_addr); |
| 426 | msg_swap_words(rmsg, 4, 5); |
| 427 | if (!msg_short(rmsg)) |
| 428 | msg_swap_words(rmsg, 6, 7); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 429 | |
| 430 | /* send self-abort message when rejecting on a connected port */ |
| 431 | if (msg_connected(msg)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 432 | struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 433 | |
| 434 | if (p_ptr) { |
Allan Stephens | dff10e9 | 2011-11-02 10:32:14 -0400 | [diff] [blame] | 435 | struct sk_buff *abuf = NULL; |
| 436 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 437 | if (p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 438 | abuf = port_build_self_abort_msg(p_ptr, err); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 439 | tipc_port_unlock(p_ptr); |
Allan Stephens | dff10e9 | 2011-11-02 10:32:14 -0400 | [diff] [blame] | 440 | tipc_net_route_msg(abuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 441 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 444 | /* send returned message & dispose of rejected message */ |
| 445 | |
Allan Stephens | 017dac3 | 2011-05-24 13:20:09 -0400 | [diff] [blame] | 446 | src_node = msg_prevnode(msg); |
| 447 | if (src_node == tipc_own_addr) |
| 448 | tipc_port_recv_msg(rbuf); |
| 449 | else |
| 450 | tipc_link_send(rbuf, src_node, msg_link_selector(rmsg)); |
Allan Stephens | acc631b | 2011-05-23 13:47:44 -0400 | [diff] [blame] | 451 | exit: |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 452 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 453 | return data_sz; |
| 454 | } |
| 455 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 456 | 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] | 457 | struct iovec const *msg_sect, u32 num_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 458 | unsigned int total_len, int err) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 459 | { |
| 460 | struct sk_buff *buf; |
| 461 | int res; |
| 462 | |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 463 | res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 464 | !p_ptr->user_port, &buf); |
| 465 | if (!buf) |
| 466 | return res; |
| 467 | |
| 468 | return tipc_reject_msg(buf, err); |
| 469 | } |
| 470 | |
| 471 | static void port_timeout(unsigned long ref) |
| 472 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 473 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 474 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 475 | |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 476 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 477 | return; |
| 478 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 479 | if (!p_ptr->connected) { |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 480 | tipc_port_unlock(p_ptr); |
| 481 | return; |
| 482 | } |
| 483 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 484 | /* Last probe answered ? */ |
| 485 | if (p_ptr->probing_state == PROBING) { |
| 486 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
| 487 | } else { |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 488 | buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 489 | p_ptr->probing_state = PROBING; |
| 490 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 491 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 492 | tipc_port_unlock(p_ptr); |
| 493 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | |
| 497 | static void port_handle_node_down(unsigned long ref) |
| 498 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 499 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 500 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 501 | |
| 502 | if (!p_ptr) |
| 503 | return; |
| 504 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 505 | tipc_port_unlock(p_ptr); |
| 506 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 510 | 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] | 511 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 512 | struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 513 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 514 | if (buf) { |
| 515 | struct tipc_msg *msg = buf_msg(buf); |
| 516 | msg_swap_words(msg, 4, 5); |
| 517 | msg_swap_words(msg, 6, 7); |
| 518 | } |
| 519 | return buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 523 | 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] | 524 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 525 | struct sk_buff *buf; |
| 526 | struct tipc_msg *msg; |
| 527 | u32 imp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 528 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 529 | if (!p_ptr->connected) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 530 | return NULL; |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 531 | |
| 532 | buf = tipc_buf_acquire(BASIC_H_SIZE); |
| 533 | if (buf) { |
| 534 | msg = buf_msg(buf); |
| 535 | memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE); |
| 536 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
| 537 | msg_set_size(msg, BASIC_H_SIZE); |
| 538 | imp = msg_importance(msg); |
| 539 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 540 | msg_set_importance(msg, ++imp); |
| 541 | msg_set_errcode(msg, err); |
| 542 | } |
| 543 | return buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 546 | void tipc_port_recv_proto_msg(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 547 | { |
| 548 | struct tipc_msg *msg = buf_msg(buf); |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 549 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 550 | struct sk_buff *r_buf = NULL; |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 551 | u32 destport = msg_destport(msg); |
| 552 | int wakeable; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 553 | |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 554 | /* Validate connection */ |
| 555 | |
| 556 | p_ptr = tipc_port_lock(destport); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 557 | 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] | 558 | r_buf = tipc_buf_acquire(BASIC_H_SIZE); |
| 559 | if (r_buf) { |
| 560 | msg = buf_msg(r_buf); |
| 561 | tipc_msg_init(msg, TIPC_HIGH_IMPORTANCE, TIPC_CONN_MSG, |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 562 | BASIC_H_SIZE, msg_orignode(msg)); |
Allan Stephens | f55b564 | 2011-06-01 15:48:42 -0400 | [diff] [blame] | 563 | msg_set_errcode(msg, TIPC_ERR_NO_PORT); |
| 564 | msg_set_origport(msg, destport); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 565 | msg_set_destport(msg, msg_origport(msg)); |
Allan Stephens | f55b564 | 2011-06-01 15:48:42 -0400 | [diff] [blame] | 566 | } |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 567 | if (p_ptr) |
| 568 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 569 | goto exit; |
| 570 | } |
| 571 | |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 572 | /* Process protocol message sent by peer */ |
| 573 | |
| 574 | switch (msg_type(msg)) { |
| 575 | case CONN_ACK: |
| 576 | wakeable = tipc_port_congested(p_ptr) && p_ptr->congested && |
| 577 | p_ptr->wakeup; |
| 578 | p_ptr->acked += msg_msgcnt(msg); |
| 579 | if (!tipc_port_congested(p_ptr)) { |
| 580 | p_ptr->congested = 0; |
| 581 | if (wakeable) |
| 582 | p_ptr->wakeup(p_ptr); |
| 583 | } |
| 584 | break; |
| 585 | case CONN_PROBE: |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 586 | r_buf = port_build_proto_msg(p_ptr, CONN_PROBE_REPLY, 0); |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 587 | break; |
| 588 | default: |
| 589 | /* CONN_PROBE_REPLY or unrecognized - no action required */ |
| 590 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 591 | } |
| 592 | p_ptr->probing_state = CONFIRMED; |
Allan Stephens | 1c1a551 | 2011-06-01 15:08:10 -0400 | [diff] [blame] | 593 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 594 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 595 | tipc_net_route_msg(r_buf); |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 596 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 599 | static void port_print(struct tipc_port *p_ptr, struct print_buf *buf, int full_id) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 600 | { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 601 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 602 | |
| 603 | if (full_id) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 604 | tipc_printf(buf, "<%u.%u.%u:%u>:", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 605 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 606 | tipc_node(tipc_own_addr), p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 607 | else |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 608 | tipc_printf(buf, "%-10u:", p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 609 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 610 | if (p_ptr->connected) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 611 | u32 dport = port_peerport(p_ptr); |
| 612 | u32 destnode = port_peernode(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 613 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 614 | tipc_printf(buf, " connected to <%u.%u.%u:%u>", |
| 615 | tipc_zone(destnode), tipc_cluster(destnode), |
| 616 | tipc_node(destnode), dport); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 617 | if (p_ptr->conn_type != 0) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 618 | tipc_printf(buf, " via {%u,%u}", |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 619 | p_ptr->conn_type, |
| 620 | p_ptr->conn_instance); |
| 621 | } else if (p_ptr->published) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 622 | tipc_printf(buf, " bound to"); |
| 623 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 624 | if (publ->lower == publ->upper) |
| 625 | tipc_printf(buf, " {%u,%u}", publ->type, |
| 626 | publ->lower); |
| 627 | else |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 628 | tipc_printf(buf, " {%u,%u,%u}", publ->type, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 629 | publ->lower, publ->upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | tipc_printf(buf, "\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | #define MAX_PORT_QUERY 32768 |
| 636 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 637 | struct sk_buff *tipc_port_get_ports(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 638 | { |
| 639 | struct sk_buff *buf; |
| 640 | struct tlv_desc *rep_tlv; |
| 641 | struct print_buf pb; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 642 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 643 | int str_len; |
| 644 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 645 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 646 | if (!buf) |
| 647 | return NULL; |
| 648 | rep_tlv = (struct tlv_desc *)buf->data; |
| 649 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 650 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY); |
| 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 | spin_lock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 654 | port_print(p_ptr, &pb, 0); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 655 | spin_unlock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 656 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 657 | spin_unlock_bh(&tipc_port_list_lock); |
| 658 | str_len = tipc_printbuf_validate(&pb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 659 | |
| 660 | skb_put(buf, TLV_SPACE(str_len)); |
| 661 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 662 | |
| 663 | return buf; |
| 664 | } |
| 665 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 666 | void tipc_port_reinit(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 667 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 668 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 669 | struct tipc_msg *msg; |
| 670 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 671 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 672 | list_for_each_entry(p_ptr, &ports, port_list) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 673 | msg = &p_ptr->phdr; |
Allan Stephens | 6d4a667 | 2008-05-21 14:54:12 -0700 | [diff] [blame] | 674 | msg_set_prevnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 675 | msg_set_orignode(msg, tipc_own_addr); |
| 676 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 677 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | /* |
| 682 | * port_dispatcher_sigh(): Signal handler for messages destinated |
| 683 | * to the tipc_port interface. |
| 684 | */ |
| 685 | |
| 686 | static void port_dispatcher_sigh(void *dummy) |
| 687 | { |
| 688 | struct sk_buff *buf; |
| 689 | |
| 690 | spin_lock_bh(&queue_lock); |
| 691 | buf = msg_queue_head; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 692 | msg_queue_head = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 693 | spin_unlock_bh(&queue_lock); |
| 694 | |
| 695 | while (buf) { |
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 | struct user_port *up_ptr; |
| 698 | struct tipc_portid orig; |
| 699 | struct tipc_name_seq dseq; |
| 700 | void *usr_handle; |
| 701 | int connected; |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 702 | int peer_invalid; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 703 | int published; |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 704 | u32 message_type; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 705 | |
| 706 | struct sk_buff *next = buf->next; |
| 707 | struct tipc_msg *msg = buf_msg(buf); |
| 708 | u32 dref = msg_destport(msg); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 709 | |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 710 | message_type = msg_type(msg); |
| 711 | if (message_type > TIPC_DIRECT_MSG) |
| 712 | goto reject; /* Unsupported message type */ |
| 713 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 714 | p_ptr = tipc_port_lock(dref); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 715 | if (!p_ptr) |
| 716 | goto reject; /* Port deleted while msg in queue */ |
| 717 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 718 | orig.ref = msg_origport(msg); |
| 719 | orig.node = msg_orignode(msg); |
| 720 | up_ptr = p_ptr->user_port; |
| 721 | usr_handle = up_ptr->usr_handle; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 722 | connected = p_ptr->connected; |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 723 | peer_invalid = connected && !tipc_port_peer_msg(p_ptr, msg); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 724 | published = p_ptr->published; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 725 | |
| 726 | if (unlikely(msg_errcode(msg))) |
| 727 | goto err; |
| 728 | |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 729 | switch (message_type) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 730 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 731 | case TIPC_CONN_MSG:{ |
| 732 | tipc_conn_msg_event cb = up_ptr->conn_msg_cb; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 733 | u32 dsz; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 734 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 735 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 736 | if (unlikely(!cb)) |
| 737 | goto reject; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 738 | if (unlikely(!connected)) { |
Allan Stephens | 84b07c1 | 2008-06-04 17:28:21 -0700 | [diff] [blame] | 739 | if (tipc_connect2port(dref, &orig)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 740 | goto reject; |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 741 | } else if (peer_invalid) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 742 | goto reject; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 743 | dsz = msg_data_sz(msg); |
| 744 | if (unlikely(dsz && |
| 745 | (++p_ptr->conn_unacked >= |
| 746 | TIPC_FLOW_CONTROL_WIN))) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 747 | tipc_acknowledge(dref, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 748 | p_ptr->conn_unacked); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 749 | skb_pull(buf, msg_hdr_sz(msg)); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 750 | cb(usr_handle, dref, &buf, msg_data(msg), dsz); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 751 | break; |
| 752 | } |
| 753 | case TIPC_DIRECT_MSG:{ |
| 754 | tipc_msg_event cb = up_ptr->msg_cb; |
| 755 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 756 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 757 | if (unlikely(!cb || connected)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 758 | goto reject; |
| 759 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 760 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 761 | msg_data_sz(msg), msg_importance(msg), |
| 762 | &orig); |
| 763 | break; |
| 764 | } |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 765 | case TIPC_MCAST_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 766 | case TIPC_NAMED_MSG:{ |
| 767 | tipc_named_msg_event cb = up_ptr->named_msg_cb; |
| 768 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 769 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 770 | if (unlikely(!cb || connected || !published)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 771 | goto reject; |
| 772 | dseq.type = msg_nametype(msg); |
| 773 | dseq.lower = msg_nameinst(msg); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 774 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
| 775 | ? dseq.lower : msg_nameupper(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 776 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 777 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 778 | msg_data_sz(msg), msg_importance(msg), |
| 779 | &orig, &dseq); |
| 780 | break; |
| 781 | } |
| 782 | } |
| 783 | if (buf) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 784 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 785 | buf = next; |
| 786 | continue; |
| 787 | err: |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 788 | switch (message_type) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 789 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 790 | case TIPC_CONN_MSG:{ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 791 | tipc_conn_shutdown_event cb = |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 792 | up_ptr->conn_err_cb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 793 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 794 | tipc_port_unlock(p_ptr); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 795 | if (!cb || !connected || peer_invalid) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 796 | break; |
| 797 | tipc_disconnect(dref); |
| 798 | skb_pull(buf, msg_hdr_sz(msg)); |
| 799 | cb(usr_handle, dref, &buf, msg_data(msg), |
| 800 | msg_data_sz(msg), msg_errcode(msg)); |
| 801 | break; |
| 802 | } |
| 803 | case TIPC_DIRECT_MSG:{ |
| 804 | tipc_msg_err_event cb = up_ptr->err_cb; |
| 805 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 806 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 807 | if (!cb || connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 808 | break; |
| 809 | skb_pull(buf, msg_hdr_sz(msg)); |
| 810 | cb(usr_handle, dref, &buf, msg_data(msg), |
| 811 | msg_data_sz(msg), msg_errcode(msg), &orig); |
| 812 | break; |
| 813 | } |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 814 | case TIPC_MCAST_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 815 | case TIPC_NAMED_MSG:{ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 816 | tipc_named_msg_err_event cb = |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 817 | up_ptr->named_err_cb; |
| 818 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 819 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 820 | if (!cb || connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 821 | break; |
| 822 | dseq.type = msg_nametype(msg); |
| 823 | dseq.lower = msg_nameinst(msg); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 824 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
| 825 | ? dseq.lower : msg_nameupper(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 826 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 827 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 828 | msg_data_sz(msg), msg_errcode(msg), &dseq); |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | if (buf) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 833 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 834 | buf = next; |
| 835 | continue; |
| 836 | reject: |
| 837 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); |
| 838 | buf = next; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * port_dispatcher(): Dispatcher for messages destinated |
| 844 | * to the tipc_port interface. Called with port locked. |
| 845 | */ |
| 846 | |
| 847 | static u32 port_dispatcher(struct tipc_port *dummy, struct sk_buff *buf) |
| 848 | { |
| 849 | buf->next = NULL; |
| 850 | spin_lock_bh(&queue_lock); |
| 851 | if (msg_queue_head) { |
| 852 | msg_queue_tail->next = buf; |
| 853 | msg_queue_tail = buf; |
| 854 | } else { |
| 855 | msg_queue_tail = msg_queue_head = buf; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 856 | tipc_k_signal((Handler)port_dispatcher_sigh, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 857 | } |
| 858 | spin_unlock_bh(&queue_lock); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 859 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 860 | } |
| 861 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 862 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 863 | * Wake up port after congestion: Called with port locked, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 864 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 865 | */ |
| 866 | |
| 867 | static void port_wakeup_sh(unsigned long ref) |
| 868 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 869 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 870 | struct user_port *up_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 871 | tipc_continue_event cb = NULL; |
| 872 | void *uh = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 873 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 874 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 875 | if (p_ptr) { |
| 876 | up_ptr = p_ptr->user_port; |
| 877 | if (up_ptr) { |
| 878 | cb = up_ptr->continue_event_cb; |
| 879 | uh = up_ptr->usr_handle; |
| 880 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 881 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 882 | } |
| 883 | if (cb) |
| 884 | cb(uh, ref); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | static void port_wakeup(struct tipc_port *p_ptr) |
| 889 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 890 | tipc_k_signal((Handler)port_wakeup_sh, p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | void tipc_acknowledge(u32 ref, u32 ack) |
| 894 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 895 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 896 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 897 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 898 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 899 | if (!p_ptr) |
| 900 | return; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 901 | if (p_ptr->connected) { |
| 902 | p_ptr->conn_unacked -= ack; |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 903 | buf = port_build_proto_msg(p_ptr, CONN_ACK, ack); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 904 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 905 | tipc_port_unlock(p_ptr); |
| 906 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /* |
Allan Stephens | b0c1e92 | 2010-12-31 18:59:22 +0000 | [diff] [blame] | 910 | * tipc_createport(): user level call. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 911 | */ |
| 912 | |
Allan Stephens | b0c1e92 | 2010-12-31 18:59:22 +0000 | [diff] [blame] | 913 | int tipc_createport(void *usr_handle, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 914 | unsigned int importance, |
| 915 | tipc_msg_err_event error_cb, |
| 916 | tipc_named_msg_err_event named_error_cb, |
| 917 | tipc_conn_shutdown_event conn_error_cb, |
| 918 | tipc_msg_event msg_cb, |
| 919 | tipc_named_msg_event named_msg_cb, |
| 920 | tipc_conn_msg_event conn_msg_cb, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 921 | tipc_continue_event continue_event_cb,/* May be zero */ |
| 922 | u32 *portref) |
| 923 | { |
| 924 | struct user_port *up_ptr; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 925 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 926 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 927 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 928 | if (!up_ptr) { |
Allan Stephens | a75bf87 | 2006-06-25 23:50:01 -0700 | [diff] [blame] | 929 | warn("Port creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 930 | return -ENOMEM; |
| 931 | } |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 932 | p_ptr = (struct tipc_port *)tipc_createport_raw(NULL, port_dispatcher, |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 933 | port_wakeup, importance); |
| 934 | if (!p_ptr) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 935 | kfree(up_ptr); |
| 936 | return -ENOMEM; |
| 937 | } |
| 938 | |
| 939 | p_ptr->user_port = up_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 940 | up_ptr->usr_handle = usr_handle; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 941 | up_ptr->ref = p_ptr->ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 942 | up_ptr->err_cb = error_cb; |
| 943 | up_ptr->named_err_cb = named_error_cb; |
| 944 | up_ptr->conn_err_cb = conn_error_cb; |
| 945 | up_ptr->msg_cb = msg_cb; |
| 946 | up_ptr->named_msg_cb = named_msg_cb; |
| 947 | up_ptr->conn_msg_cb = conn_msg_cb; |
| 948 | up_ptr->continue_event_cb = continue_event_cb; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 949 | *portref = p_ptr->ref; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 950 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 951 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 952 | } |
| 953 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 954 | int tipc_portimportance(u32 ref, unsigned int *importance) |
| 955 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 956 | struct tipc_port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 957 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 958 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 959 | if (!p_ptr) |
| 960 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 961 | *importance = (unsigned int)msg_importance(&p_ptr->phdr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 962 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 963 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | int tipc_set_portimportance(u32 ref, unsigned int imp) |
| 967 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 968 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 969 | |
| 970 | if (imp > TIPC_CRITICAL_IMPORTANCE) |
| 971 | return -EINVAL; |
| 972 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 973 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 974 | if (!p_ptr) |
| 975 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 976 | msg_set_importance(&p_ptr->phdr, (u32)imp); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 977 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 978 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | |
| 982 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 983 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 984 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 985 | struct publication *publ; |
| 986 | u32 key; |
| 987 | int res = -EINVAL; |
| 988 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 989 | p_ptr = tipc_port_lock(ref); |
Adrian Bunk | d55b4c6 | 2006-10-31 16:59:35 -0800 | [diff] [blame] | 990 | if (!p_ptr) |
| 991 | return -EINVAL; |
| 992 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 993 | if (p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 994 | goto exit; |
| 995 | if (seq->lower > seq->upper) |
| 996 | goto exit; |
| 997 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE)) |
| 998 | goto exit; |
| 999 | key = ref + p_ptr->pub_count + 1; |
| 1000 | if (key == ref) { |
| 1001 | res = -EADDRINUSE; |
| 1002 | goto exit; |
| 1003 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1004 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1005 | scope, p_ptr->ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1006 | if (publ) { |
| 1007 | list_add(&publ->pport_list, &p_ptr->publications); |
| 1008 | p_ptr->pub_count++; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1009 | p_ptr->published = 1; |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1010 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1011 | } |
| 1012 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1013 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1014 | return res; |
| 1015 | } |
| 1016 | |
| 1017 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 1018 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1019 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1020 | struct publication *publ; |
| 1021 | struct publication *tpubl; |
| 1022 | int res = -EINVAL; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1023 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1024 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1025 | if (!p_ptr) |
| 1026 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1027 | if (!seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1028 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1029 | &p_ptr->publications, pport_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1030 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1031 | publ->ref, publ->key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1032 | } |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1033 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1034 | } else { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1035 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1036 | &p_ptr->publications, pport_list) { |
| 1037 | if (publ->scope != scope) |
| 1038 | continue; |
| 1039 | if (publ->type != seq->type) |
| 1040 | continue; |
| 1041 | if (publ->lower != seq->lower) |
| 1042 | continue; |
| 1043 | if (publ->upper != seq->upper) |
| 1044 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1045 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1046 | publ->ref, publ->key); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1047 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | if (list_empty(&p_ptr->publications)) |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1052 | p_ptr->published = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1053 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1054 | return res; |
| 1055 | } |
| 1056 | |
| 1057 | int tipc_connect2port(u32 ref, struct tipc_portid const *peer) |
| 1058 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1059 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1060 | struct tipc_msg *msg; |
| 1061 | int res = -EINVAL; |
| 1062 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1063 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1064 | if (!p_ptr) |
| 1065 | return -EINVAL; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1066 | if (p_ptr->published || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1067 | goto exit; |
| 1068 | if (!peer->ref) |
| 1069 | goto exit; |
| 1070 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1071 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1072 | msg_set_destnode(msg, peer->node); |
| 1073 | msg_set_destport(msg, peer->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1074 | msg_set_type(msg, TIPC_CONN_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 1075 | msg_set_lookup_scope(msg, 0); |
Allan Stephens | 08c80e9 | 2010-12-31 18:59:17 +0000 | [diff] [blame] | 1076 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1077 | |
| 1078 | p_ptr->probing_interval = PROBING_INTERVAL; |
| 1079 | p_ptr->probing_state = CONFIRMED; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1080 | p_ptr->connected = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1081 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 1082 | |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1083 | tipc_nodesub_subscribe(&p_ptr->subscription, peer->node, |
David S. Miller | 880b005 | 2006-01-12 13:22:32 -0800 | [diff] [blame] | 1084 | (void *)(unsigned long)ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1085 | (net_ev_handler)port_handle_node_down); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1086 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1087 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1088 | tipc_port_unlock(p_ptr); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1089 | p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1090 | return res; |
| 1091 | } |
| 1092 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1093 | /** |
| 1094 | * tipc_disconnect_port - disconnect port from peer |
| 1095 | * |
| 1096 | * Port must be locked. |
| 1097 | */ |
| 1098 | |
| 1099 | int tipc_disconnect_port(struct tipc_port *tp_ptr) |
| 1100 | { |
| 1101 | int res; |
| 1102 | |
| 1103 | if (tp_ptr->connected) { |
| 1104 | tp_ptr->connected = 0; |
| 1105 | /* let timer expire on it's own to avoid deadlock! */ |
| 1106 | tipc_nodesub_unsubscribe( |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1107 | &((struct tipc_port *)tp_ptr)->subscription); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1108 | res = 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1109 | } else { |
| 1110 | res = -ENOTCONN; |
| 1111 | } |
| 1112 | return res; |
| 1113 | } |
| 1114 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1115 | /* |
| 1116 | * tipc_disconnect(): Disconnect port form peer. |
| 1117 | * This is a node local operation. |
| 1118 | */ |
| 1119 | |
| 1120 | int tipc_disconnect(u32 ref) |
| 1121 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1122 | struct tipc_port *p_ptr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1123 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1124 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1125 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1126 | if (!p_ptr) |
| 1127 | return -EINVAL; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1128 | res = tipc_disconnect_port((struct tipc_port *)p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1129 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1130 | return res; |
| 1131 | } |
| 1132 | |
| 1133 | /* |
| 1134 | * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect |
| 1135 | */ |
| 1136 | int tipc_shutdown(u32 ref) |
| 1137 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1138 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 1139 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1140 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1141 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1142 | if (!p_ptr) |
| 1143 | return -EINVAL; |
| 1144 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 1145 | buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1146 | tipc_port_unlock(p_ptr); |
| 1147 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1148 | return tipc_disconnect(ref); |
| 1149 | } |
| 1150 | |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 1151 | /** |
| 1152 | * tipc_port_recv_msg - receive message from lower layer and deliver to port user |
| 1153 | */ |
| 1154 | |
| 1155 | int tipc_port_recv_msg(struct sk_buff *buf) |
| 1156 | { |
| 1157 | struct tipc_port *p_ptr; |
| 1158 | struct tipc_msg *msg = buf_msg(buf); |
| 1159 | u32 destport = msg_destport(msg); |
| 1160 | u32 dsz = msg_data_sz(msg); |
| 1161 | u32 err; |
| 1162 | |
| 1163 | /* forward unresolved named message */ |
| 1164 | if (unlikely(!destport)) { |
| 1165 | tipc_net_route_msg(buf); |
| 1166 | return dsz; |
| 1167 | } |
| 1168 | |
| 1169 | /* validate destination & pass to port, otherwise reject message */ |
| 1170 | p_ptr = tipc_port_lock(destport); |
| 1171 | if (likely(p_ptr)) { |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 1172 | err = p_ptr->dispatcher(p_ptr, buf); |
| 1173 | tipc_port_unlock(p_ptr); |
| 1174 | if (likely(!err)) |
| 1175 | return dsz; |
| 1176 | } else { |
| 1177 | err = TIPC_ERR_NO_PORT; |
| 1178 | } |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 1179 | |
Allan Stephens | 9b64125 | 2011-11-09 13:29:18 -0500 | [diff] [blame] | 1180 | return tipc_reject_msg(buf, err); |
| 1181 | } |
| 1182 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1183 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1184 | * tipc_port_recv_sections(): Concatenate and deliver sectioned |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1185 | * message for this node. |
| 1186 | */ |
| 1187 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1188 | 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] | 1189 | struct iovec const *msg_sect, |
| 1190 | unsigned int total_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1191 | { |
| 1192 | struct sk_buff *buf; |
| 1193 | int res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1194 | |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1195 | res = tipc_msg_build(&sender->phdr, msg_sect, num_sect, total_len, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1196 | MAX_MSG_SIZE, !sender->user_port, &buf); |
| 1197 | if (likely(buf)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1198 | tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1199 | return res; |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * tipc_send - send message sections on connection |
| 1204 | */ |
| 1205 | |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1206 | int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect, |
| 1207 | unsigned int total_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1208 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1209 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1210 | u32 destnode; |
| 1211 | int res; |
| 1212 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1213 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1214 | if (!p_ptr || !p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1215 | return -EINVAL; |
| 1216 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1217 | p_ptr->congested = 1; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1218 | if (!tipc_port_congested(p_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1219 | destnode = port_peernode(p_ptr); |
| 1220 | if (likely(destnode != tipc_own_addr)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1221 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1222 | total_len, destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1223 | else |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1224 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, |
| 1225 | total_len); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1226 | |
| 1227 | if (likely(res != -ELINKCONG)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1228 | p_ptr->congested = 0; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1229 | if (res > 0) |
| 1230 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1231 | return res; |
| 1232 | } |
| 1233 | } |
| 1234 | if (port_unreliable(p_ptr)) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1235 | p_ptr->congested = 0; |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1236 | return total_len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1237 | } |
| 1238 | return -ELINKCONG; |
| 1239 | } |
| 1240 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1241 | /** |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1242 | * tipc_send2name - send message sections to port name |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1243 | */ |
| 1244 | |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1245 | 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] | 1246 | unsigned int num_sect, struct iovec const *msg_sect, |
| 1247 | unsigned int total_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1248 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1249 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1250 | struct tipc_msg *msg; |
| 1251 | u32 destnode = domain; |
Allan Stephens | 9ccc2eb | 2010-05-11 14:30:06 +0000 | [diff] [blame] | 1252 | u32 destport; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1253 | int res; |
| 1254 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1255 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1256 | if (!p_ptr || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1257 | return -EINVAL; |
| 1258 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1259 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1260 | msg_set_type(msg, TIPC_NAMED_MSG); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1261 | msg_set_hdr_sz(msg, NAMED_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1262 | msg_set_nametype(msg, name->type); |
| 1263 | msg_set_nameinst(msg, name->instance); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1264 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1265 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1266 | msg_set_destnode(msg, destnode); |
| 1267 | msg_set_destport(msg, destport); |
| 1268 | |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 1269 | if (likely(destport || destnode)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1270 | if (likely(destnode == tipc_own_addr)) |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1271 | res = tipc_port_recv_sections(p_ptr, num_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1272 | msg_sect, total_len); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1273 | else |
| 1274 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1275 | num_sect, total_len, |
| 1276 | destnode); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1277 | if (likely(res != -ELINKCONG)) { |
| 1278 | if (res > 0) |
| 1279 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1280 | return res; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1281 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1282 | if (port_unreliable(p_ptr)) { |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1283 | return total_len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1284 | } |
| 1285 | return -ELINKCONG; |
| 1286 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1287 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1288 | total_len, TIPC_ERR_NO_NAME); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1292 | * tipc_send2port - send message sections to port identity |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1293 | */ |
| 1294 | |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1295 | int tipc_send2port(u32 ref, struct tipc_portid const *dest, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1296 | unsigned int num_sect, struct iovec const *msg_sect, |
| 1297 | unsigned int total_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1298 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1299 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1300 | struct tipc_msg *msg; |
| 1301 | int res; |
| 1302 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1303 | p_ptr = tipc_port_deref(ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1304 | if (!p_ptr || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1305 | return -EINVAL; |
| 1306 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1307 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1308 | msg_set_type(msg, TIPC_DIRECT_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 1309 | msg_set_lookup_scope(msg, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1310 | msg_set_destnode(msg, dest->node); |
| 1311 | msg_set_destport(msg, dest->ref); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1312 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1313 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1314 | if (dest->node == tipc_own_addr) |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1315 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, |
| 1316 | total_len); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1317 | else |
| 1318 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1319 | total_len, dest->node); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1320 | if (likely(res != -ELINKCONG)) { |
| 1321 | if (res > 0) |
| 1322 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1323 | return res; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1324 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1325 | if (port_unreliable(p_ptr)) { |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 1326 | return total_len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1327 | } |
| 1328 | return -ELINKCONG; |
| 1329 | } |
| 1330 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1331 | /** |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1332 | * tipc_send_buf2port - send message buffer to port identity |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1333 | */ |
| 1334 | |
Allan Stephens | 12bae47 | 2010-11-30 12:01:02 +0000 | [diff] [blame] | 1335 | int tipc_send_buf2port(u32 ref, struct tipc_portid const *dest, |
| 1336 | struct sk_buff *buf, unsigned int dsz) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1337 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1338 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1339 | struct tipc_msg *msg; |
| 1340 | int res; |
| 1341 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1342 | p_ptr = (struct tipc_port *)tipc_ref_deref(ref); |
| 1343 | if (!p_ptr || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1344 | return -EINVAL; |
| 1345 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 1346 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1347 | msg_set_type(msg, TIPC_DIRECT_MSG); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1348 | msg_set_destnode(msg, dest->node); |
| 1349 | msg_set_destport(msg, dest->ref); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1350 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
| 1351 | msg_set_size(msg, BASIC_H_SIZE + dsz); |
| 1352 | if (skb_cow(buf, BASIC_H_SIZE)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1353 | return -ENOMEM; |
| 1354 | |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 1355 | skb_push(buf, BASIC_H_SIZE); |
| 1356 | skb_copy_to_linear_data(buf, msg, BASIC_H_SIZE); |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1357 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1358 | if (dest->node == tipc_own_addr) |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1359 | res = tipc_port_recv_msg(buf); |
| 1360 | else |
| 1361 | res = tipc_send_buf_fast(buf, dest->node); |
| 1362 | if (likely(res != -ELINKCONG)) { |
| 1363 | if (res > 0) |
| 1364 | p_ptr->sent++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1365 | return res; |
Allan Stephens | cb7ce91 | 2011-01-24 15:02:14 -0500 | [diff] [blame] | 1366 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1367 | if (port_unreliable(p_ptr)) |
| 1368 | return dsz; |
| 1369 | return -ELINKCONG; |
| 1370 | } |
| 1371 | |