From 8027681307f23a21dc5f9402dfd4d8b1008fc069 Mon Sep 17 00:00:00 2001 From: XOR-op <17672363+XOR-op@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:33:27 -0400 Subject: [PATCH] feat: cli option to disable tun --- boltconn/src/app.rs | 4 +++- boltconn/src/cli/mod.rs | 2 ++ boltconn/src/main.rs | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/boltconn/src/app.rs b/boltconn/src/app.rs index 557e568..beeb079 100644 --- a/boltconn/src/app.rs +++ b/boltconn/src/app.rs @@ -48,6 +48,7 @@ impl App { config_path: PathBuf, data_path: PathBuf, cert_path: PathBuf, + enable_tun: Option, ) -> anyhow::Result { // tracing let stream_logger = StreamLoggerSend::new(); @@ -129,6 +130,7 @@ impl App { }; // Create TUN + let will_enable_tun = enable_tun.unwrap_or(config.inbound.enable_tun); let (tun_udp_tx, tun_udp_rx) = flume::bounded(4096); let (udp_tun_tx, udp_tun_rx) = flume::bounded(4096); let tun = { @@ -154,7 +156,7 @@ impl App { fake_dns_server, tun.get_name(), ))); - if config.inbound.enable_tun { + if will_enable_tun { tun_configure .lock() .unwrap() diff --git a/boltconn/src/cli/mod.rs b/boltconn/src/cli/mod.rs index 08ec65c..5e25ce8 100644 --- a/boltconn/src/cli/mod.rs +++ b/boltconn/src/cli/mod.rs @@ -125,6 +125,8 @@ pub(crate) struct StartOptions { /// Path of certificate. Default to ${app_data}/cert #[arg(long)] pub cert: Option, + #[arg(short = 't', long = "tun")] + pub enable_tun: Option, } #[derive(Debug, Args)] diff --git a/boltconn/src/main.rs b/boltconn/src/main.rs index a04deba..f66cd91 100644 --- a/boltconn/src/main.rs +++ b/boltconn/src/main.rs @@ -100,7 +100,12 @@ fn main() -> ExitCode { ); return ExitCode::FAILURE; } - let app = match rt.block_on(App::create(config_path, data_path, cert_path)) { + let app = match rt.block_on(App::create( + config_path, + data_path, + cert_path, + cmds.enable_tun, + )) { Ok(app) => app, Err(e) => { eprintln!("{e}");