[Gratuitous ARP] Thread-safe LWIP API calls, fix condition for IF #2583
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://github.com/espressif/esp-lwip/blob/61d840ff4778f4946c8743f7e412345abcd537f1/src/core/ipv4/etharp.c#L142-L154
i.e.
netif_is_up(garp_netif) && netif_is_link_up(garp_netif)
https://www.nongnu.org/lwip/2_1_x/multithreading.html
Therefore, utilize the same methods as netifapi does, so that etharp method is called from within lwip/tcpip thread. netifapi itself is not included in arduino-esp32 idf sdkconfig, but required code is rather self-explanatory:
https://www.nongnu.org/lwip/2_1_x/netifapi_8h.html
https://github.com/espressif/esp-lwip/blob/2.1.2-esp/src/api/netifapi.c
As to why... Reading AsyncTCP issue tracker, using tcp/udp methods directly had caused a lot of issues in the past, until tcpip_api messaging replaced it. Even something as small as this should probably use safer methods.
Notes:
err_t
is substituted viaint8_t
, because platformio .ino converter will create .cpp as ESPEasy.ino + prototypes + everything else. As the result there's compilation error, becauseinclude <lwip/...>
only happens aftererr_t
is mentioned.Continuing from my comment:
xoseperez/espurna#1877 (comment)
I also noticed that current LWIP build for ESP32 already has gratuitous arp timer set up to trigger every 60 seconds after connection was established, but the value seems to be too high and current burst ... to 5 seconds implementation does a better job at notifying other devices about it's MAC.
platformio.ini contains some flags that try to change this behaviour:
1c451bb
But they are ineffective, because lwip is pre-built:
https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/lib/liblwip.a
Perhaps, those CONFIG... flags should be removed?