- Добавлен ETCPMON_CMD_ACTION в протокол (32 байта текст) - В GUI добавлено поле ввода и кнопка Send правее блока Sockets - Добавлен etcpmon_client_send_action для отправки команд - Обработка action 'nat' в control_server: запускает NAT check для всех линков - Сделана route_bgp_start_link_nat_check не-static - Добавлена route_bgp_request_nat_check_all - Исправлен баг route_ping.c (request_id -> nonce) - Исправлена линковка tests/Makefile.am
332 lines
12 KiB
C
332 lines
12 KiB
C
/*
|
|
* etcpmon_protocol.h - ETCP Monitor Protocol Definitions
|
|
*
|
|
* Binary protocol for monitoring ETCP connections
|
|
* Format: [2 bytes: msg_size] [1 byte: msg_type] [payload...]
|
|
*
|
|
* Period: 100ms (10 updates per second)
|
|
*/
|
|
|
|
#ifndef ETCPMON_PROTOCOL_H
|
|
#define ETCPMON_PROTOCOL_H
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* ============================================================================
|
|
* Protocol Constants
|
|
* ============================================================================ */
|
|
|
|
#define ETCPMON_PROTOCOL_VERSION 1
|
|
|
|
/* NAT types (mirrored from etcp_connections.h for monitor protocol) */
|
|
#define NAT_TYPE_UNKNOWN 0
|
|
#define NAT_TYPE_OPEN 1
|
|
#define NAT_TYPE_RESTRICTED 2
|
|
#define NAT_VERIFIED_UNKNOWN 4
|
|
#define NAT_VERIFIED_OPEN 5
|
|
#define NAT_VERIFIED_RESTRICTED 6
|
|
#define NAT_VERIFIED_DIRECT 7
|
|
#define ETCPMON_MAX_MSG_SIZE 4096
|
|
#define ETCPMON_MAX_CONN_NAME 32
|
|
#define ETCPMON_MAX_CONNECTIONS 250
|
|
#define ETCPMON_MAX_LINKS 16
|
|
|
|
/* Update interval in milliseconds */
|
|
#define ETCPMON_UPDATE_INTERVAL_MS 100
|
|
|
|
/* ============================================================================
|
|
* Message Types
|
|
* ============================================================================ */
|
|
|
|
/* Client -> Server commands */
|
|
#define ETCPMON_CMD_LIST_CONN 0x01 /* Request connection list */
|
|
#define ETCPMON_CMD_SELECT_CONN 0x02 /* Select connection by peer_node_id */
|
|
#define ETCPMON_CMD_GET_METRICS 0x03 /* Request metrics for selected */
|
|
#define ETCPMON_CMD_DISCONNECT 0x04 /* Disconnect from monitoring */
|
|
#define ETCPMON_CMD_LIST_SOCKETS 0x05 /* Request local socket list */
|
|
#define ETCPMON_CMD_ACTION 0x06 /* Execute action (text command) */
|
|
|
|
/* Server -> Client responses */
|
|
#define ETCPMON_RSP_CONN_LIST 0x81 /* Connection list response */
|
|
#define ETCPMON_RSP_METRICS 0x82 /* Metrics response */
|
|
#define ETCPMON_RSP_SOCKET_LIST 0x83 /* Socket list response */
|
|
#define ETCPMON_RSP_ERROR 0xFF /* Error response */
|
|
|
|
/* Error codes for RSP_ERROR */
|
|
#define ETCPMON_ERR_INVALID_CMD 0x01 /* Unknown command */
|
|
#define ETCPMON_ERR_INVALID_CONN 0x02 /* Invalid connection ID */
|
|
#define ETCPMON_ERR_NO_CONN_SELECTED 0x03 /* No connection selected */
|
|
#define ETCPMON_ERR_SERVER_BUSY 0x04 /* Server too busy */
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
/* ============================================================================
|
|
* Message Header
|
|
* ============================================================================
|
|
* seq_id: 0 = broadcast/unsolicited, 1-255 = request/response pair */
|
|
|
|
struct etcpmon_msg_header {
|
|
uint16_t size; /* Total message size including header */
|
|
uint8_t type; /* Message type (command or response) */
|
|
uint8_t seq_id; /* Sequence ID: request pairs use same ID */
|
|
};
|
|
|
|
/* ============================================================================
|
|
* Commands (Client -> Server)
|
|
* ============================================================================ */
|
|
|
|
/* CMD_LIST_CONN: No payload required */
|
|
|
|
/* CMD_SELECT_CONN: Select connection to monitor */
|
|
struct etcpmon_cmd_select {
|
|
uint64_t peer_node_id; /* peer_node_id of connection to monitor */
|
|
};
|
|
|
|
/* CMD_ACTION: Execute action command */
|
|
struct etcpmon_cmd_action {
|
|
char action[32]; /* Null-terminated action string */
|
|
};
|
|
|
|
/* CMD_GET_METRICS: No payload required (uses previously selected connection) */
|
|
|
|
/* CMD_DISCONNECT: No payload required */
|
|
|
|
/* ============================================================================
|
|
* Responses (Server -> Client)
|
|
* ============================================================================ */
|
|
|
|
/* RSP_CONN_LIST: List of active connections */
|
|
struct etcpmon_conn_info {
|
|
uint64_t peer_node_id; /* Connection identifier */
|
|
char name[ETCPMON_MAX_CONN_NAME]; /* Null-terminated name */
|
|
};
|
|
|
|
struct etcpmon_rsp_conn_list {
|
|
uint8_t count; /* Number of connections */
|
|
/* Followed by count * struct etcpmon_conn_info */
|
|
};
|
|
|
|
/* RSP_SOCKET_LIST: List of local sockets */
|
|
struct etcpmon_socket_info {
|
|
char name[ETCPMON_MAX_CONN_NAME]; /* Null-terminated socket name */
|
|
char ip[46]; /* Null-terminated IP address string */
|
|
uint16_t port; /* Port number (host byte order) */
|
|
uint8_t is_ipv6; /* 1 = IPv6, 0 = IPv4 */
|
|
uint8_t nat_type; /* NAT type (NAT_TYPE_*, NAT_VERIFIED_*) */
|
|
};
|
|
|
|
struct etcpmon_rsp_socket_list {
|
|
uint8_t count; /* Number of sockets */
|
|
/* Followed by count * struct etcpmon_socket_info */
|
|
};
|
|
|
|
/* RSP_METRICS: Full metrics for ETCP connection and its links */
|
|
|
|
/* ETCP Connection metrics */
|
|
struct etcpmon_etcp_metrics {
|
|
uint64_t peer_node_id; /* Connection identifier */
|
|
uint32_t rtt_last; /* Last RTT (0.1ms units) */
|
|
uint32_t rtt_avg_10; /* Average RTT over 10 packets */
|
|
uint32_t rtt_avg_100; /* Average RTT over 100 packets */
|
|
uint32_t jitter; /* Jitter (max-min RTT) */
|
|
uint64_t bytes_sent_total; /* Total bytes sent */
|
|
uint32_t retrans_count; /* Retransmission count */
|
|
uint32_t ack_count; /* ACK packets received */
|
|
uint32_t unacked_bytes; /* Current unacknowledged bytes */
|
|
uint32_t optimal_inflight; /* Target inflight window */
|
|
|
|
/* Queue metrics */
|
|
uint32_t input_queue_bytes;
|
|
uint32_t input_queue_packets;
|
|
uint32_t input_send_q_bytes;
|
|
uint32_t input_send_q_packets;
|
|
uint32_t input_wait_ack_bytes;
|
|
uint32_t input_wait_ack_packets;
|
|
uint32_t ack_q_bytes;
|
|
uint32_t ack_q_packets;
|
|
uint32_t recv_q_bytes;
|
|
uint32_t recv_q_packets;
|
|
uint32_t output_queue_bytes;
|
|
uint32_t output_queue_packets;
|
|
|
|
/* Error counters */
|
|
uint32_t reinit_count;
|
|
uint32_t reset_count;
|
|
uint32_t pkt_format_errors;
|
|
|
|
uint8_t links_count; /* Number of active links */
|
|
|
|
/* Timer flags (1 = active, 0 = NULL) */
|
|
uint8_t retrans_timer_active;
|
|
uint8_t ack_resp_timer_active;
|
|
|
|
/* input_wait_ack queue state */
|
|
uint8_t wait_ack_cb_suspended;
|
|
uint8_t wait_ack_cb_set;
|
|
uint8_t wait_ack_resume_timeout;
|
|
|
|
/* Connection IDs */
|
|
uint32_t next_tx_id;
|
|
uint32_t last_rx_id;
|
|
uint32_t last_delivered_id;
|
|
uint32_t rx_ack_till;
|
|
|
|
/* Normalizer */
|
|
uint32_t norm_input_pkts;
|
|
uint32_t norm_input_bytes;
|
|
uint32_t norm_output_pkts;
|
|
uint32_t norm_output_bytes;
|
|
uint32_t norm_alloc_errors;
|
|
uint32_t norm_logic_errors;
|
|
uint16_t norm_frag_size;
|
|
uint16_t norm_data_ptr;
|
|
uint16_t norm_data_size;
|
|
uint64_t norm_in_total_pkts;
|
|
uint64_t norm_in_total_bytes;
|
|
uint64_t norm_out_total_pkts;
|
|
uint64_t norm_out_total_bytes;
|
|
|
|
/* ACK debug counters */
|
|
uint32_t cnt_ack_hit_inf;
|
|
uint32_t cnt_ack_hit_sndq;
|
|
uint32_t cnt_ack_miss;
|
|
uint32_t cnt_link_wait;
|
|
uint32_t rx_dup_count;
|
|
uint32_t tx_dup_count;
|
|
uint32_t tx_state;
|
|
uint32_t debug[8];
|
|
|
|
/* System resources */
|
|
uint32_t active_timeouts;
|
|
uint32_t busy_memory_blocks;
|
|
};
|
|
|
|
/* Link metrics */
|
|
struct etcpmon_link_metrics {
|
|
uint8_t local_link_id; /* Local link identifier */
|
|
uint8_t status; /* 1 = up, 0 = down */
|
|
uint32_t encrypt_errors; /* Encryption errors */
|
|
uint32_t decrypt_errors; /* Decryption errors */
|
|
uint32_t send_errors; /* Send errors */
|
|
uint32_t recv_errors; /* Receive errors */
|
|
uint64_t total_encrypted; /* Total bytes encrypted/sent */
|
|
uint64_t total_decrypted; /* Total bytes decrypted/received */
|
|
uint32_t bandwidth; /* Configured bandwidth (Kbps) */
|
|
uint32_t nat_changes_count; /* NAT address changes */
|
|
uint32_t rtt_last; /* Last RTT (0.1ms units) */
|
|
uint32_t rtt_avg10; /* avg RTT (0.1ms units) */
|
|
uint32_t tt_last; /* Last transmit time (0.1ms units) */
|
|
|
|
/* Timer flags (1 = active, 0 = NULL) */
|
|
uint8_t init_timer_active;
|
|
uint8_t keepalive_timer_active;
|
|
uint8_t shaper_timer_active;
|
|
|
|
/* Keepalive counters */
|
|
uint32_t keepalive_sent;
|
|
uint32_t keepalive_recv;
|
|
|
|
/* Inflight counters */
|
|
uint32_t inflight_bytes;
|
|
uint32_t inflight_packets;
|
|
uint32_t inflight_lim_bytes;
|
|
};
|
|
|
|
/* TUN interface metrics */
|
|
struct etcpmon_tun_metrics {
|
|
uint64_t bytes_read; /* Bytes read from TUN */
|
|
uint64_t bytes_written; /* Bytes written to TUN */
|
|
uint32_t packets_read; /* Packets read from TUN */
|
|
uint32_t packets_written; /* Packets written to TUN */
|
|
uint32_t read_errors; /* Read error count */
|
|
uint32_t write_errors; /* Write error count */
|
|
|
|
/* Routing statistics */
|
|
uint64_t routed_packets; /* Successfully routed packets */
|
|
uint64_t dropped_packets; /* Dropped packets */
|
|
|
|
/* TUN queues */
|
|
uint32_t tun_in_q_packets; /* Packets in TUN input queue */
|
|
uint32_t tun_in_q_bytes; /* Bytes in TUN input queue */
|
|
uint32_t tun_out_q_packets; /* Packets in TUN output queue */
|
|
uint32_t tun_out_q_bytes; /* Bytes in TUN output queue */
|
|
|
|
/* Routing table */
|
|
uint32_t rt_count; /* Total routes in table */
|
|
uint32_t rt_local; /* Local routes */
|
|
uint32_t rt_learned; /* Learned routes (BGP) */
|
|
uint32_t rt_bgp_senders; /* BGP senders_list count (ROUTE_BGP) */
|
|
uint32_t rt_bgp_nodes; /* BGP nodes count (ROUTE_BGP) */
|
|
};
|
|
|
|
struct etcpmon_rsp_metrics {
|
|
struct etcpmon_etcp_metrics etcp; /* ETCP connection metrics */
|
|
struct etcpmon_tun_metrics tun; /* TUN interface metrics */
|
|
/* Followed by etcp.links_count * struct etcpmon_link_metrics */
|
|
};
|
|
|
|
/* RSP_ERROR: Error response */
|
|
struct etcpmon_rsp_error {
|
|
uint8_t error_code; /* Error code */
|
|
/* Followed by null-terminated error message string */
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
/* ============================================================================
|
|
* Helper Macros
|
|
* ============================================================================ */
|
|
|
|
/* Calculate size of connection list response */
|
|
#define ETCPMON_CONN_LIST_SIZE(count) \
|
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_conn_list) + \
|
|
(count) * sizeof(struct etcpmon_conn_info))
|
|
|
|
/* Calculate size of socket list response */
|
|
#define ETCPMON_SOCKET_LIST_SIZE(count) \
|
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_socket_list) + \
|
|
(count) * sizeof(struct etcpmon_socket_info))
|
|
|
|
/* Calculate size of metrics response */
|
|
#define ETCPMON_METRICS_SIZE(links_count) \
|
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_metrics) + \
|
|
(links_count) * sizeof(struct etcpmon_link_metrics))
|
|
|
|
/* Calculate size of error response */
|
|
#define ETCPMON_ERROR_SIZE(msg_len) \
|
|
(sizeof(struct etcpmon_msg_header) + sizeof(struct etcpmon_rsp_error) + (msg_len) + 1)
|
|
|
|
/* ============================================================================
|
|
* Utility Functions (optional, for both client and server)
|
|
* ============================================================================ */
|
|
|
|
/* Build message header */
|
|
static inline void etcpmon_build_header(struct etcpmon_msg_header* hdr,
|
|
uint16_t payload_size,
|
|
uint8_t msg_type,
|
|
uint8_t seq_id) {
|
|
hdr->size = sizeof(struct etcpmon_msg_header) + payload_size;
|
|
hdr->type = msg_type;
|
|
hdr->seq_id = seq_id;
|
|
}
|
|
|
|
/* Validate message header */
|
|
static inline int etcpmon_validate_header(const struct etcpmon_msg_header* hdr) {
|
|
if (hdr->size < sizeof(struct etcpmon_msg_header) ||
|
|
hdr->size > ETCPMON_MAX_MSG_SIZE) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* ETCPMON_PROTOCOL_H */
|