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