peering.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Radius based peering module
  3. *
  4. * Copyright (C) 2008 Juha Heinanen
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. /*! \file
  24. * \ingroup peering
  25. * \brief Peering:: Core
  26. *
  27. * - Module: \ref peering
  28. */
  29. /*! \defgroup peering Peering :: Radius based peering verification module
  30. *
  31. * The Peering module allows SIP providers (operators or
  32. * organizations) to verify from a broker if source or destination
  33. * of a SIP request is a trusted peer.
  34. *
  35. */
  36. #include "../../sr_module.h"
  37. #include "../../mem/mem.h"
  38. #include "../../config.h"
  39. #include "../../lib/kcore/radius.h"
  40. #include "verify.h"
  41. MODULE_VERSION
  42. struct attr attrs[A_MAX];
  43. struct val vals[V_MAX];
  44. void *rh;
  45. static int mod_init(void); /* Module initialization function */
  46. /*
  47. * Module parameter variables
  48. */
  49. static char* radius_config = DEFAULT_RADIUSCLIENT_CONF;
  50. int verify_destination_service_type = -1;
  51. int verify_source_service_type = -1;
  52. /*
  53. * Exported functions
  54. */
  55. static cmd_export_t cmds[] = {
  56. {"verify_destination", (cmd_function)verify_destination, 0, 0, 0,
  57. REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
  58. {"verify_source", (cmd_function)verify_source, 0, 0, 0,
  59. REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
  60. {0, 0, 0, 0, 0, 0}
  61. };
  62. /*
  63. * Exported parameters
  64. */
  65. static param_export_t params[] = {
  66. {"radius_config", PARAM_STRING, &radius_config},
  67. {"verify_destination_service_type", INT_PARAM,
  68. &verify_destination_service_type},
  69. {"verify_source_service_type", INT_PARAM,
  70. &verify_source_service_type},
  71. {0, 0, 0}
  72. };
  73. /*
  74. * Module interface
  75. */
  76. struct module_exports exports = {
  77. "peering",
  78. DEFAULT_DLFLAGS, /* dlopen flags */
  79. cmds, /* Exported functions */
  80. params, /* Exported parameters */
  81. 0, /* exported statistics */
  82. 0, /* exported MI functions */
  83. 0, /* exported pseudo-variables */
  84. 0, /* extra processes */
  85. mod_init, /* module initialization function */
  86. 0, /* response function */
  87. 0, /* destroy function */
  88. 0 /* child initialization function */
  89. };
  90. /*
  91. * Module initialization function
  92. */
  93. static int mod_init(void)
  94. {
  95. memset(attrs, 0, sizeof(attrs));
  96. memset(vals, 0, sizeof(vals));
  97. attrs[A_USER_NAME].n = "User-Name";
  98. attrs[A_SIP_URI_USER].n = "SIP-URI-User";
  99. attrs[A_SIP_FROM_TAG].n = "SIP-From-Tag";
  100. attrs[A_SIP_CALL_ID].n = "SIP-Call-Id";
  101. attrs[A_SIP_REQUEST_HASH].n = "SIP-Request-Hash";
  102. attrs[A_SIP_AVP].n = "SIP-AVP";
  103. attrs[A_SERVICE_TYPE].n = "Service-Type";
  104. vals[V_SIP_VERIFY_DESTINATION].n = "Sip-Verify-Destination";
  105. vals[V_SIP_VERIFY_SOURCE].n = "Sip-Verify-Source";
  106. if ((rh = rc_read_config(radius_config)) == NULL) {
  107. LM_ERR("error opening configuration file\n");
  108. return -1;
  109. }
  110. if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
  111. LM_ERR("error opening dictionary file\n");
  112. return -2;
  113. }
  114. INIT_AV(rh, attrs, A_MAX, vals, V_MAX, "peering", -3, -4);
  115. if (verify_destination_service_type != -1) {
  116. vals[V_SIP_VERIFY_DESTINATION].v =
  117. verify_destination_service_type;
  118. }
  119. if (verify_source_service_type != -1) {
  120. vals[V_SIP_VERIFY_SOURCE].v = verify_source_service_type;
  121. }
  122. return 0;
  123. }