|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include <string.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
#include <windows.h> |
|
|
|
|
#else |
|
|
|
|
@ -53,8 +54,8 @@ static void test_timeout_cb(void* arg) {
|
|
|
|
|
|
|
|
|
|
struct ncfg { |
|
|
|
|
uint64_t node_id; const char* tun_ip; const char* priv_hex; const char* pub_hex; |
|
|
|
|
int srv_cnt; struct { const char* name; int port; } srvs[3]; |
|
|
|
|
int cli_cnt; struct { const char* name; const char* peer_pubkey_hex; int lnk_cnt; struct { const char* local_srv; int remote_port; } lnks[2]; } clis[2]; |
|
|
|
|
int srv_cnt; struct { const char* name; } srvs[3]; |
|
|
|
|
int cli_cnt; struct { const char* name; const char* peer_pubkey_hex; int lnk_cnt; struct { const char* local_srv; } lnks[2]; } clis[2]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void build_cfg(char* buf, size_t size, const struct ncfg* c) { |
|
|
|
|
@ -70,11 +71,11 @@ static void build_cfg(char* buf, size_t size, const struct ncfg* c) {
|
|
|
|
|
"\n", |
|
|
|
|
c->priv_hex, c->pub_hex, c->tun_ip); |
|
|
|
|
for (int i = 0; i < c->srv_cnt; i++) |
|
|
|
|
off += snprintf(buf + off, size - off, "[server: %s]\naddr=127.0.0.1:%d\ntype=public\n\n", c->srvs[i].name, c->srvs[i].port); |
|
|
|
|
off += snprintf(buf + off, size - off, "[server: %s]\naddr=127.0.0.1:0\ntype=public\n\n", c->srvs[i].name); |
|
|
|
|
for (int i = 0; i < c->cli_cnt; i++) { |
|
|
|
|
off += snprintf(buf + off, size - off, "[client: %s]\nkeepalive=1\npeer_public_key=%s\n", c->clis[i].name, c->clis[i].peer_pubkey_hex); |
|
|
|
|
for (int j = 0; j < c->clis[i].lnk_cnt; j++) |
|
|
|
|
off += snprintf(buf + off, size - off, "link=%s:127.0.0.1:%d\n", c->clis[i].lnks[j].local_srv, c->clis[i].lnks[j].remote_port); |
|
|
|
|
off += snprintf(buf + off, size - off, "link=%s:127.0.0.1:0\n", c->clis[i].lnks[j].local_srv); |
|
|
|
|
off += snprintf(buf + off, size - off, "\n"); |
|
|
|
|
} |
|
|
|
|
off += snprintf(buf + off, size - off, "[allowed_keys]\nallow_all=1\n"); |
|
|
|
|
@ -163,48 +164,41 @@ int main(void) {
|
|
|
|
|
bytes_to_hex(keys[i].private_key, SC_PRIVKEY_SIZE, priv_hex[i], sizeof(priv_hex[i])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int base = 43000 + (getpid() % 10000); |
|
|
|
|
int p_ab_a = base++, p_ab_b = base++; |
|
|
|
|
int p_ac_a = base++, p_ac_c = base++; |
|
|
|
|
int p_bc_b = base++, p_bc_c = base++; |
|
|
|
|
int p_cd_c = base++, p_cd_d = base++; |
|
|
|
|
int p_de_d = base++, p_de_e = base++; |
|
|
|
|
|
|
|
|
|
/* A: servers for B and C, clients to B and C */ |
|
|
|
|
char cfg_a[2048]; build_cfg(cfg_a, sizeof(cfg_a), &(struct ncfg){ |
|
|
|
|
.priv_hex = priv_hex[0], .pub_hex = pub_hex[0], .tun_ip = "10.200.0.1/24", |
|
|
|
|
.srv_cnt = 2, .srvs = {{"a_srv_b", p_ab_a}, {"a_srv_c", p_ac_a}}, |
|
|
|
|
.srv_cnt = 2, .srvs = {{"a_srv_b"}, {"a_srv_c"}}, |
|
|
|
|
.cli_cnt = 2, .clis = { |
|
|
|
|
{"to_b", pub_hex[1], 1, {{"a_srv_b", p_ab_b}}}, |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"a_srv_c", p_ac_c}}}, |
|
|
|
|
{"to_b", pub_hex[1], 1, {{"a_srv_b"}}}, |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"a_srv_c"}}}, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* B: server for A, server for C, client to C */ |
|
|
|
|
char cfg_b[2048]; build_cfg(cfg_b, sizeof(cfg_b), &(struct ncfg){ |
|
|
|
|
.priv_hex = priv_hex[1], .pub_hex = pub_hex[1], .tun_ip = "10.200.0.2/24", |
|
|
|
|
.srv_cnt = 2, .srvs = {{"b_srv", p_ab_b}, {"b_srv_c", p_bc_b}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_c", pub_hex[2], 1, {{"b_srv_c", p_bc_c}}}} |
|
|
|
|
.srv_cnt = 2, .srvs = {{"b_srv"}, {"b_srv_c"}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_c", pub_hex[2], 1, {{"b_srv_c"}}}} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* C: servers for A, B, D; client to D */ |
|
|
|
|
char cfg_c[2048]; build_cfg(cfg_c, sizeof(cfg_c), &(struct ncfg){ |
|
|
|
|
.priv_hex = priv_hex[2], .pub_hex = pub_hex[2], .tun_ip = "10.200.0.3/24", |
|
|
|
|
.srv_cnt = 3, .srvs = {{"c_srv_a", p_ac_c}, {"c_srv_b", p_bc_c}, {"c_srv_d", p_cd_c}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_d", pub_hex[3], 1, {{"c_srv_d", p_cd_d}}}} |
|
|
|
|
.srv_cnt = 3, .srvs = {{"c_srv_a"}, {"c_srv_b"}, {"c_srv_d"}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_d", pub_hex[3], 1, {{"c_srv_d"}}}} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* D: server for C, server for E; client to E */ |
|
|
|
|
char cfg_d[2048]; build_cfg(cfg_d, sizeof(cfg_d), &(struct ncfg){ |
|
|
|
|
.priv_hex = priv_hex[3], .pub_hex = pub_hex[3], .tun_ip = "10.200.0.4/24", |
|
|
|
|
.srv_cnt = 2, .srvs = {{"d_srv", p_cd_d}, {"d_srv_e", p_de_d}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_e", pub_hex[4], 1, {{"d_srv_e", p_de_e}}}} |
|
|
|
|
.srv_cnt = 2, .srvs = {{"d_srv"}, {"d_srv_e"}}, |
|
|
|
|
.cli_cnt = 1, .clis = {{"to_e", pub_hex[4], 1, {{"d_srv_e"}}}} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* E: server for D, no clients */ |
|
|
|
|
char cfg_e[2048]; build_cfg(cfg_e, sizeof(cfg_e), &(struct ncfg){ |
|
|
|
|
.priv_hex = priv_hex[4], .pub_hex = pub_hex[4], .tun_ip = "10.200.0.5/24", |
|
|
|
|
.srv_cnt = 1, .srvs = {{"e_srv", p_de_e}}, |
|
|
|
|
.srv_cnt = 1, .srvs = {{"e_srv"}}, |
|
|
|
|
.cli_cnt = 0, .clis = {} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -215,6 +209,11 @@ int main(void) {
|
|
|
|
|
inst[2] = utun_instance_create_from_str(ua, cfg_c); ASSERT(inst[2], "inst C"); |
|
|
|
|
inst[3] = utun_instance_create_from_str(ua, cfg_d); ASSERT(inst[3], "inst D"); |
|
|
|
|
inst[4] = utun_instance_create_from_str(ua, cfg_e); ASSERT(inst[4], "inst E"); |
|
|
|
|
test_etcp_set_peer(inst[0], "to_b", inst[1], "b_srv"); |
|
|
|
|
test_etcp_set_peer(inst[0], "to_c", inst[2], "c_srv_a"); |
|
|
|
|
test_etcp_set_peer(inst[1], "to_c", inst[2], "c_srv_b"); |
|
|
|
|
test_etcp_set_peer(inst[2], "to_d", inst[3], "d_srv"); |
|
|
|
|
test_etcp_set_peer(inst[3], "to_e", inst[4], "e_srv"); |
|
|
|
|
for (int i = 0; i < 5; i++) { ASSERT(utun_instance_init(inst[i]) == 0, "init"); nid[i] = inst[i]->node_id; } |
|
|
|
|
|
|
|
|
|
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_TB, NULL, test_timeout_cb, "test_timeout"); |
|
|
|
|
|