Euphoria lua codec support for windows/linux

This commit is contained in:
Mark Puha
2025-02-19 17:45:02 +01:00
parent c0b400c6df
commit 652c4fe783
19 changed files with 156 additions and 50 deletions

View File

@@ -57,6 +57,7 @@ enum wgdevice_attribute {
WGDEVICE_A_H2,
WGDEVICE_A_H3,
WGDEVICE_A_H4,
WGDEVICE_A_LUA_CODEC,
__WGDEVICE_A_LAST
};

View File

@@ -11,7 +11,7 @@ while read -r -d $'\t' device; do
if [[ $device != "$last_device" ]]; then
[[ -z $last_device ]] && printf '\n' || printf '%s,\n' "$end"
last_device="$device"
read -r private_key public_key listen_port jc jmin jmax s1 s2 h1 h2 h3 h4 fwmark
read -r private_key public_key listen_port jc jmin jmax s1 s2 h1 h2 h3 h4 lua_codec fwmark
printf '\t"%s": {' "$device"
delim=$'\n'
[[ $private_key == "(none)" ]] || { printf '%s\t\t"privateKey": "%s"' "$delim" "$private_key"; delim=$',\n'; }
@@ -26,6 +26,7 @@ while read -r -d $'\t' device; do
[[ $h2 == "2" ]] || { printf '%s\t\t"h2": %u' "$delim" $(( $h2 )); delim=$',\n'; }
[[ $h3 == "3" ]] || { printf '%s\t\t"h3": %u' "$delim" $(( $h3 )); delim=$',\n'; }
[[ $h4 == "4" ]] || { printf '%s\t\t"h4": %u' "$delim" $(( $h4 )); delim=$',\n'; }
[[ $lua_codec == "(none)" ]] || { printf '%s\t\t"lua_codec": "%s"' "$delim" "$lua_codec"; delim=$',\n'; }
[[ $fwmark == "off" ]] || { printf '%s\t\t"fwmark": %u' "$delim" $(( $fwmark )); delim=$',\n'; }
printf '%s\t\t"peers": {' "$delim"; end=$'\n\t\t}\n\t}'
delim=$'\n'

View File

@@ -260,4 +260,4 @@ int main(int argc, char *argv[])
}
cleanup_and_exit(EXIT_FAILURE);
}
}

View File

