2018-09-06 15:16:02 +08:00
|
|
|
#ifndef HEADER_CURL_DOH_H
|
|
|
|
#define HEADER_CURL_DOH_H
|
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2021-01-20 17:15:43 +08:00
|
|
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2018-09-06 15:16:02 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2018-09-06 15:16:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2018-09-06 15:16:02 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "urldata.h"
|
|
|
|
#include "curl_addrinfo.h"
|
|
|
|
|
2019-05-05 23:08:21 +08:00
|
|
|
#ifndef CURL_DISABLE_DOH
|
|
|
|
|
2018-06-19 22:08:05 +08:00
|
|
|
typedef enum {
|
|
|
|
DOH_OK,
|
|
|
|
DOH_DNS_BAD_LABEL, /* 1 */
|
|
|
|
DOH_DNS_OUT_OF_RANGE, /* 2 */
|
|
|
|
DOH_DNS_LABEL_LOOP, /* 3 */
|
|
|
|
DOH_TOO_SMALL_BUFFER, /* 4 */
|
|
|
|
DOH_OUT_OF_MEM, /* 5 */
|
|
|
|
DOH_DNS_RDATA_LEN, /* 6 */
|
|
|
|
DOH_DNS_MALFORMAT, /* 7 */
|
|
|
|
DOH_DNS_BAD_RCODE, /* 8 - no such name */
|
|
|
|
DOH_DNS_UNEXPECTED_TYPE, /* 9 */
|
|
|
|
DOH_DNS_UNEXPECTED_CLASS, /* 10 */
|
|
|
|
DOH_NO_CONTENT, /* 11 */
|
2019-11-15 03:21:09 +08:00
|
|
|
DOH_DNS_BAD_ID, /* 12 */
|
|
|
|
DOH_DNS_NAME_TOO_LONG /* 13 */
|
2018-06-19 22:08:05 +08:00
|
|
|
} DOHcode;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
DNS_TYPE_A = 1,
|
|
|
|
DNS_TYPE_NS = 2,
|
|
|
|
DNS_TYPE_CNAME = 5,
|
2019-11-15 03:21:09 +08:00
|
|
|
DNS_TYPE_AAAA = 28,
|
|
|
|
DNS_TYPE_DNAME = 39 /* RFC6672 */
|
2018-06-19 22:08:05 +08:00
|
|
|
} DNStype;
|
|
|
|
|
2022-07-18 05:58:43 +08:00
|
|
|
/* one of these for each DoH request */
|
|
|
|
struct dnsprobe {
|
|
|
|
CURL *easy;
|
|
|
|
DNStype dnstype;
|
|
|
|
unsigned char dohbuffer[512];
|
|
|
|
size_t dohlen;
|
|
|
|
struct dynbuf serverdoh;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dohdata {
|
|
|
|
struct curl_slist *headers;
|
|
|
|
struct dnsprobe probe[DOH_PROBE_SLOTS];
|
|
|
|
unsigned int pending; /* still outstanding requests */
|
|
|
|
int port;
|
|
|
|
const char *host;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name
|
|
|
|
* and returns a 'Curl_addrinfo *' with the address information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
|
|
|
|
const char *hostname,
|
|
|
|
int port,
|
|
|
|
int *waitp);
|
|
|
|
|
|
|
|
CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
|
|
|
|
struct Curl_dns_entry **dns);
|
|
|
|
|
|
|
|
int Curl_doh_getsock(struct connectdata *conn, curl_socket_t *socks);
|
|
|
|
|
2018-06-19 22:08:05 +08:00
|
|
|
#define DOH_MAX_ADDR 24
|
|
|
|
#define DOH_MAX_CNAME 4
|
|
|
|
|
|
|
|
struct dohaddr {
|
|
|
|
int type;
|
|
|
|
union {
|
2018-10-04 17:57:29 +08:00
|
|
|
unsigned char v4[4]; /* network byte order */
|
|
|
|
unsigned char v6[16];
|
2018-06-19 22:08:05 +08:00
|
|
|
} ip;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dohentry {
|
2020-05-02 23:04:08 +08:00
|
|
|
struct dynbuf cname[DOH_MAX_CNAME];
|
2018-06-19 22:08:05 +08:00
|
|
|
struct dohaddr addr[DOH_MAX_ADDR];
|
2020-05-02 23:04:08 +08:00
|
|
|
int numaddr;
|
|
|
|
unsigned int ttl;
|
2018-06-19 22:08:05 +08:00
|
|
|
int numcname;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGBUILD
|
|
|
|
DOHcode doh_encode(const char *host,
|
|
|
|
DNStype dnstype,
|
|
|
|
unsigned char *dnsp, /* buffer */
|
|
|
|
size_t len, /* buffer size */
|
|
|
|
size_t *olen); /* output length */
|
2020-04-27 18:07:34 +08:00
|
|
|
DOHcode doh_decode(const unsigned char *doh,
|
2018-06-19 22:08:05 +08:00
|
|
|
size_t dohlen,
|
|
|
|
DNStype dnstype,
|
|
|
|
struct dohentry *d);
|
2020-05-02 23:04:08 +08:00
|
|
|
void de_init(struct dohentry *d);
|
2018-06-19 22:08:05 +08:00
|
|
|
void de_cleanup(struct dohentry *d);
|
|
|
|
#endif
|
2019-05-05 23:08:21 +08:00
|
|
|
|
2021-07-16 15:17:03 +08:00
|
|
|
#else /* if DoH is disabled */
|
2019-05-05 23:08:21 +08:00
|
|
|
#define Curl_doh(a,b,c,d) NULL
|
|
|
|
#define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
|
|
|
|
#endif
|
|
|
|
|
2018-10-23 16:02:24 +08:00
|
|
|
#endif /* HEADER_CURL_DOH_H */
|