libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-async-dns.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#if defined(LWS_WITH_UDP) && defined(LWS_WITH_NETWORK)
26
27typedef enum dns_query_type {
28 LWS_ADNS_RECORD_A = 0x01,
29 LWS_ADNS_RECORD_CNAME = 0x05,
30 LWS_ADNS_RECORD_SOA = 0x06,
31 LWS_ADNS_RECORD_MX = 0x0f,
32 LWS_ADNS_RECORD_TXT = 0x10,
33 LWS_ADNS_RECORD_AAAA = 0x1c,
34 LWS_ADNS_RECORD_DS = 0x2b,
35 LWS_ADNS_RECORD_RRSIG = 0x2e,
36 LWS_ADNS_RECORD_NSEC = 0x2f,
37 LWS_ADNS_RECORD_DNSKEY = 0x30,
38 LWS_ADNS_RECORD_NSEC3 = 0x32,
39 LWS_ADNS_RECORD_HTTPS = 0x41,
40
41 /*
42 * Query types are combined by OR with the flag bits defined below
43 * the enum (LWS_ADNS_SYNTHETIC .. LWS_ADNS_IGNORE_HOSTS_FILE; the
44 * largest possible combination is 0x1f0041). A C enum can only
45 * hold values within the range of its listed constants, so this
46 * sentinel extends the enum's range over the whole flag space...
47 * without it, any OR'd combination is undefined behaviour, which
48 * -fsanitize=enum trips on.
49 */
50
51 LWS_ADNS_RECORD_TYPE_AND_FLAGS_MAX = 0x1f0041,
52} adns_query_type_t;
53
54typedef enum {
55 LADNS_RET_FAILED_WSI_CLOSED = -4,
56 LADNS_RET_NXDOMAIN = -3,
57 LADNS_RET_TIMEDOUT = -2,
58 LADNS_RET_FAILED = -1,
59 LADNS_RET_FOUND,
60 LADNS_RET_CONTINUING
61} lws_async_dns_retcode_t;
62
63typedef enum {
64 LWS_ADNS_DNSSEC_OFF = 0,
65 LWS_ADNS_DNSSEC_TOLERATE,
66 LWS_ADNS_DNSSEC_REQUIRE,
67} lws_async_dns_dnssec_mode_t;
68
69#define LWS_ADNS_DNSSEC_VALID (1 << 8)
70#define LWS_ADNS_DNSSEC_INVALID (1 << 9)
71
72#define LWS_ADNS_SYNTHETIC 0x10000 /* don't send, synthetic response will
73 * be injected for testing */
74#define LWS_ADNS_INDICATE_LACKS_DNSSEC 0x20000 /* tolerate missing DNSSEC on this specific lookup */
75#define LWS_ADNS_NOCACHE 0x40000 /* force network query, bypass cache */
76#define LWS_ADNS_WANT_DNSSEC 0x80000 /* Explicitly set DO bit in EDNS0 OPT record */
77#define LWS_ADNS_IGNORE_HOSTS_FILE 0x100000 /* Bypass checking /etc/hosts and force network DNS lookup */
78#define LADNS_NO_WSI_BUT_OK ((struct lws *)(intptr_t)0x1)
79
80struct addrinfo;
81
82typedef struct lws * (*lws_async_dns_cb_t)(struct lws *wsi, const char *ads,
83 const struct addrinfo *result, int n, void *opaque);
84
85struct lws_adns_q;
86struct lws_async_dns;
87struct lws_async_dns_server;
88
110LWS_VISIBLE LWS_EXTERN lws_async_dns_retcode_t
111lws_async_dns_query(struct lws_context *context, int tsi, const char *name,
112 adns_query_type_t qtype, lws_async_dns_cb_t cb,
113 struct lws *wsi, void *opaque, struct lws_adns_q **pq);
114
126lws_async_dns_freeaddrinfo(const struct addrinfo **ai);
127
141lws_async_dns_get_rr_cache(struct lws_context *context, const char *name,
142 adns_query_type_t qtype, uint16_t *paylen);
143
155lws_async_dns_get_alpn(struct lws_context *context, const char *name, const char *alpn);
156
168lws_async_dns_server_add(struct lws_context *cx, const lws_sockaddr46 *sa46);
169
182lws_async_dns_server_remove(struct lws_context *cx, const lws_sockaddr46 *sa46);
183
184/* only needed for testing */
185
187lws_adns_get_tid(struct lws_adns_q *q);
188LWS_VISIBLE LWS_EXTERN struct lws_async_dns *
189lws_adns_get_async_dns(struct lws_adns_q *q);
190
191LWS_VISIBLE LWS_EXTERN struct lws_async_dns_server *
192lws_adns_get_server(struct lws_adns_q *q);
193
195lws_adns_parse_udp(struct lws_async_dns *dns, const uint8_t *pkt, size_t len,
196 struct lws_async_dns_server *dsrv);
197
210lws_plat_asyncdns_get_server(struct lws_context *context, int n,
211 lws_sockaddr46 *sa46);
212
222lws_async_dns_server_reload(struct lws_context *context);
223
224
234lws_async_dns_dnssec_set_mode(struct lws_context *context, lws_async_dns_dnssec_mode_t mode);
235
236#endif
unsigned short uint16_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE