David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 1 | /* AF_RXRPC sendmsg() implementation. |
| 2 | * |
| 3 | * Copyright (C) 2007, 2016 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 Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
| 14 | #include <linux/net.h> |
| 15 | #include <linux/gfp.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/export.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 18 | #include <linux/sched/signal.h> |
| 19 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 20 | #include <net/sock.h> |
| 21 | #include <net/af_rxrpc.h> |
| 22 | #include "ar-internal.h" |
| 23 | |
David Howells | 3dc20f0 | 2016-09-04 13:25:21 +0100 | [diff] [blame] | 24 | enum rxrpc_command { |
| 25 | RXRPC_CMD_SEND_DATA, /* send data message */ |
| 26 | RXRPC_CMD_SEND_ABORT, /* request abort generation */ |
| 27 | RXRPC_CMD_ACCEPT, /* [server] accept incoming call */ |
| 28 | RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ |
| 29 | }; |
| 30 | |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 31 | struct rxrpc_send_params { |
| 32 | unsigned long user_call_ID; /* User's call ID */ |
| 33 | u32 abort_code; /* Abort code to Tx (if abort) */ |
| 34 | enum rxrpc_command command : 8; /* The command to implement */ |
| 35 | bool exclusive; /* Shared or exclusive call */ |
| 36 | bool upgrade; /* If the connection is upgradeable */ |
| 37 | }; |
| 38 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 39 | /* |
| 40 | * wait for space to appear in the transmit/ACK window |
| 41 | * - caller holds the socket locked |
| 42 | */ |
| 43 | static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx, |
| 44 | struct rxrpc_call *call, |
| 45 | long *timeo) |
| 46 | { |
| 47 | DECLARE_WAITQUEUE(myself, current); |
| 48 | int ret; |
| 49 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 50 | _enter(",{%u,%u,%u}", |
| 51 | call->tx_hard_ack, call->tx_top, call->tx_winsize); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 52 | |
| 53 | add_wait_queue(&call->waitq, &myself); |
| 54 | |
| 55 | for (;;) { |
| 56 | set_current_state(TASK_INTERRUPTIBLE); |
| 57 | ret = 0; |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 58 | if (call->tx_top - call->tx_hard_ack < |
| 59 | min_t(unsigned int, call->tx_winsize, |
| 60 | call->cong_cwnd + call->cong_extra)) |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 61 | break; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 62 | if (call->state >= RXRPC_CALL_COMPLETE) { |
| 63 | ret = -call->error; |
| 64 | break; |
| 65 | } |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 66 | if (signal_pending(current)) { |
| 67 | ret = sock_intr_errno(*timeo); |
| 68 | break; |
| 69 | } |
| 70 | |
David Howells | a124fe3 | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 71 | trace_rxrpc_transmit(call, rxrpc_transmit_wait); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 72 | mutex_unlock(&call->user_mutex); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 73 | *timeo = schedule_timeout(*timeo); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 74 | if (mutex_lock_interruptible(&call->user_mutex) < 0) { |
| 75 | ret = sock_intr_errno(*timeo); |
| 76 | break; |
| 77 | } |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | remove_wait_queue(&call->waitq, &myself); |
| 81 | set_current_state(TASK_RUNNING); |
| 82 | _leave(" = %d", ret); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | /* |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 87 | * Schedule an instant Tx resend. |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 88 | */ |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 89 | static inline void rxrpc_instant_resend(struct rxrpc_call *call, int ix) |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 90 | { |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 91 | spin_lock_bh(&call->lock); |
| 92 | |
| 93 | if (call->state < RXRPC_CALL_COMPLETE) { |
| 94 | call->rxtx_annotations[ix] = RXRPC_TX_ANNO_RETRANS; |
| 95 | if (!test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events)) |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 96 | rxrpc_queue_call(call); |
| 97 | } |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 98 | |
| 99 | spin_unlock_bh(&call->lock); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 103 | * Queue a DATA packet for transmission, set the resend timeout and send the |
| 104 | * packet immediately |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 105 | */ |
| 106 | static void rxrpc_queue_packet(struct rxrpc_call *call, struct sk_buff *skb, |
| 107 | bool last) |
| 108 | { |
| 109 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 110 | rxrpc_seq_t seq = sp->hdr.seq; |
| 111 | int ret, ix; |
David Howells | 70790db | 2016-09-23 12:39:22 +0100 | [diff] [blame] | 112 | u8 annotation = RXRPC_TX_ANNO_UNACK; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 113 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 114 | _net("queue skb %p [%d]", skb, seq); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 115 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 116 | ASSERTCMP(seq, ==, call->tx_top + 1); |
| 117 | |
David Howells | 70790db | 2016-09-23 12:39:22 +0100 | [diff] [blame] | 118 | if (last) |
| 119 | annotation |= RXRPC_TX_ANNO_LAST; |
| 120 | |
David Howells | b24d289 | 2016-09-23 13:17:33 +0100 | [diff] [blame] | 121 | /* We have to set the timestamp before queueing as the retransmit |
| 122 | * algorithm can see the packet as soon as we queue it. |
| 123 | */ |
| 124 | skb->tstamp = ktime_get_real(); |
| 125 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 126 | ix = seq & RXRPC_RXTX_BUFF_MASK; |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 127 | rxrpc_get_skb(skb, rxrpc_skb_tx_got); |
David Howells | 70790db | 2016-09-23 12:39:22 +0100 | [diff] [blame] | 128 | call->rxtx_annotations[ix] = annotation; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 129 | smp_wmb(); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 130 | call->rxtx_buffer[ix] = skb; |
| 131 | call->tx_top = seq; |
David Howells | 70790db | 2016-09-23 12:39:22 +0100 | [diff] [blame] | 132 | if (last) |
David Howells | a124fe3 | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 133 | trace_rxrpc_transmit(call, rxrpc_transmit_queue_last); |
David Howells | 70790db | 2016-09-23 12:39:22 +0100 | [diff] [blame] | 134 | else |
David Howells | a124fe3 | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 135 | trace_rxrpc_transmit(call, rxrpc_transmit_queue); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 136 | |
| 137 | if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) { |
| 138 | _debug("________awaiting reply/ACK__________"); |
| 139 | write_lock_bh(&call->state_lock); |
| 140 | switch (call->state) { |
| 141 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
| 142 | call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY; |
| 143 | break; |
| 144 | case RXRPC_CALL_SERVER_ACK_REQUEST: |
| 145 | call->state = RXRPC_CALL_SERVER_SEND_REPLY; |
David Howells | 9749fd2 | 2016-10-06 08:11:50 +0100 | [diff] [blame] | 146 | call->ack_at = call->expire_at; |
| 147 | if (call->ackr_reason == RXRPC_ACK_DELAY) |
| 148 | call->ackr_reason = 0; |
| 149 | __rxrpc_set_timer(call, rxrpc_timer_init_for_send_reply, |
| 150 | ktime_get_real()); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 151 | if (!last) |
| 152 | break; |
| 153 | case RXRPC_CALL_SERVER_SEND_REPLY: |
| 154 | call->state = RXRPC_CALL_SERVER_AWAIT_ACK; |
| 155 | break; |
| 156 | default: |
| 157 | break; |
| 158 | } |
| 159 | write_unlock_bh(&call->state_lock); |
| 160 | } |
| 161 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 162 | if (seq == 1 && rxrpc_is_client_call(call)) |
| 163 | rxrpc_expose_client_call(call); |
| 164 | |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 165 | ret = rxrpc_send_data_packet(call, skb, false); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 166 | if (ret < 0) { |
| 167 | _debug("need instant resend %d", ret); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 168 | rxrpc_instant_resend(call, ix); |
David Howells | dfc3da4 | 2016-09-23 12:39:23 +0100 | [diff] [blame] | 169 | } else { |
David Howells | df0adc7 | 2016-09-26 22:12:49 +0100 | [diff] [blame] | 170 | ktime_t now = ktime_get_real(), resend_at; |
David Howells | dfc3da4 | 2016-09-23 12:39:23 +0100 | [diff] [blame] | 171 | |
David Howells | df0adc7 | 2016-09-26 22:12:49 +0100 | [diff] [blame] | 172 | resend_at = ktime_add_ms(now, rxrpc_resend_timeout); |
David Howells | dfc3da4 | 2016-09-23 12:39:23 +0100 | [diff] [blame] | 173 | |
David Howells | df0adc7 | 2016-09-26 22:12:49 +0100 | [diff] [blame] | 174 | if (ktime_before(resend_at, call->resend_at)) { |
David Howells | dfc3da4 | 2016-09-23 12:39:23 +0100 | [diff] [blame] | 175 | call->resend_at = resend_at; |
David Howells | df0adc7 | 2016-09-26 22:12:49 +0100 | [diff] [blame] | 176 | rxrpc_set_timer(call, rxrpc_timer_set_for_send, now); |
David Howells | dfc3da4 | 2016-09-23 12:39:23 +0100 | [diff] [blame] | 177 | } |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 178 | } |
| 179 | |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 180 | rxrpc_free_skb(skb, rxrpc_skb_tx_freed); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 181 | _leave(""); |
| 182 | } |
| 183 | |
| 184 | /* |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 185 | * send data through a socket |
| 186 | * - must be called in process context |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 187 | * - The caller holds the call user access mutex, but not the socket lock. |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 188 | */ |
| 189 | static int rxrpc_send_data(struct rxrpc_sock *rx, |
| 190 | struct rxrpc_call *call, |
| 191 | struct msghdr *msg, size_t len) |
| 192 | { |
| 193 | struct rxrpc_skb_priv *sp; |
| 194 | struct sk_buff *skb; |
| 195 | struct sock *sk = &rx->sk; |
| 196 | long timeo; |
| 197 | bool more; |
| 198 | int ret, copied; |
| 199 | |
| 200 | timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); |
| 201 | |
| 202 | /* this should be in poll */ |
| 203 | sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
| 204 | |
| 205 | if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) |
| 206 | return -EPIPE; |
| 207 | |
| 208 | more = msg->msg_flags & MSG_MORE; |
| 209 | |
| 210 | skb = call->tx_pending; |
| 211 | call->tx_pending = NULL; |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 212 | rxrpc_see_skb(skb, rxrpc_skb_tx_seen); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 213 | |
| 214 | copied = 0; |
| 215 | do { |
David Howells | 7aa51da | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 216 | /* Check to see if there's a ping ACK to reply to. */ |
| 217 | if (call->ackr_reason == RXRPC_ACK_PING_RESPONSE) |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 218 | rxrpc_send_ack_packet(call, false); |
David Howells | 7aa51da | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 219 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 220 | if (!skb) { |
| 221 | size_t size, chunk, max, space; |
| 222 | |
| 223 | _debug("alloc"); |
| 224 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 225 | if (call->tx_top - call->tx_hard_ack >= |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 226 | min_t(unsigned int, call->tx_winsize, |
| 227 | call->cong_cwnd + call->cong_extra)) { |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 228 | ret = -EAGAIN; |
| 229 | if (msg->msg_flags & MSG_DONTWAIT) |
| 230 | goto maybe_error; |
| 231 | ret = rxrpc_wait_for_tx_window(rx, call, |
| 232 | &timeo); |
| 233 | if (ret < 0) |
| 234 | goto maybe_error; |
| 235 | } |
| 236 | |
David Howells | 182f505 | 2016-09-17 10:49:12 +0100 | [diff] [blame] | 237 | max = RXRPC_JUMBO_DATALEN; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 238 | max -= call->conn->security_size; |
| 239 | max &= ~(call->conn->size_align - 1UL); |
| 240 | |
| 241 | chunk = max; |
| 242 | if (chunk > msg_data_left(msg) && !more) |
| 243 | chunk = msg_data_left(msg); |
| 244 | |
| 245 | space = chunk + call->conn->size_align; |
| 246 | space &= ~(call->conn->size_align - 1UL); |
| 247 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 248 | size = space + call->conn->security_size; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 249 | |
| 250 | _debug("SIZE: %zu/%zu/%zu", chunk, space, size); |
| 251 | |
| 252 | /* create a buffer that we can retain until it's ACK'd */ |
| 253 | skb = sock_alloc_send_skb( |
| 254 | sk, size, msg->msg_flags & MSG_DONTWAIT, &ret); |
| 255 | if (!skb) |
| 256 | goto maybe_error; |
| 257 | |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 258 | rxrpc_new_skb(skb, rxrpc_skb_tx_new); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 259 | |
| 260 | _debug("ALLOC SEND %p", skb); |
| 261 | |
| 262 | ASSERTCMP(skb->mark, ==, 0); |
| 263 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 264 | _debug("HS: %u", call->conn->security_size); |
| 265 | skb_reserve(skb, call->conn->security_size); |
| 266 | skb->len += call->conn->security_size; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 267 | |
| 268 | sp = rxrpc_skb(skb); |
| 269 | sp->remain = chunk; |
| 270 | if (sp->remain > skb_tailroom(skb)) |
| 271 | sp->remain = skb_tailroom(skb); |
| 272 | |
| 273 | _net("skb: hr %d, tr %d, hl %d, rm %d", |
| 274 | skb_headroom(skb), |
| 275 | skb_tailroom(skb), |
| 276 | skb_headlen(skb), |
| 277 | sp->remain); |
| 278 | |
| 279 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 280 | } |
| 281 | |
| 282 | _debug("append"); |
| 283 | sp = rxrpc_skb(skb); |
| 284 | |
| 285 | /* append next segment of data to the current buffer */ |
| 286 | if (msg_data_left(msg) > 0) { |
| 287 | int copy = skb_tailroom(skb); |
| 288 | ASSERTCMP(copy, >, 0); |
| 289 | if (copy > msg_data_left(msg)) |
| 290 | copy = msg_data_left(msg); |
| 291 | if (copy > sp->remain) |
| 292 | copy = sp->remain; |
| 293 | |
| 294 | _debug("add"); |
| 295 | ret = skb_add_data(skb, &msg->msg_iter, copy); |
| 296 | _debug("added"); |
| 297 | if (ret < 0) |
| 298 | goto efault; |
| 299 | sp->remain -= copy; |
| 300 | skb->mark += copy; |
| 301 | copied += copy; |
| 302 | } |
| 303 | |
| 304 | /* check for the far side aborting the call or a network error |
| 305 | * occurring */ |
| 306 | if (call->state == RXRPC_CALL_COMPLETE) |
| 307 | goto call_terminated; |
| 308 | |
| 309 | /* add the packet to the send queue if it's now full */ |
| 310 | if (sp->remain <= 0 || |
| 311 | (msg_data_left(msg) == 0 && !more)) { |
| 312 | struct rxrpc_connection *conn = call->conn; |
| 313 | uint32_t seq; |
| 314 | size_t pad; |
| 315 | |
| 316 | /* pad out if we're using security */ |
| 317 | if (conn->security_ix) { |
| 318 | pad = conn->security_size + skb->mark; |
| 319 | pad = conn->size_align - pad; |
| 320 | pad &= conn->size_align - 1; |
| 321 | _debug("pad %zu", pad); |
| 322 | if (pad) |
| 323 | memset(skb_put(skb, pad), 0, pad); |
| 324 | } |
| 325 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 326 | seq = call->tx_top + 1; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 327 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 328 | sp->hdr.seq = seq; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 329 | sp->hdr._rsvd = 0; |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 330 | sp->hdr.flags = conn->out_clientflag; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 331 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 332 | if (msg_data_left(msg) == 0 && !more) |
| 333 | sp->hdr.flags |= RXRPC_LAST_PACKET; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 334 | else if (call->tx_top - call->tx_hard_ack < |
| 335 | call->tx_winsize) |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 336 | sp->hdr.flags |= RXRPC_MORE_PACKETS; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 337 | |
| 338 | ret = conn->security->secure_packet( |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 339 | call, skb, skb->mark, skb->head); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 340 | if (ret < 0) |
| 341 | goto out; |
| 342 | |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 343 | rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more); |
| 344 | skb = NULL; |
| 345 | } |
| 346 | } while (msg_data_left(msg) > 0); |
| 347 | |
| 348 | success: |
| 349 | ret = copied; |
| 350 | out: |
| 351 | call->tx_pending = skb; |
| 352 | _leave(" = %d", ret); |
| 353 | return ret; |
| 354 | |
| 355 | call_terminated: |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 356 | rxrpc_free_skb(skb, rxrpc_skb_tx_freed); |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 357 | _leave(" = %d", -call->error); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 358 | return -call->error; |
David Howells | 0b58b8a | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 359 | |
| 360 | maybe_error: |
| 361 | if (copied) |
| 362 | goto success; |
| 363 | goto out; |
| 364 | |
| 365 | efault: |
| 366 | ret = -EFAULT; |
| 367 | goto out; |
| 368 | } |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 369 | |
| 370 | /* |
| 371 | * extract control messages from the sendmsg() control buffer |
| 372 | */ |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 373 | static int rxrpc_sendmsg_cmsg(struct msghdr *msg, struct rxrpc_send_params *p) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 374 | { |
| 375 | struct cmsghdr *cmsg; |
| 376 | bool got_user_ID = false; |
| 377 | int len; |
| 378 | |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 379 | if (msg->msg_controllen == 0) |
| 380 | return -EINVAL; |
| 381 | |
| 382 | for_each_cmsghdr(cmsg, msg) { |
| 383 | if (!CMSG_OK(msg, cmsg)) |
| 384 | return -EINVAL; |
| 385 | |
yuan linyu | 1ff8ceb | 2017-01-03 20:42:17 +0800 | [diff] [blame] | 386 | len = cmsg->cmsg_len - sizeof(struct cmsghdr); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 387 | _debug("CMSG %d, %d, %d", |
| 388 | cmsg->cmsg_level, cmsg->cmsg_type, len); |
| 389 | |
| 390 | if (cmsg->cmsg_level != SOL_RXRPC) |
| 391 | continue; |
| 392 | |
| 393 | switch (cmsg->cmsg_type) { |
| 394 | case RXRPC_USER_CALL_ID: |
| 395 | if (msg->msg_flags & MSG_CMSG_COMPAT) { |
| 396 | if (len != sizeof(u32)) |
| 397 | return -EINVAL; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 398 | p->user_call_ID = *(u32 *)CMSG_DATA(cmsg); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 399 | } else { |
| 400 | if (len != sizeof(unsigned long)) |
| 401 | return -EINVAL; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 402 | p->user_call_ID = *(unsigned long *) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 403 | CMSG_DATA(cmsg); |
| 404 | } |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 405 | got_user_ID = true; |
| 406 | break; |
| 407 | |
| 408 | case RXRPC_ABORT: |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 409 | if (p->command != RXRPC_CMD_SEND_DATA) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 410 | return -EINVAL; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 411 | p->command = RXRPC_CMD_SEND_ABORT; |
| 412 | if (len != sizeof(p->abort_code)) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 413 | return -EINVAL; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 414 | p->abort_code = *(unsigned int *)CMSG_DATA(cmsg); |
| 415 | if (p->abort_code == 0) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 416 | return -EINVAL; |
| 417 | break; |
| 418 | |
| 419 | case RXRPC_ACCEPT: |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 420 | if (p->command != RXRPC_CMD_SEND_DATA) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 421 | return -EINVAL; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 422 | p->command = RXRPC_CMD_ACCEPT; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 423 | if (len != 0) |
| 424 | return -EINVAL; |
| 425 | break; |
| 426 | |
| 427 | case RXRPC_EXCLUSIVE_CALL: |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 428 | p->exclusive = true; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 429 | if (len != 0) |
| 430 | return -EINVAL; |
| 431 | break; |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 432 | |
| 433 | case RXRPC_UPGRADE_SERVICE: |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 434 | p->upgrade = true; |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 435 | if (len != 0) |
| 436 | return -EINVAL; |
| 437 | break; |
| 438 | |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 439 | default: |
| 440 | return -EINVAL; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (!got_user_ID) |
| 445 | return -EINVAL; |
| 446 | _leave(" = 0"); |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | /* |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 451 | * Create a new client call for sendmsg(). |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 452 | * - Called with the socket lock held, which it must release. |
| 453 | * - If it returns a call, the call's lock will need releasing by the caller. |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 454 | */ |
| 455 | static struct rxrpc_call * |
| 456 | rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 457 | struct rxrpc_send_params *p) |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 458 | __releases(&rx->sk.sk_lock.slock) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 459 | { |
| 460 | struct rxrpc_conn_parameters cp; |
| 461 | struct rxrpc_call *call; |
| 462 | struct key *key; |
| 463 | |
| 464 | DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name); |
| 465 | |
| 466 | _enter(""); |
| 467 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 468 | if (!msg->msg_name) { |
| 469 | release_sock(&rx->sk); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 470 | return ERR_PTR(-EDESTADDRREQ); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 471 | } |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 472 | |
| 473 | key = rx->key; |
| 474 | if (key && !rx->key->payload.data[0]) |
| 475 | key = NULL; |
| 476 | |
| 477 | memset(&cp, 0, sizeof(cp)); |
| 478 | cp.local = rx->local; |
| 479 | cp.key = rx->key; |
| 480 | cp.security_level = rx->min_sec_level; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 481 | cp.exclusive = rx->exclusive | p->exclusive; |
| 482 | cp.upgrade = p->upgrade; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 483 | cp.service_id = srx->srx_service; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 484 | call = rxrpc_new_client_call(rx, &cp, srx, p->user_call_ID, GFP_KERNEL); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 485 | /* The socket is now unlocked */ |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 486 | |
| 487 | _leave(" = %p\n", call); |
| 488 | return call; |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | * send a message forming part of a client call through an RxRPC socket |
| 493 | * - caller holds the socket locked |
| 494 | * - the socket may be either a client socket or a server socket |
| 495 | */ |
| 496 | int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 497 | __releases(&rx->sk.sk_lock.slock) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 498 | { |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 499 | enum rxrpc_call_state state; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 500 | struct rxrpc_call *call; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 501 | int ret; |
| 502 | |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 503 | struct rxrpc_send_params p = { |
| 504 | .user_call_ID = 0, |
| 505 | .abort_code = 0, |
| 506 | .command = RXRPC_CMD_SEND_DATA, |
| 507 | .exclusive = false, |
| 508 | .upgrade = true, |
| 509 | }; |
| 510 | |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 511 | _enter(""); |
| 512 | |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 513 | ret = rxrpc_sendmsg_cmsg(msg, &p); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 514 | if (ret < 0) |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 515 | goto error_release_sock; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 516 | |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 517 | if (p.command == RXRPC_CMD_ACCEPT) { |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 518 | ret = -EINVAL; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 519 | if (rx->sk.sk_state != RXRPC_SERVER_LISTENING) |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 520 | goto error_release_sock; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 521 | call = rxrpc_accept_call(rx, p.user_call_ID, NULL); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 522 | /* The socket is now unlocked. */ |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 523 | if (IS_ERR(call)) |
| 524 | return PTR_ERR(call); |
David Howells | fff72429 | 2016-09-07 14:34:21 +0100 | [diff] [blame] | 525 | rxrpc_put_call(call, rxrpc_call_put); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 529 | call = rxrpc_find_call_by_user_ID(rx, p.user_call_ID); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 530 | if (!call) { |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 531 | ret = -EBADSLT; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 532 | if (p.command != RXRPC_CMD_SEND_DATA) |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 533 | goto error_release_sock; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 534 | call = rxrpc_new_client_call_for_sendmsg(rx, msg, &p); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 535 | /* The socket is now unlocked... */ |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 536 | if (IS_ERR(call)) |
| 537 | return PTR_ERR(call); |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 538 | /* ... and we have the call lock. */ |
| 539 | } else { |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 540 | switch (READ_ONCE(call->state)) { |
| 541 | case RXRPC_CALL_UNINITIALISED: |
| 542 | case RXRPC_CALL_CLIENT_AWAIT_CONN: |
| 543 | case RXRPC_CALL_SERVER_PREALLOC: |
| 544 | case RXRPC_CALL_SERVER_SECURING: |
| 545 | case RXRPC_CALL_SERVER_ACCEPTING: |
| 546 | ret = -EBUSY; |
David Howells | 37411ca | 2017-03-02 23:48:52 +0000 | [diff] [blame] | 547 | goto error_release_sock; |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 548 | default: |
| 549 | break; |
| 550 | } |
David Howells | 37411ca | 2017-03-02 23:48:52 +0000 | [diff] [blame] | 551 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 552 | ret = mutex_lock_interruptible(&call->user_mutex); |
| 553 | release_sock(&rx->sk); |
| 554 | if (ret < 0) { |
| 555 | ret = -ERESTARTSYS; |
| 556 | goto error_put; |
| 557 | } |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 558 | } |
| 559 | |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 560 | state = READ_ONCE(call->state); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 561 | _debug("CALL %d USR %lx ST %d on CONN %p", |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 562 | call->debug_id, call->user_call_ID, state, call->conn); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 563 | |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 564 | if (state >= RXRPC_CALL_COMPLETE) { |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 565 | /* it's too late for this call */ |
| 566 | ret = -ESHUTDOWN; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 567 | } else if (p.command == RXRPC_CMD_SEND_ABORT) { |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 568 | ret = 0; |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 569 | if (rxrpc_abort_call("CMD", call, 0, p.abort_code, -ECONNABORTED)) |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 570 | ret = rxrpc_send_abort_packet(call); |
David Howells | 3ab26a6 | 2017-06-07 14:41:52 +0100 | [diff] [blame^] | 571 | } else if (p.command != RXRPC_CMD_SEND_DATA) { |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 572 | ret = -EINVAL; |
| 573 | } else if (rxrpc_is_client_call(call) && |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 574 | state != RXRPC_CALL_CLIENT_SEND_REQUEST) { |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 575 | /* request phase complete for this client call */ |
| 576 | ret = -EPROTO; |
| 577 | } else if (rxrpc_is_service_call(call) && |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 578 | state != RXRPC_CALL_SERVER_ACK_REQUEST && |
| 579 | state != RXRPC_CALL_SERVER_SEND_REPLY) { |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 580 | /* Reply phase not begun or not complete for service call. */ |
| 581 | ret = -EPROTO; |
| 582 | } else { |
| 583 | ret = rxrpc_send_data(rx, call, msg, len); |
| 584 | } |
| 585 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 586 | mutex_unlock(&call->user_mutex); |
| 587 | error_put: |
David Howells | fff72429 | 2016-09-07 14:34:21 +0100 | [diff] [blame] | 588 | rxrpc_put_call(call, rxrpc_call_put); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 589 | _leave(" = %d", ret); |
| 590 | return ret; |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 591 | |
| 592 | error_release_sock: |
| 593 | release_sock(&rx->sk); |
| 594 | return ret; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
| 598 | * rxrpc_kernel_send_data - Allow a kernel service to send data on a call |
| 599 | * @sock: The socket the call is on |
| 600 | * @call: The call to send data through |
| 601 | * @msg: The data to send |
| 602 | * @len: The amount of data to send |
| 603 | * |
| 604 | * Allow a kernel service to send data on a call. The call must be in an state |
| 605 | * appropriate to sending data. No control data should be supplied in @msg, |
| 606 | * nor should an address be supplied. MSG_MORE should be flagged if there's |
| 607 | * more data to come, otherwise this data will end the transmission phase. |
| 608 | */ |
| 609 | int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, |
| 610 | struct msghdr *msg, size_t len) |
| 611 | { |
| 612 | int ret; |
| 613 | |
| 614 | _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]); |
| 615 | |
| 616 | ASSERTCMP(msg->msg_name, ==, NULL); |
| 617 | ASSERTCMP(msg->msg_control, ==, NULL); |
| 618 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 619 | mutex_lock(&call->user_mutex); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 620 | |
| 621 | _debug("CALL %d USR %lx ST %d on CONN %p", |
| 622 | call->debug_id, call->user_call_ID, call->state, call->conn); |
| 623 | |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 624 | switch (READ_ONCE(call->state)) { |
| 625 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
| 626 | case RXRPC_CALL_SERVER_ACK_REQUEST: |
| 627 | case RXRPC_CALL_SERVER_SEND_REPLY: |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 628 | ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len); |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 629 | break; |
| 630 | case RXRPC_CALL_COMPLETE: |
David Howells | 6fc166d | 2017-03-09 08:10:32 +0000 | [diff] [blame] | 631 | read_lock_bh(&call->state_lock); |
| 632 | ret = -call->error; |
| 633 | read_unlock_bh(&call->state_lock); |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 634 | break; |
| 635 | default: |
David Howells | fb46f6e | 2017-04-06 10:12:00 +0100 | [diff] [blame] | 636 | /* Request phase complete for this client call */ |
| 637 | trace_rxrpc_rx_eproto(call, 0, tracepoint_string("late_send")); |
David Howells | 146d8fe | 2017-03-04 00:01:41 +0000 | [diff] [blame] | 638 | ret = -EPROTO; |
| 639 | break; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 640 | } |
| 641 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 642 | mutex_unlock(&call->user_mutex); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 643 | _leave(" = %d", ret); |
| 644 | return ret; |
| 645 | } |
| 646 | EXPORT_SYMBOL(rxrpc_kernel_send_data); |
| 647 | |
| 648 | /** |
| 649 | * rxrpc_kernel_abort_call - Allow a kernel service to abort a call |
| 650 | * @sock: The socket the call is on |
| 651 | * @call: The call to be aborted |
| 652 | * @abort_code: The abort code to stick into the ABORT packet |
David Howells | 5a42976 | 2016-09-06 22:19:51 +0100 | [diff] [blame] | 653 | * @error: Local error value |
| 654 | * @why: 3-char string indicating why. |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 655 | * |
David Howells | 84a4c09 | 2017-04-06 10:11:59 +0100 | [diff] [blame] | 656 | * Allow a kernel service to abort a call, if it's still in an abortable state |
| 657 | * and return true if the call was aborted, false if it was already complete. |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 658 | */ |
David Howells | 84a4c09 | 2017-04-06 10:11:59 +0100 | [diff] [blame] | 659 | bool rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call, |
David Howells | 5a42976 | 2016-09-06 22:19:51 +0100 | [diff] [blame] | 660 | u32 abort_code, int error, const char *why) |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 661 | { |
David Howells | 84a4c09 | 2017-04-06 10:11:59 +0100 | [diff] [blame] | 662 | bool aborted; |
| 663 | |
David Howells | 5a42976 | 2016-09-06 22:19:51 +0100 | [diff] [blame] | 664 | _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 665 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 666 | mutex_lock(&call->user_mutex); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 667 | |
David Howells | 84a4c09 | 2017-04-06 10:11:59 +0100 | [diff] [blame] | 668 | aborted = rxrpc_abort_call(why, call, 0, abort_code, error); |
| 669 | if (aborted) |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 670 | rxrpc_send_abort_packet(call); |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 671 | |
David Howells | 540b1c4 | 2017-02-27 15:43:06 +0000 | [diff] [blame] | 672 | mutex_unlock(&call->user_mutex); |
David Howells | 84a4c09 | 2017-04-06 10:11:59 +0100 | [diff] [blame] | 673 | return aborted; |
David Howells | df423a4 | 2016-09-02 22:39:45 +0100 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | EXPORT_SYMBOL(rxrpc_kernel_abort_call); |