|
|
|
@ -109,8 +109,9 @@ struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *r
|
|
|
|
|
|
|
|
|
|
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
|
|
|
|
|
{
|
|
|
|
|
if (!entry)
|
|
|
|
|
if (!entry) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST_RWLIST_WRLOCK(&entry_list);
|
|
|
|
|
AST_RWLIST_REMOVE(&entry_list, entry, list);
|
|
|
|
@ -230,16 +231,18 @@ static int refresh_list(const void *data)
|
|
|
|
|
|
|
|
|
|
/* if a refresh or reload is already in progress, exit now */
|
|
|
|
|
if (ast_mutex_trylock(&refresh_lock)) {
|
|
|
|
|
if (info->verbose)
|
|
|
|
|
if (info->verbose) {
|
|
|
|
|
ast_log(LOG_WARNING, "DNS Manager refresh already in progress.\n");
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_verb(3, "Refreshing DNS lookups.\n");
|
|
|
|
|
AST_RWLIST_RDLOCK(info->entries);
|
|
|
|
|
AST_RWLIST_TRAVERSE(info->entries, entry, list) {
|
|
|
|
|
if (info->regex_present && regexec(&info->filter, entry->name, 0, NULL, 0))
|
|
|
|
|
if (info->regex_present && regexec(&info->filter, entry->name, 0, NULL, 0)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dnsmgr_refresh(entry, info->verbose);
|
|
|
|
|
}
|
|
|
|
@ -273,8 +276,9 @@ static char *handle_cli_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_
|
|
|
|
|
case CLI_GENERATE:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (a->argc > 2)
|
|
|
|
|
if (a->argc > 2) {
|
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_reload(0);
|
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
@ -339,8 +343,9 @@ static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a->argc > 2)
|
|
|
|
|
if (a->argc > 2) {
|
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_cli(a->fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
|
|
|
|
|
ast_cli(a->fd, "Refresh Interval: %d seconds\n", refresh_interval);
|
|
|
|
@ -377,16 +382,15 @@ int dnsmgr_reload(void)
|
|
|
|
|
static int do_reload(int loading)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config *config;
|
|
|
|
|
struct ast_variable *v;
|
|
|
|
|
struct ast_flags config_flags = { loading ? 0 : CONFIG_FLAG_FILEUNCHANGED };
|
|
|
|
|
const char *interval_value;
|
|
|
|
|
const char *enabled_value;
|
|
|
|
|
int interval;
|
|
|
|
|
int was_enabled;
|
|
|
|
|
int res = -1;
|
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
|
|
config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags);
|
|
|
|
|
if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEUNCHANGED || config == CONFIG_STATUS_FILEINVALID) {
|
|
|
|
|
return 0;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ensure that no refresh cycles run while the reload is in progress */
|
|
|
|
@ -399,23 +403,24 @@ static int do_reload(int loading)
|
|
|
|
|
|
|
|
|
|
AST_SCHED_DEL(sched, refresh_sched);
|
|
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
|
if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
|
|
|
|
|
enabled = ast_true(enabled_value);
|
|
|
|
|
}
|
|
|
|
|
if ((interval_value = ast_variable_retrieve(config, "general", "refreshinterval"))) {
|
|
|
|
|
if (sscanf(interval_value, "%30d", &interval) < 1)
|
|
|
|
|
ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", interval_value);
|
|
|
|
|
else if (interval < 0)
|
|
|
|
|
for (v = ast_variable_browse(config, "general"); v; v = v->next) {
|
|
|
|
|
if (!strcasecmp(v->name, "enable")) {
|
|
|
|
|
enabled = ast_true(v->value);
|
|
|
|
|
} else if (!strcasecmp(v->name, "refreshinterval")) {
|
|
|
|
|
if (sscanf(v->value, "%30d", &interval) < 1) {
|
|
|
|
|
ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", v->value);
|
|
|
|
|
} else if (interval < 0) {
|
|
|
|
|
ast_log(LOG_WARNING, "Invalid refresh interval '%d' specified, using default\n", interval);
|
|
|
|
|
else
|
|
|
|
|
} else {
|
|
|
|
|
refresh_interval = interval;
|
|
|
|
|
}
|
|
|
|
|
ast_config_destroy(config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ast_config_destroy(config);
|
|
|
|
|
|
|
|
|
|
if (enabled && refresh_interval)
|
|
|
|
|
if (enabled && refresh_interval) {
|
|
|
|
|
ast_log(LOG_NOTICE, "Managed DNS entries will be refreshed every %d seconds.\n", refresh_interval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if this reload enabled the manager, create the background thread
|
|
|
|
|
if it does not exist */
|
|
|
|
@ -427,20 +432,14 @@ static int do_reload(int loading)
|
|
|
|
|
}
|
|
|
|
|
/* make a background refresh happen right away */
|
|
|
|
|
refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
|
|
|
|
|
res = 0;
|
|
|
|
|
}
|
|
|
|
|
/* if this reload disabled the manager and there is a background thread,
|
|
|
|
|
kill it */
|
|
|
|
|
else if (!enabled && was_enabled && (refresh_thread != AST_PTHREADT_NULL)) {
|
|
|
|
|
/* if this reload disabled the manager and there is a background thread, kill it */
|
|
|
|
|
} else if (!enabled && was_enabled && (refresh_thread != AST_PTHREADT_NULL)) {
|
|
|
|
|
/* wake up the thread so it will exit */
|
|
|
|
|
pthread_cancel(refresh_thread);
|
|
|
|
|
pthread_kill(refresh_thread, SIGURG);
|
|
|
|
|
pthread_join(refresh_thread, NULL);
|
|
|
|
|
refresh_thread = AST_PTHREADT_NULL;
|
|
|
|
|
res = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
|
|
ast_mutex_unlock(&refresh_lock);
|
|
|
|
|
manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: DNSmgr\r\nStatus: %s\r/nMessage: DNSmgr reload Requested\r\n", enabled ? "Enabled" : "Disabled");
|
|
|
|
|