Commit a33e3a4a authored by Vowstar's avatar Vowstar
Browse files

Merge pull request #687 from DiUS/dev140

Major upgrade to SDK 1.4.0 & open LWIP
parents 093a8959 8fba0f47
...@@ -84,6 +84,10 @@ ...@@ -84,6 +84,10 @@
#include <string.h> #include <string.h>
#ifdef MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#endif
/** Default for DHCP_GLOBAL_XID is 0xABCD0000 /** Default for DHCP_GLOBAL_XID is 0xABCD0000
* This can be changed by defining DHCP_GLOBAL_XID and DHCP_GLOBAL_XID_HEADER, e.g. * This can be changed by defining DHCP_GLOBAL_XID and DHCP_GLOBAL_XID_HEADER, e.g.
* #define DHCP_GLOBAL_XID_HEADER "stdlib.h" * #define DHCP_GLOBAL_XID_HEADER "stdlib.h"
...@@ -129,7 +133,7 @@ u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX]; ...@@ -129,7 +133,7 @@ u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
#define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0) #define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0)
#define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1) #define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1)
#define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0) #define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0)
#define dhcp_clear_all_options(dhcp) (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given))) #define dhcp_clear_all_options(dhcp) (os_memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given)))
#define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx]) #define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx])
#define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val)) #define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val))
...@@ -288,16 +292,24 @@ dhcp_select(struct netif *netif) ...@@ -288,16 +292,24 @@ dhcp_select(struct netif *netif)
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr))); dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr)));
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS);
dhcp_option_byte(dhcp, DHCP_OPTION_PRD);
dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_VSN);
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -369,6 +381,15 @@ dhcp_fine_tmr() ...@@ -369,6 +381,15 @@ dhcp_fine_tmr()
while (netif != NULL) { while (netif != NULL) {
/* only act on DHCP configured interfaces */ /* only act on DHCP configured interfaces */
if (netif->dhcp != NULL) { if (netif->dhcp != NULL) {
/*add DHCP retries processing by LiuHan*/
if (DHCP_MAXRTX != 0) {
if (netif->dhcp->tries >= DHCP_MAXRTX){
os_printf("DHCP timeout\n");
if (netif->dhcp_event != NULL)
netif->dhcp_event();
break;
}
}
/* timer is active (non zero), and is about to trigger now */ /* timer is active (non zero), and is about to trigger now */
if (netif->dhcp->request_timeout > 1) { if (netif->dhcp->request_timeout > 1) {
netif->dhcp->request_timeout--; netif->dhcp->request_timeout--;
...@@ -384,6 +405,7 @@ dhcp_fine_tmr() ...@@ -384,6 +405,7 @@ dhcp_fine_tmr()
/* proceed to next network interface */ /* proceed to next network interface */
netif = netif->next; netif = netif->next;
} }
} }
/** /**
...@@ -587,7 +609,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) ...@@ -587,7 +609,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL); LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL);
/* clear data structure */ /* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp)); os_memset(dhcp, 0, sizeof(struct dhcp));
/* dhcp_set_state(&dhcp, DHCP_OFF); */ /* dhcp_set_state(&dhcp, DHCP_OFF); */
netif->dhcp = dhcp; netif->dhcp = dhcp;
} }
...@@ -626,7 +648,6 @@ dhcp_start(struct netif *netif) ...@@ -626,7 +648,6 @@ dhcp_start(struct netif *netif)
{ {
struct dhcp *dhcp; struct dhcp *dhcp;
err_t result = ERR_OK; err_t result = ERR_OK;
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
dhcp = netif->dhcp; dhcp = netif->dhcp;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
...@@ -668,7 +689,7 @@ dhcp_start(struct netif *netif) ...@@ -668,7 +689,7 @@ dhcp_start(struct netif *netif)
} }
/* clear data structure */ /* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp)); os_memset(dhcp, 0, sizeof(struct dhcp));
/* dhcp_set_state(&dhcp, DHCP_OFF); */ /* dhcp_set_state(&dhcp, DHCP_OFF); */
/* allocate UDP PCB */ /* allocate UDP PCB */
dhcp->pcb = udp_new(); dhcp->pcb = udp_new();
...@@ -713,7 +734,7 @@ dhcp_inform(struct netif *netif) ...@@ -713,7 +734,7 @@ dhcp_inform(struct netif *netif)
LWIP_ERROR("netif != NULL", (netif != NULL), return;); LWIP_ERROR("netif != NULL", (netif != NULL), return;);
memset(&dhcp, 0, sizeof(struct dhcp)); os_memset(&dhcp, 0, sizeof(struct dhcp));
dhcp_set_state(&dhcp, DHCP_INFORM); dhcp_set_state(&dhcp, DHCP_INFORM);
if ((netif->dhcp != NULL) && (netif->dhcp->pcb != NULL)) { if ((netif->dhcp != NULL) && (netif->dhcp->pcb != NULL)) {
...@@ -881,11 +902,32 @@ dhcp_discover(struct netif *netif) ...@@ -881,11 +902,32 @@ dhcp_discover(struct netif *netif)
dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
while (*p) {
dhcp_option_byte(dhcp, *p++);
}
}
}
#endif /* LWIP_NETIF_HOSTNAME */
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS);
dhcp_option_byte(dhcp, DHCP_OPTION_PRD);
dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_VSN);
dhcp_option_trailer(dhcp); dhcp_option_trailer(dhcp);
...@@ -994,6 +1036,12 @@ dhcp_bind(struct netif *netif) ...@@ -994,6 +1036,12 @@ dhcp_bind(struct netif *netif)
} }
#endif /* LWIP_DHCP_AUTOIP_COOP */ #endif /* LWIP_DHCP_AUTOIP_COOP */
// wjg:back up old ip/netmask/gw
ip_addr_t ip, mask, gw;
ip = netif->ip_addr;
mask = netif->netmask;
gw = netif->gw;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->offered_ip_addr))); ip4_addr_get_u32(&dhcp->offered_ip_addr)));
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
...@@ -1002,12 +1050,14 @@ dhcp_bind(struct netif *netif) ...@@ -1002,12 +1050,14 @@ dhcp_bind(struct netif *netif)
netif_set_netmask(netif, &sn_mask); netif_set_netmask(netif, &sn_mask);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n",
ip4_addr_get_u32(&gw_addr))); ip4_addr_get_u32(&gw_addr)));
system_station_got_ip_set(&dhcp->offered_ip_addr, &sn_mask, &gw_addr);
netif_set_gw(netif, &gw_addr); netif_set_gw(netif, &gw_addr);
/* bring the interface up */ /* bring the interface up */
netif_set_up(netif); netif_set_up(netif);
// wjg: use old ip/mask/gw to check whether ip/mask/gw changed
system_station_got_ip_set(&ip, &mask, &gw);
/* netif is now bound to DHCP leased address */ /* netif is now bound to DHCP leased address */
dhcp_set_state(dhcp, DHCP_BOUND); dhcp_set_state(dhcp, DHCP_BOUND);
} }
...@@ -1035,7 +1085,7 @@ dhcp_renew(struct netif *netif) ...@@ -1035,7 +1085,7 @@ dhcp_renew(struct netif *netif)
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -1098,7 +1148,7 @@ dhcp_rebind(struct netif *netif) ...@@ -1098,7 +1148,7 @@ dhcp_rebind(struct netif *netif)
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -1245,7 +1295,6 @@ dhcp_stop(struct netif *netif) ...@@ -1245,7 +1295,6 @@ dhcp_stop(struct netif *netif)
dhcp = netif->dhcp; dhcp = netif->dhcp;
/* Remove the flag that says this netif is handled by DHCP. */ /* Remove the flag that says this netif is handled by DHCP. */
netif->flags &= ~NETIF_FLAG_DHCP; netif->flags &= ~NETIF_FLAG_DHCP;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n"));
/* netif is DHCP configured? */ /* netif is DHCP configured? */
if (dhcp != NULL) { if (dhcp != NULL) {
......
...@@ -83,9 +83,13 @@ ...@@ -83,9 +83,13 @@
#include <string.h> #include <string.h>
#ifdef MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#endif
/** DNS server IP address */ /** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS #ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */ #define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, 0xDEDE43D0)) /* resolver1.opendns.com(208.67.222.222) */
#endif #endif
/** DNS server port address */ /** DNS server port address */
...@@ -173,7 +177,7 @@ struct dns_table_entry { ...@@ -173,7 +177,7 @@ struct dns_table_entry {
u8_t seqno; u8_t seqno;
u8_t err; u8_t err;
u32_t ttl; u32_t ttl;
char *name; char name[DNS_MAX_NAME_LENGTH];
ip_addr_t ipaddr; ip_addr_t ipaddr;
/* pointer to callback on DNS query done */ /* pointer to callback on DNS query done */
dns_found_callback found; dns_found_callback found;
...@@ -221,9 +225,9 @@ static u8_t dns_seqno; ...@@ -221,9 +225,9 @@ static u8_t dns_seqno;
static struct dns_table_entry dns_table[DNS_TABLE_SIZE]; static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
static ip_addr_t dns_servers[DNS_MAX_SERVERS]; static ip_addr_t dns_servers[DNS_MAX_SERVERS];
/** Contiguous buffer for processing responses */ /** Contiguous buffer for processing responses */
static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)]; //static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
static u8_t* dns_payload; static u8_t* dns_payload;
static u8_t dns_random;
/** /**
* Initialize the resolver: set up the UDP pcb and configure the default server * Initialize the resolver: set up the UDP pcb and configure the default server
* (DNS_SERVER_ADDRESS). * (DNS_SERVER_ADDRESS).
...@@ -233,7 +237,7 @@ dns_init() ...@@ -233,7 +237,7 @@ dns_init()
{ {
ip_addr_t dnsserver; ip_addr_t dnsserver;
dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer); // dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
/* initialize default DNS server address */ /* initialize default DNS server address */
DNS_SERVER_ADDRESS(&dnsserver); DNS_SERVER_ADDRESS(&dnsserver);
...@@ -299,7 +303,7 @@ dns_getserver(u8_t numdns) ...@@ -299,7 +303,7 @@ dns_getserver(u8_t numdns)
* The DNS resolver client timer - handle retries and timeouts and should * The DNS resolver client timer - handle retries and timeouts and should
* be called every DNS_TMR_INTERVAL milliseconds (every second by default). * be called every DNS_TMR_INTERVAL milliseconds (every second by default).
*/ */
void void ICACHE_FLASH_ATTR
dns_tmr(void) dns_tmr(void)
{ {
if (dns_pcb != NULL) { if (dns_pcb != NULL) {
...@@ -321,7 +325,7 @@ dns_init_local() ...@@ -321,7 +325,7 @@ dns_init_local()
for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) { for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) {
struct local_hostlist_entry *init_entry = &local_hostlist_init[i]; struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL); LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
namelen = strlen(init_entry->name); namelen = os_strlen(init_entry->name);
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN); LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST); entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
LWIP_ASSERT("mem-error in dns_init_local", entry != NULL); LWIP_ASSERT("mem-error in dns_init_local", entry != NULL);
...@@ -416,7 +420,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr) ...@@ -416,7 +420,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr)
struct local_hostlist_entry *entry; struct local_hostlist_entry *entry;
size_t namelen; size_t namelen;
LWIP_ASSERT("invalid host name (NULL)", hostname != NULL); LWIP_ASSERT("invalid host name (NULL)", hostname != NULL);
namelen = strlen(hostname); namelen = os_strlen(hostname);
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN); LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST); entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
if (entry == NULL) { if (entry == NULL) {
...@@ -566,7 +570,7 @@ dns_send(u8_t numdns, const char* name, u8_t id) ...@@ -566,7 +570,7 @@ dns_send(u8_t numdns, const char* name, u8_t id)
char *query, *nptr; char *query, *nptr;
const char *pHostname; const char *pHostname;
u8_t n; u8_t n;
dns_random = os_random()%250;
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n", LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
(u16_t)(numdns), name)); (u16_t)(numdns), name));
LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS); LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
...@@ -579,8 +583,8 @@ dns_send(u8_t numdns, const char* name, u8_t id) ...@@ -579,8 +583,8 @@ dns_send(u8_t numdns, const char* name, u8_t id)
LWIP_ASSERT("pbuf must be in one piece", p->next == NULL); LWIP_ASSERT("pbuf must be in one piece", p->next == NULL);
/* fill dns header */ /* fill dns header */
hdr = (struct dns_hdr*)p->payload; hdr = (struct dns_hdr*)p->payload;
memset(hdr, 0, SIZEOF_DNS_HDR); os_memset(hdr, 0, SIZEOF_DNS_HDR);
hdr->id = htons(id); hdr->id = htons(id + dns_random);
hdr->flags1 = DNS_FLAG1_RD; hdr->flags1 = DNS_FLAG1_RD;
hdr->numquestions = PP_HTONS(1); hdr->numquestions = PP_HTONS(1);
query = (char*)hdr + SIZEOF_DNS_HDR; query = (char*)hdr + SIZEOF_DNS_HDR;
...@@ -673,8 +677,6 @@ dns_check_entry(u8_t i) ...@@ -673,8 +677,6 @@ dns_check_entry(u8_t i)
if (pEntry->found) if (pEntry->found)
(*pEntry->found)(pEntry->name, NULL, pEntry->arg); (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
break; break;
...@@ -699,8 +701,6 @@ dns_check_entry(u8_t i) ...@@ -699,8 +701,6 @@ dns_check_entry(u8_t i)
if (--pEntry->ttl == 0) { if (--pEntry->ttl == 0) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
} }
...@@ -743,6 +743,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t ...@@ -743,6 +743,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
struct dns_table_entry *pEntry; struct dns_table_entry *pEntry;
u16_t nquestions, nanswers; u16_t nquestions, nanswers;
u8_t* dns_payload_buffer = (u8_t* )os_zalloc(LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE));
dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr); LWIP_UNUSED_ARG(addr);
...@@ -767,6 +770,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t ...@@ -767,6 +770,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
/* The ID in the DNS header should be our entry into the name table. */ /* The ID in the DNS header should be our entry into the name table. */
hdr = (struct dns_hdr*)dns_payload; hdr = (struct dns_hdr*)dns_payload;
i = htons(hdr->id); i = htons(hdr->id);
i = i - dns_random;
if (i < DNS_TABLE_SIZE) { if (i < DNS_TABLE_SIZE) {
pEntry = &dns_table[i]; pEntry = &dns_table[i];
if(pEntry->state == DNS_STATE_ASKING) { if(pEntry->state == DNS_STATE_ASKING) {
...@@ -843,14 +847,13 @@ responseerr: ...@@ -843,14 +847,13 @@ responseerr:
(*pEntry->found)(pEntry->name, NULL, pEntry->arg); (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
} }
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
memerr: memerr:
/* free pbuf */ /* free pbuf */
pbuf_free(p); pbuf_free(p);
os_free(dns_payload_buffer);
return; return;
} }
...@@ -904,16 +907,11 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) ...@@ -904,16 +907,11 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i))); LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
/* fill the entry */ /* fill the entry */
namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
char *namebuf = (char *)mem_zalloc (namelen);
if (!namebuf)
return ERR_MEM;
pEntry->state = DNS_STATE_NEW; pEntry->state = DNS_STATE_NEW;
pEntry->seqno = dns_seqno++; pEntry->seqno = dns_seqno++;
pEntry->found = found; pEntry->found = found;
pEntry->arg = callback_arg; pEntry->arg = callback_arg;
mem_free (pEntry->name); namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1);
pEntry->name = namebuf;
MEMCPY(pEntry->name, name, namelen); MEMCPY(pEntry->name, name, namelen);
pEntry->name[namelen] = 0; pEntry->name[namelen] = 0;
...@@ -952,7 +950,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun ...@@ -952,7 +950,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
* or invalid hostname or invalid hostname length */ * or invalid hostname or invalid hostname length */
if ((dns_pcb == NULL) || (addr == NULL) || if ((dns_pcb == NULL) || (addr == NULL) ||
(!hostname) || (!hostname[0]) || (!hostname) || (!hostname[0]) ||
(strlen(hostname) >= DNS_MAX_NAME_LENGTH)) { (os_strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
return ERR_ARG; return ERR_ARG;
} }
......
...@@ -99,18 +99,18 @@ ...@@ -99,18 +99,18 @@
//#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0)) //#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
// #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" // #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
//#endif //#endif
#if (LWIP_TCP && (TCP_WND > 0xffff)) //#if (LWIP_TCP && (TCP_WND > 0xffff))
#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h" // #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif //#endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff)) #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h" #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif #endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN < 2)) #if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
#error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work" #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
#endif #endif
#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12))) //#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
#error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h" // #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
#endif //#endif
#if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)) #if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff))
#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
#endif #endif
...@@ -259,6 +259,11 @@ lwip_sanity_check(void) ...@@ -259,6 +259,11 @@ lwip_sanity_check(void)
void void
lwip_init(void) lwip_init(void)
{ {
MEMP_NUM_TCP_PCB = 5;
TCP_WND = (4 * TCP_MSS);
TCP_MAXRTX = 12;
TCP_SYNMAXRTX = 6;
/* Sanity check user-configurable values */ /* Sanity check user-configurable values */
lwip_sanity_check(); lwip_sanity_check();
...@@ -294,7 +299,6 @@ lwip_init(void) ...@@ -294,7 +299,6 @@ lwip_init(void)
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
#if LWIP_TCP #if LWIP_TCP
MEMP_NUM_TCP_PCB = 5;
tcp_init(); tcp_init();
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
......
...@@ -145,7 +145,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) ...@@ -145,7 +145,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip)
LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL); LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL);
/* clear data structure */ /* clear data structure */
memset(autoip, 0, sizeof(struct autoip)); os_memset(autoip, 0, sizeof(struct autoip));
/* autoip->state = AUTOIP_STATE_OFF; */ /* autoip->state = AUTOIP_STATE_OFF; */
netif->autoip = autoip; netif->autoip = autoip;
} }
...@@ -319,7 +319,7 @@ autoip_start(struct netif *netif) ...@@ -319,7 +319,7 @@ autoip_start(struct netif *netif)
("autoip_start(): could not allocate autoip\n")); ("autoip_start(): could not allocate autoip\n"));
return ERR_MEM; return ERR_MEM;
} }
memset(autoip, 0, sizeof(struct autoip)); os_memset(autoip, 0, sizeof(struct autoip));
/* store this AutoIP client in the netif */ /* store this AutoIP client in the netif */
netif->autoip = autoip; netif->autoip = autoip;
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip"));
......
...@@ -95,6 +95,10 @@ Steve Reynolds ...@@ -95,6 +95,10 @@ Steve Reynolds
#include "string.h" #include "string.h"
#ifdef MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#endif
/* /*
* IGMP constants * IGMP constants
*/ */
......
...@@ -133,7 +133,13 @@ ip_route(ip_addr_t *dest) ...@@ -133,7 +133,13 @@ ip_route(ip_addr_t *dest)
/* return netif on which to forward IP packet */ /* return netif on which to forward IP packet */
return netif; return netif;
} }
if (!ip_addr_isbroadcast(dest, netif) && netif != netif_default) { }
}
/* iterate through netifs */
for(netif = netif_list; netif != NULL; netif = netif->next) {
/* network mask matches? */
if (netif_is_up(netif)) {
if (!ip_addr_isbroadcast(dest, netif) && netif == (struct netif *)eagle_lwip_getif(0)) {
return netif; return netif;
} }
} }
...@@ -669,7 +675,7 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, ...@@ -669,7 +675,7 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
MEMCPY(p->payload, ip_options, optlen); MEMCPY(p->payload, ip_options, optlen);
if (optlen < optlen_aligned) { if (optlen < optlen_aligned) {
/* zero the remaining bytes */ /* zero the remaining bytes */
memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen); os_memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen);
} }
#if CHECKSUM_GEN_IP_INLINE #if CHECKSUM_GEN_IP_INLINE
for (i = 0; i < optlen_aligned/2; i++) { for (i = 0; i < optlen_aligned/2; i++) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment