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