52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
use std::io::Error;
|
|
|
|
use fehler::throws;
|
|
|
|
use super::TunInterface;
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
#[cfg_attr(
|
|
feature = "serde",
|
|
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
|
|
)]
|
|
pub struct TunOptions {
|
|
/// (Windows + Linux) Name the tun interface.
|
|
pub name: Option<String>,
|
|
/// (Linux) Don't include packet information.
|
|
pub no_pi: bool,
|
|
/// (Linux) Avoid opening an existing persistant device.
|
|
pub tun_excl: bool,
|
|
/// (Linux) The IP address of the tun interface.
|
|
pub address: Option<String>,
|
|
}
|
|
|
|
impl TunOptions {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
pub fn name(mut self, name: &str) -> Self {
|
|
self.name = Some(name.to_owned());
|
|
self
|
|
}
|
|
|
|
pub fn no_pi(mut self, enable: bool) -> Self {
|
|
self.no_pi = enable;
|
|
self
|
|
}
|
|
|
|
pub fn tun_excl(mut self, enable: bool) -> Self {
|
|
self.tun_excl = enable;
|
|
self
|
|
}
|
|
|
|
pub fn address(mut self, address: impl ToString) -> Self {
|
|
self.address = Some(address.to_string());
|
|
self
|
|
}
|
|
|
|
#[throws]
|
|
pub fn open(self) -> TunInterface {
|
|
TunInterface::new_with_options(self)?
|
|
}
|
|
}
|