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 | * |
Jon Paul Maloy | 8826cde | 2014-03-12 11:31:09 -0400 | [diff] [blame] | 4 | * Copyright (c) 1992-2007, 2014, Ericsson AB |
Ying Xue | 198d73b | 2013-06-17 10:54:42 -0400 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, 2010-2013, 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" |
Jon Paul Maloy | 8826cde | 2014-03-12 11:31:09 -0400 | [diff] [blame] | 41 | #include "socket.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 42 | |
| 43 | /* Connection management: */ |
| 44 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 45 | |
| 46 | #define MAX_REJECT_SIZE 1024 |
| 47 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 48 | DEFINE_SPINLOCK(tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 49 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 50 | static LIST_HEAD(ports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 51 | static void port_handle_node_down(unsigned long ref); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 52 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err); |
| 53 | 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] | 54 | static void port_timeout(unsigned long ref); |
| 55 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 56 | /** |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 57 | * tipc_port_peer_msg - verify message was sent by connected port's peer |
| 58 | * |
| 59 | * Handles cases where the node's network address has changed from |
| 60 | * the default of <0.0.0> to its configured setting. |
| 61 | */ |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 62 | int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg) |
| 63 | { |
| 64 | u32 peernode; |
| 65 | u32 orignode; |
| 66 | |
Jon Paul Maloy | f9fef18 | 2014-03-12 11:31:08 -0400 | [diff] [blame] | 67 | if (msg_origport(msg) != tipc_port_peerport(p_ptr)) |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 68 | return 0; |
| 69 | |
| 70 | orignode = msg_orignode(msg); |
Jon Paul Maloy | f9fef18 | 2014-03-12 11:31:08 -0400 | [diff] [blame] | 71 | peernode = tipc_port_peernode(p_ptr); |
Allan Stephens | f0712e86 | 2012-04-17 18:42:28 -0400 | [diff] [blame] | 72 | return (orignode == peernode) || |
| 73 | (!orignode && (peernode == tipc_own_addr)) || |
| 74 | (!peernode && (orignode == tipc_own_addr)); |
| 75 | } |
| 76 | |
Jon Paul Maloy | 24be34b | 2014-03-12 11:31:10 -0400 | [diff] [blame] | 77 | /* tipc_port_init - intiate TIPC port and lock it |
| 78 | * |
| 79 | * Returns obtained reference if initialization is successful, zero otherwise |
| 80 | */ |
| 81 | u32 tipc_port_init(struct tipc_port *p_ptr, |
| 82 | const unsigned int importance) |
| 83 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 84 | struct tipc_msg *msg; |
| 85 | u32 ref; |
| 86 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 87 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 88 | if (!ref) { |
Jon Paul Maloy | 8826cde | 2014-03-12 11:31:09 -0400 | [diff] [blame] | 89 | pr_warn("Port registration failed, ref. table exhausted\n"); |
Jon Paul Maloy | 24be34b | 2014-03-12 11:31:10 -0400 | [diff] [blame] | 90 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 93 | p_ptr->max_pkt = MAX_PKT_DEFAULT; |
| 94 | p_ptr->ref = ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 95 | INIT_LIST_HEAD(&p_ptr->wait_list); |
| 96 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 98 | INIT_LIST_HEAD(&p_ptr->publications); |
| 99 | INIT_LIST_HEAD(&p_ptr->port_list); |
Allan Stephens | f21536d | 2012-04-17 18:22:49 -0400 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * Must hold port list lock while initializing message header template |
| 103 | * to ensure a change to node's own network address doesn't result |
| 104 | * in template containing out-dated network address information |
| 105 | */ |
Allan Stephens | f21536d | 2012-04-17 18:22:49 -0400 | [diff] [blame] | 106 | spin_lock_bh(&tipc_port_list_lock); |
| 107 | msg = &p_ptr->phdr; |
| 108 | tipc_msg_init(msg, importance, TIPC_NAMED_MSG, NAMED_H_SIZE, 0); |
| 109 | msg_set_origport(msg, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 110 | list_add_tail(&p_ptr->port_list, &ports); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 111 | spin_unlock_bh(&tipc_port_list_lock); |
Jon Paul Maloy | 24be34b | 2014-03-12 11:31:10 -0400 | [diff] [blame] | 112 | return ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Jon Paul Maloy | 24be34b | 2014-03-12 11:31:10 -0400 | [diff] [blame] | 115 | void tipc_port_destroy(struct tipc_port *p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 116 | { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 117 | struct sk_buff *buf = NULL; |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 118 | struct tipc_msg *msg = NULL; |
| 119 | u32 peer; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 120 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 121 | tipc_withdraw(p_ptr, 0, NULL); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 122 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 123 | spin_lock_bh(p_ptr->lock); |
| 124 | tipc_ref_discard(p_ptr->ref); |
| 125 | spin_unlock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 126 | |
| 127 | k_cancel_timer(&p_ptr->timer); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 128 | if (p_ptr->connected) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 129 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 130 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 131 | msg = buf_msg(buf); |
| 132 | peer = msg_destnode(msg); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 133 | tipc_link_xmit(buf, peer, msg_link_selector(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 134 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 135 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | list_del(&p_ptr->port_list); |
| 137 | list_del(&p_ptr->wait_list); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 138 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 139 | k_term_timer(&p_ptr->timer); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 140 | } |
| 141 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 142 | /* |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 143 | * port_build_proto_msg(): create connection protocol message for port |
| 144 | * |
| 145 | * On entry the port must be locked and connected. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 146 | */ |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 147 | static struct sk_buff *port_build_proto_msg(struct tipc_port *p_ptr, |
| 148 | u32 type, u32 ack) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 149 | { |
| 150 | struct sk_buff *buf; |
| 151 | struct tipc_msg *msg; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 152 | |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 153 | buf = tipc_buf_acquire(INT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 154 | if (buf) { |
| 155 | msg = buf_msg(buf); |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 156 | tipc_msg_init(msg, CONN_MANAGER, type, INT_H_SIZE, |
Jon Paul Maloy | f9fef18 | 2014-03-12 11:31:08 -0400 | [diff] [blame] | 157 | tipc_port_peernode(p_ptr)); |
| 158 | msg_set_destport(msg, tipc_port_peerport(p_ptr)); |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 159 | msg_set_origport(msg, p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | msg_set_msgcnt(msg, ack); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 161 | buf->next = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 162 | } |
| 163 | return buf; |
| 164 | } |
| 165 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 166 | static void port_timeout(unsigned long ref) |
| 167 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 168 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 169 | struct sk_buff *buf = NULL; |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 170 | struct tipc_msg *msg = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 171 | |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 172 | if (!p_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 173 | return; |
| 174 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 175 | if (!p_ptr->connected) { |
Allan Stephens | 065fd17 | 2006-10-16 21:38:05 -0700 | [diff] [blame] | 176 | tipc_port_unlock(p_ptr); |
| 177 | return; |
| 178 | } |
| 179 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 180 | /* Last probe answered ? */ |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 181 | if (p_ptr->probing_state == TIPC_CONN_PROBING) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 182 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
| 183 | } else { |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 184 | buf = port_build_proto_msg(p_ptr, CONN_PROBE, 0); |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 185 | p_ptr->probing_state = TIPC_CONN_PROBING; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 186 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 187 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 188 | tipc_port_unlock(p_ptr); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 189 | msg = buf_msg(buf); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 190 | tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
| 194 | static void port_handle_node_down(unsigned long ref) |
| 195 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 196 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 197 | struct sk_buff *buf = NULL; |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 198 | struct tipc_msg *msg = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 199 | |
| 200 | if (!p_ptr) |
| 201 | return; |
| 202 | buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_NODE); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 203 | tipc_port_unlock(p_ptr); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 204 | msg = buf_msg(buf); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 205 | tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 209 | 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] | 210 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 211 | struct sk_buff *buf = port_build_peer_abort_msg(p_ptr, err); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 212 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 213 | if (buf) { |
| 214 | struct tipc_msg *msg = buf_msg(buf); |
| 215 | msg_swap_words(msg, 4, 5); |
| 216 | msg_swap_words(msg, 6, 7); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 217 | buf->next = NULL; |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 218 | } |
| 219 | return buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 223 | 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] | 224 | { |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 225 | struct sk_buff *buf; |
| 226 | struct tipc_msg *msg; |
| 227 | u32 imp; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 228 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 229 | if (!p_ptr->connected) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 230 | return NULL; |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 231 | |
| 232 | buf = tipc_buf_acquire(BASIC_H_SIZE); |
| 233 | if (buf) { |
| 234 | msg = buf_msg(buf); |
| 235 | memcpy(msg, &p_ptr->phdr, BASIC_H_SIZE); |
| 236 | msg_set_hdr_sz(msg, BASIC_H_SIZE); |
| 237 | msg_set_size(msg, BASIC_H_SIZE); |
| 238 | imp = msg_importance(msg); |
| 239 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
| 240 | msg_set_importance(msg, ++imp); |
| 241 | msg_set_errcode(msg, err); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 242 | buf->next = NULL; |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 243 | } |
| 244 | return buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 247 | static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 248 | { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 249 | struct publication *publ; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 250 | int ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 251 | |
| 252 | if (full_id) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 253 | ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:", |
| 254 | tipc_zone(tipc_own_addr), |
| 255 | tipc_cluster(tipc_own_addr), |
| 256 | tipc_node(tipc_own_addr), p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 257 | else |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 258 | ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 259 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 260 | if (p_ptr->connected) { |
Jon Paul Maloy | f9fef18 | 2014-03-12 11:31:08 -0400 | [diff] [blame] | 261 | u32 dport = tipc_port_peerport(p_ptr); |
| 262 | u32 destnode = tipc_port_peernode(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 263 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 264 | ret += tipc_snprintf(buf + ret, len - ret, |
| 265 | " connected to <%u.%u.%u:%u>", |
| 266 | tipc_zone(destnode), |
| 267 | tipc_cluster(destnode), |
| 268 | tipc_node(destnode), dport); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 269 | if (p_ptr->conn_type != 0) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 270 | ret += tipc_snprintf(buf + ret, len - ret, |
| 271 | " via {%u,%u}", p_ptr->conn_type, |
| 272 | p_ptr->conn_instance); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 273 | } else if (p_ptr->published) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 274 | ret += tipc_snprintf(buf + ret, len - ret, " bound to"); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 275 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 276 | if (publ->lower == publ->upper) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 277 | ret += tipc_snprintf(buf + ret, len - ret, |
| 278 | " {%u,%u}", publ->type, |
| 279 | publ->lower); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 280 | else |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 281 | ret += tipc_snprintf(buf + ret, len - ret, |
| 282 | " {%u,%u,%u}", publ->type, |
| 283 | publ->lower, publ->upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 284 | } |
| 285 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 286 | ret += tipc_snprintf(buf + ret, len - ret, "\n"); |
| 287 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 290 | struct sk_buff *tipc_port_get_ports(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 291 | { |
| 292 | struct sk_buff *buf; |
| 293 | struct tlv_desc *rep_tlv; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 294 | char *pb; |
| 295 | int pb_len; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 296 | struct tipc_port *p_ptr; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 297 | int str_len = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 299 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 300 | if (!buf) |
| 301 | return NULL; |
| 302 | rep_tlv = (struct tlv_desc *)buf->data; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 303 | pb = TLV_DATA(rep_tlv); |
| 304 | pb_len = ULTRA_STRING_MAX_LEN; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 305 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 306 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 307 | list_for_each_entry(p_ptr, &ports, port_list) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 308 | spin_lock_bh(p_ptr->lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 309 | str_len += port_print(p_ptr, pb, pb_len, 0); |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 310 | spin_unlock_bh(p_ptr->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 311 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 312 | spin_unlock_bh(&tipc_port_list_lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 313 | str_len += 1; /* for "\0" */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 314 | skb_put(buf, TLV_SPACE(str_len)); |
| 315 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 316 | |
| 317 | return buf; |
| 318 | } |
| 319 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 320 | void tipc_port_reinit(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 321 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 322 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 323 | struct tipc_msg *msg; |
| 324 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 325 | spin_lock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 326 | list_for_each_entry(p_ptr, &ports, port_list) { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 327 | msg = &p_ptr->phdr; |
Allan Stephens | 6d4a667 | 2008-05-21 14:54:12 -0700 | [diff] [blame] | 328 | msg_set_prevnode(msg, tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 329 | msg_set_orignode(msg, tipc_own_addr); |
| 330 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 331 | spin_unlock_bh(&tipc_port_list_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 334 | void tipc_acknowledge(u32 ref, u32 ack) |
| 335 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 336 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 337 | struct sk_buff *buf = NULL; |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 338 | struct tipc_msg *msg; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 340 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 341 | if (!p_ptr) |
| 342 | return; |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 343 | if (p_ptr->connected) |
Allan Stephens | e4a0aee | 2011-06-01 16:21:12 -0400 | [diff] [blame] | 344 | buf = port_build_proto_msg(p_ptr, CONN_ACK, ack); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 345 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 346 | tipc_port_unlock(p_ptr); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 347 | if (!buf) |
| 348 | return; |
| 349 | msg = buf_msg(buf); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 350 | tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 353 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, |
| 354 | struct tipc_name_seq const *seq) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 355 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 356 | struct publication *publ; |
| 357 | u32 key; |
Adrian Bunk | d55b4c6 | 2006-10-31 16:59:35 -0800 | [diff] [blame] | 358 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 359 | if (p_ptr->connected) |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 360 | return -EINVAL; |
| 361 | key = p_ptr->ref + p_ptr->pub_count + 1; |
| 362 | if (key == p_ptr->ref) |
| 363 | return -EADDRINUSE; |
| 364 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 365 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 366 | scope, p_ptr->ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 367 | if (publ) { |
| 368 | list_add(&publ->pport_list, &p_ptr->publications); |
| 369 | p_ptr->pub_count++; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 370 | p_ptr->published = 1; |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 371 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 372 | } |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 373 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 376 | int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, |
| 377 | struct tipc_name_seq const *seq) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 378 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 379 | struct publication *publ; |
| 380 | struct publication *tpubl; |
| 381 | int res = -EINVAL; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 382 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 383 | if (!seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 384 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 385 | &p_ptr->publications, pport_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 386 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 387 | publ->ref, publ->key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 388 | } |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 389 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 390 | } else { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 391 | list_for_each_entry_safe(publ, tpubl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 392 | &p_ptr->publications, pport_list) { |
| 393 | if (publ->scope != scope) |
| 394 | continue; |
| 395 | if (publ->type != seq->type) |
| 396 | continue; |
| 397 | if (publ->lower != seq->lower) |
| 398 | continue; |
| 399 | if (publ->upper != seq->upper) |
| 400 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 401 | tipc_nametbl_withdraw(publ->type, publ->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 402 | publ->ref, publ->key); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 403 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 404 | break; |
| 405 | } |
| 406 | } |
| 407 | if (list_empty(&p_ptr->publications)) |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 408 | p_ptr->published = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 409 | return res; |
| 410 | } |
| 411 | |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 412 | int tipc_port_connect(u32 ref, struct tipc_portid const *peer) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 413 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 414 | struct tipc_port *p_ptr; |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 415 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 416 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 417 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 418 | if (!p_ptr) |
| 419 | return -EINVAL; |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 420 | res = __tipc_port_connect(ref, p_ptr, peer); |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 421 | tipc_port_unlock(p_ptr); |
| 422 | return res; |
| 423 | } |
| 424 | |
| 425 | /* |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 426 | * __tipc_port_connect - connect to a remote peer |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 427 | * |
| 428 | * Port must be locked. |
| 429 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 430 | int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr, |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 431 | struct tipc_portid const *peer) |
| 432 | { |
| 433 | struct tipc_msg *msg; |
| 434 | int res = -EINVAL; |
| 435 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 436 | if (p_ptr->published || p_ptr->connected) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 437 | goto exit; |
| 438 | if (!peer->ref) |
| 439 | goto exit; |
| 440 | |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 441 | msg = &p_ptr->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 442 | msg_set_destnode(msg, peer->node); |
| 443 | msg_set_destport(msg, peer->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 444 | msg_set_type(msg, TIPC_CONN_MSG); |
Allan Stephens | 53b9436 | 2011-04-17 16:02:11 -0400 | [diff] [blame] | 445 | msg_set_lookup_scope(msg, 0); |
Allan Stephens | 08c80e9 | 2010-12-31 18:59:17 +0000 | [diff] [blame] | 446 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 447 | |
| 448 | p_ptr->probing_interval = PROBING_INTERVAL; |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 449 | p_ptr->probing_state = TIPC_CONN_OK; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 450 | p_ptr->connected = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 451 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
| 452 | |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 453 | tipc_nodesub_subscribe(&p_ptr->subscription, peer->node, |
David S. Miller | 880b005 | 2006-01-12 13:22:32 -0800 | [diff] [blame] | 454 | (void *)(unsigned long)ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 455 | (net_ev_handler)port_handle_node_down); |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 456 | res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 457 | exit: |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 458 | p_ptr->max_pkt = tipc_node_get_mtu(peer->node, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 459 | return res; |
| 460 | } |
| 461 | |
Paul Gortmaker | bc87911 | 2012-11-29 13:48:40 -0500 | [diff] [blame] | 462 | /* |
| 463 | * __tipc_disconnect - disconnect port from peer |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 464 | * |
| 465 | * Port must be locked. |
| 466 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 467 | int __tipc_port_disconnect(struct tipc_port *tp_ptr) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 468 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 469 | if (tp_ptr->connected) { |
| 470 | tp_ptr->connected = 0; |
| 471 | /* let timer expire on it's own to avoid deadlock! */ |
Joe Perches | e319269 | 2012-06-03 17:41:40 +0000 | [diff] [blame] | 472 | tipc_nodesub_unsubscribe(&tp_ptr->subscription); |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 473 | return 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 474 | } |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 475 | |
| 476 | return -ENOTCONN; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 479 | /* |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 480 | * tipc_port_disconnect(): Disconnect port form peer. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 481 | * This is a node local operation. |
| 482 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 483 | int tipc_port_disconnect(u32 ref) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 484 | { |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 485 | struct tipc_port *p_ptr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 486 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 487 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 488 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 489 | if (!p_ptr) |
| 490 | return -EINVAL; |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 491 | res = __tipc_port_disconnect(p_ptr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 492 | tipc_port_unlock(p_ptr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 493 | return res; |
| 494 | } |
| 495 | |
| 496 | /* |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 497 | * tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 498 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 499 | int tipc_port_shutdown(u32 ref) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 500 | { |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 501 | struct tipc_msg *msg; |
Allan Stephens | 23dd4cc | 2011-01-07 11:43:40 -0500 | [diff] [blame] | 502 | struct tipc_port *p_ptr; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 503 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 504 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 505 | p_ptr = tipc_port_lock(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 506 | if (!p_ptr) |
| 507 | return -EINVAL; |
| 508 | |
Allan Stephens | e244a91 | 2011-05-31 16:10:08 -0400 | [diff] [blame] | 509 | buf = port_build_peer_abort_msg(p_ptr, TIPC_CONN_SHUTDOWN); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 510 | tipc_port_unlock(p_ptr); |
Jon Paul Maloy | b786e2b | 2014-06-25 20:41:39 -0500 | [diff] [blame] | 511 | msg = buf_msg(buf); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 512 | tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg)); |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 513 | return tipc_port_disconnect(ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 514 | } |