Integrates uip-nameserver API
On the same commit the src have been uncrustified and some typo fixes as well as includes missing.
This commit is contained in:
parent
27afb5a2ae
commit
ccc0d27da0
|
@ -88,7 +88,7 @@ makestrings(void)
|
|||
uip_getdraddr(&addr);
|
||||
makeaddr(&addr, gateway);
|
||||
|
||||
addrptr = resolv_getserver();
|
||||
addrptr = uip_nameserver_get(0);
|
||||
if(addrptr != NULL) {
|
||||
makeaddr(addrptr, dnsserver);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ dhcpc_configured(const struct dhcpc_state *s)
|
|||
uip_sethostaddr(&s->ipaddr);
|
||||
uip_setnetmask(&s->netmask);
|
||||
uip_setdraddr(&s->default_router);
|
||||
resolv_conf(&s->dnsaddr);
|
||||
uip_nameserver_update(&s->dnsaddr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
set_statustext("Configured.");
|
||||
process_post(PROCESS_CURRENT(), SHOWCONFIG, NULL);
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ makestrings(void)
|
|||
makeaddr(&addr, gateway);
|
||||
|
||||
#if UIP_UDP
|
||||
addrptr = resolv_getserver();
|
||||
addrptr = uip_nameserver_get(0);
|
||||
if(addrptr != NULL) {
|
||||
makeaddr(addrptr, dnsserver);
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ apply_tcpipconfig(void)
|
|||
#if UIP_UDP
|
||||
nullterminate(dnsserver);
|
||||
if(uiplib_ipaddrconv(dnsserver, &addr)) {
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
}
|
||||
#endif /* UIP_UDP */
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "net/ip/tcpip.h"
|
||||
#include "net/ip/resolv.h"
|
||||
#include "net/ip/uip-udp-packet.h"
|
||||
#include "net/ip/uip-nameserver.h"
|
||||
#include "lib/random.h"
|
||||
|
||||
#ifndef DEBUG
|
||||
|
@ -227,17 +228,6 @@ struct dns_hdr {
|
|||
uint16_t numextrarr;
|
||||
};
|
||||
|
||||
/** These default values for the DNS server are Google's public DNS:
|
||||
* <https://developers.google.com/speed/public-dns/docs/using>
|
||||
*/
|
||||
static uip_ipaddr_t resolv_default_dns_server =
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
{ { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 } };
|
||||
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||
{ { 8, 8, 8, 8 } };
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
/** \internal The DNS answer message structure. */
|
||||
struct dns_answer {
|
||||
/* DNS answer record starts with either a domain name or a pointer
|
||||
|
@ -269,6 +259,7 @@ struct namemap {
|
|||
#endif /* RESOLV_SUPPORTS_RECORD_EXPIRATION */
|
||||
uip_ipaddr_t ipaddr;
|
||||
uint8_t err;
|
||||
uint8_t server;
|
||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||
int is_mdns:1, is_probe:1;
|
||||
#endif
|
||||
|
@ -637,6 +628,20 @@ mdns_prep_host_announce_packet(void)
|
|||
}
|
||||
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char
|
||||
try_next_server(struct namemap *namemapptr)
|
||||
{
|
||||
#if VERBOSE_DEBUG
|
||||
printf("server %d\n", namemapptr->server);
|
||||
#endif
|
||||
if(uip_nameserver_get(++namemapptr->server) != NULL) {
|
||||
namemapptr->retries = 0;
|
||||
return 1;
|
||||
}
|
||||
namemapptr->server = 0;
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \internal
|
||||
* Runs through the list of names to see if there are any that have
|
||||
* not yet been queried and, if so, sends out a query.
|
||||
|
@ -666,6 +671,9 @@ check_entries(void)
|
|||
if(++namemapptr->retries == RESOLV_CONF_MAX_RETRIES)
|
||||
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||
{
|
||||
/* Try the next server (if possible) before failing. Otherwise
|
||||
simply mark the entry as failed. */
|
||||
if(try_next_server(namemapptr) == 0) {
|
||||
/* STATE_ERROR basically means "not found". */
|
||||
namemapptr->state = STATE_ERROR;
|
||||
|
||||
|
@ -677,6 +685,7 @@ check_entries(void)
|
|||
resolv_found(namemapptr->name, NULL);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
namemapptr->tmr = namemapptr->retries * namemapptr->retries * 3;
|
||||
|
||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||
|
@ -747,7 +756,9 @@ check_entries(void)
|
|||
} else {
|
||||
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||
(query - (uint8_t *) uip_appdata),
|
||||
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
||||
(const uip_ipaddr_t *)
|
||||
uip_nameserver_get(namemapptr->server),
|
||||
UIP_HTONS(DNS_PORT));
|
||||
|
||||
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
||||
namemapptr->name);
|
||||
|
@ -755,7 +766,8 @@ check_entries(void)
|
|||
#else /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||
(query - (uint8_t *) uip_appdata),
|
||||
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
||||
uip_nameserver_get(namemapptr->server),
|
||||
UIP_HTONS(DNS_PORT));
|
||||
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
||||
namemapptr->name);
|
||||
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||
|
@ -1041,11 +1053,28 @@ newdata(void)
|
|||
uip_ipaddr_copy(&namemapptr->ipaddr, (uip_ipaddr_t *) ans->ipaddr);
|
||||
|
||||
resolv_found(namemapptr->name, &namemapptr->ipaddr);
|
||||
break;
|
||||
|
||||
skip_to_next_answer:
|
||||
queryptr = (unsigned char *)skip_name(queryptr) + 10 + uip_htons(ans->len);
|
||||
--nanswers;
|
||||
}
|
||||
|
||||
/* Got to this point there's no answer, try next nameserver if available
|
||||
since this one doesn't know the answer */
|
||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||
if(nanswers == 0 && UIP_UDP_BUF->srcport != UIP_HTONS(MDNS_PORT)
|
||||
&& hdr->id != 0)
|
||||
#else
|
||||
if(nanswers == 0)
|
||||
#endif
|
||||
{
|
||||
if(try_next_server(namemapptr)) {
|
||||
namemapptr->state = STATE_ASKING;
|
||||
process_post(&resolv_process, PROCESS_EVENT_TIMER, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||
|
@ -1405,31 +1434,6 @@ resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr)
|
|||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Obtain the currently configured DNS server.
|
||||
*
|
||||
* \return A pointer to a 4-byte representation of the IP address of
|
||||
* the currently configured DNS server or NULL if no DNS server has
|
||||
* been configured.
|
||||
*/
|
||||
uip_ipaddr_t *
|
||||
resolv_getserver(void)
|
||||
{
|
||||
return &resolv_default_dns_server;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Configure a DNS server.
|
||||
*
|
||||
* \param dnsserver A pointer to a 4-byte representation of the IP
|
||||
* address of the DNS server to be configured.
|
||||
*/
|
||||
void
|
||||
resolv_conf(const uip_ipaddr_t * dnsserver)
|
||||
{
|
||||
uip_ipaddr_copy(&resolv_default_dns_server, dnsserver);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \internal
|
||||
* Callback function which is called when a hostname is found.
|
||||
*
|
||||
|
|
|
@ -57,11 +57,6 @@
|
|||
*/
|
||||
CCIF extern process_event_t resolv_event_found;
|
||||
|
||||
/* Functions. */
|
||||
CCIF void resolv_conf(const uip_ipaddr_t * dnsserver);
|
||||
|
||||
CCIF uip_ipaddr_t *resolv_getserver(void);
|
||||
|
||||
enum {
|
||||
/** Hostname is fresh and usable. This response is cached and will eventually
|
||||
* expire to RESOLV_STATUS_EXPIRED.*/
|
||||
|
@ -95,6 +90,7 @@ enum {
|
|||
|
||||
typedef uint8_t resolv_status_t;
|
||||
|
||||
/* Functions. */
|
||||
CCIF resolv_status_t resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr);
|
||||
|
||||
CCIF void resolv_query(const char *name);
|
||||
|
|
|
@ -49,12 +49,12 @@
|
|||
|
||||
#include <string.h>
|
||||
/** \brief Nameserver record */
|
||||
typedef struct uip_namserver_record {
|
||||
struct uip_namserver_record *next;
|
||||
typedef struct uip_nameserver_record {
|
||||
struct uip_nameserver_record *next;
|
||||
uip_ipaddr_t ip;
|
||||
uint32_t added;
|
||||
uint32_t lifetime;
|
||||
} uip_namserver_record;
|
||||
} uip_nameserver_record;
|
||||
|
||||
/** \brief Initialization flag */
|
||||
static uint8_t initialized = 0;
|
||||
|
@ -63,7 +63,7 @@ static uint8_t initialized = 0;
|
|||
* @{
|
||||
*/
|
||||
LIST(dns);
|
||||
MEMB(dnsmemb, uip_namserver_record, UIP_NAMESERVER_POOL_SIZE);
|
||||
MEMB(dnsmemb, uip_nameserver_record, UIP_NAMESERVER_POOL_SIZE);
|
||||
/** @} */
|
||||
|
||||
/** \brief Expiration time in seconds */
|
||||
|
@ -74,7 +74,7 @@ MEMB(dnsmemb, uip_namserver_record, UIP_NAMESERVER_POOL_SIZE);
|
|||
/**
|
||||
* Initialize the module variables
|
||||
*/
|
||||
static void inline
|
||||
static CC_INLINE void
|
||||
init(void)
|
||||
{
|
||||
list_init(dns);
|
||||
|
@ -85,23 +85,25 @@ init(void)
|
|||
void
|
||||
uip_nameserver_update(uip_ipaddr_t *nameserver, uint32_t lifetime)
|
||||
{
|
||||
register uip_nameserver_record *e;
|
||||
|
||||
if(initialized == 0) {
|
||||
init();
|
||||
}
|
||||
|
||||
register uip_namserver_record *e;
|
||||
for(e = list_head(dns); e != NULL; e = list_item_next(e)) {
|
||||
if(uip_ipaddr_cmp(&e->ip, nameserver)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* RFC6106: In case there's no more space, the new servers should replace
|
||||
* the the eldest ones */
|
||||
}
|
||||
}
|
||||
|
||||
if(e == NULL) {
|
||||
if((e = memb_alloc(&dnsmemb)) != NULL) {
|
||||
list_add(dns, e);
|
||||
} else {
|
||||
uip_namserver_record *p;
|
||||
uip_nameserver_record *p;
|
||||
for(e = list_head(dns), p = list_head(dns); p != NULL;
|
||||
p = list_item_next(p)) {
|
||||
if(DNS_EXPIRATION(p) < DNS_EXPIRATION(e)) {
|
||||
|
@ -131,7 +133,7 @@ uip_nameserver_update(uip_ipaddr_t *nameserver, uint32_t lifetime)
|
|||
static void
|
||||
purge(void)
|
||||
{
|
||||
register uip_namserver_record *e = NULL;
|
||||
register uip_nameserver_record *e = NULL;
|
||||
uint32_t time = clock_seconds();
|
||||
for(e = list_head(dns); e != NULL; e = list_item_next(e)) {
|
||||
if(DNS_EXPIRATION(e) < time) {
|
||||
|
@ -146,15 +148,15 @@ uip_ipaddr_t *
|
|||
uip_nameserver_get(uint8_t num)
|
||||
{
|
||||
uint8_t i;
|
||||
uip_namserver_record *e = NULL;
|
||||
uip_nameserver_record *e = NULL;
|
||||
|
||||
if(initialized == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
purge();
|
||||
for(i = 1, e = list_head(dns); e != NULL && i <= num;
|
||||
i++, e = list_item_next(e));
|
||||
i++, e = list_item_next(e)) {
|
||||
}
|
||||
|
||||
if(e != NULL) {
|
||||
return &e->ip;
|
||||
|
@ -165,14 +167,13 @@ uip_nameserver_get(uint8_t num)
|
|||
uint32_t
|
||||
uip_nameserver_next_expiration(void)
|
||||
{
|
||||
register uip_namserver_record *e = NULL;
|
||||
register uip_nameserver_record *e = NULL;
|
||||
uint32_t exp = UIP_NAMESERVER_INFINITE_LIFETIME;
|
||||
uint32_t t;
|
||||
|
||||
if(initialized == 0 || list_length(dns) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
purge();
|
||||
for(e = list_head(dns); e != NULL; e = list_item_next(e)) {
|
||||
t = DNS_EXPIRATION(e);
|
||||
|
|
|
@ -49,7 +49,11 @@
|
|||
* @{
|
||||
*/
|
||||
/** \brief Number of Nameservers to keep */
|
||||
#define UIP_NAMESERVER_POOL_SIZE 2
|
||||
#ifndef UIP_CONF_NAMESERVER_POOL_SIZE
|
||||
#define UIP_NAMESERVER_POOL_SIZE 1
|
||||
#else /* UIP_CONF_NAMESERVER_POOL_SIZE */
|
||||
#define UIP_NAMESERVER_POOL_SIZE UIP_CONF_NAMESERVER_POOL_SIZE
|
||||
#endif /* UIP_CONF_NAMESERVER_POOL_SIZE */
|
||||
/** \brief Infinite Lifetime indicator */
|
||||
#define UIP_NAMESERVER_INFINITE_LIFETIME 0xFFFFFFFF
|
||||
/** @} */
|
||||
|
@ -77,7 +81,7 @@ uip_nameserver_update(uip_ipaddr_t *nameserver, uint32_t lifetime);
|
|||
* \brief Get a Nameserver ip address given in RA
|
||||
*
|
||||
* \param num The number of the nameserver to obtain, starting at 0 and going
|
||||
* up to the pool size. (\sa UIP_ND6_RDNSS_POOL_SIZE)
|
||||
* up to the pool size.
|
||||
*/
|
||||
uip_ipaddr_t *
|
||||
uip_nameserver_get(uint8_t num);
|
||||
|
|
|
@ -147,13 +147,6 @@
|
|||
#define UIP_ND6_RA_RDNSS UIP_CONF_ND6_RA_RDNSS
|
||||
#endif
|
||||
|
||||
/** \brief Number of DNS to hold on the node */
|
||||
#if UIP_ND6_RA_RDNSS
|
||||
#define UIP_ND6_RDNSS_POOL_SIZE 2
|
||||
#else
|
||||
#define UIP_ND6_RDNSS_POOL_SIZE 0
|
||||
#endif
|
||||
|
||||
#ifndef UIP_CONF_ND6_RA_DNSSL
|
||||
#define UIP_ND6_RA_DNSSL 0
|
||||
#else
|
||||
|
|
|
@ -117,7 +117,7 @@ makestrings(void)
|
|||
makeaddr(&addr, gateway);
|
||||
|
||||
#if WITH_DNS
|
||||
addrptr = resolv_getserver();
|
||||
addrptr = uip_nameserver_get(0);
|
||||
if(addrptr != NULL) {
|
||||
makeaddr(addrptr, dnsserver);
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ dhcpc_configured(const struct dhcpc_state *s)
|
|||
uip_setnetmask(&s->netmask);
|
||||
uip_setdraddr(&s->default_router);
|
||||
#if WITH_DNS
|
||||
resolv_conf(&s->dnsaddr);
|
||||
uip_nameserver_update(&s->dnsaddr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
#endif /* WITH_DNS */
|
||||
|
||||
set_statustext("Configured.");
|
||||
|
@ -261,7 +261,7 @@ dhcpc_unconfigured(const struct dhcpc_state *s)
|
|||
uip_setnetmask(&nulladdr);
|
||||
uip_setdraddr(&nulladdr);
|
||||
#if WITH_DNS
|
||||
resolv_conf(&nulladdr);
|
||||
uip_nameserver_update(&nulladdr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
#endif /* WITH_DNS */
|
||||
|
||||
set_statustext("Unconfigured.");
|
||||
|
|
|
@ -105,7 +105,7 @@ config_read(char *filename)
|
|||
uip_setnetmask(&config.netmask);
|
||||
uip_setdraddr(&config.draddr);
|
||||
#if WITH_DNS
|
||||
resolv_conf(&config.resolvaddr);
|
||||
uip_nameserver_update(&config.resolvaddr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
#endif /* WITH_DNS */
|
||||
|
||||
return &config.ethernetcfg;
|
||||
|
|
|
@ -104,7 +104,7 @@ main(void)
|
|||
uip_setdraddr(&addr);
|
||||
|
||||
uip_ipaddr(&addr, 192,168,0,1);
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
ethernet_config = &config;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ main(void)
|
|||
uip_setdraddr(&addr);
|
||||
|
||||
uip_ipaddr(&addr, 192,168,0,1);
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
ethernet_config = &config;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ main(void)
|
|||
uip_setdraddr(&addr);
|
||||
|
||||
uip_ipaddr(&addr, 192,168,0,1);
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
ethernet_config = &config;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ main(void)
|
|||
uip_setdraddr(&addr);
|
||||
|
||||
uip_ipaddr(&addr, 192,168,0,1);
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
ethernet_config = &config;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ main(int argc, char **argv)
|
|||
log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr));
|
||||
|
||||
uip_ipaddr(&addr, 192,168,0,1);
|
||||
resolv_conf(&addr);
|
||||
uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&addr));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue