fix(linux): don't print error when removing non-existent route (#7502)

We are already handling one case where we are trying to remove a route
that doesn't exist. `ESRCH` is another variant of this error that
manifests as "No such process". According to the Internet, this just
means the route doesn't exist so we can bail out early here.
This commit is contained in:
Thomas Eizinger
2024-12-13 15:53:22 +11:00
committed by GitHub
parent 30376cd79a
commit b5d6c27680

View File

@@ -8,7 +8,8 @@ use futures::TryStreamExt;
use ip_network::{IpNetwork, Ipv4Network, Ipv6Network};
use ip_packet::{IpPacket, IpPacketBuf};
use libc::{
fcntl, makedev, mknod, open, EEXIST, ENOENT, F_GETFL, F_SETFL, O_NONBLOCK, O_RDWR, S_IFCHR,
fcntl, makedev, mknod, open, EEXIST, ENOENT, ESRCH, F_GETFL, F_SETFL, O_NONBLOCK, O_RDWR,
S_IFCHR,
};
use netlink_packet_route::route::{RouteProtocol, RouteScope};
use netlink_packet_route::rule::RuleAction;
@@ -282,6 +283,12 @@ async fn remove_route(route: &IpNetwork, idx: u32, handle: &Handle) {
return;
}
// "No such process" is another version of "route does not exist".
// See <https://askubuntu.com/questions/1330333/what-causes-rtnetlink-answers-no-such-process-when-using-ifdown-command>.
if matches!(&err, NetlinkError(err) if err.raw_code() == ESRCH) {
return;
}
tracing::warn!(error = std_dyn_err(&err), %route, "Failed to remove route");
}