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