Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 2 | /* RxRPC packet transmission |
| 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 10 | #include <linux/net.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/gfp.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 12 | #include <linux/skbuff.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 14 | #include <net/sock.h> |
| 15 | #include <net/af_rxrpc.h> |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 16 | #include <net/udp.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 17 | #include "ar-internal.h" |
| 18 | |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 19 | extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); |
| 20 | |
David Howells | 6423ac2 | 2022-11-11 16:00:21 +0000 | [diff] [blame] | 21 | static ssize_t do_udp_sendmsg(struct socket *socket, struct msghdr *msg, size_t len) |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 22 | { |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 23 | struct sockaddr *sa = msg->msg_name; |
David Howells | 6423ac2 | 2022-11-11 16:00:21 +0000 | [diff] [blame] | 24 | struct sock *sk = socket->sk; |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 25 | |
David Howells | 6423ac2 | 2022-11-11 16:00:21 +0000 | [diff] [blame] | 26 | if (IS_ENABLED(CONFIG_AF_RXRPC_IPV6)) { |
| 27 | if (sa->sa_family == AF_INET6) { |
| 28 | if (sk->sk_family != AF_INET6) { |
| 29 | pr_warn("AF_INET6 address on AF_INET socket\n"); |
| 30 | return -ENOPROTOOPT; |
| 31 | } |
| 32 | return udpv6_sendmsg(sk, msg, len); |
| 33 | } |
| 34 | } |
| 35 | return udp_sendmsg(sk, msg, len); |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 36 | } |
| 37 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 38 | struct rxrpc_abort_buffer { |
| 39 | struct rxrpc_wire_header whdr; |
| 40 | __be32 abort_code; |
| 41 | }; |
| 42 | |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 43 | static const char rxrpc_keepalive_string[] = ""; |
| 44 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 45 | /* |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 46 | * Increase Tx backoff on transmission failure and clear it on success. |
| 47 | */ |
| 48 | static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret) |
| 49 | { |
| 50 | if (ret < 0) { |
| 51 | u16 tx_backoff = READ_ONCE(call->tx_backoff); |
| 52 | |
| 53 | if (tx_backoff < HZ) |
| 54 | WRITE_ONCE(call->tx_backoff, tx_backoff + 1); |
| 55 | } else { |
| 56 | WRITE_ONCE(call->tx_backoff, 0); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /* |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 61 | * Arrange for a keepalive ping a certain time after we last transmitted. This |
| 62 | * lets the far side know we're still interested in this call and helps keep |
| 63 | * the route through any intervening firewall open. |
| 64 | * |
| 65 | * Receiving a response to the ping will prevent the ->expect_rx_by timer from |
| 66 | * expiring. |
| 67 | */ |
| 68 | static void rxrpc_set_keepalive(struct rxrpc_call *call) |
| 69 | { |
| 70 | unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6; |
| 71 | |
| 72 | keepalive_at += now; |
| 73 | WRITE_ONCE(call->keepalive_at, keepalive_at); |
| 74 | rxrpc_reduce_call_timer(call, keepalive_at, now, |
| 75 | rxrpc_timer_set_for_keepalive); |
| 76 | } |
| 77 | |
| 78 | /* |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 79 | * Fill out an ACK packet. |
| 80 | */ |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 81 | static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn, |
| 82 | struct rxrpc_call *call, |
David Howells | f789bff | 2023-01-31 15:31:49 +0000 | [diff] [blame] | 83 | struct rxrpc_txbuf *txb, |
| 84 | u16 *_rwind) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 85 | { |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 86 | struct rxrpc_ackinfo ackinfo; |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 87 | unsigned int qsize, sack, wrap, to; |
| 88 | rxrpc_seq_t window, wtop; |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 89 | int rsize; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 90 | u32 mtu, jmax; |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 91 | u8 *ackp = txb->acks; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 92 | |
David Howells | 5bbf9533 | 2022-10-17 11:44:22 +0100 | [diff] [blame] | 93 | call->ackr_nr_unacked = 0; |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 94 | atomic_set(&call->ackr_nr_consumed, 0); |
David Howells | f2a676d | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 95 | rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill); |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 96 | clear_bit(RXRPC_CALL_RX_IS_IDLE, &call->flags); |
David Howells | 9a3dedc | 2022-05-21 09:03:31 +0100 | [diff] [blame] | 97 | |
David Howells | 5bbf9533 | 2022-10-17 11:44:22 +0100 | [diff] [blame] | 98 | window = call->ackr_window; |
| 99 | wtop = call->ackr_wtop; |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 100 | sack = call->ackr_sack_base % RXRPC_SACK_SIZE; |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 101 | txb->ack.firstPacket = htonl(window); |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 102 | txb->ack.nAcks = wtop - window; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 103 | |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 104 | if (after(wtop, window)) { |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 105 | wrap = RXRPC_SACK_SIZE - sack; |
| 106 | to = min_t(unsigned int, txb->ack.nAcks, RXRPC_SACK_SIZE); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 107 | |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 108 | if (sack + txb->ack.nAcks <= RXRPC_SACK_SIZE) { |
| 109 | memcpy(txb->acks, call->ackr_sack_table + sack, txb->ack.nAcks); |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 110 | } else { |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 111 | memcpy(txb->acks, call->ackr_sack_table + sack, wrap); |
| 112 | memcpy(txb->acks + wrap, call->ackr_sack_table, |
| 113 | to - wrap); |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 114 | } |
| 115 | |
David Howells | f21e934 | 2022-10-16 08:01:32 +0100 | [diff] [blame] | 116 | ackp += to; |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 117 | } else if (before(wtop, window)) { |
| 118 | pr_warn("ack window backward %x %x", window, wtop); |
David Howells | 530403d | 2020-01-30 21:48:14 +0000 | [diff] [blame] | 119 | } else if (txb->ack.reason == RXRPC_ACK_DELAY) { |
| 120 | txb->ack.reason = RXRPC_ACK_IDLE; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 121 | } |
| 122 | |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 123 | mtu = conn->peer->if_mtu; |
| 124 | mtu -= conn->peer->hdrsize; |
David Howells | d4d02d8 | 2022-10-07 17:44:39 +0100 | [diff] [blame] | 125 | jmax = rxrpc_rx_jumbo_max; |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 126 | qsize = (window - 1) - call->rx_consumed; |
| 127 | rsize = max_t(int, call->rx_winsize - qsize, 0); |
David Howells | f789bff | 2023-01-31 15:31:49 +0000 | [diff] [blame] | 128 | *_rwind = rsize; |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 129 | ackinfo.rxMTU = htonl(rxrpc_rx_mtu); |
| 130 | ackinfo.maxMTU = htonl(mtu); |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 131 | ackinfo.rwind = htonl(rsize); |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 132 | ackinfo.jumbo_max = htonl(jmax); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 133 | |
| 134 | *ackp++ = 0; |
| 135 | *ackp++ = 0; |
| 136 | *ackp++ = 0; |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 137 | memcpy(ackp, &ackinfo, sizeof(ackinfo)); |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 138 | return txb->ack.nAcks + 3 + sizeof(ackinfo); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 142 | * Record the beginning of an RTT probe. |
| 143 | */ |
| 144 | static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial, |
| 145 | enum rxrpc_rtt_tx_trace why) |
| 146 | { |
| 147 | unsigned long avail = call->rtt_avail; |
| 148 | int rtt_slot = 9; |
| 149 | |
| 150 | if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK)) |
| 151 | goto no_slot; |
| 152 | |
| 153 | rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK); |
| 154 | if (!test_and_clear_bit(rtt_slot, &call->rtt_avail)) |
| 155 | goto no_slot; |
| 156 | |
| 157 | call->rtt_serial[rtt_slot] = serial; |
| 158 | call->rtt_sent_at[rtt_slot] = ktime_get_real(); |
| 159 | smp_wmb(); /* Write data before avail bit */ |
| 160 | set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); |
| 161 | |
| 162 | trace_rxrpc_rtt_tx(call, why, rtt_slot, serial); |
| 163 | return rtt_slot; |
| 164 | |
| 165 | no_slot: |
| 166 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial); |
| 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Cancel an RTT probe. |
| 172 | */ |
| 173 | static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call, |
| 174 | rxrpc_serial_t serial, int rtt_slot) |
| 175 | { |
| 176 | if (rtt_slot != -1) { |
| 177 | clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); |
| 178 | smp_wmb(); /* Clear pending bit before setting slot */ |
| 179 | set_bit(rtt_slot, &call->rtt_avail); |
| 180 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /* |
David Howells | b034684 | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 185 | * Transmit an ACK packet. |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 186 | */ |
David Howells | b034684 | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 187 | int rxrpc_send_ack_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 188 | { |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 189 | struct rxrpc_connection *conn; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 190 | struct msghdr msg; |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 191 | struct kvec iov[1]; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 192 | rxrpc_serial_t serial; |
| 193 | size_t len, n; |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 194 | int ret, rtt_slot = -1; |
David Howells | f789bff | 2023-01-31 15:31:49 +0000 | [diff] [blame] | 195 | u16 rwind; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 196 | |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 197 | if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags)) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 198 | return -ECONNRESET; |
| 199 | |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 200 | conn = call->conn; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 201 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 202 | msg.msg_name = &call->peer->srx.transport; |
| 203 | msg.msg_namelen = call->peer->srx.transport_len; |
| 204 | msg.msg_control = NULL; |
| 205 | msg.msg_controllen = 0; |
| 206 | msg.msg_flags = 0; |
| 207 | |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 208 | if (txb->ack.reason == RXRPC_ACK_PING) |
| 209 | txb->wire.flags |= RXRPC_REQUEST_ACK; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 210 | |
David Howells | f789bff | 2023-01-31 15:31:49 +0000 | [diff] [blame] | 211 | n = rxrpc_fill_out_ack(conn, call, txb, &rwind); |
David Howells | 4e76bd4 | 2022-05-06 16:13:13 +0100 | [diff] [blame] | 212 | if (n == 0) |
David Howells | 9a3dedc | 2022-05-21 09:03:31 +0100 | [diff] [blame] | 213 | return 0; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 214 | |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 215 | iov[0].iov_base = &txb->wire; |
| 216 | iov[0].iov_len = sizeof(txb->wire) + sizeof(txb->ack) + n; |
| 217 | len = iov[0].iov_len; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 218 | |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 219 | serial = atomic_inc_return(&conn->serial); |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 220 | txb->wire.serial = htonl(serial); |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 221 | trace_rxrpc_tx_ack(call->debug_id, serial, |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 222 | ntohl(txb->ack.firstPacket), |
David Howells | f789bff | 2023-01-31 15:31:49 +0000 | [diff] [blame] | 223 | ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks, |
| 224 | rwind); |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 225 | |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 226 | if (txb->ack.reason == RXRPC_ACK_PING) |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 227 | rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 228 | |
David Howells | f2a676d | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 229 | rxrpc_inc_stat(call->rxnet, stat_tx_ack_send); |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 230 | |
David Howells | 5d7edbc | 2022-08-27 14:27:56 +0100 | [diff] [blame] | 231 | /* Grab the highest received seq as late as possible */ |
| 232 | txb->ack.previousPacket = htonl(call->rx_highest_seq); |
| 233 | |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 234 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len); |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 235 | ret = do_udp_sendmsg(conn->local->socket, &msg, len); |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 236 | call->peer->last_tx_at = ktime_get_seconds(); |
David Howells | 84e28aa | 2022-10-17 10:55:41 +0100 | [diff] [blame] | 237 | if (ret < 0) { |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 238 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 239 | rxrpc_tx_point_call_ack); |
David Howells | 84e28aa | 2022-10-17 10:55:41 +0100 | [diff] [blame] | 240 | } else { |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 241 | trace_rxrpc_tx_packet(call->debug_id, &txb->wire, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 242 | rxrpc_tx_point_call_ack); |
David Howells | 84e28aa | 2022-10-17 10:55:41 +0100 | [diff] [blame] | 243 | if (txb->wire.flags & RXRPC_REQUEST_ACK) |
| 244 | call->peer->rtt_last_req = ktime_get_real(); |
| 245 | } |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 246 | rxrpc_tx_backoff(call, ret); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 247 | |
David Howells | 96b4059 | 2022-10-27 11:25:55 +0100 | [diff] [blame] | 248 | if (!__rxrpc_call_is_complete(call)) { |
David Howells | 72f0c6f | 2020-01-30 21:48:13 +0000 | [diff] [blame] | 249 | if (ret < 0) |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 250 | rxrpc_cancel_rtt_probe(call, serial, rtt_slot); |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 251 | rxrpc_set_keepalive(call); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 252 | } |
| 253 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 254 | return ret; |
| 255 | } |
| 256 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 257 | /* |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 258 | * Send an ABORT call packet. |
| 259 | */ |
| 260 | int rxrpc_send_abort_packet(struct rxrpc_call *call) |
| 261 | { |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 262 | struct rxrpc_connection *conn; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 263 | struct rxrpc_abort_buffer pkt; |
| 264 | struct msghdr msg; |
| 265 | struct kvec iov[1]; |
| 266 | rxrpc_serial_t serial; |
| 267 | int ret; |
| 268 | |
David Howells | dcbefc3 | 2017-11-02 15:06:26 +0000 | [diff] [blame] | 269 | /* Don't bother sending aborts for a client call once the server has |
| 270 | * hard-ACK'd all of its request data. After that point, we're not |
| 271 | * going to stop the operation proceeding, and whilst we might limit |
| 272 | * the reply, it's not worth it if we can send a new call on the same |
| 273 | * channel instead, thereby closing off this call. |
| 274 | */ |
| 275 | if (rxrpc_is_client_call(call) && |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 276 | test_bit(RXRPC_CALL_TX_ALL_ACKED, &call->flags)) |
David Howells | dcbefc3 | 2017-11-02 15:06:26 +0000 | [diff] [blame] | 277 | return 0; |
| 278 | |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 279 | if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags)) |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 280 | return -ECONNRESET; |
| 281 | |
David Howells | 5273a19 | 2020-01-30 21:50:36 +0000 | [diff] [blame] | 282 | conn = call->conn; |
| 283 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 284 | msg.msg_name = &call->peer->srx.transport; |
| 285 | msg.msg_namelen = call->peer->srx.transport_len; |
| 286 | msg.msg_control = NULL; |
| 287 | msg.msg_controllen = 0; |
| 288 | msg.msg_flags = 0; |
| 289 | |
| 290 | pkt.whdr.epoch = htonl(conn->proto.epoch); |
| 291 | pkt.whdr.cid = htonl(call->cid); |
| 292 | pkt.whdr.callNumber = htonl(call->call_id); |
| 293 | pkt.whdr.seq = 0; |
| 294 | pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 295 | pkt.whdr.flags = conn->out_clientflag; |
| 296 | pkt.whdr.userStatus = 0; |
| 297 | pkt.whdr.securityIndex = call->security_ix; |
| 298 | pkt.whdr._rsvd = 0; |
David Howells | f3441d4 | 2022-10-20 21:58:36 +0100 | [diff] [blame] | 299 | pkt.whdr.serviceId = htons(call->dest_srx.srx_service); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 300 | pkt.abort_code = htonl(call->abort_code); |
| 301 | |
| 302 | iov[0].iov_base = &pkt; |
| 303 | iov[0].iov_len = sizeof(pkt); |
| 304 | |
| 305 | serial = atomic_inc_return(&conn->serial); |
| 306 | pkt.whdr.serial = htonl(serial); |
| 307 | |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 308 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt)); |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 309 | ret = do_udp_sendmsg(conn->local->socket, &msg, sizeof(pkt)); |
| 310 | conn->peer->last_tx_at = ktime_get_seconds(); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 311 | if (ret < 0) |
| 312 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 313 | rxrpc_tx_point_call_abort); |
| 314 | else |
| 315 | trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr, |
| 316 | rxrpc_tx_point_call_abort); |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 317 | rxrpc_tx_backoff(call, ret); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 322 | * send a packet through the transport endpoint |
| 323 | */ |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 324 | int rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 325 | { |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 326 | enum rxrpc_req_ack_trace why; |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 327 | struct rxrpc_connection *conn = call->conn; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 328 | struct msghdr msg; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 329 | struct kvec iov[1]; |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 330 | rxrpc_serial_t serial; |
| 331 | size_t len; |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 332 | int ret, rtt_slot = -1; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 333 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 334 | _enter("%x,{%d}", txb->seq, txb->len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 335 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 336 | /* Each transmission of a Tx packet needs a new serial number */ |
| 337 | serial = atomic_inc_return(&conn->serial); |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 338 | txb->wire.serial = htonl(serial); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 339 | |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 340 | if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) && |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 341 | txb->seq == 1) |
| 342 | txb->wire.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE; |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 343 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 344 | iov[0].iov_base = &txb->wire; |
| 345 | iov[0].iov_len = sizeof(txb->wire) + txb->len; |
| 346 | len = iov[0].iov_len; |
| 347 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 348 | |
| 349 | msg.msg_name = &call->peer->srx.transport; |
| 350 | msg.msg_namelen = call->peer->srx.transport_len; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 351 | msg.msg_control = NULL; |
| 352 | msg.msg_controllen = 0; |
| 353 | msg.msg_flags = 0; |
| 354 | |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 355 | /* If our RTT cache needs working on, request an ACK. Also request |
| 356 | * ACKs if a DATA packet appears to have been lost. |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 357 | * |
| 358 | * However, we mustn't request an ACK on the last reply packet of a |
| 359 | * service call, lest OpenAFS incorrectly send us an ACK with some |
| 360 | * soft-ACKs in it and then never follow up with a proper hard ACK. |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 361 | */ |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 362 | if (txb->wire.flags & RXRPC_REQUEST_ACK) |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 363 | why = rxrpc_reqack_already_on; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 364 | else if (test_bit(RXRPC_TXBUF_LAST, &txb->flags) && rxrpc_sending_to_client(txb)) |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 365 | why = rxrpc_reqack_no_srv_last; |
| 366 | else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events)) |
| 367 | why = rxrpc_reqack_ack_lost; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 368 | else if (test_bit(RXRPC_TXBUF_RESENT, &txb->flags)) |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 369 | why = rxrpc_reqack_retrans; |
| 370 | else if (call->cong_mode == RXRPC_CALL_SLOW_START && call->cong_cwnd <= 2) |
| 371 | why = rxrpc_reqack_slow_start; |
| 372 | else if (call->tx_winsize <= 2) |
| 373 | why = rxrpc_reqack_small_txwin; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 374 | else if (call->peer->rtt_count < 3 && txb->seq & 1) |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 375 | why = rxrpc_reqack_more_rtt; |
| 376 | else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), ktime_get_real())) |
| 377 | why = rxrpc_reqack_old_rtt; |
| 378 | else |
| 379 | goto dont_set_request_ack; |
| 380 | |
David Howells | f7fa524 | 2022-08-18 11:52:36 +0100 | [diff] [blame] | 381 | rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]); |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 382 | trace_rxrpc_req_ack(call->debug_id, txb->seq, why); |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 383 | if (why != rxrpc_reqack_no_srv_last) |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 384 | txb->wire.flags |= RXRPC_REQUEST_ACK; |
David Howells | 4d843be | 2022-04-05 21:48:48 +0100 | [diff] [blame] | 385 | dont_set_request_ack: |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 386 | |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 387 | if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { |
| 388 | static int lose; |
| 389 | if ((lose++ & 7) == 7) { |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 390 | ret = 0; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 391 | trace_rxrpc_tx_data(call, txb->seq, serial, |
| 392 | txb->wire.flags, |
| 393 | test_bit(RXRPC_TXBUF_RESENT, &txb->flags), |
| 394 | true); |
Arnd Bergmann | 526949e | 2019-03-22 15:18:43 +0100 | [diff] [blame] | 395 | goto done; |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 399 | trace_rxrpc_tx_data(call, txb->seq, serial, txb->wire.flags, |
| 400 | test_bit(RXRPC_TXBUF_RESENT, &txb->flags), false); |
David Howells | cf37b59 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 401 | |
| 402 | /* Track what we've attempted to transmit at least once so that the |
| 403 | * retransmission algorithm doesn't try to resend what we haven't sent |
| 404 | * yet. However, this can race as we can receive an ACK before we get |
| 405 | * to this point. But, OTOH, if we won't get an ACK mentioning this |
| 406 | * packet unless the far side received it (though it could have |
| 407 | * discarded it anyway and NAK'd it). |
| 408 | */ |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 409 | cmpxchg(&call->tx_transmitted, txb->seq - 1, txb->seq); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 410 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 411 | /* send the packet with the don't fragment bit set if we currently |
| 412 | * think it's small enough */ |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 413 | if (txb->len >= call->peer->maxdata) |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 414 | goto send_fragmentable; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 415 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 416 | txb->last_sent = ktime_get_real(); |
| 417 | if (txb->wire.flags & RXRPC_REQUEST_ACK) |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 418 | rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data); |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 419 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 420 | /* send the packet by UDP |
| 421 | * - returns -EMSGSIZE if UDP would have to fragment the packet |
| 422 | * to go out of the interface |
| 423 | * - in which case, we'll have processed the ICMP error |
| 424 | * message and update the peer record |
| 425 | */ |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 426 | rxrpc_inc_stat(call->rxnet, stat_tx_data_send); |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 427 | ret = do_udp_sendmsg(conn->local->socket, &msg, len); |
| 428 | conn->peer->last_tx_at = ktime_get_seconds(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 429 | |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 430 | if (ret < 0) { |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 431 | rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 432 | rxrpc_cancel_rtt_probe(call, serial, rtt_slot); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 433 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 434 | rxrpc_tx_point_call_data_nofrag); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 435 | } else { |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 436 | trace_rxrpc_tx_packet(call->debug_id, &txb->wire, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 437 | rxrpc_tx_point_call_data_nofrag); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 438 | } |
| 439 | |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 440 | rxrpc_tx_backoff(call, ret); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 441 | if (ret == -EMSGSIZE) |
| 442 | goto send_fragmentable; |
| 443 | |
| 444 | done: |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 445 | if (ret >= 0) { |
David Howells | 1fc4fa2 | 2022-10-03 18:49:11 +0100 | [diff] [blame] | 446 | call->tx_last_sent = txb->last_sent; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 447 | if (txb->wire.flags & RXRPC_REQUEST_ACK) { |
| 448 | call->peer->rtt_last_req = txb->last_sent; |
David Howells | c410bf01 | 2020-05-11 14:54:34 +0100 | [diff] [blame] | 449 | if (call->peer->rtt_count > 1) { |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 450 | unsigned long nowj = jiffies, ack_lost_at; |
| 451 | |
David Howells | 2c13c05 | 2022-01-21 23:12:58 +0000 | [diff] [blame] | 452 | ack_lost_at = rxrpc_get_rto_backoff(call->peer, false); |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 453 | ack_lost_at += nowj; |
| 454 | WRITE_ONCE(call->ack_lost_at, ack_lost_at); |
| 455 | rxrpc_reduce_call_timer(call, ack_lost_at, nowj, |
| 456 | rxrpc_timer_set_for_lost_ack); |
| 457 | } |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 458 | } |
David Howells | c54e43d | 2018-05-10 23:26:00 +0100 | [diff] [blame] | 459 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 460 | if (txb->seq == 1 && |
David Howells | c54e43d | 2018-05-10 23:26:00 +0100 | [diff] [blame] | 461 | !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, |
| 462 | &call->flags)) { |
| 463 | unsigned long nowj = jiffies, expect_rx_by; |
| 464 | |
| 465 | expect_rx_by = nowj + call->next_rx_timo; |
| 466 | WRITE_ONCE(call->expect_rx_by, expect_rx_by); |
| 467 | rxrpc_reduce_call_timer(call, expect_rx_by, nowj, |
| 468 | rxrpc_timer_set_for_normal); |
| 469 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 470 | |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 471 | rxrpc_set_keepalive(call); |
| 472 | } else { |
| 473 | /* Cancel the call if the initial transmission fails, |
| 474 | * particularly if that's due to network routing issues that |
| 475 | * aren't going away anytime soon. The layer above can arrange |
| 476 | * the retransmission. |
| 477 | */ |
| 478 | if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags)) |
| 479 | rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, |
| 480 | RX_USER_ABORT, ret); |
| 481 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 482 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 483 | _leave(" = %d [%u]", ret, call->peer->maxdata); |
| 484 | return ret; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 485 | |
| 486 | send_fragmentable: |
| 487 | /* attempt to send this message with fragmentation enabled */ |
| 488 | _debug("send fragment"); |
| 489 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 490 | txb->last_sent = ktime_get_real(); |
| 491 | if (txb->wire.flags & RXRPC_REQUEST_ACK) |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 492 | rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data); |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 493 | |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 494 | switch (conn->local->srx.transport.family) { |
David Howells | 0e631ee | 2020-04-13 13:57:14 +0100 | [diff] [blame] | 495 | case AF_INET6: |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 496 | case AF_INET: |
David Howells | 8722014 | 2024-01-09 15:10:48 +0000 | [diff] [blame] | 497 | rxrpc_local_dont_fragment(conn->local, false); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 498 | rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag); |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 499 | ret = do_udp_sendmsg(conn->local->socket, &msg, len); |
| 500 | conn->peer->last_tx_at = ktime_get_seconds(); |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 501 | |
David Howells | 8722014 | 2024-01-09 15:10:48 +0000 | [diff] [blame] | 502 | rxrpc_local_dont_fragment(conn->local, true); |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 503 | break; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 504 | |
David Howells | 3427beb | 2019-07-02 15:55:28 +0100 | [diff] [blame] | 505 | default: |
| 506 | BUG(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 507 | } |
| 508 | |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 509 | if (ret < 0) { |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 510 | rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 511 | rxrpc_cancel_rtt_probe(call, serial, rtt_slot); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 512 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 513 | rxrpc_tx_point_call_data_frag); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 514 | } else { |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 515 | trace_rxrpc_tx_packet(call->debug_id, &txb->wire, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 516 | rxrpc_tx_point_call_data_frag); |
David Howells | 4700c4d | 2020-08-19 23:29:16 +0100 | [diff] [blame] | 517 | } |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 518 | rxrpc_tx_backoff(call, ret); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 519 | goto done; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 520 | } |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 521 | |
| 522 | /* |
David Howells | a00ce28 | 2022-10-20 09:56:36 +0100 | [diff] [blame] | 523 | * Transmit a connection-level abort. |
| 524 | */ |
| 525 | void rxrpc_send_conn_abort(struct rxrpc_connection *conn) |
| 526 | { |
| 527 | struct rxrpc_wire_header whdr; |
| 528 | struct msghdr msg; |
| 529 | struct kvec iov[2]; |
| 530 | __be32 word; |
| 531 | size_t len; |
| 532 | u32 serial; |
| 533 | int ret; |
| 534 | |
| 535 | msg.msg_name = &conn->peer->srx.transport; |
| 536 | msg.msg_namelen = conn->peer->srx.transport_len; |
| 537 | msg.msg_control = NULL; |
| 538 | msg.msg_controllen = 0; |
| 539 | msg.msg_flags = 0; |
| 540 | |
| 541 | whdr.epoch = htonl(conn->proto.epoch); |
| 542 | whdr.cid = htonl(conn->proto.cid); |
| 543 | whdr.callNumber = 0; |
| 544 | whdr.seq = 0; |
| 545 | whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 546 | whdr.flags = conn->out_clientflag; |
| 547 | whdr.userStatus = 0; |
| 548 | whdr.securityIndex = conn->security_ix; |
| 549 | whdr._rsvd = 0; |
| 550 | whdr.serviceId = htons(conn->service_id); |
| 551 | |
| 552 | word = htonl(conn->abort_code); |
| 553 | |
| 554 | iov[0].iov_base = &whdr; |
| 555 | iov[0].iov_len = sizeof(whdr); |
| 556 | iov[1].iov_base = &word; |
| 557 | iov[1].iov_len = sizeof(word); |
| 558 | |
| 559 | len = iov[0].iov_len + iov[1].iov_len; |
| 560 | |
| 561 | serial = atomic_inc_return(&conn->serial); |
| 562 | whdr.serial = htonl(serial); |
| 563 | |
| 564 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len); |
| 565 | ret = do_udp_sendmsg(conn->local->socket, &msg, len); |
| 566 | if (ret < 0) { |
| 567 | trace_rxrpc_tx_fail(conn->debug_id, serial, ret, |
| 568 | rxrpc_tx_point_conn_abort); |
| 569 | _debug("sendmsg failed: %d", ret); |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort); |
| 574 | |
| 575 | conn->peer->last_tx_at = ktime_get_seconds(); |
| 576 | } |
| 577 | |
| 578 | /* |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 579 | * Reject a packet through the local endpoint. |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 580 | */ |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 581 | void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb) |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 582 | { |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 583 | struct rxrpc_wire_header whdr; |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 584 | struct sockaddr_rxrpc srx; |
| 585 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 586 | struct msghdr msg; |
| 587 | struct kvec iov[2]; |
| 588 | size_t size; |
| 589 | __be32 code; |
David Howells | ece64fe | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 590 | int ret, ioc; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 591 | |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 592 | rxrpc_see_skb(skb, rxrpc_skb_see_reject); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 593 | |
| 594 | iov[0].iov_base = &whdr; |
| 595 | iov[0].iov_len = sizeof(whdr); |
| 596 | iov[1].iov_base = &code; |
| 597 | iov[1].iov_len = sizeof(code); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 598 | |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 599 | msg.msg_name = &srx.transport; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 600 | msg.msg_control = NULL; |
| 601 | msg.msg_controllen = 0; |
| 602 | msg.msg_flags = 0; |
| 603 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 604 | memset(&whdr, 0, sizeof(whdr)); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 605 | |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 606 | switch (skb->mark) { |
| 607 | case RXRPC_SKB_MARK_REJECT_BUSY: |
| 608 | whdr.type = RXRPC_PACKET_TYPE_BUSY; |
| 609 | size = sizeof(whdr); |
| 610 | ioc = 1; |
| 611 | break; |
| 612 | case RXRPC_SKB_MARK_REJECT_ABORT: |
| 613 | whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 614 | code = htonl(skb->priority); |
| 615 | size = sizeof(whdr) + sizeof(code); |
| 616 | ioc = 2; |
| 617 | break; |
| 618 | default: |
| 619 | return; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 620 | } |
| 621 | |
David Howells | 5e6ef4f | 2020-01-23 13:13:41 +0000 | [diff] [blame] | 622 | if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) { |
| 623 | msg.msg_namelen = srx.transport_len; |
| 624 | |
| 625 | whdr.epoch = htonl(sp->hdr.epoch); |
| 626 | whdr.cid = htonl(sp->hdr.cid); |
| 627 | whdr.callNumber = htonl(sp->hdr.callNumber); |
| 628 | whdr.serviceId = htons(sp->hdr.serviceId); |
| 629 | whdr.flags = sp->hdr.flags; |
| 630 | whdr.flags ^= RXRPC_CLIENT_INITIATED; |
| 631 | whdr.flags &= RXRPC_CLIENT_INITIATED; |
| 632 | |
| 633 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size); |
| 634 | ret = do_udp_sendmsg(local->socket, &msg, size); |
| 635 | if (ret < 0) |
| 636 | trace_rxrpc_tx_fail(local->debug_id, 0, ret, |
| 637 | rxrpc_tx_point_reject); |
| 638 | else |
| 639 | trace_rxrpc_tx_packet(local->debug_id, &whdr, |
| 640 | rxrpc_tx_point_reject); |
| 641 | } |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 642 | } |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * Send a VERSION reply to a peer as a keepalive. |
| 646 | */ |
| 647 | void rxrpc_send_keepalive(struct rxrpc_peer *peer) |
| 648 | { |
| 649 | struct rxrpc_wire_header whdr; |
| 650 | struct msghdr msg; |
| 651 | struct kvec iov[2]; |
| 652 | size_t len; |
| 653 | int ret; |
| 654 | |
| 655 | _enter(""); |
| 656 | |
| 657 | msg.msg_name = &peer->srx.transport; |
| 658 | msg.msg_namelen = peer->srx.transport_len; |
| 659 | msg.msg_control = NULL; |
| 660 | msg.msg_controllen = 0; |
| 661 | msg.msg_flags = 0; |
| 662 | |
| 663 | whdr.epoch = htonl(peer->local->rxnet->epoch); |
| 664 | whdr.cid = 0; |
| 665 | whdr.callNumber = 0; |
| 666 | whdr.seq = 0; |
| 667 | whdr.serial = 0; |
| 668 | whdr.type = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */ |
| 669 | whdr.flags = RXRPC_LAST_PACKET; |
| 670 | whdr.userStatus = 0; |
| 671 | whdr.securityIndex = 0; |
| 672 | whdr._rsvd = 0; |
| 673 | whdr.serviceId = 0; |
| 674 | |
| 675 | iov[0].iov_base = &whdr; |
| 676 | iov[0].iov_len = sizeof(whdr); |
| 677 | iov[1].iov_base = (char *)rxrpc_keepalive_string; |
| 678 | iov[1].iov_len = sizeof(rxrpc_keepalive_string); |
| 679 | |
| 680 | len = iov[0].iov_len + iov[1].iov_len; |
| 681 | |
David Howells | ed472b0 | 2022-03-22 11:07:20 +0000 | [diff] [blame] | 682 | iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len); |
| 683 | ret = do_udp_sendmsg(peer->local->socket, &msg, len); |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 684 | if (ret < 0) |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 685 | trace_rxrpc_tx_fail(peer->debug_id, 0, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 686 | rxrpc_tx_point_version_keepalive); |
| 687 | else |
| 688 | trace_rxrpc_tx_packet(peer->debug_id, &whdr, |
| 689 | rxrpc_tx_point_version_keepalive); |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 690 | |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 691 | peer->last_tx_at = ktime_get_seconds(); |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 692 | _leave(""); |
| 693 | } |
David Howells | cf37b59 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 694 | |
| 695 | /* |
| 696 | * Schedule an instant Tx resend. |
| 697 | */ |
| 698 | static inline void rxrpc_instant_resend(struct rxrpc_call *call, |
| 699 | struct rxrpc_txbuf *txb) |
| 700 | { |
David Howells | 96b4059 | 2022-10-27 11:25:55 +0100 | [diff] [blame] | 701 | if (!__rxrpc_call_is_complete(call)) |
David Howells | cf37b59 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 702 | kdebug("resend"); |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Transmit one packet. |
| 707 | */ |
| 708 | void rxrpc_transmit_one(struct rxrpc_call *call, struct rxrpc_txbuf *txb) |
| 709 | { |
| 710 | int ret; |
| 711 | |
| 712 | ret = rxrpc_send_data_packet(call, txb); |
| 713 | if (ret < 0) { |
| 714 | switch (ret) { |
| 715 | case -ENETUNREACH: |
| 716 | case -EHOSTUNREACH: |
| 717 | case -ECONNREFUSED: |
| 718 | rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, |
| 719 | 0, ret); |
| 720 | break; |
| 721 | default: |
| 722 | _debug("need instant resend %d", ret); |
| 723 | rxrpc_instant_resend(call, txb); |
| 724 | } |
| 725 | } else { |
| 726 | unsigned long now = jiffies; |
| 727 | unsigned long resend_at = now + call->peer->rto_j; |
| 728 | |
| 729 | WRITE_ONCE(call->resend_at, resend_at); |
| 730 | rxrpc_reduce_call_timer(call, resend_at, now, |
| 731 | rxrpc_timer_set_for_send); |
| 732 | } |
| 733 | } |