nat: distinguish public interface addresses from unknown NAT candidates
This commit is contained in:
1 parent
37461bb938
commit
78f71ddbb0
3 files changed
+23
-4
No files matched your search
@@ -62,11 +62,13 @@ static int addr_type_from_ip(int family, const uint8_t* addr) {
|
||||
}
|
||||
|
||||
/* Итоговая классификация: конфиг + автоопределение + IP (всё локально). */
|
||||
static int addr_type_classify(int config_type, int global, const struct address_profile *profile) {
|
||||
static int addr_type_classify(int kind, 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 (profile->mapping == ADDRESS_MAP_EIM) return ADDR_TYPE_NAT_EIM;
|
||||
if (profile->mapping == ADDRESS_MAP_DEPENDENT) return ADDR_TYPE_NAT_STRICT;
|
||||
/* Публичный адрес интерфейса известен без определения входящих и не становится NAT из-за UNKNOWN. */
|
||||
if (global && kind == TOPO_ADDR_INTERFACE && profile->mapping == ADDRESS_MAP_UNKNOWN) return ADDR_TYPE_NETIF;
|
||||
if (!global) return config_type == CFG_SERVER_TYPE_NAT ? ADDR_TYPE_NAT : ADDR_TYPE_NETIF;
|
||||
if (profile->mapping == ADDRESS_MAP_UNCHANGED && profile->inbound == ADDRESS_IN_OPEN) return ADDR_TYPE_DIRECT;
|
||||
if (profile->mapping == ADDRESS_MAP_UNCHANGED && profile->inbound == ADDRESS_IN_CONTACT) return ADDR_TYPE_CONTACT;
|
||||
@@ -109,7 +111,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(config, addr_type_from_ip(family, address) == ADDR_TYPE_DIRECT, profile);
|
||||
int summary = addr_type_classify(kind, 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