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