net_ns.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* rxrpc network namespace handling.
  2. *
  3. * Copyright (C) 2017 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 Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/proc_fs.h>
  12. #include "ar-internal.h"
  13. unsigned int rxrpc_net_id;
  14. /*
  15. * Initialise a per-network namespace record.
  16. */
  17. static __net_init int rxrpc_init_net(struct net *net)
  18. {
  19. struct rxrpc_net *rxnet = rxrpc_net(net);
  20. int ret;
  21. get_random_bytes(&rxnet->epoch, sizeof(rxnet->epoch));
  22. rxnet->epoch |= RXRPC_RANDOM_EPOCH;
  23. INIT_LIST_HEAD(&rxnet->calls);
  24. rwlock_init(&rxnet->call_lock);
  25. INIT_LIST_HEAD(&rxnet->conn_proc_list);
  26. INIT_LIST_HEAD(&rxnet->service_conns);
  27. rwlock_init(&rxnet->conn_lock);
  28. INIT_DELAYED_WORK(&rxnet->service_conn_reaper,
  29. rxrpc_service_connection_reaper);
  30. rxnet->nr_client_conns = 0;
  31. rxnet->nr_active_client_conns = 0;
  32. rxnet->kill_all_client_conns = false;
  33. spin_lock_init(&rxnet->client_conn_cache_lock);
  34. spin_lock_init(&rxnet->client_conn_discard_lock);
  35. INIT_LIST_HEAD(&rxnet->waiting_client_conns);
  36. INIT_LIST_HEAD(&rxnet->active_client_conns);
  37. INIT_LIST_HEAD(&rxnet->idle_client_conns);
  38. INIT_DELAYED_WORK(&rxnet->client_conn_reaper,
  39. rxrpc_discard_expired_client_conns);
  40. INIT_LIST_HEAD(&rxnet->local_endpoints);
  41. mutex_init(&rxnet->local_mutex);
  42. hash_init(rxnet->peer_hash);
  43. spin_lock_init(&rxnet->peer_hash_lock);
  44. ret = -ENOMEM;
  45. rxnet->proc_net = proc_net_mkdir(net, "rxrpc", net->proc_net);
  46. if (!rxnet->proc_net)
  47. goto err_proc;
  48. proc_create("calls", 0444, rxnet->proc_net, &rxrpc_call_seq_fops);
  49. proc_create("conns", 0444, rxnet->proc_net, &rxrpc_connection_seq_fops);
  50. return 0;
  51. err_proc:
  52. return ret;
  53. }
  54. /*
  55. * Clean up a per-network namespace record.
  56. */
  57. static __net_exit void rxrpc_exit_net(struct net *net)
  58. {
  59. struct rxrpc_net *rxnet = rxrpc_net(net);
  60. rxrpc_destroy_all_calls(rxnet);
  61. rxrpc_destroy_all_connections(rxnet);
  62. rxrpc_destroy_all_locals(rxnet);
  63. proc_remove(rxnet->proc_net);
  64. }
  65. struct pernet_operations rxrpc_net_ops = {
  66. .init = rxrpc_init_net,
  67. .exit = rxrpc_exit_net,
  68. .id = &rxrpc_net_id,
  69. .size = sizeof(struct rxrpc_net),
  70. };