nat: publish TCP external IPs with an unknown port
This commit is contained in:
1 parent
5eb3526186
commit
6363c8b7ea
2 files changed
+20
-2
No files matched your search
@@ -1219,6 +1219,14 @@ int topo_node_update_my_addresses(struct UTUN_INSTANCE* instance) {
|
||||
memcpy(a->addr, &sin->sin_addr.s_addr, 4); a->port = ntohs(sin->sin_port);
|
||||
a->type = TOPO_ADDR_INTERFACE; a->socket_id = ts->sock_id; a->protocol = proto;
|
||||
a->next = v4_head; v4_head = a; }
|
||||
if (ts->nat_addr.ss_family == AF_INET && ts->address_profile.source == ADDRESS_SOURCE_ETCP &&
|
||||
ts->address_profile.mapping == ADDRESS_MAP_UNKNOWN) {
|
||||
struct TOPO_ADDR4 *a = memory_pool_alloc(instance->topo_groups->v4_addr_pool);
|
||||
if (!a) goto allocation_failed;
|
||||
memcpy(a->addr, &((const struct sockaddr_in *)&ts->nat_addr)->sin_addr, 4);
|
||||
a->port = 0; a->type = TOPO_ADDR_NAT; a->socket_id = ts->sock_id; a->protocol = proto;
|
||||
a->next = v4_head; v4_head = a;
|
||||
}
|
||||
} else if (addr->ss_family == AF_INET6) {
|
||||
struct sockaddr_in6* sin6 = (struct sockaddr_in6*)addr;
|
||||
{ struct TOPO_SOCKMETA6* sm6 = memory_pool_alloc(instance->topo_groups->v6_sock_meta_pool);
|
||||
@@ -1230,6 +1238,14 @@ int topo_node_update_my_addresses(struct UTUN_INSTANCE* instance) {
|
||||
memcpy(a6->addr, &sin6->sin6_addr, 16); a6->port = ntohs(sin6->sin6_port);
|
||||
a6->type = TOPO_ADDR_INTERFACE; a6->socket_id = ts->sock_id; a6->protocol = proto;
|
||||
a6->next = v6_head; v6_head = a6; }
|
||||
if (ts->nat_addr.ss_family == AF_INET6 && ts->address_profile.source == ADDRESS_SOURCE_ETCP &&
|
||||
ts->address_profile.mapping == ADDRESS_MAP_UNKNOWN) {
|
||||
struct TOPO_ADDR6 *a6 = memory_pool_alloc(instance->topo_groups->v6_addr_pool);
|
||||
if (!a6) goto allocation_failed;
|
||||
memcpy(a6->addr, &((const struct sockaddr_in6 *)&ts->nat_addr)->sin6_addr, 16);
|
||||
a6->port = 0; a6->type = TOPO_ADDR_NAT; a6->socket_id = ts->sock_id; a6->protocol = proto;
|
||||
a6->next = v6_head; v6_head = a6;
|
||||
}
|
||||
}
|
||||
if (is_reality) {
|
||||
struct TOPO_REALITY_SOCK* r = u_calloc(1, sizeof(struct TOPO_REALITY_SOCK));
|
||||
|
||||
@@ -62,9 +62,11 @@ static int addr_type_from_ip(int family, const uint8_t* addr) {
|
||||
}
|
||||
|
||||
/* Итоговая классификация: конфиг + автоопределение + IP (всё локально). */
|
||||
static int addr_type_classify(int kind, int config_type, int global, const struct address_profile *profile) {
|
||||
static int addr_type_classify(int kind, int protocol, int config_type, int global, const struct address_profile *profile) {
|
||||
if (config_type == CFG_SERVER_TYPE_PRIVATE || config_type == CFG_SERVER_TYPE_LOCAL) return ADDR_TYPE_NETIF;
|
||||
if (!profile) return ADDR_TYPE_NAT;
|
||||
if ((protocol & TOPO_PROTO_TCP) && profile->source == ADDRESS_SOURCE_ETCP && profile->mapping == ADDRESS_MAP_UNKNOWN)
|
||||
return ADDR_TYPE_NAT;
|
||||
if (profile->mapping == ADDRESS_MAP_EIM)
|
||||
return profile->inbound == ADDRESS_IN_UNKNOWN ? ADDR_TYPE_NAT_EIM_UNVERIFIED : ADDR_TYPE_NAT_EIM;
|
||||
if (profile->mapping == ADDRESS_MAP_DEPENDENT) return ADDR_TYPE_NAT_STRICT;
|
||||
@@ -114,7 +116,7 @@ static int address_row_put(sqlite3_stmt *statement, struct TOPO_NODE *node, uint
|
||||
uint8_t protocol, uint8_t config, const struct address_profile *profile) {
|
||||
static const struct address_profile unknown = {0};
|
||||
if (!profile) profile = &unknown;
|
||||
int summary = addr_type_classify(kind, config, addr_type_from_ip(family, address) == ADDR_TYPE_DIRECT, profile);
|
||||
int summary = addr_type_classify(kind, protocol, config, addr_type_from_ip(family, address) == ADDR_TYPE_DIRECT, profile);
|
||||
struct TOPO_ADDR_REALITY_OPTS reality;
|
||||
int has_reality = (protocol & TOPO_PROTO_REALITY) && reality_opts_build(node, socket_id, &reality);
|
||||
sqlite3_bind_int64(statement, 1, (sqlite3_int64)node_id);
|
||||
|
||||
Reference in new issue
Block a user