2005-04-06 21:13:51 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-04-06 21:13:51 +00:00
|
|
|
*
|
2006-02-10 20:40:00 +00:00
|
|
|
* Copyright (C) 2005-2006, Kevin P. Fleming
|
2005-04-06 21:13:51 +00:00
|
|
|
*
|
|
|
|
* Kevin P. Fleming <kpfleming@digium.com>
|
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2005-04-06 21:13:51 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Background DNS update manager
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Kevin P. Fleming <kpfleming@digium.com>
|
2005-04-06 21:13:51 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-06 21:13:51 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <resolv.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/dnsmgr.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/sched.h"
|
|
|
|
#include "asterisk/options.h"
|
|
|
|
#include "asterisk/cli.h"
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
static struct sched_context *sched;
|
|
|
|
static int refresh_sched = -1;
|
|
|
|
static pthread_t refresh_thread = AST_PTHREADT_NULL;
|
|
|
|
|
|
|
|
struct ast_dnsmgr_entry {
|
2006-06-07 17:44:36 +00:00
|
|
|
/*! where we will store the resulting address */
|
2006-06-05 16:17:31 +00:00
|
|
|
struct in_addr *result;
|
2006-06-07 17:44:36 +00:00
|
|
|
/*! the last result, used to check if address has changed */
|
|
|
|
struct in_addr last;
|
|
|
|
/*! Set to 1 if the entry changes */
|
|
|
|
int changed:1;
|
|
|
|
ast_mutex_t lock;
|
2007-06-18 16:37:14 +00:00
|
|
|
AST_RWLIST_ENTRY(ast_dnsmgr_entry) list;
|
2006-06-07 17:44:36 +00:00
|
|
|
/*! just 1 here, but we use calloc to allocate the correct size */
|
2006-06-05 16:17:31 +00:00
|
|
|
char name[1];
|
2005-04-06 21:13:51 +00:00
|
|
|
};
|
|
|
|
|
2007-06-18 16:37:14 +00:00
|
|
|
static AST_RWLIST_HEAD_STATIC(entry_list, ast_dnsmgr_entry);
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
AST_MUTEX_DEFINE_STATIC(refresh_lock);
|
|
|
|
|
|
|
|
#define REFRESH_DEFAULT 300
|
|
|
|
|
2006-12-27 22:14:33 +00:00
|
|
|
static int enabled;
|
2005-04-06 21:13:51 +00:00
|
|
|
static int refresh_interval;
|
|
|
|
|
|
|
|
struct refresh_info {
|
|
|
|
struct entry_list *entries;
|
|
|
|
int verbose;
|
2005-04-12 14:11:59 +00:00
|
|
|
unsigned int regex_present:1;
|
2005-04-06 21:13:51 +00:00
|
|
|
regex_t filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct refresh_info master_refresh_info = {
|
|
|
|
.entries = &entry_list,
|
|
|
|
.verbose = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result)
|
|
|
|
{
|
|
|
|
struct ast_dnsmgr_entry *entry;
|
|
|
|
|
2006-02-09 16:59:50 +00:00
|
|
|
if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
|
2005-04-06 21:13:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
entry->result = result;
|
2006-06-07 17:44:36 +00:00
|
|
|
ast_mutex_init(&entry->lock);
|
2005-04-06 21:13:51 +00:00
|
|
|
strcpy(entry->name, name);
|
2007-06-18 16:56:06 +00:00
|
|
|
memcpy(&entry->last, result, sizeof(entry->last));
|
2005-04-06 21:13:51 +00:00
|
|
|
|
2007-06-18 16:37:14 +00:00
|
|
|
AST_RWLIST_WRLOCK(&entry_list);
|
|
|
|
AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
|
|
|
|
AST_RWLIST_UNLOCK(&entry_list);
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
|
|
|
|
{
|
2005-04-07 07:41:06 +00:00
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
2007-06-18 16:37:14 +00:00
|
|
|
AST_RWLIST_WRLOCK(&entry_list);
|
|
|
|
AST_RWLIST_REMOVE(&entry_list, entry, list);
|
|
|
|
AST_RWLIST_UNLOCK(&entry_list);
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(4, "removing dns manager for '%s'\n", entry->name);
|
2006-06-07 17:44:36 +00:00
|
|
|
|
|
|
|
ast_mutex_destroy(&entry->lock);
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(entry);
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr)
|
|
|
|
{
|
2007-06-08 00:03:49 +00:00
|
|
|
struct ast_hostent ahp;
|
|
|
|
struct hostent *hp;
|
|
|
|
|
2005-10-26 18:54:24 +00:00
|
|
|
if (ast_strlen_zero(name) || !result || !dnsmgr)
|
2005-04-06 21:13:51 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
|
|
|
|
return 0;
|
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
/* if it's actually an IP address and not a name,
|
|
|
|
there's no need for a managed lookup */
|
|
|
|
if (inet_aton(name, result))
|
|
|
|
return 0;
|
|
|
|
|
2007-06-08 00:03:49 +00:00
|
|
|
/* do a lookup now but add a manager so it will automagically get updated in the background */
|
|
|
|
if ((hp = ast_gethostbyname(name, &ahp)))
|
|
|
|
memcpy(result, hp->h_addr, sizeof(result));
|
|
|
|
|
|
|
|
/* if dnsmgr is not enable don't bother adding an entry */
|
|
|
|
if (!enabled)
|
2005-04-07 07:41:06 +00:00
|
|
|
return 0;
|
2007-06-08 00:03:49 +00:00
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "adding dns manager for '%s'\n", name);
|
2007-06-08 00:03:49 +00:00
|
|
|
*dnsmgr = ast_dnsmgr_get(name, result);
|
|
|
|
return !*dnsmgr;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 17:44:36 +00:00
|
|
|
/*
|
|
|
|
* Refresh a dnsmgr entry
|
|
|
|
*/
|
|
|
|
static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
|
|
|
|
{
|
|
|
|
struct ast_hostent ahp;
|
|
|
|
struct hostent *hp;
|
|
|
|
char iabuf[INET_ADDRSTRLEN];
|
|
|
|
char iabuf2[INET_ADDRSTRLEN];
|
|
|
|
struct in_addr tmp;
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
ast_mutex_lock(&entry->lock);
|
2007-07-26 15:49:18 +00:00
|
|
|
if (verbose)
|
|
|
|
ast_verb(3, "refreshing '%s'\n", entry->name);
|
2006-06-07 17:44:36 +00:00
|
|
|
|
|
|
|
if ((hp = ast_gethostbyname(entry->name, &ahp))) {
|
|
|
|
/* check to see if it has changed, do callback if requested (where de callback is defined ????) */
|
|
|
|
memcpy(&tmp, hp->h_addr, sizeof(tmp));
|
|
|
|
if (tmp.s_addr != entry->last.s_addr) {
|
2006-07-21 17:31:28 +00:00
|
|
|
ast_copy_string(iabuf, ast_inet_ntoa(entry->last), sizeof(iabuf));
|
|
|
|
ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
|
2006-06-07 17:44:36 +00:00
|
|
|
ast_log(LOG_NOTICE, "host '%s' changed from %s to %s\n",
|
2006-07-21 17:31:28 +00:00
|
|
|
entry->name, iabuf, iabuf2);
|
2006-06-07 17:44:36 +00:00
|
|
|
memcpy(entry->result, hp->h_addr, sizeof(entry->result));
|
|
|
|
memcpy(&entry->last, hp->h_addr, sizeof(entry->last));
|
|
|
|
changed = entry->changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&entry->lock);
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_dnsmgr_refresh(struct ast_dnsmgr_entry *entry)
|
|
|
|
{
|
|
|
|
return dnsmgr_refresh(entry, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if dnsmgr entry has changed from since last call to this function
|
|
|
|
*/
|
|
|
|
int ast_dnsmgr_changed(struct ast_dnsmgr_entry *entry)
|
|
|
|
{
|
|
|
|
int changed;
|
|
|
|
|
|
|
|
ast_mutex_lock(&entry->lock);
|
|
|
|
|
|
|
|
changed = entry->changed;
|
|
|
|
entry->changed = 0;
|
|
|
|
|
|
|
|
ast_mutex_unlock(&entry->lock);
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2005-04-06 21:13:51 +00:00
|
|
|
static void *do_refresh(void *data)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
pthread_testcancel();
|
2006-10-13 15:56:17 +00:00
|
|
|
usleep((ast_sched_wait(sched)*1000));
|
2005-04-06 21:13:51 +00:00
|
|
|
pthread_testcancel();
|
|
|
|
ast_sched_runq(sched);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-21 14:40:10 +00:00
|
|
|
static int refresh_list(const void *data)
|
2005-04-06 21:13:51 +00:00
|
|
|
{
|
2007-09-21 14:40:10 +00:00
|
|
|
struct refresh_info *info = (struct refresh_info *)data;
|
2005-04-06 21:13:51 +00:00
|
|
|
struct ast_dnsmgr_entry *entry;
|
|
|
|
|
|
|
|
/* if a refresh or reload is already in progress, exit now */
|
|
|
|
if (ast_mutex_trylock(&refresh_lock)) {
|
|
|
|
if (info->verbose)
|
|
|
|
ast_log(LOG_WARNING, "DNS Manager refresh already in progress.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Refreshing DNS lookups.\n");
|
2007-06-18 16:56:06 +00:00
|
|
|
AST_RWLIST_RDLOCK(info->entries);
|
|
|
|
AST_RWLIST_TRAVERSE(info->entries, entry, list) {
|
2005-04-12 14:11:59 +00:00
|
|
|
if (info->regex_present && regexec(&info->filter, entry->name, 0, NULL, 0))
|
2005-04-06 21:13:51 +00:00
|
|
|
continue;
|
|
|
|
|
2006-06-07 17:44:36 +00:00
|
|
|
dnsmgr_refresh(entry, info->verbose);
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
2007-06-18 16:56:06 +00:00
|
|
|
AST_RWLIST_UNLOCK(info->entries);
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
ast_mutex_unlock(&refresh_lock);
|
|
|
|
|
2005-11-08 01:29:14 +00:00
|
|
|
/* automatically reschedule based on the interval */
|
|
|
|
return refresh_interval * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dnsmgr_start_refresh(void)
|
|
|
|
{
|
|
|
|
if (refresh_sched > -1) {
|
|
|
|
ast_sched_del(sched, refresh_sched);
|
2005-11-08 01:32:40 +00:00
|
|
|
refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
|
2005-11-08 01:29:14 +00:00
|
|
|
}
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int do_reload(int loading);
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-04-06 21:13:51 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "dnsmgr reload";
|
|
|
|
e->usage =
|
|
|
|
"Usage: dnsmgr reload\n"
|
|
|
|
" Reloads the DNS manager configuration.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (a->argc > 2)
|
|
|
|
return CLI_SHOWUSAGE;
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
do_reload(0);
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-04-06 21:13:51 +00:00
|
|
|
{
|
|
|
|
struct refresh_info info = {
|
|
|
|
.entries = &entry_list,
|
|
|
|
.verbose = 1,
|
|
|
|
};
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "dnsmgr refresh";
|
|
|
|
e->usage =
|
|
|
|
"Usage: dnsmgr refresh [pattern]\n"
|
|
|
|
" Peforms an immediate refresh of the managed DNS entries.\n"
|
|
|
|
" Optional regular expression pattern is used to filter the entries to refresh.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (a->argc > 3)
|
|
|
|
return CLI_SHOWUSAGE;
|
2005-04-06 21:13:51 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
if (a->argc == 3) {
|
|
|
|
if ( regcomp(&info.filter, a->argv[2], REG_EXTENDED | REG_NOSUB) )
|
|
|
|
return CLI_SHOWUSAGE;
|
2005-04-12 14:11:59 +00:00
|
|
|
else
|
|
|
|
info.regex_present = 1;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh_list(&info);
|
|
|
|
|
2005-04-12 14:11:59 +00:00
|
|
|
if (info.regex_present)
|
2005-04-06 21:13:51 +00:00
|
|
|
regfree(&info.filter);
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-04-06 21:13:51 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
struct ast_dnsmgr_entry *entry;
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "dnsmgr status";
|
|
|
|
e->usage =
|
|
|
|
"Usage: dnsmgr status\n"
|
|
|
|
" Displays the DNS manager status.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-06 21:13:51 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
if (a->argc > 2)
|
|
|
|
return CLI_SHOWUSAGE;
|
2005-04-06 21:13:51 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
|
|
|
|
ast_cli(a->fd, "Refresh Interval: %d seconds\n", refresh_interval);
|
2007-06-18 16:37:14 +00:00
|
|
|
AST_RWLIST_RDLOCK(&entry_list);
|
|
|
|
AST_RWLIST_TRAVERSE(&entry_list, entry, list)
|
2005-04-06 21:13:51 +00:00
|
|
|
count++;
|
2007-06-18 16:37:14 +00:00
|
|
|
AST_RWLIST_UNLOCK(&entry_list);
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Number of entries: %d\n", count);
|
2005-04-06 21:13:51 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 20:05:18 +00:00
|
|
|
static struct ast_cli_entry cli_reload = AST_CLI_DEFINE(handle_cli_reload, "Reloads the DNS manager configuration");
|
|
|
|
static struct ast_cli_entry cli_refresh = AST_CLI_DEFINE(handle_cli_refresh, "Performs an immediate refresh");
|
|
|
|
static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the DNS manager status");
|
2005-04-06 21:13:51 +00:00
|
|
|
|
|
|
|
int dnsmgr_init(void)
|
|
|
|
{
|
2006-02-09 16:59:50 +00:00
|
|
|
if (!(sched = sched_context_create())) {
|
2005-04-06 21:13:51 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to create schedule context.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ast_cli_register(&cli_reload);
|
|
|
|
ast_cli_register(&cli_status);
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli_register(&cli_refresh);
|
2005-04-06 21:13:51 +00:00
|
|
|
return do_reload(1);
|
|
|
|
}
|
|
|
|
|
2006-02-14 23:08:06 +00:00
|
|
|
int dnsmgr_reload(void)
|
2005-04-06 21:13:51 +00:00
|
|
|
{
|
2006-02-14 23:08:06 +00:00
|
|
|
return do_reload(0);
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int do_reload(int loading)
|
|
|
|
{
|
|
|
|
struct ast_config *config;
|
2007-08-16 21:09:46 +00:00
|
|
|
struct ast_flags config_flags = { loading ? 0 : CONFIG_FLAG_FILEUNCHANGED };
|
2005-04-06 21:13:51 +00:00
|
|
|
const char *interval_value;
|
|
|
|
const char *enabled_value;
|
|
|
|
int interval;
|
|
|
|
int was_enabled;
|
|
|
|
int res = -1;
|
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
if ((config = ast_config_load("dnsmgr.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-06 21:13:51 +00:00
|
|
|
/* ensure that no refresh cycles run while the reload is in progress */
|
|
|
|
ast_mutex_lock(&refresh_lock);
|
|
|
|
|
|
|
|
/* reset defaults in preparation for reading config file */
|
|
|
|
refresh_interval = REFRESH_DEFAULT;
|
|
|
|
was_enabled = enabled;
|
|
|
|
enabled = 0;
|
|
|
|
|
|
|
|
if (refresh_sched > -1)
|
|
|
|
ast_sched_del(sched, refresh_sched);
|
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
if (config) {
|
2005-04-12 14:11:59 +00:00
|
|
|
if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
|
2005-04-06 21:13:51 +00:00
|
|
|
enabled = ast_true(enabled_value);
|
|
|
|
}
|
|
|
|
if ((interval_value = ast_variable_retrieve(config, "general", "refreshinterval"))) {
|
|
|
|
if (sscanf(interval_value, "%d", &interval) < 1)
|
|
|
|
ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", interval_value);
|
|
|
|
else if (interval < 0)
|
|
|
|
ast_log(LOG_WARNING, "Invalid refresh interval '%d' specified, using default\n", interval);
|
|
|
|
else
|
|
|
|
refresh_interval = interval;
|
|
|
|
}
|
|
|
|
ast_config_destroy(config);
|
|
|
|
}
|
|
|
|
|
2005-11-08 01:29:14 +00:00
|
|
|
if (enabled && refresh_interval)
|
2005-04-06 21:13:51 +00:00
|
|
|
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 */
|
2006-10-13 15:56:17 +00:00
|
|
|
if (enabled) {
|
|
|
|
if (!was_enabled && (refresh_thread == AST_PTHREADT_NULL)) {
|
|
|
|
if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to start refresh thread.\n");
|
|
|
|
}
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
2006-10-13 15:56:17 +00:00
|
|
|
/* make a background refresh happen right away */
|
|
|
|
refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);
|
|
|
|
res = 0;
|
2005-04-06 21:13:51 +00:00
|
|
|
}
|
|
|
|
/* 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;
|
|
|
|
ast_cli_unregister(&cli_refresh);
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
ast_mutex_unlock(&refresh_lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|