Skip to content

Commit 98ce57b

Browse files
rhaskiaconradev
authored andcommitted
Set up works, daemon still bugs out
1 parent 982cfc3 commit 98ce57b

File tree

6 files changed

+127
-58
lines changed

6 files changed

+127
-58
lines changed

Cargo.lock

Lines changed: 90 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

burrow/src/daemon/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl DaemonInstance {
5151
}
5252
RunState::Idle => {
5353
let tun_if = st.tun.open()?;
54-
tun_if.set_up(true).await?;
54+
tun_if.set_up(true)?;
5555

5656
debug!("Setting tun on wg_interface");
5757
self.wg_interface.read().await.set_tun(tun_if).await;

tun/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ log = "0.4"
1515
serde = { version = "1", features = ["derive"], optional = true }
1616
schemars = { version = "0.8", optional = true }
1717

18-
[target.'cfg(feature = "linux")'.dev-dependencies]
19-
rtnetlink = "0.14"
20-
2118
futures = { version = "0.3.28", optional = true }
19+
netlink-packet-route = "0.19.0"
20+
netlink-packet-core = "0.7.0"
21+
2222

2323
[features]
2424
serde = ["dep:serde", "dep:schemars"]
@@ -27,6 +27,9 @@ tokio = ["tokio/net", "dep:futures"]
2727
[target.'cfg(feature = "tokio")'.dev-dependencies]
2828
tokio = { features = ["rt", "macros"] }
2929

30+
[target.'cfg(target_os = "linux")'.dependencies]
31+
interfaces = "0.0.9"
32+
3033
[target.'cfg(windows)'.dependencies]
3134
lazy_static = "1.4"
3235
libloading = "0.7"

tun/src/tokio/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ impl TunInterface {
1616
}
1717

1818
#[instrument]
19-
pub async fn set_up(&self, up: bool) -> io::Result<()> {
20-
self.inner.get_ref().set_up(up)
19+
pub fn set_up(&self, up: bool) -> io::Result<()> {
20+
self.inner.get_ref().set_up(up)
2121
}
2222

2323
#[instrument]

tun/src/unix/linux/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::{
1111

1212
use fehler::throws;
1313
use libc::in6_ifreq;
14-
use rtnetlink::new_connection;
1514
use socket2::{Domain, SockAddr, Socket, Type};
1615
use tracing::{info, instrument};
1716

@@ -99,10 +98,19 @@ impl TunInterface {
9998
#[throws]
10099
#[instrument]
101100
pub fn set_up(&self, up: bool) {
102-
let connection = new_connection()?;
103-
let handle = connection.1;
104-
let link = handle.link().set(self.index()? as u32);
105-
if up { link.up() } else { link.down() }
101+
let mut inter = interfaces::Interface::get_by_name(&self.name()?)
102+
.unwrap()
103+
.unwrap();
104+
inter.set_up(up).unwrap();
105+
}
106+
107+
#[throws]
108+
#[instrument]
109+
pub fn is_up(&self) -> bool {
110+
let inter = interfaces::Interface::get_by_name(&self.name()?)
111+
.unwrap()
112+
.unwrap();
113+
inter.is_up()
106114
}
107115

108116
#[throws]

tun/tests/configure.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ fn test_set_get_broadcast_addr() {
2424
assert_eq!(broadcast_addr, result);
2525
}
2626

27+
#[test]
28+
#[throws]
29+
#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
30+
fn test_set_get_up() {
31+
let tun = TunInterface::new()?;
32+
let addr = Ipv4Addr::new(10, 0, 0, 1);
33+
tun.set_ipv4_addr(addr)?;
34+
35+
let broadcast_addr = Ipv4Addr::new(255, 255, 255, 0);
36+
tun.set_broadcast_addr(broadcast_addr)?;
37+
tun.set_up(true)?;
38+
39+
assert!(tun.is_up()?);
40+
}
41+
2742
#[test]
2843
#[throws]
2944
#[cfg(not(target_os = "windows"))]

0 commit comments

Comments
 (0)