core.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * net/tipc/core.c: TIPC module code
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2005, Wind River Systems
  6. * Copyright (c) 2005-2006, Ericsson AB
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <linux/init.h>
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/version.h>
  37. #include <linux/random.h>
  38. #include "core.h"
  39. #include "dbg.h"
  40. #include "ref.h"
  41. #include "net.h"
  42. #include "user_reg.h"
  43. #include "name_table.h"
  44. #include "subscr.h"
  45. #include "config.h"
  46. int eth_media_start(void);
  47. void eth_media_stop(void);
  48. int handler_start(void);
  49. void handler_stop(void);
  50. int socket_init(void);
  51. void socket_stop(void);
  52. int netlink_start(void);
  53. void netlink_stop(void);
  54. #define MOD_NAME "tipc_start: "
  55. #ifndef CONFIG_TIPC_ZONES
  56. #define CONFIG_TIPC_ZONES 3
  57. #endif
  58. #ifndef CONFIG_TIPC_CLUSTERS
  59. #define CONFIG_TIPC_CLUSTERS 1
  60. #endif
  61. #ifndef CONFIG_TIPC_NODES
  62. #define CONFIG_TIPC_NODES 255
  63. #endif
  64. #ifndef CONFIG_TIPC_SLAVE_NODES
  65. #define CONFIG_TIPC_SLAVE_NODES 0
  66. #endif
  67. #ifndef CONFIG_TIPC_PORTS
  68. #define CONFIG_TIPC_PORTS 8191
  69. #endif
  70. #ifndef CONFIG_TIPC_LOG
  71. #define CONFIG_TIPC_LOG 0
  72. #endif
  73. /* global variables used by multiple sub-systems within TIPC */
  74. int tipc_mode = TIPC_NOT_RUNNING;
  75. int tipc_random;
  76. atomic_t tipc_user_count = ATOMIC_INIT(0);
  77. const char tipc_alphabet[] =
  78. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  79. /* configurable TIPC parameters */
  80. u32 tipc_own_addr;
  81. int tipc_max_zones;
  82. int tipc_max_clusters;
  83. int tipc_max_nodes;
  84. int tipc_max_slaves;
  85. int tipc_max_ports;
  86. int tipc_max_subscriptions;
  87. int tipc_max_publications;
  88. int tipc_net_id;
  89. int tipc_remote_management;
  90. int tipc_get_mode(void)
  91. {
  92. return tipc_mode;
  93. }
  94. /**
  95. * stop_net - shut down TIPC networking sub-systems
  96. */
  97. void stop_net(void)
  98. {
  99. eth_media_stop();
  100. tipc_stop_net();
  101. }
  102. /**
  103. * start_net - start TIPC networking sub-systems
  104. */
  105. int start_net(void)
  106. {
  107. int res;
  108. if ((res = tipc_start_net()) ||
  109. (res = eth_media_start())) {
  110. stop_net();
  111. }
  112. return res;
  113. }
  114. /**
  115. * stop_core - switch TIPC from SINGLE NODE to NOT RUNNING mode
  116. */
  117. void stop_core(void)
  118. {
  119. if (tipc_mode != TIPC_NODE_MODE)
  120. return;
  121. tipc_mode = TIPC_NOT_RUNNING;
  122. netlink_stop();
  123. handler_stop();
  124. cfg_stop();
  125. subscr_stop();
  126. reg_stop();
  127. nametbl_stop();
  128. ref_table_stop();
  129. socket_stop();
  130. }
  131. /**
  132. * start_core - switch TIPC from NOT RUNNING to SINGLE NODE mode
  133. */
  134. int start_core(void)
  135. {
  136. int res;
  137. if (tipc_mode != TIPC_NOT_RUNNING)
  138. return -ENOPROTOOPT;
  139. get_random_bytes(&tipc_random, sizeof(tipc_random));
  140. tipc_mode = TIPC_NODE_MODE;
  141. if ((res = handler_start()) ||
  142. (res = ref_table_init(tipc_max_ports + tipc_max_subscriptions,
  143. tipc_random)) ||
  144. (res = reg_start()) ||
  145. (res = nametbl_init()) ||
  146. (res = k_signal((Handler)subscr_start, 0)) ||
  147. (res = k_signal((Handler)cfg_init, 0)) ||
  148. (res = netlink_start()) ||
  149. (res = socket_init())) {
  150. stop_core();
  151. }
  152. return res;
  153. }
  154. static int __init tipc_init(void)
  155. {
  156. int res;
  157. log_reinit(CONFIG_TIPC_LOG);
  158. info("Activated (compiled " __DATE__ " " __TIME__ ")\n");
  159. tipc_own_addr = 0;
  160. tipc_remote_management = 1;
  161. tipc_max_publications = 10000;
  162. tipc_max_subscriptions = 2000;
  163. tipc_max_ports = delimit(CONFIG_TIPC_PORTS, 127, 65536);
  164. tipc_max_zones = delimit(CONFIG_TIPC_ZONES, 1, 511);
  165. tipc_max_clusters = delimit(CONFIG_TIPC_CLUSTERS, 1, 1);
  166. tipc_max_nodes = delimit(CONFIG_TIPC_NODES, 8, 2047);
  167. tipc_max_slaves = delimit(CONFIG_TIPC_SLAVE_NODES, 0, 2047);
  168. tipc_net_id = 4711;
  169. if ((res = start_core()))
  170. err("Unable to start in single node mode\n");
  171. else
  172. info("Started in single node mode\n");
  173. return res;
  174. }
  175. static void __exit tipc_exit(void)
  176. {
  177. stop_net();
  178. stop_core();
  179. info("Deactivated\n");
  180. log_stop();
  181. }
  182. module_init(tipc_init);
  183. module_exit(tipc_exit);
  184. MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication");
  185. MODULE_LICENSE("Dual BSD/GPL");
  186. /* Native TIPC API for kernel-space applications (see tipc.h) */
  187. EXPORT_SYMBOL(tipc_attach);
  188. EXPORT_SYMBOL(tipc_detach);
  189. EXPORT_SYMBOL(tipc_get_addr);
  190. EXPORT_SYMBOL(tipc_get_mode);
  191. EXPORT_SYMBOL(tipc_createport);
  192. EXPORT_SYMBOL(tipc_deleteport);
  193. EXPORT_SYMBOL(tipc_ownidentity);
  194. EXPORT_SYMBOL(tipc_portimportance);
  195. EXPORT_SYMBOL(tipc_set_portimportance);
  196. EXPORT_SYMBOL(tipc_portunreliable);
  197. EXPORT_SYMBOL(tipc_set_portunreliable);
  198. EXPORT_SYMBOL(tipc_portunreturnable);
  199. EXPORT_SYMBOL(tipc_set_portunreturnable);
  200. EXPORT_SYMBOL(tipc_publish);
  201. EXPORT_SYMBOL(tipc_withdraw);
  202. EXPORT_SYMBOL(tipc_connect2port);
  203. EXPORT_SYMBOL(tipc_disconnect);
  204. EXPORT_SYMBOL(tipc_shutdown);
  205. EXPORT_SYMBOL(tipc_isconnected);
  206. EXPORT_SYMBOL(tipc_peer);
  207. EXPORT_SYMBOL(tipc_ref_valid);
  208. EXPORT_SYMBOL(tipc_send);
  209. EXPORT_SYMBOL(tipc_send_buf);
  210. EXPORT_SYMBOL(tipc_send2name);
  211. EXPORT_SYMBOL(tipc_forward2name);
  212. EXPORT_SYMBOL(tipc_send_buf2name);
  213. EXPORT_SYMBOL(tipc_forward_buf2name);
  214. EXPORT_SYMBOL(tipc_send2port);
  215. EXPORT_SYMBOL(tipc_forward2port);
  216. EXPORT_SYMBOL(tipc_send_buf2port);
  217. EXPORT_SYMBOL(tipc_forward_buf2port);
  218. EXPORT_SYMBOL(tipc_multicast);
  219. /* EXPORT_SYMBOL(tipc_multicast_buf); not available yet */
  220. EXPORT_SYMBOL(tipc_ispublished);
  221. EXPORT_SYMBOL(tipc_available_nodes);
  222. /* TIPC API for external bearers (see tipc_bearer.h) */
  223. EXPORT_SYMBOL(tipc_block_bearer);
  224. EXPORT_SYMBOL(tipc_continue);
  225. EXPORT_SYMBOL(tipc_disable_bearer);
  226. EXPORT_SYMBOL(tipc_enable_bearer);
  227. EXPORT_SYMBOL(tipc_recv_msg);
  228. EXPORT_SYMBOL(tipc_register_media);
  229. /* TIPC API for external APIs (see tipc_port.h) */
  230. EXPORT_SYMBOL(tipc_createport_raw);
  231. EXPORT_SYMBOL(tipc_set_msg_option);
  232. EXPORT_SYMBOL(tipc_reject_msg);
  233. EXPORT_SYMBOL(tipc_send_buf_fast);
  234. EXPORT_SYMBOL(tipc_acknowledge);
  235. EXPORT_SYMBOL(tipc_get_port);
  236. EXPORT_SYMBOL(tipc_get_handle);