2015-04-13 21:40:55 +00:00
|
|
|
/*
|
|
|
|
* include/proto/dns.h
|
|
|
|
* This file provides functions related to DNS protocol
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Baptiste Assmann <bedis9@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PROTO_DNS_H
|
|
|
|
#define _PROTO_DNS_H
|
|
|
|
|
|
|
|
#include <types/dns.h>
|
|
|
|
#include <types/proto_udp.h>
|
|
|
|
|
2015-07-22 14:42:43 +00:00
|
|
|
char *dns_str_to_dn_label(const char *string, char *dn, int dn_len);
|
2015-04-13 21:40:55 +00:00
|
|
|
int dns_str_to_dn_label_len(const char *string);
|
2017-08-04 16:35:36 +00:00
|
|
|
void dns_dn_label_to_str(char *dn, char *str, int dn_len);
|
2015-04-13 21:40:55 +00:00
|
|
|
int dns_hostname_validation(const char *string, char **err);
|
2017-08-13 22:13:01 +00:00
|
|
|
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);
|
2015-04-13 21:40:55 +00:00
|
|
|
struct task *dns_process_resolve(struct task *t);
|
2017-02-02 21:44:15 +00:00
|
|
|
int dns_init_resolvers(int close_socket);
|
2015-04-13 21:40:55 +00:00
|
|
|
uint16_t dns_rnd16(void);
|
2017-08-18 21:35:08 +00:00
|
|
|
int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct dns_resolution *resolution, int max_answer_records);
|
2017-05-03 13:43:12 +00:00
|
|
|
int dns_get_ip_from_response(struct dns_response_packet *dns_p,
|
2017-05-03 10:12:02 +00:00
|
|
|
struct dns_options *dns_opts, void *currentip,
|
2016-02-17 20:25:09 +00:00
|
|
|
short currentip_sin_family,
|
2017-05-03 13:43:12 +00:00
|
|
|
void **newip, short *newip_sin_family,
|
|
|
|
void *owner);
|
2015-04-13 21:40:55 +00:00
|
|
|
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);
|
MAJOR/REORG: dns: DNS resolution task and requester queues
This patch is a major upgrade of the internal run-time DNS resolver in
HAProxy and it brings the following 2 main changes:
1. DNS resolution task
Up to now, DNS resolution was triggered by the health check task.
From now, DNS resolution task is autonomous. It is started by HAProxy
right after the scheduler is available and it is woken either when a
network IO occurs for one of its nameserver or when a timeout is
matched.
From now, this means we can enable DNS resolution for a server without
enabling health checking.
2. Introduction of a dns_requester structure
Up to now, DNS resolution was purposely made for resolving server
hostnames.
The idea, is to ensure that any HAProxy internal object should be able
to trigger a DNS resolution. For this purpose, 2 things has to be done:
- clean up the DNS code from the server structure (this was already
quite clean actually) and clean up the server's callbacks from
manipulating too much DNS resolution
- create an agnostic structure which allows linking a DNS resolution
and a requester of any type (using obj_type enum)
3. Manage requesters through queues
Up to now, there was an uniq relationship between a resolution and it's
owner (aka the requester now). It's a shame, because in some cases,
multiple objects may share the same hostname and may benefit from a
resolution being performed by a third party.
This patch introduces the notion of queues, which are basically lists of
either currently running resolution or waiting ones.
The resolutions are now available as a pool, which belongs to the resolvers.
The pool has has a default size of 64 resolutions per resolvers and is
allocated at configuration parsing.
2017-05-22 13:17:15 +00:00
|
|
|
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);
|
2015-04-13 21:40:55 +00:00
|
|
|
int dns_check_resolution_queue(struct dns_resolvers *resolvers);
|
2016-01-20 22:46:34 +00:00
|
|
|
unsigned short dns_response_get_query_id(unsigned char *resp);
|
2017-05-03 08:11:44 +00:00
|
|
|
struct dns_resolution *dns_alloc_resolution(void);
|
|
|
|
void dns_free_resolution(struct dns_resolution *resolution);
|
2017-05-04 07:05:00 +00:00
|
|
|
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);
|
MAJOR/REORG: dns: DNS resolution task and requester queues
This patch is a major upgrade of the internal run-time DNS resolver in
HAProxy and it brings the following 2 main changes:
1. DNS resolution task
Up to now, DNS resolution was triggered by the health check task.
From now, DNS resolution task is autonomous. It is started by HAProxy
right after the scheduler is available and it is woken either when a
network IO occurs for one of its nameserver or when a timeout is
matched.
From now, this means we can enable DNS resolution for a server without
enabling health checking.
2. Introduction of a dns_requester structure
Up to now, DNS resolution was purposely made for resolving server
hostnames.
The idea, is to ensure that any HAProxy internal object should be able
to trigger a DNS resolution. For this purpose, 2 things has to be done:
- clean up the DNS code from the server structure (this was already
quite clean actually) and clean up the server's callbacks from
manipulating too much DNS resolution
- create an agnostic structure which allows linking a DNS resolution
and a requester of any type (using obj_type enum)
3. Manage requesters through queues
Up to now, there was an uniq relationship between a resolution and it's
owner (aka the requester now). It's a shame, because in some cases,
multiple objects may share the same hostname and may benefit from a
resolution being performed by a third party.
This patch introduces the notion of queues, which are basically lists of
either currently running resolution or waiting ones.
The resolutions are now available as a pool, which belongs to the resolvers.
The pool has has a default size of 64 resolutions per resolvers and is
allocated at configuration parsing.
2017-05-22 13:17:15 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* erases all information of a dns_requester structure
|
|
|
|
*/
|
|
|
|
#define dns_clear_requester(requester) memset(requester, '\0', sizeof(*requester));
|
2015-04-13 21:40:55 +00:00
|
|
|
|
|
|
|
#endif // _PROTO_DNS_H
|