146 if (!r || !keys) {
return false; }
150 if (!trust_anchors) {
return false; }
262 if (ns_count == 0 || !nameservers) {
266 pop = nameservers[ns_count - 1];
452 ldns_resolver_set_searchlist_count(
ldns_resolver *r,
size_t c)
553 r->
_timeout.tv_sec = timeout.tv_sec;
554 r->
_timeout.tv_usec = timeout.tv_usec;
575 ldns_resolver_set_searchlist_count(r, list_count + 1);
622 ldns_resolver_set_searchlist_count(r, 0);
685 goto error_searchlist;
694 goto error_searchlist;
699 goto error_nameservers;
703 goto error_nameservers;
716 goto error_tsig_keyname;
720 goto error_tsig_keydata;
724 goto error_tsig_algorithm;
728 goto error_cur_axfr_pkt;
734 error_tsig_algorithm:
778 int lnr = 0, oldline;
780 if(!line_nr) line_nr = &lnr;
806 if(!fp) fclose(myfp);
816 if (word[0] ==
'#') {
818 if(oldline == *line_nr) {
823 }
while(c != EOF && c !=
'\n');
824 if(c==
'\n') (*line_nr)++;
836 if(word[0] ==
'#')
continue;
838 if (strcasecmp(keyword[i], word) == 0) {
861 if(!fp) fclose(myfp);
871 if(!fp) fclose(myfp);
884 if(!fp) fclose(myfp);
892 if(strchr(word,
'%')) {
895 strchr(word,
'%')[0]=0;
905 if(!fp) fclose(myfp);
918 if(!fp) fclose(myfp);
926 if(!fp) fclose(myfp);
940 if(!fp) fclose(myfp);
971 if(!fp) fclose(myfp);
1012 fp = fopen(filename,
"r");
1111 new_name, t, c, flags);
1185 if (!new_rtt)
return NULL;
1186 memcpy(new_rtt, old_rtt,
sizeof(
size_t)
1195 ldns_resolver_restore_rtt(
ldns_resolver *r,
size_t *old_rtt)
1238 rtt = ldns_resolver_backup_rtt(r);
1241 ldns_resolver_restore_rtt(r, rtt);
1249 stat =
ldns_send(&answer_pkt, r, query_pkt);
1256 if (answer && answer_pkt) {
1257 *answer = answer_pkt;
1357 now.tv_sec = time(NULL);
1383 assert(name != NULL);
1436 *answer = answer_pkt;
1445 uint8_t *packet_wire;
1446 size_t packet_wire_size;
1450 if (!resolver || resolver->
_socket == -1) {
1504 fprintf(stderr,
"Error in AXFR: %s\n",
1507 fprintf(stderr,
"Error in AXFR: %d\n",
1542 closesocket(resolver->
_socket);
1580 size_t *rtt, tmprtt;
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
void ldns_buffer_new_frm_data(ldns_buffer *buffer, const void *data, size_t size)
creates a buffer with the specified data.
bool ldns_dname_absolute(const ldns_rdf *rdf)
Checks whether the given dname is absolute (i.e.
ldns_rdf * ldns_dname_cat_clone(const ldns_rdf *rd1, const ldns_rdf *rd2)
concatenates two dnames together
const char * ldns_get_errorstr_by_id(ldns_status err)
look up a descriptive text by each error.
@ LDNS_STATUS_SYNTAX_DNAME_ERR
@ LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR
@ LDNS_STATUS_CRYPTO_TSIG_ERR
enum ldns_enum_status ldns_status
ldns_lookup_table ldns_rcodes[]
Response codes.
void ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format)
ldns_rr * ldns_read_anchor_file(const char *filename)
Instantiates a DNSKEY or DS RR from file.
Including this file will include all ldns files, and define some lookup tables.
uint8_t * ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout)
Gives back a raw packet from the wire and reads the header data from the given socket.
ldns_status ldns_send(ldns_pkt **result_packet, ldns_resolver *r, const ldns_pkt *query_pkt)
Sends ptk to the nameserver at the resolver object.
#define LDNS_DEFAULT_TIMEOUT_SEC
#define LDNS_DEFAULT_TIMEOUT_USEC
ldns_pkt * ldns_pkt_clone(const ldns_pkt *pkt)
clones the given packet, creating a fully allocated copy
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
ldns_pkt * ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, type and class.
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
void ldns_pkt_set_random_id(ldns_pkt *packet)
Set the packet's id to a random value.
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
void ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
Set the packet's timestamp.
void ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
Set the packet's cd bit.
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
void ldns_pkt_set_edns_do(ldns_pkt *packet, bool value)
Set the packet's edns do bit.
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
bool ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
ldns_pkt * ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a packet with a query in it for the given name, type and class.
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
returns a token/char from the stream F.
ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit)
returns a token/char from the buffer b.
#define LDNS_PARSE_SKIP_SPACE
#define LDNS_PARSE_NORMAL
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
ldns_rdf * ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str)
creates a new rdf from a string.
ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
returns an rdf that contains the given int32 value.
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
@ LDNS_RDF_TYPE_INT32
32 bits
@ LDNS_RDF_TYPE_AAAA
AAAA record.
@ LDNS_RDF_TYPE_DNAME
domain name
@ LDNS_RDF_TYPE_A
A record.
void ldns_resolver_set_edns_udp_size(ldns_resolver *r, uint16_t s)
Set maximum udp size.
void ldns_resolver_set_random(ldns_resolver *r, bool b)
Should the nameserver list be randomized before each use.
void ldns_resolver_set_recursive(ldns_resolver *r, bool re)
Set the resolver recursion.
ldns_status ldns_resolver_push_nameserver_rr_list(ldns_resolver *r, const ldns_rr_list *rrlist)
Push a new nameserver rr_list to the resolver.
void ldns_resolver_set_dnsrch(ldns_resolver *r, bool d)
Whether the resolver uses the searchlist.
void ldns_resolver_set_tsig_algorithm(ldns_resolver *r, const char *tsig_algorithm)
Set the tsig algorithm.
ldns_pkt * ldns_resolver_query(const ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send a query to a nameserver.
ldns_rr * ldns_axfr_next(ldns_resolver *resolver)
Get the next stream of RRs in a AXFR.
const char * ldns_resolver_tsig_algorithm(const ldns_resolver *r)
Return the tsig algorithm as used by the nameserver.
void ldns_resolver_set_timeout(ldns_resolver *r, struct timeval timeout)
Set the resolver's socket time out when talking to remote hosts.
bool ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
void ldns_resolver_set_tsig_keydata(ldns_resolver *r, const char *tsig_keydata)
Set the tsig key data.
void ldns_resolver_set_dnssec_anchors(ldns_resolver *r, ldns_rr_list *l)
Set the resolver's DNSSEC anchor list directly.
ldns_resolver * ldns_resolver_new(void)
Create a new resolver structure.
void ldns_resolver_set_usevc(ldns_resolver *r, bool vc)
Whether the resolver uses a virtual circuit (TCP)
const char * ldns_resolver_tsig_keydata(const ldns_resolver *r)
Return the tsig keydata as used by the nameserver.
ldns_rdf * ldns_resolver_pop_nameserver(ldns_resolver *r)
pop the last nameserver from the resolver.
void ldns_resolver_set_nameserver_rtt(ldns_resolver *r, size_t pos, size_t value)
Set round trip time for a specific nameserver.
bool ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
void ldns_resolver_push_searchlist(ldns_resolver *r, ldns_rdf *d)
Push a new rd to the resolver's searchlist.
bool ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
size_t ldns_resolver_searchlist_count(const ldns_resolver *r)
Return the resolver's searchlist count.
ldns_rr_list * ldns_resolver_dnssec_anchors(const ldns_resolver *r)
Get the resolver's DNSSEC anchors.
void ldns_resolver_set_dnssec(ldns_resolver *r, bool d)
Whether the resolver uses DNSSEC.
ldns_status ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr)
Create a resolver structure from a file like /etc/resolv.conf.
size_t ldns_resolver_nameserver_count(const ldns_resolver *r)
How many nameserver are configured in the resolver.
void ldns_resolver_free(ldns_resolver *res)
Frees the allocated space for this resolver.
ldns_status ldns_resolver_prepare_query_pkt(ldns_pkt **query_pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Form a query packet from a resolver and name/type/class combo.
void ldns_resolver_set_retry(ldns_resolver *r, uint8_t retry)
Set the number of times a resolver should retry a nameserver before the next one is tried.
void ldns_resolver_set_rtt(ldns_resolver *r, size_t *rtt)
Set round trip time for all nameservers.
void ldns_resolver_dec_nameserver_count(ldns_resolver *r)
Decrement the resolver's nameserver count.
void ldns_resolver_set_debug(ldns_resolver *r, bool d)
Set the resolver debugging.
ldns_status ldns_resolver_query_status(ldns_pkt **pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send a query to a nameserver.
ldns_status ldns_resolver_new_frm_file(ldns_resolver **res, const char *filename)
Configure a resolver by means of a resolv.conf file The file may be NULL in which case there will be ...
bool ldns_axfr_complete(const ldns_resolver *res)
Returns true if the axfr transfer has completed (i.e.
void ldns_resolver_set_ixfr_serial(ldns_resolver *r, uint32_t serial)
Get the serial for requesting IXFR.
uint8_t ldns_resolver_retrans(const ldns_resolver *r)
Get the retransmit interval.
bool ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
bool ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
void ldns_resolver_set_port(ldns_resolver *r, uint16_t p)
Set the port the resolver should use.
bool ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
void ldns_resolver_set_nameservers(ldns_resolver *r, ldns_rdf **n)
Set the resolver's nameserver count directly by using an rdf list.
size_t ldns_resolver_nameserver_rtt(const ldns_resolver *r, size_t pos)
Return the used round trip time for a specific nameserver.
void ldns_resolver_nameservers_randomize(ldns_resolver *r)
Randomize the nameserver list in the resolver.
bool ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
bool ldns_resolver_defnames(const ldns_resolver *r)
Does the resolver apply default domain name.
uint32_t ldns_resolver_get_ixfr_serial(const ldns_resolver *res)
Get the serial for requesting IXFR.
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
uint16_t ldns_resolver_edns_udp_size(const ldns_resolver *r)
Get the resolver's udp size.
void ldns_resolver_set_dnssec_cd(ldns_resolver *r, bool d)
Whether the resolver uses the checking disable bit.
void ldns_resolver_set_nameserver_count(ldns_resolver *r, size_t c)
Set the resolver's nameserver count directly.
void ldns_resolver_set_domain(ldns_resolver *r, ldns_rdf *d)
Set the resolver's default domain.
bool ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
ldns_status ldns_resolver_push_nameserver(ldns_resolver *r, const ldns_rdf *n)
Push a new nameserver to the resolver.
size_t * ldns_resolver_rtt(const ldns_resolver *r)
Return the used round trip times for the nameservers.
bool ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
ldns_pkt * ldns_axfr_last_pkt(const ldns_resolver *res)
Returns a pointer to the last ldns_pkt that was sent by the server in the AXFR transfer usable for in...
ldns_status ldns_resolver_push_dnssec_anchor(ldns_resolver *r, ldns_rr *rr)
Push a new trust anchor to the resolver.
void ldns_resolver_set_source(ldns_resolver *r, ldns_rdf *s)
Set the source rdf (address) the resolver should use.
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
void ldns_resolver_set_ip6(ldns_resolver *r, uint8_t ip6)
Whether the resolver uses ip6.
ldns_status ldns_resolver_new_frm_fp(ldns_resolver **res, FILE *fp)
Create a resolver structure from a file like /etc/resolv.conf.
void ldns_resolver_set_igntc(ldns_resolver *r, bool i)
Whether or not to ignore the TC bit.
void ldns_axfr_abort(ldns_resolver *resolver)
Abort a transfer that is in progress.
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
bool ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
ldns_status ldns_resolver_push_nameserver_rr(ldns_resolver *r, const ldns_rr *rr)
Push a new nameserver to the resolver.
void ldns_resolver_incr_nameserver_count(ldns_resolver *r)
Incremental the resolver's nameserver count.
void ldns_resolver_set_defnames(ldns_resolver *r, bool d)
Whether the resolver uses the name set with _set_domain.
const char * ldns_resolver_tsig_keyname(const ldns_resolver *r)
Return the tsig keyname as used by the nameserver.
bool ldns_resolver_trusted_key(const ldns_resolver *r, ldns_rr_list *keys, ldns_rr_list *trusted_keys)
Returns true if at least one of the provided keys is a trust anchor.
ldns_rdf ** ldns_resolver_nameservers(const ldns_resolver *r)
Return the configured nameserver ip address.
void ldns_resolver_set_fallback(ldns_resolver *r, bool fallback)
Set whether the resolvers truncation fallback mechanism is used when ldns_resolver_query() is called.
void ldns_resolver_set_retrans(ldns_resolver *r, uint8_t retrans)
Set the resolver retrans timeout (in seconds)
void ldns_resolver_set_tsig_keyname(ldns_resolver *r, const char *tsig_keyname)
Set the tsig key name.
ldns_rdf * ldns_resolver_source(const ldns_resolver *r)
Get the source address the resolver should use.
ldns_pkt * ldns_resolver_search(const ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for using the resolver and take the search list into account The search algorithm is a...
uint16_t ldns_resolver_port(const ldns_resolver *r)
Get the port the resolver should use.
void ldns_resolver_set_fail(ldns_resolver *r, bool f)
Whether or not to fail after one failed query.
ldns_resolver * ldns_resolver_clone(ldns_resolver *src)
Clone a resolver.
ldns_status ldns_resolver_search_status(ldns_pkt **pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for using the resolver and take the search list into account The search algorithm is a...
ldns_status ldns_resolver_send_pkt(ldns_pkt **answer, ldns_resolver *r, ldns_pkt *query_pkt)
Send the given packet to a nameserver.
ldns_status ldns_resolver_send(ldns_pkt **answer, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for name as-is.
void ldns_resolver_deep_free(ldns_resolver *res)
Frees the allocated space for this resolver and all it's data.
#define LDNS_RESOLV_INETANY
#define LDNS_RESOLV_OPTIONS
#define LDNS_RESOLV_RTT_MIN
#define LDNS_RESOLV_SORTLIST
#define LDNS_RESOLV_DEFDOMAIN
#define LDNS_RESOLV_KEYWORDS
#define LDNS_RESOLV_ANCHOR
#define LDNS_RESOLV_NAMESERVER
#define LDNS_RESOLV_SEARCH
#define LDNS_RESOLV_KEYWORD
#define LDNS_RESOLV_CONF
Default location of the resolv.conf file.
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
void ldns_rr_set_question(ldns_rr *rr, bool question)
sets the question flag in the rr structure.
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
ldns_rr_list * ldns_rr_list_clone(const ldns_rr_list *rrlist)
clones an rrlist.
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
enum ldns_enum_rr_type ldns_rr_type
@ LDNS_RR_TYPE_A
a host address
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
@ LDNS_RR_TYPE_DS
RFC4034, RFC3658.
@ LDNS_RR_TYPE_AAAA
ipv6 address
enum ldns_enum_rr_class ldns_rr_class
@ LDNS_RR_CLASS_IN
the Internet
ldns_status ldns_str2rdf_dname(ldns_rdf **d, const char *str)
convert a dname string into wireformat
implementation of buffers to ease operations
A general purpose lookup table.
Resource record data field.
DNS stub resolver structure.
bool _fallback
Use new fallback mechanism (try EDNS, then do TCP)
ldns_pkt * _cur_axfr_pkt
Packet currently handled when doing part of an AXFR.
int _socket
Keep some things to make AXFR possible.
uint16_t _axfr_i
Counter for within the AXFR packets.
char * _tsig_keyname
Name of the key to use with TSIG, if _tsig_keyname and _tsig_keydata both contain values,...
uint8_t _retrans
Time to wait before retrying.
ldns_rdf * _source
Source address to query from.
bool _recursive
Whether or not to be recursive.
ldns_rr_list * _dnssec_anchors
Optional trust anchors for complete DNSSEC validation.
bool _debug
Print debug information.
size_t _nameserver_count
Number of nameservers in _nameservers.
bool _fail
Only try the first nameserver, and return with an error directly if it fails.
ldns_rdf ** _searchlist
Searchlist array, add the names in this array if a query cannot be found.
uint8_t _ip6
Whether to use ip6: 0->does not matter, 1 is IPv4, 2 is IPv6.
ldns_rdf ** _nameservers
Array of nameservers to query (IP addresses or dnames)
bool _dnssec_cd
Whether to set the CD bit on DNSSEC requests.
char * _tsig_keydata
Secret key data to use with TSIG, if _tsig_keyname and _tsig_keydata both contain values,...
size_t * _rtt
Round trip time; 0 -> infinity.
bool _usevc
Whether to use tcp or udp (tcp if the value is true)
char * _tsig_algorithm
TSIG signing algorithm.
int _axfr_soa_count
Count the number of LDNS_RR_TYPE_SOA RRs we have seen so far (the second one signifies the end of the...
bool _defnames
If true append the default domain.
bool _dnsrch
If true apply the search list.
size_t _searchlist_count
Number of entries in the searchlist array.
struct timeval _timeout
Timeout for socket connections.
bool _dnssec
Whether to do DNSSEC.
bool _random
Randomly choose a nameserver.
uint8_t _retry
Number of times to retry before giving up.
ldns_rdf * _domain
Default domain to add to non fully qualified domain names.
bool _igntc
Whether to ignore the tc bit.
uint16_t _port
Port to send queries to.
List or Set of Resource Records.
ldns_status ldns_pkt_tsig_sign(ldns_pkt *pkt, const char *key_name, const char *key_data, uint16_t fudge, const char *algorithm_name, const ldns_rdf *query_mac)
creates a tsig rr for the given packet and key.
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
uint16_t ldns_get_random(void)
Get random number.
#define LDNS_MALLOC(type)
Memory management macros.
#define LDNS_XMALLOC(type, count)
#define LDNS_XREALLOC(ptr, type, count)
ldns_status ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
converts the data on the uint8_t bytearray (in wire format) to a DNS packet.