1 #ifndef HEADER_CURL_DOH_H 2 #define HEADER_CURL_DOH_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) 2018, Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.haxx.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 ***************************************************************************/ 24 25 #include "urldata.h" 26 #include "curl_addrinfo.h" 27 28 /* 29 * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name 30 * and returns a 'Curl_addrinfo *' with the address information. 31 */ 32 33 Curl_addrinfo *Curl_doh(struct connectdata *conn, 34 const char *hostname, 35 int port, 36 int *waitp); 37 38 CURLcode Curl_doh_is_resolved(struct connectdata *conn, 39 struct Curl_dns_entry **dns); 40 41 int Curl_doh_getsock(struct connectdata *conn, curl_socket_t *socks, 42 int numsocks); 43 44 typedef enum { 45 DOH_OK, 46 DOH_DNS_BAD_LABEL, /* 1 */ 47 DOH_DNS_OUT_OF_RANGE, /* 2 */ 48 DOH_DNS_LABEL_LOOP, /* 3 */ 49 DOH_TOO_SMALL_BUFFER, /* 4 */ 50 DOH_OUT_OF_MEM, /* 5 */ 51 DOH_DNS_RDATA_LEN, /* 6 */ 52 DOH_DNS_MALFORMAT, /* 7 */ 53 DOH_DNS_BAD_RCODE, /* 8 - no such name */ 54 DOH_DNS_UNEXPECTED_TYPE, /* 9 */ 55 DOH_DNS_UNEXPECTED_CLASS, /* 10 */ 56 DOH_NO_CONTENT, /* 11 */ 57 DOH_DNS_BAD_ID /* 12 */ 58 } DOHcode; 59 60 typedef enum { 61 DNS_TYPE_A = 1, 62 DNS_TYPE_NS = 2, 63 DNS_TYPE_CNAME = 5, 64 DNS_TYPE_AAAA = 28 65 } DNStype; 66 67 #define DOH_MAX_ADDR 24 68 #define DOH_MAX_CNAME 4 69 70 struct cnamestore { 71 size_t len; /* length of cname */ 72 char *alloc; /* allocated pointer */ 73 size_t allocsize; /* allocated size */ 74 }; 75 76 struct dohaddr { 77 int type; 78 union { 79 unsigned char v4[4]; /* network byte order */ 80 unsigned char v6[16]; 81 } ip; 82 }; 83 84 struct dohentry { 85 unsigned int ttl; 86 int numaddr; 87 struct dohaddr addr[DOH_MAX_ADDR]; 88 int numcname; 89 struct cnamestore cname[DOH_MAX_CNAME]; 90 }; 91 92 93 #ifdef DEBUGBUILD 94 DOHcode doh_encode(const char *host, 95 DNStype dnstype, 96 unsigned char *dnsp, /* buffer */ 97 size_t len, /* buffer size */ 98 size_t *olen); /* output length */ 99 DOHcode doh_decode(unsigned char *doh, 100 size_t dohlen, 101 DNStype dnstype, 102 struct dohentry *d); 103 void de_cleanup(struct dohentry *d); 104 #endif 105 #endif /* HEADER_CURL_DOH_H */ 106