blob: 814b17f239710c77f173129ff4d5d9b69e176386 [file] [log] [blame]
David Howells0b58b8a2016-09-02 22:39:45 +01001/* 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>
David Howells0b58b8a2016-09-02 22:39:45 +010018#include <net/sock.h>
19#include <net/af_rxrpc.h>
20#include "ar-internal.h"
21
David Howells3dc20f02016-09-04 13:25:21 +010022enum rxrpc_command {
23 RXRPC_CMD_SEND_DATA, /* send data message */
24 RXRPC_CMD_SEND_ABORT, /* request abort generation */
25 RXRPC_CMD_ACCEPT, /* [server] accept incoming call */
26 RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */
27};
28
David Howells0b58b8a2016-09-02 22:39:45 +010029/*
30 * wait for space to appear in the transmit/ACK window
31 * - caller holds the socket locked
32 */
33static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
34 struct rxrpc_call *call,
35 long *timeo)
36{
37 DECLARE_WAITQUEUE(myself, current);
38 int ret;
39
David Howells248f2192016-09-08 11:10:12 +010040 _enter(",{%u,%u,%u}",
41 call->tx_hard_ack, call->tx_top, call->tx_winsize);
David Howells0b58b8a2016-09-02 22:39:45 +010042
43 add_wait_queue(&call->waitq, &myself);
44
45 for (;;) {
46 set_current_state(TASK_INTERRUPTIBLE);
47 ret = 0;
David Howells248f2192016-09-08 11:10:12 +010048 if (call->tx_top - call->tx_hard_ack < call->tx_winsize)
David Howells0b58b8a2016-09-02 22:39:45 +010049 break;
David Howells248f2192016-09-08 11:10:12 +010050 if (call->state >= RXRPC_CALL_COMPLETE) {
51 ret = -call->error;
52 break;
53 }
David Howells0b58b8a2016-09-02 22:39:45 +010054 if (signal_pending(current)) {
55 ret = sock_intr_errno(*timeo);
56 break;
57 }
58
David Howellsa124fe32016-09-17 10:49:13 +010059 trace_rxrpc_transmit(call, rxrpc_transmit_wait);
David Howells0b58b8a2016-09-02 22:39:45 +010060 release_sock(&rx->sk);
61 *timeo = schedule_timeout(*timeo);
62 lock_sock(&rx->sk);
63 }
64
65 remove_wait_queue(&call->waitq, &myself);
66 set_current_state(TASK_RUNNING);
67 _leave(" = %d", ret);
68 return ret;
69}
70
71/*
David Howells248f2192016-09-08 11:10:12 +010072 * Schedule an instant Tx resend.
David Howells0b58b8a2016-09-02 22:39:45 +010073 */
David Howells248f2192016-09-08 11:10:12 +010074static inline void rxrpc_instant_resend(struct rxrpc_call *call, int ix)
David Howells0b58b8a2016-09-02 22:39:45 +010075{
David Howells248f2192016-09-08 11:10:12 +010076 spin_lock_bh(&call->lock);
77
78 if (call->state < RXRPC_CALL_COMPLETE) {
79 call->rxtx_annotations[ix] = RXRPC_TX_ANNO_RETRANS;
80 if (!test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
David Howells0b58b8a2016-09-02 22:39:45 +010081 rxrpc_queue_call(call);
82 }
David Howells248f2192016-09-08 11:10:12 +010083
84 spin_unlock_bh(&call->lock);
David Howells0b58b8a2016-09-02 22:39:45 +010085}
86
87/*
David Howells248f2192016-09-08 11:10:12 +010088 * Queue a DATA packet for transmission, set the resend timeout and send the
89 * packet immediately
David Howells0b58b8a2016-09-02 22:39:45 +010090 */
91static void rxrpc_queue_packet(struct rxrpc_call *call, struct sk_buff *skb,
92 bool last)
93{
94 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells248f2192016-09-08 11:10:12 +010095 rxrpc_seq_t seq = sp->hdr.seq;
96 int ret, ix;
David Howells0b58b8a2016-09-02 22:39:45 +010097
David Howells248f2192016-09-08 11:10:12 +010098 _net("queue skb %p [%d]", skb, seq);
David Howells0b58b8a2016-09-02 22:39:45 +010099
David Howells248f2192016-09-08 11:10:12 +0100100 ASSERTCMP(seq, ==, call->tx_top + 1);
101
102 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howells71f3ca42016-09-17 10:49:14 +0100103 rxrpc_get_skb(skb, rxrpc_skb_tx_got);
David Howells248f2192016-09-08 11:10:12 +0100104 call->rxtx_annotations[ix] = RXRPC_TX_ANNO_UNACK;
David Howells0b58b8a2016-09-02 22:39:45 +0100105 smp_wmb();
David Howells248f2192016-09-08 11:10:12 +0100106 call->rxtx_buffer[ix] = skb;
107 call->tx_top = seq;
David Howellsa124fe32016-09-17 10:49:13 +0100108 if (last) {
David Howells248f2192016-09-08 11:10:12 +0100109 set_bit(RXRPC_CALL_TX_LAST, &call->flags);
David Howellsa124fe32016-09-17 10:49:13 +0100110 trace_rxrpc_transmit(call, rxrpc_transmit_queue_last);
111 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
112 trace_rxrpc_transmit(call, rxrpc_transmit_queue_reqack);
113 } else {
114 trace_rxrpc_transmit(call, rxrpc_transmit_queue);
115 }
David Howells0b58b8a2016-09-02 22:39:45 +0100116
117 if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) {
118 _debug("________awaiting reply/ACK__________");
119 write_lock_bh(&call->state_lock);
120 switch (call->state) {
121 case RXRPC_CALL_CLIENT_SEND_REQUEST:
122 call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
123 break;
124 case RXRPC_CALL_SERVER_ACK_REQUEST:
125 call->state = RXRPC_CALL_SERVER_SEND_REPLY;
126 if (!last)
127 break;
128 case RXRPC_CALL_SERVER_SEND_REPLY:
129 call->state = RXRPC_CALL_SERVER_AWAIT_ACK;
130 break;
131 default:
132 break;
133 }
134 write_unlock_bh(&call->state_lock);
135 }
136
David Howells248f2192016-09-08 11:10:12 +0100137 if (seq == 1 && rxrpc_is_client_call(call))
138 rxrpc_expose_client_call(call);
139
David Howells0b58b8a2016-09-02 22:39:45 +0100140 sp->resend_at = jiffies + rxrpc_resend_timeout;
David Howells5a924b82016-09-22 00:29:31 +0100141 ret = rxrpc_send_data_packet(call, skb);
David Howells0b58b8a2016-09-02 22:39:45 +0100142 if (ret < 0) {
143 _debug("need instant resend %d", ret);
David Howells248f2192016-09-08 11:10:12 +0100144 rxrpc_instant_resend(call, ix);
David Howells0b58b8a2016-09-02 22:39:45 +0100145 }
146
David Howells71f3ca42016-09-17 10:49:14 +0100147 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells0b58b8a2016-09-02 22:39:45 +0100148 _leave("");
149}
150
151/*
David Howells0b58b8a2016-09-02 22:39:45 +0100152 * send data through a socket
153 * - must be called in process context
154 * - caller holds the socket locked
155 */
156static int rxrpc_send_data(struct rxrpc_sock *rx,
157 struct rxrpc_call *call,
158 struct msghdr *msg, size_t len)
159{
160 struct rxrpc_skb_priv *sp;
161 struct sk_buff *skb;
162 struct sock *sk = &rx->sk;
163 long timeo;
164 bool more;
165 int ret, copied;
166
167 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
168
169 /* this should be in poll */
170 sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
171
172 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
173 return -EPIPE;
174
175 more = msg->msg_flags & MSG_MORE;
176
177 skb = call->tx_pending;
178 call->tx_pending = NULL;
David Howells71f3ca42016-09-17 10:49:14 +0100179 rxrpc_see_skb(skb, rxrpc_skb_tx_seen);
David Howells0b58b8a2016-09-02 22:39:45 +0100180
181 copied = 0;
182 do {
183 if (!skb) {
184 size_t size, chunk, max, space;
185
186 _debug("alloc");
187
David Howells248f2192016-09-08 11:10:12 +0100188 if (call->tx_top - call->tx_hard_ack >=
189 call->tx_winsize) {
David Howells0b58b8a2016-09-02 22:39:45 +0100190 ret = -EAGAIN;
191 if (msg->msg_flags & MSG_DONTWAIT)
192 goto maybe_error;
193 ret = rxrpc_wait_for_tx_window(rx, call,
194 &timeo);
195 if (ret < 0)
196 goto maybe_error;
197 }
198
David Howells182f5052016-09-17 10:49:12 +0100199 max = RXRPC_JUMBO_DATALEN;
David Howells0b58b8a2016-09-02 22:39:45 +0100200 max -= call->conn->security_size;
201 max &= ~(call->conn->size_align - 1UL);
202
203 chunk = max;
204 if (chunk > msg_data_left(msg) && !more)
205 chunk = msg_data_left(msg);
206
207 space = chunk + call->conn->size_align;
208 space &= ~(call->conn->size_align - 1UL);
209
David Howells5a924b82016-09-22 00:29:31 +0100210 size = space + call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100211
212 _debug("SIZE: %zu/%zu/%zu", chunk, space, size);
213
214 /* create a buffer that we can retain until it's ACK'd */
215 skb = sock_alloc_send_skb(
216 sk, size, msg->msg_flags & MSG_DONTWAIT, &ret);
217 if (!skb)
218 goto maybe_error;
219
David Howells71f3ca42016-09-17 10:49:14 +0100220 rxrpc_new_skb(skb, rxrpc_skb_tx_new);
David Howells0b58b8a2016-09-02 22:39:45 +0100221
222 _debug("ALLOC SEND %p", skb);
223
224 ASSERTCMP(skb->mark, ==, 0);
225
David Howells5a924b82016-09-22 00:29:31 +0100226 _debug("HS: %u", call->conn->security_size);
227 skb_reserve(skb, call->conn->security_size);
228 skb->len += call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100229
230 sp = rxrpc_skb(skb);
231 sp->remain = chunk;
232 if (sp->remain > skb_tailroom(skb))
233 sp->remain = skb_tailroom(skb);
234
235 _net("skb: hr %d, tr %d, hl %d, rm %d",
236 skb_headroom(skb),
237 skb_tailroom(skb),
238 skb_headlen(skb),
239 sp->remain);
240
241 skb->ip_summed = CHECKSUM_UNNECESSARY;
242 }
243
244 _debug("append");
245 sp = rxrpc_skb(skb);
246
247 /* append next segment of data to the current buffer */
248 if (msg_data_left(msg) > 0) {
249 int copy = skb_tailroom(skb);
250 ASSERTCMP(copy, >, 0);
251 if (copy > msg_data_left(msg))
252 copy = msg_data_left(msg);
253 if (copy > sp->remain)
254 copy = sp->remain;
255
256 _debug("add");
257 ret = skb_add_data(skb, &msg->msg_iter, copy);
258 _debug("added");
259 if (ret < 0)
260 goto efault;
261 sp->remain -= copy;
262 skb->mark += copy;
263 copied += copy;
264 }
265
266 /* check for the far side aborting the call or a network error
267 * occurring */
268 if (call->state == RXRPC_CALL_COMPLETE)
269 goto call_terminated;
270
271 /* add the packet to the send queue if it's now full */
272 if (sp->remain <= 0 ||
273 (msg_data_left(msg) == 0 && !more)) {
274 struct rxrpc_connection *conn = call->conn;
275 uint32_t seq;
276 size_t pad;
277
278 /* pad out if we're using security */
279 if (conn->security_ix) {
280 pad = conn->security_size + skb->mark;
281 pad = conn->size_align - pad;
282 pad &= conn->size_align - 1;
283 _debug("pad %zu", pad);
284 if (pad)
285 memset(skb_put(skb, pad), 0, pad);
286 }
287
David Howells248f2192016-09-08 11:10:12 +0100288 seq = call->tx_top + 1;
David Howells0b58b8a2016-09-02 22:39:45 +0100289
David Howells0b58b8a2016-09-02 22:39:45 +0100290 sp->hdr.seq = seq;
David Howells0b58b8a2016-09-02 22:39:45 +0100291 sp->hdr._rsvd = 0;
David Howells5a924b82016-09-22 00:29:31 +0100292 sp->hdr.flags = conn->out_clientflag;
David Howells0b58b8a2016-09-02 22:39:45 +0100293
David Howells0b58b8a2016-09-02 22:39:45 +0100294 if (msg_data_left(msg) == 0 && !more)
295 sp->hdr.flags |= RXRPC_LAST_PACKET;
David Howells248f2192016-09-08 11:10:12 +0100296 else if (call->tx_top - call->tx_hard_ack <
297 call->tx_winsize)
David Howells0b58b8a2016-09-02 22:39:45 +0100298 sp->hdr.flags |= RXRPC_MORE_PACKETS;
David Howells5a924b82016-09-22 00:29:31 +0100299 if (seq & 1)
David Howells0b58b8a2016-09-02 22:39:45 +0100300 sp->hdr.flags |= RXRPC_REQUEST_ACK;
301
302 ret = conn->security->secure_packet(
David Howells5a924b82016-09-22 00:29:31 +0100303 call, skb, skb->mark, skb->head);
David Howells0b58b8a2016-09-02 22:39:45 +0100304 if (ret < 0)
305 goto out;
306
David Howells0b58b8a2016-09-02 22:39:45 +0100307 rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more);
308 skb = NULL;
309 }
310 } while (msg_data_left(msg) > 0);
311
312success:
313 ret = copied;
314out:
315 call->tx_pending = skb;
316 _leave(" = %d", ret);
317 return ret;
318
319call_terminated:
David Howells71f3ca42016-09-17 10:49:14 +0100320 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells0b58b8a2016-09-02 22:39:45 +0100321 _leave(" = %d", -call->error);
David Howells248f2192016-09-08 11:10:12 +0100322 return -call->error;
David Howells0b58b8a2016-09-02 22:39:45 +0100323
324maybe_error:
325 if (copied)
326 goto success;
327 goto out;
328
329efault:
330 ret = -EFAULT;
331 goto out;
332}
David Howellsdf423a42016-09-02 22:39:45 +0100333
334/*
335 * extract control messages from the sendmsg() control buffer
336 */
337static int rxrpc_sendmsg_cmsg(struct msghdr *msg,
338 unsigned long *user_call_ID,
339 enum rxrpc_command *command,
340 u32 *abort_code,
341 bool *_exclusive)
342{
343 struct cmsghdr *cmsg;
344 bool got_user_ID = false;
345 int len;
346
347 *command = RXRPC_CMD_SEND_DATA;
348
349 if (msg->msg_controllen == 0)
350 return -EINVAL;
351
352 for_each_cmsghdr(cmsg, msg) {
353 if (!CMSG_OK(msg, cmsg))
354 return -EINVAL;
355
356 len = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr));
357 _debug("CMSG %d, %d, %d",
358 cmsg->cmsg_level, cmsg->cmsg_type, len);
359
360 if (cmsg->cmsg_level != SOL_RXRPC)
361 continue;
362
363 switch (cmsg->cmsg_type) {
364 case RXRPC_USER_CALL_ID:
365 if (msg->msg_flags & MSG_CMSG_COMPAT) {
366 if (len != sizeof(u32))
367 return -EINVAL;
368 *user_call_ID = *(u32 *) CMSG_DATA(cmsg);
369 } else {
370 if (len != sizeof(unsigned long))
371 return -EINVAL;
372 *user_call_ID = *(unsigned long *)
373 CMSG_DATA(cmsg);
374 }
375 _debug("User Call ID %lx", *user_call_ID);
376 got_user_ID = true;
377 break;
378
379 case RXRPC_ABORT:
380 if (*command != RXRPC_CMD_SEND_DATA)
381 return -EINVAL;
382 *command = RXRPC_CMD_SEND_ABORT;
383 if (len != sizeof(*abort_code))
384 return -EINVAL;
385 *abort_code = *(unsigned int *) CMSG_DATA(cmsg);
386 _debug("Abort %x", *abort_code);
387 if (*abort_code == 0)
388 return -EINVAL;
389 break;
390
391 case RXRPC_ACCEPT:
392 if (*command != RXRPC_CMD_SEND_DATA)
393 return -EINVAL;
394 *command = RXRPC_CMD_ACCEPT;
395 if (len != 0)
396 return -EINVAL;
397 break;
398
399 case RXRPC_EXCLUSIVE_CALL:
400 *_exclusive = true;
401 if (len != 0)
402 return -EINVAL;
403 break;
404 default:
405 return -EINVAL;
406 }
407 }
408
409 if (!got_user_ID)
410 return -EINVAL;
411 _leave(" = 0");
412 return 0;
413}
414
415/*
David Howellsdf423a42016-09-02 22:39:45 +0100416 * Create a new client call for sendmsg().
417 */
418static struct rxrpc_call *
419rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
420 unsigned long user_call_ID, bool exclusive)
421{
422 struct rxrpc_conn_parameters cp;
423 struct rxrpc_call *call;
424 struct key *key;
425
426 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name);
427
428 _enter("");
429
430 if (!msg->msg_name)
431 return ERR_PTR(-EDESTADDRREQ);
432
433 key = rx->key;
434 if (key && !rx->key->payload.data[0])
435 key = NULL;
436
437 memset(&cp, 0, sizeof(cp));
438 cp.local = rx->local;
439 cp.key = rx->key;
440 cp.security_level = rx->min_sec_level;
441 cp.exclusive = rx->exclusive | exclusive;
442 cp.service_id = srx->srx_service;
443 call = rxrpc_new_client_call(rx, &cp, srx, user_call_ID, GFP_KERNEL);
444
445 _leave(" = %p\n", call);
446 return call;
447}
448
449/*
450 * send a message forming part of a client call through an RxRPC socket
451 * - caller holds the socket locked
452 * - the socket may be either a client socket or a server socket
453 */
454int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
455{
456 enum rxrpc_command cmd;
457 struct rxrpc_call *call;
458 unsigned long user_call_ID = 0;
459 bool exclusive = false;
460 u32 abort_code = 0;
461 int ret;
462
463 _enter("");
464
465 ret = rxrpc_sendmsg_cmsg(msg, &user_call_ID, &cmd, &abort_code,
466 &exclusive);
467 if (ret < 0)
468 return ret;
469
470 if (cmd == RXRPC_CMD_ACCEPT) {
471 if (rx->sk.sk_state != RXRPC_SERVER_LISTENING)
472 return -EINVAL;
473 call = rxrpc_accept_call(rx, user_call_ID, NULL);
474 if (IS_ERR(call))
475 return PTR_ERR(call);
David Howellsfff72422016-09-07 14:34:21 +0100476 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100477 return 0;
478 }
479
480 call = rxrpc_find_call_by_user_ID(rx, user_call_ID);
481 if (!call) {
482 if (cmd != RXRPC_CMD_SEND_DATA)
483 return -EBADSLT;
484 call = rxrpc_new_client_call_for_sendmsg(rx, msg, user_call_ID,
485 exclusive);
486 if (IS_ERR(call))
487 return PTR_ERR(call);
488 }
489
David Howellsdf423a42016-09-02 22:39:45 +0100490 _debug("CALL %d USR %lx ST %d on CONN %p",
491 call->debug_id, call->user_call_ID, call->state, call->conn);
492
493 if (call->state >= RXRPC_CALL_COMPLETE) {
494 /* it's too late for this call */
495 ret = -ESHUTDOWN;
496 } else if (cmd == RXRPC_CMD_SEND_ABORT) {
David Howellsdf423a42016-09-02 22:39:45 +0100497 ret = 0;
David Howells248f2192016-09-08 11:10:12 +0100498 if (rxrpc_abort_call("CMD", call, 0, abort_code, ECONNABORTED))
499 ret = rxrpc_send_call_packet(call,
500 RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100501 } else if (cmd != RXRPC_CMD_SEND_DATA) {
502 ret = -EINVAL;
503 } else if (rxrpc_is_client_call(call) &&
504 call->state != RXRPC_CALL_CLIENT_SEND_REQUEST) {
505 /* request phase complete for this client call */
506 ret = -EPROTO;
507 } else if (rxrpc_is_service_call(call) &&
508 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
509 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
510 /* Reply phase not begun or not complete for service call. */
511 ret = -EPROTO;
512 } else {
513 ret = rxrpc_send_data(rx, call, msg, len);
514 }
515
David Howellsfff72422016-09-07 14:34:21 +0100516 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100517 _leave(" = %d", ret);
518 return ret;
519}
520
521/**
522 * rxrpc_kernel_send_data - Allow a kernel service to send data on a call
523 * @sock: The socket the call is on
524 * @call: The call to send data through
525 * @msg: The data to send
526 * @len: The amount of data to send
527 *
528 * Allow a kernel service to send data on a call. The call must be in an state
529 * appropriate to sending data. No control data should be supplied in @msg,
530 * nor should an address be supplied. MSG_MORE should be flagged if there's
531 * more data to come, otherwise this data will end the transmission phase.
532 */
533int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
534 struct msghdr *msg, size_t len)
535{
536 int ret;
537
538 _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]);
539
540 ASSERTCMP(msg->msg_name, ==, NULL);
541 ASSERTCMP(msg->msg_control, ==, NULL);
542
543 lock_sock(sock->sk);
544
545 _debug("CALL %d USR %lx ST %d on CONN %p",
546 call->debug_id, call->user_call_ID, call->state, call->conn);
547
548 if (call->state >= RXRPC_CALL_COMPLETE) {
549 ret = -ESHUTDOWN; /* it's too late for this call */
550 } else if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
551 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
552 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
553 ret = -EPROTO; /* request phase complete for this client call */
554 } else {
555 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len);
556 }
557
558 release_sock(sock->sk);
559 _leave(" = %d", ret);
560 return ret;
561}
562EXPORT_SYMBOL(rxrpc_kernel_send_data);
563
564/**
565 * rxrpc_kernel_abort_call - Allow a kernel service to abort a call
566 * @sock: The socket the call is on
567 * @call: The call to be aborted
568 * @abort_code: The abort code to stick into the ABORT packet
David Howells5a429762016-09-06 22:19:51 +0100569 * @error: Local error value
570 * @why: 3-char string indicating why.
David Howellsdf423a42016-09-02 22:39:45 +0100571 *
572 * Allow a kernel service to abort a call, if it's still in an abortable state.
573 */
574void rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call,
David Howells5a429762016-09-06 22:19:51 +0100575 u32 abort_code, int error, const char *why)
David Howellsdf423a42016-09-02 22:39:45 +0100576{
David Howells5a429762016-09-06 22:19:51 +0100577 _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why);
David Howellsdf423a42016-09-02 22:39:45 +0100578
579 lock_sock(sock->sk);
580
David Howells248f2192016-09-08 11:10:12 +0100581 if (rxrpc_abort_call(why, call, 0, abort_code, error))
582 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100583
584 release_sock(sock->sk);
585 _leave("");
586}
587
588EXPORT_SYMBOL(rxrpc_kernel_abort_call);