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 | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 35 | /* |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 36 | * Arrange for a keepalive ping a certain time after we last transmitted. This |
| 37 | * lets the far side know we're still interested in this call and helps keep |
| 38 | * the route through any intervening firewall open. |
| 39 | * |
| 40 | * Receiving a response to the ping will prevent the ->expect_rx_by timer from |
| 41 | * expiring. |
| 42 | */ |
| 43 | static void rxrpc_set_keepalive(struct rxrpc_call *call) |
| 44 | { |
| 45 | unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6; |
| 46 | |
| 47 | keepalive_at += now; |
| 48 | WRITE_ONCE(call->keepalive_at, keepalive_at); |
| 49 | rxrpc_reduce_call_timer(call, keepalive_at, now, |
| 50 | rxrpc_timer_set_for_keepalive); |
| 51 | } |
| 52 | |
| 53 | /* |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 54 | * Fill out an ACK packet. |
| 55 | */ |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 56 | static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn, |
| 57 | struct rxrpc_call *call, |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 58 | struct rxrpc_ack_buffer *pkt, |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 59 | rxrpc_seq_t *_hard_ack, |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 60 | rxrpc_seq_t *_top, |
| 61 | u8 reason) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 62 | { |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 63 | rxrpc_serial_t serial; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 64 | rxrpc_seq_t hard_ack, top, seq; |
| 65 | int ix; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 66 | u32 mtu, jmax; |
| 67 | u8 *ackp = pkt->acks; |
| 68 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 69 | /* Barrier against rxrpc_input_data(). */ |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 70 | serial = call->ackr_serial; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 71 | hard_ack = READ_ONCE(call->rx_hard_ack); |
| 72 | top = smp_load_acquire(&call->rx_top); |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 73 | *_hard_ack = hard_ack; |
| 74 | *_top = top; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 75 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 76 | pkt->ack.bufferSpace = htons(8); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 77 | pkt->ack.maxSkew = htons(call->ackr_skew); |
| 78 | pkt->ack.firstPacket = htonl(hard_ack + 1); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 79 | pkt->ack.previousPacket = htonl(call->ackr_prev_seq); |
David Howells | f3639df | 2016-09-17 10:49:13 +0100 | [diff] [blame] | 80 | pkt->ack.serial = htonl(serial); |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 81 | pkt->ack.reason = reason; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 82 | pkt->ack.nAcks = top - hard_ack; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 83 | |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 84 | if (reason == RXRPC_ACK_PING) |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 85 | pkt->whdr.flags |= RXRPC_REQUEST_ACK; |
| 86 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 87 | if (after(top, hard_ack)) { |
| 88 | seq = hard_ack + 1; |
| 89 | do { |
| 90 | ix = seq & RXRPC_RXTX_BUFF_MASK; |
| 91 | if (call->rxtx_buffer[ix]) |
| 92 | *ackp++ = RXRPC_ACK_TYPE_ACK; |
| 93 | else |
| 94 | *ackp++ = RXRPC_ACK_TYPE_NACK; |
| 95 | seq++; |
| 96 | } while (before_eq(seq, top)); |
| 97 | } |
| 98 | |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 99 | mtu = conn->params.peer->if_mtu; |
| 100 | mtu -= conn->params.peer->hdrsize; |
David Howells | 75e4212 | 2016-09-13 22:36:22 +0100 | [diff] [blame] | 101 | jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 102 | pkt->ackinfo.rxMTU = htonl(rxrpc_rx_mtu); |
| 103 | pkt->ackinfo.maxMTU = htonl(mtu); |
David Howells | 75e4212 | 2016-09-13 22:36:22 +0100 | [diff] [blame] | 104 | pkt->ackinfo.rwind = htonl(call->rx_winsize); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 105 | pkt->ackinfo.jumbo_max = htonl(jmax); |
| 106 | |
| 107 | *ackp++ = 0; |
| 108 | *ackp++ = 0; |
| 109 | *ackp++ = 0; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 110 | return top - hard_ack + 3; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 114 | * Send an ACK call packet. |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 115 | */ |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 116 | int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, |
| 117 | rxrpc_serial_t *_serial) |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 118 | { |
| 119 | struct rxrpc_connection *conn = NULL; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 120 | struct rxrpc_ack_buffer *pkt; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 121 | struct msghdr msg; |
| 122 | struct kvec iov[2]; |
| 123 | rxrpc_serial_t serial; |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 124 | rxrpc_seq_t hard_ack, top; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 125 | size_t len, n; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 126 | int ret; |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 127 | u8 reason; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 128 | |
| 129 | spin_lock_bh(&call->lock); |
| 130 | if (call->conn) |
| 131 | conn = rxrpc_get_connection_maybe(call->conn); |
| 132 | spin_unlock_bh(&call->lock); |
| 133 | if (!conn) |
| 134 | return -ECONNRESET; |
| 135 | |
| 136 | pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); |
| 137 | if (!pkt) { |
| 138 | rxrpc_put_connection(conn); |
| 139 | return -ENOMEM; |
| 140 | } |
| 141 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 142 | msg.msg_name = &call->peer->srx.transport; |
| 143 | msg.msg_namelen = call->peer->srx.transport_len; |
| 144 | msg.msg_control = NULL; |
| 145 | msg.msg_controllen = 0; |
| 146 | msg.msg_flags = 0; |
| 147 | |
| 148 | pkt->whdr.epoch = htonl(conn->proto.epoch); |
| 149 | pkt->whdr.cid = htonl(call->cid); |
| 150 | pkt->whdr.callNumber = htonl(call->call_id); |
| 151 | pkt->whdr.seq = 0; |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 152 | pkt->whdr.type = RXRPC_PACKET_TYPE_ACK; |
| 153 | pkt->whdr.flags = RXRPC_SLOW_START_OK | conn->out_clientflag; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 154 | pkt->whdr.userStatus = 0; |
| 155 | pkt->whdr.securityIndex = call->security_ix; |
| 156 | pkt->whdr._rsvd = 0; |
| 157 | pkt->whdr.serviceId = htons(call->service_id); |
| 158 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 159 | spin_lock_bh(&call->lock); |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 160 | if (ping) { |
| 161 | reason = RXRPC_ACK_PING; |
| 162 | } else { |
| 163 | reason = call->ackr_reason; |
| 164 | if (!call->ackr_reason) { |
| 165 | spin_unlock_bh(&call->lock); |
| 166 | ret = 0; |
| 167 | goto out; |
| 168 | } |
| 169 | call->ackr_reason = 0; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 170 | } |
David Howells | 1457cc4 | 2017-11-02 15:06:55 +0000 | [diff] [blame] | 171 | n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 172 | |
| 173 | spin_unlock_bh(&call->lock); |
| 174 | |
| 175 | iov[0].iov_base = pkt; |
| 176 | iov[0].iov_len = sizeof(pkt->whdr) + sizeof(pkt->ack) + n; |
| 177 | iov[1].iov_base = &pkt->ackinfo; |
| 178 | iov[1].iov_len = sizeof(pkt->ackinfo); |
| 179 | len = iov[0].iov_len + iov[1].iov_len; |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 180 | |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 181 | serial = atomic_inc_return(&conn->serial); |
| 182 | pkt->whdr.serial = htonl(serial); |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 183 | trace_rxrpc_tx_ack(call, serial, |
| 184 | ntohl(pkt->ack.firstPacket), |
| 185 | ntohl(pkt->ack.serial), |
| 186 | pkt->ack.reason, pkt->ack.nAcks); |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 187 | if (_serial) |
| 188 | *_serial = serial; |
David Howells | b86e218 | 2016-09-23 15:08:48 +0100 | [diff] [blame] | 189 | |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 190 | if (ping) { |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 191 | call->ping_serial = serial; |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 192 | smp_wmb(); |
| 193 | /* We need to stick a time in before we send the packet in case |
| 194 | * the reply gets back before kernel_sendmsg() completes - but |
| 195 | * asking UDP to send the packet can take a relatively long |
| 196 | * time, so we update the time after, on the assumption that |
| 197 | * the packet transmission is more likely to happen towards the |
| 198 | * end of the kernel_sendmsg() call. |
| 199 | */ |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 200 | call->ping_time = ktime_get_real(); |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 201 | set_bit(RXRPC_CALL_PINGING, &call->flags); |
| 202 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_ping, serial); |
| 203 | } |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 204 | |
| 205 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); |
David Howells | 8e83134 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 206 | if (ping) |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 207 | call->ping_time = ktime_get_real(); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 208 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 209 | if (call->state < RXRPC_CALL_COMPLETE) { |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 210 | if (ret < 0) { |
David Howells | a5af7e1 | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 211 | if (ping) |
| 212 | clear_bit(RXRPC_CALL_PINGING, &call->flags); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 213 | rxrpc_propose_ACK(call, pkt->ack.reason, |
| 214 | ntohs(pkt->ack.maxSkew), |
| 215 | ntohl(pkt->ack.serial), |
David Howells | 9c7ad43 | 2016-09-23 13:50:40 +0100 | [diff] [blame] | 216 | true, true, |
| 217 | rxrpc_propose_ack_retry_tx); |
David Howells | 805b21b | 2016-09-24 18:05:26 +0100 | [diff] [blame] | 218 | } else { |
| 219 | spin_lock_bh(&call->lock); |
| 220 | if (after(hard_ack, call->ackr_consumed)) |
| 221 | call->ackr_consumed = hard_ack; |
| 222 | if (after(top, call->ackr_seen)) |
| 223 | call->ackr_seen = top; |
| 224 | spin_unlock_bh(&call->lock); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 225 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 226 | |
| 227 | rxrpc_set_keepalive(call); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 228 | } |
| 229 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 230 | out: |
| 231 | rxrpc_put_connection(conn); |
| 232 | kfree(pkt); |
| 233 | return ret; |
| 234 | } |
| 235 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 236 | /* |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 237 | * Send an ABORT call packet. |
| 238 | */ |
| 239 | int rxrpc_send_abort_packet(struct rxrpc_call *call) |
| 240 | { |
| 241 | struct rxrpc_connection *conn = NULL; |
| 242 | struct rxrpc_abort_buffer pkt; |
| 243 | struct msghdr msg; |
| 244 | struct kvec iov[1]; |
| 245 | rxrpc_serial_t serial; |
| 246 | int ret; |
| 247 | |
David Howells | dcbefc3 | 2017-11-02 15:06:26 +0000 | [diff] [blame] | 248 | /* Don't bother sending aborts for a client call once the server has |
| 249 | * hard-ACK'd all of its request data. After that point, we're not |
| 250 | * going to stop the operation proceeding, and whilst we might limit |
| 251 | * the reply, it's not worth it if we can send a new call on the same |
| 252 | * channel instead, thereby closing off this call. |
| 253 | */ |
| 254 | if (rxrpc_is_client_call(call) && |
| 255 | test_bit(RXRPC_CALL_TX_LAST, &call->flags)) |
| 256 | return 0; |
| 257 | |
David Howells | 26cb02a | 2016-10-06 08:11:49 +0100 | [diff] [blame] | 258 | spin_lock_bh(&call->lock); |
| 259 | if (call->conn) |
| 260 | conn = rxrpc_get_connection_maybe(call->conn); |
| 261 | spin_unlock_bh(&call->lock); |
| 262 | if (!conn) |
| 263 | return -ECONNRESET; |
| 264 | |
| 265 | msg.msg_name = &call->peer->srx.transport; |
| 266 | msg.msg_namelen = call->peer->srx.transport_len; |
| 267 | msg.msg_control = NULL; |
| 268 | msg.msg_controllen = 0; |
| 269 | msg.msg_flags = 0; |
| 270 | |
| 271 | pkt.whdr.epoch = htonl(conn->proto.epoch); |
| 272 | pkt.whdr.cid = htonl(call->cid); |
| 273 | pkt.whdr.callNumber = htonl(call->call_id); |
| 274 | pkt.whdr.seq = 0; |
| 275 | pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 276 | pkt.whdr.flags = conn->out_clientflag; |
| 277 | pkt.whdr.userStatus = 0; |
| 278 | pkt.whdr.securityIndex = call->security_ix; |
| 279 | pkt.whdr._rsvd = 0; |
| 280 | pkt.whdr.serviceId = htons(call->service_id); |
| 281 | pkt.abort_code = htonl(call->abort_code); |
| 282 | |
| 283 | iov[0].iov_base = &pkt; |
| 284 | iov[0].iov_len = sizeof(pkt); |
| 285 | |
| 286 | serial = atomic_inc_return(&conn->serial); |
| 287 | pkt.whdr.serial = htonl(serial); |
| 288 | |
| 289 | ret = kernel_sendmsg(conn->params.local->socket, |
| 290 | &msg, iov, 1, sizeof(pkt)); |
| 291 | |
| 292 | rxrpc_put_connection(conn); |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 297 | * send a packet through the transport endpoint |
| 298 | */ |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 299 | int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, |
| 300 | bool retrans) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 301 | { |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 302 | struct rxrpc_connection *conn = call->conn; |
| 303 | struct rxrpc_wire_header whdr; |
| 304 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 305 | struct msghdr msg; |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 306 | struct kvec iov[2]; |
| 307 | rxrpc_serial_t serial; |
| 308 | size_t len; |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 309 | bool lost = false; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 310 | int ret, opt; |
| 311 | |
| 312 | _enter(",{%d}", skb->len); |
| 313 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 314 | /* Each transmission of a Tx packet needs a new serial number */ |
| 315 | serial = atomic_inc_return(&conn->serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 316 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 317 | whdr.epoch = htonl(conn->proto.epoch); |
| 318 | whdr.cid = htonl(call->cid); |
| 319 | whdr.callNumber = htonl(call->call_id); |
| 320 | whdr.seq = htonl(sp->hdr.seq); |
| 321 | whdr.serial = htonl(serial); |
| 322 | whdr.type = RXRPC_PACKET_TYPE_DATA; |
| 323 | whdr.flags = sp->hdr.flags; |
| 324 | whdr.userStatus = 0; |
| 325 | whdr.securityIndex = call->security_ix; |
| 326 | whdr._rsvd = htons(sp->hdr._rsvd); |
| 327 | whdr.serviceId = htons(call->service_id); |
| 328 | |
David Howells | 4e25572 | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 329 | if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) && |
| 330 | sp->hdr.seq == 1) |
| 331 | whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE; |
| 332 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 333 | iov[0].iov_base = &whdr; |
| 334 | iov[0].iov_len = sizeof(whdr); |
| 335 | iov[1].iov_base = skb->head; |
| 336 | iov[1].iov_len = skb->len; |
| 337 | len = iov[0].iov_len + iov[1].iov_len; |
| 338 | |
| 339 | msg.msg_name = &call->peer->srx.transport; |
| 340 | msg.msg_namelen = call->peer->srx.transport_len; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 341 | msg.msg_control = NULL; |
| 342 | msg.msg_controllen = 0; |
| 343 | msg.msg_flags = 0; |
| 344 | |
David Howells | 5749434 | 2016-09-24 18:05:27 +0100 | [diff] [blame] | 345 | /* If our RTT cache needs working on, request an ACK. Also request |
| 346 | * ACKs if a DATA packet appears to have been lost. |
| 347 | */ |
David Howells | bf7d620 | 2016-10-06 08:11:51 +0100 | [diff] [blame] | 348 | if (!(sp->hdr.flags & RXRPC_LAST_PACKET) && |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 349 | (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || |
| 350 | retrans || |
David Howells | bf7d620 | 2016-10-06 08:11:51 +0100 | [diff] [blame] | 351 | call->cong_mode == RXRPC_CALL_SLOW_START || |
| 352 | (call->peer->rtt_usage < 3 && sp->hdr.seq & 1) || |
| 353 | ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), |
| 354 | ktime_get_real()))) |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 355 | whdr.flags |= RXRPC_REQUEST_ACK; |
| 356 | |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 357 | if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { |
| 358 | static int lose; |
| 359 | if ((lose++ & 7) == 7) { |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 360 | ret = 0; |
| 361 | lost = true; |
| 362 | goto done; |
David Howells | 8a681c36 | 2016-09-17 10:49:15 +0100 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 366 | _proto("Tx DATA %%%u { #%u }", serial, sp->hdr.seq); |
| 367 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 368 | /* send the packet with the don't fragment bit set if we currently |
| 369 | * think it's small enough */ |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 370 | if (iov[1].iov_len >= call->peer->maxdata) |
| 371 | goto send_fragmentable; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 372 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 373 | down_read(&conn->params.local->defrag_sem); |
| 374 | /* send the packet by UDP |
| 375 | * - returns -EMSGSIZE if UDP would have to fragment the packet |
| 376 | * to go out of the interface |
| 377 | * - in which case, we'll have processed the ICMP error |
| 378 | * message and update the peer record |
| 379 | */ |
| 380 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 381 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 382 | up_read(&conn->params.local->defrag_sem); |
| 383 | if (ret == -EMSGSIZE) |
| 384 | goto send_fragmentable; |
| 385 | |
| 386 | done: |
David Howells | a176707 | 2016-09-29 22:37:15 +0100 | [diff] [blame] | 387 | trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, |
| 388 | retrans, lost); |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 389 | if (ret >= 0) { |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 390 | ktime_t now = ktime_get_real(); |
| 391 | skb->tstamp = now; |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 392 | smp_wmb(); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 393 | sp->hdr.serial = serial; |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 394 | if (whdr.flags & RXRPC_REQUEST_ACK) { |
| 395 | call->peer->rtt_last_req = now; |
David Howells | 50235c4 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 396 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); |
David Howells | bd1fdf8 | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 397 | if (call->peer->rtt_usage > 1) { |
| 398 | unsigned long nowj = jiffies, ack_lost_at; |
| 399 | |
| 400 | ack_lost_at = nsecs_to_jiffies(2 * call->peer->rtt); |
| 401 | if (ack_lost_at < 1) |
| 402 | ack_lost_at = 1; |
| 403 | |
| 404 | ack_lost_at += nowj; |
| 405 | WRITE_ONCE(call->ack_lost_at, ack_lost_at); |
| 406 | rxrpc_reduce_call_timer(call, ack_lost_at, nowj, |
| 407 | rxrpc_timer_set_for_lost_ack); |
| 408 | } |
David Howells | 0d4b103 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 409 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 410 | } |
David Howells | 415f44e | 2017-11-24 10:18:42 +0000 | [diff] [blame] | 411 | |
| 412 | rxrpc_set_keepalive(call); |
| 413 | |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 414 | _leave(" = %d [%u]", ret, call->peer->maxdata); |
| 415 | return ret; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 416 | |
| 417 | send_fragmentable: |
| 418 | /* attempt to send this message with fragmentation enabled */ |
| 419 | _debug("send fragment"); |
| 420 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 421 | down_write(&conn->params.local->defrag_sem); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 422 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 423 | switch (conn->params.local->srx.transport.family) { |
| 424 | case AF_INET: |
| 425 | opt = IP_PMTUDISC_DONT; |
| 426 | ret = kernel_setsockopt(conn->params.local->socket, |
| 427 | SOL_IP, IP_MTU_DISCOVER, |
| 428 | (char *)&opt, sizeof(opt)); |
| 429 | if (ret == 0) { |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 430 | ret = kernel_sendmsg(conn->params.local->socket, &msg, |
| 431 | iov, 2, len); |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 432 | |
| 433 | opt = IP_PMTUDISC_DO; |
| 434 | kernel_setsockopt(conn->params.local->socket, SOL_IP, |
| 435 | IP_MTU_DISCOVER, |
| 436 | (char *)&opt, sizeof(opt)); |
| 437 | } |
| 438 | break; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 439 | |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 440 | #ifdef CONFIG_AF_RXRPC_IPV6 |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 441 | case AF_INET6: |
| 442 | opt = IPV6_PMTUDISC_DONT; |
| 443 | ret = kernel_setsockopt(conn->params.local->socket, |
| 444 | SOL_IPV6, IPV6_MTU_DISCOVER, |
| 445 | (char *)&opt, sizeof(opt)); |
| 446 | if (ret == 0) { |
| 447 | ret = kernel_sendmsg(conn->params.local->socket, &msg, |
David Howells | 93c62c4 | 2018-02-22 14:38:14 +0000 | [diff] [blame] | 448 | iov, 2, len); |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 449 | |
| 450 | opt = IPV6_PMTUDISC_DO; |
| 451 | kernel_setsockopt(conn->params.local->socket, |
| 452 | SOL_IPV6, IPV6_MTU_DISCOVER, |
| 453 | (char *)&opt, sizeof(opt)); |
| 454 | } |
| 455 | break; |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 456 | #endif |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 457 | } |
| 458 | |
David Howells | 985a5c8 | 2016-06-17 11:53:37 +0100 | [diff] [blame] | 459 | up_write(&conn->params.local->defrag_sem); |
David Howells | 5a924b8 | 2016-09-22 00:29:31 +0100 | [diff] [blame] | 460 | goto done; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 461 | } |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * reject packets through the local endpoint |
| 465 | */ |
| 466 | void rxrpc_reject_packets(struct rxrpc_local *local) |
| 467 | { |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 468 | struct sockaddr_rxrpc srx; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 469 | struct rxrpc_skb_priv *sp; |
| 470 | struct rxrpc_wire_header whdr; |
| 471 | struct sk_buff *skb; |
| 472 | struct msghdr msg; |
| 473 | struct kvec iov[2]; |
| 474 | size_t size; |
| 475 | __be32 code; |
| 476 | |
| 477 | _enter("%d", local->debug_id); |
| 478 | |
| 479 | iov[0].iov_base = &whdr; |
| 480 | iov[0].iov_len = sizeof(whdr); |
| 481 | iov[1].iov_base = &code; |
| 482 | iov[1].iov_len = sizeof(code); |
| 483 | size = sizeof(whdr) + sizeof(code); |
| 484 | |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 485 | msg.msg_name = &srx.transport; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 486 | msg.msg_control = NULL; |
| 487 | msg.msg_controllen = 0; |
| 488 | msg.msg_flags = 0; |
| 489 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 490 | memset(&whdr, 0, sizeof(whdr)); |
| 491 | whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 492 | |
| 493 | while ((skb = skb_dequeue(&local->reject_queue))) { |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 494 | rxrpc_see_skb(skb, rxrpc_skb_rx_seen); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 495 | sp = rxrpc_skb(skb); |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 496 | |
David Howells | 7b674e3 | 2017-08-29 10:18:37 +0100 | [diff] [blame] | 497 | if (rxrpc_extract_addr_from_skb(local, &srx, skb) == 0) { |
David Howells | 1c2bc7b | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 498 | msg.msg_namelen = srx.transport_len; |
| 499 | |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 500 | code = htonl(skb->priority); |
| 501 | |
| 502 | whdr.epoch = htonl(sp->hdr.epoch); |
| 503 | whdr.cid = htonl(sp->hdr.cid); |
| 504 | whdr.callNumber = htonl(sp->hdr.callNumber); |
| 505 | whdr.serviceId = htons(sp->hdr.serviceId); |
| 506 | whdr.flags = sp->hdr.flags; |
| 507 | whdr.flags ^= RXRPC_CLIENT_INITIATED; |
| 508 | whdr.flags &= RXRPC_CLIENT_INITIATED; |
| 509 | |
| 510 | kernel_sendmsg(local->socket, &msg, iov, 2, size); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 511 | } |
| 512 | |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 513 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | _leave(""); |
| 517 | } |