Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/socket.c: TIPC socket API |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Maloy | e643df1 | 2012-11-27 06:15:29 -0500 | [diff] [blame] | 4 | * Copyright (c) 2001-2007, 2012 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" |
Allan Stephens | d265fef | 2010-11-30 12:00:53 +0000 | [diff] [blame] | 38 | #include "port.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 40 | #include <linux/export.h> |
| 41 | #include <net/sock.h> |
| 42 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 43 | #define SS_LISTENING -1 /* socket is listening */ |
| 44 | #define SS_READY -2 /* socket is connectionless */ |
| 45 | |
Allan Stephens | 3654ea0 | 2008-04-13 21:35:11 -0700 | [diff] [blame] | 46 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 47 | |
| 48 | struct tipc_sock { |
| 49 | struct sock sk; |
| 50 | struct tipc_port *p; |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 51 | struct tipc_portid peer_name; |
Allan Stephens | a0f40f0 | 2011-05-26 13:44:34 -0400 | [diff] [blame] | 52 | unsigned int conn_timeout; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 55 | #define tipc_sk(sk) ((struct tipc_sock *)(sk)) |
Joe Perches | e319269 | 2012-06-03 17:41:40 +0000 | [diff] [blame] | 56 | #define tipc_sk_port(sk) (tipc_sk(sk)->p) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 57 | |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 58 | #define tipc_rx_ready(sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \ |
| 59 | (sock->state == SS_DISCONNECTING)) |
| 60 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 61 | static int backlog_rcv(struct sock *sk, struct sk_buff *skb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 62 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf); |
| 63 | static void wakeupdispatch(struct tipc_port *tport); |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 64 | static void tipc_data_ready(struct sock *sk, int len); |
| 65 | static void tipc_write_space(struct sock *sk); |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 66 | static int release(struct socket *sock); |
| 67 | static int accept(struct socket *sock, struct socket *new_sock, int flags); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 68 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 69 | static const struct proto_ops packet_ops; |
| 70 | static const struct proto_ops stream_ops; |
| 71 | static const struct proto_ops msg_ops; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 72 | |
| 73 | static struct proto tipc_proto; |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 74 | static struct proto tipc_proto_kern; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 75 | |
Allan Stephens | e3ec9c7 | 2010-12-31 18:59:34 +0000 | [diff] [blame] | 76 | static int sockets_enabled; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 77 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 78 | /* |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 79 | * Revised TIPC socket locking policy: |
| 80 | * |
| 81 | * Most socket operations take the standard socket lock when they start |
| 82 | * and hold it until they finish (or until they need to sleep). Acquiring |
| 83 | * this lock grants the owner exclusive access to the fields of the socket |
| 84 | * data structures, with the exception of the backlog queue. A few socket |
| 85 | * operations can be done without taking the socket lock because they only |
| 86 | * read socket information that never changes during the life of the socket. |
| 87 | * |
| 88 | * Socket operations may acquire the lock for the associated TIPC port if they |
| 89 | * need to perform an operation on the port. If any routine needs to acquire |
| 90 | * both the socket lock and the port lock it must take the socket lock first |
| 91 | * to avoid the risk of deadlock. |
| 92 | * |
| 93 | * The dispatcher handling incoming messages cannot grab the socket lock in |
| 94 | * the standard fashion, since invoked it runs at the BH level and cannot block. |
| 95 | * Instead, it checks to see if the socket lock is currently owned by someone, |
| 96 | * and either handles the message itself or adds it to the socket's backlog |
| 97 | * queue; in the latter case the queued message is processed once the process |
| 98 | * owning the socket lock releases it. |
| 99 | * |
| 100 | * NOTE: Releasing the socket lock while an operation is sleeping overcomes |
| 101 | * the problem of a blocked socket operation preventing any other operations |
| 102 | * from occurring. However, applications must be careful if they have |
| 103 | * multiple threads trying to send (or receive) on the same socket, as these |
| 104 | * operations might interfere with each other. For example, doing a connect |
| 105 | * and a receive at the same time might allow the receive to consume the |
| 106 | * ACK message meant for the connect. While additional work could be done |
| 107 | * to try and overcome this, it doesn't seem to be worthwhile at the present. |
| 108 | * |
| 109 | * NOTE: Releasing the socket lock while an operation is sleeping also ensures |
| 110 | * that another operation that must be performed in a non-blocking manner is |
| 111 | * not delayed for very long because the lock has already been taken. |
| 112 | * |
| 113 | * NOTE: This code assumes that certain fields of a port/socket pair are |
| 114 | * constant over its lifetime; such fields can be examined without taking |
| 115 | * the socket lock and/or port lock, and do not need to be re-read even |
| 116 | * after resuming processing after waiting. These fields include: |
| 117 | * - socket type |
| 118 | * - pointer to socket sk structure (aka tipc_sock structure) |
| 119 | * - pointer to port structure |
| 120 | * - port reference |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 121 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 122 | |
| 123 | /** |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 124 | * advance_rx_queue - discard first buffer in socket receive queue |
| 125 | * |
| 126 | * Caller must hold socket lock |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 128 | static void advance_rx_queue(struct sock *sk) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 129 | { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 130 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 134 | * reject_rx_queue - reject all buffers in socket receive queue |
| 135 | * |
| 136 | * Caller must hold socket lock |
| 137 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 138 | static void reject_rx_queue(struct sock *sk) |
| 139 | { |
| 140 | struct sk_buff *buf; |
| 141 | |
Ying Xue | 9da3d47 | 2012-11-27 06:15:27 -0500 | [diff] [blame] | 142 | while ((buf = __skb_dequeue(&sk->sk_receive_queue))) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 143 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 147 | * tipc_sk_create - create a TIPC socket |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 148 | * @net: network namespace (must be default network) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 149 | * @sock: pre-allocated socket structure |
| 150 | * @protocol: protocol indicator (must be 0) |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 151 | * @kern: caused by kernel or by userspace? |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 152 | * |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 153 | * This routine creates additional data structures used by the TIPC socket, |
| 154 | * initializes them, and links them together. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 155 | * |
| 156 | * Returns 0 on success, errno otherwise |
| 157 | */ |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 158 | static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, |
| 159 | int kern) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 161 | const struct proto_ops *ops; |
| 162 | socket_state state; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 163 | struct sock *sk; |
Allan Stephens | 7ef43eb | 2008-05-12 15:42:28 -0700 | [diff] [blame] | 164 | struct tipc_port *tp_ptr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 165 | |
| 166 | /* Validate arguments */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 167 | if (unlikely(protocol != 0)) |
| 168 | return -EPROTONOSUPPORT; |
| 169 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 170 | switch (sock->type) { |
| 171 | case SOCK_STREAM: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 172 | ops = &stream_ops; |
| 173 | state = SS_UNCONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 174 | break; |
| 175 | case SOCK_SEQPACKET: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 176 | ops = &packet_ops; |
| 177 | state = SS_UNCONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 178 | break; |
| 179 | case SOCK_DGRAM: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 180 | case SOCK_RDM: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 181 | ops = &msg_ops; |
| 182 | state = SS_READY; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 183 | break; |
Allan Stephens | 4997865 | 2006-06-25 23:47:18 -0700 | [diff] [blame] | 184 | default: |
Allan Stephens | 4997865 | 2006-06-25 23:47:18 -0700 | [diff] [blame] | 185 | return -EPROTOTYPE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 188 | /* Allocate socket's protocol area */ |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 189 | if (!kern) |
| 190 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto); |
| 191 | else |
| 192 | sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto_kern); |
| 193 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 194 | if (sk == NULL) |
| 195 | return -ENOMEM; |
| 196 | |
| 197 | /* Allocate TIPC port for socket to use */ |
Ying Xue | 3c5db8e | 2013-06-17 10:54:44 -0400 | [diff] [blame] | 198 | tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch, |
| 199 | TIPC_LOW_IMPORTANCE); |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 200 | if (unlikely(!tp_ptr)) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 201 | sk_free(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 202 | return -ENOMEM; |
| 203 | } |
| 204 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 205 | /* Finish initializing socket data structures */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 206 | sock->ops = ops; |
| 207 | sock->state = state; |
| 208 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 209 | sock_init_data(sock, sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 210 | sk->sk_backlog_rcv = backlog_rcv; |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 211 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 212 | sk->sk_data_ready = tipc_data_ready; |
| 213 | sk->sk_write_space = tipc_write_space; |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 214 | tipc_sk(sk)->p = tp_ptr; |
Allan Stephens | a0f40f0 | 2011-05-26 13:44:34 -0400 | [diff] [blame] | 215 | tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 216 | |
Allan Stephens | 7ef43eb | 2008-05-12 15:42:28 -0700 | [diff] [blame] | 217 | spin_unlock_bh(tp_ptr->lock); |
| 218 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 219 | if (sock->state == SS_READY) { |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 220 | tipc_set_portunreturnable(tp_ptr->ref, 1); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 221 | if (sock->type == SOCK_DGRAM) |
Allan Stephens | 0ea5224 | 2008-07-14 22:42:19 -0700 | [diff] [blame] | 222 | tipc_set_portunreliable(tp_ptr->ref, 1); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 223 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 224 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /** |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 229 | * tipc_sock_create_local - create TIPC socket from inside TIPC module |
| 230 | * @type: socket type - SOCK_RDM or SOCK_SEQPACKET |
| 231 | * |
| 232 | * We cannot use sock_creat_kern here because it bumps module user count. |
| 233 | * Since socket owner and creator is the same module we must make sure |
| 234 | * that module count remains zero for module local sockets, otherwise |
| 235 | * we cannot do rmmod. |
| 236 | * |
| 237 | * Returns 0 on success, errno otherwise |
| 238 | */ |
| 239 | int tipc_sock_create_local(int type, struct socket **res) |
| 240 | { |
| 241 | int rc; |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 242 | |
| 243 | rc = sock_create_lite(AF_TIPC, type, 0, res); |
| 244 | if (rc < 0) { |
| 245 | pr_err("Failed to create kernel socket\n"); |
| 246 | return rc; |
| 247 | } |
| 248 | tipc_sk_create(&init_net, *res, 0, 1); |
| 249 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * tipc_sock_release_local - release socket created by tipc_sock_create_local |
| 255 | * @sock: the socket to be released. |
| 256 | * |
| 257 | * Module reference count is not incremented when such sockets are created, |
| 258 | * so we must keep it from being decremented when they are released. |
| 259 | */ |
| 260 | void tipc_sock_release_local(struct socket *sock) |
| 261 | { |
| 262 | release(sock); |
| 263 | sock->ops = NULL; |
| 264 | sock_release(sock); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * tipc_sock_accept_local - accept a connection on a socket created |
| 269 | * with tipc_sock_create_local. Use this function to avoid that |
| 270 | * module reference count is inadvertently incremented. |
| 271 | * |
| 272 | * @sock: the accepting socket |
| 273 | * @newsock: reference to the new socket to be created |
| 274 | * @flags: socket flags |
| 275 | */ |
| 276 | |
| 277 | int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 278 | int flags) |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 279 | { |
| 280 | struct sock *sk = sock->sk; |
| 281 | int ret; |
| 282 | |
| 283 | ret = sock_create_lite(sk->sk_family, sk->sk_type, |
| 284 | sk->sk_protocol, newsock); |
| 285 | if (ret < 0) |
| 286 | return ret; |
| 287 | |
| 288 | ret = accept(sock, *newsock, flags); |
| 289 | if (ret < 0) { |
| 290 | sock_release(*newsock); |
| 291 | return ret; |
| 292 | } |
| 293 | (*newsock)->ops = sock->ops; |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | * release - destroy a TIPC socket |
| 299 | * @sock: socket to destroy |
| 300 | * |
| 301 | * This routine cleans up any messages that are still queued on the socket. |
| 302 | * For DGRAM and RDM socket types, all queued messages are rejected. |
| 303 | * For SEQPACKET and STREAM socket types, the first message is rejected |
| 304 | * and any others are discarded. (If the first message on a STREAM socket |
| 305 | * 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] | 306 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 307 | * NOTE: Rejected messages are not necessarily returned to the sender! They |
| 308 | * are returned or discarded according to the "destination droppable" setting |
| 309 | * specified for the message by the sender. |
| 310 | * |
| 311 | * Returns 0 on success, errno otherwise |
| 312 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 313 | static int release(struct socket *sock) |
| 314 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 315 | struct sock *sk = sock->sk; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 316 | struct tipc_port *tport; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 317 | struct sk_buff *buf; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 318 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 319 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 320 | /* |
| 321 | * Exit if socket isn't fully initialized (occurs when a failed accept() |
| 322 | * releases a pre-allocated child socket that was never used) |
| 323 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 324 | if (sk == NULL) |
| 325 | return 0; |
| 326 | |
| 327 | tport = tipc_sk_port(sk); |
| 328 | lock_sock(sk); |
| 329 | |
| 330 | /* |
| 331 | * Reject all unreceived messages, except on an active connection |
| 332 | * (which disconnects locally & sends a 'FIN+' to peer) |
| 333 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 334 | while (sock->state != SS_DISCONNECTING) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 335 | buf = __skb_dequeue(&sk->sk_receive_queue); |
| 336 | if (buf == NULL) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 337 | break; |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 338 | if (TIPC_SKB_CB(buf)->handle != NULL) |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 339 | kfree_skb(buf); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 340 | else { |
| 341 | if ((sock->state == SS_CONNECTING) || |
| 342 | (sock->state == SS_CONNECTED)) { |
| 343 | sock->state = SS_DISCONNECTING; |
| 344 | tipc_disconnect(tport->ref); |
| 345 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | tipc_reject_msg(buf, TIPC_ERR_NO_PORT); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 347 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 350 | /* |
| 351 | * Delete TIPC port; this ensures no more messages are queued |
| 352 | * (also disconnects an active connection & sends a 'FIN-' to peer) |
| 353 | */ |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 354 | res = tipc_deleteport(tport); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 355 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 356 | /* Discard any remaining (connection-based) messages in receive queue */ |
Ying Xue | 57467e5 | 2013-01-20 23:30:08 +0100 | [diff] [blame] | 357 | __skb_queue_purge(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 358 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 359 | /* Reject any messages that accumulated in backlog queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 360 | sock->state = SS_DISCONNECTING; |
| 361 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 362 | |
| 363 | sock_put(sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 364 | sock->sk = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 365 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 366 | return res; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * bind - associate or disassocate TIPC name(s) with a socket |
| 371 | * @sock: socket structure |
| 372 | * @uaddr: socket address describing name(s) and desired operation |
| 373 | * @uaddr_len: size of socket address data structure |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 374 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 375 | * Name and name sequence binding is indicated using a positive scope value; |
| 376 | * a negative scope value unbinds the specified name. Specifying no name |
| 377 | * (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] | 378 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 379 | * Returns 0 on success, errno otherwise |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 380 | * |
| 381 | * NOTE: This routine doesn't need to take the socket lock since it doesn't |
| 382 | * access any non-constant socket information. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 383 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 384 | static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len) |
| 385 | { |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 386 | struct sock *sk = sock->sk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 387 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 388 | struct tipc_port *tport = tipc_sk_port(sock->sk); |
| 389 | int res = -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 390 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 391 | lock_sock(sk); |
| 392 | if (unlikely(!uaddr_len)) { |
| 393 | res = tipc_withdraw(tport, 0, NULL); |
| 394 | goto exit; |
| 395 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 396 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 397 | if (uaddr_len < sizeof(struct sockaddr_tipc)) { |
| 398 | res = -EINVAL; |
| 399 | goto exit; |
| 400 | } |
| 401 | if (addr->family != AF_TIPC) { |
| 402 | res = -EAFNOSUPPORT; |
| 403 | goto exit; |
| 404 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 405 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 406 | if (addr->addrtype == TIPC_ADDR_NAME) |
| 407 | addr->addr.nameseq.upper = addr->addr.nameseq.lower; |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 408 | else if (addr->addrtype != TIPC_ADDR_NAMESEQ) { |
| 409 | res = -EAFNOSUPPORT; |
| 410 | goto exit; |
| 411 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 412 | |
Ying Xue | 13a2e89 | 2013-06-17 10:54:40 -0400 | [diff] [blame] | 413 | if ((addr->addr.nameseq.type < TIPC_RESERVED_TYPES) && |
Ying Xue | 7d0ab17 | 2013-06-17 10:54:41 -0400 | [diff] [blame] | 414 | (addr->addr.nameseq.type != TIPC_TOP_SRV) && |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 415 | (addr->addr.nameseq.type != TIPC_CFG_SRV)) { |
| 416 | res = -EACCES; |
| 417 | goto exit; |
| 418 | } |
Allan Stephens | c422f1b | 2011-11-02 15:49:40 -0400 | [diff] [blame] | 419 | |
Ying Xue | 8460276 | 2013-12-27 10:18:28 +0800 | [diff] [blame] | 420 | res = (addr->scope > 0) ? |
| 421 | tipc_publish(tport, addr->scope, &addr->addr.nameseq) : |
| 422 | tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq); |
| 423 | exit: |
| 424 | release_sock(sk); |
| 425 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 426 | } |
| 427 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 428 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 429 | * get_name - get port ID of socket or peer socket |
| 430 | * @sock: socket structure |
| 431 | * @uaddr: area for returned socket address |
| 432 | * @uaddr_len: area for returned length of socket address |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 433 | * @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] | 434 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 435 | * Returns 0 on success, errno otherwise |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 436 | * |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 437 | * NOTE: This routine doesn't need to take the socket lock since it only |
| 438 | * accesses socket information that is unchanging (or which changes in |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 439 | * a completely predictable manner). |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 440 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 441 | static int get_name(struct socket *sock, struct sockaddr *uaddr, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 442 | int *uaddr_len, int peer) |
| 443 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 444 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 445 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 446 | |
Kulikov Vasiliy | 88f8a5e | 2010-10-31 07:10:32 +0000 | [diff] [blame] | 447 | memset(addr, 0, sizeof(*addr)); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 448 | if (peer) { |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 449 | if ((sock->state != SS_CONNECTED) && |
| 450 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) |
| 451 | return -ENOTCONN; |
| 452 | addr->addr.id.ref = tsock->peer_name.ref; |
| 453 | addr->addr.id.node = tsock->peer_name.node; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 454 | } else { |
Allan Stephens | b924dcf | 2010-11-30 12:01:03 +0000 | [diff] [blame] | 455 | addr->addr.id.ref = tsock->p->ref; |
| 456 | addr->addr.id.node = tipc_own_addr; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 457 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 458 | |
| 459 | *uaddr_len = sizeof(*addr); |
| 460 | addr->addrtype = TIPC_ADDR_ID; |
| 461 | addr->family = AF_TIPC; |
| 462 | addr->scope = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 463 | addr->addr.name.domain = 0; |
| 464 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 465 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
| 469 | * poll - read and possibly block on pollmask |
| 470 | * @file: file structure associated with the socket |
| 471 | * @sock: socket for which to calculate the poll bits |
| 472 | * @wait: ??? |
| 473 | * |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 474 | * Returns pollmask value |
| 475 | * |
| 476 | * COMMENTARY: |
| 477 | * It appears that the usual socket locking mechanisms are not useful here |
| 478 | * since the pollmask info is potentially out-of-date the moment this routine |
| 479 | * exits. TCP and other protocols seem to rely on higher level poll routines |
| 480 | * to handle any preventable race conditions, so TIPC will do the same ... |
| 481 | * |
| 482 | * TIPC sets the returned events as follows: |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 483 | * |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 484 | * socket state flags set |
| 485 | * ------------ --------- |
| 486 | * unconnected no read flags |
Erik Hugne | c4fc298 | 2012-10-16 16:47:06 +0200 | [diff] [blame] | 487 | * POLLOUT if port is not congested |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 488 | * |
| 489 | * connecting POLLIN/POLLRDNORM if ACK/NACK in rx queue |
| 490 | * no write flags |
| 491 | * |
| 492 | * connected POLLIN/POLLRDNORM if data in rx queue |
| 493 | * POLLOUT if port is not congested |
| 494 | * |
| 495 | * disconnecting POLLIN/POLLRDNORM/POLLHUP |
| 496 | * no write flags |
| 497 | * |
| 498 | * listening POLLIN if SYN in rx queue |
| 499 | * no write flags |
| 500 | * |
| 501 | * ready POLLIN/POLLRDNORM if data in rx queue |
| 502 | * [connectionless] POLLOUT (since port cannot be congested) |
| 503 | * |
| 504 | * IMPORTANT: The fact that a read or write operation is indicated does NOT |
| 505 | * imply that the operation will succeed, merely that it should be performed |
| 506 | * and will not block. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 507 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 508 | static unsigned int poll(struct file *file, struct socket *sock, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 509 | poll_table *wait) |
| 510 | { |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 511 | struct sock *sk = sock->sk; |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 512 | u32 mask = 0; |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 513 | |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 514 | sock_poll_wait(file, sk_sleep(sk), wait); |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 515 | |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 516 | switch ((int)sock->state) { |
Erik Hugne | c4fc298 | 2012-10-16 16:47:06 +0200 | [diff] [blame] | 517 | case SS_UNCONNECTED: |
| 518 | if (!tipc_sk_port(sk)->congested) |
| 519 | mask |= POLLOUT; |
| 520 | break; |
Allan Stephens | f662c07 | 2010-08-17 11:00:06 +0000 | [diff] [blame] | 521 | case SS_READY: |
| 522 | case SS_CONNECTED: |
| 523 | if (!tipc_sk_port(sk)->congested) |
| 524 | mask |= POLLOUT; |
| 525 | /* fall thru' */ |
| 526 | case SS_CONNECTING: |
| 527 | case SS_LISTENING: |
| 528 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 529 | mask |= (POLLIN | POLLRDNORM); |
| 530 | break; |
| 531 | case SS_DISCONNECTING: |
| 532 | mask = (POLLIN | POLLRDNORM | POLLHUP); |
| 533 | break; |
| 534 | } |
Allan Stephens | 9b674e8 | 2008-03-26 16:48:21 -0700 | [diff] [blame] | 535 | |
| 536 | return mask; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 537 | } |
| 538 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 539 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 540 | * dest_name_check - verify user is permitted to send to specified port name |
| 541 | * @dest: destination address |
| 542 | * @m: descriptor for message to be sent |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 543 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 544 | * Prevents restricted configuration commands from being issued by |
| 545 | * unauthorized users. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 546 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 547 | * Returns 0 if permission is granted, otherwise errno |
| 548 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 549 | static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 550 | { |
| 551 | struct tipc_cfg_msg_hdr hdr; |
| 552 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 553 | if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES)) |
| 554 | return 0; |
| 555 | if (likely(dest->addr.name.name.type == TIPC_TOP_SRV)) |
| 556 | return 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 557 | if (likely(dest->addr.name.name.type != TIPC_CFG_SRV)) |
| 558 | return -EACCES; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 559 | |
Allan Stephens | 3f8dd94 | 2011-01-18 13:09:29 -0500 | [diff] [blame] | 560 | if (!m->msg_iovlen || (m->msg_iov[0].iov_len < sizeof(hdr))) |
| 561 | return -EMSGSIZE; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 562 | 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] | 563 | return -EFAULT; |
Allan Stephens | 70cb234 | 2006-06-25 23:41:47 -0700 | [diff] [blame] | 564 | if ((ntohs(hdr.tcm_type) & 0xC000) && (!capable(CAP_NET_ADMIN))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 565 | return -EACCES; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 566 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame^] | 570 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) |
| 571 | { |
| 572 | struct sock *sk = sock->sk; |
| 573 | struct tipc_port *tport = tipc_sk_port(sk); |
| 574 | DEFINE_WAIT(wait); |
| 575 | int done; |
| 576 | |
| 577 | do { |
| 578 | int err = sock_error(sk); |
| 579 | if (err) |
| 580 | return err; |
| 581 | if (sock->state == SS_DISCONNECTING) |
| 582 | return -EPIPE; |
| 583 | if (!*timeo_p) |
| 584 | return -EAGAIN; |
| 585 | if (signal_pending(current)) |
| 586 | return sock_intr_errno(*timeo_p); |
| 587 | |
| 588 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 589 | done = sk_wait_event(sk, timeo_p, !tport->congested); |
| 590 | finish_wait(sk_sleep(sk), &wait); |
| 591 | } while (!done); |
| 592 | return 0; |
| 593 | } |
| 594 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 595 | /** |
| 596 | * send_msg - send message in connectionless manner |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 597 | * @iocb: if NULL, indicates that socket lock is already held |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 598 | * @sock: socket structure |
| 599 | * @m: message to send |
Allan Stephens | e9024f0f | 2006-06-25 23:43:57 -0700 | [diff] [blame] | 600 | * @total_len: length of message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 601 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 602 | * Message must have an destination specified explicitly. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 603 | * Used for SOCK_RDM and SOCK_DGRAM messages, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 604 | * and for 'SYN' messages on SOCK_SEQPACKET and SOCK_STREAM connections. |
| 605 | * (Note: 'SYN+' is prohibited on SOCK_STREAM.) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 606 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 607 | * Returns the number of bytes sent on success, or errno otherwise |
| 608 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 609 | static int send_msg(struct kiocb *iocb, struct socket *sock, |
| 610 | struct msghdr *m, size_t total_len) |
| 611 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 612 | struct sock *sk = sock->sk; |
| 613 | struct tipc_port *tport = tipc_sk_port(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 614 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 615 | int needs_conn; |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame^] | 616 | long timeo; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 617 | int res = -EINVAL; |
| 618 | |
| 619 | if (unlikely(!dest)) |
| 620 | return -EDESTADDRREQ; |
Allan Stephens | 51f9cc1 | 2006-06-25 23:49:06 -0700 | [diff] [blame] | 621 | if (unlikely((m->msg_namelen < sizeof(*dest)) || |
| 622 | (dest->family != AF_TIPC))) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 623 | return -EINVAL; |
Ying Xue | 97f8b87 | 2013-01-31 21:51:47 +0100 | [diff] [blame] | 624 | if (total_len > TIPC_MAX_USER_MSG_SIZE) |
Allan Stephens | c29c3f7 | 2010-04-20 17:58:24 -0400 | [diff] [blame] | 625 | return -EMSGSIZE; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 626 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 627 | if (iocb) |
| 628 | lock_sock(sk); |
| 629 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 630 | needs_conn = (sock->state != SS_READY); |
| 631 | if (unlikely(needs_conn)) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 632 | if (sock->state == SS_LISTENING) { |
| 633 | res = -EPIPE; |
| 634 | goto exit; |
Allan Stephens | 3388007 | 2006-06-25 23:44:57 -0700 | [diff] [blame] | 635 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 636 | if (sock->state != SS_UNCONNECTED) { |
| 637 | res = -EISCONN; |
| 638 | goto exit; |
| 639 | } |
Erik Hugne | 5d21cb7 | 2013-06-17 10:54:38 -0400 | [diff] [blame] | 640 | if (tport->published) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 641 | res = -EOPNOTSUPP; |
| 642 | goto exit; |
| 643 | } |
| 644 | if (dest->addrtype == TIPC_ADDR_NAME) { |
| 645 | tport->conn_type = dest->addr.name.name.type; |
| 646 | tport->conn_instance = dest->addr.name.name.instance; |
| 647 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 648 | |
| 649 | /* Abort any pending connection attempts (very unlikely) */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 650 | reject_rx_queue(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 651 | } |
| 652 | |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame^] | 653 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 654 | do { |
| 655 | if (dest->addrtype == TIPC_ADDR_NAME) { |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 656 | res = dest_name_check(dest, m); |
| 657 | if (res) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 658 | break; |
| 659 | res = tipc_send2name(tport->ref, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 660 | &dest->addr.name.name, |
| 661 | dest->addr.name.domain, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 662 | m->msg_iov, |
| 663 | total_len); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 664 | } else if (dest->addrtype == TIPC_ADDR_ID) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 665 | res = tipc_send2port(tport->ref, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 666 | &dest->addr.id, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 667 | m->msg_iov, |
| 668 | total_len); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 669 | } else if (dest->addrtype == TIPC_ADDR_MCAST) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 670 | if (needs_conn) { |
| 671 | res = -EOPNOTSUPP; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 672 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 673 | } |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 674 | res = dest_name_check(dest, m); |
| 675 | if (res) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 676 | break; |
| 677 | res = tipc_multicast(tport->ref, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 678 | &dest->addr.nameseq, |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 679 | m->msg_iov, |
| 680 | total_len); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 681 | } |
| 682 | if (likely(res != -ELINKCONG)) { |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 683 | if (needs_conn && (res >= 0)) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 684 | sock->state = SS_CONNECTING; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 685 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 686 | } |
Ying Xue | 3f40504 | 2014-01-17 09:50:05 +0800 | [diff] [blame^] | 687 | res = tipc_wait_for_sndmsg(sock, &timeo); |
| 688 | if (res) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 689 | break; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 690 | } while (1); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 691 | |
| 692 | exit: |
| 693 | if (iocb) |
| 694 | release_sock(sk); |
| 695 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 696 | } |
| 697 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 698 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 699 | * send_packet - send a connection-oriented message |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 700 | * @iocb: if NULL, indicates that socket lock is already held |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 701 | * @sock: socket structure |
| 702 | * @m: message to send |
Allan Stephens | e9024f0f | 2006-06-25 23:43:57 -0700 | [diff] [blame] | 703 | * @total_len: length of message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 704 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 705 | * Used for SOCK_SEQPACKET messages and SOCK_STREAM data. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 706 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 707 | * Returns the number of bytes sent on success, or errno otherwise |
| 708 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 709 | static int send_packet(struct kiocb *iocb, struct socket *sock, |
| 710 | struct msghdr *m, size_t total_len) |
| 711 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 712 | struct sock *sk = sock->sk; |
| 713 | struct tipc_port *tport = tipc_sk_port(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 714 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; |
Ying Xue | 1d83587 | 2011-07-06 05:53:15 -0400 | [diff] [blame] | 715 | long timeout_val; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 716 | int res; |
| 717 | |
| 718 | /* Handle implied connection establishment */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 719 | if (unlikely(dest)) |
| 720 | return send_msg(iocb, sock, m, total_len); |
| 721 | |
Ying Xue | 97f8b87 | 2013-01-31 21:51:47 +0100 | [diff] [blame] | 722 | if (total_len > TIPC_MAX_USER_MSG_SIZE) |
Allan Stephens | c29c3f7 | 2010-04-20 17:58:24 -0400 | [diff] [blame] | 723 | return -EMSGSIZE; |
| 724 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 725 | if (iocb) |
| 726 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 727 | |
Ying Xue | 1d83587 | 2011-07-06 05:53:15 -0400 | [diff] [blame] | 728 | timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
| 729 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 730 | do { |
Allan Stephens | bdd9478 | 2006-06-25 23:45:53 -0700 | [diff] [blame] | 731 | if (unlikely(sock->state != SS_CONNECTED)) { |
| 732 | if (sock->state == SS_DISCONNECTING) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 733 | res = -EPIPE; |
Allan Stephens | bdd9478 | 2006-06-25 23:45:53 -0700 | [diff] [blame] | 734 | else |
| 735 | res = -ENOTCONN; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 736 | break; |
Allan Stephens | bdd9478 | 2006-06-25 23:45:53 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 739 | res = tipc_send(tport->ref, m->msg_iov, total_len); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 740 | if (likely(res != -ELINKCONG)) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 741 | break; |
Ying Xue | 1d83587 | 2011-07-06 05:53:15 -0400 | [diff] [blame] | 742 | if (timeout_val <= 0L) { |
| 743 | res = timeout_val ? timeout_val : -EWOULDBLOCK; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 744 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 745 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 746 | release_sock(sk); |
Ying Xue | 1d83587 | 2011-07-06 05:53:15 -0400 | [diff] [blame] | 747 | timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk), |
| 748 | (!tport->congested || !tport->connected), timeout_val); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 749 | lock_sock(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 750 | } while (1); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 751 | |
| 752 | if (iocb) |
| 753 | release_sock(sk); |
| 754 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 755 | } |
| 756 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 757 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 758 | * send_stream - send stream-oriented data |
| 759 | * @iocb: (unused) |
| 760 | * @sock: socket structure |
| 761 | * @m: data to send |
| 762 | * @total_len: total length of data to be sent |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 763 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 764 | * Used for SOCK_STREAM data. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 765 | * |
| 766 | * Returns the number of bytes sent on success (or partial success), |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 767 | * or errno if no data sent |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 768 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 769 | static int send_stream(struct kiocb *iocb, struct socket *sock, |
| 770 | struct msghdr *m, size_t total_len) |
| 771 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 772 | struct sock *sk = sock->sk; |
| 773 | struct tipc_port *tport = tipc_sk_port(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 774 | struct msghdr my_msg; |
| 775 | struct iovec my_iov; |
| 776 | struct iovec *curr_iov; |
| 777 | int curr_iovlen; |
| 778 | char __user *curr_start; |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 779 | u32 hdr_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 780 | int curr_left; |
| 781 | int bytes_to_send; |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 782 | int bytes_sent; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 783 | int res; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 784 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 785 | lock_sock(sk); |
| 786 | |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 787 | /* Handle special cases where there is no connection */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 788 | if (unlikely(sock->state != SS_CONNECTED)) { |
wangweidong | 3b8401f | 2013-12-12 09:36:40 +0800 | [diff] [blame] | 789 | if (sock->state == SS_UNCONNECTED) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 790 | res = send_packet(NULL, sock, m, total_len); |
wangweidong | b055597 | 2013-12-27 10:09:39 +0800 | [diff] [blame] | 791 | else |
| 792 | res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; |
wangweidong | 3b8401f | 2013-12-12 09:36:40 +0800 | [diff] [blame] | 793 | goto exit; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 794 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 795 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 796 | if (unlikely(m->msg_name)) { |
| 797 | res = -EISCONN; |
| 798 | goto exit; |
| 799 | } |
Allan Stephens | eb5959c | 2006-10-16 21:43:54 -0700 | [diff] [blame] | 800 | |
Ying Xue | 97f8b87 | 2013-01-31 21:51:47 +0100 | [diff] [blame] | 801 | if (total_len > (unsigned int)INT_MAX) { |
Allan Stephens | c29c3f7 | 2010-04-20 17:58:24 -0400 | [diff] [blame] | 802 | res = -EMSGSIZE; |
| 803 | goto exit; |
| 804 | } |
| 805 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 806 | /* |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 807 | * Send each iovec entry using one or more messages |
| 808 | * |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 809 | * Note: This algorithm is good for the most likely case |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 810 | * (i.e. one large iovec entry), but could be improved to pass sets |
| 811 | * of small iovec entries into send_packet(). |
| 812 | */ |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 813 | curr_iov = m->msg_iov; |
| 814 | curr_iovlen = m->msg_iovlen; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 815 | my_msg.msg_iov = &my_iov; |
| 816 | my_msg.msg_iovlen = 1; |
Allan Stephens | eb5959c | 2006-10-16 21:43:54 -0700 | [diff] [blame] | 817 | my_msg.msg_flags = m->msg_flags; |
| 818 | my_msg.msg_name = NULL; |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 819 | bytes_sent = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 820 | |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 821 | hdr_size = msg_hdr_sz(&tport->phdr); |
| 822 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 823 | while (curr_iovlen--) { |
| 824 | curr_start = curr_iov->iov_base; |
| 825 | curr_left = curr_iov->iov_len; |
| 826 | |
| 827 | while (curr_left) { |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 828 | bytes_to_send = tport->max_pkt - hdr_size; |
| 829 | if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE) |
| 830 | bytes_to_send = TIPC_MAX_USER_MSG_SIZE; |
| 831 | if (curr_left < bytes_to_send) |
| 832 | bytes_to_send = curr_left; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 833 | my_iov.iov_base = curr_start; |
| 834 | my_iov.iov_len = bytes_to_send; |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 835 | res = send_packet(NULL, sock, &my_msg, bytes_to_send); |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 836 | if (res < 0) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 837 | if (bytes_sent) |
Allan Stephens | 05646c9 | 2007-06-10 17:25:24 -0700 | [diff] [blame] | 838 | res = bytes_sent; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 839 | goto exit; |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 840 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 841 | curr_left -= bytes_to_send; |
| 842 | curr_start += bytes_to_send; |
Allan Stephens | 1303e8f | 2006-06-25 23:46:50 -0700 | [diff] [blame] | 843 | bytes_sent += bytes_to_send; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | curr_iov++; |
| 847 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 848 | res = bytes_sent; |
| 849 | exit: |
| 850 | release_sock(sk); |
| 851 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /** |
| 855 | * auto_connect - complete connection setup to a remote port |
| 856 | * @sock: socket structure |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 857 | * @msg: peer's response message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 858 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 859 | * Returns 0 on success, errno otherwise |
| 860 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 861 | static int auto_connect(struct socket *sock, struct tipc_msg *msg) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 862 | { |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 863 | struct tipc_sock *tsock = tipc_sk(sock->sk); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 864 | struct tipc_port *p_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 865 | |
Allan Stephens | 2da5991 | 2008-07-14 22:43:32 -0700 | [diff] [blame] | 866 | tsock->peer_name.ref = msg_origport(msg); |
| 867 | tsock->peer_name.node = msg_orignode(msg); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 868 | p_ptr = tipc_port_deref(tsock->p->ref); |
| 869 | if (!p_ptr) |
| 870 | return -EINVAL; |
| 871 | |
| 872 | __tipc_connect(tsock->p->ref, p_ptr, &tsock->peer_name); |
| 873 | |
| 874 | if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE) |
| 875 | return -EINVAL; |
| 876 | msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 877 | sock->state = SS_CONNECTED; |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * set_orig_addr - capture sender's address for received message |
| 883 | * @m: descriptor for message info |
| 884 | * @msg: received message header |
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 | * Note: Address is not captured if not requested by receiver. |
| 887 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 888 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 889 | { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 890 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 891 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 892 | if (addr) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 893 | addr->family = AF_TIPC; |
| 894 | addr->addrtype = TIPC_ADDR_ID; |
Mathias Krause | 60085c3 | 2013-04-07 01:52:00 +0000 | [diff] [blame] | 895 | memset(&addr->addr, 0, sizeof(addr->addr)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 896 | addr->addr.id.ref = msg_origport(msg); |
| 897 | addr->addr.id.node = msg_orignode(msg); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 898 | addr->addr.name.domain = 0; /* could leave uninitialized */ |
| 899 | addr->scope = 0; /* could leave uninitialized */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 900 | m->msg_namelen = sizeof(struct sockaddr_tipc); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /** |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 905 | * anc_data_recv - optionally capture ancillary data for received message |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 906 | * @m: descriptor for message info |
| 907 | * @msg: received message header |
| 908 | * @tport: TIPC port associated with message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 909 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 910 | * Note: Ancillary data is not captured if not requested by receiver. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 911 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 912 | * Returns 0 if successful, otherwise errno |
| 913 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 914 | static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 915 | struct tipc_port *tport) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 916 | { |
| 917 | u32 anc_data[3]; |
| 918 | u32 err; |
| 919 | u32 dest_type; |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 920 | int has_name; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 921 | int res; |
| 922 | |
| 923 | if (likely(m->msg_controllen == 0)) |
| 924 | return 0; |
| 925 | |
| 926 | /* Optionally capture errored message object(s) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 927 | err = msg ? msg_errcode(msg) : 0; |
| 928 | if (unlikely(err)) { |
| 929 | anc_data[0] = err; |
| 930 | anc_data[1] = msg_data_sz(msg); |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 931 | res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); |
| 932 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 933 | return res; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 934 | if (anc_data[1]) { |
| 935 | res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], |
| 936 | msg_data(msg)); |
| 937 | if (res) |
| 938 | return res; |
| 939 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /* Optionally capture message destination object */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 943 | dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; |
| 944 | switch (dest_type) { |
| 945 | case TIPC_NAMED_MSG: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 946 | has_name = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 947 | anc_data[0] = msg_nametype(msg); |
| 948 | anc_data[1] = msg_namelower(msg); |
| 949 | anc_data[2] = msg_namelower(msg); |
| 950 | break; |
| 951 | case TIPC_MCAST_MSG: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 952 | has_name = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 953 | anc_data[0] = msg_nametype(msg); |
| 954 | anc_data[1] = msg_namelower(msg); |
| 955 | anc_data[2] = msg_nameupper(msg); |
| 956 | break; |
| 957 | case TIPC_CONN_MSG: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 958 | has_name = (tport->conn_type != 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 959 | anc_data[0] = tport->conn_type; |
| 960 | anc_data[1] = tport->conn_instance; |
| 961 | anc_data[2] = tport->conn_instance; |
| 962 | break; |
| 963 | default: |
Allan Stephens | 3546c75 | 2006-06-25 23:45:24 -0700 | [diff] [blame] | 964 | has_name = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 965 | } |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 966 | if (has_name) { |
| 967 | res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); |
| 968 | if (res) |
| 969 | return res; |
| 970 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 975 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 976 | * recv_msg - receive packet-oriented message |
| 977 | * @iocb: (unused) |
| 978 | * @m: descriptor for message info |
| 979 | * @buf_len: total size of user buffer area |
| 980 | * @flags: receive flags |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 981 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 982 | * Used for SOCK_DGRAM, SOCK_RDM, and SOCK_SEQPACKET messages. |
| 983 | * If the complete message doesn't fit in user area, truncate it. |
| 984 | * |
| 985 | * Returns size of returned message data, errno otherwise |
| 986 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 987 | static int recv_msg(struct kiocb *iocb, struct socket *sock, |
| 988 | struct msghdr *m, size_t buf_len, int flags) |
| 989 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 990 | struct sock *sk = sock->sk; |
| 991 | struct tipc_port *tport = tipc_sk_port(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 992 | struct sk_buff *buf; |
| 993 | struct tipc_msg *msg; |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 994 | long timeout; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 995 | unsigned int sz; |
| 996 | u32 err; |
| 997 | int res; |
| 998 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 999 | /* Catch invalid receive requests */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1000 | if (unlikely(!buf_len)) |
| 1001 | return -EINVAL; |
| 1002 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1003 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1005 | if (unlikely(sock->state == SS_UNCONNECTED)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1006 | res = -ENOTCONN; |
| 1007 | goto exit; |
| 1008 | } |
| 1009 | |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1010 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1011 | restart: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1012 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1013 | /* Look for a message in receive queue; wait if necessary */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1014 | while (skb_queue_empty(&sk->sk_receive_queue)) { |
| 1015 | if (sock->state == SS_DISCONNECTING) { |
| 1016 | res = -ENOTCONN; |
| 1017 | goto exit; |
| 1018 | } |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1019 | if (timeout <= 0L) { |
| 1020 | res = timeout ? timeout : -EWOULDBLOCK; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1021 | goto exit; |
| 1022 | } |
| 1023 | release_sock(sk); |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1024 | timeout = wait_event_interruptible_timeout(*sk_sleep(sk), |
| 1025 | tipc_rx_ready(sock), |
| 1026 | timeout); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1027 | lock_sock(sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /* Look at first message in receive queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1031 | buf = skb_peek(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1032 | msg = buf_msg(buf); |
| 1033 | sz = msg_data_sz(msg); |
| 1034 | err = msg_errcode(msg); |
| 1035 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1036 | /* Discard an empty non-errored message & try again */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1037 | if ((!sz) && (!err)) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1038 | advance_rx_queue(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1039 | goto restart; |
| 1040 | } |
| 1041 | |
| 1042 | /* Capture sender's address (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1043 | set_orig_addr(m, msg); |
| 1044 | |
| 1045 | /* Capture ancillary data (optional) */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1046 | res = anc_data_recv(m, msg, tport); |
| 1047 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1048 | goto exit; |
| 1049 | |
| 1050 | /* Capture message data (if valid) & compute return value (always) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1051 | if (!err) { |
| 1052 | if (unlikely(buf_len < sz)) { |
| 1053 | sz = buf_len; |
| 1054 | m->msg_flags |= MSG_TRUNC; |
| 1055 | } |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1056 | res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg), |
| 1057 | m->msg_iov, sz); |
| 1058 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1059 | goto exit; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1060 | res = sz; |
| 1061 | } else { |
| 1062 | if ((sock->state == SS_READY) || |
| 1063 | ((err == TIPC_CONN_SHUTDOWN) || m->msg_control)) |
| 1064 | res = 0; |
| 1065 | else |
| 1066 | res = -ECONNRESET; |
| 1067 | } |
| 1068 | |
| 1069 | /* Consume received message (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1070 | if (likely(!(flags & MSG_PEEK))) { |
Allan Stephens | 99009806 | 2008-04-15 00:06:12 -0700 | [diff] [blame] | 1071 | if ((sock->state != SS_READY) && |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1072 | (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
| 1073 | tipc_acknowledge(tport->ref, tport->conn_unacked); |
| 1074 | advance_rx_queue(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1075 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1076 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1077 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1078 | return res; |
| 1079 | } |
| 1080 | |
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 | * recv_stream - receive stream-oriented data |
| 1083 | * @iocb: (unused) |
| 1084 | * @m: descriptor for message info |
| 1085 | * @buf_len: total size of user buffer area |
| 1086 | * @flags: receive flags |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1087 | * |
| 1088 | * Used for SOCK_STREAM messages only. If not enough data is available |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1089 | * will optionally wait for more; never truncates data. |
| 1090 | * |
| 1091 | * Returns size of returned message data, errno otherwise |
| 1092 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1093 | static int recv_stream(struct kiocb *iocb, struct socket *sock, |
| 1094 | struct msghdr *m, size_t buf_len, int flags) |
| 1095 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1096 | struct sock *sk = sock->sk; |
| 1097 | struct tipc_port *tport = tipc_sk_port(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1098 | struct sk_buff *buf; |
| 1099 | struct tipc_msg *msg; |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1100 | long timeout; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1101 | unsigned int sz; |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1102 | int sz_to_copy, target, needed; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1103 | int sz_copied = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1104 | u32 err; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1105 | int res = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1106 | |
| 1107 | /* Catch invalid receive attempts */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1108 | if (unlikely(!buf_len)) |
| 1109 | return -EINVAL; |
| 1110 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1111 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1112 | |
Erik Hugne | 5d21cb7 | 2013-06-17 10:54:38 -0400 | [diff] [blame] | 1113 | if (unlikely((sock->state == SS_UNCONNECTED))) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1114 | res = -ENOTCONN; |
| 1115 | goto exit; |
| 1116 | } |
| 1117 | |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1118 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1119 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1120 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1121 | restart: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1122 | /* Look for a message in receive queue; wait if necessary */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1123 | while (skb_queue_empty(&sk->sk_receive_queue)) { |
| 1124 | if (sock->state == SS_DISCONNECTING) { |
| 1125 | res = -ENOTCONN; |
| 1126 | goto exit; |
| 1127 | } |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1128 | if (timeout <= 0L) { |
| 1129 | res = timeout ? timeout : -EWOULDBLOCK; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1130 | goto exit; |
| 1131 | } |
| 1132 | release_sock(sk); |
Allan Stephens | 71092ea | 2011-02-23 14:52:14 -0500 | [diff] [blame] | 1133 | timeout = wait_event_interruptible_timeout(*sk_sleep(sk), |
| 1134 | tipc_rx_ready(sock), |
| 1135 | timeout); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1136 | lock_sock(sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /* Look at first message in receive queue */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1140 | buf = skb_peek(&sk->sk_receive_queue); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1141 | msg = buf_msg(buf); |
| 1142 | sz = msg_data_sz(msg); |
| 1143 | err = msg_errcode(msg); |
| 1144 | |
| 1145 | /* Discard an empty non-errored message & try again */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1146 | if ((!sz) && (!err)) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1147 | advance_rx_queue(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1148 | goto restart; |
| 1149 | } |
| 1150 | |
| 1151 | /* Optionally capture sender's address & ancillary data of first msg */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1152 | if (sz_copied == 0) { |
| 1153 | set_orig_addr(m, msg); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1154 | res = anc_data_recv(m, msg, tport); |
| 1155 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1156 | goto exit; |
| 1157 | } |
| 1158 | |
| 1159 | /* Capture message data (if valid) & compute return value (always) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1160 | if (!err) { |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1161 | u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1162 | |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1163 | sz -= offset; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1164 | needed = (buf_len - sz_copied); |
| 1165 | sz_to_copy = (sz <= needed) ? sz : needed; |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1166 | |
| 1167 | res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg) + offset, |
| 1168 | m->msg_iov, sz_to_copy); |
| 1169 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1170 | goto exit; |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1171 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1172 | sz_copied += sz_to_copy; |
| 1173 | |
| 1174 | if (sz_to_copy < sz) { |
| 1175 | if (!(flags & MSG_PEEK)) |
Allan Stephens | 0232fd0 | 2011-02-21 09:45:40 -0500 | [diff] [blame] | 1176 | TIPC_SKB_CB(buf)->handle = |
| 1177 | (void *)(unsigned long)(offset + sz_to_copy); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1178 | goto exit; |
| 1179 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1180 | } else { |
| 1181 | if (sz_copied != 0) |
| 1182 | goto exit; /* can't add error msg to valid data */ |
| 1183 | |
| 1184 | if ((err == TIPC_CONN_SHUTDOWN) || m->msg_control) |
| 1185 | res = 0; |
| 1186 | else |
| 1187 | res = -ECONNRESET; |
| 1188 | } |
| 1189 | |
| 1190 | /* Consume received message (optional) */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1191 | if (likely(!(flags & MSG_PEEK))) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1192 | if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) |
| 1193 | tipc_acknowledge(tport->ref, tport->conn_unacked); |
| 1194 | advance_rx_queue(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1195 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1196 | |
| 1197 | /* Loop around if more data is required */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1198 | if ((sz_copied < buf_len) && /* didn't get all requested data */ |
| 1199 | (!skb_queue_empty(&sk->sk_receive_queue) || |
Florian Westphal | 3720d40 | 2010-08-17 11:00:04 +0000 | [diff] [blame] | 1200 | (sz_copied < target)) && /* and more is ready or required */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1201 | (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */ |
| 1202 | (!err)) /* and haven't reached a FIN */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1203 | goto restart; |
| 1204 | |
| 1205 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1206 | release_sock(sk); |
Allan Stephens | a3b0a5a | 2006-06-25 23:48:22 -0700 | [diff] [blame] | 1207 | return sz_copied ? sz_copied : res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /** |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 1211 | * tipc_write_space - wake up thread if port congestion is released |
| 1212 | * @sk: socket |
| 1213 | */ |
| 1214 | static void tipc_write_space(struct sock *sk) |
| 1215 | { |
| 1216 | struct socket_wq *wq; |
| 1217 | |
| 1218 | rcu_read_lock(); |
| 1219 | wq = rcu_dereference(sk->sk_wq); |
| 1220 | if (wq_has_sleeper(wq)) |
| 1221 | wake_up_interruptible_sync_poll(&wq->wait, POLLOUT | |
| 1222 | POLLWRNORM | POLLWRBAND); |
| 1223 | rcu_read_unlock(); |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * tipc_data_ready - wake up threads to indicate messages have been received |
| 1228 | * @sk: socket |
| 1229 | * @len: the length of messages |
| 1230 | */ |
| 1231 | static void tipc_data_ready(struct sock *sk, int len) |
| 1232 | { |
| 1233 | struct socket_wq *wq; |
| 1234 | |
| 1235 | rcu_read_lock(); |
| 1236 | wq = rcu_dereference(sk->sk_wq); |
| 1237 | if (wq_has_sleeper(wq)) |
| 1238 | wake_up_interruptible_sync_poll(&wq->wait, POLLIN | |
| 1239 | POLLRDNORM | POLLRDBAND); |
| 1240 | rcu_read_unlock(); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1244 | * filter_connect - Handle all incoming messages for a connection-based socket |
| 1245 | * @tsock: TIPC socket |
| 1246 | * @msg: message |
| 1247 | * |
| 1248 | * Returns TIPC error status code and socket error status code |
| 1249 | * once it encounters some errors |
| 1250 | */ |
| 1251 | static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) |
| 1252 | { |
| 1253 | struct socket *sock = tsock->sk.sk_socket; |
| 1254 | struct tipc_msg *msg = buf_msg(*buf); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1255 | struct sock *sk = &tsock->sk; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1256 | u32 retval = TIPC_ERR_NO_PORT; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1257 | int res; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1258 | |
| 1259 | if (msg_mcast(msg)) |
| 1260 | return retval; |
| 1261 | |
| 1262 | switch ((int)sock->state) { |
| 1263 | case SS_CONNECTED: |
| 1264 | /* Accept only connection-based messages sent by peer */ |
| 1265 | if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) { |
| 1266 | if (unlikely(msg_errcode(msg))) { |
| 1267 | sock->state = SS_DISCONNECTING; |
| 1268 | __tipc_disconnect(tsock->p); |
| 1269 | } |
| 1270 | retval = TIPC_OK; |
| 1271 | } |
| 1272 | break; |
| 1273 | case SS_CONNECTING: |
| 1274 | /* Accept only ACK or NACK message */ |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1275 | if (unlikely(msg_errcode(msg))) { |
| 1276 | sock->state = SS_DISCONNECTING; |
Erik Hugne | 2c8d851 | 2013-08-28 09:29:58 +0200 | [diff] [blame] | 1277 | sk->sk_err = ECONNREFUSED; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1278 | retval = TIPC_OK; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | if (unlikely(!msg_connected(msg))) |
| 1283 | break; |
| 1284 | |
| 1285 | res = auto_connect(sock, msg); |
| 1286 | if (res) { |
| 1287 | sock->state = SS_DISCONNECTING; |
Erik Hugne | 2c8d851 | 2013-08-28 09:29:58 +0200 | [diff] [blame] | 1288 | sk->sk_err = -res; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1289 | retval = TIPC_OK; |
| 1290 | break; |
| 1291 | } |
| 1292 | |
| 1293 | /* If an incoming message is an 'ACK-', it should be |
| 1294 | * discarded here because it doesn't contain useful |
| 1295 | * data. In addition, we should try to wake up |
| 1296 | * connect() routine if sleeping. |
| 1297 | */ |
| 1298 | if (msg_data_sz(msg) == 0) { |
| 1299 | kfree_skb(*buf); |
| 1300 | *buf = NULL; |
| 1301 | if (waitqueue_active(sk_sleep(sk))) |
| 1302 | wake_up_interruptible(sk_sleep(sk)); |
| 1303 | } |
| 1304 | retval = TIPC_OK; |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1305 | break; |
| 1306 | case SS_LISTENING: |
| 1307 | case SS_UNCONNECTED: |
| 1308 | /* Accept only SYN message */ |
| 1309 | if (!msg_connected(msg) && !(msg_errcode(msg))) |
| 1310 | retval = TIPC_OK; |
| 1311 | break; |
| 1312 | case SS_DISCONNECTING: |
| 1313 | break; |
| 1314 | default: |
| 1315 | pr_err("Unknown socket state %u\n", sock->state); |
| 1316 | } |
| 1317 | return retval; |
| 1318 | } |
| 1319 | |
| 1320 | /** |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1321 | * rcvbuf_limit - get proper overload limit of socket receive queue |
| 1322 | * @sk: socket |
| 1323 | * @buf: message |
| 1324 | * |
| 1325 | * For all connection oriented messages, irrespective of importance, |
| 1326 | * the default overload value (i.e. 67MB) is set as limit. |
| 1327 | * |
| 1328 | * For all connectionless messages, by default new queue limits are |
| 1329 | * as belows: |
| 1330 | * |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 1331 | * TIPC_LOW_IMPORTANCE (4 MB) |
| 1332 | * TIPC_MEDIUM_IMPORTANCE (8 MB) |
| 1333 | * TIPC_HIGH_IMPORTANCE (16 MB) |
| 1334 | * TIPC_CRITICAL_IMPORTANCE (32 MB) |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1335 | * |
| 1336 | * Returns overload limit according to corresponding message importance |
| 1337 | */ |
| 1338 | static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) |
| 1339 | { |
| 1340 | struct tipc_msg *msg = buf_msg(buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1341 | |
| 1342 | if (msg_connected(msg)) |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 1343 | return sysctl_tipc_rmem[2]; |
| 1344 | |
| 1345 | return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << |
| 1346 | msg_importance(msg); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | /** |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1350 | * filter_rcv - validate incoming message |
| 1351 | * @sk: socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1352 | * @buf: message |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1353 | * |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1354 | * Enqueues message on receive queue if acceptable; optionally handles |
| 1355 | * disconnect indication for a connected socket. |
| 1356 | * |
| 1357 | * Called with socket lock already taken; port lock may also be taken. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1358 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1359 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) |
| 1360 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1361 | static u32 filter_rcv(struct sock *sk, struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1362 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1363 | struct socket *sock = sk->sk_socket; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1364 | struct tipc_msg *msg = buf_msg(buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1365 | unsigned int limit = rcvbuf_limit(sk, buf); |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1366 | u32 res = TIPC_OK; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1367 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1368 | /* Reject message if it is wrong sort of message for socket */ |
Allan Stephens | aad5854 | 2012-04-26 18:13:08 -0400 | [diff] [blame] | 1369 | if (msg_type(msg) > TIPC_DIRECT_MSG) |
| 1370 | return TIPC_ERR_NO_PORT; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1371 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1372 | if (sock->state == SS_READY) { |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 1373 | if (msg_connected(msg)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1374 | return TIPC_ERR_NO_PORT; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1375 | } else { |
Ying Xue | 7e6c131 | 2012-11-29 18:39:14 -0500 | [diff] [blame] | 1376 | res = filter_connect(tipc_sk(sk), &buf); |
| 1377 | if (res != TIPC_OK || buf == NULL) |
| 1378 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /* Reject message if there isn't room to queue it */ |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1382 | if (sk_rmem_alloc_get(sk) + buf->truesize >= limit) |
| 1383 | return TIPC_ERR_OVERLOAD; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1384 | |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1385 | /* Enqueue message */ |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 1386 | TIPC_SKB_CB(buf)->handle = NULL; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1387 | __skb_queue_tail(&sk->sk_receive_queue, buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1388 | skb_set_owner_r(buf, sk); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1389 | |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 1390 | sk->sk_data_ready(sk, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1391 | return TIPC_OK; |
| 1392 | } |
| 1393 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1394 | /** |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1395 | * backlog_rcv - handle incoming message from backlog queue |
| 1396 | * @sk: socket |
| 1397 | * @buf: message |
| 1398 | * |
| 1399 | * Caller must hold socket lock, but not port lock. |
| 1400 | * |
| 1401 | * Returns 0 |
| 1402 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1403 | static int backlog_rcv(struct sock *sk, struct sk_buff *buf) |
| 1404 | { |
| 1405 | u32 res; |
| 1406 | |
| 1407 | res = filter_rcv(sk, buf); |
| 1408 | if (res) |
| 1409 | tipc_reject_msg(buf, res); |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | /** |
| 1414 | * dispatch - handle incoming message |
| 1415 | * @tport: TIPC port that received message |
| 1416 | * @buf: message |
| 1417 | * |
| 1418 | * Called with port lock already taken. |
| 1419 | * |
| 1420 | * Returns TIPC error status code (TIPC_OK if message is not to be rejected) |
| 1421 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1422 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf) |
| 1423 | { |
Ying Xue | c0fee8a | 2013-06-17 10:54:46 -0400 | [diff] [blame] | 1424 | struct sock *sk = tport->sk; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1425 | u32 res; |
| 1426 | |
| 1427 | /* |
| 1428 | * Process message if socket is unlocked; otherwise add to backlog queue |
| 1429 | * |
| 1430 | * This code is based on sk_receive_skb(), but must be distinct from it |
| 1431 | * since a TIPC-specific filter/reject mechanism is utilized |
| 1432 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1433 | bh_lock_sock(sk); |
| 1434 | if (!sock_owned_by_user(sk)) { |
| 1435 | res = filter_rcv(sk, buf); |
| 1436 | } else { |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1437 | if (sk_add_backlog(sk, buf, rcvbuf_limit(sk, buf))) |
Zhu Yi | 53eecb1 | 2010-03-04 18:01:45 +0000 | [diff] [blame] | 1438 | res = TIPC_ERR_OVERLOAD; |
| 1439 | else |
| 1440 | res = TIPC_OK; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1441 | } |
| 1442 | bh_unlock_sock(sk); |
| 1443 | |
| 1444 | return res; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1448 | * wakeupdispatch - wake up port after congestion |
| 1449 | * @tport: port to wakeup |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1450 | * |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1451 | * Called with port lock already taken. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1452 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1453 | static void wakeupdispatch(struct tipc_port *tport) |
| 1454 | { |
Ying Xue | c0fee8a | 2013-06-17 10:54:46 -0400 | [diff] [blame] | 1455 | struct sock *sk = tport->sk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1456 | |
Ying Xue | f288bef | 2012-08-21 11:16:57 +0800 | [diff] [blame] | 1457 | sk->sk_write_space(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1460 | static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) |
| 1461 | { |
| 1462 | struct sock *sk = sock->sk; |
| 1463 | DEFINE_WAIT(wait); |
| 1464 | int done; |
| 1465 | |
| 1466 | do { |
| 1467 | int err = sock_error(sk); |
| 1468 | if (err) |
| 1469 | return err; |
| 1470 | if (!*timeo_p) |
| 1471 | return -ETIMEDOUT; |
| 1472 | if (signal_pending(current)) |
| 1473 | return sock_intr_errno(*timeo_p); |
| 1474 | |
| 1475 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 1476 | done = sk_wait_event(sk, timeo_p, sock->state != SS_CONNECTING); |
| 1477 | finish_wait(sk_sleep(sk), &wait); |
| 1478 | } while (!done); |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1482 | /** |
| 1483 | * connect - establish a connection to another TIPC port |
| 1484 | * @sock: socket structure |
| 1485 | * @dest: socket address for destination port |
| 1486 | * @destlen: size of socket address data structure |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1487 | * @flags: file-related flags associated with socket |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1488 | * |
| 1489 | * Returns 0 on success, errno otherwise |
| 1490 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1491 | static int connect(struct socket *sock, struct sockaddr *dest, int destlen, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1492 | int flags) |
| 1493 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1494 | struct sock *sk = sock->sk; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1495 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; |
| 1496 | struct msghdr m = {NULL,}; |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1497 | long timeout = (flags & O_NONBLOCK) ? 0 : tipc_sk(sk)->conn_timeout; |
| 1498 | socket_state previous; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1499 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1500 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1501 | lock_sock(sk); |
| 1502 | |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1503 | /* 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] | 1504 | if (sock->state == SS_READY) { |
| 1505 | res = -EOPNOTSUPP; |
| 1506 | goto exit; |
| 1507 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1508 | |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1509 | /* |
| 1510 | * Reject connection attempt using multicast address |
| 1511 | * |
| 1512 | * Note: send_msg() validates the rest of the address fields, |
| 1513 | * so there's no need to do it here |
| 1514 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1515 | if (dst->addrtype == TIPC_ADDR_MCAST) { |
| 1516 | res = -EINVAL; |
| 1517 | goto exit; |
| 1518 | } |
| 1519 | |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1520 | previous = sock->state; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1521 | switch (sock->state) { |
| 1522 | case SS_UNCONNECTED: |
| 1523 | /* Send a 'SYN-' to destination */ |
| 1524 | m.msg_name = dest; |
| 1525 | m.msg_namelen = destlen; |
| 1526 | |
| 1527 | /* If connect is in non-blocking case, set MSG_DONTWAIT to |
| 1528 | * indicate send_msg() is never blocked. |
| 1529 | */ |
| 1530 | if (!timeout) |
| 1531 | m.msg_flags = MSG_DONTWAIT; |
| 1532 | |
| 1533 | res = send_msg(NULL, sock, &m, 0); |
| 1534 | if ((res < 0) && (res != -EWOULDBLOCK)) |
| 1535 | goto exit; |
| 1536 | |
| 1537 | /* Just entered SS_CONNECTING state; the only |
| 1538 | * difference is that return value in non-blocking |
| 1539 | * case is EINPROGRESS, rather than EALREADY. |
| 1540 | */ |
| 1541 | res = -EINPROGRESS; |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1542 | case SS_CONNECTING: |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1543 | if (previous == SS_CONNECTING) |
| 1544 | res = -EALREADY; |
| 1545 | if (!timeout) |
| 1546 | goto exit; |
| 1547 | timeout = msecs_to_jiffies(timeout); |
| 1548 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ |
| 1549 | res = tipc_wait_for_connect(sock, &timeout); |
Ying Xue | 584d24b | 2012-11-29 18:51:19 -0500 | [diff] [blame] | 1550 | break; |
| 1551 | case SS_CONNECTED: |
| 1552 | res = -EISCONN; |
| 1553 | break; |
| 1554 | default: |
| 1555 | res = -EINVAL; |
Ying Xue | 78eb3a5 | 2014-01-17 09:50:03 +0800 | [diff] [blame] | 1556 | break; |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1557 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1558 | exit: |
| 1559 | release_sock(sk); |
Allan Stephens | b89741a | 2008-04-15 00:20:37 -0700 | [diff] [blame] | 1560 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1563 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1564 | * listen - allow socket to listen for incoming connections |
| 1565 | * @sock: socket structure |
| 1566 | * @len: (unused) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1567 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1568 | * Returns 0 on success, errno otherwise |
| 1569 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1570 | static int listen(struct socket *sock, int len) |
| 1571 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1572 | struct sock *sk = sock->sk; |
| 1573 | int res; |
| 1574 | |
| 1575 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1576 | |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 1577 | if (sock->state != SS_UNCONNECTED) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1578 | res = -EINVAL; |
| 1579 | else { |
| 1580 | sock->state = SS_LISTENING; |
| 1581 | res = 0; |
| 1582 | } |
| 1583 | |
| 1584 | release_sock(sk); |
| 1585 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1586 | } |
| 1587 | |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1588 | static int tipc_wait_for_accept(struct socket *sock, long timeo) |
| 1589 | { |
| 1590 | struct sock *sk = sock->sk; |
| 1591 | DEFINE_WAIT(wait); |
| 1592 | int err; |
| 1593 | |
| 1594 | /* True wake-one mechanism for incoming connections: only |
| 1595 | * one process gets woken up, not the 'whole herd'. |
| 1596 | * Since we do not 'race & poll' for established sockets |
| 1597 | * anymore, the common case will execute the loop only once. |
| 1598 | */ |
| 1599 | for (;;) { |
| 1600 | prepare_to_wait_exclusive(sk_sleep(sk), &wait, |
| 1601 | TASK_INTERRUPTIBLE); |
| 1602 | if (skb_queue_empty(&sk->sk_receive_queue)) { |
| 1603 | release_sock(sk); |
| 1604 | timeo = schedule_timeout(timeo); |
| 1605 | lock_sock(sk); |
| 1606 | } |
| 1607 | err = 0; |
| 1608 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 1609 | break; |
| 1610 | err = -EINVAL; |
| 1611 | if (sock->state != SS_LISTENING) |
| 1612 | break; |
| 1613 | err = sock_intr_errno(timeo); |
| 1614 | if (signal_pending(current)) |
| 1615 | break; |
| 1616 | err = -EAGAIN; |
| 1617 | if (!timeo) |
| 1618 | break; |
| 1619 | } |
| 1620 | finish_wait(sk_sleep(sk), &wait); |
| 1621 | return err; |
| 1622 | } |
| 1623 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1624 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1625 | * accept - wait for connection request |
| 1626 | * @sock: listening socket |
| 1627 | * @newsock: new socket that is to be connected |
| 1628 | * @flags: file-related flags associated with socket |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1629 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1630 | * Returns 0 on success, errno otherwise |
| 1631 | */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1632 | static int accept(struct socket *sock, struct socket *new_sock, int flags) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1633 | { |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1634 | struct sock *new_sk, *sk = sock->sk; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1635 | struct sk_buff *buf; |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1636 | struct tipc_sock *new_tsock; |
| 1637 | struct tipc_port *new_tport; |
| 1638 | struct tipc_msg *msg; |
| 1639 | u32 new_ref; |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1640 | long timeo; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1641 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1642 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1643 | lock_sock(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1644 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1645 | if (sock->state != SS_LISTENING) { |
| 1646 | res = -EINVAL; |
| 1647 | goto exit; |
| 1648 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1649 | |
Ying Xue | 6398e23 | 2014-01-17 09:50:04 +0800 | [diff] [blame] | 1650 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 1651 | res = tipc_wait_for_accept(sock, timeo); |
| 1652 | if (res) |
| 1653 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1654 | |
| 1655 | buf = skb_peek(&sk->sk_receive_queue); |
| 1656 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 1657 | res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 1); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1658 | if (res) |
| 1659 | goto exit; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1660 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1661 | new_sk = new_sock->sk; |
| 1662 | new_tsock = tipc_sk(new_sk); |
| 1663 | new_tport = new_tsock->p; |
| 1664 | new_ref = new_tport->ref; |
| 1665 | msg = buf_msg(buf); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1666 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1667 | /* we lock on new_sk; but lockdep sees the lock on sk */ |
| 1668 | lock_sock_nested(new_sk, SINGLE_DEPTH_NESTING); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1669 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1670 | /* |
| 1671 | * Reject any stray messages received by new socket |
| 1672 | * before the socket lock was taken (very, very unlikely) |
| 1673 | */ |
| 1674 | reject_rx_queue(new_sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1675 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1676 | /* Connect new socket to it's peer */ |
| 1677 | new_tsock->peer_name.ref = msg_origport(msg); |
| 1678 | new_tsock->peer_name.node = msg_orignode(msg); |
| 1679 | tipc_connect(new_ref, &new_tsock->peer_name); |
| 1680 | new_sock->state = SS_CONNECTED; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1681 | |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1682 | tipc_set_portimportance(new_ref, msg_importance(msg)); |
| 1683 | if (msg_named(msg)) { |
| 1684 | new_tport->conn_type = msg_nametype(msg); |
| 1685 | new_tport->conn_instance = msg_nameinst(msg); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1686 | } |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1687 | |
| 1688 | /* |
| 1689 | * Respond to 'SYN-' by discarding it & returning 'ACK'-. |
| 1690 | * Respond to 'SYN+' by queuing it on new socket. |
| 1691 | */ |
| 1692 | if (!msg_data_sz(msg)) { |
| 1693 | struct msghdr m = {NULL,}; |
| 1694 | |
| 1695 | advance_rx_queue(sk); |
| 1696 | send_packet(NULL, new_sock, &m, 0); |
| 1697 | } else { |
| 1698 | __skb_dequeue(&sk->sk_receive_queue); |
| 1699 | __skb_queue_head(&new_sk->sk_receive_queue, buf); |
Ying Xue | aba79f3 | 2013-01-20 23:30:09 +0100 | [diff] [blame] | 1700 | skb_set_owner_r(buf, new_sk); |
Paul Gortmaker | 0fef8f2 | 2012-12-04 11:01:55 -0500 | [diff] [blame] | 1701 | } |
| 1702 | release_sock(new_sk); |
| 1703 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1704 | exit: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1705 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1706 | return res; |
| 1707 | } |
| 1708 | |
| 1709 | /** |
| 1710 | * shutdown - shutdown socket connection |
| 1711 | * @sock: socket structure |
Allan Stephens | e247a8f | 2008-03-06 15:05:38 -0800 | [diff] [blame] | 1712 | * @how: direction to close (must be SHUT_RDWR) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1713 | * |
| 1714 | * Terminates connection (if necessary), then purges socket's receive queue. |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1715 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1716 | * Returns 0 on success, errno otherwise |
| 1717 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1718 | static int shutdown(struct socket *sock, int how) |
| 1719 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1720 | struct sock *sk = sock->sk; |
| 1721 | struct tipc_port *tport = tipc_sk_port(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1722 | struct sk_buff *buf; |
| 1723 | int res; |
| 1724 | |
Allan Stephens | e247a8f | 2008-03-06 15:05:38 -0800 | [diff] [blame] | 1725 | if (how != SHUT_RDWR) |
| 1726 | return -EINVAL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1727 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1728 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1729 | |
| 1730 | switch (sock->state) { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1731 | case SS_CONNECTING: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1732 | case SS_CONNECTED: |
| 1733 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1734 | restart: |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 1735 | /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1736 | buf = __skb_dequeue(&sk->sk_receive_queue); |
| 1737 | if (buf) { |
Ying Xue | 4068243 | 2013-10-18 07:23:16 +0200 | [diff] [blame] | 1738 | if (TIPC_SKB_CB(buf)->handle != NULL) { |
Allan Stephens | 5f6d912 | 2011-11-04 13:24:29 -0400 | [diff] [blame] | 1739 | kfree_skb(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1740 | goto restart; |
| 1741 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1742 | tipc_disconnect(tport->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1743 | tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN); |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1744 | } else { |
| 1745 | tipc_shutdown(tport->ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1746 | } |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1747 | |
| 1748 | sock->state = SS_DISCONNECTING; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1749 | |
| 1750 | /* fall through */ |
| 1751 | |
| 1752 | case SS_DISCONNECTING: |
| 1753 | |
Ying Xue | 7503115 | 2012-10-29 09:38:15 -0400 | [diff] [blame] | 1754 | /* Discard any unreceived messages */ |
Ying Xue | 57467e5 | 2013-01-20 23:30:08 +0100 | [diff] [blame] | 1755 | __skb_queue_purge(&sk->sk_receive_queue); |
Ying Xue | 7503115 | 2012-10-29 09:38:15 -0400 | [diff] [blame] | 1756 | |
| 1757 | /* Wake up anyone sleeping in poll */ |
| 1758 | sk->sk_state_change(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1759 | res = 0; |
| 1760 | break; |
| 1761 | |
| 1762 | default: |
| 1763 | res = -ENOTCONN; |
| 1764 | } |
| 1765 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1766 | release_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1767 | return res; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * setsockopt - set socket option |
| 1772 | * @sock: socket structure |
| 1773 | * @lvl: option level |
| 1774 | * @opt: option identifier |
| 1775 | * @ov: pointer to new option value |
| 1776 | * @ol: length of option value |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1777 | * |
| 1778 | * For stream sockets only, accepts and ignores all IPPROTO_TCP options |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1779 | * (to ease compatibility). |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1780 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1781 | * Returns 0 on success, errno otherwise |
| 1782 | */ |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 1783 | static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov, |
| 1784 | unsigned int ol) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1785 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1786 | struct sock *sk = sock->sk; |
| 1787 | struct tipc_port *tport = tipc_sk_port(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1788 | u32 value; |
| 1789 | int res; |
| 1790 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1791 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
| 1792 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1793 | if (lvl != SOL_TIPC) |
| 1794 | return -ENOPROTOOPT; |
| 1795 | if (ol < sizeof(value)) |
| 1796 | return -EINVAL; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1797 | res = get_user(value, (u32 __user *)ov); |
| 1798 | if (res) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1799 | return res; |
| 1800 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1801 | lock_sock(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1802 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1803 | switch (opt) { |
| 1804 | case TIPC_IMPORTANCE: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1805 | res = tipc_set_portimportance(tport->ref, value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1806 | break; |
| 1807 | case TIPC_SRC_DROPPABLE: |
| 1808 | if (sock->type != SOCK_STREAM) |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1809 | res = tipc_set_portunreliable(tport->ref, value); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1810 | else |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1811 | res = -ENOPROTOOPT; |
| 1812 | break; |
| 1813 | case TIPC_DEST_DROPPABLE: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1814 | res = tipc_set_portunreturnable(tport->ref, value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1815 | break; |
| 1816 | case TIPC_CONN_TIMEOUT: |
Allan Stephens | a0f40f0 | 2011-05-26 13:44:34 -0400 | [diff] [blame] | 1817 | tipc_sk(sk)->conn_timeout = value; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1818 | /* no need to set "res", since already 0 at this point */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1819 | break; |
| 1820 | default: |
| 1821 | res = -EINVAL; |
| 1822 | } |
| 1823 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1824 | release_sock(sk); |
| 1825 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1826 | return res; |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * getsockopt - get socket option |
| 1831 | * @sock: socket structure |
| 1832 | * @lvl: option level |
| 1833 | * @opt: option identifier |
| 1834 | * @ov: receptacle for option value |
| 1835 | * @ol: receptacle for length of option value |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1836 | * |
| 1837 | * 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] | 1838 | * (to ease compatibility). |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1839 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1840 | * Returns 0 on success, errno otherwise |
| 1841 | */ |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 1842 | static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov, |
| 1843 | int __user *ol) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1844 | { |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1845 | struct sock *sk = sock->sk; |
| 1846 | struct tipc_port *tport = tipc_sk_port(sk); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1847 | int len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1848 | u32 value; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1849 | int res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1850 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1851 | if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) |
| 1852 | return put_user(0, ol); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1853 | if (lvl != SOL_TIPC) |
| 1854 | return -ENOPROTOOPT; |
Allan Stephens | 2db9983 | 2010-12-31 18:59:33 +0000 | [diff] [blame] | 1855 | res = get_user(len, ol); |
| 1856 | if (res) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1857 | return res; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1858 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1859 | lock_sock(sk); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1860 | |
| 1861 | switch (opt) { |
| 1862 | case TIPC_IMPORTANCE: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1863 | res = tipc_portimportance(tport->ref, &value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1864 | break; |
| 1865 | case TIPC_SRC_DROPPABLE: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1866 | res = tipc_portunreliable(tport->ref, &value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1867 | break; |
| 1868 | case TIPC_DEST_DROPPABLE: |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1869 | res = tipc_portunreturnable(tport->ref, &value); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1870 | break; |
| 1871 | case TIPC_CONN_TIMEOUT: |
Allan Stephens | a0f40f0 | 2011-05-26 13:44:34 -0400 | [diff] [blame] | 1872 | value = tipc_sk(sk)->conn_timeout; |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1873 | /* no need to set "res", since already 0 at this point */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1874 | break; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1875 | case TIPC_NODE_RECVQ_DEPTH: |
Ying Xue | 9da3d47 | 2012-11-27 06:15:27 -0500 | [diff] [blame] | 1876 | value = 0; /* was tipc_queue_size, now obsolete */ |
oscar.medina@motorola.com | 6650613 | 2009-06-30 03:25:39 +0000 | [diff] [blame] | 1877 | break; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1878 | case TIPC_SOCK_RECVQ_DEPTH: |
oscar.medina@motorola.com | 6650613 | 2009-06-30 03:25:39 +0000 | [diff] [blame] | 1879 | value = skb_queue_len(&sk->sk_receive_queue); |
| 1880 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1881 | default: |
| 1882 | res = -EINVAL; |
| 1883 | } |
| 1884 | |
Allan Stephens | 0c3141e | 2008-04-15 00:22:02 -0700 | [diff] [blame] | 1885 | release_sock(sk); |
| 1886 | |
Paul Gortmaker | 25860c3 | 2010-12-31 18:59:31 +0000 | [diff] [blame] | 1887 | if (res) |
| 1888 | return res; /* "get" failed */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1889 | |
Paul Gortmaker | 25860c3 | 2010-12-31 18:59:31 +0000 | [diff] [blame] | 1890 | if (len < sizeof(value)) |
| 1891 | return -EINVAL; |
| 1892 | |
| 1893 | if (copy_to_user(ov, &value, sizeof(value))) |
| 1894 | return -EFAULT; |
| 1895 | |
| 1896 | return put_user(sizeof(value), ol); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
Ben Hutchings | ae86b9e | 2012-07-10 10:55:35 +0000 | [diff] [blame] | 1899 | /* Protocol switches for the various types of TIPC sockets */ |
| 1900 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 1901 | static const struct proto_ops msg_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1902 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1903 | .family = AF_TIPC, |
| 1904 | .release = release, |
| 1905 | .bind = bind, |
| 1906 | .connect = connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1907 | .socketpair = sock_no_socketpair, |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 1908 | .accept = sock_no_accept, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1909 | .getname = get_name, |
| 1910 | .poll = poll, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1911 | .ioctl = sock_no_ioctl, |
Ying Xue | 245f3d3 | 2011-07-06 06:01:13 -0400 | [diff] [blame] | 1912 | .listen = sock_no_listen, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1913 | .shutdown = shutdown, |
| 1914 | .setsockopt = setsockopt, |
| 1915 | .getsockopt = getsockopt, |
| 1916 | .sendmsg = send_msg, |
| 1917 | .recvmsg = recv_msg, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 1918 | .mmap = sock_no_mmap, |
| 1919 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1920 | }; |
| 1921 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 1922 | static const struct proto_ops packet_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1923 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1924 | .family = AF_TIPC, |
| 1925 | .release = release, |
| 1926 | .bind = bind, |
| 1927 | .connect = connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1928 | .socketpair = sock_no_socketpair, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1929 | .accept = accept, |
| 1930 | .getname = get_name, |
| 1931 | .poll = poll, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1932 | .ioctl = sock_no_ioctl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1933 | .listen = listen, |
| 1934 | .shutdown = shutdown, |
| 1935 | .setsockopt = setsockopt, |
| 1936 | .getsockopt = getsockopt, |
| 1937 | .sendmsg = send_packet, |
| 1938 | .recvmsg = recv_msg, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 1939 | .mmap = sock_no_mmap, |
| 1940 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1941 | }; |
| 1942 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 1943 | static const struct proto_ops stream_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1944 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1945 | .family = AF_TIPC, |
| 1946 | .release = release, |
| 1947 | .bind = bind, |
| 1948 | .connect = connect, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1949 | .socketpair = sock_no_socketpair, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1950 | .accept = accept, |
| 1951 | .getname = get_name, |
| 1952 | .poll = poll, |
Allan Stephens | 5eee6a6 | 2007-06-10 17:24:55 -0700 | [diff] [blame] | 1953 | .ioctl = sock_no_ioctl, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1954 | .listen = listen, |
| 1955 | .shutdown = shutdown, |
| 1956 | .setsockopt = setsockopt, |
| 1957 | .getsockopt = getsockopt, |
| 1958 | .sendmsg = send_stream, |
| 1959 | .recvmsg = recv_stream, |
YOSHIFUJI Hideaki | 8238745 | 2007-07-19 10:44:56 +0900 | [diff] [blame] | 1960 | .mmap = sock_no_mmap, |
| 1961 | .sendpage = sock_no_sendpage |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1962 | }; |
| 1963 | |
Florian Westphal | bca65ea | 2008-02-07 18:18:01 -0800 | [diff] [blame] | 1964 | static const struct net_proto_family tipc_family_ops = { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 1965 | .owner = THIS_MODULE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1966 | .family = AF_TIPC, |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 1967 | .create = tipc_sk_create |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1968 | }; |
| 1969 | |
| 1970 | static struct proto tipc_proto = { |
| 1971 | .name = "TIPC", |
| 1972 | .owner = THIS_MODULE, |
Ying Xue | cc79dd1 | 2013-06-17 10:54:37 -0400 | [diff] [blame] | 1973 | .obj_size = sizeof(struct tipc_sock), |
| 1974 | .sysctl_rmem = sysctl_tipc_rmem |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1975 | }; |
| 1976 | |
Ying Xue | c5fa7b3 | 2013-06-17 10:54:39 -0400 | [diff] [blame] | 1977 | static struct proto tipc_proto_kern = { |
| 1978 | .name = "TIPC", |
| 1979 | .obj_size = sizeof(struct tipc_sock), |
| 1980 | .sysctl_rmem = sysctl_tipc_rmem |
| 1981 | }; |
| 1982 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1983 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1984 | * tipc_socket_init - initialize TIPC socket interface |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1985 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1986 | * Returns 0 on success, errno otherwise |
| 1987 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1988 | int tipc_socket_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1989 | { |
| 1990 | int res; |
| 1991 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1992 | res = proto_register(&tipc_proto, 1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1993 | if (res) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 1994 | pr_err("Failed to register TIPC protocol type\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1995 | goto out; |
| 1996 | } |
| 1997 | |
| 1998 | res = sock_register(&tipc_family_ops); |
| 1999 | if (res) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 2000 | pr_err("Failed to register TIPC socket type\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2001 | proto_unregister(&tipc_proto); |
| 2002 | goto out; |
| 2003 | } |
| 2004 | |
| 2005 | sockets_enabled = 1; |
| 2006 | out: |
| 2007 | return res; |
| 2008 | } |
| 2009 | |
| 2010 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2011 | * tipc_socket_stop - stop TIPC socket interface |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2012 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 2013 | void tipc_socket_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 2014 | { |
| 2015 | if (!sockets_enabled) |
| 2016 | return; |
| 2017 | |
| 2018 | sockets_enabled = 0; |
| 2019 | sock_unregister(tipc_family_ops.family); |
| 2020 | proto_unregister(&tipc_proto); |
| 2021 | } |