tests: derive NCD fixture addresses from bound sockets
This commit is contained in:
1 parent
b0ca182fc5
commit
4b499a076a
1 file changed
+8
-4
@@ -25,6 +25,7 @@
|
||||
#include <stdarg.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_net.h"
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#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, ©, NULL, NULL, NULL, NULL) < 0) return -1;
|
||||
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; }
|
||||
*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 };
|
||||
copy->v4_addrs = addr;
|
||||
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) {
|
||||
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);
|
||||
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(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);
|
||||
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: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);
|
||||
return 0;
|
||||
}
|
||||
@@ -367,6 +369,8 @@ 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) { 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_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",
|
||||
|
||||
Reference in new issue
Block a user