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