Asterisk - The Open Source Telephony Project GIT-master-7e7a603
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.

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}
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
Definition: search.h:40

References ast_mutex_lock, and ast_mutex_unlock.

Referenced by iax2_do_register().

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

132{
134}
enum ast_cc_service_type service
Definition: ccss.c:383
static PGresult * result
Definition: cel_pgsql.c:84
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
static const char name[]
Definition: format_mp3.c:68

References ast_dnsmgr_get_family(), name, result, and service.

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

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
127
128 return entry;
129}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
#define ast_mutex_init(pmutex)
Definition: lock.h:186
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Definition: dnsmgr.c:66
unsigned int family
Definition: dnsmgr.c:72

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().

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

192{
194}
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

References internal_dnsmgr_lookup(), name, NULL, result, and service.

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

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

197{
198 return internal_dnsmgr_lookup(name, result, dnsmgr, service, func, data);
199}

References ast_dnsmgr_entry::data, internal_dnsmgr_lookup(), name, result, and service.

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

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

References dnsmgr_refresh().

Referenced by build_peer(), and iax2_do_register().

◆ ast_dnsmgr_release()

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry)

Free a DNS manager entry.

Parameters
entrythe DNS manager entry to free

Definition at line 136 of file dnsmgr.c.

137{
138 if (!entry) {
139 return;
140 }
141
145 ast_debug(6, "removing dns manager for '%s'\n", entry->name);
146
147 ast_mutex_destroy(&entry->lock);
149}
#define ast_free(a)
Definition: astmm.h:180
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
#define ast_mutex_destroy(a)
Definition: lock.h:188

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().