mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-08-02 09:32:51 +02:00
fix: after review
This commit is contained in:
parent
191c06c14c
commit
5d3c2a6096
4 changed files with 52 additions and 52 deletions
34
src/config.c
34
src/config.c
|
@ -410,7 +410,7 @@ err:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool parse_string(char **device_value, const char *name, const char *value) {
|
static inline bool parse_awg_string(char **device_value, const char *name, const char *value) {
|
||||||
size_t len = strlen(value);
|
size_t len = strlen(value);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
fprintf(stderr, "Unable to parse empty string for: %s\n", name);
|
fprintf(stderr, "Unable to parse empty string for: %s\n", name);
|
||||||
|
@ -575,35 +575,35 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_H4;
|
ctx->device->flags |= WGDEVICE_HAS_H4;
|
||||||
} else if (key_match("I1")) {
|
} else if (key_match("I1")) {
|
||||||
ret = parse_string(&ctx->device->i1, "I1", value);
|
ret = parse_awg_string(&ctx->device->i1, "I1", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_I1;
|
ctx->device->flags |= WGDEVICE_HAS_I1;
|
||||||
} else if (key_match("I2")) {
|
} else if (key_match("I2")) {
|
||||||
ret = parse_string(&ctx->device->i2, "I2", value);
|
ret = parse_awg_string(&ctx->device->i2, "I2", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_I2;
|
ctx->device->flags |= WGDEVICE_HAS_I2;
|
||||||
} else if (key_match("I3")) {
|
} else if (key_match("I3")) {
|
||||||
ret = parse_string(&ctx->device->i3, "I3", value);
|
ret = parse_awg_string(&ctx->device->i3, "I3", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_I3;
|
ctx->device->flags |= WGDEVICE_HAS_I3;
|
||||||
} else if (key_match("I4")) {
|
} else if (key_match("I4")) {
|
||||||
ret = parse_string(&ctx->device->i4, "I4", value);
|
ret = parse_awg_string(&ctx->device->i4, "I4", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_I4;
|
ctx->device->flags |= WGDEVICE_HAS_I4;
|
||||||
} else if (key_match("I5")) {
|
} else if (key_match("I5")) {
|
||||||
ret = parse_string(&ctx->device->i5, "I5", value);
|
ret = parse_awg_string(&ctx->device->i5, "I5", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_I5;
|
ctx->device->flags |= WGDEVICE_HAS_I5;
|
||||||
} else if (key_match("J1")) {
|
} else if (key_match("J1")) {
|
||||||
ret = parse_string(&ctx->device->j1, "J1", value);
|
ret = parse_awg_string(&ctx->device->j1, "J1", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_J1;
|
ctx->device->flags |= WGDEVICE_HAS_J1;
|
||||||
} else if (key_match("J2")) {
|
} else if (key_match("J2")) {
|
||||||
ret = parse_string(&ctx->device->j2, "J2", value);
|
ret = parse_awg_string(&ctx->device->j2, "J2", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_J2;
|
ctx->device->flags |= WGDEVICE_HAS_J2;
|
||||||
} else if (key_match("J3")) {
|
} else if (key_match("J3")) {
|
||||||
ret = parse_string(&ctx->device->j3, "J3", value);
|
ret = parse_awg_string(&ctx->device->j3, "J3", value);
|
||||||
if (ret)
|
if (ret)
|
||||||
ctx->device->flags |= WGDEVICE_HAS_J3;
|
ctx->device->flags |= WGDEVICE_HAS_J3;
|
||||||
} else if (key_match("Itime")) {
|
} else if (key_match("Itime")) {
|
||||||
|
@ -850,56 +850,56 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
} else if (!strcmp(argv[0], "i1") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "i1") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->i1, "i1", argv[1]))
|
if (!parse_awg_string(&device->i1, "i1", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_I1;
|
device->flags |= WGDEVICE_HAS_I1;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
} else if (!strcmp(argv[0], "i2") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "i2") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->i2, "i2", argv[1]))
|
if (!parse_awg_string(&device->i2, "i2", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_I2;
|
device->flags |= WGDEVICE_HAS_I2;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "i3") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "i3") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->i3, "i3", argv[1]))
|
if (!parse_awg_string(&device->i3, "i3", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_I3;
|
device->flags |= WGDEVICE_HAS_I3;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "i4") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "i4") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->i4, "i4", argv[1]))
|
if (!parse_awg_string(&device->i4, "i4", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_I4;
|
device->flags |= WGDEVICE_HAS_I4;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "i5") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "i5") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->i5, "i5", argv[1]))
|
if (!parse_awg_string(&device->i5, "i5", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_I5;
|
device->flags |= WGDEVICE_HAS_I5;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "j1") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "j1") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->j1, "j1", argv[1]))
|
if (!parse_awg_string(&device->j1, "j1", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_J1;
|
device->flags |= WGDEVICE_HAS_J1;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "j2") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "j2") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->j2, "j2", argv[1]))
|
if (!parse_awg_string(&device->j2, "j2", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_J2;
|
device->flags |= WGDEVICE_HAS_J2;
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -=2;
|
argc -=2;
|
||||||
} else if (!strcmp(argv[0], "j3") && argc >= 2 && !peer) {
|
} else if (!strcmp(argv[0], "j3") && argc >= 2 && !peer) {
|
||||||
if (!parse_string(&device->j3, "j3", argv[1]))
|
if (!parse_awg_string(&device->j3, "j3", argv[1]))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->flags |= WGDEVICE_HAS_J3;
|
device->flags |= WGDEVICE_HAS_J3;
|
||||||
|
|
|
@ -640,57 +640,57 @@ static int kernel_set_device(struct wgdevice* dev)
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_I1)
|
if (dev->flags & WG_DEVICE_HAS_I1)
|
||||||
{
|
{
|
||||||
const size_t i1_size = strlen(dev->i1);
|
const size_t i1_size = strlen(dev->i1) + 1;
|
||||||
wg_iface->I1 = (UCHAR*)malloc(i1_size + 1);
|
wg_iface->I1 = (UCHAR*)malloc(i1_size);
|
||||||
memcpy(wg_iface->I1, dev->i1, i1_size);
|
memcpy(wg_iface->I1, dev->i1, i1_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_I1;
|
dev->flags |= WG_IOCTL_INTERFACE_I1;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_I2)
|
if (dev->flags & WG_DEVICE_HAS_I2)
|
||||||
{
|
{
|
||||||
const size_t i2_size = strlen(dev->i2);
|
const size_t i2_size = strlen(dev->i2) + 1;
|
||||||
wg_iface->I2 = (UCHAR*)malloc(i2_size + 1);
|
wg_iface->I2 = (UCHAR*)malloc(i2_size);
|
||||||
memcpy(wg_iface->I2, dev->i2, i2_size);
|
memcpy(wg_iface->I2, dev->i2, i2_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_I2;
|
dev->flags |= WG_IOCTL_INTERFACE_I2;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_I3)
|
if (dev->flags & WG_DEVICE_HAS_I3)
|
||||||
{
|
{
|
||||||
const size_t i3_size = strlen(dev->i3);
|
const size_t i3_size = strlen(dev->i3) + 1;
|
||||||
wg_iface->I3 = (UCHAR*)malloc(i3_size + 1);
|
wg_iface->I3 = (UCHAR*)malloc(i3_size);
|
||||||
memcpy(wg_iface->I3, dev->i3, i3_size);
|
memcpy(wg_iface->I3, dev->i3, i3_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_I3;
|
dev->flags |= WG_IOCTL_INTERFACE_I3;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_I4)
|
if (dev->flags & WG_DEVICE_HAS_I4)
|
||||||
{
|
{
|
||||||
const size_t i4_size = strlen(dev->i4);
|
const size_t i4_size = strlen(dev->i4) + 1;
|
||||||
wg_iface->I4 = (UCHAR*)malloc(i4_size + 1);
|
wg_iface->I4 = (UCHAR*)malloc(i4_size);
|
||||||
memcpy(wg_iface->I4, dev->i4, i4_size);
|
memcpy(wg_iface->I4, dev->i4, i4_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_I4;
|
dev->flags |= WG_IOCTL_INTERFACE_I4;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_I5)
|
if (dev->flags & WG_DEVICE_HAS_I5)
|
||||||
{
|
{
|
||||||
const size_t i5_size = strlen(dev->i5);
|
const size_t i5_size = strlen(dev->i5) + 1;
|
||||||
wg_iface->I5 = (UCHAR*)malloc(i5_size + 1);
|
wg_iface->I5 = (UCHAR*)malloc(i5_size);
|
||||||
memcpy(wg_iface->I5, dev->i5, i5_size);
|
memcpy(wg_iface->I5, dev->i5, i5_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_I5;
|
dev->flags |= WG_IOCTL_INTERFACE_I5;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_J1)
|
if (dev->flags & WG_DEVICE_HAS_J1)
|
||||||
{
|
{
|
||||||
const size_t j1_size = strlen(dev->j1);
|
const size_t j1_size = strlen(dev->j1) + 1;
|
||||||
wg_iface->J1 = (UCHAR*)malloc(j1_size + 1);
|
wg_iface->J1 = (UCHAR*)malloc(j1_size);
|
||||||
memcpy(wg_iface->J1, dev->j1, j1_size);
|
memcpy(wg_iface->J1, dev->j1, j1_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_J1;
|
dev->flags |= WG_IOCTL_INTERFACE_J1;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_J2)
|
if (dev->flags & WG_DEVICE_HAS_J2)
|
||||||
{
|
{
|
||||||
const size_t j2_size = strlen(dev->j2);
|
const size_t j2_size = strlen(dev->j2) + 1;
|
||||||
wg_iface->J2 = (UCHAR*)malloc(j2_size + 1);
|
wg_iface->J2 = (UCHAR*)malloc(j2_size);
|
||||||
memcpy(wg_iface->J2, dev->j2, j2_size);
|
memcpy(wg_iface->J2, dev->j2, j2_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_J2;
|
dev->flags |= WG_IOCTL_INTERFACE_J2;
|
||||||
}
|
}
|
||||||
if (dev->flags & WG_DEVICE_HAS_J3)
|
if (dev->flags & WG_DEVICE_HAS_J3)
|
||||||
{
|
{
|
||||||
const size_t j3_size = strlen(dev->j3);
|
const size_t j3_size = strlen(dev->j3) + 1;
|
||||||
wg_iface->J3 = (UCHAR*)malloc(j3_size + 1);
|
wg_iface->J3 = (UCHAR*)malloc(j3_size);
|
||||||
memcpy(wg_iface->J3, dev->j3, j3_size);
|
memcpy(wg_iface->J3, dev->j3, j3_size);
|
||||||
dev->flags |= WG_IOCTL_INTERFACE_J3;
|
dev->flags |= WG_IOCTL_INTERFACE_J3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ static void pretty_print(struct wgdevice *device)
|
||||||
if (device->j3)
|
if (device->j3)
|
||||||
terminal_printf(" " TERMINAL_BOLD "j3" TERMINAL_RESET ": %s\n", device->j3);
|
terminal_printf(" " TERMINAL_BOLD "j3" TERMINAL_RESET ": %s\n", device->j3);
|
||||||
if (device->itime)
|
if (device->itime)
|
||||||
terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %d\n", device->itime);
|
terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %u\n", device->itime);
|
||||||
|
|
||||||
if (device->first_peer) {
|
if (device->first_peer) {
|
||||||
sort_peers(device);
|
sort_peers(device);
|
||||||
|
@ -314,7 +314,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
|
||||||
printf("%s\t", device->j1);
|
printf("%s\t", device->j1);
|
||||||
printf("%s\t", device->j2);
|
printf("%s\t", device->j2);
|
||||||
printf("%s\t", device->j3);
|
printf("%s\t", device->j3);
|
||||||
printf("%d\t", device->itime);
|
printf("%u\t", device->itime);
|
||||||
|
|
||||||
if (device->fwmark)
|
if (device->fwmark)
|
||||||
printf("0x%x\n", device->fwmark);
|
printf("0x%x\n", device->fwmark);
|
||||||
|
@ -438,7 +438,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
|
||||||
} else if(!strcmp(param, "itime")) {
|
} else if(!strcmp(param, "itime")) {
|
||||||
if (with_interface)
|
if (with_interface)
|
||||||
printf("%s\t", device->name);
|
printf("%s\t", device->name);
|
||||||
printf("%d\n", device->itime);
|
printf("%u\n", device->itime);
|
||||||
} else if (!strcmp(param, "endpoints")) {
|
} else if (!strcmp(param, "endpoints")) {
|
||||||
for_each_wgpeer(device, peer) {
|
for_each_wgpeer(device, peer) {
|
||||||
if (with_interface)
|
if (with_interface)
|
||||||
|
|
|
@ -1278,23 +1278,23 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
|
||||||
is_asecurity_on = true;
|
is_asecurity_on = true;
|
||||||
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
|
||||||
is_asecurity_on = true;
|
is_asecurity_on = true;
|
||||||
} else if (!strncasecmp(clean, "I1", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "I1=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "I2", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "I2=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "I3", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "I3=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "I4", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "I4=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "I5", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "I5=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "J1", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "J1=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "J2", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "J2=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "J3", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "J3=", 3) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
} else if (!strncasecmp(clean, "Itime", 3) && j > 4) {
|
} else if (!strncasecmp(clean, "Itime=", 6) && j > 4) {
|
||||||
is_special_handshake_on = true;
|
is_special_handshake_on = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue