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