xref: /openbmc/linux/net/rxrpc/output.c (revision f97769fd)
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  */
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  */
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  */
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 	rxrpc_seq_t hard_ack, top, seq;
78 	int ix;
79 	u32 mtu, jmax;
80 	u8 *ackp = pkt->acks;
81 
82 	/* Barrier against rxrpc_input_data(). */
83 	serial = call->ackr_serial;
84 	hard_ack = READ_ONCE(call->rx_hard_ack);
85 	top = smp_load_acquire(&call->rx_top);
86 	*_hard_ack = hard_ack;
87 	*_top = top;
88 
89 	pkt->ack.bufferSpace	= htons(8);
90 	pkt->ack.maxSkew	= htons(0);
91 	pkt->ack.firstPacket	= htonl(hard_ack + 1);
92 	pkt->ack.previousPacket	= htonl(call->ackr_prev_seq);
93 	pkt->ack.serial		= htonl(serial);
94 	pkt->ack.reason		= reason;
95 	pkt->ack.nAcks		= top - hard_ack;
96 
97 	if (reason == RXRPC_ACK_PING)
98 		pkt->whdr.flags |= RXRPC_REQUEST_ACK;
99 
100 	if (after(top, hard_ack)) {
101 		seq = hard_ack + 1;
102 		do {
103 			ix = seq & RXRPC_RXTX_BUFF_MASK;
104 			if (call->rxtx_buffer[ix])
105 				*ackp++ = RXRPC_ACK_TYPE_ACK;
106 			else
107 				*ackp++ = RXRPC_ACK_TYPE_NACK;
108 			seq++;
109 		} while (before_eq(seq, top));
110 	}
111 
112 	mtu = conn->params.peer->if_mtu;
113 	mtu -= conn->params.peer->hdrsize;
114 	jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max;
115 	pkt->ackinfo.rxMTU	= htonl(rxrpc_rx_mtu);
116 	pkt->ackinfo.maxMTU	= htonl(mtu);
117 	pkt->ackinfo.rwind	= htonl(call->rx_winsize);
118 	pkt->ackinfo.jumbo_max	= htonl(jmax);
119 
120 	*ackp++ = 0;
121 	*ackp++ = 0;
122 	*ackp++ = 0;
123 	return top - hard_ack + 3;
124 }
125 
126 /*
127  * Record the beginning of an RTT probe.
128  */
129 static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial,
130 				 enum rxrpc_rtt_tx_trace why)
131 {
132 	unsigned long avail = call->rtt_avail;
133 	int rtt_slot = 9;
134 
135 	if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK))
136 		goto no_slot;
137 
138 	rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK);
139 	if (!test_and_clear_bit(rtt_slot, &call->rtt_avail))
140 		goto no_slot;
141 
142 	call->rtt_serial[rtt_slot] = serial;
143 	call->rtt_sent_at[rtt_slot] = ktime_get_real();
144 	smp_wmb(); /* Write data before avail bit */
145 	set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
146 
147 	trace_rxrpc_rtt_tx(call, why, rtt_slot, serial);
148 	return rtt_slot;
149 
150 no_slot:
151 	trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial);
152 	return -1;
153 }
154 
155 /*
156  * Cancel an RTT probe.
157  */
158 static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call,
159 				   rxrpc_serial_t serial, int rtt_slot)
160 {
161 	if (rtt_slot != -1) {
162 		clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
163 		smp_wmb(); /* Clear pending bit before setting slot */
164 		set_bit(rtt_slot, &call->rtt_avail);
165 		trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial);
166 	}
167 }
168 
169 /*
170  * Send an ACK call packet.
171  */
172 int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping,
173 			  rxrpc_serial_t *_serial)
174 {
175 	struct rxrpc_connection *conn;
176 	struct rxrpc_ack_buffer *pkt;
177 	struct msghdr msg;
178 	struct kvec iov[2];
179 	rxrpc_serial_t serial;
180 	rxrpc_seq_t hard_ack, top;
181 	size_t len, n;
182 	int ret, rtt_slot = -1;
183 	u8 reason;
184 
185 	if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
186 		return -ECONNRESET;
187 
188 	pkt = kzalloc(sizeof(*pkt), GFP_KERNEL);
189 	if (!pkt)
190 		return -ENOMEM;
191 
192 	conn = call->conn;
193 
194 	msg.msg_name	= &call->peer->srx.transport;
195 	msg.msg_namelen	= call->peer->srx.transport_len;
196 	msg.msg_control	= NULL;
197 	msg.msg_controllen = 0;
198 	msg.msg_flags	= 0;
199 
200 	pkt->whdr.epoch		= htonl(conn->proto.epoch);
201 	pkt->whdr.cid		= htonl(call->cid);
202 	pkt->whdr.callNumber	= htonl(call->call_id);
203 	pkt->whdr.seq		= 0;
204 	pkt->whdr.type		= RXRPC_PACKET_TYPE_ACK;
205 	pkt->whdr.flags		= RXRPC_SLOW_START_OK | conn->out_clientflag;
206 	pkt->whdr.userStatus	= 0;
207 	pkt->whdr.securityIndex	= call->security_ix;
208 	pkt->whdr._rsvd		= 0;
209 	pkt->whdr.serviceId	= htons(call->service_id);
210 
211 	spin_lock_bh(&call->lock);
212 	if (ping) {
213 		reason = RXRPC_ACK_PING;
214 	} else {
215 		reason = call->ackr_reason;
216 		if (!call->ackr_reason) {
217 			spin_unlock_bh(&call->lock);
218 			ret = 0;
219 			goto out;
220 		}
221 		call->ackr_reason = 0;
222 	}
223 	n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason);
224 
225 	spin_unlock_bh(&call->lock);
226 
227 	iov[0].iov_base	= pkt;
228 	iov[0].iov_len	= sizeof(pkt->whdr) + sizeof(pkt->ack) + n;
229 	iov[1].iov_base = &pkt->ackinfo;
230 	iov[1].iov_len	= sizeof(pkt->ackinfo);
231 	len = iov[0].iov_len + iov[1].iov_len;
232 
233 	serial = atomic_inc_return(&conn->serial);
234 	pkt->whdr.serial = htonl(serial);
235 	trace_rxrpc_tx_ack(call->debug_id, serial,
236 			   ntohl(pkt->ack.firstPacket),
237 			   ntohl(pkt->ack.serial),
238 			   pkt->ack.reason, pkt->ack.nAcks);
239 	if (_serial)
240 		*_serial = serial;
241 
242 	if (ping)
243 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping);
244 
245 	ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
246 	conn->params.peer->last_tx_at = ktime_get_seconds();
247 	if (ret < 0)
248 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
249 				    rxrpc_tx_point_call_ack);
250 	else
251 		trace_rxrpc_tx_packet(call->debug_id, &pkt->whdr,
252 				      rxrpc_tx_point_call_ack);
253 	rxrpc_tx_backoff(call, ret);
254 
255 	if (call->state < RXRPC_CALL_COMPLETE) {
256 		if (ret < 0) {
257 			rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
258 			rxrpc_propose_ACK(call, pkt->ack.reason,
259 					  ntohl(pkt->ack.serial),
260 					  false, true,
261 					  rxrpc_propose_ack_retry_tx);
262 		} else {
263 			spin_lock_bh(&call->lock);
264 			if (after(hard_ack, call->ackr_consumed))
265 				call->ackr_consumed = hard_ack;
266 			if (after(top, call->ackr_seen))
267 				call->ackr_seen = top;
268 			spin_unlock_bh(&call->lock);
269 		}
270 
271 		rxrpc_set_keepalive(call);
272 	}
273 
274 out:
275 	kfree(pkt);
276 	return ret;
277 }
278 
279 /*
280  * Send an ABORT call packet.
281  */
282 int rxrpc_send_abort_packet(struct rxrpc_call *call)
283 {
284 	struct rxrpc_connection *conn;
285 	struct rxrpc_abort_buffer pkt;
286 	struct msghdr msg;
287 	struct kvec iov[1];
288 	rxrpc_serial_t serial;
289 	int ret;
290 
291 	/* Don't bother sending aborts for a client call once the server has
292 	 * hard-ACK'd all of its request data.  After that point, we're not
293 	 * going to stop the operation proceeding, and whilst we might limit
294 	 * the reply, it's not worth it if we can send a new call on the same
295 	 * channel instead, thereby closing off this call.
296 	 */
297 	if (rxrpc_is_client_call(call) &&
298 	    test_bit(RXRPC_CALL_TX_LAST, &call->flags))
299 		return 0;
300 
301 	if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
302 		return -ECONNRESET;
303 
304 	conn = call->conn;
305 
306 	msg.msg_name	= &call->peer->srx.transport;
307 	msg.msg_namelen	= call->peer->srx.transport_len;
308 	msg.msg_control	= NULL;
309 	msg.msg_controllen = 0;
310 	msg.msg_flags	= 0;
311 
312 	pkt.whdr.epoch		= htonl(conn->proto.epoch);
313 	pkt.whdr.cid		= htonl(call->cid);
314 	pkt.whdr.callNumber	= htonl(call->call_id);
315 	pkt.whdr.seq		= 0;
316 	pkt.whdr.type		= RXRPC_PACKET_TYPE_ABORT;
317 	pkt.whdr.flags		= conn->out_clientflag;
318 	pkt.whdr.userStatus	= 0;
319 	pkt.whdr.securityIndex	= call->security_ix;
320 	pkt.whdr._rsvd		= 0;
321 	pkt.whdr.serviceId	= htons(call->service_id);
322 	pkt.abort_code		= htonl(call->abort_code);
323 
324 	iov[0].iov_base	= &pkt;
325 	iov[0].iov_len	= sizeof(pkt);
326 
327 	serial = atomic_inc_return(&conn->serial);
328 	pkt.whdr.serial = htonl(serial);
329 
330 	ret = kernel_sendmsg(conn->params.local->socket,
331 			     &msg, iov, 1, sizeof(pkt));
332 	conn->params.peer->last_tx_at = ktime_get_seconds();
333 	if (ret < 0)
334 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
335 				    rxrpc_tx_point_call_abort);
336 	else
337 		trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
338 				      rxrpc_tx_point_call_abort);
339 	rxrpc_tx_backoff(call, ret);
340 	return ret;
341 }
342 
343 /*
344  * send a packet through the transport endpoint
345  */
346 int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
347 			   bool retrans)
348 {
349 	struct rxrpc_connection *conn = call->conn;
350 	struct rxrpc_wire_header whdr;
351 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
352 	struct msghdr msg;
353 	struct kvec iov[2];
354 	rxrpc_serial_t serial;
355 	size_t len;
356 	int ret, rtt_slot = -1;
357 
358 	_enter(",{%d}", skb->len);
359 
360 	/* Each transmission of a Tx packet needs a new serial number */
361 	serial = atomic_inc_return(&conn->serial);
362 
363 	whdr.epoch	= htonl(conn->proto.epoch);
364 	whdr.cid	= htonl(call->cid);
365 	whdr.callNumber	= htonl(call->call_id);
366 	whdr.seq	= htonl(sp->hdr.seq);
367 	whdr.serial	= htonl(serial);
368 	whdr.type	= RXRPC_PACKET_TYPE_DATA;
369 	whdr.flags	= sp->hdr.flags;
370 	whdr.userStatus	= 0;
371 	whdr.securityIndex = call->security_ix;
372 	whdr._rsvd	= htons(sp->hdr._rsvd);
373 	whdr.serviceId	= htons(call->service_id);
374 
375 	if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
376 	    sp->hdr.seq == 1)
377 		whdr.userStatus	= RXRPC_USERSTATUS_SERVICE_UPGRADE;
378 
379 	iov[0].iov_base = &whdr;
380 	iov[0].iov_len = sizeof(whdr);
381 	iov[1].iov_base = skb->head;
382 	iov[1].iov_len = skb->len;
383 	len = iov[0].iov_len + iov[1].iov_len;
384 
385 	msg.msg_name = &call->peer->srx.transport;
386 	msg.msg_namelen = call->peer->srx.transport_len;
387 	msg.msg_control = NULL;
388 	msg.msg_controllen = 0;
389 	msg.msg_flags = 0;
390 
391 	/* If our RTT cache needs working on, request an ACK.  Also request
392 	 * ACKs if a DATA packet appears to have been lost.
393 	 *
394 	 * However, we mustn't request an ACK on the last reply packet of a
395 	 * service call, lest OpenAFS incorrectly send us an ACK with some
396 	 * soft-ACKs in it and then never follow up with a proper hard ACK.
397 	 */
398 	if ((!(sp->hdr.flags & RXRPC_LAST_PACKET) ||
399 	     rxrpc_to_server(sp)
400 	     ) &&
401 	    (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) ||
402 	     retrans ||
403 	     call->cong_mode == RXRPC_CALL_SLOW_START ||
404 	     (call->peer->rtt_count < 3 && sp->hdr.seq & 1) ||
405 	     ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000),
406 			  ktime_get_real())))
407 		whdr.flags |= RXRPC_REQUEST_ACK;
408 
409 	if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
410 		static int lose;
411 		if ((lose++ & 7) == 7) {
412 			ret = 0;
413 			trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
414 					    whdr.flags, retrans, true);
415 			goto done;
416 		}
417 	}
418 
419 	trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
420 			    false);
421 
422 	/* send the packet with the don't fragment bit set if we currently
423 	 * think it's small enough */
424 	if (iov[1].iov_len >= call->peer->maxdata)
425 		goto send_fragmentable;
426 
427 	down_read(&conn->params.local->defrag_sem);
428 
429 	sp->hdr.serial = serial;
430 	smp_wmb(); /* Set serial before timestamp */
431 	skb->tstamp = ktime_get_real();
432 	if (whdr.flags & RXRPC_REQUEST_ACK)
433 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
434 
435 	/* send the packet by UDP
436 	 * - returns -EMSGSIZE if UDP would have to fragment the packet
437 	 *   to go out of the interface
438 	 *   - in which case, we'll have processed the ICMP error
439 	 *     message and update the peer record
440 	 */
441 	ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
442 	conn->params.peer->last_tx_at = ktime_get_seconds();
443 
444 	up_read(&conn->params.local->defrag_sem);
445 	if (ret < 0) {
446 		rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
447 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
448 				    rxrpc_tx_point_call_data_nofrag);
449 	} else {
450 		trace_rxrpc_tx_packet(call->debug_id, &whdr,
451 				      rxrpc_tx_point_call_data_nofrag);
452 	}
453 
454 	rxrpc_tx_backoff(call, ret);
455 	if (ret == -EMSGSIZE)
456 		goto send_fragmentable;
457 
458 done:
459 	if (ret >= 0) {
460 		if (whdr.flags & RXRPC_REQUEST_ACK) {
461 			call->peer->rtt_last_req = skb->tstamp;
462 			if (call->peer->rtt_count > 1) {
463 				unsigned long nowj = jiffies, ack_lost_at;
464 
465 				ack_lost_at = rxrpc_get_rto_backoff(call->peer, retrans);
466 				ack_lost_at += nowj;
467 				WRITE_ONCE(call->ack_lost_at, ack_lost_at);
468 				rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
469 							rxrpc_timer_set_for_lost_ack);
470 			}
471 		}
472 
473 		if (sp->hdr.seq == 1 &&
474 		    !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
475 				      &call->flags)) {
476 			unsigned long nowj = jiffies, expect_rx_by;
477 
478 			expect_rx_by = nowj + call->next_rx_timo;
479 			WRITE_ONCE(call->expect_rx_by, expect_rx_by);
480 			rxrpc_reduce_call_timer(call, expect_rx_by, nowj,
481 						rxrpc_timer_set_for_normal);
482 		}
483 
484 		rxrpc_set_keepalive(call);
485 	} else {
486 		/* Cancel the call if the initial transmission fails,
487 		 * particularly if that's due to network routing issues that
488 		 * aren't going away anytime soon.  The layer above can arrange
489 		 * the retransmission.
490 		 */
491 		if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags))
492 			rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
493 						  RX_USER_ABORT, ret);
494 	}
495 
496 	_leave(" = %d [%u]", ret, call->peer->maxdata);
497 	return ret;
498 
499 send_fragmentable:
500 	/* attempt to send this message with fragmentation enabled */
501 	_debug("send fragment");
502 
503 	down_write(&conn->params.local->defrag_sem);
504 
505 	sp->hdr.serial = serial;
506 	smp_wmb(); /* Set serial before timestamp */
507 	skb->tstamp = ktime_get_real();
508 	if (whdr.flags & RXRPC_REQUEST_ACK)
509 		rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
510 
511 	switch (conn->params.local->srx.transport.family) {
512 	case AF_INET6:
513 	case AF_INET:
514 		ip_sock_set_mtu_discover(conn->params.local->socket->sk,
515 				IP_PMTUDISC_DONT);
516 		ret = kernel_sendmsg(conn->params.local->socket, &msg,
517 				     iov, 2, len);
518 		conn->params.peer->last_tx_at = ktime_get_seconds();
519 
520 		ip_sock_set_mtu_discover(conn->params.local->socket->sk,
521 				IP_PMTUDISC_DO);
522 		break;
523 
524 	default:
525 		BUG();
526 	}
527 
528 	if (ret < 0) {
529 		rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
530 		trace_rxrpc_tx_fail(call->debug_id, serial, ret,
531 				    rxrpc_tx_point_call_data_frag);
532 	} else {
533 		trace_rxrpc_tx_packet(call->debug_id, &whdr,
534 				      rxrpc_tx_point_call_data_frag);
535 	}
536 	rxrpc_tx_backoff(call, ret);
537 
538 	up_write(&conn->params.local->defrag_sem);
539 	goto done;
540 }
541 
542 /*
543  * reject packets through the local endpoint
544  */
545 void rxrpc_reject_packets(struct rxrpc_local *local)
546 {
547 	struct sockaddr_rxrpc srx;
548 	struct rxrpc_skb_priv *sp;
549 	struct rxrpc_wire_header whdr;
550 	struct sk_buff *skb;
551 	struct msghdr msg;
552 	struct kvec iov[2];
553 	size_t size;
554 	__be32 code;
555 	int ret, ioc;
556 
557 	_enter("%d", local->debug_id);
558 
559 	iov[0].iov_base = &whdr;
560 	iov[0].iov_len = sizeof(whdr);
561 	iov[1].iov_base = &code;
562 	iov[1].iov_len = sizeof(code);
563 
564 	msg.msg_name = &srx.transport;
565 	msg.msg_control = NULL;
566 	msg.msg_controllen = 0;
567 	msg.msg_flags = 0;
568 
569 	memset(&whdr, 0, sizeof(whdr));
570 
571 	while ((skb = skb_dequeue(&local->reject_queue))) {
572 		rxrpc_see_skb(skb, rxrpc_skb_seen);
573 		sp = rxrpc_skb(skb);
574 
575 		switch (skb->mark) {
576 		case RXRPC_SKB_MARK_REJECT_BUSY:
577 			whdr.type = RXRPC_PACKET_TYPE_BUSY;
578 			size = sizeof(whdr);
579 			ioc = 1;
580 			break;
581 		case RXRPC_SKB_MARK_REJECT_ABORT:
582 			whdr.type = RXRPC_PACKET_TYPE_ABORT;
583 			code = htonl(skb->priority);
584 			size = sizeof(whdr) + sizeof(code);
585 			ioc = 2;
586 			break;
587 		default:
588 			rxrpc_free_skb(skb, rxrpc_skb_freed);
589 			continue;
590 		}
591 
592 		if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
593 			msg.msg_namelen = srx.transport_len;
594 
595 			whdr.epoch	= htonl(sp->hdr.epoch);
596 			whdr.cid	= htonl(sp->hdr.cid);
597 			whdr.callNumber	= htonl(sp->hdr.callNumber);
598 			whdr.serviceId	= htons(sp->hdr.serviceId);
599 			whdr.flags	= sp->hdr.flags;
600 			whdr.flags	^= RXRPC_CLIENT_INITIATED;
601 			whdr.flags	&= RXRPC_CLIENT_INITIATED;
602 
603 			ret = kernel_sendmsg(local->socket, &msg,
604 					     iov, ioc, size);
605 			if (ret < 0)
606 				trace_rxrpc_tx_fail(local->debug_id, 0, ret,
607 						    rxrpc_tx_point_reject);
608 			else
609 				trace_rxrpc_tx_packet(local->debug_id, &whdr,
610 						      rxrpc_tx_point_reject);
611 		}
612 
613 		rxrpc_free_skb(skb, rxrpc_skb_freed);
614 	}
615 
616 	_leave("");
617 }
618 
619 /*
620  * Send a VERSION reply to a peer as a keepalive.
621  */
622 void rxrpc_send_keepalive(struct rxrpc_peer *peer)
623 {
624 	struct rxrpc_wire_header whdr;
625 	struct msghdr msg;
626 	struct kvec iov[2];
627 	size_t len;
628 	int ret;
629 
630 	_enter("");
631 
632 	msg.msg_name	= &peer->srx.transport;
633 	msg.msg_namelen	= peer->srx.transport_len;
634 	msg.msg_control	= NULL;
635 	msg.msg_controllen = 0;
636 	msg.msg_flags	= 0;
637 
638 	whdr.epoch	= htonl(peer->local->rxnet->epoch);
639 	whdr.cid	= 0;
640 	whdr.callNumber	= 0;
641 	whdr.seq	= 0;
642 	whdr.serial	= 0;
643 	whdr.type	= RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */
644 	whdr.flags	= RXRPC_LAST_PACKET;
645 	whdr.userStatus	= 0;
646 	whdr.securityIndex = 0;
647 	whdr._rsvd	= 0;
648 	whdr.serviceId	= 0;
649 
650 	iov[0].iov_base	= &whdr;
651 	iov[0].iov_len	= sizeof(whdr);
652 	iov[1].iov_base	= (char *)rxrpc_keepalive_string;
653 	iov[1].iov_len	= sizeof(rxrpc_keepalive_string);
654 
655 	len = iov[0].iov_len + iov[1].iov_len;
656 
657 	_proto("Tx VERSION (keepalive)");
658 
659 	ret = kernel_sendmsg(peer->local->socket, &msg, iov, 2, len);
660 	if (ret < 0)
661 		trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
662 				    rxrpc_tx_point_version_keepalive);
663 	else
664 		trace_rxrpc_tx_packet(peer->debug_id, &whdr,
665 				      rxrpc_tx_point_version_keepalive);
666 
667 	peer->last_tx_at = ktime_get_seconds();
668 	_leave("");
669 }
670