David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 1 | /* RxRPC packet transmission |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 14 | #include <linux/net.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/gfp.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/circ_buf.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 18 | #include <linux/export.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 19 | #include <net/sock.h> |
| 20 | #include <net/af_rxrpc.h> |
| 21 | #include "ar-internal.h" |
| 22 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 23 | /* |
| 24 | * Time till packet resend (in jiffies). |
| 25 | */ |
David Howells | dad8aff | 2016-03-09 23:22:56 +0000 | [diff] [blame] | 26 | unsigned int rxrpc_resend_timeout = 4 * HZ; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 27 | |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 28 | static int rxrpc_send_data(struct rxrpc_sock *rx, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 29 | struct rxrpc_call *call, |
| 30 | struct msghdr *msg, size_t len); |
| 31 | |
| 32 | /* |
| 33 | * extract control messages from the sendmsg() control buffer |
| 34 | */ |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 35 | static int rxrpc_sendmsg_cmsg(struct msghdr *msg, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 36 | unsigned long *user_call_ID, |
| 37 | enum rxrpc_command *command, |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 38 | u32 *abort_code, |
| 39 | bool *_exclusive) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 40 | { |
| 41 | struct cmsghdr *cmsg; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 42 | bool got_user_ID = false; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 43 | int len; |
| 44 | |
| 45 | *command = RXRPC_CMD_SEND_DATA; |
| 46 | |
| 47 | if (msg->msg_controllen == 0) |
| 48 | return -EINVAL; |
| 49 | |
Gu Zheng | f95b414 | 2014-12-11 11:22:04 +0800 | [diff] [blame] | 50 | for_each_cmsghdr(cmsg, msg) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 51 | if (!CMSG_OK(msg, cmsg)) |
| 52 | return -EINVAL; |
| 53 | |
| 54 | len = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)); |
| 55 | _debug("CMSG %d, %d, %d", |
| 56 | cmsg->cmsg_level, cmsg->cmsg_type, len); |
| 57 | |
| 58 | if (cmsg->cmsg_level != SOL_RXRPC) |
| 59 | continue; |
| 60 | |
| 61 | switch (cmsg->cmsg_type) { |
| 62 | case RXRPC_USER_CALL_ID: |
| 63 | if (msg->msg_flags & MSG_CMSG_COMPAT) { |
| 64 | if (len != sizeof(u32)) |
| 65 | return -EINVAL; |
| 66 | *user_call_ID = *(u32 *) CMSG_DATA(cmsg); |
| 67 | } else { |
| 68 | if (len != sizeof(unsigned long)) |
| 69 | return -EINVAL; |
| 70 | *user_call_ID = *(unsigned long *) |
| 71 | CMSG_DATA(cmsg); |
| 72 | } |
| 73 | _debug("User Call ID %lx", *user_call_ID); |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 74 | got_user_ID = true; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 75 | break; |
| 76 | |
| 77 | case RXRPC_ABORT: |
| 78 | if (*command != RXRPC_CMD_SEND_DATA) |
| 79 | return -EINVAL; |
| 80 | *command = RXRPC_CMD_SEND_ABORT; |
| 81 | if (len != sizeof(*abort_code)) |
| 82 | return -EINVAL; |
| 83 | *abort_code = *(unsigned int *) CMSG_DATA(cmsg); |
| 84 | _debug("Abort %x", *abort_code); |
| 85 | if (*abort_code == 0) |
| 86 | return -EINVAL; |
| 87 | break; |
| 88 | |
| 89 | case RXRPC_ACCEPT: |
| 90 | if (*command != RXRPC_CMD_SEND_DATA) |
| 91 | return -EINVAL; |
| 92 | *command = RXRPC_CMD_ACCEPT; |
| 93 | if (len != 0) |
| 94 | return -EINVAL; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 95 | break; |
| 96 | |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 97 | case RXRPC_EXCLUSIVE_CALL: |
| 98 | *_exclusive = true; |
| 99 | if (len != 0) |
| 100 | return -EINVAL; |
| 101 | break; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 102 | default: |
| 103 | return -EINVAL; |
| 104 | } |
| 105 | } |
| 106 | |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 107 | if (!got_user_ID) |
| 108 | return -EINVAL; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 109 | _leave(" = 0"); |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * abort a call, sending an ABORT packet to the peer |
| 115 | */ |
| 116 | static void rxrpc_send_abort(struct rxrpc_call *call, u32 abort_code) |
| 117 | { |
| 118 | write_lock_bh(&call->state_lock); |
| 119 | |
| 120 | if (call->state <= RXRPC_CALL_COMPLETE) { |
| 121 | call->state = RXRPC_CALL_LOCALLY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 122 | call->local_abort = abort_code; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 123 | set_bit(RXRPC_CALL_EV_ABORT, &call->events); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 124 | del_timer_sync(&call->resend_timer); |
| 125 | del_timer_sync(&call->ack_timer); |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 126 | clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events); |
| 127 | clear_bit(RXRPC_CALL_EV_ACK, &call->events); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 128 | clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 129 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | write_unlock_bh(&call->state_lock); |
| 133 | } |
| 134 | |
| 135 | /* |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 136 | * Create a new client call for sendmsg(). |
| 137 | */ |
| 138 | static struct rxrpc_call * |
| 139 | rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 140 | unsigned long user_call_ID, bool exclusive) |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 141 | { |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 142 | struct rxrpc_conn_parameters cp; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 143 | struct rxrpc_conn_bundle *bundle; |
| 144 | struct rxrpc_transport *trans; |
| 145 | struct rxrpc_call *call; |
| 146 | struct key *key; |
| 147 | long ret; |
| 148 | |
| 149 | DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name); |
| 150 | |
| 151 | _enter(""); |
| 152 | |
| 153 | if (!msg->msg_name) |
| 154 | return ERR_PTR(-EDESTADDRREQ); |
| 155 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 156 | key = rx->key; |
| 157 | if (key && !rx->key->payload.data[0]) |
| 158 | key = NULL; |
| 159 | |
| 160 | memset(&cp, 0, sizeof(cp)); |
| 161 | cp.local = rx->local; |
| 162 | cp.key = rx->key; |
| 163 | cp.security_level = rx->min_sec_level; |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 164 | cp.exclusive = rx->exclusive | exclusive; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 165 | cp.service_id = srx->srx_service; |
| 166 | trans = rxrpc_name_to_transport(&cp, msg->msg_name, msg->msg_namelen, |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 167 | GFP_KERNEL); |
| 168 | if (IS_ERR(trans)) { |
| 169 | ret = PTR_ERR(trans); |
| 170 | goto out; |
| 171 | } |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 172 | cp.peer = trans->peer; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 173 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 174 | bundle = rxrpc_get_bundle(rx, trans, cp.key, srx->srx_service, |
| 175 | GFP_KERNEL); |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 176 | if (IS_ERR(bundle)) { |
| 177 | ret = PTR_ERR(bundle); |
| 178 | goto out_trans; |
| 179 | } |
| 180 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 181 | call = rxrpc_new_client_call(rx, &cp, trans, bundle, user_call_ID, |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 182 | GFP_KERNEL); |
| 183 | rxrpc_put_bundle(trans, bundle); |
| 184 | rxrpc_put_transport(trans); |
| 185 | if (IS_ERR(call)) { |
| 186 | ret = PTR_ERR(call); |
| 187 | goto out_trans; |
| 188 | } |
| 189 | |
| 190 | _leave(" = %p\n", call); |
| 191 | return call; |
| 192 | |
| 193 | out_trans: |
| 194 | rxrpc_put_transport(trans); |
| 195 | out: |
| 196 | _leave(" = %ld", ret); |
| 197 | return ERR_PTR(ret); |
| 198 | } |
| 199 | |
| 200 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 201 | * send a message forming part of a client call through an RxRPC socket |
| 202 | * - caller holds the socket locked |
| 203 | * - the socket may be either a client socket or a server socket |
| 204 | */ |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 205 | int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 206 | { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 207 | enum rxrpc_command cmd; |
| 208 | struct rxrpc_call *call; |
| 209 | unsigned long user_call_ID = 0; |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 210 | bool exclusive = false; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 211 | u32 abort_code = 0; |
| 212 | int ret; |
| 213 | |
| 214 | _enter(""); |
| 215 | |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 216 | ret = rxrpc_sendmsg_cmsg(msg, &user_call_ID, &cmd, &abort_code, |
| 217 | &exclusive); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 218 | if (ret < 0) |
| 219 | return ret; |
| 220 | |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 221 | if (cmd == RXRPC_CMD_ACCEPT) { |
| 222 | if (rx->sk.sk_state != RXRPC_SERVER_LISTENING) |
| 223 | return -EINVAL; |
| 224 | call = rxrpc_accept_call(rx, user_call_ID); |
| 225 | if (IS_ERR(call)) |
| 226 | return PTR_ERR(call); |
| 227 | rxrpc_put_call(call); |
| 228 | return 0; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 229 | } |
| 230 | |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 231 | call = rxrpc_find_call_by_user_ID(rx, user_call_ID); |
| 232 | if (!call) { |
| 233 | if (cmd != RXRPC_CMD_SEND_DATA) |
| 234 | return -EBADSLT; |
David Howells | cc8feb8 | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 235 | call = rxrpc_new_client_call_for_sendmsg(rx, msg, user_call_ID, |
| 236 | exclusive); |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 237 | if (IS_ERR(call)) |
| 238 | return PTR_ERR(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | _debug("CALL %d USR %lx ST %d on CONN %p", |
| 242 | call->debug_id, call->user_call_ID, call->state, call->conn); |
| 243 | |
| 244 | if (call->state >= RXRPC_CALL_COMPLETE) { |
| 245 | /* it's too late for this call */ |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 246 | ret = -ECONNRESET; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 247 | } else if (cmd == RXRPC_CMD_SEND_ABORT) { |
| 248 | rxrpc_send_abort(call, abort_code); |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 249 | ret = 0; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 250 | } else if (cmd != RXRPC_CMD_SEND_DATA) { |
| 251 | ret = -EINVAL; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 252 | } else if (!call->in_clientflag && |
| 253 | call->state != RXRPC_CALL_CLIENT_SEND_REQUEST) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 254 | /* request phase complete for this client call */ |
| 255 | ret = -EPROTO; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 256 | } else if (call->in_clientflag && |
| 257 | call->state != RXRPC_CALL_SERVER_ACK_REQUEST && |
| 258 | call->state != RXRPC_CALL_SERVER_SEND_REPLY) { |
| 259 | /* Reply phase not begun or not complete for service call. */ |
| 260 | ret = -EPROTO; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 261 | } else { |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 262 | ret = rxrpc_send_data(rx, call, msg, len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | rxrpc_put_call(call); |
| 266 | _leave(" = %d", ret); |
| 267 | return ret; |
| 268 | } |
| 269 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 270 | /** |
| 271 | * rxrpc_kernel_send_data - Allow a kernel service to send data on a call |
| 272 | * @call: The call to send data through |
| 273 | * @msg: The data to send |
| 274 | * @len: The amount of data to send |
| 275 | * |
| 276 | * Allow a kernel service to send data on a call. The call must be in an state |
| 277 | * appropriate to sending data. No control data should be supplied in @msg, |
| 278 | * nor should an address be supplied. MSG_MORE should be flagged if there's |
| 279 | * more data to come, otherwise this data will end the transmission phase. |
| 280 | */ |
| 281 | int rxrpc_kernel_send_data(struct rxrpc_call *call, struct msghdr *msg, |
| 282 | size_t len) |
| 283 | { |
| 284 | int ret; |
| 285 | |
| 286 | _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]); |
| 287 | |
| 288 | ASSERTCMP(msg->msg_name, ==, NULL); |
| 289 | ASSERTCMP(msg->msg_control, ==, NULL); |
| 290 | |
| 291 | lock_sock(&call->socket->sk); |
| 292 | |
| 293 | _debug("CALL %d USR %lx ST %d on CONN %p", |
| 294 | call->debug_id, call->user_call_ID, call->state, call->conn); |
| 295 | |
| 296 | if (call->state >= RXRPC_CALL_COMPLETE) { |
| 297 | ret = -ESHUTDOWN; /* it's too late for this call */ |
| 298 | } else if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST && |
| 299 | call->state != RXRPC_CALL_SERVER_ACK_REQUEST && |
| 300 | call->state != RXRPC_CALL_SERVER_SEND_REPLY) { |
| 301 | ret = -EPROTO; /* request phase complete for this client call */ |
| 302 | } else { |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 303 | ret = rxrpc_send_data(call->socket, call, msg, len); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | release_sock(&call->socket->sk); |
| 307 | _leave(" = %d", ret); |
| 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | EXPORT_SYMBOL(rxrpc_kernel_send_data); |
| 312 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 313 | /** |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 314 | * rxrpc_kernel_abort_call - Allow a kernel service to abort a call |
| 315 | * @call: The call to be aborted |
| 316 | * @abort_code: The abort code to stick into the ABORT packet |
| 317 | * |
| 318 | * Allow a kernel service to abort a call, if it's still in an abortable state. |
| 319 | */ |
| 320 | void rxrpc_kernel_abort_call(struct rxrpc_call *call, u32 abort_code) |
| 321 | { |
| 322 | _enter("{%d},%d", call->debug_id, abort_code); |
| 323 | |
| 324 | lock_sock(&call->socket->sk); |
| 325 | |
| 326 | _debug("CALL %d USR %lx ST %d on CONN %p", |
| 327 | call->debug_id, call->user_call_ID, call->state, call->conn); |
| 328 | |
| 329 | if (call->state < RXRPC_CALL_COMPLETE) |
| 330 | rxrpc_send_abort(call, abort_code); |
| 331 | |
| 332 | release_sock(&call->socket->sk); |
| 333 | _leave(""); |
| 334 | } |
| 335 | |
| 336 | EXPORT_SYMBOL(rxrpc_kernel_abort_call); |
| 337 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 338 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 339 | * send a packet through the transport endpoint |
| 340 | */ |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 341 | int rxrpc_send_data_packet(struct rxrpc_connection *conn, struct sk_buff *skb) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 342 | { |
| 343 | struct kvec iov[1]; |
| 344 | struct msghdr msg; |
| 345 | int ret, opt; |
| 346 | |
| 347 | _enter(",{%d}", skb->len); |
| 348 | |
| 349 | iov[0].iov_base = skb->head; |
| 350 | iov[0].iov_len = skb->len; |
| 351 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 352 | msg.msg_name = &conn->params.peer->srx.transport; |
| 353 | msg.msg_namelen = conn->params.peer->srx.transport_len; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 354 | msg.msg_control = NULL; |
| 355 | msg.msg_controllen = 0; |
| 356 | msg.msg_flags = 0; |
| 357 | |
| 358 | /* send the packet with the don't fragment bit set if we currently |
| 359 | * think it's small enough */ |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 360 | if (skb->len - sizeof(struct rxrpc_wire_header) < conn->params.peer->maxdata) { |
| 361 | down_read(&conn->params.local->defrag_sem); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 362 | /* send the packet by UDP |
| 363 | * - returns -EMSGSIZE if UDP would have to fragment the packet |
| 364 | * to go out of the interface |
| 365 | * - in which case, we'll have processed the ICMP error |
| 366 | * message and update the peer record |
| 367 | */ |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 368 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 1, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 369 | iov[0].iov_len); |
| 370 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 371 | up_read(&conn->params.local->defrag_sem); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 372 | if (ret == -EMSGSIZE) |
| 373 | goto send_fragmentable; |
| 374 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 375 | _leave(" = %d [%u]", ret, conn->params.peer->maxdata); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | send_fragmentable: |
| 380 | /* attempt to send this message with fragmentation enabled */ |
| 381 | _debug("send fragment"); |
| 382 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 383 | down_write(&conn->params.local->defrag_sem); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 384 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 385 | switch (conn->params.local->srx.transport.family) { |
| 386 | case AF_INET: |
| 387 | opt = IP_PMTUDISC_DONT; |
| 388 | ret = kernel_setsockopt(conn->params.local->socket, |
| 389 | SOL_IP, IP_MTU_DISCOVER, |
| 390 | (char *)&opt, sizeof(opt)); |
| 391 | if (ret == 0) { |
| 392 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 1, |
| 393 | iov[0].iov_len); |
| 394 | |
| 395 | opt = IP_PMTUDISC_DO; |
| 396 | kernel_setsockopt(conn->params.local->socket, SOL_IP, |
| 397 | IP_MTU_DISCOVER, |
| 398 | (char *)&opt, sizeof(opt)); |
| 399 | } |
| 400 | break; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 401 | } |
| 402 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 403 | up_write(&conn->params.local->defrag_sem); |
| 404 | _leave(" = %d [frag %u]", ret, conn->params.peer->maxdata); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * wait for space to appear in the transmit/ACK window |
| 410 | * - caller holds the socket locked |
| 411 | */ |
| 412 | static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx, |
| 413 | struct rxrpc_call *call, |
| 414 | long *timeo) |
| 415 | { |
| 416 | DECLARE_WAITQUEUE(myself, current); |
| 417 | int ret; |
| 418 | |
| 419 | _enter(",{%d},%ld", |
David Howells | ee72b9f | 2016-03-04 15:58:06 +0000 | [diff] [blame] | 420 | CIRC_SPACE(call->acks_head, ACCESS_ONCE(call->acks_tail), |
| 421 | call->acks_winsz), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 422 | *timeo); |
| 423 | |
| 424 | add_wait_queue(&call->tx_waitq, &myself); |
| 425 | |
| 426 | for (;;) { |
| 427 | set_current_state(TASK_INTERRUPTIBLE); |
| 428 | ret = 0; |
David Howells | ee72b9f | 2016-03-04 15:58:06 +0000 | [diff] [blame] | 429 | if (CIRC_SPACE(call->acks_head, ACCESS_ONCE(call->acks_tail), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 430 | call->acks_winsz) > 0) |
| 431 | break; |
| 432 | if (signal_pending(current)) { |
| 433 | ret = sock_intr_errno(*timeo); |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | release_sock(&rx->sk); |
| 438 | *timeo = schedule_timeout(*timeo); |
| 439 | lock_sock(&rx->sk); |
| 440 | } |
| 441 | |
| 442 | remove_wait_queue(&call->tx_waitq, &myself); |
| 443 | set_current_state(TASK_RUNNING); |
| 444 | _leave(" = %d", ret); |
| 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * attempt to schedule an instant Tx resend |
| 450 | */ |
| 451 | static inline void rxrpc_instant_resend(struct rxrpc_call *call) |
| 452 | { |
| 453 | read_lock_bh(&call->state_lock); |
| 454 | if (try_to_del_timer_sync(&call->resend_timer) >= 0) { |
| 455 | clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); |
| 456 | if (call->state < RXRPC_CALL_COMPLETE && |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 457 | !test_and_set_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events)) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 458 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 459 | } |
| 460 | read_unlock_bh(&call->state_lock); |
| 461 | } |
| 462 | |
| 463 | /* |
| 464 | * queue a packet for transmission, set the resend timer and attempt |
| 465 | * to send the packet immediately |
| 466 | */ |
| 467 | static void rxrpc_queue_packet(struct rxrpc_call *call, struct sk_buff *skb, |
| 468 | bool last) |
| 469 | { |
| 470 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
| 471 | int ret; |
| 472 | |
| 473 | _net("queue skb %p [%d]", skb, call->acks_head); |
| 474 | |
| 475 | ASSERT(call->acks_window != NULL); |
| 476 | call->acks_window[call->acks_head] = (unsigned long) skb; |
| 477 | smp_wmb(); |
| 478 | call->acks_head = (call->acks_head + 1) & (call->acks_winsz - 1); |
| 479 | |
| 480 | if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) { |
| 481 | _debug("________awaiting reply/ACK__________"); |
| 482 | write_lock_bh(&call->state_lock); |
| 483 | switch (call->state) { |
| 484 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
| 485 | call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY; |
| 486 | break; |
| 487 | case RXRPC_CALL_SERVER_ACK_REQUEST: |
| 488 | call->state = RXRPC_CALL_SERVER_SEND_REPLY; |
| 489 | if (!last) |
| 490 | break; |
| 491 | case RXRPC_CALL_SERVER_SEND_REPLY: |
| 492 | call->state = RXRPC_CALL_SERVER_AWAIT_ACK; |
| 493 | break; |
| 494 | default: |
| 495 | break; |
| 496 | } |
| 497 | write_unlock_bh(&call->state_lock); |
| 498 | } |
| 499 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 500 | _proto("Tx DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 501 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 502 | sp->need_resend = false; |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 503 | sp->resend_at = jiffies + rxrpc_resend_timeout; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 504 | if (!test_and_set_bit(RXRPC_CALL_RUN_RTIMER, &call->flags)) { |
| 505 | _debug("run timer"); |
| 506 | call->resend_timer.expires = sp->resend_at; |
| 507 | add_timer(&call->resend_timer); |
| 508 | } |
| 509 | |
| 510 | /* attempt to cancel the rx-ACK timer, deferring reply transmission if |
| 511 | * we're ACK'ing the request phase of an incoming call */ |
| 512 | ret = -EAGAIN; |
| 513 | if (try_to_del_timer_sync(&call->ack_timer) >= 0) { |
| 514 | /* the packet may be freed by rxrpc_process_call() before this |
| 515 | * returns */ |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame^] | 516 | ret = rxrpc_send_data_packet(call->conn, skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 517 | _net("sent skb %p", skb); |
| 518 | } else { |
| 519 | _debug("failed to delete ACK timer"); |
| 520 | } |
| 521 | |
| 522 | if (ret < 0) { |
| 523 | _debug("need instant resend %d", ret); |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 524 | sp->need_resend = true; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 525 | rxrpc_instant_resend(call); |
| 526 | } |
| 527 | |
| 528 | _leave(""); |
| 529 | } |
| 530 | |
| 531 | /* |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 532 | * Convert a host-endian header into a network-endian header. |
| 533 | */ |
| 534 | static void rxrpc_insert_header(struct sk_buff *skb) |
| 535 | { |
| 536 | struct rxrpc_wire_header whdr; |
| 537 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
| 538 | |
| 539 | whdr.epoch = htonl(sp->hdr.epoch); |
| 540 | whdr.cid = htonl(sp->hdr.cid); |
| 541 | whdr.callNumber = htonl(sp->hdr.callNumber); |
| 542 | whdr.seq = htonl(sp->hdr.seq); |
| 543 | whdr.serial = htonl(sp->hdr.serial); |
| 544 | whdr.type = sp->hdr.type; |
| 545 | whdr.flags = sp->hdr.flags; |
| 546 | whdr.userStatus = sp->hdr.userStatus; |
| 547 | whdr.securityIndex = sp->hdr.securityIndex; |
| 548 | whdr._rsvd = htons(sp->hdr._rsvd); |
| 549 | whdr.serviceId = htons(sp->hdr.serviceId); |
| 550 | |
| 551 | memcpy(skb->head, &whdr, sizeof(whdr)); |
| 552 | } |
| 553 | |
| 554 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 555 | * send data through a socket |
| 556 | * - must be called in process context |
| 557 | * - caller holds the socket locked |
| 558 | */ |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 559 | static int rxrpc_send_data(struct rxrpc_sock *rx, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 560 | struct rxrpc_call *call, |
| 561 | struct msghdr *msg, size_t len) |
| 562 | { |
| 563 | struct rxrpc_skb_priv *sp; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 564 | struct sk_buff *skb; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 565 | struct sock *sk = &rx->sk; |
| 566 | long timeo; |
| 567 | bool more; |
Al Viro | af2b040 | 2014-11-27 21:44:24 -0500 | [diff] [blame] | 568 | int ret, copied; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 569 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 570 | timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); |
| 571 | |
| 572 | /* this should be in poll */ |
Eric Dumazet | 9cd3e07 | 2015-11-29 20:03:10 -0800 | [diff] [blame] | 573 | sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 574 | |
| 575 | if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) |
| 576 | return -EPIPE; |
| 577 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 578 | more = msg->msg_flags & MSG_MORE; |
| 579 | |
| 580 | skb = call->tx_pending; |
| 581 | call->tx_pending = NULL; |
| 582 | |
| 583 | copied = 0; |
David Howells | 3af6878 | 2015-04-01 14:06:00 +0100 | [diff] [blame] | 584 | do { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 585 | if (!skb) { |
| 586 | size_t size, chunk, max, space; |
| 587 | |
| 588 | _debug("alloc"); |
| 589 | |
David Howells | ee72b9f | 2016-03-04 15:58:06 +0000 | [diff] [blame] | 590 | if (CIRC_SPACE(call->acks_head, |
| 591 | ACCESS_ONCE(call->acks_tail), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 592 | call->acks_winsz) <= 0) { |
| 593 | ret = -EAGAIN; |
| 594 | if (msg->msg_flags & MSG_DONTWAIT) |
| 595 | goto maybe_error; |
| 596 | ret = rxrpc_wait_for_tx_window(rx, call, |
| 597 | &timeo); |
| 598 | if (ret < 0) |
| 599 | goto maybe_error; |
| 600 | } |
| 601 | |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 602 | max = call->conn->params.peer->maxdata; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 603 | max -= call->conn->security_size; |
| 604 | max &= ~(call->conn->size_align - 1UL); |
| 605 | |
| 606 | chunk = max; |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 607 | if (chunk > msg_data_left(msg) && !more) |
| 608 | chunk = msg_data_left(msg); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 609 | |
| 610 | space = chunk + call->conn->size_align; |
| 611 | space &= ~(call->conn->size_align - 1UL); |
| 612 | |
| 613 | size = space + call->conn->header_size; |
| 614 | |
| 615 | _debug("SIZE: %zu/%zu/%zu", chunk, space, size); |
| 616 | |
| 617 | /* create a buffer that we can retain until it's ACK'd */ |
| 618 | skb = sock_alloc_send_skb( |
| 619 | sk, size, msg->msg_flags & MSG_DONTWAIT, &ret); |
| 620 | if (!skb) |
| 621 | goto maybe_error; |
| 622 | |
| 623 | rxrpc_new_skb(skb); |
| 624 | |
| 625 | _debug("ALLOC SEND %p", skb); |
| 626 | |
| 627 | ASSERTCMP(skb->mark, ==, 0); |
| 628 | |
| 629 | _debug("HS: %u", call->conn->header_size); |
| 630 | skb_reserve(skb, call->conn->header_size); |
| 631 | skb->len += call->conn->header_size; |
| 632 | |
| 633 | sp = rxrpc_skb(skb); |
| 634 | sp->remain = chunk; |
| 635 | if (sp->remain > skb_tailroom(skb)) |
| 636 | sp->remain = skb_tailroom(skb); |
| 637 | |
| 638 | _net("skb: hr %d, tr %d, hl %d, rm %d", |
| 639 | skb_headroom(skb), |
| 640 | skb_tailroom(skb), |
| 641 | skb_headlen(skb), |
| 642 | sp->remain); |
| 643 | |
| 644 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 645 | } |
| 646 | |
| 647 | _debug("append"); |
| 648 | sp = rxrpc_skb(skb); |
| 649 | |
| 650 | /* append next segment of data to the current buffer */ |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 651 | if (msg_data_left(msg) > 0) { |
David Howells | aab9483 | 2015-04-01 15:48:00 +0100 | [diff] [blame] | 652 | int copy = skb_tailroom(skb); |
| 653 | ASSERTCMP(copy, >, 0); |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 654 | if (copy > msg_data_left(msg)) |
| 655 | copy = msg_data_left(msg); |
David Howells | aab9483 | 2015-04-01 15:48:00 +0100 | [diff] [blame] | 656 | if (copy > sp->remain) |
| 657 | copy = sp->remain; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 658 | |
David Howells | aab9483 | 2015-04-01 15:48:00 +0100 | [diff] [blame] | 659 | _debug("add"); |
| 660 | ret = skb_add_data(skb, &msg->msg_iter, copy); |
| 661 | _debug("added"); |
| 662 | if (ret < 0) |
| 663 | goto efault; |
| 664 | sp->remain -= copy; |
| 665 | skb->mark += copy; |
| 666 | copied += copy; |
David Howells | aab9483 | 2015-04-01 15:48:00 +0100 | [diff] [blame] | 667 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 668 | |
| 669 | /* check for the far side aborting the call or a network error |
| 670 | * occurring */ |
| 671 | if (call->state > RXRPC_CALL_COMPLETE) |
| 672 | goto call_aborted; |
| 673 | |
| 674 | /* add the packet to the send queue if it's now full */ |
David Howells | 382d797 | 2015-04-01 15:43:26 +0100 | [diff] [blame] | 675 | if (sp->remain <= 0 || |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 676 | (msg_data_left(msg) == 0 && !more)) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 677 | struct rxrpc_connection *conn = call->conn; |
David Howells | e8388eb | 2014-02-14 20:05:32 +0000 | [diff] [blame] | 678 | uint32_t seq; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 679 | size_t pad; |
| 680 | |
| 681 | /* pad out if we're using security */ |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 682 | if (conn->security_ix) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 683 | pad = conn->security_size + skb->mark; |
| 684 | pad = conn->size_align - pad; |
| 685 | pad &= conn->size_align - 1; |
| 686 | _debug("pad %zu", pad); |
| 687 | if (pad) |
| 688 | memset(skb_put(skb, pad), 0, pad); |
| 689 | } |
| 690 | |
David Howells | e8388eb | 2014-02-14 20:05:32 +0000 | [diff] [blame] | 691 | seq = atomic_inc_return(&call->sequence); |
| 692 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 693 | sp->hdr.epoch = conn->proto.epoch; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 694 | sp->hdr.cid = call->cid; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 695 | sp->hdr.callNumber = call->call_id; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 696 | sp->hdr.seq = seq; |
| 697 | sp->hdr.serial = atomic_inc_return(&conn->serial); |
| 698 | sp->hdr.type = RXRPC_PACKET_TYPE_DATA; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 699 | sp->hdr.userStatus = 0; |
| 700 | sp->hdr.securityIndex = conn->security_ix; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 701 | sp->hdr._rsvd = 0; |
| 702 | sp->hdr.serviceId = call->service_id; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 703 | |
| 704 | sp->hdr.flags = conn->out_clientflag; |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 705 | if (msg_data_left(msg) == 0 && !more) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 706 | sp->hdr.flags |= RXRPC_LAST_PACKET; |
David Howells | ee72b9f | 2016-03-04 15:58:06 +0000 | [diff] [blame] | 707 | else if (CIRC_SPACE(call->acks_head, |
| 708 | ACCESS_ONCE(call->acks_tail), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 709 | call->acks_winsz) > 1) |
| 710 | sp->hdr.flags |= RXRPC_MORE_PACKETS; |
David Howells | e8388eb | 2014-02-14 20:05:32 +0000 | [diff] [blame] | 711 | if (more && seq & 1) |
| 712 | sp->hdr.flags |= RXRPC_REQUEST_ACK; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 713 | |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 714 | ret = conn->security->secure_packet( |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 715 | call, skb, skb->mark, |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 716 | skb->head + sizeof(struct rxrpc_wire_header)); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 717 | if (ret < 0) |
| 718 | goto out; |
| 719 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 720 | rxrpc_insert_header(skb); |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 721 | rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 722 | skb = NULL; |
| 723 | } |
Al Viro | 01e97e6 | 2014-12-15 21:39:31 -0500 | [diff] [blame] | 724 | } while (msg_data_left(msg) > 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 725 | |
David Howells | 19e6454 | 2007-06-18 23:30:41 -0700 | [diff] [blame] | 726 | success: |
| 727 | ret = copied; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 728 | out: |
| 729 | call->tx_pending = skb; |
| 730 | _leave(" = %d", ret); |
| 731 | return ret; |
| 732 | |
| 733 | call_aborted: |
| 734 | rxrpc_free_skb(skb); |
| 735 | if (call->state == RXRPC_CALL_NETWORK_ERROR) |
David Howells | f66d749 | 2016-04-04 14:00:34 +0100 | [diff] [blame] | 736 | ret = call->error_report < RXRPC_LOCAL_ERROR_OFFSET ? |
| 737 | call->error_report : |
| 738 | call->error_report - RXRPC_LOCAL_ERROR_OFFSET; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 739 | else |
| 740 | ret = -ECONNABORTED; |
| 741 | _leave(" = %d", ret); |
| 742 | return ret; |
| 743 | |
| 744 | maybe_error: |
| 745 | if (copied) |
David Howells | 19e6454 | 2007-06-18 23:30:41 -0700 | [diff] [blame] | 746 | goto success; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 747 | goto out; |
| 748 | |
| 749 | efault: |
| 750 | ret = -EFAULT; |
| 751 | goto out; |
| 752 | } |