mirror of
				https://github.com/yuezk/GlobalProtect-openconnect.git
				synced 2025-05-20 07:26:58 -04:00 
			
		
		
		
	feat: add disable_ipv6 option (related #364)
This commit is contained in:
		| @@ -20,6 +20,7 @@ pub(crate) struct ConnectOptions { | ||||
|   pub csd_wrapper: *const c_char, | ||||
|  | ||||
|   pub mtu: u32, | ||||
|   pub disable_ipv6: u32, | ||||
| } | ||||
|  | ||||
| #[link(name = "vpn")] | ||||
|   | ||||
| @@ -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) | ||||
|     { | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -24,6 +24,7 @@ pub struct Vpn { | ||||
|   csd_wrapper: Option<CString>, | ||||
|  | ||||
|   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<String>, | ||||
|  | ||||
|   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<Vpn, VpnError> { | ||||
|     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(), | ||||
|     }) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user