SIP-router core :: resolver/dns related functions, dns cache and failoverModule: SIP-router core.
More...
#include "str.h"
#include "config.h"
#include "timer.h"
#include "ip_addr.h"
#include "atomic_ops.h"
#include "resolve.h"
Go to the source code of this file.
Data Structures
Defines
-
#define DNS_SRV_LB
- uncomment the define below for SRV weight based load balancing
|
|
- #define DNS_FLAG_BAD_NAME 1
- dns entry flags, shall be on the power of 2
-
#define DNS_FLAG_PERMANENT 2
- permanent record, never times out, never deleted, never overwritten unless explicitely requested
|
|
-
#define DNS_NO_FLAGS 0
-
#define DNS_IPV4_ONLY 1
-
#define DNS_IPV6_ONLY 2
-
#define DNS_IPV6_FIRST 4
-
#define DNS_SRV_RR_LB 8
- SRV RR weight based load balancing.
-
#define DNS_TRY_NAPTR 16
- enable naptr lookup
|
|
-
#define IP_ERR_BAD_DST 2
-
#define IP_ERR_SND 3
-
#define IP_ERR_TIMEOUT 4
-
#define IP_ERR_TCP_CON 5
Enumerations
- enum dns_errors { ,
E_DNS_EOR,
E_DNS_UNKNOWN,
E_DNS_INTERNAL_ERR
, E_DNS_NO_SRV
,
E_DNS_NO_IP,
E_DNS_BAD_IP,
E_DNS_BLACKLIST_IP,
E_DNS_NAME_TOO_LONG,
E_DNS_AF_MISMATCH,
E_DNS_NO_NAPTR,
E_DNS_CRITICAL
}
dns functions return them as negative values (e.g.
More...
Functions
- int dns_cache_add_record (unsigned short type, str *name, int ttl, str *value, int priority, int weight, int port, int flags)
- Adds a new record to the cache.
- int dns_cache_delete_single_record (unsigned short type, str *name, str *value, int flags)
- Delete a single record from the cache, i.e.
- void dns_cache_flush (int del_permanent)
- Delete all the entries from the cache.
- int dns_get_ip (str *name, struct ip_addr *ip, int flags)
- performs an A, AAAA (or both) query/queries Params: name - query target (e.g.
- int dns_sip_resolve (struct dns_srv_handle *h, str *name, struct ip_addr *ip, unsigned short *port, char *proto, int flags)
- resolve name to an ip, using srv record.
-
static int dns_sip_resolve2su (struct dns_srv_handle *h, union sockaddr_union *su, str *name, unsigned short port, char *proto, int flags)
- same as above, but fills su intead of changing port and filling an ip
- int dns_srv_get_ip (str *name, struct ip_addr *ip, unsigned short *port, int flags)
- performes a srv query on name Params: name - srv query target (e.g.
-
static void dns_srv_handle_cpy (struct dns_srv_handle *dst, struct dns_srv_handle *src)
- safe copy increases the refcnt, src must not change while in this function WARNING: the copy must be dns_srv_handle_put !
-
static int dns_srv_handle_next (struct dns_srv_handle *h, int err)
- get "next" ip next time a dns_srv_handle function is called params: h - struct dns_srv_handler err - return code of the last dns_*_resolve* call returns: 0 if it doesn't make sense to try another record, 1 otherwise
-
static void dns_srv_handle_put_shm_unsafe (struct dns_srv_handle *h)
- same as above but assume shm_lock held (for internal tm use only)
-
static void dns_srv_handle_ref (struct dns_srv_handle *h)
- use it when copying, it manually increases the ref cound
-
const char * dns_strerror (int err)
- return a short string, printable error description (err <=0)
Detailed Description
Definition in file dns_cache.h.
Define Documentation
| #define DNS_FLAG_BAD_NAME 1 |
Enumeration Type Documentation
return -E_DNS_NO_IP)
listed in the order of importance ( if more errors, only the most important is returned)
- Enumerator:
| E_DNS_EOR |
no more records (not an error) -- returned only by the dns_resolve* functions when called iteratively,; it signals the end of the ip/records list
|
| E_DNS_UNKNOWN |
unkown error
|
| E_DNS_INTERNAL_ERR |
internal error
|
| E_DNS_NO_SRV |
unresolvable srv record
|
| E_DNS_NO_IP |
unresolvable a or aaaa records
|
| E_DNS_BAD_IP |
the ip is invalid
|
| E_DNS_BLACKLIST_IP |
the ip is blacklisted
|
| E_DNS_NAME_TOO_LONG |
try again with a shorter name
|
| E_DNS_AF_MISMATCH |
ipv4 or ipv6 only requested, but name contains an ip addr.
of the opossite type
|
| E_DNS_NO_NAPTR |
unresolvable naptr record
|
| E_DNS_CRITICAL |
critical error, marks the end of the error table (always last)
|
Definition at line 75 of file dns_cache.h.
Function Documentation
| int dns_cache_add_record |
( |
unsigned short |
type, |
|
|
str * |
name, |
|
|
int |
ttl, |
|
|
str * |
value, |
|
|
int |
priority, |
|
|
int |
weight, |
|
|
int |
port, |
|
|
int |
flags | |
|
) |
| | |
If there is an existing record with the same name and value (ip address in case of A/AAAA record, name in case of SRV record) only the remaining fields are updated.
Note that permanent records cannot be overwritten unless the new record is also permanent. A permanent record completely replaces a non-permanent one.
Currently only A, AAAA, and SRV records are supported.
| int dns_cache_delete_single_record |
( |
unsigned short |
type, |
|
|
str * |
name, |
|
|
str * |
value, |
|
|
int |
flags | |
|
) |
| | |
the record with the same name and value (ip address in case of A/AAAA record, name in case of SRV record).
Currently only A, AAAA, and SRV records are supported.
| void dns_cache_flush |
( |
int |
del_permanent |
) |
|
If del_permanent is 0, then only the non-permanent entries are deleted.
| int dns_get_ip |
( |
str * |
name, |
|
|
struct ip_addr * |
ip, |
|
|
int |
flags | |
|
) |
| | |
foo.bar) ip - result: first good ip found flags - resolve options (like ipv4 only, ipv6 prefered a.s.o) Returns: < 0 on error (can be passed to dns_strerror(), 0 on success
| int dns_sip_resolve |
( |
struct dns_srv_handle * |
h, |
|
|
str * |
name, |
|
|
struct ip_addr * |
ip, |
|
|
unsigned short * |
port, |
|
|
char * |
proto, |
|
|
int |
flags | |
|
) |
| | |
Can be called multiple times to iterate on all the possible ips, e.g : dns_srv_handle_init(h); ret_code=dns_sip_resolve(h,...); while( dns_srv_handle_next(h, ret_code){ ret_code=dns_sip_resolve(h...); } dns_srv_handle_put(h); WARNING: dns_srv_handle_init() must be called to initialize h and dns_srv_handle_put(h) must be called when h is no longer needed
Referenced by dns_sip_resolve2su().
| int dns_srv_get_ip |
( |
str * |
name, |
|
|
struct ip_addr * |
ip, |
|
|
unsigned short * |
port, |
|
|
int |
flags | |
|
) |
| | |
_sip._udp.foo.bar) ip - result: first good ip found port - result: corresponding port number flags - resolve options (like ipv4 only, ipv6 prefered a.s.o) Returns: < 0 on error (can be passed to dns_strerror(), 0 on success