Skip to content

Commit

Permalink
Merge pull request #999 from adamdunkels/lebrush-rdnss-support-rebased
Browse files Browse the repository at this point in the history
RDNSS support, again
  • Loading branch information
Nicolas Tsiftes committed Mar 30, 2015
2 parents 793ed65 + 952e1e4 commit 8f50d97
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 63 deletions.
4 changes: 2 additions & 2 deletions apps/dhcp/dhcp.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/netconf/netconf.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
}
Expand Down
1 change: 1 addition & 0 deletions core/contiki-net.h
Expand Up @@ -44,6 +44,7 @@
#include "net/ip/uiplib.h"
#include "net/ip/uip-udp-packet.h"
#include "net/ip/simple-udp.h"
#include "net/ip/uip-nameserver.h"

#if NETSTACK_CONF_WITH_IPV6
#include "net/ipv6/uip-icmp6.h"
Expand Down
93 changes: 49 additions & 44 deletions core/net/ip/resolv.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -637,6 +628,21 @@ 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
namemapptr->server++;
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.
Expand Down Expand Up @@ -666,16 +672,20 @@ check_entries(void)
if(++namemapptr->retries == RESOLV_CONF_MAX_RETRIES)
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
{
/* STATE_ERROR basically means "not found". */
namemapptr->state = STATE_ERROR;
/* 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;

#if RESOLV_SUPPORTS_RECORD_EXPIRATION
/* Keep the "not found" error valid for 30 seconds */
namemapptr->expiration = clock_seconds() + 30;
/* Keep the "not found" error valid for 30 seconds */
namemapptr->expiration = clock_seconds() + 30;
#endif /* RESOLV_SUPPORTS_RECORD_EXPIRATION */

resolv_found(namemapptr->name, NULL);
continue;
resolv_found(namemapptr->name, NULL);
continue;
}
}
namemapptr->tmr = namemapptr->retries * namemapptr->retries * 3;

Expand Down Expand Up @@ -747,15 +757,18 @@ 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);
}
#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 */
Expand Down Expand Up @@ -1041,11 +1054,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
Expand Down Expand Up @@ -1405,31 +1435,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.
*
Expand Down
6 changes: 1 addition & 5 deletions core/net/ip/resolv.h
Expand Up @@ -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.*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8f50d97

Please sign in to comment.