Mon Mar 12 2012 21:38:50

Asterisk developer's documentation


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.

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


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

{
   int changed;

   ast_mutex_lock(&entry->lock);

   changed = entry->changed;
   entry->changed = 0;

   ast_mutex_unlock(&entry->lock);
   
   return changed;
}
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:
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 113 of file dnsmgr.c.

References ast_dnsmgr_get_family().

{
   return ast_dnsmgr_get_family(name, result, service, 0);
}
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:
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 88 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::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_get(), and ast_dnsmgr_lookup().

{
   struct ast_dnsmgr_entry *entry;
   int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);

   if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size))) {
      return NULL;
   }

   entry->result = result;
   ast_mutex_init(&entry->lock);
   strcpy(entry->name, name);
   if (service) {
      entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
      strcpy(entry->service, service);
   }
   entry->family = family;

   AST_RWLIST_WRLOCK(&entry_list);
   AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
   AST_RWLIST_UNLOCK(&entry_list);

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

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 132 of file dnsmgr.c.

References ast_dnsmgr_get_family(), ast_get_ip_or_srv(), ast_sockaddr_parse(), ast_strlen_zero(), ast_verb, enabled, ast_dnsmgr_entry::family, PARSE_PORT_FORBID, and ast_sockaddr::ss.

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

{
   unsigned int family;

   if (ast_strlen_zero(name) || !result || !dnsmgr) {
      return -1;
   }

   if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name)) {
      return 0;
   }

   /* Lookup address family filter. */
   family = result->ss.ss_family;

   /*
    * If it's actually an IP address and not a name, there's no
    * need for a managed lookup.
    */
   if (ast_sockaddr_parse(result, name, PARSE_PORT_FORBID)) {
      return 0;
   }

   ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);

   /* do a lookup now but add a manager so it will automagically get updated in the background */
   ast_get_ip_or_srv(result, name, service);
   
   /* if dnsmgr is not enable don't bother adding an entry */
   if (!enabled) {
      return 0;
   }
   
   ast_verb(3, "adding dns manager for '%s'\n", name);
   *dnsmgr = ast_dnsmgr_get_family(name, result, service, family);
   return !*dnsmgr;
}
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 207 of file dnsmgr.c.

References dnsmgr_refresh().

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

{
   return dnsmgr_refresh(entry, 0);
}
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 118 of file dnsmgr.c.

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

Referenced by delete_users(), peer_destructor(), sip_destroy_peer(), sip_registry_destroy(), and sip_subscribe_mwi_destroy().

{
   if (!entry)
      return;

   AST_RWLIST_WRLOCK(&entry_list);
   AST_RWLIST_REMOVE(&entry_list, entry, list);
   AST_RWLIST_UNLOCK(&entry_list);
   ast_verb(4, "removing dns manager for '%s'\n", entry->name);

   ast_mutex_destroy(&entry->lock);
   ast_free(entry);
}