resolve.h File Reference

DNS resolver related functions. More...

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/nameser.h>
#include "ip_addr.h"
#include "proxy.h"

Include dependency graph for resolve.h:

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

Go to the source code of this file.

Data Structures

struct  a_rdata
 A rec. struct. More...
struct  aaaa_rdata
struct  cname_rdata
 cname rec. struct More...
struct  dns_node
 DNS failover related structures. More...
union  dns_query
 query union More...
struct  ebl_rdata
 EBL rec. struct. More...
struct  naptr_rdata
 naptr rec. struct More...
struct  rdata
 rdata struct More...
struct  srv_rdata
 srv rec. struct More...
struct  txt_rdata
 txt rec. struct More...

Defines

#define ANS_SIZE   8192
#define DNS_HDR_SIZE   12
#define get_naptr(_rdata)   ( ((struct naptr_rdata*)(_rdata)->rdata) )
#define get_srv(_rdata)   ( ((struct srv_rdata*)(_rdata)->rdata) )
#define HEX2I(c)
#define MAX_DNS_NAME   256
#define MAX_DNS_STRING   255
#define MAX_QUERY_SIZE   8192
#define rev_resolvehost(ip)   gethostbyaddr((char*)(ip)->u.addr, (ip)->len, (ip)->af);
#define T_EBL   65300
 this is not official yet

Functions

struct dns_nodedns_res_copy (struct dns_node *s)
 make a perfect copy of a resolver state machine
void free_dns_res (struct proxy_l *p)
 free the DNS resolver state machine
void free_rdata_list (struct rdata *head)
 frees completely a struct rdata list
int get_next_su (struct proxy_l *p, union sockaddr_union *su, int add_to_bl)
 taked the next destination from a resolver state machine
struct rdataget_record (char *name, int type)
 Hets the DNS records for name:type.
int resolv_blacklist_init (void)
 Initialize blacklist.
int resolv_init (void)
 Initialize the DNS resolver retr_time - time before retransmitting (must be >0) retr_no - retransmissions number servers_no - how many dns servers will be used (from the one listed in /etc/resolv.conf) search - if 0 the search list in /etc/resolv.conf will be ignored (HINT: even if you don't have a search list in resolv.conf, it's still better to set search to 0, because an empty searchlist means in fact search "" => it takes more time) If any of the parameters <0, the default (system specific) value will be used. See also resolv.conf(5).
static struct hostent * resolvehost (char *name, int no_ip_test)
 gethostbyname wrappers use this, someday they will use a local cache
struct hostent * sip_resolvehost (str *name, unsigned short *port, unsigned short *proto, int is_sips, struct dns_node **dn)
 Resolve SIP hostname to ip address, protocol and port.
static struct ip_addrstr2ip (str *st)
 converts a str to an ipv4 address, returns the address or 0 on error Warning: the result is a pointer to a statically allocated structure
static struct ip_addrstr2ip6 (str *st)
 returns an ip_addr struct.; on error returns 0 the ip_addr struct is static, so subsequent calls will destroy its content

Variables

int dns_try_ipv6


Detailed Description

DNS resolver related functions.

Definition in file resolve.h.


Define Documentation

#define ANS_SIZE   8192

Definition at line 52 of file resolve.h.

Referenced by get_record().

#define DNS_HDR_SIZE   12

Definition at line 53 of file resolve.h.

Referenced by get_record().

#define get_naptr ( _rdata   )     ( ((struct naptr_rdata*)(_rdata)->rdata) )

Definition at line 161 of file resolve.h.

Referenced by filter_and_sort_naptr(), sip_resolvehost(), and srv2dns_node().

#define get_srv ( _rdata   )     ( ((struct srv_rdata*)(_rdata)->rdata) )

Definition at line 164 of file resolve.h.

Referenced by a2dns_node().

#define HEX2I (  ) 

Value:

(  (((c)>='0') && ((c)<='9'))? (c)-'0' :  \
      (((c)>='A') && ((c)<='F'))? ((c)-'A')+10 : \
      (((c)>='a') && ((c)<='f'))? ((c)-'a')+10 : -1 )

Definition at line 155 of file resolve.h.

Referenced by str2ip6().

#define MAX_DNS_NAME   256

#define MAX_DNS_STRING   255

Definition at line 55 of file resolve.h.

#define MAX_QUERY_SIZE   8192

Definition at line 51 of file resolve.h.

#define rev_resolvehost ( ip   )     gethostbyaddr((char*)(ip)->u.addr, (ip)->len, (ip)->af);

Definition at line 150 of file resolve.h.

Referenced by check_via_address(), comp_ip(), and fix_socket_list().

#define T_EBL   65300

this is not official yet

Definition at line 58 of file resolve.h.

Referenced by get_record(), and i_enum_query_2().


Function Documentation

struct dns_node* dns_res_copy ( struct dns_node s  )  [read]

make a perfect copy of a resolver state machine

Definition at line 1310 of file resolve.c.

References dns_node_copy(), dns_node::kids, NULL, and shm_free.

Referenced by shm_clone_proxy().

void free_dns_res ( struct proxy_l p  ) 

free the DNS resolver state machine

Definition at line 1226 of file resolve.c.

References proxy_l::dn, dns_node::kids, NULL, and shm_free.

