Asterisk - The Open Source Telephony Project  18.5.0
Typedefs | Functions
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. More...
 
struct ast_dnsmgr_entryast_dnsmgr_get (const char *name, struct ast_sockaddr *result, const char *service)
 Allocate a new DNS manager entry. More...
 
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. 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...
 

Detailed Description

Background DNS update manager.

Definition in file dnsmgr.h.

Typedef Documentation

◆ dns_update_func

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

◆ ast_dnsmgr_changed()

int ast_dnsmgr_changed ( struct ast_dnsmgr_entry entry)

Check is see if a dnsmgr entry has changed.

Return values
non-zeroif the dnsmgr entry has changed since the last call to this function
zeroif 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, ast_mutex_unlock, ast_dnsmgr_entry::changed, and ast_dnsmgr_entry::lock.

Referenced by iax2_do_register().

248 {
249  int changed;
250 
251  ast_mutex_lock(&entry->lock);
252 
253  changed = entry->changed;
254  entry->changed = 0;
255 
256  ast_mutex_unlock(&entry->lock);
257 
258  return changed;
259 }
ast_mutex_t lock
Definition: dnsmgr.c:79
#define ast_mutex_lock(a)
Definition: lock.h:187
unsigned int changed
Definition: dnsmgr.c:74
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ ast_dnsmgr_get()

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

Allocate a new DNS manager entry.

Parameters
namethe hostname
resultwhere 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 131 of file dnsmgr.c.

References ast_dnsmgr_get_family().

132 {
133  return ast_dnsmgr_get_family(name, result, service, 0);
134 }
enum ast_cc_service_type service
Definition: chan_sip.c:949
static const char name[]
Definition: cdr_mysql.c:74
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.
Definition: dnsmgr.c:106

◆ 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.

Parameters
namethe hostname
resultwhere the DNS manager should store the IP address as it refreshes it.
service
familyAddress 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 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, ast_dnsmgr_entry::lock, NULL, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_get(), and internal_dnsmgr_lookup().

107 {
108  struct ast_dnsmgr_entry *entry;
109  int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
110 
111  if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size))) {
112  return NULL;
113  }
114 
115  entry->result = result;
116  ast_mutex_init(&entry->lock);
117  strcpy(entry->name, name);
118  if (service) {
119  entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
120  strcpy(entry->service, service);
121  }
122  entry->family = family;
123 
125  AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
127 
128  return entry;
129 }
ast_mutex_t lock
Definition: dnsmgr.c:79
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
enum ast_cc_service_type service
Definition: chan_sip.c:949
Definition: dnsmgr.c:66
#define NULL
Definition: resample.c:96
unsigned int family
Definition: dnsmgr.c:72
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
struct ast_sockaddr * result
Definition: dnsmgr.c:68
static const char name[]
Definition: cdr_mysql.c:74
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static PGresult * result
Definition: cel_pgsql.c:88
Definition: search.h:40
#define ast_mutex_init(pmutex)
Definition: lock.h:184
char * service
Definition: dnsmgr.c:70

◆ ast_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.

Parameters
namethe hostname
resultwhere 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.
dnsmgrWhere 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
0success
non-zerofailure
Version
1.6.1 result changed from struct in_addr to struct aockaddr_in to store port number

Definition at line 191 of file dnsmgr.c.

References internal_dnsmgr_lookup(), and NULL.

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

192 {
193  return internal_dnsmgr_lookup(name, result, dnsmgr, service, NULL, NULL);
194 }
enum ast_cc_service_type service
Definition: chan_sip.c:949
#define NULL
Definition: resample.c:96
static const char name[]
Definition: cdr_mysql.c:74
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)
Definition: dnsmgr.c:151

◆ ast_dnsmgr_lookup_cb()

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
namethe hostname
resultThe 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.
dnsmgrWhere to store the allocate DNS manager entry
service
funcThe 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
dataA 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
0success
non-zerofailure

Definition at line 196 of file dnsmgr.c.

References internal_dnsmgr_lookup().

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

197 {
198  return internal_dnsmgr_lookup(name, result, dnsmgr, service, func, data);
199 }
enum ast_cc_service_type service
Definition: chan_sip.c:949
void * data
Definition: dnsmgr.c:76
static const char name[]
Definition: cdr_mysql.c:74
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)
Definition: dnsmgr.c:151

◆ ast_dnsmgr_refresh()

int ast_dnsmgr_refresh ( struct ast_dnsmgr_entry entry)

Force a refresh of a dnsmgr entry.

Return values
non-zeroif the result is different than the previous result
zeroif the result is the same as the previous result

Definition at line 239 of file dnsmgr.c.

References dnsmgr_refresh().

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

240 {
241  return dnsmgr_refresh(entry, 0);
242 }
static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
Definition: dnsmgr.c:204

◆ ast_dnsmgr_release()

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry)

Free a DNS manager entry.

Parameters
entrythe DNS manager entry to free
Returns
nothing

Definition at line 136 of file dnsmgr.c.

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

Referenced by __cleanup_registration(), __shutdown_mwi_subscription(), delete_users(), destroy_sip_transport_state(), match_and_cleanup_peer_sched(), and peer_destructor().

137 {
138  if (!entry) {
139  return;
140  }
141 
143  AST_RWLIST_REMOVE(&entry_list, entry, list);
145  ast_debug(6, "removing dns manager for '%s'\n", entry->name);
146 
147  ast_mutex_destroy(&entry->lock);
148  ast_free(entry);
149 }
ast_mutex_t lock
Definition: dnsmgr.c:79
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_free(a)
Definition: astmm.h:182
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
#define ast_mutex_destroy(a)
Definition: lock.h:186