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