dnsmgr.h File Reference

Background DNS update manager. More...

#include "asterisk/netsock2.h"
#include "asterisk/srv.h"

Include dependency graph for dnsmgr.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* dns_update_func )(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data)

Functions

int ast_dnsmgr_changed (struct ast_dnsmgr_entry *entry)
 Check is see if a dnsmgr entry has changed.
struct ast_dnsmgr_entryast_dnsmgr_get (const char *name, struct ast_sockaddr *result, const char *service)
 Allocate a new DNS manager entry.
struct ast_dnsmgr_entryast_dnsmgr_get_family (const char *name, struct ast_sockaddr *result, const char *service, unsigned int family)
 Allocate a new DNS manager entry.
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.
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.
int ast_dnsmgr_refresh (struct ast_dnsmgr_entry *entry)
 Force a refresh of a dnsmgr entry.
void ast_dnsmgr_release (struct ast_dnsmgr_entry *entry)
 Free a DNS manager entry.


Detailed Description

Background DNS update manager.

Definition in file dnsmgr.h.


Typedef Documentation

typedef void(* dns_update_func)(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data)

Definition at line 40 of file dnsmgr.h.


Function Documentation

int ast_dnsmgr_changed ( struct ast_dnsmgr_entry entry  ) 

Check is see if a dnsmgr entry has changed.

Return values:
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 248 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().

00249 {
00250    int changed;
00251 
00252    ast_mutex_lock(&entry->lock);
00253 
00254    changed = entry->changed;
00255    entry->changed = 0;
00256 
00257    ast_mutex_unlock(&entry->lock);
00258 
00259    return changed;
00260 }

struct ast_dnsmgr_entry* ast_dnsmgr_get ( const char *  name,
struct ast_sockaddr result,
const char *  service 
) [read]

Allocate a new DNS manager entry.

Parameters:
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.

Returns:
a DNS manager entry
Version:
1.6.1 result changed from struct in_addr to struct sockaddr_in to store port number

1.8.0 result changed from struct ast_sockaddr_in to ast_sockaddr for IPv6 support

Definition at line 132 of file dnsmgr.c.

References ast_dnsmgr_get_family().

00133 {
00134    return ast_dnsmgr_get_family(name, result, service, 0);
00135 }

struct ast_dnsmgr_entry* ast_dnsmgr_get_family ( const char *  name,
struct ast_sockaddr result,
const char *  service,
unsigned int  family 
) [read]

Allocate a new DNS manager entry.

Parameters:
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.

Returns:
a DNS manager entry

Definition at line 107 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::name, NULL, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_get(), and internal_dnsmgr_lookup().

00108 {
00109    struct ast_dnsmgr_entry *entry;
00110    int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
00111 
00112    if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size))) {
00113       return NULL;
00114    }
00115 
00116    entry->result = result;
00117    ast_mutex_init(&entry->lock);
00118    strcpy(entry->name, name);
00119    if (service) {
00120       entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
00121       strcpy(entry->service, service);
00122    }
00123    entry->family = family;
00124 
00125    AST_RWLIST_WRLOCK(&entry_list);
00126    AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
00127    AST_RWLIST_UNLOCK(&entry_list);
00128 
00129    return entry;
00130 }

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.

Parameters:
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 
Note:
This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function _does_ force an initial lookup, so it may block for some period of time.
Return values:
0 success
non-zero failure
Version:
1.6.1 result changed from struct in_addr to struct aockaddr_in to store port number

Definition at line 192 of file dnsmgr.c.

References internal_dnsmgr_lookup(), and NULL.

Referenced by __iax2_do_register_s(), build_peer(), iax2_append_register(), and transport_apply().

00193 {
00194    return internal_dnsmgr_lookup(name, result, dnsmgr, service, NULL, NULL);
00195 }

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.

Parameters:
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
Note:
This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function _does_ force an initial lookup, so it may block for some period of time.
Return values:
0 success
non-zero failure

Definition at line 197 of file dnsmgr.c.

References internal_dnsmgr_lookup().

Referenced by __sip_subscribe_mwi_do(), build_peer(), and transmit_register().

00198 {
00199    return internal_dnsmgr_lookup(name, result, dnsmgr, service, func, data);
00200 }

int ast_dnsmgr_refresh ( struct ast_dnsmgr_entry entry  ) 

Force a refresh of a dnsmgr entry.

Return values:
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 240 of file dnsmgr.c.

References dnsmgr_refresh().

Referenced by build_peer(), iax2_do_register(), and sip_reg_timeout().

00241 {
00242    return dnsmgr_refresh(entry, 0);
00243 }

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry  ) 

Free a DNS manager entry.

Parameters:
entry the DNS manager entry to free
Returns:
nothing

Definition at line 137 of file dnsmgr.c.

References ast_debug, ast_free, ast_mutex_destroy, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_dnsmgr_entry::lock, and ast_dnsmgr_entry::name.

Referenced by cleanup_registration(), delete_users(), match_and_cleanup_peer_sched(), peer_destructor(), transport_destroy(), and unload_module().

00138 {
00139    if (!entry) {
00140       return;
00141    }
00142 
00143    AST_RWLIST_WRLOCK(&entry_list);
00144    AST_RWLIST_REMOVE(&entry_list, entry, list);
00145    AST_RWLIST_UNLOCK(&entry_list);
00146    ast_debug(6, "removing dns manager for '%s'\n", entry->name);
00147 
00148    ast_mutex_destroy(&entry->lock);
00149    ast_free(entry);
00150 }


Generated on Thu Apr 16 06:30:46 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6