diff options
author | Linus Nordberg <linus@nordberg.se> | 2019-04-08 12:14:50 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2019-04-08 12:14:50 +0200 |
commit | 1b76dc7b38624136838580ea5853189c43b4236d (patch) | |
tree | cbc00d2632aaaf983c584ead87fe58beb6cc182b | |
parent | Correct logic in log_warn, log_info (diff) | |
download | wg-dynamic-1b76dc7b38624136838580ea5853189c43b4236d.tar.xz wg-dynamic-1b76dc7b38624136838580ea5853189c43b4236d.zip |
Use a fixed low TCP port
970 is the ASCII sum of the string "wireguard" and is also not
registered by by IANA.
-rw-r--r-- | common.h | 2 | ||||
-rw-r--r-- | wg-dynamic-client.c | 13 |
2 files changed, 4 insertions, 11 deletions
@@ -22,7 +22,7 @@ #define MAX_RESPONSE_SIZE 8192 static const char WG_DYNAMIC_ADDR[] = "fe80::"; -static const uint16_t WG_DYNAMIC_PORT = 1337; +static const uint16_t WG_DYNAMIC_PORT = 970; #define WG_DYNAMIC_LEASETIME 10 /* NOTE: 10s is good for testing purposes */ diff --git a/wg-dynamic-client.c b/wg-dynamic-client.c index 2838eaf..cf9d941 100644 --- a/wg-dynamic-client.c +++ b/wg-dynamic-client.c @@ -20,7 +20,6 @@ #include "netlink.h" #define LEASE_CHECK_INTERVAL 1000 /* 1s is convenient for testing */ -#define LOW_PORT_START 214 int DBG_LVL = 3; @@ -200,6 +199,7 @@ static int do_connect(int *fd) struct sockaddr_in6 our_addr = { .sin6_family = AF_INET6, .sin6_addr = our_lladdr, + .sin6_port = htons(WG_DYNAMIC_PORT), .sin6_scope_id = device->ifindex, }; struct sockaddr_in6 their_addr = { @@ -212,15 +212,8 @@ static int do_connect(int *fd) if (*fd < 0) fatal("Creating a socket failed"); - for (int port = LOW_PORT_START;; port++) { - our_addr.sin6_port = htons(port); - if (!bind(*fd, (struct sockaddr *)&our_addr, sizeof(our_addr))) - break; - if (errno != EADDRINUSE) - fatal("Binding socket failed"); - if (port >= 1024) - die("No low ports available"); - } + if (bind(*fd, (struct sockaddr *)&our_addr, sizeof(our_addr))) + fatal("Binding socket failed"); if (!inet_pton(AF_INET6, WG_DYNAMIC_ADDR, &their_addr.sin6_addr)) fatal("inet_pton()"); |