blob: 0fcf157aa09f8350b156234693b700ac3a89dbcf [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells0b58b8a2016-09-02 22:39:45 +01002/* AF_RXRPC sendmsg() implementation.
3 *
4 * Copyright (C) 2007, 2016 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howells0b58b8a2016-09-02 22:39:45 +01006 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/net.h>
11#include <linux/gfp.h>
12#include <linux/skbuff.h>
13#include <linux/export.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010014#include <linux/sched/signal.h>
15
David Howells0b58b8a2016-09-02 22:39:45 +010016#include <net/sock.h>
17#include <net/af_rxrpc.h>
18#include "ar-internal.h"
19
David Howells0b58b8a2016-09-02 22:39:45 +010020/*
David Howells158fe662020-03-13 09:05:38 +000021 * Return true if there's sufficient Tx queue space.
22 */
23static bool rxrpc_check_tx_space(struct rxrpc_call *call, rxrpc_seq_t *_tx_win)
24{
25 unsigned int win_size =
26 min_t(unsigned int, call->tx_winsize,
27 call->cong_cwnd + call->cong_extra);
28 rxrpc_seq_t tx_win = READ_ONCE(call->tx_hard_ack);
29
30 if (_tx_win)
31 *_tx_win = tx_win;
32 return call->tx_top - tx_win < win_size;
33}
34
35/*
David Howellsbc5e3a52017-10-18 11:07:31 +010036 * Wait for space to appear in the Tx queue or a signal to occur.
37 */
38static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx,
39 struct rxrpc_call *call,
40 long *timeo)
41{
42 for (;;) {
43 set_current_state(TASK_INTERRUPTIBLE);
David Howells158fe662020-03-13 09:05:38 +000044 if (rxrpc_check_tx_space(call, NULL))
David Howellsbc5e3a52017-10-18 11:07:31 +010045 return 0;
46
47 if (call->state >= RXRPC_CALL_COMPLETE)
48 return call->error;
49
50 if (signal_pending(current))
51 return sock_intr_errno(*timeo);
52
53 trace_rxrpc_transmit(call, rxrpc_transmit_wait);
54 mutex_unlock(&call->user_mutex);
55 *timeo = schedule_timeout(*timeo);
56 if (mutex_lock_interruptible(&call->user_mutex) < 0)
57 return sock_intr_errno(*timeo);
58 }
59}
60
61/*
62 * Wait for space to appear in the Tx queue uninterruptibly, but with
63 * a timeout of 2*RTT if no progress was made and a signal occurred.
64 */
David Howellse138aa72020-03-13 09:22:09 +000065static int rxrpc_wait_for_tx_window_waitall(struct rxrpc_sock *rx,
David Howellsbc5e3a52017-10-18 11:07:31 +010066 struct rxrpc_call *call)
67{
68 rxrpc_seq_t tx_start, tx_win;
69 signed long rtt2, timeout;
70 u64 rtt;
71
72 rtt = READ_ONCE(call->peer->rtt);
73 rtt2 = nsecs_to_jiffies64(rtt) * 2;
David Howells498b5772020-03-13 17:30:27 +000074 if (rtt2 < 2)
75 rtt2 = 2;
David Howellsbc5e3a52017-10-18 11:07:31 +010076
77 timeout = rtt2;
78 tx_start = READ_ONCE(call->tx_hard_ack);
79
80 for (;;) {
81 set_current_state(TASK_UNINTERRUPTIBLE);
82
83 tx_win = READ_ONCE(call->tx_hard_ack);
David Howells158fe662020-03-13 09:05:38 +000084 if (rxrpc_check_tx_space(call, &tx_win))
David Howellsbc5e3a52017-10-18 11:07:31 +010085 return 0;
86
87 if (call->state >= RXRPC_CALL_COMPLETE)
88 return call->error;
89
David Howellse138aa72020-03-13 09:22:09 +000090 if (timeout == 0 &&
David Howellsbc5e3a52017-10-18 11:07:31 +010091 tx_win == tx_start && signal_pending(current))
92 return -EINTR;
93
94 if (tx_win != tx_start) {
95 timeout = rtt2;
96 tx_start = tx_win;
97 }
98
99 trace_rxrpc_transmit(call, rxrpc_transmit_wait);
100 timeout = schedule_timeout(timeout);
101 }
102}
103
104/*
David Howellse138aa72020-03-13 09:22:09 +0000105 * Wait for space to appear in the Tx queue uninterruptibly.
106 */
107static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
108 struct rxrpc_call *call,
109 long *timeo)
110{
111 for (;;) {
112 set_current_state(TASK_UNINTERRUPTIBLE);
113 if (rxrpc_check_tx_space(call, NULL))
114 return 0;
115
116 if (call->state >= RXRPC_CALL_COMPLETE)
117 return call->error;
118
119 trace_rxrpc_transmit(call, rxrpc_transmit_wait);
120 *timeo = schedule_timeout(*timeo);
121 }
122}
123
124/*
David Howells0b58b8a2016-09-02 22:39:45 +0100125 * wait for space to appear in the transmit/ACK window
126 * - caller holds the socket locked
127 */
128static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
129 struct rxrpc_call *call,
David Howellsbc5e3a52017-10-18 11:07:31 +0100130 long *timeo,
131 bool waitall)
David Howells0b58b8a2016-09-02 22:39:45 +0100132{
133 DECLARE_WAITQUEUE(myself, current);
134 int ret;
135
David Howells248f2192016-09-08 11:10:12 +0100136 _enter(",{%u,%u,%u}",
137 call->tx_hard_ack, call->tx_top, call->tx_winsize);
David Howells0b58b8a2016-09-02 22:39:45 +0100138
139 add_wait_queue(&call->waitq, &myself);
140
David Howellse138aa72020-03-13 09:22:09 +0000141 switch (call->interruptibility) {
142 case RXRPC_INTERRUPTIBLE:
143 if (waitall)
144 ret = rxrpc_wait_for_tx_window_waitall(rx, call);
145 else
146 ret = rxrpc_wait_for_tx_window_intr(rx, call, timeo);
147 break;
148 case RXRPC_PREINTERRUPTIBLE:
149 case RXRPC_UNINTERRUPTIBLE:
150 default:
151 ret = rxrpc_wait_for_tx_window_nonintr(rx, call, timeo);
152 break;
153 }
David Howells0b58b8a2016-09-02 22:39:45 +0100154
155 remove_wait_queue(&call->waitq, &myself);
156 set_current_state(TASK_RUNNING);
157 _leave(" = %d", ret);
158 return ret;
159}
160
161/*
David Howells248f2192016-09-08 11:10:12 +0100162 * Schedule an instant Tx resend.
David Howells0b58b8a2016-09-02 22:39:45 +0100163 */
David Howells248f2192016-09-08 11:10:12 +0100164static inline void rxrpc_instant_resend(struct rxrpc_call *call, int ix)
David Howells0b58b8a2016-09-02 22:39:45 +0100165{
David Howells248f2192016-09-08 11:10:12 +0100166 spin_lock_bh(&call->lock);
167
168 if (call->state < RXRPC_CALL_COMPLETE) {
David Howells03877bf2018-03-30 21:04:43 +0100169 call->rxtx_annotations[ix] =
170 (call->rxtx_annotations[ix] & RXRPC_TX_ANNO_LAST) |
171 RXRPC_TX_ANNO_RETRANS;
David Howells248f2192016-09-08 11:10:12 +0100172 if (!test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
David Howells0b58b8a2016-09-02 22:39:45 +0100173 rxrpc_queue_call(call);
174 }
David Howells248f2192016-09-08 11:10:12 +0100175
176 spin_unlock_bh(&call->lock);
David Howells0b58b8a2016-09-02 22:39:45 +0100177}
178
179/*
David Howellse8332512017-08-29 10:18:56 +0100180 * Notify the owner of the call that the transmit phase is ended and the last
181 * packet has been queued.
182 */
183static void rxrpc_notify_end_tx(struct rxrpc_sock *rx, struct rxrpc_call *call,
184 rxrpc_notify_end_tx_t notify_end_tx)
185{
186 if (notify_end_tx)
187 notify_end_tx(&rx->sk, call, call->user_call_ID);
188}
189
190/*
Marc Dionne8e8715a2019-04-12 16:33:54 +0100191 * Queue a DATA packet for transmission, set the resend timeout and send
192 * the packet immediately. Returns the error from rxrpc_send_data_packet()
193 * in case the caller wants to do something with it.
David Howells0b58b8a2016-09-02 22:39:45 +0100194 */
Marc Dionne8e8715a2019-04-12 16:33:54 +0100195static int rxrpc_queue_packet(struct rxrpc_sock *rx, struct rxrpc_call *call,
196 struct sk_buff *skb, bool last,
197 rxrpc_notify_end_tx_t notify_end_tx)
David Howells0b58b8a2016-09-02 22:39:45 +0100198{
199 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howellsa158bdd2017-11-24 10:18:41 +0000200 unsigned long now;
David Howells248f2192016-09-08 11:10:12 +0100201 rxrpc_seq_t seq = sp->hdr.seq;
202 int ret, ix;
David Howells70790dbe2016-09-23 12:39:22 +0100203 u8 annotation = RXRPC_TX_ANNO_UNACK;
David Howells0b58b8a2016-09-02 22:39:45 +0100204
David Howells248f2192016-09-08 11:10:12 +0100205 _net("queue skb %p [%d]", skb, seq);
David Howells0b58b8a2016-09-02 22:39:45 +0100206
David Howells248f2192016-09-08 11:10:12 +0100207 ASSERTCMP(seq, ==, call->tx_top + 1);
208
David Howellse122d842019-01-10 16:59:13 +0000209 if (last)
David Howells70790dbe2016-09-23 12:39:22 +0100210 annotation |= RXRPC_TX_ANNO_LAST;
211
David Howellsb24d2892016-09-23 13:17:33 +0100212 /* We have to set the timestamp before queueing as the retransmit
213 * algorithm can see the packet as soon as we queue it.
214 */
215 skb->tstamp = ktime_get_real();
216
David Howells248f2192016-09-08 11:10:12 +0100217 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howells987db9f2019-08-19 09:25:38 +0100218 rxrpc_get_skb(skb, rxrpc_skb_got);
David Howells70790dbe2016-09-23 12:39:22 +0100219 call->rxtx_annotations[ix] = annotation;
David Howells0b58b8a2016-09-02 22:39:45 +0100220 smp_wmb();
David Howells248f2192016-09-08 11:10:12 +0100221 call->rxtx_buffer[ix] = skb;
222 call->tx_top = seq;
David Howells70790dbe2016-09-23 12:39:22 +0100223 if (last)
David Howellsa124fe32016-09-17 10:49:13 +0100224 trace_rxrpc_transmit(call, rxrpc_transmit_queue_last);
David Howells70790dbe2016-09-23 12:39:22 +0100225 else
David Howellsa124fe32016-09-17 10:49:13 +0100226 trace_rxrpc_transmit(call, rxrpc_transmit_queue);
David Howells0b58b8a2016-09-02 22:39:45 +0100227
228 if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) {
229 _debug("________awaiting reply/ACK__________");
230 write_lock_bh(&call->state_lock);
231 switch (call->state) {
232 case RXRPC_CALL_CLIENT_SEND_REQUEST:
233 call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
David Howellse8332512017-08-29 10:18:56 +0100234 rxrpc_notify_end_tx(rx, call, notify_end_tx);
David Howells0b58b8a2016-09-02 22:39:45 +0100235 break;
236 case RXRPC_CALL_SERVER_ACK_REQUEST:
237 call->state = RXRPC_CALL_SERVER_SEND_REPLY;
David Howellsa158bdd2017-11-24 10:18:41 +0000238 now = jiffies;
239 WRITE_ONCE(call->ack_at, now + MAX_JIFFY_OFFSET);
David Howells9749fd22016-10-06 08:11:50 +0100240 if (call->ackr_reason == RXRPC_ACK_DELAY)
241 call->ackr_reason = 0;
David Howellsa158bdd2017-11-24 10:18:41 +0000242 trace_rxrpc_timer(call, rxrpc_timer_init_for_send_reply, now);
David Howells0b58b8a2016-09-02 22:39:45 +0100243 if (!last)
244 break;
Gustavo A. R. Silvae3cf39702017-10-19 16:54:48 -0500245 /* Fall through */
David Howells0b58b8a2016-09-02 22:39:45 +0100246 case RXRPC_CALL_SERVER_SEND_REPLY:
247 call->state = RXRPC_CALL_SERVER_AWAIT_ACK;
David Howellse8332512017-08-29 10:18:56 +0100248 rxrpc_notify_end_tx(rx, call, notify_end_tx);
David Howells0b58b8a2016-09-02 22:39:45 +0100249 break;
250 default:
251 break;
252 }
253 write_unlock_bh(&call->state_lock);
254 }
255
David Howells248f2192016-09-08 11:10:12 +0100256 if (seq == 1 && rxrpc_is_client_call(call))
257 rxrpc_expose_client_call(call);
258
David Howellsa1767072016-09-29 22:37:15 +0100259 ret = rxrpc_send_data_packet(call, skb, false);
David Howells0b58b8a2016-09-02 22:39:45 +0100260 if (ret < 0) {
David Howellsc54e43d2018-05-10 23:26:00 +0100261 switch (ret) {
262 case -ENETUNREACH:
263 case -EHOSTUNREACH:
264 case -ECONNREFUSED:
265 rxrpc_set_call_completion(call,
266 RXRPC_CALL_LOCAL_ERROR,
267 0, ret);
David Howellsc69565e2019-07-30 14:42:50 +0100268 rxrpc_notify_socket(call);
David Howellsc54e43d2018-05-10 23:26:00 +0100269 goto out;
270 }
David Howells0b58b8a2016-09-02 22:39:45 +0100271 _debug("need instant resend %d", ret);
David Howells248f2192016-09-08 11:10:12 +0100272 rxrpc_instant_resend(call, ix);
David Howellsdfc3da42016-09-23 12:39:23 +0100273 } else {
David Howellsa158bdd2017-11-24 10:18:41 +0000274 unsigned long now = jiffies, resend_at;
David Howellsdfc3da42016-09-23 12:39:23 +0100275
David Howellsbeb8e5e2017-11-24 10:18:41 +0000276 if (call->peer->rtt_usage > 1)
277 resend_at = nsecs_to_jiffies(call->peer->rtt * 3 / 2);
278 else
279 resend_at = rxrpc_resend_timeout;
280 if (resend_at < 1)
281 resend_at = 1;
282
Gustavo A. R. Silva282ef472017-11-28 11:28:52 -0600283 resend_at += now;
David Howellsa158bdd2017-11-24 10:18:41 +0000284 WRITE_ONCE(call->resend_at, resend_at);
285 rxrpc_reduce_call_timer(call, resend_at, now,
286 rxrpc_timer_set_for_send);
David Howells0b58b8a2016-09-02 22:39:45 +0100287 }
288
David Howellsc54e43d2018-05-10 23:26:00 +0100289out:
David Howells987db9f2019-08-19 09:25:38 +0100290 rxrpc_free_skb(skb, rxrpc_skb_freed);
Marc Dionne8e8715a2019-04-12 16:33:54 +0100291 _leave(" = %d", ret);
292 return ret;
David Howells0b58b8a2016-09-02 22:39:45 +0100293}
294
295/*
David Howells0b58b8a2016-09-02 22:39:45 +0100296 * send data through a socket
297 * - must be called in process context
David Howells540b1c42017-02-27 15:43:06 +0000298 * - The caller holds the call user access mutex, but not the socket lock.
David Howells0b58b8a2016-09-02 22:39:45 +0100299 */
300static int rxrpc_send_data(struct rxrpc_sock *rx,
301 struct rxrpc_call *call,
David Howellse8332512017-08-29 10:18:56 +0100302 struct msghdr *msg, size_t len,
303 rxrpc_notify_end_tx_t notify_end_tx)
David Howells0b58b8a2016-09-02 22:39:45 +0100304{
305 struct rxrpc_skb_priv *sp;
306 struct sk_buff *skb;
307 struct sock *sk = &rx->sk;
308 long timeo;
309 bool more;
310 int ret, copied;
311
312 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
313
314 /* this should be in poll */
315 sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
316
317 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
318 return -EPIPE;
319
320 more = msg->msg_flags & MSG_MORE;
321
David Howellse754eba2017-06-07 12:40:03 +0100322 if (call->tx_total_len != -1) {
323 if (len > call->tx_total_len)
324 return -EMSGSIZE;
325 if (!more && len != call->tx_total_len)
326 return -EMSGSIZE;
327 }
328
David Howells0b58b8a2016-09-02 22:39:45 +0100329 skb = call->tx_pending;
330 call->tx_pending = NULL;
David Howells987db9f2019-08-19 09:25:38 +0100331 rxrpc_see_skb(skb, rxrpc_skb_seen);
David Howells0b58b8a2016-09-02 22:39:45 +0100332
333 copied = 0;
334 do {
David Howells7aa51da2016-09-22 00:29:31 +0100335 /* Check to see if there's a ping ACK to reply to. */
336 if (call->ackr_reason == RXRPC_ACK_PING_RESPONSE)
David Howellsbd1fdf82017-11-24 10:18:42 +0000337 rxrpc_send_ack_packet(call, false, NULL);
David Howells7aa51da2016-09-22 00:29:31 +0100338
David Howells0b58b8a2016-09-02 22:39:45 +0100339 if (!skb) {
340 size_t size, chunk, max, space;
341
342 _debug("alloc");
343
David Howells158fe662020-03-13 09:05:38 +0000344 if (!rxrpc_check_tx_space(call, NULL)) {
David Howells0b58b8a2016-09-02 22:39:45 +0100345 ret = -EAGAIN;
346 if (msg->msg_flags & MSG_DONTWAIT)
347 goto maybe_error;
348 ret = rxrpc_wait_for_tx_window(rx, call,
David Howellsbc5e3a52017-10-18 11:07:31 +0100349 &timeo,
350 msg->msg_flags & MSG_WAITALL);
David Howells0b58b8a2016-09-02 22:39:45 +0100351 if (ret < 0)
352 goto maybe_error;
353 }
354
David Howells182f5052016-09-17 10:49:12 +0100355 max = RXRPC_JUMBO_DATALEN;
David Howells0b58b8a2016-09-02 22:39:45 +0100356 max -= call->conn->security_size;
357 max &= ~(call->conn->size_align - 1UL);
358
359 chunk = max;
360 if (chunk > msg_data_left(msg) && !more)
361 chunk = msg_data_left(msg);
362
363 space = chunk + call->conn->size_align;
364 space &= ~(call->conn->size_align - 1UL);
365
David Howells5a924b82016-09-22 00:29:31 +0100366 size = space + call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100367
368 _debug("SIZE: %zu/%zu/%zu", chunk, space, size);
369
370 /* create a buffer that we can retain until it's ACK'd */
371 skb = sock_alloc_send_skb(
372 sk, size, msg->msg_flags & MSG_DONTWAIT, &ret);
373 if (!skb)
374 goto maybe_error;
375
David Howellsb311e682019-08-19 09:25:37 +0100376 sp = rxrpc_skb(skb);
377 sp->rx_flags |= RXRPC_SKB_TX_BUFFER;
David Howells987db9f2019-08-19 09:25:38 +0100378 rxrpc_new_skb(skb, rxrpc_skb_new);
David Howells0b58b8a2016-09-02 22:39:45 +0100379
380 _debug("ALLOC SEND %p", skb);
381
382 ASSERTCMP(skb->mark, ==, 0);
383
David Howells5a924b82016-09-22 00:29:31 +0100384 _debug("HS: %u", call->conn->security_size);
385 skb_reserve(skb, call->conn->security_size);
386 skb->len += call->conn->security_size;
David Howells0b58b8a2016-09-02 22:39:45 +0100387
David Howells0b58b8a2016-09-02 22:39:45 +0100388 sp->remain = chunk;
389 if (sp->remain > skb_tailroom(skb))
390 sp->remain = skb_tailroom(skb);
391
392 _net("skb: hr %d, tr %d, hl %d, rm %d",
393 skb_headroom(skb),
394 skb_tailroom(skb),
395 skb_headlen(skb),
396 sp->remain);
397
398 skb->ip_summed = CHECKSUM_UNNECESSARY;
399 }
400
401 _debug("append");
402 sp = rxrpc_skb(skb);
403
404 /* append next segment of data to the current buffer */
405 if (msg_data_left(msg) > 0) {
406 int copy = skb_tailroom(skb);
407 ASSERTCMP(copy, >, 0);
408 if (copy > msg_data_left(msg))
409 copy = msg_data_left(msg);
410 if (copy > sp->remain)
411 copy = sp->remain;
412
413 _debug("add");
414 ret = skb_add_data(skb, &msg->msg_iter, copy);
415 _debug("added");
416 if (ret < 0)
417 goto efault;
418 sp->remain -= copy;
419 skb->mark += copy;
420 copied += copy;
David Howellse754eba2017-06-07 12:40:03 +0100421 if (call->tx_total_len != -1)
422 call->tx_total_len -= copy;
David Howells0b58b8a2016-09-02 22:39:45 +0100423 }
424
David Howellse122d842019-01-10 16:59:13 +0000425 /* check for the far side aborting the call or a network error
426 * occurring */
427 if (call->state == RXRPC_CALL_COMPLETE)
428 goto call_terminated;
429
David Howells0b58b8a2016-09-02 22:39:45 +0100430 /* add the packet to the send queue if it's now full */
431 if (sp->remain <= 0 ||
432 (msg_data_left(msg) == 0 && !more)) {
433 struct rxrpc_connection *conn = call->conn;
434 uint32_t seq;
435 size_t pad;
436
437 /* pad out if we're using security */
438 if (conn->security_ix) {
439 pad = conn->security_size + skb->mark;
440 pad = conn->size_align - pad;
441 pad &= conn->size_align - 1;
442 _debug("pad %zu", pad);
443 if (pad)
Johannes Bergb080db52017-06-16 14:29:19 +0200444 skb_put_zero(skb, pad);
David Howells0b58b8a2016-09-02 22:39:45 +0100445 }
446
David Howells248f2192016-09-08 11:10:12 +0100447 seq = call->tx_top + 1;
David Howells0b58b8a2016-09-02 22:39:45 +0100448
David Howells0b58b8a2016-09-02 22:39:45 +0100449 sp->hdr.seq = seq;
David Howells0b58b8a2016-09-02 22:39:45 +0100450 sp->hdr._rsvd = 0;
David Howells5a924b82016-09-22 00:29:31 +0100451 sp->hdr.flags = conn->out_clientflag;
David Howells0b58b8a2016-09-02 22:39:45 +0100452
David Howells0b58b8a2016-09-02 22:39:45 +0100453 if (msg_data_left(msg) == 0 && !more)
454 sp->hdr.flags |= RXRPC_LAST_PACKET;
David Howells248f2192016-09-08 11:10:12 +0100455 else if (call->tx_top - call->tx_hard_ack <
456 call->tx_winsize)
David Howells0b58b8a2016-09-02 22:39:45 +0100457 sp->hdr.flags |= RXRPC_MORE_PACKETS;
David Howells0b58b8a2016-09-02 22:39:45 +0100458
David Howells91fcfbe2019-10-07 10:58:29 +0100459 ret = call->security->secure_packet(
David Howells5a924b82016-09-22 00:29:31 +0100460 call, skb, skb->mark, skb->head);
David Howells0b58b8a2016-09-02 22:39:45 +0100461 if (ret < 0)
462 goto out;
463
Marc Dionne8e8715a2019-04-12 16:33:54 +0100464 ret = rxrpc_queue_packet(rx, call, skb,
465 !msg_data_left(msg) && !more,
466 notify_end_tx);
467 /* Should check for failure here */
David Howells0b58b8a2016-09-02 22:39:45 +0100468 skb = NULL;
469 }
470 } while (msg_data_left(msg) > 0);
471
472success:
473 ret = copied;
474out:
475 call->tx_pending = skb;
476 _leave(" = %d", ret);
477 return ret;
478
David Howellse122d842019-01-10 16:59:13 +0000479call_terminated:
David Howells987db9f2019-08-19 09:25:38 +0100480 rxrpc_free_skb(skb, rxrpc_skb_freed);
David Howellse122d842019-01-10 16:59:13 +0000481 _leave(" = %d", call->error);
482 return call->error;
483
David Howells0b58b8a2016-09-02 22:39:45 +0100484maybe_error:
485 if (copied)
486 goto success;
487 goto out;
488
489efault:
490 ret = -EFAULT;
491 goto out;
492}
David Howellsdf423a42016-09-02 22:39:45 +0100493
494/*
495 * extract control messages from the sendmsg() control buffer
496 */
David Howells3ab26a62017-06-07 14:41:52 +0100497static int rxrpc_sendmsg_cmsg(struct msghdr *msg, struct rxrpc_send_params *p)
David Howellsdf423a42016-09-02 22:39:45 +0100498{
499 struct cmsghdr *cmsg;
500 bool got_user_ID = false;
501 int len;
502
David Howellsdf423a42016-09-02 22:39:45 +0100503 if (msg->msg_controllen == 0)
504 return -EINVAL;
505
506 for_each_cmsghdr(cmsg, msg) {
507 if (!CMSG_OK(msg, cmsg))
508 return -EINVAL;
509
yuan linyu1ff8ceb2017-01-03 20:42:17 +0800510 len = cmsg->cmsg_len - sizeof(struct cmsghdr);
David Howellsdf423a42016-09-02 22:39:45 +0100511 _debug("CMSG %d, %d, %d",
512 cmsg->cmsg_level, cmsg->cmsg_type, len);
513
514 if (cmsg->cmsg_level != SOL_RXRPC)
515 continue;
516
517 switch (cmsg->cmsg_type) {
518 case RXRPC_USER_CALL_ID:
519 if (msg->msg_flags & MSG_CMSG_COMPAT) {
520 if (len != sizeof(u32))
521 return -EINVAL;
David Howells48124172017-11-24 10:18:41 +0000522 p->call.user_call_ID = *(u32 *)CMSG_DATA(cmsg);
David Howellsdf423a42016-09-02 22:39:45 +0100523 } else {
524 if (len != sizeof(unsigned long))
525 return -EINVAL;
David Howells48124172017-11-24 10:18:41 +0000526 p->call.user_call_ID = *(unsigned long *)
David Howellsdf423a42016-09-02 22:39:45 +0100527 CMSG_DATA(cmsg);
528 }
David Howellsdf423a42016-09-02 22:39:45 +0100529 got_user_ID = true;
530 break;
531
532 case RXRPC_ABORT:
David Howells3ab26a62017-06-07 14:41:52 +0100533 if (p->command != RXRPC_CMD_SEND_DATA)
David Howellsdf423a42016-09-02 22:39:45 +0100534 return -EINVAL;
David Howells3ab26a62017-06-07 14:41:52 +0100535 p->command = RXRPC_CMD_SEND_ABORT;
536 if (len != sizeof(p->abort_code))
David Howellsdf423a42016-09-02 22:39:45 +0100537 return -EINVAL;
David Howells3ab26a62017-06-07 14:41:52 +0100538 p->abort_code = *(unsigned int *)CMSG_DATA(cmsg);
539 if (p->abort_code == 0)
David Howellsdf423a42016-09-02 22:39:45 +0100540 return -EINVAL;
541 break;
542
543 case RXRPC_ACCEPT:
David Howells3ab26a62017-06-07 14:41:52 +0100544 if (p->command != RXRPC_CMD_SEND_DATA)
David Howellsdf423a42016-09-02 22:39:45 +0100545 return -EINVAL;
David Howells3ab26a62017-06-07 14:41:52 +0100546 p->command = RXRPC_CMD_ACCEPT;
David Howellsdf423a42016-09-02 22:39:45 +0100547 if (len != 0)
548 return -EINVAL;
549 break;
550
551 case RXRPC_EXCLUSIVE_CALL:
David Howells3ab26a62017-06-07 14:41:52 +0100552 p->exclusive = true;
David Howellsdf423a42016-09-02 22:39:45 +0100553 if (len != 0)
554 return -EINVAL;
555 break;
David Howells4e255722017-06-05 14:30:49 +0100556
557 case RXRPC_UPGRADE_SERVICE:
David Howells3ab26a62017-06-07 14:41:52 +0100558 p->upgrade = true;
David Howells4e255722017-06-05 14:30:49 +0100559 if (len != 0)
560 return -EINVAL;
561 break;
562
David Howellse754eba2017-06-07 12:40:03 +0100563 case RXRPC_TX_LENGTH:
David Howells48124172017-11-24 10:18:41 +0000564 if (p->call.tx_total_len != -1 || len != sizeof(__s64))
David Howellse754eba2017-06-07 12:40:03 +0100565 return -EINVAL;
David Howells48124172017-11-24 10:18:41 +0000566 p->call.tx_total_len = *(__s64 *)CMSG_DATA(cmsg);
567 if (p->call.tx_total_len < 0)
David Howellse754eba2017-06-07 12:40:03 +0100568 return -EINVAL;
569 break;
570
David Howellsa158bdd2017-11-24 10:18:41 +0000571 case RXRPC_SET_CALL_TIMEOUT:
572 if (len & 3 || len < 4 || len > 12)
573 return -EINVAL;
574 memcpy(&p->call.timeouts, CMSG_DATA(cmsg), len);
575 p->call.nr_timeouts = len / 4;
576 if (p->call.timeouts.hard > INT_MAX / HZ)
577 return -ERANGE;
578 if (p->call.nr_timeouts >= 2 && p->call.timeouts.idle > 60 * 60 * 1000)
579 return -ERANGE;
580 if (p->call.nr_timeouts >= 3 && p->call.timeouts.normal > 60 * 60 * 1000)
581 return -ERANGE;
582 break;
583
David Howellsdf423a42016-09-02 22:39:45 +0100584 default:
585 return -EINVAL;
586 }
587 }
588
589 if (!got_user_ID)
590 return -EINVAL;
David Howells48124172017-11-24 10:18:41 +0000591 if (p->call.tx_total_len != -1 && p->command != RXRPC_CMD_SEND_DATA)
David Howellse754eba2017-06-07 12:40:03 +0100592 return -EINVAL;
David Howellsdf423a42016-09-02 22:39:45 +0100593 _leave(" = 0");
594 return 0;
595}
596
597/*
David Howellsdf423a42016-09-02 22:39:45 +0100598 * Create a new client call for sendmsg().
David Howells540b1c42017-02-27 15:43:06 +0000599 * - Called with the socket lock held, which it must release.
600 * - If it returns a call, the call's lock will need releasing by the caller.
David Howellsdf423a42016-09-02 22:39:45 +0100601 */
602static struct rxrpc_call *
603rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
David Howells3ab26a62017-06-07 14:41:52 +0100604 struct rxrpc_send_params *p)
David Howells540b1c42017-02-27 15:43:06 +0000605 __releases(&rx->sk.sk_lock.slock)
David Howells88f2a8252018-03-30 21:05:17 +0100606 __acquires(&call->user_mutex)
David Howellsdf423a42016-09-02 22:39:45 +0100607{
608 struct rxrpc_conn_parameters cp;
609 struct rxrpc_call *call;
610 struct key *key;
611
612 DECLARE_SOCKADDR(struct sockaddr_rxrpc *, srx, msg->msg_name);
613
614 _enter("");
615
David Howells540b1c42017-02-27 15:43:06 +0000616 if (!msg->msg_name) {
617 release_sock(&rx->sk);
David Howellsdf423a42016-09-02 22:39:45 +0100618 return ERR_PTR(-EDESTADDRREQ);
David Howells540b1c42017-02-27 15:43:06 +0000619 }
David Howellsdf423a42016-09-02 22:39:45 +0100620
621 key = rx->key;
622 if (key && !rx->key->payload.data[0])
623 key = NULL;
624
625 memset(&cp, 0, sizeof(cp));
626 cp.local = rx->local;
627 cp.key = rx->key;
628 cp.security_level = rx->min_sec_level;
David Howells3ab26a62017-06-07 14:41:52 +0100629 cp.exclusive = rx->exclusive | p->exclusive;
630 cp.upgrade = p->upgrade;
David Howellsdf423a42016-09-02 22:39:45 +0100631 cp.service_id = srx->srx_service;
David Howellsa25e21f2018-03-27 23:03:00 +0100632 call = rxrpc_new_client_call(rx, &cp, srx, &p->call, GFP_KERNEL,
633 atomic_inc_return(&rxrpc_debug_id));
David Howells540b1c42017-02-27 15:43:06 +0000634 /* The socket is now unlocked */
David Howellsdf423a42016-09-02 22:39:45 +0100635
David Howells17226f12018-03-30 21:05:44 +0100636 rxrpc_put_peer(cp.peer);
David Howellsdf423a42016-09-02 22:39:45 +0100637 _leave(" = %p\n", call);
638 return call;
639}
640
641/*
642 * send a message forming part of a client call through an RxRPC socket
643 * - caller holds the socket locked
644 * - the socket may be either a client socket or a server socket
645 */
646int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
David Howells540b1c42017-02-27 15:43:06 +0000647 __releases(&rx->sk.sk_lock.slock)
David Howells88f2a8252018-03-30 21:05:17 +0100648 __releases(&call->user_mutex)
David Howellsdf423a42016-09-02 22:39:45 +0100649{
David Howells146d8fe2017-03-04 00:01:41 +0000650 enum rxrpc_call_state state;
David Howellsdf423a42016-09-02 22:39:45 +0100651 struct rxrpc_call *call;
David Howellsa158bdd2017-11-24 10:18:41 +0000652 unsigned long now, j;
David Howellsdf423a42016-09-02 22:39:45 +0100653 int ret;
654
David Howells3ab26a62017-06-07 14:41:52 +0100655 struct rxrpc_send_params p = {
David Howells48124172017-11-24 10:18:41 +0000656 .call.tx_total_len = -1,
657 .call.user_call_ID = 0,
David Howellsa158bdd2017-11-24 10:18:41 +0000658 .call.nr_timeouts = 0,
David Howellse138aa72020-03-13 09:22:09 +0000659 .call.interruptibility = RXRPC_INTERRUPTIBLE,
David Howells48124172017-11-24 10:18:41 +0000660 .abort_code = 0,
661 .command = RXRPC_CMD_SEND_DATA,
662 .exclusive = false,
663 .upgrade = false,
David Howells3ab26a62017-06-07 14:41:52 +0100664 };
665
David Howellsdf423a42016-09-02 22:39:45 +0100666 _enter("");
667
David Howells3ab26a62017-06-07 14:41:52 +0100668 ret = rxrpc_sendmsg_cmsg(msg, &p);
David Howellsdf423a42016-09-02 22:39:45 +0100669 if (ret < 0)
David Howells540b1c42017-02-27 15:43:06 +0000670 goto error_release_sock;
David Howellsdf423a42016-09-02 22:39:45 +0100671
David Howells3ab26a62017-06-07 14:41:52 +0100672 if (p.command == RXRPC_CMD_ACCEPT) {
David Howells540b1c42017-02-27 15:43:06 +0000673 ret = -EINVAL;
David Howellsdf423a42016-09-02 22:39:45 +0100674 if (rx->sk.sk_state != RXRPC_SERVER_LISTENING)
David Howells540b1c42017-02-27 15:43:06 +0000675 goto error_release_sock;
David Howells48124172017-11-24 10:18:41 +0000676 call = rxrpc_accept_call(rx, p.call.user_call_ID, NULL);
David Howells540b1c42017-02-27 15:43:06 +0000677 /* The socket is now unlocked. */
David Howellsdf423a42016-09-02 22:39:45 +0100678 if (IS_ERR(call))
679 return PTR_ERR(call);
David Howells03a6c822017-11-24 10:18:40 +0000680 ret = 0;
681 goto out_put_unlock;
David Howellsdf423a42016-09-02 22:39:45 +0100682 }
683
David Howells48124172017-11-24 10:18:41 +0000684 call = rxrpc_find_call_by_user_ID(rx, p.call.user_call_ID);
David Howellsdf423a42016-09-02 22:39:45 +0100685 if (!call) {
David Howells540b1c42017-02-27 15:43:06 +0000686 ret = -EBADSLT;
David Howells3ab26a62017-06-07 14:41:52 +0100687 if (p.command != RXRPC_CMD_SEND_DATA)
David Howells540b1c42017-02-27 15:43:06 +0000688 goto error_release_sock;
David Howells3ab26a62017-06-07 14:41:52 +0100689 call = rxrpc_new_client_call_for_sendmsg(rx, msg, &p);
David Howells540b1c42017-02-27 15:43:06 +0000690 /* The socket is now unlocked... */
David Howellsdf423a42016-09-02 22:39:45 +0100691 if (IS_ERR(call))
692 return PTR_ERR(call);
David Howells540b1c42017-02-27 15:43:06 +0000693 /* ... and we have the call lock. */
694 } else {
David Howells146d8fe2017-03-04 00:01:41 +0000695 switch (READ_ONCE(call->state)) {
696 case RXRPC_CALL_UNINITIALISED:
697 case RXRPC_CALL_CLIENT_AWAIT_CONN:
698 case RXRPC_CALL_SERVER_PREALLOC:
699 case RXRPC_CALL_SERVER_SECURING:
700 case RXRPC_CALL_SERVER_ACCEPTING:
David Howellsc48fc112019-10-07 10:58:28 +0100701 rxrpc_put_call(call, rxrpc_call_put);
David Howells146d8fe2017-03-04 00:01:41 +0000702 ret = -EBUSY;
David Howells37411ca2017-03-02 23:48:52 +0000703 goto error_release_sock;
David Howells146d8fe2017-03-04 00:01:41 +0000704 default:
705 break;
706 }
David Howells37411ca2017-03-02 23:48:52 +0000707
David Howells540b1c42017-02-27 15:43:06 +0000708 ret = mutex_lock_interruptible(&call->user_mutex);
709 release_sock(&rx->sk);
710 if (ret < 0) {
711 ret = -ERESTARTSYS;
712 goto error_put;
713 }
David Howellse754eba2017-06-07 12:40:03 +0100714
David Howells48124172017-11-24 10:18:41 +0000715 if (p.call.tx_total_len != -1) {
David Howellse754eba2017-06-07 12:40:03 +0100716 ret = -EINVAL;
717 if (call->tx_total_len != -1 ||
718 call->tx_pending ||
719 call->tx_top != 0)
720 goto error_put;
David Howells48124172017-11-24 10:18:41 +0000721 call->tx_total_len = p.call.tx_total_len;
David Howellse754eba2017-06-07 12:40:03 +0100722 }
David Howellsdf423a42016-09-02 22:39:45 +0100723 }
724
David Howellsa158bdd2017-11-24 10:18:41 +0000725 switch (p.call.nr_timeouts) {
726 case 3:
727 j = msecs_to_jiffies(p.call.timeouts.normal);
728 if (p.call.timeouts.normal > 0 && j == 0)
729 j = 1;
730 WRITE_ONCE(call->next_rx_timo, j);
731 /* Fall through */
732 case 2:
733 j = msecs_to_jiffies(p.call.timeouts.idle);
734 if (p.call.timeouts.idle > 0 && j == 0)
735 j = 1;
736 WRITE_ONCE(call->next_req_timo, j);
737 /* Fall through */
738 case 1:
739 if (p.call.timeouts.hard > 0) {
740 j = msecs_to_jiffies(p.call.timeouts.hard);
741 now = jiffies;
742 j += now;
743 WRITE_ONCE(call->expect_term_by, j);
744 rxrpc_reduce_call_timer(call, j, now,
745 rxrpc_timer_set_for_hard);
746 }
747 break;
748 }
749
David Howells146d8fe2017-03-04 00:01:41 +0000750 state = READ_ONCE(call->state);
David Howellsdf423a42016-09-02 22:39:45 +0100751 _debug("CALL %d USR %lx ST %d on CONN %p",
David Howells146d8fe2017-03-04 00:01:41 +0000752 call->debug_id, call->user_call_ID, state, call->conn);
David Howellsdf423a42016-09-02 22:39:45 +0100753
David Howells146d8fe2017-03-04 00:01:41 +0000754 if (state >= RXRPC_CALL_COMPLETE) {
David Howellsdf423a42016-09-02 22:39:45 +0100755 /* it's too late for this call */
756 ret = -ESHUTDOWN;
David Howells3ab26a62017-06-07 14:41:52 +0100757 } else if (p.command == RXRPC_CMD_SEND_ABORT) {
David Howellsdf423a42016-09-02 22:39:45 +0100758 ret = 0;
David Howells3ab26a62017-06-07 14:41:52 +0100759 if (rxrpc_abort_call("CMD", call, 0, p.abort_code, -ECONNABORTED))
David Howells26cb02a2016-10-06 08:11:49 +0100760 ret = rxrpc_send_abort_packet(call);
David Howells3ab26a62017-06-07 14:41:52 +0100761 } else if (p.command != RXRPC_CMD_SEND_DATA) {
David Howellsdf423a42016-09-02 22:39:45 +0100762 ret = -EINVAL;
763 } else if (rxrpc_is_client_call(call) &&
David Howells146d8fe2017-03-04 00:01:41 +0000764 state != RXRPC_CALL_CLIENT_SEND_REQUEST) {
David Howellsdf423a42016-09-02 22:39:45 +0100765 /* request phase complete for this client call */
766 ret = -EPROTO;
767 } else if (rxrpc_is_service_call(call) &&
David Howells146d8fe2017-03-04 00:01:41 +0000768 state != RXRPC_CALL_SERVER_ACK_REQUEST &&
769 state != RXRPC_CALL_SERVER_SEND_REPLY) {
David Howellsdf423a42016-09-02 22:39:45 +0100770 /* Reply phase not begun or not complete for service call. */
771 ret = -EPROTO;
772 } else {
David Howellse8332512017-08-29 10:18:56 +0100773 ret = rxrpc_send_data(rx, call, msg, len, NULL);
David Howellsdf423a42016-09-02 22:39:45 +0100774 }
775
David Howells03a6c822017-11-24 10:18:40 +0000776out_put_unlock:
David Howells540b1c42017-02-27 15:43:06 +0000777 mutex_unlock(&call->user_mutex);
778error_put:
David Howellsfff724292016-09-07 14:34:21 +0100779 rxrpc_put_call(call, rxrpc_call_put);
David Howellsdf423a42016-09-02 22:39:45 +0100780 _leave(" = %d", ret);
781 return ret;
David Howells540b1c42017-02-27 15:43:06 +0000782
783error_release_sock:
784 release_sock(&rx->sk);
785 return ret;
David Howellsdf423a42016-09-02 22:39:45 +0100786}
787
788/**
789 * rxrpc_kernel_send_data - Allow a kernel service to send data on a call
790 * @sock: The socket the call is on
791 * @call: The call to send data through
792 * @msg: The data to send
793 * @len: The amount of data to send
David Howellse8332512017-08-29 10:18:56 +0100794 * @notify_end_tx: Notification that the last packet is queued.
David Howellsdf423a42016-09-02 22:39:45 +0100795 *
796 * Allow a kernel service to send data on a call. The call must be in an state
797 * appropriate to sending data. No control data should be supplied in @msg,
798 * nor should an address be supplied. MSG_MORE should be flagged if there's
799 * more data to come, otherwise this data will end the transmission phase.
800 */
801int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
David Howellse8332512017-08-29 10:18:56 +0100802 struct msghdr *msg, size_t len,
803 rxrpc_notify_end_tx_t notify_end_tx)
David Howellsdf423a42016-09-02 22:39:45 +0100804{
805 int ret;
806
807 _enter("{%d,%s},", call->debug_id, rxrpc_call_states[call->state]);
808
809 ASSERTCMP(msg->msg_name, ==, NULL);
810 ASSERTCMP(msg->msg_control, ==, NULL);
811
David Howells540b1c42017-02-27 15:43:06 +0000812 mutex_lock(&call->user_mutex);
David Howellsdf423a42016-09-02 22:39:45 +0100813
814 _debug("CALL %d USR %lx ST %d on CONN %p",
815 call->debug_id, call->user_call_ID, call->state, call->conn);
816
David Howells146d8fe2017-03-04 00:01:41 +0000817 switch (READ_ONCE(call->state)) {
818 case RXRPC_CALL_CLIENT_SEND_REQUEST:
819 case RXRPC_CALL_SERVER_ACK_REQUEST:
820 case RXRPC_CALL_SERVER_SEND_REPLY:
David Howellse8332512017-08-29 10:18:56 +0100821 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len,
822 notify_end_tx);
David Howells146d8fe2017-03-04 00:01:41 +0000823 break;
824 case RXRPC_CALL_COMPLETE:
David Howells6fc166d2017-03-09 08:10:32 +0000825 read_lock_bh(&call->state_lock);
David Howellsbd2db2d2017-08-29 10:18:43 +0100826 ret = call->error;
David Howells6fc166d2017-03-09 08:10:32 +0000827 read_unlock_bh(&call->state_lock);
David Howells146d8fe2017-03-04 00:01:41 +0000828 break;
829 default:
David Howellsfb46f6e2017-04-06 10:12:00 +0100830 /* Request phase complete for this client call */
831 trace_rxrpc_rx_eproto(call, 0, tracepoint_string("late_send"));
David Howells146d8fe2017-03-04 00:01:41 +0000832 ret = -EPROTO;
833 break;
David Howellsdf423a42016-09-02 22:39:45 +0100834 }
835
David Howells540b1c42017-02-27 15:43:06 +0000836 mutex_unlock(&call->user_mutex);
David Howellsdf423a42016-09-02 22:39:45 +0100837 _leave(" = %d", ret);
838 return ret;
839}
840EXPORT_SYMBOL(rxrpc_kernel_send_data);
841
842/**
843 * rxrpc_kernel_abort_call - Allow a kernel service to abort a call
844 * @sock: The socket the call is on
845 * @call: The call to be aborted
846 * @abort_code: The abort code to stick into the ABORT packet
David Howells5a429762016-09-06 22:19:51 +0100847 * @error: Local error value
848 * @why: 3-char string indicating why.
David Howellsdf423a42016-09-02 22:39:45 +0100849 *
David Howells84a4c092017-04-06 10:11:59 +0100850 * Allow a kernel service to abort a call, if it's still in an abortable state
851 * and return true if the call was aborted, false if it was already complete.
David Howellsdf423a42016-09-02 22:39:45 +0100852 */
David Howells84a4c092017-04-06 10:11:59 +0100853bool rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call,
David Howells5a429762016-09-06 22:19:51 +0100854 u32 abort_code, int error, const char *why)
David Howellsdf423a42016-09-02 22:39:45 +0100855{
David Howells84a4c092017-04-06 10:11:59 +0100856 bool aborted;
857
David Howells5a429762016-09-06 22:19:51 +0100858 _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why);
David Howellsdf423a42016-09-02 22:39:45 +0100859
David Howells540b1c42017-02-27 15:43:06 +0000860 mutex_lock(&call->user_mutex);
David Howellsdf423a42016-09-02 22:39:45 +0100861
David Howells84a4c092017-04-06 10:11:59 +0100862 aborted = rxrpc_abort_call(why, call, 0, abort_code, error);
863 if (aborted)
David Howells26cb02a2016-10-06 08:11:49 +0100864 rxrpc_send_abort_packet(call);
David Howellsdf423a42016-09-02 22:39:45 +0100865
David Howells540b1c42017-02-27 15:43:06 +0000866 mutex_unlock(&call->user_mutex);
David Howells84a4c092017-04-06 10:11:59 +0100867 return aborted;
David Howellsdf423a42016-09-02 22:39:45 +0100868}
David Howellsdf423a42016-09-02 22:39:45 +0100869EXPORT_SYMBOL(rxrpc_kernel_abort_call);
David Howellse754eba2017-06-07 12:40:03 +0100870
871/**
872 * rxrpc_kernel_set_tx_length - Set the total Tx length on a call
873 * @sock: The socket the call is on
874 * @call: The call to be informed
875 * @tx_total_len: The amount of data to be transmitted for this call
876 *
877 * Allow a kernel service to set the total transmit length on a call. This
878 * allows buffer-to-packet encrypt-and-copy to be performed.
879 *
880 * This function is primarily for use for setting the reply length since the
881 * request length can be set when beginning the call.
882 */
883void rxrpc_kernel_set_tx_length(struct socket *sock, struct rxrpc_call *call,
884 s64 tx_total_len)
885{
886 WARN_ON(call->tx_total_len != -1);
887 call->tx_total_len = tx_total_len;
888}
889EXPORT_SYMBOL(rxrpc_kernel_set_tx_length);