Repository navigation
fix: renew_ip keeps the default route - #79
Conversation
There was a problem hiding this comment.
Thanks, the fix is right for the common case.
It adds a regression though that needs to be fixed: renew_ip now fails on an interface that is down. When renew_ip runs after link_down(), or on an interface built with start_down, the address change succeeds. Then replace_default_route_v4 asks the kernel for a gateway route through a down device. The kernel rejects it: the prefix route for the subnet is not installed while the device is down, so the gateway is unreachable. At that point the core record and the kernel already hold the new IP. The caller gets an Err, and no DeviceIpChanged event is emitted. On main the same call succeeds.
link_up() already re-adds the default route for the default_via interface. So renew_ip can skip the route when the link is down, or ignore that specific error. A test that does link_down, renew_ip, link_up and then pings across the NAT would cover it.
Smaller points:
wire_iface_asyncadds the default route withadd_default_route_v4(gw), without an output interface.renew_ipnow usesreplace_default_route_v4(&ifname, gw), which sets the output interface. Both work, but the two paths now produce slightly different routes. Using the same helper in both places keeps them identical.
6006d37 to
8ac8c3c
Compare
|
Thanks, good catch on the down link. Fixed in the new commit:
I also rebased on main, since the netlink code moved in #83. |
|
Link-down fix looks good, thanks. One more issue: Setup only works by ordering. I'd fix it in the helper: give |
Removing the old address drops the default route, so renew_ip adds it again.
link_up adds it back. Use add_default_route_v4, as wire_iface_async does.
add_default_route_v4 set no output interface, so the kernel chose one through the gateway's subnet route. With two interfaces on the same router, renew_ip on eth0 re-added its subnet route behind eth1's, and the default route moved to eth1. The helper now takes the interface name and sets it as the oif. The three callers in wiring.rs and renew_ip pass their interface.
8ac8c3c to
eb468b8
Compare
|
You're right, thanks. I only tested with one interface, so the ordering never showed up. Fixed it in the helper as you suggested: New test Also rebased on main. |
renew_ipremoves the old address, and the kernel drops the default route with it. After a renewal the device has no default route.renew_ipnow adds the default route back when the renewed interface carries it. When the link is down it skips that step, andlink_upadds the route once the link is back.add_default_route_v4now takes the interface and sets it as the route's oif. Without it the kernel picked the interface through the gateway's subnet route, so with two interfaces on the same router the route could end up on the other one after a renewal.renew_ip_keeps_default_routefails onmainand passes with this change.renew_ip_while_link_downcovers the down-link case, andrenew_ip_keeps_default_route_on_its_ifacecovers two interfaces on one router.