@@ -410,13 +410,29 @@ err:
return false;
}
static inline bool parse_string(char **device_value, const char *name, const char *value) {
size_t len = strlen(value);
if (!len) {
fprintf(stderr, "Unable to parse empty string for: %s\n", name);
return false;
}
if( len >= MAX_AWG_LUA_CODEC_LEN) {
fprintf(stderr, "Unable to process hex string longer than: %d\n", MAX_AWG_LUA_CODEC_LEN);
return false;
}
*device_value = strdup(value);
return true;
}
static inline bool parse_uint16(uint16_t *device_value, const char *name, const char *value) {
if (!strlen(value)) {
fprintf(stderr, "Unable to parse empty string\n");
return false;
}
char *end;
uint32_t ret;
ret = strtoul(value, &end, 10);
@@ -431,6 +447,7 @@ static inline bool parse_uint16(uint16_t *device_value, const char *name, const
static inline bool parse_uint32(uint32_t *device_value, const char *name, const char *value) {
if (!strlen(value)) {
fprintf(stderr, "Unable to parse empty string\n");
return false;
@@ -558,6 +575,10 @@ static bool process_line(struct config_ctx *ctx, const char *line)
ret = parse_uint32(&ctx->device->transport_packet_magic_header, "H4", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H4;
} else if (key_match("LuaCodec")) {
ret = parse_string(&ctx->device->lua_codec, "LuaCodec", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_LUA_CODEC;
} else
goto error;
} else if (ctx->is_peer_section) {
@@ -703,66 +724,73 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
} else if (!strcmp(argv[0], "jc") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_count, "jc", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_JC;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "jmin") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_min_size, "jmin", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_JMIN;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "jmax") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_max_size, "jmax", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_JMAX;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "s1") && argc >= 2 && !peer) {
if (!parse_uint16(&device->init_packet_junk_size, "s1", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_S1;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "s2") && argc >= 2 && !peer) {
if (!parse_uint16(&device->response_packet_junk_size, "s2", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_S2;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h1") && argc >= 2 && !peer) {
if (!parse_uint32(&device->init_packet_magic_header, "h1", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_H1;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h2") && argc >= 2 && !peer) {
if (!parse_uint32(&device->response_packet_magic_header, "h2", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_H2;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h3") && argc >= 2 && !peer) {
if (!parse_uint32(&device->underload_packet_magic_header, "h3", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_H3;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h4") && argc >= 2 && !peer) {
if (!parse_uint32(&device->transport_packet_magic_header, "h4", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_H4;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "lua_codec") && argc >= 2 && !peer) {
if (!parse_string(&device->lua_codec, "lua_codec", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_LUA_CODEC;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "peer") && argc >= 2) {
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));

View File

@@ -23,6 +23,8 @@
#define WG_KEY_LEN 32
#endif
#define MAX_AWG_LUA_CODEC_LEN 10 * 1024
/* Cross platform __kernel_timespec */
struct timespec64 {
int64_t tv_sec;
@@ -84,7 +86,8 @@ enum {
WGDEVICE_HAS_H1 = 1U << 10,
WGDEVICE_HAS_H2 = 1U << 11,
WGDEVICE_HAS_H3 = 1U << 12,
WGDEVICE_HAS_H4 = 1U << 13
WGDEVICE_HAS_H4 = 1U << 13,
WGDEVICE_HAS_LUA_CODEC = 1U << 14
};
struct wgdevice {
@@ -110,6 +113,7 @@ struct wgdevice {
uint32_t response_packet_magic_header;
uint32_t underload_packet_magic_header;
uint32_t transport_packet_magic_header;
char *lua_codec;
};
#define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer)

View File

@@ -4,7 +4,9 @@
*
*/
#include "containers.h"
#include <assert.h>
#include <cstring>
#include <sys/nv.h>
#include <sys/sockio.h>
#include <dev/wg/if_wg.h>
@@ -91,68 +93,75 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
dev->flags |= WGDEVICE_HAS_LISTEN_PORT;
}
}
if (nvlist_exists_number(nvl_device, "jc")) {
if (nvlist_exists_number(nvl_device, "jc")) {
number = nvlist_get_number(nvl_device, "jc");
if (number <= UINT16_MAX){
dev->junk_packet_count = number;
dev->flags |= WGDEVICE_HAS_JC;
}
}
if (nvlist_exists_number(nvl_device, "jmin")) {
if (nvlist_exists_number(nvl_device, "jmin")) {
number = nvlist_get_number(nvl_device, "jmin");
if (number <= UINT16_MAX){
dev->junk_packet_min_size = number;
dev->junk_packet_min_size = number;
dev->flags |= WGDEVICE_HAS_JMIN;
}
}
}
if (nvlist_exists_number(nvl_device, "jmax")) {
if (nvlist_exists_number(nvl_device, "jmax")) {
number = nvlist_get_number(nvl_device, "jmax");
if (number <= UINT16_MAX){
dev->junk_packet_max_size = number;
dev->junk_packet_max_size = number;
dev->flags |= WGDEVICE_HAS_JMAX;
}
}
}
if (nvlist_exists_number(nvl_device, "s1")) {
if (nvlist_exists_number(nvl_device, "s1")) {
number = nvlist_get_number(nvl_device, "s1");
if (number <= UINT16_MAX){
dev->init_packet_junk_size = number;
dev->init_packet_junk_size = number;
dev->flags |= WGDEVICE_HAS_S1;
}
}
}
if (nvlist_exists_number(nvl_device, "s2")) {
if (nvlist_exists_number(nvl_device, "s2")) {
number = nvlist_get_number(nvl_device, "s2");
if (number <= UINT16_MAX){
dev->response_packet_junk_size = number;
dev->response_packet_junk_size = number;
dev->flags |= WGDEVICE_HAS_S2;
}
}
}
if (nvlist_exists_number(nvl_device, "h1")) {
if (nvlist_exists_number(nvl_device, "h1")) {
number = nvlist_get_number(nvl_device, "h1");
if (number <= UINT32_MAX){
dev->init_packet_magic_header = number;
dev->init_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H1;
}
}
}
if (nvlist_exists_number(nvl_device, "h2")) {
if (nvlist_exists_number(nvl_device, "h2")) {
number = nvlist_get_number(nvl_device, "h2");
if (number <= UINT32_MAX){
dev->response_packet_magic_header = number;
dev->response_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H2;
}
}
}
if (nvlist_exists_number(nvl_device, "h3")) {
if (nvlist_exists_number(nvl_device, "h3")) {
number = nvlist_get_number(nvl_device, "h3");
if (number <= UINT32_MAX){
dev->underload_packet_magic_header = number;
dev->underload_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H3;
}
}
}
if (nvlist_exists_number(nvl_device, "h4")) {
if (nvlist_exists_number(nvl_device, "h4")) {
number = nvlist_get_number(nvl_device, "h4");
if (number <= UINT32_MAX){
dev->transport_packet_magic_header = number;
dev->transport_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H4;
}
}
}
if (nvlist_exists_binary(nvl_device, "lua_codec")) {
binary = nvlist_get_binary(nvl_device, "lua_codec", &size);
if (binary && size < MAX_AWG_LUA_CODEC_LEN) {
dev->lua_codec = strdup((const char*)binary);
dev->flags |= WGDEVICE_HAS_LUA_CODEC;
}
}
if (nvlist_exists_number(nvl_device, "user-cookie")) {
@@ -354,6 +363,8 @@ static int kernel_set_device(struct wgdevice *dev)
nvlist_add_number(nvl_device, "h3", dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
nvlist_add_number(nvl_device, "h4", dev->transport_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_LUA_CODEC)
nvlist_add_binary(nvl_device, "lua_codec", dev->lua_codec, strlen(dev->lua_codec) + 1);
if (dev->flags & WGDEVICE_HAS_FWMARK)
nvlist_add_number(nvl_device, "user-cookie", dev->fwmark);
if (dev->flags & WGDEVICE_REPLACE_PEERS)

View File

@@ -181,6 +181,8 @@ again:
mnl_attr_put_u32(nlh, WGDEVICE_A_H3, dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
mnl_attr_put_u32(nlh, WGDEVICE_A_H4, dev->transport_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_LUA_CODEC)
mnl_attr_put_strz(nlh, WGDEVICE_A_LUA_CODEC, dev->lua_codec);
if (dev->flags & WGDEVICE_HAS_FWMARK)
mnl_attr_put_u32(nlh, WGDEVICE_A_FWMARK, dev->fwmark);
if (dev->flags & WGDEVICE_REPLACE_PEERS)
@@ -537,6 +539,12 @@ static int parse_device(const struct nlattr *attr, void *data)
device->flags |= WGDEVICE_HAS_H4;
}
break;
case WGDEVICE_A_LUA_CODEC:
if (!mnl_attr_validate(attr, MNL_TYPE_STRING)) {
device->lua_codec = strdup(mnl_attr_get_str(attr));
device->flags |= WGDEVICE_HAS_LUA_CODEC;
}
break;
}
return MNL_CB_OK;

View File

@@ -154,7 +154,12 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->transport_packet_magic_header = wg_iface->i_transport_packet_magic_header;
dev->flags |= WGDEVICE_HAS_H4;
}
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_LUA_CODEC) {
dev->lua_codec = strdup(wg_iface->i_lua_codec);
dev->flags |= WGDEVICE_HAS_LUA_CODEC;
}
wg_peer = &wg_iface->i_peers[0];
for (size_t i = 0; i < wg_iface->i_peers_count; ++i) {
peer = calloc(1, sizeof(*peer));
@@ -312,6 +317,11 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H4;
}
if (dev->flags & WGDEVICE_HAS_LUA_CODEC) {
wg_iface->i_lua_codec = strdup(dev->lua_codec);
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_LUA_CODEC;
}
peer_count = 0;
wg_peer = &wg_iface->i_peers[0];
for_each_wgpeer(dev, peer) {

View File

@@ -69,6 +69,8 @@ static int userspace_set_device(struct wgdevice *dev)
fprintf(f, "h3=%u\n", dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
fprintf(f, "h4=%u\n", dev->transport_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_LUA_CODEC)
fprintf(f, "lua_codec=%s\n", dev->lua_codec);
for_each_wgpeer(dev, peer) {
key_to_hex(hex, peer->public_key);
@@ -192,6 +194,7 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
value = strchr(key, '=');
if (!value || line_len == 0 || key[line_len - 1] != '\n')
break;
*value++ = key[--line_len] = '\0';
if (!peer && !strcmp(key, "private_key")) {
@@ -232,6 +235,9 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
} else if(!peer && !strcmp(key, "h4")) {
dev->transport_packet_magic_header = NUM(0xffffffffU);
dev->flags |= WGDEVICE_HAS_H4;
} else if(!peer && !strcmp(key, "lua_codec")) {
dev->lua_codec = strdup(value);
dev->flags |= WGDEVICE_HAS_LUA_CODEC;
} else if (!strcmp(key, "public_key")) {
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));

View File

@@ -299,6 +299,12 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->transport_packet_magic_header = wg_iface->TransportPacketMagicHeader;
dev->flags |= WGDEVICE_HAS_H4;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_LUA_CODEC) {
const size_t lua_codec_size = strlen((char*)wg_iface->LuaCodec);
dev->lua_codec = (char*)malloc(lua_codec_size + 1);
memcpy(dev->lua_codec, wg_iface->LuaCodec, lua_codec_size + 1);
dev->flags |= WGDEVICE_HAS_LUA_CODEC;
}
wg_peer = buf + sizeof(WG_IOCTL_INTERFACE);
for (ULONG i = 0; i < wg_iface->PeersCount; ++i) {
@@ -467,6 +473,13 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->Flags |= WG_IOCTL_INTERFACE_H4;
}
if (dev->flags & WGDEVICE_HAS_LUA_CODEC) {
const size_t lua_codec_size = strlen(dev->lua_codec);
wg_iface->LuaCodec = (UCHAR*)malloc(lua_codec_size + 1);
memcpy(wg_iface->LuaCodec, dev->lua_codec, lua_codec_size + 1);
dev->flags |= WG_IOCTL_INTERFACE_LUA_CODEC ;
}
peer_count = 0;
wg_peer = (void *)wg_iface + sizeof(WG_IOCTL_INTERFACE);
for_each_wgpeer(dev, peer) {

View File

@@ -18,7 +18,7 @@ int set_main(int argc, const char *argv[])
int ret = 1;
if (argc < 3) {
fprintf(stderr, "Usage: %s %s <interface> [listen-port <port>] [fwmark <mark>] [private-key <file path>] [peer <base64 public key> [remove] [preshared-key <file path>] [endpoint <ip>:<port>] [persistent-keepalive <interval seconds>] [allowed-ips <ip1>/<cidr1>[,<ip2>/<cidr2>] [advanced-security <on|off>]...] ]...\n", PROG_NAME, argv[0]);
fprintf(stderr, "Usage: %s %s <interface> [listen-port <port>] [fwmark <mark>] [private-key <file path>] [jc <junk_count>] [jmin <min_value>] [jmax <max_value>] [s1 <init_junk>] [s2 <resp_junk>] [h1 <init_header>] [h2 <resp_header>] [h3 <cookie_header>] [h4 <transp_header>] [lua_codec <base64 lua code>] [peer <base64 public key> [remove] [preshared-key <file path>] [endpoint <ip>:<port>] [persistent-keepalive <interval seconds>] [allowed-ips <ip1>/<cidr1>[,<ip2>/<cidr2>] [advanced-security <on|off>]...] ]...\n", PROG_NAME, argv[0]);
return 1;
}

View File

@@ -202,7 +202,7 @@ static char *bytes(uint64_t b)
static const char *COMMAND_NAME;
static void show_usage(void)
{
fprintf(stderr, "Usage: %s %s { <interface> | all | interfaces } [public-key | private-key | listen-port | fwmark | peers | preshared-keys | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump]\n", PROG_NAME, COMMAND_NAME);
fprintf(stderr, "Usage: %s %s { <interface> | all | interfaces } [public-key | private-key | listen-port | fwmark | peers | preshared-keys | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump | jc | jmin | jmax | s1 | s2 | h1 | h2 | h3 | h4 | lua_codec]\n", PROG_NAME, COMMAND_NAME);
}
static void pretty_print(struct wgdevice *device)
@@ -238,6 +238,8 @@ static void pretty_print(struct wgdevice *device)
terminal_printf(" " TERMINAL_BOLD "h3" TERMINAL_RESET ": %u\n", device->underload_packet_magic_header);
if (device->transport_packet_magic_header)
terminal_printf(" " TERMINAL_BOLD "h4" TERMINAL_RESET ": %u\n", device->transport_packet_magic_header);
if (device->lua_codec)
terminal_printf(" " TERMINAL_BOLD "lua_codec" TERMINAL_RESET ": %s\n", device->lua_codec);
if (device->first_peer) {
sort_peers(device);
terminal_printf("\n");
@@ -287,6 +289,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("%u\t", device->response_packet_magic_header);
printf("%u\t", device->underload_packet_magic_header);
printf("%u\t", device->transport_packet_magic_header);
printf("%s\t", device->lua_codec);
if (device->fwmark)
printf("0x%x\n", device->fwmark);
else
@@ -374,6 +377,10 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
if (with_interface)
printf("%s\t", device->name);
printf("%u\n", device->transport_packet_magic_header);
} else if(!strcmp(param, "lua_codec")) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\n", device->lua_codec);
} else if (!strcmp(param, "endpoints")) {
for_each_wgpeer(device, peer) {
if (with_interface)

View File

@@ -64,6 +64,8 @@ int showconf_main(int argc, const char *argv[])
printf("H3 = %u\n", device->underload_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H4)
printf("H4 = %u\n", device->transport_packet_magic_header);
if (device->flags & WGDEVICE_HAS_LUA_CODEC)
printf("LuaCodec = %s\n", device->lua_codec);
printf("\n");
for_each_wgpeer(device, peer) {

View File

@@ -192,6 +192,7 @@ enum wgdevice_attribute {
WGDEVICE_A_H3,
WGDEVICE_A_H4,
WGDEVICE_A_PEER,
WGDEVICE_A_LUA_CODEC,
__WGDEVICE_A_LAST
};
#define WGDEVICE_A_MAX (__WGDEVICE_A_LAST - 1)

View File

@@ -81,6 +81,7 @@ struct wg_peer_io {
#define WG_INTERFACE_DEVICE_HAS_H2 (1 << 11)
#define WG_INTERFACE_DEVICE_HAS_H3 (1 << 12)
#define WG_INTERFACE_DEVICE_HAS_H4 (1 << 13)
#define WG_INTERFACE_DEVICE_HAS_LUA_CODEC (1 << 14)
struct wg_interface_io {
uint16_t i_flags;
@@ -100,6 +101,7 @@ struct wg_interface_io {
uint32_t i_response_packet_magic_header;
uint32_t i_underload_packet_magic_header;
uint32_t i_transport_packet_magic_header;
uint8_t *i_lua_codec;
};
struct wg_data_io {

View File

@@ -66,7 +66,8 @@ typedef enum
WG_IOCTL_INTERFACE_H1 = 1 << 10,
WG_IOCTL_INTERFACE_H2 = 1 << 11,
WG_IOCTL_INTERFACE_H3 = 1 << 12,
WG_IOCTL_INTERFACE_H4 = 1 << 13
WG_IOCTL_INTERFACE_H4 = 1 << 13,
WG_IOCTL_INTERFACE_LUA_CODEC = 1 << 14
} WG_IOCTL_INTERFACE_FLAG;
typedef struct _WG_IOCTL_INTERFACE
@@ -85,6 +86,7 @@ typedef struct _WG_IOCTL_INTERFACE
ULONG ResponsePacketMagicHeader;
ULONG UnderloadPacketMagicHeader;
ULONG TransportPacketMagicHeader;
UCHAR *LuaCodec;
} __attribute__((aligned(8))) WG_IOCTL_INTERFACE;
#define WG_IOCTL_GET CTL_CODE(45208U, 321, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)

View File

@@ -42,6 +42,7 @@ static bool is_exiting = false;
static bool binder_available = false;
static unsigned int sdk_version;
static bool is_asecurity_on = false;
static bool is_lua_encode_on = false;
static void *xmalloc(size_t size)
{
@@ -633,7 +634,7 @@ static void auto_su(int argc, char *argv[])
static void add_if(const char *iface)
{
if (is_asecurity_on)
if (is_asecurity_on || is_lua_encode_on)
cmd("amneziawg-go %s", iface);
else
cmd("ip link add %s type amneziawg", iface);
@@ -1278,6 +1279,8 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
is_asecurity_on = true;
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
is_asecurity_on = true;
} else if (!strncasecmp(clean, "LuaCodec=", 9) && j > 4) {
is_lua_encode_on = true;
}
}
*config = concat_and_free(*config, "", line);
@@ -1322,4 +1325,4 @@ int main(int argc, char *argv[])
return 1;
}
return 0;
}
}

View File

@@ -107,7 +107,10 @@ parse_options() {
H1);&
H2);&
H3);&
H4) IS_ASESCURITY_ON=1;;
H4)IS_ASESCURITY_ON=1;;
esac
case "$key" in
LuaCodec)IS_LUA_ENCODE_ON=1;;
esac
fi
WG_CONFIG+="$line"$'\n'
@@ -501,4 +504,4 @@ else
exit 1
fi
exit 0
exit 0

View File

@@ -28,6 +28,7 @@ CONFIG_FILE=""
PROGRAM="${0##*/}"
ARGS=( "$@" )
IS_ASESCURITY_ON=0
IS_LUA_ENCODE_ON=0
cmd() {
echo "[#] $*" >&3
@@ -78,8 +79,11 @@ parse_options() {
H1);&
H2);&
H3);&
H4) IS_ASESCURITY_ON=1;;
H4)IS_ASESCURITY_ON=1;;
esac
case "$key" in
LuaCodec)IS_LUA_ENCODE_ON=1;;
esac
fi
WG_CONFIG+="$line"$'\n'
done < "$CONFIG_FILE"
@@ -118,8 +122,8 @@ add_if() {
while true; do
local -A existing_ifs="( $(wg show interfaces | sed 's/\([^ ]*\)/[\1]=1/g') )"
local index ret
if [[ $IS_ASESCURITY_ON == 1 ]]; then
cmd "amneziawg-go "$INTERFACE"";
if [[ $IS_ASESCURITY_ON -eq 1 || $IS_LUA_ENCODE_ON -eq 1 ]]; then
cmd "amneziawg-go \"$INTERFACE\"";
return $?
else
for ((index=0; index <= 2147483647; ++index)); do [[ -v existing_ifs[wg$index] ]] || break; done
@@ -495,4 +499,4 @@ else
exit 1
fi
exit 0
exit 0