blob: 16ff56f6925636a538b145cacfd7bc8974a0f5ea [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* RxRPC recvmsg() implementation
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Joe Perches9b6d5392016-06-02 12:08:52 -070012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
David Howells17926a72007-04-26 15:48:28 -070014#include <linux/net.h>
15#include <linux/skbuff.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040016#include <linux/export.h>
David Howells17926a72007-04-26 15:48:28 -070017#include <net/sock.h>
18#include <net/af_rxrpc.h>
19#include "ar-internal.h"
20
21/*
David Howells248f2192016-09-08 11:10:12 +010022 * Post a call for attention by the socket or kernel service. Further
23 * notifications are suppressed by putting recvmsg_link on a dummy queue.
24 */
25void rxrpc_notify_socket(struct rxrpc_call *call)
26{
27 struct rxrpc_sock *rx;
28 struct sock *sk;
29
30 _enter("%d", call->debug_id);
31
32 if (!list_empty(&call->recvmsg_link))
33 return;
34
35 rcu_read_lock();
36
37 rx = rcu_dereference(call->socket);
38 sk = &rx->sk;
39 if (rx && sk->sk_state < RXRPC_CLOSE) {
40 if (call->notify_rx) {
41 call->notify_rx(sk, call, call->user_call_ID);
42 } else {
43 write_lock_bh(&rx->recvmsg_lock);
44 if (list_empty(&call->recvmsg_link)) {
45 rxrpc_get_call(call, rxrpc_call_got);
46 list_add_tail(&call->recvmsg_link, &rx->recvmsg_q);
47 }
48 write_unlock_bh(&rx->recvmsg_lock);
49
50 if (!sock_flag(sk, SOCK_DEAD)) {
51 _debug("call %ps", sk->sk_data_ready);
52 sk->sk_data_ready(sk);
53 }
54 }
55 }
56
57 rcu_read_unlock();
58 _leave("");
59}
60
61/*
62 * Pass a call terminating message to userspace.
63 */
64static int rxrpc_recvmsg_term(struct rxrpc_call *call, struct msghdr *msg)
65{
66 u32 tmp = 0;
67 int ret;
68
69 switch (call->completion) {
70 case RXRPC_CALL_SUCCEEDED:
71 ret = 0;
72 if (rxrpc_is_service_call(call))
73 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_ACK, 0, &tmp);
74 break;
75 case RXRPC_CALL_REMOTELY_ABORTED:
76 tmp = call->abort_code;
77 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_ABORT, 4, &tmp);
78 break;
79 case RXRPC_CALL_LOCALLY_ABORTED:
80 tmp = call->abort_code;
81 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_ABORT, 4, &tmp);
82 break;
83 case RXRPC_CALL_NETWORK_ERROR:
84 tmp = call->error;
85 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_NET_ERROR, 4, &tmp);
86 break;
87 case RXRPC_CALL_LOCAL_ERROR:
88 tmp = call->error;
89 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_LOCAL_ERROR, 4, &tmp);
90 break;
91 default:
92 pr_err("Invalid terminal call state %u\n", call->state);
93 BUG();
94 break;
95 }
96
97 return ret;
98}
99
100/*
101 * Pass back notification of a new call. The call is added to the
102 * to-be-accepted list. This means that the next call to be accepted might not
103 * be the last call seen awaiting acceptance, but unless we leave this on the
104 * front of the queue and block all other messages until someone gives us a
105 * user_ID for it, there's not a lot we can do.
106 */
107static int rxrpc_recvmsg_new_call(struct rxrpc_sock *rx,
108 struct rxrpc_call *call,
109 struct msghdr *msg, int flags)
110{
111 int tmp = 0, ret;
112
113 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_NEW_CALL, 0, &tmp);
114
115 if (ret == 0 && !(flags & MSG_PEEK)) {
116 _debug("to be accepted");
117 write_lock_bh(&rx->recvmsg_lock);
118 list_del_init(&call->recvmsg_link);
119 write_unlock_bh(&rx->recvmsg_lock);
120
121 write_lock(&rx->call_lock);
122 list_add_tail(&call->accept_link, &rx->to_be_accepted);
123 write_unlock(&rx->call_lock);
124 }
125
126 return ret;
127}
128
129/*
130 * End the packet reception phase.
131 */
132static void rxrpc_end_rx_phase(struct rxrpc_call *call)
133{
134 _enter("%d,%s", call->debug_id, rxrpc_call_states[call->state]);
135
136 if (call->state == RXRPC_CALL_CLIENT_RECV_REPLY) {
137 rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, true, false);
138 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
139 } else {
140 rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, false, false);
141 }
142
143 write_lock_bh(&call->state_lock);
144
145 switch (call->state) {
146 case RXRPC_CALL_CLIENT_RECV_REPLY:
147 __rxrpc_call_completed(call);
148 break;
149
150 case RXRPC_CALL_SERVER_RECV_REQUEST:
151 call->state = RXRPC_CALL_SERVER_ACK_REQUEST;
152 break;
153 default:
154 break;
155 }
156
157 write_unlock_bh(&call->state_lock);
158}
159
160/*
161 * Discard a packet we've used up and advance the Rx window by one.
162 */
163static void rxrpc_rotate_rx_window(struct rxrpc_call *call)
164{
165 struct sk_buff *skb;
166 rxrpc_seq_t hard_ack, top;
167 int ix;
168
169 _enter("%d", call->debug_id);
170
171 hard_ack = call->rx_hard_ack;
172 top = smp_load_acquire(&call->rx_top);
173 ASSERT(before(hard_ack, top));
174
175 hard_ack++;
176 ix = hard_ack & RXRPC_RXTX_BUFF_MASK;
177 skb = call->rxtx_buffer[ix];
178 rxrpc_see_skb(skb);
179 call->rxtx_buffer[ix] = NULL;
180 call->rxtx_annotations[ix] = 0;
181 /* Barrier against rxrpc_input_data(). */
182 smp_store_release(&call->rx_hard_ack, hard_ack);
183
184 rxrpc_free_skb(skb);
185
186 _debug("%u,%u,%lx", hard_ack, top, call->flags);
187 if (hard_ack == top && test_bit(RXRPC_CALL_RX_LAST, &call->flags))
188 rxrpc_end_rx_phase(call);
189}
190
191/*
192 * Decrypt and verify a (sub)packet. The packet's length may be changed due to
193 * padding, but if this is the case, the packet length will be resident in the
194 * socket buffer. Note that we can't modify the master skb info as the skb may
195 * be the home to multiple subpackets.
196 */
197static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
198 u8 annotation,
199 unsigned int offset, unsigned int len)
200{
201 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
202 rxrpc_seq_t seq = sp->hdr.seq;
203 u16 cksum = sp->hdr.cksum;
204
205 _enter("");
206
207 /* For all but the head jumbo subpacket, the security checksum is in a
208 * jumbo header immediately prior to the data.
209 */
210 if ((annotation & RXRPC_RX_ANNO_JUMBO) > 1) {
211 __be16 tmp;
212 if (skb_copy_bits(skb, offset - 2, &tmp, 2) < 0)
213 BUG();
214 cksum = ntohs(tmp);
215 seq += (annotation & RXRPC_RX_ANNO_JUMBO) - 1;
216 }
217
218 return call->conn->security->verify_packet(call, skb, offset, len,
219 seq, cksum);
220}
221
222/*
223 * Locate the data within a packet. This is complicated by:
224 *
225 * (1) An skb may contain a jumbo packet - so we have to find the appropriate
226 * subpacket.
227 *
228 * (2) The (sub)packets may be encrypted and, if so, the encrypted portion
229 * contains an extra header which includes the true length of the data,
230 * excluding any encrypted padding.
231 */
232static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
233 u8 *_annotation,
234 unsigned int *_offset, unsigned int *_len)
235{
236 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
237 unsigned int offset = *_offset;
238 unsigned int len = *_len;
239 int ret;
240 u8 annotation = *_annotation;
241
242 if (offset > 0)
243 return 0;
244
245 /* Locate the subpacket */
246 offset = sp->offset;
247 len = skb->len - sp->offset;
248 if ((annotation & RXRPC_RX_ANNO_JUMBO) > 0) {
249 offset += (((annotation & RXRPC_RX_ANNO_JUMBO) - 1) *
250 RXRPC_JUMBO_SUBPKTLEN);
251 len = (annotation & RXRPC_RX_ANNO_JLAST) ?
252 skb->len - offset : RXRPC_JUMBO_SUBPKTLEN;
253 }
254
255 if (!(annotation & RXRPC_RX_ANNO_VERIFIED)) {
256 ret = rxrpc_verify_packet(call, skb, annotation, offset, len);
257 if (ret < 0)
258 return ret;
259 *_annotation |= RXRPC_RX_ANNO_VERIFIED;
260 }
261
262 *_offset = offset;
263 *_len = len;
264 call->conn->security->locate_data(call, skb, _offset, _len);
265 return 0;
266}
267
268/*
269 * Deliver messages to a call. This keeps processing packets until the buffer
270 * is filled and we find either more DATA (returns 0) or the end of the DATA
271 * (returns 1). If more packets are required, it returns -EAGAIN.
272 */
273static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
274 struct msghdr *msg, struct iov_iter *iter,
275 size_t len, int flags, size_t *_offset)
276{
277 struct rxrpc_skb_priv *sp;
278 struct sk_buff *skb;
279 rxrpc_seq_t hard_ack, top, seq;
280 size_t remain;
281 bool last;
282 unsigned int rx_pkt_offset, rx_pkt_len;
283 int ix, copy, ret = 0;
284
285 _enter("");
286
287 rx_pkt_offset = call->rx_pkt_offset;
288 rx_pkt_len = call->rx_pkt_len;
289
290 /* Barriers against rxrpc_input_data(). */
291 hard_ack = call->rx_hard_ack;
292 top = smp_load_acquire(&call->rx_top);
293 for (seq = hard_ack + 1; before_eq(seq, top); seq++) {
294 ix = seq & RXRPC_RXTX_BUFF_MASK;
295 skb = call->rxtx_buffer[ix];
296 if (!skb)
297 break;
298 smp_rmb();
299 rxrpc_see_skb(skb);
300 sp = rxrpc_skb(skb);
301
302 if (msg)
303 sock_recv_timestamp(msg, sock->sk, skb);
304
305 ret = rxrpc_locate_data(call, skb, &call->rxtx_annotations[ix],
306 &rx_pkt_offset, &rx_pkt_len);
307 _debug("recvmsg %x DATA #%u { %d, %d }",
308 sp->hdr.callNumber, seq, rx_pkt_offset, rx_pkt_len);
309
310 /* We have to handle short, empty and used-up DATA packets. */
311 remain = len - *_offset;
312 copy = rx_pkt_len;
313 if (copy > remain)
314 copy = remain;
315 if (copy > 0) {
316 ret = skb_copy_datagram_iter(skb, rx_pkt_offset, iter,
317 copy);
318 if (ret < 0)
319 goto out;
320
321 /* handle piecemeal consumption of data packets */
322 _debug("copied %d @%zu", copy, *_offset);
323
324 rx_pkt_offset += copy;
325 rx_pkt_len -= copy;
326 *_offset += copy;
327 }
328
329 if (rx_pkt_len > 0) {
330 _debug("buffer full");
331 ASSERTCMP(*_offset, ==, len);
332 break;
333 }
334
335 /* The whole packet has been transferred. */
336 last = sp->hdr.flags & RXRPC_LAST_PACKET;
337 if (!(flags & MSG_PEEK))
338 rxrpc_rotate_rx_window(call);
339 rx_pkt_offset = 0;
340 rx_pkt_len = 0;
341
342 ASSERTIFCMP(last, seq, ==, top);
343 }
344
345 if (after(seq, top)) {
346 ret = -EAGAIN;
347 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags))
348 ret = 1;
349 }
350out:
351 if (!(flags & MSG_PEEK)) {
352 call->rx_pkt_offset = rx_pkt_offset;
353 call->rx_pkt_len = rx_pkt_len;
354 }
355 _leave(" = %d [%u/%u]", ret, seq, top);
356 return ret;
357}
358
359/*
360 * Receive a message from an RxRPC socket
David Howells17926a72007-04-26 15:48:28 -0700361 * - we need to be careful about two or more threads calling recvmsg
362 * simultaneously
363 */
Ying Xue1b784142015-03-02 15:37:48 +0800364int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
365 int flags)
David Howells17926a72007-04-26 15:48:28 -0700366{
David Howells248f2192016-09-08 11:10:12 +0100367 struct rxrpc_call *call;
David Howells17926a72007-04-26 15:48:28 -0700368 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
David Howells248f2192016-09-08 11:10:12 +0100369 struct list_head *l;
370 size_t copied = 0;
David Howells17926a72007-04-26 15:48:28 -0700371 long timeo;
David Howells248f2192016-09-08 11:10:12 +0100372 int ret;
David Howells17926a72007-04-26 15:48:28 -0700373
374 DEFINE_WAIT(wait);
375
376 _enter(",,,%zu,%d", len, flags);
377
378 if (flags & (MSG_OOB | MSG_TRUNC))
379 return -EOPNOTSUPP;
380
David Howells17926a72007-04-26 15:48:28 -0700381 timeo = sock_rcvtimeo(&rx->sk, flags & MSG_DONTWAIT);
David Howells17926a72007-04-26 15:48:28 -0700382
David Howells248f2192016-09-08 11:10:12 +0100383try_again:
David Howells17926a72007-04-26 15:48:28 -0700384 lock_sock(&rx->sk);
385
David Howells248f2192016-09-08 11:10:12 +0100386 /* Return immediately if a client socket has no outstanding calls */
387 if (RB_EMPTY_ROOT(&rx->calls) &&
388 list_empty(&rx->recvmsg_q) &&
389 rx->sk.sk_state != RXRPC_SERVER_LISTENING) {
390 release_sock(&rx->sk);
391 return -ENODATA;
392 }
393
394 if (list_empty(&rx->recvmsg_q)) {
395 ret = -EWOULDBLOCK;
396 if (timeo == 0)
397 goto error_no_call;
398
399 release_sock(&rx->sk);
400
401 /* Wait for something to happen */
402 prepare_to_wait_exclusive(sk_sleep(&rx->sk), &wait,
403 TASK_INTERRUPTIBLE);
404 ret = sock_error(&rx->sk);
405 if (ret)
406 goto wait_error;
407
408 if (list_empty(&rx->recvmsg_q)) {
409 if (signal_pending(current))
410 goto wait_interrupted;
411 timeo = schedule_timeout(timeo);
David Howells17926a72007-04-26 15:48:28 -0700412 }
David Howells248f2192016-09-08 11:10:12 +0100413 finish_wait(sk_sleep(&rx->sk), &wait);
414 goto try_again;
415 }
David Howells17926a72007-04-26 15:48:28 -0700416
David Howells248f2192016-09-08 11:10:12 +0100417 /* Find the next call and dequeue it if we're not just peeking. If we
418 * do dequeue it, that comes with a ref that we will need to release.
419 */
420 write_lock_bh(&rx->recvmsg_lock);
421 l = rx->recvmsg_q.next;
422 call = list_entry(l, struct rxrpc_call, recvmsg_link);
423 if (!(flags & MSG_PEEK))
424 list_del_init(&call->recvmsg_link);
425 else
David Howellsfff724292016-09-07 14:34:21 +0100426 rxrpc_get_call(call, rxrpc_call_got);
David Howells248f2192016-09-08 11:10:12 +0100427 write_unlock_bh(&rx->recvmsg_lock);
David Howells17926a72007-04-26 15:48:28 -0700428
David Howells248f2192016-09-08 11:10:12 +0100429 _debug("recvmsg call %p", call);
David Howells17926a72007-04-26 15:48:28 -0700430
David Howells248f2192016-09-08 11:10:12 +0100431 if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
David Howells17926a72007-04-26 15:48:28 -0700432 BUG();
David Howells248f2192016-09-08 11:10:12 +0100433
434 if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
435 if (flags & MSG_CMSG_COMPAT) {
436 unsigned int id32 = call->user_call_ID;
437
438 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
439 sizeof(unsigned int), &id32);
440 } else {
441 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
442 sizeof(unsigned long),
443 &call->user_call_ID);
David Howellsf5c17aa2016-08-30 09:49:28 +0100444 }
David Howells248f2192016-09-08 11:10:12 +0100445 if (ret < 0)
446 goto error;
447 }
448
449 if (msg->msg_name) {
450 size_t len = sizeof(call->conn->params.peer->srx);
451 memcpy(msg->msg_name, &call->conn->params.peer->srx, len);
452 msg->msg_namelen = len;
453 }
454
455 switch (call->state) {
456 case RXRPC_CALL_SERVER_ACCEPTING:
457 ret = rxrpc_recvmsg_new_call(rx, call, msg, flags);
David Howells17926a72007-04-26 15:48:28 -0700458 break;
David Howells248f2192016-09-08 11:10:12 +0100459 case RXRPC_CALL_CLIENT_RECV_REPLY:
460 case RXRPC_CALL_SERVER_RECV_REQUEST:
461 case RXRPC_CALL_SERVER_ACK_REQUEST:
462 ret = rxrpc_recvmsg_data(sock, call, msg, &msg->msg_iter, len,
463 flags, &copied);
464 if (ret == -EAGAIN)
465 ret = 0;
David Howells33b603f2016-09-13 22:36:21 +0100466
467 if (after(call->rx_top, call->rx_hard_ack) &&
468 call->rxtx_buffer[(call->rx_hard_ack + 1) & RXRPC_RXTX_BUFF_MASK])
469 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700470 break;
471 default:
David Howells248f2192016-09-08 11:10:12 +0100472 ret = 0;
David Howells17926a72007-04-26 15:48:28 -0700473 break;
474 }
475
476 if (ret < 0)
David Howells248f2192016-09-08 11:10:12 +0100477 goto error;
David Howells17926a72007-04-26 15:48:28 -0700478
David Howells248f2192016-09-08 11:10:12 +0100479 if (call->state == RXRPC_CALL_COMPLETE) {
480 ret = rxrpc_recvmsg_term(call, msg);
481 if (ret < 0)
482 goto error;
483 if (!(flags & MSG_PEEK))
484 rxrpc_release_call(rx, call);
485 msg->msg_flags |= MSG_EOR;
486 ret = 1;
David Howells17926a72007-04-26 15:48:28 -0700487 }
488
David Howells248f2192016-09-08 11:10:12 +0100489 if (ret == 0)
490 msg->msg_flags |= MSG_MORE;
491 else
492 msg->msg_flags &= ~MSG_MORE;
493 ret = copied;
David Howells17926a72007-04-26 15:48:28 -0700494
David Howells248f2192016-09-08 11:10:12 +0100495error:
David Howellsfff724292016-09-07 14:34:21 +0100496 rxrpc_put_call(call, rxrpc_call_put);
David Howells248f2192016-09-08 11:10:12 +0100497error_no_call:
498 release_sock(&rx->sk);
David Howells17926a72007-04-26 15:48:28 -0700499 _leave(" = %d", ret);
500 return ret;
501
David Howells17926a72007-04-26 15:48:28 -0700502wait_interrupted:
503 ret = sock_intr_errno(timeo);
504wait_error:
Eric Dumazet4a4771a2010-04-25 22:20:06 +0000505 finish_wait(sk_sleep(&rx->sk), &wait);
David Howells248f2192016-09-08 11:10:12 +0100506 release_sock(&rx->sk);
507 _leave(" = %d [wait]", ret);
David Howellsd0016482016-08-30 20:42:14 +0100508 return ret;
509}
David Howells651350d2007-04-26 15:50:17 -0700510
511/**
David Howellsd0016482016-08-30 20:42:14 +0100512 * rxrpc_kernel_recv_data - Allow a kernel service to receive data/info
513 * @sock: The socket that the call exists on
514 * @call: The call to send data through
515 * @buf: The buffer to receive into
516 * @size: The size of the buffer, including data already read
517 * @_offset: The running offset into the buffer.
518 * @want_more: True if more data is expected to be read
519 * @_abort: Where the abort code is stored if -ECONNABORTED is returned
David Howells651350d2007-04-26 15:50:17 -0700520 *
David Howellsd0016482016-08-30 20:42:14 +0100521 * Allow a kernel service to receive data and pick up information about the
522 * state of a call. Returns 0 if got what was asked for and there's more
523 * available, 1 if we got what was asked for and we're at the end of the data
524 * and -EAGAIN if we need more data.
525 *
526 * Note that we may return -EAGAIN to drain empty packets at the end of the
527 * data, even if we've already copied over the requested data.
528 *
529 * This function adds the amount it transfers to *_offset, so this should be
530 * precleared as appropriate. Note that the amount remaining in the buffer is
531 * taken to be size - *_offset.
532 *
533 * *_abort should also be initialised to 0.
David Howells651350d2007-04-26 15:50:17 -0700534 */
David Howellsd0016482016-08-30 20:42:14 +0100535int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
536 void *buf, size_t size, size_t *_offset,
537 bool want_more, u32 *_abort)
David Howells651350d2007-04-26 15:50:17 -0700538{
David Howellsd0016482016-08-30 20:42:14 +0100539 struct iov_iter iter;
540 struct kvec iov;
541 int ret;
David Howells651350d2007-04-26 15:50:17 -0700542
David Howells248f2192016-09-08 11:10:12 +0100543 _enter("{%d,%s},%zu/%zu,%d",
544 call->debug_id, rxrpc_call_states[call->state],
545 *_offset, size, want_more);
David Howellsd0016482016-08-30 20:42:14 +0100546
547 ASSERTCMP(*_offset, <=, size);
548 ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_ACCEPTING);
549
550 iov.iov_base = buf + *_offset;
551 iov.iov_len = size - *_offset;
552 iov_iter_kvec(&iter, ITER_KVEC | READ, &iov, 1, size - *_offset);
553
554 lock_sock(sock->sk);
555
556 switch (call->state) {
557 case RXRPC_CALL_CLIENT_RECV_REPLY:
558 case RXRPC_CALL_SERVER_RECV_REQUEST:
559 case RXRPC_CALL_SERVER_ACK_REQUEST:
David Howells248f2192016-09-08 11:10:12 +0100560 ret = rxrpc_recvmsg_data(sock, call, NULL, &iter, size, 0,
561 _offset);
David Howellsd0016482016-08-30 20:42:14 +0100562 if (ret < 0)
563 goto out;
564
565 /* We can only reach here with a partially full buffer if we
566 * have reached the end of the data. We must otherwise have a
567 * full buffer or have been given -EAGAIN.
568 */
569 if (ret == 1) {
570 if (*_offset < size)
571 goto short_data;
572 if (!want_more)
573 goto read_phase_complete;
574 ret = 0;
575 goto out;
576 }
577
578 if (!want_more)
579 goto excess_data;
580 goto out;
581
582 case RXRPC_CALL_COMPLETE:
583 goto call_complete;
584
585 default:
David Howellsd0016482016-08-30 20:42:14 +0100586 ret = -EINPROGRESS;
587 goto out;
588 }
589
590read_phase_complete:
591 ret = 1;
592out:
593 release_sock(sock->sk);
594 _leave(" = %d [%zu,%d]", ret, *_offset, *_abort);
595 return ret;
596
597short_data:
598 ret = -EBADMSG;
599 goto out;
600excess_data:
601 ret = -EMSGSIZE;
602 goto out;
603call_complete:
604 *_abort = call->abort_code;
605 ret = call->error;
606 if (call->completion == RXRPC_CALL_SUCCEEDED) {
607 ret = 1;
608 if (size > 0)
609 ret = -ECONNRESET;
610 }
611 goto out;
David Howells651350d2007-04-26 15:50:17 -0700612}
David Howellsd0016482016-08-30 20:42:14 +0100613EXPORT_SYMBOL(rxrpc_kernel_recv_data);