Files
utun2/src/utun_instance.h
T
Evgeny 1f4fe37fe5 proxy: rename + simplify + backpressure
- tcp_proxy/remote_proxy → tcp_proxy_client/tcp_proxy_server
- Все proxy файлы перенесены в src/proxy/
- Конфиг: [tcp_proxy]→[tcp_proxy_client], [remote_proxy]→[tcp_proxy_server]
- Убран subcmd CONNECTED (0x02) — клиент шлёт DATA сразу после CONNECT
- Backpressure: etcp_router_waiter_register/cancel через ll_queue threshold waiter
- Клиент: recv_cb send fail → tx_buf+waiter, не tcp_recved() (окно lwIP=0)
- Сервер: read_cb send fail → pause_buf+waiter, пауза read_id
- CLOSE/ERROR отправляется только после drain всех очередей
- Fail: conn не найден/closed → send ERROR вместо CLOSE/silent drop
- PROTOCOL.md: полная архитектура с диаграммами состояний и потоков
2026-06-02 18:02:37 +03:00

126 lines
3.7 KiB
C

#ifndef UTUN_INSTANCE_H
#define UTUN_INSTANCE_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "../lib/memory_pool.h"
#include "secure_channel.h"
#include "etcp_api.h"
#include "config_parser.h"
#include "firewall.h"
#include "eim_nat.h"
#include "nat_transport.h"
#include "proxy/tcp_proxy_client.h"
#include "etcp_router.h"
#include "proxy/tcp_proxy_server.h"
// Forward declarations
struct utun_config;
struct uasync_s;
struct ROUTE_TABLE;
struct ETCP_CONN;
typedef void (*etcp_new_conn_fn)(struct ETCP_CONN* conn, void* arg);
struct ETCP_SOCKET;
struct tun_if;
struct ETCP_BINDINGS;
struct ETCP_ROUTER_BINDINGS;
struct ROUTE_BGP;
struct control_server;
struct PING_CONTEXT;
// uTun instance configuration
struct UTUN_INSTANCE {
// Identification
char name[16]; // Instance name from config
// Configuration (moved from utun_state)
struct utun_config *config;
// TUN interface
struct tun_if* tun;
// Route subnets (for cleanup on shutdown)
struct CFG_ROUTE_ENTRY* route_subnets;
struct ROUTE_TABLE* rt;
struct ROUTE_BGP* bgp; // BGP module for route exchange
// Identification
uint64_t node_id;
struct SC_MYKEYS my_keys;
uint8_t next_socket_id; // Counter for unique socket IDs (0-255)
// Main async context
struct UASYNC* ua;
// State
int running;
// Connections (список всех подключений для instance)
struct ETCP_CONN* connections;// linked-list
int connections_count; // Number of connections
// Callback for new ETCP connections
etcp_new_conn_fn etcp_new_conn_cbk;
void* etcp_new_conn_arg;
struct memory_pool* data_pool;// для входных-выходных данных пакета
struct memory_pool* pkt_pool;
struct memory_pool* ack_pool;
// Active sockets
struct ETCP_SOCKET* etcp_sockets;// linked-list
// Pending one-shot pings (for callback on PONG or timeout)
struct PING_CONTEXT* pending_pings;
// Routing statistics
uint64_t routed_packets;
uint64_t dropped_packets;
// ETCP API bindings (per-instance)
struct ETCP_BINDINGS api_bindings;
// Control server for monitoring
struct control_server* control_srv;
// Firewall
struct firewall_ctx fw;
// EIM NAT
struct eim_nat_ctx nat;
struct nat_transport_ctx nat_tr;
// Socket initialization status: 0=OK, 1=partial (some sockets failed), -1=error (none created)
int socket_init_status;
// TCP proxy client (optional, NULL if not enabled)
struct tcp_proxy_client* tcp_proxy_client;
// etcp_router bindings и seq-connections (per-instance service routing)
struct ETCP_ROUTER_BINDINGS router_bindings;
struct ll_queue* router_conns;
// TCP proxy server (exit node)
struct tcp_proxy_server tcp_proxy_server;
};
// Functions
struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char* config_file);
struct UTUN_INSTANCE* utun_instance_create_from_config(struct UASYNC* ua, struct utun_config* config);
struct UTUN_INSTANCE* utun_instance_create_from_str(struct UASYNC* ua, const char* config_text);
void utun_instance_destroy(struct UTUN_INSTANCE* instance);
int utun_instance_init(struct UTUN_INSTANCE *instance);
struct UTUN_INSTANCE *utun_instance_reload(struct UTUN_INSTANCE *instance, struct UASYNC *ua, const char *config_file);
void utun_instance_run(struct UTUN_INSTANCE *instance);
void utun_instance_stop(struct UTUN_INSTANCE *instance);
void utun_instance_set_tun_init_enabled(int enabled);
// Diagnostic function for memory leak analysis
void utun_instance_diagnose_leaks(struct UTUN_INSTANCE* instance, const char* phase);
#endif // UTUN_INSTANCE_H