|
|
|
|
@ -12,6 +12,7 @@
|
|
|
|
|
#include <stdarg.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#endif |
|
|
|
|
@ -39,7 +40,6 @@ static volatile int result = 0;
|
|
|
|
|
static void* ttimer = NULL; |
|
|
|
|
static char tdir[] = "/tmp/utun_cm_XXXXXX"; |
|
|
|
|
static char ca[256], cb[256]; |
|
|
|
|
static int pa = 0, pb = 0; |
|
|
|
|
static volatile int cdone = 0, cevent = 0; |
|
|
|
|
|
|
|
|
|
static int wf(const char* p, const char* f, ...) { |
|
|
|
|
@ -84,17 +84,19 @@ static void test2(void* arg) {
|
|
|
|
|
/* ---- phase 1: setup/cleanup ---- */ |
|
|
|
|
static void setup(void) { |
|
|
|
|
test_mkdtemp(tdir); |
|
|
|
|
int base = 47000 + (getpid() % 15000); pa = base; pb = base + 1; |
|
|
|
|
snprintf(ca, sizeof(ca), "%s/a.conf", tdir); snprintf(cb, sizeof(cb), "%s/b.conf", tdir); |
|
|
|
|
wf(ca, "[global]\ntun_ip=10.99.0.1/24\ntun_ifname=tun99\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pa); |
|
|
|
|
wf(cb, "[global]\ntun_ip=10.99.0.2/24\ntun_ifname=tun98\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pb); |
|
|
|
|
wf(ca, "[global]\ntun_ip=10.99.0.1/24\ntun_ifname=tun99\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n"); |
|
|
|
|
wf(cb, "[global]\ntun_ip=10.99.0.2/24\ntun_ifname=tun98\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n"); |
|
|
|
|
config_ensure_keys_and_node_id(ca); config_ensure_keys_and_node_id(cb); |
|
|
|
|
{ struct utun_config* cfa = parse_config(ca); struct utun_config* cfb = parse_config(cb); |
|
|
|
|
g_nid_a = cfa->global.my_node_id; g_nid_b = cfb->global.my_node_id; |
|
|
|
|
free_config(cfa); free_config(cfb); } |
|
|
|
|
char *p0 = gv(ca,"pub"), *r0 = gv(ca,"priv"), *p1 = gv(cb,"pub"), *r1 = gv(cb,"priv"); |
|
|
|
|
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.0.1/24\ntun_ifname=tun99\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n[allowed_keys]\nallow_all=1\n", r0, p0, pa, p1, pb); |
|
|
|
|
wf(cb, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.0.2/24\ntun_ifname=tun98\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", r1, p1, pb); |
|
|
|
|
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.0.1/24\ntun_ifname=tun99\n" |
|
|
|
|
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\n" |
|
|
|
|
"link=s1:127.0.0.1:0\n[allowed_keys]\nallow_all=1\n", r0, p0, p1); |
|
|
|
|
wf(cb, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.0.2/24\ntun_ifname=tun98\n" |
|
|
|
|
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n", r1, p1); |
|
|
|
|
u_free(p0); u_free(r0); u_free(p1); u_free(r1); |
|
|
|
|
} |
|
|
|
|
static void cleanup(void) { test_unlink(ca); test_unlink(cb); test_rmdir(tdir); } |
|
|
|
|
@ -106,7 +108,7 @@ static uint64_t g_nid_a2 = 0, g_nid_b2 = 0, g_nid_c = 0;
|
|
|
|
|
static volatile int cdone2 = 0, cevent2 = 0; |
|
|
|
|
static char tdir2[] = "/tmp/utun_cm_db_XXXXXX"; |
|
|
|
|
static char ca2[256], cb2[256]; |
|
|
|
|
static int pa2 = 0, pb2 = 0; |
|
|
|
|
static int pb2 = 0; |
|
|
|
|
|
|
|
|
|
static void ccb2(struct CONN_MGR_HANDLE* h, uint64_t id, uint64_t gid, |
|
|
|
|
enum conn_mgr_event event, void* arg) { |
|
|
|
|
@ -159,24 +161,23 @@ static void test3_check(void* arg) {
|
|
|
|
|
|
|
|
|
|
static void setup_db_test(void) { |
|
|
|
|
test_mkdtemp(tdir2); |
|
|
|
|
int base = 48000 + (getpid() % 10000); pa2 = base; pb2 = base + 1; |
|
|
|
|
char dbdir_a[320], dbdir_b[320]; |
|
|
|
|
snprintf(dbdir_a, sizeof(dbdir_a), "%s/db_a", tdir2); utun_mkdir(dbdir_a, 0755); |
|
|
|
|
snprintf(dbdir_b, sizeof(dbdir_b), "%s/db_b", tdir2); utun_mkdir(dbdir_b, 0755); |
|
|
|
|
snprintf(ca2, sizeof(ca2), "%s/a2.conf", tdir2); snprintf(cb2, sizeof(cb2), "%s/b2.conf", tdir2); |
|
|
|
|
wf(ca2, "[global]\ntun_ip=10.98.0.1/24\ntun_ifname=tun97\n" |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", dbdir_a, pa2); |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n", dbdir_a); |
|
|
|
|
wf(cb2, "[global]\ntun_ip=10.98.0.2/24\ntun_ifname=tun96\n" |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", dbdir_b, pb2); |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n", dbdir_b); |
|
|
|
|
config_ensure_keys_and_node_id(ca2); config_ensure_keys_and_node_id(cb2); |
|
|
|
|
{ struct utun_config* cfa = parse_config(ca2); g_nid_a2 = cfa->global.my_node_id; free_config(cfa); |
|
|
|
|
struct utun_config* cfb = parse_config(cb2); g_nid_b2 = cfb->global.my_node_id; free_config(cfb); } |
|
|
|
|
char *r0 = gv(ca2,"priv"), *p0 = gv(ca2,"pub"); |
|
|
|
|
char *r1 = gv(cb2,"priv"), *p1 = gv(cb2,"pub"); |
|
|
|
|
wf(ca2, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.98.0.1/24\ntun_ifname=tun97\n" |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", r0, p0, dbdir_a, pa2); |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n", r0, p0, dbdir_a); |
|
|
|
|
wf(cb2, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.98.0.2/24\ntun_ifname=tun96\n" |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", r1, p1, dbdir_b, pb2); |
|
|
|
|
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n", r1, p1, dbdir_b); |
|
|
|
|
u_free(r0); u_free(p0); u_free(r1); u_free(p1); |
|
|
|
|
g_nid_c = 0xC0DEC0DEC0DEC0DEULL; |
|
|
|
|
} |
|
|
|
|
@ -192,6 +193,7 @@ int main(void) {
|
|
|
|
|
ua = uasync_create(); |
|
|
|
|
g_a = utun_instance_create(ua, ca); g_b = utun_instance_create(ua, cb); |
|
|
|
|
if (!g_a || !g_b) goto phase1_cleanup; |
|
|
|
|
test_etcp_set_peer(g_a, "to_b", g_b, "s1"); |
|
|
|
|
utun_instance_init(g_a); utun_instance_init(g_b); |
|
|
|
|
uasync_call_soon(ua, NULL, test1); |
|
|
|
|
ttimer = uasync_set_timeout(ua, TIMEOUT_TB, NULL, to_cb, "to1"); |
|
|
|
|
@ -212,6 +214,7 @@ phase1_cleanup:
|
|
|
|
|
ua2 = uasync_create(); |
|
|
|
|
g_a2 = utun_instance_create(ua2, ca2); g_b2 = utun_instance_create(ua2, cb2); |
|
|
|
|
if (!g_a2 || !g_b2) goto done; |
|
|
|
|
pb2 = ss_get_port(&test_etcp_bound_socket(g_b2, "s1")->local_addr); |
|
|
|
|
utun_instance_init(g_a2); utun_instance_init(g_b2); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|