dns_client.c
Go to the documentation of this file.
1 /**
2  * @file dns_client.c
3  * @brief DNS client (Domain Name System)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.2.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL DNS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_cache.h"
37 #include "dns/dns_client.h"
38 #include "dns/dns_common.h"
39 #include "dns/dns_debug.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (DNS_CLIENT_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Resolve a host name using DNS
48  * @param[in] interface Underlying network interface
49  * @param[in] name Name of the host to be resolved
50  * @param[in] type Host type (IPv4 or IPv6)
51  * @param[out] ipAddr IP address corresponding to the specified host name
52  **/
53 
56 {
57  error_t error;
58  DnsCacheEntry *entry;
59 
60 #if (NET_RTOS_SUPPORT == ENABLED)
61  systime_t delay;
62 
63  //Debug message
64  TRACE_INFO("Resolving host name %s (DNS resolver)...\r\n", name);
65 #endif
66 
67  //Get exclusive access
69 
70  //Search the DNS cache for the specified host name
71  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_DNS);
72 
73  //Check whether a matching entry has been found
74  if(entry)
75  {
76  //Host name already resolved?
77  if(entry->state == DNS_STATE_RESOLVED ||
78  entry->state == DNS_STATE_PERMANENT)
79  {
80  //Return the corresponding IP address
81  *ipAddr = entry->ipAddr;
82  //Successful host name resolution
83  error = NO_ERROR;
84  }
85  else
86  {
87  //Host name resolution is in progress
88  error = ERROR_IN_PROGRESS;
89  }
90  }
91  else
92  {
93  //If no entry exists, then create a new one
94  entry = dnsCreateEntry();
95 
96  //Record the host name whose IP address is unknown
97  osStrcpy(entry->name, name);
98 
99  //Initialize DNS cache entry
100  entry->type = type;
102  entry->interface = interface;
103  //Select primary DNS server
104  entry->dnsServerIndex = 0;
105 
106  //Get an ephemeral port number
107  entry->port = udpGetDynamicPort();
108 
109  //An identifier is used by the DNS client to match replies
110  //with corresponding requests
111  entry->id = (uint16_t) netGenerateRand();
112 
113  //Callback function to be called when a DNS response is received
114  error = udpAttachRxCallback(interface, entry->port, dnsProcessResponse,
115  NULL);
116 
117  //Check status code
118  if(!error)
119  {
120  //Initialize retransmission counter
122  //Send DNS query
123  error = dnsSendQuery(entry);
124 
125  //DNS message successfully sent?
126  if(!error)
127  {
128  //Save the time at which the query message was sent
129  entry->timestamp = osGetSystemTime();
130  //Set timeout value
133  //Decrement retransmission counter
134  entry->retransmitCount--;
135 
136  //Switch state
137  entry->state = DNS_STATE_IN_PROGRESS;
138  //Host name resolution is in progress
139  error = ERROR_IN_PROGRESS;
140  }
141  else
142  {
143  //Unregister callback function
144  udpDetachRxCallback(interface, entry->port);
145  }
146  }
147  }
148 
149  //Release exclusive access
151 
152 #if (NET_RTOS_SUPPORT == ENABLED)
153  //Set default polling interval
155 
156  //Wait the host name resolution to complete
157  while(error == ERROR_IN_PROGRESS)
158  {
159  //Wait until the next polling period
160  osDelayTask(delay);
161 
162  //Get exclusive access
164 
165  //Search the DNS cache for the specified host name
166  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_DNS);
167 
168  //Check whether a matching entry has been found
169  if(entry)
170  {
171  //Host name successfully resolved?
172  if(entry->state == DNS_STATE_RESOLVED)
173  {
174  //Return the corresponding IP address
175  *ipAddr = entry->ipAddr;
176  //Successful host name resolution
177  error = NO_ERROR;
178  }
179  }
180  else
181  {
182  //Host name resolution failed
183  error = ERROR_FAILURE;
184  }
185 
186  //Release exclusive access
188 
189  //Backoff support for less aggressive polling
190  delay = MIN(delay * 2, DNS_CACHE_MAX_POLLING_INTERVAL);
191  }
192 
193  //Check status code
194  if(error)
195  {
196  //Failed to resolve host name
197  TRACE_INFO("Host name resolution failed!\r\n");
198  }
199  else
200  {
201  //Successful host name resolution
202  TRACE_INFO("Host name resolved to %s...\r\n", ipAddrToString(ipAddr, NULL));
203  }
204 #endif
205 
206  //Return status code
207  return error;
208 }
209 
210 
211 /**
212  * @brief Send a DNS query message
213  * @param[in] entry Pointer to a valid DNS cache entry
214  * @return Error code
215  **/
216 
218 {
219  error_t error;
220  size_t length;
221  size_t offset;
222  NetBuffer *buffer;
224  DnsQuestion *dnsQuestion;
226  NetTxAncillary ancillary;
227 
228 #if (IPV4_SUPPORT == ENABLED)
229  //An IPv4 address is expected?
230  if(entry->type == HOST_TYPE_IPV4)
231  {
232  //Point to the IPv4 context
233  Ipv4Context *ipv4Context = &entry->interface->ipv4Context;
234 
235  //Select the relevant DNS server
236  while(1)
237  {
238  //Out of range index?
240  return ERROR_NO_DNS_SERVER;
241 
242  //Copy the address of the DNS server
243  destIpAddr.length = sizeof(Ipv4Addr);
244  destIpAddr.ipv4Addr = ipv4Context->dnsServerList[entry->dnsServerIndex];
245 
246  //Make sure the IP address is valid
247  if(destIpAddr.ipv4Addr != IPV4_UNSPECIFIED_ADDR)
248  break;
249 
250  //Select the next DNS server in the list
251  entry->dnsServerIndex++;
252  }
253  }
254  else
255 #endif
256 #if (IPV6_SUPPORT == ENABLED)
257  //An IPv6 address is expected?
258  if(entry->type == HOST_TYPE_IPV6)
259  {
260  //Point to the IPv6 context
261  Ipv6Context *ipv6Context = &entry->interface->ipv6Context;
262 
263  //Select the relevant DNS server
264  while(1)
265  {
266  //Out of range index?
268  return ERROR_NO_DNS_SERVER;
269 
270  //Copy the address of the DNS server
271  destIpAddr.length = sizeof(Ipv6Addr);
272  destIpAddr.ipv6Addr = ipv6Context->dnsServerList[entry->dnsServerIndex];
273 
274  //Make sure the IP address is valid
276  break;
277 
278  //Select the next DNS server in the list
279  entry->dnsServerIndex++;
280  }
281  }
282  else
283 #endif
284  //Invalid host type?
285  {
286  //Report an error
288  }
289 
290  //Allocate a memory buffer to hold the DNS query message
291  buffer = udpAllocBuffer(DNS_MESSAGE_MAX_SIZE, &offset);
292  //Failed to allocate buffer?
293  if(buffer == NULL)
294  return ERROR_OUT_OF_MEMORY;
295 
296  //Point to the DNS header
297  message = netBufferAt(buffer, offset);
298 
299  //Format DNS query message
300  message->id = htons(entry->id);
301  message->qr = 0;
302  message->opcode = DNS_OPCODE_QUERY;
303  message->aa = 0;
304  message->tc = 0;
305  message->rd = 1;
306  message->ra = 0;
307  message->z = 0;
308  message->rcode = DNS_RCODE_NO_ERROR;
309 
310  //The DNS query contains one question
311  message->qdcount = HTONS(1);
312  message->ancount = 0;
313  message->nscount = 0;
314  message->arcount = 0;
315 
316  //Length of the DNS query message
317  length = sizeof(DnsHeader);
318 
319  //Encode the host name using the DNS name notation
320  length += dnsEncodeName(entry->name, message->questions);
321 
322  //Point to the corresponding question structure
323  dnsQuestion = DNS_GET_QUESTION(message, length);
324 
325 #if (IPV4_SUPPORT == ENABLED)
326  //An IPv4 address is expected?
327  if(entry->type == HOST_TYPE_IPV4)
328  {
329  //Fill in question structure
330  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_A);
331  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
332  }
333 #endif
334 #if (IPV6_SUPPORT == ENABLED)
335  //An IPv6 address is expected?
336  if(entry->type == HOST_TYPE_IPV6)
337  {
338  //Fill in question structure
339  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_AAAA);
340  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
341  }
342 #endif
343 
344  //Update the length of the DNS query message
345  length += sizeof(DnsQuestion);
346 
347  //Adjust the length of the multi-part buffer
348  netBufferSetLength(buffer, offset + length);
349 
350  //Debug message
351  TRACE_INFO("Sending DNS message (%" PRIuSIZE " bytes)...\r\n", length);
352  //Dump message
354 
355  //Additional options can be passed to the stack along with the packet
356  ancillary = NET_DEFAULT_TX_ANCILLARY;
357 
358  //Send DNS query message
359  error = udpSendBuffer(entry->interface, NULL, entry->port, &destIpAddr,
360  DNS_PORT, buffer, offset, &ancillary);
361 
362  //Free previously allocated memory
363  netBufferFree(buffer);
364  //Return status code
365  return error;
366 }
367 
368 
369 /**
370  * @brief Process incoming DNS response message
371  * @param[in] interface Underlying network interface
372  * @param[in] pseudoHeader UDP pseudo header
373  * @param[in] udpHeader UDP header
374  * @param[in] buffer Multi-part buffer containing the incoming DNS message
375  * @param[in] offset Offset to the first byte of the DNS message
376  * @param[in] ancillary Additional options passed to the stack along with
377  * the packet
378  * @param[in] param Callback function parameter (not used)
379  **/
380 
382  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
383  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
384  void *param)
385 {
386  uint_t i;
387  uint_t j;
388  size_t pos;
389  size_t length;
391  DnsQuestion *question;
392  DnsResourceRecord *record;
393  DnsCacheEntry *entry;
394 
395  //Retrieve the length of the DNS message
396  length = netBufferGetLength(buffer) - offset;
397 
398  //Ensure the DNS message is valid
399  if(length < sizeof(DnsHeader))
400  return;
402  return;
403 
404  //Point to the DNS message header
405  message = netBufferAt(buffer, offset);
406  //Sanity check
407  if(message == NULL)
408  return;
409 
410  //Debug message
411  TRACE_INFO("DNS message received (%" PRIuSIZE " bytes)...\r\n", length);
412  //Dump message
414 
415  //Check message type
416  if(!message->qr)
417  return;
418 
419  //The DNS message shall contain one question
420  if(ntohs(message->qdcount) != 1)
421  return;
422 
423  //Loop through DNS cache entries
424  for(i = 0; i < DNS_CACHE_SIZE; i++)
425  {
426  //Point to the current entry
427  entry = &dnsCache[i];
428 
429  //DNS name resolution in progress?
430  if(entry->state == DNS_STATE_IN_PROGRESS &&
432  {
433  //Check destination port number
434  if(entry->port == ntohs(udpHeader->destPort))
435  {
436  //Compare identifier against the expected one
437  if(ntohs(message->id) != entry->id)
438  break;
439 
440  //Point to the first question
441  pos = sizeof(DnsHeader);
442  //Parse domain name
443  pos = dnsParseName(message, length, pos, NULL, 0);
444 
445  //Invalid name?
446  if(!pos)
447  break;
448  //Malformed DNS message?
449  if((pos + sizeof(DnsQuestion)) > length)
450  break;
451 
452  //Compare domain name
453  if(dnsCompareName(message, length, sizeof(DnsHeader), entry->name, 0))
454  break;
455 
456  //Point to the corresponding entry
457  question = DNS_GET_QUESTION(message, pos);
458 
459  //Check the class of the query
460  if(ntohs(question->qclass) != DNS_RR_CLASS_IN)
461  break;
462 
463  //Check the type of the query
464  if(entry->type == HOST_TYPE_IPV4 && ntohs(question->qtype) != DNS_RR_TYPE_A)
465  break;
466  if(entry->type == HOST_TYPE_IPV6 && ntohs(question->qtype) != DNS_RR_TYPE_AAAA)
467  break;
468 
469  //Check return code
470  if(message->rcode != DNS_RCODE_NO_ERROR)
471  {
472  //The entry should be deleted since name resolution has failed
473  dnsDeleteEntry(entry);
474  //Exit immediately
475  break;
476  }
477 
478  //Point to the first answer
479  pos += sizeof(DnsQuestion);
480 
481  //Parse answer resource records
482  for(j = 0; j < ntohs(message->ancount); j++)
483  {
484  //Parse domain name
485  pos = dnsParseName(message, length, pos, NULL, 0);
486  //Invalid name?
487  if(!pos)
488  break;
489 
490  //Point to the associated resource record
491  record = DNS_GET_RESOURCE_RECORD(message, pos);
492  //Point to the resource data
493  pos += sizeof(DnsResourceRecord);
494 
495  //Make sure the resource record is valid
496  if(pos > length)
497  break;
498  if((pos + ntohs(record->rdlength)) > length)
499  break;
500 
501 #if (IPV4_SUPPORT == ENABLED)
502  //IPv4 address expected?
503  if(entry->type == HOST_TYPE_IPV4)
504  {
505  //A resource record found?
506  if(ntohs(record->rtype) == DNS_RR_TYPE_A &&
507  ntohs(record->rdlength) == sizeof(Ipv4Addr))
508  {
509  //Copy the IPv4 address
510  entry->ipAddr.length = sizeof(Ipv4Addr);
511  ipv4CopyAddr(&entry->ipAddr.ipv4Addr, record->rdata);
512 
513  //Save current time
514  entry->timestamp = osGetSystemTime();
515  //Save TTL value
516  entry->timeout = ntohl(record->ttl) * 1000;
517 
518  //Limit the lifetime of the DNS cache entries
519  if(entry->timeout >= DNS_MAX_LIFETIME)
520  entry->timeout = DNS_MAX_LIFETIME;
521  if(entry->timeout <= DNS_MIN_LIFETIME)
522  entry->timeout = DNS_MIN_LIFETIME;
523 
524  //Unregister UDP callback function
525  udpDetachRxCallback(interface, entry->port);
526  //Host name successfully resolved
527  entry->state = DNS_STATE_RESOLVED;
528  //Exit immediately
529  break;
530  }
531  }
532 #endif
533 #if (IPV6_SUPPORT == ENABLED)
534  //IPv6 address expected?
535  if(entry->type == HOST_TYPE_IPV6)
536  {
537  //AAAA resource record found?
538  if(ntohs(record->rtype) == DNS_RR_TYPE_AAAA &&
539  ntohs(record->rdlength) == sizeof(Ipv6Addr))
540  {
541  //Copy the IPv6 address
542  entry->ipAddr.length = sizeof(Ipv6Addr);
543  ipv6CopyAddr(&entry->ipAddr.ipv6Addr, record->rdata);
544 
545  //Save current time
546  entry->timestamp = osGetSystemTime();
547  //Save TTL value
548  entry->timeout = ntohl(record->ttl) * 1000;
549 
550  //Limit the lifetime of the DNS cache entries
551  if(entry->timeout >= DNS_MAX_LIFETIME)
552  entry->timeout = DNS_MAX_LIFETIME;
553  if(entry->timeout <= DNS_MIN_LIFETIME)
554  entry->timeout = DNS_MIN_LIFETIME;
555 
556  //Unregister UDP callback function
557  udpDetachRxCallback(interface, entry->port);
558  //Host name successfully resolved
559  entry->state = DNS_STATE_RESOLVED;
560  //Exit immediately
561  break;
562  }
563  }
564 #endif
565  //Point to the next resource record
566  pos += ntohs(record->rdlength);
567  }
568 
569  //We are done
570  break;
571  }
572  }
573  }
574 }
575 
576 #endif
error_t dnsSendQuery(DnsCacheEntry *entry)
Send a DNS query message.
Definition: dns_client.c:217
uint8_t length
Definition: coap_common.h:193
#define htons(value)
Definition: cpu_endian.h:413
HostType
Host types.
Definition: socket.h:174
@ DNS_STATE_PERMANENT
Definition: dns_cache.h:88
#define DNS_MAX_LIFETIME
Definition: dns_client.h:77
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:99
__start_packed struct @2 DnsResourceRecord
Resource record format.
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
@ HOST_NAME_RESOLVER_DNS
Definition: socket.h:188
#define netMutex
Definition: net_legacy.h:266
Ipv4Addr dnsServerList[IPV4_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv4.h:367
IP network address.
Definition: ip.h:79
__start_packed struct @0 UdpHeader
UDP header.
@ DNS_OPCODE_QUERY
Definition: dns_common.h:81
#define DNS_MIN_LIFETIME
Definition: dns_client.h:70
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:108
__start_packed struct @0 DnsHeader
DNS message header.
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:806
size_t dnsParseName(const DnsHeader *message, size_t length, size_t pos, char_t *dest, uint_t level)
Decode a domain name that uses the DNS name encoding.
Definition: dns_common.c:133
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
HostnameResolver protocol
Name resolution protocol.
Definition: dns_cache.h:100
#define ipv6CompAddr(ipAddr1, ipAddr2)
Definition: ipv6.h:121
@ DNS_RR_CLASS_IN
Internet.
Definition: dns_common.h:110
#define DNS_CLIENT_MAX_RETRIES
Definition: dns_client.h:49
char_t name[]
IpAddr ipAddr
IP address.
Definition: dns_cache.h:106
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:261
IPv6 context.
Definition: ipv6.h:459
@ ERROR_NO_DNS_SERVER
Definition: error.h:252
IPv4 context.
Definition: ipv4.h:361
uint32_t netGenerateRand(void)
Generate a random 32-bit value.
Definition: net_misc.c:874
@ HOST_TYPE_IPV6
Definition: socket.h:177
IP pseudo header.
Definition: ip.h:98
uint16_t id
Identifier used to match queries and responses.
Definition: dns_cache.h:104
@ ERROR_IN_PROGRESS
Definition: error.h:212
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:103
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t dnsResolve(NetInterface *interface, const char_t *name, HostType type, IpAddr *ipAddr)
Resolve a host name using DNS.
Definition: dns_client.c:54
char_t type
error_t
Error codes.
Definition: error.h:43
#define DNS_GET_QUESTION(message, offset)
Definition: dns_common.h:63
char_t name[DNS_MAX_NAME_LEN+1]
Domain name.
Definition: dns_cache.h:105
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: dns_cache.h:107
#define DNS_GET_RESOURCE_RECORD(message, offset)
Definition: dns_common.h:64
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:413
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
Ipv6Addr dnsServerList[IPV6_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv6.h:468
#define IPV4_DNS_SERVER_LIST_SIZE
Definition: ipv4.h:70
error_t udpDetachRxCallback(NetInterface *interface, uint16_t port)
Unregister user callback.
Definition: udp.c:918
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
error_t udpAttachRxCallback(NetInterface *interface, uint16_t port, UdpRxCallback callback, void *param)
Register user callback.
Definition: udp.c:877
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
DNS cache entry.
Definition: dns_cache.h:97
@ DNS_RR_TYPE_A
Host address.
Definition: dns_common.h:123
error_t udpSendBuffer(NetInterface *interface, const IpAddr *srcIpAddr, uint16_t srcPort, const IpAddr *destIpAddr, uint16_t destPort, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a UDP datagram.
Definition: udp.c:548
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:104
#define NetTxAncillary
Definition: net_misc.h:36
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:109
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:66
#define IPV6_DNS_SERVER_LIST_SIZE
Definition: ipv6.h:94
#define TRACE_INFO(...)
Definition: debug.h:95
#define DNS_PORT
Definition: dns_common.h:57
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
void dnsDumpMessage(const DnsHeader *message, size_t length)
Dump DNS message for debugging purpose.
Definition: dns_debug.c:52
#define MIN(a, b)
Definition: os_port.h:62
NetBuffer * udpAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a UDP packet.
Definition: udp.c:808
size_t length
Definition: ip.h:80
@ HOST_TYPE_IPV4
Definition: socket.h:176
uint16_t udpGetDynamicPort(void)
Get an ephemeral port number.
Definition: udp.c:81
size_t dnsEncodeName(const char_t *src, uint8_t *dest)
Encode a domain name using the DNS name notation.
Definition: dns_common.c:59
DNS client (Domain Name System)
#define DNS_CACHE_INIT_POLLING_INTERVAL
Definition: dns_cache.h:61
uint32_t systime_t
System time.
#define ntohs(value)
Definition: cpu_endian.h:421
char char_t
Definition: compiler_port.h:43
DnsCacheEntry * dnsFindEntry(NetInterface *interface, const char_t *name, HostType type, HostnameResolver protocol)
Search the DNS cache for a given domain name.
Definition: dns_cache.c:187
Ipv4Addr ipv4Addr
Definition: ip.h:84
DNS cache management.
#define ipv6CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv6.h:117
#define HTONS(value)
Definition: cpu_endian.h:410
@ DNS_STATE_IN_PROGRESS
Definition: dns_cache.h:86
NetInterface * interface
Underlying network interface.
Definition: dns_cache.h:101
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
#define DNS_CACHE_SIZE
Definition: dns_cache.h:47
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
__start_packed struct @1 DnsQuestion
Question format.
@ DNS_STATE_RESOLVED
Definition: dns_cache.h:87
#define DNS_MESSAGE_MAX_SIZE
Definition: dns_common.h:45
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
Definition: net_mem.c:320
#define DNS_CLIENT_INIT_TIMEOUT
Definition: dns_client.h:56
uint8_t message[]
Definition: chap.h:152
#define DNS_CLIENT_MAX_TIMEOUT
Definition: dns_client.h:63
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:153
#define ipv4CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv4.h:142
void osDelayTask(systime_t delay)
Delay routine.
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:52
DnsState state
Entry state.
Definition: dns_cache.h:98
uint_t dnsServerIndex
This parameter selects between the primary and secondary DNS server.
Definition: dns_cache.h:102
Ipv6Addr ipv6Addr
Definition: ip.h:87
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:110
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
@ DNS_RCODE_NO_ERROR
Definition: dns_common.h:95
@ DNS_RR_TYPE_AAAA
IPv6 address.
Definition: dns_common.h:133
Data logging functions for debugging purpose (DNS)
Common DNS routines.
int_t dnsCompareName(const DnsHeader *message, size_t length, size_t pos, const char_t *name, uint_t level)
Compare domain names.
Definition: dns_common.c:243
#define osStrcpy(s1, s2)
Definition: os_port.h:197
__start_packed struct @0 Ipv6Addr
IPv6 network address.
#define DNS_CACHE_MAX_POLLING_INTERVAL
Definition: dns_cache.h:68
uint8_t ipAddr[4]
Definition: mib_common.h:187
void dnsProcessResponse(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process incoming DNS response message.
Definition: dns_client.c:381
#define ntohl(value)
Definition: cpu_endian.h:422
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define IPV4_UNSPECIFIED_ADDR
Definition: ipv4.h:104
systime_t osGetSystemTime(void)
Retrieve system time.
Ipv4Addr destIpAddr
Definition: ipcp.h:78