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