You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
#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 "tun_if.h" |
|
|
|
// Forward declarations |
|
struct utun_config; |
|
struct uasync_s; |
|
struct routing_table; |
|
struct ETCP_CONN; |
|
struct ETCP_SOCKET; |
|
|
|
// uTun instance configuration |
|
struct UTUN_INSTANCE { |
|
// Configuration (moved from utun_state) |
|
struct utun_config *config; |
|
|
|
// TUN interface |
|
struct tun_config tun; |
|
void *tun_socket_id; // Socket ID from uasync_add_socket |
|
|
|
// Identification |
|
uint64_t node_id; |
|
|
|
struct SC_MYKEYS my_keys; |
|
|
|
// Main async context |
|
struct UASYNC* ua; |
|
|
|
// State |
|
int running; |
|
FILE *log_fp; |
|
|
|
struct memory_pool* pkt_pool; |
|
// Routing |
|
struct routing_table *routing_table; |
|
|
|
// Connections |
|
struct ETCP_CONN* connections;// linked-list |
|
int connections_count; // Number of connections |
|
|
|
// Active sockets |
|
struct ETCP_SOCKET* etcp_sockets;// linked-list |
|
}; |
|
|
|
// Instance creation flags |
|
#define UTUN_CREATE_ALLOW_TUN_FAILURE 0x0001 // Continue if TUN creation fails |
|
#define UTUN_CREATE_NO_TUN 0x0002 // Skip TUN initialization entirely |
|
#define UTUN_CREATE_TEST_MODE 0x0004 // Enable test hooks and virtual interfaces |
|
#define UTUN_CREATE_NO_SOCKET_BIND 0x0008 // Skip socket binding (for test injection) |
|
|
|
// Functions |
|
struct UTUN_INSTANCE* utun_instance_create_ex(struct UASYNC* ua, const char* config_file, const char* log_file, uint32_t flags); |
|
|
|
// Backward compatibility wrapper |
|
static inline struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char* config_file, const char* log_file) { |
|
return utun_instance_create_ex(ua, config_file, log_file, 0); |
|
} |
|
void utun_instance_destroy(struct UTUN_INSTANCE* instance); |
|
int utun_instance_init(struct UTUN_INSTANCE *instance); |
|
void utun_instance_run(struct UTUN_INSTANCE *instance); |
|
void utun_instance_stop(struct UTUN_INSTANCE *instance); |
|
|
|
// Diagnostic function for memory leak analysis |
|
void utun_instance_diagnose_leaks(struct UTUN_INSTANCE* instance, const char* phase); |
|
|
|
#endif // UTUN_INSTANCE_H
|
|
|