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