]> granicus.if.org Git - esp-idf/commitdiff
lwip: rebind UDP/TCP pcb to valid ip address when ip is changed
authorLiu Zhi Fu <liuzhifu@espressif.com>
Wed, 15 Nov 2017 08:15:24 +0000 (16:15 +0800)
committerLiu Zhi Fu <liuzhifu@espressif.com>
Wed, 15 Nov 2017 08:15:24 +0000 (16:15 +0800)
This change fix the issue UDP/TCP pcb failed to rebind to correct ip address when ip is changed

components/lwip/core/netif.c
components/lwip/include/lwip/lwip/netif.h

index 76e6f6132d37c96da06fd2eb28e874650c92b271..2b25143c6fa76931ca456be3997c76e41323ae97 100755 (executable)
@@ -453,14 +453,20 @@ void
 netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
 {
   ip4_addr_t new_addr = (ipaddr ? *ipaddr : *IP4_ADDR_ANY);
+#if ESP_LWIP
+  ip4_addr_t *last_addr = ip_2_ip4(&netif->last_ip_addr);
+#else
+  ip4_addr_t *last_addr = netif_ip4_addr(netif);
+#endif
+
   /* address is actually being changed? */
   if (ip4_addr_cmp(&new_addr, netif_ip4_addr(netif)) == 0) {
     LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
 #if LWIP_TCP
-    tcp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr);
+    tcp_netif_ipv4_addr_changed(last_addr, ipaddr);
 #endif /* LWIP_TCP */
 #if LWIP_UDP
-    udp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr);
+    udp_netif_ipv4_addr_changed(last_addr, ipaddr);
 #endif /* LWIP_UDP */
 
     mib2_remove_ip4(netif);
@@ -482,6 +488,10 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
     ip4_addr2_16(netif_ip4_addr(netif)),
     ip4_addr3_16(netif_ip4_addr(netif)),
     ip4_addr4_16(netif_ip4_addr(netif))));
+
+  if (ipaddr && !ip4_addr_isany(ipaddr)) {
+    ip4_addr_set(ip_2_ip4(&netif->last_ip_addr), ipaddr);
+  }
 }
 
 /**
index f5ca067edea36da3010b2557e1de13dd387bbcd9..bd25b82173415b382e877241026137710db9945e 100755 (executable)
@@ -333,6 +333,7 @@ struct netif {
 
 #if ESP_LWIP
   void (*l2_buffer_free_notify)(void *user_buf); /* Allows LWIP to notify driver when a L2-supplied pbuf can be freed */
+  ip_addr_t last_ip_addr; /* Store last non-zero ip address */
 #endif
 };