fix(esp_netif): Fix mldv6 report memory leak in esp_netif

This commit is contained in:
WanqQixiang 2024-05-17 15:30:45 +08:00
parent d962b76743
commit e3a2ba8b07
3 changed files with 27 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -112,8 +112,8 @@ static netif_ext_callback_t netif_callback = { .callback_fn = NULL, .next = NULL
static void esp_netif_internal_dhcpc_cb(struct netif *netif);
#if LWIP_IPV6
static void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index);
static void netif_set_mldv6_flag(struct netif *netif);
static void netif_unset_mldv6_flag(struct netif *netif);
static void netif_set_mldv6_flag(esp_netif_t *netif);
static void netif_unset_mldv6_flag(esp_netif_t *netif);
#endif /* LWIP_IPV6 */
static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args)
@ -124,7 +124,8 @@ static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, co
#if LWIP_IPV6
if ((reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED) && (args != NULL)) {
s8_t addr_idx = args->ipv6_addr_state_changed.addr_index;
if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
if (!(args->ipv6_addr_state_changed.old_state & IP6_ADDR_VALID) &&
netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
/* address is valid -> call the callback function */
esp_netif_internal_nd6_cb(netif, addr_idx);
}
@ -820,7 +821,7 @@ static void esp_netif_lwip_remove(esp_netif_t *esp_netif)
#endif
#if ESP_MLDV6_REPORT && LWIP_IPV6
if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
netif_unset_mldv6_flag(esp_netif->lwip_netif);
netif_unset_mldv6_flag(esp_netif);
}
#endif
if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) {
@ -1634,7 +1635,7 @@ static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg)
#if CONFIG_LWIP_IPV6
#if ESP_MLDV6_REPORT
if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) {
netif_unset_mldv6_flag(esp_netif->lwip_netif);
netif_unset_mldv6_flag(esp_netif);
}
#endif
for(int8_t i = 0 ;i < LWIP_IPV6_NUM_ADDRESSES ;i++) {
@ -1949,25 +1950,31 @@ esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty
static void netif_send_mldv6(void *arg)
{
struct netif *netif = arg;
if (!netif_is_up(netif)) {
esp_netif_t *esp_netif = arg;
esp_netif->mldv6_report_timer_started = false;
if (!netif_is_up(esp_netif->lwip_netif)) {
return;
}
mld6_report_groups(netif);
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif);
mld6_report_groups(esp_netif->lwip_netif);
esp_netif->mldv6_report_timer_started = true;
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, esp_netif);
}
static void netif_set_mldv6_flag(struct netif *netif)
static void netif_set_mldv6_flag(esp_netif_t *esp_netif)
{
if (!netif_is_up(netif)) {
if (!netif_is_up(esp_netif->lwip_netif) || esp_netif->mldv6_report_timer_started) {
return;
}
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif);
esp_netif->mldv6_report_timer_started = true;
sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, esp_netif);
}
static void netif_unset_mldv6_flag(struct netif *netif)
static void netif_unset_mldv6_flag(esp_netif_t *esp_netif)
{
sys_untimeout(netif_send_mldv6, netif);
if (esp_netif->mldv6_report_timer_started) {
esp_netif->mldv6_report_timer_started = false;
sys_untimeout(netif_send_mldv6, esp_netif);
}
}
#endif
@ -2014,7 +2021,7 @@ static void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t ip_index)
if (esp_netif->flags&ESP_NETIF_FLAG_MLDV6_REPORT) {
#if ESP_MLDV6_REPORT
netif_set_mldv6_flag(netif);
netif_set_mldv6_flag(esp_netif);
#else
ESP_LOGW(TAG,"CONFIG_LWIP_ESP_MLDV6_REPORT not enabled, but esp-netif configured with ESP_NETIF_FLAG_MLDV6_REPORT");
#endif

View File

@ -111,6 +111,8 @@ struct esp_netif_obj {
uint16_t max_fdb_sta_entries;
uint8_t max_ports;
#endif // CONFIG_ESP_NETIF_BRIDGE_EN
// mldv6 timer
bool mldv6_report_timer_started;
};
#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */

View File

@ -4,5 +4,5 @@
nvs, data, nvs, , 0x4000,
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, , 1500K,
ota_1, app, ota_1, , 1500K,
ota_0, app, ota_0, , 1600K,
ota_1, app, ota_1, , 1600K,

1 # Name, Type, SubType, Offset, Size, Flags
4 otadata, data, ota, , 0x2000,
5 phy_init, data, phy, , 0x1000,
6 ota_0, app, ota_0, , 1500K, ota_0, app, ota_0, , 1600K,
7 ota_1, app, ota_1, , 1500K, ota_1, app, ota_1, , 1600K,
8