xref: /openbmc/linux/net/rxrpc/output.c (revision 72f0c6fb)
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 
21ed472b0cSDavid Howells static ssize_t do_udp_sendmsg(struct socket *sk, struct msghdr *msg, size_t len)
22ed472b0cSDavid Howells {
23ed472b0cSDavid Howells #if IS_ENABLED(CONFIG_AF_RXRPC_IPV6)
24ed472b0cSDavid Howells 	struct sockaddr *sa = msg->msg_name;
25ed472b0cSDavid Howells 
26ed472b0cSDavid Howells 	if (sa->sa_family == AF_INET6)
27ed472b0cSDavid Howells 		return udpv6_sendmsg(sk->sk, msg, len);
28ed472b0cSDavid Howells #endif
29ed472b0cSDavid Howells 	return udp_sendmsg(sk->sk, msg, len);
30ed472b0cSDavid Howells }
31ed472b0cSDavid Howells 
3226cb02aaSDavid Howells struct rxrpc_abort_buffer {
3326cb02aaSDavid Howells 	struct rxrpc_wire_header whdr;
3426cb02aaSDavid Howells 	__be32 abort_code;
3526cb02aaSDavid Howells };
3626cb02aaSDavid Howells 
37ace45becSDavid Howells static const char rxrpc_keepalive_string[] = "";
38ace45becSDavid Howells 
398d94aa38SDavid Howells /*
40c7e86acfSDavid Howells  * Increase Tx backoff on transmission failure and clear it on success.
41c7e86acfSDavid Howells  */
42c7e86acfSDavid Howells static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret)
43c7e86acfSDavid Howells {
44c7e86acfSDavid Howells 	if (ret < 0) {
45c7e86acfSDavid Howells 		u16 tx_backoff = READ_ONCE(call->tx_backoff);
46c7e86acfSDavid Howells 
47c7e86acfSDavid Howells 		if (tx_backoff < HZ)
48c7e86acfSDavid Howells 			WRITE_ONCE(call->tx_backoff, tx_backoff + 1);
49c7e86acfSDavid Howells 	} else {
50c7e86acfSDavid Howells 		WRITE_ONCE(call->tx_backoff, 0);
51c7e86acfSDavid Howells 	}
52c7e86acfSDavid Howells }
53c7e86acfSDavid Howells 
54c7e86acfSDavid Howells /*
55415f44e4SDavid Howells  * Arrange for a keepalive ping a certain time after we last transmitted.  This
56415f44e4SDavid Howells  * lets the far side know we're still interested in this call and helps keep
57415f44e4SDavid Howells  * the route through any intervening firewall open.
58415f44e4SDavid Howells  *
59415f44e4SDavid Howells  * Receiving a response to the ping will prevent the ->expect_rx_by timer from
60415f44e4SDavid Howells  * expiring.
61415f44e4SDavid Howells  */
62415f44e4SDavid Howells static void rxrpc_set_keepalive(struct rxrpc_call *call)
63415f44e4SDavid Howells {
64415f44e4SDavid Howells 	unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6;
65415f44e4SDavid Howells 
66415f44e4SDavid Howells 	keepalive_at += now;
67415f44e4SDavid Howells 	WRITE_ONCE(call->keepalive_at, keepalive_at);
68415f44e4SDavid Howells 	rxrpc_reduce_call_timer(call, keepalive_at, now,
69415f44e4SDavid Howells 				rxrpc_timer_set_for_keepalive);
70415f44e4SDavid Howells }
71415f44e4SDavid Howells 
72415f44e4SDavid Howells /*
738d94aa38SDavid Howells  * Fill out an ACK packet.
748d94aa38SDavid Howells  */
751457cc4cSDavid Howells static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
761457cc4cSDavid Howells 				 struct rxrpc_call *call,
77*72f0c6fbSDavid Howells 				 struct rxrpc_txbuf *txb,
78805b21b9SDavid Howells 				 rxrpc_seq_t *_hard_ack,
79*72f0c6fbSDavid Howells 				 rxrpc_seq_t *_top)
808d94aa38SDavid Howells {
81*72f0c6fbSDavid Howells 	struct rxrpc_ackinfo ackinfo;
829a3dedcfSDavid Howells 	unsigned int tmp;
83248f219cSDavid Howells 	rxrpc_seq_t hard_ack, top, seq;
84248f219cSDavid Howells 	int ix;
858d94aa38SDavid Howells 	u32 mtu, jmax;
86*72f0c6fbSDavid Howells 	u8 *ackp = txb->acks;
878d94aa38SDavid Howells 
889a3dedcfSDavid Howells 	tmp = atomic_xchg(&call->ackr_nr_unacked, 0);
899a3dedcfSDavid Howells 	tmp |= atomic_xchg(&call->ackr_nr_consumed, 0);
90*72f0c6fbSDavid Howells 	if (!tmp && (txb->ack.reason == RXRPC_ACK_DELAY ||
91*72f0c6fbSDavid Howells 		     txb->ack.reason == RXRPC_ACK_IDLE)) {
92f2a676d1SDavid Howells 		rxrpc_inc_stat(call->rxnet, stat_tx_ack_skip);
939a3dedcfSDavid Howells 		return 0;
94f2a676d1SDavid Howells 	}
95f2a676d1SDavid Howells 
96f2a676d1SDavid Howells 	rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill);
979a3dedcfSDavid Howells 
98248f219cSDavid Howells 	/* Barrier against rxrpc_input_data(). */
99248f219cSDavid Howells 	hard_ack = READ_ONCE(call->rx_hard_ack);
100248f219cSDavid Howells 	top = smp_load_acquire(&call->rx_top);
101805b21b9SDavid Howells 	*_hard_ack = hard_ack;
102805b21b9SDavid Howells 	*_top = top;
103248f219cSDavid Howells 
104*72f0c6fbSDavid Howells 	txb->ack.firstPacket	= htonl(hard_ack + 1);
105*72f0c6fbSDavid Howells 	txb->ack.previousPacket	= htonl(call->ackr_highest_seq);
106*72f0c6fbSDavid Howells 	txb->ack.nAcks		= top - hard_ack;
1078d94aa38SDavid Howells 
108*72f0c6fbSDavid Howells 	if (txb->ack.nAcks) {
109248f219cSDavid Howells 		seq = hard_ack + 1;
110248f219cSDavid Howells 		do {
111248f219cSDavid Howells 			ix = seq & RXRPC_RXTX_BUFF_MASK;
112248f219cSDavid Howells 			if (call->rxtx_buffer[ix])
113248f219cSDavid Howells 				*ackp++ = RXRPC_ACK_TYPE_ACK;
114248f219cSDavid Howells 			else
115248f219cSDavid Howells 				*ackp++ = RXRPC_ACK_TYPE_NACK;
116248f219cSDavid Howells 			seq++;
117248f219cSDavid Howells 		} while (before_eq(seq, top));
118248f219cSDavid Howells 	}
119248f219cSDavid Howells 
1201457cc4cSDavid Howells 	mtu = conn->params.peer->if_mtu;
1211457cc4cSDavid Howells 	mtu -= conn->params.peer->hdrsize;
12275e42126SDavid Howells 	jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max;
123*72f0c6fbSDavid Howells 	ackinfo.rxMTU		= htonl(rxrpc_rx_mtu);
124*72f0c6fbSDavid Howells 	ackinfo.maxMTU		= htonl(mtu);
125*72f0c6fbSDavid Howells 	ackinfo.rwind		= htonl(call->rx_winsize);
126*72f0c6fbSDavid Howells 	ackinfo.jumbo_max	= htonl(jmax);
1278d94aa38SDavid Howells 
1288d94aa38SDavid Howells 	*ackp++ = 0;
1298d94aa38SDavid Howells 	*ackp++ = 0;
1308d94aa38SDavid Howells 	*ackp++ = 0;
131*72f0c6fbSDavid Howells 	memcpy(ackp, &ackinfo, sizeof(ackinfo));
132*72f0c6fbSDavid Howells 	return top - hard_ack + 3 + sizeof(ackinfo);
1338d94aa38SDavid Howells }
1348d94aa38SDavid Howells 
1358d94aa38SDavid Howells /*
1364700c4d8SDavid Howells  * Record the beginning of an RTT probe.
1374700c4d8SDavid Howells  */
1384700c4d8SDavid Howells static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial,
1394700c4d8SDavid Howells 				 enum rxrpc_rtt_tx_trace why)
1404700c4d8SDavid Howells {
1414700c4d8SDavid Howells 	unsigned long avail = call->rtt_avail;
1424700c4d8SDavid Howells 	int rtt_slot = 9;
1434700c4d8SDavid Howells 
1444700c4d8SDavid Howells 	if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK))
1454700c4d8SDavid Howells 		goto no_slot;
1464700c4d8SDavid Howells 
1474700c4d8SDavid Howells 	rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK);
1484700c4d8SDavid Howells 	if (!test_and_clear_bit(rtt_slot, &call->rtt_avail))
1494700c4d8SDavid Howells 		goto no_slot;
1504700c4d8SDavid Howells 
1514700c4d8SDavid Howells 	call->rtt_serial[rtt_slot] = serial;
1524700c4d8SDavid Howells 	call->rtt_sent_at[rtt_slot] = ktime_get_real();
1534700c4d8SDavid Howells 	smp_wmb(); /* Write data before avail bit */
1544700c4d8SDavid Howells 	set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
1554700c4d8SDavid Howells 
1564700c4d8SDavid Howells 	trace_rxrpc_rtt_tx(call, why, rtt_slot, serial);
1574700c4d8SDavid Howells 	return rtt_slot;
1584700c4d8SDavid Howells 
1594700c4d8SDavid Howells no_slot:
1604700c4d8SDavid Howells 	trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial);
1614700c4d8SDavid Howells 	return -1;
1624700c4d8SDavid Howells }
1634700c4d8SDavid Howells 
1644700c4d8SDavid Howells /*
1654700c4d8SDavid Howells  * Cancel an RTT probe.
1664700c4d8SDavid Howells  */
1674700c4d8SDavid Howells static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call,
1684700c4d8SDavid Howells 				   rxrpc_serial_t serial, int rtt_slot)
1694700c4d8SDavid Howells {
1704700c4d8SDavid Howells 	if (rtt_slot != -1) {
1714700c4d8SDavid Howells 		clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
1724700c4d8SDavid Howells 		smp_wmb(); /* Clear pending bit before setting slot */
1734700c4d8SDavid Howells 		set_bit(rtt_slot, &call->rtt_avail);
1744700c4d8SDavid Howells 		trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial);
1754700c4d8SDavid Howells 	}
1764700c4d8SDavid Howells }
1774700c4d8SDavid Howells 
1784700c4d8SDavid Howells /*
17926cb02aaSDavid Howells  * Send an ACK call packet.
1808d94aa38SDavid Howells  */
181*72f0c6fbSDavid Howells static int rxrpc_send_ack_packet(struct rxrpc_local *local, struct rxrpc_txbuf *txb)
1828d94aa38SDavid Howells {
1835273a191SDavid Howells 	struct rxrpc_connection *conn;
18426cb02aaSDavid Howells 	struct rxrpc_ack_buffer *pkt;
185*72f0c6fbSDavid Howells 	struct rxrpc_call *call = txb->call;
1868d94aa38SDavid Howells 	struct msghdr msg;
187*72f0c6fbSDavid Howells 	struct kvec iov[1];
1888d94aa38SDavid Howells 	rxrpc_serial_t serial;
189805b21b9SDavid Howells 	rxrpc_seq_t hard_ack, top;
1908d94aa38SDavid Howells 	size_t len, n;
1914700c4d8SDavid Howells 	int ret, rtt_slot = -1;
1928d94aa38SDavid Howells 
1935273a191SDavid Howells 	if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
1948d94aa38SDavid Howells 		return -ECONNRESET;
1958d94aa38SDavid Howells 
1965273a191SDavid Howells 	conn = call->conn;
1978d94aa38SDavid Howells 
1988d94aa38SDavid Howells 	msg.msg_name	= &call->peer->srx.transport;
1998d94aa38SDavid Howells 	msg.msg_namelen	= call->peer->srx.transport_len;
2008d94aa38SDavid Howells 	msg.msg_control	= NULL;
2018d94aa38SDavid Howells 	msg.msg_controllen = 0;
2028d94aa38SDavid Howells 	msg.msg_flags	= 0;
2038d94aa38SDavid Howells 
204*72f0c6fbSDavid Howells 	if (txb->ack.reason == RXRPC_ACK_PING)
205*72f0c6fbSDavid Howells 		txb->wire.flags |= RXRPC_REQUEST_ACK;
2068d94aa38SDavid Howells 
2078d94aa38SDavid Howells 	spin_lock_bh(&call->lock);
208*72f0c6fbSDavid Howells 	n = rxrpc_fill_out_ack(conn, call, txb, &hard_ack, &top);
2098d94aa38SDavid Howells 	spin_unlock_bh(&call->lock);
2109a3dedcfSDavid Howells 	if (n == 0) {
2119a3dedcfSDavid Howells 		kfree(pkt);
2129a3dedcfSDavid Howells 		return 0;
2139a3dedcfSDavid Howells 	}
2148d94aa38SDavid Howells 
215*72f0c6fbSDavid Howells 	iov[0].iov_base	= &txb->wire;
216*72f0c6fbSDavid Howells 	iov[0].iov_len	= sizeof(txb->wire) + sizeof(txb->ack) + n;
217*72f0c6fbSDavid Howells 	len = iov[0].iov_len;
2188d94aa38SDavid Howells 
219b86e218eSDavid Howells 	serial = atomic_inc_return(&conn->serial);
220*72f0c6fbSDavid Howells 	txb->wire.serial = htonl(serial);
2214764c0daSDavid Howells 	trace_rxrpc_tx_ack(call->debug_id, serial,
222*72f0c6fbSDavid Howells 			   ntohl(txb->ack.firstPacket),
223*72f0c6fbSDavid Howells 			   ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks);
224*72f0c6fbSDavid Howells 	if (txb->ack_why == rxrpc_propose_ack_ping_for_lost_ack)
225*72f0c6fbSDavid Howells 		call->acks_lost_ping = serial;
226b86e218eSDavid Howells 
227*72f0c6fbSDavid Howells 	if (txb->ack.reason == RXRPC_ACK_PING)
2284700c4d8SDavid Howells 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping);
22926cb02aaSDavid Howells 
230f2a676d1SDavid Howells 	rxrpc_inc_stat(call->rxnet, stat_tx_ack_send);
231ed472b0cSDavid Howells 
232*72f0c6fbSDavid Howells 	iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
233ed472b0cSDavid Howells 	ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
234ed472b0cSDavid Howells 	call->peer->last_tx_at = ktime_get_seconds();
2356b47fe1dSDavid Howells 	if (ret < 0)
2366b47fe1dSDavid Howells 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
2374764c0daSDavid Howells 				    rxrpc_tx_point_call_ack);
2384764c0daSDavid Howells 	else
239*72f0c6fbSDavid Howells 		trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
2404764c0daSDavid Howells 				      rxrpc_tx_point_call_ack);
241c7e86acfSDavid Howells 	rxrpc_tx_backoff(call, ret);
2428d94aa38SDavid Howells 
24326cb02aaSDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
244*72f0c6fbSDavid Howells 		if (ret < 0)
2454700c4d8SDavid Howells 			rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
246415f44e4SDavid Howells 		rxrpc_set_keepalive(call);
247248f219cSDavid Howells 	}
248248f219cSDavid Howells 
2498d94aa38SDavid Howells 	kfree(pkt);
2508d94aa38SDavid Howells 	return ret;
2518d94aa38SDavid Howells }
2528d94aa38SDavid Howells 
2538c3e34a4SDavid Howells /*
254*72f0c6fbSDavid Howells  * ACK transmitter for a local endpoint.  The UDP socket locks around each
255*72f0c6fbSDavid Howells  * transmission, so we can only transmit one packet at a time, ACK, DATA or
256*72f0c6fbSDavid Howells  * otherwise.
257*72f0c6fbSDavid Howells  */
258*72f0c6fbSDavid Howells void rxrpc_transmit_ack_packets(struct rxrpc_local *local)
259*72f0c6fbSDavid Howells {
260*72f0c6fbSDavid Howells 	LIST_HEAD(queue);
261*72f0c6fbSDavid Howells 	int ret;
262*72f0c6fbSDavid Howells 
263*72f0c6fbSDavid Howells 	trace_rxrpc_local(local->debug_id, rxrpc_local_tx_ack,
264*72f0c6fbSDavid Howells 			  refcount_read(&local->ref), NULL);
265*72f0c6fbSDavid Howells 
266*72f0c6fbSDavid Howells 	if (list_empty(&local->ack_tx_queue))
267*72f0c6fbSDavid Howells 		return;
268*72f0c6fbSDavid Howells 
269*72f0c6fbSDavid Howells 	spin_lock_bh(&local->ack_tx_lock);
270*72f0c6fbSDavid Howells 	list_splice_tail_init(&local->ack_tx_queue, &queue);
271*72f0c6fbSDavid Howells 	spin_unlock_bh(&local->ack_tx_lock);
272*72f0c6fbSDavid Howells 
273*72f0c6fbSDavid Howells 	while (!list_empty(&queue)) {
274*72f0c6fbSDavid Howells 		struct rxrpc_txbuf *txb =
275*72f0c6fbSDavid Howells 			list_entry(queue.next, struct rxrpc_txbuf, tx_link);
276*72f0c6fbSDavid Howells 
277*72f0c6fbSDavid Howells 		ret = rxrpc_send_ack_packet(local, txb);
278*72f0c6fbSDavid Howells 		if (ret < 0 && ret != -ECONNRESET) {
279*72f0c6fbSDavid Howells 			spin_lock_bh(&local->ack_tx_lock);
280*72f0c6fbSDavid Howells 			list_splice_init(&queue, &local->ack_tx_queue);
281*72f0c6fbSDavid Howells 			spin_unlock_bh(&local->ack_tx_lock);
282*72f0c6fbSDavid Howells 			break;
283*72f0c6fbSDavid Howells 		}
284*72f0c6fbSDavid Howells 
285*72f0c6fbSDavid Howells 		list_del_init(&txb->tx_link);
286*72f0c6fbSDavid Howells 		rxrpc_put_call(txb->call, rxrpc_call_put);
287*72f0c6fbSDavid Howells 		rxrpc_put_txbuf(txb, rxrpc_txbuf_put_ack_tx);
288*72f0c6fbSDavid Howells 	}
289*72f0c6fbSDavid Howells }
290*72f0c6fbSDavid Howells 
291*72f0c6fbSDavid Howells /*
29226cb02aaSDavid Howells  * Send an ABORT call packet.
29326cb02aaSDavid Howells  */
29426cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *call)
29526cb02aaSDavid Howells {
2965273a191SDavid Howells 	struct rxrpc_connection *conn;
29726cb02aaSDavid Howells 	struct rxrpc_abort_buffer pkt;
29826cb02aaSDavid Howells 	struct msghdr msg;
29926cb02aaSDavid Howells 	struct kvec iov[1];
30026cb02aaSDavid Howells 	rxrpc_serial_t serial;
30126cb02aaSDavid Howells 	int ret;
30226cb02aaSDavid Howells 
303dcbefc30SDavid Howells 	/* Don't bother sending aborts for a client call once the server has
304dcbefc30SDavid Howells 	 * hard-ACK'd all of its request data.  After that point, we're not
305dcbefc30SDavid Howells 	 * going to stop the operation proceeding, and whilst we might limit
306dcbefc30SDavid Howells 	 * the reply, it's not worth it if we can send a new call on the same
307dcbefc30SDavid Howells 	 * channel instead, thereby closing off this call.
308dcbefc30SDavid Howells 	 */
309dcbefc30SDavid Howells 	if (rxrpc_is_client_call(call) &&
310dcbefc30SDavid Howells 	    test_bit(RXRPC_CALL_TX_LAST, &call->flags))
311dcbefc30SDavid Howells 		return 0;
312dcbefc30SDavid Howells 
3135273a191SDavid Howells 	if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
31426cb02aaSDavid Howells 		return -ECONNRESET;
31526cb02aaSDavid Howells 
3165273a191SDavid Howells 	conn = call->conn;
3175273a191SDavid Howells 
31826cb02aaSDavid Howells 	msg.msg_name	= &call->peer->srx.transport;
31926cb02aaSDavid Howells 	msg.msg_namelen	= call->peer->srx.transport_len;
32026cb02aaSDavid Howells 	msg.msg_control	= NULL;
32126cb02aaSDavid Howells 	msg.msg_controllen = 0;
32226cb02aaSDavid Howells 	msg.msg_flags	= 0;
32326cb02aaSDavid Howells 
32426cb02aaSDavid Howells 	pkt.whdr.epoch		= htonl(conn->proto.epoch);
32526cb02aaSDavid Howells 	pkt.whdr.cid		= htonl(call->cid);
32626cb02aaSDavid Howells 	pkt.whdr.callNumber	= htonl(call->call_id);
32726cb02aaSDavid Howells 	pkt.whdr.seq		= 0;
32826cb02aaSDavid Howells 	pkt.whdr.type		= RXRPC_PACKET_TYPE_ABORT;
32926cb02aaSDavid Howells 	pkt.whdr.flags		= conn->out_clientflag;
33026cb02aaSDavid Howells 	pkt.whdr.userStatus	= 0;
33126cb02aaSDavid Howells 	pkt.whdr.securityIndex	= call->security_ix;
33226cb02aaSDavid Howells 	pkt.whdr._rsvd		= 0;
33326cb02aaSDavid Howells 	pkt.whdr.serviceId	= htons(call->service_id);
33426cb02aaSDavid Howells 	pkt.abort_code		= htonl(call->abort_code);
33526cb02aaSDavid Howells 
33626cb02aaSDavid Howells 	iov[0].iov_base	= &pkt;
33726cb02aaSDavid Howells 	iov[0].iov_len	= sizeof(pkt);
33826cb02aaSDavid Howells 
33926cb02aaSDavid Howells 	serial = atomic_inc_return(&conn->serial);
34026cb02aaSDavid Howells 	pkt.whdr.serial = htonl(serial);
34126cb02aaSDavid Howells 
342ed472b0cSDavid Howells 	iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
343ed472b0cSDavid Howells 	ret = do_udp_sendmsg(conn->params.local->socket, &msg, sizeof(pkt));
344330bdcfaSDavid Howells 	conn->params.peer->last_tx_at = ktime_get_seconds();
3456b47fe1dSDavid Howells 	if (ret < 0)
3466b47fe1dSDavid Howells 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
3474764c0daSDavid Howells 				    rxrpc_tx_point_call_abort);
3484764c0daSDavid Howells 	else
3494764c0daSDavid Howells 		trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
3504764c0daSDavid Howells 				      rxrpc_tx_point_call_abort);
351c7e86acfSDavid Howells 	rxrpc_tx_backoff(call, ret);
35226cb02aaSDavid Howells 	return ret;
35326cb02aaSDavid Howells }
35426cb02aaSDavid Howells 
35526cb02aaSDavid Howells /*
3568c3e34a4SDavid Howells  * send a packet through the transport endpoint
3578c3e34a4SDavid Howells  */
358a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
359a1767077SDavid Howells 			   bool retrans)
3608c3e34a4SDavid Howells {
3614d843be5SDavid Howells 	enum rxrpc_req_ack_trace why;
3625a924b89SDavid Howells 	struct rxrpc_connection *conn = call->conn;
3635a924b89SDavid Howells 	struct rxrpc_wire_header whdr;
3645a924b89SDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
3658c3e34a4SDavid Howells 	struct msghdr msg;
3665a924b89SDavid Howells 	struct kvec iov[2];
3675a924b89SDavid Howells 	rxrpc_serial_t serial;
3685a924b89SDavid Howells 	size_t len;
3694700c4d8SDavid Howells 	int ret, rtt_slot = -1;
3708c3e34a4SDavid Howells 
3718c3e34a4SDavid Howells 	_enter(",{%d}", skb->len);
3728c3e34a4SDavid Howells 
373245500d8SDavid Howells 	if (hlist_unhashed(&call->error_link)) {
374245500d8SDavid Howells 		spin_lock_bh(&call->peer->lock);
375245500d8SDavid Howells 		hlist_add_head_rcu(&call->error_link, &call->peer->error_targets);
376245500d8SDavid Howells 		spin_unlock_bh(&call->peer->lock);
377245500d8SDavid Howells 	}
378245500d8SDavid Howells 
3795a924b89SDavid Howells 	/* Each transmission of a Tx packet needs a new serial number */
3805a924b89SDavid Howells 	serial = atomic_inc_return(&conn->serial);
3818c3e34a4SDavid Howells 
3825a924b89SDavid Howells 	whdr.epoch	= htonl(conn->proto.epoch);
3835a924b89SDavid Howells 	whdr.cid	= htonl(call->cid);
3845a924b89SDavid Howells 	whdr.callNumber	= htonl(call->call_id);
3855a924b89SDavid Howells 	whdr.seq	= htonl(sp->hdr.seq);
3865a924b89SDavid Howells 	whdr.serial	= htonl(serial);
3875a924b89SDavid Howells 	whdr.type	= RXRPC_PACKET_TYPE_DATA;
3885a924b89SDavid Howells 	whdr.flags	= sp->hdr.flags;
3895a924b89SDavid Howells 	whdr.userStatus	= 0;
3905a924b89SDavid Howells 	whdr.securityIndex = call->security_ix;
3915a924b89SDavid Howells 	whdr._rsvd	= htons(sp->hdr._rsvd);
3925a924b89SDavid Howells 	whdr.serviceId	= htons(call->service_id);
3935a924b89SDavid Howells 
3944e255721SDavid Howells 	if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
3954e255721SDavid Howells 	    sp->hdr.seq == 1)
3964e255721SDavid Howells 		whdr.userStatus	= RXRPC_USERSTATUS_SERVICE_UPGRADE;
3974e255721SDavid Howells 
3985a924b89SDavid Howells 	iov[0].iov_base = &whdr;
3995a924b89SDavid Howells 	iov[0].iov_len = sizeof(whdr);
4005a924b89SDavid Howells 	iov[1].iov_base = skb->head;
4015a924b89SDavid Howells 	iov[1].iov_len = skb->len;
4025a924b89SDavid Howells 	len = iov[0].iov_len + iov[1].iov_len;
403ed472b0cSDavid Howells 	iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
4045a924b89SDavid Howells 
4055a924b89SDavid Howells 	msg.msg_name = &call->peer->srx.transport;
4065a924b89SDavid Howells 	msg.msg_namelen = call->peer->srx.transport_len;
4078c3e34a4SDavid Howells 	msg.msg_control = NULL;
4088c3e34a4SDavid Howells 	msg.msg_controllen = 0;
4098c3e34a4SDavid Howells 	msg.msg_flags = 0;
4108c3e34a4SDavid Howells 
41157494343SDavid Howells 	/* If our RTT cache needs working on, request an ACK.  Also request
41257494343SDavid Howells 	 * ACKs if a DATA packet appears to have been lost.
413b604dd98SDavid Howells 	 *
414b604dd98SDavid Howells 	 * However, we mustn't request an ACK on the last reply packet of a
415b604dd98SDavid Howells 	 * service call, lest OpenAFS incorrectly send us an ACK with some
416b604dd98SDavid Howells 	 * soft-ACKs in it and then never follow up with a proper hard ACK.
41757494343SDavid Howells 	 */
4184d843be5SDavid Howells 	if (whdr.flags & RXRPC_REQUEST_ACK)
4194d843be5SDavid Howells 		why = rxrpc_reqack_already_on;
4204d843be5SDavid Howells 	else if ((whdr.flags & RXRPC_LAST_PACKET) && rxrpc_to_client(sp))
4214d843be5SDavid Howells 		why = rxrpc_reqack_no_srv_last;
4224d843be5SDavid Howells 	else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
4234d843be5SDavid Howells 		why = rxrpc_reqack_ack_lost;
4244d843be5SDavid Howells 	else if (retrans)
4254d843be5SDavid Howells 		why = rxrpc_reqack_retrans;
4264d843be5SDavid Howells 	else if (call->cong_mode == RXRPC_CALL_SLOW_START && call->cong_cwnd <= 2)
4274d843be5SDavid Howells 		why = rxrpc_reqack_slow_start;
4284d843be5SDavid Howells 	else if (call->tx_winsize <= 2)
4294d843be5SDavid Howells 		why = rxrpc_reqack_small_txwin;
4304d843be5SDavid Howells 	else if (call->peer->rtt_count < 3 && sp->hdr.seq & 1)
4314d843be5SDavid Howells 		why = rxrpc_reqack_more_rtt;
4324d843be5SDavid Howells 	else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), ktime_get_real()))
4334d843be5SDavid Howells 		why = rxrpc_reqack_old_rtt;
4344d843be5SDavid Howells 	else
4354d843be5SDavid Howells 		goto dont_set_request_ack;
4364d843be5SDavid Howells 
437f7fa5242SDavid Howells 	rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]);
4384d843be5SDavid Howells 	trace_rxrpc_req_ack(call->debug_id, sp->hdr.seq, why);
4394d843be5SDavid Howells 	if (why != rxrpc_reqack_no_srv_last)
4400d4b103cSDavid Howells 		whdr.flags |= RXRPC_REQUEST_ACK;
4414d843be5SDavid Howells dont_set_request_ack:
4420d4b103cSDavid Howells 
4438a681c36SDavid Howells 	if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
4448a681c36SDavid Howells 		static int lose;
4458a681c36SDavid Howells 		if ((lose++ & 7) == 7) {
446a1767077SDavid Howells 			ret = 0;
447526949e8SArnd Bergmann 			trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
448526949e8SArnd Bergmann 					    whdr.flags, retrans, true);
449526949e8SArnd Bergmann 			goto done;
4508a681c36SDavid Howells 		}
4518a681c36SDavid Howells 	}
4528a681c36SDavid Howells 
453526949e8SArnd Bergmann 	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
454526949e8SArnd Bergmann 			    false);
4555a924b89SDavid Howells 
4568c3e34a4SDavid Howells 	/* send the packet with the don't fragment bit set if we currently
4578c3e34a4SDavid Howells 	 * think it's small enough */
4585a924b89SDavid Howells 	if (iov[1].iov_len >= call->peer->maxdata)
4595a924b89SDavid Howells 		goto send_fragmentable;
4605a924b89SDavid Howells 
461985a5c82SDavid Howells 	down_read(&conn->params.local->defrag_sem);
462b604dd98SDavid Howells 
463b604dd98SDavid Howells 	sp->hdr.serial = serial;
464b604dd98SDavid Howells 	smp_wmb(); /* Set serial before timestamp */
465b604dd98SDavid Howells 	skb->tstamp = ktime_get_real();
4664700c4d8SDavid Howells 	if (whdr.flags & RXRPC_REQUEST_ACK)
4674700c4d8SDavid Howells 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
468b604dd98SDavid Howells 
4698c3e34a4SDavid Howells 	/* send the packet by UDP
4708c3e34a4SDavid Howells 	 * - returns -EMSGSIZE if UDP would have to fragment the packet
4718c3e34a4SDavid Howells 	 *   to go out of the interface
4728c3e34a4SDavid Howells 	 *   - in which case, we'll have processed the ICMP error
4738c3e34a4SDavid Howells 	 *     message and update the peer record
4748c3e34a4SDavid Howells 	 */
475b0154246SDavid Howells 	rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
476ed472b0cSDavid Howells 	ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
477330bdcfaSDavid Howells 	conn->params.peer->last_tx_at = ktime_get_seconds();
4788c3e34a4SDavid Howells 
479985a5c82SDavid Howells 	up_read(&conn->params.local->defrag_sem);
4804700c4d8SDavid Howells 	if (ret < 0) {
4814700c4d8SDavid Howells 		rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
4826b47fe1dSDavid Howells 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
4834764c0daSDavid Howells 				    rxrpc_tx_point_call_data_nofrag);
4844700c4d8SDavid Howells 	} else {
4854764c0daSDavid Howells 		trace_rxrpc_tx_packet(call->debug_id, &whdr,
4864764c0daSDavid Howells 				      rxrpc_tx_point_call_data_nofrag);
4874700c4d8SDavid Howells 	}
4884700c4d8SDavid Howells 
489c7e86acfSDavid Howells 	rxrpc_tx_backoff(call, ret);
4908c3e34a4SDavid Howells 	if (ret == -EMSGSIZE)
4918c3e34a4SDavid Howells 		goto send_fragmentable;
4928c3e34a4SDavid Howells 
4935a924b89SDavid Howells done:
49450235c4bSDavid Howells 	if (ret >= 0) {
4950d4b103cSDavid Howells 		if (whdr.flags & RXRPC_REQUEST_ACK) {
496b604dd98SDavid Howells 			call->peer->rtt_last_req = skb->tstamp;
497c410bf01SDavid Howells 			if (call->peer->rtt_count > 1) {
498bd1fdf8cSDavid Howells 				unsigned long nowj = jiffies, ack_lost_at;
499bd1fdf8cSDavid Howells 
5002c13c05cSDavid Howells 				ack_lost_at = rxrpc_get_rto_backoff(call->peer, false);
501bd1fdf8cSDavid Howells 				ack_lost_at += nowj;
502bd1fdf8cSDavid Howells 				WRITE_ONCE(call->ack_lost_at, ack_lost_at);
503bd1fdf8cSDavid Howells 				rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
504bd1fdf8cSDavid Howells 							rxrpc_timer_set_for_lost_ack);
505bd1fdf8cSDavid Howells 			}
5068c3e34a4SDavid Howells 		}
507c54e43d7SDavid Howells 
508c54e43d7SDavid Howells 		if (sp->hdr.seq == 1 &&
509c54e43d7SDavid Howells 		    !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
510c54e43d7SDavid Howells 				      &call->flags)) {
511c54e43d7SDavid Howells 			unsigned long nowj = jiffies, expect_rx_by;
512c54e43d7SDavid Howells 
513c54e43d7SDavid Howells 			expect_rx_by = nowj + call->next_rx_timo;
514c54e43d7SDavid Howells 			WRITE_ONCE(call->expect_rx_by, expect_rx_by);
515c54e43d7SDavid Howells 			rxrpc_reduce_call_timer(call, expect_rx_by, nowj,
516c54e43d7SDavid Howells 						rxrpc_timer_set_for_normal);
517c54e43d7SDavid Howells 		}
518415f44e4SDavid Howells 
519415f44e4SDavid Howells 		rxrpc_set_keepalive(call);
520c7e86acfSDavid Howells 	} else {
521c7e86acfSDavid Howells 		/* Cancel the call if the initial transmission fails,
522c7e86acfSDavid Howells 		 * particularly if that's due to network routing issues that
523c7e86acfSDavid Howells 		 * aren't going away anytime soon.  The layer above can arrange
524c7e86acfSDavid Howells 		 * the retransmission.
525c7e86acfSDavid Howells 		 */
526c7e86acfSDavid Howells 		if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags))
527c7e86acfSDavid Howells 			rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
528c7e86acfSDavid Howells 						  RX_USER_ABORT, ret);
529c7e86acfSDavid Howells 	}
530415f44e4SDavid Howells 
5315a924b89SDavid Howells 	_leave(" = %d [%u]", ret, call->peer->maxdata);
5325a924b89SDavid Howells 	return ret;
5338c3e34a4SDavid Howells 
5348c3e34a4SDavid Howells send_fragmentable:
5358c3e34a4SDavid Howells 	/* attempt to send this message with fragmentation enabled */
5368c3e34a4SDavid Howells 	_debug("send fragment");
5378c3e34a4SDavid Howells 
538985a5c82SDavid Howells 	down_write(&conn->params.local->defrag_sem);
539985a5c82SDavid Howells 
540b604dd98SDavid Howells 	sp->hdr.serial = serial;
541b604dd98SDavid Howells 	smp_wmb(); /* Set serial before timestamp */
542b604dd98SDavid Howells 	skb->tstamp = ktime_get_real();
5434700c4d8SDavid Howells 	if (whdr.flags & RXRPC_REQUEST_ACK)
5444700c4d8SDavid Howells 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
545b604dd98SDavid Howells 
546985a5c82SDavid Howells 	switch (conn->params.local->srx.transport.family) {
5470e631eeeSDavid Howells 	case AF_INET6:
548985a5c82SDavid Howells 	case AF_INET:
5492de569bdSChristoph Hellwig 		ip_sock_set_mtu_discover(conn->params.local->socket->sk,
5502de569bdSChristoph Hellwig 				IP_PMTUDISC_DONT);
551b0154246SDavid Howells 		rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag);
552ed472b0cSDavid Howells 		ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
553330bdcfaSDavid Howells 		conn->params.peer->last_tx_at = ktime_get_seconds();
5548c3e34a4SDavid Howells 
5552de569bdSChristoph Hellwig 		ip_sock_set_mtu_discover(conn->params.local->socket->sk,
5562de569bdSChristoph Hellwig 				IP_PMTUDISC_DO);
55775b54cb5SDavid Howells 		break;
5583427beb6SDavid Howells 
5593427beb6SDavid Howells 	default:
5603427beb6SDavid Howells 		BUG();
5618c3e34a4SDavid Howells 	}
5628c3e34a4SDavid Howells 
5634700c4d8SDavid Howells 	if (ret < 0) {
5644700c4d8SDavid Howells 		rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
5656b47fe1dSDavid Howells 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
5664764c0daSDavid Howells 				    rxrpc_tx_point_call_data_frag);
5674700c4d8SDavid Howells 	} else {
5684764c0daSDavid Howells 		trace_rxrpc_tx_packet(call->debug_id, &whdr,
5694764c0daSDavid Howells 				      rxrpc_tx_point_call_data_frag);
5704700c4d8SDavid Howells 	}
571c7e86acfSDavid Howells 	rxrpc_tx_backoff(call, ret);
5726b47fe1dSDavid Howells 
573985a5c82SDavid Howells 	up_write(&conn->params.local->defrag_sem);
5745a924b89SDavid Howells 	goto done;
5758c3e34a4SDavid Howells }
576248f219cSDavid Howells 
577248f219cSDavid Howells /*
578248f219cSDavid Howells  * reject packets through the local endpoint
579248f219cSDavid Howells  */
580248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *local)
581248f219cSDavid Howells {
5821c2bc7b9SDavid Howells 	struct sockaddr_rxrpc srx;
583248f219cSDavid Howells 	struct rxrpc_skb_priv *sp;
584248f219cSDavid Howells 	struct rxrpc_wire_header whdr;
585248f219cSDavid Howells 	struct sk_buff *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 
592248f219cSDavid Howells 	_enter("%d", local->debug_id);
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 
606248f219cSDavid Howells 	while ((skb = skb_dequeue(&local->reject_queue))) {
607987db9f7SDavid Howells 		rxrpc_see_skb(skb, rxrpc_skb_seen);
608248f219cSDavid Howells 		sp = rxrpc_skb(skb);
6091c2bc7b9SDavid Howells 
610ece64fecSDavid Howells 		switch (skb->mark) {
611ece64fecSDavid Howells 		case RXRPC_SKB_MARK_REJECT_BUSY:
612ece64fecSDavid Howells 			whdr.type = RXRPC_PACKET_TYPE_BUSY;
613ece64fecSDavid Howells 			size = sizeof(whdr);
614ece64fecSDavid Howells 			ioc = 1;
615ece64fecSDavid Howells 			break;
616ece64fecSDavid Howells 		case RXRPC_SKB_MARK_REJECT_ABORT:
617ece64fecSDavid Howells 			whdr.type = RXRPC_PACKET_TYPE_ABORT;
618ece64fecSDavid Howells 			code = htonl(skb->priority);
619ece64fecSDavid Howells 			size = sizeof(whdr) + sizeof(code);
620ece64fecSDavid Howells 			ioc = 2;
621ece64fecSDavid Howells 			break;
622ece64fecSDavid Howells 		default:
623987db9f7SDavid Howells 			rxrpc_free_skb(skb, rxrpc_skb_freed);
624ece64fecSDavid Howells 			continue;
625ece64fecSDavid Howells 		}
626ece64fecSDavid Howells 
6275a790b73SDavid Howells 		if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
6281c2bc7b9SDavid Howells 			msg.msg_namelen = srx.transport_len;
6291c2bc7b9SDavid Howells 
630248f219cSDavid Howells 			whdr.epoch	= htonl(sp->hdr.epoch);
631248f219cSDavid Howells 			whdr.cid	= htonl(sp->hdr.cid);
632248f219cSDavid Howells 			whdr.callNumber	= htonl(sp->hdr.callNumber);
633248f219cSDavid Howells 			whdr.serviceId	= htons(sp->hdr.serviceId);
634248f219cSDavid Howells 			whdr.flags	= sp->hdr.flags;
635248f219cSDavid Howells 			whdr.flags	^= RXRPC_CLIENT_INITIATED;
636248f219cSDavid Howells 			whdr.flags	&= RXRPC_CLIENT_INITIATED;
637248f219cSDavid Howells 
638ed472b0cSDavid Howells 			iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size);
639ed472b0cSDavid Howells 			ret = do_udp_sendmsg(local->socket, &msg, size);
6406b47fe1dSDavid Howells 			if (ret < 0)
6416b47fe1dSDavid Howells 				trace_rxrpc_tx_fail(local->debug_id, 0, ret,
6424764c0daSDavid Howells 						    rxrpc_tx_point_reject);
6434764c0daSDavid Howells 			else
6444764c0daSDavid Howells 				trace_rxrpc_tx_packet(local->debug_id, &whdr,
6454764c0daSDavid Howells 						      rxrpc_tx_point_reject);
646248f219cSDavid Howells 		}
647248f219cSDavid Howells 
648987db9f7SDavid Howells 		rxrpc_free_skb(skb, rxrpc_skb_freed);
649248f219cSDavid Howells 	}
650248f219cSDavid Howells 
651248f219cSDavid Howells 	_leave("");
652248f219cSDavid Howells }
653ace45becSDavid Howells 
654ace45becSDavid Howells /*
655ace45becSDavid Howells  * Send a VERSION reply to a peer as a keepalive.
656ace45becSDavid Howells  */
657ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *peer)
658ace45becSDavid Howells {
659ace45becSDavid Howells 	struct rxrpc_wire_header whdr;
660ace45becSDavid Howells 	struct msghdr msg;
661ace45becSDavid Howells 	struct kvec iov[2];
662ace45becSDavid Howells 	size_t len;
663ace45becSDavid Howells 	int ret;
664ace45becSDavid Howells 
665ace45becSDavid Howells 	_enter("");
666ace45becSDavid Howells 
667ace45becSDavid Howells 	msg.msg_name	= &peer->srx.transport;
668ace45becSDavid Howells 	msg.msg_namelen	= peer->srx.transport_len;
669ace45becSDavid Howells 	msg.msg_control	= NULL;
670ace45becSDavid Howells 	msg.msg_controllen = 0;
671ace45becSDavid Howells 	msg.msg_flags	= 0;
672ace45becSDavid Howells 
673ace45becSDavid Howells 	whdr.epoch	= htonl(peer->local->rxnet->epoch);
674ace45becSDavid Howells 	whdr.cid	= 0;
675ace45becSDavid Howells 	whdr.callNumber	= 0;
676ace45becSDavid Howells 	whdr.seq	= 0;
677ace45becSDavid Howells 	whdr.serial	= 0;
678ace45becSDavid Howells 	whdr.type	= RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */
679ace45becSDavid Howells 	whdr.flags	= RXRPC_LAST_PACKET;
680ace45becSDavid Howells 	whdr.userStatus	= 0;
681ace45becSDavid Howells 	whdr.securityIndex = 0;
682ace45becSDavid Howells 	whdr._rsvd	= 0;
683ace45becSDavid Howells 	whdr.serviceId	= 0;
684ace45becSDavid Howells 
685ace45becSDavid Howells 	iov[0].iov_base	= &whdr;
686ace45becSDavid Howells 	iov[0].iov_len	= sizeof(whdr);
687ace45becSDavid Howells 	iov[1].iov_base	= (char *)rxrpc_keepalive_string;
688ace45becSDavid Howells 	iov[1].iov_len	= sizeof(rxrpc_keepalive_string);
689ace45becSDavid Howells 
690ace45becSDavid Howells 	len = iov[0].iov_len + iov[1].iov_len;
691ace45becSDavid Howells 
692ace45becSDavid Howells 	_proto("Tx VERSION (keepalive)");
693ace45becSDavid Howells 
694ed472b0cSDavid Howells 	iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
695ed472b0cSDavid Howells 	ret = do_udp_sendmsg(peer->local->socket, &msg, len);
696ace45becSDavid Howells 	if (ret < 0)
6976b47fe1dSDavid Howells 		trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
6984764c0daSDavid Howells 				    rxrpc_tx_point_version_keepalive);
6994764c0daSDavid Howells 	else
7004764c0daSDavid Howells 		trace_rxrpc_tx_packet(peer->debug_id, &whdr,
7014764c0daSDavid Howells 				      rxrpc_tx_point_version_keepalive);
702ace45becSDavid Howells 
703330bdcfaSDavid Howells 	peer->last_tx_at = ktime_get_seconds();
704ace45becSDavid Howells 	_leave("");
705ace45becSDavid Howells }
706