mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-27 07:59:59 -07:00
Use /proc/net/route instead of ip route command
Fix #811, allegedly /proc/net/route is almost always available, and no additional dependency is needed at all.
This commit is contained in:
committed by
Cooper Quintin
parent
a3d0d8f4f9
commit
be15035ad4
@@ -181,11 +181,8 @@ pub struct RouteStatus {
|
||||
}
|
||||
|
||||
pub async fn get_route_status() -> Json<RouteStatus> {
|
||||
let mut cmd = Command::new("busybox");
|
||||
cmd.args(["ip", "route"]);
|
||||
|
||||
let has_default_route = match get_cmd_output(cmd).await {
|
||||
Ok(output) => output.lines().any(|line| line.starts_with("default ")),
|
||||
let has_default_route = match check_default_route().await {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
log::warn!("Failed to check default route: {err}");
|
||||
// More likely than not, this is a portability issue. The logic hasn't been fully
|
||||
@@ -196,3 +193,14 @@ pub async fn get_route_status() -> Json<RouteStatus> {
|
||||
|
||||
Json(RouteStatus { has_default_route })
|
||||
}
|
||||
|
||||
// Checks for an IPv4 default route by reading /proc/net/route
|
||||
// instead of shelling out to `ip route`, which may not be available on all devices.
|
||||
async fn check_default_route() -> std::io::Result<bool> {
|
||||
let contents = tokio::fs::read_to_string("/proc/net/route").await?;
|
||||
Ok(contents.lines().skip(1).any(|line| {
|
||||
line.split_whitespace()
|
||||
.nth(1)
|
||||
.is_some_and(|dest| dest == "00000000")
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user