Browse Source

tests: derive NCD fixture addresses from bound sockets

master
evgeny 3 days ago
parent
commit
4b499a076a
  1. 12
      tests/test_node_conn_direct.c

12
tests/test_node_conn_direct.c

@ -25,6 +25,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "../lib/platform_compat.h" #include "../lib/platform_compat.h"
#include "test_utils.h" #include "test_utils.h"
#include "test_net.h"
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -110,7 +111,7 @@ static int update_addresses(int up) {
if (len < 0 || topo_node_deserialize(&group, wire + sizeof(struct TOPOMSG_HEADER), (size_t)len, &copy, NULL, NULL, NULL, NULL) < 0) return -1; if (len < 0 || topo_node_deserialize(&group, wire + sizeof(struct TOPOMSG_HEADER), (size_t)len, &copy, NULL, NULL, NULL, NULL) < 0) return -1;
struct TOPO_ADDR4* addr = memory_pool_alloc(g_a->topo_groups->v4_addr_pool); struct TOPO_ADDR4* addr = memory_pool_alloc(g_a->topo_groups->v4_addr_pool);
if (!addr) { topo_node_destroy(g_a->topo_groups, copy); return -1; } if (!addr) { topo_node_destroy(g_a->topo_groups, copy); return -1; }
*addr = (struct TOPO_ADDR4){ .next = copy->v4_addrs, .addr = {127,0,0,2}, .port = (uint16_t)(pb + up), *addr = (struct TOPO_ADDR4){ .next = copy->v4_addrs, .addr = {127,0,0,2}, .port = (uint16_t)(pb == UINT16_MAX && up ? pb - 1 : pb + up),
.protocol = TOPO_PROTO_UDP }; .protocol = TOPO_PROTO_UDP };
copy->v4_addrs = addr; copy->v4_addrs = addr;
copy->timestamp += (uint64_t)up + 1; copy->timestamp += (uint64_t)up + 1;
@ -351,10 +352,11 @@ static int inject_node(struct UTUN_INSTANCE* inst, uint64_t nid, const uint8_t p
static int setup(void) { static int setup(void) {
test_mkdtemp(tdir); test_mkdtemp(tdir);
int base = 49000 + (getpid() % 10000); pa = base; pb = base + 1;
snprintf(ca, sizeof(ca), "%s/a.conf", tdir); snprintf(cb, sizeof(cb), "%s/b.conf", tdir); snprintf(ca, sizeof(ca), "%s/a.conf", tdir); snprintf(cb, sizeof(cb), "%s/b.conf", tdir);
wf(ca, "[global]\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\nkeepalive_timeout=100\nkeepalive_interval=10\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pa); wf(ca, "[global]\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\nkeepalive_timeout=100\nkeepalive_interval=10\n"
wf(cb, "[global]\ntun_ip=10.97.0.2/24\ntun_ifname=tun94\nkeepalive_timeout=100\nkeepalive_interval=10\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pb); "[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n");
wf(cb, "[global]\ntun_ip=10.97.0.2/24\ntun_ifname=tun94\nkeepalive_timeout=100\nkeepalive_interval=10\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); config_ensure_keys_and_node_id(ca); config_ensure_keys_and_node_id(cb);
return 0; return 0;
} }
@ -367,6 +369,8 @@ int main(void) {
ua = uasync_create(); ua = uasync_create();
g_a = utun_instance_create(ua, ca); g_b = utun_instance_create(ua, cb); g_a = utun_instance_create(ua, ca); g_b = utun_instance_create(ua, cb);
if (!g_a || !g_b) { g_result = 2; goto done; } if (!g_a || !g_b) { g_result = 2; goto done; }
pa = ss_get_port(&test_etcp_bound_socket(g_a, "s1")->local_addr);
pb = ss_get_port(&test_etcp_bound_socket(g_b, "s1")->local_addr);
nid_b = g_b->node_id; memcpy(pubkey_b, g_b->my_keys.public_key, SC_PUBKEY_SIZE); nid_b = g_b->node_id; memcpy(pubkey_b, g_b->my_keys.public_key, SC_PUBKEY_SIZE);
nid_a = g_a->node_id; memcpy(pubkey_a, g_a->my_keys.public_key, SC_PUBKEY_SIZE); nid_a = g_a->node_id; memcpy(pubkey_a, g_a->my_keys.public_key, SC_PUBKEY_SIZE);
fprintf(stderr, "A: 0x%016llx port=%d B: 0x%016llx port=%d\n", fprintf(stderr, "A: 0x%016llx port=%d B: 0x%016llx port=%d\n",

Loading…
Cancel
Save