|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include <string.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include <sys/socket.h> |
|
|
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|