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