Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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/net/net_ip.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
38};
39
41#ifndef DNS_MAX_NAME_SIZE
42#define DNS_MAX_NAME_SIZE 20
43#endif
44
47/* Make sure that we can compile things even if CONFIG_DNS_RESOLVER
48 * is not enabled.
49 */
50#if !defined(CONFIG_DNS_RESOLVER_MAX_SERVERS)
51#define CONFIG_DNS_RESOLVER_MAX_SERVERS 1
52#endif
53#if !defined(CONFIG_DNS_NUM_CONCUR_QUERIES)
54#define CONFIG_DNS_NUM_CONCUR_QUERIES 1
55#endif
56
57/* If mDNS is enabled, then add some extra well known multicast servers to the
58 * server list.
59 */
60#if defined(CONFIG_MDNS_RESOLVER)
61#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
62#define MDNS_SERVER_COUNT 2
63#else
64#define MDNS_SERVER_COUNT 1
65#endif /* CONFIG_NET_IPV6 && CONFIG_NET_IPV4 */
66#else
67#define MDNS_SERVER_COUNT 0
68#endif /* CONFIG_MDNS_RESOLVER */
69
70/* If LLMNR is enabled, then add some extra well known multicast servers to the
71 * server list.
72 */
73#if defined(CONFIG_LLMNR_RESOLVER)
74#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
75#define LLMNR_SERVER_COUNT 2
76#else
77#define LLMNR_SERVER_COUNT 1
78#endif /* CONFIG_NET_IPV6 && CONFIG_NET_IPV4 */
79#else
80#define LLMNR_SERVER_COUNT 0
81#endif /* CONFIG_MDNS_RESOLVER */
82
83#define DNS_MAX_MCAST_SERVERS (MDNS_SERVER_COUNT + LLMNR_SERVER_COUNT)
84
95};
96
135};
136
156typedef void (*dns_resolve_cb_t)(enum dns_resolve_status status,
157 struct dns_addrinfo *info,
158 void *user_data);
159
164};
165
170 struct {
173
176
179
182 } servers[CONFIG_DNS_RESOLVER_MAX_SERVERS + DNS_MAX_MCAST_SERVERS];
183
185 struct k_mutex lock;
186
191
201
204
210
213
216
228 const char *query;
229
232
235
243 } queries[CONFIG_DNS_NUM_CONCUR_QUERIES];
244
247};
248
277 const char *dns_servers_str[],
278 const struct sockaddr *dns_servers_sa[]);
279
291
312 const char *servers_str[],
313 const struct sockaddr *servers_sa[]);
314
326 uint16_t dns_id);
327
341 uint16_t dns_id,
342 const char *query_name,
343 enum dns_query_type query_type);
344
373 const char *query,
374 enum dns_query_type type,
375 uint16_t *dns_id,
377 void *user_data,
378 int32_t timeout);
379
391
419static inline int dns_get_addr_info(const char *query,
420 enum dns_query_type type,
421 uint16_t *dns_id,
423 void *user_data,
424 int32_t timeout)
425{
427 query,
428 type,
429 dns_id,
430 cb,
431 user_data,
432 timeout);
433}
434
444static inline int dns_cancel_addr_info(uint16_t dns_id)
445{
447}
448
458#if defined(CONFIG_DNS_RESOLVER)
459void dns_init_resolver(void);
460
461#else
462#define dns_init_resolver(...)
463#endif /* CONFIG_DNS_RESOLVER */
464
467#ifdef __cplusplus
468}
469#endif
470
471#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:444
dns_resolve_status
Status values for the callback.
Definition: dns_resolve.h:100
dns_query_type
DNS query type enum.
Definition: dns_resolve.h:33
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:156
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:42
struct dns_resolve_context * dns_resolve_get_default(void)
Get default DNS context.
dns_resolve_context_state
Definition: dns_resolve.h:160
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:419
@ DNS_EAI_MEMORY
Memory allocation failure.
Definition: dns_resolve.h:120
@ DNS_EAI_NOTCANCELED
Request not canceled.
Definition: dns_resolve.h:130
@ DNS_EAI_IDN_ENCODE
IDN encoding failed.
Definition: dns_resolve.h:134
@ DNS_EAI_ADDRFAMILY
Address family for NAME not supported.
Definition: dns_resolve.h:118
@ DNS_EAI_INPROGRESS
Processing request in progress.
Definition: dns_resolve.h:126
@ DNS_EAI_FAIL
Non-recoverable failure in name res.
Definition: dns_resolve.h:108
@ DNS_EAI_AGAIN
Temporary failure in name resolution.
Definition: dns_resolve.h:106
@ DNS_EAI_NODATA
No address associated with NAME.
Definition: dns_resolve.h:110
@ DNS_EAI_NONAME
NAME or SERVICE is unknown.
Definition: dns_resolve.h:104
@ DNS_EAI_FAMILY
‘ai_family’ not supported
Definition: dns_resolve.h:112
@ DNS_EAI_OVERFLOW
Argument buffer overflow.
Definition: dns_resolve.h:124
@ DNS_EAI_CANCELED
Request canceled.
Definition: dns_resolve.h:128
@ DNS_EAI_BADFLAGS
Invalid value for ‘ai_flags’ field.
Definition: dns_resolve.h:102
@ DNS_EAI_SOCKTYPE
‘ai_socktype’ not supported
Definition: dns_resolve.h:114
@ DNS_EAI_ALLDONE
All requests done.
Definition: dns_resolve.h:132
@ DNS_EAI_SYSTEM
System error returned in ‘errno’.
Definition: dns_resolve.h:122
@ DNS_EAI_SERVICE
SRV not supported for ‘ai_socktype’.
Definition: dns_resolve.h:116
@ DNS_QUERY_TYPE_A
IPv4 query.
Definition: dns_resolve.h:35
@ DNS_QUERY_TYPE_AAAA
IPv6 query.
Definition: dns_resolve.h:37
@ DNS_RESOLVE_CONTEXT_INACTIVE
Definition: dns_resolve.h:163
@ DNS_RESOLVE_CONTEXT_DEACTIVATING
Definition: dns_resolve.h:162
@ DNS_RESOLVE_CONTEXT_ACTIVE
Definition: dns_resolve.h:161
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
Network context 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:90
char ai_canonname[20+1]
Definition: dns_resolve.h:94
struct sockaddr ai_addr
Definition: dns_resolve.h:91
socklen_t ai_addrlen
Definition: dns_resolve.h:92
uint8_t ai_family
Definition: dns_resolve.h:93
Result callbacks.
Definition: dns_resolve.h:198
const char * query
String containing the thing to resolve like www.example.com.
Definition: dns_resolve.h:228
uint16_t query_hash
Hash of the DNS name + query type we are querying.
Definition: dns_resolve.h:242
struct dns_resolve_context * ctx
Back pointer to ctx, needed in timeout handler.
Definition: dns_resolve.h:203
void * user_data
User data.
Definition: dns_resolve.h:212
struct k_work_delayable timer
Timeout timer.
Definition: dns_resolve.h:200
uint16_t id
DNS id of this query.
Definition: dns_resolve.h:234
k_timeout_t timeout
TX timeout.
Definition: dns_resolve.h:215
dns_resolve_cb_t cb
Result callback.
Definition: dns_resolve.h:209
enum dns_query_type query_type
Query type.
Definition: dns_resolve.h:231
DNS resolve context structure.
Definition: dns_resolve.h:169
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:190
uint8_t is_llmnr
Is this server LLMNR one.
Definition: dns_resolve.h:181
enum dns_resolve_context_state state
Is this context in use.
Definition: dns_resolve.h:246
struct k_mutex lock
Prevent concurrent access.
Definition: dns_resolve.h:185
uint8_t is_mdns
Is this server mDNS one.
Definition: dns_resolve.h:178
struct net_context * net_ctx
Connection to the DNS server.
Definition: dns_resolve.h:175
struct sockaddr dns_server
DNS server information.
Definition: dns_resolve.h:172
struct dns_resolve_context::@259 servers[CONFIG_DNS_RESOLVER_MAX_SERVERS+DNS_MAX_MCAST_SERVERS]
Mutex Structure.
Definition: kernel.h:2911
Kernel timeout type.
Definition: sys_clock.h:65
A structure used to submit work after a delay.
Definition: kernel.h:3893
Note that we do not store the actual source IP address in the context because the address is already ...
Definition: net_context.h:201
Generic sockaddr struct.
Definition: net_ip.h:347