dns_cache.h
Go to the documentation of this file.
1 /**
2  * @file dns_cache.h
3  * @brief DNS cache management
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
29  **/
30 
31 #ifndef _DNS_CACHE_H
32 #define _DNS_CACHE_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/socket.h"
37 
38 //DNS tick interval
39 #ifndef DNS_TICK_INTERVAL
40  #define DNS_TICK_INTERVAL 200
41 #elif (DNS_TICK_INTERVAL < 10)
42  #error DNS_TICK_INTERVAL parameter is not valid
43 #endif
44 
45 //Size of DNS cache
46 #ifndef DNS_CACHE_SIZE
47  #define DNS_CACHE_SIZE 8
48 #elif (DNS_CACHE_SIZE < 1)
49  #error DNS_CACHE_SIZE parameter is not valid
50 #endif
51 
52 //Maximum length of domain names
53 #ifndef DNS_MAX_NAME_LEN
54  #define DNS_MAX_NAME_LEN 63
55 #elif (DNS_MAX_NAME_LEN < 1)
56  #error DNS_MAX_NAME_LEN parameter is not valid
57 #endif
58 
59 //Initial polling interval
60 #ifndef DNS_CACHE_INIT_POLLING_INTERVAL
61  #define DNS_CACHE_INIT_POLLING_INTERVAL 10
62 #elif (DNS_CACHE_INIT_POLLING_INTERVAL < 1)
63  #error DNS_CACHE_INIT_POLLING_INTERVAL parameter is not valid
64 #endif
65 
66 //Maximum polling interval
67 #ifndef DNS_CACHE_MAX_POLLING_INTERVAL
68  #define DNS_CACHE_MAX_POLLING_INTERVAL 1000
69 #elif (DNS_CACHE_MAX_POLLING_INTERVAL < 10)
70  #error DNS_CACHE_MAX_POLLING_INTERVAL parameter is not valid
71 #endif
72 
73 //C++ guard
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 
79 /**
80  * @brief DNS cache entry states
81  **/
82 
83 typedef enum
84 {
89 } DnsState;
90 
91 
92 /**
93  * @brief DNS cache entry
94  **/
95 
96 typedef struct
97 {
98  DnsState state; ///<Entry state
99  HostType type; ///<IPv4 or IPv6 host?
100  HostnameResolver protocol; ///<Name resolution protocol
101  NetInterface *interface; ///<Underlying network interface
102  uint_t dnsServerNum; ///<This parameter selects between the primary and secondary DNS server
103  uint16_t port; ///<Port number used by the resolver
104  uint16_t id; ///<Identifier used to match queries and responses
105  char_t name[DNS_MAX_NAME_LEN + 1]; ///<Domain name
106  IpAddr ipAddr; ///<IP address
107  systime_t timestamp; ///<Time stamp to manage entry lifetime
108  systime_t timeout; ///<Retransmission timeout
109  systime_t maxTimeout; ///<Maximum retransmission timeout
110  uint_t retransmitCount; ///<Retransmission counter
111 } DnsCacheEntry;
112 
113 
114 //Global variables
117 
118 //DNS related functions
119 error_t dnsInit(void);
120 
121 void dnsFlushCache(NetInterface *interface);
122 
124 void dnsDeleteEntry(DnsCacheEntry *entry);
125 
128 
129 void dnsTick(void);
130 
131 //C++ guard
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif
HostType
Host types.
Definition: socket.h:171
@ DNS_STATE_PERMANENT
Definition: dns_cache.h:88
void dnsFlushCache(NetInterface *interface)
Flush DNS cache.
Definition: dns_cache.c:74
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:99
HostnameResolver
Name resolution protocols.
Definition: socket.h:183
IP network address.
Definition: ip.h:71
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:108
HostnameResolver protocol
Name resolution protocol.
Definition: dns_cache.h:100
char_t name[]
IpAddr ipAddr
IP address.
Definition: dns_cache.h:106
uint16_t id
Identifier used to match queries and responses.
Definition: dns_cache.h:104
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:103
uint_t dnsServerNum
This parameter selects between the primary and secondary DNS server.
Definition: dns_cache.h:102
char_t type
error_t
Error codes.
Definition: error.h:42
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: dns_cache.h:107
uint8_t protocol
DnsState
DNS cache entry states.
Definition: dns_cache.h:83
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:183
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:101
#define NetInterface
Definition: net.h:36
DNS cache entry.
Definition: dns_cache.h:96
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:59
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:109
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:150
systime_t dnsTickCounter
Definition: dns_cache.c:49
char char_t
Definition: compiler_port.h:43
@ DNS_STATE_IN_PROGRESS
Definition: dns_cache.h:86
NetInterface * interface
Underlying network interface.
Definition: dns_cache.h:101
#define DNS_CACHE_SIZE
Definition: dns_cache.h:47
@ DNS_STATE_RESOLVED
Definition: dns_cache.h:87
void dnsTick(void)
DNS timer handler.
Definition: dns_cache.c:225
Socket API.
DnsState state
Entry state.
Definition: dns_cache.h:98
#define DNS_MAX_NAME_LEN
Definition: dns_cache.h:54
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:110
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:51
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
@ DNS_STATE_NONE
Definition: dns_cache.h:85
uint32_t systime_t
Definition: compiler_port.h:46