From dbd48bde71bf06e33d419b0caeffc817822b33f6 Mon Sep 17 00:00:00 2001
From: Mark Puha
Date: Tue, 15 Jul 2025 06:30:51 +0200
Subject: [PATCH] fix: minor issues with new params
---
contrib/json/wg-json | 4 +++-
src/ipc-linux.h | 2 +-
src/ipc-openbsd.h | 2 +-
src/ipc-windows.h | 27 +++++++++------------------
src/set.c | 2 +-
src/show.c | 12 +++++++++++-
src/wg-quick/android.c | 4 ++++
7 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/contrib/json/wg-json b/contrib/json/wg-json
index d24296a..971f199 100755
--- a/contrib/json/wg-json
+++ b/contrib/json/wg-json
@@ -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 i1 i2 i3 i4 i5 j1 j2 j3 itime fwmark
+ read -r private_key public_key listen_port jc jmin jmax s1 s2 s3 s4 h1 h2 h3 h4 i1 i2 i3 i4 i5 j1 j2 j3 itime fwmark
printf '\t"%s": {' "$device"
delim=$'\n'
[[ $private_key == "(none)" ]] || { printf '%s\t\t"privateKey": "%s"' "$delim" "$private_key"; delim=$',\n'; }
@@ -22,6 +22,8 @@ while read -r -d $'\t' device; do
[[ $jmax == "0" ]] || { printf '%s\t\t"jmax": %u' "$delim" $(( $jmax )); delim=$',\n'; }
[[ $s1 == "0" ]] || { printf '%s\t\t"s1": %u' "$delim" $(( $s1 )); delim=$',\n'; }
[[ $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'; }
diff --git a/src/ipc-linux.h b/src/ipc-linux.h
index 0531ff5..8c082a3 100644
--- a/src/ipc-linux.h
+++ b/src/ipc-linux.h
@@ -653,7 +653,7 @@ static int parse_device(const struct nlattr *attr, void *data)
}
break;
case WGDEVICE_A_ITIME:
- if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ if (!mnl_attr_validate(attr, MNL_TYPE_U32))
{
device->itime = mnl_attr_get_u32(attr);
device->flags |= WGDEVICE_HAS_ITIME;
diff --git a/src/ipc-openbsd.h b/src/ipc-openbsd.h
index dd063ae..61bac7f 100644
--- a/src/ipc-openbsd.h
+++ b/src/ipc-openbsd.h
@@ -215,7 +215,7 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_ITIME)
{
- dev->itime = wg_iface->i_itime ;
+ dev->itime = wg_iface->i_itime;
dev->flags |= WGDEVICE_HAS_ITIME;
}
diff --git a/src/ipc-windows.h b/src/ipc-windows.h
index faa8b8f..3756a52 100644
--- a/src/ipc-windows.h
+++ b/src/ipc-windows.h
@@ -307,64 +307,55 @@ 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_I1)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I1) {
const size_t i1_size = strlen((char*)wg_iface->I1) + 1;
dev->i1 = (char*)malloc(i1_size);
memcpy(dev->i1, wg_iface->I1, i1_size);
dev->flags |= WGDEVICE_HAS_I1;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_I2)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I2) {
const size_t i2_size = strlen((char*)wg_iface->I2) + 1;
dev->i2 = (char*)malloc(i2_size);
memcpy(dev->i2, wg_iface->I2, i2_size);
dev->flags |= WGDEVICE_HAS_I2;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_I3)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I3) {
const size_t i3_size = strlen((char*)wg_iface->I3) + 1;
dev->i3 = (char*)malloc(i3_size);
memcpy(dev->i3, wg_iface->I3, i3_size);
dev->flags |= WGDEVICE_HAS_I3;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_I4)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I4) {
const size_t i4_size = strlen((char*)wg_iface->I4) + 1;
dev->i4 = (char*)malloc(i4_size);
memcpy(dev->i4, wg_iface->I4, i4_size);
dev->flags |= WGDEVICE_HAS_I4;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_I5)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I5) {
const size_t i5_size = strlen((char*)wg_iface->I5) + 1;
dev->i5 = (char*)malloc(i5_size);
memcpy(dev->i5, wg_iface->I5, i5_size);
dev->flags |= WGDEVICE_HAS_I5;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_J1)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J1) {
const size_t j1_size = strlen((char*)wg_iface->J1) + 1;
dev->j1 = (char*)malloc(j1_size);
memcpy(dev->j1, wg_iface->J1, j1_size);
dev->flags |= WGDEVICE_HAS_J1;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_J2)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J2) {
const size_t j2_size = strlen((char*)wg_iface->J2) + 1;
dev->j2 = (char*)malloc(j2_size);
memcpy(dev->j2, wg_iface->J2, j2_size);
dev->flags |= WGDEVICE_HAS_J2;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_J3)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J3) {
const size_t j3_size = strlen((char*)wg_iface->J3) + 1;
dev->j3 = (char*)malloc(j3_size);
memcpy(dev->j3, wg_iface->J3, j3_size);
dev->flags |= WGDEVICE_HAS_J3;
}
- if (wg_iface->Flags & WG_IOCTL_INTERFACE_ITIME)
- {
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_ITIME) {
dev->itime = wg_iface->Itime;
dev->flags |= WGDEVICE_HAS_ITIME;
}
diff --git a/src/set.c b/src/set.c
index 6bec30a..dc56667 100644
--- a/src/set.c
+++ b/src/set.c
@@ -18,7 +18,7 @@ int set_main(int argc, const char *argv[])
int ret = 1;
if (argc < 3) {
- fprintf(stderr, "Usage: %s %s [listen-port ] [fwmark ] [private-key ] [jc ] [jmin ] [jmax ] [s1 ] [s2 ] [h1 ] [h2 ] [h3 ] [h4 ] [i1 \"\"] [i2 \"\"] [i3 \"\"] [i4 \"\"] [i5 \"\"] [j1 \"\"] [j2 \"\"] [j3 \"\"] [itime ][peer [remove] [preshared-key ] [endpoint :] [persistent-keepalive ] [allowed-ips /[,/] [advanced-security ]...] ]...\n", PROG_NAME, argv[0]);
+ fprintf(stderr, "Usage: %s %s [listen-port ] [fwmark ] [private-key ] [jc ] [jmin ] [jmax ] [s1 ] [s2 ] [s3 ] [s4 ] [h1 ] [h2 ] [h3 ] [h4 ] [i1 \"\"] [i2 \"\"] [i3 \"\"] [i4 \"\"] [i5 \"\"] [j1 \"\"] [j2 \"\"] [j3 \"\"] [itime ][peer [remove] [preshared-key ] [endpoint :] [persistent-keepalive ] [allowed-ips /[,/] [advanced-security ]...] ]...\n", PROG_NAME, argv[0]);
return 1;
}
diff --git a/src/show.c b/src/show.c
index 9b047c9..93e1b03 100644
--- a/src/show.c
+++ b/src/show.c
@@ -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 { | 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 | i1 | i2 | i3 | i4 | i5 | j1 | j2 | j3 | itime]\n", PROG_NAME, COMMAND_NAME);
+ fprintf(stderr, "Usage: %s %s { | 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 | s3 | s4 | h1 | h2 | h3 | h4 | i1 | i2 | i3 | i4 | i5 | j1 | j2 | j3 | itime]\n", PROG_NAME, COMMAND_NAME);
}
static void pretty_print(struct wgdevice *device)
@@ -306,6 +306,8 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("%u\t", device->junk_packet_max_size);
printf("%u\t", device->init_packet_junk_size);
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);
@@ -391,6 +393,14 @@ 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->response_packet_junk_size);
+ } else if(!strcmp(param, "s3")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%u\n", device->cookie_reply_packet_junk_size);
+ } else if(!strcmp(param, "s4")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%u\n", device->transport_packet_junk_size);
} else if(!strcmp(param, "h1")) {
if (with_interface)
printf("%s\t", device->name);
diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
index 167c6d6..dd3a340 100644
--- a/src/wg-quick/android.c
+++ b/src/wg-quick/android.c
@@ -1271,6 +1271,10 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
is_asecurity_on = true;
} else if (!strncasecmp(clean, "S2=", 3) && j > 4) {
is_asecurity_on = true;
+ } else if (!strncasecmp(clean, "S3=", 3) && j > 4) {
+ is_asecurity_on = true;
+ } else if (!strncasecmp(clean, "S4=", 3) && j > 4) {
+ is_asecurity_on = true;
} else if (!strncasecmp(clean, "H1=", 3) && j > 4) {
is_asecurity_on = true;
} else if (!strncasecmp(clean, "H2=", 3) && j > 4) {