sctp_mod.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2008 iptelorg GmbH
  5. * Copyright (C) 2013 Daniel-Constantin Mierla (asipto.com)
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Permission to use, copy, modify, and distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include "../../sr_module.h"
  26. #include "../../dprint.h"
  27. #include "../../shm_init.h"
  28. #include "../../sctp_core.h"
  29. #include "sctp_options.h"
  30. #include "sctp_server.h"
  31. #include "sctp_rpc.h"
  32. MODULE_VERSION
  33. static int mod_init(void);
  34. #ifdef USE_SCTP
  35. static int sctp_mod_pre_init(void);
  36. #endif
  37. static cmd_export_t cmds[]={
  38. {0, 0, 0, 0, 0, 0}
  39. };
  40. static param_export_t params[]={
  41. {"sctp_socket_rcvbuf", PARAM_INT, &sctp_default_cfg.so_rcvbuf},
  42. {"sctp_socket_sndbuf", PARAM_INT, &sctp_default_cfg.so_sndbuf},
  43. {"sctp_autoclose", PARAM_INT, &sctp_default_cfg.autoclose},
  44. {"sctp_send_ttl", PARAM_INT, &sctp_default_cfg.send_ttl},
  45. {"sctp_send_retries", PARAM_INT, &sctp_default_cfg.send_retries},
  46. {"sctp_assoc_tracking", PARAM_INT, &sctp_default_cfg.assoc_tracking},
  47. {"sctp_assoc_reuse", PARAM_INT, &sctp_default_cfg.assoc_reuse},
  48. {"sctp_max_assocs", PARAM_INT, &sctp_default_cfg.max_assocs},
  49. {"sctp_srto_initial", PARAM_INT, &sctp_default_cfg.srto_initial},
  50. {"sctp_srto_max", PARAM_INT, &sctp_default_cfg.srto_max},
  51. {"sctp_srto_min", PARAM_INT, &sctp_default_cfg.srto_min},
  52. {"sctp_asocmaxrxt", PARAM_INT, &sctp_default_cfg.asocmaxrxt},
  53. {"sctp_init_max_attempts", PARAM_INT, &sctp_default_cfg.init_max_attempts},
  54. {"sctp_init_max_timeo", PARAM_INT, &sctp_default_cfg.init_max_timeo},
  55. {"sctp_hbinterval", PARAM_INT, &sctp_default_cfg.hbinterval},
  56. {"sctp_pathmaxrxt", PARAM_INT, &sctp_default_cfg.pathmaxrxt},
  57. {"sctp_sack_delay", PARAM_INT, &sctp_default_cfg.sack_delay},
  58. {"sctp_sack_freq", PARAM_INT, &sctp_default_cfg.sack_freq},
  59. {"sctp_max_burst", PARAM_INT, &sctp_default_cfg.max_burst},
  60. {0, 0, 0}
  61. };
  62. struct module_exports exports = {
  63. "sctp",
  64. DEFAULT_DLFLAGS, /* dlopen flags */
  65. cmds,
  66. params,
  67. 0,
  68. 0, /* exported MI functions */
  69. 0, /* exported pseudo-variables */
  70. 0, /* extra processes */
  71. mod_init, /* module initialization function */
  72. 0, /* response function */
  73. 0, /* destroy function */
  74. 0 /* per child init function */
  75. };
  76. int mod_register(char *path, int *dlflags, void *p1, void *p2)
  77. {
  78. if(!shm_initialized() && init_shm()<0)
  79. return -1;
  80. #ifdef USE_SCTP
  81. /* shm is used, be sure it is initialized */
  82. if(sctp_mod_pre_init()<0)
  83. return -1;
  84. return 0;
  85. #else
  86. LOG(L_CRIT, "sctp core support not enabled\n");
  87. return -1;
  88. #endif
  89. }
  90. static int mod_init(void)
  91. {
  92. #ifdef USE_SCTP
  93. char tmp[256];
  94. if (sctp_check_compiled_sockopts(tmp, 256)!=0){
  95. LM_WARN("sctp unsupported socket options: %s\n", tmp);
  96. }
  97. if (sctp_register_cfg()){
  98. LOG(L_CRIT, "could not register the sctp configuration\n");
  99. return -1;
  100. }
  101. if (sctp_register_rpc()){
  102. LOG(L_CRIT, "could not register the sctp rpc commands\n");
  103. return -1;
  104. }
  105. return 0;
  106. #else /* USE_SCTP */
  107. LOG(L_CRIT, "sctp core support not enabled\n");
  108. return -1;
  109. #endif /* USE_SCTP */
  110. }
  111. #ifdef USE_SCTP
  112. static int sctp_mod_pre_init(void)
  113. {
  114. sctp_srapi_t api;
  115. /* set defaults before the config mod params */
  116. init_sctp_options();
  117. memset(&api, 0, sizeof(sctp_srapi_t));
  118. api.init = init_sctp;
  119. api.destroy = destroy_sctp;
  120. api.init_sock = sctp_init_sock;
  121. api.check_support = sctp_check_support;
  122. api.rcv_loop = sctp_rcv_loop;
  123. api.msg_send = sctp_msg_send;
  124. if(sctp_core_register_api(&api)<0) {
  125. LM_ERR("cannot regiser sctp core api\n");
  126. return -1;
  127. }
  128. return 0;
  129. }
  130. #endif