mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-07-26 06:52:50 +02:00
parent
ae857090cd
commit
481106b19d
19 changed files with 76 additions and 1078 deletions
|
@ -53,29 +53,17 @@ enum wgdevice_attribute {
|
|||
WGDEVICE_A_JMAX,
|
||||
WGDEVICE_A_S1,
|
||||
WGDEVICE_A_S2,
|
||||
WGDEVICE_A_S3,
|
||||
WGDEVICE_A_S4,
|
||||
WGDEVICE_A_H1,
|
||||
WGDEVICE_A_H2,
|
||||
WGDEVICE_A_H3,
|
||||
WGDEVICE_A_H4,
|
||||
WGDEVICE_A_I1,
|
||||
WGDEVICE_A_I2,
|
||||
WGDEVICE_A_I3,
|
||||
WGDEVICE_A_I4,
|
||||
WGDEVICE_A_I5,
|
||||
WGDEVICE_A_J1,
|
||||
WGDEVICE_A_J2,
|
||||
WGDEVICE_A_J3,
|
||||
WGDEVICE_A_ITIME,
|
||||
__WGDEVICE_A_LAST
|
||||
};
|
||||
|
||||
enum wgpeer_flag {
|
||||
WGPEER_F_REMOVE_ME = 1U << 0,
|
||||
WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
|
||||
WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3,
|
||||
WGPEER_F_HAS_SPECIAL_HANDSHAKE = 1U << 4
|
||||
WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3
|
||||
};
|
||||
enum wgpeer_attribute {
|
||||
WGPEER_A_UNSPEC,
|
||||
|
@ -90,7 +78,6 @@ enum wgpeer_attribute {
|
|||
WGPEER_A_ALLOWEDIPS,
|
||||
WGPEER_A_PROTOCOL_VERSION,
|
||||
WGPEER_A_ADVANCED_SECURITY,
|
||||
WGPEER_A_SPECIAL_HANDSHAKE,
|
||||
__WGPEER_A_LAST
|
||||
};
|
||||
|
||||
|
|
|
@ -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 h1 h2 h3 h4 fwmark
|
||||
printf '\t"%s": {' "$device"
|
||||
delim=$'\n'
|
||||
[[ $private_key == "(none)" ]] || { printf '%s\t\t"privateKey": "%s"' "$delim" "$private_key"; delim=$',\n'; }
|
||||
|
@ -26,15 +26,6 @@ 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'; }
|
||||
[[ $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'; }
|
||||
[[ $i4 == "(none)" ]] || { printf '%s\t\t"i4": "%s"' "$delim" "$i4"; delim=$',\n'; }
|
||||
[[ $i5 == "(none)" ]] || { printf '%s\t\t"i5": "%s"' "$delim" "$i5"; delim=$',\n'; }
|
||||
[[ $j1 == "(none)" ]] || { printf '%s\t\t"j1": "%s"' "$delim" "$j1"; delim=$',\n'; }
|
||||
[[ $j2 == "(none)" ]] || { printf '%s\t\t"j2": "%s"' "$delim" "$j2"; delim=$',\n'; }
|
||||
[[ $j3 == "(none)" ]] || { printf '%s\t\t"j3": "%s"' "$delim" "$j3"; delim=$',\n'; }
|
||||
[[ $itime == "0" ]] || { printf '%s\t\t"itime": %u' "$delim" $(( itime )); 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'
|
||||
|
|
|
@ -5,7 +5,6 @@ INTERFACE_NAME=$2
|
|||
PUBLIC_KEY=$3
|
||||
ENDPOINT=$4
|
||||
ADVANCED_SECURITY=$5
|
||||
SPECIAL_HANDSHAKE=$6
|
||||
|
||||
ACCOUNT_STR=`grep "${PUBLIC_KEY}" "${ACCOUNTS_FILE}"`
|
||||
|
||||
|
@ -20,7 +19,7 @@ PSK=$(echo ${ACCOUNT[2]}|tr -d '"')
|
|||
PSK_FILE=$(tempfile)
|
||||
echo "${PSK}" > "${PSK_FILE}"
|
||||
|
||||
awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK_FILE}" advanced-security "${ADVANCED_SECURITY}" special-handshake "${SPECIAL_HANDSHAKE}"
|
||||
awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK_FILE}" advanced-security "${ADVANCED_SECURITY}"
|
||||
EXIT_CODE=$?
|
||||
|
||||
rm -f "{$PSK_FILE}"
|
||||
|
|
|
@ -116,19 +116,18 @@ static int get_endpoint(struct nlattr *peer[], char **endpoint_ip)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool advanced_security, bool special_handshake)
|
||||
static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool advanced_security)
|
||||
{
|
||||
char** new_argv = malloc((cb_argc + 2) * sizeof *new_argv);
|
||||
|
||||
new_argv[0] = cb_argv[1];
|
||||
for (int i = 2; i < cb_argc - 4; i++) {
|
||||
for (int i = 2; i < cb_argc - 3; i++) {
|
||||
new_argv[i - 1] = cb_argv[i];
|
||||
}
|
||||
new_argv[cb_argc - 5] = ifname;
|
||||
new_argv[cb_argc - 4] = pubkey;
|
||||
new_argv[cb_argc - 3] = endpoint_ip;
|
||||
new_argv[cb_argc - 2] = (advanced_security ? "on\0" : "off\0");
|
||||
new_argv[cb_argc - 1] = (special_handshake ? "on\0" : "off\0");
|
||||
new_argv[cb_argc - 4] = ifname;
|
||||
new_argv[cb_argc - 3] = pubkey;
|
||||
new_argv[cb_argc - 2] = endpoint_ip;
|
||||
new_argv[cb_argc - 1] = (advanced_security ? "on\0" : "off\0");
|
||||
new_argv[cb_argc] = NULL;
|
||||
|
||||
int child_pid = fork(), ret;
|
||||
|
@ -157,7 +156,6 @@ static int netlink_callback(struct nl_msg *msg, void *arg)
|
|||
|
||||
char *ifname, *pubkey, *endpoint_ip;
|
||||
bool advanced_security = false;
|
||||
bool special_handshake = false;
|
||||
int cb_ret;
|
||||
|
||||
switch (gnlh->cmd) {
|
||||
|
@ -181,10 +179,7 @@ static int netlink_callback(struct nl_msg *msg, void *arg)
|
|||
if (nla_get_flag(peer[WGPEER_A_ADVANCED_SECURITY])) {
|
||||
advanced_security = true;
|
||||
}
|
||||
if (nla_get_flag(peer[WGPEER_A_SPECIAL_HANDSHAKE])) {
|
||||
special_handshake = true;
|
||||
}
|
||||
if (cb_ret = run_callback(ifname, pubkey, endpoint_ip, advanced_security, special_handshake)) {
|
||||
if (cb_ret = run_callback(ifname, pubkey, endpoint_ip, advanced_security)) {
|
||||
prerr("failed to execute callback script: %d!\n", cb_ret);
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
@ -265,4 +260,4 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
cleanup_and_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
219
src/config.c
219
src/config.c
|
@ -22,13 +22,6 @@
|
|||
|
||||
#define COMMENT_CHAR '#'
|
||||
|
||||
// Keys that should return empty string instead of NULL when not found
|
||||
static const char *awg_optional_keys[] = {
|
||||
"I1", "I2", "I3", "I4", "I5",
|
||||
"J1", "J2", "J3",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *get_value(const char *line, const char *key)
|
||||
{
|
||||
size_t linelen = strlen(line);
|
||||
|
@ -40,7 +33,6 @@ static const char *get_value(const char *line, const char *key)
|
|||
if (strncasecmp(line, key, keylen))
|
||||
return NULL;
|
||||
|
||||
|
||||
return line + keylen;
|
||||
}
|
||||
|
||||
|
@ -418,29 +410,13 @@ err:
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline bool parse_awg_string(char **device_value, const char *name, const char *value) {
|
||||
size_t len = strlen(value);
|
||||
if (!len) {
|
||||
*device_value = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
if( len >= MAX_AWG_JUNK_LEN) {
|
||||
fprintf(stderr, "Unable to process string for: %s; longer than: %d\n", name, MAX_AWG_JUNK_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);
|
||||
|
@ -566,14 +542,6 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
|||
ret = parse_uint16(&ctx->device->response_packet_junk_size, "S2", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_S2;
|
||||
} else if (key_match("S3")) {
|
||||
ret = parse_uint16(&ctx->device->cookie_reply_packet_junk_size, "S3", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_S3;
|
||||
} else if (key_match("S4")) {
|
||||
ret = parse_uint16(&ctx->device->transport_packet_junk_size, "S4", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_S4;
|
||||
} else if (key_match("H1")) {
|
||||
ret = parse_uint32(&ctx->device->init_packet_magic_header, "H1", value);
|
||||
if (ret)
|
||||
|
@ -590,52 +558,8 @@ 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("I1")) {
|
||||
ret = parse_awg_string(&ctx->device->i1, "I1", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_I1;
|
||||
} else if (key_match("I2")) {
|
||||
ret = parse_awg_string(&ctx->device->i2, "I2", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_I2;
|
||||
} else if (key_match("I3")) {
|
||||
ret = parse_awg_string(&ctx->device->i3, "I3", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_I3;
|
||||
} else if (key_match("I4")) {
|
||||
ret = parse_awg_string(&ctx->device->i4, "I4", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_I4;
|
||||
} else if (key_match("I5")) {
|
||||
ret = parse_awg_string(&ctx->device->i5, "I5", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_I5;
|
||||
} else if (key_match("J1")) {
|
||||
ret = parse_awg_string(&ctx->device->j1, "J1", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_J1;
|
||||
} else if (key_match("J2")) {
|
||||
ret = parse_awg_string(&ctx->device->j2, "J2", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_J2;
|
||||
} else if (key_match("J3")) {
|
||||
ret = parse_awg_string(&ctx->device->j3, "J3", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_J3;
|
||||
} else if (key_match("Itime")) {
|
||||
ret = parse_uint32(&ctx->device->itime, "Itime", value);
|
||||
if (ret)
|
||||
ctx->device->flags |= WGDEVICE_HAS_ITIME;
|
||||
} else {
|
||||
// Check if this is an AWG optional key
|
||||
if (strlen(line) == 3) {
|
||||
for (int i = 0; awg_optional_keys[i] != NULL; i++) {
|
||||
if (!strncasecmp(line, awg_optional_keys[i], 2))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else
|
||||
goto error;
|
||||
}
|
||||
} else if (ctx->is_peer_section) {
|
||||
if (key_match("Endpoint"))
|
||||
ret = parse_endpoint(&ctx->last_peer->endpoint.addr, value);
|
||||
|
@ -655,10 +579,6 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
|||
ret = parse_bool(&ctx->last_peer->advanced_security, "AdvancedSecurity", value);
|
||||
if (ret)
|
||||
ctx->last_peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
|
||||
} else if (key_match("SpecialHandshake")) {
|
||||
ret = parse_bool(&ctx->last_peer->special_handshake, "SpecialHandshake", value);
|
||||
if (ret)
|
||||
ctx->last_peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
|
||||
} else
|
||||
goto error;
|
||||
} else
|
||||
|
@ -677,9 +597,6 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
|
|||
size_t len, cleaned_len = 0;
|
||||
char *line, *comment;
|
||||
bool ret = true;
|
||||
bool found_equals = false;
|
||||
bool found_value_start = false;
|
||||
size_t value_end = 0;
|
||||
|
||||
/* This is what strchrnul is for, but that isn't portable. */
|
||||
comment = strchr(input, COMMENT_CHAR);
|
||||
|
@ -695,37 +612,10 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* Remove preceding and trailing whitespaces before value
|
||||
First pass: find the actual end of the value (trim trailing spaces) */
|
||||
for (size_t i = len; i > 0; --i) {
|
||||
if (!char_is_space(input[i - 1])) {
|
||||
value_end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Second pass: clean according to KEY = VALUE rules */
|
||||
for (size_t i = 0; i < value_end; ++i) {
|
||||
if (!found_equals) {
|
||||
/* Before '=': remove all whitespace */
|
||||
if (input[i] == '=') {
|
||||
line[cleaned_len++] = input[i];
|
||||
found_equals = true;
|
||||
} else if (!char_is_space(input[i])) {
|
||||
line[cleaned_len++] = input[i];
|
||||
}
|
||||
} else if (!found_value_start) {
|
||||
/* After '=' but before value: skip whitespace until first non-space */
|
||||
if (!char_is_space(input[i])) {
|
||||
line[cleaned_len++] = input[i];
|
||||
found_value_start = true;
|
||||
}
|
||||
} else {
|
||||
/* Within value: preserve all characters including spaces */
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
if (!char_is_space(input[i]))
|
||||
line[cleaned_len++] = input[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!cleaned_len)
|
||||
goto out;
|
||||
ret = process_line(ctx, line);
|
||||
|
@ -813,143 +703,66 @@ 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], "s3") && argc >= 2 && !peer) {
|
||||
if (!parse_uint16(&device->cookie_reply_packet_junk_size, "s3", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_S3;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else if (!strcmp(argv[0], "s4") && argc >= 2 && !peer) {
|
||||
if (!parse_uint16(&device->transport_packet_junk_size, "s4", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_S4;
|
||||
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], "i1") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->i1, "i1", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_I1;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else if (!strcmp(argv[0], "i2") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->i2, "i2", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_I2;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "i3") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->i3, "i3", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_I3;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "i4") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->i4, "i4", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_I4;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "i5") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->i5, "i5", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_I5;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "j1") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->j1, "j1", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_J1;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "j2") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->j2, "j2", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_J2;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "j3") && argc >= 2 && !peer) {
|
||||
if (!parse_awg_string(&device->j3, "j3", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_J3;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "itime") && argc >= 2 && !peer) {
|
||||
if (!parse_uint32(&device->itime, "itime", argv[1]))
|
||||
goto error;
|
||||
|
||||
device->flags |= WGDEVICE_HAS_ITIME;
|
||||
argv += 2;
|
||||
argc -=2;
|
||||
} else if (!strcmp(argv[0], "peer") && argc >= 2) {
|
||||
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
|
||||
|
||||
|
@ -1006,12 +819,6 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
|
|||
peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else if (!strcmp(argv[0], "special-handshake") && argc >= 2 && peer) {
|
||||
if (!parse_bool(&peer->special_handshake, "SpecialHandshake", argv[1]))
|
||||
goto error;
|
||||
peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid argument: %s\n", argv[0]);
|
||||
goto error;
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
#define WG_KEY_LEN 32
|
||||
#endif
|
||||
|
||||
#ifndef MAX_AWG_JUNK_LEN
|
||||
#define MAX_AWG_JUNK_LEN 5 * 1024
|
||||
#endif
|
||||
|
||||
/* Cross platform __kernel_timespec */
|
||||
struct timespec64 {
|
||||
int64_t tv_sec;
|
||||
|
@ -49,8 +45,7 @@ enum {
|
|||
WGPEER_HAS_PUBLIC_KEY = 1U << 2,
|
||||
WGPEER_HAS_PRESHARED_KEY = 1U << 3,
|
||||
WGPEER_HAS_PERSISTENT_KEEPALIVE_INTERVAL = 1U << 4,
|
||||
WGPEER_HAS_ADVANCED_SECURITY = 1U << 5,
|
||||
WGPEER_HAS_SPECIAL_HANDSHAKE = 1U << 6
|
||||
WGPEER_HAS_ADVANCED_SECURITY = 1U << 5
|
||||
};
|
||||
|
||||
struct wgpeer {
|
||||
|
@ -70,7 +65,6 @@ struct wgpeer {
|
|||
uint16_t persistent_keepalive_interval;
|
||||
|
||||
bool advanced_security;
|
||||
bool special_handshake;
|
||||
|
||||
struct wgallowedip *first_allowedip, *last_allowedip;
|
||||
struct wgpeer *next_peer;
|
||||
|
@ -87,21 +81,10 @@ enum {
|
|||
WGDEVICE_HAS_JMAX = 1U << 7,
|
||||
WGDEVICE_HAS_S1 = 1U << 8,
|
||||
WGDEVICE_HAS_S2 = 1U << 9,
|
||||
WGDEVICE_HAS_S3 = 1U << 10,
|
||||
WGDEVICE_HAS_S4 = 1U << 11,
|
||||
WGDEVICE_HAS_H1 = 1U << 12,
|
||||
WGDEVICE_HAS_H2 = 1U << 12,
|
||||
WGDEVICE_HAS_H3 = 1U << 13,
|
||||
WGDEVICE_HAS_H4 = 1U << 14,
|
||||
WGDEVICE_HAS_I1 = 1U << 15,
|
||||
WGDEVICE_HAS_I2 = 1U << 16,
|
||||
WGDEVICE_HAS_I3 = 1U << 17,
|
||||
WGDEVICE_HAS_I4 = 1U << 18,
|
||||
WGDEVICE_HAS_I5 = 1U << 19,
|
||||
WGDEVICE_HAS_J1 = 1U << 20,
|
||||
WGDEVICE_HAS_J2 = 1U << 21,
|
||||
WGDEVICE_HAS_J3 = 1U << 22,
|
||||
WGDEVICE_HAS_ITIME = 1U << 23
|
||||
WGDEVICE_HAS_H1 = 1U << 10,
|
||||
WGDEVICE_HAS_H2 = 1U << 11,
|
||||
WGDEVICE_HAS_H3 = 1U << 12,
|
||||
WGDEVICE_HAS_H4 = 1U << 13
|
||||
};
|
||||
|
||||
struct wgdevice {
|
||||
|
@ -123,21 +106,10 @@ struct wgdevice {
|
|||
uint16_t junk_packet_max_size;
|
||||
uint16_t init_packet_junk_size;
|
||||
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* i1;
|
||||
char* i2;
|
||||
char* i3;
|
||||
char* i4;
|
||||
char* i5;
|
||||
char* j1;
|
||||
char* j2;
|
||||
char* j3;
|
||||
uint32_t itime;
|
||||
};
|
||||
|
||||
#define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer)
|
||||
|
|
|
@ -91,163 +91,68 @@ 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, "s3")) {
|
||||
number = nvlist_get_number(nvl_device, "s3");
|
||||
if (number <= UINT16_MAX){
|
||||
dev->cookie_reply_packet_junk_size = number;
|
||||
dev->flags |= WGDEVICE_HAS_S3;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_number(nvl_device, "s4")) {
|
||||
number = nvlist_get_number(nvl_device, "s4");
|
||||
if (number <= UINT16_MAX){
|
||||
dev->transport_packet_junk_size = number;
|
||||
dev->flags |= WGDEVICE_HAS_S4;
|
||||
}
|
||||
}
|
||||
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, "i1"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "i1", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->i1 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_I1;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "i2"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "i2", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->i2 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_I2;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "i3"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "i3", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->i3 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_I3;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "i4"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "i4", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->i4 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_I4;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "i5"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "i5", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->i5 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_I5;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "j1"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "j1", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->j1 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_J1;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "j2"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "j2", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->j2 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_J2;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "j3"))
|
||||
{
|
||||
binary = nvlist_get_binary(nvl_device, "j3", &size);
|
||||
if (binary && size < MAX_AWG_JUNK_LEN)
|
||||
{
|
||||
dev->j3 = strdup((const char*)binary);
|
||||
dev->flags |= WGDEVICE_HAS_J3;
|
||||
}
|
||||
}
|
||||
if (nvlist_exists_binary(nvl_device, "itime"))
|
||||
{
|
||||
number = nvlist_get_number(nvl_device, "itime");
|
||||
if (number <= UINT32_MAX)
|
||||
{
|
||||
dev->itime = number;
|
||||
dev->flags |= WGDEVICE_HAS_ITIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nvlist_exists_number(nvl_device, "user-cookie")) {
|
||||
|
@ -441,10 +346,6 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
nvlist_add_number(nvl_device, "s1", dev->init_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S2)
|
||||
nvlist_add_number(nvl_device, "s2", dev->response_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S3)
|
||||
nvlist_add_number(nvl_device, "s3", dev->cookie_reply_packet_junk_size);
|
||||
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);
|
||||
if (dev->flags & WGDEVICE_HAS_H2)
|
||||
|
@ -453,24 +354,6 @@ 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_I1)
|
||||
nvlist_add_binary(nvl_device, "i1", dev->i1, strlen(dev->i1) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_I2)
|
||||
nvlist_add_binary(nvl_device, "i2", dev->i2, strlen(dev->i2) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_I3)
|
||||
nvlist_add_binary(nvl_device, "i3", dev->i3, strlen(dev->i3) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_I4)
|
||||
nvlist_add_binary(nvl_device, "i4", dev->i4, strlen(dev->i4) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_I5)
|
||||
nvlist_add_binary(nvl_device, "i5", dev->i5, strlen(dev->i5) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_J1)
|
||||
nvlist_add_binary(nvl_device, "j1", dev->j1, strlen(dev->j1) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_J2)
|
||||
nvlist_add_binary(nvl_device, "j2", dev->j2, strlen(dev->j2) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_J3)
|
||||
nvlist_add_binary(nvl_device, "j3", dev->j3, strlen(dev->j3) + 1);
|
||||
if (dev->flags & WGDEVICE_HAS_ITIME)
|
||||
nvlist_add_number(nvl_device, "itime", dev->itime);
|
||||
if (dev->flags & WGDEVICE_HAS_FWMARK)
|
||||
nvlist_add_number(nvl_device, "user-cookie", dev->fwmark);
|
||||
if (dev->flags & WGDEVICE_REPLACE_PEERS)
|
||||
|
|
122
src/ipc-linux.h
122
src/ipc-linux.h
|
@ -173,10 +173,6 @@ again:
|
|||
mnl_attr_put_u16(nlh, WGDEVICE_A_S1, dev->init_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S2)
|
||||
mnl_attr_put_u16(nlh, WGDEVICE_A_S2, dev->response_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S3)
|
||||
mnl_attr_put_u16(nlh, WGDEVICE_A_S3, dev->cookie_reply_packet_junk_size);
|
||||
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);
|
||||
if (dev->flags & WGDEVICE_HAS_H2)
|
||||
|
@ -185,24 +181,6 @@ 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_I1)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_I1, dev->i1);
|
||||
if (dev->flags & WGDEVICE_HAS_I2)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_I2, dev->i2);
|
||||
if (dev->flags & WGDEVICE_HAS_I3)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_I3, dev->i3);
|
||||
if (dev->flags & WGDEVICE_HAS_I4)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_I4, dev->i4);
|
||||
if (dev->flags & WGDEVICE_HAS_I5)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_I5, dev->i5);
|
||||
if (dev->flags & WGDEVICE_HAS_J1)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_J1, dev->j1);
|
||||
if (dev->flags & WGDEVICE_HAS_J2)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_J2, dev->j2);
|
||||
if (dev->flags & WGDEVICE_HAS_J3)
|
||||
mnl_attr_put_strz(nlh, WGDEVICE_A_J3, dev->j3);
|
||||
if (dev->flags & WGDEVICE_HAS_ITIME)
|
||||
mnl_attr_put_u32(nlh, WGDEVICE_A_ITIME, dev->itime);
|
||||
if (dev->flags & WGDEVICE_HAS_FWMARK)
|
||||
mnl_attr_put_u32(nlh, WGDEVICE_A_FWMARK, dev->fwmark);
|
||||
if (dev->flags & WGDEVICE_REPLACE_PEERS)
|
||||
|
@ -248,13 +226,6 @@ again:
|
|||
mnl_attr_put_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_ADVANCED_SECURITY, 0, NULL);
|
||||
flags |= WGPEER_F_HAS_ADVANCED_SECURITY;
|
||||
}
|
||||
if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE)
|
||||
{
|
||||
if (peer->special_handshake)
|
||||
mnl_attr_put_check(
|
||||
nlh, SOCKET_BUFFER_SIZE, WGPEER_A_SPECIAL_HANDSHAKE, 0, NULL);
|
||||
flags |= WGPEER_F_HAS_SPECIAL_HANDSHAKE;
|
||||
}
|
||||
if (flags) {
|
||||
if (!mnl_attr_put_u32_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_FLAGS, flags))
|
||||
goto toobig_peers;
|
||||
|
@ -431,13 +402,6 @@ static int parse_peer(const struct nlattr *attr, void *data)
|
|||
peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
|
||||
peer->advanced_security = false;
|
||||
}
|
||||
if (
|
||||
flags & WGPEER_F_HAS_SPECIAL_HANDSHAKE &&
|
||||
!(peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE))
|
||||
{
|
||||
peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
|
||||
peer->special_handshake = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WGPEER_A_ADVANCED_SECURITY:
|
||||
|
@ -449,17 +413,6 @@ static int parse_peer(const struct nlattr *attr, void *data)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case WGPEER_A_SPECIAL_HANDSHAKE:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_FLAG))
|
||||
{
|
||||
peer->special_handshake = true;
|
||||
|
||||
if (!(peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE))
|
||||
{
|
||||
peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WGPEER_A_ALLOWEDIPS:
|
||||
return mnl_attr_parse_nested(attr, parse_allowedips, peer);
|
||||
}
|
||||
|
@ -560,18 +513,6 @@ static int parse_device(const struct nlattr *attr, void *data)
|
|||
device->flags |= WGDEVICE_HAS_S2;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_S3:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
|
||||
device->cookie_reply_packet_junk_size = mnl_attr_get_u16(attr);
|
||||
device->flags |= WGDEVICE_HAS_S3;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_S4:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
|
||||
device->transport_packet_junk_size = mnl_attr_get_u16(attr);
|
||||
device->flags |= WGDEVICE_HAS_S4;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_H1:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
|
||||
device->init_packet_magic_header = mnl_attr_get_u32(attr);
|
||||
|
@ -596,69 +537,6 @@ static int parse_device(const struct nlattr *attr, void *data)
|
|||
device->flags |= WGDEVICE_HAS_H4;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_I1:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->i1 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_I1;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_I2:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->i2 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_I2;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_I3:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->i3 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_I3;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_I4:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->i4 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_I4;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_I5:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->i5 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_I5;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_J1:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->j1 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_J1;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_J2:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->j2 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_J2;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_J3:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->j3 = strdup(mnl_attr_get_str(attr));
|
||||
device->flags |= WGDEVICE_HAS_J3;
|
||||
}
|
||||
break;
|
||||
case WGDEVICE_A_ITIME:
|
||||
if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
|
||||
{
|
||||
device->itime = mnl_attr_get_u32(attr);
|
||||
device->flags |= WGDEVICE_HAS_ITIME;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return MNL_CB_OK;
|
||||
|
|
|
@ -135,16 +135,6 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
|
|||
dev->flags |= WGDEVICE_HAS_S2;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_S3) {
|
||||
dev->cookie_reply_packet_junk_size = wg_iface->i_cookie_reply_packet_junk_size;
|
||||
dev->flags |= WGDEVICE_HAS_S3;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_S4) {
|
||||
dev->transport_packet_junk_size = wg_iface->i_transport_packet_junk_size;
|
||||
dev->flags |= WGDEVICE_HAS_S4;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H1) {
|
||||
dev->init_packet_magic_header = wg_iface->i_init_packet_magic_header;
|
||||
dev->flags |= WGDEVICE_HAS_H1;
|
||||
|
@ -164,61 +154,7 @@ 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_I1)
|
||||
{
|
||||
dev->i1 = strdup(wg_iface->i_i1);
|
||||
dev->flags |= WGDEVICE_HAS_I1;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I2)
|
||||
{
|
||||
dev->i2 = strdup(wg_iface->i_i2);
|
||||
dev->flags |= WGDEVICE_HAS_I2;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I3)
|
||||
{
|
||||
dev->i3 = strdup(wg_iface->i_i3);
|
||||
dev->flags |= WGDEVICE_HAS_I3;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I4)
|
||||
{
|
||||
dev->i4 = strdup(wg_iface->i_i4);
|
||||
dev->flags |= WGDEVICE_HAS_I4;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I5)
|
||||
{
|
||||
dev->i5 = strdup(wg_iface->i_i5);
|
||||
dev->flags |= WGDEVICE_HAS_I5;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J1)
|
||||
{
|
||||
dev->j1 = strdup(wg_iface->i_j1);
|
||||
dev->flags |= WGDEVICE_HAS_J1;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J2)
|
||||
{
|
||||
dev->j2 = strdup(wg_iface->i_j2);
|
||||
dev->flags |= WGDEVICE_HAS_J2;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J3)
|
||||
{
|
||||
dev->j3 = strdup(wg_iface->i_j3);
|
||||
dev->flags |= WGDEVICE_HAS_J3;
|
||||
}
|
||||
|
||||
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_ITIME)
|
||||
{
|
||||
dev->itime = wg_iface->i_itime ;
|
||||
dev->flags |= WGDEVICE_HAS_ITIME;
|
||||
}
|
||||
|
||||
|
||||
wg_peer = &wg_iface->i_peers[0];
|
||||
for (size_t i = 0; i < wg_iface->i_peers_count; ++i) {
|
||||
peer = calloc(1, sizeof(*peer));
|
||||
|
@ -356,16 +292,6 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S2;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_S3) {
|
||||
wg_iface->i_cookie_reply_packet_junk_size = dev->cookie_reply_packet_junk_size;
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S3;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_S4) {
|
||||
wg_iface->i_transport_packet_junk_size = dev->transport_packet_junk_size;
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S4;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_H1) {
|
||||
wg_iface->i_init_packet_magic_header = dev->init_packet_magic_header;
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H1;
|
||||
|
@ -386,60 +312,6 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H4;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I1)
|
||||
{
|
||||
wg_iface->i_i1 = strdup(dev->i1);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I1;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I2)
|
||||
{
|
||||
wg_iface->i_i2 = strdup(dev->i2);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I2;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I3)
|
||||
{
|
||||
wg_iface->i_i3 = strdup(dev->i3);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I3;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I4)
|
||||
{
|
||||
wg_iface->i_i4 = strdup(dev->i4);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I4;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I5)
|
||||
{
|
||||
wg_iface->i_i5 = strdup(dev->i5);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I5;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_J1)
|
||||
{
|
||||
wg_iface->i_j1 = strdup(dev->j1);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J1;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_J2)
|
||||
{
|
||||
wg_iface->i_j2 = strdup(dev->j2);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J2;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_J3)
|
||||
{
|
||||
wg_iface->i_j3 = strdup(dev->j3);
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J3;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_ITIME)
|
||||
{
|
||||
wg_iface->i_itime = dev->itime;
|
||||
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_ITIME;
|
||||
}
|
||||
|
||||
peer_count = 0;
|
||||
wg_peer = &wg_iface->i_peers[0];
|
||||
for_each_wgpeer(dev, peer) {
|
||||
|
|
|
@ -61,10 +61,6 @@ static int userspace_set_device(struct wgdevice *dev)
|
|||
fprintf(f, "s1=%u\n", dev->init_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S2)
|
||||
fprintf(f, "s2=%u\n", dev->response_packet_junk_size);
|
||||
if (dev->flags & WGDEVICE_HAS_S3)
|
||||
fprintf(f, "s3=%u\n", dev->cookie_reply_packet_junk_size);
|
||||
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);
|
||||
if (dev->flags & WGDEVICE_HAS_H2)
|
||||
|
@ -74,25 +70,6 @@ static int userspace_set_device(struct wgdevice *dev)
|
|||
if (dev->flags & WGDEVICE_HAS_H4)
|
||||
fprintf(f, "h4=%u\n", dev->transport_packet_magic_header);
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I1)
|
||||
fprintf(f, "i1=%s\n", dev->i1);
|
||||
if (dev->flags & WGDEVICE_HAS_I2)
|
||||
fprintf(f, "i2=%s\n", dev->i2);
|
||||
if (dev->flags & WGDEVICE_HAS_I3)
|
||||
fprintf(f, "i3=%s\n", dev->i3);
|
||||
if (dev->flags & WGDEVICE_HAS_I4)
|
||||
fprintf(f, "i4=%s\n", dev->i4);
|
||||
if (dev->flags & WGDEVICE_HAS_I5)
|
||||
fprintf(f, "i5=%s\n", dev->i5);
|
||||
if (dev->flags & WGDEVICE_HAS_J1)
|
||||
fprintf(f, "j1=%s\n", dev->j1);
|
||||
if (dev->flags & WGDEVICE_HAS_J2)
|
||||
fprintf(f, "j2=%s\n", dev->j2);
|
||||
if (dev->flags & WGDEVICE_HAS_J3)
|
||||
fprintf(f, "j3=%s\n", dev->j3);
|
||||
if (dev->flags & WGDEVICE_HAS_ITIME)
|
||||
fprintf(f, "itime=%u\n", dev->itime);
|
||||
|
||||
for_each_wgpeer(dev, peer) {
|
||||
key_to_hex(hex, peer->public_key);
|
||||
fprintf(f, "public_key=%s\n", hex);
|
||||
|
@ -100,11 +77,6 @@ static int userspace_set_device(struct wgdevice *dev)
|
|||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (peer->flags & WGPEER_REMOVE_ME) {
|
||||
fprintf(f, "remove=true\n");
|
||||
continue;
|
||||
|
@ -248,12 +220,6 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
|
|||
} else if(!peer && !strcmp(key, "s2")) {
|
||||
dev->response_packet_junk_size = NUM(0xffffU);
|
||||
dev->flags |= WGDEVICE_HAS_S2;
|
||||
} else if(!peer && !strcmp(key, "s3")) {
|
||||
dev->cookie_reply_packet_junk_size = NUM(0xffffU);
|
||||
dev->flags |= WGDEVICE_HAS_S3;
|
||||
} else if(!peer && !strcmp(key, "s4")) {
|
||||
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->flags |= WGDEVICE_HAS_H1;
|
||||
|
@ -266,41 +232,6 @@ 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, "i1")) {
|
||||
dev->i1 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_I1;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "i2")) {
|
||||
dev->i2 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_I2;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "i3")) {
|
||||
dev->i3 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_I3;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "i4")) {
|
||||
dev->i4 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_I4;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "i5")) {
|
||||
dev->i5 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_I5;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "j1")) {
|
||||
dev->j1 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_J1;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "j2")) {
|
||||
dev->j2 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_J2;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "j3")) {
|
||||
dev->j3 = strdup(value);
|
||||
dev->flags |= WGDEVICE_HAS_J3;
|
||||
}
|
||||
else if (!peer && !strcmp(key, "itime")) {
|
||||
dev->itime = NUM(0xffffffffU);
|
||||
dev->flags |= WGDEVICE_HAS_ITIME;
|
||||
} else if (!strcmp(key, "public_key")) {
|
||||
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
|
||||
|
||||
|
|
|
@ -283,14 +283,6 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
|
|||
dev->response_packet_junk_size = wg_iface->ResponsePacketJunkSize;
|
||||
dev->flags |= WGDEVICE_HAS_S2;
|
||||
}
|
||||
if (wg_iface->Flags & WG_IOCTL_INTERFACE_S3) {
|
||||
dev->cookie_reply_packet_junk_size = wg_iface->CookieReplyPacketJunkSize;
|
||||
dev->flags |= WGDEVICE_HAS_S3;
|
||||
}
|
||||
if (wg_iface->Flags & WG_IOCTL_INTERFACE_S4) {
|
||||
dev->transport_packet_junk_size = wg_iface->TransportPacketJunkSize;
|
||||
dev->flags |= WGDEVICE_HAS_S4;
|
||||
}
|
||||
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H1) {
|
||||
dev->init_packet_magic_header = wg_iface->InitPacketMagicHeader;
|
||||
dev->flags |= WGDEVICE_HAS_H1;
|
||||
|
@ -307,67 +299,6 @@ 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
dev->itime = wg_iface->Itime;
|
||||
dev->flags |= WGDEVICE_HAS_ITIME;
|
||||
}
|
||||
|
||||
wg_peer = buf + sizeof(WG_IOCTL_INTERFACE);
|
||||
for (ULONG i = 0; i < wg_iface->PeersCount; ++i) {
|
||||
|
@ -515,14 +446,6 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
wg_iface->ResponsePacketJunkSize = dev->response_packet_junk_size;
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_S2;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_S3) {
|
||||
wg_iface->CookieReplyPacketJunkSize = dev->cookie_reply_packet_junk_size;
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_S3;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_S4) {
|
||||
wg_iface->TransportPacketJunkSize = dev->transport_packet_junk_size;
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_S4;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_H1) {
|
||||
wg_iface->InitPacketMagicHeader = dev->init_packet_magic_header;
|
||||
|
@ -544,68 +467,6 @@ static int kernel_set_device(struct wgdevice *dev)
|
|||
wg_iface->Flags |= WG_IOCTL_INTERFACE_H4;
|
||||
}
|
||||
|
||||
if (dev->flags & WGDEVICE_HAS_I1)
|
||||
{
|
||||
const size_t i1_size = strlen(dev->i1) + 1;
|
||||
wg_iface->I1 = (UCHAR*)malloc(i1_size);
|
||||
memcpy(wg_iface->I1, dev->i1, i1_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_I1;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_I2)
|
||||
{
|
||||
const size_t i2_size = strlen(dev->i2) + 1;
|
||||
wg_iface->I2 = (UCHAR*)malloc(i2_size);
|
||||
memcpy(wg_iface->I2, dev->i2, i2_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_I2;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_I3)
|
||||
{
|
||||
const size_t i3_size = strlen(dev->i3) + 1;
|
||||
wg_iface->I3 = (UCHAR*)malloc(i3_size);
|
||||
memcpy(wg_iface->I3, dev->i3, i3_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_I3;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_I4)
|
||||
{
|
||||
const size_t i4_size = strlen(dev->i4) + 1;
|
||||
wg_iface->I4 = (UCHAR*)malloc(i4_size);
|
||||
memcpy(wg_iface->I4, dev->i4, i4_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_I4;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_I5)
|
||||
{
|
||||
const size_t i5_size = strlen(dev->i5) + 1;
|
||||
wg_iface->I5 = (UCHAR*)malloc(i5_size);
|
||||
memcpy(wg_iface->I5, dev->i5, i5_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_I5;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_J1)
|
||||
{
|
||||
const size_t j1_size = strlen(dev->j1) + 1;
|
||||
wg_iface->J1 = (UCHAR*)malloc(j1_size);
|
||||
memcpy(wg_iface->J1, dev->j1, j1_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_J1;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_J2)
|
||||
{
|
||||
const size_t j2_size = strlen(dev->j2) + 1;
|
||||
wg_iface->J2 = (UCHAR*)malloc(j2_size);
|
||||
memcpy(wg_iface->J2, dev->j2, j2_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_J2;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_J3)
|
||||
{
|
||||
const size_t j3_size = strlen(dev->j3) + 1;
|
||||
wg_iface->J3 = (UCHAR*)malloc(j3_size);
|
||||
memcpy(wg_iface->J3, dev->j3, j3_size);
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_J3;
|
||||
}
|
||||
if (dev->flags & WGDEVICE_HAS_ITIME)
|
||||
{
|
||||
wg_iface->Itime = dev->itime;
|
||||
wg_iface->Flags |= WG_IOCTL_INTERFACE_ITIME;
|
||||
}
|
||||
|
||||
peer_count = 0;
|
||||
wg_peer = (void *)wg_iface + sizeof(WG_IOCTL_INTERFACE);
|
||||
for_each_wgpeer(dev, peer) {
|
||||
|
|
|
@ -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>] [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>] [i1 \"<taged_junk>\"] [i2 \"<taged_junk>\"] [i3 \"<taged_junk>\"] [i4 \"<taged_junk>\"] [i5 \"<taged_junk>\"] [j1 \"<taged_junk>\"] [j2 \"<taged_junk>\"] [j3 \"<taged_junk>\"] [itime <itimeout>][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>] [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;
|
||||
}
|
||||
|
||||
|
|
71
src/show.c
71
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 { <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 | i1 | i2 | i3 | i4 | i5 | j1 | j2 | j3 | itime]\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]\n", PROG_NAME, COMMAND_NAME);
|
||||
}
|
||||
|
||||
static void pretty_print(struct wgdevice *device)
|
||||
|
@ -230,10 +230,6 @@ static void pretty_print(struct wgdevice *device)
|
|||
terminal_printf(" " TERMINAL_BOLD "s1" TERMINAL_RESET ": %u\n", device->init_packet_junk_size);
|
||||
if (device->response_packet_junk_size)
|
||||
terminal_printf(" " TERMINAL_BOLD "s2" TERMINAL_RESET ": %u\n", device->response_packet_junk_size);
|
||||
if (device->cookie_reply_packet_junk_size)
|
||||
terminal_printf(" " TERMINAL_BOLD "s3" TERMINAL_RESET ": %u\n", device->cookie_reply_packet_junk_size);
|
||||
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);
|
||||
if (device->response_packet_magic_header)
|
||||
|
@ -242,25 +238,6 @@ 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->i1)
|
||||
terminal_printf(" " TERMINAL_BOLD "i1" TERMINAL_RESET ": %s\n", device->i1);
|
||||
if (device->i2)
|
||||
terminal_printf(" " TERMINAL_BOLD "i2" TERMINAL_RESET ": %s\n", device->i2);
|
||||
if (device->i3)
|
||||
terminal_printf(" " TERMINAL_BOLD "i3" TERMINAL_RESET ": %s\n", device->i3);
|
||||
if (device->i4)
|
||||
terminal_printf(" " TERMINAL_BOLD "i4" TERMINAL_RESET ": %s\n", device->i4);
|
||||
if (device->i5)
|
||||
terminal_printf(" " TERMINAL_BOLD "i5" TERMINAL_RESET ": %s\n", device->i5);
|
||||
if (device->j1)
|
||||
terminal_printf(" " TERMINAL_BOLD "j1" TERMINAL_RESET ": %s\n", device->j1);
|
||||
if (device->j2)
|
||||
terminal_printf(" " TERMINAL_BOLD "j2" TERMINAL_RESET ": %s\n", device->j2);
|
||||
if (device->j3)
|
||||
terminal_printf(" " TERMINAL_BOLD "j3" TERMINAL_RESET ": %s\n", device->j3);
|
||||
if (device->itime)
|
||||
terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %u\n", device->itime);
|
||||
|
||||
if (device->first_peer) {
|
||||
sort_peers(device);
|
||||
terminal_printf("\n");
|
||||
|
@ -310,16 +287,6 @@ 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->i1);
|
||||
printf("%s\t", device->i2);
|
||||
printf("%s\t", device->i3);
|
||||
printf("%s\t", device->i4);
|
||||
printf("%s\t", device->i5);
|
||||
printf("%s\t", device->j1);
|
||||
printf("%s\t", device->j2);
|
||||
printf("%s\t", device->j3);
|
||||
printf("%u\t", device->itime);
|
||||
|
||||
if (device->fwmark)
|
||||
printf("0x%x\n", device->fwmark);
|
||||
else
|
||||
|
@ -407,42 +374,6 @@ 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, "i1")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->i1);
|
||||
} else if(!strcmp(param, "i2")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->i2);
|
||||
} else if(!strcmp(param, "i3")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->i3);
|
||||
} else if(!strcmp(param, "i4")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->i4);
|
||||
} else if(!strcmp(param, "i5")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->i5);
|
||||
} else if(!strcmp(param, "j1")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->j1);
|
||||
} else if(!strcmp(param, "j2")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->j2);
|
||||
} else if(!strcmp(param, "j3")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%s\n", device->j3);
|
||||
} else if(!strcmp(param, "itime")) {
|
||||
if (with_interface)
|
||||
printf("%s\t", device->name);
|
||||
printf("%u\n", device->itime);
|
||||
} else if (!strcmp(param, "endpoints")) {
|
||||
for_each_wgpeer(device, peer) {
|
||||
if (with_interface)
|
||||
|
|
|
@ -56,10 +56,6 @@ int showconf_main(int argc, const char *argv[])
|
|||
printf("S1 = %u\n", device->init_packet_junk_size);
|
||||
if (device->flags & WGDEVICE_HAS_S2)
|
||||
printf("S2 = %u\n", device->response_packet_junk_size);
|
||||
if (device->flags & WGDEVICE_HAS_S3)
|
||||
printf("S3 = %u\n", device->cookie_reply_packet_junk_size);
|
||||
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);
|
||||
if (device->flags & WGDEVICE_HAS_H2)
|
||||
|
@ -68,24 +64,6 @@ 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_I1)
|
||||
printf("I1 = %s\n", device->i1);
|
||||
if (device->flags & WGDEVICE_HAS_I2)
|
||||
printf("I2 = %s\n", device->i2);
|
||||
if (device->flags & WGDEVICE_HAS_I3)
|
||||
printf("I3 = %s\n", device->i3);
|
||||
if (device->flags & WGDEVICE_HAS_I4)
|
||||
printf("I4 = %s\n", device->i4);
|
||||
if (device->flags & WGDEVICE_HAS_I5)
|
||||
printf("I5 = %s\n", device->i5);
|
||||
if (device->flags & WGDEVICE_HAS_J1)
|
||||
printf("J1 = %s\n", device->j1);
|
||||
if (device->flags & WGDEVICE_HAS_J2)
|
||||
printf("J2 = %s\n", device->j2);
|
||||
if (device->flags & WGDEVICE_HAS_J3)
|
||||
printf("J3 = %s\n", device->j3);
|
||||
if (device->flags & WGDEVICE_HAS_ITIME)
|
||||
printf("Itime = %u\n", device->itime);
|
||||
|
||||
printf("\n");
|
||||
for_each_wgpeer(device, peer) {
|
||||
|
@ -98,9 +76,6 @@ int showconf_main(int argc, const char *argv[])
|
|||
if (peer->flags & WGPEER_HAS_ADVANCED_SECURITY) {
|
||||
printf("AdvancedSecurity = %s\n", peer->advanced_security ? "on" : "off");
|
||||
}
|
||||
if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE) {
|
||||
printf("SpecialHandshake = %s\n", peer->special_handshake ? "on" : "off");
|
||||
}
|
||||
if (peer->first_allowedip)
|
||||
printf("AllowedIPs = ");
|
||||
for_each_wgallowedip(peer, allowedip) {
|
||||
|
|
|
@ -114,9 +114,6 @@
|
|||
* WGPEER_A_ADVANCED_SECURITY: flag indicating that advanced security
|
||||
* techniques provided by AmneziaWG should
|
||||
* be used.
|
||||
* WGPEER_A_SPECIAL_HANDSHAKE: flag indicating that special handshake
|
||||
* techniques provided by AmneziaWG should
|
||||
* be used.
|
||||
* 0: NLA_NESTED
|
||||
* ...
|
||||
* ...
|
||||
|
@ -150,9 +147,6 @@
|
|||
* WGPEER_A_ADVANCED_SECURITY: flag indicating that advanced security
|
||||
* techniques provided by AmneziaWG should
|
||||
* be used.
|
||||
* WGPEER_A_SPECIAL_HANDSHAKE: flag indicating that special handshake
|
||||
* techniques provided by AmneziaWG should
|
||||
* be used.
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -193,21 +187,10 @@ enum wgdevice_attribute {
|
|||
WGDEVICE_A_JMAX,
|
||||
WGDEVICE_A_S1,
|
||||
WGDEVICE_A_S2,
|
||||
WGDEVICE_A_S3,
|
||||
WGDEVICE_A_S4,
|
||||
WGDEVICE_A_H1,
|
||||
WGDEVICE_A_H2,
|
||||
WGDEVICE_A_H3,
|
||||
WGDEVICE_A_H4,
|
||||
WGDEVICE_A_I1,
|
||||
WGDEVICE_A_I2,
|
||||
WGDEVICE_A_I3,
|
||||
WGDEVICE_A_I4,
|
||||
WGDEVICE_A_I5,
|
||||
WGDEVICE_A_J1,
|
||||
WGDEVICE_A_J2,
|
||||
WGDEVICE_A_J3,
|
||||
WGDEVICE_A_ITIME,
|
||||
WGDEVICE_A_PEER,
|
||||
__WGDEVICE_A_LAST
|
||||
};
|
||||
|
@ -218,7 +201,6 @@ enum wgpeer_flag {
|
|||
WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
|
||||
WGPEER_F_UPDATE_ONLY = 1U << 2,
|
||||
WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3,
|
||||
WGPEER_F_HAS_SPECIAL_HANDSHAKE = 1U << 4,
|
||||
__WGPEER_F_ALL = WGPEER_F_REMOVE_ME | WGPEER_F_REPLACE_ALLOWEDIPS |
|
||||
WGPEER_F_UPDATE_ONLY
|
||||
};
|
||||
|
@ -235,7 +217,6 @@ enum wgpeer_attribute {
|
|||
WGPEER_A_ALLOWEDIPS,
|
||||
WGPEER_A_PROTOCOL_VERSION,
|
||||
WGPEER_A_ADVANCED_SECURITY,
|
||||
WGPEER_A_SPECIAL_HANDSHAKE,
|
||||
__WGPEER_A_LAST
|
||||
};
|
||||
#define WGPEER_A_MAX (__WGPEER_A_LAST - 1)
|
||||
|
|
|
@ -67,31 +67,20 @@ struct wg_peer_io {
|
|||
struct wg_aip_io p_aips[];
|
||||
};
|
||||
|
||||
#define WG_INTERFACE_HAS_PUBLIC (1 << 0)
|
||||
#define WG_INTERFACE_HAS_PRIVATE (1 << 1)
|
||||
#define WG_INTERFACE_HAS_PORT (1 << 2)
|
||||
#define WG_INTERFACE_HAS_RTABLE (1 << 3)
|
||||
#define WG_INTERFACE_REPLACE_PEERS (1 << 4)
|
||||
#define WG_INTERFACE_DEVICE_HAS_JC (1 << 5)
|
||||
#define WG_INTERFACE_HAS_PUBLIC (1 << 0)
|
||||
#define WG_INTERFACE_HAS_PRIVATE (1 << 1)
|
||||
#define WG_INTERFACE_HAS_PORT (1 << 2)
|
||||
#define WG_INTERFACE_HAS_RTABLE (1 << 3)
|
||||
#define WG_INTERFACE_REPLACE_PEERS (1 << 4)
|
||||
#define WG_INTERFACE_DEVICE_HAS_JC (1 << 5)
|
||||
#define WG_INTERFACE_DEVICE_HAS_JMIN (1 << 6)
|
||||
#define WG_INTERFACE_DEVICE_HAS_JMAX (1 << 7)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S1 (1 << 8)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S2 (1 << 9)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S3 (1 << 10)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S4 (1 << 11)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H1 (1 << 12)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H2 (1 << 13)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H3 (1 << 14)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H4 (1 << 15)
|
||||
#define WG_INTERFACE_DEVICE_HAS_I1 (1 << 16)
|
||||
#define WG_INTERFACE_DEVICE_HAS_I2 (1 << 17)
|
||||
#define WG_INTERFACE_DEVICE_HAS_I3 (1 << 18)
|
||||
#define WG_INTERFACE_DEVICE_HAS_I4 (1 << 19)
|
||||
#define WG_INTERFACE_DEVICE_HAS_I5 (1 << 20)
|
||||
#define WG_INTERFACE_DEVICE_HAS_J1 (1 << 21)
|
||||
#define WG_INTERFACE_DEVICE_HAS_J2 (1 << 22)
|
||||
#define WG_INTERFACE_DEVICE_HAS_J3 (1 << 23)
|
||||
#define WG_INTERFACE_DEVICE_HAS_ITIME (1 << 24)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S1 (1 << 8)
|
||||
#define WG_INTERFACE_DEVICE_HAS_S2 (1 << 9)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H1 (1 << 10)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H2 (1 << 11)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H3 (1 << 12)
|
||||
#define WG_INTERFACE_DEVICE_HAS_H4 (1 << 13)
|
||||
|
||||
struct wg_interface_io {
|
||||
uint16_t i_flags;
|
||||
|
@ -107,22 +96,10 @@ struct wg_interface_io {
|
|||
uint16_t i_junk_packet_max_size;
|
||||
uint16_t i_init_packet_junk_size;
|
||||
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_i1;
|
||||
uint8_t* i_i2;
|
||||
uint8_t* i_i3;
|
||||
uint8_t* i_i4;
|
||||
uint8_t* i_i5;
|
||||
uint8_t* i_j1;
|
||||
uint8_t* i_j2;
|
||||
uint8_t* i_j3;
|
||||
uint32_t i_itime;
|
||||
};
|
||||
|
||||
struct wg_data_io {
|
||||
|
|
|
@ -63,21 +63,10 @@ typedef enum
|
|||
WG_IOCTL_INTERFACE_JMAX = 1 << 7,
|
||||
WG_IOCTL_INTERFACE_S1 = 1 << 8,
|
||||
WG_IOCTL_INTERFACE_S2 = 1 << 9,
|
||||
WG_IOCTL_INTERFACE_S3 = 1 << 10,
|
||||
WG_IOCTL_INTERFACE_S4 = 1 << 11,
|
||||
WG_IOCTL_INTERFACE_H1 = 1 << 12,
|
||||
WG_IOCTL_INTERFACE_H2 = 1 << 12,
|
||||
WG_IOCTL_INTERFACE_H3 = 1 << 13,
|
||||
WG_IOCTL_INTERFACE_H4 = 1 << 14,
|
||||
WG_IOCTL_INTERFACE_I1 = 1U << 15,
|
||||
WG_IOCTL_INTERFACE_I2 = 1U << 16,
|
||||
WG_IOCTL_INTERFACE_I3 = 1U << 17,
|
||||
WG_IOCTL_INTERFACE_I4 = 1U << 18,
|
||||
WG_IOCTL_INTERFACE_I5 = 1U << 19,
|
||||
WG_IOCTL_INTERFACE_J1 = 1U << 20,
|
||||
WG_IOCTL_INTERFACE_J2 = 1U << 21,
|
||||
WG_IOCTL_INTERFACE_J3 = 1U << 22,
|
||||
WG_IOCTL_INTERFACE_ITIME = 1U << 23
|
||||
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_FLAG;
|
||||
|
||||
typedef struct _WG_IOCTL_INTERFACE
|
||||
|
@ -92,22 +81,10 @@ typedef struct _WG_IOCTL_INTERFACE
|
|||
USHORT JunkPacketMaxSize;
|
||||
USHORT InitPacketJunkSize;
|
||||
USHORT ResponsePacketJunkSize;
|
||||
USHORT CookieReplyPacketJunkSize;
|
||||
USHORT TransportPacketJunkSize;
|
||||
ULONG InitPacketMagicHeader;
|
||||
ULONG ResponsePacketMagicHeader;
|
||||
ULONG UnderloadPacketMagicHeader;
|
||||
ULONG TransportPacketMagicHeader;
|
||||
|
||||
UCHAR* I1;
|
||||
UCHAR* I2;
|
||||
UCHAR* I3;
|
||||
UCHAR* I4;
|
||||
UCHAR* I5;
|
||||
UCHAR* J1;
|
||||
UCHAR* J2;
|
||||
UCHAR* J3;
|
||||
ULONG Itime;
|
||||
} __attribute__((aligned(8))) WG_IOCTL_INTERFACE;
|
||||
|
||||
#define WG_IOCTL_GET CTL_CODE(45208U, 321, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
|
|
|
@ -42,7 +42,6 @@ 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 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_asecurity_on)
|
||||
cmd("amneziawg-go %s", iface);
|
||||
else
|
||||
cmd("ip link add %s type amneziawg", iface);
|
||||
|
@ -1279,24 +1278,6 @@ 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, "I1=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "I2=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "I3=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "I4=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "I5=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "J1=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "J2=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "J3=", 3) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
} else if (!strncasecmp(clean, "Itime=", 6) && j > 4) {
|
||||
is_special_handshake_on = true;
|
||||
}
|
||||
}
|
||||
*config = concat_and_free(*config, "", line);
|
||||
|
@ -1341,4 +1322,4 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
2
src/wg.c
2
src/wg.c
|
@ -42,7 +42,7 @@ int main(int argc, const char *argv[])
|
|||
PROG_NAME = argv[0];
|
||||
|
||||
if (argc == 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version") || !strcmp(argv[1], "version"))) {
|
||||
printf("amneziawg-tools v%s - https://amnezia.org\n", WIREGUARD_TOOLS_VERSION);
|
||||
printf("wireguard-tools v%s - https://git.zx2c4.com/wireguard-tools/\n", WIREGUARD_TOOLS_VERSION);
|
||||
return 0;
|
||||
}
|
||||
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "help"))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue