Set up works, daemon still bugs out
This commit is contained in:
parent
982cfc39b6
commit
98ce57bba0
6 changed files with 127 additions and 58 deletions
|
|
@ -15,10 +15,10 @@ log = "0.4"
|
|||
serde = { version = "1", features = ["derive"], optional = true }
|
||||
schemars = { version = "0.8", optional = true }
|
||||
|
||||
[target.'cfg(feature = "linux")'.dev-dependencies]
|
||||
rtnetlink = "0.14"
|
||||
|
||||
futures = { version = "0.3.28", optional = true }
|
||||
netlink-packet-route = "0.19.0"
|
||||
netlink-packet-core = "0.7.0"
|
||||
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde", "dep:schemars"]
|
||||
|
|
@ -27,6 +27,9 @@ tokio = ["tokio/net", "dep:futures"]
|
|||
[target.'cfg(feature = "tokio")'.dev-dependencies]
|
||||
tokio = { features = ["rt", "macros"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
interfaces = "0.0.9"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
lazy_static = "1.4"
|
||||
libloading = "0.7"
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ impl TunInterface {
|
|||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn set_up(&self, up: bool) -> io::Result<()> {
|
||||
self.inner.get_ref().set_up(up)
|
||||
pub fn set_up(&self, up: bool) -> io::Result<()> {
|
||||
self.inner.get_ref().set_up(up)
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use std::{
|
|||
|
||||
use fehler::throws;
|
||||
use libc::in6_ifreq;
|
||||
use rtnetlink::new_connection;
|
||||
use socket2::{Domain, SockAddr, Socket, Type};
|
||||
use tracing::{info, instrument};
|
||||
|
||||
|
|
@ -99,10 +98,19 @@ impl TunInterface {
|
|||
#[throws]
|
||||
#[instrument]
|
||||
pub fn set_up(&self, up: bool) {
|
||||
let connection = new_connection()?;
|
||||
let handle = connection.1;
|
||||
let link = handle.link().set(self.index()? as u32);
|
||||
if up { link.up() } else { link.down() }
|
||||
let mut inter = interfaces::Interface::get_by_name(&self.name()?)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
inter.set_up(up).unwrap();
|
||||
}
|
||||
|
||||
#[throws]
|
||||
#[instrument]
|
||||
pub fn is_up(&self) -> bool {
|
||||
let inter = interfaces::Interface::get_by_name(&self.name()?)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
inter.is_up()
|
||||
}
|
||||
|
||||
#[throws]
|
||||
|
|
|
|||
|
|
@ -24,6 +24,21 @@ fn test_set_get_broadcast_addr() {
|
|||
assert_eq!(broadcast_addr, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[throws]
|
||||
#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
|
||||
fn test_set_get_up() {
|
||||
let tun = TunInterface::new()?;
|
||||
let addr = Ipv4Addr::new(10, 0, 0, 1);
|
||||
tun.set_ipv4_addr(addr)?;
|
||||
|
||||
let broadcast_addr = Ipv4Addr::new(255, 255, 255, 0);
|
||||
tun.set_broadcast_addr(broadcast_addr)?;
|
||||
tun.set_up(true)?;
|
||||
|
||||
assert!(tun.is_up()?);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[throws]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue