Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dns_resolve.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2017 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_DNS_RESOLVE_H_
14#define ZEPHYR_INCLUDE_NET_DNS_RESOLVE_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/net/net_ip.h>
19#include <zephyr/net/net_core.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
40};
41
43#ifndef DNS_MAX_NAME_SIZE
44#define DNS_MAX_NAME_SIZE 20
45#endif
46
49/* Make sure that we can compile things even if CONFIG_DNS_RESOLVER
50 * is not enabled.
51 */
52#if !defined(CONFIG_DNS_RESOLVER_MAX_SERVERS)
53#define CONFIG_DNS_RESOLVER_MAX_SERVERS 1
54#endif
55#if !defined(CONFIG_DNS_NUM_CONCUR_QUERIES)
56#define CONFIG_DNS_NUM_CONCUR_QUERIES 1
57#endif
58
59/* If mDNS is enabled, then add some extra well known multicast servers to the
60 * server list.
61 */
62#if defined(CONFIG_MDNS_RESOLVER)
63#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
64#define MDNS_SERVER_COUNT 2
65#else
66#define MDNS_SERVER_COUNT 1
67#endif /* CONFIG_NET_IPV6 && CONFIG_NET_IPV4 */
68#else
69#define MDNS_SERVER_COUNT 0
70#endif /* CONFIG_MDNS_RESOLVER */
71
72/* If LLMNR is enabled, then add some extra well known multicast servers to the
73 * server list.
74 */
75#if defined(CONFIG_LLMNR_RESOLVER)
76#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
77#define LLMNR_SERVER_COUNT 2
78#else
79#define LLMNR_SERVER_COUNT 1
80#endif /* CONFIG_NET_IPV6 && CONFIG_NET_IPV4 */
81#else
82#define LLMNR_SERVER_COUNT 0
83#endif /* CONFIG_MDNS_RESOLVER */
84
85#define DNS_MAX_MCAST_SERVERS (MDNS_SERVER_COUNT + LLMNR_SERVER_COUNT)
86
101};
102
141};
142
162typedef void (*dns_resolve_cb_t)(enum dns_resolve_status status,
163 struct dns_addrinfo *info,
164 void *user_data);
165
168enum dns_resolve_context_state {
169 DNS_RESOLVE_CONTEXT_ACTIVE,
170 DNS_RESOLVE_CONTEXT_DEACTIVATING,
171 DNS_RESOLVE_CONTEXT_INACTIVE,
172};
173
181 struct {
184
186 int sock;
187
190
193 } servers[CONFIG_DNS_RESOLVER_MAX_SERVERS + DNS_MAX_MCAST_SERVERS];
194
196#if (IS_ENABLED(CONFIG_NET_IPV6) && IS_ENABLED(CONFIG_NET_IPV4))
197#define DNS_RESOLVER_MAX_POLL (2 * (CONFIG_DNS_RESOLVER_MAX_SERVERS + DNS_MAX_MCAST_SERVERS))
198#else
199#define DNS_RESOLVER_MAX_POLL (1 * (CONFIG_DNS_RESOLVER_MAX_SERVERS + DNS_MAX_MCAST_SERVERS))
200#endif
202 struct zsock_pollfd fds[DNS_RESOLVER_MAX_POLL];
206 struct k_mutex lock;
207
212
222
225
231
234
237
249 const char *query;
250
253
256
264 } queries[CONFIG_DNS_NUM_CONCUR_QUERIES];
265
267 enum dns_resolve_context_state state;
268};
269
298 const char *dns_servers_str[],
299 const struct sockaddr *dns_servers_sa[]);
300
309
321
342 const char *servers_str[],
343 const struct sockaddr *servers_sa[]);
344
356 uint16_t dns_id);
357
371 uint16_t dns_id,
372 const char *query_name,
373 enum dns_query_type query_type);
374
403 const char *query,
404 enum dns_query_type type,
405 uint16_t *dns_id,
407 void *user_data,
408 int32_t timeout);
409
421
449static inline int dns_get_addr_info(const char *query,
450 enum dns_query_type type,
451 uint16_t *dns_id,
453 void *user_data,
454 int32_t timeout)
455{
457 query,
458 type,
459 dns_id,
460 cb,
461 user_data,
462 timeout);
463}
464
474static inline int dns_cancel_addr_info(uint16_t dns_id)
475{
477}
478
488#if defined(CONFIG_DNS_RESOLVER_AUTO_INIT)
489void dns_init_resolver(void);
490
491#else
492#define dns_init_resolver(...)
493#endif /* CONFIG_DNS_RESOLVER_AUTO_INIT */
494
497#ifdef __cplusplus
498}
499#endif
500
501#endif /* ZEPHYR_INCLUDE_NET_DNS_RESOLVE_H_ */
int dns_resolve_name(struct dns_resolve_context *ctx, const char *query, enum dns_query_type type, uint16_t *dns_id, dns_resolve_cb_t cb, void *user_data, int32_t timeout)
Resolve DNS name.
static int dns_cancel_addr_info(uint16_t dns_id)
Cancel a pending DNS query.
Definition: dns_resolve.h:474
dns_resolve_status
Status values for the callback.
Definition: dns_resolve.h:106
dns_query_type
DNS query type enum.
Definition: dns_resolve.h:35
int dns_resolve_init_default(struct dns_resolve_context *ctx)
Init DNS resolving context with default Kconfig options.
int dns_resolve_init(struct dns_resolve_context *ctx, const char *dns_servers_str[], const struct sockaddr *dns_servers_sa[])
Init DNS resolving context.
int dns_resolve_cancel(struct dns_resolve_context *ctx, uint16_t dns_id)
Cancel a pending DNS query.
void(* dns_resolve_cb_t)(enum dns_resolve_status status, struct dns_addrinfo *info, void *user_data)
DNS resolve callback.
Definition: dns_resolve.h:162
int dns_resolve_reconfigure(struct dns_resolve_context *ctx, const char *servers_str[], const struct sockaddr *servers_sa[])
Reconfigure DNS resolving context.
int dns_resolve_close(struct dns_resolve_context *ctx)
Close DNS resolving context.
#define DNS_MAX_NAME_SIZE
Max size of the resolved name.
Definition: dns_resolve.h:44
struct dns_resolve_context * dns_resolve_get_default(void)
Get default DNS context.
int dns_resolve_cancel_with_name(struct dns_resolve_context *ctx, uint16_t dns_id, const char *query_name, enum dns_query_type query_type)
Cancel a pending DNS query using id, name and type.
static int dns_get_addr_info(const char *query, enum dns_query_type type, uint16_t *dns_id, dns_resolve_cb_t cb, void *user_data, int32_t timeout)
Get IP address info from DNS.
Definition: dns_resolve.h:449
@ DNS_EAI_MEMORY
Memory allocation failure.
Definition: dns_resolve.h:126
@ DNS_EAI_NOTCANCELED
Request not canceled.
Definition: dns_resolve.h:136
@ DNS_EAI_IDN_ENCODE
IDN encoding failed.
Definition: dns_resolve.h:140
@ DNS_EAI_ADDRFAMILY
Address family for NAME not supported.
Definition: dns_resolve.h:124
@ DNS_EAI_INPROGRESS
Processing request in progress.
Definition: dns_resolve.h:132
@ DNS_EAI_FAIL
Non-recoverable failure in name res.
Definition: dns_resolve.h:114
@ DNS_EAI_AGAIN
Temporary failure in name resolution.
Definition: dns_resolve.h:112
@ DNS_EAI_NODATA
No address associated with NAME.
Definition: dns_resolve.h:116
@ DNS_EAI_NONAME
NAME or SERVICE is unknown.
Definition: dns_resolve.h:110
@ DNS_EAI_FAMILY
‘ai_family’ not supported
Definition: dns_resolve.h:118
@ DNS_EAI_OVERFLOW
Argument buffer overflow.
Definition: dns_resolve.h:130
@ DNS_EAI_CANCELED
Request canceled.
Definition: dns_resolve.h:134
@ DNS_EAI_BADFLAGS
Invalid value for ‘ai_flags’ field.
Definition: dns_resolve.h:108
@ DNS_EAI_SOCKTYPE
‘ai_socktype’ not supported
Definition: dns_resolve.h:120
@ DNS_EAI_ALLDONE
All requests done.
Definition: dns_resolve.h:138
@ DNS_EAI_SYSTEM
System error returned in ‘errno’.
Definition: dns_resolve.h:128
@ DNS_EAI_SERVICE
SRV not supported for ‘ai_socktype’.
Definition: dns_resolve.h:122
@ DNS_QUERY_TYPE_A
IPv4 query.
Definition: dns_resolve.h:37
@ DNS_QUERY_TYPE_AAAA
IPv6 query.
Definition: dns_resolve.h:39
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
Public kernel APIs.
Network core definitions.
IPv6 and IPv4 definitions.
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Address info struct is passed to callback that gets all the results.
Definition: dns_resolve.h:92
char ai_canonname[20+1]
Canonical name of the address.
Definition: dns_resolve.h:100
struct sockaddr ai_addr
IP address information.
Definition: dns_resolve.h:94
socklen_t ai_addrlen
Length of the ai_addr field.
Definition: dns_resolve.h:96
uint8_t ai_family
Address family of the address information.
Definition: dns_resolve.h:98
Result callbacks.
Definition: dns_resolve.h:219
const char * query
String containing the thing to resolve like www.example.com.
Definition: dns_resolve.h:249
uint16_t query_hash
Hash of the DNS name + query type we are querying.
Definition: dns_resolve.h:263
struct dns_resolve_context * ctx
Back pointer to ctx, needed in timeout handler.
Definition: dns_resolve.h:224
void * user_data
User data.
Definition: dns_resolve.h:233
struct k_work_delayable timer
Timeout timer.
Definition: dns_resolve.h:221
uint16_t id
DNS id of this query.
Definition: dns_resolve.h:255
k_timeout_t timeout
TX timeout.
Definition: dns_resolve.h:236
dns_resolve_cb_t cb
Result callback.
Definition: dns_resolve.h:230
enum dns_query_type query_type
Query type.
Definition: dns_resolve.h:252
DNS resolve context structure.
Definition: dns_resolve.h:179
struct dns_resolve_context::dns_pending_query queries[CONFIG_DNS_NUM_CONCUR_QUERIES]
k_timeout_t buf_timeout
This timeout is also used when a buffer is required from the buffer pools.
Definition: dns_resolve.h:211
uint8_t is_llmnr
Is this server LLMNR one.
Definition: dns_resolve.h:192
struct dns_resolve_context::@284 servers[CONFIG_DNS_RESOLVER_MAX_SERVERS+DNS_MAX_MCAST_SERVERS]
List of configured DNS servers.
enum dns_resolve_context_state state
Is this context in use.
Definition: dns_resolve.h:267
struct k_mutex lock
Prevent concurrent access.
Definition: dns_resolve.h:206
uint8_t is_mdns
Is this server mDNS one.
Definition: dns_resolve.h:189
int sock
Connection to the DNS server.
Definition: dns_resolve.h:186
struct sockaddr dns_server
DNS server information.
Definition: dns_resolve.h:183
Mutex Structure.
Definition: kernel.h:2914
Kernel timeout type.
Definition: sys_clock.h:65
A structure used to submit work after a delay.
Definition: kernel.h:3903
Generic sockaddr struct.
Definition: net_ip.h:385
Definition of the monitored socket/file descriptor.
Definition: socket_poll.h:28