linux fixes
This commit is contained in:
parent
d922bc1f5d
commit
cf6a139928
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -5291,7 +5291,6 @@ dependencies = [
|
||||
"getrandom",
|
||||
"glob",
|
||||
"hex",
|
||||
"ifstructs",
|
||||
"jni",
|
||||
"jni-sys",
|
||||
"js-sys",
|
||||
@ -5306,8 +5305,6 @@ dependencies = [
|
||||
"lz4_flex",
|
||||
"ndk",
|
||||
"ndk-glue",
|
||||
"netlink-packet-route",
|
||||
"netlink-sys",
|
||||
"nix 0.27.1",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
@ -5316,7 +5313,6 @@ dependencies = [
|
||||
"parking_lot 0.12.1",
|
||||
"paste",
|
||||
"range-set-blaze",
|
||||
"rtnetlink",
|
||||
"rustls",
|
||||
"rustls-pemfile",
|
||||
"schemars",
|
||||
@ -5483,6 +5479,7 @@ dependencies = [
|
||||
"fn_name",
|
||||
"futures-util",
|
||||
"getrandom",
|
||||
"ifstructs",
|
||||
"jni",
|
||||
"jni-sys",
|
||||
"js-sys",
|
||||
@ -5491,6 +5488,8 @@ dependencies = [
|
||||
"log",
|
||||
"ndk",
|
||||
"ndk-glue",
|
||||
"netlink-packet-route",
|
||||
"netlink-sys",
|
||||
"nix 0.27.1",
|
||||
"once_cell",
|
||||
"oslog",
|
||||
@ -5499,6 +5498,7 @@ dependencies = [
|
||||
"rand",
|
||||
"rand_core",
|
||||
"range-set-blaze",
|
||||
"rtnetlink",
|
||||
"send_wrapper 0.6.0",
|
||||
"serial_test",
|
||||
"simplelog",
|
||||
|
@ -25,7 +25,6 @@ rt-async-std = [
|
||||
"async-std-resolver",
|
||||
"trust-dns-resolver",
|
||||
"async_executors/async_std",
|
||||
"rtnetlink/smol_socket",
|
||||
"veilid-tools/rt-async-std",
|
||||
]
|
||||
rt-tokio = [
|
||||
@ -36,7 +35,6 @@ rt-tokio = [
|
||||
"async_executors/tokio_tp",
|
||||
"async_executors/tokio_io",
|
||||
"async_executors/tokio_timer",
|
||||
"rtnetlink/tokio_socket",
|
||||
"veilid-tools/rt-tokio",
|
||||
]
|
||||
|
||||
@ -238,16 +236,6 @@ ndk = { version = "0.7.0" }
|
||||
ndk-glue = { version = "0.7.0", features = ["logger"] }
|
||||
paranoid-android = { version = "0.2.1", optional = true }
|
||||
|
||||
# Dependenices for all Unix (Linux, Android, MacOS, iOS)
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
ifstructs = "0.1.1"
|
||||
|
||||
# Dependencies for Linux or Android
|
||||
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
|
||||
rtnetlink = { version = "=0.13.1", default-features = false }
|
||||
netlink-sys = { version = "=0.8.5" }
|
||||
netlink-packet-route = { version = "=0.17.1" }
|
||||
|
||||
# Dependencies for Windows
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3.9", features = ["iptypes", "iphlpapi"] }
|
||||
|
@ -14,10 +14,11 @@ crate-type = ["cdylib", "staticlib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = ["rt-tokio"]
|
||||
rt-async-std = ["async-std", "async_executors/async_std"]
|
||||
rt-async-std = ["async-std", "async_executors/async_std", "rtnetlink/smol_socket"]
|
||||
rt-tokio = [
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"rtnetlink/tokio_socket",
|
||||
"async_executors/tokio_tp",
|
||||
"async_executors/tokio_io",
|
||||
"async_executors/tokio_timer",
|
||||
@ -82,6 +83,12 @@ getrandom = { version = "0.2", features = ["js"] }
|
||||
async-lock = "2.8.0"
|
||||
send_wrapper = { version = "0.6.0", features = ["futures"] }
|
||||
|
||||
# Dependencies for Linux or Android
|
||||
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
|
||||
rtnetlink = { version = "=0.13.1", default-features = false }
|
||||
netlink-sys = { version = "=0.8.5" }
|
||||
netlink-packet-route = { version = "=0.17.1" }
|
||||
|
||||
# Dependencies for Android
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
jni = "0.21.1"
|
||||
@ -101,6 +108,10 @@ winapi = { version = "0.3.9", features = ["iptypes", "iphlpapi"] }
|
||||
oslog = { version = "0.2.0", optional = true }
|
||||
tracing-oslog = { version = "0.1.2", optional = true }
|
||||
|
||||
# Dependenices for all Unix (Linux, Android, MacOS, iOS)
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
ifstructs = "0.1.1"
|
||||
|
||||
### DEV DEPENDENCIES
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use alloc::collections::btree_map::Entry;
|
||||
use futures_util::stream::TryStreamExt;
|
||||
use ifstructs::ifreq;
|
||||
use libc::{
|
||||
@ -14,6 +13,7 @@ use netlink_packet_route::{
|
||||
IFA_F_OPTIMISTIC, IFA_F_PERMANENT, IFA_F_TEMPORARY, IFA_F_TENTATIVE,
|
||||
};
|
||||
use rtnetlink::{new_connection_with_socket, Handle, IpVersion};
|
||||
use std::collections::btree_map::Entry;
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
use netlink_sys::{SmolSocket as RTNetLinkSocket};
|
||||
@ -34,11 +34,11 @@ fn get_interface_name(index: u32) -> io::Result<String> {
|
||||
cfg_if! {
|
||||
if #[cfg(all(any(target_os = "android", target_os="linux"), any(target_arch = "arm", target_arch = "aarch64")))] {
|
||||
if unsafe { if_indextoname(index, ifnamebuf.as_mut_ptr()) }.is_null() {
|
||||
bail!("if_indextoname returned null");
|
||||
bail_io_error_other!("if_indextoname returned null");
|
||||
}
|
||||
} else {
|
||||
if unsafe { if_indextoname(index, ifnamebuf.as_mut_ptr() as *mut i8) }.is_null() {
|
||||
bail!("if_indextoname returned null");
|
||||
bail_io_error_other!("if_indextoname returned null");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,11 +46,11 @@ fn get_interface_name(index: u32) -> io::Result<String> {
|
||||
let ifnamebuflen = ifnamebuf
|
||||
.iter()
|
||||
.position(|c| *c == 0u8)
|
||||
.ok_or_else(|| eyre!("null not found in interface name"))?;
|
||||
.ok_or_else(|| io_error_other!("null not found in interface name"))?;
|
||||
let ifname_str = CStr::from_bytes_with_nul(&ifnamebuf[0..=ifnamebuflen])
|
||||
.wrap_err("failed to convert interface name")?
|
||||
.map_err(|e| io_error_other!(e))?
|
||||
.to_str()
|
||||
.wrap_err("invalid characters in interface name")?;
|
||||
.map_err(|e| io_error_other!(e))?;
|
||||
Ok(ifname_str.to_owned())
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ impl PlatformSupportNetlink {
|
||||
}
|
||||
|
||||
// Figure out which interfaces have default routes
|
||||
async fn refresh_default_route_interfaces(&mut self) -> EyreResult<()> {
|
||||
async fn refresh_default_route_interfaces(&mut self) {
|
||||
self.default_route_interfaces.clear();
|
||||
let mut routesv4 = self
|
||||
.handle
|
||||
@ -112,15 +112,14 @@ impl PlatformSupportNetlink {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_interface_flags(&self, index: u32, ifname: &str) -> EyreResult<InterfaceFlags> {
|
||||
let mut req = ifreq::from_name(ifname).wrap_err("failed to convert interface name")?;
|
||||
fn get_interface_flags(&self, index: u32, ifname: &str) -> io::Result<InterfaceFlags> {
|
||||
let mut req = ifreq::from_name(ifname)?;
|
||||
|
||||
let sock = unsafe { socket(AF_INET as i32, SOCK_DGRAM, 0) };
|
||||
if sock < 0 {
|
||||
return Err(io::Error::last_os_error()).wrap_err("failed to create socket");
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
@ -132,7 +131,7 @@ impl PlatformSupportNetlink {
|
||||
}
|
||||
unsafe { close(sock) };
|
||||
if res < 0 {
|
||||
return Err(io::Error::last_os_error()).wrap_err("failed to close socket");
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
let flags = req.get_flags() as c_int;
|
||||
@ -249,12 +248,12 @@ impl PlatformSupportNetlink {
|
||||
interfaces: &mut BTreeMap<String, NetworkInterface>,
|
||||
) -> io::Result<()> {
|
||||
// Refresh the routes
|
||||
self.refresh_default_route_interfaces().await?;
|
||||
self.refresh_default_route_interfaces().await;
|
||||
|
||||
// Ask for all the addresses we have
|
||||
let mut names = BTreeMap::<u32, String>::new();
|
||||
let mut addresses = self.handle.as_ref().unwrap().address().get().execute();
|
||||
while let Some(msg) = addresses.try_next().await? {
|
||||
while let Some(msg) = addresses.try_next().await.map_err(|e| io_error_other!(e))? {
|
||||
// Have we seen this interface index yet?
|
||||
// Get the name from the index, cached, if we can
|
||||
let ifname = match names.entry(msg.header.index) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(dead_code)]
|
||||
// Copyright 2018 MaidSafe.net limited.
|
||||
//
|
||||
// This SAFE Network Software is licensed to you under the MIT license <LICENSE-MIT
|
||||
|
Loading…
x
Reference in New Issue
Block a user