Background DNS update manager. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include <regex.h>
#include <signal.h>
#include "asterisk/dnsmgr.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
#include "asterisk/config.h"
#include "asterisk/sched.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/acl.h"
Go to the source code of this file.
Data Structures | |
struct | ast_dnsmgr_entry |
struct | entry_list |
struct | refresh_info |
Macros | |
#define | REFRESH_DEFAULT 300 |
Functions | |
int | ast_dnsmgr_changed (struct ast_dnsmgr_entry *entry) |
Check is see if a dnsmgr entry has changed. More... | |
struct ast_dnsmgr_entry * | ast_dnsmgr_get (const char *name, struct ast_sockaddr *result, const char *service) |
Allocate a new DNS manager entry. More... | |
struct ast_dnsmgr_entry * | ast_dnsmgr_get_family (const char *name, struct ast_sockaddr *result, const char *service, unsigned int family) |
Allocate a new DNS manager entry. More... | |
int | ast_dnsmgr_lookup (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service) |
Allocate and initialize a DNS manager entry. More... | |
int | ast_dnsmgr_lookup_cb (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data) |
Allocate and initialize a DNS manager entry, with update callback. More... | |
int | ast_dnsmgr_refresh (struct ast_dnsmgr_entry *entry) |
Force a refresh of a dnsmgr entry. More... | |
void | ast_dnsmgr_release (struct ast_dnsmgr_entry *entry) |
Free a DNS manager entry. More... | |
int | dnsmgr_init (void) |
static int | dnsmgr_refresh (struct ast_dnsmgr_entry *entry, int verbose) |
int | dnsmgr_reload (void) |
static void | dnsmgr_shutdown (void) |
void | dnsmgr_start_refresh (void) |
static void * | do_refresh (void *data) |
static int | do_reload (int loading) |
static char * | handle_cli_refresh (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | internal_dnsmgr_lookup (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data) |
static int | refresh_list (const void *data) |
Variables | |
static struct ast_cli_entry | cli_refresh = AST_CLI_DEFINE(handle_cli_refresh, "Performs an immediate refresh") |
static struct ast_cli_entry | cli_reload = AST_CLI_DEFINE(handle_cli_reload, "Reloads the DNS manager configuration") |
static struct ast_cli_entry | cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the DNS manager status") |
static int | enabled |
static struct entry_list | entry_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 } , } |
static struct refresh_info | master_refresh_info |
static int | refresh_interval |
static ast_mutex_t | refresh_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
static int | refresh_sched = -1 |
static pthread_t | refresh_thread = AST_PTHREADT_NULL |
static struct sched_context * | sched |
Background DNS update manager.
Definition in file dnsmgr.c.
#define REFRESH_DEFAULT 300 |
Definition at line 79 of file dnsmgr.c.
Referenced by do_reload().
int ast_dnsmgr_changed | ( | struct ast_dnsmgr_entry * | entry | ) |
Check is see if a dnsmgr entry has changed.
non-zero | if the dnsmgr entry has changed since the last call to this function |
zero | if the dnsmgr entry has not changed since the last call to this function |
Definition at line 238 of file dnsmgr.c.
References ast_mutex_lock, ast_mutex_unlock, ast_dnsmgr_entry::changed, and ast_dnsmgr_entry::lock.
Referenced by iax2_do_register().
struct ast_dnsmgr_entry* ast_dnsmgr_get | ( | const char * | name, |
struct ast_sockaddr * | result, | ||
const char * | service | ||
) |
Allocate a new DNS manager entry.
name | the hostname |
result | where the DNS manager should store the IP address as it refreshes it. |
service |
This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function does not force an initial lookup of the IP address. So, generally, this should be used when the initial address is already known.
Definition at line 121 of file dnsmgr.c.
References ast_dnsmgr_get_family().
struct ast_dnsmgr_entry* ast_dnsmgr_get_family | ( | const char * | name, |
struct ast_sockaddr * | result, | ||
const char * | service, | ||
unsigned int | family | ||
) |
Allocate a new DNS manager entry.
name | the hostname |
result | where the DNS manager should store the IP address as it refreshes it. |
service | |
family | Address family to filter DNS addresses. |
This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function does not force an initial lookup of the IP address. So, generally, this should be used when the initial address is already known.
Definition at line 96 of file dnsmgr.c.
References ast_calloc, ast_mutex_init, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_dnsmgr_entry::family, ast_dnsmgr_entry::lock, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.
Referenced by ast_dnsmgr_get(), and internal_dnsmgr_lookup().
int ast_dnsmgr_lookup | ( | const char * | name, |
struct ast_sockaddr * | result, | ||
struct ast_dnsmgr_entry ** | dnsmgr, | ||
const char * | service | ||
) |
Allocate and initialize a DNS manager entry.
name | the hostname |
result | where to store the IP address as the DNS manager refreshes it. The address family is used as an input parameter to filter the returned addresses. If it is 0, both IPv4 and IPv6 addresses can be returned. |
dnsmgr | Where to store the allocate DNS manager entry |
service |
0 | success |
non-zero | failure |
Definition at line 180 of file dnsmgr.c.
References internal_dnsmgr_lookup().
Referenced by build_peer(), and iax2_append_register().
int ast_dnsmgr_lookup_cb | ( | const char * | name, |
struct ast_sockaddr * | result, | ||
struct ast_dnsmgr_entry ** | dnsmgr, | ||
const char * | service, | ||
dns_update_func | func, | ||
void * | data | ||
) |
Allocate and initialize a DNS manager entry, with update callback.
name | the hostname |
result | The addr which is intended to be updated in the update callback when DNS manager calls it on refresh. The address family is used as an input parameter to filter the returned addresses. If it is 0, both IPv4 and IPv6 addresses can be returned. |
dnsmgr | Where to store the allocate DNS manager entry |
service | |
func | The update callback function The update callback will be called when DNS manager detects that an IP address has been changed. Instead of updating the addr itself, DNS manager will call this callback function with the old and new addresses. It is the responsibility of the callback to perform any updates |
data | A pointer to data that will be passed through to the callback function |
0 | success |
non-zero | failure |
Definition at line 185 of file dnsmgr.c.
References internal_dnsmgr_lookup().
Referenced by __sip_subscribe_mwi_do(), build_peer(), and transmit_register().
int ast_dnsmgr_refresh | ( | struct ast_dnsmgr_entry * | entry | ) |
Force a refresh of a dnsmgr entry.
non-zero | if the result is different than the previous result |
zero | if the result is the same as the previous result |
Definition at line 230 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by build_peer(), iax2_do_register(), and sip_reg_timeout().
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Free a DNS manager entry.
entry | the DNS manager entry to free |
Definition at line 126 of file dnsmgr.c.
References ast_free, ast_mutex_destroy, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and ast_dnsmgr_entry::lock.
Referenced by cleanup_all_regs(), delete_users(), match_and_cleanup_peer_sched(), peer_destructor(), and unload_module().
int dnsmgr_init | ( | void | ) |
Provided by dnsmgr.c
Definition at line 417 of file dnsmgr.c.
References ast_cli_register(), ast_log(), ast_register_atexit(), cli_refresh, cli_reload, cli_status, dnsmgr_shutdown(), do_reload(), LOG_ERROR, and sched_context_create().
Referenced by main().
|
static |
Definition at line 193 of file dnsmgr.c.
References ast_get_ip_or_srv(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_strdupa, ast_verb, ast_dnsmgr_entry::changed, ast_dnsmgr_entry::data, ast_dnsmgr_entry::family, ast_sockaddr::len, ast_dnsmgr_entry::lock, LOG_NOTICE, ast_dnsmgr_entry::result, ast_dnsmgr_entry::service, ast_sockaddr::ss, and ast_dnsmgr_entry::update_func.
Referenced by ast_dnsmgr_refresh(), and refresh_list().
int dnsmgr_reload | ( | void | ) |
|
static |
Definition at line 397 of file dnsmgr.c.
References ast_cli_unregister(), ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, cli_refresh, cli_reload, cli_status, and sched_context_destroy().
Referenced by dnsmgr_init().
void dnsmgr_start_refresh | ( | void | ) |
Provided by dnsmgr.c
Definition at line 291 of file dnsmgr.c.
References ast_sched_add_variable(), AST_SCHED_DEL, master_refresh_info, and refresh_list().
Referenced by main().
|
static |
Definition at line 252 of file dnsmgr.c.
References ast_sched_runq(), and ast_sched_wait().
Referenced by do_reload().
|
static |
Definition at line 437 of file dnsmgr.c.
References ast_config_destroy(), ast_config_load2(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_pthread_create_background, AST_PTHREADT_NULL, ast_sched_add_variable(), AST_SCHED_DEL, ast_true(), ast_variable_retrieve(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, do_refresh(), enabled, EVENT_FLAG_SYSTEM, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, master_refresh_info, REFRESH_DEFAULT, refresh_interval, and refresh_list().
Referenced by dnsmgr_init(), dnsmgr_reload(), and handle_cli_reload().
|
static |
Definition at line 320 of file dnsmgr.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, refresh_info::entries, entry_list, ast_cli_args::fd, refresh_info::filter, refresh_list(), refresh_info::regex_present, and ast_cli_entry::usage.
|
static |
Definition at line 301 of file dnsmgr.c.
References ast_cli_args::argc, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, do_reload(), and ast_cli_entry::usage.
|
static |
Definition at line 364 of file dnsmgr.c.
References ast_cli_args::argc, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, ast_cli_args::fd, refresh_interval, and ast_cli_entry::usage.
|
static |
Definition at line 140 of file dnsmgr.c.
References ast_dnsmgr_get_family(), ast_get_ip_or_srv(), ast_sockaddr_parse(), ast_strlen_zero(), ast_verb, ast_dnsmgr_entry::data, enabled, ast_dnsmgr_entry::family, PARSE_PORT_FORBID, and ast_sockaddr::ss.
Referenced by ast_dnsmgr_lookup(), and ast_dnsmgr_lookup_cb().
|
static |
Definition at line 263 of file dnsmgr.c.
References ast_log(), ast_mutex_trylock, ast_mutex_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_verb, dnsmgr_refresh(), refresh_info::entries, refresh_info::filter, LOG_WARNING, refresh_interval, refresh_info::regex_present, and refresh_info::verbose.
Referenced by dnsmgr_start_refresh(), do_reload(), and handle_cli_refresh().
|
static |
Definition at line 394 of file dnsmgr.c.
Referenced by dnsmgr_init(), and dnsmgr_shutdown().
|
static |
Definition at line 393 of file dnsmgr.c.
Referenced by dnsmgr_init(), and dnsmgr_shutdown().
|
static |
Definition at line 395 of file dnsmgr.c.
Referenced by dnsmgr_init(), and dnsmgr_shutdown().
|
static |
Referenced by handle_cli_refresh().
|
static |
Definition at line 91 of file dnsmgr.c.
Referenced by dnsmgr_start_refresh(), and do_reload().
|
static |
Definition at line 82 of file dnsmgr.c.
Referenced by do_reload(), handle_cli_status(), and refresh_list().
|
static |
|
static |
|
static |