What is the best way to re-initialize a network interface?

Hi,

I am trying to address the following use case in an automated fashion: in the case of ethernet interface, ethernet cable is unplugged from existing switch and then plugged into switch with different IP/Mask/Gateway setup.

I tried disconnect() before connect(), delete and create new EthernetInterface, toggle reset pin of ethernet Phy IC, none of these approaches work reliably even when cable is unplugged and then plugged back to the same switch. Sometimes it takes 60+ seconds to timeout, or system hangs all together, sometimes connect() and getting IP will succeed but gets -3001 error when trying to use it to connect to network.

On the other hand, reset and reboot system always work. Is this the only way?

Please advise. Thanks.

no solution, but I have played also with the events that Ethernet fires. I found it difficult to handle, later I found that it is necessary to query for the event source to do some actions. Actions must not run in the event handler as it is usually in interrupt context.
And then the implementation is very target specific, I had used only STM until now. In general, it should be possible to handle network if up/down, but in particular it would be nice to have examples for how to do it.