feat(lwip): Rebind UDP pcb when IP changed

1. Rebind the UDP pcb, which originally bind to non-zero IPv4 address, to
   the new IPv4 address when the IPv4 address of related netif is changed.
2. Rebind the TCP pcb, which is in listening status, to the new IPv4 address
   when IPv4 address of related netif is changed.

Notice: Recompile some related libs due to netif.h changed.

internal: f194dd34
This commit is contained in:
Espressif Systems
2017-08-25 12:14:33 +08:00
parent e0f5e219ea
commit 7fbd498a3c
8 changed files with 41 additions and 10 deletions

View File

@ -1,13 +1,14 @@
gwen: gwen:
espconn: 730c7f0
espnow: 1aafc07 espnow: 1aafc07
main: b2944d6 main: 730c7f0
mesh: 1aafc07 mesh: 1aafc07
net80211: 1aafc07 net80211: 730c7f0
pp: 1474356 pp: 1474356
wpa: 1aafc07 wpa: 730c7f0
wps: 1aafc07 wps: 1aafc07
gitlab: gitlab:
lwip: 243eb8be lwip: 2235ad17
driver: 7bee5263 driver: 7bee5263
mbedtls: 1ac9f1f4 mbedtls: 1ac9f1f4

View File

@ -160,6 +160,10 @@ struct netif {
/** pointer to next in linked list */ /** pointer to next in linked list */
struct netif *next; struct netif *next;
#ifdef LWIP_ESP8266
ip_addr_t last_ip_addr;
#endif
/** IP address configuration in network byte order */ /** IP address configuration in network byte order */
ip_addr_t ip_addr; ip_addr_t ip_addr;
ip_addr_t netmask; ip_addr_t netmask;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -395,16 +395,42 @@ netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)
} }
} }
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
/* PCB bound to current local interface address? */ if (!ip_addr_isany(ipaddr)) {
if ((!(ip_addr_isany(ipX_2_ip(&lpcb->local_ip)))) && /* PCB bound to current local interface address? */
(ip_addr_cmp(ipX_2_ip(&lpcb->local_ip), &(netif->ip_addr)))) { if ((!(ip_addr_isany(ipX_2_ip(&lpcb->local_ip)))) &&
/* The PCB is listening to the old ipaddr and (ip_addr_cmp(ipX_2_ip(&lpcb->local_ip), &(netif->last_ip_addr)))) {
* is set to listen to the new one instead */ /* The PCB is listening to the old ipaddr and
ip_addr_set(ipX_2_ip(&lpcb->local_ip), ipaddr); * is set to listen to the new one instead */
ip_addr_set(ipX_2_ip(&lpcb->local_ip), ipaddr);
}
} }
} }
} }
#endif #endif
#if LWIP_UDP
#ifdef LWIP_ESP8266
if (ipaddr && (ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
if (!ip_addr_isany(ipaddr)) {
struct udp_pcb* upcb;
for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
/* PCB bound to current local interface address? */
if (!ip_addr_isany(ipX_2_ip(&upcb->local_ip)) &&
ip_addr_cmp(ipX_2_ip(&upcb->local_ip), &(netif->last_ip_addr))) {
/* The PCB is bound to the old ipaddr and
* is set to bound to the new one instead */
ip_addr_set(ipX_2_ip(&upcb->local_ip), ipaddr);
}
}
}
}
if (ipaddr && !ip_addr_isany(ipaddr)) {
ip_addr_set(&(netif->last_ip_addr), ipaddr);
}
#endif
#endif
snmp_delete_ipaddridx_tree(netif); snmp_delete_ipaddridx_tree(netif);
snmp_delete_iprteidx_tree(0,netif); snmp_delete_iprteidx_tree(0,netif);
/* set new IP address to netif */ /* set new IP address to netif */