From 4b25e43d6722ff7cfe67eb74a5f31d8acee9c26b Mon Sep 17 00:00:00 2001
From: Mark Puha
Date: Fri, 18 Jul 2025 04:50:40 +0200
Subject: [PATCH] feat: ranged magic header
---
contrib/json/wg-json | 8 +++----
src/config.c | 16 ++++++-------
src/containers.h | 8 +++----
src/ipc-freebsd.h | 36 ++++++++++++++++-------------
src/ipc-linux.h | 16 ++++++-------
src/ipc-openbsd.h | 16 ++++++-------
src/ipc-uapi.h | 16 ++++++-------
src/ipc-windows.h | 32 ++++++++++++++++++-------
src/show.c | 24 +++++++++----------
src/showconf.c | 8 +++----
src/uapi/openbsd/net/if_wg.h | 8 +++----
src/uapi/windows/wireguard.h | 8 +++----
src/wg-quick/android.c | 45 ++++++++++++++++++------------------
src/wg-quick/freebsd.bash | 19 +++++++++++----
src/wg-quick/openbsd.bash | 19 +++++++++++----
15 files changed, 160 insertions(+), 119 deletions(-)
diff --git a/contrib/json/wg-json b/contrib/json/wg-json
index 971f199..3778b1d 100755
--- a/contrib/json/wg-json
+++ b/contrib/json/wg-json
@@ -24,10 +24,10 @@ while read -r -d $'\t' device; do
[[ $s2 == "0" ]] || { printf '%s\t\t"s2": %u' "$delim" $(( $s2 )); delim=$',\n'; }
[[ $s3 == "0" ]] || { printf '%s\t\t"s3": %u' "$delim" $(( $s3 )); delim=$',\n'; }
[[ $s4 == "0" ]] || { printf '%s\t\t"s4": %u' "$delim" $(( $s4 )); delim=$',\n'; }
- [[ $h1 == "1" ]] || { printf '%s\t\t"h1": %u' "$delim" $(( $h1 )); delim=$',\n'; }
- [[ $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'; }
+ [[ $h1 == "1" ]] || { printf '%s\t\t"h1": %s' "$delim" $(( $h1 )); delim=$',\n'; }
+ [[ $h2 == "2" ]] || { printf '%s\t\t"h2": %s' "$delim" $(( $h2 )); delim=$',\n'; }
+ [[ $h3 == "3" ]] || { printf '%s\t\t"h3": %s' "$delim" $(( $h3 )); delim=$',\n'; }
+ [[ $h4 == "4" ]] || { printf '%s\t\t"h4": %s' "$delim" $(( $h4 )); delim=$',\n'; }
[[ $i1 == "(none)" ]] || { printf '%s\t\t"i1": "%s"' "$delim" "$i1"; delim=$',\n'; }
[[ $i2 == "(none)" ]] || { printf '%s\t\t"i2": "%s"' "$delim" "$i2"; delim=$',\n'; }
[[ $i3 == "(none)" ]] || { printf '%s\t\t"i3": "%s"' "$delim" "$i3"; delim=$',\n'; }
diff --git a/src/config.c b/src/config.c
index c5cfb89..6aa31b0 100644
--- a/src/config.c
+++ b/src/config.c
@@ -575,19 +575,19 @@ static bool process_line(struct config_ctx *ctx, const char *line)
if (ret)
ctx->device->flags |= WGDEVICE_HAS_S4;
} else if (key_match("H1")) {
- ret = parse_uint32(&ctx->device->init_packet_magic_header, "H1", value);
+ ret = parse_awg_string(&ctx->device->init_packet_magic_header, "H1", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H1;
} else if (key_match("H2")) {
- ret = parse_uint32(&ctx->device->response_packet_magic_header, "H2", value);
+ ret = parse_awg_string(&ctx->device->response_packet_magic_header, "H2", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H2;
} else if (key_match("H3")) {
- ret = parse_uint32(&ctx->device->underload_packet_magic_header, "H3", value);
+ ret = parse_awg_string(&ctx->device->underload_packet_magic_header, "H3", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H3;
} else if (key_match("H4")) {
- ret = parse_uint32(&ctx->device->transport_packet_magic_header, "H4", value);
+ ret = parse_awg_string(&ctx->device->transport_packet_magic_header, "H4", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H4;
} else if (key_match("I1")) {
@@ -876,28 +876,28 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h1") && argc >= 2 && !peer) {
- if (!parse_uint32(&device->init_packet_magic_header, "h1", argv[1]))
+ if (!parse_awg_string(&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]))
+ if (!parse_awg_string(&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]))
+ if (!parse_awg_string(&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]))
+ if (!parse_awg_string(&device->transport_packet_magic_header, "h4", argv[1]))
goto error;
device->flags |= WGDEVICE_HAS_H4;
diff --git a/src/containers.h b/src/containers.h
index 09ff619..21f22a0 100644
--- a/src/containers.h
+++ b/src/containers.h
@@ -125,10 +125,10 @@ struct wgdevice {
uint16_t response_packet_junk_size;
uint16_t cookie_reply_packet_junk_size;
uint16_t transport_packet_junk_size;
- uint32_t init_packet_magic_header;
- uint32_t response_packet_magic_header;
- uint32_t underload_packet_magic_header;
- uint32_t transport_packet_magic_header;
+ char* init_packet_magic_header;
+ char* response_packet_magic_header;
+ char* underload_packet_magic_header;
+ char* transport_packet_magic_header;
char* i1;
char* i2;
char* i3;
diff --git a/src/ipc-freebsd.h b/src/ipc-freebsd.h
index 206ebcd..5773937 100644
--- a/src/ipc-freebsd.h
+++ b/src/ipc-freebsd.h
@@ -141,30 +141,34 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
}
}
if (nvlist_exists_number(nvl_device, "h1")) {
- number = nvlist_get_number(nvl_device, "h1");
- if (number <= UINT32_MAX){
- dev->init_packet_magic_header = number;
+ binary = nvlist_get_binary(nvl_device, "h1", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->init_packet_magic_header = strdup((const char*)binary);
dev->flags |= WGDEVICE_HAS_H1;
}
}
if (nvlist_exists_number(nvl_device, "h2")) {
- number = nvlist_get_number(nvl_device, "h2");
- if (number <= UINT32_MAX){
- dev->response_packet_magic_header = number;
+ binary = nvlist_get_binary(nvl_device, "h2", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->response_packet_magic_header = strdup((const char*)binary);
dev->flags |= WGDEVICE_HAS_H2;
}
}
if (nvlist_exists_number(nvl_device, "h3")) {
- number = nvlist_get_number(nvl_device, "h3");
- if (number <= UINT32_MAX){
- dev->underload_packet_magic_header = number;
+ binary = nvlist_get_binary(nvl_device, "h3", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->underload_packet_magic_header = strdup((const char*)binary);
dev->flags |= WGDEVICE_HAS_H3;
}
}
if (nvlist_exists_number(nvl_device, "h4")) {
- number = nvlist_get_number(nvl_device, "h4");
- if (number <= UINT32_MAX){
- dev->transport_packet_magic_header = number;
+ binary = nvlist_get_binary(nvl_device, "h4", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->transport_packet_magic_header = strdup((const char*)binary);
dev->flags |= WGDEVICE_HAS_H4;
}
}
@@ -446,13 +450,13 @@ static int kernel_set_device(struct wgdevice *dev)
if (dev->flags & WGDEVICE_HAS_S4)
nvlist_add_number(nvl_device, "s4", dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
- nvlist_add_number(nvl_device, "h1", dev->init_packet_magic_header);
+ nvlist_add_binary(nvl_device, "h1", dev->init_packet_magic_header, strlen(dev->h1) + 1);
if (dev->flags & WGDEVICE_HAS_H2)
- nvlist_add_number(nvl_device, "h2", dev->response_packet_magic_header);
+ nvlist_add_binary(nvl_device, "h2", dev->response_packet_magic_header, strlen(dev->h2) + 1);
if (dev->flags & WGDEVICE_HAS_H3)
- nvlist_add_number(nvl_device, "h3", dev->underload_packet_magic_header);
+ nvlist_add_binary(nvl_device, "h3", dev->underload_packet_magic_header, strlen(dev->h3) + 1);
if (dev->flags & WGDEVICE_HAS_H4)
- nvlist_add_number(nvl_device, "h4", dev->transport_packet_magic_header);
+ nvlist_add_binary(nvl_device, "h4", dev->transport_packet_magic_header, strlen(dev->h4) + 1);
if (dev->flags & WGDEVICE_HAS_I1)
nvlist_add_binary(nvl_device, "i1", dev->i1, strlen(dev->i1) + 1);
if (dev->flags & WGDEVICE_HAS_I2)
diff --git a/src/ipc-linux.h b/src/ipc-linux.h
index 8c082a3..09bf48a 100644
--- a/src/ipc-linux.h
+++ b/src/ipc-linux.h
@@ -178,13 +178,13 @@ again:
if (dev->flags & WGDEVICE_HAS_S4)
mnl_attr_put_u16(nlh, WGDEVICE_A_S4, dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
- mnl_attr_put_u32(nlh, WGDEVICE_A_H1, dev->init_packet_magic_header);
+ mnl_attr_put_strz(nlh, WGDEVICE_A_H1, dev->init_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H2)
- mnl_attr_put_u32(nlh, WGDEVICE_A_H2, dev->response_packet_magic_header);
+ mnl_attr_put_strz(nlh, WGDEVICE_A_H2, dev->response_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H3)
- mnl_attr_put_u32(nlh, WGDEVICE_A_H3, dev->underload_packet_magic_header);
+ mnl_attr_put_strz(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);
+ mnl_attr_put_strz(nlh, WGDEVICE_A_H4, dev->transport_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_I1)
mnl_attr_put_strz(nlh, WGDEVICE_A_I1, dev->i1);
if (dev->flags & WGDEVICE_HAS_I2)
@@ -574,25 +574,25 @@ static int parse_device(const struct nlattr *attr, void *data)
break;
case WGDEVICE_A_H1:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
- device->init_packet_magic_header = mnl_attr_get_u32(attr);
+ device->init_packet_magic_header = strdup(mnl_attr_get_str(attr));
device->flags |= WGDEVICE_HAS_H1;
}
break;
case WGDEVICE_A_H2:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
- device->response_packet_magic_header = mnl_attr_get_u32(attr);
+ device->response_packet_magic_header = strdup(mnl_attr_get_str(attr));
device->flags |= WGDEVICE_HAS_H2;
}
break;
case WGDEVICE_A_H3:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
- device->underload_packet_magic_header = mnl_attr_get_u32(attr);
+ device->underload_packet_magic_header = strdup(mnl_attr_get_str(attr));
device->flags |= WGDEVICE_HAS_H3;
}
break;
case WGDEVICE_A_H4:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
- device->transport_packet_magic_header = mnl_attr_get_u32(attr);
+ device->transport_packet_magic_header = strdup(mnl_attr_get_str(attr));
device->flags |= WGDEVICE_HAS_H4;
}
break;
diff --git a/src/ipc-openbsd.h b/src/ipc-openbsd.h
index 61bac7f..383de9b 100644
--- a/src/ipc-openbsd.h
+++ b/src/ipc-openbsd.h
@@ -146,22 +146,22 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
}
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H1) {
- dev->init_packet_magic_header = wg_iface->i_init_packet_magic_header;
+ dev->init_packet_magic_header = strdup(wg_iface->i_init_packet_magic_header);
dev->flags |= WGDEVICE_HAS_H1;
}
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H2) {
- dev->response_packet_magic_header = wg_iface->i_response_packet_magic_header;
+ dev->response_packet_magic_header = strdup(wg_iface->i_response_packet_magic_header);
dev->flags |= WGDEVICE_HAS_H2;
}
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H3) {
- dev->underload_packet_magic_header = wg_iface->i_underload_packet_magic_header;
+ dev->underload_packet_magic_header = strdup(wg_iface->i_underload_packet_magic_header);
dev->flags |= WGDEVICE_HAS_H3;
}
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H4) {
- dev->transport_packet_magic_header = wg_iface->i_transport_packet_magic_header;
+ dev->transport_packet_magic_header = strdup(wg_iface->i_transport_packet_magic_header);
dev->flags |= WGDEVICE_HAS_H4;
}
@@ -367,22 +367,22 @@ static int kernel_set_device(struct wgdevice *dev)
}
if (dev->flags & WGDEVICE_HAS_H1) {
- wg_iface->i_init_packet_magic_header = dev->init_packet_magic_header;
+ wg_iface->i_init_packet_magic_header = strdup(dev->init_packet_magic_header);
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H1;
}
if (dev->flags & WGDEVICE_HAS_H2) {
- wg_iface->i_response_packet_magic_header = dev->response_packet_magic_header;
+ wg_iface->i_response_packet_magic_header = strdup(dev->response_packet_magic_header);
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H2;
}
if (dev->flags & WGDEVICE_HAS_H3) {
- wg_iface->i_underload_packet_magic_header = dev->underload_packet_magic_header;
+ wg_iface->i_underload_packet_magic_header = strdup(dev->underload_packet_magic_header);
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H3;
}
if (dev->flags & WGDEVICE_HAS_H4) {
- wg_iface->i_transport_packet_magic_header = dev->transport_packet_magic_header;
+ wg_iface->i_transport_packet_magic_header = strdup(dev->transport_packet_magic_header);
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H4;
}
diff --git a/src/ipc-uapi.h b/src/ipc-uapi.h
index 32be0d8..74640a6 100644
--- a/src/ipc-uapi.h
+++ b/src/ipc-uapi.h
@@ -66,13 +66,13 @@ static int userspace_set_device(struct wgdevice *dev)
if (dev->flags & WGDEVICE_HAS_S4)
fprintf(f, "s4=%u\n", dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
- fprintf(f, "h1=%u\n", dev->init_packet_magic_header);
+ fprintf(f, "h1=%s\n", dev->init_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H2)
- fprintf(f, "h2=%u\n", dev->response_packet_magic_header);
+ fprintf(f, "h2=%s\n", dev->response_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H3)
- fprintf(f, "h3=%u\n", dev->underload_packet_magic_header);
+ fprintf(f, "h3=%s\n", dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
- fprintf(f, "h4=%u\n", dev->transport_packet_magic_header);
+ fprintf(f, "h4=%s\n", dev->transport_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_I1)
fprintf(f, "i1=%s\n", dev->i1);
@@ -255,16 +255,16 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
dev->transport_packet_junk_size = NUM(0xffffU);
dev->flags |= WGDEVICE_HAS_S4;
} else if(!peer && !strcmp(key, "h1")) {
- dev->init_packet_magic_header = NUM(0xffffffffU);
+ dev->init_packet_magic_header = strdup(value);
dev->flags |= WGDEVICE_HAS_H1;
} else if(!peer && !strcmp(key, "h2")) {
- dev->response_packet_magic_header = NUM(0xffffffffU);
+ dev->response_packet_magic_header = strdup(value);
dev->flags |= WGDEVICE_HAS_H2;
} else if(!peer && !strcmp(key, "h3")) {
- dev->underload_packet_magic_header = NUM(0xffffffffU);
+ dev->underload_packet_magic_header = strdup(value);
dev->flags |= WGDEVICE_HAS_H3;
} else if(!peer && !strcmp(key, "h4")) {
- dev->transport_packet_magic_header = NUM(0xffffffffU);
+ dev->transport_packet_magic_header = strdup(value);
dev->flags |= WGDEVICE_HAS_H4;
} else if (!peer && !strcmp(key, "i1")) {
dev->i1 = strdup(value);
diff --git a/src/ipc-windows.h b/src/ipc-windows.h
index 3756a52..cddadd4 100644
--- a/src/ipc-windows.h
+++ b/src/ipc-windows.h
@@ -292,19 +292,27 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->flags |= WGDEVICE_HAS_S4;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H1) {
- dev->init_packet_magic_header = wg_iface->InitPacketMagicHeader;
+ const size_t init_size = strlen((char*)wg_iface->InitPacketMagicHeader) + 1;
+ dev->init_packet_magic_header = (char*)malloc(init_size);
+ memcpy(dev->init_packet_magic_header, wg_iface->InitPacketMagicHeader, init_size);
dev->flags |= WGDEVICE_HAS_H1;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H2) {
- dev->response_packet_magic_header = wg_iface->ResponsePacketMagicHeader;
+ const size_t response_size = strlen((char*)wg_iface->ResponsePacketMagicHeader) + 1;
+ dev->response_packet_magic_header = (char*)malloc(response_size);
+ memcpy(dev->response_packet_magic_header, wg_iface->ResponsePacketMagicHeader, response_size);
dev->flags |= WGDEVICE_HAS_H2;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H3) {
- dev->underload_packet_magic_header = wg_iface->UnderloadPacketMagicHeader;
+ const size_t underload_size = strlen((char*)wg_iface->UnderloadPacketMagicHeader) + 1;
+ dev->underload_packet_magic_header = (char*)malloc(underload_size);
+ memcpy(dev->underload_packet_magic_header, wg_iface->UnderloadPacketMagicHeader, underload_size);
dev->flags |= WGDEVICE_HAS_H3;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H4) {
- dev->transport_packet_magic_header = wg_iface->TransportPacketMagicHeader;
+ const size_t transport_size = strlen((char*)wg_iface->TransportPacketMagicHeader) + 1;
+ dev->transport_packet_magic_header = (char*)malloc(transport_size);
+ memcpy(dev->transport_packet_magic_header, wg_iface->TransportPacketMagicHeader, transport_size);
dev->flags |= WGDEVICE_HAS_H4;
}
if (wg_iface->Flags & WG_IOCTL_INTERFACE_I1) {
@@ -516,22 +524,30 @@ static int kernel_set_device(struct wgdevice *dev)
}
if (dev->flags & WGDEVICE_HAS_H1) {
- wg_iface->InitPacketMagicHeader = dev->init_packet_magic_header;
+ const size_t init_size = strlen(dev->init_packet_magic_header) + 1;
+ wg_iface->InitPacketMagicHeader = (char*)init_size;
+ memcpy(wg_iface->InitPacketMagicHeader, dev->init_packet_magic_header, init_size);
wg_iface->Flags |= WG_IOCTL_INTERFACE_H1;
}
if (dev->flags & WGDEVICE_HAS_H2) {
- wg_iface->ResponsePacketMagicHeader = dev->response_packet_magic_header;
+ const size_t response_size = strlen(dev->response_packet_magic_header) + 1;
+ wg_iface->ResponsePacketMagicHeader = (char*)response_size;
+ memcpy(wg_iface->ResponsePacketMagicHeader, dev->response_packet_magic_header, response_size);
wg_iface->Flags |= WG_IOCTL_INTERFACE_H2;
}
if (dev->flags & WGDEVICE_HAS_H3) {
- wg_iface->UnderloadPacketMagicHeader = dev->underload_packet_magic_header;
+ const size_t underload_size = strlen(dev->underload_packet_magic_header) + 1;
+ wg_iface->UnderloadPacketMagicHeader = (char*)underload_size;
+ memcpy(wg_iface->UnderloadPacketMagicHeader, dev->underload_packet_magic_header, underload_size);
wg_iface->Flags |= WG_IOCTL_INTERFACE_H3;
}
if (dev->flags & WGDEVICE_HAS_H4) {
- wg_iface->TransportPacketMagicHeader = dev->transport_packet_magic_header;
+ const size_t transport_size = strlen(dev->transport_packet_magic_header) + 1;
+ wg_iface->TransportPacketMagicHeader = (char*)transport_size;
+ memcpy(wg_iface->TransportPacketMagicHeader, dev->transport_packet_magic_header, transport_size);
wg_iface->Flags |= WG_IOCTL_INTERFACE_H4;
}
diff --git a/src/show.c b/src/show.c
index 93e1b03..dbecafb 100644
--- a/src/show.c
+++ b/src/show.c
@@ -235,13 +235,13 @@ static void pretty_print(struct wgdevice *device)
if (device->transport_packet_junk_size)
terminal_printf(" " TERMINAL_BOLD "s4" TERMINAL_RESET ": %u\n", device->transport_packet_junk_size);
if (device->init_packet_magic_header)
- terminal_printf(" " TERMINAL_BOLD "h1" TERMINAL_RESET ": %u\n", device->init_packet_magic_header);
+ terminal_printf(" " TERMINAL_BOLD "h1" TERMINAL_RESET ": %s\n", device->init_packet_magic_header);
if (device->response_packet_magic_header)
- terminal_printf(" " TERMINAL_BOLD "h2" TERMINAL_RESET ": %u\n", device->response_packet_magic_header);
+ terminal_printf(" " TERMINAL_BOLD "h2" TERMINAL_RESET ": %s\n", device->response_packet_magic_header);
if (device->underload_packet_magic_header)
- terminal_printf(" " TERMINAL_BOLD "h3" TERMINAL_RESET ": %u\n", device->underload_packet_magic_header);
+ terminal_printf(" " TERMINAL_BOLD "h3" TERMINAL_RESET ": %s\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);
+ terminal_printf(" " TERMINAL_BOLD "h4" TERMINAL_RESET ": %s\n", device->transport_packet_magic_header);
if (device->i1)
terminal_printf(" " TERMINAL_BOLD "i1" TERMINAL_RESET ": %s\n", device->i1);
if (device->i2)
@@ -308,10 +308,10 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("%u\t", device->response_packet_junk_size);
printf("%u\t", device->cookie_reply_packet_junk_size);
printf("%u\t", device->transport_packet_junk_size);
- printf("%u\t", device->init_packet_magic_header);
- 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->init_packet_magic_header);
+ printf("%s\t", device->response_packet_magic_header);
+ printf("%s\t", device->underload_packet_magic_header);
+ printf("%s\t", device->transport_packet_magic_header);
printf("%s\t", device->i1);
printf("%s\t", device->i2);
printf("%s\t", device->i3);
@@ -404,19 +404,19 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
} else if(!strcmp(param, "h1")) {
if (with_interface)
printf("%s\t", device->name);
- printf("%u\n", device->init_packet_magic_header);
+ printf("%s\n", device->init_packet_magic_header);
} else if(!strcmp(param, "h2")) {
if (with_interface)
printf("%s\t", device->name);
- printf("%u\n", device->response_packet_magic_header);
+ printf("%s\n", device->response_packet_magic_header);
} else if(!strcmp(param, "h3")) {
if (with_interface)
printf("%s\t", device->name);
- printf("%u\n", device->underload_packet_magic_header);
+ printf("%s\n", device->underload_packet_magic_header);
} else if(!strcmp(param, "h4")) {
if (with_interface)
printf("%s\t", device->name);
- printf("%u\n", device->transport_packet_magic_header);
+ printf("%s\n", device->transport_packet_magic_header);
} else if(!strcmp(param, "i1")) {
if (with_interface)
printf("%s\t", device->name);
diff --git a/src/showconf.c b/src/showconf.c
index b049f6e..11952cb 100644
--- a/src/showconf.c
+++ b/src/showconf.c
@@ -61,13 +61,13 @@ int showconf_main(int argc, const char *argv[])
if (device->flags & WGDEVICE_HAS_S4)
printf("S4 = %u\n", device->transport_packet_junk_size);
if (device->flags & WGDEVICE_HAS_H1)
- printf("H1 = %u\n", device->init_packet_magic_header);
+ printf("H1 = %s\n", device->init_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H2)
- printf("H2 = %u\n", device->response_packet_magic_header);
+ printf("H2 = %s\n", device->response_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H3)
- printf("H3 = %u\n", device->underload_packet_magic_header);
+ printf("H3 = %s\n", device->underload_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H4)
- printf("H4 = %u\n", device->transport_packet_magic_header);
+ printf("H4 = %s\n", device->transport_packet_magic_header);
if (device->flags & WGDEVICE_HAS_I1)
printf("I1 = %s\n", device->i1);
if (device->flags & WGDEVICE_HAS_I2)
diff --git a/src/uapi/openbsd/net/if_wg.h b/src/uapi/openbsd/net/if_wg.h
index 1f30572..5a8c94d 100644
--- a/src/uapi/openbsd/net/if_wg.h
+++ b/src/uapi/openbsd/net/if_wg.h
@@ -109,10 +109,10 @@ struct wg_interface_io {
uint16_t i_response_packet_junk_size;
uint16_t i_cookie_reply_packet_junk_size;
uint16_t i_transport_packet_junk_size;
- uint32_t i_init_packet_magic_header;
- uint32_t i_response_packet_magic_header;
- uint32_t i_underload_packet_magic_header;
- uint32_t i_transport_packet_magic_header;
+ uint8_t* i_init_packet_magic_header;
+ uint8_t* i_response_packet_magic_header;
+ uint8_t* i_underload_packet_magic_header;
+ uint8_t* i_transport_packet_magic_header;
uint8_t* i_i1;
uint8_t* i_i2;
diff --git a/src/uapi/windows/wireguard.h b/src/uapi/windows/wireguard.h
index a076b46..0ddcde6 100644
--- a/src/uapi/windows/wireguard.h
+++ b/src/uapi/windows/wireguard.h
@@ -94,10 +94,10 @@ typedef struct _WG_IOCTL_INTERFACE
USHORT ResponsePacketJunkSize;
USHORT CookieReplyPacketJunkSize;
USHORT TransportPacketJunkSize;
- ULONG InitPacketMagicHeader;
- ULONG ResponsePacketMagicHeader;
- ULONG UnderloadPacketMagicHeader;
- ULONG TransportPacketMagicHeader;
+ UCHAR* InitPacketMagicHeader;
+ UCHAR* ResponsePacketMagicHeader;
+ UCHAR* UnderloadPacketMagicHeader;
+ UCHAR* TransportPacketMagicHeader;
UCHAR* I1;
UCHAR* I2;
diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
index dd3a340..e2d9f67 100644
--- a/src/wg-quick/android.c
+++ b/src/wg-quick/android.c
@@ -41,8 +41,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_special_handshake_on = false;
+static bool is_awg_on = false;
static void *xmalloc(size_t size)
{
@@ -634,7 +633,7 @@ static void auto_su(int argc, char *argv[])
static void add_if(const char *iface)
{
- if (is_asecurity_on || is_special_handshake_on)
+ if (is_awg_on)
cmd("amneziawg-go %s", iface);
else
cmd("ip link add %s type amneziawg", iface);
@@ -1262,45 +1261,45 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
*mtu = atoi(clean + 4);
continue;
} else if (!strncasecmp(clean, "Jc=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "Jmin=", 5) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "Jmax=", 5) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "S1=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "S2=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "S3=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "S4=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "H1=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "H2=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "H3=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
- is_asecurity_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "I1=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "I2=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "I3=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "I4=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "I5=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "J1=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "J2=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "J3=", 3) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
} else if (!strncasecmp(clean, "Itime=", 6) && j > 4) {
- is_special_handshake_on = true;
+ is_awg_on = true;
}
}
*config = concat_and_free(*config, "", line);
diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash
index 8cb065d..60e7ca6 100755
--- a/src/wg-quick/freebsd.bash
+++ b/src/wg-quick/freebsd.bash
@@ -28,7 +28,7 @@ CONFIG_FILE=""
PROGRAM="${0##*/}"
ARGS=( "$@" )
-IS_ASESCURITY_ON=0
+IS_AWG_ON=0
cmd() {
echo "[#] $*" >&3
@@ -104,10 +104,21 @@ parse_options() {
Jmax);&
S1);&
S2);&
+ S3);&
+ S4);&
H1);&
H2);&
H3);&
- H4) IS_ASESCURITY_ON=1;;
+ H4);&
+ I1);&
+ i2);&
+ I3);&
+ I4);&
+ I5);&
+ J1);&
+ J2);&
+ J3);&
+ Itime) IS_AWG_ON=1;;
esac
fi
WG_CONFIG+="$line"$'\n'
@@ -130,7 +141,7 @@ auto_su() {
add_if() {
local ret rc
local cmd="ifconfig wg create name "$INTERFACE""
- if [[ $IS_ASESCURITY_ON == 1 ]]; then
+ if [[ $IS_AWG_ON == 1 ]]; then
cmd="amneziawg-go "$INTERFACE"";
fi
if ret="$(cmd $cmd 2>&1 >/dev/null)"; then
@@ -501,4 +512,4 @@ else
exit 1
fi
-exit 0
\ No newline at end of file
+exit 0
diff --git a/src/wg-quick/openbsd.bash b/src/wg-quick/openbsd.bash
index 502cc9a..210570b 100755
--- a/src/wg-quick/openbsd.bash
+++ b/src/wg-quick/openbsd.bash
@@ -27,7 +27,7 @@ SAVE_CONFIG=0
CONFIG_FILE=""
PROGRAM="${0##*/}"
ARGS=( "$@" )
-IS_ASESCURITY_ON=0
+IS_AWG_ON=0
cmd() {
echo "[#] $*" >&3
@@ -75,10 +75,21 @@ parse_options() {
Jmax);&
S1);&
S2);&
+ S3);&
+ S4);&
H1);&
H2);&
H3);&
- H4) IS_ASESCURITY_ON=1;;
+ H4);&
+ I1);&
+ i2);&
+ I3);&
+ I4);&
+ I5);&
+ J1);&
+ J2);&
+ J3);&
+ Itime) IS_AWG_ON=1;;
esac
fi
WG_CONFIG+="$line"$'\n'
@@ -118,7 +129,7 @@ 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
+ if [[ $IS_AWG_ON == 1 ]]; then
cmd "amneziawg-go "$INTERFACE"";
return $?
else
@@ -495,4 +506,4 @@ else
exit 1
fi
-exit 0
\ No newline at end of file
+exit 0