next_local_port(), which is used as a local port when connecting outside isn't random and instead uses the same value after resets or panic. This causes issues when trying to connect to a server, which already had a previous connection opened with that port, because it might be stuck in a previous case.
With the current implementation, it always uses 41001 when opening a new connection. Since esp32 supports hardware RNG, I think it should be used as a source of entropy for selecting a port.
next_local_port()
, which is used as a local port when connecting outside isn't random and instead uses the same value after resets or panic. This causes issues when trying to connect to a server, which already had a previous connection opened with that port, because it might be stuck in a previous case.With the current implementation, it always uses
41001
when opening a new connection. Sinceesp32
supports hardware RNG, I think it should be used as a source of entropy for selecting a port.https://github.com/esp-rs/esp-wifi/blob/6f438e33bbac2d37abe522470b3afd648e858573/esp-wifi/src/wifi_interface.rs#L435-L443
Reference: https://github.com/smoltcp-rs/smoltcp/issues/850
EDIT: There is a similar issue when using async +
embassy_net
as the seed used determines the port, but we hardcode the seed in the examples to1234
https://github.com/esp-rs/esp-wifi/blob/6f438e33bbac2d37abe522470b3afd648e858573/esp-wifi/examples/embassy_dhcp.rs#L58-L66Reference: https://github.com/embassy-rs/embassy/blob/14f41a71b6ea9dedb4ee5b9c741fe10575772c7d/embassy-net/src/lib.rs#L314