Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
Jon Paul Maloy | 02c00c2 | 2014-06-09 11:08:18 -0500 | [diff] [blame] | 2 | * net/tipc/socket.c: TIPC socket API |
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) 2001-2007, 2012-2014, Ericsson AB |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -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 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 37 | #include "core.h" |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 38 | #include "name_table.h" |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 39 | #include "node.h" |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 40 | #include "link.h" |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 41 | #include <linux/export.h> |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 42 | #include "config.h" |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 43 | #include "socket.h" |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 44 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 45 | #define SS_LISTENING -1 /* socket is listening */ |
| 46 | #define SS_READY -2 /* socket is connectionless */ |
| 47 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 48 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 49 | #define CONN_PROBING_INTERVAL 3600000 /* [ms] => 1 h */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 50 | #define TIPC_FWD_MSG 1 |
| 51 | #define TIPC_CONN_OK 0 |
| 52 | #define TIPC_CONN_PROBING 1 |
| 53 | |
| 54 | /** |
| 55 | * struct tipc_sock - TIPC socket structure |
| 56 | * @sk: socket - interacts with 'port' and with user via the socket API |
| 57 | * @connected: non-zero if port is currently connected to a peer port |
| 58 | * @conn_type: TIPC type used when connection was established |
| 59 | * @conn_instance: TIPC instance used when connection was established |
| 60 | * @published: non-zero if port has one or more associated names |
| 61 | * @max_pkt: maximum packet size "hint" used when building messages sent by port |
| 62 | * @ref: unique reference to port in TIPC object registry |
| 63 | * @phdr: preformatted message header used when sending messages |
| 64 | * @port_list: adjacent ports in TIPC's global list of ports |
| 65 | * @publications: list of publications for port |
| 66 | * @pub_count: total # of publications port has made during its lifetime |
| 67 | * @probing_state: |
| 68 | * @probing_interval: |
| 69 | * @timer: |
| 70 | * @port: port - interacts with 'sk' and with the rest of the TIPC stack |
| 71 | * @peer_name: the peer of the connection, if any |
| 72 | * @conn_timeout: the time we can wait for an unresponded setup request |
| 73 | * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue |
| 74 | * @link_cong: non-zero if owner must sleep because of link congestion |
| 75 | * @sent_unacked: # messages sent by socket, and not yet acked by peer |
| 76 | * @rcv_unacked: # messages read by user, but not yet acked back to peer |
| 77 | */ |
| 78 | struct tipc_sock { |
| 79 | struct sock sk; |
| 80 | int connected; |
| 81 | u32 conn_type; |
| 82 | u32 conn_instance; |
| 83 | int published; |
| 84 | u32 max_pkt; |
| 85 | u32 ref; |
| 86 | struct tipc_msg phdr; |
| 87 | struct list_head sock_list; |
| 88 | struct list_head publications; |
| 89 | u32 pub_count; |
| 90 | u32 probing_state; |
| 91 | u32 probing_interval; |
| 92 | struct timer_list timer; |
| 93 | uint conn_timeout; |
| 94 | atomic_t dupl_rcvcnt; |
| 95 | bool link_cong; |
| 96 | uint sent_unacked; |
| 97 | uint rcv_unacked; |
| 98 | }; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 99 | |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 100 | static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb); |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 101 | static void tipc_data_ready(struct sock *sk); |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 102 | static void tipc_write_space(struct sock *sk); |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 103 | static int tipc_release(struct socket *sock); |
| 104 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); |
Jon Paul Maloy | 0abd8ff | 2014-07-16 20:41:01 -0400 | [diff] [blame] | 105 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 106 | static void tipc_sk_timeout(unsigned long ref); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 107 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 108 | struct tipc_name_seq const *seq); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 109 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 110 | struct tipc_name_seq const *seq); |
Jon Paul Maloy | 808d90f | 2014-08-22 18:09:19 -0400 | [diff] [blame] | 111 | static u32 tipc_sk_ref_acquire(struct tipc_sock *tsk); |
| 112 | static void tipc_sk_ref_discard(u32 ref); |
| 113 | static struct tipc_sock *tipc_sk_get(u32 ref); |
| 114 | static struct tipc_sock *tipc_sk_get_next(u32 *ref); |
| 115 | static void tipc_sk_put(struct tipc_sock *tsk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 116 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 117 | static const struct proto_ops packet_ops; |
| 118 | static const struct proto_ops stream_ops; |
| 119 | static const struct proto_ops msg_ops; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 120 | |
| 121 | static struct proto tipc_proto; |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 122 | static struct proto tipc_proto_kern; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 123 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 124 | /* |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 125 | * Revised TIPC socket locking policy: |
| 126 | * |
| 127 | * Most socket operations take the standard socket lock when they start |
| 128 | * and hold it until they finish (or until they need to sleep). Acquiring |
| 129 | * this lock grants the owner exclusive access to the fields of the socket |
| 130 | * data structures, with the exception of the backlog queue. A few socket |
| 131 | * operations can be done without taking the socket lock because they only |
| 132 | * read socket information that never changes during the life of the socket. |
| 133 | * |
| 134 | * Socket operations may acquire the lock for the associated TIPC port if they |
| 135 | * need to perform an operation on the port. If any routine needs to acquire |
| 136 | * both the socket lock and the port lock it must take the socket lock first |
| 137 | * to avoid the risk of deadlock. |
| 138 | * |
| 139 | * The dispatcher handling incoming messages cannot grab the socket lock in |
| 140 | * the standard fashion, since invoked it runs at the BH level and cannot block. |
| 141 | * Instead, it checks to see if the socket lock is currently owned by someone, |
| 142 | * and either handles the message itself or adds it to the socket's backlog |
| 143 | * queue; in the latter case the queued message is processed once the process |
| 144 | * owning the socket lock releases it. |
| 145 | * |
| 146 | * NOTE: Releasing the socket lock while an operation is sleeping overcomes |
| 147 | * the problem of a blocked socket operation preventing any other operations |
| 148 | * from occurring. However, applications must be careful if they have |
| 149 | * multiple threads trying to send (or receive) on the same socket, as these |
| 150 | * operations might interfere with each other. For example, doing a connect |
| 151 | * and a receive at the same time might allow the receive to consume the |
| 152 | * ACK message meant for the connect. While additional work could be done |
| 153 | * to try and overcome this, it doesn't seem to be worthwhile at the present. |
| 154 | * |
| 155 | * NOTE: Releasing the socket lock while an operation is sleeping also ensures |
| 156 | * that another operation that must be performed in a non-blocking manner is |
| 157 | * not delayed for very long because the lock has already been taken. |
| 158 | * |
| 159 | * NOTE: This code assumes that certain fields of a port/socket pair are |
| 160 | * constant over its lifetime; such fields can be examined without taking |
| 161 | * the socket lock and/or port lock, and do not need to be re-read even |
| 162 | * after resuming processing after waiting. These fields include: |
| 163 | * - socket type |
| 164 | * - pointer to socket sk structure (aka tipc_sock structure) |
| 165 | * - pointer to port structure |
| 166 | * - port reference |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 167 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 168 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 169 | static u32 tsk_peer_node(struct tipc_sock *tsk) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 170 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 171 | return msg_destnode(&tsk->phdr); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 174 | static u32 tsk_peer_port(struct tipc_sock *tsk) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 175 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 176 | return msg_destport(&tsk->phdr); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 179 | static bool tsk_unreliable(struct tipc_sock *tsk) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 180 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 181 | return msg_src_droppable(&tsk->phdr) != 0; |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 184 | static void tsk_set_unreliable(struct tipc_sock *tsk, bool unreliable) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 185 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 186 | msg_set_src_droppable(&tsk->phdr, unreliable ? 1 : 0); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 189 | static bool tsk_unreturnable(struct tipc_sock *tsk) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 190 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 191 | return msg_dest_droppable(&tsk->phdr) != 0; |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 194 | static void tsk_set_unreturnable(struct tipc_sock *tsk, bool unreturnable) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 195 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 196 | msg_set_dest_droppable(&tsk->phdr, unreturnable ? 1 : 0); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 199 | static int tsk_importance(struct tipc_sock *tsk) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 200 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 201 | return msg_importance(&tsk->phdr); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 204 | static int tsk_set_importance(struct tipc_sock *tsk, int imp) |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 205 | { |
| 206 | if (imp > TIPC_CRITICAL_IMPORTANCE) |
| 207 | return -EINVAL; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 208 | msg_set_importance(&tsk->phdr, (u32)imp); |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 209 | return 0; |
| 210 | } |
Jon Paul Maloy | 8826cde | 2014-03-12 11:31:09 -0400 | [diff] [blame] | 211 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 212 | static struct tipc_sock *tipc_sk(const struct sock *sk) |
| 213 | { |
| 214 | return container_of(sk, struct tipc_sock, sk); |
| 215 | } |
| 216 | |
| 217 | static int tsk_conn_cong(struct tipc_sock *tsk) |
| 218 | { |
| 219 | return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN; |
| 220 | } |
| 221 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 222 | /** |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 223 | * tsk_advance_rx_queue - discard first buffer in socket receive queue |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 224 | * |
| 225 | * Caller must hold socket lock |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 226 | */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 227 | static void tsk_advance_rx_queue(struct sock *sk) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 228 | { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 229 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 233 | * tsk_rej_rx_queue - reject all buffers in socket receive queue |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 234 | * |
| 235 | * Caller must hold socket lock |
| 236 | */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 237 | static void tsk_rej_rx_queue(struct sock *sk) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 238 | { |
| 239 | struct sk_buff *buf; |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 240 | u32 dnode; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 241 | |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 242 | while ((buf = __skb_dequeue(&sk->sk_receive_queue))) { |
| 243 | if (tipc_msg_reverse(buf, &dnode, TIPC_ERR_NO_PORT)) |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 244 | tipc_link_xmit(buf, dnode, 0); |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 245 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 248 | /* tsk_peer_msg - verify if message was sent by connected port's peer |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 249 | * |
| 250 | * Handles cases where the node's network address has changed from |
| 251 | * the default of <0.0.0> to its configured setting. |
| 252 | */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 253 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 254 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 255 | u32 peer_port = tsk_peer_port(tsk); |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 256 | u32 orig_node; |
| 257 | u32 peer_node; |
| 258 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 259 | if (unlikely(!tsk->connected)) |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 260 | return false; |
| 261 | |
| 262 | if (unlikely(msg_origport(msg) != peer_port)) |
| 263 | return false; |
| 264 | |
| 265 | orig_node = msg_orignode(msg); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 266 | peer_node = tsk_peer_node(tsk); |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 267 | |
| 268 | if (likely(orig_node == peer_node)) |
| 269 | return true; |
| 270 | |
| 271 | if (!orig_node && (peer_node == tipc_own_addr)) |
| 272 | return true; |
| 273 | |
| 274 | if (!peer_node && (orig_node == tipc_own_addr)) |
| 275 | return true; |
| 276 | |
| 277 | return false; |
| 278 | } |
| 279 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 280 | /** |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 281 | * tipc_sk_create - create a TIPC socket |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 282 | * @net: network namespace (must be default network) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 283 | * @sock: pre-allocated socket structure |
| 284 | * @protocol: protocol indicator (must be 0) |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 285 | * @kern: caused by kernel or by userspace? |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 286 | * |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 287 | * This routine creates additional data structures used by the TIPC socket, |
| 288 | * initializes them, and links them together. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 289 | * |
| 290 | * Returns 0 on success, errno otherwise |
| 291 | */ |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 292 | static int tipc_sk_create(struct net *net, struct socket *sock, |
| 293 | int protocol, int kern) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 294 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 295 | const struct proto_ops *ops; |
| 296 | socket_state state; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 297 | struct sock *sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 298 | struct tipc_sock *tsk; |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 299 | struct tipc_msg *msg; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 300 | u32 ref; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 301 | |
| 302 | /* Validate arguments */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 303 | if (unlikely(protocol != 0)) |
| 304 | return -EPROTONOSUPPORT; |
| 305 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 306 | switch (sock->type) { |
| 307 | case SOCK_STREAM: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 308 | ops = &stream_ops; |
| 309 | state = SS_UNCONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 310 | break; |
| 311 | case SOCK_SEQPACKET: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 312 | ops = &packet_ops; |
| 313 | state = SS_UNCONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 314 | break; |
| 315 | case SOCK_DGRAM: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 316 | case SOCK_RDM: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 317 | ops = &msg_ops; |
| 318 | state = SS_READY; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 319 | break; |
Allan Stephens | 4997865 | 2006-06-25 23:47:18 -0700 | [diff] [blame] | 320 | default: |
Allan Stephens | 4997865 | 2006-06-25 23:47:18 -0700 | [diff] [blame] | 321 | return -EPROTOTYPE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 324 | /* Allocate socket's protocol area */ |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 325 | if (!kern) |
| 326 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto); |
| 327 | else |
| 328 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto_kern); |
| 329 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 330 | if (sk == NULL) |
| 331 | return -ENOMEM; |
| 332 | |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 333 | tsk = tipc_sk(sk); |
Jon Paul Maloy | 808d90f | 2014-08-22 18:09:19 -0400 | [diff] [blame] | 334 | ref = tipc_sk_ref_acquire(tsk); |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 335 | if (!ref) { |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 336 | pr_warn("Socket create failed; reference table exhausted\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 337 | return -ENOMEM; |
| 338 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 339 | tsk->max_pkt = MAX_PKT_DEFAULT; |
| 340 | tsk->ref = ref; |
| 341 | INIT_LIST_HEAD(&tsk->publications); |
| 342 | msg = &tsk->phdr; |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 343 | tipc_msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, |
| 344 | NAMED_H_SIZE, 0); |
| 345 | msg_set_origport(msg, ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 347 | /* Finish initializing socket data structures */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 348 | sock->ops = ops; |
| 349 | sock->state = state; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 350 | sock_init_data(sock, sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 351 | k_init_timer(&tsk->timer, (Handler)tipc_sk_timeout, ref); |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 352 | sk->sk_backlog_rcv = tipc_backlog_rcv; |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 353 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 354 | sk->sk_data_ready = tipc_data_ready; |
| 355 | sk->sk_write_space = tipc_write_space; |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 356 | tsk->conn_timeout = CONN_TIMEOUT_DEFAULT; |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 357 | tsk->sent_unacked = 0; |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 358 | atomic_set(&tsk->dupl_rcvcnt, 0); |
Allan Stephens | 7ef43eb | 2008-05-12 15:42:28 -0700 | [diff] [blame] | 359 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 360 | if (sock->state == SS_READY) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 361 | tsk_set_unreturnable(tsk, true); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 362 | if (sock->type == SOCK_DGRAM) |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 363 | tsk_set_unreliable(tsk, true); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 364 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /** |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 369 | * tipc_sock_create_local - create TIPC socket from inside TIPC module |
| 370 | * @type: socket type - SOCK_RDM or SOCK_SEQPACKET |
| 371 | * |
| 372 | * We cannot use sock_creat_kern here because it bumps module user count. |
| 373 | * Since socket owner and creator is the same module we must make sure |
| 374 | * that module count remains zero for module local sockets, otherwise |
| 375 | * we cannot do rmmod. |
| 376 | * |
| 377 | * Returns 0 on success, errno otherwise |
| 378 | */ |
| 379 | int tipc_sock_create_local(int type, struct socket **res) |
| 380 | { |
| 381 | int rc; |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 382 | |
| 383 | rc = sock_create_lite(AF_TIPC, type, 0, res); |
| 384 | if (rc < 0) { |
| 385 | pr_err("Failed to create kernel socket\n"); |
| 386 | return rc; |
| 387 | } |
| 388 | tipc_sk_create(&init_net, *res, 0, 1); |
| 389 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * tipc_sock_release_local - release socket created by tipc_sock_create_local |
| 395 | * @sock: the socket to be released. |
| 396 | * |
| 397 | * Module reference count is not incremented when such sockets are created, |
| 398 | * so we must keep it from being decremented when they are released. |
| 399 | */ |
| 400 | void tipc_sock_release_local(struct socket *sock) |
| 401 | { |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 402 | tipc_release(sock); |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 403 | sock->ops = NULL; |
| 404 | sock_release(sock); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * tipc_sock_accept_local - accept a connection on a socket created |
| 409 | * with tipc_sock_create_local. Use this function to avoid that |
| 410 | * module reference count is inadvertently incremented. |
| 411 | * |
| 412 | * @sock: the accepting socket |
| 413 | * @newsock: reference to the new socket to be created |
| 414 | * @flags: socket flags |
| 415 | */ |
| 416 | |
| 417 | int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 418 | int flags) |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 419 | { |
| 420 | struct sock *sk = sock->sk; |
| 421 | int ret; |
| 422 | |
| 423 | ret = sock_create_lite(sk->sk_family, sk->sk_type, |
| 424 | sk->sk_protocol, newsock); |
| 425 | if (ret < 0) |
| 426 | return ret; |
| 427 | |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 428 | ret = tipc_accept(sock, *newsock, flags); |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 429 | if (ret < 0) { |
| 430 | sock_release(*newsock); |
| 431 | return ret; |
| 432 | } |
| 433 | (*newsock)->ops = sock->ops; |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 438 | * tipc_release - destroy a TIPC socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 439 | * @sock: socket to destroy |
| 440 | * |
| 441 | * This routine cleans up any messages that are still queued on the socket. |
| 442 | * For DGRAM and RDM socket types, all queued messages are rejected. |
| 443 | * For SEQPACKET and STREAM socket types, the first message is rejected |
| 444 | * and any others are discarded. (If the first message on a STREAM socket |
| 445 | * is partially-read, it is discarded and the next one is rejected instead.) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 446 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 447 | * NOTE: Rejected messages are not necessarily returned to the sender! They |
| 448 | * are returned or discarded according to the "destination droppable" setting |
| 449 | * specified for the message by the sender. |
| 450 | * |
| 451 | * Returns 0 on success, errno otherwise |
| 452 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 453 | static int tipc_release(struct socket *sock) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 454 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 455 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 456 | struct tipc_sock *tsk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 457 | struct sk_buff *buf; |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 458 | u32 dnode; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 459 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 460 | /* |
| 461 | * Exit if socket isn't fully initialized (occurs when a failed accept() |
| 462 | * releases a pre-allocated child socket that was never used) |
| 463 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 464 | if (sk == NULL) |
| 465 | return 0; |
| 466 | |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 467 | tsk = tipc_sk(sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 468 | lock_sock(sk); |
| 469 | |
| 470 | /* |
| 471 | * Reject all unreceived messages, except on an active connection |
| 472 | * (which disconnects locally & sends a 'FIN+' to peer) |
| 473 | */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 474 | dnode = tsk_peer_node(tsk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 475 | while (sock->state != SS_DISCONNECTING) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 476 | buf = __skb_dequeue(&sk->sk_receive_queue); |
| 477 | if (buf == NULL) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 478 | break; |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 479 | if (TIPC_SKB_CB(buf)->handle != NULL) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 480 | kfree_skb(buf); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 481 | else { |
| 482 | if ((sock->state == SS_CONNECTING) || |
| 483 | (sock->state == SS_CONNECTED)) { |
| 484 | sock->state = SS_DISCONNECTING; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 485 | tsk->connected = 0; |
| 486 | tipc_node_remove_conn(dnode, tsk->ref); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 487 | } |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 488 | if (tipc_msg_reverse(buf, &dnode, TIPC_ERR_NO_PORT)) |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 489 | tipc_link_xmit(buf, dnode, 0); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 490 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 491 | } |
| 492 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 493 | tipc_sk_withdraw(tsk, 0, NULL); |
| 494 | tipc_sk_ref_discard(tsk->ref); |
| 495 | k_cancel_timer(&tsk->timer); |
| 496 | if (tsk->connected) { |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 497 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, |
| 498 | SHORT_H_SIZE, 0, dnode, tipc_own_addr, |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 499 | tsk_peer_port(tsk), |
| 500 | tsk->ref, TIPC_ERR_NO_PORT); |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 501 | if (buf) |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 502 | tipc_link_xmit(buf, dnode, tsk->ref); |
| 503 | tipc_node_remove_conn(dnode, tsk->ref); |
Jon Paul Maloy | 5b8fa7c | 2014-08-22 18:09:13 -0400 | [diff] [blame] | 504 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 505 | k_term_timer(&tsk->timer); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 506 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 507 | /* Discard any remaining (connection-based) messages in receive queue */ |
Ying Xue | 57467e5 | 2013-01-20 23:30:08 +0100 | [diff] [blame] | 508 | __skb_queue_purge(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 509 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 510 | /* Reject any messages that accumulated in backlog queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 511 | sock->state = SS_DISCONNECTING; |
| 512 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 513 | sock_put(sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 514 | sock->sk = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | |
Geert Uytterhoeven | 065d7e3 | 2014-04-06 15:56:14 +0200 | [diff] [blame] | 516 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 520 | * tipc_bind - associate or disassocate TIPC name(s) with a socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 521 | * @sock: socket structure |
| 522 | * @uaddr: socket address describing name(s) and desired operation |
| 523 | * @uaddr_len: size of socket address data structure |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 524 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 525 | * Name and name sequence binding is indicated using a positive scope value; |
| 526 | * a negative scope value unbinds the specified name. Specifying no name |
| 527 | * (i.e. a socket address length of 0) unbinds all names from the socket. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 528 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 529 | * Returns 0 on success, errno otherwise |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 530 | * |
| 531 | * NOTE: This routine doesn't need to take the socket lock since it doesn't |
| 532 | * access any non-constant socket information. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 533 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 534 | static int tipc_bind(struct socket *sock, struct sockaddr *uaddr, |
| 535 | int uaddr_len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 536 | { |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 537 | struct sock *sk = sock->sk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 538 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 539 | struct tipc_sock *tsk = tipc_sk(sk); |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 540 | int res = -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 541 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 542 | lock_sock(sk); |
| 543 | if (unlikely(!uaddr_len)) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 544 | res = tipc_sk_withdraw(tsk, 0, NULL); |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 545 | goto exit; |
| 546 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 547 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 548 | if (uaddr_len < sizeof(struct sockaddr_tipc)) { |
| 549 | res = -EINVAL; |
| 550 | goto exit; |
| 551 | } |
| 552 | if (addr->family != AF_TIPC) { |
| 553 | res = -EAFNOSUPPORT; |
| 554 | goto exit; |
| 555 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 556 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 557 | if (addr->addrtype == TIPC_ADDR_NAME) |
| 558 | addr->addr.nameseq.upper = addr->addr.nameseq.lower; |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 559 | else if (addr->addrtype != TIPC_ADDR_NAMESEQ) { |
| 560 | res = -EAFNOSUPPORT; |
| 561 | goto exit; |
| 562 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 563 | |
Ying Xue | 13a2e89 | 2013-06-17 10:54:40 -0400 | [diff] [blame] | 564 | if ((addr->addr.nameseq.type < TIPC_RESERVED_TYPES) && |
Ying Xue | 7d0ab17 | 2013-06-17 10:54:41 -0400 | [diff] [blame] | 565 | (addr->addr.nameseq.type != TIPC_TOP_SRV) && |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 566 | (addr->addr.nameseq.type != TIPC_CFG_SRV)) { |
| 567 | res = -EACCES; |
| 568 | goto exit; |
| 569 | } |
Allan Stephens | c422f1b | 2011-11-02 15:49:40 -0400 | [diff] [blame] | 570 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 571 | res = (addr->scope > 0) ? |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 572 | tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) : |
| 573 | tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq); |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 574 | exit: |
| 575 | release_sock(sk); |
| 576 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 577 | } |
| 578 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 579 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 580 | * tipc_getname - get port ID of socket or peer socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 581 | * @sock: socket structure |
| 582 | * @uaddr: area for returned socket address |
| 583 | * @uaddr_len: area for returned length of socket address |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 584 | * @peer: 0 = own ID, 1 = current peer ID, 2 = current/former peer ID |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 585 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 586 | * Returns 0 on success, errno otherwise |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 587 | * |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 588 | * NOTE: This routine doesn't need to take the socket lock since it only |
| 589 | * accesses socket information that is unchanging (or which changes in |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 590 | * a completely predictable manner). |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 591 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 592 | static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, |
| 593 | int *uaddr_len, int peer) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 594 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 595 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 596 | struct tipc_sock *tsk = tipc_sk(sock->sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 597 | |
Kulikov Vasiliy | 88f8a5e | 2010-10-31 07:10:32 +0000 | [diff] [blame] | 598 | memset(addr, 0, sizeof(*addr)); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 599 | if (peer) { |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 600 | if ((sock->state != SS_CONNECTED) && |
| 601 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) |
| 602 | return -ENOTCONN; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 603 | addr->addr.id.ref = tsk_peer_port(tsk); |
| 604 | addr->addr.id.node = tsk_peer_node(tsk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 605 | } else { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 606 | addr->addr.id.ref = tsk->ref; |
Allan Stephens | b924dcf | 2010-11-30 12:01:03 +0000 | [diff] [blame] | 607 | addr->addr.id.node = tipc_own_addr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 608 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 609 | |
| 610 | *uaddr_len = sizeof(*addr); |
| 611 | addr->addrtype = TIPC_ADDR_ID; |
| 612 | addr->family = AF_TIPC; |
| 613 | addr->scope = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 614 | addr->addr.name.domain = 0; |
| 615 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 616 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 620 | * tipc_poll - read and possibly block on pollmask |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 621 | * @file: file structure associated with the socket |
| 622 | * @sock: socket for which to calculate the poll bits |
| 623 | * @wait: ??? |
| 624 | * |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 625 | * Returns pollmask value |
| 626 | * |
| 627 | * COMMENTARY: |
| 628 | * It appears that the usual socket locking mechanisms are not useful here |
| 629 | * since the pollmask info is potentially out-of-date the moment this routine |
| 630 | * exits. TCP and other protocols seem to rely on higher level poll routines |
| 631 | * to handle any preventable race conditions, so TIPC will do the same ... |
| 632 | * |
| 633 | * TIPC sets the returned events as follows: |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 634 | * |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 635 | * socket state flags set |
| 636 | * ------------ --------- |
| 637 | * unconnected no read flags |
Erik Hugne | c4fc298 | 2012-10-16 16:47:06 +0200 | [diff] [blame] | 638 | * POLLOUT if port is not congested |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 639 | * |
| 640 | * connecting POLLIN/POLLRDNORM if ACK/NACK in rx queue |
| 641 | * no write flags |
| 642 | * |
| 643 | * connected POLLIN/POLLRDNORM if data in rx queue |
| 644 | * POLLOUT if port is not congested |
| 645 | * |
| 646 | * disconnecting POLLIN/POLLRDNORM/POLLHUP |
| 647 | * no write flags |
| 648 | * |
| 649 | * listening POLLIN if SYN in rx queue |
| 650 | * no write flags |
| 651 | * |
| 652 | * ready POLLIN/POLLRDNORM if data in rx queue |
| 653 | * [connectionless] POLLOUT (since port cannot be congested) |
| 654 | * |
| 655 | * IMPORTANT: The fact that a read or write operation is indicated does NOT |
| 656 | * imply that the operation will succeed, merely that it should be performed |
| 657 | * and will not block. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 658 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 659 | static unsigned int tipc_poll(struct file *file, struct socket *sock, |
| 660 | poll_table *wait) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 661 | { |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 662 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 663 | struct tipc_sock *tsk = tipc_sk(sk); |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 664 | u32 mask = 0; |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 665 | |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 666 | sock_poll_wait(file, sk_sleep(sk), wait); |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 667 | |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 668 | switch ((int)sock->state) { |
Erik Hugne | c4fc298 | 2012-10-16 16:47:06 +0200 | [diff] [blame] | 669 | case SS_UNCONNECTED: |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 670 | if (!tsk->link_cong) |
Erik Hugne | c4fc298 | 2012-10-16 16:47:06 +0200 | [diff] [blame] | 671 | mask |= POLLOUT; |
| 672 | break; |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 673 | case SS_READY: |
| 674 | case SS_CONNECTED: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 675 | if (!tsk->link_cong && !tsk_conn_cong(tsk)) |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 676 | mask |= POLLOUT; |
| 677 | /* fall thru' */ |
| 678 | case SS_CONNECTING: |
| 679 | case SS_LISTENING: |
| 680 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 681 | mask |= (POLLIN | POLLRDNORM); |
| 682 | break; |
| 683 | case SS_DISCONNECTING: |
| 684 | mask = (POLLIN | POLLRDNORM | POLLHUP); |
| 685 | break; |
| 686 | } |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 687 | |
| 688 | return mask; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Jon Paul Maloy | 0abd8ff | 2014-07-16 20:41:01 -0400 | [diff] [blame] | 691 | /** |
| 692 | * tipc_sendmcast - send multicast message |
| 693 | * @sock: socket structure |
| 694 | * @seq: destination address |
| 695 | * @iov: message data to send |
| 696 | * @dsz: total length of message data |
| 697 | * @timeo: timeout to wait for wakeup |
| 698 | * |
| 699 | * Called from function tipc_sendmsg(), which has done all sanity checks |
| 700 | * Returns the number of bytes sent on success, or errno |
| 701 | */ |
| 702 | static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, |
| 703 | struct iovec *iov, size_t dsz, long timeo) |
| 704 | { |
| 705 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 706 | struct tipc_msg *mhdr = &tipc_sk(sk)->phdr; |
Jon Paul Maloy | 0abd8ff | 2014-07-16 20:41:01 -0400 | [diff] [blame] | 707 | struct sk_buff *buf; |
| 708 | uint mtu; |
| 709 | int rc; |
| 710 | |
| 711 | msg_set_type(mhdr, TIPC_MCAST_MSG); |
| 712 | msg_set_lookup_scope(mhdr, TIPC_CLUSTER_SCOPE); |
| 713 | msg_set_destport(mhdr, 0); |
| 714 | msg_set_destnode(mhdr, 0); |
| 715 | msg_set_nametype(mhdr, seq->type); |
| 716 | msg_set_namelower(mhdr, seq->lower); |
| 717 | msg_set_nameupper(mhdr, seq->upper); |
| 718 | msg_set_hdr_sz(mhdr, MCAST_H_SIZE); |
| 719 | |
| 720 | new_mtu: |
| 721 | mtu = tipc_bclink_get_mtu(); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 722 | rc = tipc_msg_build(mhdr, iov, 0, dsz, mtu, &buf); |
Jon Paul Maloy | 0abd8ff | 2014-07-16 20:41:01 -0400 | [diff] [blame] | 723 | if (unlikely(rc < 0)) |
| 724 | return rc; |
| 725 | |
| 726 | do { |
| 727 | rc = tipc_bclink_xmit(buf); |
| 728 | if (likely(rc >= 0)) { |
| 729 | rc = dsz; |
| 730 | break; |
| 731 | } |
| 732 | if (rc == -EMSGSIZE) |
| 733 | goto new_mtu; |
| 734 | if (rc != -ELINKCONG) |
| 735 | break; |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 736 | tipc_sk(sk)->link_cong = 1; |
Jon Paul Maloy | 0abd8ff | 2014-07-16 20:41:01 -0400 | [diff] [blame] | 737 | rc = tipc_wait_for_sndmsg(sock, &timeo); |
| 738 | if (rc) |
| 739 | kfree_skb_list(buf); |
| 740 | } while (!rc); |
| 741 | return rc; |
| 742 | } |
| 743 | |
Jon Paul Maloy | 078bec8 | 2014-07-16 20:41:00 -0400 | [diff] [blame] | 744 | /* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets |
| 745 | */ |
| 746 | void tipc_sk_mcast_rcv(struct sk_buff *buf) |
| 747 | { |
| 748 | struct tipc_msg *msg = buf_msg(buf); |
| 749 | struct tipc_port_list dports = {0, NULL, }; |
| 750 | struct tipc_port_list *item; |
| 751 | struct sk_buff *b; |
| 752 | uint i, last, dst = 0; |
| 753 | u32 scope = TIPC_CLUSTER_SCOPE; |
| 754 | |
| 755 | if (in_own_node(msg_orignode(msg))) |
| 756 | scope = TIPC_NODE_SCOPE; |
| 757 | |
| 758 | /* Create destination port list: */ |
| 759 | tipc_nametbl_mc_translate(msg_nametype(msg), |
| 760 | msg_namelower(msg), |
| 761 | msg_nameupper(msg), |
| 762 | scope, |
| 763 | &dports); |
| 764 | last = dports.count; |
| 765 | if (!last) { |
| 766 | kfree_skb(buf); |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | for (item = &dports; item; item = item->next) { |
| 771 | for (i = 0; i < PLSIZE && ++dst <= last; i++) { |
| 772 | b = (dst != last) ? skb_clone(buf, GFP_ATOMIC) : buf; |
| 773 | if (!b) { |
| 774 | pr_warn("Failed do clone mcast rcv buffer\n"); |
| 775 | continue; |
| 776 | } |
| 777 | msg_set_destport(msg, item->ports[i]); |
| 778 | tipc_sk_rcv(b); |
| 779 | } |
| 780 | } |
| 781 | tipc_port_list_free(&dports); |
| 782 | } |
| 783 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 784 | /** |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 785 | * tipc_sk_proto_rcv - receive a connection mng protocol message |
| 786 | * @tsk: receiving socket |
| 787 | * @dnode: node to send response message to, if any |
| 788 | * @buf: buffer containing protocol message |
| 789 | * Returns 0 (TIPC_OK) if message was consumed, 1 (TIPC_FWD_MSG) if |
| 790 | * (CONN_PROBE_REPLY) message should be forwarded. |
| 791 | */ |
Wei Yongjun | 52f50ce | 2014-07-20 13:14:28 +0800 | [diff] [blame] | 792 | static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode, |
| 793 | struct sk_buff *buf) |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 794 | { |
| 795 | struct tipc_msg *msg = buf_msg(buf); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 796 | int conn_cong; |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 797 | |
| 798 | /* Ignore if connection cannot be validated: */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 799 | if (!tsk_peer_msg(tsk, msg)) |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 800 | goto exit; |
| 801 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 802 | tsk->probing_state = TIPC_CONN_OK; |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 803 | |
| 804 | if (msg_type(msg) == CONN_ACK) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 805 | conn_cong = tsk_conn_cong(tsk); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 806 | tsk->sent_unacked -= msg_msgcnt(msg); |
| 807 | if (conn_cong) |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 808 | tsk->sk.sk_write_space(&tsk->sk); |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 809 | } else if (msg_type(msg) == CONN_PROBE) { |
| 810 | if (!tipc_msg_reverse(buf, dnode, TIPC_OK)) |
| 811 | return TIPC_OK; |
| 812 | msg_set_type(msg, CONN_PROBE_REPLY); |
| 813 | return TIPC_FWD_MSG; |
| 814 | } |
| 815 | /* Do nothing if msg_type() == CONN_PROBE_REPLY */ |
| 816 | exit: |
| 817 | kfree_skb(buf); |
| 818 | return TIPC_OK; |
| 819 | } |
| 820 | |
| 821 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 822 | * dest_name_check - verify user is permitted to send to specified port name |
| 823 | * @dest: destination address |
| 824 | * @m: descriptor for message to be sent |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 825 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 826 | * Prevents restricted configuration commands from being issued by |
| 827 | * unauthorized users. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 828 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 829 | * Returns 0 if permission is granted, otherwise errno |
| 830 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 831 | static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 832 | { |
| 833 | struct tipc_cfg_msg_hdr hdr; |
| 834 | |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 835 | if (unlikely(dest->addrtype == TIPC_ADDR_ID)) |
| 836 | return 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 837 | if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES)) |
| 838 | return 0; |
| 839 | if (likely(dest->addr.name.name.type == TIPC_TOP_SRV)) |
| 840 | return 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 841 | if (likely(dest->addr.name.name.type != TIPC_CFG_SRV)) |
| 842 | return -EACCES; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 843 | |
Allan Stephens | 3f8dd94 | 2011-01-18 13:09:29 -0500 | [diff] [blame] | 844 | if (!m->msg_iovlen || (m->msg_iov[0].iov_len < sizeof(hdr))) |
| 845 | return -EMSGSIZE; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 846 | if (copy_from_user(&hdr, m->msg_iov[0].iov_base, sizeof(hdr))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 847 | return -EFAULT; |
Allan Stephens | 70cb234 | 2006-06-25 23:41:47 -0700 | [diff] [blame] | 848 | if ((ntohs(hdr.tcm_type) & 0xC000) && (!capable(CAP_NET_ADMIN))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 849 | return -EACCES; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 850 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame] | 854 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) |
| 855 | { |
| 856 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 857 | struct tipc_sock *tsk = tipc_sk(sk); |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame] | 858 | DEFINE_WAIT(wait); |
| 859 | int done; |
| 860 | |
| 861 | do { |
| 862 | int err = sock_error(sk); |
| 863 | if (err) |
| 864 | return err; |
| 865 | if (sock->state == SS_DISCONNECTING) |
| 866 | return -EPIPE; |
| 867 | if (!*timeo_p) |
| 868 | return -EAGAIN; |
| 869 | if (signal_pending(current)) |
| 870 | return sock_intr_errno(*timeo_p); |
| 871 | |
| 872 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 873 | done = sk_wait_event(sk, timeo_p, !tsk->link_cong); |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame] | 874 | finish_wait(sk_sleep(sk), &wait); |
| 875 | } while (!done); |
| 876 | return 0; |
| 877 | } |
| 878 | |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 879 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 880 | * tipc_sendmsg - send message in connectionless manner |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 881 | * @iocb: if NULL, indicates that socket lock is already held |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 882 | * @sock: socket structure |
| 883 | * @m: message to send |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 884 | * @dsz: amount of user data to be sent |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 885 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 886 | * Message must have an destination specified explicitly. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 887 | * Used for SOCK_RDM and SOCK_DGRAM messages, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 888 | * and for 'SYN' messages on SOCK_SEQPACKET and SOCK_STREAM connections. |
| 889 | * (Note: 'SYN+' is prohibited on SOCK_STREAM.) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 890 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 891 | * Returns the number of bytes sent on success, or errno otherwise |
| 892 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 893 | static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 894 | struct msghdr *m, size_t dsz) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 895 | { |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 896 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 897 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 898 | struct tipc_sock *tsk = tipc_sk(sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 899 | struct tipc_msg *mhdr = &tsk->phdr; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 900 | struct iovec *iov = m->msg_iov; |
| 901 | u32 dnode, dport; |
| 902 | struct sk_buff *buf; |
| 903 | struct tipc_name_seq *seq = &dest->addr.nameseq; |
| 904 | u32 mtu; |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame] | 905 | long timeo; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 906 | int rc = -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 907 | |
| 908 | if (unlikely(!dest)) |
| 909 | return -EDESTADDRREQ; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 910 | |
Allan Stephens | 51f9cc1 | 2006-06-25 23:49:06 -0700 | [diff] [blame] | 911 | if (unlikely((m->msg_namelen < sizeof(*dest)) || |
| 912 | (dest->family != AF_TIPC))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 913 | return -EINVAL; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 914 | |
| 915 | if (dsz > TIPC_MAX_USER_MSG_SIZE) |
Allan Stephens | c29c3f7 | 2010-04-20 17:58:24 -0400 | [diff] [blame] | 916 | return -EMSGSIZE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 917 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 918 | if (iocb) |
| 919 | lock_sock(sk); |
| 920 | |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 921 | if (unlikely(sock->state != SS_READY)) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 922 | if (sock->state == SS_LISTENING) { |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 923 | rc = -EPIPE; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 924 | goto exit; |
Allan Stephens | 3388007 | 2006-06-25 23:44:57 -0700 | [diff] [blame] | 925 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 926 | if (sock->state != SS_UNCONNECTED) { |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 927 | rc = -EISCONN; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 928 | goto exit; |
| 929 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 930 | if (tsk->published) { |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 931 | rc = -EOPNOTSUPP; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 932 | goto exit; |
| 933 | } |
| 934 | if (dest->addrtype == TIPC_ADDR_NAME) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 935 | tsk->conn_type = dest->addr.name.name.type; |
| 936 | tsk->conn_instance = dest->addr.name.name.instance; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 937 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 938 | } |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 939 | rc = dest_name_check(dest, m); |
| 940 | if (rc) |
| 941 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 942 | |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame] | 943 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 944 | |
| 945 | if (dest->addrtype == TIPC_ADDR_MCAST) { |
| 946 | rc = tipc_sendmcast(sock, seq, iov, dsz, timeo); |
| 947 | goto exit; |
| 948 | } else if (dest->addrtype == TIPC_ADDR_NAME) { |
| 949 | u32 type = dest->addr.name.name.type; |
| 950 | u32 inst = dest->addr.name.name.instance; |
| 951 | u32 domain = dest->addr.name.domain; |
| 952 | |
| 953 | dnode = domain; |
| 954 | msg_set_type(mhdr, TIPC_NAMED_MSG); |
| 955 | msg_set_hdr_sz(mhdr, NAMED_H_SIZE); |
| 956 | msg_set_nametype(mhdr, type); |
| 957 | msg_set_nameinst(mhdr, inst); |
| 958 | msg_set_lookup_scope(mhdr, tipc_addr_scope(domain)); |
| 959 | dport = tipc_nametbl_translate(type, inst, &dnode); |
| 960 | msg_set_destnode(mhdr, dnode); |
| 961 | msg_set_destport(mhdr, dport); |
| 962 | if (unlikely(!dport && !dnode)) { |
| 963 | rc = -EHOSTUNREACH; |
| 964 | goto exit; |
| 965 | } |
| 966 | } else if (dest->addrtype == TIPC_ADDR_ID) { |
| 967 | dnode = dest->addr.id.node; |
| 968 | msg_set_type(mhdr, TIPC_DIRECT_MSG); |
| 969 | msg_set_lookup_scope(mhdr, 0); |
| 970 | msg_set_destnode(mhdr, dnode); |
| 971 | msg_set_destport(mhdr, dest->addr.id.ref); |
| 972 | msg_set_hdr_sz(mhdr, BASIC_H_SIZE); |
| 973 | } |
| 974 | |
| 975 | new_mtu: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 976 | mtu = tipc_node_get_mtu(dnode, tsk->ref); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 977 | rc = tipc_msg_build(mhdr, iov, 0, dsz, mtu, &buf); |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 978 | if (rc < 0) |
| 979 | goto exit; |
| 980 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 981 | do { |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 982 | TIPC_SKB_CB(buf)->wakeup_pending = tsk->link_cong; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 983 | rc = tipc_link_xmit(buf, dnode, tsk->ref); |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 984 | if (likely(rc >= 0)) { |
| 985 | if (sock->state != SS_READY) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 986 | sock->state = SS_CONNECTING; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 987 | rc = dsz; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 988 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 989 | } |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 990 | if (rc == -EMSGSIZE) |
| 991 | goto new_mtu; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 992 | if (rc != -ELINKCONG) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 993 | break; |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 994 | tsk->link_cong = 1; |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 995 | rc = tipc_wait_for_sndmsg(sock, &timeo); |
Erik Hugne | 70452dc | 2014-07-06 20:38:50 -0400 | [diff] [blame] | 996 | if (rc) |
| 997 | kfree_skb_list(buf); |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 998 | } while (!rc); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 999 | exit: |
| 1000 | if (iocb) |
| 1001 | release_sock(sk); |
Jon Paul Maloy | e2dafe8 | 2014-06-25 20:41:37 -0500 | [diff] [blame] | 1002 | |
| 1003 | return rc; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
Ying Xue | 391a6dd | 2014-01-17 09:50:06 +0800 | [diff] [blame] | 1006 | static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) |
| 1007 | { |
| 1008 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1009 | struct tipc_sock *tsk = tipc_sk(sk); |
Ying Xue | 391a6dd | 2014-01-17 09:50:06 +0800 | [diff] [blame] | 1010 | DEFINE_WAIT(wait); |
| 1011 | int done; |
| 1012 | |
| 1013 | do { |
| 1014 | int err = sock_error(sk); |
| 1015 | if (err) |
| 1016 | return err; |
| 1017 | if (sock->state == SS_DISCONNECTING) |
| 1018 | return -EPIPE; |
| 1019 | else if (sock->state != SS_CONNECTED) |
| 1020 | return -ENOTCONN; |
| 1021 | if (!*timeo_p) |
| 1022 | return -EAGAIN; |
| 1023 | if (signal_pending(current)) |
| 1024 | return sock_intr_errno(*timeo_p); |
| 1025 | |
| 1026 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 1027 | done = sk_wait_event(sk, timeo_p, |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1028 | (!tsk->link_cong && |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1029 | !tsk_conn_cong(tsk)) || |
| 1030 | !tsk->connected); |
Ying Xue | 391a6dd | 2014-01-17 09:50:06 +0800 | [diff] [blame] | 1031 | finish_wait(sk_sleep(sk), &wait); |
| 1032 | } while (!done); |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1036 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1037 | * tipc_send_stream - send stream-oriented data |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1038 | * @iocb: (unused) |
| 1039 | * @sock: socket structure |
| 1040 | * @m: data to send |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1041 | * @dsz: total length of data to be transmitted |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1042 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1043 | * Used for SOCK_STREAM data. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1044 | * |
| 1045 | * Returns the number of bytes sent on success (or partial success), |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 1046 | * or errno if no data sent |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1047 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1048 | static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1049 | struct msghdr *m, size_t dsz) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1050 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1051 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1052 | struct tipc_sock *tsk = tipc_sk(sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1053 | struct tipc_msg *mhdr = &tsk->phdr; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1054 | struct sk_buff *buf; |
| 1055 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1056 | u32 ref = tsk->ref; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1057 | int rc = -EINVAL; |
| 1058 | long timeo; |
| 1059 | u32 dnode; |
| 1060 | uint mtu, send, sent = 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1061 | |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1062 | /* Handle implied connection establishment */ |
| 1063 | if (unlikely(dest)) { |
| 1064 | rc = tipc_sendmsg(iocb, sock, m, dsz); |
| 1065 | if (dsz && (dsz == rc)) |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1066 | tsk->sent_unacked = 1; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1067 | return rc; |
| 1068 | } |
| 1069 | if (dsz > (uint)INT_MAX) |
| 1070 | return -EMSGSIZE; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1071 | |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1072 | if (iocb) |
| 1073 | lock_sock(sk); |
| 1074 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1075 | if (unlikely(sock->state != SS_CONNECTED)) { |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1076 | if (sock->state == SS_DISCONNECTING) |
| 1077 | rc = -EPIPE; |
wangweidong | b055597 | 2013-12-27 10:09:39 +0800 | [diff] [blame] | 1078 | else |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1079 | rc = -ENOTCONN; |
wangweidong | 3b8401f | 2013-12-12 09:36:40 +0800 | [diff] [blame] | 1080 | goto exit; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1081 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1082 | |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1083 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1084 | dnode = tsk_peer_node(tsk); |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1085 | |
| 1086 | next: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1087 | mtu = tsk->max_pkt; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1088 | send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE); |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 1089 | rc = tipc_msg_build(mhdr, m->msg_iov, sent, send, mtu, &buf); |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1090 | if (unlikely(rc < 0)) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1091 | goto exit; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1092 | do { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1093 | if (likely(!tsk_conn_cong(tsk))) { |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 1094 | rc = tipc_link_xmit(buf, dnode, ref); |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1095 | if (likely(!rc)) { |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1096 | tsk->sent_unacked++; |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1097 | sent += send; |
| 1098 | if (sent == dsz) |
| 1099 | break; |
| 1100 | goto next; |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 1101 | } |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1102 | if (rc == -EMSGSIZE) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1103 | tsk->max_pkt = tipc_node_get_mtu(dnode, ref); |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1104 | goto next; |
| 1105 | } |
| 1106 | if (rc != -ELINKCONG) |
| 1107 | break; |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 1108 | tsk->link_cong = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1109 | } |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1110 | rc = tipc_wait_for_sndpkt(sock, &timeo); |
Erik Hugne | 70452dc | 2014-07-06 20:38:50 -0400 | [diff] [blame] | 1111 | if (rc) |
| 1112 | kfree_skb_list(buf); |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1113 | } while (!rc); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1114 | exit: |
Jon Paul Maloy | 4ccfe5e | 2014-06-25 20:41:38 -0500 | [diff] [blame] | 1115 | if (iocb) |
| 1116 | release_sock(sk); |
| 1117 | return sent ? sent : rc; |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * tipc_send_packet - send a connection-oriented message |
| 1122 | * @iocb: if NULL, indicates that socket lock is already held |
| 1123 | * @sock: socket structure |
| 1124 | * @m: message to send |
| 1125 | * @dsz: length of data to be transmitted |
| 1126 | * |
| 1127 | * Used for SOCK_SEQPACKET messages. |
| 1128 | * |
| 1129 | * Returns the number of bytes sent on success, or errno otherwise |
| 1130 | */ |
| 1131 | static int tipc_send_packet(struct kiocb *iocb, struct socket *sock, |
| 1132 | struct msghdr *m, size_t dsz) |
| 1133 | { |
| 1134 | if (dsz > TIPC_MAX_USER_MSG_SIZE) |
| 1135 | return -EMSGSIZE; |
| 1136 | |
| 1137 | return tipc_send_stream(iocb, sock, m, dsz); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1138 | } |
| 1139 | |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1140 | /* tipc_sk_finish_conn - complete the setup of a connection |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1141 | */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1142 | static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1143 | u32 peer_node) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1144 | { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1145 | struct tipc_msg *msg = &tsk->phdr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1146 | |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1147 | msg_set_destnode(msg, peer_node); |
| 1148 | msg_set_destport(msg, peer_port); |
| 1149 | msg_set_type(msg, TIPC_CONN_MSG); |
| 1150 | msg_set_lookup_scope(msg, 0); |
| 1151 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
Jon Paul Maloy | f9fef18 | 2014-03-12 11:31:08 -0400 | [diff] [blame] | 1152 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1153 | tsk->probing_interval = CONN_PROBING_INTERVAL; |
| 1154 | tsk->probing_state = TIPC_CONN_OK; |
| 1155 | tsk->connected = 1; |
| 1156 | k_start_timer(&tsk->timer, tsk->probing_interval); |
| 1157 | tipc_node_add_conn(peer_node, tsk->ref, peer_port); |
| 1158 | tsk->max_pkt = tipc_node_get_mtu(peer_node, tsk->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
| 1162 | * set_orig_addr - capture sender's address for received message |
| 1163 | * @m: descriptor for message info |
| 1164 | * @msg: received message header |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1165 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1166 | * Note: Address is not captured if not requested by receiver. |
| 1167 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 1168 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1169 | { |
Steffen Hurrle | 342dfc3 | 2014-01-17 22:53:15 +0100 | [diff] [blame] | 1170 | DECLARE_SOCKADDR(struct sockaddr_tipc *, addr, m->msg_name); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1171 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1172 | if (addr) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1173 | addr->family = AF_TIPC; |
| 1174 | addr->addrtype = TIPC_ADDR_ID; |
Mathias Krause | 60085c3 | 2013-04-07 01:52:00 +0000 | [diff] [blame] | 1175 | memset(&addr->addr, 0, sizeof(addr->addr)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1176 | addr->addr.id.ref = msg_origport(msg); |
| 1177 | addr->addr.id.node = msg_orignode(msg); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1178 | addr->addr.name.domain = 0; /* could leave uninitialized */ |
| 1179 | addr->scope = 0; /* could leave uninitialized */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1180 | m->msg_namelen = sizeof(struct sockaddr_tipc); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | /** |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1185 | * tipc_sk_anc_data_recv - optionally capture ancillary data for received message |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1186 | * @m: descriptor for message info |
| 1187 | * @msg: received message header |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1188 | * @tsk: TIPC port associated with message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1189 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1190 | * Note: Ancillary data is not captured if not requested by receiver. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1191 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1192 | * Returns 0 if successful, otherwise errno |
| 1193 | */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1194 | static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, |
| 1195 | struct tipc_sock *tsk) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1196 | { |
| 1197 | u32 anc_data[3]; |
| 1198 | u32 err; |
| 1199 | u32 dest_type; |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 1200 | int has_name; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1201 | int res; |
| 1202 | |
| 1203 | if (likely(m->msg_controllen == 0)) |
| 1204 | return 0; |
| 1205 | |
| 1206 | /* Optionally capture errored message object(s) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1207 | err = msg ? msg_errcode(msg) : 0; |
| 1208 | if (unlikely(err)) { |
| 1209 | anc_data[0] = err; |
| 1210 | anc_data[1] = msg_data_sz(msg); |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1211 | res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); |
| 1212 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1213 | return res; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1214 | if (anc_data[1]) { |
| 1215 | res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], |
| 1216 | msg_data(msg)); |
| 1217 | if (res) |
| 1218 | return res; |
| 1219 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /* Optionally capture message destination object */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1223 | dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; |
| 1224 | switch (dest_type) { |
| 1225 | case TIPC_NAMED_MSG: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 1226 | has_name = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1227 | anc_data[0] = msg_nametype(msg); |
| 1228 | anc_data[1] = msg_namelower(msg); |
| 1229 | anc_data[2] = msg_namelower(msg); |
| 1230 | break; |
| 1231 | case TIPC_MCAST_MSG: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 1232 | has_name = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1233 | anc_data[0] = msg_nametype(msg); |
| 1234 | anc_data[1] = msg_namelower(msg); |
| 1235 | anc_data[2] = msg_nameupper(msg); |
| 1236 | break; |
| 1237 | case TIPC_CONN_MSG: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1238 | has_name = (tsk->conn_type != 0); |
| 1239 | anc_data[0] = tsk->conn_type; |
| 1240 | anc_data[1] = tsk->conn_instance; |
| 1241 | anc_data[2] = tsk->conn_instance; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1242 | break; |
| 1243 | default: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 1244 | has_name = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1245 | } |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1246 | if (has_name) { |
| 1247 | res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); |
| 1248 | if (res) |
| 1249 | return res; |
| 1250 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1255 | static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) |
Jon Paul Maloy | 739f5e4 | 2014-08-22 18:09:12 -0400 | [diff] [blame] | 1256 | { |
| 1257 | struct sk_buff *buf = NULL; |
| 1258 | struct tipc_msg *msg; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1259 | u32 peer_port = tsk_peer_port(tsk); |
| 1260 | u32 dnode = tsk_peer_node(tsk); |
Jon Paul Maloy | 739f5e4 | 2014-08-22 18:09:12 -0400 | [diff] [blame] | 1261 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1262 | if (!tsk->connected) |
Jon Paul Maloy | 739f5e4 | 2014-08-22 18:09:12 -0400 | [diff] [blame] | 1263 | return; |
| 1264 | buf = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, dnode, |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1265 | tipc_own_addr, peer_port, tsk->ref, TIPC_OK); |
Jon Paul Maloy | 739f5e4 | 2014-08-22 18:09:12 -0400 | [diff] [blame] | 1266 | if (!buf) |
| 1267 | return; |
| 1268 | msg = buf_msg(buf); |
| 1269 | msg_set_msgcnt(msg, ack); |
| 1270 | tipc_link_xmit(buf, dnode, msg_link_selector(msg)); |
| 1271 | } |
| 1272 | |
Arnaldo Carvalho de Melo | 85d3fc9 | 2014-05-23 15:55:12 -0400 | [diff] [blame] | 1273 | static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1274 | { |
| 1275 | struct sock *sk = sock->sk; |
| 1276 | DEFINE_WAIT(wait); |
Arnaldo Carvalho de Melo | 85d3fc9 | 2014-05-23 15:55:12 -0400 | [diff] [blame] | 1277 | long timeo = *timeop; |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1278 | int err; |
| 1279 | |
| 1280 | for (;;) { |
| 1281 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
Ying Xue | fe8e464 | 2014-03-06 14:40:18 +0100 | [diff] [blame] | 1282 | if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1283 | if (sock->state == SS_DISCONNECTING) { |
| 1284 | err = -ENOTCONN; |
| 1285 | break; |
| 1286 | } |
| 1287 | release_sock(sk); |
| 1288 | timeo = schedule_timeout(timeo); |
| 1289 | lock_sock(sk); |
| 1290 | } |
| 1291 | err = 0; |
| 1292 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 1293 | break; |
| 1294 | err = sock_intr_errno(timeo); |
| 1295 | if (signal_pending(current)) |
| 1296 | break; |
| 1297 | err = -EAGAIN; |
| 1298 | if (!timeo) |
| 1299 | break; |
| 1300 | } |
| 1301 | finish_wait(sk_sleep(sk), &wait); |
Arnaldo Carvalho de Melo | 85d3fc9 | 2014-05-23 15:55:12 -0400 | [diff] [blame] | 1302 | *timeop = timeo; |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1303 | return err; |
| 1304 | } |
| 1305 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1306 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1307 | * tipc_recvmsg - receive packet-oriented message |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1308 | * @iocb: (unused) |
| 1309 | * @m: descriptor for message info |
| 1310 | * @buf_len: total size of user buffer area |
| 1311 | * @flags: receive flags |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1312 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1313 | * Used for SOCK_DGRAM, SOCK_RDM, and SOCK_SEQPACKET messages. |
| 1314 | * If the complete message doesn't fit in user area, truncate it. |
| 1315 | * |
| 1316 | * Returns size of returned message data, errno otherwise |
| 1317 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1318 | static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 1319 | struct msghdr *m, size_t buf_len, int flags) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1320 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1321 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1322 | struct tipc_sock *tsk = tipc_sk(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1323 | struct sk_buff *buf; |
| 1324 | struct tipc_msg *msg; |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1325 | long timeo; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1326 | unsigned int sz; |
| 1327 | u32 err; |
| 1328 | int res; |
| 1329 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1330 | /* Catch invalid receive requests */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1331 | if (unlikely(!buf_len)) |
| 1332 | return -EINVAL; |
| 1333 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1334 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1335 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1336 | if (unlikely(sock->state == SS_UNCONNECTED)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1337 | res = -ENOTCONN; |
| 1338 | goto exit; |
| 1339 | } |
| 1340 | |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1341 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1342 | restart: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1343 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1344 | /* Look for a message in receive queue; wait if necessary */ |
Arnaldo Carvalho de Melo | 85d3fc9 | 2014-05-23 15:55:12 -0400 | [diff] [blame] | 1345 | res = tipc_wait_for_rcvmsg(sock, &timeo); |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1346 | if (res) |
| 1347 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* Look at first message in receive queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1350 | buf = skb_peek(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1351 | msg = buf_msg(buf); |
| 1352 | sz = msg_data_sz(msg); |
| 1353 | err = msg_errcode(msg); |
| 1354 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1355 | /* Discard an empty non-errored message & try again */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1356 | if ((!sz) && (!err)) { |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 1357 | tsk_advance_rx_queue(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1358 | goto restart; |
| 1359 | } |
| 1360 | |
| 1361 | /* Capture sender's address (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1362 | set_orig_addr(m, msg); |
| 1363 | |
| 1364 | /* Capture ancillary data (optional) */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1365 | res = tipc_sk_anc_data_recv(m, msg, tsk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1366 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1367 | goto exit; |
| 1368 | |
| 1369 | /* Capture message data (if valid) & compute return value (always) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1370 | if (!err) { |
| 1371 | if (unlikely(buf_len < sz)) { |
| 1372 | sz = buf_len; |
| 1373 | m->msg_flags |= MSG_TRUNC; |
| 1374 | } |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1375 | res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg), |
| 1376 | m->msg_iov, sz); |
| 1377 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1378 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1379 | res = sz; |
| 1380 | } else { |
| 1381 | if ((sock->state == SS_READY) || |
| 1382 | ((err == TIPC_CONN_SHUTDOWN) || m->msg_control)) |
| 1383 | res = 0; |
| 1384 | else |
| 1385 | res = -ECONNRESET; |
| 1386 | } |
| 1387 | |
| 1388 | /* Consume received message (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1389 | if (likely(!(flags & MSG_PEEK))) { |
Allan Stephens | 9900980 | 2008-04-15 00:06:12 -0700 | [diff] [blame] | 1390 | if ((sock->state != SS_READY) && |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1391 | (++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1392 | tipc_sk_send_ack(tsk, tsk->rcv_unacked); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1393 | tsk->rcv_unacked = 0; |
| 1394 | } |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 1395 | tsk_advance_rx_queue(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1396 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1397 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1398 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1399 | return res; |
| 1400 | } |
| 1401 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1402 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1403 | * tipc_recv_stream - receive stream-oriented data |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1404 | * @iocb: (unused) |
| 1405 | * @m: descriptor for message info |
| 1406 | * @buf_len: total size of user buffer area |
| 1407 | * @flags: receive flags |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1408 | * |
| 1409 | * Used for SOCK_STREAM messages only. If not enough data is available |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1410 | * will optionally wait for more; never truncates data. |
| 1411 | * |
| 1412 | * Returns size of returned message data, errno otherwise |
| 1413 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1414 | static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock, |
| 1415 | struct msghdr *m, size_t buf_len, int flags) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1416 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1417 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1418 | struct tipc_sock *tsk = tipc_sk(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1419 | struct sk_buff *buf; |
| 1420 | struct tipc_msg *msg; |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1421 | long timeo; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1422 | unsigned int sz; |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1423 | int sz_to_copy, target, needed; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1424 | int sz_copied = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1425 | u32 err; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1426 | int res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1427 | |
| 1428 | /* Catch invalid receive attempts */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1429 | if (unlikely(!buf_len)) |
| 1430 | return -EINVAL; |
| 1431 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1432 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1433 | |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1434 | if (unlikely(sock->state == SS_UNCONNECTED)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1435 | res = -ENOTCONN; |
| 1436 | goto exit; |
| 1437 | } |
| 1438 | |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1439 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1440 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1441 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1442 | restart: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1443 | /* Look for a message in receive queue; wait if necessary */ |
Arnaldo Carvalho de Melo | 85d3fc9 | 2014-05-23 15:55:12 -0400 | [diff] [blame] | 1444 | res = tipc_wait_for_rcvmsg(sock, &timeo); |
Ying Xue | 9bbb4ec | 2014-01-17 09:50:07 +0800 | [diff] [blame] | 1445 | if (res) |
| 1446 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1447 | |
| 1448 | /* Look at first message in receive queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1449 | buf = skb_peek(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1450 | msg = buf_msg(buf); |
| 1451 | sz = msg_data_sz(msg); |
| 1452 | err = msg_errcode(msg); |
| 1453 | |
| 1454 | /* Discard an empty non-errored message & try again */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1455 | if ((!sz) && (!err)) { |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 1456 | tsk_advance_rx_queue(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1457 | goto restart; |
| 1458 | } |
| 1459 | |
| 1460 | /* Optionally capture sender's address & ancillary data of first msg */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1461 | if (sz_copied == 0) { |
| 1462 | set_orig_addr(m, msg); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1463 | res = tipc_sk_anc_data_recv(m, msg, tsk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1464 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1465 | goto exit; |
| 1466 | } |
| 1467 | |
| 1468 | /* Capture message data (if valid) & compute return value (always) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1469 | if (!err) { |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1470 | u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1471 | |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1472 | sz -= offset; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1473 | needed = (buf_len - sz_copied); |
| 1474 | sz_to_copy = (sz <= needed) ? sz : needed; |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1475 | |
| 1476 | res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg) + offset, |
| 1477 | m->msg_iov, sz_to_copy); |
| 1478 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1479 | goto exit; |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1480 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1481 | sz_copied += sz_to_copy; |
| 1482 | |
| 1483 | if (sz_to_copy < sz) { |
| 1484 | if (!(flags & MSG_PEEK)) |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1485 | TIPC_SKB_CB(buf)->handle = |
| 1486 | (void *)(unsigned long)(offset + sz_to_copy); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1487 | goto exit; |
| 1488 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1489 | } else { |
| 1490 | if (sz_copied != 0) |
| 1491 | goto exit; /* can't add error msg to valid data */ |
| 1492 | |
| 1493 | if ((err == TIPC_CONN_SHUTDOWN) || m->msg_control) |
| 1494 | res = 0; |
| 1495 | else |
| 1496 | res = -ECONNRESET; |
| 1497 | } |
| 1498 | |
| 1499 | /* Consume received message (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1500 | if (likely(!(flags & MSG_PEEK))) { |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1501 | if (unlikely(++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1502 | tipc_sk_send_ack(tsk, tsk->rcv_unacked); |
Jon Paul Maloy | 6012052 | 2014-06-25 20:41:42 -0500 | [diff] [blame] | 1503 | tsk->rcv_unacked = 0; |
| 1504 | } |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 1505 | tsk_advance_rx_queue(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1506 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1507 | |
| 1508 | /* Loop around if more data is required */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1509 | if ((sz_copied < buf_len) && /* didn't get all requested data */ |
| 1510 | (!skb_queue_empty(&sk->sk_receive_queue) || |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1511 | (sz_copied < target)) && /* and more is ready or required */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1512 | (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */ |
| 1513 | (!err)) /* and haven't reached a FIN */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1514 | goto restart; |
| 1515 | |
| 1516 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1517 | release_sock(sk); |
Allan Stephens | a3b0a5a | 2006-06-25 23:48:22 -0700 | [diff] [blame] | 1518 | return sz_copied ? sz_copied : res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 1522 | * tipc_write_space - wake up thread if port congestion is released |
| 1523 | * @sk: socket |
| 1524 | */ |
| 1525 | static void tipc_write_space(struct sock *sk) |
| 1526 | { |
| 1527 | struct socket_wq *wq; |
| 1528 | |
| 1529 | rcu_read_lock(); |
| 1530 | wq = rcu_dereference(sk->sk_wq); |
| 1531 | if (wq_has_sleeper(wq)) |
| 1532 | wake_up_interruptible_sync_poll(&wq->wait, POLLOUT | |
| 1533 | POLLWRNORM | POLLWRBAND); |
| 1534 | rcu_read_unlock(); |
| 1535 | } |
| 1536 | |
| 1537 | /** |
| 1538 | * tipc_data_ready - wake up threads to indicate messages have been received |
| 1539 | * @sk: socket |
| 1540 | * @len: the length of messages |
| 1541 | */ |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 1542 | static void tipc_data_ready(struct sock *sk) |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 1543 | { |
| 1544 | struct socket_wq *wq; |
| 1545 | |
| 1546 | rcu_read_lock(); |
| 1547 | wq = rcu_dereference(sk->sk_wq); |
| 1548 | if (wq_has_sleeper(wq)) |
| 1549 | wake_up_interruptible_sync_poll(&wq->wait, POLLIN | |
| 1550 | POLLRDNORM | POLLRDBAND); |
| 1551 | rcu_read_unlock(); |
| 1552 | } |
| 1553 | |
| 1554 | /** |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1555 | * filter_connect - Handle all incoming messages for a connection-based socket |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1556 | * @tsk: TIPC socket |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1557 | * @msg: message |
| 1558 | * |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1559 | * Returns 0 (TIPC_OK) if everyting ok, -TIPC_ERR_NO_PORT otherwise |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1560 | */ |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1561 | static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1562 | { |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1563 | struct sock *sk = &tsk->sk; |
Jon Paul Maloy | 8826cde | 2014-03-12 11:31:09 -0400 | [diff] [blame] | 1564 | struct socket *sock = sk->sk_socket; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1565 | struct tipc_msg *msg = buf_msg(*buf); |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1566 | int retval = -TIPC_ERR_NO_PORT; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1567 | |
| 1568 | if (msg_mcast(msg)) |
| 1569 | return retval; |
| 1570 | |
| 1571 | switch ((int)sock->state) { |
| 1572 | case SS_CONNECTED: |
| 1573 | /* Accept only connection-based messages sent by peer */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 1574 | if (tsk_peer_msg(tsk, msg)) { |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1575 | if (unlikely(msg_errcode(msg))) { |
| 1576 | sock->state = SS_DISCONNECTING; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1577 | tsk->connected = 0; |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1578 | /* let timer expire on it's own */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1579 | tipc_node_remove_conn(tsk_peer_node(tsk), |
| 1580 | tsk->ref); |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1581 | } |
| 1582 | retval = TIPC_OK; |
| 1583 | } |
| 1584 | break; |
| 1585 | case SS_CONNECTING: |
| 1586 | /* Accept only ACK or NACK message */ |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1587 | |
| 1588 | if (unlikely(!msg_connected(msg))) |
| 1589 | break; |
| 1590 | |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1591 | if (unlikely(msg_errcode(msg))) { |
| 1592 | sock->state = SS_DISCONNECTING; |
Erik Hugne | 2c8d851 | 2013-08-28 09:29:58 +0200 | [diff] [blame] | 1593 | sk->sk_err = ECONNREFUSED; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1594 | retval = TIPC_OK; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1595 | break; |
| 1596 | } |
| 1597 | |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1598 | if (unlikely(msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)) { |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1599 | sock->state = SS_DISCONNECTING; |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1600 | sk->sk_err = EINVAL; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1601 | retval = TIPC_OK; |
| 1602 | break; |
| 1603 | } |
| 1604 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1605 | tipc_sk_finish_conn(tsk, msg_origport(msg), msg_orignode(msg)); |
| 1606 | msg_set_importance(&tsk->phdr, msg_importance(msg)); |
Jon Paul Maloy | dadebc0 | 2014-08-22 18:09:11 -0400 | [diff] [blame] | 1607 | sock->state = SS_CONNECTED; |
| 1608 | |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1609 | /* If an incoming message is an 'ACK-', it should be |
| 1610 | * discarded here because it doesn't contain useful |
| 1611 | * data. In addition, we should try to wake up |
| 1612 | * connect() routine if sleeping. |
| 1613 | */ |
| 1614 | if (msg_data_sz(msg) == 0) { |
| 1615 | kfree_skb(*buf); |
| 1616 | *buf = NULL; |
| 1617 | if (waitqueue_active(sk_sleep(sk))) |
| 1618 | wake_up_interruptible(sk_sleep(sk)); |
| 1619 | } |
| 1620 | retval = TIPC_OK; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1621 | break; |
| 1622 | case SS_LISTENING: |
| 1623 | case SS_UNCONNECTED: |
| 1624 | /* Accept only SYN message */ |
| 1625 | if (!msg_connected(msg) && !(msg_errcode(msg))) |
| 1626 | retval = TIPC_OK; |
| 1627 | break; |
| 1628 | case SS_DISCONNECTING: |
| 1629 | break; |
| 1630 | default: |
| 1631 | pr_err("Unknown socket state %u\n", sock->state); |
| 1632 | } |
| 1633 | return retval; |
| 1634 | } |
| 1635 | |
| 1636 | /** |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1637 | * rcvbuf_limit - get proper overload limit of socket receive queue |
| 1638 | * @sk: socket |
| 1639 | * @buf: message |
| 1640 | * |
| 1641 | * For all connection oriented messages, irrespective of importance, |
| 1642 | * the default overload value (i.e. 67MB) is set as limit. |
| 1643 | * |
| 1644 | * For all connectionless messages, by default new queue limits are |
| 1645 | * as belows: |
| 1646 | * |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 1647 | * TIPC_LOW_IMPORTANCE (4 MB) |
| 1648 | * TIPC_MEDIUM_IMPORTANCE (8 MB) |
| 1649 | * TIPC_HIGH_IMPORTANCE (16 MB) |
| 1650 | * TIPC_CRITICAL_IMPORTANCE (32 MB) |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1651 | * |
| 1652 | * Returns overload limit according to corresponding message importance |
| 1653 | */ |
| 1654 | static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) |
| 1655 | { |
| 1656 | struct tipc_msg *msg = buf_msg(buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1657 | |
| 1658 | if (msg_connected(msg)) |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 1659 | return sysctl_tipc_rmem[2]; |
| 1660 | |
| 1661 | return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << |
| 1662 | msg_importance(msg); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /** |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1666 | * filter_rcv - validate incoming message |
| 1667 | * @sk: socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1668 | * @buf: message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1669 | * |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1670 | * Enqueues message on receive queue if acceptable; optionally handles |
| 1671 | * disconnect indication for a connected socket. |
| 1672 | * |
| 1673 | * Called with socket lock already taken; port lock may also be taken. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1674 | * |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1675 | * Returns 0 (TIPC_OK) if message was consumed, -TIPC error code if message |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 1676 | * to be rejected, 1 (TIPC_FWD_MSG) if (CONN_MANAGER) message to be forwarded |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1677 | */ |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1678 | static int filter_rcv(struct sock *sk, struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1679 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1680 | struct socket *sock = sk->sk_socket; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 1681 | struct tipc_sock *tsk = tipc_sk(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1682 | struct tipc_msg *msg = buf_msg(buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1683 | unsigned int limit = rcvbuf_limit(sk, buf); |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 1684 | u32 onode; |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1685 | int rc = TIPC_OK; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1686 | |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 1687 | if (unlikely(msg_user(msg) == CONN_MANAGER)) |
| 1688 | return tipc_sk_proto_rcv(tsk, &onode, buf); |
Jon Paul Maloy | ec8a2e5 | 2014-06-25 20:41:40 -0500 | [diff] [blame] | 1689 | |
Jon Paul Maloy | 50100a5 | 2014-08-22 18:09:07 -0400 | [diff] [blame] | 1690 | if (unlikely(msg_user(msg) == SOCK_WAKEUP)) { |
| 1691 | kfree_skb(buf); |
| 1692 | tsk->link_cong = 0; |
| 1693 | sk->sk_write_space(sk); |
| 1694 | return TIPC_OK; |
| 1695 | } |
| 1696 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1697 | /* Reject message if it is wrong sort of message for socket */ |
Allan Stephens | aad5854 | 2012-04-26 18:13:08 -0400 | [diff] [blame] | 1698 | if (msg_type(msg) > TIPC_DIRECT_MSG) |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1699 | return -TIPC_ERR_NO_PORT; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1700 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1701 | if (sock->state == SS_READY) { |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 1702 | if (msg_connected(msg)) |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1703 | return -TIPC_ERR_NO_PORT; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1704 | } else { |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1705 | rc = filter_connect(tsk, &buf); |
| 1706 | if (rc != TIPC_OK || buf == NULL) |
| 1707 | return rc; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* Reject message if there isn't room to queue it */ |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1711 | if (sk_rmem_alloc_get(sk) + buf->truesize >= limit) |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1712 | return -TIPC_ERR_OVERLOAD; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1713 | |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1714 | /* Enqueue message */ |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 1715 | TIPC_SKB_CB(buf)->handle = NULL; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1716 | __skb_queue_tail(&sk->sk_receive_queue, buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1717 | skb_set_owner_r(buf, sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1718 | |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 1719 | sk->sk_data_ready(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1720 | return TIPC_OK; |
| 1721 | } |
| 1722 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1723 | /** |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1724 | * tipc_backlog_rcv - handle incoming message from backlog queue |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1725 | * @sk: socket |
| 1726 | * @buf: message |
| 1727 | * |
| 1728 | * Caller must hold socket lock, but not port lock. |
| 1729 | * |
| 1730 | * Returns 0 |
| 1731 | */ |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1732 | static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1733 | { |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1734 | int rc; |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 1735 | u32 onode; |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1736 | struct tipc_sock *tsk = tipc_sk(sk); |
Jon Paul Maloy | 02c00c2 | 2014-06-09 11:08:18 -0500 | [diff] [blame] | 1737 | uint truesize = buf->truesize; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1738 | |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1739 | rc = filter_rcv(sk, buf); |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1740 | |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame] | 1741 | if (likely(!rc)) { |
| 1742 | if (atomic_read(&tsk->dupl_rcvcnt) < TIPC_CONN_OVERLOAD_LIMIT) |
| 1743 | atomic_add(truesize, &tsk->dupl_rcvcnt); |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
| 1747 | if ((rc < 0) && !tipc_msg_reverse(buf, &onode, -rc)) |
| 1748 | return 0; |
| 1749 | |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 1750 | tipc_link_xmit(buf, onode, 0); |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1751 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
Jon Paul Maloy | 24be34b | 2014-03-12 11:31:10 -0400 | [diff] [blame] | 1756 | * tipc_sk_rcv - handle incoming message |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1757 | * @buf: buffer containing arriving message |
| 1758 | * Consumes buffer |
| 1759 | * Returns 0 if success, or errno: -EHOSTUNREACH |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1760 | */ |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1761 | int tipc_sk_rcv(struct sk_buff *buf) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1762 | { |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1763 | struct tipc_sock *tsk; |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1764 | struct sock *sk; |
| 1765 | u32 dport = msg_destport(buf_msg(buf)); |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1766 | int rc = TIPC_OK; |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1767 | uint limit; |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 1768 | u32 dnode; |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1769 | |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 1770 | /* Validate destination and message */ |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 1771 | tsk = tipc_sk_get(dport); |
Jon Paul Maloy | 9b50fd0 | 2014-08-22 18:09:15 -0400 | [diff] [blame] | 1772 | if (unlikely(!tsk)) { |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 1773 | rc = tipc_msg_eval(buf, &dnode); |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1774 | goto exit; |
| 1775 | } |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1776 | sk = &tsk->sk; |
| 1777 | |
| 1778 | /* Queue message */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1779 | bh_lock_sock(sk); |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1780 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1781 | if (!sock_owned_by_user(sk)) { |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1782 | rc = filter_rcv(sk, buf); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1783 | } else { |
Jon Paul Maloy | 4f4482d | 2014-05-14 05:39:09 -0400 | [diff] [blame] | 1784 | if (sk->sk_backlog.len == 0) |
| 1785 | atomic_set(&tsk->dupl_rcvcnt, 0); |
| 1786 | limit = rcvbuf_limit(sk, buf) + atomic_read(&tsk->dupl_rcvcnt); |
| 1787 | if (sk_add_backlog(sk, buf, limit)) |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1788 | rc = -TIPC_ERR_OVERLOAD; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1789 | } |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1790 | bh_unlock_sock(sk); |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 1791 | tipc_sk_put(tsk); |
Jon Paul Maloy | e4de5fa | 2014-06-25 20:41:31 -0500 | [diff] [blame] | 1792 | if (likely(!rc)) |
Jon Paul Maloy | 9816f06 | 2014-05-14 05:39:15 -0400 | [diff] [blame] | 1793 | return 0; |
| 1794 | exit: |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 1795 | if ((rc < 0) && !tipc_msg_reverse(buf, &dnode, -rc)) |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 1796 | return -EHOSTUNREACH; |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 1797 | |
Jon Paul Maloy | 9fbfb8b | 2014-07-16 20:41:03 -0400 | [diff] [blame] | 1798 | tipc_link_xmit(buf, dnode, 0); |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 1799 | return (rc < 0) ? -EHOSTUNREACH : 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1802 | static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) |
| 1803 | { |
| 1804 | struct sock *sk = sock->sk; |
| 1805 | DEFINE_WAIT(wait); |
| 1806 | int done; |
| 1807 | |
| 1808 | do { |
| 1809 | int err = sock_error(sk); |
| 1810 | if (err) |
| 1811 | return err; |
| 1812 | if (!*timeo_p) |
| 1813 | return -ETIMEDOUT; |
| 1814 | if (signal_pending(current)) |
| 1815 | return sock_intr_errno(*timeo_p); |
| 1816 | |
| 1817 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 1818 | done = sk_wait_event(sk, timeo_p, sock->state != SS_CONNECTING); |
| 1819 | finish_wait(sk_sleep(sk), &wait); |
| 1820 | } while (!done); |
| 1821 | return 0; |
| 1822 | } |
| 1823 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1824 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1825 | * tipc_connect - establish a connection to another TIPC port |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1826 | * @sock: socket structure |
| 1827 | * @dest: socket address for destination port |
| 1828 | * @destlen: size of socket address data structure |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1829 | * @flags: file-related flags associated with socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1830 | * |
| 1831 | * Returns 0 on success, errno otherwise |
| 1832 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1833 | static int tipc_connect(struct socket *sock, struct sockaddr *dest, |
| 1834 | int destlen, int flags) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1835 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1836 | struct sock *sk = sock->sk; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1837 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; |
| 1838 | struct msghdr m = {NULL,}; |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1839 | long timeout = (flags & O_NONBLOCK) ? 0 : tipc_sk(sk)->conn_timeout; |
| 1840 | socket_state previous; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1841 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1842 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1843 | lock_sock(sk); |
| 1844 | |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1845 | /* For now, TIPC does not allow use of connect() with DGRAM/RDM types */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1846 | if (sock->state == SS_READY) { |
| 1847 | res = -EOPNOTSUPP; |
| 1848 | goto exit; |
| 1849 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1850 | |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1851 | /* |
| 1852 | * Reject connection attempt using multicast address |
| 1853 | * |
| 1854 | * Note: send_msg() validates the rest of the address fields, |
| 1855 | * so there's no need to do it here |
| 1856 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1857 | if (dst->addrtype == TIPC_ADDR_MCAST) { |
| 1858 | res = -EINVAL; |
| 1859 | goto exit; |
| 1860 | } |
| 1861 | |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1862 | previous = sock->state; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1863 | switch (sock->state) { |
| 1864 | case SS_UNCONNECTED: |
| 1865 | /* Send a 'SYN-' to destination */ |
| 1866 | m.msg_name = dest; |
| 1867 | m.msg_namelen = destlen; |
| 1868 | |
| 1869 | /* If connect is in non-blocking case, set MSG_DONTWAIT to |
| 1870 | * indicate send_msg() is never blocked. |
| 1871 | */ |
| 1872 | if (!timeout) |
| 1873 | m.msg_flags = MSG_DONTWAIT; |
| 1874 | |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1875 | res = tipc_sendmsg(NULL, sock, &m, 0); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1876 | if ((res < 0) && (res != -EWOULDBLOCK)) |
| 1877 | goto exit; |
| 1878 | |
| 1879 | /* Just entered SS_CONNECTING state; the only |
| 1880 | * difference is that return value in non-blocking |
| 1881 | * case is EINPROGRESS, rather than EALREADY. |
| 1882 | */ |
| 1883 | res = -EINPROGRESS; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1884 | case SS_CONNECTING: |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1885 | if (previous == SS_CONNECTING) |
| 1886 | res = -EALREADY; |
| 1887 | if (!timeout) |
| 1888 | goto exit; |
| 1889 | timeout = msecs_to_jiffies(timeout); |
| 1890 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ |
| 1891 | res = tipc_wait_for_connect(sock, &timeout); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1892 | break; |
| 1893 | case SS_CONNECTED: |
| 1894 | res = -EISCONN; |
| 1895 | break; |
| 1896 | default: |
| 1897 | res = -EINVAL; |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1898 | break; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1899 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1900 | exit: |
| 1901 | release_sock(sk); |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1902 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1903 | } |
| 1904 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1905 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1906 | * tipc_listen - allow socket to listen for incoming connections |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1907 | * @sock: socket structure |
| 1908 | * @len: (unused) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1909 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1910 | * Returns 0 on success, errno otherwise |
| 1911 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1912 | static int tipc_listen(struct socket *sock, int len) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1913 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1914 | struct sock *sk = sock->sk; |
| 1915 | int res; |
| 1916 | |
| 1917 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1918 | |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 1919 | if (sock->state != SS_UNCONNECTED) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1920 | res = -EINVAL; |
| 1921 | else { |
| 1922 | sock->state = SS_LISTENING; |
| 1923 | res = 0; |
| 1924 | } |
| 1925 | |
| 1926 | release_sock(sk); |
| 1927 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1930 | static int tipc_wait_for_accept(struct socket *sock, long timeo) |
| 1931 | { |
| 1932 | struct sock *sk = sock->sk; |
| 1933 | DEFINE_WAIT(wait); |
| 1934 | int err; |
| 1935 | |
| 1936 | /* True wake-one mechanism for incoming connections: only |
| 1937 | * one process gets woken up, not the 'whole herd'. |
| 1938 | * Since we do not 'race & poll' for established sockets |
| 1939 | * anymore, the common case will execute the loop only once. |
| 1940 | */ |
| 1941 | for (;;) { |
| 1942 | prepare_to_wait_exclusive(sk_sleep(sk), &wait, |
| 1943 | TASK_INTERRUPTIBLE); |
Ying Xue | fe8e464 | 2014-03-06 14:40:18 +0100 | [diff] [blame] | 1944 | if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1945 | release_sock(sk); |
| 1946 | timeo = schedule_timeout(timeo); |
| 1947 | lock_sock(sk); |
| 1948 | } |
| 1949 | err = 0; |
| 1950 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 1951 | break; |
| 1952 | err = -EINVAL; |
| 1953 | if (sock->state != SS_LISTENING) |
| 1954 | break; |
| 1955 | err = sock_intr_errno(timeo); |
| 1956 | if (signal_pending(current)) |
| 1957 | break; |
| 1958 | err = -EAGAIN; |
| 1959 | if (!timeo) |
| 1960 | break; |
| 1961 | } |
| 1962 | finish_wait(sk_sleep(sk), &wait); |
| 1963 | return err; |
| 1964 | } |
| 1965 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1966 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1967 | * tipc_accept - wait for connection request |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1968 | * @sock: listening socket |
| 1969 | * @newsock: new socket that is to be connected |
| 1970 | * @flags: file-related flags associated with socket |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1971 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1972 | * Returns 0 on success, errno otherwise |
| 1973 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 1974 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1975 | { |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1976 | struct sock *new_sk, *sk = sock->sk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1977 | struct sk_buff *buf; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 1978 | struct tipc_sock *new_tsock; |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1979 | struct tipc_msg *msg; |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1980 | long timeo; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1981 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1982 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1983 | lock_sock(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1984 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1985 | if (sock->state != SS_LISTENING) { |
| 1986 | res = -EINVAL; |
| 1987 | goto exit; |
| 1988 | } |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1989 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 1990 | res = tipc_wait_for_accept(sock, timeo); |
| 1991 | if (res) |
| 1992 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1993 | |
| 1994 | buf = skb_peek(&sk->sk_receive_queue); |
| 1995 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 1996 | res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 1); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1997 | if (res) |
| 1998 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1999 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2000 | new_sk = new_sock->sk; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2001 | new_tsock = tipc_sk(new_sk); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2002 | msg = buf_msg(buf); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2003 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2004 | /* we lock on new_sk; but lockdep sees the lock on sk */ |
| 2005 | lock_sock_nested(new_sk, SINGLE_DEPTH_NESTING); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2006 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2007 | /* |
| 2008 | * Reject any stray messages received by new socket |
| 2009 | * before the socket lock was taken (very, very unlikely) |
| 2010 | */ |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 2011 | tsk_rej_rx_queue(new_sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2012 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2013 | /* Connect new socket to it's peer */ |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2014 | tipc_sk_finish_conn(new_tsock, msg_origport(msg), msg_orignode(msg)); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2015 | new_sock->state = SS_CONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2016 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2017 | tsk_set_importance(new_tsock, msg_importance(msg)); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2018 | if (msg_named(msg)) { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2019 | new_tsock->conn_type = msg_nametype(msg); |
| 2020 | new_tsock->conn_instance = msg_nameinst(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2021 | } |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2022 | |
| 2023 | /* |
| 2024 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. |
| 2025 | * Respond to 'SYN+' by queuing it on new socket. |
| 2026 | */ |
| 2027 | if (!msg_data_sz(msg)) { |
| 2028 | struct msghdr m = {NULL,}; |
| 2029 | |
Jon Paul Maloy | 2e84c60 | 2014-08-22 18:09:18 -0400 | [diff] [blame] | 2030 | tsk_advance_rx_queue(sk); |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2031 | tipc_send_packet(NULL, new_sock, &m, 0); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2032 | } else { |
| 2033 | __skb_dequeue(&sk->sk_receive_queue); |
| 2034 | __skb_queue_head(&new_sk->sk_receive_queue, buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 2035 | skb_set_owner_r(buf, new_sk); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 2036 | } |
| 2037 | release_sock(new_sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2038 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2039 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2040 | return res; |
| 2041 | } |
| 2042 | |
| 2043 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2044 | * tipc_shutdown - shutdown socket connection |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2045 | * @sock: socket structure |
Allan Stephens | e247a8f | 2008-03-06 15:05:38 -0800 | [diff] [blame] | 2046 | * @how: direction to close (must be SHUT_RDWR) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2047 | * |
| 2048 | * Terminates connection (if necessary), then purges socket's receive queue. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2049 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2050 | * Returns 0 on success, errno otherwise |
| 2051 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2052 | static int tipc_shutdown(struct socket *sock, int how) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2053 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2054 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 2055 | struct tipc_sock *tsk = tipc_sk(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2056 | struct sk_buff *buf; |
Jon Paul Maloy | 80e44c2 | 2014-08-22 18:09:10 -0400 | [diff] [blame] | 2057 | u32 dnode; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2058 | int res; |
| 2059 | |
Allan Stephens | e247a8f | 2008-03-06 15:05:38 -0800 | [diff] [blame] | 2060 | if (how != SHUT_RDWR) |
| 2061 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2062 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2063 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2064 | |
| 2065 | switch (sock->state) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2066 | case SS_CONNECTING: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2067 | case SS_CONNECTED: |
| 2068 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2069 | restart: |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 2070 | /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2071 | buf = __skb_dequeue(&sk->sk_receive_queue); |
| 2072 | if (buf) { |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 2073 | if (TIPC_SKB_CB(buf)->handle != NULL) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 2074 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2075 | goto restart; |
| 2076 | } |
Jon Paul Maloy | 80e44c2 | 2014-08-22 18:09:10 -0400 | [diff] [blame] | 2077 | if (tipc_msg_reverse(buf, &dnode, TIPC_CONN_SHUTDOWN)) |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2078 | tipc_link_xmit(buf, dnode, tsk->ref); |
| 2079 | tipc_node_remove_conn(dnode, tsk->ref); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2080 | } else { |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2081 | dnode = tsk_peer_node(tsk); |
Jon Paul Maloy | 80e44c2 | 2014-08-22 18:09:10 -0400 | [diff] [blame] | 2082 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, |
| 2083 | TIPC_CONN_MSG, SHORT_H_SIZE, |
| 2084 | 0, dnode, tipc_own_addr, |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2085 | tsk_peer_port(tsk), |
| 2086 | tsk->ref, TIPC_CONN_SHUTDOWN); |
| 2087 | tipc_link_xmit(buf, dnode, tsk->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2088 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2089 | tsk->connected = 0; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2090 | sock->state = SS_DISCONNECTING; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2091 | tipc_node_remove_conn(dnode, tsk->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2092 | /* fall through */ |
| 2093 | |
| 2094 | case SS_DISCONNECTING: |
| 2095 | |
Ying Xue | 7503115 | 2012-10-29 09:38:15 -0400 | [diff] [blame] | 2096 | /* Discard any unreceived messages */ |
Ying Xue | 57467e5 | 2013-01-20 23:30:08 +0100 | [diff] [blame] | 2097 | __skb_queue_purge(&sk->sk_receive_queue); |
Ying Xue | 7503115 | 2012-10-29 09:38:15 -0400 | [diff] [blame] | 2098 | |
| 2099 | /* Wake up anyone sleeping in poll */ |
| 2100 | sk->sk_state_change(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2101 | res = 0; |
| 2102 | break; |
| 2103 | |
| 2104 | default: |
| 2105 | res = -ENOTCONN; |
| 2106 | } |
| 2107 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2108 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2109 | return res; |
| 2110 | } |
| 2111 | |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2112 | static void tipc_sk_timeout(unsigned long ref) |
| 2113 | { |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2114 | struct tipc_sock *tsk; |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2115 | struct sock *sk; |
| 2116 | struct sk_buff *buf = NULL; |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2117 | u32 peer_port, peer_node; |
| 2118 | |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2119 | tsk = tipc_sk_get(ref); |
Jon Paul Maloy | 9b50fd0 | 2014-08-22 18:09:15 -0400 | [diff] [blame] | 2120 | if (!tsk) |
Ying Xue | cc086fc | 2014-08-28 10:02:41 +0800 | [diff] [blame] | 2121 | return; |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2122 | |
Ying Xue | cc086fc | 2014-08-28 10:02:41 +0800 | [diff] [blame] | 2123 | sk = &tsk->sk; |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2124 | bh_lock_sock(sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2125 | if (!tsk->connected) { |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2126 | bh_unlock_sock(sk); |
| 2127 | goto exit; |
| 2128 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2129 | peer_port = tsk_peer_port(tsk); |
| 2130 | peer_node = tsk_peer_node(tsk); |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2131 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2132 | if (tsk->probing_state == TIPC_CONN_PROBING) { |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2133 | /* Previous probe not answered -> self abort */ |
| 2134 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, |
| 2135 | SHORT_H_SIZE, 0, tipc_own_addr, |
| 2136 | peer_node, ref, peer_port, |
| 2137 | TIPC_ERR_NO_PORT); |
| 2138 | } else { |
| 2139 | buf = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, |
| 2140 | 0, peer_node, tipc_own_addr, |
| 2141 | peer_port, ref, TIPC_OK); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2142 | tsk->probing_state = TIPC_CONN_PROBING; |
| 2143 | k_start_timer(&tsk->timer, tsk->probing_interval); |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2144 | } |
| 2145 | bh_unlock_sock(sk); |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2146 | if (buf) |
| 2147 | tipc_link_xmit(buf, peer_node, ref); |
| 2148 | exit: |
| 2149 | tipc_sk_put(tsk); |
Jon Paul Maloy | 5728901 | 2014-08-22 18:09:09 -0400 | [diff] [blame] | 2150 | } |
| 2151 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2152 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2153 | struct tipc_name_seq const *seq) |
| 2154 | { |
| 2155 | struct publication *publ; |
| 2156 | u32 key; |
| 2157 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2158 | if (tsk->connected) |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2159 | return -EINVAL; |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2160 | key = tsk->ref + tsk->pub_count + 1; |
| 2161 | if (key == tsk->ref) |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2162 | return -EADDRINUSE; |
| 2163 | |
| 2164 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2165 | scope, tsk->ref, key); |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2166 | if (unlikely(!publ)) |
| 2167 | return -EINVAL; |
| 2168 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2169 | list_add(&publ->pport_list, &tsk->publications); |
| 2170 | tsk->pub_count++; |
| 2171 | tsk->published = 1; |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2172 | return 0; |
| 2173 | } |
| 2174 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2175 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2176 | struct tipc_name_seq const *seq) |
| 2177 | { |
| 2178 | struct publication *publ; |
| 2179 | struct publication *safe; |
| 2180 | int rc = -EINVAL; |
| 2181 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2182 | list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) { |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2183 | if (seq) { |
| 2184 | if (publ->scope != scope) |
| 2185 | continue; |
| 2186 | if (publ->type != seq->type) |
| 2187 | continue; |
| 2188 | if (publ->lower != seq->lower) |
| 2189 | continue; |
| 2190 | if (publ->upper != seq->upper) |
| 2191 | break; |
| 2192 | tipc_nametbl_withdraw(publ->type, publ->lower, |
| 2193 | publ->ref, publ->key); |
| 2194 | rc = 0; |
| 2195 | break; |
| 2196 | } |
| 2197 | tipc_nametbl_withdraw(publ->type, publ->lower, |
| 2198 | publ->ref, publ->key); |
| 2199 | rc = 0; |
| 2200 | } |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2201 | if (list_empty(&tsk->publications)) |
| 2202 | tsk->published = 0; |
Jon Paul Maloy | 0fc87aa | 2014-08-22 18:09:17 -0400 | [diff] [blame] | 2203 | return rc; |
| 2204 | } |
| 2205 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2206 | static int tipc_sk_show(struct tipc_sock *tsk, char *buf, |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2207 | int len, int full_id) |
| 2208 | { |
| 2209 | struct publication *publ; |
| 2210 | int ret; |
| 2211 | |
| 2212 | if (full_id) |
| 2213 | ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:", |
| 2214 | tipc_zone(tipc_own_addr), |
| 2215 | tipc_cluster(tipc_own_addr), |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2216 | tipc_node(tipc_own_addr), tsk->ref); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2217 | else |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2218 | ret = tipc_snprintf(buf, len, "%-10u:", tsk->ref); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2219 | |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2220 | if (tsk->connected) { |
| 2221 | u32 dport = tsk_peer_port(tsk); |
| 2222 | u32 destnode = tsk_peer_node(tsk); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2223 | |
| 2224 | ret += tipc_snprintf(buf + ret, len - ret, |
| 2225 | " connected to <%u.%u.%u:%u>", |
| 2226 | tipc_zone(destnode), |
| 2227 | tipc_cluster(destnode), |
| 2228 | tipc_node(destnode), dport); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2229 | if (tsk->conn_type != 0) |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2230 | ret += tipc_snprintf(buf + ret, len - ret, |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2231 | " via {%u,%u}", tsk->conn_type, |
| 2232 | tsk->conn_instance); |
| 2233 | } else if (tsk->published) { |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2234 | ret += tipc_snprintf(buf + ret, len - ret, " bound to"); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2235 | list_for_each_entry(publ, &tsk->publications, pport_list) { |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2236 | if (publ->lower == publ->upper) |
| 2237 | ret += tipc_snprintf(buf + ret, len - ret, |
| 2238 | " {%u,%u}", publ->type, |
| 2239 | publ->lower); |
| 2240 | else |
| 2241 | ret += tipc_snprintf(buf + ret, len - ret, |
| 2242 | " {%u,%u,%u}", publ->type, |
| 2243 | publ->lower, publ->upper); |
| 2244 | } |
| 2245 | } |
| 2246 | ret += tipc_snprintf(buf + ret, len - ret, "\n"); |
| 2247 | return ret; |
| 2248 | } |
| 2249 | |
| 2250 | struct sk_buff *tipc_sk_socks_show(void) |
| 2251 | { |
| 2252 | struct sk_buff *buf; |
| 2253 | struct tlv_desc *rep_tlv; |
| 2254 | char *pb; |
| 2255 | int pb_len; |
| 2256 | struct tipc_sock *tsk; |
| 2257 | int str_len = 0; |
| 2258 | u32 ref = 0; |
| 2259 | |
| 2260 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
| 2261 | if (!buf) |
| 2262 | return NULL; |
| 2263 | rep_tlv = (struct tlv_desc *)buf->data; |
| 2264 | pb = TLV_DATA(rep_tlv); |
| 2265 | pb_len = ULTRA_STRING_MAX_LEN; |
| 2266 | |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2267 | tsk = tipc_sk_get_next(&ref); |
| 2268 | for (; tsk; tsk = tipc_sk_get_next(&ref)) { |
| 2269 | lock_sock(&tsk->sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2270 | str_len += tipc_sk_show(tsk, pb + str_len, |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2271 | pb_len - str_len, 0); |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2272 | release_sock(&tsk->sk); |
| 2273 | tipc_sk_put(tsk); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2274 | } |
| 2275 | str_len += 1; /* for "\0" */ |
| 2276 | skb_put(buf, TLV_SPACE(str_len)); |
| 2277 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 2278 | |
| 2279 | return buf; |
| 2280 | } |
| 2281 | |
| 2282 | /* tipc_sk_reinit: set non-zero address in all existing sockets |
| 2283 | * when we go from standalone to network mode. |
| 2284 | */ |
| 2285 | void tipc_sk_reinit(void) |
| 2286 | { |
| 2287 | struct tipc_msg *msg; |
| 2288 | u32 ref = 0; |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2289 | struct tipc_sock *tsk = tipc_sk_get_next(&ref); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2290 | |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2291 | for (; tsk; tsk = tipc_sk_get_next(&ref)) { |
| 2292 | lock_sock(&tsk->sk); |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2293 | msg = &tsk->phdr; |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2294 | msg_set_prevnode(msg, tipc_own_addr); |
| 2295 | msg_set_orignode(msg, tipc_own_addr); |
Jon Paul Maloy | 6c9808c | 2014-08-22 18:09:16 -0400 | [diff] [blame] | 2296 | release_sock(&tsk->sk); |
| 2297 | tipc_sk_put(tsk); |
Jon Paul Maloy | 5a9ee0be | 2014-08-22 18:09:14 -0400 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2301 | /** |
Jon Paul Maloy | 808d90f | 2014-08-22 18:09:19 -0400 | [diff] [blame] | 2302 | * struct reference - TIPC socket reference entry |
| 2303 | * @tsk: pointer to socket associated with reference entry |
| 2304 | * @ref: reference value for socket (combines instance & array index info) |
| 2305 | */ |
| 2306 | struct reference { |
| 2307 | struct tipc_sock *tsk; |
| 2308 | u32 ref; |
| 2309 | }; |
| 2310 | |
| 2311 | /** |
| 2312 | * struct tipc_ref_table - table of TIPC socket reference entries |
| 2313 | * @entries: pointer to array of reference entries |
| 2314 | * @capacity: array index of first unusable entry |
| 2315 | * @init_point: array index of first uninitialized entry |
| 2316 | * @first_free: array index of first unused socket reference entry |
| 2317 | * @last_free: array index of last unused socket reference entry |
| 2318 | * @index_mask: bitmask for array index portion of reference values |
| 2319 | * @start_mask: initial value for instance value portion of reference values |
| 2320 | */ |
| 2321 | struct ref_table { |
| 2322 | struct reference *entries; |
| 2323 | u32 capacity; |
| 2324 | u32 init_point; |
| 2325 | u32 first_free; |
| 2326 | u32 last_free; |
| 2327 | u32 index_mask; |
| 2328 | u32 start_mask; |
| 2329 | }; |
| 2330 | |
| 2331 | /* Socket reference table consists of 2**N entries. |
| 2332 | * |
| 2333 | * State Socket ptr Reference |
| 2334 | * ----- ---------- --------- |
| 2335 | * In use non-NULL XXXX|own index |
| 2336 | * (XXXX changes each time entry is acquired) |
| 2337 | * Free NULL YYYY|next free index |
| 2338 | * (YYYY is one more than last used XXXX) |
| 2339 | * Uninitialized NULL 0 |
| 2340 | * |
| 2341 | * Entry 0 is not used; this allows index 0 to denote the end of the free list. |
| 2342 | * |
| 2343 | * Note that a reference value of 0 does not necessarily indicate that an |
| 2344 | * entry is uninitialized, since the last entry in the free list could also |
| 2345 | * have a reference value of 0 (although this is unlikely). |
| 2346 | */ |
| 2347 | |
| 2348 | static struct ref_table tipc_ref_table; |
| 2349 | |
| 2350 | static DEFINE_RWLOCK(ref_table_lock); |
| 2351 | |
| 2352 | /** |
| 2353 | * tipc_ref_table_init - create reference table for sockets |
| 2354 | */ |
| 2355 | int tipc_sk_ref_table_init(u32 req_sz, u32 start) |
| 2356 | { |
| 2357 | struct reference *table; |
| 2358 | u32 actual_sz; |
| 2359 | |
| 2360 | /* account for unused entry, then round up size to a power of 2 */ |
| 2361 | |
| 2362 | req_sz++; |
| 2363 | for (actual_sz = 16; actual_sz < req_sz; actual_sz <<= 1) { |
| 2364 | /* do nothing */ |
| 2365 | }; |
| 2366 | |
| 2367 | /* allocate table & mark all entries as uninitialized */ |
| 2368 | table = vzalloc(actual_sz * sizeof(struct reference)); |
| 2369 | if (table == NULL) |
| 2370 | return -ENOMEM; |
| 2371 | |
| 2372 | tipc_ref_table.entries = table; |
| 2373 | tipc_ref_table.capacity = req_sz; |
| 2374 | tipc_ref_table.init_point = 1; |
| 2375 | tipc_ref_table.first_free = 0; |
| 2376 | tipc_ref_table.last_free = 0; |
| 2377 | tipc_ref_table.index_mask = actual_sz - 1; |
| 2378 | tipc_ref_table.start_mask = start & ~tipc_ref_table.index_mask; |
| 2379 | |
| 2380 | return 0; |
| 2381 | } |
| 2382 | |
| 2383 | /** |
| 2384 | * tipc_ref_table_stop - destroy reference table for sockets |
| 2385 | */ |
| 2386 | void tipc_sk_ref_table_stop(void) |
| 2387 | { |
| 2388 | if (!tipc_ref_table.entries) |
| 2389 | return; |
| 2390 | vfree(tipc_ref_table.entries); |
| 2391 | tipc_ref_table.entries = NULL; |
| 2392 | } |
| 2393 | |
| 2394 | /* tipc_ref_acquire - create reference to a socket |
| 2395 | * |
| 2396 | * Register an socket pointer in the reference table. |
| 2397 | * Returns a unique reference value that is used from then on to retrieve the |
| 2398 | * socket pointer, or to determine if the socket has been deregistered. |
| 2399 | */ |
| 2400 | u32 tipc_sk_ref_acquire(struct tipc_sock *tsk) |
| 2401 | { |
| 2402 | u32 index; |
| 2403 | u32 index_mask; |
| 2404 | u32 next_plus_upper; |
| 2405 | u32 ref = 0; |
| 2406 | struct reference *entry; |
| 2407 | |
| 2408 | if (unlikely(!tsk)) { |
| 2409 | pr_err("Attempt to acquire ref. to non-existent obj\n"); |
| 2410 | return 0; |
| 2411 | } |
| 2412 | if (unlikely(!tipc_ref_table.entries)) { |
| 2413 | pr_err("Ref. table not found in acquisition attempt\n"); |
| 2414 | return 0; |
| 2415 | } |
| 2416 | |
| 2417 | /* Take a free entry, if available; otherwise initialize a new one */ |
| 2418 | write_lock_bh(&ref_table_lock); |
| 2419 | index = tipc_ref_table.first_free; |
| 2420 | entry = &tipc_ref_table.entries[index]; |
| 2421 | |
| 2422 | if (likely(index)) { |
| 2423 | index = tipc_ref_table.first_free; |
| 2424 | entry = &tipc_ref_table.entries[index]; |
| 2425 | index_mask = tipc_ref_table.index_mask; |
| 2426 | next_plus_upper = entry->ref; |
| 2427 | tipc_ref_table.first_free = next_plus_upper & index_mask; |
| 2428 | ref = (next_plus_upper & ~index_mask) + index; |
| 2429 | entry->tsk = tsk; |
| 2430 | } else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { |
| 2431 | index = tipc_ref_table.init_point++; |
| 2432 | entry = &tipc_ref_table.entries[index]; |
| 2433 | ref = tipc_ref_table.start_mask + index; |
| 2434 | } |
| 2435 | |
| 2436 | if (ref) { |
| 2437 | entry->ref = ref; |
| 2438 | entry->tsk = tsk; |
| 2439 | } |
| 2440 | write_unlock_bh(&ref_table_lock); |
| 2441 | return ref; |
| 2442 | } |
| 2443 | |
| 2444 | /* tipc_sk_ref_discard - invalidate reference to an socket |
| 2445 | * |
| 2446 | * Disallow future references to an socket and free up the entry for re-use. |
| 2447 | */ |
| 2448 | void tipc_sk_ref_discard(u32 ref) |
| 2449 | { |
| 2450 | struct reference *entry; |
| 2451 | u32 index; |
| 2452 | u32 index_mask; |
| 2453 | |
| 2454 | if (unlikely(!tipc_ref_table.entries)) { |
| 2455 | pr_err("Ref. table not found during discard attempt\n"); |
| 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | index_mask = tipc_ref_table.index_mask; |
| 2460 | index = ref & index_mask; |
| 2461 | entry = &tipc_ref_table.entries[index]; |
| 2462 | |
| 2463 | write_lock_bh(&ref_table_lock); |
| 2464 | |
| 2465 | if (unlikely(!entry->tsk)) { |
| 2466 | pr_err("Attempt to discard ref. to non-existent socket\n"); |
| 2467 | goto exit; |
| 2468 | } |
| 2469 | if (unlikely(entry->ref != ref)) { |
| 2470 | pr_err("Attempt to discard non-existent reference\n"); |
| 2471 | goto exit; |
| 2472 | } |
| 2473 | |
| 2474 | /* Mark entry as unused; increment instance part of entry's |
| 2475 | * reference to invalidate any subsequent references |
| 2476 | */ |
| 2477 | |
| 2478 | entry->tsk = NULL; |
| 2479 | entry->ref = (ref & ~index_mask) + (index_mask + 1); |
| 2480 | |
| 2481 | /* Append entry to free entry list */ |
| 2482 | if (unlikely(tipc_ref_table.first_free == 0)) |
| 2483 | tipc_ref_table.first_free = index; |
| 2484 | else |
| 2485 | tipc_ref_table.entries[tipc_ref_table.last_free].ref |= index; |
| 2486 | tipc_ref_table.last_free = index; |
| 2487 | exit: |
| 2488 | write_unlock_bh(&ref_table_lock); |
| 2489 | } |
| 2490 | |
| 2491 | /* tipc_sk_get - find referenced socket and return pointer to it |
| 2492 | */ |
| 2493 | struct tipc_sock *tipc_sk_get(u32 ref) |
| 2494 | { |
| 2495 | struct reference *entry; |
| 2496 | struct tipc_sock *tsk; |
| 2497 | |
| 2498 | if (unlikely(!tipc_ref_table.entries)) |
| 2499 | return NULL; |
| 2500 | read_lock_bh(&ref_table_lock); |
| 2501 | entry = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; |
| 2502 | tsk = entry->tsk; |
| 2503 | if (likely(tsk && (entry->ref == ref))) |
| 2504 | sock_hold(&tsk->sk); |
| 2505 | else |
| 2506 | tsk = NULL; |
| 2507 | read_unlock_bh(&ref_table_lock); |
| 2508 | return tsk; |
| 2509 | } |
| 2510 | |
| 2511 | /* tipc_sk_get_next - lock & return next socket after referenced one |
| 2512 | */ |
| 2513 | struct tipc_sock *tipc_sk_get_next(u32 *ref) |
| 2514 | { |
| 2515 | struct reference *entry; |
| 2516 | struct tipc_sock *tsk = NULL; |
| 2517 | uint index = *ref & tipc_ref_table.index_mask; |
| 2518 | |
| 2519 | read_lock_bh(&ref_table_lock); |
| 2520 | while (++index < tipc_ref_table.capacity) { |
| 2521 | entry = &tipc_ref_table.entries[index]; |
| 2522 | if (!entry->tsk) |
| 2523 | continue; |
| 2524 | tsk = entry->tsk; |
| 2525 | sock_hold(&tsk->sk); |
| 2526 | *ref = entry->ref; |
| 2527 | break; |
| 2528 | } |
| 2529 | read_unlock_bh(&ref_table_lock); |
| 2530 | return tsk; |
| 2531 | } |
| 2532 | |
| 2533 | static void tipc_sk_put(struct tipc_sock *tsk) |
| 2534 | { |
| 2535 | sock_put(&tsk->sk); |
| 2536 | } |
| 2537 | |
| 2538 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2539 | * tipc_setsockopt - set socket option |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2540 | * @sock: socket structure |
| 2541 | * @lvl: option level |
| 2542 | * @opt: option identifier |
| 2543 | * @ov: pointer to new option value |
| 2544 | * @ol: length of option value |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2545 | * |
| 2546 | * For stream sockets only, accepts and ignores all IPPROTO_TCP options |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2547 | * (to ease compatibility). |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2548 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2549 | * Returns 0 on success, errno otherwise |
| 2550 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2551 | static int tipc_setsockopt(struct socket *sock, int lvl, int opt, |
| 2552 | char __user *ov, unsigned int ol) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2553 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2554 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 2555 | struct tipc_sock *tsk = tipc_sk(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2556 | u32 value; |
| 2557 | int res; |
| 2558 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2559 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
| 2560 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2561 | if (lvl != SOL_TIPC) |
| 2562 | return -ENOPROTOOPT; |
| 2563 | if (ol < sizeof(value)) |
| 2564 | return -EINVAL; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 2565 | res = get_user(value, (u32 __user *)ov); |
| 2566 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2567 | return res; |
| 2568 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2569 | lock_sock(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2570 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2571 | switch (opt) { |
| 2572 | case TIPC_IMPORTANCE: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2573 | res = tsk_set_importance(tsk, value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2574 | break; |
| 2575 | case TIPC_SRC_DROPPABLE: |
| 2576 | if (sock->type != SOCK_STREAM) |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2577 | tsk_set_unreliable(tsk, value); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2578 | else |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2579 | res = -ENOPROTOOPT; |
| 2580 | break; |
| 2581 | case TIPC_DEST_DROPPABLE: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2582 | tsk_set_unreturnable(tsk, value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2583 | break; |
| 2584 | case TIPC_CONN_TIMEOUT: |
Allan Stephens | a0f40f0 | 2011-05-26 13:44:34 -0400 | [diff] [blame] | 2585 | tipc_sk(sk)->conn_timeout = value; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2586 | /* no need to set "res", since already 0 at this point */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2587 | break; |
| 2588 | default: |
| 2589 | res = -EINVAL; |
| 2590 | } |
| 2591 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2592 | release_sock(sk); |
| 2593 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2594 | return res; |
| 2595 | } |
| 2596 | |
| 2597 | /** |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2598 | * tipc_getsockopt - get socket option |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2599 | * @sock: socket structure |
| 2600 | * @lvl: option level |
| 2601 | * @opt: option identifier |
| 2602 | * @ov: receptacle for option value |
| 2603 | * @ol: receptacle for length of option value |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2604 | * |
| 2605 | * For stream sockets only, returns 0 length result for all IPPROTO_TCP options |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2606 | * (to ease compatibility). |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2607 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2608 | * Returns 0 on success, errno otherwise |
| 2609 | */ |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2610 | static int tipc_getsockopt(struct socket *sock, int lvl, int opt, |
| 2611 | char __user *ov, int __user *ol) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2612 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2613 | struct sock *sk = sock->sk; |
Jon Paul Maloy | 58ed944 | 2014-03-12 11:31:12 -0400 | [diff] [blame] | 2614 | struct tipc_sock *tsk = tipc_sk(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2615 | int len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2616 | u32 value; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2617 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2618 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2619 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
| 2620 | return put_user(0, ol); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2621 | if (lvl != SOL_TIPC) |
| 2622 | return -ENOPROTOOPT; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 2623 | res = get_user(len, ol); |
| 2624 | if (res) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2625 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2626 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2627 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2628 | |
| 2629 | switch (opt) { |
| 2630 | case TIPC_IMPORTANCE: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2631 | value = tsk_importance(tsk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2632 | break; |
| 2633 | case TIPC_SRC_DROPPABLE: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2634 | value = tsk_unreliable(tsk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2635 | break; |
| 2636 | case TIPC_DEST_DROPPABLE: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2637 | value = tsk_unreturnable(tsk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2638 | break; |
| 2639 | case TIPC_CONN_TIMEOUT: |
Jon Paul Maloy | 301bae5 | 2014-08-22 18:09:20 -0400 | [diff] [blame] | 2640 | value = tsk->conn_timeout; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2641 | /* no need to set "res", since already 0 at this point */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2642 | break; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2643 | case TIPC_NODE_RECVQ_DEPTH: |
Ying Xue | 9da3d47 | 2012-11-27 06:15:27 -0500 | [diff] [blame] | 2644 | value = 0; /* was tipc_queue_size, now obsolete */ |
oscar.medina@motorola.com | 6650613 | 2009-06-30 03:25:39 +0000 | [diff] [blame] | 2645 | break; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2646 | case TIPC_SOCK_RECVQ_DEPTH: |
oscar.medina@motorola.com | 6650613 | 2009-06-30 03:25:39 +0000 | [diff] [blame] | 2647 | value = skb_queue_len(&sk->sk_receive_queue); |
| 2648 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2649 | default: |
| 2650 | res = -EINVAL; |
| 2651 | } |
| 2652 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 2653 | release_sock(sk); |
| 2654 | |
Paul Gortmaker | 25860c3 | 2010-12-31 18:59:31 +0000 | [diff] [blame] | 2655 | if (res) |
| 2656 | return res; /* "get" failed */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2657 | |
Paul Gortmaker | 25860c3 | 2010-12-31 18:59:31 +0000 | [diff] [blame] | 2658 | if (len < sizeof(value)) |
| 2659 | return -EINVAL; |
| 2660 | |
| 2661 | if (copy_to_user(ov, &value, sizeof(value))) |
| 2662 | return -EFAULT; |
| 2663 | |
| 2664 | return put_user(sizeof(value), ol); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2665 | } |
| 2666 | |
Wei Yongjun | 52f50ce | 2014-07-20 13:14:28 +0800 | [diff] [blame] | 2667 | static int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg) |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 2668 | { |
| 2669 | struct tipc_sioc_ln_req lnr; |
| 2670 | void __user *argp = (void __user *)arg; |
| 2671 | |
| 2672 | switch (cmd) { |
| 2673 | case SIOCGETLINKNAME: |
| 2674 | if (copy_from_user(&lnr, argp, sizeof(lnr))) |
| 2675 | return -EFAULT; |
| 2676 | if (!tipc_node_get_linkname(lnr.bearer_id, lnr.peer, |
| 2677 | lnr.linkname, TIPC_MAX_LINK_NAME)) { |
| 2678 | if (copy_to_user(argp, &lnr, sizeof(lnr))) |
| 2679 | return -EFAULT; |
| 2680 | return 0; |
| 2681 | } |
| 2682 | return -EADDRNOTAVAIL; |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 2683 | default: |
| 2684 | return -ENOIOCTLCMD; |
| 2685 | } |
| 2686 | } |
| 2687 | |
Ben Hutchings | ae86b9e | 2012-07-10 10:55:35 +0000 | [diff] [blame] | 2688 | /* Protocol switches for the various types of TIPC sockets */ |
| 2689 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 2690 | static const struct proto_ops msg_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2691 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2692 | .family = AF_TIPC, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2693 | .release = tipc_release, |
| 2694 | .bind = tipc_bind, |
| 2695 | .connect = tipc_connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 2696 | .socketpair = sock_no_socketpair, |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 2697 | .accept = sock_no_accept, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2698 | .getname = tipc_getname, |
| 2699 | .poll = tipc_poll, |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 2700 | .ioctl = tipc_ioctl, |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 2701 | .listen = sock_no_listen, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2702 | .shutdown = tipc_shutdown, |
| 2703 | .setsockopt = tipc_setsockopt, |
| 2704 | .getsockopt = tipc_getsockopt, |
| 2705 | .sendmsg = tipc_sendmsg, |
| 2706 | .recvmsg = tipc_recvmsg, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 2707 | .mmap = sock_no_mmap, |
| 2708 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2709 | }; |
| 2710 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 2711 | static const struct proto_ops packet_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2712 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2713 | .family = AF_TIPC, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2714 | .release = tipc_release, |
| 2715 | .bind = tipc_bind, |
| 2716 | .connect = tipc_connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 2717 | .socketpair = sock_no_socketpair, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2718 | .accept = tipc_accept, |
| 2719 | .getname = tipc_getname, |
| 2720 | .poll = tipc_poll, |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 2721 | .ioctl = tipc_ioctl, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2722 | .listen = tipc_listen, |
| 2723 | .shutdown = tipc_shutdown, |
| 2724 | .setsockopt = tipc_setsockopt, |
| 2725 | .getsockopt = tipc_getsockopt, |
| 2726 | .sendmsg = tipc_send_packet, |
| 2727 | .recvmsg = tipc_recvmsg, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 2728 | .mmap = sock_no_mmap, |
| 2729 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2730 | }; |
| 2731 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 2732 | static const struct proto_ops stream_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2733 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2734 | .family = AF_TIPC, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2735 | .release = tipc_release, |
| 2736 | .bind = tipc_bind, |
| 2737 | .connect = tipc_connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 2738 | .socketpair = sock_no_socketpair, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2739 | .accept = tipc_accept, |
| 2740 | .getname = tipc_getname, |
| 2741 | .poll = tipc_poll, |
Erik Hugne | 78acb1f | 2014-04-24 16:26:47 +0200 | [diff] [blame] | 2742 | .ioctl = tipc_ioctl, |
Ying Xue | 247f0f3 | 2014-02-18 16:06:46 +0800 | [diff] [blame] | 2743 | .listen = tipc_listen, |
| 2744 | .shutdown = tipc_shutdown, |
| 2745 | .setsockopt = tipc_setsockopt, |
| 2746 | .getsockopt = tipc_getsockopt, |
| 2747 | .sendmsg = tipc_send_stream, |
| 2748 | .recvmsg = tipc_recv_stream, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 2749 | .mmap = sock_no_mmap, |
| 2750 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2751 | }; |
| 2752 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 2753 | static const struct net_proto_family tipc_family_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 2754 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2755 | .family = AF_TIPC, |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 2756 | .create = tipc_sk_create |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2757 | }; |
| 2758 | |
| 2759 | static struct proto tipc_proto = { |
| 2760 | .name = "TIPC", |
| 2761 | .owner = THIS_MODULE, |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 2762 | .obj_size = sizeof(struct tipc_sock), |
| 2763 | .sysctl_rmem = sysctl_tipc_rmem |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2764 | }; |
| 2765 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 2766 | static struct proto tipc_proto_kern = { |
| 2767 | .name = "TIPC", |
| 2768 | .obj_size = sizeof(struct tipc_sock), |
| 2769 | .sysctl_rmem = sysctl_tipc_rmem |
| 2770 | }; |
| 2771 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2772 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2773 | * tipc_socket_init - initialize TIPC socket interface |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2774 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2775 | * Returns 0 on success, errno otherwise |
| 2776 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2777 | int tipc_socket_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2778 | { |
| 2779 | int res; |
| 2780 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 2781 | res = proto_register(&tipc_proto, 1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2782 | if (res) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2783 | pr_err("Failed to register TIPC protocol type\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2784 | goto out; |
| 2785 | } |
| 2786 | |
| 2787 | res = sock_register(&tipc_family_ops); |
| 2788 | if (res) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2789 | pr_err("Failed to register TIPC socket type\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2790 | proto_unregister(&tipc_proto); |
| 2791 | goto out; |
| 2792 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2793 | out: |
| 2794 | return res; |
| 2795 | } |
| 2796 | |
| 2797 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2798 | * tipc_socket_stop - stop TIPC socket interface |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2799 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2800 | void tipc_socket_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2801 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2802 | sock_unregister(tipc_family_ops.family); |
| 2803 | proto_unregister(&tipc_proto); |
| 2804 | } |