Skip to content

Commit

Permalink
Set up works, daemon still bugs out
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaskia committed Mar 9, 2024
1 parent 059798e commit 32ec6f7
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 58 deletions.
137 changes: 90 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion burrow/src/daemon/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl DaemonInstance {
}
RunState::Idle => {
let tun_if = st.tun.open()?;
tun_if.set_up(true).await?;
tun_if.set_up(true)?;

debug!("Setting tun on wg_interface");
self.wg_interface.read().await.set_tun(tun_if).await;
Expand Down
9 changes: 6 additions & 3 deletions tun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tun/src/tokio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 13 additions & 5 deletions tun/src/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions tun/tests/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

0 comments on commit 32ec6f7

Please sign in to comment.