1
This commit is contained in:
1 parent
995d004209
commit
ed5e833fcb
4 files changed
+28
-3
No files matched your search
+1
-1
@@ -114,7 +114,7 @@ typedef struct {
|
||||
char str[48]; // INET6_ADDRSTRLEN(45) + \0
|
||||
} ip_str_t;
|
||||
|
||||
ip_str_t ip_to_str(const void *addr, int family);
|
||||
ip_str_t ip_to_str(const void *addr, int family);// big endian addr
|
||||
|
||||
// hex dump в лог
|
||||
void log_dump(const char* prefix, const uint8_t* data, size_t len);
|
||||
|
||||
+2
-2
@@ -219,11 +219,11 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
||||
l->nat_type = info->nat_type;
|
||||
l = l->next;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO from %s: socket_id=%u type=%s ip=%u.%u.%u.%u port=%u",
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO from %s: socket_id=%u type=%s ip=%u.%u.%u.%u %s port=%u",
|
||||
from_conn->log_name, socket_id,
|
||||
info->nat_type == NAT_TYPE_OPEN ? "OPEN" : "RESTRICTED",
|
||||
(info->nat_ip[0]), (info->nat_ip[1]),
|
||||
(info->nat_ip[2]), (info->nat_ip[3]),
|
||||
(info->nat_ip[2]), (info->nat_ip[3]), ip_to_str(&nat_ip, AF_INET).str,
|
||||
(unsigned)nat_port);
|
||||
}
|
||||
} else if (subcmd == ROUTE_SUBCMD_NAT_CHECK_REQ) {
|
||||
|
||||
@@ -307,3 +307,20 @@ int parse_subnet(const char *subnet_str, uint32_t *network, uint8_t *prefix_leng
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_local_subnet(uint32_t ip) {
|
||||
uint8_t* bip=(uint8_t*)&ip;
|
||||
uint8_t first_octet = bip[0];
|
||||
uint8_t second_octet = bip[1];
|
||||
|
||||
if (first_octet == 0) return 1;
|
||||
if (first_octet == 10) return 1;
|
||||
if (first_octet == 127) return 1;
|
||||
if (first_octet == 169 && second_octet == 254) return 1;
|
||||
if (first_octet >= 224 && first_octet <= 239) return 1;
|
||||
if (first_octet == 172 && second_octet >= 16 && second_octet <= 31) return 1;
|
||||
if (first_octet == 192 && second_octet == 168) return 1;
|
||||
if (ip=0xffffffff) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -112,4 +112,12 @@ int parse_subnet(const char *subnet_str, uint32_t *network, uint8_t *prefix_leng
|
||||
|
||||
bool route_add_local_subnet(struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length);
|
||||
|
||||
/**
|
||||
* @brief Проверяет что IP адрес НЕ является публичным (роутится в интернете)
|
||||
*
|
||||
* @param ip IP адрес в сетевом порядке (big-endian)
|
||||
* @return 0 - публичный (роутится в интернете), 1 - локальный/мультикастовый/зарезервированный
|
||||
*/
|
||||
int is_local_subnet(uint32_t ip);
|
||||
|
||||
#endif // ROUTE_LIB_H
|
||||
Reference in new issue
Block a user