Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/dns.h |
| 3 | * This file provides functions related to DNS protocol |
| 4 | * |
| 5 | * Copyright (C) 2014 Baptiste Assmann <bedis9@gmail.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROTO_DNS_H |
| 23 | #define _PROTO_DNS_H |
| 24 | |
| 25 | #include <types/dns.h> |
| 26 | #include <types/proto_udp.h> |
| 27 | |
Willy Tarreau | 2100b49 | 2015-07-22 16:42:43 +0200 | [diff] [blame] | 28 | char *dns_str_to_dn_label(const char *string, char *dn, int dn_len); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 29 | int dns_str_to_dn_label_len(const char *string); |
Olivier Houchard | 8da5f98 | 2017-08-04 18:35:36 +0200 | [diff] [blame] | 30 | void dns_dn_label_to_str(char *dn, char *str, int dn_len); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 31 | int dns_hostname_validation(const char *string, char **err); |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 32 | 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); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 33 | struct task *dns_process_resolve(struct task *t); |
Baptiste Assmann | 5cd1b92 | 2017-02-02 22:44:15 +0100 | [diff] [blame] | 34 | int dns_init_resolvers(int close_socket); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 35 | uint16_t dns_rnd16(void); |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 36 | int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct dns_resolution *resolution, int max_answer_records); |
Baptiste Assmann | fb7091e | 2017-05-03 15:43:12 +0200 | [diff] [blame] | 37 | int dns_get_ip_from_response(struct dns_response_packet *dns_p, |
Baptiste Assmann | 4274637 | 2017-05-03 12:12:02 +0200 | [diff] [blame] | 38 | struct dns_options *dns_opts, void *currentip, |
Thierry Fournier | ada3484 | 2016-02-17 21:25:09 +0100 | [diff] [blame] | 39 | short currentip_sin_family, |
Baptiste Assmann | fb7091e | 2017-05-03 15:43:12 +0200 | [diff] [blame] | 40 | void **newip, short *newip_sin_family, |
| 41 | void *owner); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 42 | void dns_resolve_send(struct dgram_conn *dgram); |
| 43 | void dns_resolve_recv(struct dgram_conn *dgram); |
| 44 | int dns_send_query(struct dns_resolution *resolution); |
| 45 | void dns_print_current_resolutions(struct dns_resolvers *resolvers); |
| 46 | void dns_update_resolvers_timeout(struct dns_resolvers *resolvers); |
| 47 | void dns_reset_resolution(struct dns_resolution *resolution); |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 48 | void dns_resolution_free(struct dns_resolvers *resolvers, struct dns_resolution *resolution); |
| 49 | void dns_rm_requester_from_resolution(struct dns_requester *requester, struct dns_resolution *resolution); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 50 | int dns_check_resolution_queue(struct dns_resolvers *resolvers); |
Thiago Farina | b1af23e | 2016-01-20 23:46:34 +0100 | [diff] [blame] | 51 | unsigned short dns_response_get_query_id(unsigned char *resp); |
Baptiste Assmann | 81ed1a0 | 2017-05-03 10:11:44 +0200 | [diff] [blame] | 52 | struct dns_resolution *dns_alloc_resolution(void); |
| 53 | void dns_free_resolution(struct dns_resolution *resolution); |
Baptiste Assmann | fa4a663 | 2017-05-04 09:05:00 +0200 | [diff] [blame] | 54 | struct chunk *dns_cache_key(int query_type, char *hostname_dn, int hostname_dn_len, struct chunk *buf); |
| 55 | struct lru64 *dns_cache_lookup(int query_type, char *hostname_dn, int hostname_dn_len, int valid_period, void *cache_domain); |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 56 | int dns_link_resolution(void *requester, int requester_type, struct dns_resolution *resolution); |
| 57 | struct dns_resolution *dns_resolution_list_get(struct dns_resolvers *resolvers, char *hostname_dn, int query_type); |
| 58 | int dns_trigger_resolution(struct dns_resolution *resolution); |
| 59 | int dns_alloc_resolution_pool(struct dns_resolvers *resolvers); |
| 60 | |
| 61 | void dump_dns_config(void); |
| 62 | |
| 63 | /* |
| 64 | * erases all information of a dns_requester structure |
| 65 | */ |
| 66 | #define dns_clear_requester(requester) memset(requester, '\0', sizeof(*requester)); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 67 | |
| 68 | #endif // _PROTO_DNS_H |