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