mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #3526 from geky/lwip-fix-static-ip-dns
lwip - Fix static IP address issues with IPv4pull/3550/head
commit
7b83e0ff93
|
@ -243,24 +243,24 @@ const ip_addr_t *mbed_lwip_get_ip_addr(bool any_addr, const struct netif *netif)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LWIP_IPV6
|
|
||||||
void add_dns_addr(struct netif *lwip_netif)
|
void add_dns_addr(struct netif *lwip_netif)
|
||||||
{
|
{
|
||||||
|
// Do nothing if not brought up
|
||||||
const ip_addr_t *ip_addr = mbed_lwip_get_ip_addr(true, lwip_netif);
|
const ip_addr_t *ip_addr = mbed_lwip_get_ip_addr(true, lwip_netif);
|
||||||
if (ip_addr) {
|
if (!ip_addr) {
|
||||||
if (IP_IS_V6(ip_addr)) {
|
return;
|
||||||
const ip_addr_t *dns_ip_addr;
|
}
|
||||||
bool dns_addr_exists = false;
|
|
||||||
|
|
||||||
|
// Check for existing dns server
|
||||||
for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) {
|
for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) {
|
||||||
dns_ip_addr = dns_getserver(numdns);
|
const ip_addr_t *dns_ip_addr = dns_getserver(numdns);
|
||||||
if (!ip_addr_isany(dns_ip_addr)) {
|
if (!ip_addr_isany(dns_ip_addr)) {
|
||||||
dns_addr_exists = true;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dns_addr_exists) {
|
#if LWIP_IPV6
|
||||||
|
if (IP_IS_V6(ip_addr)) {
|
||||||
/* 2001:4860:4860::8888 google */
|
/* 2001:4860:4860::8888 google */
|
||||||
ip_addr_t ipv6_dns_addr = IPADDR6_INIT(
|
ip_addr_t ipv6_dns_addr = IPADDR6_INIT(
|
||||||
PP_HTONL(0x20014860UL),
|
PP_HTONL(0x20014860UL),
|
||||||
|
@ -269,11 +269,17 @@ void add_dns_addr(struct netif *lwip_netif)
|
||||||
PP_HTONL(0x00008888UL));
|
PP_HTONL(0x00008888UL));
|
||||||
dns_setserver(0, &ipv6_dns_addr);
|
dns_setserver(0, &ipv6_dns_addr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LWIP_IPV4
|
||||||
|
if (IP_IS_V4(ip_addr)) {
|
||||||
|
/* 8.8.8.8 google */
|
||||||
|
ip_addr_t ipv4_dns_addr = IPADDR4_INIT(0x08080808);
|
||||||
|
dns_setserver(0, &ipv4_dns_addr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static sys_sem_t lwip_tcpip_inited;
|
static sys_sem_t lwip_tcpip_inited;
|
||||||
static void mbed_lwip_tcpip_init_irq(void *eh)
|
static void mbed_lwip_tcpip_init_irq(void *eh)
|
||||||
{
|
{
|
||||||
|
@ -495,7 +501,6 @@ nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask,
|
||||||
if (ret == SYS_ARCH_TIMEOUT) {
|
if (ret == SYS_ARCH_TIMEOUT) {
|
||||||
return NSAPI_ERROR_DHCP_FAILURE;
|
return NSAPI_ERROR_DHCP_FAILURE;
|
||||||
}
|
}
|
||||||
lwip_connected = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ADDR_TIMEOUT
|
#if ADDR_TIMEOUT
|
||||||
|
@ -506,10 +511,9 @@ nsapi_error_t mbed_lwip_bringup(bool dhcp, const char *ip, const char *netmask,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LWIP_IPV6
|
|
||||||
add_dns_addr(&lwip_netif);
|
add_dns_addr(&lwip_netif);
|
||||||
#endif
|
|
||||||
|
|
||||||
|
lwip_connected = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,6 +622,22 @@ static nsapi_error_t mbed_lwip_gethostbyname(nsapi_stack_t *stack, const char *h
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsapi_error_t mbed_lwip_add_dns_server(nsapi_stack_t *stack, nsapi_addr_t addr)
|
||||||
|
{
|
||||||
|
// Shift all dns servers down to give precedence to new server
|
||||||
|
for (int i = DNS_MAX_SERVERS-1; i > 0; i--) {
|
||||||
|
dns_setserver(i, dns_getserver(i-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_addr_t ip_addr;
|
||||||
|
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
|
||||||
|
return NSAPI_ERROR_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
dns_setserver(0, &ip_addr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static nsapi_error_t mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
|
static nsapi_error_t mbed_lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||||
{
|
{
|
||||||
// check if network is connected
|
// check if network is connected
|
||||||
|
@ -874,6 +894,7 @@ static void mbed_lwip_socket_attach(nsapi_stack_t *stack, nsapi_socket_t handle,
|
||||||
/* LWIP network stack */
|
/* LWIP network stack */
|
||||||
const nsapi_stack_api_t lwip_stack_api = {
|
const nsapi_stack_api_t lwip_stack_api = {
|
||||||
.gethostbyname = mbed_lwip_gethostbyname,
|
.gethostbyname = mbed_lwip_gethostbyname,
|
||||||
|
.add_dns_server = mbed_lwip_add_dns_server,
|
||||||
.socket_open = mbed_lwip_socket_open,
|
.socket_open = mbed_lwip_socket_open,
|
||||||
.socket_close = mbed_lwip_socket_close,
|
.socket_close = mbed_lwip_socket_close,
|
||||||
.socket_bind = mbed_lwip_socket_bind,
|
.socket_bind = mbed_lwip_socket_bind,
|
||||||
|
|
Loading…
Reference in New Issue