|
|
|
|
@ -7,6 +7,7 @@
|
|
|
|
|
|
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
#include <windows.h> |
|
|
|
|
#include <direct.h> |
|
|
|
|
@ -77,15 +78,7 @@ static void gen_payload(uint32_t seq, uint8_t* buf, int len) {
|
|
|
|
|
for (int i=0;i<len;i++) buf[i]=(uint8_t)((i^seq^0xA5)&0xFF); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int create_temp_configs(void) { |
|
|
|
|
if (test_mkdtemp(temp_dir) != 0) { fprintf(stderr, "mkdtemp fail\n"); return -1; } |
|
|
|
|
int base = 42000+(getpid()%15000); |
|
|
|
|
a_port=base; b_port_a=base+1; b_port_c=base+2; c_port=base+3; |
|
|
|
|
if (sc_generate_keypair(&keys_a)!=SC_OK||sc_generate_keypair(&keys_b)!=SC_OK||sc_generate_keypair(&keys_c)!=SC_OK) { fprintf(stderr,"keygen fail\n"); return -1; } |
|
|
|
|
hex_encode(keys_a.private_key,32,privhex_a); hex_encode(keys_a.public_key,32,pubhex_a); |
|
|
|
|
hex_encode(keys_b.private_key,32,privhex_b); hex_encode(keys_b.public_key,32,pubhex_b); |
|
|
|
|
hex_encode(keys_c.private_key,32,privhex_c); hex_encode(keys_c.public_key,32,pubhex_c); |
|
|
|
|
|
|
|
|
|
static int write_configs(void) { |
|
|
|
|
snprintf(a_conf,sizeof(a_conf),"%s/a.conf",temp_dir); |
|
|
|
|
FILE* f=fopen(a_conf,"w"); if(!f){perror("a_conf");return -1;} |
|
|
|
|
fprintf(f,"[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.0.1/24\ntun_ifname=tun99\n\n" |
|
|
|
|
@ -110,6 +103,17 @@ static int create_temp_configs(void) {
|
|
|
|
|
} |
|
|
|
|
static void cleanup(void) { test_unlink(a_conf); test_unlink(b_conf); test_unlink(c_conf); test_rmdir(temp_dir); } |
|
|
|
|
|
|
|
|
|
static int create_temp_configs(void) { |
|
|
|
|
if (test_mkdtemp(temp_dir) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "router restart fixture: mkdtemp failed"); return -1; } |
|
|
|
|
if (sc_generate_keypair(&keys_a) != SC_OK || sc_generate_keypair(&keys_b) != SC_OK || sc_generate_keypair(&keys_c) != SC_OK) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "router restart fixture: key generation failed"); return -1; |
|
|
|
|
} |
|
|
|
|
hex_encode(keys_a.private_key,32,privhex_a); hex_encode(keys_a.public_key,32,pubhex_a); |
|
|
|
|
hex_encode(keys_b.private_key,32,privhex_b); hex_encode(keys_b.public_key,32,pubhex_b); |
|
|
|
|
hex_encode(keys_c.private_key,32,privhex_c); hex_encode(keys_c.public_key,32,pubhex_c); |
|
|
|
|
return write_configs(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void recv_handler(struct ETCP_CONN* conn, struct ll_entry* entry) { |
|
|
|
|
if (!entry || !entry->dgram) { fprintf(stderr, "RECV: null entry\n"); g_test_ok=-1; g_fail_code=10; return; } |
|
|
|
|
if (entry->len == ROUTER_SVC_HDR_SIZE) { queue_dgram_free(entry); queue_entry_free(entry); return; } |
|
|
|
|
@ -235,7 +239,7 @@ static void timeout_cb(void* arg) {
|
|
|
|
|
int main(void) { |
|
|
|
|
srand(1); |
|
|
|
|
if (create_temp_configs()!=0) return 1; |
|
|
|
|
printf("=== ETCP Router Reconnect Test ===\nPorts: a=%d b_a=%d b_c=%d c=%d\n", a_port, b_port_a, b_port_c, c_port); |
|
|
|
|
printf("=== ETCP Router Reconnect Test ===\n"); |
|
|
|
|
debug_config_init(); |
|
|
|
|
debug_set_level(DEBUG_LEVEL_ERROR); |
|
|
|
|
utun_instance_set_tun_init_enabled(0); |
|
|
|
|
@ -243,7 +247,18 @@ int main(void) {
|
|
|
|
|
ua=uasync_create(); if(!ua){cleanup();return 1;} |
|
|
|
|
g_a=utun_instance_create(ua,a_conf); if(!g_a||utun_instance_init(g_a)<0){fprintf(stderr,"FAIL: a\n");goto fail;} |
|
|
|
|
g_c=utun_instance_create(ua,c_conf); if(!g_c||utun_instance_init(g_c)<0){fprintf(stderr,"FAIL: c\n");goto fail;} |
|
|
|
|
g_b=utun_instance_create(ua,b_conf); if(!g_b||utun_instance_init(g_b)<0){fprintf(stderr,"FAIL: b\n");goto fail;} |
|
|
|
|
g_b=utun_instance_create(ua,b_conf); |
|
|
|
|
if (g_b) { |
|
|
|
|
a_port = ss_get_port(&test_etcp_bound_socket(g_a, "hub_a")->local_addr); |
|
|
|
|
c_port = ss_get_port(&test_etcp_bound_socket(g_c, "hub_c")->local_addr); |
|
|
|
|
b_port_a = ss_get_port(&test_etcp_bound_socket(g_b, "s_a")->local_addr); |
|
|
|
|
b_port_c = ss_get_port(&test_etcp_bound_socket(g_b, "s_c")->local_addr); |
|
|
|
|
test_etcp_set_peer(g_b, "to_a", g_a, "hub_a"); |
|
|
|
|
test_etcp_set_peer(g_b, "to_c", g_c, "hub_c"); |
|
|
|
|
if (write_configs() != 0) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "router restart fixture: cannot persist endpoints"); goto fail; } |
|
|
|
|
printf("Ports retained for restart: a=%d b_a=%d b_c=%d c=%d\n", a_port, b_port_a, b_port_c, c_port); |
|
|
|
|
} |
|
|
|
|
if(!g_b||utun_instance_init(g_b)<0){fprintf(stderr,"FAIL: b\n");goto fail;} |
|
|
|
|
|
|
|
|
|
const char* log = getenv("ROUTER_TEST_LOG"); |
|
|
|
|
if (log) { |
|
|
|
|
|