rxrpc: Clone received jumbo subpackets and queue separately
[platform/kernel/linux-rpi.git] / net / rxrpc / output.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* RxRPC packet transmission
3  *
4  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
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>
14 #include <net/sock.h>
15 #include <net/af_rxrpc.h>
16 #include <net/udp.h>
17 #include "ar-internal.h"
18
19 extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
20
21 static ssize_t do_udp_sendmsg(struct socket *sk, struct msghdr *msg, size_t len)
22 {
23 #if IS_ENABLED(CONFIG_AF_RXRPC_IPV6)
24         struct sockaddr *sa = msg->msg_name;
25
26         if (sa->sa_family == AF_INET6)
27                 return udpv6_sendmsg(sk->sk, msg, len);
28 #endif
29         return udp_sendmsg(sk->sk, msg, len);
30 }
31
32 struct rxrpc_abort_buffer {
33         struct rxrpc_wire_header whdr;
34         __be32 abort_code;
35 };
36
37 static const char rxrpc_keepalive_string[] = "";
38
39 /*
40  * Increase Tx backoff on transmission failure and clear it on success.
41  */
42 static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret)
43 {
44         if (ret < 0) {
45                 u16 tx_backoff = READ_ONCE(call->tx_backoff);
46
47                 if (tx_backoff < HZ)
48                         WRITE_ONCE(call->tx_backoff, tx_backoff + 1);
49         } else {
50                 WRITE_ONCE(call->tx_backoff, 0);
51         }
52 }
53
54 /*
55  * Arrange for a keepalive ping a certain time after we last transmitted.  This
56  * lets the far side know we're still interested in this call and helps keep
57  * the route through any intervening firewall open.
58  *
59  * Receiving a response to the ping will prevent the ->expect_rx_by timer from
60  * expiring.
61  */
62 static void rxrpc_set_keepalive(struct rxrpc_call *call)
63 {
64         unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6;
65
66         keepalive_at += now;
67         WRITE_ONCE(call->keepalive_at, keepalive_at);
68         rxrpc_reduce_call_timer(call, keepalive_at, now,
69                                 rxrpc_timer_set_for_keepalive);
70 }
71
72 /*
73  * Fill out an ACK packet.
74  */
75 static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
76                                  struct rxrpc_call *call,
77                                  struct rxrpc_txbuf *txb,
78                                  rxrpc_seq_t *_hard_ack,
79                                  rxrpc_seq_t *_top)
80 {
81         struct rxrpc_ackinfo ackinfo;
82         unsigned int tmp;
83         rxrpc_seq_t hard_ack, top, seq;
84         int ix;
85         u32 mtu, jmax;
86         u8 *ackp = txb->acks;
87
88         tmp = atomic_xchg(&call->ackr_nr_unacked, 0);
89         tmp |= atomic_xchg(&call->ackr_nr_consumed, 0);
90         if (!tmp && (txb->ack.reason == RXRPC_ACK_DELAY ||
91                      txb->ack.reason == RXRPC_ACK_IDLE)) {
92                 rxrpc_inc_stat(call->rxnet, stat_tx_ack_skip);
93                 return 0;
94         }
95
96         rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill);
97
98         /* Barrier against rxrpc_input_data(). */
99         hard_ack = READ_ONCE(call->rx_hard_ack);
100         top = smp_load_acquire(&call->rx_top);
101         *_hard_ack = hard_ack;
102         *_top = top;
103
104         txb->ack.firstPacket    = htonl(hard_ack + 1);
105         txb->ack.previousPacket = htonl(call->ackr_highest_seq);
106         txb->ack.nAcks          = top - hard_ack;
107
108         if (txb->ack.nAcks) {
109                 seq = hard_ack + 1;
110                 do {
111                         ix = seq & RXRPC_RXTX_BUFF_MASK;
112                         if (call->rxtx_buffer[ix])
113                                 *ackp++ = RXRPC_ACK_TYPE_ACK;
114                         else
115                                 *ackp++ = RXRPC_ACK_TYPE_NACK;
116                         seq++;
117                 } while (before_eq(seq, top));
118         } else if (txb->ack.reason == RXRPC_ACK_DELAY) {
119                 txb->ack.reason = RXRPC_ACK_IDLE;
120         }
121
122         mtu = conn->params.peer->if_mtu;
123         mtu -= conn->params.peer->hdrsize;
124         jmax = rxrpc_rx_jumbo_max;
125         ackinfo.rxMTU           = htonl(rxrpc_rx_mtu);
126         ackinfo.maxMTU          = htonl(mtu);
127         ackinfo.rwind           = htonl(call->rx_winsize);
128         ackinfo.jumbo_max       = htonl(jmax);
129
130         *ackp++ = 0;
131         *ackp++ = 0;
132         *ackp++ = 0;
133         memcpy(ackp, &ackinfo, sizeof(ackinfo));
134         return top - hard_ack + 3 + sizeof(ackinfo);
135 }
136
137 /*
138  * Record the beginning of an RTT probe.
139  */
140 static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial,
141                                  enum rxrpc_rtt_tx_trace why)
142 {
143         unsigned long avail = call->rtt_avail;
144         int rtt_slot = 9;
145
146         if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK))
147                 goto no_slot;
148
149         rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK);
150         if (!test_and_clear_bit(rtt_slot, &call->rtt_avail))
151                 goto no_slot;
152
153         call->rtt_serial[rtt_slot] = serial;
154         call->rtt_sent_at[rtt_slot] = ktime_get_real();
155         smp_wmb(); /* Write data before avail bit */
156         set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
157
158         trace_rxrpc_rtt_tx(call, why, rtt_slot, serial);
159         return rtt_slot;
160
161 no_slot:
162         trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial);
163         return -1;
164 }
165
166 /*
167  * Cancel an RTT probe.
168  */
169 static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call,
170                                    rxrpc_serial_t serial, int rtt_slot)
171 {
172         if (rtt_slot != -1) {
173                 clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
174                 smp_wmb(); /* Clear pending bit before setting slot */
175                 set_bit(rtt_slot, &call->rtt_avail);
176                 trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial);
177         }
178 }
179
180 /*
181  * Send an ACK call packet.
182  */
183 static int rxrpc_send_ack_packet(struct rxrpc_local *local, struct rxrpc_txbuf *txb)
184 {
185         struct rxrpc_connection *conn;
186         struct rxrpc_ack_buffer *pkt;
187         struct rxrpc_call *call = txb->call;
188         struct msghdr msg;
189         struct kvec iov[1];
190         rxrpc_serial_t serial;
191         rxrpc_seq_t hard_ack, top;
192         size_t len, n;
193         int ret, rtt_slot = -1;
194
195         if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
196                 return -ECONNRESET;
197
198         conn = call->conn;
199
200         msg.msg_name    = &call->peer->srx.transport;
201         msg.msg_namelen = call->peer->srx.transport_len;
202         msg.msg_control = NULL;
203         msg.msg_controllen = 0;
204         msg.msg_flags   = 0;
205
206         if (txb->ack.reason == RXRPC_ACK_PING)
207                 txb->wire.flags |= RXRPC_REQUEST_ACK;
208
209         if (txb->ack.reason == RXRPC_ACK_DELAY)
210                 clear_bit(RXRPC_CALL_DELAY_ACK_PENDING, &call->flags);
211         if (txb->ack.reason == RXRPC_ACK_IDLE)
212                 clear_bit(RXRPC_CALL_IDLE_ACK_PENDING, &call->flags);
213
214         spin_lock_bh(&call->lock);
215         n = rxrpc_fill_out_ack(conn, call, txb, &hard_ack, &top);
216         spin_unlock_bh(&call->lock);
217         if (n == 0) {
218                 kfree(pkt);
219                 return 0;
220         }
221
222         iov[0].iov_base = &txb->wire;
223         iov[0].iov_len  = sizeof(txb->wire) + sizeof(txb->ack) + n;
224         len = iov[0].iov_len;
225
226         serial = atomic_inc_return(&conn->serial);
227         txb->wire.serial = htonl(serial);
228         trace_rxrpc_tx_ack(call->debug_id, serial,
229                            ntohl(txb->ack.firstPacket),
230                            ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks);
231         if (txb->ack_why == rxrpc_propose_ack_ping_for_lost_ack)
232                 call->acks_lost_ping = serial;
233
234         if (txb->ack.reason == RXRPC_ACK_PING)
235                 rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping);
236
237         rxrpc_inc_stat(call->rxnet, stat_tx_ack_send);
238
239         iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
240         ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
241         call->peer->last_tx_at = ktime_get_seconds();
242         if (ret < 0)
243                 trace_rxrpc_tx_fail(call->debug_id, serial, ret,
244                                     rxrpc_tx_point_call_ack);
245         else
246                 trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
247                                       rxrpc_tx_point_call_ack);
248         rxrpc_tx_backoff(call, ret);
249
250         if (call->state < RXRPC_CALL_COMPLETE) {
251                 if (ret < 0)
252                         rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
253                 rxrpc_set_keepalive(call);
254         }
255
256         kfree(pkt);
257         return ret;
258 }
259
260 /*
261  * ACK transmitter for a local endpoint.  The UDP socket locks around each
262  * transmission, so we can only transmit one packet at a time, ACK, DATA or
263  * otherwise.
264  */
265 void rxrpc_transmit_ack_packets(struct rxrpc_local *local)
266 {
267         LIST_HEAD(queue);
268         int ret;
269
270         trace_rxrpc_local(local->debug_id, rxrpc_local_tx_ack,
271                           refcount_read(&local->ref), NULL);
272
273         if (list_empty(&local->ack_tx_queue))
274                 return;
275
276         spin_lock_bh(&local->ack_tx_lock);
277         list_splice_tail_init(&local->ack_tx_queue, &queue);
278         spin_unlock_bh(&local->ack_tx_lock);
279
280         while (!list_empty(&queue)) {
281                 struct rxrpc_txbuf *txb =
282                         list_entry(queue.next, struct rxrpc_txbuf, tx_link);
283
284                 ret = rxrpc_send_ack_packet(local, txb);
285                 if (ret < 0 && ret != -ECONNRESET) {
286                         spin_lock_bh(&local->ack_tx_lock);
287                         list_splice_init(&queue, &local->ack_tx_queue);
288                         spin_unlock_bh(&local->ack_tx_lock);
289                         break;
290                 }
291
292                 list_del_init(&txb->tx_link);
293                 rxrpc_put_call(txb->call, rxrpc_call_put);
294                 rxrpc_put_txbuf(txb, rxrpc_txbuf_put_ack_tx);
295         }
296 }
297
298 /*
299  * Send an ABORT call packet.
300  */
301 int rxrpc_send_abort_packet(struct rxrpc_call *call)
302 {
303         struct rxrpc_connection *conn;
304         struct rxrpc_abort_buffer pkt;
305         struct msghdr msg;
306         struct kvec iov[1];
307         rxrpc_serial_t serial;
308         int ret;
309
310         /* Don't bother sending aborts for a client call once the server has
311          * hard-ACK'd all of its request data.  After that point, we're not
312          * going to stop the operation proceeding, and whilst we might limit
313          * the reply, it's not worth it if we can send a new call on the same
314          * channel instead, thereby closing off this call.
315          */
316         if (rxrpc_is_client_call(call) &&
317             test_bit(RXRPC_CALL_TX_LAST, &call->flags))
318                 return 0;
319
320         if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
321                 return -ECONNRESET;
322
323         conn = call->conn;
324
325         msg.msg_name    = &call->peer->srx.transport;
326         msg.msg_namelen = call->peer->srx.transport_len;
327         msg.msg_control = NULL;
328         msg.msg_controllen = 0;
329         msg.msg_flags   = 0;
330
331         pkt.whdr.epoch          = htonl(conn->proto.epoch);
332         pkt.whdr.cid            = htonl(call->cid);
333         pkt.whdr.callNumber     = htonl(call->call_id);
334         pkt.whdr.seq            = 0;
335         pkt.whdr.type           = RXRPC_PACKET_TYPE_ABORT;
336         pkt.whdr.flags          = conn->out_clientflag;
337         pkt.whdr.userStatus     = 0;
338         pkt.whdr.securityIndex  = call->security_ix;
339         pkt.whdr._rsvd          = 0;
340         pkt.whdr.serviceId      = htons(call->service_id);
341         pkt.abort_code          = htonl(call->abort_code);
342
343         iov[0].iov_base = &pkt;
344         iov[0].iov_len  = sizeof(pkt);
345
346         serial = atomic_inc_return(&conn->serial);
347         pkt.whdr.serial = htonl(serial);
348
349         iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
350         ret = do_udp_sendmsg(conn->params.local->socket, &msg, sizeof(pkt));
351         conn->params.peer->last_tx_at = ktime_get_seconds();
352         if (ret < 0)
353                 trace_rxrpc_tx_fail(call->debug_id, serial, ret,
354                                     rxrpc_tx_point_call_abort);
355         else
356                 trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
357                                       rxrpc_tx_point_call_abort);
358         rxrpc_tx_backoff(call, ret);
359         return ret;
360 }
361
362 /*
363  * send a packet through the transport endpoint
364  */
365 int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
366                            bool retrans)
367 {
368         enum rxrpc_req_ack_trace why;
369         struct rxrpc_connection *conn = call->conn;
370         struct rxrpc_wire_header whdr;
371         struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
372         struct msghdr msg;
373         struct kvec iov[2];
374         rxrpc_serial_t serial;
375         size_t len;
376         int ret, rtt_slot = -1;
377
378         _enter(",{%d}", skb->len);
379
380         if (hlist_unhashed(&call->error_link)) {
381                 spin_lock_bh(&call->peer->lock);
382                 hlist_add_head_rcu(&call->error_link, &call->peer->error_targets);
383                 spin_unlock_bh(&call->peer->lock);
384         }
385
386         /* Each transmission of a Tx packet needs a new serial number */
387         serial = atomic_inc_return(&conn->serial);
388
389         whdr.epoch      = htonl(conn->proto.epoch);
390         whdr.cid        = htonl(call->cid);
391         whdr.callNumber = htonl(call->call_id);
392         whdr.seq        = htonl(sp->hdr.seq);
393         whdr.serial     = htonl(serial);
394         whdr.type       = RXRPC_PACKET_TYPE_DATA;
395         whdr.flags      = sp->hdr.flags;
396         whdr.userStatus = 0;
397         whdr.securityIndex = call->security_ix;
398         whdr._rsvd      = htons(sp->hdr._rsvd);
399         whdr.serviceId  = htons(call->service_id);
400
401         if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
402             sp->hdr.seq == 1)
403                 whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE;
404
405         iov[0].iov_base = &whdr;
406         iov[0].iov_len = sizeof(whdr);
407         iov[1].iov_base = skb->head;
408         iov[1].iov_len = skb->len;
409         len = iov[0].iov_len + iov[1].iov_len;
410         iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
411
412         msg.msg_name = &call->peer->srx.transport;
413         msg.msg_namelen = call->peer->srx.transport_len;
414         msg.msg_control = NULL;
415         msg.msg_controllen = 0;
416         msg.msg_flags = 0;
417
418         /* If our RTT cache needs working on, request an ACK.  Also request
419          * ACKs if a DATA packet appears to have been lost.
420          *
421          * However, we mustn't request an ACK on the last reply packet of a
422          * service call, lest OpenAFS incorrectly send us an ACK with some
423          * soft-ACKs in it and then never follow up with a proper hard ACK.
424          */
425         if (whdr.flags & RXRPC_REQUEST_ACK)
426                 why = rxrpc_reqack_already_on;
427         else if ((whdr.flags & RXRPC_LAST_PACKET) && rxrpc_to_client(sp))
428                 why = rxrpc_reqack_no_srv_last;
429         else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
430                 why = rxrpc_reqack_ack_lost;
431         else if (retrans)
432                 why = rxrpc_reqack_retrans;
433         else if (call->cong_mode == RXRPC_CALL_SLOW_START && call->cong_cwnd <= 2)
434                 why = rxrpc_reqack_slow_start;
435         else if (call->tx_winsize <= 2)
436                 why = rxrpc_reqack_small_txwin;
437         else if (call->peer->rtt_count < 3 && sp->hdr.seq & 1)
438                 why = rxrpc_reqack_more_rtt;
439         else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), ktime_get_real()))
440                 why = rxrpc_reqack_old_rtt;
441         else
442                 goto dont_set_request_ack;
443
444         rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]);
445         trace_rxrpc_req_ack(call->debug_id, sp->hdr.seq, why);
446         if (why != rxrpc_reqack_no_srv_last)
447                 whdr.flags |= RXRPC_REQUEST_ACK;
448 dont_set_request_ack:
449
450         if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
451                 static int lose;
452                 if ((lose++ & 7) == 7) {
453                         ret = 0;
454                         trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
455                                             whdr.flags, retrans, true);
456                         goto done;
457                 }
458         }
459
460         trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
461                             false);
462
463         /* send the packet with the don't fragment bit set if we currently
464          * think it's small enough */
465         if (iov[1].iov_len >= call->peer->maxdata)
466                 goto send_fragmentable;
467
468         down_read(&conn->params.local->defrag_sem);
469
470         sp->hdr.serial = serial;
471         smp_wmb(); /* Set serial before timestamp */
472         skb->tstamp = ktime_get_real();
473         if (whdr.flags & RXRPC_REQUEST_ACK)
474                 rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
475
476         /* send the packet by UDP
477          * - returns -EMSGSIZE if UDP would have to fragment the packet
478          *   to go out of the interface
479          *   - in which case, we'll have processed the ICMP error
480          *     message and update the peer record
481          */
482         rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
483         ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
484         conn->params.peer->last_tx_at = ktime_get_seconds();
485
486         up_read(&conn->params.local->defrag_sem);
487         if (ret < 0) {
488                 rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
489                 trace_rxrpc_tx_fail(call->debug_id, serial, ret,
490                                     rxrpc_tx_point_call_data_nofrag);
491         } else {
492                 trace_rxrpc_tx_packet(call->debug_id, &whdr,
493                                       rxrpc_tx_point_call_data_nofrag);
494         }
495
496         rxrpc_tx_backoff(call, ret);
497         if (ret == -EMSGSIZE)
498                 goto send_fragmentable;
499
500 done:
501         if (ret >= 0) {
502                 if (whdr.flags & RXRPC_REQUEST_ACK) {
503                         call->peer->rtt_last_req = skb->tstamp;
504                         if (call->peer->rtt_count > 1) {
505                                 unsigned long nowj = jiffies, ack_lost_at;
506
507                                 ack_lost_at = rxrpc_get_rto_backoff(call->peer, false);
508                                 ack_lost_at += nowj;
509                                 WRITE_ONCE(call->ack_lost_at, ack_lost_at);
510                                 rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
511                                                         rxrpc_timer_set_for_lost_ack);
512                         }
513                 }
514
515                 if (sp->hdr.seq == 1 &&
516                     !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
517                                       &call->flags)) {
518                         unsigned long nowj = jiffies, expect_rx_by;
519
520                         expect_rx_by = nowj + call->next_rx_timo;
521                         WRITE_ONCE(call->expect_rx_by, expect_rx_by);
522                         rxrpc_reduce_call_timer(call, expect_rx_by, nowj,
523                                                 rxrpc_timer_set_for_normal);
524                 }
525
526                 rxrpc_set_keepalive(call);
527         } else {
528                 /* Cancel the call if the initial transmission fails,
529                  * particularly if that's due to network routing issues that
530                  * aren't going away anytime soon.  The layer above can arrange
531                  * the retransmission.
532                  */
533                 if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags))
534                         rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
535                                                   RX_USER_ABORT, ret);
536         }
537
538         _leave(" = %d [%u]", ret, call->peer->maxdata);
539         return ret;
540
541 send_fragmentable:
542         /* attempt to send this message with fragmentation enabled */
543         _debug("send fragment");
544
545         down_write(&conn->params.local->defrag_sem);
546
547         sp->hdr.serial = serial;
548         smp_wmb(); /* Set serial before timestamp */
549         skb->tstamp = ktime_get_real();
550         if (whdr.flags & RXRPC_REQUEST_ACK)
551                 rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
552
553         switch (conn->params.local->srx.transport.family) {
554         case AF_INET6:
555         case AF_INET:
556                 ip_sock_set_mtu_discover(conn->params.local->socket->sk,
557                                 IP_PMTUDISC_DONT);
558                 rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag);
559                 ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
560                 conn->params.peer->last_tx_at = ktime_get_seconds();
561
562                 ip_sock_set_mtu_discover(conn->params.local->socket->sk,
563                                 IP_PMTUDISC_DO);
564                 break;
565
566         default:
567                 BUG();
568         }
569
570         if (ret < 0) {
571                 rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
572                 trace_rxrpc_tx_fail(call->debug_id, serial, ret,
573                                     rxrpc_tx_point_call_data_frag);
574         } else {
575                 trace_rxrpc_tx_packet(call->debug_id, &whdr,
576                                       rxrpc_tx_point_call_data_frag);
577         }
578         rxrpc_tx_backoff(call, ret);
579
580         up_write(&conn->params.local->defrag_sem);
581         goto done;
582 }
583
584 /*
585  * reject packets through the local endpoint
586  */
587 void rxrpc_reject_packets(struct rxrpc_local *local)
588 {
589         struct sockaddr_rxrpc srx;
590         struct rxrpc_skb_priv *sp;
591         struct rxrpc_wire_header whdr;
592         struct sk_buff *skb;
593         struct msghdr msg;
594         struct kvec iov[2];
595         size_t size;
596         __be32 code;
597         int ret, ioc;
598
599         _enter("%d", local->debug_id);
600
601         iov[0].iov_base = &whdr;
602         iov[0].iov_len = sizeof(whdr);
603         iov[1].iov_base = &code;
604         iov[1].iov_len = sizeof(code);
605
606         msg.msg_name = &srx.transport;
607         msg.msg_control = NULL;
608         msg.msg_controllen = 0;
609         msg.msg_flags = 0;
610
611         memset(&whdr, 0, sizeof(whdr));
612
613         while ((skb = skb_dequeue(&local->reject_queue))) {
614                 rxrpc_see_skb(skb, rxrpc_skb_seen);
615                 sp = rxrpc_skb(skb);
616
617                 switch (skb->mark) {
618                 case RXRPC_SKB_MARK_REJECT_BUSY:
619                         whdr.type = RXRPC_PACKET_TYPE_BUSY;
620                         size = sizeof(whdr);
621                         ioc = 1;
622                         break;
623                 case RXRPC_SKB_MARK_REJECT_ABORT:
624                         whdr.type = RXRPC_PACKET_TYPE_ABORT;
625                         code = htonl(skb->priority);
626                         size = sizeof(whdr) + sizeof(code);
627                         ioc = 2;
628                         break;
629                 default:
630                         rxrpc_free_skb(skb, rxrpc_skb_freed);
631                         continue;
632                 }
633
634                 if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
635                         msg.msg_namelen = srx.transport_len;
636
637                         whdr.epoch      = htonl(sp->hdr.epoch);
638                         whdr.cid        = htonl(sp->hdr.cid);
639                         whdr.callNumber = htonl(sp->hdr.callNumber);
640                         whdr.serviceId  = htons(sp->hdr.serviceId);
641                         whdr.flags      = sp->hdr.flags;
642                         whdr.flags      ^= RXRPC_CLIENT_INITIATED;
643                         whdr.flags      &= RXRPC_CLIENT_INITIATED;
644
645                         iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size);
646                         ret = do_udp_sendmsg(local->socket, &msg, size);
647                         if (ret < 0)
648                                 trace_rxrpc_tx_fail(local->debug_id, 0, ret,
649                                                     rxrpc_tx_point_reject);
650                         else
651                                 trace_rxrpc_tx_packet(local->debug_id, &whdr,
652                                                       rxrpc_tx_point_reject);
653                 }
654
655                 rxrpc_free_skb(skb, rxrpc_skb_freed);
656         }
657
658         _leave("");
659 }
660
661 /*
662  * Send a VERSION reply to a peer as a keepalive.
663  */
664 void rxrpc_send_keepalive(struct rxrpc_peer *peer)
665 {
666         struct rxrpc_wire_header whdr;
667         struct msghdr msg;
668         struct kvec iov[2];
669         size_t len;
670         int ret;
671
672         _enter("");
673
674         msg.msg_name    = &peer->srx.transport;
675         msg.msg_namelen = peer->srx.transport_len;
676         msg.msg_control = NULL;
677         msg.msg_controllen = 0;
678         msg.msg_flags   = 0;
679
680         whdr.epoch      = htonl(peer->local->rxnet->epoch);
681         whdr.cid        = 0;
682         whdr.callNumber = 0;
683         whdr.seq        = 0;
684         whdr.serial     = 0;
685         whdr.type       = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */
686         whdr.flags      = RXRPC_LAST_PACKET;
687         whdr.userStatus = 0;
688         whdr.securityIndex = 0;
689         whdr._rsvd      = 0;
690         whdr.serviceId  = 0;
691
692         iov[0].iov_base = &whdr;
693         iov[0].iov_len  = sizeof(whdr);
694         iov[1].iov_base = (char *)rxrpc_keepalive_string;
695         iov[1].iov_len  = sizeof(rxrpc_keepalive_string);
696
697         len = iov[0].iov_len + iov[1].iov_len;
698
699         _proto("Tx VERSION (keepalive)");
700
701         iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
702         ret = do_udp_sendmsg(peer->local->socket, &msg, len);
703         if (ret < 0)
704                 trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
705                                     rxrpc_tx_point_version_keepalive);
706         else
707                 trace_rxrpc_tx_packet(peer->debug_id, &whdr,
708                                       rxrpc_tx_point_version_keepalive);
709
710         peer->last_tx_at = ktime_get_seconds();
711         _leave("");
712 }