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