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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _DNS_CACHE_H
30 #define _DNS_CACHE_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "core/socket.h"
35 
36 //DNS tick interval
37 #ifndef DNS_TICK_INTERVAL
38  #define DNS_TICK_INTERVAL 200
39 #elif (DNS_TICK_INTERVAL < 10)
40  #error DNS_TICK_INTERVAL parameter is not valid
41 #endif
42 
43 //Size of DNS cache
44 #ifndef DNS_CACHE_SIZE
45  #define DNS_CACHE_SIZE 8
46 #elif (DNS_CACHE_SIZE < 1)
47  #error DNS_CACHE_SIZE parameter is not valid
48 #endif
49 
50 //Maximum length of domain names
51 #ifndef DNS_MAX_NAME_LEN
52  #define DNS_MAX_NAME_LEN 63
53 #elif (DNS_MAX_NAME_LEN < 1)
54  #error DNS_MAX_NAME_LEN parameter is not valid
55 #endif
56 
57 //Initial polling interval
58 #ifndef DNS_CACHE_INIT_POLLING_INTERVAL
59  #define DNS_CACHE_INIT_POLLING_INTERVAL 10
60 #elif (DNS_CACHE_INIT_POLLING_INTERVAL < 1)
61  #error DNS_CACHE_INIT_POLLING_INTERVAL parameter is not valid
62 #endif
63 
64 //Maximum polling interval
65 #ifndef DNS_CACHE_MAX_POLLING_INTERVAL
66  #define DNS_CACHE_MAX_POLLING_INTERVAL 1000
67 #elif (DNS_CACHE_MAX_POLLING_INTERVAL < 10)
68  #error DNS_CACHE_MAX_POLLING_INTERVAL parameter is not valid
69 #endif
70 
71 //C++ guard
72 #ifdef __cplusplus
73  extern "C" {
74 #endif
75 
76 
77 /**
78  * @brief DNS cache entry states
79  **/
80 
81 typedef enum
82 {
87 } DnsState;
88 
89 
90 /**
91  * @brief DNS cache entry
92  **/
93 
94 typedef struct
95 {
96  DnsState state; ///<Entry state
97  HostType type; ///<IPv4 or IPv6 host?
98  HostnameResolver protocol; ///<Name resolution protocol
99  NetInterface *interface; ///<Underlying network interface
100  uint_t dnsServerNum; ///<This parameter selects between the primary and secondary DNS server
101  uint16_t port; ///<Port number used by the resolver
102  uint16_t id; ///<Identifier used to match queries and responses
103  char_t name[DNS_MAX_NAME_LEN + 1]; ///<Domain name
104  IpAddr ipAddr; ///<IP address
105  systime_t timestamp; ///<Time stamp to manage entry lifetime
106  systime_t timeout; ///<Retransmission timeout
107  systime_t maxTimeout; ///<Maximum retransmission timeout
108  uint_t retransmitCount; ///<Retransmission counter
109 } DnsCacheEntry;
110 
111 
112 //Global variables
115 
116 //DNS related functions
117 error_t dnsInit(void);
118 
119 void dnsFlushCache(NetInterface *interface);
120 
122 void dnsDeleteEntry(DnsCacheEntry *entry);
123 
126 
127 void dnsTick(void);
128 
129 //C++ guard
130 #ifdef __cplusplus
131  }
132 #endif
133 
134 #endif
uint32_t systime_t
Definition: compiler_port.h:44
char char_t
Definition: compiler_port.h:41
HostnameResolver protocol
Name resolution protocol.
Definition: dns_cache.h:98
void dnsFlushCache(NetInterface *interface)
Flush DNS cache.
Definition: dns_cache.c:72
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:49
TCP/IP stack core.
IpAddr ipAddr
IP address.
Definition: dns_cache.h:104
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:97
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:181
IP network address.
Definition: ip.h:57
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:106
#define DNS_MAX_NAME_LEN
Definition: dns_cache.h:52
char_t type
uint16_t id
Identifier used to match queries and responses.
Definition: dns_cache.h:102
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:148
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: dns_cache.h:105
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:101
error_t dnsInit(void)
DNS cache initialization.
Definition: dns_cache.c:57
systime_t dnsTickCounter
Definition: dns_cache.c:47
DNS cache entry.
Definition: dns_cache.h:94
HostType
Host types.
Definition: socket.h:168
char_t name[]
uint_t dnsServerNum
This parameter selects between the primary and secondary DNS server.
Definition: dns_cache.h:100
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:99
NetInterface * interface
Underlying network interface.
Definition: dns_cache.h:99
void dnsTick(void)
DNS timer handler.
Definition: dns_cache.c:223
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:107
error_t
Error codes.
Definition: error.h:40
unsigned int uint_t
Definition: compiler_port.h:43
#define NetInterface
Definition: net.h:34
DnsState
DNS cache entry states.
Definition: dns_cache.h:81
DnsState state
Entry state.
Definition: dns_cache.h:96
uint8_t protocol
HostnameResolver
Name resolution protocols.
Definition: socket.h:180
Socket API.
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:108
#define DNS_CACHE_SIZE
Definition: dns_cache.h:45