Initialize Tun Interface based on platform
This commit is contained in:
parent
c346ec5b39
commit
54ec260fe3
6 changed files with 24 additions and 14 deletions
|
|
@ -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<BurrowStartRequest> {
|
||||
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<BurrowStartRequest> {
|
||||
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<T>: Decodable where T: Decodable {
|
||||
|
|
|
|||
|
|
@ -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<BurrowResult<String>>.self)
|
||||
else {
|
||||
throw BurrowError.cantParseResult
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
}
|
||||
|
|
@ -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)?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue