mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-14 10:21:12 +00:00
Worked on IPv6-only stack:
- prepared DNS; - fixed compiling ppp.c
This commit is contained in:
parent
69c337b31d
commit
e77e18f8c4
@ -113,7 +113,11 @@ static u16_t dns_txid;
|
|||||||
|
|
||||||
/** DNS server IP address */
|
/** DNS server IP address */
|
||||||
#ifndef DNS_SERVER_ADDRESS
|
#ifndef DNS_SERVER_ADDRESS
|
||||||
|
#if LWIP_IPV4
|
||||||
#define DNS_SERVER_ADDRESS(ipaddr) ip_addr_set_ip4_u32(ipaddr, ipaddr_addr("208.67.222.222")) /* resolver1.opendns.com */
|
#define DNS_SERVER_ADDRESS(ipaddr) ip_addr_set_ip4_u32(ipaddr, ipaddr_addr("208.67.222.222")) /* resolver1.opendns.com */
|
||||||
|
#else
|
||||||
|
#define DNS_SERVER_ADDRESS(ipaddr) ipaddr_aton("2001:4860:4860::8888", ipaddr)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** DNS server port address */
|
/** DNS server port address */
|
||||||
@ -449,17 +453,21 @@ dns_init_local()
|
|||||||
* Scans the local host-list for a hostname.
|
* Scans the local host-list for a hostname.
|
||||||
*
|
*
|
||||||
* @param hostname Hostname to look for in the local host-list
|
* @param hostname Hostname to look for in the local host-list
|
||||||
* @return The first IP address for the hostname in the local host-list or
|
* @param addr the first IP address for the hostname in the local host-list or
|
||||||
* IPADDR_NONE if not found.
|
* IPADDR_NONE if not found.
|
||||||
|
* @return ERR_OK if found, ERR_ARG if not found
|
||||||
*/
|
*/
|
||||||
static u32_t
|
static err_t
|
||||||
dns_lookup_local(const char *hostname)
|
dns_lookup_local(const char *hostname, ip_addr_t *addr)
|
||||||
{
|
{
|
||||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||||
struct local_hostlist_entry *entry = local_hostlist_dynamic;
|
struct local_hostlist_entry *entry = local_hostlist_dynamic;
|
||||||
while(entry != NULL) {
|
while(entry != NULL) {
|
||||||
if (LWIP_DNS_STRICMP(entry->name, hostname) == 0) {
|
if (LWIP_DNS_STRICMP(entry->name, hostname) == 0) {
|
||||||
return ip_addr_get_ip4_u32(&entry->addr);
|
if (addr) {
|
||||||
|
ip_addr_copy(*addr, entry->addr);
|
||||||
|
}
|
||||||
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
}
|
}
|
||||||
@ -467,11 +475,14 @@ dns_lookup_local(const char *hostname)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
|
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
|
||||||
if (LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) {
|
if (LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) {
|
||||||
return ip_addr_get_ip4_u32(&local_hostlist_static[i].addr);
|
if (addr) {
|
||||||
|
ip_addr_copy(*addr, local_hostlist_static[i].addr);
|
||||||
|
}
|
||||||
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||||
return IPADDR_NONE;
|
return ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||||
@ -550,20 +561,20 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr)
|
|||||||
* for a hostname.
|
* for a hostname.
|
||||||
*
|
*
|
||||||
* @param name the hostname to look up
|
* @param name the hostname to look up
|
||||||
* @return the hostname's IP address, as u32_t (instead of ip_addr_t to
|
* @param addr the hostname's IP address, as u32_t (instead of ip_addr_t to
|
||||||
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
|
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
|
||||||
* was not found in the cached dns_table.
|
* was not found in the cached dns_table.
|
||||||
|
* @return ERR_OK if found, ERR_ARG if not found
|
||||||
*/
|
*/
|
||||||
static u32_t
|
static err_t
|
||||||
dns_lookup(const char *name)
|
dns_lookup(const char *name, ip_addr_t *addr)
|
||||||
{
|
{
|
||||||
u8_t i;
|
u8_t i;
|
||||||
#if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN)
|
#if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN)
|
||||||
u32_t addr;
|
|
||||||
#endif /* DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) */
|
#endif /* DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN) */
|
||||||
#if DNS_LOCAL_HOSTLIST
|
#if DNS_LOCAL_HOSTLIST
|
||||||
if ((addr = dns_lookup_local(name)) != IPADDR_NONE) {
|
if (dns_lookup_local(name, addr) == ERR_OK) {
|
||||||
return addr;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
#endif /* DNS_LOCAL_HOSTLIST */
|
#endif /* DNS_LOCAL_HOSTLIST */
|
||||||
#ifdef DNS_LOOKUP_LOCAL_EXTERN
|
#ifdef DNS_LOOKUP_LOCAL_EXTERN
|
||||||
@ -577,13 +588,16 @@ dns_lookup(const char *name)
|
|||||||
if ((dns_table[i].state == DNS_STATE_DONE) &&
|
if ((dns_table[i].state == DNS_STATE_DONE) &&
|
||||||
(LWIP_DNS_STRICMP(name, dns_table[i].name) == 0)) {
|
(LWIP_DNS_STRICMP(name, dns_table[i].name) == 0)) {
|
||||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
|
LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
|
||||||
ip4_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
|
ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
|
||||||
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
|
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
|
||||||
return ip_addr_get_ip4_u32(&dns_table[i].ipaddr);
|
if (addr) {
|
||||||
|
ip_addr_copy(*addr, dns_table[i].ipaddr);
|
||||||
|
}
|
||||||
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IPADDR_NONE;
|
return ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1058,6 +1072,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
|
|
||||||
/* Check for IP address type and Internet class. Others are discarded. */
|
/* Check for IP address type and Internet class. Others are discarded. */
|
||||||
pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx);
|
pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx);
|
||||||
|
#if LWIP_IPV4
|
||||||
if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
|
if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
|
||||||
(ans.len == PP_HTONS(sizeof(ip4_addr_t))) ) {
|
(ans.len == PP_HTONS(sizeof(ip4_addr_t))) ) {
|
||||||
res_idx += SIZEOF_DNS_ANSWER;
|
res_idx += SIZEOF_DNS_ANSWER;
|
||||||
@ -1082,7 +1097,10 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
}
|
}
|
||||||
/* deallocate memory and return */
|
/* deallocate memory and return */
|
||||||
goto memerr;
|
goto memerr;
|
||||||
} else {
|
} else
|
||||||
|
#endif /* LWIP_IPV4 */
|
||||||
|
{
|
||||||
|
/* @todo: parse IPv6 answers */
|
||||||
res_idx += SIZEOF_DNS_ANSWER + htons(ans.len);
|
res_idx += SIZEOF_DNS_ANSWER + htons(ans.len);
|
||||||
}
|
}
|
||||||
--nanswers;
|
--nanswers;
|
||||||
@ -1100,7 +1118,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
responseerr:
|
responseerr:
|
||||||
/* ERROR: call specified callback function with NULL as name to indicate an error */
|
/* ERROR: call specified callback function with NULL as name to indicate an error */
|
||||||
dns_call_found(entry_idx, NULL);
|
dns_call_found(entry_idx, NULL);
|
||||||
|
#if LWIP_IPV4
|
||||||
flushentry:
|
flushentry:
|
||||||
|
#endif /* LWIP_IPV4 */
|
||||||
/* flush this entry */
|
/* flush this entry */
|
||||||
dns_table[entry_idx].state = DNS_STATE_UNUSED;
|
dns_table[entry_idx].state = DNS_STATE_UNUSED;
|
||||||
|
|
||||||
@ -1257,7 +1277,6 @@ err_t
|
|||||||
dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found,
|
dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found,
|
||||||
void *callback_arg)
|
void *callback_arg)
|
||||||
{
|
{
|
||||||
u32_t ipaddr;
|
|
||||||
size_t hostnamelen;
|
size_t hostnamelen;
|
||||||
/* not initialized or no valid server yet, or invalid addr pointer
|
/* not initialized or no valid server yet, or invalid addr pointer
|
||||||
* or invalid hostname or invalid hostname length */
|
* or invalid hostname or invalid hostname length */
|
||||||
@ -1286,13 +1305,11 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
|
|||||||
#endif /* LWIP_HAVE_LOOPIF */
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
|
||||||
/* host name already in octet notation? set ip addr and return ERR_OK */
|
/* host name already in octet notation? set ip addr and return ERR_OK */
|
||||||
ipaddr = ipaddr_addr(hostname);
|
if (ipaddr_aton(hostname, addr)) {
|
||||||
if (ipaddr == IPADDR_NONE) {
|
return ERR_OK;
|
||||||
/* already have this address cached? */
|
|
||||||
ipaddr = dns_lookup(hostname);
|
|
||||||
}
|
}
|
||||||
if (ipaddr != IPADDR_NONE) {
|
/* already have this address cached? */
|
||||||
ip_addr_set_ip4_u32(addr, ipaddr);
|
if(dns_lookup(hostname, addr) == ERR_OK) {
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,13 +36,7 @@
|
|||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
/* @todo/@fixme: implement IPV6 support for DNS (see task #12243) */
|
#if LWIP_DNS
|
||||||
#if !LWIP_IPV4 && LWIP_DNS
|
|
||||||
/* init.c/timers.c compatibility until task #12243 is done: */
|
|
||||||
#define dns_init()
|
|
||||||
#define dns_tmr()
|
|
||||||
#define DNS_TMR_INTERVAL 1000
|
|
||||||
#elif LWIP_DNS /* don't build if not configured for use in lwipopts.h */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -181,7 +181,9 @@ const struct protent* const protocols[] = {
|
|||||||
/* Prototypes for procedures local to this file. */
|
/* Prototypes for procedures local to this file. */
|
||||||
static void ppp_do_connect(void *arg);
|
static void ppp_do_connect(void *arg);
|
||||||
static err_t ppp_netif_init_cb(struct netif *netif);
|
static err_t ppp_netif_init_cb(struct netif *netif);
|
||||||
|
#if PPP_IPV4_SUPPORT
|
||||||
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr);
|
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr);
|
||||||
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
#if PPP_IPV6_SUPPORT
|
#if PPP_IPV6_SUPPORT
|
||||||
static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr);
|
static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr);
|
||||||
#endif /* PPP_IPV6_SUPPORT */
|
#endif /* PPP_IPV6_SUPPORT */
|
||||||
@ -410,8 +412,10 @@ static void ppp_do_connect(void *arg) {
|
|||||||
static err_t ppp_netif_init_cb(struct netif *netif) {
|
static err_t ppp_netif_init_cb(struct netif *netif) {
|
||||||
netif->name[0] = 'p';
|
netif->name[0] = 'p';
|
||||||
netif->name[1] = 'p';
|
netif->name[1] = 'p';
|
||||||
|
#if PPP_IPV4_SUPPORT
|
||||||
/* FIXME: change that when netif_null_output_ip4() will materialize */
|
/* FIXME: change that when netif_null_output_ip4() will materialize */
|
||||||
netif->output = ppp_netif_output_ip4;
|
netif->output = ppp_netif_output_ip4;
|
||||||
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
#if PPP_IPV6_SUPPORT
|
#if PPP_IPV6_SUPPORT
|
||||||
netif->output_ip6 = ppp_netif_output_ip6;
|
netif->output_ip6 = ppp_netif_output_ip6;
|
||||||
#endif /* PPP_IPV6_SUPPORT */
|
#endif /* PPP_IPV6_SUPPORT */
|
||||||
@ -423,6 +427,7 @@ static err_t ppp_netif_init_cb(struct netif *netif) {
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PPP_IPV4_SUPPORT
|
||||||
/*
|
/*
|
||||||
* Send an IPv4 packet on the given connection.
|
* Send an IPv4 packet on the given connection.
|
||||||
*/
|
*/
|
||||||
@ -448,6 +453,7 @@ static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip
|
|||||||
return ERR_IF;
|
return ERR_IF;
|
||||||
#endif /* PPP_IPV4_SUPPORT */
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
}
|
}
|
||||||
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
|
|
||||||
#if PPP_IPV6_SUPPORT
|
#if PPP_IPV6_SUPPORT
|
||||||
/*
|
/*
|
||||||
@ -556,7 +562,10 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
|
|||||||
pcb->settings.fsm_max_nak_loops = FSM_DEFMAXNAKLOOPS;
|
pcb->settings.fsm_max_nak_loops = FSM_DEFMAXNAKLOOPS;
|
||||||
|
|
||||||
pcb->netif = pppif;
|
pcb->netif = pppif;
|
||||||
if (!netif_add(pcb->netif, IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY,
|
if (!netif_add(pcb->netif,
|
||||||
|
#if LWIP_IPV4
|
||||||
|
IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY,
|
||||||
|
#endif /* LWIP_IPV4 */
|
||||||
(void *)pcb, ppp_netif_init_cb, NULL)) {
|
(void *)pcb, ppp_netif_init_cb, NULL)) {
|
||||||
memp_free(MEMP_PPP_PCB, pcb);
|
memp_free(MEMP_PPP_PCB, pcb);
|
||||||
PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n"));
|
PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n"));
|
||||||
@ -681,10 +690,12 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
|
|||||||
|
|
||||||
switch(protocol) {
|
switch(protocol) {
|
||||||
|
|
||||||
|
#if PPP_IPV4_SUPPORT
|
||||||
case PPP_IP: /* Internet Protocol */
|
case PPP_IP: /* Internet Protocol */
|
||||||
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
|
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
|
||||||
ip4_input(pb, pcb->netif);
|
ip4_input(pb, pcb->netif);
|
||||||
return;
|
return;
|
||||||
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
|
|
||||||
#if PPP_IPV6_SUPPORT
|
#if PPP_IPV6_SUPPORT
|
||||||
case PPP_IPV6: /* Internet Protocol Version 6 */
|
case PPP_IPV6: /* Internet Protocol Version 6 */
|
||||||
@ -1154,6 +1165,7 @@ int get_loop_output(void) {
|
|||||||
}
|
}
|
||||||
#endif /* DEMAND_SUPPORT */
|
#endif /* DEMAND_SUPPORT */
|
||||||
|
|
||||||
|
#if PPP_IPV4_SUPPORT
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
*
|
*
|
||||||
* Return user specified netmask, modified by any mask we might determine
|
* Return user specified netmask, modified by any mask we might determine
|
||||||
@ -1189,6 +1201,7 @@ u32_t get_mask(u32_t addr) {
|
|||||||
LWIP_UNUSED_ARG(addr);
|
LWIP_UNUSED_ARG(addr);
|
||||||
return IPADDR_BROADCAST;
|
return IPADDR_BROADCAST;
|
||||||
}
|
}
|
||||||
|
#endif /* PPP_IPV4_SUPPORT */
|
||||||
|
|
||||||
|
|
||||||
#if PPP_PROTOCOLNAME
|
#if PPP_PROTOCOLNAME
|
||||||
|
Loading…
x
Reference in New Issue
Block a user