mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 14:36:15 -05:00
feat: add the -i/--interface option (#512)
This commit is contained in:
1 parent
ea9819d161
commit
c1ab26aef3
5 files changed
+19
-1
No files matched your search
@@ -44,6 +44,9 @@ pub(crate) struct ConnectArgs {
|
|||||||
#[arg(long, short, help = "The VPNC script to use")]
|
#[arg(long, short, help = "The VPNC script to use")]
|
||||||
script: Option<String>,
|
script: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long, short, help = "The IFNAME for tunnel interface")]
|
||||||
|
interface: Option<String>,
|
||||||
|
|
||||||
#[arg(long, help = "Connect the server as a gateway, instead of a portal")]
|
#[arg(long, help = "Connect the server as a gateway, instead of a portal")]
|
||||||
as_gateway: bool,
|
as_gateway: bool,
|
||||||
|
|
||||||
@@ -313,6 +316,7 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
||||||
let vpn = Vpn::builder(gateway, cookie)
|
let vpn = Vpn::builder(gateway, cookie)
|
||||||
.script(self.args.script.clone())
|
.script(self.args.script.clone())
|
||||||
|
.interface(self.args.interface.clone())
|
||||||
.user_agent(self.args.user_agent.clone())
|
.user_agent(self.args.user_agent.clone())
|
||||||
.os(Some(os))
|
.os(Some(os))
|
||||||
.certificate(self.args.certificate.clone())
|
.certificate(self.args.certificate.clone())
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub(crate) struct ConnectOptions {
|
|||||||
pub user_agent: *const c_char,
|
pub user_agent: *const c_char,
|
||||||
|
|
||||||
pub script: *const c_char,
|
pub script: *const c_char,
|
||||||
|
pub interface: *const c_char,
|
||||||
pub os: *const c_char,
|
pub os: *const c_char,
|
||||||
pub certificate: *const c_char,
|
pub certificate: *const c_char,
|
||||||
pub sslkey: *const c_char,
|
pub sslkey: *const c_char,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ void *g_user_data;
|
|||||||
|
|
||||||
static int g_cmd_pipe_fd;
|
static int g_cmd_pipe_fd;
|
||||||
static const char *g_vpnc_script;
|
static const char *g_vpnc_script;
|
||||||
|
static const char *g_vpnc_interface;
|
||||||
static vpn_connected_callback on_vpn_connected;
|
static vpn_connected_callback on_vpn_connected;
|
||||||
|
|
||||||
/* Validate the peer certificate */
|
/* Validate the peer certificate */
|
||||||
@@ -38,7 +39,7 @@ static void print_progress(__attribute__((unused)) void *_vpninfo, int level, co
|
|||||||
|
|
||||||
static void setup_tun_handler(void *_vpninfo)
|
static void setup_tun_handler(void *_vpninfo)
|
||||||
{
|
{
|
||||||
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script, NULL);
|
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script, g_vpnc_interface);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
||||||
}
|
}
|
||||||
@@ -53,6 +54,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
|
|
||||||
g_user_data = options->user_data;
|
g_user_data = options->user_data;
|
||||||
g_vpnc_script = options->script;
|
g_vpnc_script = options->script;
|
||||||
|
g_vpnc_interface = options->interface;
|
||||||
on_vpn_connected = callback;
|
on_vpn_connected = callback;
|
||||||
|
|
||||||
INFO("User agent: %s", options->user_agent);
|
INFO("User agent: %s", options->user_agent);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ typedef struct vpn_options
|
|||||||
const char *user_agent;
|
const char *user_agent;
|
||||||
|
|
||||||
const char *script;
|
const char *script;
|
||||||
|
const char *interface;
|
||||||
const char *os;
|
const char *os;
|
||||||
const char *certificate;
|
const char *certificate;
|
||||||
const char *sslkey;
|
const char *sslkey;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub struct Vpn {
|
|||||||
cookie: CString,
|
cookie: CString,
|
||||||
user_agent: CString,
|
user_agent: CString,
|
||||||
script: CString,
|
script: CString,
|
||||||
|
interface: Option<CString>,
|
||||||
os: CString,
|
os: CString,
|
||||||
certificate: Option<CString>,
|
certificate: Option<CString>,
|
||||||
sslkey: Option<CString>,
|
sslkey: Option<CString>,
|
||||||
@@ -65,6 +66,7 @@ impl Vpn {
|
|||||||
cookie: self.cookie.as_ptr(),
|
cookie: self.cookie.as_ptr(),
|
||||||
user_agent: self.user_agent.as_ptr(),
|
user_agent: self.user_agent.as_ptr(),
|
||||||
script: self.script.as_ptr(),
|
script: self.script.as_ptr(),
|
||||||
|
interface: Self::option_to_ptr(&self.interface),
|
||||||
os: self.os.as_ptr(),
|
os: self.os.as_ptr(),
|
||||||
|
|
||||||
certificate: Self::option_to_ptr(&self.certificate),
|
certificate: Self::option_to_ptr(&self.certificate),
|
||||||
@@ -113,6 +115,7 @@ pub struct VpnBuilder {
|
|||||||
server: String,
|
server: String,
|
||||||
cookie: String,
|
cookie: String,
|
||||||
script: Option<String>,
|
script: Option<String>,
|
||||||
|
interface: Option<String>,
|
||||||
|
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
os: Option<String>,
|
os: Option<String>,
|
||||||
@@ -136,6 +139,7 @@ impl VpnBuilder {
|
|||||||
server: server.to_string(),
|
server: server.to_string(),
|
||||||
cookie: cookie.to_string(),
|
cookie: cookie.to_string(),
|
||||||
script: None,
|
script: None,
|
||||||
|
interface: None,
|
||||||
|
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
os: None,
|
os: None,
|
||||||
@@ -159,6 +163,11 @@ impl VpnBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn interface<T: Into<Option<String>>>(mut self, interface: T) -> Self {
|
||||||
|
self.interface = interface.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn user_agent<T: Into<Option<String>>>(mut self, user_agent: T) -> Self {
|
pub fn user_agent<T: Into<Option<String>>>(mut self, user_agent: T) -> Self {
|
||||||
self.user_agent = user_agent.into();
|
self.user_agent = user_agent.into();
|
||||||
self
|
self
|
||||||
@@ -235,6 +244,7 @@ impl VpnBuilder {
|
|||||||
cookie: Self::to_cstring(&self.cookie),
|
cookie: Self::to_cstring(&self.cookie),
|
||||||
user_agent: Self::to_cstring(&user_agent),
|
user_agent: Self::to_cstring(&user_agent),
|
||||||
script: Self::to_cstring(&script),
|
script: Self::to_cstring(&script),
|
||||||
|
interface: self.interface.as_deref().map(Self::to_cstring),
|
||||||
os: Self::to_cstring(&os),
|
os: Self::to_cstring(&os),
|
||||||
|
|
||||||
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
||||||
|
|||||||
Reference in new issue
Block a user