Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 2 | /* RxRPC packet transmission |
| 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 10 | #include <linux/net.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/gfp.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 12 | #include <linux/skbuff.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 14 | #include <net/sock.h> |
| 15 | #include <net/af_rxrpc.h> |
| 16 | #include "ar-internal.h" |
| 17 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 18 | struct rxrpc_ack_buffer { |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 19 | struct rxrpc_wire_header whdr; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 20 | struct rxrpc_ackpacket ack; |
| 21 | u8 acks[255]; |
| 22 | u8 pad[3]; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 23 | struct rxrpc_ackinfo ackinfo; |
| 24 | }; |
| 25 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 26 | struct rxrpc_abort_buffer { |
| 27 | struct rxrpc_wire_header whdr; |
| 28 | __be32 abort_code; |
| 29 | }; |
| 30 | |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 31 | static const char rxrpc_keepalive_string[] = ""; |
| 32 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 33 | /* |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 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 | /* |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 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 | /* |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 67 | * Fill out an ACK packet. |
| 68 | */ |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 69 | static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn, |
| 70 | struct rxrpc_call *call, |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 71 | struct rxrpc_ack_buffer *pkt, |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 72 | rxrpc_seq_t *_hard_ack, |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 73 | rxrpc_seq_t *_top, |
| 74 | u8 reason) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 75 | { |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 76 | rxrpc_serial_t serial; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 77 | rxrpc_seq_t hard_ack, top, seq; |
| 78 | int ix; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 79 | u32 mtu, jmax; |
| 80 | u8 *ackp = pkt->acks; |
| 81 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 82 | /* Barrier against rxrpc_input_data(). */ |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 83 | serial = call->ackr_serial; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 84 | hard_ack = READ_ONCE(call->rx_hard_ack); |
| 85 | top = smp_load_acquire(&call->rx_top); |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 86 | *_hard_ack = hard_ack; |
| 87 | *_top = top; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 88 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 89 | pkt->ack.bufferSpace = htons(8); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 90 | pkt->ack.maxSkew = htons(call->ackr_skew); |
| 91 | pkt->ack.firstPacket = htonl(hard_ack + 1); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 92 | pkt->ack.previousPacket = htonl(call->ackr_prev_seq); |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 93 | pkt->ack.serial = htonl(serial); |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 94 | pkt->ack.reason = reason; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 95 | pkt->ack.nAcks = top - hard_ack; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 96 | |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 97 | if (reason == RXRPC_ACK_PING) |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 98 | pkt->whdr.flags |= RXRPC_REQUEST_ACK; |
| 99 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 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 | |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 112 | mtu = conn->params.peer->if_mtu; |
| 113 | mtu -= conn->params.peer->hdrsize; |
David Howells | 75e4212 | 2016-09-13 22:36:22 +0100 | [diff] [blame] | 114 | jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 115 | pkt->ackinfo.rxMTU = htonl(rxrpc_rx_mtu); |
| 116 | pkt->ackinfo.maxMTU = htonl(mtu); |
David Howells | 75e4212 | 2016-09-13 22:36:22 +0100 | [diff] [blame] | 117 | pkt->ackinfo.rwind = htonl(call->rx_winsize); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 118 | pkt->ackinfo.jumbo_max = htonl(jmax); |
| 119 | |
| 120 | *ackp++ = 0; |
| 121 | *ackp++ = 0; |
| 122 | *ackp++ = 0; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 123 | return top - hard_ack + 3; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 127 | * Send an ACK call packet. |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 128 | */ |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 129 | int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, |
| 130 | rxrpc_serial_t *_serial) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 131 | { |
| 132 | struct rxrpc_connection *conn = NULL; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 133 | struct rxrpc_ack_buffer *pkt; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 134 | struct msghdr msg; |
| 135 | struct kvec iov[2]; |
| 136 | rxrpc_serial_t serial; |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 137 | rxrpc_seq_t hard_ack, top; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 138 | size_t len, n; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 139 | int ret; |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 140 | u8 reason; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 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 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 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; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 165 | pkt->whdr.type = RXRPC_PACKET_TYPE_ACK; |
| 166 | pkt->whdr.flags = RXRPC_SLOW_START_OK | conn->out_clientflag; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 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 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 172 | spin_lock_bh(&call->lock); |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 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; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 183 | } |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 184 | n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 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; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 193 | |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 194 | serial = atomic_inc_return(&conn->serial); |
| 195 | pkt->whdr.serial = htonl(serial); |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 196 | trace_rxrpc_tx_ack(call->debug_id, serial, |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 197 | ntohl(pkt->ack.firstPacket), |
| 198 | ntohl(pkt->ack.serial), |
| 199 | pkt->ack.reason, pkt->ack.nAcks); |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 200 | if (_serial) |
| 201 | *_serial = serial; |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 202 | |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 203 | if (ping) { |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 204 | call->ping_serial = serial; |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 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 |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 209 | * time. |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 210 | */ |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 211 | call->ping_time = ktime_get_real(); |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 212 | set_bit(RXRPC_CALL_PINGING, &call->flags); |
| 213 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_ping, serial); |
| 214 | } |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 215 | |
| 216 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 217 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 218 | if (ret < 0) |
| 219 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 220 | rxrpc_tx_point_call_ack); |
| 221 | else |
| 222 | trace_rxrpc_tx_packet(call->debug_id, &pkt->whdr, |
| 223 | rxrpc_tx_point_call_ack); |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 224 | rxrpc_tx_backoff(call, ret); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 225 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 226 | if (call->state < RXRPC_CALL_COMPLETE) { |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 227 | if (ret < 0) { |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 228 | if (ping) |
| 229 | clear_bit(RXRPC_CALL_PINGING, &call->flags); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 230 | rxrpc_propose_ACK(call, pkt->ack.reason, |
| 231 | ntohs(pkt->ack.maxSkew), |
| 232 | ntohl(pkt->ack.serial), |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 233 | false, true, |
David Howells | 9c7ad43 | 2016-09-23 13:50:40 +0100 | [diff] [blame] | 234 | rxrpc_propose_ack_retry_tx); |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 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); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 242 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 243 | |
| 244 | rxrpc_set_keepalive(call); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 245 | } |
| 246 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 247 | out: |
| 248 | rxrpc_put_connection(conn); |
| 249 | kfree(pkt); |
| 250 | return ret; |
| 251 | } |
| 252 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 253 | /* |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 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 | |
David Howells | dcbefc3 | 2017-11-02 15:06:26 +0000 | [diff] [blame] | 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 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 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)); |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 308 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 309 | if (ret < 0) |
| 310 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 311 | rxrpc_tx_point_call_abort); |
| 312 | else |
| 313 | trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr, |
| 314 | rxrpc_tx_point_call_abort); |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 315 | rxrpc_tx_backoff(call, ret); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 316 | |
| 317 | rxrpc_put_connection(conn); |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 322 | * send a packet through the transport endpoint |
| 323 | */ |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 324 | int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, |
| 325 | bool retrans) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 326 | { |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 327 | struct rxrpc_connection *conn = call->conn; |
| 328 | struct rxrpc_wire_header whdr; |
| 329 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 330 | struct msghdr msg; |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 331 | struct kvec iov[2]; |
| 332 | rxrpc_serial_t serial; |
| 333 | size_t len; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 334 | int ret, opt; |
| 335 | |
| 336 | _enter(",{%d}", skb->len); |
| 337 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 338 | /* Each transmission of a Tx packet needs a new serial number */ |
| 339 | serial = atomic_inc_return(&conn->serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 340 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 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 | |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 353 | if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) && |
| 354 | sp->hdr.seq == 1) |
| 355 | whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE; |
| 356 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 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; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 365 | msg.msg_control = NULL; |
| 366 | msg.msg_controllen = 0; |
| 367 | msg.msg_flags = 0; |
| 368 | |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 369 | /* If our RTT cache needs working on, request an ACK. Also request |
| 370 | * ACKs if a DATA packet appears to have been lost. |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 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. |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 375 | */ |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 376 | if ((!(sp->hdr.flags & RXRPC_LAST_PACKET) || |
| 377 | rxrpc_to_server(sp) |
| 378 | ) && |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 379 | (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || |
| 380 | retrans || |
David Howells | bf7d620 | 2016-10-06 08:11:51 +0100 | [diff] [blame] | 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()))) |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 385 | whdr.flags |= RXRPC_REQUEST_ACK; |
| 386 | |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 387 | if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { |
| 388 | static int lose; |
| 389 | if ((lose++ & 7) == 7) { |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 390 | ret = 0; |
Arnd Bergmann | 526949e | 2019-03-22 15:18:43 +0100 | [diff] [blame] | 391 | trace_rxrpc_tx_data(call, sp->hdr.seq, serial, |
| 392 | whdr.flags, retrans, true); |
| 393 | goto done; |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Arnd Bergmann | 526949e | 2019-03-22 15:18:43 +0100 | [diff] [blame] | 397 | trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans, |
| 398 | false); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 399 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 400 | /* send the packet with the don't fragment bit set if we currently |
| 401 | * think it's small enough */ |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 402 | if (iov[1].iov_len >= call->peer->maxdata) |
| 403 | goto send_fragmentable; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 404 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 405 | down_read(&conn->params.local->defrag_sem); |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 406 | |
| 407 | sp->hdr.serial = serial; |
| 408 | smp_wmb(); /* Set serial before timestamp */ |
| 409 | skb->tstamp = ktime_get_real(); |
| 410 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 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); |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 418 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 419 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 420 | up_read(&conn->params.local->defrag_sem); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 421 | if (ret < 0) |
| 422 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 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); |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 427 | rxrpc_tx_backoff(call, ret); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 428 | if (ret == -EMSGSIZE) |
| 429 | goto send_fragmentable; |
| 430 | |
| 431 | done: |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 432 | if (ret >= 0) { |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 433 | if (whdr.flags & RXRPC_REQUEST_ACK) { |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 434 | call->peer->rtt_last_req = skb->tstamp; |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 435 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 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 | } |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 448 | } |
David Howells | c54e43d | 2018-05-10 23:26:00 +0100 | [diff] [blame] | 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 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 460 | |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 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 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 472 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 473 | _leave(" = %d [%u]", ret, call->peer->maxdata); |
| 474 | return ret; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 475 | |
| 476 | send_fragmentable: |
| 477 | /* attempt to send this message with fragmentation enabled */ |
| 478 | _debug("send fragment"); |
| 479 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 480 | down_write(&conn->params.local->defrag_sem); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 481 | |
David Howells | b604dd9 | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 482 | sp->hdr.serial = serial; |
| 483 | smp_wmb(); /* Set serial before timestamp */ |
| 484 | skb->tstamp = ktime_get_real(); |
| 485 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 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) { |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 493 | ret = kernel_sendmsg(conn->params.local->socket, &msg, |
| 494 | iov, 2, len); |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 495 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 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; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 503 | |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 504 | #ifdef CONFIG_AF_RXRPC_IPV6 |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 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, |
David Howells | 93c62c4 | 2018-02-22 14:38:14 +0000 | [diff] [blame] | 512 | iov, 2, len); |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 513 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 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; |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 521 | #endif |
David Howells | 3427beb | 2019-07-02 15:55:28 +0100 | [diff] [blame^] | 522 | |
| 523 | default: |
| 524 | BUG(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 525 | } |
| 526 | |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 527 | if (ret < 0) |
| 528 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 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); |
David Howells | c7e86ac | 2018-11-01 13:39:53 +0000 | [diff] [blame] | 533 | rxrpc_tx_backoff(call, ret); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 534 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 535 | up_write(&conn->params.local->defrag_sem); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 536 | goto done; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 537 | } |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 538 | |
| 539 | /* |
| 540 | * reject packets through the local endpoint |
| 541 | */ |
| 542 | void rxrpc_reject_packets(struct rxrpc_local *local) |
| 543 | { |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 544 | struct sockaddr_rxrpc srx; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 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; |
David Howells | ece64fe | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 552 | int ret, ioc; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 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); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 560 | |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 561 | msg.msg_name = &srx.transport; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 562 | msg.msg_control = NULL; |
| 563 | msg.msg_controllen = 0; |
| 564 | msg.msg_flags = 0; |
| 565 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 566 | memset(&whdr, 0, sizeof(whdr)); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 567 | |
| 568 | while ((skb = skb_dequeue(&local->reject_queue))) { |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 569 | rxrpc_see_skb(skb, rxrpc_skb_rx_seen); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 570 | sp = rxrpc_skb(skb); |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 571 | |
David Howells | ece64fe | 2018-09-27 15:13:08 +0100 | [diff] [blame] | 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 | |
David Howells | 5a790b7 | 2018-10-04 09:32:28 +0100 | [diff] [blame] | 589 | if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) { |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 590 | msg.msg_namelen = srx.transport_len; |
| 591 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 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 | |
YueHaibing | d6672a5 | 2018-10-11 22:32:39 +0100 | [diff] [blame] | 600 | ret = kernel_sendmsg(local->socket, &msg, |
| 601 | iov, ioc, size); |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 602 | if (ret < 0) |
| 603 | trace_rxrpc_tx_fail(local->debug_id, 0, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 604 | rxrpc_tx_point_reject); |
| 605 | else |
| 606 | trace_rxrpc_tx_packet(local->debug_id, &whdr, |
| 607 | rxrpc_tx_point_reject); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 608 | } |
| 609 | |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 610 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | _leave(""); |
| 614 | } |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 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) |
David Howells | 6b47fe1 | 2018-05-10 23:26:01 +0100 | [diff] [blame] | 658 | trace_rxrpc_tx_fail(peer->debug_id, 0, ret, |
David Howells | 4764c0d | 2018-07-23 17:18:37 +0100 | [diff] [blame] | 659 | rxrpc_tx_point_version_keepalive); |
| 660 | else |
| 661 | trace_rxrpc_tx_packet(peer->debug_id, &whdr, |
| 662 | rxrpc_tx_point_version_keepalive); |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 663 | |
David Howells | 330bdcf | 2018-08-08 11:30:02 +0100 | [diff] [blame] | 664 | peer->last_tx_at = ktime_get_seconds(); |
David Howells | ace45be | 2018-03-30 21:04:43 +0100 | [diff] [blame] | 665 | _leave(""); |
| 666 | } |