blob: ca3811bfbd177bc1dd6bedadfcf8610fe249b4a7 [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
David Howellsb24d2892016-09-23 13:17:33 +0100102 /* We have to set the timestamp before queueing as the retransmit
103 * algorithm can see the packet as soon as we queue it.
104 */
105 skb->tstamp = ktime_get_real();
106
David Howells248f2192016-09-08 11:10:12 +0100107 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howells71f3ca42016-09-17 10:49:14 +0100108 rxrpc_get_skb(skb, rxrpc_skb_tx_got);
David Howells248f2192016-09-08 11:10:12 +0100109 call->rxtx_annotations[ix] = RXRPC_TX_ANNO_UNACK;
David Howells0b58b8a2016-09-02 22:39:45 +0100110 smp_wmb();
David Howells248f2192016-09-08 11:10:12 +0100111 call->rxtx_buffer[ix] = skb;
112 call->tx_top = seq;
David Howellsa124fe32016-09-17 10:49:13 +0100113 if (last) {
David Howells248f2192016-09-08 11:10:12 +0100114 set_bit(RXRPC_CALL_TX_LAST, &call->flags);
David Howellsa124fe32016-09-17 10:49:13 +0100115 trace_rxrpc_transmit(call, rxrpc_transmit_queue_last);
116 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
117 trace_rxrpc_transmit(call, rxrpc_transmit_queue_reqack);
118 } else {
119 trace_rxrpc_transmit(call, rxrpc_transmit_queue);
120 }
David Howells0b58b8a2016-09-02 22:39:45 +0100121
122 if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) {
123 _debug("________awaiting reply/ACK__________");
124 write_lock_bh(&call->state_lock);
125 switch (call->state) {
126 case RXRPC_CALL_CLIENT_SEND_REQUEST:
127 call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
128 break;
129 case RXRPC_CALL_SERVER_ACK_REQUEST:
130 call->state = RXRPC_CALL_SERVER_SEND_REPLY;
131 if (!last)
132 break;
133 case RXRPC_CALL_SERVER_SEND_REPLY:
134 call->state = RXRPC_CALL_SERVER_AWAIT_ACK;
135 break;
136 default:
137 break;
138 }
139 write_unlock_bh(&call->state_lock);
140 }
141
David Howells248f2192016-09-08 11:10:12 +0100142 if (seq == 1 && rxrpc_is_client_call(call))
143 rxrpc_expose_client_call(call);
144
David Howells5a924b82016-09-22 00:29:31 +0100145 ret = rxrpc_send_data_packet(call, skb);
David Howells0b58b8a2016-09-02 22:39:45 +0100146 if (ret < 0) {
147 _debug("need instant resend %d", ret);
David Howells248f2192016-09-08 11:10:12 +0100148 rxrpc_instant_resend(call, ix);
David Howells0b58b8a2016-09-02 22:39:45 +0100149 }
150
David Howells71f3ca42016-09-17 10:49:14 +0100151 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells0b58b8a2016-09-02 22:39:45 +0100152 _leave("");
153}
154
155/*
David Howells0b58b8a2016-09-02 22:39:45 +0100156 * send data through a socket
157 * - must be called in process context
158 * - caller holds the socket locked
159 */
160static int rxrpc_send_data(struct rxrpc_sock *rx,
161 struct rxrpc_call *call,
162 struct msghdr *msg, size_t len)
163{
164 struct rxrpc_skb_priv *sp;
165 struct sk_buff *skb;
166 struct sock *sk = &rx->sk;
167 long timeo;
168 bool more;
169 int ret, copied;
170
171 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
172
173 /* this should be in poll */
174 sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
175
176 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
177 return -EPIPE;
178
179 more = msg->msg_flags & MSG_MORE;
180
181 skb = call->tx_pending;
182 call->tx_pending = NULL;
David Howells71f3ca42016-09-17 10:49:14 +0100183 rxrpc_see_skb(skb, rxrpc_skb_tx_seen);
David Howells0b58b8a2016-09-02 22:39:45 +0100184
185 copied = 0;
186 do {
David Howells7aa51da2016-09-22 00:29:31 +0100187 /* Check to see if there's a ping ACK to reply to. */
188 if (call->ackr_reason == RXRPC_ACK_PING_RESPONSE)
189 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
190
David Howells0b58b8a2016-09-02 22:39:45 +0100191 if (!skb) {
192 size_t size, chunk, max, space;
193
194 _debug("alloc");
195
David Howells248f2192016-09-08 11:10:12 +0100196 if (call->tx_top - call->tx_hard_ack >=
197 call->tx_winsize) {
David Howells0b58b8a2016-09-02 22:39:45 +0100198 ret = -EAGAIN;
199 if (msg->msg_flags & MSG_DONTWAIT)
200 goto maybe_error;
201 ret = rxrpc_wait_for_tx_window(rx, call,
202 &timeo);
203 if (ret < 0)
204 goto maybe_error;
205 }
206
David Howells182f5052016-09-17 10:49:12 +0100207 max = RXRPC_JUMBO_DATALEN;
David Howells0b58b8a2016-09-02 22:39:45 +0100208 max -= call->conn->security_size;
209 max &= ~(call->conn->size_align - 1UL);
210
211 chunk = max;
212 if (chunk > msg_data_left(msg) && !more)
213 chunk = msg_data_left(msg);
214
215 space = chunk + call->conn->size_align;
216 space &= ~(call->conn->size_align - 1UL);
217
David Howells5a924b82016-09-22 00:29:31 +0100218 size = space + call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100219
220 _debug("SIZE: %zu/%zu/%zu", chunk, space, size);
221
222 /* create a buffer that we can retain until it's ACK'd */
223 skb = sock_alloc_send_skb(
224 sk, size, msg->msg_flags & MSG_DONTWAIT, &ret);
225 if (!skb)
226 goto maybe_error;
227
David Howells71f3ca42016-09-17 10:49:14 +0100228 rxrpc_new_skb(skb, rxrpc_skb_tx_new);
David Howells0b58b8a2016-09-02 22:39:45 +0100229
230 _debug("ALLOC SEND %p", skb);
231
232 ASSERTCMP(skb->mark, ==, 0);
233
David Howells5a924b82016-09-22 00:29:31 +0100234 _debug("HS: %u", call->conn->security_size);
235 skb_reserve(skb, call->conn->security_size);
236 skb->len += call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100237
238 sp = rxrpc_skb(skb);
239 sp->remain = chunk;
240 if (sp->remain > skb_tailroom(skb))
241 sp->remain = skb_tailroom(skb);
242
243 _net("skb: hr %d, tr %d, hl %d, rm %d",
244 skb_headroom(skb),
245 skb_tailroom(skb),
246 skb_headlen(skb),
247 sp->remain);
248
249 skb->ip_summed = CHECKSUM_UNNECESSARY;
250 }
251
252 _debug("append");
253 sp = rxrpc_skb(skb);
254
255 /* append next segment of data to the current buffer */
256 if (msg_data_left(msg) > 0) {
257 int copy = skb_tailroom(skb);
258 ASSERTCMP(copy, >, 0);
259 if (copy > msg_data_left(msg))
260 copy = msg_data_left(msg);
261 if (copy > sp->remain)
262 copy = sp->remain;
263
264 _debug("add");
265 ret = skb_add_data(skb, &msg->msg_iter, copy);
266 _debug("added");
267 if (ret < 0)
268 goto efault;
269 sp->remain -= copy;
270 skb->mark += copy;
271 copied += copy;
272 }
273
274 /* check for the far side aborting the call or a network error
275 * occurring */
276 if (call->state == RXRPC_CALL_COMPLETE)
277 goto call_terminated;
278
279 /* add the packet to the send queue if it's now full */
280 if (sp->remain <= 0 ||
281 (msg_data_left(msg) == 0 && !more)) {
282 struct rxrpc_connection *conn = call->conn;
283 uint32_t seq;
284 size_t pad;
285
286 /* pad out if we're using security */
287 if (conn->security_ix) {
288 pad = conn->security_size + skb->mark;
289 pad = conn->size_align - pad;
290 pad &= conn->size_align - 1;
291 _debug("pad %zu", pad);
292 if (pad)
293 memset(skb_put(skb, pad), 0, pad);
294 }
295
David Howells248f2192016-09-08 11:10:12 +0100296 seq = call->tx_top + 1;
David Howells0b58b8a2016-09-02 22:39:45 +0100297
David Howells0b58b8a2016-09-02 22:39:45 +0100298 sp->hdr.seq = seq;
David Howells0b58b8a2016-09-02 22:39:45 +0100299 sp->hdr._rsvd = 0;
David Howells5a924b82016-09-22 00:29:31 +0100300 sp->hdr.flags = conn->out_clientflag;
David Howells0b58b8a2016-09-02 22:39:45 +0100301
David Howells0b58b8a2016-09-02 22:39:45 +0100302 if (msg_data_left(msg) == 0 && !more)
303 sp->hdr.flags |= RXRPC_LAST_PACKET;
David Howells248f2192016-09-08 11:10:12 +0100304 else if (call->tx_top - call->tx_hard_ack <
305 call->tx_winsize)
David Howells0b58b8a2016-09-02 22:39:45 +0100306 sp->hdr.flags |= RXRPC_MORE_PACKETS;
David Howells0b58b8a2016-09-02 22:39:45 +0100307
308 ret = conn->security->secure_packet(
David Howells5a924b82016-09-22 00:29:31 +0100309 call, skb, skb->mark, skb->head);
David Howells0b58b8a2016-09-02 22:39:45 +0100310 if (ret < 0)
311 goto out;
312
David Howells0b58b8a2016-09-02 22:39:45 +0100313 rxrpc_queue_packet(call, skb, !msg_data_left(msg) && !more);
314 skb = NULL;
315 }
316 } while (msg_data_left(msg) > 0);
317
318success:
319 ret = copied;
320out:
321 call->tx_pending = skb;
322 _leave(" = %d", ret);
323 return ret;
324
325call_terminated:
David Howells71f3ca42016-09-17 10:49:14 +0100326 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells0b58b8a2016-09-02 22:39:45 +0100327 _leave(" = %d", -call->error);
David Howells248f2192016-09-08 11:10:12 +0100328 return -call->error;
David Howells0b58b8a2016-09-02 22:39:45 +0100329
330maybe_error:
331 if (copied)
332 goto success;
333 goto out;
334
335efault:
336 ret = -EFAULT;
337 goto out;
338}
David Howellsdf423a42016-09-02 22:39:45 +0100339
340/*
341 * extract control messages from the sendmsg() control buffer
342 */
343static int rxrpc_sendmsg_cmsg(struct msghdr *msg,
344 unsigned long *user_call_ID,
345 enum rxrpc_command *command,
346 u32 *abort_code,
347 bool *_exclusive)
348{
349 struct cmsghdr *cmsg;
350 bool got_user_ID = false;
351 int len;
352
353 *command = RXRPC_CMD_SEND_DATA;
354
355 if (msg->msg_controllen == 0)
356 return -EINVAL;
357
358 for_each_cmsghdr(cmsg, msg) {
359 if (!CMSG_OK(msg, cmsg))
360 return -EINVAL;
361
362 len = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr));
363 _debug("CMSG %d, %d, %d",
364 cmsg->cmsg_level, cmsg->cmsg_type, len);
365
366 if (cmsg->cmsg_level != SOL_RXRPC)
367 continue;
368
369 switch (cmsg->cmsg_type) {
370 case RXRPC_USER_CALL_ID:
371 if (msg->msg_flags & MSG_CMSG_COMPAT) {
372 if (len != sizeof(u32))
373 return -EINVAL;
374 *user_call_ID = *(u32 *) CMSG_DATA(cmsg);
375 } else {
376 if (len != sizeof(unsigned long))
377 return -EINVAL;
378 *user_call_ID = *(unsigned long *)
379 CMSG_DATA(cmsg);
380 }
381 _debug("User Call ID %lx", *user_call_ID);
382 got_user_ID = true;
383 break;
384
385 case RXRPC_ABORT:
386 if (*command != RXRPC_CMD_SEND_DATA)
387 return -EINVAL;
388 *command = RXRPC_CMD_SEND_ABORT;
389 if (len != sizeof(*abort_code))
390 return -EINVAL;
391 *abort_code = *(unsigned int *) CMSG_DATA(cmsg);
392 _debug("Abort %x", *abort_code);
393 if (*abort_code == 0)
394 return -EINVAL;
395 break;
396
397 case RXRPC_ACCEPT:
398 if (*command != RXRPC_CMD_SEND_DATA)
399 return -EINVAL;
400 *command = RXRPC_CMD_ACCEPT;
401 if (len != 0)
402 return -EINVAL;
403 break;
404
405 case RXRPC_EXCLUSIVE_CALL:
406 *_exclusive = true;
407 if (len != 0)
408 return -EINVAL;
409 break;
410 default:
411 return -EINVAL;
412 }
413 }
414
415 if (!got_user_ID)
416 return -EINVAL;
417 _leave(" = 0");
418 return 0;
419}
420
421/*
David Howellsdf423a42016-09-02 22:39:45 +0100422 * Create a new client call for sendmsg().
423 */
424static struct rxrpc_call *
425rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
426 unsigned long user_call_ID, bool exclusive)
427{
428 struct rxrpc_conn_parameters cp;
429 struct rxrpc_call *call;
430 struct key *key;
431
432 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name);
433
434 _enter("");
435
436 if (!msg->msg_name)
437 return ERR_PTR(-EDESTADDRREQ);
438
439 key = rx->key;
440 if (key && !rx->key->payload.data[0])
441 key = NULL;
442
443 memset(&cp, 0, sizeof(cp));
444 cp.local = rx->local;
445 cp.key = rx->key;
446 cp.security_level = rx->min_sec_level;
447 cp.exclusive = rx->exclusive | exclusive;
448 cp.service_id = srx->srx_service;
449 call = rxrpc_new_client_call(rx, &cp, srx, user_call_ID, GFP_KERNEL);
450
451 _leave(" = %p\n", call);
452 return call;
453}
454
455/*
456 * send a message forming part of a client call through an RxRPC socket
457 * - caller holds the socket locked
458 * - the socket may be either a client socket or a server socket
459 */
460int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
461{
462 enum rxrpc_command cmd;
463 struct rxrpc_call *call;
464 unsigned long user_call_ID = 0;
465 bool exclusive = false;
466 u32 abort_code = 0;
467 int ret;
468
469 _enter("");
470
471 ret = rxrpc_sendmsg_cmsg(msg, &user_call_ID, &cmd, &abort_code,
472 &exclusive);
473 if (ret < 0)
474 return ret;
475
476 if (cmd == RXRPC_CMD_ACCEPT) {
477 if (rx->sk.sk_state != RXRPC_SERVER_LISTENING)
478 return -EINVAL;
479 call = rxrpc_accept_call(rx, user_call_ID, NULL);
480 if (IS_ERR(call))
481 return PTR_ERR(call);
David Howellsfff724292016-09-07 14:34:21 +0100482 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100483 return 0;
484 }
485
486 call = rxrpc_find_call_by_user_ID(rx, user_call_ID);
487 if (!call) {
488 if (cmd != RXRPC_CMD_SEND_DATA)
489 return -EBADSLT;
490 call = rxrpc_new_client_call_for_sendmsg(rx, msg, user_call_ID,
491 exclusive);
492 if (IS_ERR(call))
493 return PTR_ERR(call);
494 }
495
David Howellsdf423a42016-09-02 22:39:45 +0100496 _debug("CALL %d USR %lx ST %d on CONN %p",
497 call->debug_id, call->user_call_ID, call->state, call->conn);
498
499 if (call->state >= RXRPC_CALL_COMPLETE) {
500 /* it's too late for this call */
501 ret = -ESHUTDOWN;
502 } else if (cmd == RXRPC_CMD_SEND_ABORT) {
David Howellsdf423a42016-09-02 22:39:45 +0100503 ret = 0;
David Howells248f2192016-09-08 11:10:12 +0100504 if (rxrpc_abort_call("CMD", call, 0, abort_code, ECONNABORTED))
505 ret = rxrpc_send_call_packet(call,
506 RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100507 } else if (cmd != RXRPC_CMD_SEND_DATA) {
508 ret = -EINVAL;
509 } else if (rxrpc_is_client_call(call) &&
510 call->state != RXRPC_CALL_CLIENT_SEND_REQUEST) {
511 /* request phase complete for this client call */
512 ret = -EPROTO;
513 } else if (rxrpc_is_service_call(call) &&
514 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
515 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
516 /* Reply phase not begun or not complete for service call. */
517 ret = -EPROTO;
518 } else {
519 ret = rxrpc_send_data(rx, call, msg, len);
520 }
521
David Howellsfff724292016-09-07 14:34:21 +0100522 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100523 _leave(" = %d", ret);
524 return ret;
525}
526
527/**
528 * rxrpc_kernel_send_data - Allow a kernel service to send data on a call
529 * @sock: The socket the call is on
530 * @call: The call to send data through
531 * @msg: The data to send
532 * @len: The amount of data to send
533 *
534 * Allow a kernel service to send data on a call. The call must be in an state
535 * appropriate to sending data. No control data should be supplied in @msg,
536 * nor should an address be supplied. MSG_MORE should be flagged if there's
537 * more data to come, otherwise this data will end the transmission phase.
538 */
539int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
540 struct msghdr *msg, size_t len)
541{
542 int ret;
543
544 _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]);
545
546 ASSERTCMP(msg->msg_name, ==, NULL);
547 ASSERTCMP(msg->msg_control, ==, NULL);
548
549 lock_sock(sock->sk);
550
551 _debug("CALL %d USR %lx ST %d on CONN %p",
552 call->debug_id, call->user_call_ID, call->state, call->conn);
553
554 if (call->state >= RXRPC_CALL_COMPLETE) {
555 ret = -ESHUTDOWN; /* it's too late for this call */
556 } else if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
557 call->state != RXRPC_CALL_SERVER_ACK_REQUEST &&
558 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
559 ret = -EPROTO; /* request phase complete for this client call */
560 } else {
561 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len);
562 }
563
564 release_sock(sock->sk);
565 _leave(" = %d", ret);
566 return ret;
567}
568EXPORT_SYMBOL(rxrpc_kernel_send_data);
569
570/**
571 * rxrpc_kernel_abort_call - Allow a kernel service to abort a call
572 * @sock: The socket the call is on
573 * @call: The call to be aborted
574 * @abort_code: The abort code to stick into the ABORT packet
David Howells5a429762016-09-06 22:19:51 +0100575 * @error: Local error value
576 * @why: 3-char string indicating why.
David Howellsdf423a42016-09-02 22:39:45 +0100577 *
578 * Allow a kernel service to abort a call, if it's still in an abortable state.
579 */
580void rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call,
David Howells5a429762016-09-06 22:19:51 +0100581 u32 abort_code, int error, const char *why)
David Howellsdf423a42016-09-02 22:39:45 +0100582{
David Howells5a429762016-09-06 22:19:51 +0100583 _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why);
David Howellsdf423a42016-09-02 22:39:45 +0100584
585 lock_sock(sock->sk);
586
David Howells248f2192016-09-08 11:10:12 +0100587 if (rxrpc_abort_call(why, call, 0, abort_code, error))
588 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ABORT);
David Howellsdf423a42016-09-02 22:39:45 +0100589
590 release_sock(sock->sk);
591 _leave("");
592}
593
594EXPORT_SYMBOL(rxrpc_kernel_abort_call);