Initialize Tun Interface based on platform
This commit is contained in:
parent
c346ec5b39
commit
54ec260fe3
6 changed files with 24 additions and 14 deletions
|
|
@ -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