Asterisk - The Open Source Telephony Project  21.4.1
Typedefs | Functions
dnsmgr.h File Reference

Background DNS update manager. More...

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

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.

Function Documentation

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_dnsmgr_entry::changed.

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 }
unsigned int changed
Definition: dnsmgr.c:74
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 }
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
char * service
Definition: dnsmgr.c:70
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_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_dnsmgr_entry::family, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_get().

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 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
Definition: dnsmgr.c:66
unsigned int family
Definition: dnsmgr.c:72
struct ast_sockaddr * result
Definition: dnsmgr.c:68
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
char * service
Definition: dnsmgr.c:70
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.

Referenced by build_peer().

192 {
193  return internal_dnsmgr_lookup(name, result, dnsmgr, service, NULL, NULL);
194 }
char * service
Definition: dnsmgr.c:70
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 }
void * data
Definition: dnsmgr.c:76
char * service
Definition: dnsmgr.c:70
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.

Referenced by build_peer().

240 {
241  return dnsmgr_refresh(entry, 0);
242 }
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.

References ast_debug, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

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 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151