Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Background DNS update manager. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include <regex.h>
#include <signal.h>
#include "asterisk/module.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 | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
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... | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static int | dnsmgr_refresh (struct ast_dnsmgr_entry *entry, int verbose) |
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 | load_module (void) |
static int | refresh_list (const void *data) |
static int | reload_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "DNS Manager" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig", } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_refresh = { .handler = handle_cli_refresh , .summary = "Performs an immediate refresh" ,} |
static struct ast_cli_entry | cli_reload = { .handler = handle_cli_reload , .summary = "Reloads the DNS manager configuration" ,} |
static struct ast_cli_entry | cli_status = { .handler = handle_cli_status , .summary = "Display the DNS manager status" ,} |
static int | enabled |
static struct entry_list | entry_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
static struct refresh_info | master_refresh_info |
static int | refresh_interval |
static ast_mutex_t | refresh_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
static int | refresh_sched = -1 |
static pthread_t | refresh_thread = AST_PTHREADT_NULL |
static struct ast_sched_context * | sched |
Background DNS update manager.
Definition in file dnsmgr.c.
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 247 of file dnsmgr.c.
References ast_mutex_lock, and ast_mutex_unlock.
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 131 of file dnsmgr.c.
References ast_dnsmgr_get_family(), name, result, and service.
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 106 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, name, NULL, result, and 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 191 of file dnsmgr.c.
References internal_dnsmgr_lookup(), name, NULL, result, and service.
Referenced by __iax2_do_register_s(), build_peer(), iax2_append_register(), and transport_apply().
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 196 of file dnsmgr.c.
References ast_dnsmgr_entry::data, internal_dnsmgr_lookup(), name, result, and service.
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 239 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by build_peer(), and iax2_do_register().
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Free a DNS manager entry.
entry | the DNS manager entry to free |
Definition at line 136 of file dnsmgr.c.
References ast_debug, ast_free, ast_mutex_destroy, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by delete_users(), destroy_sip_transport_state(), and peer_destructor().
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
|
static |
Definition at line 204 of file dnsmgr.c.
References ast_debug, ast_get_ip_or_srv_with_preference(), 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, entry::data, LOG_NOTICE, and tmp().
Referenced by ast_dnsmgr_refresh(), and refresh_list().
void dnsmgr_start_refresh | ( | void | ) |
Provided by dnsmgr.c
Definition at line 302 of file dnsmgr.c.
References ast_sched_add_variable(), AST_SCHED_DEL, master_refresh_info, refresh_list(), and refresh_sched.
Referenced by asterisk_daemon().
|
static |
Definition at line 261 of file dnsmgr.c.
References ast_sched_runq(), ast_sched_wait(), and NULL.
Referenced by do_reload().
|
static |
Definition at line 450 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_browse(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, do_refresh(), enabled, LOG_ERROR, LOG_NOTICE, LOG_WARNING, master_refresh_info, ast_variable::name, ast_variable::next, NULL, REFRESH_DEFAULT, refresh_interval, refresh_list(), refresh_lock, refresh_sched, refresh_thread, and ast_variable::value.
Referenced by handle_cli_reload(), load_module(), and reload_module().
|
static |
Definition at line 332 of file dnsmgr.c.
References a, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, entry_list, sip_to_pjsip::info(), NULL, refresh_list(), and ast_cli_entry::usage.
|
static |
Definition at line 312 of file dnsmgr.c.
References a, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, do_reload(), NULL, and ast_cli_entry::usage.
|
static |
Definition at line 376 of file dnsmgr.c.
References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, NULL, refresh_interval, and ast_cli_entry::usage.
|
static |
Definition at line 151 of file dnsmgr.c.
References ast_debug, ast_dnsmgr_get_family(), ast_get_ip_or_srv(), ast_sockaddr_parse(), ast_strlen_zero(), ast_dnsmgr_entry::data, enabled, ast_dnsmgr_entry::family, name, PARSE_PORT_FORBID, result, and service.
Referenced by ast_dnsmgr_lookup(), and ast_dnsmgr_lookup_cb().
|
static |
Definition at line 432 of file dnsmgr.c.
References ast_cli_register, ast_log, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_sched_context_create(), cli_refresh, cli_reload, cli_status, do_reload(), and LOG_ERROR.
|
static |
Definition at line 272 of file dnsmgr.c.
References ast_debug, ast_log, ast_mutex_trylock, ast_mutex_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, dnsmgr_refresh(), sip_to_pjsip::info(), LOG_WARNING, NULL, refresh_interval, and refresh_lock.
Referenced by dnsmgr_start_refresh(), do_reload(), and handle_cli_refresh().
|
static |
|
static |
Definition at line 410 of file dnsmgr.c.
References ast_cli_unregister(), ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, ast_sched_context_destroy(), cli_refresh, cli_reload, cli_status, NULL, refresh_lock, and refresh_thread.
|
static |
|
static |
|
static |
Definition at line 407 of file dnsmgr.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 406 of file dnsmgr.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 408 of file dnsmgr.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 91 of file dnsmgr.c.
Referenced by __ast_http_load(), ast_ari_config_init(), ast_cel_check_enabled(), ast_context_set_autohints(), callid_group_set_filter(), do_reload(), func_channel_write_real(), handle_cli_refresh(), handle_cli_status(), handle_logger_chanloggroup_filter(), internal_dnsmgr_lookup(), load_module(), load_odbc_config(), and process_config().
|
static |
Referenced by handle_cli_refresh().
|
static |
Definition at line 101 of file dnsmgr.c.
Referenced by dnsmgr_start_refresh(), and do_reload().
|
static |
Definition at line 92 of file dnsmgr.c.
Referenced by do_reload(), handle_cli_status(), and refresh_list().
|
static |
Definition at line 87 of file dnsmgr.c.
Referenced by do_reload(), refresh_list(), and unload_module().
|
static |
Definition at line 63 of file dnsmgr.c.
Referenced by dnsmgr_start_refresh(), and do_reload().
|
static |
Definition at line 64 of file dnsmgr.c.
Referenced by do_reload(), and unload_module().
|
static |