diff --git a/apps/gpclient/src/connect.rs b/apps/gpclient/src/connect.rs index a9fccf09..f1b1ed9e 100644 --- a/apps/gpclient/src/connect.rs +++ b/apps/gpclient/src/connect.rs @@ -48,6 +48,8 @@ pub(crate) struct ConnectArgs { #[arg(long, help = "Same as the '--csd-wrapper' option in the openconnect command")] csd_wrapper: Option, + #[arg(long, default_value = "300", help = "Reconnection retry timeout in seconds")] + reconnect_timeout: u32, #[arg(short, long, help = "Request MTU from server (legacy servers only)")] mtu: Option, #[arg(long, help = "Do not ask for IPv6 connectivity")] @@ -217,6 +219,7 @@ impl<'a> ConnectHandler<'a> { .user_agent(self.args.user_agent.clone()) .csd_uid(csd_uid) .csd_wrapper(csd_wrapper) + .reconnect_timeout(self.args.reconnect_timeout) .mtu(mtu) .disable_ipv6(self.args.disable_ipv6) .build()?; diff --git a/apps/gpservice/src/vpn_task.rs b/apps/gpservice/src/vpn_task.rs index 192fb8ba..a90e365d 100644 --- a/apps/gpservice/src/vpn_task.rs +++ b/apps/gpservice/src/vpn_task.rs @@ -38,10 +38,11 @@ impl VpnTaskContext { let vpn = match Vpn::builder(req.gateway().server(), args.cookie()) .script(args.vpnc_script()) .user_agent(args.user_agent()) + .os(args.openconnect_os()) .csd_uid(args.csd_uid()) .csd_wrapper(args.csd_wrapper()) + .reconnect_timeout(args.reconnect_timeout()) .mtu(args.mtu()) - .os(args.openconnect_os()) .disable_ipv6(args.disable_ipv6()) .build() { diff --git a/crates/gpapi/src/service/request.rs b/crates/gpapi/src/service/request.rs index 28279dcc..1f960ec9 100644 --- a/crates/gpapi/src/service/request.rs +++ b/crates/gpapi/src/service/request.rs @@ -32,10 +32,11 @@ pub struct ConnectArgs { cookie: String, vpnc_script: Option, user_agent: Option, + os: Option, csd_uid: u32, csd_wrapper: Option, + reconnect_timeout: u32, mtu: u32, - os: Option, disable_ipv6: bool, } @@ -48,6 +49,7 @@ impl ConnectArgs { os: None, csd_uid: 0, csd_wrapper: None, + reconnect_timeout: 300, mtu: 0, disable_ipv6: false, } @@ -77,6 +79,10 @@ impl ConnectArgs { self.csd_wrapper.clone() } + pub fn reconnect_timeout(&self) -> u32 { + self.reconnect_timeout + } + pub fn mtu(&self) -> u32 { self.mtu } @@ -125,6 +131,11 @@ impl ConnectRequest { self } + pub fn with_reconnect_timeout(mut self, reconnect_timeout: u32) -> Self { + self.args.reconnect_timeout = reconnect_timeout; + self + } + pub fn with_mtu(mut self, mtu: u32) -> Self { self.args.mtu = mtu; self diff --git a/crates/openconnect/src/ffi/mod.rs b/crates/openconnect/src/ffi/mod.rs index cdae0196..5469c18f 100644 --- a/crates/openconnect/src/ffi/mod.rs +++ b/crates/openconnect/src/ffi/mod.rs @@ -19,6 +19,7 @@ pub(crate) struct ConnectOptions { pub csd_uid: u32, pub csd_wrapper: *const c_char, + pub reconnect_timeout: u32, pub mtu: u32, pub disable_ipv6: u32, } diff --git a/crates/openconnect/src/ffi/vpn.c b/crates/openconnect/src/ffi/vpn.c index d5b83433..6aec00e4 100644 --- a/crates/openconnect/src/ffi/vpn.c +++ b/crates/openconnect/src/ffi/vpn.c @@ -63,6 +63,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback) INFO("OS: %s", options->os); INFO("CSD_USER: %d", options->csd_uid); INFO("CSD_WRAPPER: %s", options->csd_wrapper); + INFO("RECONNECT_TIMEOUT: %d", options->reconnect_timeout); INFO("MTU: %d", options->mtu); INFO("DISABLE_IPV6: %d", options->disable_ipv6); @@ -137,7 +138,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback) while (1) { - int ret = openconnect_mainloop(vpninfo, 300, 10); + int ret = openconnect_mainloop(vpninfo, options->reconnect_timeout, 10); if (ret) { diff --git a/crates/openconnect/src/ffi/vpn.h b/crates/openconnect/src/ffi/vpn.h index d2e8b58c..f301cc08 100644 --- a/crates/openconnect/src/ffi/vpn.h +++ b/crates/openconnect/src/ffi/vpn.h @@ -20,8 +20,8 @@ typedef struct vpn_options const uid_t csd_uid; const char *csd_wrapper; + const int reconnect_timeout; const int mtu; - const int disable_ipv6; } vpn_options; diff --git a/crates/openconnect/src/vpn.rs b/crates/openconnect/src/vpn.rs index bb2040f8..74fb40ed 100644 --- a/crates/openconnect/src/vpn.rs +++ b/crates/openconnect/src/vpn.rs @@ -23,6 +23,7 @@ pub struct Vpn { csd_uid: u32, csd_wrapper: Option, + reconnect_timeout: u32, mtu: u32, disable_ipv6: bool, @@ -68,6 +69,7 @@ impl Vpn { csd_uid: self.csd_uid, csd_wrapper: Self::option_to_ptr(&self.csd_wrapper), + reconnect_timeout: self.reconnect_timeout, mtu: self.mtu, disable_ipv6: self.disable_ipv6 as u32, } @@ -111,6 +113,7 @@ pub struct VpnBuilder { csd_uid: u32, csd_wrapper: Option, + reconnect_timeout: u32, mtu: u32, disable_ipv6: bool, } @@ -128,6 +131,7 @@ impl VpnBuilder { csd_uid: 0, csd_wrapper: None, + reconnect_timeout: 300, mtu: 0, disable_ipv6: false, } @@ -158,6 +162,11 @@ impl VpnBuilder { self } + pub fn reconnect_timeout(mut self, reconnect_timeout: u32) -> Self { + self.reconnect_timeout = reconnect_timeout; + self + } + pub fn mtu(mut self, mtu: u32) -> Self { self.mtu = mtu; self @@ -196,6 +205,7 @@ impl VpnBuilder { csd_uid: self.csd_uid, csd_wrapper: self.csd_wrapper.as_deref().map(Self::to_cstring), + reconnect_timeout: self.reconnect_timeout, mtu: self.mtu, disable_ipv6: self.disable_ipv6,