12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/net.h>
25 static unsigned long rxrpc_connection_timeout = 10 * 60;
59 ((
unsigned long) bundle->
key - (
unsigned long)
key);
90 if (rxrpc_cmp_bundle(bundle, key, service_id) < 0)
92 else if (rxrpc_cmp_bundle(bundle, key, service_id) > 0)
95 goto found_extant_bundle;
102 candidate = rxrpc_alloc_bundle(gfp);
108 candidate->
key = key_get(key);
119 if (rxrpc_cmp_bundle(bundle, key, service_id) < 0)
121 else if (rxrpc_cmp_bundle(bundle, key, service_id) > 0)
124 goto found_extant_second;
131 rb_link_node(&bundle->
node, parent, pp);
139 _leave(
" = %p [new]", bundle);
205 skb_queue_head_init(&conn->
rx_queue);
240 real_conn_id = conn->
trans->conn_idcounter;
244 p = &conn->
trans->client_conns.rb_node;
250 if (epoch < xconn->epoch)
252 else if (epoch > xconn->
epoch)
254 else if (real_conn_id < xconn->real_conn_id)
264 rb_link_node(&conn->
node, parent, p);
280 conn->
trans->conn_idcounter = real_conn_id;
281 goto attempt_insertion;
286 goto attempt_insertion;
289 if (epoch < xconn->epoch ||
290 real_conn_id < xconn->real_conn_id)
291 goto attempt_insertion;
308 p = &conn->
calls.rb_node;
314 if (call_id < xcall->call_id)
316 else if (call_id > xcall->
call_id)
322 rb_link_node(&call->
conn_node, parent, p);
331 static int rxrpc_connect_exclusive(
struct rxrpc_sock *
rx,
346 conn = rxrpc_alloc_connection(gfp);
362 conn->
key = key_get(rx->
key);
368 _leave(
" = %d [key]", ret);
379 _net(
"CONNECT EXCL new %d on TRANS %d",
382 rxrpc_assign_connection_id(conn);
394 goto no_free_channels;
404 _net(
"CONNECT client on conn %d chan %d as call %x",
409 rxrpc_add_call_ID_to_conn(conn, call);
437 return rxrpc_connect_exclusive(rx, trans, bundle->
service_id,
510 goto interrupted_dequeue;
521 candidate = rxrpc_alloc_connection(gfp);
537 candidate->
key = key_get(bundle->
key);
543 _leave(
" = %d [key]", ret);
558 _net(
"CONNECT new %d on TRANS %d",
561 rxrpc_assign_connection_id(candidate);
563 candidate->
security->prime_packet_security(candidate);
593 _net(
"CONNECT client on conn %d chan %d as call %x",
599 rxrpc_add_call_ID_to_conn(conn, call);
608 _leave(
" = -ERESTARTSYS");
622 const char *
new =
"old";
642 if (epoch < conn->epoch)
644 else if (epoch > conn->
epoch)
646 else if (conn_id < conn->real_conn_id)
651 goto found_extant_connection;
657 candidate = rxrpc_alloc_connection(gfp);
671 candidate->
state = RXRPC_CONN_SERVER;
673 candidate->
state = RXRPC_CONN_SERVER_UNSECURED;
683 if (epoch < conn->epoch)
685 else if (epoch > conn->
epoch)
687 else if (conn_id < conn->real_conn_id)
692 goto found_extant_second;
698 rb_link_node(&conn->
node, p, pp);
717 found_extant_connection:
720 goto security_mismatch;
730 goto security_mismatch;
739 _leave(
" = -EKEYREJECTED");
772 if (epoch < conn->epoch)
774 else if (epoch > conn->
epoch)
776 else if (conn_id < conn->real_conn_id)
843 unsigned long now, earliest, reap_time;
854 _debug(
"reap CONN %d { u=%d,t=%ld }",
856 (
long) now - (
long) conn->
put_time);
861 spin_lock(&conn->
trans->client_lock);
863 reap_time = conn->
put_time + rxrpc_connection_timeout;
867 }
else if (reap_time <= now) {
868 list_move_tail(&conn->
link, &graveyard);
871 &conn->
trans->client_conns);
874 &conn->
trans->server_conns);
877 conn->
bundle->num_conns--;
880 }
else if (reap_time < earliest) {
881 earliest = reap_time;
885 spin_unlock(&conn->
trans->client_lock);
890 _debug(
"reschedule reaper %ld", (
long) earliest - now);
893 (earliest - now) *
HZ);
897 while (!list_empty(&graveyard)) {
900 list_del_init(&conn->
link);
903 rxrpc_destroy_connection(conn);
917 rxrpc_connection_timeout = 0;