doh.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef HEADER_CURL_DOH_H
  2. #define HEADER_CURL_DOH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2018 - 2022, 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.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. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "urldata.h"
  27. #include "curl_addrinfo.h"
  28. #ifndef CURL_DISABLE_DOH
  29. typedef enum {
  30. DOH_OK,
  31. DOH_DNS_BAD_LABEL, /* 1 */
  32. DOH_DNS_OUT_OF_RANGE, /* 2 */
  33. DOH_DNS_LABEL_LOOP, /* 3 */
  34. DOH_TOO_SMALL_BUFFER, /* 4 */
  35. DOH_OUT_OF_MEM, /* 5 */
  36. DOH_DNS_RDATA_LEN, /* 6 */
  37. DOH_DNS_MALFORMAT, /* 7 */
  38. DOH_DNS_BAD_RCODE, /* 8 - no such name */
  39. DOH_DNS_UNEXPECTED_TYPE, /* 9 */
  40. DOH_DNS_UNEXPECTED_CLASS, /* 10 */
  41. DOH_NO_CONTENT, /* 11 */
  42. DOH_DNS_BAD_ID, /* 12 */
  43. DOH_DNS_NAME_TOO_LONG /* 13 */
  44. } DOHcode;
  45. typedef enum {
  46. DNS_TYPE_A = 1,
  47. DNS_TYPE_NS = 2,
  48. DNS_TYPE_CNAME = 5,
  49. DNS_TYPE_AAAA = 28,
  50. DNS_TYPE_DNAME = 39 /* RFC6672 */
  51. } DNStype;
  52. /* one of these for each DoH request */
  53. struct dnsprobe {
  54. CURL *easy;
  55. DNStype dnstype;
  56. unsigned char dohbuffer[512];
  57. size_t dohlen;
  58. struct dynbuf serverdoh;
  59. };
  60. struct dohdata {
  61. struct curl_slist *headers;
  62. struct dnsprobe probe[DOH_PROBE_SLOTS];
  63. unsigned int pending; /* still outstanding requests */
  64. int port;
  65. const char *host;
  66. };
  67. /*
  68. * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name
  69. * and returns a 'Curl_addrinfo *' with the address information.
  70. */
  71. struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
  72. const char *hostname,
  73. int port,
  74. int *waitp);
  75. CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
  76. struct Curl_dns_entry **dns);
  77. int Curl_doh_getsock(struct connectdata *conn, curl_socket_t *socks);
  78. #define DOH_MAX_ADDR 24
  79. #define DOH_MAX_CNAME 4
  80. struct dohaddr {
  81. int type;
  82. union {
  83. unsigned char v4[4]; /* network byte order */
  84. unsigned char v6[16];
  85. } ip;
  86. };
  87. struct dohentry {
  88. struct dynbuf cname[DOH_MAX_CNAME];
  89. struct dohaddr addr[DOH_MAX_ADDR];
  90. int numaddr;
  91. unsigned int ttl;
  92. int numcname;
  93. };
  94. #ifdef DEBUGBUILD
  95. DOHcode doh_encode(const char *host,
  96. DNStype dnstype,
  97. unsigned char *dnsp, /* buffer */
  98. size_t len, /* buffer size */
  99. size_t *olen); /* output length */
  100. DOHcode doh_decode(const unsigned char *doh,
  101. size_t dohlen,
  102. DNStype dnstype,
  103. struct dohentry *d);
  104. void de_init(struct dohentry *d);
  105. void de_cleanup(struct dohentry *d);
  106. #endif
  107. #else /* if DoH is disabled */
  108. #define Curl_doh(a,b,c,d) NULL
  109. #define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
  110. #endif
  111. #endif /* HEADER_CURL_DOH_H */