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