Skip to content

Commit cf8dad0

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/esp_netif_reassign_static_ip_v5.5' into 'release/v5.5'
fix(esp_netif): Fix reasigning static IP after netif down -> up (v5.5) See merge request espressif/esp-idf!40169
2 parents adb3f2a + a6f0925 commit cf8dad0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

components/esp_netif/lwip/esp_netif_lwip.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,12 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif)
14631463
} else {
14641464
if (!ip4_addr_cmp(&ip_info->ip, IP4_ADDR_ANY4)) {
14651465
esp_netif_start_ip_lost_timer(esp_netif);
1466-
// synchronize lwip netif with esp_netif setting ip_info to 0,
1467-
// so the next time we get a valid IP we can raise the event
1468-
ip4_addr_set(&ip_info->ip, ip_2_ip4(&netif->ip_addr));
1469-
ip4_addr_set(&ip_info->netmask, ip_2_ip4(&netif->netmask));
1470-
ip4_addr_set(&ip_info->gw, ip_2_ip4(&netif->gw));
1466+
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT && esp_netif->dhcpc_status == ESP_NETIF_DHCP_STARTED) {
1467+
// Only for active DHCP client (in case of static IP, we keep the last configure value in ip_info)
1468+
// synchronize lwip netif with esp_netif setting ip_info to 0,
1469+
// so the next time we get a valid IP we can raise the event
1470+
esp_netif_reset_ip_info(esp_netif);
1471+
}
14711472
}
14721473
}
14731474
}
@@ -1495,7 +1496,10 @@ static void esp_netif_ip_lost_timer(void *arg)
14951496
esp_netif_update_default_netif(esp_netif, ESP_NETIF_LOST_IP);
14961497
ESP_LOGD(TAG, "if%p ip lost tmr: raise ip lost event", esp_netif);
14971498
memset(esp_netif->ip_info_old, 0, sizeof(esp_netif_ip_info_t));
1498-
memset(esp_netif->ip_info, 0, sizeof(esp_netif_ip_info_t));
1499+
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT && esp_netif->dhcpc_status == ESP_NETIF_DHCP_STARTED) {
1500+
// Reset IP info if using DHCP client (static IP is supposed to be restored based on the ip_info)
1501+
esp_netif_reset_ip_info(esp_netif);
1502+
}
14991503
if (esp_netif->lost_ip_event) {
15001504
ret = esp_event_post(IP_EVENT, esp_netif->lost_ip_event,
15011505
&evt, sizeof(evt), 0);

0 commit comments

Comments
 (0)