add proxy server/client indicator (S/C) in connection monitor

This commit is contained in:
evgeny committed 2026-08-10 10:30:07 +03:00
1 parent f1941e61a2
commit cf956cf2f0
6 files changed
+50 -4

No files matched your search

+33
View File
@@ -16,6 +16,9 @@
#include "../transport_layer/etcp_connections.h"
#include "../transport_layer/stcp_link.h"
#include "../transport_layer/pkt_normalizer.h"
#include "../proxy/tcp_proxy_server.h"
#include "../proxy/udp_proxy.h"
#include "../proxy/icmp_proxy.h"
#include <string.h>
static const char* nat_type_str(uint8_t t) {
@@ -147,6 +150,18 @@ static void collect_conn_list(void) {
uint8_t flags = 0;
if (conn->links_up) flags |= 1;
if (conn->initialized) flags |= 2;
if (g_cc.inst->tcp_proxy_client && ce->peer_node_id == g_cc.inst->config->global.tcp_proxy_client_via_node_id)
flags |= 4;
if (g_cc.inst->config->global.tcp_proxy_server_enabled) {
for (struct tcp_proxy_server_conn* sc = g_cc.inst->tcp_proxy_server.conns; sc; sc = sc->next)
if (sc->peer_node_id == ce->peer_node_id) { flags |= 8; break; }
if (!(flags & 8) && g_udp_ctx && g_udp_ctx->is_exit)
for (struct udp_flow* f = g_udp_ctx->flows; f; f = f->next)
if (f->client_node_id == ce->peer_node_id) { flags |= 8; break; }
if (!(flags & 8) && g_icmp_ctx && g_icmp_ctx->is_exit)
for (struct icmp_request* r = g_icmp_ctx->pending; r; r = r->next)
if (r->client_node_id == ce->peer_node_id) { flags |= 8; break; }
}
*p++ = flags;
uint8_t lc = 0;
@@ -198,12 +213,29 @@ static void collect_conn_metrics(uint64_t peer_node_id) {
char peername[64]; get_node_name(peer_node_id, peername, sizeof(peername));
if (!peername[0]) snprintf(peername, sizeof(peername), "%016llX", (unsigned long long)peer_node_id);
int is_client = 0, is_server = 0;
if (g_cc.inst->tcp_proxy_client && peer_node_id == g_cc.inst->config->global.tcp_proxy_client_via_node_id)
is_client = 1;
if (g_cc.inst->config->global.tcp_proxy_server_enabled) {
for (struct tcp_proxy_server_conn* sc = g_cc.inst->tcp_proxy_server.conns; sc; sc = sc->next)
if (sc->peer_node_id == peer_node_id) { is_server = 1; break; }
if (!is_server && g_udp_ctx && g_udp_ctx->is_exit)
for (struct udp_flow* f = g_udp_ctx->flows; f; f = f->next)
if (f->client_node_id == peer_node_id) { is_server = 1; break; }
if (!is_server && g_icmp_ctx && g_icmp_ctx->is_exit)
for (struct icmp_request* r = g_icmp_ctx->pending; r; r = r->next)
if (r->client_node_id == peer_node_id) { is_server = 1; break; }
}
const char* role_str = is_client && is_server ? "proxy client+server" :
is_client ? "proxy client" : is_server ? "proxy server" : "none";
/* Count links */
int link_count = 0, links_up_count = 0;
struct ETCP_LINK* tl = conn->links; while (tl) { if (tl->link_status) links_up_count++; link_count++; tl = tl->next; }
off += snprintf(buf + off, sizeof(buf) - off,
"=== PEER: %04llX\u2192%04llX [%s] ===\n"
"Role: %s\n"
"Status: %s Links: %d/%d Initialized: %s Session: 0x%X MTU: %d\n"
"Reinit: %u Reset: %u Tx_state: %d Routing_exchange: %d\n"
"\n--- ETCP ---\n"
@@ -214,6 +246,7 @@ static void collect_conn_metrics(uint64_t peer_node_id) {
"IDs: next_tx=%u last_rx=%u last_del=%u rx_ack_till=%u\n"
"\n--- Queues ---\n",
(unsigned long long)(my_id & 0xFFFF), (unsigned long long)(peer_node_id & 0xFFFF), peername,
role_str,
conn->links_up ? "UP" : "DOWN", links_up_count, link_count,
conn->initialized ? "yes" : "no", conn->session_id, conn->mtu,
conn->reinit_count, conn->reset_count, conn->tx_state, conn->routing_exchange_active,
+1 -1
View File
@@ -48,7 +48,7 @@ struct ip {
#define ICMP_DEF_TTL 64
#define ICMP_TIMEOUT_TB 50000 // 5s for echo reply
static struct icmp_proxy_ctx* g_icmp_ctx = NULL;
struct icmp_proxy_ctx* g_icmp_ctx = NULL;
static void req_expire_timer_cb(void* arg);
static void req_expire(struct icmp_proxy_ctx* ctx);
+2
View File
@@ -50,6 +50,8 @@ struct icmp_proxy_ctx {
void* expire_timer; // периодический таймер очистки истёкших запросов
};
extern struct icmp_proxy_ctx* g_icmp_ctx;
int icmp_proxy_init(struct UTUN_INSTANCE* inst, struct UASYNC* ua);
void icmp_proxy_destroy(struct UTUN_INSTANCE* inst);
+1 -1
View File
@@ -23,7 +23,7 @@
#define UDP_FLOW_TIMEOUT_TB 600000 // 60с
static struct udp_proxy_ctx* g_udp_ctx = NULL;
struct udp_proxy_ctx* g_udp_ctx = NULL;
static void flow_expire_timer_cb(void* arg);
static void flow_expire(struct udp_proxy_ctx* ctx);
+2
View File
@@ -48,6 +48,8 @@ struct udp_proxy_ctx {
void* expire_timer; // периодический таймер очистки истёкших потоков
};
extern struct udp_proxy_ctx* g_udp_ctx;
int udp_proxy_init(struct UTUN_INSTANCE* inst, struct UASYNC* ua);
void udp_proxy_destroy(struct UTUN_INSTANCE* inst);