12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28c3e34a4SDavid Howells /* RxRPC packet transmission
38c3e34a4SDavid Howells *
48c3e34a4SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
58c3e34a4SDavid Howells * Written by David Howells (dhowells@redhat.com)
68c3e34a4SDavid Howells */
78c3e34a4SDavid Howells
88c3e34a4SDavid Howells #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
98c3e34a4SDavid Howells
108c3e34a4SDavid Howells #include <linux/net.h>
118c3e34a4SDavid Howells #include <linux/gfp.h>
128c3e34a4SDavid Howells #include <linux/skbuff.h>
138c3e34a4SDavid Howells #include <linux/export.h>
148c3e34a4SDavid Howells #include <net/sock.h>
158c3e34a4SDavid Howells #include <net/af_rxrpc.h>
16ed472b0cSDavid Howells #include <net/udp.h>
178c3e34a4SDavid Howells #include "ar-internal.h"
188c3e34a4SDavid Howells
19ed472b0cSDavid Howells extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
20ed472b0cSDavid Howells
do_udp_sendmsg(struct socket * socket,struct msghdr * msg,size_t len)216423ac2eSDavid Howells static ssize_t do_udp_sendmsg(struct socket *socket, struct msghdr *msg, size_t len)
22ed472b0cSDavid Howells {
23ed472b0cSDavid Howells struct sockaddr *sa = msg->msg_name;
246423ac2eSDavid Howells struct sock *sk = socket->sk;
25ed472b0cSDavid Howells
266423ac2eSDavid Howells if (IS_ENABLED(CONFIG_AF_RXRPC_IPV6)) {
276423ac2eSDavid Howells if (sa->sa_family == AF_INET6) {
286423ac2eSDavid Howells if (sk->sk_family != AF_INET6) {
296423ac2eSDavid Howells pr_warn("AF_INET6 address on AF_INET socket\n");
306423ac2eSDavid Howells return -ENOPROTOOPT;
316423ac2eSDavid Howells }
326423ac2eSDavid Howells return udpv6_sendmsg(sk, msg, len);
336423ac2eSDavid Howells }
346423ac2eSDavid Howells }
356423ac2eSDavid Howells return udp_sendmsg(sk, msg, len);
36ed472b0cSDavid Howells }
37ed472b0cSDavid Howells
3826cb02aaSDavid Howells struct rxrpc_abort_buffer {
3926cb02aaSDavid Howells struct rxrpc_wire_header whdr;
4026cb02aaSDavid Howells __be32 abort_code;
4126cb02aaSDavid Howells };
4226cb02aaSDavid Howells
43ace45becSDavid Howells static const char rxrpc_keepalive_string[] = "";
44ace45becSDavid Howells
458d94aa38SDavid Howells /*
46c7e86acfSDavid Howells * Increase Tx backoff on transmission failure and clear it on success.
47c7e86acfSDavid Howells */
rxrpc_tx_backoff(struct rxrpc_call * call,int ret)48c7e86acfSDavid Howells static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret)
49c7e86acfSDavid Howells {
50c7e86acfSDavid Howells if (ret < 0) {
51c7e86acfSDavid Howells u16 tx_backoff = READ_ONCE(call->tx_backoff);
52c7e86acfSDavid Howells
53c7e86acfSDavid Howells if (tx_backoff < HZ)
54c7e86acfSDavid Howells WRITE_ONCE(call->tx_backoff, tx_backoff + 1);
55c7e86acfSDavid Howells } else {
56c7e86acfSDavid Howells WRITE_ONCE(call->tx_backoff, 0);
57c7e86acfSDavid Howells }
58c7e86acfSDavid Howells }
59c7e86acfSDavid Howells
60c7e86acfSDavid Howells /*
61415f44e4SDavid Howells * Arrange for a keepalive ping a certain time after we last transmitted. This
62415f44e4SDavid Howells * lets the far side know we're still interested in this call and helps keep
63415f44e4SDavid Howells * the route through any intervening firewall open.
64415f44e4SDavid Howells *
65415f44e4SDavid Howells * Receiving a response to the ping will prevent the ->expect_rx_by timer from
66415f44e4SDavid Howells * expiring.
67415f44e4SDavid Howells */
rxrpc_set_keepalive(struct rxrpc_call * call)68415f44e4SDavid Howells static void rxrpc_set_keepalive(struct rxrpc_call *call)
69415f44e4SDavid Howells {
70415f44e4SDavid Howells unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6;
71415f44e4SDavid Howells
72415f44e4SDavid Howells keepalive_at += now;
73415f44e4SDavid Howells WRITE_ONCE(call->keepalive_at, keepalive_at);
74415f44e4SDavid Howells rxrpc_reduce_call_timer(call, keepalive_at, now,
75415f44e4SDavid Howells rxrpc_timer_set_for_keepalive);
76415f44e4SDavid Howells }
77415f44e4SDavid Howells
78415f44e4SDavid Howells /*
798d94aa38SDavid Howells * Fill out an ACK packet.
808d94aa38SDavid Howells */
rxrpc_fill_out_ack(struct rxrpc_connection * conn,struct rxrpc_call * call,struct rxrpc_txbuf * txb,u16 * _rwind)811457cc4cSDavid Howells static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
821457cc4cSDavid Howells struct rxrpc_call *call,
83f789bff2SDavid Howells struct rxrpc_txbuf *txb,
84f789bff2SDavid Howells u16 *_rwind)
858d94aa38SDavid Howells {
86*59881e57SDavid Howells struct rxrpc_acktrailer trailer;
87f21e9348SDavid Howells unsigned int qsize, sack, wrap, to;
88f21e9348SDavid Howells rxrpc_seq_t window, wtop;
895d7edbc9SDavid Howells int rsize;
908d94aa38SDavid Howells u32 mtu, jmax;
9172f0c6fbSDavid Howells u8 *ackp = txb->acks;
928d94aa38SDavid Howells
935bbf9533SDavid Howells call->ackr_nr_unacked = 0;
945d7edbc9SDavid Howells atomic_set(&call->ackr_nr_consumed, 0);
95f2a676d1SDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill);
96f21e9348SDavid Howells clear_bit(RXRPC_CALL_RX_IS_IDLE, &call->flags);
979a3dedcfSDavid Howells
985bbf9533SDavid Howells window = call->ackr_window;
995bbf9533SDavid Howells wtop = call->ackr_wtop;
100f21e9348SDavid Howells sack = call->ackr_sack_base % RXRPC_SACK_SIZE;
1015d7edbc9SDavid Howells txb->ack.firstPacket = htonl(window);
102f21e9348SDavid Howells txb->ack.nAcks = wtop - window;
103248f219cSDavid Howells
1045d7edbc9SDavid Howells if (after(wtop, window)) {
105f21e9348SDavid Howells wrap = RXRPC_SACK_SIZE - sack;
106f21e9348SDavid Howells to = min_t(unsigned int, txb->ack.nAcks, RXRPC_SACK_SIZE);
1078d94aa38SDavid Howells
108f21e9348SDavid Howells if (sack + txb->ack.nAcks <= RXRPC_SACK_SIZE) {
109f21e9348SDavid Howells memcpy(txb->acks, call->ackr_sack_table + sack, txb->ack.nAcks);
1105d7edbc9SDavid Howells } else {
111f21e9348SDavid Howells memcpy(txb->acks, call->ackr_sack_table + sack, wrap);
112f21e9348SDavid Howells memcpy(txb->acks + wrap, call->ackr_sack_table,
113f21e9348SDavid Howells to - wrap);
1145d7edbc9SDavid Howells }
1155d7edbc9SDavid Howells
116f21e9348SDavid Howells ackp += to;
1175d7edbc9SDavid Howells } else if (before(wtop, window)) {
1185d7edbc9SDavid Howells pr_warn("ack window backward %x %x", window, wtop);
119530403d9SDavid Howells } else if (txb->ack.reason == RXRPC_ACK_DELAY) {
120530403d9SDavid Howells txb->ack.reason = RXRPC_ACK_IDLE;
121248f219cSDavid Howells }
122248f219cSDavid Howells
1232cc80086SDavid Howells mtu = conn->peer->if_mtu;
1242cc80086SDavid Howells mtu -= conn->peer->hdrsize;
125d4d02d8bSDavid Howells jmax = rxrpc_rx_jumbo_max;
1265d7edbc9SDavid Howells qsize = (window - 1) - call->rx_consumed;
1275d7edbc9SDavid Howells rsize = max_t(int, call->rx_winsize - qsize, 0);
128f789bff2SDavid Howells *_rwind = rsize;
129*59881e57SDavid Howells trailer.maxMTU = htonl(rxrpc_rx_mtu);
130*59881e57SDavid Howells trailer.ifMTU = htonl(mtu);
131*59881e57SDavid Howells trailer.rwind = htonl(rsize);
132*59881e57SDavid Howells trailer.jumbo_max = htonl(jmax);
1338d94aa38SDavid Howells
1348d94aa38SDavid Howells *ackp++ = 0;
1358d94aa38SDavid Howells *ackp++ = 0;
1368d94aa38SDavid Howells *ackp++ = 0;
137*59881e57SDavid Howells memcpy(ackp, &trailer, sizeof(trailer));
138*59881e57SDavid Howells return txb->ack.nAcks + 3 + sizeof(trailer);
1398d94aa38SDavid Howells }
1408d94aa38SDavid Howells
1418d94aa38SDavid Howells /*
1424700c4d8SDavid Howells * Record the beginning of an RTT probe.
1434700c4d8SDavid Howells */
rxrpc_begin_rtt_probe(struct rxrpc_call * call,rxrpc_serial_t serial,enum rxrpc_rtt_tx_trace why)1444700c4d8SDavid Howells static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial,
1454700c4d8SDavid Howells enum rxrpc_rtt_tx_trace why)
1464700c4d8SDavid Howells {
1474700c4d8SDavid Howells unsigned long avail = call->rtt_avail;
1484700c4d8SDavid Howells int rtt_slot = 9;
1494700c4d8SDavid Howells
1504700c4d8SDavid Howells if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK))
1514700c4d8SDavid Howells goto no_slot;
1524700c4d8SDavid Howells
1534700c4d8SDavid Howells rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK);
1544700c4d8SDavid Howells if (!test_and_clear_bit(rtt_slot, &call->rtt_avail))
1554700c4d8SDavid Howells goto no_slot;
1564700c4d8SDavid Howells
1574700c4d8SDavid Howells call->rtt_serial[rtt_slot] = serial;
1584700c4d8SDavid Howells call->rtt_sent_at[rtt_slot] = ktime_get_real();
1594700c4d8SDavid Howells smp_wmb(); /* Write data before avail bit */
1604700c4d8SDavid Howells set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
1614700c4d8SDavid Howells
1624700c4d8SDavid Howells trace_rxrpc_rtt_tx(call, why, rtt_slot, serial);
1634700c4d8SDavid Howells return rtt_slot;
1644700c4d8SDavid Howells
1654700c4d8SDavid Howells no_slot:
1664700c4d8SDavid Howells trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial);
1674700c4d8SDavid Howells return -1;
1684700c4d8SDavid Howells }
1694700c4d8SDavid Howells
1704700c4d8SDavid Howells /*
1714700c4d8SDavid Howells * Cancel an RTT probe.
1724700c4d8SDavid Howells */
rxrpc_cancel_rtt_probe(struct rxrpc_call * call,rxrpc_serial_t serial,int rtt_slot)1734700c4d8SDavid Howells static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call,
1744700c4d8SDavid Howells rxrpc_serial_t serial, int rtt_slot)
1754700c4d8SDavid Howells {
1764700c4d8SDavid Howells if (rtt_slot != -1) {
1774700c4d8SDavid Howells clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
1784700c4d8SDavid Howells smp_wmb(); /* Clear pending bit before setting slot */
1794700c4d8SDavid Howells set_bit(rtt_slot, &call->rtt_avail);
1804700c4d8SDavid Howells trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial);
1814700c4d8SDavid Howells }
1824700c4d8SDavid Howells }
1834700c4d8SDavid Howells
1844700c4d8SDavid Howells /*
185b0346843SDavid Howells * Transmit an ACK packet.
1868d94aa38SDavid Howells */
rxrpc_send_ack_packet(struct rxrpc_call * call,struct rxrpc_txbuf * txb)187b0346843SDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
1888d94aa38SDavid Howells {
1895273a191SDavid Howells struct rxrpc_connection *conn;
1908d94aa38SDavid Howells struct msghdr msg;
19172f0c6fbSDavid Howells struct kvec iov[1];
1928d94aa38SDavid Howells rxrpc_serial_t serial;
1938d94aa38SDavid Howells size_t len, n;
1944700c4d8SDavid Howells int ret, rtt_slot = -1;
195f789bff2SDavid Howells u16 rwind;
1968d94aa38SDavid Howells
1975273a191SDavid Howells if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
1988d94aa38SDavid Howells return -ECONNRESET;
1998d94aa38SDavid Howells
2005273a191SDavid Howells conn = call->conn;
2018d94aa38SDavid Howells
2028d94aa38SDavid Howells msg.msg_name = &call->peer->srx.transport;
2038d94aa38SDavid Howells msg.msg_namelen = call->peer->srx.transport_len;
2048d94aa38SDavid Howells msg.msg_control = NULL;
2058d94aa38SDavid Howells msg.msg_controllen = 0;
2068d94aa38SDavid Howells msg.msg_flags = 0;
2078d94aa38SDavid Howells
20872f0c6fbSDavid Howells if (txb->ack.reason == RXRPC_ACK_PING)
20972f0c6fbSDavid Howells txb->wire.flags |= RXRPC_REQUEST_ACK;
2108d94aa38SDavid Howells
211f789bff2SDavid Howells n = rxrpc_fill_out_ack(conn, call, txb, &rwind);
2124e76bd40SDavid Howells if (n == 0)
2139a3dedcfSDavid Howells return 0;
2148d94aa38SDavid Howells
21572f0c6fbSDavid Howells iov[0].iov_base = &txb->wire;
21672f0c6fbSDavid Howells iov[0].iov_len = sizeof(txb->wire) + sizeof(txb->ack) + n;
21772f0c6fbSDavid Howells len = iov[0].iov_len;
2188d94aa38SDavid Howells
2192c9dc472SDavid Howells serial = rxrpc_get_next_serial(conn);
22072f0c6fbSDavid Howells txb->wire.serial = htonl(serial);
2214764c0daSDavid Howells trace_rxrpc_tx_ack(call->debug_id, serial,
22272f0c6fbSDavid Howells ntohl(txb->ack.firstPacket),
223f789bff2SDavid Howells ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks,
224f789bff2SDavid Howells rwind);
225b86e218eSDavid Howells
22672f0c6fbSDavid Howells if (txb->ack.reason == RXRPC_ACK_PING)
2274700c4d8SDavid Howells rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping);
22826cb02aaSDavid Howells
229f2a676d1SDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_ack_send);
230ed472b0cSDavid Howells
2315d7edbc9SDavid Howells /* Grab the highest received seq as late as possible */
2325d7edbc9SDavid Howells txb->ack.previousPacket = htonl(call->rx_highest_seq);
2335d7edbc9SDavid Howells
23472f0c6fbSDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
2352cc80086SDavid Howells ret = do_udp_sendmsg(conn->local->socket, &msg, len);
236ed472b0cSDavid Howells call->peer->last_tx_at = ktime_get_seconds();
23784e28aa5SDavid Howells if (ret < 0) {
2386b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret,
2394764c0daSDavid Howells rxrpc_tx_point_call_ack);
24084e28aa5SDavid Howells } else {
24172f0c6fbSDavid Howells trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
2424764c0daSDavid Howells rxrpc_tx_point_call_ack);
24384e28aa5SDavid Howells if (txb->wire.flags & RXRPC_REQUEST_ACK)
24484e28aa5SDavid Howells call->peer->rtt_last_req = ktime_get_real();
24584e28aa5SDavid Howells }
246c7e86acfSDavid Howells rxrpc_tx_backoff(call, ret);
2478d94aa38SDavid Howells
24896b4059fSDavid Howells if (!__rxrpc_call_is_complete(call)) {
24972f0c6fbSDavid Howells if (ret < 0)
2504700c4d8SDavid Howells rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
251415f44e4SDavid Howells rxrpc_set_keepalive(call);
252248f219cSDavid Howells }
253248f219cSDavid Howells
2548d94aa38SDavid Howells return ret;
2558d94aa38SDavid Howells }
2568d94aa38SDavid Howells
2578c3e34a4SDavid Howells /*
25826cb02aaSDavid Howells * Send an ABORT call packet.
25926cb02aaSDavid Howells */
rxrpc_send_abort_packet(struct rxrpc_call * call)26026cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *call)
26126cb02aaSDavid Howells {
2625273a191SDavid Howells struct rxrpc_connection *conn;
26326cb02aaSDavid Howells struct rxrpc_abort_buffer pkt;
26426cb02aaSDavid Howells struct msghdr msg;
26526cb02aaSDavid Howells struct kvec iov[1];
26626cb02aaSDavid Howells rxrpc_serial_t serial;
26726cb02aaSDavid Howells int ret;
26826cb02aaSDavid Howells
269dcbefc30SDavid Howells /* Don't bother sending aborts for a client call once the server has
270dcbefc30SDavid Howells * hard-ACK'd all of its request data. After that point, we're not
271dcbefc30SDavid Howells * going to stop the operation proceeding, and whilst we might limit
272dcbefc30SDavid Howells * the reply, it's not worth it if we can send a new call on the same
273dcbefc30SDavid Howells * channel instead, thereby closing off this call.
274dcbefc30SDavid Howells */
275dcbefc30SDavid Howells if (rxrpc_is_client_call(call) &&
276a4ea4c47SDavid Howells test_bit(RXRPC_CALL_TX_ALL_ACKED, &call->flags))
277dcbefc30SDavid Howells return 0;
278dcbefc30SDavid Howells
2795273a191SDavid Howells if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
28026cb02aaSDavid Howells return -ECONNRESET;
28126cb02aaSDavid Howells
2825273a191SDavid Howells conn = call->conn;
2835273a191SDavid Howells
28426cb02aaSDavid Howells msg.msg_name = &call->peer->srx.transport;
28526cb02aaSDavid Howells msg.msg_namelen = call->peer->srx.transport_len;
28626cb02aaSDavid Howells msg.msg_control = NULL;
28726cb02aaSDavid Howells msg.msg_controllen = 0;
28826cb02aaSDavid Howells msg.msg_flags = 0;
28926cb02aaSDavid Howells
29026cb02aaSDavid Howells pkt.whdr.epoch = htonl(conn->proto.epoch);
29126cb02aaSDavid Howells pkt.whdr.cid = htonl(call->cid);
29226cb02aaSDavid Howells pkt.whdr.callNumber = htonl(call->call_id);
29326cb02aaSDavid Howells pkt.whdr.seq = 0;
29426cb02aaSDavid Howells pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT;
29526cb02aaSDavid Howells pkt.whdr.flags = conn->out_clientflag;
29626cb02aaSDavid Howells pkt.whdr.userStatus = 0;
29726cb02aaSDavid Howells pkt.whdr.securityIndex = call->security_ix;
29826cb02aaSDavid Howells pkt.whdr._rsvd = 0;
299f3441d41SDavid Howells pkt.whdr.serviceId = htons(call->dest_srx.srx_service);
30026cb02aaSDavid Howells pkt.abort_code = htonl(call->abort_code);
30126cb02aaSDavid Howells
30226cb02aaSDavid Howells iov[0].iov_base = &pkt;
30326cb02aaSDavid Howells iov[0].iov_len = sizeof(pkt);
30426cb02aaSDavid Howells
3052c9dc472SDavid Howells serial = rxrpc_get_next_serial(conn);
30626cb02aaSDavid Howells pkt.whdr.serial = htonl(serial);
30726cb02aaSDavid Howells
308ed472b0cSDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
3092cc80086SDavid Howells ret = do_udp_sendmsg(conn->local->socket, &msg, sizeof(pkt));
3102cc80086SDavid Howells conn->peer->last_tx_at = ktime_get_seconds();
3116b47fe1dSDavid Howells if (ret < 0)
3126b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret,
3134764c0daSDavid Howells rxrpc_tx_point_call_abort);
3144764c0daSDavid Howells else
3154764c0daSDavid Howells trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
3164764c0daSDavid Howells rxrpc_tx_point_call_abort);
317c7e86acfSDavid Howells rxrpc_tx_backoff(call, ret);
31826cb02aaSDavid Howells return ret;
31926cb02aaSDavid Howells }
32026cb02aaSDavid Howells
32126cb02aaSDavid Howells /*
3228c3e34a4SDavid Howells * send a packet through the transport endpoint
3238c3e34a4SDavid Howells */
rxrpc_send_data_packet(struct rxrpc_call * call,struct rxrpc_txbuf * txb)324a4ea4c47SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
3258c3e34a4SDavid Howells {
3264d843be5SDavid Howells enum rxrpc_req_ack_trace why;
3275a924b89SDavid Howells struct rxrpc_connection *conn = call->conn;
3288c3e34a4SDavid Howells struct msghdr msg;
329a4ea4c47SDavid Howells struct kvec iov[1];
3305a924b89SDavid Howells rxrpc_serial_t serial;
3315a924b89SDavid Howells size_t len;
3324700c4d8SDavid Howells int ret, rtt_slot = -1;
3338c3e34a4SDavid Howells
334a4ea4c47SDavid Howells _enter("%x,{%d}", txb->seq, txb->len);
3358c3e34a4SDavid Howells
3365a924b89SDavid Howells /* Each transmission of a Tx packet needs a new serial number */
3372c9dc472SDavid Howells serial = rxrpc_get_next_serial(conn);
338a4ea4c47SDavid Howells txb->wire.serial = htonl(serial);
3395a924b89SDavid Howells
3404e255721SDavid Howells if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
341a4ea4c47SDavid Howells txb->seq == 1)
342a4ea4c47SDavid Howells txb->wire.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE;
3434e255721SDavid Howells
344a4ea4c47SDavid Howells iov[0].iov_base = &txb->wire;
345a4ea4c47SDavid Howells iov[0].iov_len = sizeof(txb->wire) + txb->len;
346a4ea4c47SDavid Howells len = iov[0].iov_len;
347a4ea4c47SDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
3485a924b89SDavid Howells
3495a924b89SDavid Howells msg.msg_name = &call->peer->srx.transport;
3505a924b89SDavid Howells msg.msg_namelen = call->peer->srx.transport_len;
3518c3e34a4SDavid Howells msg.msg_control = NULL;
3528c3e34a4SDavid Howells msg.msg_controllen = 0;
3538c3e34a4SDavid Howells msg.msg_flags = 0;
3548c3e34a4SDavid Howells
35557494343SDavid Howells /* If our RTT cache needs working on, request an ACK. Also request
35657494343SDavid Howells * ACKs if a DATA packet appears to have been lost.
357b604dd98SDavid Howells *
358b604dd98SDavid Howells * However, we mustn't request an ACK on the last reply packet of a
359b604dd98SDavid Howells * service call, lest OpenAFS incorrectly send us an ACK with some
360b604dd98SDavid Howells * soft-ACKs in it and then never follow up with a proper hard ACK.
36157494343SDavid Howells */
362a4ea4c47SDavid Howells if (txb->wire.flags & RXRPC_REQUEST_ACK)
3634d843be5SDavid Howells why = rxrpc_reqack_already_on;
364a4ea4c47SDavid Howells else if (test_bit(RXRPC_TXBUF_LAST, &txb->flags) && rxrpc_sending_to_client(txb))
3654d843be5SDavid Howells why = rxrpc_reqack_no_srv_last;
3664d843be5SDavid Howells else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
3674d843be5SDavid Howells why = rxrpc_reqack_ack_lost;
368a4ea4c47SDavid Howells else if (test_bit(RXRPC_TXBUF_RESENT, &txb->flags))
3694d843be5SDavid Howells why = rxrpc_reqack_retrans;
3704d843be5SDavid Howells else if (call->cong_mode == RXRPC_CALL_SLOW_START && call->cong_cwnd <= 2)
3714d843be5SDavid Howells why = rxrpc_reqack_slow_start;
3724d843be5SDavid Howells else if (call->tx_winsize <= 2)
3734d843be5SDavid Howells why = rxrpc_reqack_small_txwin;
374a4ea4c47SDavid Howells else if (call->peer->rtt_count < 3 && txb->seq & 1)
3754d843be5SDavid Howells why = rxrpc_reqack_more_rtt;
3764d843be5SDavid Howells else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), ktime_get_real()))
3774d843be5SDavid Howells why = rxrpc_reqack_old_rtt;
3784d843be5SDavid Howells else
3794d843be5SDavid Howells goto dont_set_request_ack;
3804d843be5SDavid Howells
381f7fa5242SDavid Howells rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]);
382a4ea4c47SDavid Howells trace_rxrpc_req_ack(call->debug_id, txb->seq, why);
3834d843be5SDavid Howells if (why != rxrpc_reqack_no_srv_last)
384a4ea4c47SDavid Howells txb->wire.flags |= RXRPC_REQUEST_ACK;
3854d843be5SDavid Howells dont_set_request_ack:
3860d4b103cSDavid Howells
3878a681c36SDavid Howells if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
3888a681c36SDavid Howells static int lose;
3898a681c36SDavid Howells if ((lose++ & 7) == 7) {
390a1767077SDavid Howells ret = 0;
391a4ea4c47SDavid Howells trace_rxrpc_tx_data(call, txb->seq, serial,
392a4ea4c47SDavid Howells txb->wire.flags,
393a4ea4c47SDavid Howells test_bit(RXRPC_TXBUF_RESENT, &txb->flags),
394a4ea4c47SDavid Howells true);
395526949e8SArnd Bergmann goto done;
3968a681c36SDavid Howells }
3978a681c36SDavid Howells }
3988a681c36SDavid Howells
399a4ea4c47SDavid Howells trace_rxrpc_tx_data(call, txb->seq, serial, txb->wire.flags,
400a4ea4c47SDavid Howells test_bit(RXRPC_TXBUF_RESENT, &txb->flags), false);
401cf37b598SDavid Howells
402cf37b598SDavid Howells /* Track what we've attempted to transmit at least once so that the
403cf37b598SDavid Howells * retransmission algorithm doesn't try to resend what we haven't sent
404cf37b598SDavid Howells * yet. However, this can race as we can receive an ACK before we get
405cf37b598SDavid Howells * to this point. But, OTOH, if we won't get an ACK mentioning this
406cf37b598SDavid Howells * packet unless the far side received it (though it could have
407cf37b598SDavid Howells * discarded it anyway and NAK'd it).
408cf37b598SDavid Howells */
409a4ea4c47SDavid Howells cmpxchg(&call->tx_transmitted, txb->seq - 1, txb->seq);
4105a924b89SDavid Howells
4118c3e34a4SDavid Howells /* send the packet with the don't fragment bit set if we currently
4128c3e34a4SDavid Howells * think it's small enough */
413a4ea4c47SDavid Howells if (txb->len >= call->peer->maxdata)
4145a924b89SDavid Howells goto send_fragmentable;
4155a924b89SDavid Howells
416a4ea4c47SDavid Howells txb->last_sent = ktime_get_real();
417a4ea4c47SDavid Howells if (txb->wire.flags & RXRPC_REQUEST_ACK)
4184700c4d8SDavid Howells rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
419b604dd98SDavid Howells
4208c3e34a4SDavid Howells /* send the packet by UDP
4218c3e34a4SDavid Howells * - returns -EMSGSIZE if UDP would have to fragment the packet
4228c3e34a4SDavid Howells * to go out of the interface
4238c3e34a4SDavid Howells * - in which case, we'll have processed the ICMP error
4248c3e34a4SDavid Howells * message and update the peer record
4258c3e34a4SDavid Howells */
426b0154246SDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
4272cc80086SDavid Howells ret = do_udp_sendmsg(conn->local->socket, &msg, len);
4282cc80086SDavid Howells conn->peer->last_tx_at = ktime_get_seconds();
4298c3e34a4SDavid Howells
4304700c4d8SDavid Howells if (ret < 0) {
43132cf8edbSDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail);
4324700c4d8SDavid Howells rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
4336b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret,
4344764c0daSDavid Howells rxrpc_tx_point_call_data_nofrag);
4354700c4d8SDavid Howells } else {
436a4ea4c47SDavid Howells trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
4374764c0daSDavid Howells rxrpc_tx_point_call_data_nofrag);
4384700c4d8SDavid Howells }
4394700c4d8SDavid Howells
440c7e86acfSDavid Howells rxrpc_tx_backoff(call, ret);
4418c3e34a4SDavid Howells if (ret == -EMSGSIZE)
4428c3e34a4SDavid Howells goto send_fragmentable;
4438c3e34a4SDavid Howells
4445a924b89SDavid Howells done:
44550235c4bSDavid Howells if (ret >= 0) {
4461fc4fa2aSDavid Howells call->tx_last_sent = txb->last_sent;
447a4ea4c47SDavid Howells if (txb->wire.flags & RXRPC_REQUEST_ACK) {
448a4ea4c47SDavid Howells call->peer->rtt_last_req = txb->last_sent;
449c410bf01SDavid Howells if (call->peer->rtt_count > 1) {
450bd1fdf8cSDavid Howells unsigned long nowj = jiffies, ack_lost_at;
451bd1fdf8cSDavid Howells
4522c13c05cSDavid Howells ack_lost_at = rxrpc_get_rto_backoff(call->peer, false);
453bd1fdf8cSDavid Howells ack_lost_at += nowj;
454bd1fdf8cSDavid Howells WRITE_ONCE(call->ack_lost_at, ack_lost_at);
455bd1fdf8cSDavid Howells rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
456bd1fdf8cSDavid Howells rxrpc_timer_set_for_lost_ack);
457bd1fdf8cSDavid Howells }
4588c3e34a4SDavid Howells }
459c54e43d7SDavid Howells
460a4ea4c47SDavid Howells if (txb->seq == 1 &&
461c54e43d7SDavid Howells !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
462c54e43d7SDavid Howells &call->flags)) {
463c54e43d7SDavid Howells unsigned long nowj = jiffies, expect_rx_by;
464c54e43d7SDavid Howells
465c54e43d7SDavid Howells expect_rx_by = nowj + call->next_rx_timo;
466c54e43d7SDavid Howells WRITE_ONCE(call->expect_rx_by, expect_rx_by);
467c54e43d7SDavid Howells rxrpc_reduce_call_timer(call, expect_rx_by, nowj,
468c54e43d7SDavid Howells rxrpc_timer_set_for_normal);
469c54e43d7SDavid Howells }
470415f44e4SDavid Howells
471415f44e4SDavid Howells rxrpc_set_keepalive(call);
472c7e86acfSDavid Howells } else {
473c7e86acfSDavid Howells /* Cancel the call if the initial transmission fails,
474c7e86acfSDavid Howells * particularly if that's due to network routing issues that
475c7e86acfSDavid Howells * aren't going away anytime soon. The layer above can arrange
476c7e86acfSDavid Howells * the retransmission.
477c7e86acfSDavid Howells */
478c7e86acfSDavid Howells if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags))
479c7e86acfSDavid Howells rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
480c7e86acfSDavid Howells RX_USER_ABORT, ret);
481c7e86acfSDavid Howells }
482415f44e4SDavid Howells
4835a924b89SDavid Howells _leave(" = %d [%u]", ret, call->peer->maxdata);
4845a924b89SDavid Howells return ret;
4858c3e34a4SDavid Howells
4868c3e34a4SDavid Howells send_fragmentable:
4878c3e34a4SDavid Howells /* attempt to send this message with fragmentation enabled */
4888c3e34a4SDavid Howells _debug("send fragment");
4898c3e34a4SDavid Howells
490a4ea4c47SDavid Howells txb->last_sent = ktime_get_real();
491a4ea4c47SDavid Howells if (txb->wire.flags & RXRPC_REQUEST_ACK)
4924700c4d8SDavid Howells rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
493b604dd98SDavid Howells
4942cc80086SDavid Howells switch (conn->local->srx.transport.family) {
4950e631eeeSDavid Howells case AF_INET6:
496985a5c82SDavid Howells case AF_INET:
4975c4017a2SDavid Howells rxrpc_local_dont_fragment(conn->local, false);
498b0154246SDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag);
4992cc80086SDavid Howells ret = do_udp_sendmsg(conn->local->socket, &msg, len);
5002cc80086SDavid Howells conn->peer->last_tx_at = ktime_get_seconds();
5018c3e34a4SDavid Howells
5025c4017a2SDavid Howells rxrpc_local_dont_fragment(conn->local, true);
50375b54cb5SDavid Howells break;
5043427beb6SDavid Howells
5053427beb6SDavid Howells default:
5063427beb6SDavid Howells BUG();
5078c3e34a4SDavid Howells }
5088c3e34a4SDavid Howells
5094700c4d8SDavid Howells if (ret < 0) {
51032cf8edbSDavid Howells rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail);
5114700c4d8SDavid Howells rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
5126b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret,
5134764c0daSDavid Howells rxrpc_tx_point_call_data_frag);
5144700c4d8SDavid Howells } else {
515a4ea4c47SDavid Howells trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
5164764c0daSDavid Howells rxrpc_tx_point_call_data_frag);
5174700c4d8SDavid Howells }
518c7e86acfSDavid Howells rxrpc_tx_backoff(call, ret);
5195a924b89SDavid Howells goto done;
5208c3e34a4SDavid Howells }
521248f219cSDavid Howells
522248f219cSDavid Howells /*
523a00ce28bSDavid Howells * Transmit a connection-level abort.
524a00ce28bSDavid Howells */
rxrpc_send_conn_abort(struct rxrpc_connection * conn)525a00ce28bSDavid Howells void rxrpc_send_conn_abort(struct rxrpc_connection *conn)
526a00ce28bSDavid Howells {
527a00ce28bSDavid Howells struct rxrpc_wire_header whdr;
528a00ce28bSDavid Howells struct msghdr msg;
529a00ce28bSDavid Howells struct kvec iov[2];
530a00ce28bSDavid Howells __be32 word;
531a00ce28bSDavid Howells size_t len;
532a00ce28bSDavid Howells u32 serial;
533a00ce28bSDavid Howells int ret;
534a00ce28bSDavid Howells
535a00ce28bSDavid Howells msg.msg_name = &conn->peer->srx.transport;
536a00ce28bSDavid Howells msg.msg_namelen = conn->peer->srx.transport_len;
537a00ce28bSDavid Howells msg.msg_control = NULL;
538a00ce28bSDavid Howells msg.msg_controllen = 0;
539a00ce28bSDavid Howells msg.msg_flags = 0;
540a00ce28bSDavid Howells
541a00ce28bSDavid Howells whdr.epoch = htonl(conn->proto.epoch);
542a00ce28bSDavid Howells whdr.cid = htonl(conn->proto.cid);
543a00ce28bSDavid Howells whdr.callNumber = 0;
544a00ce28bSDavid Howells whdr.seq = 0;
545a00ce28bSDavid Howells whdr.type = RXRPC_PACKET_TYPE_ABORT;
546a00ce28bSDavid Howells whdr.flags = conn->out_clientflag;
547a00ce28bSDavid Howells whdr.userStatus = 0;
548a00ce28bSDavid Howells whdr.securityIndex = conn->security_ix;
549a00ce28bSDavid Howells whdr._rsvd = 0;
550a00ce28bSDavid Howells whdr.serviceId = htons(conn->service_id);
551a00ce28bSDavid Howells
552a00ce28bSDavid Howells word = htonl(conn->abort_code);
553a00ce28bSDavid Howells
554a00ce28bSDavid Howells iov[0].iov_base = &whdr;
555a00ce28bSDavid Howells iov[0].iov_len = sizeof(whdr);
556a00ce28bSDavid Howells iov[1].iov_base = &word;
557a00ce28bSDavid Howells iov[1].iov_len = sizeof(word);
558a00ce28bSDavid Howells
559a00ce28bSDavid Howells len = iov[0].iov_len + iov[1].iov_len;
560a00ce28bSDavid Howells
5612c9dc472SDavid Howells serial = rxrpc_get_next_serial(conn);
562a00ce28bSDavid Howells whdr.serial = htonl(serial);
563a00ce28bSDavid Howells
564a00ce28bSDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
565a00ce28bSDavid Howells ret = do_udp_sendmsg(conn->local->socket, &msg, len);
566a00ce28bSDavid Howells if (ret < 0) {
567a00ce28bSDavid Howells trace_rxrpc_tx_fail(conn->debug_id, serial, ret,
568a00ce28bSDavid Howells rxrpc_tx_point_conn_abort);
569a00ce28bSDavid Howells _debug("sendmsg failed: %d", ret);
570a00ce28bSDavid Howells return;
571a00ce28bSDavid Howells }
572a00ce28bSDavid Howells
573a00ce28bSDavid Howells trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort);
574a00ce28bSDavid Howells
575a00ce28bSDavid Howells conn->peer->last_tx_at = ktime_get_seconds();
576a00ce28bSDavid Howells }
577a00ce28bSDavid Howells
578a00ce28bSDavid Howells /*
5795e6ef4f1SDavid Howells * Reject a packet through the local endpoint.
580248f219cSDavid Howells */
rxrpc_reject_packet(struct rxrpc_local * local,struct sk_buff * skb)5815e6ef4f1SDavid Howells void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
582248f219cSDavid Howells {
583248f219cSDavid Howells struct rxrpc_wire_header whdr;
5845e6ef4f1SDavid Howells struct sockaddr_rxrpc srx;
5855e6ef4f1SDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
586248f219cSDavid Howells struct msghdr msg;
587248f219cSDavid Howells struct kvec iov[2];
588248f219cSDavid Howells size_t size;
589248f219cSDavid Howells __be32 code;
590ece64fecSDavid Howells int ret, ioc;
591248f219cSDavid Howells
5925e6ef4f1SDavid Howells rxrpc_see_skb(skb, rxrpc_skb_see_reject);
593248f219cSDavid Howells
594248f219cSDavid Howells iov[0].iov_base = &whdr;
595248f219cSDavid Howells iov[0].iov_len = sizeof(whdr);
596248f219cSDavid Howells iov[1].iov_base = &code;
597248f219cSDavid Howells iov[1].iov_len = sizeof(code);
598248f219cSDavid Howells
5991c2bc7b9SDavid Howells msg.msg_name = &srx.transport;
600248f219cSDavid Howells msg.msg_control = NULL;
601248f219cSDavid Howells msg.msg_controllen = 0;
602248f219cSDavid Howells msg.msg_flags = 0;
603248f219cSDavid Howells
604248f219cSDavid Howells memset(&whdr, 0, sizeof(whdr));
605248f219cSDavid Howells
606ece64fecSDavid Howells switch (skb->mark) {
607ece64fecSDavid Howells case RXRPC_SKB_MARK_REJECT_BUSY:
608ece64fecSDavid Howells whdr.type = RXRPC_PACKET_TYPE_BUSY;
609ece64fecSDavid Howells size = sizeof(whdr);
610ece64fecSDavid Howells ioc = 1;
611ece64fecSDavid Howells break;
612ece64fecSDavid Howells case RXRPC_SKB_MARK_REJECT_ABORT:
613ece64fecSDavid Howells whdr.type = RXRPC_PACKET_TYPE_ABORT;
614ece64fecSDavid Howells code = htonl(skb->priority);
615ece64fecSDavid Howells size = sizeof(whdr) + sizeof(code);
616ece64fecSDavid Howells ioc = 2;
617ece64fecSDavid Howells break;
618ece64fecSDavid Howells default:
6195e6ef4f1SDavid Howells return;
620ece64fecSDavid Howells }
621ece64fecSDavid Howells
6225a790b73SDavid Howells if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
6231c2bc7b9SDavid Howells msg.msg_namelen = srx.transport_len;
6241c2bc7b9SDavid Howells
625248f219cSDavid Howells whdr.epoch = htonl(sp->hdr.epoch);
626248f219cSDavid Howells whdr.cid = htonl(sp->hdr.cid);
627248f219cSDavid Howells whdr.callNumber = htonl(sp->hdr.callNumber);
628248f219cSDavid Howells whdr.serviceId = htons(sp->hdr.serviceId);
629248f219cSDavid Howells whdr.flags = sp->hdr.flags;
630248f219cSDavid Howells whdr.flags ^= RXRPC_CLIENT_INITIATED;
631248f219cSDavid Howells whdr.flags &= RXRPC_CLIENT_INITIATED;
632248f219cSDavid Howells
633ed472b0cSDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size);
634ed472b0cSDavid Howells ret = do_udp_sendmsg(local->socket, &msg, size);
6356b47fe1dSDavid Howells if (ret < 0)
6366b47fe1dSDavid Howells trace_rxrpc_tx_fail(local->debug_id, 0, ret,
6374764c0daSDavid Howells rxrpc_tx_point_reject);
6384764c0daSDavid Howells else
6394764c0daSDavid Howells trace_rxrpc_tx_packet(local->debug_id, &whdr,
6404764c0daSDavid Howells rxrpc_tx_point_reject);
641248f219cSDavid Howells }
642248f219cSDavid Howells }
643ace45becSDavid Howells
644ace45becSDavid Howells /*
645ace45becSDavid Howells * Send a VERSION reply to a peer as a keepalive.
646ace45becSDavid Howells */
rxrpc_send_keepalive(struct rxrpc_peer * peer)647ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *peer)
648ace45becSDavid Howells {
649ace45becSDavid Howells struct rxrpc_wire_header whdr;
650ace45becSDavid Howells struct msghdr msg;
651ace45becSDavid Howells struct kvec iov[2];
652ace45becSDavid Howells size_t len;
653ace45becSDavid Howells int ret;
654ace45becSDavid Howells
655ace45becSDavid Howells _enter("");
656ace45becSDavid Howells
657ace45becSDavid Howells msg.msg_name = &peer->srx.transport;
658ace45becSDavid Howells msg.msg_namelen = peer->srx.transport_len;
659ace45becSDavid Howells msg.msg_control = NULL;
660ace45becSDavid Howells msg.msg_controllen = 0;
661ace45becSDavid Howells msg.msg_flags = 0;
662ace45becSDavid Howells
663ace45becSDavid Howells whdr.epoch = htonl(peer->local->rxnet->epoch);
664ace45becSDavid Howells whdr.cid = 0;
665ace45becSDavid Howells whdr.callNumber = 0;
666ace45becSDavid Howells whdr.seq = 0;
667ace45becSDavid Howells whdr.serial = 0;
668ace45becSDavid Howells whdr.type = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */
669ace45becSDavid Howells whdr.flags = RXRPC_LAST_PACKET;
670ace45becSDavid Howells whdr.userStatus = 0;
671ace45becSDavid Howells whdr.securityIndex = 0;
672ace45becSDavid Howells whdr._rsvd = 0;
673ace45becSDavid Howells whdr.serviceId = 0;
674ace45becSDavid Howells
675ace45becSDavid Howells iov[0].iov_base = &whdr;
676ace45becSDavid Howells iov[0].iov_len = sizeof(whdr);
677ace45becSDavid Howells iov[1].iov_base = (char *)rxrpc_keepalive_string;
678ace45becSDavid Howells iov[1].iov_len = sizeof(rxrpc_keepalive_string);
679ace45becSDavid Howells
680ace45becSDavid Howells len = iov[0].iov_len + iov[1].iov_len;
681ace45becSDavid Howells
682ed472b0cSDavid Howells iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
683ed472b0cSDavid Howells ret = do_udp_sendmsg(peer->local->socket, &msg, len);
684ace45becSDavid Howells if (ret < 0)
6856b47fe1dSDavid Howells trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
6864764c0daSDavid Howells rxrpc_tx_point_version_keepalive);
6874764c0daSDavid Howells else
6884764c0daSDavid Howells trace_rxrpc_tx_packet(peer->debug_id, &whdr,
6894764c0daSDavid Howells rxrpc_tx_point_version_keepalive);
690ace45becSDavid Howells
691330bdcfaSDavid Howells peer->last_tx_at = ktime_get_seconds();
692ace45becSDavid Howells _leave("");
693ace45becSDavid Howells }
694cf37b598SDavid Howells
695cf37b598SDavid Howells /*
696cf37b598SDavid Howells * Schedule an instant Tx resend.
697cf37b598SDavid Howells */
rxrpc_instant_resend(struct rxrpc_call * call,struct rxrpc_txbuf * txb)698cf37b598SDavid Howells static inline void rxrpc_instant_resend(struct rxrpc_call *call,
699cf37b598SDavid Howells struct rxrpc_txbuf *txb)
700cf37b598SDavid Howells {
70196b4059fSDavid Howells if (!__rxrpc_call_is_complete(call))
702cf37b598SDavid Howells kdebug("resend");
703cf37b598SDavid Howells }
704cf37b598SDavid Howells
705cf37b598SDavid Howells /*
706cf37b598SDavid Howells * Transmit one packet.
707cf37b598SDavid Howells */
rxrpc_transmit_one(struct rxrpc_call * call,struct rxrpc_txbuf * txb)708cf37b598SDavid Howells void rxrpc_transmit_one(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
709cf37b598SDavid Howells {
710cf37b598SDavid Howells int ret;
711cf37b598SDavid Howells
712cf37b598SDavid Howells ret = rxrpc_send_data_packet(call, txb);
713cf37b598SDavid Howells if (ret < 0) {
714cf37b598SDavid Howells switch (ret) {
715cf37b598SDavid Howells case -ENETUNREACH:
716cf37b598SDavid Howells case -EHOSTUNREACH:
717cf37b598SDavid Howells case -ECONNREFUSED:
718cf37b598SDavid Howells rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
719cf37b598SDavid Howells 0, ret);
720cf37b598SDavid Howells break;
721cf37b598SDavid Howells default:
722cf37b598SDavid Howells _debug("need instant resend %d", ret);
723cf37b598SDavid Howells rxrpc_instant_resend(call, txb);
724cf37b598SDavid Howells }
725cf37b598SDavid Howells } else {
726cf37b598SDavid Howells unsigned long now = jiffies;
727cf37b598SDavid Howells unsigned long resend_at = now + call->peer->rto_j;
728cf37b598SDavid Howells
729cf37b598SDavid Howells WRITE_ONCE(call->resend_at, resend_at);
730cf37b598SDavid Howells rxrpc_reduce_call_timer(call, resend_at, now,
731cf37b598SDavid Howells rxrpc_timer_set_for_send);
732cf37b598SDavid Howells }
733cf37b598SDavid Howells }
734