Start Tun Interface at Daemon Command

This commit is contained in:
Jett Chen 2023-12-09 20:13:49 +08:00
parent 347b78453f
commit ede0d13bca
9 changed files with 83 additions and 52 deletions

View file

@ -13,6 +13,10 @@ pub struct TunOptions {
pub(crate) no_pi: Option<()>,
/// (Linux) Avoid opening an existing persistant device.
pub(crate) tun_excl: Option<()>,
/// (MacOS) Whether to seek the first available utun device.
pub(crate) seek_utun: Option<()>,
/// (Linux) The IP address of the tun interface.
pub(crate) address: Option<String>,
}
impl TunOptions {
@ -27,6 +31,11 @@ impl TunOptions {
pub fn tun_excl(mut self, enable: bool) { self.tun_excl = enable.then_some(()); }
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)? }
}