diff --git a/apps/gpclient/src/connect.rs b/apps/gpclient/src/connect.rs index b6cf650c..a9fccf09 100644 --- a/apps/gpclient/src/connect.rs +++ b/apps/gpclient/src/connect.rs @@ -50,6 +50,8 @@ pub(crate) struct ConnectArgs { #[arg(short, long, help = "Request MTU from server (legacy servers only)")] mtu: Option, + #[arg(long, help = "Do not ask for IPv6 connectivity")] + disable_ipv6: bool, #[arg(long, default_value = GP_USER_AGENT, help = "The user agent to use")] user_agent: String, @@ -216,6 +218,7 @@ impl<'a> ConnectHandler<'a> { .csd_uid(csd_uid) .csd_wrapper(csd_wrapper) .mtu(mtu) + .disable_ipv6(self.args.disable_ipv6) .build()?; let vpn = Arc::new(vpn); diff --git a/apps/gpservice/src/vpn_task.rs b/apps/gpservice/src/vpn_task.rs index 80fc3924..192fb8ba 100644 --- a/apps/gpservice/src/vpn_task.rs +++ b/apps/gpservice/src/vpn_task.rs @@ -42,6 +42,7 @@ impl VpnTaskContext { .csd_wrapper(args.csd_wrapper()) .mtu(args.mtu()) .os(args.openconnect_os()) + .disable_ipv6(args.disable_ipv6()) .build() { Ok(vpn) => vpn, diff --git a/crates/gpapi/src/service/request.rs b/crates/gpapi/src/service/request.rs index 57f37ee2..28279dcc 100644 --- a/crates/gpapi/src/service/request.rs +++ b/crates/gpapi/src/service/request.rs @@ -36,6 +36,7 @@ pub struct ConnectArgs { csd_wrapper: Option, mtu: u32, os: Option, + disable_ipv6: bool, } impl ConnectArgs { @@ -48,6 +49,7 @@ impl ConnectArgs { csd_uid: 0, csd_wrapper: None, mtu: 0, + disable_ipv6: false, } } @@ -78,6 +80,10 @@ impl ConnectArgs { pub fn mtu(&self) -> u32 { self.mtu } + + pub fn disable_ipv6(&self) -> bool { + self.disable_ipv6 + } } #[derive(Debug, Deserialize, Serialize, Type)] @@ -109,11 +115,6 @@ impl ConnectRequest { self } - pub fn with_mtu(mut self, mtu: u32) -> Self { - self.args.mtu = mtu; - self - } - pub fn with_user_agent>>(mut self, user_agent: T) -> Self { self.args.user_agent = user_agent.into(); self @@ -124,6 +125,16 @@ impl ConnectRequest { self } + pub fn with_mtu(mut self, mtu: u32) -> Self { + self.args.mtu = mtu; + self + } + + pub fn with_disable_ipv6(mut self, disable_ipv6: bool) -> Self { + self.args.disable_ipv6 = disable_ipv6; + self + } + pub fn gateway(&self) -> &Gateway { self.info.gateway() } diff --git a/crates/openconnect/src/ffi/mod.rs b/crates/openconnect/src/ffi/mod.rs index aa5a4a37..cdae0196 100644 --- a/crates/openconnect/src/ffi/mod.rs +++ b/crates/openconnect/src/ffi/mod.rs @@ -20,6 +20,7 @@ pub(crate) struct ConnectOptions { pub csd_wrapper: *const c_char, pub mtu: u32, + pub disable_ipv6: u32, } #[link(name = "vpn")] diff --git a/crates/openconnect/src/ffi/vpn.c b/crates/openconnect/src/ffi/vpn.c index e1f6c698..d5b83433 100644 --- a/crates/openconnect/src/ffi/vpn.c +++ b/crates/openconnect/src/ffi/vpn.c @@ -64,6 +64,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback) INFO("CSD_USER: %d", options->csd_uid); INFO("CSD_WRAPPER: %s", options->csd_wrapper); INFO("MTU: %d", options->mtu); + INFO("DISABLE_IPV6: %d", options->disable_ipv6); vpninfo = openconnect_vpninfo_new(options->user_agent, validate_peer_cert, NULL, NULL, print_progress, NULL); @@ -103,6 +104,10 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback) openconnect_set_reqmtu(vpninfo, mtu); } + if (options->disable_ipv6) { + openconnect_disable_ipv6(vpninfo); + } + g_cmd_pipe_fd = openconnect_setup_cmd_pipe(vpninfo); if (g_cmd_pipe_fd < 0) { diff --git a/crates/openconnect/src/ffi/vpn.h b/crates/openconnect/src/ffi/vpn.h index 58c52f00..d2e8b58c 100644 --- a/crates/openconnect/src/ffi/vpn.h +++ b/crates/openconnect/src/ffi/vpn.h @@ -21,6 +21,8 @@ typedef struct vpn_options const char *csd_wrapper; const int mtu; + + const int disable_ipv6; } vpn_options; int vpn_connect(const vpn_options *options, vpn_connected_callback callback); @@ -35,7 +37,7 @@ static char *format_message(const char *format, va_list args) int len = vsnprintf(NULL, 0, format, args_copy); va_end(args_copy); - char *buffer = malloc(len + 1); + char *buffer = (char*)malloc(len + 1); if (buffer == NULL) { return NULL; diff --git a/crates/openconnect/src/vpn.rs b/crates/openconnect/src/vpn.rs index e5f32805..bb2040f8 100644 --- a/crates/openconnect/src/vpn.rs +++ b/crates/openconnect/src/vpn.rs @@ -24,6 +24,7 @@ pub struct Vpn { csd_wrapper: Option, mtu: u32, + disable_ipv6: bool, callback: OnConnectedCallback, } @@ -68,6 +69,7 @@ impl Vpn { csd_wrapper: Self::option_to_ptr(&self.csd_wrapper), mtu: self.mtu, + disable_ipv6: self.disable_ipv6 as u32, } } @@ -110,6 +112,7 @@ pub struct VpnBuilder { csd_wrapper: Option, mtu: u32, + disable_ipv6: bool, } impl VpnBuilder { @@ -126,6 +129,7 @@ impl VpnBuilder { csd_wrapper: None, mtu: 0, + disable_ipv6: false, } } @@ -159,6 +163,11 @@ impl VpnBuilder { self } + pub fn disable_ipv6(mut self, disable_ipv6: bool) -> Self { + self.disable_ipv6 = disable_ipv6; + self + } + pub fn build(self) -> Result { let script = match self.script { Some(script) => { @@ -188,6 +197,7 @@ impl VpnBuilder { csd_wrapper: self.csd_wrapper.as_deref().map(Self::to_cstring), mtu: self.mtu, + disable_ipv6: self.disable_ipv6, callback: Default::default(), })