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