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