diff --git a/Apple/NetworkExtension/DataTypes.swift b/Apple/NetworkExtension/DataTypes.swift index 6b3a070..f7ba572 100644 --- a/Apple/NetworkExtension/DataTypes.swift +++ b/Apple/NetworkExtension/DataTypes.swift @@ -28,7 +28,7 @@ struct BurrowStartRequest: Codable { let name: String? let no_pi: Bool let tun_excl: Bool - let seek_utun: Int? + let tun_retrieve: Bool let address: String? } struct StartOptions: Codable{ @@ -37,8 +37,8 @@ struct BurrowStartRequest: Codable { let Start: StartOptions } -func start_req_fd(id: UInt, fd: Int) -> BurrowRequest { - return BurrowRequest(id: id, command: BurrowStartRequest(Start: BurrowStartRequest.StartOptions(tun: BurrowStartRequest.TunOptions(name: nil, no_pi: false, tun_excl: false, seek_utun: fd, address: nil)))) +func start_req_fd(id: UInt) -> BurrowRequest { + return BurrowRequest(id: id, command: BurrowStartRequest(Start: BurrowStartRequest.StartOptions(tun: BurrowStartRequest.TunOptions(name: nil, no_pi: false, tun_excl: false, tun_retrieve: true, address: nil)))) } struct Response: Decodable where T: Decodable { diff --git a/Apple/NetworkExtension/PacketTunnelProvider.swift b/Apple/NetworkExtension/PacketTunnelProvider.swift index e9c48dd..711f6de 100644 --- a/Apple/NetworkExtension/PacketTunnelProvider.swift +++ b/Apple/NetworkExtension/PacketTunnelProvider.swift @@ -34,7 +34,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { // let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int; // self.logger.info("Found File Descriptor: \(tunFd)") - let start_command = start_req_fd(id: 1, fd: 0) + let start_command = start_req_fd(id: 1) guard let data = try await client?.request(start_command, type: Response>.self) else { throw BurrowError.cantParseResult diff --git a/burrow/src/daemon/instance.rs b/burrow/src/daemon/instance.rs index 6a430c5..7866fb5 100644 --- a/burrow/src/daemon/instance.rs +++ b/burrow/src/daemon/instance.rs @@ -54,12 +54,7 @@ impl DaemonInstance { warn!("Got start, but tun interface already up."); } RunState::Idle => { - let raw = tun::TunInterface::retrieve().unwrap(); - debug!("TunInterface retrieved: {:?}", raw.name()?); - - let retrieved = TunInterface::new(raw)?; - let tun_if = Arc::new(RwLock::new(retrieved)); - // let tun_if = Arc::new(RwLock::new(TunInterface::new(st.tun.open()?)?)); + let tun_if = Arc::new(RwLock::new(st.tun.open()?)); debug!("Setting tun_interface"); self.tun_interface = Some(tun_if.clone()); diff --git a/burrow/src/daemon/mod.rs b/burrow/src/daemon/mod.rs index 4e91968..5066b26 100644 --- a/burrow/src/daemon/mod.rs +++ b/burrow/src/daemon/mod.rs @@ -53,9 +53,14 @@ pub async fn daemon_main() -> Result<()> { let private_key = parse_secret_key("GNqIAOCRxjl/cicZyvkvpTklgQuUmGUIEkH7IXF/sEE=")?; let public_key = parse_public_key("uy75leriJay0+oHLhRMpV+A5xAQ0hCJ+q7Ww81AOvT4=")?; let preshared_key = Some(parse_key("s7lx/mg+reVEMnGnqeyYOQkzD86n2+gYnx1M9ygi08k=")?); - let endpoint = "wg.burrow.rs:51820".to_socket_addrs()?.next() + tracing::debug!("beginning to find endpoint location"); + let endpoint = "wg.burrow.rs:51820".to_socket_addrs()? + .filter(|sock| {sock.is_ipv4()}) + .next() .ok_or(anyhow!("DNS Lookup Fails!"))?; // DNS lookup under macos fails, somehow + tracing::debug!("endpoint initialized: {:?}", endpoint.to_string()); + let iface = Interface::new(vec![Peer { endpoint, private_key, diff --git a/tun/src/options.rs b/tun/src/options.rs index 7c414dc..f5f6778 100644 --- a/tun/src/options.rs +++ b/tun/src/options.rs @@ -2,7 +2,7 @@ use std::io::Error; use fehler::throws; -use super::TunInterface; +use super::tokio::TunInterface; #[derive(Debug, Clone, Default)] #[cfg_attr( @@ -16,6 +16,8 @@ pub struct TunOptions { pub no_pi: bool, /// (Linux) Avoid opening an existing persistant device. pub tun_excl: bool, + /// (Apple) Retrieve the tun interface + pub tun_retrieve: bool, /// (Linux) The IP address of the tun interface. pub address: Option, } @@ -47,6 +49,7 @@ impl TunOptions { #[throws] pub fn open(self) -> TunInterface { - TunInterface::new_with_options(self)? + let ti = super::TunInterface::new_with_options(self)?; + TunInterface::new(ti)? } } diff --git a/tun/src/unix/apple/mod.rs b/tun/src/unix/apple/mod.rs index ab08505..ba0dfd8 100644 --- a/tun/src/unix/apple/mod.rs +++ b/tun/src/unix/apple/mod.rs @@ -35,7 +35,14 @@ impl TunInterface { #[throws] #[instrument] pub fn new_with_options(options: TunOptions) -> TunInterface { - let ti = TunInterface::connect(0)?; + let ti = if options.tun_retrieve{ + TunInterface::retrieve().ok_or(Error::new( + std::io::ErrorKind::NotFound, + "No tun interface found", + ))? + } else { + TunInterface::connect(0)? + }; ti.configure(options)?; ti }