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