Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP Lost event generated for old net if (IDFGH-14438) #15218

Open
3 tasks done
stefansobol opened this issue Jan 15, 2025 · 0 comments
Open
3 tasks done

IP Lost event generated for old net if (IDFGH-14438) #15218

stefansobol opened this issue Jan 15, 2025 · 0 comments
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@stefansobol
Copy link

stefansobol commented Jan 15, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

5.2.2

Espressif SoC revision.

ESP32-D0WD-V3 (revision v3.0)

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

Custom board

Power Supply used.

USB

What is the expected behavior?

A netif can be created and destroyed at any times and there are no timers left active if the netif does not exists anymore.
When using CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL = 120 (default value) a timer is started with the given time interval, so that an ip lost event is generated. Expectation is that when the netif is destroyed, the timer is also stopped.

What is the actual behavior?

IP Lost timer remains active even if the netif is destroyed and if by chance a new netif is generated later having the same address, then the timer will fire and generates an ip lost event.

Please check my log bellow and see that after a while a new netif is created with the same address.

...
D (12048) APP: WiFiPL station created net interface 0x3ffcad1c
...
D (14598) APP: WiFiPL release free netif 0x3ffcad1c
...
D (24908) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (27388) APP: WiFiPL release netif 0x3ffc9ae4
...
D (32648) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (35128) APP: WiFiPL release netif 0x3ffc9ae4
...
D (254488) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254518) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254528) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
...

As one can see in my log, is possible that a new netif is allocated at the same address (0x3ffc9ae4) when using esp_netif_new and esp_netif_destroy.

Steps to reproduce.

In a loop:

  • init wifi station:
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);
    esp_wifi_set_mode(WIFI_MODE_STA);
    wifi_config_t wifi_config = {};
    wifi_config.sta.threshold.authmode = getAuthMode(auth_mode);
    wifi_config.sta.pmf_cfg.capable = true;
    wifi_config.sta.pmf_cfg.required = false;
    std::strncpy(reinterpret_cast<char *>(wifi_config.sta.ssid), ssid, sizeof(wifi_config.sta.ssid));
    std::strncpy(reinterpret_cast<char *>(wifi_config.sta.password), password, sizeof(wifi_config.sta.password));
    esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
  • create netif:
    esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_WIFI_STA();
    net_if = esp_netif_new(&netif_config);
  • complete initialization:
    esp_netif_attach_wifi_station(net_if);
    esp_wifi_set_default_wifi_sta_handlers();
    esp_wifi_start();
  • set event handlers
    int32_t got_ip_event_id = esp_netif_get_event_id(net_if, ESP_NETIF_IP_EVENT_GOT_IP);
    int32_t lost_ip_event_id = esp_netif_get_event_id(net_if, ESP_NETIF_IP_EVENT_LOST_IP);
    esp_netif_set_hostname(net_if, name);
    esp_event_handler_instance_register(IP_EVENT, got_ip_event_id, &gotIpEventHandler, this, &_got_ip_event_handler) ;
    esp_event_handler_instance_register(IP_EVENT, lost_ip_event_id, &lostIpEventHandler, this, &_lost_ip_event_handler);
  • wait for a short time and do the destroy sequence:
    esp_event_handler_instance_unregister(IP_EVENT, ESP_EVENT_ANY_ID, _got_ip_event_handler);
    esp_event_handler_instance_unregister(IP_EVENT, ESP_EVENT_ANY_ID, _lost_ip_event_handler);
    esp_wifi_stop();
    esp_wifi_clear_default_wifi_driver_and_handlers(net_if);
    esp_netif_destroy(net_if);
    esp_wifi_deinit();

After 120s (or whatever is configured in CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL) the event callback for ip lost is called. The number of calls looks to be the same as the number of times netif was created with same address.

Debug Logs.

