aboutsummaryrefslogtreecommitdiffstats
path: root/wg-dynamic-client.c
diff options
context:
space:
mode:
authorThomas Gschwantner <tharre3@gmail.com>2019-12-11 03:58:04 +0100
committerThomas Gschwantner <tharre3@gmail.com>2019-12-11 06:22:17 +0100
commitf10e95340d9b99942fc594b642c4afcd829beed9 (patch)
tree329d5e2a827e8f0a6ac9ac214c9a14e1d7dca3af /wg-dynamic-client.c
parentPostpone freeing memory for leases until after updating allowedips (diff)
downloadwg-dynamic-f10e95340d9b99942fc594b642c4afcd829beed9.tar.xz
wg-dynamic-f10e95340d9b99942fc594b642c4afcd829beed9.zip
Change request_ip protocol
ipv4 and ipv6 keys have been combined into one common key, ip. To distinguish between multiple IPs in later versions ip=0.0.0.0/32 and ip=::/128 respectively now mean we want to be assigned a random address from the server. Releasing/not wanting an IP is now done by just not listing that IP, i.e. if we only wanted an (random) ipv4 address the request would look as follows: request_ip=1 ip=0.0.0.0/32
Diffstat (limited to 'wg-dynamic-client.c')
-rw-r--r--wg-dynamic-client.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/wg-dynamic-client.c b/wg-dynamic-client.c
index 2edb413..7284e3b 100644
--- a/wg-dynamic-client.c
+++ b/wg-dynamic-client.c
@@ -42,9 +42,9 @@ static void usage()
static void cleanup()
{
if (ipv4_assigned && ipm_deladdr_v4(device->ifindex, &ipv4))
- debug("Failed to cleanup ipv4 address");
+ debug("Failed to cleanup ipv4 address\n");
if (ipv6_assigned && ipm_deladdr_v6(device->ifindex, &ipv6))
- debug("Failed to cleanup ipv6 address");
+ debug("Failed to cleanup ipv6 address\n");
if (sockfd >= 0)
close(sockfd);
@@ -111,14 +111,12 @@ static int request_ip(struct wg_dynamic_request_ip *rip)
if (connect(sockfd, (struct sockaddr *)&dstaddr, sizeof(dstaddr)))
fatal("connect()");
- if (ipv4_assigned) {
+ rip->has_ipv4 = rip->has_ipv6 = true;
+ if (ipv4_assigned)
memcpy(&rip->ipv4, &ipv4, sizeof rip->ipv4);
- rip->has_ipv4 = true;
- }
- if (ipv6_assigned) {
+
+ if (ipv6_assigned)
memcpy(&rip->ipv6, &ipv6, sizeof rip->ipv6);
- rip->has_ipv6 = true;
- }
msglen = serialize_request_ip(true, (char *)buf, RECV_BUFSIZE, rip);
do {