diff --git a/tests/test_icmp_proxy.c b/tests/test_icmp_proxy.c index 9af5c62e..39df9179 100644 --- a/tests/test_icmp_proxy.c +++ b/tests/test_icmp_proxy.c @@ -6,6 +6,7 @@ #include #include "../lib/platform_compat.h" #include "test_utils.h" +#include "test_net.h" #ifndef _WIN32 #include #include @@ -44,8 +45,8 @@ static const char* cfg_node_client(void) { "my_public_key=ce8871f07fa056c636d297115f231b08c29cdf94e0d440fce83a07c34416d36a\n" "tun_ip=10.99.0.1/24\n" "tun_ifname=tun99\n" - "[server: s1]\naddr=127.0.0.1:9081\ntype=public\n" - "[client: c1]\nkeepalive=1\nlink=s1:127.0.0.1:9082\n" + "[server: s1]\naddr=127.0.0.1:0\ntype=public\n" + "[client: c1]\nkeepalive=1\nlink=s1:127.0.0.1:0\n" "peer_public_key=b3193173def895bd0fcea6f86af077c7d77216f10395275f627ac18242ec0f01\n" "[tcp_proxy_client]\n" "enabled=yes\n" @@ -63,7 +64,7 @@ static const char* cfg_node_exit(void) { "my_public_key=b3193173def895bd0fcea6f86af077c7d77216f10395275f627ac18242ec0f01\n" "tun_ip=10.99.0.2/24\n" "tun_ifname=tun98\n" - "[server: s1]\naddr=127.0.0.1:9082\ntype=public\n" + "[server: s1]\naddr=127.0.0.1:0\ntype=public\n" "[allowed_keys]\nallow_all=1\n" "[tcp_proxy_server]\nenabled=yes\n"); return buf; @@ -155,6 +156,7 @@ int main(void) { exit_node = utun_instance_create_from_str(ua, cfg_node_exit()); if (!exit_node) { printf("[FAIL] exit instance create\n"); goto done; } + test_etcp_set_peer(cli, "c1", exit_node, "s1"); if (utun_instance_init(cli) < 0) { printf("[FAIL] client init\n"); goto done; } if (utun_instance_init(exit_node) < 0) { printf("[FAIL] exit init\n"); goto done; } diff --git a/tests/test_nat_transport.c b/tests/test_nat_transport.c index 69a4a363..057f0046 100644 --- a/tests/test_nat_transport.c +++ b/tests/test_nat_transport.c @@ -15,6 +15,7 @@ #include #include #include "test_utils.h" +#include "test_net.h" #include "etcp.h" #include "etcp_connections.h" #include "../src/config_parser.h" @@ -103,7 +104,7 @@ static int create_temp_configs(void) { "tun_test_mode=1\n" "\n" "[server:prov]\n" - "addr=127.0.0.1:39101\n" + "addr=127.0.0.1:0\n" "type=public\n" "\n" "[allowed_keys]\n" @@ -129,13 +130,13 @@ static int create_temp_configs(void) { "tun_test_mode=1\n" "\n" "[server:cl]\n" - "addr=127.0.0.1:39102\n" + "addr=127.0.0.1:0\n" "type=public\n" "\n" "[client:to_prov]\n" "keepalive=1\n" "peer_public_key=%s\n" - "link=cl:127.0.0.1:39101\n" + "link=cl:127.0.0.1:0\n" "\n" "[nat]\n" "enabled=1\n" @@ -549,6 +550,7 @@ int main(void) { goto cleanup; } + test_etcp_set_peer(inst_client, "to_prov", inst_provider, "prov"); if (utun_instance_init(inst_provider) != 0 || utun_instance_init(inst_client) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_NAT, "Failed to init instances"); goto cleanup; diff --git a/tests/test_udp_proxy.c b/tests/test_udp_proxy.c index 9db77ce6..1f2e6a5a 100644 --- a/tests/test_udp_proxy.c +++ b/tests/test_udp_proxy.c @@ -6,6 +6,7 @@ #include #include "../lib/platform_compat.h" #include "test_utils.h" +#include "test_net.h" #ifndef _WIN32 #include #include @@ -30,7 +31,7 @@ #include "../lib/debug_config.h" #include "../lib/mem.h" -#define UDP_ECHO_PORT 29991 +static uint16_t echo_port; #define TEST_TIMEOUT_MS 5000 #define PAYLOAD_SIZE 64 @@ -43,8 +44,8 @@ static const char* cfg_node_client(void) { "my_public_key=ce8871f07fa056c636d297115f231b08c29cdf94e0d440fce83a07c34416d36a\n" "tun_ip=10.99.0.1/24\n" "tun_ifname=tun99\n" - "[server: s1]\naddr=127.0.0.1:9071\ntype=public\n" - "[client: c1]\nkeepalive=1\nlink=s1:127.0.0.1:9072\n" + "[server: s1]\naddr=127.0.0.1:0\ntype=public\n" + "[client: c1]\nkeepalive=1\nlink=s1:127.0.0.1:0\n" "peer_public_key=b3193173def895bd0fcea6f86af077c7d77216f10395275f627ac18242ec0f01\n" "[tcp_proxy_client]\n" "enabled=yes\n" @@ -62,7 +63,7 @@ static const char* cfg_node_exit(void) { "my_public_key=b3193173def895bd0fcea6f86af077c7d77216f10395275f627ac18242ec0f01\n" "tun_ip=10.99.0.2/24\n" "tun_ifname=tun98\n" - "[server: s1]\naddr=127.0.0.1:9072\ntype=public\n" + "[server: s1]\naddr=127.0.0.1:0\ntype=public\n" "[allowed_keys]\nallow_all=1\n" "[tcp_proxy_server]\nenabled=yes\n"); return buf; @@ -135,7 +136,7 @@ static void monitor(void* arg) { for (int i = 0; i < PAYLOAD_SIZE; i++) send_buf[i] = (uint8_t)(rand() & 0xFF); udp_proxy_send_to_exit(cli, exit_node_id, inet_addr("10.99.0.1"), htons(12345), - inet_addr("127.0.0.1"), htons(UDP_ECHO_PORT), + inet_addr("127.0.0.1"), htons(echo_port), send_buf, PAYLOAD_SIZE); } } @@ -161,6 +162,7 @@ int main(void) { exit_node = utun_instance_create_from_str(ua, cfg_node_exit()); if (!exit_node) { printf("[FAIL] exit instance create\n"); goto done; } + test_etcp_set_peer(cli, "c1", exit_node, "s1"); if (utun_instance_init(cli) < 0) { printf("[FAIL] client init\n"); goto done; } if (utun_instance_init(exit_node) < 0) { printf("[FAIL] exit init\n"); goto done; } @@ -169,8 +171,9 @@ int main(void) { // UDP echo server (same uasync, no fork) g_echo_sock = socket(AF_INET, SOCK_DGRAM, 0); if (g_echo_sock == SOCKET_INVALID) { printf("[FAIL] echo socket\n"); goto done; } - struct sockaddr_in ea = {.sin_family = AF_INET, .sin_addr = {.s_addr = inet_addr("127.0.0.1")}, .sin_port = htons(UDP_ECHO_PORT)}; + struct sockaddr_in ea = {.sin_family = AF_INET, .sin_addr = {.s_addr = inet_addr("127.0.0.1")}}; if (bind(g_echo_sock, (struct sockaddr*)&ea, sizeof(ea)) < 0) { printf("[FAIL] echo bind: %s\n", strerror(errno)); goto done; } + echo_port = test_bound_port(g_echo_sock); socket_set_nonblocking(g_echo_sock); g_echo_id = uasync_add_socket_t(ua, g_echo_sock, udp_echo_cb, NULL, NULL, "udp_echo", NULL);