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