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