From fb3ad33b53b12028ffbac8b5e466d024357802a9 Mon Sep 17 00:00:00 2001 From: "B. Blechschmidt" Date: Thu, 13 Apr 2023 21:54:02 +0200 Subject: [PATCH] Add file descriptor and MTU to CLI arguments --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 166012c..43b128e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,14 @@ struct Args { #[arg(short, long, value_name = "name", default_value = "tun0")] tun: String, + /// File descriptor of the tun interface + #[arg(long, value_name = "fd")] + tun_fd: Option, + + /// MTU of the tun interface (only with tunnel file descriptor) + #[arg(long, value_name = "mtu", default_value = "1500")] + tun_mtu: usize, + /// Proxy URL in the form proto://[username[:password]@]host:port #[arg(short, long, value_parser = Proxy::from_url, value_name = "URL")] proxy: Proxy, @@ -67,6 +75,14 @@ fn main() -> ExitCode { options = options.with_virtual_dns(); } + let interface = match args.tun_fd { + None => NetworkInterface::Named(args.tun.clone()), + Some(fd) => { + options = options.with_mtu(args.tun_mtu); + NetworkInterface::Fd(fd) + } + }; + if let Err(e) = (|| -> Result<(), Error> { #[cfg(target_os = "linux")] { @@ -89,7 +105,6 @@ fn main() -> ExitCode { } } - let interface = NetworkInterface::Named(args.tun); main_entry(&interface, &args.proxy, options)?; Ok(())