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