sctp_rpc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2009 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "../../rpc_lookup.h"
  19. #include "../../socket_info.h"
  20. #include "../../globals.h"
  21. #include "../../config.h"
  22. #ifdef USE_SCTP
  23. #include "sctp_options.h"
  24. #include "sctp_server.h"
  25. #endif
  26. static const char* core_sctp_options_doc[] = {
  27. "Returns active sctp options. With one parameter"
  28. " it returns the sctp options set in the kernel for a specific socket"
  29. "(debugging), with 0 filled in for non-kernel related options."
  30. " The parameter can be: \"default\" | \"first\" | address[:port] ."
  31. " With no parameters it returns ser's idea of the current sctp options"
  32. " (intended non-debugging use).",
  33. /* Documentation string */
  34. 0 /* Method signature(s) */
  35. };
  36. static void core_sctp_options(rpc_t* rpc, void* c)
  37. {
  38. #ifdef USE_SCTP
  39. void *handle;
  40. struct cfg_group_sctp t;
  41. char* param;
  42. struct socket_info* si;
  43. char* host;
  44. str hs;
  45. int hlen;
  46. int port;
  47. int proto;
  48. param=0;
  49. if (!sctp_disable){
  50. /* look for optional socket parameter */
  51. if (rpc->scan(c, "*s", &param)>0){
  52. si=0;
  53. if (strcasecmp(param, "default")==0){
  54. si=sendipv4_sctp?sendipv4_sctp:sendipv6_sctp;
  55. }else if (strcasecmp(param, "first")==0){
  56. si=sctp_listen;
  57. }else{
  58. if (parse_phostport(param, &host, &hlen, &port, &proto)!=0){
  59. rpc->fault(c, 500, "bad param (use address, address:port,"
  60. " default or first)");
  61. return;
  62. }
  63. if (proto && proto!=PROTO_SCTP){
  64. rpc->fault(c, 500, "bad protocol in param (only SCTP"
  65. " allowed)");
  66. return;
  67. }
  68. hs.s=host;
  69. hs.len=hlen;
  70. si=grep_sock_info(&hs, port, PROTO_SCTP);
  71. if (si==0){
  72. rpc->fault(c, 500, "not listening on sctp %s", param);
  73. return;
  74. }
  75. }
  76. if (si==0 || si->socket==-1){
  77. rpc->fault(c, 500, "could not find a sctp socket");
  78. return;
  79. }
  80. memset(&t, 0, sizeof(t));
  81. if (sctp_get_cfg_from_sock(si->socket, &t)!=0){
  82. rpc->fault(c, 500, "failed to get socket options");
  83. return;
  84. }
  85. }else{
  86. sctp_options_get(&t);
  87. }
  88. rpc->add(c, "{", &handle);
  89. rpc->struct_add(handle, "ddddddddddddddddddd",
  90. "sctp_socket_rcvbuf", t.so_rcvbuf,
  91. "sctp_socket_sndbuf", t.so_sndbuf,
  92. "sctp_autoclose", t.autoclose,
  93. "sctp_send_ttl", t.send_ttl,
  94. "sctp_send_retries", t.send_retries,
  95. "sctp_assoc_tracking", t.assoc_tracking,
  96. "sctp_assoc_reuse", t.assoc_reuse,
  97. "sctp_max_assocs", t.max_assocs,
  98. "sctp_srto_initial", t.srto_initial,
  99. "sctp_srto_max", t.srto_max,
  100. "sctp_srto_min", t.srto_min,
  101. "sctp_asocmaxrxt", t.asocmaxrxt,
  102. "sctp_init_max_attempts", t.init_max_attempts,
  103. "sctp_init_max_timeo",t.init_max_timeo,
  104. "sctp_hbinterval", t.hbinterval,
  105. "sctp_pathmaxrxt", t.pathmaxrxt,
  106. "sctp_sack_delay", t.sack_delay,
  107. "sctp_sack_freq", t.sack_freq,
  108. "sctp_max_burst", t.max_burst
  109. );
  110. }else{
  111. rpc->fault(c, 500, "sctp support disabled");
  112. }
  113. #else
  114. rpc->fault(c, 500, "sctp support not compiled");
  115. #endif
  116. }
  117. static const char* core_sctpinfo_doc[] = {
  118. "Returns sctp related info.", /* Documentation string */
  119. 0 /* Method signature(s) */
  120. };
  121. static void core_sctpinfo(rpc_t* rpc, void* c)
  122. {
  123. #ifdef USE_SCTP
  124. void *handle;
  125. struct sctp_gen_info i;
  126. if (!sctp_disable){
  127. sctp_get_info(&i);
  128. rpc->add(c, "{", &handle);
  129. rpc->struct_add(handle, "ddd",
  130. "opened_connections", i.sctp_connections_no,
  131. "tracked_connections", i.sctp_tracked_no,
  132. "total_connections", i.sctp_total_connections
  133. );
  134. }else{
  135. rpc->fault(c, 500, "sctp support disabled");
  136. }
  137. #else
  138. rpc->fault(c, 500, "sctp support not compiled");
  139. #endif
  140. }
  141. /*
  142. * RPC Methods exported by this module
  143. */
  144. static rpc_export_t scp_rpc_methods[] = {
  145. {"sctp.options", core_sctp_options, core_sctp_options_doc,
  146. 0},
  147. {"sctp.info", core_sctpinfo, core_sctpinfo_doc, 0},
  148. {0, 0, 0, 0}
  149. };
  150. int sctp_register_rpc(void)
  151. {
  152. if (rpc_register_array(scp_rpc_methods)!=0)
  153. {
  154. LM_ERR("failed to register RPC commands\n");
  155. return -1;
  156. }
  157. return 0;
  158. }