From 652c4fe783790e0e6d3d24a1bf05e550611ef0f2 Mon Sep 17 00:00:00 2001 From: Mark Puha Date: Wed, 19 Feb 2025 17:45:02 +0100 Subject: [PATCH] Euphoria lua codec support for windows/linux --- contrib/embeddable-wg-library/wireguard.c | 1 + contrib/json/wg-json | 3 +- contrib/peer-approver/notification-listener.c | 2 +- src/config.c | 48 ++++++++++++--- src/containers.h | 6 +- src/ipc-freebsd.h | 61 +++++++++++-------- src/ipc-linux.h | 8 +++ src/ipc-openbsd.h | 12 +++- src/ipc-uapi.h | 6 ++ src/ipc-windows.h | 13 ++++ src/set.c | 2 +- src/show.c | 9 ++- src/showconf.c | 2 + src/uapi/linux/linux/wireguard.h | 1 + src/uapi/openbsd/net/if_wg.h | 2 + src/uapi/windows/wireguard.h | 4 +- src/wg-quick/android.c | 7 ++- src/wg-quick/freebsd.bash | 7 ++- src/wg-quick/openbsd.bash | 12 ++-- 19 files changed, 156 insertions(+), 50 deletions(-) diff --git a/contrib/embeddable-wg-library/wireguard.c b/contrib/embeddable-wg-library/wireguard.c index 500f33d..6367510 100644 --- a/contrib/embeddable-wg-library/wireguard.c +++ b/contrib/embeddable-wg-library/wireguard.c @@ -57,6 +57,7 @@ enum wgdevice_attribute { WGDEVICE_A_H2, WGDEVICE_A_H3, WGDEVICE_A_H4, + WGDEVICE_A_LUA_CODEC, __WGDEVICE_A_LAST }; diff --git a/contrib/json/wg-json b/contrib/json/wg-json index 83ab135..900cd85 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 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' diff --git a/contrib/peer-approver/notification-listener.c b/contrib/peer-approver/notification-listener.c index a264673..4acd2c5 100644 --- a/contrib/peer-approver/notification-listener.c +++ b/contrib/peer-approver/notification-listener.c @@ -260,4 +260,4 @@ int main(int argc, char *argv[]) } cleanup_and_exit(EXIT_FAILURE); -} \ No newline at end of file +} diff --git a/src/config.c b/src/config.c index f663b7d..0e1dace 100644 --- a/src/config.c +++ b/src/config.c @@ -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)); diff --git a/src/containers.h b/src/containers.h index 8f93bb5..a922930 100644 --- a/src/containers.h +++ b/src/containers.h @@ -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) diff --git a/src/ipc-freebsd.h b/src/ipc-freebsd.h index 1acddc4..c8ba99d 100644 --- a/src/ipc-freebsd.h +++ b/src/ipc-freebsd.h @@ -4,7 +4,9 @@ * */ +#include "containers.h" #include +#include #include #include #include @@ -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) diff --git a/src/ipc-linux.h b/src/ipc-linux.h index c6d9847..7eb363a 100644 --- a/src/ipc-linux.h +++ b/src/ipc-linux.h @@ -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; diff --git a/src/ipc-openbsd.h b/src/ipc-openbsd.h index 1b0955d..f098dcf 100644 --- a/src/ipc-openbsd.h +++ b/src/ipc-openbsd.h @@ -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) { diff --git a/src/ipc-uapi.h b/src/ipc-uapi.h index 250606c..97e0190 100644 --- a/src/ipc-uapi.h +++ b/src/ipc-uapi.h @@ -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)); diff --git a/src/ipc-windows.h b/src/ipc-windows.h index 7925cf0..fa749b6 100644 --- a/src/ipc-windows.h +++ b/src/ipc-windows.h @@ -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) { diff --git a/src/set.c b/src/set.c index 8f749b1..8985168 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 ] [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 ] [h1 ] [h2 ] [h3 ] [h4 ] [lua_codec ] [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 001ca1d..d140bce 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]\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 | 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) diff --git a/src/showconf.c b/src/showconf.c index 424b2be..a3da9a9 100644 --- a/src/showconf.c +++ b/src/showconf.c @@ -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) { diff --git a/src/uapi/linux/linux/wireguard.h b/src/uapi/linux/linux/wireguard.h index 8d38c90..7934315 100644 --- a/src/uapi/linux/linux/wireguard.h +++ b/src/uapi/linux/linux/wireguard.h @@ -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) diff --git a/src/uapi/openbsd/net/if_wg.h b/src/uapi/openbsd/net/if_wg.h index f768a32..ea6c2d6 100644 --- a/src/uapi/openbsd/net/if_wg.h +++ b/src/uapi/openbsd/net/if_wg.h @@ -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 { diff --git a/src/uapi/windows/wireguard.h b/src/uapi/windows/wireguard.h index 917d785..21c3f12 100644 --- a/src/uapi/windows/wireguard.h +++ b/src/uapi/windows/wireguard.h @@ -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) diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c index 425a068..3f56b80 100644 --- a/src/wg-quick/android.c +++ b/src/wg-quick/android.c @@ -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; -} \ No newline at end of file +} diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash index 8cb065d..e29db3e 100755 --- a/src/wg-quick/freebsd.bash +++ b/src/wg-quick/freebsd.bash @@ -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 \ No newline at end of file +exit 0 diff --git a/src/wg-quick/openbsd.bash b/src/wg-quick/openbsd.bash index 502cc9a..b276fc4 100755 --- a/src/wg-quick/openbsd.bash +++ b/src/wg-quick/openbsd.bash @@ -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 \ No newline at end of file +exit 0