feat: add the --force-dpd option

gh-519
This commit is contained in:
Kevin Yue committed 2025-07-15 22:03:35 +08:00
1 parent 11925a372d
commit 5ba7bf2e18
5 files changed
+25

No files matched your search

+4
View File
@@ -96,6 +96,9 @@ pub(crate) struct ConnectArgs {
#[arg(long, help = "Disable DTLS and ESP")] #[arg(long, help = "Disable DTLS and ESP")]
no_dtls: bool, no_dtls: bool,
#[arg(long = "force-dpd", help = "Same as the '--force-dpd' option in the openconnect command")]
dpd_interval: Option<u32>,
#[cfg(feature = "webview-auth")] #[cfg(feature = "webview-auth")]
#[arg(long, help = "The HiDPI mode, useful for high-resolution screens")] #[arg(long, help = "The HiDPI mode, useful for high-resolution screens")]
hidpi: bool, hidpi: bool,
@@ -328,6 +331,7 @@ impl<'a> ConnectHandler<'a> {
.mtu(mtu) .mtu(mtu)
.disable_ipv6(self.args.disable_ipv6) .disable_ipv6(self.args.disable_ipv6)
.no_dtls(self.args.no_dtls) .no_dtls(self.args.no_dtls)
.dpd_interval(self.args.dpd_interval.unwrap_or(0))
.build()?; .build()?;
let vpn = Arc::new(vpn); let vpn = Arc::new(vpn);
+2
View File
@@ -26,6 +26,8 @@ pub(crate) struct ConnectOptions {
pub mtu: u32, pub mtu: u32,
pub disable_ipv6: u32, pub disable_ipv6: u32,
pub no_dtls: u32, pub no_dtls: u32,
pub dpd_interval: u32,
} }
#[link(name = "vpn")] #[link(name = "vpn")]
+5
View File
@@ -66,6 +66,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
INFO("MTU: %d", options->mtu); INFO("MTU: %d", options->mtu);
INFO("DISABLE_IPV6: %d", options->disable_ipv6); INFO("DISABLE_IPV6: %d", options->disable_ipv6);
INFO("NO_DTLS: %d", options->no_dtls); INFO("NO_DTLS: %d", options->no_dtls);
INFO("DPD_INTERVAL: %d", options->dpd_interval);
vpninfo = openconnect_vpninfo_new(options->user_agent, validate_peer_cert, NULL, NULL, print_progress, NULL); vpninfo = openconnect_vpninfo_new(options->user_agent, validate_peer_cert, NULL, NULL, print_progress, NULL);
@@ -106,6 +107,10 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
openconnect_disable_ipv6(vpninfo); openconnect_disable_ipv6(vpninfo);
} }
if (options->dpd_interval > 0) {
openconnect_set_dpd(vpninfo, options->dpd_interval);
}
g_cmd_pipe_fd = openconnect_setup_cmd_pipe(vpninfo); g_cmd_pipe_fd = openconnect_setup_cmd_pipe(vpninfo);
if (g_cmd_pipe_fd < 0) { if (g_cmd_pipe_fd < 0) {
ERROR("openconnect_setup_cmd_pipe failed"); ERROR("openconnect_setup_cmd_pipe failed");
+2
View File
@@ -27,6 +27,8 @@ typedef struct vpn_options
const int mtu; const int mtu;
const int disable_ipv6; const int disable_ipv6;
const int no_dtls; const int no_dtls;
const int dpd_interval;
} vpn_options; } vpn_options;
int vpn_connect(const vpn_options *options, vpn_connected_callback callback); int vpn_connect(const vpn_options *options, vpn_connected_callback callback);
+12
View File
@@ -31,6 +31,8 @@ pub struct Vpn {
disable_ipv6: bool, disable_ipv6: bool,
no_dtls: bool, no_dtls: bool,
dpd_interval: u32,
callback: OnConnectedCallback, callback: OnConnectedCallback,
} }
@@ -81,6 +83,7 @@ impl Vpn {
mtu: self.mtu, mtu: self.mtu,
disable_ipv6: self.disable_ipv6 as u32, disable_ipv6: self.disable_ipv6 as u32,
no_dtls: self.no_dtls as u32, no_dtls: self.no_dtls as u32,
dpd_interval: self.dpd_interval,
} }
} }
@@ -131,6 +134,8 @@ pub struct VpnBuilder {
mtu: u32, mtu: u32,
disable_ipv6: bool, disable_ipv6: bool,
no_dtls: bool, no_dtls: bool,
dpd_interval: u32,
} }
impl VpnBuilder { impl VpnBuilder {
@@ -155,6 +160,7 @@ impl VpnBuilder {
mtu: 0, mtu: 0,
disable_ipv6: false, disable_ipv6: false,
no_dtls: false, no_dtls: false,
dpd_interval: 0,
} }
} }
@@ -223,6 +229,11 @@ impl VpnBuilder {
self self
} }
pub fn dpd_interval(mut self, dpd_interval: u32) -> Self {
self.dpd_interval = dpd_interval;
self
}
pub fn build(self) -> Result<Vpn, VpnError> { pub fn build(self) -> Result<Vpn, VpnError> {
let script = match self.script { let script = match self.script {
Some(script) => { Some(script) => {
@@ -259,6 +270,7 @@ impl VpnBuilder {
mtu: self.mtu, mtu: self.mtu,
disable_ipv6: self.disable_ipv6, disable_ipv6: self.disable_ipv6,
no_dtls: self.no_dtls, no_dtls: self.no_dtls,
dpd_interval: self.dpd_interval,
callback: Default::default(), callback: Default::default(),
}) })