blob: 3c969de3ef05a2e03eb3161046ef6fe3a7a2668a [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 {
David Howells7aa51da2016-09-22 00:29:31 +0100183 /* Check to see if there's a ping ACK to reply to. */
184 if (call->ackr_reason == RXRPC_ACK_PING_RESPONSE)
185 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
186
David Howells0b58b8a2016-09-02 22:39:45 +0100187 if (!skb) {
188 size_t size, chunk, max, space;
189
190 _debug("alloc");
191
David Howells248f2192016-09-08 11:10:12 +0100192 if (call->tx_top - call->tx_hard_ack >=
193 call->tx_winsize) {
David Howells0b58b8a2016-09-02 22:39:45 +0100194 ret = -EAGAIN;
195 if (msg->msg_flags & MSG_DONTWAIT)
196 goto maybe_error;
197 ret = rxrpc_wait_for_tx_window(rx, call,
198 &timeo);
199 if (ret < 0)
200 goto maybe_error;
201 }
202
David Howells182f5052016-09-17 10:49:12 +0100203 max = RXRPC_JUMBO_DATALEN;
David Howells0b58b8a2016-09-02 22:39:45 +0100204 max -= call->conn->security_size;
205 max &= ~(call->conn->size_align - 1UL);
206
207 chunk = max;
208 if (chunk > msg_data_left(msg) && !more)
209 chunk = msg_data_left(msg);
210
211 space = chunk + call->conn->size_align;
212 space &= ~(call->conn->size_align - 1UL);
213
David Howells5a924b82016-09-22 00:29:31 +0100214 size = space + call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100215
216 _debug("SIZE: %zu/%zu/%zu", chunk, space, size);
217
218 /* create a buffer that we can retain until it's ACK'd */
219 skb = sock_alloc_send_skb(
220 sk, size, msg->msg_flags & MSG_DONTWAIT, &ret);
221 if (!skb)
222 goto maybe_error;
223
David Howells71f3ca42016-09-17 10:49:14 +0100224 rxrpc_new_skb(skb, rxrpc_skb_tx_new);
David Howells0b58b8a2016-09-02 22:39:45 +0100225
226 _debug("ALLOC SEND %p", skb);
227
228 ASSERTCMP(skb->mark, ==, 0);
229
David Howells5a924b82016-09-22 00:29:31 +0100230 _debug("HS: %u", call->conn->security_size);
231 skb_reserve(skb, call->conn->security_size);
232 skb->len += call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100233
234 sp = rxrpc_skb(skb);
235 sp->remain = chunk;
236 if (sp->remain > skb_tailroom(skb))
237 sp->remain = skb_tailroom(skb);
238
239 _net("skb: hr %d, tr %d, hl %d, rm %d",
240 skb_headroom(skb),
241 skb_tailroom(skb),
242 skb_headlen(skb),
243 sp->remain);
244
245 skb->ip_summed = CHECKSUM_UNNECESSARY;
246 }
247
248 _debug("append");
249 sp = rxrpc_skb(skb);
250
251 /* append next segment of data to the current buffer */
252 if (msg_data_left(msg) > 0) {
253 int copy = skb_tailroom(skb);
254 ASSERTCMP(copy, >, 0);
255 if (copy > msg_data_left(msg))
256 copy = msg_data_left(msg);
257 if (copy > sp->remain)
258 copy = sp->remain;
259
260 _debug("add");
261 ret = skb_add_data(skb, &msg->msg_iter, copy);
262 _debug("added");
263 if (ret < 0)
264 goto efault;
265 sp->remain -= copy;
266 skb->mark += copy;
267 copied += copy;
268 }
269
270 /* check for the far side aborting the call or a network error
271 * occurring */
272 if (call->state == RXRPC_CALL_COMPLETE)
273 goto call_terminated;
274
275 /* add the packet to the send queue if it's now full */
276 if (sp->remain <= 0 ||
277 (msg_data_left(msg) == 0 && !more)) {
278 struct rxrpc_connection *conn = call->conn;
279 uint32_t seq;
280 size_t pad;
281
282 /* pad out if we're using security */
283 if (conn->security_ix) {
284 pad = conn->security_size + skb->mark;
285 pad = conn->size_align - pad;
286 pad &= conn->size_align - 1;
287 _debug("pad %zu", pad);
288 if (pad)
289 memset(skb_put(skb, pad), 0, pad);
290 }
291
David Howells248f2192016-09-08 11:10:12 +0100292 seq = call->tx_top + 1;
David Howells0b58b8a2016-09-02 22:39:45 +0100293
David Howells0b58b8a2016-09-02 22:39:45 +0100294 sp->hdr.seq = seq;
David Howells0b58b8a2016-09-02 22:39:45 +0100295 sp->hdr._rsvd = 0;
David Howells5a924b82016-09-22 00:29:31 +0100296 sp->hdr.flags = conn->out_clientflag;
David Howells0b58b8a2016-09-02 22:39:45 +0100297
David Howells0b58b8a2016-09-02 22:39:45 +0100298 if (msg_data_left(msg) == 0 && !more)
299 sp->hdr.flags |= RXRPC_LAST_PACKET;
David Howells248f2192016-09-08 11:10:12 +0100300 else if (call->tx_top - call->tx_hard_ack <
301 call->tx_winsize)
David Howells0b58b8a2016-09-02 22:39:45 +0100302 sp->hdr.flags |= RXRPC_MORE_PACKETS;
David Howells5a924b82016-09-22 00:29:31 +0100303 if (seq & 1)
David Howells0b58b8a2016-09-02 22:39:45 +0100304 sp->hdr.flags |= RXRPC_REQUEST_ACK;
305
306 ret = conn->security->secure_packet(
David Howells5a924b82016-09-22 00:29:31 +0100307 call, skb, skb->mark, skb->head);
David Howells0b58b8a2016-09-02 22:39:45 +0100308 if (ret < 0)
309 goto out;
310
David Howells0b58b8a2016-09-02 22:39:45 +0100311 rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more);
312 skb = NULL;
313 }
314 } while (msg_data_left(msg) > 0);
315
316success:
317 ret = copied;
318out:
319 call->tx_pending = skb;
320 _leave(" = %d", ret);
321 return ret;
322
323call_terminated:
David Howells71f3ca42016-09-17 10:49:14 +0100324 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells0b58b8a2016-09-02 22:39:45 +0100325 _leave(" = %d", -call->error);
David Howells248f2192016-09-08 11:10:12 +0100326 return -call->error;
David Howells0b58b8a2016-09-02 22:39:45 +0100327
328maybe_error:
329 if (copied)
330 goto success;
331 goto out;
332
333efault:
334 ret = -EFAULT;
335 goto out;
336}
David Howellsdf423a42016-09-02 22:39:45 +0100337
338/*
339 * extract control messages from the sendmsg() control buffer
340 */
341static int rxrpc_sendmsg_cmsg(struct msghdr *msg,
342 unsigned long *user_call_ID,
343 enum rxrpc_command *command,
344 u32 *abort_code,
345 bool *_exclusive)
346{
347 struct cmsghdr *cmsg;
348 bool got_user_ID = false;
349 int len;
350
351 *command = RXRPC_CMD_SEND_DATA;
352
353 if (msg->msg_controllen == 0)
354 return -EINVAL;
355
356 for_each_cmsghdr(cmsg, msg) {
357 if (!CMSG_OK(msg, cmsg))
358 return -EINVAL;
359
360 len = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr));
361 _debug("CMSG %d, %d, %d",
362 cmsg->cmsg_level, cmsg->cmsg_type, len);
363
364 if (cmsg->cmsg_level != SOL_RXRPC)
365 continue;
366
367 switch (cmsg->cmsg_type) {
368 case RXRPC_USER_CALL_ID:
369 if (msg->msg_flags & MSG_CMSG_COMPAT) {
370 if (len != sizeof(u32))
371 return -EINVAL;
372 *user_call_ID = *(u32 *) CMSG_DATA(cmsg);
373 } else {
374 if (len != sizeof(unsigned long))
375 return -EINVAL;
376 *user_call_ID = *(unsigned long *)
377 CMSG_DATA(cmsg);
378 }
379 _debug("User Call ID %lx", *user_call_ID);
380 got_user_ID = true;
381 break;
382
383 case RXRPC_ABORT:
384 if (*command != RXRPC_CMD_SEND_DATA)
385 return -EINVAL;
386 *command = RXRPC_CMD_SEND_ABORT;
387 if (len != sizeof(*abort_code))
388 return -EINVAL;
389 *abort_code = *(unsigned int *) CMSG_DATA(cmsg);
390 _debug("Abort %x", *abort_code);
391 if (*abort_code == 0)
392 return -EINVAL;
393 break;
394
395 case RXRPC_ACCEPT:
396 if (*command != RXRPC_CMD_SEND_DATA)
397 return -EINVAL;
398 *command = RXRPC_CMD_ACCEPT;
399 if (len != 0)
400 return -EINVAL;
401 break;
402
403 case RXRPC_EXCLUSIVE_CALL:
404 *_exclusive = true;
405 if (len != 0)
406 return -EINVAL;
407 break;
408 default:
409 return -EINVAL;
410 }
411 }
412
413 if (!got_user_ID)
414 return -EINVAL;
415 _leave(" = 0");
416 return 0;
417}
418
419/*
David Howellsdf423a42016-09-02 22:39:45 +0100420 * Create a new client call for sendmsg().
421 */
422static struct rxrpc_call *
423rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
424 unsigned long user_call_ID, bool exclusive)
425{
426 struct rxrpc_conn_parameters cp;
427 struct rxrpc_call *call;
428 struct key *key;
429
430 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name);
431
432 _enter("");
433
434 if (!msg->msg_name)
435 return ERR_PTR(-EDESTADDRREQ);
436
437 key = rx->key;
438 if (key && !rx->key->payload.data[0])
439 key = NULL;
440
441 memset(&cp, 0, sizeof(cp));
442 cp.local = rx->local;
443 cp.key = rx->key;
444 cp.security_level = rx->min_sec_level;
445 cp.exclusive = rx->exclusive | exclusive;
446 cp.service_id = srx->srx_service;
447 call = rxrpc_new_client_call(rx, &cp, srx, user_call_ID, GFP_KERNEL);
448
449 _leave(" = %p\n", call);
450 return call;
451}
452
453/*
454 * send a message forming part of a client call through an RxRPC socket
455 * - caller holds the socket locked
456 * - the socket may be either a client socket or a server socket
457 */
458int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
459{
460 enum rxrpc_command cmd;
461 struct rxrpc_call *call;
462 unsigned long user_call_ID = 0;
463 bool exclusive = false;
464 u32 abort_code = 0;
465 int ret;
466
467 _enter("");
468
469 ret = rxrpc_sendmsg_cmsg(msg, &user_call_ID, &cmd, &abort_code,
470 &exclusive);
471 if (ret < 0)
472 return ret;
473
474 if (cmd == RXRPC_CMD_ACCEPT) {
475 if (rx->sk.sk_state != RXRPC_SERVER_LISTENING)
476 return -EINVAL;
477 call = rxrpc_accept_call(rx, user_call_ID, NULL);
478 if (IS_ERR(call))
479 return PTR_ERR(call);
David Howellsfff724292016-09-07 14:34:21 +0100480 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100481 return 0;
482 }
483
484 call = rxrpc_find_call_by_user_ID(rx, user_call_ID);
485 if (!call) {
486 if (cmd != RXRPC_CMD_SEND_DATA)
487 return -EBADSLT;
488 call = rxrpc_new_client_call_for_sendmsg(rx, msg, user_call_ID,
489 exclusive);
490 if (IS_ERR(call))
491 return PTR_ERR(call);
492 }
493
David Howellsdf423a42016-09-02 22:39:45 +0100494 _debug("CALL %d USR %lx ST %d on CONN %p",
495 call->debug_id, call->user_call_ID, call->state, call->conn);
496
497 if (call->state >= RXRPC_CALL_COMPLETE) {
498 /* it's too late for this call */
499 ret = -ESHUTDOWN;
500 } else if (cmd == RXRPC_CMD_SEND_ABORT) {
David Howellsdf423a42016-09-02 22:39:45 +0100501 ret = 0;
David Howells248f2192016-09-08 11:10:12 +0100502 if (rxrpc_abort_call("CMD", call, 0, abort_code, ECONNABORTED))
503 ret = rxrpc_send_call_packet(call,
504 RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100505 } else if (cmd != RXRPC_CMD_SEND_DATA) {
506 ret = -EINVAL;
507 } else if (rxrpc_is_client_call(call) &&
508 call->state != RXRPC_CALL_CLIENT_SEND_REQUEST) {
509 /* request phase complete for this client call */
510 ret = -EPROTO;
511 } else if (rxrpc_is_service_call(call) &&
512 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
513 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
514 /* Reply phase not begun or not complete for service call. */
515 ret = -EPROTO;
516 } else {
517 ret = rxrpc_send_data(rx, call, msg, len);
518 }
519
David Howellsfff724292016-09-07 14:34:21 +0100520 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100521 _leave(" = %d", ret);
522 return ret;
523}
524
525/**
526 * rxrpc_kernel_send_data - Allow a kernel service to send data on a call
527 * @sock: The socket the call is on
528 * @call: The call to send data through
529 * @msg: The data to send
530 * @len: The amount of data to send
531 *
532 * Allow a kernel service to send data on a call. The call must be in an state
533 * appropriate to sending data. No control data should be supplied in @msg,
534 * nor should an address be supplied. MSG_MORE should be flagged if there's
535 * more data to come, otherwise this data will end the transmission phase.
536 */
537int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
538 struct msghdr *msg, size_t len)
539{
540 int ret;
541
542 _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]);
543
544 ASSERTCMP(msg->msg_name, ==, NULL);
545 ASSERTCMP(msg->msg_control, ==, NULL);
546
547 lock_sock(sock->sk);
548
549 _debug("CALL %d USR %lx ST %d on CONN %p",
550 call->debug_id, call->user_call_ID, call->state, call->conn);
551
552 if (call->state >= RXRPC_CALL_COMPLETE) {
553 ret = -ESHUTDOWN; /* it's too late for this call */
554 } else if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
555 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
556 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
557 ret = -EPROTO; /* request phase complete for this client call */
558 } else {
559 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len);
560 }
561
562 release_sock(sock->sk);
563 _leave(" = %d", ret);
564 return ret;
565}
566EXPORT_SYMBOL(rxrpc_kernel_send_data);
567
568/**
569 * rxrpc_kernel_abort_call - Allow a kernel service to abort a call
570 * @sock: The socket the call is on
571 * @call: The call to be aborted
572 * @abort_code: The abort code to stick into the ABORT packet
David Howells5a429762016-09-06 22:19:51 +0100573 * @error: Local error value
574 * @why: 3-char string indicating why.
David Howellsdf423a42016-09-02 22:39:45 +0100575 *
576 * Allow a kernel service to abort a call, if it's still in an abortable state.
577 */
578void rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call,
David Howells5a429762016-09-06 22:19:51 +0100579 u32 abort_code, int error, const char *why)
David Howellsdf423a42016-09-02 22:39:45 +0100580{
David Howells5a429762016-09-06 22:19:51 +0100581 _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why);
David Howellsdf423a42016-09-02 22:39:45 +0100582
583 lock_sock(sock->sk);
584
David Howells248f2192016-09-08 11:10:12 +0100585 if (rxrpc_abort_call(why, call, 0, abort_code, error))
586 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100587
588 release_sock(sock->sk);
589 _leave("");
590}
591
592EXPORT_SYMBOL(rxrpc_kernel_abort_call);