Browse Source

tests: assign NAT and route ping ports through bind zero

master
evgeny 2 days ago
parent
commit
3f4a67f552
  1. 13
      tests/test_nat_detection.c
  2. 13
      tests/test_route_ping.c

13
tests/test_nat_detection.c

@ -15,6 +15,7 @@
#include <string.h>
#include <unistd.h>
#include "test_utils.h"
#include "test_net.h"
#include "etcp.h"
#include "etcp_connections.h"
#include "../src/config_parser.h"
@ -86,7 +87,7 @@ static int create_temp_configs(void) {
"tun_ifname=tun100\n"
"\n"
"[server:test_s]\n"
"addr=127.0.0.1:39011\n"
"addr=127.0.0.1:0\n"
"type=public\n"
"\n"
"[allowed_keys]\n"
@ -102,13 +103,13 @@ static int create_temp_configs(void) {
"tun_ifname=tun103\n"
"\n"
"[server:test_c2]\n"
"addr=127.0.0.1:39013\n"
"addr=127.0.0.1:0\n"
"type=public\n"
"\n"
"[client:to_s]\n"
"keepalive=1\n"
"peer_public_key=%s\n"
"link=test_c2:127.0.0.1:39011\n";
"link=test_c2:127.0.0.1:0\n";
char tpl_c2_full[4096];
snprintf(tpl_c2_full, sizeof(tpl_c2_full), tpl_c2, pub_s);
if (write_config(config_c2, tpl_c2_full) != 0) { free(pub_s); return -1; }
@ -122,13 +123,13 @@ static int create_temp_configs(void) {
"tun_ifname=tun102\n"
"\n"
"[server:test_c1]\n"
"addr=127.0.0.1:39012\n"
"addr=127.0.0.1:0\n"
"type=nat\n"
"\n"
"[client:to_s]\n"
"keepalive=1\n"
"peer_public_key=%s\n"
"link=test_c1:127.0.0.1:39011\n";
"link=test_c1:127.0.0.1:0\n";
char tpl_c1_full[4096];
snprintf(tpl_c1_full, sizeof(tpl_c1_full), tpl_c1, pub_s);
free(pub_s);
@ -211,6 +212,8 @@ int main(void) {
goto cleanup;
}
test_etcp_set_peer(inst_c1, "to_s", inst_s, "test_s");
test_etcp_set_peer(inst_c2, "to_s", inst_s, "test_s");
// Разрешаем NAT check для localhost (для теста)
if (utun_instance_init(inst_s) != 0 || utun_instance_init(inst_c1) != 0 || utun_instance_init(inst_c2) != 0) {

13
tests/test_route_ping.c

@ -15,6 +15,7 @@
#include <string.h>
#include <unistd.h>
#include "test_utils.h"
#include "test_net.h"
#include "etcp.h"
#include "etcp_connections.h"
#include "../src/config_parser.h"
@ -85,7 +86,7 @@ static int create_temp_configs(void) {
"tun_ifname=tun102\n"
"\n"
"[server:test_c]\n"
"addr=127.0.0.1:39013\n"
"addr=127.0.0.1:0\n"
"type=public\n"
"\n"
"[allowed_keys]\n"
@ -103,7 +104,7 @@ static int create_temp_configs(void) {
"tun_ifname=tun101\n"
"\n"
"[server:test_b]\n"
"addr=127.0.0.1:39012\n"
"addr=127.0.0.1:0\n"
"type=public\n"
"\n"
"[allowed_keys]\n"
@ -112,7 +113,7 @@ static int create_temp_configs(void) {
"[client:to_c]\n"
"keepalive=1\n"
"peer_public_key=%s\n"
"link=test_b:127.0.0.1:39013\n",
"link=test_b:127.0.0.1:0\n",
pub_c);
free(pub_c);
if (write_config(config_b, tpl_b) != 0) return -1;
@ -128,7 +129,7 @@ static int create_temp_configs(void) {
"tun_ifname=tun100\n"
"\n"
"[server:test_a]\n"
"addr=127.0.0.1:39011\n"
"addr=127.0.0.1:0\n"
"type=public\n"
"\n"
"[allowed_keys]\n"
@ -137,7 +138,7 @@ static int create_temp_configs(void) {
"[client:to_b]\n"
"keepalive=1\n"
"peer_public_key=%s\n"
"link=test_a:127.0.0.1:39012\n",
"link=test_a:127.0.0.1:0\n",
pub_b);
free(pub_b);
if (write_config(config_a, tpl_a) != 0) return -1;
@ -218,6 +219,8 @@ int main(void) {
goto cleanup;
}
test_etcp_set_peer(inst_a, "to_b", inst_b, "test_b");
test_etcp_set_peer(inst_b, "to_c", inst_c, "test_c");
if (utun_instance_init(inst_a) != 0 || utun_instance_init(inst_b) != 0 || utun_instance_init(inst_c) != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to init connections");
goto cleanup;

Loading…
Cancel
Save