Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

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