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