mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
fix: retain VPN cancellation throughout connection startup
This commit is contained in:
5 files changed
+298
-53
No files matched your search
@@ -53,24 +53,38 @@ pub(crate) struct VpnSessionInfoRaw {
|
||||
|
||||
#[link(name = "vpn")]
|
||||
unsafe extern "C" {
|
||||
fn vpn_write_cancel(fd: c_int) -> c_int;
|
||||
#[link_name = "vpn_connect"]
|
||||
fn vpn_connect(
|
||||
options: *const ConnectOptions,
|
||||
callback: extern "C" fn(i32, *const VpnSessionInfoRaw, *mut c_void),
|
||||
) -> c_int;
|
||||
|
||||
#[link_name = "vpn_disconnect"]
|
||||
fn vpn_disconnect();
|
||||
}
|
||||
|
||||
pub(crate) fn write_cancel(fd: i32) -> std::io::Result<()> {
|
||||
let error = unsafe { vpn_write_cancel(fd) };
|
||||
if error == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(std::io::Error::from_raw_os_error(error))
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn vpn_attach_command_pipe(vpn: *mut c_void, fd: c_int) -> c_int {
|
||||
unsafe { &*(vpn as *const Vpn) }.attach_command_pipe(fd).into()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn vpn_detach_command_pipe(vpn: *mut c_void) {
|
||||
unsafe { &*(vpn as *const Vpn) }.detach_command_pipe();
|
||||
}
|
||||
|
||||
pub(crate) fn connect(options: &ConnectOptions) -> i32 {
|
||||
unsafe { vpn_connect(options, on_vpn_connected) }
|
||||
}
|
||||
|
||||
pub(crate) fn disconnect() {
|
||||
unsafe { vpn_disconnect() }
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn on_vpn_connected(pipe_fd: i32, session_info: *const VpnSessionInfoRaw, vpn: *mut c_void) {
|
||||
let vpn = unsafe { &*(vpn as *const Vpn) };
|
||||
|
||||
Reference in new issue
Block a user