blob: a284205b8ecf9b1fc5ae57cd9428786d57a31393 [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
David Howells3432a752016-09-13 09:05:14 +0100121 rxrpc_get_call(call, rxrpc_call_got);
David Howells248f2192016-09-08 11:10:12 +0100122 write_lock(&rx->call_lock);
123 list_add_tail(&call->accept_link, &rx->to_be_accepted);
124 write_unlock(&rx->call_lock);
125 }
126
127 return ret;
128}
129
130/*
131 * End the packet reception phase.
132 */
133static void rxrpc_end_rx_phase(struct rxrpc_call *call)
134{
135 _enter("%d,%s", call->debug_id, rxrpc_call_states[call->state]);
136
137 if (call->state == RXRPC_CALL_CLIENT_RECV_REPLY) {
138 rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, true, false);
139 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
140 } else {
141 rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, false, false);
142 }
143
144 write_lock_bh(&call->state_lock);
145
146 switch (call->state) {
147 case RXRPC_CALL_CLIENT_RECV_REPLY:
148 __rxrpc_call_completed(call);
149 break;
150
151 case RXRPC_CALL_SERVER_RECV_REQUEST:
152 call->state = RXRPC_CALL_SERVER_ACK_REQUEST;
153 break;
154 default:
155 break;
156 }
157
158 write_unlock_bh(&call->state_lock);
159}
160
161/*
162 * Discard a packet we've used up and advance the Rx window by one.
163 */
164static void rxrpc_rotate_rx_window(struct rxrpc_call *call)
165{
166 struct sk_buff *skb;
167 rxrpc_seq_t hard_ack, top;
168 int ix;
169
170 _enter("%d", call->debug_id);
171
172 hard_ack = call->rx_hard_ack;
173 top = smp_load_acquire(&call->rx_top);
174 ASSERT(before(hard_ack, top));
175
176 hard_ack++;
177 ix = hard_ack & RXRPC_RXTX_BUFF_MASK;
178 skb = call->rxtx_buffer[ix];
179 rxrpc_see_skb(skb);
180 call->rxtx_buffer[ix] = NULL;
181 call->rxtx_annotations[ix] = 0;
182 /* Barrier against rxrpc_input_data(). */
183 smp_store_release(&call->rx_hard_ack, hard_ack);
184
185 rxrpc_free_skb(skb);
186
187 _debug("%u,%u,%lx", hard_ack, top, call->flags);
188 if (hard_ack == top && test_bit(RXRPC_CALL_RX_LAST, &call->flags))
189 rxrpc_end_rx_phase(call);
190}
191
192/*
193 * Decrypt and verify a (sub)packet. The packet's length may be changed due to
194 * padding, but if this is the case, the packet length will be resident in the
195 * socket buffer. Note that we can't modify the master skb info as the skb may
196 * be the home to multiple subpackets.
197 */
198static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
199 u8 annotation,
200 unsigned int offset, unsigned int len)
201{
202 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
203 rxrpc_seq_t seq = sp->hdr.seq;
204 u16 cksum = sp->hdr.cksum;
205
206 _enter("");
207
208 /* For all but the head jumbo subpacket, the security checksum is in a
209 * jumbo header immediately prior to the data.
210 */
211 if ((annotation & RXRPC_RX_ANNO_JUMBO) > 1) {
212 __be16 tmp;
213 if (skb_copy_bits(skb, offset - 2, &tmp, 2) < 0)
214 BUG();
215 cksum = ntohs(tmp);
216 seq += (annotation & RXRPC_RX_ANNO_JUMBO) - 1;
217 }
218
219 return call->conn->security->verify_packet(call, skb, offset, len,
220 seq, cksum);
221}
222
223/*
224 * Locate the data within a packet. This is complicated by:
225 *
226 * (1) An skb may contain a jumbo packet - so we have to find the appropriate
227 * subpacket.
228 *
229 * (2) The (sub)packets may be encrypted and, if so, the encrypted portion
230 * contains an extra header which includes the true length of the data,
231 * excluding any encrypted padding.
232 */
233static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
234 u8 *_annotation,
235 unsigned int *_offset, unsigned int *_len)
236{
237 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
238 unsigned int offset = *_offset;
239 unsigned int len = *_len;
240 int ret;
241 u8 annotation = *_annotation;
242
243 if (offset > 0)
244 return 0;
245
246 /* Locate the subpacket */
247 offset = sp->offset;
248 len = skb->len - sp->offset;
249 if ((annotation & RXRPC_RX_ANNO_JUMBO) > 0) {
250 offset += (((annotation & RXRPC_RX_ANNO_JUMBO) - 1) *
251 RXRPC_JUMBO_SUBPKTLEN);
252 len = (annotation & RXRPC_RX_ANNO_JLAST) ?
253 skb->len - offset : RXRPC_JUMBO_SUBPKTLEN;
254 }
255
256 if (!(annotation & RXRPC_RX_ANNO_VERIFIED)) {
257 ret = rxrpc_verify_packet(call, skb, annotation, offset, len);
258 if (ret < 0)
259 return ret;
260 *_annotation |= RXRPC_RX_ANNO_VERIFIED;
261 }
262
263 *_offset = offset;
264 *_len = len;
265 call->conn->security->locate_data(call, skb, _offset, _len);
266 return 0;
267}
268
269/*
270 * Deliver messages to a call. This keeps processing packets until the buffer
271 * is filled and we find either more DATA (returns 0) or the end of the DATA
272 * (returns 1). If more packets are required, it returns -EAGAIN.
273 */
274static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
275 struct msghdr *msg, struct iov_iter *iter,
276 size_t len, int flags, size_t *_offset)
277{
278 struct rxrpc_skb_priv *sp;
279 struct sk_buff *skb;
280 rxrpc_seq_t hard_ack, top, seq;
281 size_t remain;
282 bool last;
283 unsigned int rx_pkt_offset, rx_pkt_len;
284 int ix, copy, ret = 0;
285
286 _enter("");
287
288 rx_pkt_offset = call->rx_pkt_offset;
289 rx_pkt_len = call->rx_pkt_len;
290
291 /* Barriers against rxrpc_input_data(). */
292 hard_ack = call->rx_hard_ack;
293 top = smp_load_acquire(&call->rx_top);
294 for (seq = hard_ack + 1; before_eq(seq, top); seq++) {
295 ix = seq & RXRPC_RXTX_BUFF_MASK;
296 skb = call->rxtx_buffer[ix];
297 if (!skb)
298 break;
299 smp_rmb();
300 rxrpc_see_skb(skb);
301 sp = rxrpc_skb(skb);
302
303 if (msg)
304 sock_recv_timestamp(msg, sock->sk, skb);
305
306 ret = rxrpc_locate_data(call, skb, &call->rxtx_annotations[ix],
307 &rx_pkt_offset, &rx_pkt_len);
308 _debug("recvmsg %x DATA #%u { %d, %d }",
309 sp->hdr.callNumber, seq, rx_pkt_offset, rx_pkt_len);
310
311 /* We have to handle short, empty and used-up DATA packets. */
312 remain = len - *_offset;
313 copy = rx_pkt_len;
314 if (copy > remain)
315 copy = remain;
316 if (copy > 0) {
317 ret = skb_copy_datagram_iter(skb, rx_pkt_offset, iter,
318 copy);
319 if (ret < 0)
320 goto out;
321
322 /* handle piecemeal consumption of data packets */
323 _debug("copied %d @%zu", copy, *_offset);
324
325 rx_pkt_offset += copy;
326 rx_pkt_len -= copy;
327 *_offset += copy;
328 }
329
330 if (rx_pkt_len > 0) {
331 _debug("buffer full");
332 ASSERTCMP(*_offset, ==, len);
333 break;
334 }
335
336 /* The whole packet has been transferred. */
337 last = sp->hdr.flags & RXRPC_LAST_PACKET;
338 if (!(flags & MSG_PEEK))
339 rxrpc_rotate_rx_window(call);
340 rx_pkt_offset = 0;
341 rx_pkt_len = 0;
342
343 ASSERTIFCMP(last, seq, ==, top);
344 }
345
346 if (after(seq, top)) {
347 ret = -EAGAIN;
348 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags))
349 ret = 1;
350 }
351out:
352 if (!(flags & MSG_PEEK)) {
353 call->rx_pkt_offset = rx_pkt_offset;
354 call->rx_pkt_len = rx_pkt_len;
355 }
356 _leave(" = %d [%u/%u]", ret, seq, top);
357 return ret;
358}
359
360/*
361 * Receive a message from an RxRPC socket
David Howells17926a72007-04-26 15:48:28 -0700362 * - we need to be careful about two or more threads calling recvmsg
363 * simultaneously
364 */
Ying Xue1b784142015-03-02 15:37:48 +0800365int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
366 int flags)
David Howells17926a72007-04-26 15:48:28 -0700367{
David Howells248f2192016-09-08 11:10:12 +0100368 struct rxrpc_call *call;
David Howells17926a72007-04-26 15:48:28 -0700369 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
David Howells248f2192016-09-08 11:10:12 +0100370 struct list_head *l;
371 size_t copied = 0;
David Howells17926a72007-04-26 15:48:28 -0700372 long timeo;
David Howells248f2192016-09-08 11:10:12 +0100373 int ret;
David Howells17926a72007-04-26 15:48:28 -0700374
375 DEFINE_WAIT(wait);
376
377 _enter(",,,%zu,%d", len, flags);
378
379 if (flags & (MSG_OOB | MSG_TRUNC))
380 return -EOPNOTSUPP;
381
David Howells17926a72007-04-26 15:48:28 -0700382 timeo = sock_rcvtimeo(&rx->sk, flags & MSG_DONTWAIT);
David Howells17926a72007-04-26 15:48:28 -0700383
David Howells248f2192016-09-08 11:10:12 +0100384try_again:
David Howells17926a72007-04-26 15:48:28 -0700385 lock_sock(&rx->sk);
386
David Howells248f2192016-09-08 11:10:12 +0100387 /* Return immediately if a client socket has no outstanding calls */
388 if (RB_EMPTY_ROOT(&rx->calls) &&
389 list_empty(&rx->recvmsg_q) &&
390 rx->sk.sk_state != RXRPC_SERVER_LISTENING) {
391 release_sock(&rx->sk);
392 return -ENODATA;
393 }
394
395 if (list_empty(&rx->recvmsg_q)) {
396 ret = -EWOULDBLOCK;
397 if (timeo == 0)
398 goto error_no_call;
399
400 release_sock(&rx->sk);
401
402 /* Wait for something to happen */
403 prepare_to_wait_exclusive(sk_sleep(&rx->sk), &wait,
404 TASK_INTERRUPTIBLE);
405 ret = sock_error(&rx->sk);
406 if (ret)
407 goto wait_error;
408
409 if (list_empty(&rx->recvmsg_q)) {
410 if (signal_pending(current))
411 goto wait_interrupted;
412 timeo = schedule_timeout(timeo);
David Howells17926a72007-04-26 15:48:28 -0700413 }
David Howells248f2192016-09-08 11:10:12 +0100414 finish_wait(sk_sleep(&rx->sk), &wait);
415 goto try_again;
416 }
David Howells17926a72007-04-26 15:48:28 -0700417
David Howells248f2192016-09-08 11:10:12 +0100418 /* Find the next call and dequeue it if we're not just peeking. If we
419 * do dequeue it, that comes with a ref that we will need to release.
420 */
421 write_lock_bh(&rx->recvmsg_lock);
422 l = rx->recvmsg_q.next;
423 call = list_entry(l, struct rxrpc_call, recvmsg_link);
424 if (!(flags & MSG_PEEK))
425 list_del_init(&call->recvmsg_link);
426 else
David Howellsfff724292016-09-07 14:34:21 +0100427 rxrpc_get_call(call, rxrpc_call_got);
David Howells248f2192016-09-08 11:10:12 +0100428 write_unlock_bh(&rx->recvmsg_lock);
David Howells17926a72007-04-26 15:48:28 -0700429
David Howells248f2192016-09-08 11:10:12 +0100430 _debug("recvmsg call %p", call);
David Howells17926a72007-04-26 15:48:28 -0700431
David Howells248f2192016-09-08 11:10:12 +0100432 if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
David Howells17926a72007-04-26 15:48:28 -0700433 BUG();
David Howells248f2192016-09-08 11:10:12 +0100434
435 if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
436 if (flags & MSG_CMSG_COMPAT) {
437 unsigned int id32 = call->user_call_ID;
438
439 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
440 sizeof(unsigned int), &id32);
441 } else {
442 ret = put_cmsg(msg, SOL_RXRPC, RXRPC_USER_CALL_ID,
443 sizeof(unsigned long),
444 &call->user_call_ID);
David Howellsf5c17aa2016-08-30 09:49:28 +0100445 }
David Howells248f2192016-09-08 11:10:12 +0100446 if (ret < 0)
447 goto error;
448 }
449
450 if (msg->msg_name) {
451 size_t len = sizeof(call->conn->params.peer->srx);
452 memcpy(msg->msg_name, &call->conn->params.peer->srx, len);
453 msg->msg_namelen = len;
454 }
455
456 switch (call->state) {
457 case RXRPC_CALL_SERVER_ACCEPTING:
458 ret = rxrpc_recvmsg_new_call(rx, call, msg, flags);
David Howells17926a72007-04-26 15:48:28 -0700459 break;
David Howells248f2192016-09-08 11:10:12 +0100460 case RXRPC_CALL_CLIENT_RECV_REPLY:
461 case RXRPC_CALL_SERVER_RECV_REQUEST:
462 case RXRPC_CALL_SERVER_ACK_REQUEST:
463 ret = rxrpc_recvmsg_data(sock, call, msg, &msg->msg_iter, len,
464 flags, &copied);
465 if (ret == -EAGAIN)
466 ret = 0;
David Howells33b603f2016-09-13 22:36:21 +0100467
468 if (after(call->rx_top, call->rx_hard_ack) &&
469 call->rxtx_buffer[(call->rx_hard_ack + 1) & RXRPC_RXTX_BUFF_MASK])
470 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700471 break;
472 default:
David Howells248f2192016-09-08 11:10:12 +0100473 ret = 0;
David Howells17926a72007-04-26 15:48:28 -0700474 break;
475 }
476
477 if (ret < 0)
David Howells248f2192016-09-08 11:10:12 +0100478 goto error;
David Howells17926a72007-04-26 15:48:28 -0700479
David Howells248f2192016-09-08 11:10:12 +0100480 if (call->state == RXRPC_CALL_COMPLETE) {
481 ret = rxrpc_recvmsg_term(call, msg);
482 if (ret < 0)
483 goto error;
484 if (!(flags & MSG_PEEK))
485 rxrpc_release_call(rx, call);
486 msg->msg_flags |= MSG_EOR;
487 ret = 1;
David Howells17926a72007-04-26 15:48:28 -0700488 }
489
David Howells248f2192016-09-08 11:10:12 +0100490 if (ret == 0)
491 msg->msg_flags |= MSG_MORE;
492 else
493 msg->msg_flags &= ~MSG_MORE;
494 ret = copied;
David Howells17926a72007-04-26 15:48:28 -0700495
David Howells248f2192016-09-08 11:10:12 +0100496error:
David Howellsfff724292016-09-07 14:34:21 +0100497 rxrpc_put_call(call, rxrpc_call_put);
David Howells248f2192016-09-08 11:10:12 +0100498error_no_call:
499 release_sock(&rx->sk);
David Howells17926a72007-04-26 15:48:28 -0700500 _leave(" = %d", ret);
501 return ret;
502
David Howells17926a72007-04-26 15:48:28 -0700503wait_interrupted:
504 ret = sock_intr_errno(timeo);
505wait_error:
Eric Dumazet4a4771a2010-04-25 22:20:06 +0000506 finish_wait(sk_sleep(&rx->sk), &wait);
David Howells248f2192016-09-08 11:10:12 +0100507 release_sock(&rx->sk);
508 _leave(" = %d [wait]", ret);
David Howellsd0016482016-08-30 20:42:14 +0100509 return ret;
510}
David Howells651350d2007-04-26 15:50:17 -0700511
512/**
David Howellsd0016482016-08-30 20:42:14 +0100513 * rxrpc_kernel_recv_data - Allow a kernel service to receive data/info
514 * @sock: The socket that the call exists on
515 * @call: The call to send data through
516 * @buf: The buffer to receive into
517 * @size: The size of the buffer, including data already read
518 * @_offset: The running offset into the buffer.
519 * @want_more: True if more data is expected to be read
520 * @_abort: Where the abort code is stored if -ECONNABORTED is returned
David Howells651350d2007-04-26 15:50:17 -0700521 *
David Howellsd0016482016-08-30 20:42:14 +0100522 * Allow a kernel service to receive data and pick up information about the
523 * state of a call. Returns 0 if got what was asked for and there's more
524 * available, 1 if we got what was asked for and we're at the end of the data
525 * and -EAGAIN if we need more data.
526 *
527 * Note that we may return -EAGAIN to drain empty packets at the end of the
528 * data, even if we've already copied over the requested data.
529 *
530 * This function adds the amount it transfers to *_offset, so this should be
531 * precleared as appropriate. Note that the amount remaining in the buffer is
532 * taken to be size - *_offset.
533 *
534 * *_abort should also be initialised to 0.
David Howells651350d2007-04-26 15:50:17 -0700535 */
David Howellsd0016482016-08-30 20:42:14 +0100536int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
537 void *buf, size_t size, size_t *_offset,
538 bool want_more, u32 *_abort)
David Howells651350d2007-04-26 15:50:17 -0700539{
David Howellsd0016482016-08-30 20:42:14 +0100540 struct iov_iter iter;
541 struct kvec iov;
542 int ret;
David Howells651350d2007-04-26 15:50:17 -0700543
David Howells248f2192016-09-08 11:10:12 +0100544 _enter("{%d,%s},%zu/%zu,%d",
545 call->debug_id, rxrpc_call_states[call->state],
546 *_offset, size, want_more);
David Howellsd0016482016-08-30 20:42:14 +0100547
548 ASSERTCMP(*_offset, <=, size);
549 ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_ACCEPTING);
550
551 iov.iov_base = buf + *_offset;
552 iov.iov_len = size - *_offset;
553 iov_iter_kvec(&iter, ITER_KVEC | READ, &iov, 1, size - *_offset);
554
555 lock_sock(sock->sk);
556
557 switch (call->state) {
558 case RXRPC_CALL_CLIENT_RECV_REPLY:
559 case RXRPC_CALL_SERVER_RECV_REQUEST:
560 case RXRPC_CALL_SERVER_ACK_REQUEST:
David Howells248f2192016-09-08 11:10:12 +0100561 ret = rxrpc_recvmsg_data(sock, call, NULL, &iter, size, 0,
562 _offset);
David Howellsd0016482016-08-30 20:42:14 +0100563 if (ret < 0)
564 goto out;
565
566 /* We can only reach here with a partially full buffer if we
567 * have reached the end of the data. We must otherwise have a
568 * full buffer or have been given -EAGAIN.
569 */
570 if (ret == 1) {
571 if (*_offset < size)
572 goto short_data;
573 if (!want_more)
574 goto read_phase_complete;
575 ret = 0;
576 goto out;
577 }
578
579 if (!want_more)
580 goto excess_data;
581 goto out;
582
583 case RXRPC_CALL_COMPLETE:
584 goto call_complete;
585
586 default:
David Howellsd0016482016-08-30 20:42:14 +0100587 ret = -EINPROGRESS;
588 goto out;
589 }
590
591read_phase_complete:
592 ret = 1;
593out:
594 release_sock(sock->sk);
595 _leave(" = %d [%zu,%d]", ret, *_offset, *_abort);
596 return ret;
597
598short_data:
599 ret = -EBADMSG;
600 goto out;
601excess_data:
602 ret = -EMSGSIZE;
603 goto out;
604call_complete:
605 *_abort = call->abort_code;
606 ret = call->error;
607 if (call->completion == RXRPC_CALL_SUCCEEDED) {
608 ret = 1;
609 if (size > 0)
610 ret = -ECONNRESET;
611 }
612 goto out;
David Howells651350d2007-04-26 15:50:17 -0700613}
David Howellsd0016482016-08-30 20:42:14 +0100614EXPORT_SYMBOL(rxrpc_kernel_recv_data);