Referenced by free_proxy(), free_shm_proxy(), get_next_su(), mk_proxy(), and mk_shm_proxy().

void free_rdata_list ( struct rdata head  ) 

int get_next_su ( struct proxy_l p,
union sockaddr_union su,
int  add_to_bl 
)

struct rdata* get_record ( char *  name,
int  type 
) [read]

int resolv_blacklist_init ( void   ) 

Initialize blacklist.

Definition at line 115 of file resolve.c.

References BL_BY_DEFAULT, BL_DO_EXPIRE, create_bl_head(), disable_dns_blacklist, DNS_REVOLVER_BL_ID, DNS_REVOLVER_BL_NAME, LM_ERR, bl_head::name, NULL, and str_init.

Referenced by main().

int resolv_init ( void   ) 

Initialize the DNS resolver retr_time - time before retransmitting (must be >0) retr_no - retransmissions number servers_no - how many dns servers will be used (from the one listed in /etc/resolv.conf) search - if 0 the search list in /etc/resolv.conf will be ignored (HINT: even if you don't have a search list in resolv.conf, it's still better to set search to 0, because an empty searchlist means in fact search "" => it takes more time) If any of the parameters <0, the default (system specific) value will be used. See also resolv.conf(5).

Returns:
0 on success, -1 on error

Definition at line 93 of file resolve.c.

References dns_retr_no, dns_retr_time, dns_search_list, dns_servers_no, and LM_WARN.

Referenced by main().

static struct hostent* resolvehost ( char *  name,
int  no_ip_test 
) [static, read]

gethostbyname wrappers use this, someday they will use a local cache

Definition at line 315 of file resolve.h.

References dns_try_ipv6, ip_addr2he(), _str::len, _str::s, s, str2ip(), and str2ip6().

Referenced by add_dest2list(), comp_ip(), do_srv_lookup(), fix_actions(), fix_socket_list(), get_next_he(), mi_mod_init(), seas_init(), sip_resolvehost(), and start_stats_server().

struct hostent* sip_resolvehost ( str name,
unsigned short *  port,
unsigned short *  proto,
int  is_sips,
struct dns_node **  dn 
) [read]

Resolve SIP hostname to ip address, protocol and port.

Resolve SIP hostname to ip address, protocol and port if necessary. If no port is given, it will be resolved with SRV, if additional no protocol is given, then it will be resolved with NAPTR. This function fallback from NAPTR to SRV and then to A record lookup, if no valid records could be found. If the NAPTR lookup fails, it will use the TLS (for SIPS) or UDP protocol, if the SRV lookup fails, it will use the default port for SIP or SIPS. If the hostname is already an IP address, it will also use the default port and protocol.

Parameters:
name hostname
port port, set to 0 if you want to resolve it
proto SIP protocol, set to PROTO_NONE if you want to resolve it
is_sips set to true for SIPS
dn DNS node
Returns:
host IP address, or zero on errors

Definition at line 978 of file resolve.c.

References do_srv_lookup(), filter_and_sort_naptr(), free_rdata_list(), get_naptr, get_naptr_proto(), get_record(), ip_addr2he(), _str::len, LM_DBG, LM_ERR, LM_WARN, MAX_DNS_NAME, rdata::next, NULL, PROTO_NONE, PROTO_SCTP, PROTO_TCP, PROTO_TLS, PROTO_UDP, resolvehost(), _str::s, shm_free, SIP_PORT, SIPS_PORT, srv2dns_node(), SRV_MAX_PREFIX_LEN, SRV_SCTP_PREFIX, SRV_SCTP_PREFIX_LEN, SRV_TCP_PREFIX, SRV_TCP_PREFIX_LEN, SRV_TLS_PREFIX, SRV_TLS_PREFIX_LEN, SRV_UDP_PREFIX, SRV_UDP_PREFIX_LEN, str2ip(), and str2ip6().

Referenced by check_via_address(), get_natping_socket(), is_from_user_enum_2(), mk_proxy(), mk_shm_proxy(), nh_timer(), and update_sock_struct_from_via().

static struct ip_addr* str2ip ( str st  )  [static, read]

converts a str to an ipv4 address, returns the address or 0 on error Warning: the result is a pointer to a statically allocated structure

Definition at line 171 of file resolve.h.

References ip_addr::addr, ip_addr::addr32, ip_addr::af, ip_addr::len, _str::len, LM_DBG, _str::s, s, and ip_addr::u.

Referenced by allow_address(), do_from_gw(), do_to_gw(), pike_check_req(), resolvehost(), rfc1918address(), and sip_resolvehost().

static struct ip_addr* str2ip6 ( str st  )  [static, read]

returns an ip_addr struct.; on error returns 0 the ip_addr struct is static, so subsequent calls will destroy its content

Definition at line 216 of file resolve.h.

References ip_addr::addr, ip_addr::addr16, ip_addr::af, hex, HEX2I, ip_addr::len, _str::len, LM_DBG, _str::s, s, and ip_addr::u.

Referenced by grep_sock_info(), resolvehost(), and sip_resolvehost().


Variable Documentation

default off

Definition at line 66 of file resolve.c.

Referenced by resolvehost().


Generated on Thu May 24 10:00:42 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6