|
|
|
|
@ -68,7 +68,7 @@ static void connect_cancel(struct ETCP_CONNECT* ctx) {
|
|
|
|
|
static void connect_create_links_v4(struct ETCP_CONNECT* ctx, struct TOPO_GROUP_NODE* node) { |
|
|
|
|
if (!node) return; |
|
|
|
|
struct TOPO_NODE* ni = topo_node_registry_find(ctx->instance->topo_groups, node->node_id); |
|
|
|
|
if (!ni) { DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v4: ni NOT in registry for node=%016llx", (unsigned long long)node->node_id); return; } |
|
|
|
|
if (!ni) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v4: ni NOT in registry for node=%016llx", (unsigned long long)node->node_id); return; } |
|
|
|
|
int addr_count = 0, sock_count = 0, link_count = 0; |
|
|
|
|
{ struct ETCP_SOCKET* s = ctx->instance->etcp_sockets; while (s) { sock_count++; s = s->next; } } |
|
|
|
|
for (const struct TOPO_ADDR4* a = ni->v4_addrs; a; a = a->next) { |
|
|
|
|
@ -93,26 +93,30 @@ static void connect_create_links_v4(struct ETCP_CONNECT* ctx, struct TOPO_GROUP_
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] link_v4: %d.%d.%d.%d:%d proto=%d links=%d conn=[%s]", |
|
|
|
|
a->addr[0], a->addr[1], a->addr[2], a->addr[3], a->port, a->protocol, addr_links, ctx->conn->log_name); |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v4: TOTAL addrs=%d socks=%d links=%d for node=%016llx", |
|
|
|
|
addr_count, sock_count, link_count, (unsigned long long)node->node_id); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v4: TOTAL addrs=%d socks=%d links=%d%s for node=%016llx", |
|
|
|
|
addr_count, sock_count, link_count, addr_count == 0 ? " (v4_addrs EMPTY)" : "", (unsigned long long)node->node_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void connect_create_links_v6(struct ETCP_CONNECT* ctx, struct TOPO_GROUP_NODE* node) { |
|
|
|
|
if (!node) return; |
|
|
|
|
struct TOPO_NODE* ni = topo_node_registry_find(ctx->instance->topo_groups, node->node_id); |
|
|
|
|
if (!ni) return; |
|
|
|
|
if (!ni) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v6: ni NOT in registry for node=%016llx", (unsigned long long)node->node_id); return; } |
|
|
|
|
int addr_count = 0, sock_count = 0, link_count = 0; |
|
|
|
|
{ struct ETCP_SOCKET* s = ctx->instance->etcp_sockets; while (s) { sock_count++; s = s->next; } } |
|
|
|
|
for (const struct TOPO_ADDR6* a = ni->v6_addrs; a; a = a->next) { |
|
|
|
|
if (a->port == 0) continue; |
|
|
|
|
int zero = 1; for (int j = 0; j < 16; j++) if (a->addr[j] != 0) { zero = 0; break; } if (zero) continue; |
|
|
|
|
addr_count++; |
|
|
|
|
if (a->port == 0) { DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] link_v6: skip port==0 node=%016llx", (unsigned long long)node->node_id); continue; } |
|
|
|
|
int zero = 1; for (int j = 0; j < 16; j++) if (a->addr[j] != 0) { zero = 0; break; } if (zero) { DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] link_v6: skip zero addr node=%016llx", (unsigned long long)node->node_id); continue; } |
|
|
|
|
struct sockaddr_in6 sin6; memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; |
|
|
|
|
memcpy(&sin6.sin6_addr, a->addr, 16); sin6.sin6_port = htons(a->port); |
|
|
|
|
int is_ll = (a->addr[0] == 0xfe && (a->addr[1] & 0xc0) == 0x80); |
|
|
|
|
int addr_links = 0; |
|
|
|
|
if (!(a->protocol & TOPO_PROTO_TCP)) { |
|
|
|
|
struct ETCP_SOCKET* s = ctx->instance->etcp_sockets; |
|
|
|
|
while (s) { if (s->local_addr.ss_family == AF_INET6) { |
|
|
|
|
if (is_ll) sin6.sin6_scope_id = s->netif_index; |
|
|
|
|
struct sockaddr_storage sa; memcpy(&sa, &sin6, sizeof(sin6)); |
|
|
|
|
etcp_link_new(ctx->conn, s, &sa, 0); |
|
|
|
|
if (etcp_link_new(ctx->conn, s, &sa, 0)) { link_count++; addr_links++; } |
|
|
|
|
} s = s->next; } |
|
|
|
|
} |
|
|
|
|
if (a->protocol & TOPO_PROTO_TCP) { |
|
|
|
|
@ -124,10 +128,14 @@ static void connect_create_links_v6(struct ETCP_CONNECT* ctx, struct TOPO_GROUP_
|
|
|
|
|
struct ETCP_SOCKET* s = ctx->instance->etcp_sockets; |
|
|
|
|
while (s) { if (s->is_tcp && s->local_addr.ss_family == AF_INET6) { |
|
|
|
|
struct ETCP_LINK *tlink = etcp_link_new(ctx->conn, s, &sa, 0); |
|
|
|
|
if (tlink) { tlink->is_tcp = 1; etcp_tcp_link_start_connect(tlink, &sa, a->port); } |
|
|
|
|
if (tlink) { tlink->is_tcp = 1; etcp_tcp_link_start_connect(tlink, &sa, a->port); link_count++; addr_links++; } |
|
|
|
|
} s = s->next; } |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] link_v6: %s:%d proto=%d links=%d conn=[%s]", |
|
|
|
|
ip_to_str(a->addr, AF_INET6).str, a->port, a->protocol, addr_links, ctx->conn->log_name); |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] links_v6: TOTAL addrs=%d socks=%d links=%d%s for node=%016llx", |
|
|
|
|
addr_count, sock_count, link_count, addr_count == 0 ? " (v6_addrs EMPTY)" : "", (unsigned long long)node->node_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void connect_bgp_ready_cb(struct ETCP_CONN* conn) { |
|
|
|
|
@ -225,8 +233,10 @@ int etcp_connect(struct UTUN_INSTANCE* inst, struct TOPO_GROUP_NODE* node,
|
|
|
|
|
|
|
|
|
|
struct TOPO_NODE* ni = topo_node_registry_find(inst->topo_groups, node->node_id); |
|
|
|
|
if (!ni) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP_CONNECT, "[etcp_connect] node not in registry"); return -1; } |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[etcp_connect] registry OK node=%016llx pub=%016llx v4addrs=%p v4socks=%p", |
|
|
|
|
(unsigned long long)node->node_id, *(uint64_t*)ni->public_key, (void*)ni->v4_addrs, (void*)ni->v4_sock_meta); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[etcp_connect] registry OK node=%016llx pub=%016llx v4addrs=%d v6addrs=%d", |
|
|
|
|
(unsigned long long)node->node_id, *(uint64_t*)ni->public_key, |
|
|
|
|
topo_list_count((struct _topo_head*)ni->v4_addrs), |
|
|
|
|
topo_list_count((struct _topo_head*)ni->v6_addrs)); |
|
|
|
|
|
|
|
|
|
uint64_t node_id = ni->node_id; |
|
|
|
|
if (node_id == 0) { |
|
|
|
|
|