MAJOR: dns: Refactor the DNS code

This is a huge patch with many changes, all about the DNS. Initially, the idea
was to update the DNS part to ease the threads support integration. But quickly,
I started to refactor some parts. And after several iterations, it was
impossible for me to commit the different parts atomically. So, instead of
adding tens of patches, often reworking the same parts, it was easier to merge
all my changes in a uniq patch. Here are all changes made on the DNS.

First, the DNS initialization has been refactored. The DNS configuration parsing
remains untouched, in cfgparse.c. But all checks have been moved in a post-check
callback. In the function dns_finalize_config, for each resolvers, the
nameservers configuration is tested and the task used to manage DNS resolutions
is created. The links between the backend's servers and the resolvers are also
created at this step. Here no connection are kept alive. So there is no needs
anymore to reopen them after HAProxy fork. Connections used to send DNS queries
will be opened on demand.

Then, the way DNS requesters are linked to a DNS resolution has been
reworked. The resolution used by a requester is now referenced into the
dns_requester structure and the resolution pointers in server and dns_srvrq
structures have been removed. wait and curr list of requesters, for a DNS
resolution, have been replaced by a uniq list. And Finally, the way a requester
is removed from a DNS resolution has been simplified. Now everything is done in
dns_unlink_resolution.

srv_set_fqdn function has been simplified. Now, there is only 1 way to set the
server's FQDN, independently it is done by the CLI or when a SRV record is
resolved.

The static DNS resolutions pool has been replaced by a dynamoc pool. The part
has been modified by Baptiste Assmann.

The way the DNS resolutions are triggered by the task or by a health-check has
been totally refactored. Now, all timeouts are respected. Especially
hold.valid. The default frequency to wake up a resolvers is now configurable
using "timeout resolve" parameter.

Now, as documented, as long as invalid repsonses are received, we really wait
all name servers responses before retrying.

As far as possible, resources allocated during DNS configuration parsing are
releases when HAProxy is shutdown.

Beside all these changes, the code has been cleaned to ease code review and the
doc has been updated.
diff --git a/include/proto/dns.h b/include/proto/dns.h
index aa063c7..c3e3846 100644
--- a/include/proto/dns.h
+++ b/include/proto/dns.h
@@ -23,46 +23,26 @@
 #define _PROTO_DNS_H
 
 #include <types/dns.h>
-#include <types/proto_udp.h>
 
-char *dns_str_to_dn_label(const char *string, char *dn, int dn_len);
-int dns_str_to_dn_label_len(const char *string);
-void dns_dn_label_to_str(char *dn, char *str, int dn_len);
+extern struct list dns_resolvers;
+
+struct dns_resolvers *find_resolvers_by_id(const char *id);
+struct dns_srvrq *find_srvrq_by_name(const char *name, struct proxy *px);
+struct dns_srvrq *new_dns_srvrq(struct server *srv, char *fqdn);
+
+int dns_str_to_dn_label(const char *str, int str_len, char *dn, int dn_len);
+int dns_dn_label_to_str(const char *dn, int dn_len, char *str, int str_len);
+
 int dns_hostname_validation(const char *string, char **err);
-int dns_build_query(int query_id, int query_type, unsigned int accepted_payload_size, char *hostname_dn, int hostname_dn_len, char *buf, int bufsize);
-struct task *dns_process_resolve(struct task *t);
-int dns_init_resolvers(int close_socket);
-uint16_t dns_rnd16(void);
-int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct dns_resolution *resolution, int max_answer_records);
 int dns_get_ip_from_response(struct dns_response_packet *dns_p,
                              struct dns_options *dns_opts, void *currentip,
                              short currentip_sin_family,
                              void **newip, short *newip_sin_family,
                              void *owner);
-void dns_resolve_send(struct dgram_conn *dgram);
-void dns_resolve_recv(struct dgram_conn *dgram);
-int dns_send_query(struct dns_resolution *resolution);
-void dns_print_current_resolutions(struct dns_resolvers *resolvers);
-void dns_update_resolvers_timeout(struct dns_resolvers *resolvers);
-void dns_reset_resolution(struct dns_resolution *resolution);
-void dns_resolution_free(struct dns_resolvers *resolvers, struct dns_resolution *resolution);
-void dns_rm_requester_from_resolution(struct dns_requester *requester, struct dns_resolution *resolution);
-int dns_check_resolution_queue(struct dns_resolvers *resolvers);
-unsigned short dns_response_get_query_id(unsigned char *resp);
-struct dns_resolution *dns_alloc_resolution(void);
-void dns_free_resolution(struct dns_resolution *resolution);
-struct chunk *dns_cache_key(int query_type, char *hostname_dn, int hostname_dn_len, struct chunk *buf);
-struct lru64 *dns_cache_lookup(int query_type, char *hostname_dn, int hostname_dn_len, int valid_period, void *cache_domain);
-int dns_link_resolution(void *requester, int requester_type, struct dns_resolution *resolution);
-struct dns_resolution *dns_resolution_list_get(struct dns_resolvers *resolvers, char *hostname_dn, int query_type);
-int dns_trigger_resolution(struct dns_resolution *resolution);
-int dns_alloc_resolution_pool(struct dns_resolvers *resolvers);
 
-void dump_dns_config(void);
+int dns_link_resolution(void *requester, int requester_type);
+void dns_unlink_resolution(struct dns_requester *requester);
+void dns_trigger_resolution(struct dns_requester *requester);
 
-/*
- * erases all information of a dns_requester structure
- */
-#define		dns_clear_requester(requester)	memset(requester, '\0', sizeof(*requester));
 
 #endif // _PROTO_DNS_H