Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/dns.h |
| 3 | * This file provides structures and types for DNS. |
| 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 _TYPES_DNS_H |
| 23 | #define _TYPES_DNS_H |
| 24 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 25 | #include <eb32tree.h> |
| 26 | |
| 27 | #include <common/mini-clist.h> |
Christopher Faulet | b2812a6 | 2017-10-04 16:17:58 +0200 | [diff] [blame] | 28 | #include <common/hathreads.h> |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 29 | |
| 30 | #include <types/connection.h> |
| 31 | #include <types/obj_type.h> |
| 32 | #include <types/proto_udp.h> |
| 33 | #include <types/proxy.h> |
| 34 | #include <types/server.h> |
| 35 | #include <types/task.h> |
| 36 | |
Baptiste Assmann | dfd35fd | 2019-01-21 08:18:09 +0100 | [diff] [blame] | 37 | extern struct pool_head *dns_requester_pool; |
| 38 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 39 | /*DNS maximum values */ |
| 40 | /* |
| 41 | * Maximum issued from RFC: |
| 42 | * RFC 1035: https://www.ietf.org/rfc/rfc1035.txt chapter 2.3.4 |
| 43 | * RFC 2671: http://tools.ietf.org/html/rfc2671 |
| 44 | */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 45 | #define DNS_MAX_LABEL_SIZE 63 |
| 46 | #define DNS_MAX_NAME_SIZE 255 |
| 47 | #define DNS_MAX_UDP_MESSAGE 8192 |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 48 | |
Ilya Shipitsin | d425950 | 2020-04-08 01:07:56 +0500 | [diff] [blame] | 49 | /* DNS minimum record size: 1 char + 1 NULL + type + class */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 50 | #define DNS_MIN_RECORD_SIZE (1 + 1 + 2 + 2) |
Baptiste Assmann | 4ec076f | 2015-12-09 14:02:01 +0100 | [diff] [blame] | 51 | |
Baptiste Assmann | d0aa6d2 | 2017-04-03 14:40:20 +0200 | [diff] [blame] | 52 | /* DNS smallest fqdn 'a.gl' size */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 53 | # define DNS_SMALLEST_FQDN_SIZE 4 |
Baptiste Assmann | d0aa6d2 | 2017-04-03 14:40:20 +0200 | [diff] [blame] | 54 | |
Baptiste Assmann | 4ec076f | 2015-12-09 14:02:01 +0100 | [diff] [blame] | 55 | /* maximum number of query records in a DNS response |
| 56 | * For now, we allow only one */ |
| 57 | #define DNS_MAX_QUERY_RECORDS 1 |
| 58 | |
| 59 | /* maximum number of answer record in a DNS response */ |
| 60 | #define DNS_MAX_ANSWER_RECORDS ((DNS_MAX_UDP_MESSAGE - DNS_HEADER_SIZE) / DNS_MIN_RECORD_SIZE) |
| 61 | |
Baptiste Assmann | c1ce5f3 | 2016-05-14 11:26:22 +0200 | [diff] [blame] | 62 | /* size of dns_buffer used to store responses from the buffer |
| 63 | * dns_buffer is used to store data collected from records found in a response. |
| 64 | * Before using it, caller will always check that there is at least DNS_MAX_NAME_SIZE bytes |
| 65 | * available */ |
| 66 | #define DNS_ANALYZE_BUFFER_SIZE DNS_MAX_UDP_MESSAGE + DNS_MAX_NAME_SIZE |
| 67 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 68 | /* DNS error messages */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 69 | #define DNS_TOO_LONG_FQDN "hostname too long" |
| 70 | #define DNS_LABEL_TOO_LONG "one label too long" |
| 71 | #define DNS_INVALID_CHARACTER "found an invalid character" |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 72 | |
| 73 | /* dns query class */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 74 | #define DNS_RCLASS_IN 1 /* internet class */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 75 | |
| 76 | /* dns record types (non exhaustive list) */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 77 | #define DNS_RTYPE_A 1 /* IPv4 address */ |
| 78 | #define DNS_RTYPE_CNAME 5 /* canonical name */ |
| 79 | #define DNS_RTYPE_AAAA 28 /* IPv6 address */ |
| 80 | #define DNS_RTYPE_SRV 33 /* SRV record */ |
| 81 | #define DNS_RTYPE_OPT 41 /* OPT */ |
| 82 | #define DNS_RTYPE_ANY 255 /* all records */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 83 | |
| 84 | /* dns rcode values */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 85 | #define DNS_RCODE_NO_ERROR 0 /* no error */ |
| 86 | #define DNS_RCODE_NX_DOMAIN 3 /* non existent domain */ |
| 87 | #define DNS_RCODE_REFUSED 5 /* query refused */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 88 | |
Baptiste Assmann | 042d0a1 | 2015-09-02 21:52:37 +0200 | [diff] [blame] | 89 | /* dns flags masks */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 90 | #define DNS_FLAG_TRUNCATED 0x0200 /* mask for truncated flag */ |
| 91 | #define DNS_FLAG_REPLYCODE 0x000F /* mask for reply code */ |
Baptiste Assmann | 042d0a1 | 2015-09-02 21:52:37 +0200 | [diff] [blame] | 92 | |
Joseph Herlant | 42cf639 | 2018-11-15 10:33:28 -0800 | [diff] [blame] | 93 | /* max number of network preference entries are available from the |
Thierry Fournier | ac88cfe | 2016-02-17 22:05:30 +0100 | [diff] [blame] | 94 | * configuration file. |
| 95 | */ |
| 96 | #define SRV_MAX_PREF_NET 5 |
| 97 | |
Baptiste Assmann | ed97c95 | 2015-07-21 15:34:51 +0200 | [diff] [blame] | 98 | /* DNS header size */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 99 | #define DNS_HEADER_SIZE ((int)sizeof(struct dns_header)) |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 100 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 101 | /* DNS request or response header structure */ |
| 102 | struct dns_header { |
Nenad Merdanovic | 8ab7942 | 2016-07-13 14:03:43 +0200 | [diff] [blame] | 103 | uint16_t id; |
| 104 | uint16_t flags; |
| 105 | uint16_t qdcount; |
| 106 | uint16_t ancount; |
| 107 | uint16_t nscount; |
| 108 | uint16_t arcount; |
| 109 | } __attribute__ ((packed)); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 110 | |
| 111 | /* short structure to describe a DNS question */ |
Baptiste Assmann | 83b0a17 | 2016-09-05 19:09:49 +0200 | [diff] [blame] | 112 | /* NOTE: big endian structure */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 113 | struct dns_question { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 114 | unsigned short qtype; /* question type */ |
| 115 | unsigned short qclass; /* query class */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
Baptiste Assmann | 83b0a17 | 2016-09-05 19:09:49 +0200 | [diff] [blame] | 118 | /* NOTE: big endian structure */ |
Baptiste Assmann | 5748f73 | 2015-07-21 15:36:24 +0200 | [diff] [blame] | 119 | struct dns_query_item { |
Remi Gacogne | 00488dd | 2018-12-05 17:59:56 +0100 | [diff] [blame] | 120 | char name[DNS_MAX_NAME_SIZE+1]; /* query name */ |
| 121 | unsigned short type; /* question type */ |
| 122 | unsigned short class; /* query class */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 123 | struct list list; |
Baptiste Assmann | 5748f73 | 2015-07-21 15:36:24 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Baptiste Assmann | 83b0a17 | 2016-09-05 19:09:49 +0200 | [diff] [blame] | 126 | /* NOTE: big endian structure */ |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 127 | struct dns_additional_record { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 128 | uint8_t name; /* domain name, must be 0 (RFC 6891) */ |
| 129 | uint16_t type; /* record type DNS_RTYPE_OPT (41) */ |
| 130 | uint16_t udp_payload_size; /* maximum size accepted for the response */ |
| 131 | uint32_t extension; /* extended rcode and flags, not used for now */ |
| 132 | uint16_t data_length; /* data length */ |
| 133 | /* as of today, we don't support yet edns options, that said I already put a |
| 134 | * placeholder here for this purpose. We may need to define a dns_option_record |
| 135 | * structure which itself should point to different type of data, based on the |
| 136 | * extension set (client subnet, tcp keepalive, etc...)*/ |
| 137 | // struct list options; /* list of option records */ |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 138 | } __attribute__ ((packed)); |
| 139 | |
| 140 | /* NOTE: big endian structure */ |
Baptiste Assmann | 5748f73 | 2015-07-21 15:36:24 +0200 | [diff] [blame] | 141 | struct dns_answer_item { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 142 | /*For SRV type, name also includes service and protocol value */ |
Remi Gacogne | 00488dd | 2018-12-05 17:59:56 +0100 | [diff] [blame] | 143 | char name[DNS_MAX_NAME_SIZE+1]; /* answer name */ |
| 144 | int16_t type; /* question type */ |
| 145 | int16_t class; /* query class */ |
| 146 | int32_t ttl; /* response TTL */ |
| 147 | int16_t priority; /* SRV type priority */ |
| 148 | uint16_t weight; /* SRV type weight */ |
Willy Tarreau | d1f56c9 | 2019-05-22 20:07:45 +0200 | [diff] [blame] | 149 | uint16_t port; /* SRV type port */ |
Remi Gacogne | 00488dd | 2018-12-05 17:59:56 +0100 | [diff] [blame] | 150 | uint16_t data_len; /* number of bytes in target below */ |
| 151 | struct sockaddr address; /* IPv4 or IPv6, network format */ |
| 152 | char target[DNS_MAX_NAME_SIZE+1]; /* Response data: SRV or CNAME type target */ |
| 153 | time_t last_seen; /* When was the answer was last seen */ |
Ilya Shipitsin | d425950 | 2020-04-08 01:07:56 +0500 | [diff] [blame] | 154 | struct dns_answer_item *ar_item; /* pointer to a RRset from the additional section, if exists */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 155 | struct list list; |
Baptiste Assmann | 5748f73 | 2015-07-21 15:36:24 +0200 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | struct dns_response_packet { |
| 159 | struct dns_header header; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 160 | struct list query_list; |
| 161 | struct list answer_list; |
Baptiste Assmann | 13a9232 | 2019-06-07 09:40:55 +0200 | [diff] [blame] | 162 | struct list ar_list; /* additional records */ |
| 163 | /* authority ignored for now */ |
Baptiste Assmann | 5748f73 | 2015-07-21 15:36:24 +0200 | [diff] [blame] | 164 | }; |
| 165 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 166 | /* Resolvers section and parameters. It is linked to the name servers |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 167 | * servers points to it. |
| 168 | * current resolution are stored in a FIFO list. |
| 169 | */ |
| 170 | struct dns_resolvers { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 171 | char *id; /* resolvers unique identifier */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 172 | struct { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 173 | const char *file; /* file where the section appears */ |
| 174 | int line; /* line where the section appears */ |
| 175 | } conf; /* config information */ |
| 176 | struct list nameservers; /* dns server list */ |
| 177 | unsigned int accepted_payload_size; /* maximum payload size we accept for responses */ |
| 178 | int nb_nameservers; /* total number of active nameservers in a resolvers section */ |
| 179 | int resolve_retries; /* number of retries before giving up */ |
| 180 | struct { /* time to: */ |
| 181 | int resolve; /* wait between 2 queries for the same resolution */ |
| 182 | int retry; /* wait for a response before retrying */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 183 | } timeout; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 184 | struct { /* time to hold current data when */ |
| 185 | int valid; /* a response is valid */ |
| 186 | int nx; /* a response doesn't exist */ |
| 187 | int timeout; /* no answer was delivered */ |
| 188 | int refused; /* dns server refused to answer */ |
| 189 | int other; /* other dns response errors */ |
| 190 | int obsolete; /* an answer hasn't been seen */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 191 | } hold; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 192 | struct task *t; /* timeout management */ |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 193 | struct { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 194 | struct list wait; /* resolutions managed to this resolvers section */ |
| 195 | struct list curr; /* current running resolutions */ |
| 196 | } resolutions; |
| 197 | struct eb_root query_ids; /* tree to quickly lookup/retrieve query ids currently in use |
| 198 | * used by each nameserver, but stored in resolvers since there must |
| 199 | * be a unique relation between an eb_root and an eb_node (resolution) */ |
Christopher Faulet | 9dcf9b6 | 2017-11-13 10:34:01 +0100 | [diff] [blame] | 200 | __decl_hathreads(HA_SPINLOCK_T lock); |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 201 | struct list list; /* resolvers list */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 202 | }; |
| 203 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 204 | /* Structure describing a name server used during name resolution. |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 205 | * A name server belongs to a resolvers section. |
| 206 | */ |
| 207 | struct dns_nameserver { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 208 | char *id; /* nameserver unique identifier */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 209 | struct { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 210 | const char *file; /* file where the section appears */ |
| 211 | int line; /* line where the section appears */ |
| 212 | } conf; /* config information */ |
| 213 | |
| 214 | struct dns_resolvers *resolvers; |
| 215 | struct dgram_conn *dgram; /* transport layer */ |
| 216 | struct sockaddr_storage addr; /* IP address */ |
| 217 | |
| 218 | struct { /* numbers relted to this name server: */ |
| 219 | long long sent; /* - queries sent */ |
| 220 | long long snd_error; /* - sending errors */ |
| 221 | long long valid; /* - valid response */ |
| 222 | long long update; /* - valid response used to update server's IP */ |
| 223 | long long cname; /* - CNAME response requiring new resolution */ |
| 224 | long long cname_error; /* - error when resolving CNAMEs */ |
| 225 | long long any_err; /* - void response (usually because ANY qtype) */ |
| 226 | long long nx; /* - NX response */ |
| 227 | long long timeout; /* - queries which reached timeout */ |
| 228 | long long refused; /* - queries refused */ |
| 229 | long long other; /* - other type of response */ |
| 230 | long long invalid; /* - malformed DNS response */ |
| 231 | long long too_big; /* - too big response */ |
| 232 | long long outdated; /* - outdated response (server slower than the other ones) */ |
| 233 | long long truncated; /* - truncated response */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 234 | } counters; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 235 | struct list list; /* nameserver chained list */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 236 | }; |
| 237 | |
Thierry Fournier | ada3484 | 2016-02-17 21:25:09 +0100 | [diff] [blame] | 238 | struct dns_options { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 239 | int family_prio; /* which IP family should the resolver use when both are returned */ |
Thierry Fournier | ac88cfe | 2016-02-17 22:05:30 +0100 | [diff] [blame] | 240 | struct { |
| 241 | int family; |
| 242 | union { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 243 | struct in_addr in4; |
Thierry Fournier | ac88cfe | 2016-02-17 22:05:30 +0100 | [diff] [blame] | 244 | struct in6_addr in6; |
| 245 | } addr; |
| 246 | union { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 247 | struct in_addr in4; |
Thierry Fournier | ac88cfe | 2016-02-17 22:05:30 +0100 | [diff] [blame] | 248 | struct in6_addr in6; |
| 249 | } mask; |
| 250 | } pref_net[SRV_MAX_PREF_NET]; |
Joseph Herlant | 42cf639 | 2018-11-15 10:33:28 -0800 | [diff] [blame] | 251 | int pref_net_nb; /* The number of registered preferred networks. */ |
Baptiste Assmann | 8e2d943 | 2018-06-22 15:04:43 +0200 | [diff] [blame] | 252 | int accept_duplicate_ip; /* flag to indicate whether the associated object can use an IP address |
| 253 | already set to an other object of the same group */ |
Daniel Corbett | f871691 | 2019-11-17 09:48:56 -0500 | [diff] [blame] | 254 | int ignore_weight; /* flag to indicate whether to ignore the weight within the record */ |
Thierry Fournier | ada3484 | 2016-02-17 21:25:09 +0100 | [diff] [blame] | 255 | }; |
| 256 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 257 | /* Resolution structure associated to single server and used to manage name |
| 258 | * resolution for this server. |
| 259 | * The only link between the resolution and a nameserver is through the |
| 260 | * query_id. |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 261 | */ |
| 262 | struct dns_resolution { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 263 | struct dns_resolvers *resolvers; /* pointer to the resolvers structure owning the resolution */ |
| 264 | struct list requesters; /* list of requesters using this resolution */ |
| 265 | int uuid; /* unique id (used for debugging purpose) */ |
| 266 | char *hostname_dn; /* server hostname in domain name label format */ |
| 267 | int hostname_dn_len; /* server domain name label len */ |
| 268 | unsigned int last_resolution; /* time of the last resolution */ |
| 269 | unsigned int last_query; /* time of the last query sent */ |
| 270 | unsigned int last_valid; /* time of the last valid response */ |
| 271 | int query_id; /* DNS query ID dedicated for this resolution */ |
| 272 | struct eb32_node qid; /* ebtree query id */ |
Joseph Herlant | 42cf639 | 2018-11-15 10:33:28 -0800 | [diff] [blame] | 273 | int prefered_query_type; /* preferred query type */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 274 | int query_type; /* current query type */ |
| 275 | int status; /* status of the resolution being processed RSLV_STATUS_* */ |
| 276 | int step; /* RSLV_STEP_* */ |
| 277 | int try; /* current resolution try */ |
| 278 | int nb_queries; /* count number of queries sent */ |
| 279 | int nb_responses; /* count number of responses received */ |
| 280 | |
| 281 | struct dns_response_packet response; /* structure hosting the DNS response */ |
| 282 | struct dns_query_item response_query_records[DNS_MAX_QUERY_RECORDS]; /* <response> query records */ |
| 283 | |
| 284 | struct list list; /* resolution list */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 287 | /* Structure used to describe the owner of a DNS resolution. */ |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 288 | struct dns_requester { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 289 | enum obj_type *owner; /* pointer to the owner (server or dns_srvrq) */ |
| 290 | struct dns_resolution *resolution; /* pointer to the owned DNS resolution */ |
| 291 | |
| 292 | int (*requester_cb)(struct dns_requester *, struct dns_nameserver *); /* requester callback for valid response */ |
| 293 | int (*requester_error_cb)(struct dns_requester *, int); /* requester callback, for error management */ |
| 294 | |
| 295 | struct list list; /* requester list */ |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 296 | }; |
| 297 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 298 | /* Last resolution status code */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 299 | enum { |
Joseph Herlant | 42cf639 | 2018-11-15 10:33:28 -0800 | [diff] [blame] | 300 | RSLV_STATUS_NONE = 0, /* no resolution occurred yet */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 301 | RSLV_STATUS_VALID, /* no error */ |
| 302 | RSLV_STATUS_INVALID, /* invalid responses */ |
| 303 | RSLV_STATUS_ERROR, /* error */ |
| 304 | RSLV_STATUS_NX, /* NXDOMAIN */ |
| 305 | RSLV_STATUS_REFUSED, /* server refused our query */ |
| 306 | RSLV_STATUS_TIMEOUT, /* no response from DNS servers */ |
| 307 | RSLV_STATUS_OTHER, /* other errors */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 308 | }; |
| 309 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 310 | /* Current resolution step */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 311 | enum { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 312 | RSLV_STEP_NONE = 0, /* nothing happening currently */ |
| 313 | RSLV_STEP_RUNNING, /* resolution is running */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 314 | }; |
| 315 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 316 | /* Return codes after analyzing a DNS response */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 317 | enum { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 318 | DNS_RESP_VALID = 0, /* valid response */ |
| 319 | DNS_RESP_INVALID, /* invalid response (various type of errors can trigger it) */ |
| 320 | DNS_RESP_ERROR, /* DNS error code */ |
| 321 | DNS_RESP_NX_DOMAIN, /* resolution unsuccessful */ |
| 322 | DNS_RESP_REFUSED, /* DNS server refused to answer */ |
| 323 | DNS_RESP_ANCOUNT_ZERO, /* no answers in the response */ |
| 324 | DNS_RESP_WRONG_NAME, /* response does not match query name */ |
| 325 | DNS_RESP_CNAME_ERROR, /* error when resolving a CNAME in an atomic response */ |
| 326 | DNS_RESP_TIMEOUT, /* DNS server has not answered in time */ |
| 327 | DNS_RESP_TRUNCATED, /* DNS response is truncated */ |
| 328 | DNS_RESP_NO_EXPECTED_RECORD, /* No expected records were found in the response */ |
| 329 | DNS_RESP_QUERY_COUNT_ERROR, /* we did not get the expected number of queries in the response */ |
| 330 | DNS_RESP_INTERNAL, /* internal resolver error */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 331 | }; |
| 332 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 333 | /* Return codes after searching an IP in a DNS response buffer, using a family |
| 334 | * preference |
| 335 | */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 336 | enum { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 337 | DNS_UPD_NO = 1, /* provided IP was found and preference is matched |
| 338 | * OR provided IP found and preference is not matched, but no IP |
| 339 | * matching preference was found */ |
| 340 | DNS_UPD_SRVIP_NOT_FOUND, /* provided IP not found |
| 341 | * OR provided IP found and preference is not match and an IP |
| 342 | * matching preference was found */ |
| 343 | DNS_UPD_CNAME, /* CNAME without any IP provided in the response */ |
| 344 | DNS_UPD_NAME_ERROR, /* name in the response did not match the query */ |
| 345 | DNS_UPD_NO_IP_FOUND, /* no IP could be found in the response */ |
| 346 | DNS_UPD_OBSOLETE_IP, /* The server IP was obsolete, and no other IP was found */ |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
Olivier Houchard | 8da5f98 | 2017-08-04 18:35:36 +0200 | [diff] [blame] | 349 | struct dns_srvrq { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 350 | enum obj_type obj_type; /* object type == OBJ_TYPE_SRVRQ */ |
| 351 | struct dns_resolvers *resolvers; /* pointer to the resolvers structure used for this server template */ |
| 352 | struct proxy *proxy; /* associated proxy */ |
| 353 | char *name; |
| 354 | char *hostname_dn; /* server hostname in Domain Name format */ |
| 355 | int hostname_dn_len; /* string length of the server hostname in Domain Name format */ |
| 356 | struct dns_requester *dns_requester; /* used to link to its DNS resolution */ |
| 357 | struct list list; /* Next SRV RQ for the same proxy */ |
Olivier Houchard | 8da5f98 | 2017-08-04 18:35:36 +0200 | [diff] [blame] | 358 | }; |
| 359 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 360 | #endif /* _TYPES_DNS_H */ |