[SOLVED] Netifd not restoring routes on carrier down?

I have two network interfaces, one ethernet and one wifi (client). Each one has a default route. At startup the wifi is not connected (no AP available), and the ethernet default route is installed. Then I start the AP, the wifi client connects and the wifi default route is installed (the ethernet default route disappears). Now, I shutdown the AP, the client disconnects, the wifi default route disappears but the ethernet default route is not reinstalled.

I am willing to correct this and I wonder what is the best way to do it.
The scenario I came with is as follows: when removing a route, browse all the routes known netifd and reinstall the ones matching the removed target, provided the underlying network is up and running.
I go through all interfaces then go through all their routes; or maybe I could chain all known routes in an additional list and go through this list.

Or maybe I am totally wrong about the expected behavior in the case outlined above?

By default, there is only one default route. You can have multiple routes to the same net (which might be the 0.0.0.0/0 "wildcard" net) with different priorities, but only one is "default".

netifd is not as sophisticated as, for example, NetworkManager (thankfully so, sometimes) and what your asking for isn't really "restoring the old", but "changing to a new" when one interface goes down and another is detected as being the "primary" interface.

You probably can achieve what you want by setting the route metric of one or the other interfaces to a higher/lower value. That way when the "other" interface comes up, it shouldn't overwrite the wildcard-net entry that already exists in the routing table.

Thanks for your insight and feedback. Works great after I add an uci option in /etc/config/network:

config interface 'wifi'
    option gateway 10.1.0.1
    option metric 1
...
config interface 'lan'
    option gateway 192.168.48.1
    option metric 2
...

Now, the two default routes are managed independently. When by chance it happens that both interfaces are available, the one with metric=1 (lowest) is chosen.