...
I (11998) APP: IP connection start interface wifi0 config wifi0
...
D (12018) APP: WiFi connect
D (12028) APP: WiFi connect ssid SSID1 auth_mode wpa2_psk
D (12028) APP: WiFiPL init station
D (12048) APP: WiFiPL station created net interface 0x3ffcad1c
...
D (14598) APP: WiFiPL release free netif 0x3ffcad1c
...
I (14618) APP: IP connection start interface wifi0 config wifi1
...
D (14648) APP: WiFiPL station created net interface 0x3ffc9b7c
...
D (17078) APP: WiFi station disconnected from SSID2, reason 201
D (17078) APP: WiFi station disconnected from SSID2, error ap not found
D (17128) APP: WiFiPL release netif 0x3ffc9b7c
...
D (22378) APP: WiFiPL station created net interface 0x3ffcf348
...
D (24858) APP: WiFiPL release netif 0x3ffcf348
...
D (24908) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (27388) APP: WiFiPL release netif 0x3ffc9ae4
...
D (32648) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (35128) APP: WiFiPL release netif 0x3ffc9ae4
...
D (35178) APP: WiFiPL station created net interface 0x3ffc9b7c
...
D (37658) APP: WiFiPL release netif 0x3ffc9b7c
...
D (42908) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (45388) APP: WiFiPL release netif 0x3ffc9ae4
...
D (45438) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (47918) APP: WiFiPL release netif 0x3ffc9ae4
...
D (53178) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (55658) APP: WiFiPL release netif 0x3ffc9ae4
...
D (55708) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (58188) APP: WiFiPL release netif 0x3ffc9ae4
...
D (63438) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (65918) APP: WiFiPL release netif 0x3ffc9ae4
...
D (65978) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (68458) APP: WiFiPL release netif 0x3ffc9ae4
...
D (132048) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (134528) APP: WiFiPL release netif 0x3ffc9ae4
...
D (134578) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (137058) APP: WiFiPL release netif 0x3ffc9ae4
...
D (142308) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (144788) APP: WiFiPL release netif 0x3ffc9ae4
...
D (144838) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (147318) APP: WiFiPL release netif 0x3ffc9ae4
...
D (152568) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (155048) APP: WiFiPL release netif 0x3ffc9ae4
...
D (155098) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (157578) APP: WiFiPL release netif 0x3ffc9ae4
...
D (162828) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (165308) APP: WiFiPL release netif 0x3ffc9ae4
...
D (165358) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (167838) APP: WiFiPL release netif 0x3ffc9ae4
...
D (173098) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (175578) APP: WiFiPL release 0x3ffc9ae4
...
D (175628) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (178108) APP: WiFiPL release netif 0x3ffc9ae4
...
D (183358) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (185838) APP: WiFiPL release netif 0x3ffc9ae4
...
D (185888) APP: WiFiPL station created net interface 0x3ffc9ae4
...
D (188368) APP: WiFiPL release netif 0x3ffc9ae4
...
D (252048) APP: WiFiPL station created net interface 0x3ffc9ae4
..
D (254488) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254518) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254528) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254548) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254558) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254578) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254588) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254598) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254608) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254618) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254628) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254648) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254658) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254678) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254698) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254718) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254728) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254748) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254768) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254778) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254798) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254818) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254838) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254848) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4
D (254868) APP: IPMPL lost IP (evt id 1), net if 0x3ffc9ae4

More Information.

In version 5.2.2 (but I don't see any change in 5.4) the timer is created here and I don't think is ever destroyed. I think the timer relays on the fact that if a netif is destroyed, then is not found anymore here.

I think the solution will be to add here something like:

    if (esp_netif->timer_running) {
        sys_untimeout(esp_netif_ip_lost_timer, (void *)esp_netif);
        esp_netif->timer_running = false;
    }
@stefansobol stefansobol added the Type: Bug bugs in IDF label Jan 15, 2025
@github-actions github-actions bot changed the title IP Lost event generated for old net if IP Lost event generated for old net if (IDFGH-14438) Jan 15, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

2 participants