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