mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-30 15:14:17 +00:00
add acl stuff
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7966 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
9943975660
commit
bba65f4a1e
15 files changed
+464
-3
No files matched your search
@@ -46,6 +46,8 @@
|
||||
#include <switch_odbc.h>
|
||||
#endif
|
||||
|
||||
#define SOFIA_MAX_ACL 100
|
||||
|
||||
#define MODNAME "mod_sofia"
|
||||
static const switch_state_handler_table_t noop_state_handler = { 0 };
|
||||
struct sofia_gateway;
|
||||
@@ -308,6 +310,11 @@ struct sofia_profile {
|
||||
char *odbc_pass;
|
||||
switch_odbc_handle_t *master_odbc;
|
||||
switch_queue_t *sql_queue;
|
||||
char *acl[SOFIA_MAX_ACL];
|
||||
uint32_t acl_count;
|
||||
char *reg_acl[SOFIA_MAX_ACL];
|
||||
uint32_t reg_acl_count;
|
||||
|
||||
};
|
||||
|
||||
struct private_object {
|
||||
|
||||
@@ -1195,6 +1195,18 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||
profile->username = switch_core_strdup(profile->pool, val);
|
||||
} else if (!strcasecmp(var, "context")) {
|
||||
profile->context = switch_core_strdup(profile->pool, val);
|
||||
} else if (!strcasecmp(var, "apply-inbound-acl")) {
|
||||
if (profile->acl_count < SOFIA_MAX_ACL) {
|
||||
profile->acl[profile->acl_count++] = switch_core_strdup(profile->pool, val);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
|
||||
}
|
||||
} else if (!strcasecmp(var, "apply-register-acl")) {
|
||||
if (profile->reg_acl_count < SOFIA_MAX_ACL) {
|
||||
profile->reg_acl[profile->reg_acl_count++] = switch_core_strdup(profile->pool, val);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max acl records of %d reached\n", SOFIA_MAX_ACL);
|
||||
}
|
||||
} else if (!strcasecmp(var, "alias")) {
|
||||
sip_alias_node_t *node;
|
||||
if ((node = switch_core_alloc(profile->pool, sizeof(*node)))) {
|
||||
@@ -2478,6 +2490,18 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
|
||||
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
|
||||
|
||||
if (profile->acl_count) {
|
||||
int x = 0;
|
||||
for (x = 0 ; x < profile->acl_count; x++) {
|
||||
if (!switch_check_network_list_ip(network_ip, profile->acl[x])) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->acl[x]);
|
||||
nua_respond(nh, SIP_403_FORBIDDEN, TAG_END());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((profile->pflags & PFLAG_AUTH_CALLS) || (!(profile->pflags & PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization))) {
|
||||
if (strcmp(network_ip, profile->sipip)) {
|
||||
if (sofia_reg_handle_register(nua, profile, nh, sip, REG_INVITE, key, sizeof(key), &v_event)) {
|
||||
|
||||
@@ -655,6 +655,23 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
|
||||
{
|
||||
char key[128] = "";
|
||||
switch_event_t *v_event = NULL;
|
||||
char network_ip[80];
|
||||
su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
|
||||
|
||||
if (profile->reg_acl_count) {
|
||||
int x = 0;
|
||||
|
||||
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
|
||||
|
||||
for (x = 0 ; x < profile->reg_acl_count; x++) {
|
||||
if (!switch_check_network_list_ip(network_ip, profile->reg_acl[x])) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
|
||||
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!(profile->mflags & MFLAG_REGISTER)) {
|
||||
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
|
||||
|
||||
Reference in new issue
Block a user