diff --git a/lib/ll_queue.h b/lib/ll_queue.h index 5d0653be..086ccec7 100644 --- a/lib/ll_queue.h +++ b/lib/ll_queue.h @@ -1,6 +1,11 @@ #ifndef LL_QUEUE_H #define LL_QUEUE_H +#ifdef __cplusplus +extern "C" { +#endif + + #include // для size_t #include // для uint64_t #include "memory_pool.h" // для struct memory_pool @@ -412,4 +417,8 @@ static inline size_t queue_total_bytes(struct ll_queue* q) { return q->total_bytes; } + +#ifdef __cplusplus +} +#endif #endif // LL_QUEUE_H diff --git a/lib/memory_pool.h b/lib/memory_pool.h index 4cb0f474..dfe1cd2c 100644 --- a/lib/memory_pool.h +++ b/lib/memory_pool.h @@ -2,6 +2,11 @@ #ifndef MEMORY_POOL_H #define MEMORY_POOL_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "debug_config.h" @@ -37,4 +42,8 @@ size_t memory_pool_get_total_free_blocks(void); int memory_pool_is_freed(struct memory_pool* pool, void* obj); + +#ifdef __cplusplus +} +#endif #endif // MEMORY_POOL_H diff --git a/lib/platform_compat.h b/lib/platform_compat.h index 00c7f277..2a9664f8 100644 --- a/lib/platform_compat.h +++ b/lib/platform_compat.h @@ -5,6 +5,11 @@ #ifndef PLATFORM_COMPAT_H #define PLATFORM_COMPAT_H +#ifdef __cplusplus +extern "C" { +#endif + + #ifdef _WIN32 #include #include @@ -186,4 +191,8 @@ int get_interface_ipv6_by_index(uint32_t netif_index, int temporary, uint8_t* ad // family: AF_INET or AF_INET6, returns ifindex (0 on failure) uint32_t get_default_route_netif_index(int family); + +#ifdef __cplusplus +} +#endif #endif // PLATFORM_COMPAT_H diff --git a/lib/radix.h b/lib/radix.h index e1b12591..9dffd3e7 100644 --- a/lib/radix.h +++ b/lib/radix.h @@ -32,6 +32,15 @@ #ifndef _RADIX_H_ #define _RADIX_H_ +#ifdef __cplusplus +extern "C" { + +#ifdef __cplusplus +} +#endif +#endif + + #include #include "mem.h" diff --git a/lib/serialize.h b/lib/serialize.h index eee638c4..56dfc426 100644 --- a/lib/serialize.h +++ b/lib/serialize.h @@ -76,6 +76,11 @@ */ #ifndef SERIALIZE_H #define SERIALIZE_H + +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include "../lib/mem.h" @@ -127,4 +132,8 @@ int serialize_decode(const uint8_t* in_buf, size_t in_len, void serialize_free(const struct SerializeSchema* schema, void** structure); + +#ifdef __cplusplus +} +#endif #endif // SERIALIZE_H diff --git a/lib/sha256.h b/lib/sha256.h index a9754f4a..d6fd600a 100644 --- a/lib/sha256.h +++ b/lib/sha256.h @@ -9,6 +9,11 @@ #ifndef SC_SHA256_H #define SC_SHA256_H +#ifdef __cplusplus +extern "C" { +#endif + + /*************************** HEADER FILES ***************************/ #include #include @@ -29,4 +34,8 @@ void sc_sha256_init(SC_SHA256_CTX *ctx); void sc_sha256_update(SC_SHA256_CTX *ctx, const uint8_t data[], size_t len); void sc_sha256_final(SC_SHA256_CTX *ctx, uint8_t hash[]); + +#ifdef __cplusplus +} +#endif #endif // SC_SHA256_H diff --git a/lib/socket_compat.h b/lib/socket_compat.h index d2fbe4d9..f7e154cd 100644 --- a/lib/socket_compat.h +++ b/lib/socket_compat.h @@ -5,6 +5,11 @@ #ifndef SOCKET_COMPAT_H #define SOCKET_COMPAT_H + +#ifdef __cplusplus +extern "C" { +#endif + #include #ifdef _WIN32 @@ -73,4 +78,8 @@ const char* socket_strerror(int err); // взять порт из sockaddr_storage uint16_t ss_get_port(const struct sockaddr_storage *addr); + +#ifdef __cplusplus +} +#endif #endif // SOCKET_COMPAT_H diff --git a/lib/tcp_io.h b/lib/tcp_io.h index fc4bf2c0..a8f609e4 100644 --- a/lib/tcp_io.h +++ b/lib/tcp_io.h @@ -22,6 +22,11 @@ #ifndef TCP_IO_H #define TCP_IO_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "u_async.h" #include "socket_compat.h" #include "ll_queue.h" @@ -108,4 +113,8 @@ void tcp_conn_set_flushed(struct tcp_conn* tc, void (*on_flushed)(struct tcp_con // Принудительная остановка чтения: убирает EPOLLIN и отменяет read_waiter. void tcp_conn_pause_read(struct tcp_conn* tc); + +#ifdef __cplusplus +} +#endif #endif diff --git a/lib/timeout_heap.h b/lib/timeout_heap.h index 8e093f2f..182eccca 100644 --- a/lib/timeout_heap.h +++ b/lib/timeout_heap.h @@ -3,6 +3,11 @@ #ifndef TIMEOUT_HEAP_H #define TIMEOUT_HEAP_H +#ifdef __cplusplus +extern "C" { +#endif + + #include // For uint64_t #include // For size_t @@ -94,4 +99,8 @@ size_t timeout_heap_get_freed_count(TimeoutHeap *h); size_t timeout_heap_get_size(TimeoutHeap *h); + +#ifdef __cplusplus +} +#endif #endif // TIMEOUT_HEAP_H diff --git a/lib/u_async.h b/lib/u_async.h index 187e12b7..6028bd59 100644 --- a/lib/u_async.h +++ b/lib/u_async.h @@ -5,18 +5,23 @@ #ifndef UASYNC_H #define UASYNC_H -#include "platform_compat.h" -#include -#include -#include "timeout_heap.h" +#ifdef __cplusplus +extern "C" { +#endif + + +#include "platform_compat.h" +#include +#include +#include "timeout_heap.h" #include "socket_compat.h" typedef void (*timeout_callback_t)(void* user_arg);// передаёт user_arg из uasync_set_timeout typedef void (*socket_callback_t)(int fd, void* user_arg);// передаёт user_arg из uasync_add_socket (for pipe/file) typedef void (*socket_t_callback_t)(socket_t sock, void* user_arg);// передаёт user_arg из uasync_add_socket_t (for sockets) // user_arg полезен если нужно передать управляющую структуру. Ее можно выделить в памяти и в ней хранить всё что надо. т.е. при set_timeout передаём и получаем ее в callback-е - - + + // Error type typedef int err_t; #define ERR_OK 0 @@ -28,21 +33,21 @@ typedef int err_t; typedef void (*uasync_post_callback_t)(void* user_arg); -#include "memory_pool.h" - -struct timeout_node; // Forward declaration - +#include "memory_pool.h" + +struct timeout_node; // Forward declaration + struct posted_task { uasync_post_callback_t callback; void* arg; struct posted_task* next; }; -// Uasync instance structure -struct UASYNC { - struct memory_pool* timeout_pool; // Pool for timeout_node allocation - struct timeout_node* immediate_queue_head; // FIFO queue for immediate execution - struct timeout_node* immediate_queue_tail; +// Uasync instance structure +struct UASYNC { + struct memory_pool* timeout_pool; // Pool for timeout_node allocation + struct timeout_node* immediate_queue_head; // FIFO queue for immediate execution + struct timeout_node* immediate_queue_tail; TimeoutHeap* timeout_heap; // Heap for timeout management struct socket_array* sockets; // Array-based socket management // Debug counters for memory allocation tracking @@ -67,55 +72,55 @@ struct UASYNC { #ifdef _WIN32 CRITICAL_SECTION posted_lock; #else - pthread_mutex_t posted_lock; -#endif - volatile sig_atomic_t stop; + pthread_mutex_t posted_lock; +#endif + volatile sig_atomic_t stop; }; - -// Type definitions -typedef struct UASYNC uasync_t; -typedef struct UASYNC UASYNC_t; - -// Instance API - основной API для работы с uasync -struct UASYNC* uasync_create(void); -void uasync_destroy(struct UASYNC* ua, int close_fds); - -// текущее время (timebase 0.1ms) -uint64_t get_time_tb(void); -// текущее время в микросекундах (для burst-измерений) -uint64_t get_time_us(void); - -// Timeouts, timebase = 0.1 mS -// Как работать с таймаутами если таймаут может быть использован несколько раз: -// 1. заводим дескриптор таймаута и обнуляем -// 2. перед активацией таймаута проверяем дескриптор (t_id) на null -// 3. при cancel или срабатывании дескриптор обнуляем -// это обеспечит отсутствие утечек и задвоений таймаутов -void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback, const char* name); -err_t uasync_cancel_timeout(struct UASYNC* ua, void* t_id); - -// Immediate execution in next mainloop (FIFO order) -void* uasync_call_soon(struct UASYNC* ua, void* user_arg, timeout_callback_t callback); -err_t uasync_call_soon_cancel(struct UASYNC* ua, void* t_id); - + +// Type definitions +typedef struct UASYNC uasync_t; +typedef struct UASYNC UASYNC_t; + +// Instance API - основной API для работы с uasync +struct UASYNC* uasync_create(void); +void uasync_destroy(struct UASYNC* ua, int close_fds); + +// текущее время (timebase 0.1ms) +uint64_t get_time_tb(void); +// текущее время в микросекундах (для burst-измерений) +uint64_t get_time_us(void); + +// Timeouts, timebase = 0.1 mS +// Как работать с таймаутами если таймаут может быть использован несколько раз: +// 1. заводим дескриптор таймаута и обнуляем +// 2. перед активацией таймаута проверяем дескриптор (t_id) на null +// 3. при cancel или срабатывании дескриптор обнуляем +// это обеспечит отсутствие утечек и задвоений таймаутов +void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback, const char* name); +err_t uasync_cancel_timeout(struct UASYNC* ua, void* t_id); + +// Immediate execution in next mainloop (FIFO order) +void* uasync_call_soon(struct UASYNC* ua, void* user_arg, timeout_callback_t callback); +err_t uasync_call_soon_cancel(struct UASYNC* ua, void* t_id); + // Sockets - for regular file descriptors (pipe, file) void* uasync_add_socket(struct UASYNC* ua, int fd, socket_callback_t read_cbk, socket_callback_t write_cbk, socket_callback_t except_cbk, void* user_arg); // Sockets - for socket_t (cross-platform sockets) void* uasync_add_socket_t(struct UASYNC* ua, socket_t sock, socket_t_callback_t read_cbk, socket_t_callback_t write_cbk, socket_t_callback_t except_cbk, void* user_arg); -err_t uasync_remove_socket(struct UASYNC* ua, void* s_id); -err_t uasync_remove_socket_t(struct UASYNC* ua, socket_t sock); - -// Динамическое управление мониторингом чтения/записи для сокета -err_t uasync_set_socket_read(struct UASYNC* ua, void* s_id, int enable); +err_t uasync_remove_socket(struct UASYNC* ua, void* s_id); +err_t uasync_remove_socket_t(struct UASYNC* ua, socket_t sock); + +// Динамическое управление мониторингом чтения/записи для сокета +err_t uasync_set_socket_read(struct UASYNC* ua, void* s_id, int enable); err_t uasync_set_socket_write(struct UASYNC* ua, void* s_id, int enable); - -// Single iteration of event loop with timeout (timebase units) -void uasync_poll(struct UASYNC* ua, int timeout_tb); - -// Mainloop (бесконечный цикл, __noreturn) -void uasync_mainloop(struct UASYNC* ua); -void uasync_stop(struct UASYNC* ua); - + +// Single iteration of event loop with timeout (timebase units) +void uasync_poll(struct UASYNC* ua, int timeout_tb); + +// Mainloop (бесконечный цикл, __noreturn) +void uasync_mainloop(struct UASYNC* ua); +void uasync_stop(struct UASYNC* ua); + // Debug statistics void uasync_get_stats(struct UASYNC* ua, size_t* timer_alloc, size_t* timer_free, size_t* socket_alloc, size_t* socket_free); @@ -124,15 +129,19 @@ int uasync_lookup_socket(struct UASYNC* ua, int fd, void** socket_id); // Print all resources (timers, sockets) for debugging void uasync_print_resources(struct UASYNC* ua, const char* prefix); - -// Wakeup mechanism for interrupting poll -int uasync_wakeup(struct UASYNC* ua); -int uasync_get_wakeup_fd(struct UASYNC* ua); // returns write fd for wakeup pipe (for signal handlers) - -// сообщить async (из другого thread) чтобы он вызвал callback с аргументом -void uasync_post(struct UASYNC* ua, uasync_post_callback_t callback, void* user_arg); - -// синхронизация памяти (для доступности из других потоков) -void uasync_memsync(struct UASYNC* ua); - -#endif // UASYNC_H + +// Wakeup mechanism for interrupting poll +int uasync_wakeup(struct UASYNC* ua); +int uasync_get_wakeup_fd(struct UASYNC* ua); // returns write fd for wakeup pipe (for signal handlers) + +// сообщить async (из другого thread) чтобы он вызвал callback с аргументом +void uasync_post(struct UASYNC* ua, uasync_post_callback_t callback, void* user_arg); + +// синхронизация памяти (для доступности из других потоков) +void uasync_memsync(struct UASYNC* ua); + + +#ifdef __cplusplus +} +#endif +#endif // UASYNC_H diff --git a/src/conn_mgr.h b/src/conn_mgr.h index 67754278..8b3b1526 100644 --- a/src/conn_mgr.h +++ b/src/conn_mgr.h @@ -1,6 +1,11 @@ #ifndef CONN_MGR_H #define CONN_MGR_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include "../lib/ll_queue.h" @@ -436,4 +441,8 @@ int conn_mgr_send(struct CONN_MGR* mgr, uint64_t node_id, struct ll_entry* entry */ void conn_mgr_update_best_candidates(struct CONN_MGR* mgr, uint64_t node_id, uint16_t rtt); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/crc32.h b/src/crc32.h index ea1a334b..89c55cb5 100644 --- a/src/crc32.h +++ b/src/crc32.h @@ -1,6 +1,11 @@ #ifndef CRC32_H #define CRC32_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -16,4 +21,8 @@ uint32_t crc32_calc_ex(const uint8_t *data, size_t len, uint32_t initial_crc); // Update CRC32 incrementally uint32_t crc32_update(uint32_t crc, const uint8_t *data, size_t len); + +#ifdef __cplusplus +} +#endif #endif // CRC32_H \ No newline at end of file diff --git a/src/db_sync.h b/src/db_sync.h index 7b23aaa7..52ccaa4e 100644 --- a/src/db_sync.h +++ b/src/db_sync.h @@ -2,6 +2,11 @@ #ifndef DB_SYNC_H #define DB_SYNC_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -38,4 +43,8 @@ int db_sync_insert(struct UTUN_INSTANCE* inst, const char* json_data); int db_sync_insert_len(struct UTUN_INSTANCE* inst, const char* json_data, size_t len); uint32_t db_sync_count(struct UTUN_INSTANCE* inst); + +#ifdef __cplusplus +} +#endif #endif // DB_SYNC_H diff --git a/src/dnsmasq/dnsmasq-2.93.tar.xz b/src/dnsmasq/dnsmasq-2.93.tar.xz new file mode 100644 index 00000000..269baa34 Binary files /dev/null and b/src/dnsmasq/dnsmasq-2.93.tar.xz differ diff --git a/src/dummynet.h b/src/dummynet.h index dbc0bd8c..ca3f38a2 100644 --- a/src/dummynet.h +++ b/src/dummynet.h @@ -21,6 +21,11 @@ #ifndef DUMMYNET_H #define DUMMYNET_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -179,4 +184,8 @@ const struct dummynet_stats* dummynet_filter_get_stats(struct dummynet_filter* d void dummynet_filter_block_addr(struct dummynet_filter* df, uint32_t ip, uint16_t port); void dummynet_filter_unblock_addr(struct dummynet_filter* df, uint32_t ip, uint16_t port); + +#ifdef __cplusplus +} +#endif #endif // DUMMYNET_H diff --git a/src/eim_nat.h b/src/eim_nat.h index 9c984677..b8d5aac3 100644 --- a/src/eim_nat.h +++ b/src/eim_nat.h @@ -1,6 +1,11 @@ #ifndef EIM_NAT_H #define EIM_NAT_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -51,4 +56,8 @@ int eim_nat_add_forward(struct eim_nat_ctx* ctx, uint8_t proto, uint32_t internal_ip_host, uint16_t internal_port_net, uint16_t external_port); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/etcp_api.h b/src/etcp_api.h index 6df7ae4e..4285eef8 100644 --- a/src/etcp_api.h +++ b/src/etcp_api.h @@ -17,6 +17,11 @@ #ifndef ETCP_API_H #define ETCP_API_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "../lib/ll_queue.h" @@ -157,4 +162,8 @@ void etcp_set_routing_exchange_state(struct ETCP_CONN* conn, uint8_t new_state); */ void etcp_int_recv(struct ll_queue* queue, void* arg); + +#ifdef __cplusplus +} +#endif #endif // ETCP_API_H diff --git a/src/etcp_bbr.h b/src/etcp_bbr.h index be747be5..941842b5 100644 --- a/src/etcp_bbr.h +++ b/src/etcp_bbr.h @@ -1,6 +1,10 @@ #pragma once #include +#ifdef __cplusplus +extern "C" { +#endif + #define BBR_SCALE 8 #define BBR_UNIT (1 << BBR_SCALE) #define BW_SCALE 24 @@ -110,3 +114,7 @@ void bbr_main(struct bbr* bbr, const struct bbr_rate_sample* rs, uint32_t mss, uint32_t inflight_bytes, int is_cwnd_limited); void bbr_note_loss(struct bbr* bbr); void bbr_tx_start(struct bbr* bbr); + +#ifdef __cplusplus +} +#endif diff --git a/src/etcp_connections.h b/src/etcp_connections.h index deefd185..b5ca765f 100644 --- a/src/etcp_connections.h +++ b/src/etcp_connections.h @@ -1,6 +1,11 @@ #ifndef ETCP_CONNECTIONS_H #define ETCP_CONNECTIONS_H +#ifdef __cplusplus +extern "C" { +#endif + + // подмодуль ETCP который обслуживает сокеты ETCP для приёма-передачи пакетов и одно ETCP подключение через несколько каналов связи (failover) #include "secure_channel.h" @@ -334,4 +339,8 @@ int etcp_send_ping_to_socket(struct UTUN_INSTANCE* instance, struct ETCP_SOCKET* void etcp_connections_read_callback_socket(socket_t sock, void* arg); + +#ifdef __cplusplus +} +#endif #endif // ETCP_CONNECTIONS_H diff --git a/src/etcp_debug.h b/src/etcp_debug.h index b307d271..2b540d51 100644 --- a/src/etcp_debug.h +++ b/src/etcp_debug.h @@ -1,6 +1,11 @@ #ifndef ETCP_DEBUG_H #define ETCP_DEBUG_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "etcp_connections.h" typedef struct { char a[16]; } IP_STR; @@ -9,4 +14,8 @@ IP_STR ip_to_string(uint32_t ip); void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int is_send); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/etcp_dump.h b/src/etcp_dump.h index 0d06b217..17562f22 100644 --- a/src/etcp_dump.h +++ b/src/etcp_dump.h @@ -1,10 +1,19 @@ #ifndef ETCP_DUMP_H #define ETCP_DUMP_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "etcp.h" #include "utun_instance.h" void etcp_dump_conn_state(struct ETCP_CONN* conn); void etcp_dump_all_conns(struct UTUN_INSTANCE* instance); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/etcp_router.h b/src/etcp_router.h index 11068ca6..709017ed 100644 --- a/src/etcp_router.h +++ b/src/etcp_router.h @@ -9,6 +9,11 @@ #ifndef ETCP_ROUTER_H #define ETCP_ROUTER_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "etcp_api.h" @@ -219,4 +224,8 @@ void etcp_router_conn_restart(struct UTUN_INSTANCE* inst, uint64_t remote_node_i // Удалить все транзитные очереди соединения (вызывается при закрытии ETCP_CONN) void etcp_router_transit_queues_destroy(struct ETCP_CONN* conn); + +#ifdef __cplusplus +} +#endif #endif // ETCP_ROUTER_H diff --git a/src/lwip_tcp/lwip_pbuf.h b/src/lwip_tcp/lwip_pbuf.h index 58e12c1e..ab7b9a87 100644 --- a/src/lwip_tcp/lwip_pbuf.h +++ b/src/lwip_tcp/lwip_pbuf.h @@ -2,6 +2,11 @@ #ifndef LWIP_PBUF_H #define LWIP_PBUF_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -38,4 +43,8 @@ int pbuf_take(struct pbuf *p, const void *data, uint16_t len); int pbuf_take_at(struct pbuf *p, const void *data, uint16_t len, uint16_t offset); void* pbuf_get_contiguous(const struct pbuf *p, void *buf, size_t len, size_t offset); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/lwip_tcp/lwip_tcp.h b/src/lwip_tcp/lwip_tcp.h index 9da4acbf..525ee954 100644 --- a/src/lwip_tcp/lwip_tcp.h +++ b/src/lwip_tcp/lwip_tcp.h @@ -2,6 +2,11 @@ #ifndef LWIP_TCP_H #define LWIP_TCP_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include "lwip_pbuf.h" @@ -270,4 +275,8 @@ void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, uint8_t interval); #define tcp_clear_flags(pcb, clr_flags) ((pcb)->flags &= (tcpflags_t)~(clr_flags)) #define tcp_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0) + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/lwip_tcp/lwip_tcp_opts.h b/src/lwip_tcp/lwip_tcp_opts.h index 4c5f5b59..edd70e4a 100644 --- a/src/lwip_tcp/lwip_tcp_opts.h +++ b/src/lwip_tcp/lwip_tcp_opts.h @@ -2,6 +2,11 @@ #ifndef LWIP_TCP_OPTS_H #define LWIP_TCP_OPTS_H +#ifdef __cplusplus +extern "C" { +#endif + + #define TCP_MSS 1460 #define TCP_SND_BUF (16 * TCP_MSS) #define TCP_WND (8 * TCP_MSS) @@ -47,4 +52,8 @@ #define TCP_PRIO_NORMAL 64 #define TCP_PRIO_MAX 127 + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/lwip_tcp/lwip_tcp_priv.h b/src/lwip_tcp/lwip_tcp_priv.h index ddee3020..4ff59d77 100644 --- a/src/lwip_tcp/lwip_tcp_priv.h +++ b/src/lwip_tcp/lwip_tcp_priv.h @@ -2,6 +2,11 @@ #ifndef LWIP_TCP_PRIV_H #define LWIP_TCP_PRIV_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "lwip_tcp.h" #include "lwip_tcp_opts.h" #include @@ -245,4 +250,8 @@ void lwip_tcp_stats_clear(struct lwip_tcp_ctx *ctx); #define TCP_REG_ACTIVE(ctx, npcb) TCP_REG(&(ctx)->active_pcbs, npcb) #define TCP_RMV_ACTIVE(ctx, npcb) TCP_RMV(&(ctx)->active_pcbs, npcb) + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/nat_transport.h b/src/nat_transport.h index f86afc3e..7d7b956e 100644 --- a/src/nat_transport.h +++ b/src/nat_transport.h @@ -2,6 +2,11 @@ #ifndef NAT_TRANSPORT_H #define NAT_TRANSPORT_H +#ifdef __cplusplus +extern "C" { +#endif + + #include struct tun_if; @@ -19,4 +24,8 @@ struct UTUN_INSTANCE; int nat_transport_init(struct UTUN_INSTANCE* inst); void nat_transport_destroy(struct UTUN_INSTANCE* inst); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/packet_dump.h b/src/packet_dump.h index ad2b8ebd..c722246d 100644 --- a/src/packet_dump.h +++ b/src/packet_dump.h @@ -1,6 +1,19 @@ +#ifndef PACKET_DUMP_H +#define PACKET_DUMP_H + #include #include #include #include "../lib/platform_compat.h" +#ifdef __cplusplus +extern "C" { +#endif + char* dump_ip_packet_to_buffer(const uint8_t* data, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif // PACKET_DUMP_H diff --git a/src/pkt_normalizer.h b/src/pkt_normalizer.h index b97a21e5..95de7b01 100644 --- a/src/pkt_normalizer.h +++ b/src/pkt_normalizer.h @@ -2,6 +2,11 @@ #ifndef PKT_NORMALIZER_H #define PKT_NORMALIZER_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "../lib/ll_queue.h" #include "../lib/u_async.h" #include @@ -67,4 +72,8 @@ void pn_unpacker_reset_state(struct PKTNORM* pn); // создаёт malloc data, копирует, помещает в input. //void pn_packer_send(struct PKTNORM* pn, uint8_t* data, uint16_t len); + +#ifdef __cplusplus +} +#endif #endif // PKT_NORMALIZER_H \ No newline at end of file diff --git a/src/proxy/icmp_proxy.h b/src/proxy/icmp_proxy.h index 9b7fe147..c5b09ae1 100644 --- a/src/proxy/icmp_proxy.h +++ b/src/proxy/icmp_proxy.h @@ -2,6 +2,11 @@ #ifndef ICMP_PROXY_H #define ICMP_PROXY_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "../lib/socket_compat.h" @@ -62,4 +67,8 @@ int icmp_proxy_deliver_reply(struct UTUN_INSTANCE* inst, void icmp_proxy_set_test_loopback(struct UTUN_INSTANCE* inst, int enabled); + +#ifdef __cplusplus +} +#endif #endif // ICMP_PROXY_H diff --git a/src/proxy/socks_proxy.h b/src/proxy/socks_proxy.h index ce92a2e1..5b31882e 100644 --- a/src/proxy/socks_proxy.h +++ b/src/proxy/socks_proxy.h @@ -2,6 +2,11 @@ #ifndef SOCKS_PROXY_H #define SOCKS_PROXY_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "../lib/socket_compat.h" #include "../lib/ll_queue.h" @@ -80,4 +85,8 @@ void socks_proxy_conn_free(struct socks_proxy_conn* c); // Освободить все соединения в списке void socks_proxy_conn_free_all(struct socks_proxy_conn** head, int* count); + +#ifdef __cplusplus +} +#endif #endif // SOCKS_PROXY_H diff --git a/src/proxy/tcp_proxy_client.h b/src/proxy/tcp_proxy_client.h index 6e9c34f4..9b8da4fb 100644 --- a/src/proxy/tcp_proxy_client.h +++ b/src/proxy/tcp_proxy_client.h @@ -2,6 +2,11 @@ #ifndef TCP_PROXY_CLIENT_H #define TCP_PROXY_CLIENT_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include "../lib/socket_compat.h" @@ -82,4 +87,8 @@ struct tcp_proxy_client* tcp_proxy_client_create(struct UTUN_INSTANCE* inst, str void tcp_proxy_client_destroy(struct tcp_proxy_client* p); void tcp_proxy_client_router_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry); + +#ifdef __cplusplus +} +#endif #endif // TCP_PROXY_CLIENT_H diff --git a/src/proxy/tcp_proxy_server.h b/src/proxy/tcp_proxy_server.h index 71e7b497..b9016e84 100644 --- a/src/proxy/tcp_proxy_server.h +++ b/src/proxy/tcp_proxy_server.h @@ -2,6 +2,11 @@ #ifndef TCP_PROXY_SERVER_H #define TCP_PROXY_SERVER_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "../lib/socket_compat.h" #include "../lib/ll_queue.h" @@ -73,4 +78,8 @@ void tcp_proxy_server_handle_close(struct UTUN_INSTANCE* inst, uint32_t stream_i void tcp_proxy_server_handle_error(struct UTUN_INSTANCE* inst, uint32_t stream_id); void tcp_proxy_server_handle_fin(struct UTUN_INSTANCE* inst, uint32_t stream_id); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/proxy/udp_proxy.h b/src/proxy/udp_proxy.h index cbbb3069..f54843ad 100644 --- a/src/proxy/udp_proxy.h +++ b/src/proxy/udp_proxy.h @@ -2,6 +2,11 @@ #ifndef UDP_PROXY_H #define UDP_PROXY_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "../lib/socket_compat.h" @@ -62,4 +67,8 @@ int udp_proxy_deliver_reply(struct UTUN_INSTANCE* inst, uint32_t dst_ip, uint16_t dst_port, const uint8_t* payload, size_t payload_len); + +#ifdef __cplusplus +} +#endif #endif // UDP_PROXY_H diff --git a/src/route6_lib.h b/src/route6_lib.h index 0b356b64..3132552f 100644 --- a/src/route6_lib.h +++ b/src/route6_lib.h @@ -1,5 +1,10 @@ #ifndef ROUTE6_LIB_H #define ROUTE6_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -65,4 +70,8 @@ bool route6_insert(struct ROUTE6_TABLE *table, struct NODEINFO_Q *node); void route6_delete(struct ROUTE6_TABLE *table, struct NODEINFO_Q *node); const struct ROUTE6_DATA *route6_lookup(struct ROUTE6_TABLE *table, const uint8_t addr[16]); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/route_bgp.h b/src/route_bgp.h index 4c6ac8e8..e6d9e593 100644 --- a/src/route_bgp.h +++ b/src/route_bgp.h @@ -1,6 +1,11 @@ #ifndef ROUTE_BGP_H #define ROUTE_BGP_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include "../lib/ll_queue.h" @@ -224,4 +229,8 @@ struct nat_check_arg { uint16_t nat_port; }; + +#ifdef __cplusplus +} +#endif #endif // ROUTE_BGP_H diff --git a/src/route_connectivity.h b/src/route_connectivity.h index 1d6f65e3..08154663 100644 --- a/src/route_connectivity.h +++ b/src/route_connectivity.h @@ -1,6 +1,11 @@ #ifndef ROUTE_CONNECTIVITY_H #define ROUTE_CONNECTIVITY_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "route_node.h" @@ -17,4 +22,8 @@ void route_connectivity_cancel_node(struct UTUN_INSTANCE* instance, // Отменяет все pending пробы для всех узлов (при destroy) void route_connectivity_cancel_all(struct UTUN_INSTANCE* instance); + +#ifdef __cplusplus +} +#endif #endif // ROUTE_CONNECTIVITY_H diff --git a/src/route_lib.h b/src/route_lib.h index d52d3cdf..caa49253 100644 --- a/src/route_lib.h +++ b/src/route_lib.h @@ -1,5 +1,10 @@ #ifndef ROUTE_LIB_H #define ROUTE_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -120,4 +125,8 @@ bool route_add_local_subnet(struct ROUTE_TABLE *table, uint32_t network, uint8_t */ int is_local_subnet(uint32_t ip); + +#ifdef __cplusplus +} +#endif #endif // ROUTE_LIB_H diff --git a/src/route_node.h b/src/route_node.h index 319bfca6..7a3ac70f 100644 --- a/src/route_node.h +++ b/src/route_node.h @@ -1,6 +1,10 @@ #ifndef ROUTE_NODE_H #define ROUTE_NODE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include "../lib/ll_queue.h" @@ -199,4 +203,8 @@ struct NODEINFO_Q* nodeinfo_find_by_id(struct ROUTE_BGP* bgp, uint64_t node_id); void route_node_dump_all(struct ROUTE_BGP* bgp); int route_node_format_all(struct ROUTE_BGP* bgp, char* buf, size_t buf_size); +#ifdef __cplusplus +} +#endif + #endif // ROUTE_NODE_H diff --git a/src/route_node_lmdb.h b/src/route_node_lmdb.h index 2a4eba4b..da4498b3 100644 --- a/src/route_node_lmdb.h +++ b/src/route_node_lmdb.h @@ -1,6 +1,11 @@ #ifndef ROUTE_NODE_LMDB_H #define ROUTE_NODE_LMDB_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include "route_node.h" @@ -11,4 +16,8 @@ void route_node_lmdb_destroy(struct ROUTE_BGP* bgp); int route_node_lmdb_put(struct ROUTE_BGP* bgp, struct NODEINFO_Q* nq); int route_node_lmdb_del(struct ROUTE_BGP* bgp, uint64_t node_id); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/route_ping.h b/src/route_ping.h index c657a451..702bb808 100644 --- a/src/route_ping.h +++ b/src/route_ping.h @@ -1,6 +1,11 @@ #ifndef ROUTE_PING_H #define ROUTE_PING_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include "route_bgp.h" @@ -53,4 +58,8 @@ void route_ping_cancel_for_conn(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn); void route_ping_handle_req(struct ROUTE_BGP* bgp, struct ETCP_CONN* from_conn, const uint8_t* data, size_t len); void route_ping_handle_resp(struct ROUTE_BGP* bgp, struct ETCP_CONN* from_conn, const uint8_t* data, size_t len); + +#ifdef __cplusplus +} +#endif #endif // ROUTE_PING_H diff --git a/src/routing.h b/src/routing.h index c298e104..45620e82 100644 --- a/src/routing.h +++ b/src/routing.h @@ -2,6 +2,11 @@ #ifndef ROUTING_H #define ROUTING_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -56,4 +61,8 @@ void routing_set_tun(struct UTUN_INSTANCE* instance); */ void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, uint64_t src_node_id); + +#ifdef __cplusplus +} +#endif #endif // ROUTING_H diff --git a/src/secure_channel.h b/src/secure_channel.h index 8a63ebdf..342e846e 100644 --- a/src/secure_channel.h +++ b/src/secure_channel.h @@ -2,6 +2,11 @@ #ifndef SECURE_CHANNEL_H #define SECURE_CHANNEL_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include @@ -106,4 +111,8 @@ void sc_stream_sign_cleanup(struct sc_stream_sign_state *state); sc_status_t sc_derive_ed25519_pubkey(const uint8_t *x25519_privkey, uint8_t *ed25519_pubkey_out); + +#ifdef __cplusplus +} +#endif #endif // SECURE_CHANNEL_H diff --git a/src/stcp.h b/src/stcp.h index caa8e11d..aff96f77 100644 --- a/src/stcp.h +++ b/src/stcp.h @@ -2,6 +2,11 @@ #ifndef STCP_H #define STCP_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "secure_channel.h" #include "crc32.h" #include "../lib/u_async.h" @@ -77,4 +82,8 @@ void stcp_conn_set_tx_queue(struct stcp_conn *c, struct ll_queue *q); void stcp_conn_set_rx_queue(struct stcp_conn *c, struct ll_queue *q); void stcp_conn_set_on_close(struct stcp_conn *c, void (*cb)(struct stcp_conn *conn, int err, void *arg), void *arg); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/stcp_client.h b/src/stcp_client.h index a47abb48..deb40878 100644 --- a/src/stcp_client.h +++ b/src/stcp_client.h @@ -2,6 +2,11 @@ #ifndef STCP_CLIENT_H #define STCP_CLIENT_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "stcp.h" typedef void (*stcp_ready_cb)(struct stcp_conn *conn, void *arg); @@ -12,4 +17,8 @@ struct stcp_client *stcp_client_connect(struct UASYNC *ua, const char *addr, uin void stcp_client_destroy(struct stcp_client *cli); struct stcp_conn *stcp_client_get_conn(struct stcp_client *cli); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/stcp_link.h b/src/stcp_link.h index 00a5412a..94b825a7 100644 --- a/src/stcp_link.h +++ b/src/stcp_link.h @@ -2,6 +2,11 @@ #ifndef STCP_LINK_H #define STCP_LINK_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "secure_channel.h" #include "../lib/u_async.h" #include "../lib/socket_compat.h" @@ -45,4 +50,8 @@ typedef void (*stcp_link_cb)(struct stcp_link *link, void *arg); void stcp_link_set_on_ready(struct stcp_link *link, stcp_link_cb cb, void *arg); void stcp_link_set_on_close(struct stcp_link *link, void (*cb)(struct stcp_link *link, int err, void *arg), void *arg); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/stcp_server.h b/src/stcp_server.h index b510f0db..a8dfba66 100644 --- a/src/stcp_server.h +++ b/src/stcp_server.h @@ -2,6 +2,11 @@ #ifndef STCP_SERVER_H #define STCP_SERVER_H +#ifdef __cplusplus +extern "C" { +#endif + + #include "stcp.h" typedef void (*stcp_connect_cb)(struct stcp_conn *conn, void *arg); @@ -11,4 +16,8 @@ struct stcp_server *stcp_server_create(struct UASYNC *ua, uint16_t port, stcp_connect_cb connect_cb, void *arg); void stcp_server_destroy(struct stcp_server *srv); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/utun_instance.h b/src/utun_instance.h index a3231772..e60ff9f2 100644 --- a/src/utun_instance.h +++ b/src/utun_instance.h @@ -1,6 +1,11 @@ #ifndef UTUN_INSTANCE_H #define UTUN_INSTANCE_H +#ifdef __cplusplus +extern "C" { +#endif + + #include #include #include @@ -150,4 +155,8 @@ 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); + +#ifdef __cplusplus +} +#endif #endif // UTUN_INSTANCE_H