etcp: use human-readable names for socket type and NAT type in logs
Add helper functions server_type_str() and nat_type_str() to convert
CFG_SERVER_TYPE_* and NAT_TYPE_* codes to readable names.
Now: Add Socket type=PUBLIC instead of type=1
self-detect check: type=PUBLIC nat=UNKNOWN instead of type=1 nat_type=0
This commit is contained in:
1 parent
e57bac290a
commit
4ea4e37866
1 file changed
+13
-3
@@ -29,6 +29,16 @@
|
||||
#include "../lib/mem.h"
|
||||
#include "etcp.h"
|
||||
|
||||
static const char* server_type_str(uint8_t type) {
|
||||
static const char* names[] = {"UNKNOWN", "PUBLIC", "NAT", "PRIVATE", "LOCAL"};
|
||||
return type < 5 ? names[type] : "?";
|
||||
}
|
||||
static const char* nat_type_str(uint8_t nat_type) {
|
||||
if (nat_type >= 4 && nat_type <= 7) nat_type -= 4;
|
||||
static const char* names[] = {"UNKNOWN", "EIM", "STRICT", "DIRECT"};
|
||||
return nat_type < 4 ? names[nat_type] : "?";
|
||||
}
|
||||
|
||||
// TCP server: on new incoming connection → create minimal ETCP_CONN
|
||||
static void tcp_server_on_link(struct stcp_link *link, void *arg) {
|
||||
struct UTUN_INSTANCE *inst = (struct UTUN_INSTANCE *)arg;
|
||||
@@ -723,7 +733,7 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct CFG_S
|
||||
u_free(e_sock);
|
||||
return NULL;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Add Socket type=%d", type);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Add Socket type=%s", server_type_str(type));
|
||||
e_sock->next = instance->etcp_sockets;
|
||||
instance->etcp_sockets = e_sock;
|
||||
e_sock->socket_id = uasync_add_socket_t(instance->ua, e_sock->fd, etcp_connections_read_callback_socket, NULL, NULL, e_sock);
|
||||
@@ -1432,8 +1442,8 @@ static void send_init_response(struct ETCP_SOCKET* e_sock, struct ETCP_DGRAM* pk
|
||||
}
|
||||
}
|
||||
/* Self-detection: if my IP is non-local, I'm on a public IP */
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NAT, "self-detect check: socket=%s type=%d nat_type=%d if_addr=%s local_addr=%s",
|
||||
e_sock->name, e_sock->type, e_sock->nat_type,
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NAT, "self-detect check: socket=%s type=%s nat=%s if_addr=%s local_addr=%s",
|
||||
e_sock->name, server_type_str(e_sock->type), nat_type_str(e_sock->nat_type),
|
||||
sockaddr_storage_to_str(&e_sock->interface_addr).str,
|
||||
sockaddr_storage_to_str(&e_sock->local_addr).str);
|
||||
if (e_sock->nat_type != NAT_VERIFIED_DIRECT && e_sock->interface_addr.ss_family == AF_INET) {
|
||||
|
||||
Reference in new issue
Block a user