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