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 | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, 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" |
| 39 | #include "dbg.h" |
| 40 | #include "port.h" |
| 41 | #include "addr.h" |
| 42 | #include "link.h" |
| 43 | #include "node.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 44 | #include "name_table.h" |
| 45 | #include "user_reg.h" |
| 46 | #include "msg.h" |
| 47 | #include "bcast.h" |
| 48 | |
| 49 | /* Connection management: */ |
| 50 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ |
| 51 | #define CONFIRMED 0 |
| 52 | #define PROBING 1 |
| 53 | |
| 54 | #define MAX_REJECT_SIZE 1024 |
| 55 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 56 | static struct sk_buff *msg_queue_head = NULL; |
| 57 | static struct sk_buff *msg_queue_tail = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 58 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 59 | DEFINE_SPINLOCK(tipc_port_list_lock); |
| 60 | static DEFINE_SPINLOCK(queue_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 61 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 62 | static LIST_HEAD(ports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 63 | static void port_handle_node_down(unsigned long ref); |
| 64 | static struct sk_buff* port_build_self_abort_msg(struct port *,u32 err); |
| 65 | static struct sk_buff* port_build_peer_abort_msg(struct port *,u32 err); |
| 66 | static void port_timeout(unsigned long ref); |
| 67 | |
| 68 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 69 | static u32 port_peernode(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 70 | { |
| 71 | return msg_destnode(&p_ptr->publ.phdr); |
| 72 | } |
| 73 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 74 | static u32 port_peerport(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 75 | { |
| 76 | return msg_destport(&p_ptr->publ.phdr); |
| 77 | } |
| 78 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 79 | static u32 port_out_seqno(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 80 | { |
| 81 | return msg_transp_seqno(&p_ptr->publ.phdr); |
| 82 | } |
| 83 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 84 | static void port_incr_out_seqno(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 85 | { |
| 86 | struct tipc_msg *m = &p_ptr->publ.phdr; |
| 87 | |
| 88 | if (likely(!msg_routed(m))) |
| 89 | return; |
| 90 | msg_set_transp_seqno(m, (msg_transp_seqno(m) + 1)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * tipc_multicast - send a multicast message to local and remote destinations |
| 95 | */ |
| 96 | |
| 97 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, |
| 98 | u32 num_sect, struct iovec const *msg_sect) |
| 99 | { |
| 100 | struct tipc_msg *hdr; |
| 101 | struct sk_buff *buf; |
| 102 | struct sk_buff *ibuf = NULL; |
| 103 | struct port_list dports = {0, NULL, }; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 104 | struct port *oport = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 105 | int ext_targets; |
| 106 | int res; |
| 107 | |
| 108 | if (unlikely(!oport)) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | /* Create multicast message */ |
| 112 | |
| 113 | hdr = &oport->publ.phdr; |
| 114 | msg_set_type(hdr, TIPC_MCAST_MSG); |
| 115 | msg_set_nametype(hdr, seq->type); |
| 116 | msg_set_namelower(hdr, seq->lower); |
| 117 | msg_set_nameupper(hdr, seq->upper); |
| 118 | msg_set_hdr_sz(hdr, MCAST_H_SIZE); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 119 | res = tipc_msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 120 | !oport->user_port, &buf); |
| 121 | if (unlikely(!buf)) |
| 122 | return res; |
| 123 | |
| 124 | /* Figure out where to send multicast message */ |
| 125 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 126 | ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper, |
| 127 | TIPC_NODE_SCOPE, &dports); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 128 | |
| 129 | /* Send message to destinations (duplicate it only if necessary) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 130 | |
| 131 | if (ext_targets) { |
| 132 | if (dports.count != 0) { |
| 133 | ibuf = skb_copy(buf, GFP_ATOMIC); |
| 134 | if (ibuf == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 135 | tipc_port_list_free(&dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | buf_discard(buf); |
| 137 | return -ENOMEM; |
| 138 | } |
| 139 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 140 | res = tipc_bclink_send_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 141 | if ((res < 0) && (dports.count != 0)) { |
| 142 | buf_discard(ibuf); |
| 143 | } |
| 144 | } else { |
| 145 | ibuf = buf; |
| 146 | } |
| 147 | |
| 148 | if (res >= 0) { |
| 149 | if (ibuf) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 150 | tipc_port_recv_mcast(ibuf, &dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 151 | } else { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 152 | tipc_port_list_free(&dports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 153 | } |
| 154 | return res; |
| 155 | } |
| 156 | |
| 157 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 158 | * tipc_port_recv_mcast - deliver multicast message to all destination ports |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 159 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | * If there is no port list, perform a lookup to create one |
| 161 | */ |
| 162 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 163 | 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] | 164 | { |
| 165 | struct tipc_msg* msg; |
| 166 | struct port_list dports = {0, NULL, }; |
| 167 | struct port_list *item = dp; |
| 168 | int cnt = 0; |
| 169 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 170 | msg = buf_msg(buf); |
| 171 | |
| 172 | /* Create destination port list, if one wasn't supplied */ |
| 173 | |
| 174 | if (dp == NULL) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 175 | tipc_nametbl_mc_translate(msg_nametype(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 176 | msg_namelower(msg), |
| 177 | msg_nameupper(msg), |
| 178 | TIPC_CLUSTER_SCOPE, |
| 179 | &dports); |
| 180 | item = dp = &dports; |
| 181 | } |
| 182 | |
| 183 | /* Deliver a copy of message to each destination port */ |
| 184 | |
| 185 | if (dp->count != 0) { |
| 186 | if (dp->count == 1) { |
| 187 | msg_set_destport(msg, dp->ports[0]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 188 | tipc_port_recv_msg(buf); |
| 189 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | for (; cnt < dp->count; cnt++) { |
| 193 | int index = cnt % PLSIZE; |
| 194 | struct sk_buff *b = skb_clone(buf, GFP_ATOMIC); |
| 195 | |
| 196 | if (b == NULL) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 197 | warn("Unable to deliver multicast message(s)\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 198 | msg_dbg(msg, "LOST:"); |
| 199 | goto exit; |
| 200 | } |
| 201 | if ((index == 0) && (cnt != 0)) { |
| 202 | item = item->next; |
| 203 | } |
| 204 | msg_set_destport(buf_msg(b),item->ports[index]); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 205 | tipc_port_recv_msg(b); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | exit: |
| 209 | buf_discard(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 210 | tipc_port_list_free(dp); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
Allan Stephens | 7ef43eb | 2008-05-12 15:42:28 -0700 | [diff] [blame] | 214 | * tipc_createport_raw - create a generic TIPC port |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 215 | * |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 216 | * 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] | 217 | */ |
| 218 | |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 219 | struct tipc_port *tipc_createport_raw(void *usr_handle, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 220 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *), |
| 221 | void (*wakeup)(struct tipc_port *), |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 222 | const u32 importance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 223 | { |
| 224 | struct port *p_ptr; |
| 225 | struct tipc_msg *msg; |
| 226 | u32 ref; |
| 227 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 228 | p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 229 | if (!p_ptr) { |
| 230 | warn("Port creation failed, no memory\n"); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 231 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 232 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 233 | ref = tipc_ref_acquire(p_ptr, &p_ptr->publ.lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 234 | if (!ref) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 235 | warn("Port creation failed, reference table exhausted\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 236 | kfree(p_ptr); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 237 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 240 | p_ptr->publ.usr_handle = usr_handle; |
| 241 | p_ptr->publ.max_pkt = MAX_PKT_DEFAULT; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 242 | p_ptr->publ.ref = ref; |
| 243 | msg = &p_ptr->publ.phdr; |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 244 | tipc_msg_init(msg, importance, TIPC_NAMED_MSG, LONG_H_SIZE, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 245 | msg_set_origport(msg, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | p_ptr->last_in_seqno = 41; |
| 247 | p_ptr->sent = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 248 | INIT_LIST_HEAD(&p_ptr->wait_list); |
| 249 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 250 | p_ptr->dispatcher = dispatcher; |
| 251 | p_ptr->wakeup = wakeup; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 252 | p_ptr->user_port = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 253 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 254 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 255 | INIT_LIST_HEAD(&p_ptr->publications); |
| 256 | INIT_LIST_HEAD(&p_ptr->port_list); |
| 257 | list_add_tail(&p_ptr->port_list, &ports); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 258 | spin_unlock_bh(&tipc_port_list_lock); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 259 | return &(p_ptr->publ); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | int tipc_deleteport(u32 ref) |
| 263 | { |
| 264 | struct port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 265 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 266 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 267 | tipc_withdraw(ref, 0, NULL); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 268 | p_ptr = tipc_port_lock(ref); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 269 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 270 | return -EINVAL; |
| 271 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 272 | tipc_ref_discard(ref); |
| 273 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 274 | |
| 275 | k_cancel_timer(&p_ptr->timer); |
| 276 | if (p_ptr->publ.connected) { |
| 277 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 278 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 279 | } |
| 280 | if (p_ptr->user_port) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 281 | tipc_reg_remove_port(p_ptr->user_port); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 282 | kfree(p_ptr->user_port); |
| 283 | } |
| 284 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 285 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 286 | list_del(&p_ptr->port_list); |
| 287 | list_del(&p_ptr->wait_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 288 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 289 | k_term_timer(&p_ptr->timer); |
| 290 | kfree(p_ptr); |
| 291 | dbg("Deleted port %u\n", ref); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 292 | tipc_net_route_msg(buf); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 293 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /** |
| 297 | * tipc_get_port() - return port associated with 'ref' |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 298 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 299 | * Note: Port is not locked. |
| 300 | */ |
| 301 | |
| 302 | struct tipc_port *tipc_get_port(const u32 ref) |
| 303 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 304 | return (struct tipc_port *)tipc_ref_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /** |
| 308 | * tipc_get_handle - return user handle associated to port 'ref' |
| 309 | */ |
| 310 | |
| 311 | void *tipc_get_handle(const u32 ref) |
| 312 | { |
| 313 | struct port *p_ptr; |
| 314 | void * handle; |
| 315 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 316 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 317 | if (!p_ptr) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 318 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 319 | handle = p_ptr->publ.usr_handle; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 320 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 321 | return handle; |
| 322 | } |
| 323 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 324 | static int port_unreliable(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 325 | { |
| 326 | return msg_src_droppable(&p_ptr->publ.phdr); |
| 327 | } |
| 328 | |
| 329 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) |
| 330 | { |
| 331 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 332 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 333 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 334 | if (!p_ptr) |
| 335 | return -EINVAL; |
| 336 | *isunreliable = port_unreliable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 337 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 338 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) |
| 342 | { |
| 343 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 344 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 345 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | if (!p_ptr) |
| 347 | return -EINVAL; |
| 348 | msg_set_src_droppable(&p_ptr->publ.phdr, (isunreliable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 349 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 350 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 353 | static int port_unreturnable(struct port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 354 | { |
| 355 | return msg_dest_droppable(&p_ptr->publ.phdr); |
| 356 | } |
| 357 | |
| 358 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) |
| 359 | { |
| 360 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 361 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 362 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 363 | if (!p_ptr) |
| 364 | return -EINVAL; |
| 365 | *isunrejectable = port_unreturnable(p_ptr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 366 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 367 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) |
| 371 | { |
| 372 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 373 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 374 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 375 | if (!p_ptr) |
| 376 | return -EINVAL; |
| 377 | msg_set_dest_droppable(&p_ptr->publ.phdr, (isunrejectable != 0)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 378 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 379 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 380 | } |
| 381 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 382 | /* |
| 383 | * port_build_proto_msg(): build a port level protocol |
| 384 | * or a connection abortion message. Called with |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 385 | * tipc_port lock on. |
| 386 | */ |
| 387 | static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, |
| 388 | u32 origport, u32 orignode, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 389 | u32 usr, u32 type, u32 err, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 390 | u32 seqno, u32 ack) |
| 391 | { |
| 392 | struct sk_buff *buf; |
| 393 | struct tipc_msg *msg; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 394 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 395 | buf = buf_acquire(LONG_H_SIZE); |
| 396 | if (buf) { |
| 397 | msg = buf_msg(buf); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 398 | tipc_msg_init(msg, usr, type, LONG_H_SIZE, destnode); |
Allan Stephens | 7571521 | 2008-06-04 17:37:34 -0700 | [diff] [blame] | 399 | msg_set_errcode(msg, err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 400 | msg_set_destport(msg, destport); |
| 401 | msg_set_origport(msg, origport); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 402 | msg_set_orignode(msg, orignode); |
| 403 | msg_set_transp_seqno(msg, seqno); |
| 404 | msg_set_msgcnt(msg, ack); |
| 405 | msg_dbg(msg, "PORT>SEND>:"); |
| 406 | } |
| 407 | return buf; |
| 408 | } |
| 409 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 410 | int tipc_reject_msg(struct sk_buff *buf, u32 err) |
| 411 | { |
| 412 | struct tipc_msg *msg = buf_msg(buf); |
| 413 | struct sk_buff *rbuf; |
| 414 | struct tipc_msg *rmsg; |
| 415 | int hdr_sz; |
| 416 | u32 imp = msg_importance(msg); |
| 417 | u32 data_sz = msg_data_sz(msg); |
| 418 | |
| 419 | if (data_sz > MAX_REJECT_SIZE) |
| 420 | data_sz = MAX_REJECT_SIZE; |
| 421 | if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) |
| 422 | imp++; |
| 423 | msg_dbg(msg, "port->rej: "); |
| 424 | |
| 425 | /* discard rejected message if it shouldn't be returned to sender */ |
| 426 | if (msg_errcode(msg) || msg_dest_droppable(msg)) { |
| 427 | buf_discard(buf); |
| 428 | return data_sz; |
| 429 | } |
| 430 | |
| 431 | /* construct rejected message */ |
| 432 | if (msg_mcast(msg)) |
| 433 | hdr_sz = MCAST_H_SIZE; |
| 434 | else |
| 435 | hdr_sz = LONG_H_SIZE; |
| 436 | rbuf = buf_acquire(data_sz + hdr_sz); |
| 437 | if (rbuf == NULL) { |
| 438 | buf_discard(buf); |
| 439 | return data_sz; |
| 440 | } |
| 441 | rmsg = buf_msg(rbuf); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 442 | 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] | 443 | msg_set_errcode(rmsg, err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 444 | msg_set_destport(rmsg, msg_origport(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 445 | msg_set_origport(rmsg, msg_destport(msg)); |
Allan Stephens | 99c1459 | 2008-06-04 17:48:25 -0700 | [diff] [blame] | 446 | if (msg_short(msg)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 447 | msg_set_orignode(rmsg, tipc_own_addr); |
Allan Stephens | 99c1459 | 2008-06-04 17:48:25 -0700 | [diff] [blame] | 448 | /* leave name type & instance as zeroes */ |
| 449 | } else { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 450 | msg_set_orignode(rmsg, msg_destnode(msg)); |
Allan Stephens | 99c1459 | 2008-06-04 17:48:25 -0700 | [diff] [blame] | 451 | msg_set_nametype(rmsg, msg_nametype(msg)); |
| 452 | msg_set_nameinst(rmsg, msg_nameinst(msg)); |
| 453 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 454 | msg_set_size(rmsg, data_sz + hdr_sz); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 455 | 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] | 456 | |
| 457 | /* send self-abort message when rejecting on a connected port */ |
| 458 | if (msg_connected(msg)) { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 459 | struct sk_buff *abuf = NULL; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 460 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 461 | |
| 462 | if (p_ptr) { |
| 463 | if (p_ptr->publ.connected) |
| 464 | abuf = port_build_self_abort_msg(p_ptr, err); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 465 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 466 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 467 | tipc_net_route_msg(abuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* send rejected message */ |
| 471 | buf_discard(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 472 | tipc_net_route_msg(rbuf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 473 | return data_sz; |
| 474 | } |
| 475 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 476 | int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr, |
| 477 | struct iovec const *msg_sect, u32 num_sect, |
| 478 | int err) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 479 | { |
| 480 | struct sk_buff *buf; |
| 481 | int res; |
| 482 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 483 | res = tipc_msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 484 | !p_ptr->user_port, &buf); |
| 485 | if (!buf) |
| 486 | return res; |
| 487 | |
| 488 | return tipc_reject_msg(buf, err); |
| 489 | } |
| 490 | |
| 491 | static void port_timeout(unsigned long ref) |
| 492 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 493 | struct port *p_ptr = tipc_port_lock(ref); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 494 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 495 | |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 496 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 497 | return; |
| 498 | |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 499 | if (!p_ptr->publ.connected) { |
| 500 | tipc_port_unlock(p_ptr); |
| 501 | return; |
| 502 | } |
| 503 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 504 | /* Last probe answered ? */ |
| 505 | if (p_ptr->probing_state == PROBING) { |
| 506 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
| 507 | } else { |
| 508 | buf = port_build_proto_msg(port_peerport(p_ptr), |
| 509 | port_peernode(p_ptr), |
| 510 | p_ptr->publ.ref, |
| 511 | tipc_own_addr, |
| 512 | CONN_MANAGER, |
| 513 | CONN_PROBE, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 514 | TIPC_OK, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | port_out_seqno(p_ptr), |
| 516 | 0); |
| 517 | port_incr_out_seqno(p_ptr); |
| 518 | p_ptr->probing_state = PROBING; |
| 519 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 520 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 521 | tipc_port_unlock(p_ptr); |
| 522 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | |
| 526 | static void port_handle_node_down(unsigned long ref) |
| 527 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 528 | struct port *p_ptr = tipc_port_lock(ref); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 529 | struct sk_buff* buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 530 | |
| 531 | if (!p_ptr) |
| 532 | return; |
| 533 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 534 | tipc_port_unlock(p_ptr); |
| 535 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
| 539 | static struct sk_buff *port_build_self_abort_msg(struct port *p_ptr, u32 err) |
| 540 | { |
| 541 | u32 imp = msg_importance(&p_ptr->publ.phdr); |
| 542 | |
| 543 | if (!p_ptr->publ.connected) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 544 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 545 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 546 | imp++; |
| 547 | return port_build_proto_msg(p_ptr->publ.ref, |
| 548 | tipc_own_addr, |
| 549 | port_peerport(p_ptr), |
| 550 | port_peernode(p_ptr), |
| 551 | imp, |
| 552 | TIPC_CONN_MSG, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 553 | err, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 554 | p_ptr->last_in_seqno + 1, |
| 555 | 0); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | static struct sk_buff *port_build_peer_abort_msg(struct port *p_ptr, u32 err) |
| 560 | { |
| 561 | u32 imp = msg_importance(&p_ptr->publ.phdr); |
| 562 | |
| 563 | if (!p_ptr->publ.connected) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 564 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 565 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 566 | imp++; |
| 567 | return port_build_proto_msg(port_peerport(p_ptr), |
| 568 | port_peernode(p_ptr), |
| 569 | p_ptr->publ.ref, |
| 570 | tipc_own_addr, |
| 571 | imp, |
| 572 | TIPC_CONN_MSG, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 573 | err, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 574 | port_out_seqno(p_ptr), |
| 575 | 0); |
| 576 | } |
| 577 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 578 | void tipc_port_recv_proto_msg(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 579 | { |
| 580 | struct tipc_msg *msg = buf_msg(buf); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 581 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 582 | u32 err = TIPC_OK; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 583 | struct sk_buff *r_buf = NULL; |
| 584 | struct sk_buff *abort_buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 585 | |
| 586 | msg_dbg(msg, "PORT<RECV<:"); |
| 587 | |
| 588 | if (!p_ptr) { |
| 589 | err = TIPC_ERR_NO_PORT; |
| 590 | } else if (p_ptr->publ.connected) { |
Allan Stephens | 96d841b | 2010-08-17 11:00:11 +0000 | [diff] [blame] | 591 | if ((port_peernode(p_ptr) != msg_orignode(msg)) || |
| 592 | (port_peerport(p_ptr) != msg_origport(msg))) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 593 | err = TIPC_ERR_NO_PORT; |
Allan Stephens | 96d841b | 2010-08-17 11:00:11 +0000 | [diff] [blame] | 594 | } else if (msg_type(msg) == CONN_ACK) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 595 | int wakeup = tipc_port_congested(p_ptr) && |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 596 | p_ptr->publ.congested && |
| 597 | p_ptr->wakeup; |
| 598 | p_ptr->acked += msg_msgcnt(msg); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 599 | if (tipc_port_congested(p_ptr)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 600 | goto exit; |
| 601 | p_ptr->publ.congested = 0; |
| 602 | if (!wakeup) |
| 603 | goto exit; |
| 604 | p_ptr->wakeup(&p_ptr->publ); |
| 605 | goto exit; |
| 606 | } |
| 607 | } else if (p_ptr->publ.published) { |
| 608 | err = TIPC_ERR_NO_PORT; |
| 609 | } |
| 610 | if (err) { |
| 611 | r_buf = port_build_proto_msg(msg_origport(msg), |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 612 | msg_orignode(msg), |
| 613 | msg_destport(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 614 | tipc_own_addr, |
Allan Stephens | 06d82c9 | 2008-03-06 15:06:55 -0800 | [diff] [blame] | 615 | TIPC_HIGH_IMPORTANCE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 616 | TIPC_CONN_MSG, |
| 617 | err, |
| 618 | 0, |
| 619 | 0); |
| 620 | goto exit; |
| 621 | } |
| 622 | |
| 623 | /* All is fine */ |
| 624 | if (msg_type(msg) == CONN_PROBE) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 625 | r_buf = port_build_proto_msg(msg_origport(msg), |
| 626 | msg_orignode(msg), |
| 627 | msg_destport(msg), |
| 628 | tipc_own_addr, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 629 | CONN_MANAGER, |
| 630 | CONN_PROBE_REPLY, |
| 631 | TIPC_OK, |
| 632 | port_out_seqno(p_ptr), |
| 633 | 0); |
| 634 | } |
| 635 | p_ptr->probing_state = CONFIRMED; |
| 636 | port_incr_out_seqno(p_ptr); |
| 637 | exit: |
| 638 | if (p_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 639 | tipc_port_unlock(p_ptr); |
| 640 | tipc_net_route_msg(r_buf); |
| 641 | tipc_net_route_msg(abort_buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 642 | buf_discard(buf); |
| 643 | } |
| 644 | |
| 645 | static void port_print(struct port *p_ptr, struct print_buf *buf, int full_id) |
| 646 | { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 647 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 648 | |
| 649 | if (full_id) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 650 | tipc_printf(buf, "<%u.%u.%u:%u>:", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 651 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 652 | tipc_node(tipc_own_addr), p_ptr->publ.ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 653 | else |
| 654 | tipc_printf(buf, "%-10u:", p_ptr->publ.ref); |
| 655 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 656 | if (p_ptr->publ.connected) { |
| 657 | u32 dport = port_peerport(p_ptr); |
| 658 | u32 destnode = port_peernode(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 659 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 660 | tipc_printf(buf, " connected to <%u.%u.%u:%u>", |
| 661 | tipc_zone(destnode), tipc_cluster(destnode), |
| 662 | tipc_node(destnode), dport); |
| 663 | if (p_ptr->publ.conn_type != 0) |
| 664 | tipc_printf(buf, " via {%u,%u}", |
| 665 | p_ptr->publ.conn_type, |
| 666 | p_ptr->publ.conn_instance); |
| 667 | } |
| 668 | else if (p_ptr->publ.published) { |
| 669 | tipc_printf(buf, " bound to"); |
| 670 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 671 | if (publ->lower == publ->upper) |
| 672 | tipc_printf(buf, " {%u,%u}", publ->type, |
| 673 | publ->lower); |
| 674 | else |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 675 | tipc_printf(buf, " {%u,%u,%u}", publ->type, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 676 | publ->lower, publ->upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | tipc_printf(buf, "\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | #define MAX_PORT_QUERY 32768 |
| 683 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 684 | struct sk_buff *tipc_port_get_ports(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 685 | { |
| 686 | struct sk_buff *buf; |
| 687 | struct tlv_desc *rep_tlv; |
| 688 | struct print_buf pb; |
| 689 | struct port *p_ptr; |
| 690 | int str_len; |
| 691 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 692 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 693 | if (!buf) |
| 694 | return NULL; |
| 695 | rep_tlv = (struct tlv_desc *)buf->data; |
| 696 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 697 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY); |
| 698 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 699 | list_for_each_entry(p_ptr, &ports, port_list) { |
| 700 | spin_lock_bh(p_ptr->publ.lock); |
| 701 | port_print(p_ptr, &pb, 0); |
| 702 | spin_unlock_bh(p_ptr->publ.lock); |
| 703 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 704 | spin_unlock_bh(&tipc_port_list_lock); |
| 705 | str_len = tipc_printbuf_validate(&pb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 706 | |
| 707 | skb_put(buf, TLV_SPACE(str_len)); |
| 708 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 709 | |
| 710 | return buf; |
| 711 | } |
| 712 | |
| 713 | #if 0 |
| 714 | |
| 715 | #define MAX_PORT_STATS 2000 |
| 716 | |
| 717 | struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space) |
| 718 | { |
| 719 | u32 ref; |
| 720 | struct port *p_ptr; |
| 721 | struct sk_buff *buf; |
| 722 | struct tlv_desc *rep_tlv; |
| 723 | struct print_buf pb; |
| 724 | int str_len; |
| 725 | |
| 726 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_PORT_REF)) |
| 727 | return cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| 728 | |
| 729 | ref = *(u32 *)TLV_DATA(req_tlv_area); |
| 730 | ref = ntohl(ref); |
| 731 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 732 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 733 | if (!p_ptr) |
| 734 | return cfg_reply_error_string("port not found"); |
| 735 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 736 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_STATS)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 737 | if (!buf) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 738 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 739 | return NULL; |
| 740 | } |
| 741 | rep_tlv = (struct tlv_desc *)buf->data; |
| 742 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 743 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_STATS); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 744 | port_print(p_ptr, &pb, 1); |
| 745 | /* NEED TO FILL IN ADDITIONAL PORT STATISTICS HERE */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 746 | tipc_port_unlock(p_ptr); |
| 747 | str_len = tipc_printbuf_validate(&pb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 748 | |
| 749 | skb_put(buf, TLV_SPACE(str_len)); |
| 750 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 751 | |
| 752 | return buf; |
| 753 | } |
| 754 | |
| 755 | #endif |
| 756 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 757 | void tipc_port_reinit(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 758 | { |
| 759 | struct port *p_ptr; |
| 760 | struct tipc_msg *msg; |
| 761 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 762 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 763 | list_for_each_entry(p_ptr, &ports, port_list) { |
| 764 | msg = &p_ptr->publ.phdr; |
| 765 | if (msg_orignode(msg) == tipc_own_addr) |
| 766 | break; |
Allan Stephens | 6d4a667 | 2008-05-21 14:54:12 -0700 | [diff] [blame] | 767 | msg_set_prevnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 768 | msg_set_orignode(msg, tipc_own_addr); |
| 769 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 770 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | |
| 774 | /* |
| 775 | * port_dispatcher_sigh(): Signal handler for messages destinated |
| 776 | * to the tipc_port interface. |
| 777 | */ |
| 778 | |
| 779 | static void port_dispatcher_sigh(void *dummy) |
| 780 | { |
| 781 | struct sk_buff *buf; |
| 782 | |
| 783 | spin_lock_bh(&queue_lock); |
| 784 | buf = msg_queue_head; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 785 | msg_queue_head = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 786 | spin_unlock_bh(&queue_lock); |
| 787 | |
| 788 | while (buf) { |
| 789 | struct port *p_ptr; |
| 790 | struct user_port *up_ptr; |
| 791 | struct tipc_portid orig; |
| 792 | struct tipc_name_seq dseq; |
| 793 | void *usr_handle; |
| 794 | int connected; |
| 795 | int published; |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 796 | u32 message_type; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 797 | |
| 798 | struct sk_buff *next = buf->next; |
| 799 | struct tipc_msg *msg = buf_msg(buf); |
| 800 | u32 dref = msg_destport(msg); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 801 | |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 802 | message_type = msg_type(msg); |
| 803 | if (message_type > TIPC_DIRECT_MSG) |
| 804 | goto reject; /* Unsupported message type */ |
| 805 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 806 | p_ptr = tipc_port_lock(dref); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 807 | if (!p_ptr) |
| 808 | goto reject; /* Port deleted while msg in queue */ |
| 809 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 810 | orig.ref = msg_origport(msg); |
| 811 | orig.node = msg_orignode(msg); |
| 812 | up_ptr = p_ptr->user_port; |
| 813 | usr_handle = up_ptr->usr_handle; |
| 814 | connected = p_ptr->publ.connected; |
| 815 | published = p_ptr->publ.published; |
| 816 | |
| 817 | if (unlikely(msg_errcode(msg))) |
| 818 | goto err; |
| 819 | |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 820 | switch (message_type) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 821 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 822 | case TIPC_CONN_MSG:{ |
| 823 | tipc_conn_msg_event cb = up_ptr->conn_msg_cb; |
| 824 | u32 peer_port = port_peerport(p_ptr); |
| 825 | u32 peer_node = port_peernode(p_ptr); |
| 826 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 827 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 828 | if (unlikely(!cb)) |
| 829 | goto reject; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 830 | if (unlikely(!connected)) { |
Allan Stephens | 84b07c1 | 2008-06-04 17:28:21 -0700 | [diff] [blame] | 831 | if (tipc_connect2port(dref, &orig)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 832 | goto reject; |
Allan Stephens | 84b07c1 | 2008-06-04 17:28:21 -0700 | [diff] [blame] | 833 | } else if ((msg_origport(msg) != peer_port) || |
| 834 | (msg_orignode(msg) != peer_node)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 835 | goto reject; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 836 | if (unlikely(++p_ptr->publ.conn_unacked >= |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 837 | TIPC_FLOW_CONTROL_WIN)) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 838 | tipc_acknowledge(dref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 839 | p_ptr->publ.conn_unacked); |
| 840 | skb_pull(buf, msg_hdr_sz(msg)); |
| 841 | cb(usr_handle, dref, &buf, msg_data(msg), |
| 842 | msg_data_sz(msg)); |
| 843 | break; |
| 844 | } |
| 845 | case TIPC_DIRECT_MSG:{ |
| 846 | tipc_msg_event cb = up_ptr->msg_cb; |
| 847 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 848 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 849 | if (unlikely(!cb || connected)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 850 | goto reject; |
| 851 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 852 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 853 | msg_data_sz(msg), msg_importance(msg), |
| 854 | &orig); |
| 855 | break; |
| 856 | } |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 857 | case TIPC_MCAST_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 858 | case TIPC_NAMED_MSG:{ |
| 859 | tipc_named_msg_event cb = up_ptr->named_msg_cb; |
| 860 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 861 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 862 | if (unlikely(!cb || connected || !published)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 863 | goto reject; |
| 864 | dseq.type = msg_nametype(msg); |
| 865 | dseq.lower = msg_nameinst(msg); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 866 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
| 867 | ? dseq.lower : msg_nameupper(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 868 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 869 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 870 | msg_data_sz(msg), msg_importance(msg), |
| 871 | &orig, &dseq); |
| 872 | break; |
| 873 | } |
| 874 | } |
| 875 | if (buf) |
| 876 | buf_discard(buf); |
| 877 | buf = next; |
| 878 | continue; |
| 879 | err: |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 880 | switch (message_type) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 881 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 882 | case TIPC_CONN_MSG:{ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 883 | tipc_conn_shutdown_event cb = |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 884 | up_ptr->conn_err_cb; |
| 885 | u32 peer_port = port_peerport(p_ptr); |
| 886 | u32 peer_node = port_peernode(p_ptr); |
| 887 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 888 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 889 | if (!cb || !connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 890 | break; |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 891 | if ((msg_origport(msg) != peer_port) || |
| 892 | (msg_orignode(msg) != peer_node)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 893 | break; |
| 894 | tipc_disconnect(dref); |
| 895 | skb_pull(buf, msg_hdr_sz(msg)); |
| 896 | cb(usr_handle, dref, &buf, msg_data(msg), |
| 897 | msg_data_sz(msg), msg_errcode(msg)); |
| 898 | break; |
| 899 | } |
| 900 | case TIPC_DIRECT_MSG:{ |
| 901 | tipc_msg_err_event cb = up_ptr->err_cb; |
| 902 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 903 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 904 | if (!cb || connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 905 | break; |
| 906 | skb_pull(buf, msg_hdr_sz(msg)); |
| 907 | cb(usr_handle, dref, &buf, msg_data(msg), |
| 908 | msg_data_sz(msg), msg_errcode(msg), &orig); |
| 909 | break; |
| 910 | } |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 911 | case TIPC_MCAST_MSG: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 912 | case TIPC_NAMED_MSG:{ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 913 | tipc_named_msg_err_event cb = |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 914 | up_ptr->named_err_cb; |
| 915 | |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 916 | tipc_port_unlock(p_ptr); |
Allan Stephens | 5307e46 | 2008-06-04 17:28:45 -0700 | [diff] [blame] | 917 | if (!cb || connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 918 | break; |
| 919 | dseq.type = msg_nametype(msg); |
| 920 | dseq.lower = msg_nameinst(msg); |
Allan Stephens | 9688243 | 2006-06-25 23:38:58 -0700 | [diff] [blame] | 921 | dseq.upper = (message_type == TIPC_NAMED_MSG) |
| 922 | ? dseq.lower : msg_nameupper(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 923 | skb_pull(buf, msg_hdr_sz(msg)); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 924 | cb(usr_handle, dref, &buf, msg_data(msg), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 925 | msg_data_sz(msg), msg_errcode(msg), &dseq); |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | if (buf) |
| 930 | buf_discard(buf); |
| 931 | buf = next; |
| 932 | continue; |
| 933 | reject: |
| 934 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); |
| 935 | buf = next; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * port_dispatcher(): Dispatcher for messages destinated |
| 941 | * to the tipc_port interface. Called with port locked. |
| 942 | */ |
| 943 | |
| 944 | static u32 port_dispatcher(struct tipc_port *dummy, struct sk_buff *buf) |
| 945 | { |
| 946 | buf->next = NULL; |
| 947 | spin_lock_bh(&queue_lock); |
| 948 | if (msg_queue_head) { |
| 949 | msg_queue_tail->next = buf; |
| 950 | msg_queue_tail = buf; |
| 951 | } else { |
| 952 | msg_queue_tail = msg_queue_head = buf; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 953 | tipc_k_signal((Handler)port_dispatcher_sigh, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 954 | } |
| 955 | spin_unlock_bh(&queue_lock); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 956 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 957 | } |
| 958 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 959 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 960 | * Wake up port after congestion: Called with port locked, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 961 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 962 | */ |
| 963 | |
| 964 | static void port_wakeup_sh(unsigned long ref) |
| 965 | { |
| 966 | struct port *p_ptr; |
| 967 | struct user_port *up_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 968 | tipc_continue_event cb = NULL; |
| 969 | void *uh = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 970 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 971 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 972 | if (p_ptr) { |
| 973 | up_ptr = p_ptr->user_port; |
| 974 | if (up_ptr) { |
| 975 | cb = up_ptr->continue_event_cb; |
| 976 | uh = up_ptr->usr_handle; |
| 977 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 978 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 979 | } |
| 980 | if (cb) |
| 981 | cb(uh, ref); |
| 982 | } |
| 983 | |
| 984 | |
| 985 | static void port_wakeup(struct tipc_port *p_ptr) |
| 986 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 987 | tipc_k_signal((Handler)port_wakeup_sh, p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | void tipc_acknowledge(u32 ref, u32 ack) |
| 991 | { |
| 992 | struct port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 993 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 994 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 995 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 996 | if (!p_ptr) |
| 997 | return; |
| 998 | if (p_ptr->publ.connected) { |
| 999 | p_ptr->publ.conn_unacked -= ack; |
| 1000 | buf = port_build_proto_msg(port_peerport(p_ptr), |
| 1001 | port_peernode(p_ptr), |
| 1002 | ref, |
| 1003 | tipc_own_addr, |
| 1004 | CONN_MANAGER, |
| 1005 | CONN_ACK, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1006 | TIPC_OK, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1007 | port_out_seqno(p_ptr), |
| 1008 | ack); |
| 1009 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1010 | tipc_port_unlock(p_ptr); |
| 1011 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * tipc_createport(): user level call. Will add port to |
| 1016 | * registry if non-zero user_ref. |
| 1017 | */ |
| 1018 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1019 | int tipc_createport(u32 user_ref, |
| 1020 | void *usr_handle, |
| 1021 | unsigned int importance, |
| 1022 | tipc_msg_err_event error_cb, |
| 1023 | tipc_named_msg_err_event named_error_cb, |
| 1024 | tipc_conn_shutdown_event conn_error_cb, |
| 1025 | tipc_msg_event msg_cb, |
| 1026 | tipc_named_msg_event named_msg_cb, |
| 1027 | tipc_conn_msg_event conn_msg_cb, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1028 | tipc_continue_event continue_event_cb,/* May be zero */ |
| 1029 | u32 *portref) |
| 1030 | { |
| 1031 | struct user_port *up_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1032 | struct port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1033 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 1034 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 1035 | if (!up_ptr) { |
Allan Stephens | a75bf87 | 2006-06-25 23:50:01 -0700 | [diff] [blame] | 1036 | warn("Port creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1037 | return -ENOMEM; |
| 1038 | } |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 1039 | p_ptr = (struct port *)tipc_createport_raw(NULL, port_dispatcher, |
| 1040 | port_wakeup, importance); |
| 1041 | if (!p_ptr) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1042 | kfree(up_ptr); |
| 1043 | return -ENOMEM; |
| 1044 | } |
| 1045 | |
| 1046 | p_ptr->user_port = up_ptr; |
| 1047 | up_ptr->user_ref = user_ref; |
| 1048 | up_ptr->usr_handle = usr_handle; |
| 1049 | up_ptr->ref = p_ptr->publ.ref; |
| 1050 | up_ptr->err_cb = error_cb; |
| 1051 | up_ptr->named_err_cb = named_error_cb; |
| 1052 | up_ptr->conn_err_cb = conn_error_cb; |
| 1053 | up_ptr->msg_cb = msg_cb; |
| 1054 | up_ptr->named_msg_cb = named_msg_cb; |
| 1055 | up_ptr->conn_msg_cb = conn_msg_cb; |
| 1056 | up_ptr->continue_event_cb = continue_event_cb; |
| 1057 | INIT_LIST_HEAD(&up_ptr->uport_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1058 | tipc_reg_add_port(up_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1059 | *portref = p_ptr->publ.ref; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1060 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1061 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | int tipc_ownidentity(u32 ref, struct tipc_portid *id) |
| 1065 | { |
| 1066 | id->ref = ref; |
| 1067 | id->node = tipc_own_addr; |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1068 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | int tipc_portimportance(u32 ref, unsigned int *importance) |
| 1072 | { |
| 1073 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1074 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1075 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1076 | if (!p_ptr) |
| 1077 | return -EINVAL; |
| 1078 | *importance = (unsigned int)msg_importance(&p_ptr->publ.phdr); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 1079 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1080 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | int tipc_set_portimportance(u32 ref, unsigned int imp) |
| 1084 | { |
| 1085 | struct port *p_ptr; |
| 1086 | |
| 1087 | if (imp > TIPC_CRITICAL_IMPORTANCE) |
| 1088 | return -EINVAL; |
| 1089 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1090 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1091 | if (!p_ptr) |
| 1092 | return -EINVAL; |
| 1093 | msg_set_importance(&p_ptr->publ.phdr, (u32)imp); |
Julia Lawall | 4cec72c | 2008-01-08 23:48:20 -0800 | [diff] [blame] | 1094 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1095 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 1100 | { |
| 1101 | struct port *p_ptr; |
| 1102 | struct publication *publ; |
| 1103 | u32 key; |
| 1104 | int res = -EINVAL; |
| 1105 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1106 | p_ptr = tipc_port_lock(ref); |
Adrian Bunk | d55b4c6 | 2006-10-31 16:59:35 -0800 | [diff] [blame] | 1107 | if (!p_ptr) |
| 1108 | return -EINVAL; |
| 1109 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1110 | dbg("tipc_publ %u, p_ptr = %x, conn = %x, scope = %x, " |
| 1111 | "lower = %u, upper = %u\n", |
| 1112 | ref, p_ptr, p_ptr->publ.connected, scope, seq->lower, seq->upper); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1113 | if (p_ptr->publ.connected) |
| 1114 | goto exit; |
| 1115 | if (seq->lower > seq->upper) |
| 1116 | goto exit; |
| 1117 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE)) |
| 1118 | goto exit; |
| 1119 | key = ref + p_ptr->pub_count + 1; |
| 1120 | if (key == ref) { |
| 1121 | res = -EADDRINUSE; |
| 1122 | goto exit; |
| 1123 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1124 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
| 1125 | scope, p_ptr->publ.ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1126 | if (publ) { |
| 1127 | list_add(&publ->pport_list, &p_ptr->publications); |
| 1128 | p_ptr->pub_count++; |
| 1129 | p_ptr->publ.published = 1; |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1130 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1131 | } |
| 1132 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1133 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1134 | return res; |
| 1135 | } |
| 1136 | |
| 1137 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
| 1138 | { |
| 1139 | struct port *p_ptr; |
| 1140 | struct publication *publ; |
| 1141 | struct publication *tpubl; |
| 1142 | int res = -EINVAL; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1143 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1144 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1145 | if (!p_ptr) |
| 1146 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1147 | if (!seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1148 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1149 | &p_ptr->publications, pport_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1150 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1151 | publ->ref, publ->key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1152 | } |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1153 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1154 | } else { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1155 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1156 | &p_ptr->publications, pport_list) { |
| 1157 | if (publ->scope != scope) |
| 1158 | continue; |
| 1159 | if (publ->type != seq->type) |
| 1160 | continue; |
| 1161 | if (publ->lower != seq->lower) |
| 1162 | continue; |
| 1163 | if (publ->upper != seq->upper) |
| 1164 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1165 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1166 | publ->ref, publ->key); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1167 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | if (list_empty(&p_ptr->publications)) |
| 1172 | p_ptr->publ.published = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1173 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1174 | return res; |
| 1175 | } |
| 1176 | |
| 1177 | int tipc_connect2port(u32 ref, struct tipc_portid const *peer) |
| 1178 | { |
| 1179 | struct port *p_ptr; |
| 1180 | struct tipc_msg *msg; |
| 1181 | int res = -EINVAL; |
| 1182 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1183 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1184 | if (!p_ptr) |
| 1185 | return -EINVAL; |
| 1186 | if (p_ptr->publ.published || p_ptr->publ.connected) |
| 1187 | goto exit; |
| 1188 | if (!peer->ref) |
| 1189 | goto exit; |
| 1190 | |
| 1191 | msg = &p_ptr->publ.phdr; |
| 1192 | msg_set_destnode(msg, peer->node); |
| 1193 | msg_set_destport(msg, peer->ref); |
| 1194 | msg_set_orignode(msg, tipc_own_addr); |
| 1195 | msg_set_origport(msg, p_ptr->publ.ref); |
| 1196 | msg_set_transp_seqno(msg, 42); |
| 1197 | msg_set_type(msg, TIPC_CONN_MSG); |
| 1198 | if (!may_route(peer->node)) |
| 1199 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
| 1200 | else |
| 1201 | msg_set_hdr_sz(msg, LONG_H_SIZE); |
| 1202 | |
| 1203 | p_ptr->probing_interval = PROBING_INTERVAL; |
| 1204 | p_ptr->probing_state = CONFIRMED; |
| 1205 | p_ptr->publ.connected = 1; |
| 1206 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 1207 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1208 | tipc_nodesub_subscribe(&p_ptr->subscription,peer->node, |
David S. Miller | 880b005 | 2006-01-12 13:22:32 -0800 | [diff] [blame] | 1209 | (void *)(unsigned long)ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1210 | (net_ev_handler)port_handle_node_down); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1211 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1212 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1213 | tipc_port_unlock(p_ptr); |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 1214 | p_ptr->publ.max_pkt = tipc_link_get_max_pkt(peer->node, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1215 | return res; |
| 1216 | } |
| 1217 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1218 | /** |
| 1219 | * tipc_disconnect_port - disconnect port from peer |
| 1220 | * |
| 1221 | * Port must be locked. |
| 1222 | */ |
| 1223 | |
| 1224 | int tipc_disconnect_port(struct tipc_port *tp_ptr) |
| 1225 | { |
| 1226 | int res; |
| 1227 | |
| 1228 | if (tp_ptr->connected) { |
| 1229 | tp_ptr->connected = 0; |
| 1230 | /* let timer expire on it's own to avoid deadlock! */ |
| 1231 | tipc_nodesub_unsubscribe( |
| 1232 | &((struct port *)tp_ptr)->subscription); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1233 | res = 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1234 | } else { |
| 1235 | res = -ENOTCONN; |
| 1236 | } |
| 1237 | return res; |
| 1238 | } |
| 1239 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1240 | /* |
| 1241 | * tipc_disconnect(): Disconnect port form peer. |
| 1242 | * This is a node local operation. |
| 1243 | */ |
| 1244 | |
| 1245 | int tipc_disconnect(u32 ref) |
| 1246 | { |
| 1247 | struct port *p_ptr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1248 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1249 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1250 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1251 | if (!p_ptr) |
| 1252 | return -EINVAL; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1253 | res = tipc_disconnect_port((struct tipc_port *)p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1254 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1255 | return res; |
| 1256 | } |
| 1257 | |
| 1258 | /* |
| 1259 | * tipc_shutdown(): Send a SHUTDOWN msg to peer and disconnect |
| 1260 | */ |
| 1261 | int tipc_shutdown(u32 ref) |
| 1262 | { |
| 1263 | struct port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 1264 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1265 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1266 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1267 | if (!p_ptr) |
| 1268 | return -EINVAL; |
| 1269 | |
| 1270 | if (p_ptr->publ.connected) { |
| 1271 | u32 imp = msg_importance(&p_ptr->publ.phdr); |
| 1272 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 1273 | imp++; |
| 1274 | buf = port_build_proto_msg(port_peerport(p_ptr), |
| 1275 | port_peernode(p_ptr), |
| 1276 | ref, |
| 1277 | tipc_own_addr, |
| 1278 | imp, |
| 1279 | TIPC_CONN_MSG, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1280 | TIPC_CONN_SHUTDOWN, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1281 | port_out_seqno(p_ptr), |
| 1282 | 0); |
| 1283 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1284 | tipc_port_unlock(p_ptr); |
| 1285 | tipc_net_route_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1286 | return tipc_disconnect(ref); |
| 1287 | } |
| 1288 | |
| 1289 | int tipc_isconnected(u32 ref, int *isconnected) |
| 1290 | { |
| 1291 | struct port *p_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1292 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1293 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1294 | if (!p_ptr) |
| 1295 | return -EINVAL; |
| 1296 | *isconnected = p_ptr->publ.connected; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1297 | tipc_port_unlock(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1298 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | int tipc_peer(u32 ref, struct tipc_portid *peer) |
| 1302 | { |
| 1303 | struct port *p_ptr; |
| 1304 | int res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1305 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1306 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1307 | if (!p_ptr) |
| 1308 | return -EINVAL; |
| 1309 | if (p_ptr->publ.connected) { |
| 1310 | peer->ref = port_peerport(p_ptr); |
| 1311 | peer->node = port_peernode(p_ptr); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 1312 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1313 | } else |
| 1314 | res = -ENOTCONN; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1315 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1316 | return res; |
| 1317 | } |
| 1318 | |
| 1319 | int tipc_ref_valid(u32 ref) |
| 1320 | { |
| 1321 | /* Works irrespective of type */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1322 | return !!tipc_ref_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1327 | * tipc_port_recv_sections(): Concatenate and deliver sectioned |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1328 | * message for this node. |
| 1329 | */ |
| 1330 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1331 | int tipc_port_recv_sections(struct port *sender, unsigned int num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1332 | struct iovec const *msg_sect) |
| 1333 | { |
| 1334 | struct sk_buff *buf; |
| 1335 | int res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1336 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1337 | res = tipc_msg_build(&sender->publ.phdr, msg_sect, num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1338 | MAX_MSG_SIZE, !sender->user_port, &buf); |
| 1339 | if (likely(buf)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1340 | tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1341 | return res; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * tipc_send - send message sections on connection |
| 1346 | */ |
| 1347 | |
| 1348 | int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect) |
| 1349 | { |
| 1350 | struct port *p_ptr; |
| 1351 | u32 destnode; |
| 1352 | int res; |
| 1353 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1354 | p_ptr = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1355 | if (!p_ptr || !p_ptr->publ.connected) |
| 1356 | return -EINVAL; |
| 1357 | |
| 1358 | p_ptr->publ.congested = 1; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1359 | if (!tipc_port_congested(p_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1360 | destnode = port_peernode(p_ptr); |
| 1361 | if (likely(destnode != tipc_own_addr)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1362 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
| 1363 | destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1364 | else |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1365 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1366 | |
| 1367 | if (likely(res != -ELINKCONG)) { |
| 1368 | port_incr_out_seqno(p_ptr); |
| 1369 | p_ptr->publ.congested = 0; |
| 1370 | p_ptr->sent++; |
| 1371 | return res; |
| 1372 | } |
| 1373 | } |
| 1374 | if (port_unreliable(p_ptr)) { |
| 1375 | p_ptr->publ.congested = 0; |
| 1376 | /* Just calculate msg length and return */ |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1377 | return tipc_msg_calc_data_size(msg_sect, num_sect); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1378 | } |
| 1379 | return -ELINKCONG; |
| 1380 | } |
| 1381 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1382 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1383 | * tipc_send_buf - send message buffer on connection |
| 1384 | */ |
| 1385 | |
| 1386 | int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz) |
| 1387 | { |
| 1388 | struct port *p_ptr; |
| 1389 | struct tipc_msg *msg; |
| 1390 | u32 destnode; |
| 1391 | u32 hsz; |
| 1392 | u32 sz; |
| 1393 | u32 res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1394 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1395 | p_ptr = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1396 | if (!p_ptr || !p_ptr->publ.connected) |
| 1397 | return -EINVAL; |
| 1398 | |
| 1399 | msg = &p_ptr->publ.phdr; |
| 1400 | hsz = msg_hdr_sz(msg); |
| 1401 | sz = hsz + dsz; |
| 1402 | msg_set_size(msg, sz); |
| 1403 | if (skb_cow(buf, hsz)) |
| 1404 | return -ENOMEM; |
| 1405 | |
| 1406 | skb_push(buf, hsz); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1407 | skb_copy_to_linear_data(buf, msg, hsz); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1408 | destnode = msg_destnode(msg); |
| 1409 | p_ptr->publ.congested = 1; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1410 | if (!tipc_port_congested(p_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1411 | if (likely(destnode != tipc_own_addr)) |
| 1412 | res = tipc_send_buf_fast(buf, destnode); |
| 1413 | else { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1414 | tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1415 | res = sz; |
| 1416 | } |
| 1417 | if (likely(res != -ELINKCONG)) { |
| 1418 | port_incr_out_seqno(p_ptr); |
| 1419 | p_ptr->sent++; |
| 1420 | p_ptr->publ.congested = 0; |
| 1421 | return res; |
| 1422 | } |
| 1423 | } |
| 1424 | if (port_unreliable(p_ptr)) { |
| 1425 | p_ptr->publ.congested = 0; |
| 1426 | return dsz; |
| 1427 | } |
| 1428 | return -ELINKCONG; |
| 1429 | } |
| 1430 | |
| 1431 | /** |
| 1432 | * tipc_forward2name - forward message sections to port name |
| 1433 | */ |
| 1434 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1435 | int tipc_forward2name(u32 ref, |
| 1436 | struct tipc_name const *name, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1437 | u32 domain, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1438 | u32 num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1439 | struct iovec const *msg_sect, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1440 | struct tipc_portid const *orig, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1441 | unsigned int importance) |
| 1442 | { |
| 1443 | struct port *p_ptr; |
| 1444 | struct tipc_msg *msg; |
| 1445 | u32 destnode = domain; |
Allan Stephens | 9ccc2eb | 2010-05-11 14:30:06 +0000 | [diff] [blame] | 1446 | u32 destport; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1447 | int res; |
| 1448 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1449 | p_ptr = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1450 | if (!p_ptr || p_ptr->publ.connected) |
| 1451 | return -EINVAL; |
| 1452 | |
| 1453 | msg = &p_ptr->publ.phdr; |
| 1454 | msg_set_type(msg, TIPC_NAMED_MSG); |
| 1455 | msg_set_orignode(msg, orig->node); |
| 1456 | msg_set_origport(msg, orig->ref); |
| 1457 | msg_set_hdr_sz(msg, LONG_H_SIZE); |
| 1458 | msg_set_nametype(msg, name->type); |
| 1459 | msg_set_nameinst(msg, name->instance); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1460 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1461 | if (importance <= TIPC_CRITICAL_IMPORTANCE) |
| 1462 | msg_set_importance(msg,importance); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1463 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1464 | msg_set_destnode(msg, destnode); |
| 1465 | msg_set_destport(msg, destport); |
| 1466 | |
Allan Stephens | 5d9c54c | 2010-09-03 08:33:39 +0000 | [diff] [blame^] | 1467 | if (likely(destport)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1468 | p_ptr->sent++; |
| 1469 | if (likely(destnode == tipc_own_addr)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1470 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1471 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1472 | destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1473 | if (likely(res != -ELINKCONG)) |
| 1474 | return res; |
| 1475 | if (port_unreliable(p_ptr)) { |
| 1476 | /* Just calculate msg length and return */ |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1477 | return tipc_msg_calc_data_size(msg_sect, num_sect); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1478 | } |
| 1479 | return -ELINKCONG; |
| 1480 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1481 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1482 | TIPC_ERR_NO_NAME); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * tipc_send2name - send message sections to port name |
| 1487 | */ |
| 1488 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1489 | int tipc_send2name(u32 ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1490 | struct tipc_name const *name, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1491 | unsigned int domain, |
| 1492 | unsigned int num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1493 | struct iovec const *msg_sect) |
| 1494 | { |
| 1495 | struct tipc_portid orig; |
| 1496 | |
| 1497 | orig.ref = ref; |
| 1498 | orig.node = tipc_own_addr; |
| 1499 | return tipc_forward2name(ref, name, domain, num_sect, msg_sect, &orig, |
| 1500 | TIPC_PORT_IMPORTANCE); |
| 1501 | } |
| 1502 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1503 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1504 | * tipc_forward_buf2name - forward message buffer to port name |
| 1505 | */ |
| 1506 | |
| 1507 | int tipc_forward_buf2name(u32 ref, |
| 1508 | struct tipc_name const *name, |
| 1509 | u32 domain, |
| 1510 | struct sk_buff *buf, |
| 1511 | unsigned int dsz, |
| 1512 | struct tipc_portid const *orig, |
| 1513 | unsigned int importance) |
| 1514 | { |
| 1515 | struct port *p_ptr; |
| 1516 | struct tipc_msg *msg; |
| 1517 | u32 destnode = domain; |
Allan Stephens | 9ccc2eb | 2010-05-11 14:30:06 +0000 | [diff] [blame] | 1518 | u32 destport; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1519 | int res; |
| 1520 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1521 | p_ptr = (struct port *)tipc_ref_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1522 | if (!p_ptr || p_ptr->publ.connected) |
| 1523 | return -EINVAL; |
| 1524 | |
| 1525 | msg = &p_ptr->publ.phdr; |
| 1526 | if (importance <= TIPC_CRITICAL_IMPORTANCE) |
| 1527 | msg_set_importance(msg, importance); |
| 1528 | msg_set_type(msg, TIPC_NAMED_MSG); |
| 1529 | msg_set_orignode(msg, orig->node); |
| 1530 | msg_set_origport(msg, orig->ref); |
| 1531 | msg_set_nametype(msg, name->type); |
| 1532 | msg_set_nameinst(msg, name->instance); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1533 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1534 | msg_set_hdr_sz(msg, LONG_H_SIZE); |
| 1535 | msg_set_size(msg, LONG_H_SIZE + dsz); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1536 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1537 | msg_set_destnode(msg, destnode); |
| 1538 | msg_set_destport(msg, destport); |
| 1539 | msg_dbg(msg, "forw2name ==> "); |
| 1540 | if (skb_cow(buf, LONG_H_SIZE)) |
| 1541 | return -ENOMEM; |
| 1542 | skb_push(buf, LONG_H_SIZE); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1543 | skb_copy_to_linear_data(buf, msg, LONG_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1544 | msg_dbg(buf_msg(buf),"PREP:"); |
Allan Stephens | 5d9c54c | 2010-09-03 08:33:39 +0000 | [diff] [blame^] | 1545 | if (likely(destport)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1546 | p_ptr->sent++; |
| 1547 | if (destnode == tipc_own_addr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1548 | return tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1549 | res = tipc_send_buf_fast(buf, destnode); |
| 1550 | if (likely(res != -ELINKCONG)) |
| 1551 | return res; |
| 1552 | if (port_unreliable(p_ptr)) |
| 1553 | return dsz; |
| 1554 | return -ELINKCONG; |
| 1555 | } |
| 1556 | return tipc_reject_msg(buf, TIPC_ERR_NO_NAME); |
| 1557 | } |
| 1558 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1559 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1560 | * tipc_send_buf2name - send message buffer to port name |
| 1561 | */ |
| 1562 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1563 | int tipc_send_buf2name(u32 ref, |
| 1564 | struct tipc_name const *dest, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1565 | u32 domain, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1566 | struct sk_buff *buf, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1567 | unsigned int dsz) |
| 1568 | { |
| 1569 | struct tipc_portid orig; |
| 1570 | |
| 1571 | orig.ref = ref; |
| 1572 | orig.node = tipc_own_addr; |
| 1573 | return tipc_forward_buf2name(ref, dest, domain, buf, dsz, &orig, |
| 1574 | TIPC_PORT_IMPORTANCE); |
| 1575 | } |
| 1576 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1577 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1578 | * tipc_forward2port - forward message sections to port identity |
| 1579 | */ |
| 1580 | |
| 1581 | int tipc_forward2port(u32 ref, |
| 1582 | struct tipc_portid const *dest, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1583 | unsigned int num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1584 | struct iovec const *msg_sect, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1585 | struct tipc_portid const *orig, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1586 | unsigned int importance) |
| 1587 | { |
| 1588 | struct port *p_ptr; |
| 1589 | struct tipc_msg *msg; |
| 1590 | int res; |
| 1591 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1592 | p_ptr = tipc_port_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1593 | if (!p_ptr || p_ptr->publ.connected) |
| 1594 | return -EINVAL; |
| 1595 | |
| 1596 | msg = &p_ptr->publ.phdr; |
| 1597 | msg_set_type(msg, TIPC_DIRECT_MSG); |
| 1598 | msg_set_orignode(msg, orig->node); |
| 1599 | msg_set_origport(msg, orig->ref); |
| 1600 | msg_set_destnode(msg, dest->node); |
| 1601 | msg_set_destport(msg, dest->ref); |
| 1602 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); |
| 1603 | if (importance <= TIPC_CRITICAL_IMPORTANCE) |
| 1604 | msg_set_importance(msg, importance); |
| 1605 | p_ptr->sent++; |
| 1606 | if (dest->node == tipc_own_addr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1607 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); |
| 1608 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, dest->node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1609 | if (likely(res != -ELINKCONG)) |
| 1610 | return res; |
| 1611 | if (port_unreliable(p_ptr)) { |
| 1612 | /* Just calculate msg length and return */ |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 1613 | return tipc_msg_calc_data_size(msg_sect, num_sect); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1614 | } |
| 1615 | return -ELINKCONG; |
| 1616 | } |
| 1617 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1618 | /** |
| 1619 | * tipc_send2port - send message sections to port identity |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1620 | */ |
| 1621 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1622 | int tipc_send2port(u32 ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1623 | struct tipc_portid const *dest, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1624 | unsigned int num_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1625 | struct iovec const *msg_sect) |
| 1626 | { |
| 1627 | struct tipc_portid orig; |
| 1628 | |
| 1629 | orig.ref = ref; |
| 1630 | orig.node = tipc_own_addr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1631 | return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1632 | TIPC_PORT_IMPORTANCE); |
| 1633 | } |
| 1634 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1635 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1636 | * tipc_forward_buf2port - forward message buffer to port identity |
| 1637 | */ |
| 1638 | int tipc_forward_buf2port(u32 ref, |
| 1639 | struct tipc_portid const *dest, |
| 1640 | struct sk_buff *buf, |
| 1641 | unsigned int dsz, |
| 1642 | struct tipc_portid const *orig, |
| 1643 | unsigned int importance) |
| 1644 | { |
| 1645 | struct port *p_ptr; |
| 1646 | struct tipc_msg *msg; |
| 1647 | int res; |
| 1648 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1649 | p_ptr = (struct port *)tipc_ref_deref(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1650 | if (!p_ptr || p_ptr->publ.connected) |
| 1651 | return -EINVAL; |
| 1652 | |
| 1653 | msg = &p_ptr->publ.phdr; |
| 1654 | msg_set_type(msg, TIPC_DIRECT_MSG); |
| 1655 | msg_set_orignode(msg, orig->node); |
| 1656 | msg_set_origport(msg, orig->ref); |
| 1657 | msg_set_destnode(msg, dest->node); |
| 1658 | msg_set_destport(msg, dest->ref); |
| 1659 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); |
| 1660 | if (importance <= TIPC_CRITICAL_IMPORTANCE) |
| 1661 | msg_set_importance(msg, importance); |
| 1662 | msg_set_size(msg, DIR_MSG_H_SIZE + dsz); |
| 1663 | if (skb_cow(buf, DIR_MSG_H_SIZE)) |
| 1664 | return -ENOMEM; |
| 1665 | |
| 1666 | skb_push(buf, DIR_MSG_H_SIZE); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1667 | skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1668 | msg_dbg(msg, "buf2port: "); |
| 1669 | p_ptr->sent++; |
| 1670 | if (dest->node == tipc_own_addr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1671 | return tipc_port_recv_msg(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1672 | res = tipc_send_buf_fast(buf, dest->node); |
| 1673 | if (likely(res != -ELINKCONG)) |
| 1674 | return res; |
| 1675 | if (port_unreliable(p_ptr)) |
| 1676 | return dsz; |
| 1677 | return -ELINKCONG; |
| 1678 | } |
| 1679 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1680 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1681 | * tipc_send_buf2port - send message buffer to port identity |
| 1682 | */ |
| 1683 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1684 | int tipc_send_buf2port(u32 ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1685 | struct tipc_portid const *dest, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1686 | struct sk_buff *buf, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1687 | unsigned int dsz) |
| 1688 | { |
| 1689 | struct tipc_portid orig; |
| 1690 | |
| 1691 | orig.ref = ref; |
| 1692 | orig.node = tipc_own_addr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1693 | return tipc_forward_buf2port(ref, dest, buf, dsz, &orig, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1694 | TIPC_PORT_IMPORTANCE); |
| 1695 | } |
| 1696 | |