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