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


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_node * | dns_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 rdata * | get_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_addr * | str2ip (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_addr * | str2ip6 (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 |
Definition in file resolve.h.
| #define ANS_SIZE 8192 |
| #define DNS_HDR_SIZE 12 |
| #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 HEX2I | ( | c | ) |
| #define MAX_DNS_NAME 256 |
Definition at line 54 of file resolve.h.
Referenced by dns_cname_parser(), dns_ebl_parser(), dns_naptr_parser(), dns_srv_parser(), and sip_resolvehost().
| #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().
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 | ) |
frees completely a struct rdata list
Definition at line 439 of file resolve.c.
References local_free, rdata::next, and rdata::rdata.
Referenced by do_query(), do_srv_lookup(), enum_pv_query_3(), get_record(), i_enum_query_2(), is_from_user_enum_2(), sip_resolvehost(), and sort_srvs().
| 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
Definition at line 1239 of file resolve.c.
References add_list_to_head(), add_rule_to_list(), proxy_l::addr_idx, ip_addr::af, proxy_l::dn, DNS_BL_EXPIRE, proxy_l::flags, free_dns_res(), free_hostent(), free_shm_hostent(), get_next_he(), proxy_l::host, hostent2ip_addr, hostent2su(), hostent_cpy(), hostent_shm_cpy(), net::ip, ip_addr::len, LM_ERR, net::mask, NULL, proxy_l::port, proxy_l::proto, PROXY_SHM_FLAG, and SIP_PORT.
Referenced by do_dns_failover(), forward_request(), forward_sl_request(), t_forward_nonack(), trace_send_duplicate(), and utils_forward().
| struct rdata* get_record | ( | char * | name, | |
| int | type | |||
| ) | [read] |
Hets the DNS records for name:type.
Definition at line 460 of file resolve.c.
References ANS_SIZE, dns_query::buff, rdata::class, dns_a_parser(), dns_aaaa_parser(), dns_cname_parser(), dns_ebl_parser(), DNS_HDR_SIZE, dns_naptr_parser(), dns_skipname(), dns_srv_parser(), dns_txt_parser(), free_rdata_list(), dns_query::hdr, LM_DBG, LM_ERR, local_free, local_malloc, rdata::next, srv_rdata::priority, rdata::rdata, T_EBL, rdata::ttl, rdata::type, and srv_rdata::weight.
Referenced by do_query(), do_srv_lookup(), dp_can_connect_str(), enum_pv_query_3(), i_enum_query_2(), is_from_user_enum_2(), and sip_resolvehost().
| 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).
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.
| 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 |
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().
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().
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().
| int dns_try_ipv6 |
1.5.6