diff --git a/Cargo.toml b/Cargo.toml index a17bdb8..f2d171d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tun2proxy" -version = "0.6.2" +version = "0.6.3" edition = "2021" license = "MIT" repository = "https://github.com/tun2proxy/tun2proxy" diff --git a/README.md b/README.md index 5b4ba04..06f0601 100644 --- a/README.md +++ b/README.md @@ -160,8 +160,9 @@ Options: --daemonize Daemonize for unix family or run as Windows service --exit-on-fatal-error Exit immediately when fatal error occurs, useful for running as a service --max-sessions Maximum number of sessions to be handled concurrently [default: 200] - --udpgw-server UDP gateway server address, similar to badvpn-udpgw - --udpgw-max-connections Max udpgw connections, default value is 5 + --udpgw-server UDP gateway server address, forwards UDP packets via specified TCP server + --udpgw-connections Max connections for the UDP gateway, default value is 5 + --udpgw-keepalive Keepalive interval in seconds for the UDP gateway, default value is 30 -h, --help Print help -V, --version Print version ``` diff --git a/src/args.rs b/src/args.rs index 919c673..85904db 100644 --- a/src/args.rs +++ b/src/args.rs @@ -111,15 +111,20 @@ pub struct Args { #[arg(long, value_name = "number", default_value = "200")] pub max_sessions: usize, - /// UDP gateway server address, similar to badvpn-udpgw + /// UDP gateway server address, forwards UDP packets via specified TCP server #[cfg(feature = "udpgw")] #[arg(long, value_name = "IP:PORT")] pub udpgw_server: Option, - /// Max udpgw connections, default value is 5 + /// Max connections for the UDP gateway, default value is 5 #[cfg(feature = "udpgw")] #[arg(long, value_name = "number", requires = "udpgw_server")] - pub udpgw_max_connections: Option, + pub udpgw_connections: Option, + + /// Keepalive interval in seconds for the UDP gateway, default value is 30 + #[cfg(feature = "udpgw")] + #[arg(long, value_name = "seconds", requires = "udpgw_server")] + pub udpgw_keepalive: Option, } fn validate_tun(p: &str) -> Result { @@ -166,7 +171,9 @@ impl Default for Args { #[cfg(feature = "udpgw")] udpgw_server: None, #[cfg(feature = "udpgw")] - udpgw_max_connections: None, + udpgw_connections: None, + #[cfg(feature = "udpgw")] + udpgw_keepalive: None, } } } @@ -201,8 +208,8 @@ impl Args { } #[cfg(feature = "udpgw")] - pub fn udpgw_max_connections(&mut self, udpgw_max_connections: usize) -> &mut Self { - self.udpgw_max_connections = Some(udpgw_max_connections); + pub fn udpgw_connections(&mut self, udpgw_connections: usize) -> &mut Self { + self.udpgw_connections = Some(udpgw_connections); self } diff --git a/src/lib.rs b/src/lib.rs index 1aa64ca..932dda8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -240,14 +240,15 @@ where let mut ip_stack = ipstack::IpStack::new(ipstack_config, device); #[cfg(feature = "udpgw")] - let udpgw_client = args.udpgw_server.as_ref().map(|addr| { - log::info!("UDPGW enabled"); + let udpgw_client = args.udpgw_server.map(|addr| { + log::info!("UDP Gateway enabled, server: {}", addr); + use std::time::Duration; let client = Arc::new(UdpGwClient::new( mtu, - args.udpgw_max_connections.unwrap_or(UDPGW_MAX_CONNECTIONS), - UDPGW_KEEPALIVE_TIME, + args.udpgw_connections.unwrap_or(UDPGW_MAX_CONNECTIONS), + args.udpgw_keepalive.map(Duration::from_secs).unwrap_or(UDPGW_KEEPALIVE_TIME), args.udp_timeout, - *addr, + addr, )); let client_keepalive = client.clone(); tokio::spawn(async move {