Skip to content

Commit bc34abb

Browse files
committed
Merge branch 'fix/esp_netif_reassign_static_ip' into 'master'
fix(esp_netif): Fix reasigning static IP after netif down -> up Closes IDF-13024 and WIFIBUG-1228 See merge request espressif/esp-idf!39725
2 parents ce6e136 + c57254c commit bc34abb

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
@@ -1470,11 +1470,12 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif)
14701470
} else {
14711471
if (!ip4_addr_cmp(&ip_info->ip, IP4_ADDR_ANY4)) {
14721472
esp_netif_start_ip_lost_timer(esp_netif);
1473-
// synchronize lwip netif with esp_netif setting ip_info to 0,
1474-
// so the next time we get a valid IP we can raise the event
1475-
ip4_addr_set(&ip_info->ip, ip_2_ip4(&netif->ip_addr));
1476-
ip4_addr_set(&ip_info->netmask, ip_2_ip4(&netif->netmask));
1477-
ip4_addr_set(&ip_info->gw, ip_2_ip4(&netif->gw));
1473+
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT && esp_netif->dhcpc_status == ESP_NETIF_DHCP_STARTED) {
1474+
// Only for active DHCP client (in case of static IP, we keep the last configure value in ip_info)
1475+
// synchronize lwip netif with esp_netif setting ip_info to 0,
1476+
// so the next time we get a valid IP we can raise the event
1477+
esp_netif_reset_ip_info(esp_netif);
1478+
}
14781479
}
14791480
}
14801481
}
@@ -1502,7 +1503,10 @@ static void esp_netif_ip_lost_timer(void *arg)
15021503
esp_netif_update_default_netif(esp_netif, ESP_NETIF_LOST_IP);
15031504
ESP_LOGD(TAG, "if%p ip lost tmr: raise ip lost event", esp_netif);
15041505
memset(esp_netif->ip_info_old, 0, sizeof(esp_netif_ip_info_t));
1505-
memset(esp_netif->ip_info, 0, sizeof(esp_netif_ip_info_t));
1506+
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT && esp_netif->dhcpc_status == ESP_NETIF_DHCP_STARTED) {
1507+
// Reset IP info if using DHCP client (static IP is supposed to be restored based on the ip_info)
1508+
esp_netif_reset_ip_info(esp_netif);
1509+
}
15061510
if (esp_netif->lost_ip_event) {
15071511
ret = esp_event_post(IP_EVENT, esp_netif->lost_ip_event,
15081512
&evt, sizeof(evt), 0);

0 commit comments

Comments
 (0)