David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 1 | /* RxRPC packet reception |
| 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/module.h> |
| 15 | #include <linux/net.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/errqueue.h> |
| 18 | #include <linux/udp.h> |
| 19 | #include <linux/in.h> |
| 20 | #include <linux/in6.h> |
| 21 | #include <linux/icmp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 23 | #include <net/sock.h> |
| 24 | #include <net/af_rxrpc.h> |
| 25 | #include <net/ip.h> |
Herbert Xu | 1781f7f | 2007-12-11 11:30:32 -0800 | [diff] [blame] | 26 | #include <net/udp.h> |
Pavel Emelyanov | 0283328 | 2008-07-05 21:18:48 -0700 | [diff] [blame] | 27 | #include <net/net_namespace.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 28 | #include "ar-internal.h" |
| 29 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 30 | /* |
| 31 | * queue a packet for recvmsg to pass to userspace |
| 32 | * - the caller must hold a lock on call->lock |
| 33 | * - must not be called with interrupts disabled (sk_filter() disables BH's) |
| 34 | * - eats the packet whether successful or not |
| 35 | * - there must be just one reference to the packet, which the caller passes to |
| 36 | * this function |
| 37 | */ |
| 38 | int rxrpc_queue_rcv_skb(struct rxrpc_call *call, struct sk_buff *skb, |
| 39 | bool force, bool terminal) |
| 40 | { |
| 41 | struct rxrpc_skb_priv *sp; |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 42 | struct rxrpc_sock *rx = call->socket; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 43 | struct sock *sk; |
Eric Dumazet | 884cf70 | 2014-08-22 20:30:12 -0700 | [diff] [blame] | 44 | int ret; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 45 | |
| 46 | _enter(",,%d,%d", force, terminal); |
| 47 | |
| 48 | ASSERT(!irqs_disabled()); |
| 49 | |
| 50 | sp = rxrpc_skb(skb); |
| 51 | ASSERTCMP(sp->call, ==, call); |
| 52 | |
| 53 | /* if we've already posted the terminal message for a call, then we |
| 54 | * don't post any more */ |
| 55 | if (test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) { |
| 56 | _debug("already terminated"); |
| 57 | ASSERTCMP(call->state, >=, RXRPC_CALL_COMPLETE); |
| 58 | skb->destructor = NULL; |
| 59 | sp->call = NULL; |
| 60 | rxrpc_put_call(call); |
| 61 | rxrpc_free_skb(skb); |
| 62 | return 0; |
| 63 | } |
| 64 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 65 | sk = &rx->sk; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 66 | |
| 67 | if (!force) { |
| 68 | /* cast skb->rcvbuf to unsigned... It's pointless, but |
| 69 | * reduces number of warnings when compiling with -W |
| 70 | * --ANK */ |
| 71 | // ret = -ENOBUFS; |
| 72 | // if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 73 | // (unsigned int) sk->sk_rcvbuf) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 74 | // goto out; |
| 75 | |
| 76 | ret = sk_filter(sk, skb); |
| 77 | if (ret < 0) |
| 78 | goto out; |
| 79 | } |
| 80 | |
| 81 | spin_lock_bh(&sk->sk_receive_queue.lock); |
| 82 | if (!test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags) && |
| 83 | !test_bit(RXRPC_CALL_RELEASED, &call->flags) && |
| 84 | call->socket->sk.sk_state != RXRPC_CLOSE) { |
| 85 | skb->destructor = rxrpc_packet_destructor; |
| 86 | skb->dev = NULL; |
| 87 | skb->sk = sk; |
| 88 | atomic_add(skb->truesize, &sk->sk_rmem_alloc); |
| 89 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 90 | if (terminal) { |
| 91 | _debug("<<<< TERMINAL MESSAGE >>>>"); |
| 92 | set_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags); |
| 93 | } |
| 94 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 95 | /* allow interception by a kernel service */ |
| 96 | if (rx->interceptor) { |
| 97 | rx->interceptor(sk, call->user_call_ID, skb); |
| 98 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
| 99 | } else { |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 100 | _net("post skb %p", skb); |
| 101 | __skb_queue_tail(&sk->sk_receive_queue, skb); |
| 102 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
| 103 | |
| 104 | if (!sock_flag(sk, SOCK_DEAD)) |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 105 | sk->sk_data_ready(sk); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 106 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 107 | skb = NULL; |
| 108 | } else { |
| 109 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
| 110 | } |
| 111 | ret = 0; |
| 112 | |
| 113 | out: |
| 114 | /* release the socket buffer */ |
| 115 | if (skb) { |
| 116 | skb->destructor = NULL; |
| 117 | sp->call = NULL; |
| 118 | rxrpc_put_call(call); |
| 119 | rxrpc_free_skb(skb); |
| 120 | } |
| 121 | |
| 122 | _leave(" = %d", ret); |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * process a DATA packet, posting the packet to the appropriate queue |
| 128 | * - eats the packet if successful |
| 129 | */ |
| 130 | static int rxrpc_fast_process_data(struct rxrpc_call *call, |
| 131 | struct sk_buff *skb, u32 seq) |
| 132 | { |
| 133 | struct rxrpc_skb_priv *sp; |
| 134 | bool terminal; |
| 135 | int ret, ackbit, ack; |
| 136 | |
| 137 | _enter("{%u,%u},,{%u}", call->rx_data_post, call->rx_first_oos, seq); |
| 138 | |
| 139 | sp = rxrpc_skb(skb); |
| 140 | ASSERTCMP(sp->call, ==, NULL); |
| 141 | |
| 142 | spin_lock(&call->lock); |
| 143 | |
| 144 | if (call->state > RXRPC_CALL_COMPLETE) |
| 145 | goto discard; |
| 146 | |
| 147 | ASSERTCMP(call->rx_data_expect, >=, call->rx_data_post); |
| 148 | ASSERTCMP(call->rx_data_post, >=, call->rx_data_recv); |
| 149 | ASSERTCMP(call->rx_data_recv, >=, call->rx_data_eaten); |
| 150 | |
| 151 | if (seq < call->rx_data_post) { |
| 152 | _debug("dup #%u [-%u]", seq, call->rx_data_post); |
| 153 | ack = RXRPC_ACK_DUPLICATE; |
| 154 | ret = -ENOBUFS; |
| 155 | goto discard_and_ack; |
| 156 | } |
| 157 | |
| 158 | /* we may already have the packet in the out of sequence queue */ |
| 159 | ackbit = seq - (call->rx_data_eaten + 1); |
| 160 | ASSERTCMP(ackbit, >=, 0); |
David S. Miller | 68c708f | 2007-04-26 20:20:21 -0700 | [diff] [blame] | 161 | if (__test_and_set_bit(ackbit, call->ackr_window)) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 162 | _debug("dup oos #%u [%u,%u]", |
| 163 | seq, call->rx_data_eaten, call->rx_data_post); |
| 164 | ack = RXRPC_ACK_DUPLICATE; |
| 165 | goto discard_and_ack; |
| 166 | } |
| 167 | |
| 168 | if (seq >= call->ackr_win_top) { |
| 169 | _debug("exceed #%u [%u]", seq, call->ackr_win_top); |
David S. Miller | 68c708f | 2007-04-26 20:20:21 -0700 | [diff] [blame] | 170 | __clear_bit(ackbit, call->ackr_window); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 171 | ack = RXRPC_ACK_EXCEEDS_WINDOW; |
| 172 | goto discard_and_ack; |
| 173 | } |
| 174 | |
| 175 | if (seq == call->rx_data_expect) { |
| 176 | clear_bit(RXRPC_CALL_EXPECT_OOS, &call->flags); |
| 177 | call->rx_data_expect++; |
| 178 | } else if (seq > call->rx_data_expect) { |
| 179 | _debug("oos #%u [%u]", seq, call->rx_data_expect); |
| 180 | call->rx_data_expect = seq + 1; |
| 181 | if (test_and_set_bit(RXRPC_CALL_EXPECT_OOS, &call->flags)) { |
| 182 | ack = RXRPC_ACK_OUT_OF_SEQUENCE; |
| 183 | goto enqueue_and_ack; |
| 184 | } |
| 185 | goto enqueue_packet; |
| 186 | } |
| 187 | |
| 188 | if (seq != call->rx_data_post) { |
| 189 | _debug("ahead #%u [%u]", seq, call->rx_data_post); |
| 190 | goto enqueue_packet; |
| 191 | } |
| 192 | |
| 193 | if (test_bit(RXRPC_CALL_RCVD_LAST, &call->flags)) |
| 194 | goto protocol_error; |
| 195 | |
| 196 | /* if the packet need security things doing to it, then it goes down |
| 197 | * the slow path */ |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 198 | if (call->conn->security_ix) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 199 | goto enqueue_packet; |
| 200 | |
| 201 | sp->call = call; |
| 202 | rxrpc_get_call(call); |
| 203 | terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) && |
| 204 | !(sp->hdr.flags & RXRPC_CLIENT_INITIATED)); |
| 205 | ret = rxrpc_queue_rcv_skb(call, skb, false, terminal); |
| 206 | if (ret < 0) { |
| 207 | if (ret == -ENOMEM || ret == -ENOBUFS) { |
David S. Miller | 68c708f | 2007-04-26 20:20:21 -0700 | [diff] [blame] | 208 | __clear_bit(ackbit, call->ackr_window); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 209 | ack = RXRPC_ACK_NOSPACE; |
| 210 | goto discard_and_ack; |
| 211 | } |
| 212 | goto out; |
| 213 | } |
| 214 | |
| 215 | skb = NULL; |
| 216 | |
| 217 | _debug("post #%u", seq); |
| 218 | ASSERTCMP(call->rx_data_post, ==, seq); |
| 219 | call->rx_data_post++; |
| 220 | |
| 221 | if (sp->hdr.flags & RXRPC_LAST_PACKET) |
| 222 | set_bit(RXRPC_CALL_RCVD_LAST, &call->flags); |
| 223 | |
| 224 | /* if we've reached an out of sequence packet then we need to drain |
| 225 | * that queue into the socket Rx queue now */ |
| 226 | if (call->rx_data_post == call->rx_first_oos) { |
| 227 | _debug("drain rx oos now"); |
| 228 | read_lock(&call->state_lock); |
| 229 | if (call->state < RXRPC_CALL_COMPLETE && |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 230 | !test_and_set_bit(RXRPC_CALL_EV_DRAIN_RX_OOS, &call->events)) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 231 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 232 | read_unlock(&call->state_lock); |
| 233 | } |
| 234 | |
| 235 | spin_unlock(&call->lock); |
| 236 | atomic_inc(&call->ackr_not_idle); |
| 237 | rxrpc_propose_ACK(call, RXRPC_ACK_DELAY, sp->hdr.serial, false); |
| 238 | _leave(" = 0 [posted]"); |
| 239 | return 0; |
| 240 | |
| 241 | protocol_error: |
| 242 | ret = -EBADMSG; |
| 243 | out: |
| 244 | spin_unlock(&call->lock); |
| 245 | _leave(" = %d", ret); |
| 246 | return ret; |
| 247 | |
| 248 | discard_and_ack: |
| 249 | _debug("discard and ACK packet %p", skb); |
| 250 | __rxrpc_propose_ACK(call, ack, sp->hdr.serial, true); |
| 251 | discard: |
| 252 | spin_unlock(&call->lock); |
| 253 | rxrpc_free_skb(skb); |
| 254 | _leave(" = 0 [discarded]"); |
| 255 | return 0; |
| 256 | |
| 257 | enqueue_and_ack: |
| 258 | __rxrpc_propose_ACK(call, ack, sp->hdr.serial, true); |
| 259 | enqueue_packet: |
| 260 | _net("defer skb %p", skb); |
| 261 | spin_unlock(&call->lock); |
| 262 | skb_queue_tail(&call->rx_queue, skb); |
| 263 | atomic_inc(&call->ackr_not_idle); |
| 264 | read_lock(&call->state_lock); |
| 265 | if (call->state < RXRPC_CALL_DEAD) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 266 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 267 | read_unlock(&call->state_lock); |
| 268 | _leave(" = 0 [queued]"); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * assume an implicit ACKALL of the transmission phase of a client socket upon |
| 274 | * reception of the first reply packet |
| 275 | */ |
| 276 | static void rxrpc_assume_implicit_ackall(struct rxrpc_call *call, u32 serial) |
| 277 | { |
| 278 | write_lock_bh(&call->state_lock); |
| 279 | |
| 280 | switch (call->state) { |
| 281 | case RXRPC_CALL_CLIENT_AWAIT_REPLY: |
| 282 | call->state = RXRPC_CALL_CLIENT_RECV_REPLY; |
| 283 | call->acks_latest = serial; |
| 284 | |
| 285 | _debug("implicit ACKALL %%%u", call->acks_latest); |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 286 | set_bit(RXRPC_CALL_EV_RCVD_ACKALL, &call->events); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 287 | write_unlock_bh(&call->state_lock); |
| 288 | |
| 289 | if (try_to_del_timer_sync(&call->resend_timer) >= 0) { |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 290 | clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events); |
| 291 | clear_bit(RXRPC_CALL_EV_RESEND, &call->events); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 292 | clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); |
| 293 | } |
| 294 | break; |
| 295 | |
| 296 | default: |
| 297 | write_unlock_bh(&call->state_lock); |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * post an incoming packet to the nominated call to deal with |
| 304 | * - must get rid of the sk_buff, either by freeing it or by queuing it |
| 305 | */ |
| 306 | void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb) |
| 307 | { |
| 308 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 309 | __be32 wtmp; |
| 310 | u32 hi_serial, abort_code; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 311 | |
| 312 | _enter("%p,%p", call, skb); |
| 313 | |
| 314 | ASSERT(!irqs_disabled()); |
| 315 | |
| 316 | #if 0 // INJECT RX ERROR |
| 317 | if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA) { |
| 318 | static int skip = 0; |
| 319 | if (++skip == 3) { |
| 320 | printk("DROPPED 3RD PACKET!!!!!!!!!!!!!\n"); |
| 321 | skip = 0; |
| 322 | goto free_packet; |
| 323 | } |
| 324 | } |
| 325 | #endif |
| 326 | |
| 327 | /* track the latest serial number on this connection for ACK packet |
| 328 | * information */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 329 | hi_serial = atomic_read(&call->conn->hi_serial); |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 330 | while (sp->hdr.serial > hi_serial) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 331 | hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial, |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 332 | sp->hdr.serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 333 | |
| 334 | /* request ACK generation for any ACK or DATA packet that requests |
| 335 | * it */ |
| 336 | if (sp->hdr.flags & RXRPC_REQUEST_ACK) { |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 337 | _proto("ACK Requested on %%%u", sp->hdr.serial); |
David Howells | 9823f39 | 2014-02-07 18:58:45 +0000 | [diff] [blame] | 338 | rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, sp->hdr.serial, false); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | switch (sp->hdr.type) { |
| 342 | case RXRPC_PACKET_TYPE_ABORT: |
| 343 | _debug("abort"); |
| 344 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 345 | if (skb_copy_bits(skb, 0, &wtmp, sizeof(wtmp)) < 0) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 346 | goto protocol_error; |
| 347 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 348 | abort_code = ntohl(wtmp); |
| 349 | _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 350 | |
| 351 | write_lock_bh(&call->state_lock); |
| 352 | if (call->state < RXRPC_CALL_COMPLETE) { |
| 353 | call->state = RXRPC_CALL_REMOTELY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 354 | call->remote_abort = abort_code; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 355 | set_bit(RXRPC_CALL_EV_RCVD_ABORT, &call->events); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 356 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 357 | } |
| 358 | goto free_packet_unlock; |
| 359 | |
| 360 | case RXRPC_PACKET_TYPE_BUSY: |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 361 | _proto("Rx BUSY %%%u", sp->hdr.serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 362 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 363 | if (rxrpc_conn_is_service(call->conn)) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 364 | goto protocol_error; |
| 365 | |
| 366 | write_lock_bh(&call->state_lock); |
| 367 | switch (call->state) { |
| 368 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
| 369 | call->state = RXRPC_CALL_SERVER_BUSY; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 370 | set_bit(RXRPC_CALL_EV_RCVD_BUSY, &call->events); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 371 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 372 | case RXRPC_CALL_SERVER_BUSY: |
| 373 | goto free_packet_unlock; |
| 374 | default: |
| 375 | goto protocol_error_locked; |
| 376 | } |
| 377 | |
| 378 | default: |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 379 | _proto("Rx %s %%%u", rxrpc_pkts[sp->hdr.type], sp->hdr.serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 380 | goto protocol_error; |
| 381 | |
| 382 | case RXRPC_PACKET_TYPE_DATA: |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 383 | _proto("Rx DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 384 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 385 | if (sp->hdr.seq == 0) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 386 | goto protocol_error; |
| 387 | |
| 388 | call->ackr_prev_seq = sp->hdr.seq; |
| 389 | |
| 390 | /* received data implicitly ACKs all of the request packets we |
| 391 | * sent when we're acting as a client */ |
| 392 | if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 393 | rxrpc_assume_implicit_ackall(call, sp->hdr.serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 394 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 395 | switch (rxrpc_fast_process_data(call, skb, sp->hdr.seq)) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 396 | case 0: |
| 397 | skb = NULL; |
| 398 | goto done; |
| 399 | |
| 400 | default: |
| 401 | BUG(); |
| 402 | |
| 403 | /* data packet received beyond the last packet */ |
| 404 | case -EBADMSG: |
| 405 | goto protocol_error; |
| 406 | } |
| 407 | |
David Howells | 1000345 | 2011-02-28 03:27:43 +0000 | [diff] [blame] | 408 | case RXRPC_PACKET_TYPE_ACKALL: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 409 | case RXRPC_PACKET_TYPE_ACK: |
| 410 | /* ACK processing is done in process context */ |
| 411 | read_lock_bh(&call->state_lock); |
| 412 | if (call->state < RXRPC_CALL_DEAD) { |
| 413 | skb_queue_tail(&call->rx_queue, skb); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 414 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 415 | skb = NULL; |
| 416 | } |
| 417 | read_unlock_bh(&call->state_lock); |
| 418 | goto free_packet; |
| 419 | } |
| 420 | |
| 421 | protocol_error: |
| 422 | _debug("protocol error"); |
| 423 | write_lock_bh(&call->state_lock); |
| 424 | protocol_error_locked: |
| 425 | if (call->state <= RXRPC_CALL_COMPLETE) { |
| 426 | call->state = RXRPC_CALL_LOCALLY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 427 | call->local_abort = RX_PROTOCOL_ERROR; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 428 | set_bit(RXRPC_CALL_EV_ABORT, &call->events); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 429 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 430 | } |
| 431 | free_packet_unlock: |
| 432 | write_unlock_bh(&call->state_lock); |
| 433 | free_packet: |
| 434 | rxrpc_free_skb(skb); |
| 435 | done: |
| 436 | _leave(""); |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * split up a jumbo data packet |
| 441 | */ |
| 442 | static void rxrpc_process_jumbo_packet(struct rxrpc_call *call, |
| 443 | struct sk_buff *jumbo) |
| 444 | { |
| 445 | struct rxrpc_jumbo_header jhdr; |
| 446 | struct rxrpc_skb_priv *sp; |
| 447 | struct sk_buff *part; |
| 448 | |
| 449 | _enter(",{%u,%u}", jumbo->data_len, jumbo->len); |
| 450 | |
| 451 | sp = rxrpc_skb(jumbo); |
| 452 | |
| 453 | do { |
| 454 | sp->hdr.flags &= ~RXRPC_JUMBO_PACKET; |
| 455 | |
| 456 | /* make a clone to represent the first subpacket in what's left |
| 457 | * of the jumbo packet */ |
| 458 | part = skb_clone(jumbo, GFP_ATOMIC); |
| 459 | if (!part) { |
| 460 | /* simply ditch the tail in the event of ENOMEM */ |
| 461 | pskb_trim(jumbo, RXRPC_JUMBO_DATALEN); |
| 462 | break; |
| 463 | } |
| 464 | rxrpc_new_skb(part); |
| 465 | |
| 466 | pskb_trim(part, RXRPC_JUMBO_DATALEN); |
| 467 | |
| 468 | if (!pskb_pull(jumbo, RXRPC_JUMBO_DATALEN)) |
| 469 | goto protocol_error; |
| 470 | |
| 471 | if (skb_copy_bits(jumbo, 0, &jhdr, sizeof(jhdr)) < 0) |
| 472 | goto protocol_error; |
| 473 | if (!pskb_pull(jumbo, sizeof(jhdr))) |
| 474 | BUG(); |
| 475 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 476 | sp->hdr.seq += 1; |
| 477 | sp->hdr.serial += 1; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 478 | sp->hdr.flags = jhdr.flags; |
David Howells | ac5d268 | 2016-07-01 08:35:02 +0100 | [diff] [blame] | 479 | sp->hdr._rsvd = ntohs(jhdr._rsvd); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 480 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 481 | _proto("Rx DATA Jumbo %%%u", sp->hdr.serial - 1); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 482 | |
| 483 | rxrpc_fast_process_packet(call, part); |
| 484 | part = NULL; |
| 485 | |
| 486 | } while (sp->hdr.flags & RXRPC_JUMBO_PACKET); |
| 487 | |
| 488 | rxrpc_fast_process_packet(call, jumbo); |
| 489 | _leave(""); |
| 490 | return; |
| 491 | |
| 492 | protocol_error: |
| 493 | _debug("protocol error"); |
| 494 | rxrpc_free_skb(part); |
| 495 | rxrpc_free_skb(jumbo); |
| 496 | write_lock_bh(&call->state_lock); |
| 497 | if (call->state <= RXRPC_CALL_COMPLETE) { |
| 498 | call->state = RXRPC_CALL_LOCALLY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 499 | call->local_abort = RX_PROTOCOL_ERROR; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 500 | set_bit(RXRPC_CALL_EV_ABORT, &call->events); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 501 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 502 | } |
| 503 | write_unlock_bh(&call->state_lock); |
| 504 | _leave(""); |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * post an incoming packet to the appropriate call/socket to deal with |
| 509 | * - must get rid of the sk_buff, either by freeing it or by queuing it |
| 510 | */ |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 511 | static void rxrpc_post_packet_to_call(struct rxrpc_call *call, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 512 | struct sk_buff *skb) |
| 513 | { |
| 514 | struct rxrpc_skb_priv *sp; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 515 | |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 516 | _enter("%p,%p", call, skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 517 | |
| 518 | sp = rxrpc_skb(skb); |
| 519 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 520 | _debug("extant call [%d]", call->state); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 521 | |
| 522 | read_lock(&call->state_lock); |
| 523 | switch (call->state) { |
| 524 | case RXRPC_CALL_LOCALLY_ABORTED: |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 525 | if (!test_and_set_bit(RXRPC_CALL_EV_ABORT, &call->events)) { |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 526 | rxrpc_queue_call(call); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 527 | goto free_unlock; |
| 528 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 529 | case RXRPC_CALL_REMOTELY_ABORTED: |
| 530 | case RXRPC_CALL_NETWORK_ERROR: |
| 531 | case RXRPC_CALL_DEAD: |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 532 | goto dead_call; |
| 533 | case RXRPC_CALL_COMPLETE: |
| 534 | case RXRPC_CALL_CLIENT_FINAL_ACK: |
| 535 | /* complete server call */ |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 536 | if (rxrpc_conn_is_service(call->conn)) |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 537 | goto dead_call; |
| 538 | /* resend last packet of a completed call */ |
| 539 | _debug("final ack again"); |
| 540 | rxrpc_get_call(call); |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 541 | set_bit(RXRPC_CALL_EV_ACK_FINAL, &call->events); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 542 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 543 | goto free_unlock; |
| 544 | default: |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | read_unlock(&call->state_lock); |
| 549 | rxrpc_get_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 550 | |
| 551 | if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA && |
| 552 | sp->hdr.flags & RXRPC_JUMBO_PACKET) |
| 553 | rxrpc_process_jumbo_packet(call, skb); |
| 554 | else |
| 555 | rxrpc_fast_process_packet(call, skb); |
| 556 | |
| 557 | rxrpc_put_call(call); |
| 558 | goto done; |
| 559 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 560 | dead_call: |
Tim Smith | b6f3a40 | 2014-02-07 18:58:43 +0000 | [diff] [blame] | 561 | if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) { |
| 562 | skb->priority = RX_CALL_DEAD; |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 563 | rxrpc_reject_packet(call->conn->params.local, skb); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 564 | goto unlock; |
Tim Smith | b6f3a40 | 2014-02-07 18:58:43 +0000 | [diff] [blame] | 565 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 566 | free_unlock: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 567 | rxrpc_free_skb(skb); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 568 | unlock: |
| 569 | read_unlock(&call->state_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 570 | done: |
| 571 | _leave(""); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * post connection-level events to the connection |
| 576 | * - this includes challenges, responses and some aborts |
| 577 | */ |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 578 | static bool rxrpc_post_packet_to_conn(struct rxrpc_connection *conn, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 579 | struct sk_buff *skb) |
| 580 | { |
| 581 | _enter("%p,%p", conn, skb); |
| 582 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 583 | skb_queue_tail(&conn->rx_queue, skb); |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 584 | return rxrpc_queue_conn(conn); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 585 | } |
| 586 | |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 587 | /* |
| 588 | * post endpoint-level events to the local endpoint |
| 589 | * - this includes debug and version messages |
| 590 | */ |
| 591 | static void rxrpc_post_packet_to_local(struct rxrpc_local *local, |
| 592 | struct sk_buff *skb) |
| 593 | { |
| 594 | _enter("%p,%p", local, skb); |
| 595 | |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 596 | skb_queue_tail(&local->event_queue, skb); |
David Howells | 5acbee4 | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 597 | rxrpc_queue_local(local); |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 598 | } |
| 599 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 600 | /* |
| 601 | * Extract the wire header from a packet and translate the byte order. |
| 602 | */ |
| 603 | static noinline |
| 604 | int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb) |
| 605 | { |
| 606 | struct rxrpc_wire_header whdr; |
| 607 | |
| 608 | /* dig out the RxRPC connection details */ |
Willem de Bruijn | 4d0fc73 | 2016-04-07 11:44:59 -0400 | [diff] [blame] | 609 | if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0) |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 610 | return -EBADMSG; |
Willem de Bruijn | 4d0fc73 | 2016-04-07 11:44:59 -0400 | [diff] [blame] | 611 | if (!pskb_pull(skb, sizeof(whdr))) |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 612 | BUG(); |
| 613 | |
| 614 | memset(sp, 0, sizeof(*sp)); |
| 615 | sp->hdr.epoch = ntohl(whdr.epoch); |
| 616 | sp->hdr.cid = ntohl(whdr.cid); |
| 617 | sp->hdr.callNumber = ntohl(whdr.callNumber); |
| 618 | sp->hdr.seq = ntohl(whdr.seq); |
| 619 | sp->hdr.serial = ntohl(whdr.serial); |
| 620 | sp->hdr.flags = whdr.flags; |
| 621 | sp->hdr.type = whdr.type; |
| 622 | sp->hdr.userStatus = whdr.userStatus; |
| 623 | sp->hdr.securityIndex = whdr.securityIndex; |
| 624 | sp->hdr._rsvd = ntohs(whdr._rsvd); |
| 625 | sp->hdr.serviceId = ntohs(whdr.serviceId); |
| 626 | return 0; |
| 627 | } |
| 628 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 629 | /* |
| 630 | * handle data received on the local endpoint |
| 631 | * - may be called in interrupt context |
David Howells | 4f95dd7 | 2016-04-04 14:00:35 +0100 | [diff] [blame] | 632 | * |
| 633 | * The socket is locked by the caller and this prevents the socket from being |
| 634 | * shut down and the local endpoint from going away, thus sk_user_data will not |
| 635 | * be cleared until this function returns. |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 636 | */ |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 637 | void rxrpc_data_ready(struct sock *sk) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 638 | { |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 639 | struct rxrpc_connection *conn; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 640 | struct rxrpc_skb_priv *sp; |
David Howells | 4f95dd7 | 2016-04-04 14:00:35 +0100 | [diff] [blame] | 641 | struct rxrpc_local *local = sk->sk_user_data; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 642 | struct sk_buff *skb; |
| 643 | int ret; |
| 644 | |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 645 | _enter("%p", sk); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 646 | |
| 647 | ASSERT(!irqs_disabled()); |
| 648 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 649 | skb = skb_recv_datagram(sk, 0, 1, &ret); |
| 650 | if (!skb) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 651 | if (ret == -EAGAIN) |
| 652 | return; |
| 653 | _debug("UDP socket error %d", ret); |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | rxrpc_new_skb(skb); |
| 658 | |
| 659 | _net("recv skb %p", skb); |
| 660 | |
| 661 | /* we'll probably need to checksum it (didn't call sock_recvmsg) */ |
| 662 | if (skb_checksum_complete(skb)) { |
| 663 | rxrpc_free_skb(skb); |
Eric Dumazet | 02c2234 | 2016-04-27 16:44:30 -0700 | [diff] [blame] | 664 | __UDP_INC_STATS(&init_net, UDP_MIB_INERRORS, 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 665 | _leave(" [CSUM failed]"); |
| 666 | return; |
| 667 | } |
| 668 | |
Eric Dumazet | 02c2234 | 2016-04-27 16:44:30 -0700 | [diff] [blame] | 669 | __UDP_INC_STATS(&init_net, UDP_MIB_INDATAGRAMS, 0); |
Herbert Xu | 1781f7f | 2007-12-11 11:30:32 -0800 | [diff] [blame] | 670 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 671 | /* The socket buffer we have is owned by UDP, with UDP's data all over |
| 672 | * it, but we really want our own data there. |
| 673 | */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 674 | skb_orphan(skb); |
| 675 | sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 676 | |
| 677 | _net("Rx UDP packet from %08x:%04hu", |
| 678 | ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source)); |
| 679 | |
| 680 | /* dig out the RxRPC connection details */ |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 681 | if (rxrpc_extract_header(sp, skb) < 0) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 682 | goto bad_message; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 683 | |
| 684 | _net("Rx RxRPC %s ep=%x call=%x:%x", |
| 685 | sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient", |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 686 | sp->hdr.epoch, sp->hdr.cid, sp->hdr.callNumber); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 687 | |
David Howells | 351c1e6 | 2016-03-04 15:56:06 +0000 | [diff] [blame] | 688 | if (sp->hdr.type >= RXRPC_N_PACKET_TYPES || |
| 689 | !((RXRPC_SUPPORTED_PACKET_TYPES >> sp->hdr.type) & 1)) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 690 | _proto("Rx Bad Packet Type %u", sp->hdr.type); |
| 691 | goto bad_message; |
| 692 | } |
| 693 | |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 694 | if (sp->hdr.type == RXRPC_PACKET_TYPE_VERSION) { |
| 695 | rxrpc_post_packet_to_local(local, skb); |
| 696 | goto out; |
| 697 | } |
David Howells | bc6e1ea | 2016-06-10 22:30:27 +0100 | [diff] [blame] | 698 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 699 | if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA && |
| 700 | (sp->hdr.callNumber == 0 || sp->hdr.seq == 0)) |
| 701 | goto bad_message; |
| 702 | |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 703 | rcu_read_lock(); |
| 704 | |
| 705 | retry_find_conn: |
| 706 | conn = rxrpc_find_connection_rcu(local, skb); |
| 707 | if (!conn) |
| 708 | goto cant_route_call; |
| 709 | |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 710 | if (sp->hdr.callNumber == 0) { |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 711 | /* Connection-level packet */ |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 712 | _debug("CONN %p {%d}", conn, conn->debug_id); |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 713 | if (!rxrpc_post_packet_to_conn(conn, skb)) |
| 714 | goto retry_find_conn; |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 715 | } else { |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 716 | /* Call-bound packets are routed by connection channel. */ |
| 717 | unsigned int channel = sp->hdr.cid & RXRPC_CHANNELMASK; |
| 718 | struct rxrpc_channel *chan = &conn->channels[channel]; |
| 719 | struct rxrpc_call *call = rcu_dereference(chan->call); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 720 | |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 721 | if (!call || atomic_read(&call->usage) == 0) |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 722 | goto cant_route_call; |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 723 | |
| 724 | rxrpc_post_packet_to_call(call, skb); |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 725 | } |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 726 | |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 727 | rcu_read_unlock(); |
David Howells | 44ba069 | 2015-04-01 16:31:26 +0100 | [diff] [blame] | 728 | out: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 729 | return; |
| 730 | |
| 731 | cant_route_call: |
David Howells | 8496af5 | 2016-07-01 07:51:50 +0100 | [diff] [blame] | 732 | rcu_read_unlock(); |
| 733 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 734 | _debug("can't route call"); |
| 735 | if (sp->hdr.flags & RXRPC_CLIENT_INITIATED && |
| 736 | sp->hdr.type == RXRPC_PACKET_TYPE_DATA) { |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 737 | if (sp->hdr.seq == 1) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 738 | _debug("first packet"); |
| 739 | skb_queue_tail(&local->accept_queue, skb); |
David Howells | 4f95dd7 | 2016-04-04 14:00:35 +0100 | [diff] [blame] | 740 | rxrpc_queue_work(&local->processor); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 741 | _leave(" [incoming]"); |
| 742 | return; |
| 743 | } |
| 744 | skb->priority = RX_INVALID_OPERATION; |
| 745 | } else { |
| 746 | skb->priority = RX_CALL_DEAD; |
| 747 | } |
| 748 | |
Tim Smith | b6f3a40 | 2014-02-07 18:58:43 +0000 | [diff] [blame] | 749 | if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) { |
| 750 | _debug("reject type %d",sp->hdr.type); |
| 751 | rxrpc_reject_packet(local, skb); |
| 752 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 753 | _leave(" [no call]"); |
| 754 | return; |
| 755 | |
| 756 | bad_message: |
| 757 | skb->priority = RX_PROTOCOL_ERROR; |
| 758 | rxrpc_reject_packet(local, skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 759 | _leave(" [badmsg]"); |
| 760 | } |