mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 06:06:13 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2aa875a626 | ||
|
|
e4fa429dcc | ||
|
|
5ba7bf2e18 | ||
|
|
11925a372d | ||
|
|
e1eb9e20f1 | ||
|
|
1d3aa889d5 | ||
|
|
c1ab26aef3 | ||
|
|
ea9819d161 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 8
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
ColumnLimit: 80
|
||||
BreakBeforeBraces: Linux
|
||||
@@ -8,5 +8,9 @@ end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[{*.c,*.h}]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
|
||||
[{Makefile,Makefile.in}]
|
||||
indent_style = tab
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
run: |
|
||||
# Set the matrix to include arm64 if the ref is a tag or is the dev branch
|
||||
if [[ "${{ github.ref }}" == "refs/tags/"* || "${{ github.ref }}" == "refs/heads/dev" ]]; then
|
||||
echo 'matrix=[{"runner": "ubuntu-latest", "arch": "amd64"}, {"runner": "arm64", "arch": "arm64"}]' >> $GITHUB_OUTPUT
|
||||
echo 'matrix=[{"runner": "ubuntu-latest", "arch": "amd64"}, {"runner": "ubuntu-24.04-arm", "arch": "ubuntu-24.04-arm"}]' >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo 'matrix=[{"runner": "ubuntu-latest", "arch": "amd64"}]' >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
@@ -73,9 +73,9 @@ jobs:
|
||||
const inputs = ${{ toJson(inputs) }}
|
||||
const { arch } = inputs
|
||||
const osMap = {
|
||||
"all": ["ubuntu-latest", "arm64"],
|
||||
"all": ["ubuntu-latest", "ubuntu-24.04-arm"],
|
||||
"x86_64": ["ubuntu-latest"],
|
||||
"arm64": ["arm64"]
|
||||
"arm64": ["ubuntu-24.04-arm"]
|
||||
}
|
||||
|
||||
const package = Object.entries(inputs)
|
||||
|
||||
Generated
+8
-8
@@ -176,7 +176,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||
|
||||
[[package]]
|
||||
name = "auth"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"block2",
|
||||
@@ -642,7 +642,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"is_executable",
|
||||
]
|
||||
@@ -1625,7 +1625,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gpapi"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.22.1",
|
||||
@@ -1662,7 +1662,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gpauth"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"auth",
|
||||
@@ -1681,7 +1681,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gpclient"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -1703,7 +1703,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gpgui-helper"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -1721,7 +1721,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gpservice"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
@@ -2987,7 +2987,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openconnect"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"common",
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ members = [
|
||||
|
||||
[workspace.package]
|
||||
rust-version = "1.80"
|
||||
version = "2.4.4"
|
||||
version = "2.4.5"
|
||||
authors = ["Kevin Yue <[email protected]>"]
|
||||
homepage = "https://github.com/yuezk/GlobalProtect-openconnect"
|
||||
edition = "2021"
|
||||
|
||||
@@ -141,7 +141,7 @@ It is available via `guru` and `lamdness` overlays.
|
||||
```bash
|
||||
sudo eselect repository enable guru
|
||||
sudo emerge -r guru sync
|
||||
sudo emerge -av net-vpn/globalprotect-openconnect
|
||||
sudo emerge -av net-vpn/GlobalProtect-openconnect
|
||||
```
|
||||
|
||||
### Other distributions
|
||||
|
||||
@@ -44,6 +44,9 @@ pub(crate) struct ConnectArgs {
|
||||
#[arg(long, short, help = "The VPNC script to use")]
|
||||
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")]
|
||||
as_gateway: bool,
|
||||
|
||||
@@ -93,6 +96,9 @@ pub(crate) struct ConnectArgs {
|
||||
#[arg(long, help = "Disable DTLS and ESP")]
|
||||
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")]
|
||||
#[arg(long, help = "The HiDPI mode, useful for high-resolution screens")]
|
||||
hidpi: bool,
|
||||
@@ -313,6 +319,7 @@ impl<'a> ConnectHandler<'a> {
|
||||
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
||||
let vpn = Vpn::builder(gateway, cookie)
|
||||
.script(self.args.script.clone())
|
||||
.interface(self.args.interface.clone())
|
||||
.user_agent(self.args.user_agent.clone())
|
||||
.os(Some(os))
|
||||
.certificate(self.args.certificate.clone())
|
||||
@@ -324,6 +331,7 @@ impl<'a> ConnectHandler<'a> {
|
||||
.mtu(mtu)
|
||||
.disable_ipv6(self.args.disable_ipv6)
|
||||
.no_dtls(self.args.no_dtls)
|
||||
.dpd_interval(self.args.dpd_interval.unwrap_or(0))
|
||||
.build()?;
|
||||
|
||||
let vpn = Arc::new(vpn);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 2.4.5 - 2025-07-16
|
||||
|
||||
- GUI/CLI: fix the issue that the custom port is not supported issue (fix [#404](https://github.com/yuezk/GlobalProtect-openconnect/issues/404))
|
||||
- CLI: add the `--force-dpd` option to specify the interval for DPD (Dead Peer Detection).
|
||||
- CLI: add the `-i/--interface` option to specify the interface to use.
|
||||
|
||||
## 2.4.4 - 2025-02-09
|
||||
|
||||
- GUI: fix multiple tray icons issue (fix [#464](https://github.com/yuezk/GlobalProtect-openconnect/issues/464))
|
||||
|
||||
@@ -12,6 +12,7 @@ pub(crate) struct ConnectOptions {
|
||||
pub user_agent: *const c_char,
|
||||
|
||||
pub script: *const c_char,
|
||||
pub interface: *const c_char,
|
||||
pub os: *const c_char,
|
||||
pub certificate: *const c_char,
|
||||
pub sslkey: *const c_char,
|
||||
@@ -25,6 +26,8 @@ pub(crate) struct ConnectOptions {
|
||||
pub mtu: u32,
|
||||
pub disable_ipv6: u32,
|
||||
pub no_dtls: u32,
|
||||
|
||||
pub dpd_interval: u32,
|
||||
}
|
||||
|
||||
#[link(name = "vpn")]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <openconnect.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <openconnect.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "vpn.h"
|
||||
|
||||
@@ -11,143 +11,159 @@ void *g_user_data;
|
||||
|
||||
static int g_cmd_pipe_fd;
|
||||
static const char *g_vpnc_script;
|
||||
static const char *g_vpnc_interface;
|
||||
static vpn_connected_callback on_vpn_connected;
|
||||
|
||||
/* Validate the peer certificate */
|
||||
static int validate_peer_cert(__attribute__((unused)) void *_vpninfo, const char *reason)
|
||||
static int validate_peer_cert(__attribute__((unused)) void *_vpninfo,
|
||||
const char *reason)
|
||||
{
|
||||
INFO("Accepting the server certificate though %s", reason);
|
||||
return 0;
|
||||
INFO("Accepting the server certificate though %s", reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Print progress messages */
|
||||
static void print_progress(__attribute__((unused)) void *_vpninfo, int level, const char *format, ...)
|
||||
static void print_progress(__attribute__((unused)) void *_vpninfo, int level,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char *message = format_message(format, args);
|
||||
va_end(args);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char *message = format_message(format, args);
|
||||
va_end(args);
|
||||
|
||||
if (message == NULL) {
|
||||
ERROR("Failed to format log message");
|
||||
} else {
|
||||
LOG(level, message);
|
||||
free(message);
|
||||
}
|
||||
if (message == NULL) {
|
||||
ERROR("Failed to format log message");
|
||||
} else {
|
||||
LOG(level, message);
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_tun_handler(void *_vpninfo)
|
||||
{
|
||||
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script, NULL);
|
||||
if (!ret) {
|
||||
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
||||
}
|
||||
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script,
|
||||
g_vpnc_interface);
|
||||
if (!ret) {
|
||||
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize VPN connection */
|
||||
int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
{
|
||||
INFO("openconnect version: %s", openconnect_get_version());
|
||||
struct openconnect_info *vpninfo;
|
||||
struct utsname utsbuf;
|
||||
INFO("openconnect version: %s", openconnect_get_version());
|
||||
struct openconnect_info *vpninfo;
|
||||
struct utsname utsbuf;
|
||||
|
||||
g_user_data = options->user_data;
|
||||
g_vpnc_script = options->script;
|
||||
on_vpn_connected = callback;
|
||||
g_user_data = options->user_data;
|
||||
g_vpnc_script = options->script;
|
||||
g_vpnc_interface = options->interface;
|
||||
on_vpn_connected = callback;
|
||||
|
||||
INFO("User agent: %s", options->user_agent);
|
||||
INFO("VPNC script: %s", options->script);
|
||||
INFO("OS: %s", options->os);
|
||||
INFO("CSD_USER: %d", options->csd_uid);
|
||||
INFO("CSD_WRAPPER: %s", options->csd_wrapper);
|
||||
INFO("RECONNECT_TIMEOUT: %d", options->reconnect_timeout);
|
||||
INFO("MTU: %d", options->mtu);
|
||||
INFO("DISABLE_IPV6: %d", options->disable_ipv6);
|
||||
INFO("NO_DTLS: %d", options->no_dtls);
|
||||
INFO("User agent: %s", options->user_agent);
|
||||
INFO("VPNC script: %s", options->script);
|
||||
INFO("OS: %s", options->os);
|
||||
INFO("CSD_USER: %d", options->csd_uid);
|
||||
INFO("CSD_WRAPPER: %s", options->csd_wrapper);
|
||||
INFO("RECONNECT_TIMEOUT: %d", options->reconnect_timeout);
|
||||
INFO("MTU: %d", options->mtu);
|
||||
INFO("DISABLE_IPV6: %d", options->disable_ipv6);
|
||||
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);
|
||||
|
||||
if (!vpninfo) {
|
||||
ERROR("openconnect_vpninfo_new failed");
|
||||
return 1;
|
||||
}
|
||||
if (!vpninfo) {
|
||||
ERROR("openconnect_vpninfo_new failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
openconnect_set_loglevel(vpninfo, PRG_TRACE);
|
||||
openconnect_init_ssl();
|
||||
openconnect_set_protocol(vpninfo, "gp");
|
||||
openconnect_set_hostname(vpninfo, options->server);
|
||||
openconnect_set_cookie(vpninfo, options->cookie);
|
||||
openconnect_set_loglevel(vpninfo, PRG_TRACE);
|
||||
openconnect_init_ssl();
|
||||
openconnect_set_protocol(vpninfo, "gp");
|
||||
openconnect_parse_url(vpninfo, options->server);
|
||||
openconnect_set_cookie(vpninfo, options->cookie);
|
||||
|
||||
if (options->os) {
|
||||
openconnect_set_reported_os(vpninfo, options->os);
|
||||
}
|
||||
if (options->os) {
|
||||
openconnect_set_reported_os(vpninfo, options->os);
|
||||
}
|
||||
|
||||
if (options->certificate) {
|
||||
INFO("Setting client certificate: %s", options->certificate);
|
||||
openconnect_set_client_cert(vpninfo, options->certificate, options->sslkey);
|
||||
}
|
||||
if (options->certificate) {
|
||||
INFO("Setting client certificate: %s", options->certificate);
|
||||
openconnect_set_client_cert(vpninfo, options->certificate,
|
||||
options->sslkey);
|
||||
}
|
||||
|
||||
if (options->key_password) {
|
||||
openconnect_set_key_password(vpninfo, options->key_password);
|
||||
}
|
||||
if (options->key_password) {
|
||||
openconnect_set_key_password(vpninfo, options->key_password);
|
||||
}
|
||||
|
||||
if (options->csd_wrapper) {
|
||||
openconnect_setup_csd(vpninfo, options->csd_uid, 1, options->csd_wrapper);
|
||||
}
|
||||
if (options->csd_wrapper) {
|
||||
openconnect_setup_csd(vpninfo, options->csd_uid, 1,
|
||||
options->csd_wrapper);
|
||||
}
|
||||
|
||||
if (options->mtu > 0) {
|
||||
int mtu = options->mtu < 576 ? 576 : options->mtu;
|
||||
openconnect_set_reqmtu(vpninfo, mtu);
|
||||
}
|
||||
if (options->mtu > 0) {
|
||||
int mtu = options->mtu < 576 ? 576 : options->mtu;
|
||||
openconnect_set_reqmtu(vpninfo, mtu);
|
||||
}
|
||||
|
||||
if (options->disable_ipv6) {
|
||||
openconnect_disable_ipv6(vpninfo);
|
||||
}
|
||||
if (options->disable_ipv6) {
|
||||
openconnect_disable_ipv6(vpninfo);
|
||||
}
|
||||
|
||||
g_cmd_pipe_fd = openconnect_setup_cmd_pipe(vpninfo);
|
||||
if (g_cmd_pipe_fd < 0) {
|
||||
ERROR("openconnect_setup_cmd_pipe failed");
|
||||
return 1;
|
||||
}
|
||||
if (options->dpd_interval > 0) {
|
||||
openconnect_set_dpd(vpninfo, options->dpd_interval);
|
||||
}
|
||||
|
||||
if (!uname(&utsbuf)) {
|
||||
openconnect_set_localname(vpninfo, utsbuf.nodename);
|
||||
}
|
||||
g_cmd_pipe_fd = openconnect_setup_cmd_pipe(vpninfo);
|
||||
if (g_cmd_pipe_fd < 0) {
|
||||
ERROR("openconnect_setup_cmd_pipe failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Essential step
|
||||
if (openconnect_make_cstp_connection(vpninfo) != 0) {
|
||||
ERROR("openconnect_make_cstp_connection failed");
|
||||
return 1;
|
||||
}
|
||||
if (!uname(&utsbuf)) {
|
||||
openconnect_set_localname(vpninfo, utsbuf.nodename);
|
||||
}
|
||||
|
||||
if (options->no_dtls || openconnect_setup_dtls(vpninfo, 60) != 0) {
|
||||
openconnect_disable_dtls(vpninfo);
|
||||
}
|
||||
// Essential step
|
||||
if (openconnect_make_cstp_connection(vpninfo) != 0) {
|
||||
ERROR("openconnect_make_cstp_connection failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Essential step
|
||||
openconnect_set_setup_tun_handler(vpninfo, setup_tun_handler);
|
||||
if (options->no_dtls || openconnect_setup_dtls(vpninfo, 60) != 0) {
|
||||
openconnect_disable_dtls(vpninfo);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int ret = openconnect_mainloop(vpninfo, options->reconnect_timeout, 10);
|
||||
// Essential step
|
||||
openconnect_set_setup_tun_handler(vpninfo, setup_tun_handler);
|
||||
|
||||
if (ret) {
|
||||
INFO("openconnect_mainloop returned %d, exiting", ret);
|
||||
openconnect_vpninfo_free(vpninfo);
|
||||
return ret;
|
||||
}
|
||||
while (1) {
|
||||
int ret = openconnect_mainloop(vpninfo,
|
||||
options->reconnect_timeout, 10);
|
||||
|
||||
INFO("openconnect_mainloop returned 0, reconnecting");
|
||||
}
|
||||
if (ret) {
|
||||
INFO("openconnect_mainloop returned %d, exiting", ret);
|
||||
openconnect_vpninfo_free(vpninfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
INFO("openconnect_mainloop returned 0, reconnecting");
|
||||
}
|
||||
}
|
||||
|
||||
/* Stop the VPN connection */
|
||||
void vpn_disconnect()
|
||||
{
|
||||
char cmd = OC_CMD_CANCEL;
|
||||
char cmd = OC_CMD_CANCEL;
|
||||
|
||||
INFO("Stopping VPN connection: %d", g_cmd_pipe_fd);
|
||||
INFO("Stopping VPN connection: %d", g_cmd_pipe_fd);
|
||||
|
||||
if (write(g_cmd_pipe_fd, &cmd, 1) < 0) {
|
||||
ERROR("Failed to write to command pipe, VPN connection may not be stopped");
|
||||
}
|
||||
if (write(g_cmd_pipe_fd, &cmd, 1) < 0) {
|
||||
ERROR("Failed to write to command pipe, VPN connection may not "
|
||||
"be stopped");
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,33 @@
|
||||
#include <openconnect.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <openconnect.h>
|
||||
|
||||
typedef void (*vpn_connected_callback)(int cmd_pipe_fd, void *user_data);
|
||||
|
||||
typedef struct vpn_options
|
||||
{
|
||||
void *user_data;
|
||||
const char *server;
|
||||
const char *cookie;
|
||||
const char *user_agent;
|
||||
typedef struct vpn_options {
|
||||
void *user_data;
|
||||
const char *server;
|
||||
const char *cookie;
|
||||
const char *user_agent;
|
||||
|
||||
const char *script;
|
||||
const char *os;
|
||||
const char *certificate;
|
||||
const char *sslkey;
|
||||
const char *key_password;
|
||||
const char *servercert;
|
||||
const char *script;
|
||||
const char *interface;
|
||||
const char *os;
|
||||
const char *certificate;
|
||||
const char *sslkey;
|
||||
const char *key_password;
|
||||
const char *servercert;
|
||||
|
||||
const uid_t csd_uid;
|
||||
const char *csd_wrapper;
|
||||
const uid_t csd_uid;
|
||||
const char *csd_wrapper;
|
||||
|
||||
const int reconnect_timeout;
|
||||
const int mtu;
|
||||
const int disable_ipv6;
|
||||
const int no_dtls;
|
||||
const int reconnect_timeout;
|
||||
const int mtu;
|
||||
const int disable_ipv6;
|
||||
const int no_dtls;
|
||||
|
||||
const int dpd_interval;
|
||||
} vpn_options;
|
||||
|
||||
int vpn_connect(const vpn_options *options, vpn_connected_callback callback);
|
||||
@@ -35,40 +37,36 @@ extern void vpn_log(int level, const char *msg);
|
||||
|
||||
static char *format_message(const char *format, va_list args)
|
||||
{
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
int len = vsnprintf(NULL, 0, format, args_copy);
|
||||
va_end(args_copy);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
int len = vsnprintf(NULL, 0, format, args_copy);
|
||||
va_end(args_copy);
|
||||
|
||||
char *buffer = (char*)malloc(len + 1);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
char *buffer = (char *)malloc(len + 1);
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vsnprintf(buffer, len + 1, format, args);
|
||||
return buffer;
|
||||
vsnprintf(buffer, len + 1, format, args);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void _log(int level, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, level);
|
||||
va_list args;
|
||||
va_start(args, level);
|
||||
|
||||
char *format = va_arg(args, char *);
|
||||
char *message = format_message(format, args);
|
||||
char *format = va_arg(args, char *);
|
||||
char *message = format_message(format, args);
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
|
||||
if (message == NULL)
|
||||
{
|
||||
vpn_log(PRG_ERR, "Failed to format log message");
|
||||
}
|
||||
else
|
||||
{
|
||||
vpn_log(level, message);
|
||||
free(message);
|
||||
}
|
||||
if (message == NULL) {
|
||||
vpn_log(PRG_ERR, "Failed to format log message");
|
||||
} else {
|
||||
vpn_log(level, message);
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
|
||||
#define LOG(level, ...) _log(level, __VA_ARGS__)
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct Vpn {
|
||||
cookie: CString,
|
||||
user_agent: CString,
|
||||
script: CString,
|
||||
interface: Option<CString>,
|
||||
os: CString,
|
||||
certificate: Option<CString>,
|
||||
sslkey: Option<CString>,
|
||||
@@ -30,6 +31,8 @@ pub struct Vpn {
|
||||
disable_ipv6: bool,
|
||||
no_dtls: bool,
|
||||
|
||||
dpd_interval: u32,
|
||||
|
||||
callback: OnConnectedCallback,
|
||||
}
|
||||
|
||||
@@ -65,6 +68,7 @@ impl Vpn {
|
||||
cookie: self.cookie.as_ptr(),
|
||||
user_agent: self.user_agent.as_ptr(),
|
||||
script: self.script.as_ptr(),
|
||||
interface: Self::option_to_ptr(&self.interface),
|
||||
os: self.os.as_ptr(),
|
||||
|
||||
certificate: Self::option_to_ptr(&self.certificate),
|
||||
@@ -79,6 +83,7 @@ impl Vpn {
|
||||
mtu: self.mtu,
|
||||
disable_ipv6: self.disable_ipv6 as u32,
|
||||
no_dtls: self.no_dtls as u32,
|
||||
dpd_interval: self.dpd_interval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +118,7 @@ pub struct VpnBuilder {
|
||||
server: String,
|
||||
cookie: String,
|
||||
script: Option<String>,
|
||||
interface: Option<String>,
|
||||
|
||||
user_agent: Option<String>,
|
||||
os: Option<String>,
|
||||
@@ -128,6 +134,8 @@ pub struct VpnBuilder {
|
||||
mtu: u32,
|
||||
disable_ipv6: bool,
|
||||
no_dtls: bool,
|
||||
|
||||
dpd_interval: u32,
|
||||
}
|
||||
|
||||
impl VpnBuilder {
|
||||
@@ -136,6 +144,7 @@ impl VpnBuilder {
|
||||
server: server.to_string(),
|
||||
cookie: cookie.to_string(),
|
||||
script: None,
|
||||
interface: None,
|
||||
|
||||
user_agent: None,
|
||||
os: None,
|
||||
@@ -151,6 +160,7 @@ impl VpnBuilder {
|
||||
mtu: 0,
|
||||
disable_ipv6: false,
|
||||
no_dtls: false,
|
||||
dpd_interval: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +169,11 @@ impl VpnBuilder {
|
||||
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 {
|
||||
self.user_agent = user_agent.into();
|
||||
self
|
||||
@@ -214,6 +229,11 @@ impl VpnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn dpd_interval(mut self, dpd_interval: u32) -> Self {
|
||||
self.dpd_interval = dpd_interval;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<Vpn, VpnError> {
|
||||
let script = match self.script {
|
||||
Some(script) => {
|
||||
@@ -235,6 +255,7 @@ impl VpnBuilder {
|
||||
cookie: Self::to_cstring(&self.cookie),
|
||||
user_agent: Self::to_cstring(&user_agent),
|
||||
script: Self::to_cstring(&script),
|
||||
interface: self.interface.as_deref().map(Self::to_cstring),
|
||||
os: Self::to_cstring(&os),
|
||||
|
||||
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
||||
@@ -249,6 +270,7 @@ impl VpnBuilder {
|
||||
mtu: self.mtu,
|
||||
disable_ipv6: self.disable_ipv6,
|
||||
no_dtls: self.no_dtls,
|
||||
dpd_interval: self.dpd_interval,
|
||||
|
||||
callback: Default::default(),
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user