David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 1 | /* RxRPC virtual connection handler |
| 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 16 | #include <linux/net.h> |
| 17 | #include <linux/skbuff.h> |
| 18 | #include <linux/crypto.h> |
| 19 | #include <net/sock.h> |
| 20 | #include <net/af_rxrpc.h> |
| 21 | #include "ar-internal.h" |
| 22 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 23 | /* |
| 24 | * Time till a connection expires after last use (in seconds). |
| 25 | */ |
David Howells | dad8aff | 2016-03-09 23:22:56 +0000 | [diff] [blame] | 26 | unsigned int rxrpc_connection_expiry = 10 * 60; |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 27 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 28 | static void rxrpc_connection_reaper(struct work_struct *work); |
| 29 | |
| 30 | LIST_HEAD(rxrpc_connections); |
| 31 | DEFINE_RWLOCK(rxrpc_connection_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 32 | static DECLARE_DELAYED_WORK(rxrpc_connection_reap, rxrpc_connection_reaper); |
| 33 | |
| 34 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 35 | * allocate a new connection |
| 36 | */ |
| 37 | static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp) |
| 38 | { |
| 39 | struct rxrpc_connection *conn; |
| 40 | |
| 41 | _enter(""); |
| 42 | |
| 43 | conn = kzalloc(sizeof(struct rxrpc_connection), gfp); |
| 44 | if (conn) { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 45 | spin_lock_init(&conn->channel_lock); |
| 46 | init_waitqueue_head(&conn->channel_wq); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 47 | INIT_WORK(&conn->processor, &rxrpc_process_connection); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 48 | INIT_LIST_HEAD(&conn->link); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 49 | conn->calls = RB_ROOT; |
| 50 | skb_queue_head_init(&conn->rx_queue); |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 51 | conn->security = &rxrpc_no_security; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 52 | rwlock_init(&conn->lock); |
| 53 | spin_lock_init(&conn->state_lock); |
| 54 | atomic_set(&conn->usage, 1); |
| 55 | conn->debug_id = atomic_inc_return(&rxrpc_debug_id); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 56 | atomic_set(&conn->avail_chans, RXRPC_MAXCALLS); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 57 | conn->size_align = 4; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 58 | conn->header_size = sizeof(struct rxrpc_wire_header); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Adrian Bunk | 16c61ad | 2007-06-15 15:15:43 -0700 | [diff] [blame] | 61 | _leave(" = %p{%d}", conn, conn ? conn->debug_id : 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 62 | return conn; |
| 63 | } |
| 64 | |
| 65 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 66 | * add a call to a connection's call-by-ID tree |
| 67 | */ |
| 68 | static void rxrpc_add_call_ID_to_conn(struct rxrpc_connection *conn, |
| 69 | struct rxrpc_call *call) |
| 70 | { |
| 71 | struct rxrpc_call *xcall; |
| 72 | struct rb_node *parent, **p; |
David Howells | 88b99d0 | 2016-07-01 08:27:42 +0100 | [diff] [blame] | 73 | u32 call_id; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 74 | |
| 75 | write_lock_bh(&conn->lock); |
| 76 | |
| 77 | call_id = call->call_id; |
| 78 | p = &conn->calls.rb_node; |
| 79 | parent = NULL; |
| 80 | while (*p) { |
| 81 | parent = *p; |
| 82 | xcall = rb_entry(parent, struct rxrpc_call, conn_node); |
| 83 | |
| 84 | if (call_id < xcall->call_id) |
| 85 | p = &(*p)->rb_left; |
| 86 | else if (call_id > xcall->call_id) |
| 87 | p = &(*p)->rb_right; |
| 88 | else |
| 89 | BUG(); |
| 90 | } |
| 91 | |
| 92 | rb_link_node(&call->conn_node, parent, p); |
| 93 | rb_insert_color(&call->conn_node, &conn->calls); |
| 94 | |
| 95 | write_unlock_bh(&conn->lock); |
| 96 | } |
| 97 | |
| 98 | /* |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 99 | * Allocate a client connection. The caller must take care to clear any |
| 100 | * padding bytes in *cp. |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 101 | */ |
| 102 | static struct rxrpc_connection * |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 103 | rxrpc_alloc_client_connection(struct rxrpc_conn_parameters *cp, gfp_t gfp) |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 104 | { |
| 105 | struct rxrpc_connection *conn; |
| 106 | int ret; |
| 107 | |
| 108 | _enter(""); |
| 109 | |
| 110 | conn = rxrpc_alloc_connection(gfp); |
| 111 | if (!conn) { |
| 112 | _leave(" = -ENOMEM"); |
| 113 | return ERR_PTR(-ENOMEM); |
| 114 | } |
| 115 | |
| 116 | conn->params = *cp; |
| 117 | conn->proto.local = cp->local; |
| 118 | conn->proto.epoch = rxrpc_epoch; |
| 119 | conn->proto.cid = 0; |
| 120 | conn->proto.in_clientflag = 0; |
| 121 | conn->proto.family = cp->peer->srx.transport.family; |
| 122 | conn->out_clientflag = RXRPC_CLIENT_INITIATED; |
| 123 | conn->state = RXRPC_CONN_CLIENT; |
| 124 | |
| 125 | switch (conn->proto.family) { |
| 126 | case AF_INET: |
| 127 | conn->proto.addr_size = sizeof(conn->proto.ipv4_addr); |
| 128 | conn->proto.ipv4_addr = cp->peer->srx.transport.sin.sin_addr; |
| 129 | conn->proto.port = cp->peer->srx.transport.sin.sin_port; |
| 130 | break; |
| 131 | } |
| 132 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 133 | ret = rxrpc_get_client_connection_id(conn, gfp); |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 134 | if (ret < 0) |
| 135 | goto error_0; |
| 136 | |
| 137 | ret = rxrpc_init_client_conn_security(conn); |
| 138 | if (ret < 0) |
| 139 | goto error_1; |
| 140 | |
Herbert Xu | a263629 | 2016-06-26 14:55:24 -0700 | [diff] [blame] | 141 | ret = conn->security->prime_packet_security(conn); |
| 142 | if (ret < 0) |
| 143 | goto error_2; |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 144 | |
| 145 | write_lock(&rxrpc_connection_lock); |
| 146 | list_add_tail(&conn->link, &rxrpc_connections); |
| 147 | write_unlock(&rxrpc_connection_lock); |
| 148 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 149 | /* We steal the caller's peer ref. */ |
| 150 | cp->peer = NULL; |
| 151 | rxrpc_get_local(conn->params.local); |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 152 | key_get(conn->params.key); |
| 153 | |
| 154 | _leave(" = %p", conn); |
| 155 | return conn; |
| 156 | |
Herbert Xu | a263629 | 2016-06-26 14:55:24 -0700 | [diff] [blame] | 157 | error_2: |
| 158 | conn->security->clear(conn); |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 159 | error_1: |
| 160 | rxrpc_put_client_connection_id(conn); |
| 161 | error_0: |
| 162 | kfree(conn); |
| 163 | _leave(" = %d", ret); |
| 164 | return ERR_PTR(ret); |
| 165 | } |
| 166 | |
| 167 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 168 | * find a connection for a call |
| 169 | * - called in process context with IRQs enabled |
| 170 | */ |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 171 | int rxrpc_connect_call(struct rxrpc_call *call, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 172 | struct rxrpc_conn_parameters *cp, |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 173 | struct sockaddr_rxrpc *srx, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 174 | gfp_t gfp) |
| 175 | { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 176 | struct rxrpc_connection *conn, *candidate = NULL; |
| 177 | struct rxrpc_local *local = cp->local; |
| 178 | struct rb_node *p, **pp, *parent; |
| 179 | long diff; |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 180 | int chan; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 181 | |
| 182 | DECLARE_WAITQUEUE(myself, current); |
| 183 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 184 | _enter("{%d,%lx},", call->debug_id, call->user_call_ID); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 185 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 186 | cp->peer = rxrpc_lookup_peer(cp->local, srx, gfp); |
| 187 | if (!cp->peer) |
| 188 | return -ENOMEM; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 189 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 190 | if (!cp->exclusive) { |
| 191 | /* Search for a existing client connection unless this is going |
| 192 | * to be a connection that's used exclusively for a single call. |
| 193 | */ |
| 194 | _debug("search 1"); |
| 195 | spin_lock(&local->client_conns_lock); |
| 196 | p = local->client_conns.rb_node; |
| 197 | while (p) { |
| 198 | conn = rb_entry(p, struct rxrpc_connection, client_node); |
| 199 | |
| 200 | #define cmp(X) ((long)conn->params.X - (long)cp->X) |
| 201 | diff = (cmp(peer) ?: |
| 202 | cmp(key) ?: |
| 203 | cmp(security_level)); |
| 204 | if (diff < 0) |
| 205 | p = p->rb_left; |
| 206 | else if (diff > 0) |
| 207 | p = p->rb_right; |
| 208 | else |
| 209 | goto found_extant_conn; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 210 | } |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 211 | spin_unlock(&local->client_conns_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 212 | } |
| 213 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 214 | /* We didn't find a connection or we want an exclusive one. */ |
| 215 | _debug("get new conn"); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 216 | candidate = rxrpc_alloc_client_connection(cp, gfp); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 217 | if (!candidate) { |
| 218 | _leave(" = -ENOMEM"); |
| 219 | return -ENOMEM; |
| 220 | } |
| 221 | |
| 222 | if (cp->exclusive) { |
| 223 | /* Assign the call on an exclusive connection to channel 0 and |
| 224 | * don't add the connection to the endpoint's shareable conn |
| 225 | * lookup tree. |
| 226 | */ |
| 227 | _debug("exclusive chan 0"); |
| 228 | conn = candidate; |
| 229 | atomic_set(&conn->avail_chans, RXRPC_MAXCALLS - 1); |
| 230 | spin_lock(&conn->channel_lock); |
| 231 | chan = 0; |
| 232 | goto found_channel; |
| 233 | } |
| 234 | |
| 235 | /* We need to redo the search before attempting to add a new connection |
| 236 | * lest we race with someone else adding a conflicting instance. |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 237 | */ |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 238 | _debug("search 2"); |
| 239 | spin_lock(&local->client_conns_lock); |
| 240 | |
| 241 | pp = &local->client_conns.rb_node; |
| 242 | parent = NULL; |
| 243 | while (*pp) { |
| 244 | parent = *pp; |
| 245 | conn = rb_entry(parent, struct rxrpc_connection, client_node); |
| 246 | |
| 247 | diff = (cmp(peer) ?: |
| 248 | cmp(key) ?: |
| 249 | cmp(security_level)); |
| 250 | if (diff < 0) |
| 251 | pp = &(*pp)->rb_left; |
| 252 | else if (diff > 0) |
| 253 | pp = &(*pp)->rb_right; |
| 254 | else |
| 255 | goto found_extant_conn; |
| 256 | } |
| 257 | |
| 258 | /* The second search also failed; simply add the new connection with |
| 259 | * the new call in channel 0. Note that we need to take the channel |
| 260 | * lock before dropping the client conn lock. |
| 261 | */ |
| 262 | _debug("new conn"); |
| 263 | conn = candidate; |
| 264 | candidate = NULL; |
| 265 | |
| 266 | rb_link_node(&conn->client_node, parent, pp); |
| 267 | rb_insert_color(&conn->client_node, &local->client_conns); |
| 268 | |
| 269 | atomic_set(&conn->avail_chans, RXRPC_MAXCALLS - 1); |
| 270 | spin_lock(&conn->channel_lock); |
| 271 | spin_unlock(&local->client_conns_lock); |
| 272 | chan = 0; |
| 273 | |
| 274 | found_channel: |
| 275 | _debug("found chan"); |
| 276 | call->conn = conn; |
| 277 | call->channel = chan; |
| 278 | call->epoch = conn->proto.epoch; |
| 279 | call->cid = conn->proto.cid | chan; |
| 280 | call->call_id = ++conn->call_counter; |
| 281 | rcu_assign_pointer(conn->channels[chan], call); |
| 282 | |
| 283 | _net("CONNECT call %d on conn %d", call->debug_id, conn->debug_id); |
| 284 | |
| 285 | rxrpc_add_call_ID_to_conn(conn, call); |
| 286 | spin_unlock(&conn->channel_lock); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 287 | rxrpc_put_peer(cp->peer); |
| 288 | cp->peer = NULL; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 289 | _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage)); |
| 290 | return 0; |
| 291 | |
| 292 | /* We found a suitable connection already in existence. Discard any |
| 293 | * candidate we may have allocated, and try to get a channel on this |
| 294 | * one. |
| 295 | */ |
| 296 | found_extant_conn: |
| 297 | _debug("found conn"); |
| 298 | rxrpc_get_connection(conn); |
| 299 | spin_unlock(&local->client_conns_lock); |
| 300 | |
| 301 | rxrpc_put_connection(candidate); |
| 302 | |
| 303 | if (!atomic_add_unless(&conn->avail_chans, -1, 0)) { |
| 304 | if (!gfpflags_allow_blocking(gfp)) { |
| 305 | rxrpc_put_connection(conn); |
| 306 | _leave(" = -EAGAIN"); |
| 307 | return -EAGAIN; |
| 308 | } |
| 309 | |
| 310 | add_wait_queue(&conn->channel_wq, &myself); |
| 311 | for (;;) { |
| 312 | set_current_state(TASK_INTERRUPTIBLE); |
| 313 | if (atomic_add_unless(&conn->avail_chans, -1, 0)) |
| 314 | break; |
| 315 | if (signal_pending(current)) |
| 316 | goto interrupted; |
| 317 | schedule(); |
| 318 | } |
| 319 | remove_wait_queue(&conn->channel_wq, &myself); |
| 320 | __set_current_state(TASK_RUNNING); |
| 321 | } |
| 322 | |
| 323 | /* The connection allegedly now has a free channel and we can now |
| 324 | * attach the call to it. |
| 325 | */ |
| 326 | spin_lock(&conn->channel_lock); |
| 327 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 328 | for (chan = 0; chan < RXRPC_MAXCALLS; chan++) |
| 329 | if (!conn->channels[chan]) |
| 330 | goto found_channel; |
| 331 | BUG(); |
| 332 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 333 | interrupted: |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 334 | remove_wait_queue(&conn->channel_wq, &myself); |
| 335 | __set_current_state(TASK_RUNNING); |
| 336 | rxrpc_put_connection(conn); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 337 | rxrpc_put_peer(cp->peer); |
| 338 | cp->peer = NULL; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 339 | _leave(" = -ERESTARTSYS"); |
| 340 | return -ERESTARTSYS; |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * get a record of an incoming connection |
| 345 | */ |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 346 | struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local, |
| 347 | struct rxrpc_peer *peer, |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 348 | struct sk_buff *skb) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 349 | { |
| 350 | struct rxrpc_connection *conn, *candidate = NULL; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 351 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 352 | struct rb_node *p, **pp; |
| 353 | const char *new = "old"; |
David Howells | 88b99d0 | 2016-07-01 08:27:42 +0100 | [diff] [blame] | 354 | u32 epoch, cid; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 355 | |
| 356 | _enter(""); |
| 357 | |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 358 | ASSERT(sp->hdr.flags & RXRPC_CLIENT_INITIATED); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 359 | |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 360 | epoch = sp->hdr.epoch; |
| 361 | cid = sp->hdr.cid & RXRPC_CIDMASK; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 362 | |
| 363 | /* search the connection list first */ |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 364 | read_lock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 365 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 366 | p = peer->service_conns.rb_node; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 367 | while (p) { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 368 | conn = rb_entry(p, struct rxrpc_connection, service_node); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 369 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 370 | _debug("maybe %x", conn->proto.cid); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 371 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 372 | if (epoch < conn->proto.epoch) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 373 | p = p->rb_left; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 374 | else if (epoch > conn->proto.epoch) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 375 | p = p->rb_right; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 376 | else if (cid < conn->proto.cid) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 377 | p = p->rb_left; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 378 | else if (cid > conn->proto.cid) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 379 | p = p->rb_right; |
| 380 | else |
| 381 | goto found_extant_connection; |
| 382 | } |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 383 | read_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 384 | |
| 385 | /* not yet present - create a candidate for a new record and then |
| 386 | * redo the search */ |
David Howells | 843099c | 2016-04-07 17:23:37 +0100 | [diff] [blame] | 387 | candidate = rxrpc_alloc_connection(GFP_NOIO); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 388 | if (!candidate) { |
| 389 | _leave(" = -ENOMEM"); |
| 390 | return ERR_PTR(-ENOMEM); |
| 391 | } |
| 392 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 393 | candidate->proto.local = local; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 394 | candidate->proto.epoch = sp->hdr.epoch; |
| 395 | candidate->proto.cid = sp->hdr.cid & RXRPC_CIDMASK; |
| 396 | candidate->proto.in_clientflag = RXRPC_CLIENT_INITIATED; |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 397 | candidate->params.local = local; |
| 398 | candidate->params.peer = peer; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 399 | candidate->params.service_id = sp->hdr.serviceId; |
| 400 | candidate->security_ix = sp->hdr.securityIndex; |
| 401 | candidate->out_clientflag = 0; |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 402 | candidate->state = RXRPC_CONN_SERVICE; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 403 | if (candidate->params.service_id) |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 404 | candidate->state = RXRPC_CONN_SERVICE_UNSECURED; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 405 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 406 | write_lock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 407 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 408 | pp = &peer->service_conns.rb_node; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 409 | p = NULL; |
| 410 | while (*pp) { |
| 411 | p = *pp; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 412 | conn = rb_entry(p, struct rxrpc_connection, service_node); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 413 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 414 | if (epoch < conn->proto.epoch) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 415 | pp = &(*pp)->rb_left; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 416 | else if (epoch > conn->proto.epoch) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 417 | pp = &(*pp)->rb_right; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 418 | else if (cid < conn->proto.cid) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 419 | pp = &(*pp)->rb_left; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 420 | else if (cid > conn->proto.cid) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 421 | pp = &(*pp)->rb_right; |
| 422 | else |
| 423 | goto found_extant_second; |
| 424 | } |
| 425 | |
| 426 | /* we can now add the new candidate to the list */ |
| 427 | conn = candidate; |
| 428 | candidate = NULL; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 429 | rb_link_node(&conn->service_node, p, pp); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 430 | rb_insert_color(&conn->service_node, &peer->service_conns); |
| 431 | rxrpc_get_peer(peer); |
| 432 | rxrpc_get_local(local); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 433 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 434 | write_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 435 | |
David Howells | b3f5750 | 2016-06-21 16:10:03 +0100 | [diff] [blame] | 436 | write_lock(&rxrpc_connection_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 437 | list_add_tail(&conn->link, &rxrpc_connections); |
David Howells | b3f5750 | 2016-06-21 16:10:03 +0100 | [diff] [blame] | 438 | write_unlock(&rxrpc_connection_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 439 | |
| 440 | new = "new"; |
| 441 | |
| 442 | success: |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 443 | _net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->proto.cid); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 444 | |
| 445 | _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage)); |
| 446 | return conn; |
| 447 | |
| 448 | /* we found the connection in the list immediately */ |
| 449 | found_extant_connection: |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 450 | if (sp->hdr.securityIndex != conn->security_ix) { |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 451 | read_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 452 | goto security_mismatch; |
| 453 | } |
David Howells | 5627cc8 | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 454 | rxrpc_get_connection(conn); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 455 | read_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 456 | goto success; |
| 457 | |
| 458 | /* we found the connection on the second time through the list */ |
| 459 | found_extant_second: |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 460 | if (sp->hdr.securityIndex != conn->security_ix) { |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 461 | write_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 462 | goto security_mismatch; |
| 463 | } |
David Howells | 5627cc8 | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 464 | rxrpc_get_connection(conn); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 465 | write_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 466 | kfree(candidate); |
| 467 | goto success; |
| 468 | |
| 469 | security_mismatch: |
| 470 | kfree(candidate); |
| 471 | _leave(" = -EKEYREJECTED"); |
| 472 | return ERR_PTR(-EKEYREJECTED); |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * find a connection based on transport and RxRPC connection ID for an incoming |
| 477 | * packet |
| 478 | */ |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 479 | struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_local *local, |
| 480 | struct rxrpc_peer *peer, |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 481 | struct sk_buff *skb) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 482 | { |
| 483 | struct rxrpc_connection *conn; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 484 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 485 | struct rb_node *p; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 486 | u32 epoch, cid; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 487 | |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 488 | _enter(",{%x,%x}", sp->hdr.cid, sp->hdr.flags); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 489 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 490 | read_lock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 491 | |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 492 | cid = sp->hdr.cid & RXRPC_CIDMASK; |
| 493 | epoch = sp->hdr.epoch; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 494 | |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 495 | if (sp->hdr.flags & RXRPC_CLIENT_INITIATED) { |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 496 | p = peer->service_conns.rb_node; |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 497 | while (p) { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 498 | conn = rb_entry(p, struct rxrpc_connection, service_node); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 499 | |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 500 | _debug("maybe %x", conn->proto.cid); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 501 | |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 502 | if (epoch < conn->proto.epoch) |
| 503 | p = p->rb_left; |
| 504 | else if (epoch > conn->proto.epoch) |
| 505 | p = p->rb_right; |
| 506 | else if (cid < conn->proto.cid) |
| 507 | p = p->rb_left; |
| 508 | else if (cid > conn->proto.cid) |
| 509 | p = p->rb_right; |
| 510 | else |
| 511 | goto found; |
| 512 | } |
| 513 | } else { |
| 514 | conn = idr_find(&rxrpc_client_conn_ids, cid >> RXRPC_CIDSHIFT); |
David Howells | 689f4c6 | 2016-06-30 11:34:30 +0100 | [diff] [blame] | 515 | if (conn && |
| 516 | conn->proto.epoch == epoch && |
| 517 | conn->params.peer == peer) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 518 | goto found; |
| 519 | } |
| 520 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 521 | read_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 522 | _leave(" = NULL"); |
| 523 | return NULL; |
| 524 | |
| 525 | found: |
David Howells | 5627cc8 | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 526 | rxrpc_get_connection(conn); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 527 | read_unlock_bh(&peer->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 528 | _leave(" = %p", conn); |
| 529 | return conn; |
| 530 | } |
| 531 | |
| 532 | /* |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 533 | * Disconnect a call and clear any channel it occupies when that call |
| 534 | * terminates. |
| 535 | */ |
| 536 | void rxrpc_disconnect_call(struct rxrpc_call *call) |
| 537 | { |
| 538 | struct rxrpc_connection *conn = call->conn; |
| 539 | unsigned chan = call->channel; |
| 540 | |
| 541 | _enter("%d,%d", conn->debug_id, call->channel); |
| 542 | |
David Howells | e653cfe | 2016-04-04 14:00:38 +0100 | [diff] [blame^] | 543 | spin_lock(&conn->channel_lock); |
| 544 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 545 | if (conn->channels[chan] == call) { |
| 546 | rcu_assign_pointer(conn->channels[chan], NULL); |
| 547 | atomic_inc(&conn->avail_chans); |
| 548 | wake_up(&conn->channel_wq); |
| 549 | } |
David Howells | e653cfe | 2016-04-04 14:00:38 +0100 | [diff] [blame^] | 550 | |
| 551 | spin_unlock(&conn->channel_lock); |
| 552 | |
| 553 | call->conn = NULL; |
| 554 | rxrpc_put_connection(conn); |
| 555 | _leave(""); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 559 | * release a virtual connection |
| 560 | */ |
| 561 | void rxrpc_put_connection(struct rxrpc_connection *conn) |
| 562 | { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 563 | if (!conn) |
| 564 | return; |
| 565 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 566 | _enter("%p{u=%d,d=%d}", |
| 567 | conn, atomic_read(&conn->usage), conn->debug_id); |
| 568 | |
| 569 | ASSERTCMP(atomic_read(&conn->usage), >, 0); |
| 570 | |
Ksenija Stanojevic | 22a3f9a | 2015-09-17 18:12:53 +0200 | [diff] [blame] | 571 | conn->put_time = ktime_get_seconds(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 572 | if (atomic_dec_and_test(&conn->usage)) { |
| 573 | _debug("zombie"); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 574 | rxrpc_queue_delayed_work(&rxrpc_connection_reap, 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | _leave(""); |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * destroy a virtual connection |
| 582 | */ |
| 583 | static void rxrpc_destroy_connection(struct rxrpc_connection *conn) |
| 584 | { |
| 585 | _enter("%p{%d}", conn, atomic_read(&conn->usage)); |
| 586 | |
| 587 | ASSERTCMP(atomic_read(&conn->usage), ==, 0); |
| 588 | |
| 589 | _net("DESTROY CONN %d", conn->debug_id); |
| 590 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 591 | ASSERT(RB_EMPTY_ROOT(&conn->calls)); |
| 592 | rxrpc_purge_queue(&conn->rx_queue); |
| 593 | |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 594 | conn->security->clear(conn); |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 595 | key_put(conn->params.key); |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 596 | key_put(conn->server_key); |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 597 | rxrpc_put_peer(conn->params.peer); |
| 598 | rxrpc_put_local(conn->params.local); |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 599 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 600 | kfree(conn); |
| 601 | _leave(""); |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * reap dead connections |
| 606 | */ |
Roel Kluin | 5eaa65b | 2008-12-10 15:18:31 -0800 | [diff] [blame] | 607 | static void rxrpc_connection_reaper(struct work_struct *work) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 608 | { |
| 609 | struct rxrpc_connection *conn, *_p; |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 610 | struct rxrpc_peer *peer; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 611 | unsigned long now, earliest, reap_time; |
| 612 | |
| 613 | LIST_HEAD(graveyard); |
| 614 | |
| 615 | _enter(""); |
| 616 | |
Ksenija Stanojevic | 22a3f9a | 2015-09-17 18:12:53 +0200 | [diff] [blame] | 617 | now = ktime_get_seconds(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 618 | earliest = ULONG_MAX; |
| 619 | |
David Howells | b3f5750 | 2016-06-21 16:10:03 +0100 | [diff] [blame] | 620 | write_lock(&rxrpc_connection_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 621 | list_for_each_entry_safe(conn, _p, &rxrpc_connections, link) { |
| 622 | _debug("reap CONN %d { u=%d,t=%ld }", |
| 623 | conn->debug_id, atomic_read(&conn->usage), |
| 624 | (long) now - (long) conn->put_time); |
| 625 | |
| 626 | if (likely(atomic_read(&conn->usage) > 0)) |
| 627 | continue; |
| 628 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 629 | if (rxrpc_conn_is_client(conn)) { |
| 630 | struct rxrpc_local *local = conn->params.local; |
| 631 | spin_lock(&local->client_conns_lock); |
| 632 | reap_time = conn->put_time + rxrpc_connection_expiry; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 633 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 634 | if (atomic_read(&conn->usage) > 0) { |
| 635 | ; |
| 636 | } else if (reap_time <= now) { |
| 637 | list_move_tail(&conn->link, &graveyard); |
David Howells | 4a3388c | 2016-04-04 14:00:37 +0100 | [diff] [blame] | 638 | rxrpc_put_client_connection_id(conn); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 639 | rb_erase(&conn->client_node, |
| 640 | &local->client_conns); |
| 641 | } else if (reap_time < earliest) { |
| 642 | earliest = reap_time; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 643 | } |
| 644 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 645 | spin_unlock(&local->client_conns_lock); |
| 646 | } else { |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 647 | peer = conn->params.peer; |
| 648 | write_lock_bh(&peer->conn_lock); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 649 | reap_time = conn->put_time + rxrpc_connection_expiry; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 650 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 651 | if (atomic_read(&conn->usage) > 0) { |
| 652 | ; |
| 653 | } else if (reap_time <= now) { |
| 654 | list_move_tail(&conn->link, &graveyard); |
| 655 | rb_erase(&conn->service_node, |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 656 | &peer->service_conns); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 657 | } else if (reap_time < earliest) { |
| 658 | earliest = reap_time; |
| 659 | } |
| 660 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 661 | write_unlock_bh(&peer->conn_lock); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 662 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 663 | } |
David Howells | b3f5750 | 2016-06-21 16:10:03 +0100 | [diff] [blame] | 664 | write_unlock(&rxrpc_connection_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 665 | |
| 666 | if (earliest != ULONG_MAX) { |
| 667 | _debug("reschedule reaper %ld", (long) earliest - now); |
| 668 | ASSERTCMP(earliest, >, now); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 669 | rxrpc_queue_delayed_work(&rxrpc_connection_reap, |
| 670 | (earliest - now) * HZ); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* then destroy all those pulled out */ |
| 674 | while (!list_empty(&graveyard)) { |
| 675 | conn = list_entry(graveyard.next, struct rxrpc_connection, |
| 676 | link); |
| 677 | list_del_init(&conn->link); |
| 678 | |
| 679 | ASSERTCMP(atomic_read(&conn->usage), ==, 0); |
| 680 | rxrpc_destroy_connection(conn); |
| 681 | } |
| 682 | |
| 683 | _leave(""); |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * preemptively destroy all the connection records rather than waiting for them |
| 688 | * to time out |
| 689 | */ |
| 690 | void __exit rxrpc_destroy_all_connections(void) |
| 691 | { |
| 692 | _enter(""); |
| 693 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 694 | rxrpc_connection_expiry = 0; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 695 | cancel_delayed_work(&rxrpc_connection_reap); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 696 | rxrpc_queue_delayed_work(&rxrpc_connection_reap, 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 697 | |
| 698 | _leave(""); |
| 699 | } |