Skip to content

Commit

Permalink
feat: add the --reconnect-timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezk committed May 19, 2024
1 parent 90a8c11 commit af51bc2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions apps/gpclient/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub(crate) struct ConnectArgs {
#[arg(long, help = "Same as the '--csd-wrapper' option in the openconnect command")]
csd_wrapper: Option<String>,

#[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<u32>,
#[arg(long, help = "Do not ask for IPv6 connectivity")]
Expand Down Expand Up @@ -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()?;
Expand Down
3 changes: 2 additions & 1 deletion apps/gpservice/src/vpn_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
13 changes: 12 additions & 1 deletion crates/gpapi/src/service/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ pub struct ConnectArgs {
cookie: String,
vpnc_script: Option<String>,
user_agent: Option<String>,
os: Option<ClientOs>,
csd_uid: u32,
csd_wrapper: Option<String>,
reconnect_timeout: u32,
mtu: u32,
os: Option<ClientOs>,
disable_ipv6: bool,
}

Expand All @@ -48,6 +49,7 @@ impl ConnectArgs {
os: None,
csd_uid: 0,
csd_wrapper: None,
reconnect_timeout: 300,
mtu: 0,
disable_ipv6: false,
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/openconnect/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/openconnect/src/ffi/vpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion crates/openconnect/src/ffi/vpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions crates/openconnect/src/vpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Vpn {
csd_uid: u32,
csd_wrapper: Option<CString>,

reconnect_timeout: u32,
mtu: u32,
disable_ipv6: bool,

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -111,6 +113,7 @@ pub struct VpnBuilder {
csd_uid: u32,
csd_wrapper: Option<String>,

reconnect_timeout: u32,
mtu: u32,
disable_ipv6: bool,
}
Expand All @@ -128,6 +131,7 @@ impl VpnBuilder {
csd_uid: 0,
csd_wrapper: None,

reconnect_timeout: 300,
mtu: 0,
disable_ipv6: false,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit af51bc2

Please sign in to comment.