Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dns_cache.h Source File

dns_cache.h

Go to the documentation of this file.
00001 /**
00002  * @file dns_cache.h
00003  * @brief DNS cache management
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _DNS_CACHE_H
00030 #define _DNS_CACHE_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "core/socket.h"
00035 
00036 //DNS tick interval
00037 #ifndef DNS_TICK_INTERVAL
00038    #define DNS_TICK_INTERVAL 200
00039 #elif (DNS_TICK_INTERVAL < 10)
00040    #error DNS_TICK_INTERVAL parameter is not valid
00041 #endif
00042 
00043 //Size of DNS cache
00044 #ifndef DNS_CACHE_SIZE
00045    #define DNS_CACHE_SIZE 8
00046 #elif (DNS_CACHE_SIZE < 1)
00047    #error DNS_CACHE_SIZE parameter is not valid
00048 #endif
00049 
00050 //Maximum length of domain names
00051 #ifndef DNS_MAX_NAME_LEN
00052    #define DNS_MAX_NAME_LEN 63
00053 #elif (DNS_MAX_NAME_LEN < 1)
00054    #error DNS_MAX_NAME_LEN parameter is not valid
00055 #endif
00056 
00057 //Initial polling interval
00058 #ifndef DNS_CACHE_INIT_POLLING_INTERVAL
00059    #define DNS_CACHE_INIT_POLLING_INTERVAL 10
00060 #elif (DNS_CACHE_INIT_POLLING_INTERVAL < 1)
00061    #error DNS_CACHE_INIT_POLLING_INTERVAL parameter is not valid
00062 #endif
00063 
00064 //Maximum polling interval
00065 #ifndef DNS_CACHE_MAX_POLLING_INTERVAL
00066    #define DNS_CACHE_MAX_POLLING_INTERVAL 1000
00067 #elif (DNS_CACHE_MAX_POLLING_INTERVAL < 10)
00068    #error DNS_CACHE_MAX_POLLING_INTERVAL parameter is not valid
00069 #endif
00070 
00071 
00072 /**
00073  * @brief DNS cache entry states
00074  **/
00075 
00076 typedef enum
00077 {
00078    DNS_STATE_NONE        = 0,
00079    DNS_STATE_IN_PROGRESS = 1,
00080    DNS_STATE_RESOLVED    = 2,
00081    DNS_STATE_PERMANENT   = 3
00082 } DnsState;
00083 
00084 
00085 /**
00086  * @brief DNS cache entry
00087  **/
00088 
00089 typedef struct
00090 {
00091    DnsState state;                    ///<Entry state
00092    HostType type;                     ///<IPv4 or IPv6 host?
00093    HostnameResolver protocol;         ///<Name resolution protocol
00094    NetInterface *interface;           ///<Underlying network interface
00095    uint_t dnsServerNum;               ///<This parameter selects between the primary and secondary DNS server
00096    uint16_t port;                     ///<Port number used by the resolver
00097    uint16_t id;                       ///<Identifier used to match queries and responses
00098    char_t name[DNS_MAX_NAME_LEN + 1]; ///<Domain name
00099    IpAddr ipAddr;                     ///<IP address
00100    systime_t timestamp;               ///<Time stamp to manage entry lifetime
00101    systime_t timeout;                 ///<Retransmission timeout
00102    systime_t maxTimeout;              ///<Maximum retransmission timeout
00103    uint_t retransmitCount;            ///<Retransmission counter
00104 } DnsCacheEntry;
00105 
00106 
00107 //Global variables
00108 extern systime_t dnsTickCounter;
00109 extern DnsCacheEntry dnsCache[DNS_CACHE_SIZE];
00110 
00111 //DNS related functions
00112 error_t dnsInit(void);
00113 
00114 void dnsFlushCache(NetInterface *interface);
00115 
00116 DnsCacheEntry *dnsCreateEntry(void);
00117 void dnsDeleteEntry(DnsCacheEntry *entry);
00118 
00119 DnsCacheEntry *dnsFindEntry(NetInterface *interface,
00120    const char_t *name, HostType type, HostnameResolver protocol);
00121 
00122 void dnsTick(void);
00123 
00124 #endif
00125