core.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * net/tipc/core.c: TIPC module code
  3. *
  4. * Copyright (c) 2003-2006, 2013, Ericsson AB
  5. * Copyright (c) 2005-2006, 2010-2013, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  37. #include "core.h"
  38. #include "name_table.h"
  39. #include "subscr.h"
  40. #include "bearer.h"
  41. #include "net.h"
  42. #include "socket.h"
  43. #include <linux/module.h>
  44. /* configurable TIPC parameters */
  45. int tipc_net_id __read_mostly;
  46. int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */
  47. static int __net_init tipc_init_net(struct net *net)
  48. {
  49. struct tipc_net *tn = net_generic(net, tipc_net_id);
  50. int err;
  51. tn->net_id = 4711;
  52. tn->own_addr = 0;
  53. get_random_bytes(&tn->random, sizeof(int));
  54. INIT_LIST_HEAD(&tn->node_list);
  55. spin_lock_init(&tn->node_list_lock);
  56. err = tipc_sk_rht_init(net);
  57. if (err)
  58. goto out_sk_rht;
  59. err = tipc_nametbl_init(net);
  60. if (err)
  61. goto out_nametbl;
  62. err = tipc_topsrv_start(net);
  63. if (err)
  64. goto out_subscr;
  65. return 0;
  66. out_subscr:
  67. tipc_nametbl_stop(net);
  68. out_nametbl:
  69. tipc_sk_rht_destroy(net);
  70. out_sk_rht:
  71. return err;
  72. }
  73. static void __net_exit tipc_exit_net(struct net *net)
  74. {
  75. tipc_topsrv_stop(net);
  76. tipc_net_stop(net);
  77. tipc_nametbl_stop(net);
  78. tipc_sk_rht_destroy(net);
  79. }
  80. static struct pernet_operations tipc_net_ops = {
  81. .init = tipc_init_net,
  82. .exit = tipc_exit_net,
  83. .id = &tipc_net_id,
  84. .size = sizeof(struct tipc_net),
  85. };
  86. static int __init tipc_init(void)
  87. {
  88. int err;
  89. pr_info("Activated (version " TIPC_MOD_VER ")\n");
  90. sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
  91. TIPC_LOW_IMPORTANCE;
  92. sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
  93. TIPC_CRITICAL_IMPORTANCE;
  94. sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT;
  95. err = tipc_netlink_start();
  96. if (err)
  97. goto out_netlink;
  98. err = tipc_netlink_compat_start();
  99. if (err)
  100. goto out_netlink_compat;
  101. err = tipc_socket_init();
  102. if (err)
  103. goto out_socket;
  104. err = tipc_register_sysctl();
  105. if (err)
  106. goto out_sysctl;
  107. err = register_pernet_subsys(&tipc_net_ops);
  108. if (err)
  109. goto out_pernet;
  110. err = tipc_bearer_setup();
  111. if (err)
  112. goto out_bearer;
  113. pr_info("Started in single node mode\n");
  114. return 0;
  115. out_bearer:
  116. unregister_pernet_subsys(&tipc_net_ops);
  117. out_pernet:
  118. tipc_unregister_sysctl();
  119. out_sysctl:
  120. tipc_socket_stop();
  121. out_socket:
  122. tipc_netlink_compat_stop();
  123. out_netlink_compat:
  124. tipc_netlink_stop();
  125. out_netlink:
  126. pr_err("Unable to start in single node mode\n");
  127. return err;
  128. }
  129. static void __exit tipc_exit(void)
  130. {
  131. tipc_bearer_cleanup();
  132. unregister_pernet_subsys(&tipc_net_ops);
  133. tipc_netlink_stop();
  134. tipc_netlink_compat_stop();
  135. tipc_socket_stop();
  136. tipc_unregister_sysctl();
  137. pr_info("Deactivated\n");
  138. }
  139. module_init(tipc_init);
  140. module_exit(tipc_exit);
  141. MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication");
  142. MODULE_LICENSE("Dual BSD/GPL");
  143. MODULE_VERSION(TIPC_MOD_VER);