Skip to content

Commit f23450b

Browse files
committed
Merge branch 'bugfix/mldv6_report_memory_leak_v5.2' into 'release/v5.2'
fix(esp_netif): Fix mldv6 report memory leak in esp_netif(v5.2) See merge request espressif/esp-idf!31063
2 parents 786d478 + 79d3229 commit f23450b

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

components/esp_netif/lwip/esp_netif_lwip.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -140,8 +140,8 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif);
140140
#endif
141141
#if LWIP_IPV6
142142
static void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index);
143-
static void netif_set_mldv6_flag(struct netif *netif);
144-
static void netif_unset_mldv6_flag(struct netif *netif);
143+
static void netif_set_mldv6_flag(esp_netif_t *netif);
144+
static void netif_unset_mldv6_flag(esp_netif_t *netif);
145145
#endif /* LWIP_IPV6 */
146146

147147
static esp_err_t esp_netif_destroy_api(esp_netif_api_msg_t *msg);
@@ -156,7 +156,8 @@ static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, co
156156
#if LWIP_IPV6
157157
if ((reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED) && (args != NULL)) {
158158
s8_t addr_idx = args->ipv6_addr_state_changed.addr_index;
159-
if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
159+
if (!(args->ipv6_addr_state_changed.old_state & IP6_ADDR_VALID) &&
160+
netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
160161
/* address is valid -> call the callback function */
161162
esp_netif_internal_nd6_cb(netif, addr_idx);
162163
}
@@ -845,7 +846,7 @@ static void esp_netif_lwip_remove(esp_netif_t *esp_netif)
845846
#endif
846847
#if ESP_MLDV6_REPORT && LWIP_IPV6
847848
if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
848-
netif_unset_mldv6_flag(esp_netif->lwip_netif);
849+
netif_unset_mldv6_flag(esp_netif);
849850
}
850851
#endif
851852
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) {
@@ -1693,7 +1694,7 @@ static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg)
16931694
#if CONFIG_LWIP_IPV6
16941695
#if ESP_MLDV6_REPORT
16951696
if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
1696-
netif_unset_mldv6_flag(esp_netif->lwip_netif);
1697+
netif_unset_mldv6_flag(esp_netif);
16971698
}
16981699
#endif
16991700
for(int8_t i = 0 ;i < LWIP_IPV6_NUM_ADDRESSES ;i++) {
@@ -1997,25 +1998,31 @@ esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty
19971998

19981999
static void netif_send_mldv6(void *arg)
19992000
{
2000-
struct netif *netif = arg;
2001-
if (!netif_is_up(netif)) {
2001+
esp_netif_t *esp_netif = arg;
2002+
esp_netif->mldv6_report_timer_started = false;
2003+
if (!netif_is_up(esp_netif->lwip_netif)) {
20022004
return;
20032005
}
2004-
mld6_report_groups(netif);
2005-
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif);
2006+
mld6_report_groups(esp_netif->lwip_netif);
2007+
esp_netif->mldv6_report_timer_started = true;
2008+
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, esp_netif);
20062009
}
20072010

2008-
static void netif_set_mldv6_flag(struct netif *netif)
2011+
static void netif_set_mldv6_flag(esp_netif_t *esp_netif)
20092012
{
2010-
if (!netif_is_up(netif)) {
2013+
if (!netif_is_up(esp_netif->lwip_netif) || esp_netif->mldv6_report_timer_started) {
20112014
return;
20122015
}
2013-
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif);
2016+
esp_netif->mldv6_report_timer_started = true;
2017+
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, esp_netif);
20142018
}
20152019

2016-
static void netif_unset_mldv6_flag(struct netif *netif)
2020+
static void netif_unset_mldv6_flag(esp_netif_t *esp_netif)
20172021
{
2018-
sys_untimeout(netif_send_mldv6, netif);
2022+
if (esp_netif->mldv6_report_timer_started) {
2023+
esp_netif->mldv6_report_timer_started = false;
2024+
sys_untimeout(netif_send_mldv6, esp_netif);
2025+
}
20192026
}
20202027

20212028
#endif
@@ -2062,7 +2069,7 @@ static void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t ip_index)
20622069

20632070
if (esp_netif->flags&ESP_NETIF_FLAG_MLDV6_REPORT) {
20642071
#if ESP_MLDV6_REPORT
2065-
netif_set_mldv6_flag(netif);
2072+
netif_set_mldv6_flag(esp_netif);
20662073
#else
20672074
ESP_LOGW(TAG,"CONFIG_LWIP_ESP_MLDV6_REPORT not enabled, but esp-netif configured with ESP_NETIF_FLAG_MLDV6_REPORT");
20682075
#endif

components/esp_netif/lwip/esp_netif_lwip_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,6 @@ struct esp_netif_obj {
112112
uint16_t max_fdb_sta_entries;
113113
uint8_t max_ports;
114114
#endif // CONFIG_ESP_NETIF_BRIDGE_EN
115+
// mldv6 timer
116+
bool mldv6_report_timer_started;
115117
};

0 commit comments

Comments
 (0)