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