Файлы: route_node.* route_node_lmdb.* route_bgp.* -> topo_node.* topo_node_lmdb.* topo_bgp.* Структуры: - ROUTE_BGP -> TOPO_BGP, ROUTE_BGP_CONN_ITEM -> TOPO_BGP_CONN_ITEM - NODEINFO -> TOPO_NODE, NODEINFO_Q -> TOPO_NODEQ, NODEINFO_PATH -> TOPO_NODEPATH - NODEINFO_ROUTES -> TOPO_NODESUBNETS, NODE_CONNECTIVITY -> TOPO_CONNECTIVITY - wire: NODEINFO_MSG -> TOPOMSG_NODE, NODEINFO_IPV4_* -> TOPOMSG_*4 и т.д. - memory: NI_IPV4_* -> TOPO_*4, NI_IPV6_* -> TOPO_*6 - ROUTE_SUBCMD_* -> TOPO_SUBCMD_*, ETCP_ID_ROUTE_ENTRY -> ETCP_ID_TOPO_ENTRY Функции: - route_bgp_* -> topo_bgp_* - nodeinfo_* -> topo_node_* - route_node_* -> topo_node_* - route_node_lmdb_* -> topo_node_lmdb_* Смысл: отделение механизма формирования топологии узлов от IP-роутинга.
128 lines
3.7 KiB
C
128 lines
3.7 KiB
C
/*
|
|
* control_server.h - Control Socket Server for ETCP Monitoring
|
|
*
|
|
* Provides TCP control interface for ETCP connection monitoring
|
|
*/
|
|
|
|
#ifndef CONTROL_SERVER_H
|
|
#define CONTROL_SERVER_H
|
|
|
|
#include "../tools/etcpmon/etcpmon_protocol.h"
|
|
#include "../lib/socket_compat.h"
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Forward declarations */
|
|
struct UTUN_INSTANCE;
|
|
struct UASYNC;
|
|
struct TOPO_NODEQ;
|
|
struct ll_queue;
|
|
|
|
/* Forward declaration */
|
|
struct control_server;
|
|
|
|
/* Client connection state */
|
|
struct control_client {
|
|
struct control_client* next; /* Linked list */
|
|
struct control_server* server; /* Back pointer to server */
|
|
socket_t fd; /* Client socket */
|
|
void* socket_id; /* uasync socket ID */
|
|
|
|
/* Receive buffer */
|
|
uint8_t recv_buffer[ETCPMON_MAX_MSG_SIZE];
|
|
uint16_t recv_len; /* Bytes received so far */
|
|
|
|
/* Selected connection */
|
|
uint64_t selected_peer_id; /* 0 = none selected */
|
|
|
|
struct ll_queue* output_queue; /* Output queue for async sends */
|
|
void* idle_timer; /* Client idle timeout */
|
|
uint8_t subscribed_nodes; /* 1 = subscribed to node updates */
|
|
uint8_t write_registered; /* 1 = write events registered in uasync */
|
|
};
|
|
|
|
/* Control server state */
|
|
struct control_server {
|
|
struct UTUN_INSTANCE* instance; /* Parent instance */
|
|
struct UASYNC* ua; /* Async context */
|
|
|
|
/* Listening socket */
|
|
socket_t listen_fd;
|
|
void* listen_socket_id; /* uasync socket ID */
|
|
struct sockaddr_storage bind_addr; /* Bound address */
|
|
|
|
/* Client connections */
|
|
struct control_client* clients; /* Linked list of clients */
|
|
uint32_t client_count; /* Number of connected clients */
|
|
uint32_t max_clients; /* Maximum allowed clients */
|
|
|
|
/* Log file */
|
|
FILE* log_file;
|
|
};
|
|
|
|
/* ============================================================================
|
|
* Public API
|
|
* ============================================================================ */
|
|
|
|
/* Initialize control server
|
|
*
|
|
* Creates listening socket and registers with uasync
|
|
*
|
|
* Parameters:
|
|
* server - Server state structure to initialize
|
|
* ua - uasync context for event handling
|
|
* instance - Parent utun instance
|
|
* bind_addr - Address to bind (from config control_sock)
|
|
* max_clients - Maximum concurrent client connections
|
|
*
|
|
* Returns:
|
|
* 0 on success, -1 on error
|
|
*/
|
|
int control_server_init(struct control_server* server,
|
|
struct UASYNC* ua,
|
|
struct UTUN_INSTANCE* instance,
|
|
struct sockaddr_storage* bind_addr,
|
|
uint32_t max_clients);
|
|
|
|
/* Shutdown control server
|
|
*
|
|
* Closes all client connections and listening socket
|
|
*
|
|
* Parameters:
|
|
* server - Server state to shutdown
|
|
*/
|
|
void control_server_shutdown(struct control_server* server);
|
|
|
|
/* Process periodic updates
|
|
*
|
|
* Should be called periodically (e.g., from main loop) to send
|
|
* metrics updates to clients that have selected connections
|
|
*
|
|
* Parameters:
|
|
* server - Server state
|
|
*/
|
|
void control_server_process_updates(struct control_server* server);
|
|
|
|
/* Get number of connected clients
|
|
*
|
|
* Parameters:
|
|
* server - Server state
|
|
*
|
|
* Returns:
|
|
* Number of connected clients
|
|
*/
|
|
uint32_t control_server_get_client_count(const struct control_server* server);
|
|
|
|
void control_server_notify_node_change(struct control_server* server, struct TOPO_NODEQ* node);
|
|
void control_server_notify_node_removed(struct control_server* server, uint64_t node_id);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* CONTROL_SERVER_H */
|