Replaced file-based config creation with direct struct population.
This eliminates temporary files and makes the test cleaner.
Key changes:
- Added helper functions for creating config structures
- Create CFG_SERVER, CFG_CLIENT, CFG_CLIENT_LINK programmatically
- Use utun_instance_create_from_config() instead of file-based creation
- No temp directories or file cleanup needed
The test now builds configs in memory using helper functions like
make_sockaddr(), create_server(), create_client(), etc.
When receiving an INIT packet, the code was looking up existing links by
address. However, in a mesh topology where each node has both client and
server connections to peers, a client link created during initialization
would be found when receiving an incoming INIT packet from that peer.
This caused the code to try decrypting the INIT packet using the client
link's crypto context, which failed because the session keys weren't
properly established yet.
The fix checks if the found link is a client link (is_server==0) and if
so, treats the packet as a new INIT connection that needs to create a
server-side link instead.
Changed condition from:
if (link==NULL)
to:
if (link==NULL || link->is_server==0)
- Создана общая функция instance_init_common() для инициализации instance
- Упрощены utun_instance_create() и utun_instance_create_from_config()
- Удалено ~90 строк дублирующегося кода
- Обе функции теперь используют общую логику инициализации
- Добавлена опция tun_test_mode в конфиг для работы без реального TUN устройства
- Добавлены функции для работы с очередями TUN в тестовом режиме
- Добавлен API для программного создания instance из структуры конфига
- Создан тест test_routing_mesh.c с 3-instance mesh топологией
- Ключи генерируются автоматически и распределяются между instance
- Remove FD_SETSIZE check for Windows sockets (can have any value)
- Fix process_timeouts to handle all expired timers (continue instead of break)
- Handle case when no sockets to poll (sleep instead of calling poll)
- Disable wakeup pipe on Windows (incompatible with WSAPoll)
- Add gettimeofday and ssize_t implementations for Windows
- Add Windows implementation of default_CSPRNG() using CryptGenRandom
- Add fallback stub for platforms without CSPRNG support
- Fix build.sh to properly detect build failures (use PIPESTATUS)
- Show proper error message instead of "Build completed successfully" on failure
- Remove sys/socket.h include from test_etcp_two_instances.c (Linux-only)
- Fix test_mkdtemp buffer overflow - use memcpy instead of strncpy
- Fix test_mkdtemp return value check (replace == NULL with != 0)
- Add Windows socket libraries (-lws2_32 -liphlpapi) to test builds
- All tests build successfully on Linux
- Create test_utils.h with cross-platform utility functions:
* test_mkdtemp() - Windows uses GetTempPath + _mkdir, Linux uses mkdtemp
* test_unlink() - Windows _unlink, Linux unlink
* test_rmdir() - Windows _rmdir, Linux rmdir
- Update all test files to use test_utils.h
- Replace arpa/inet.h and netinet/in.h with platform_compat.h
- Replace unistd.h with conditional includes
- Replace mkdtemp(), unlink(), rmdir() with test_* versions
- Tests now build on both Linux and Windows
- Note: Some integration tests may fail on Linux due to test environment
- Add * to Wintun function pointer declarations (wintun.h defines types as functions)
- Use (void *) cast in GetProcAddress to avoid errors
- All 22 tests pass on Linux
- Fix function pointer declarations in tun_windows.c (removed broken macro)
- Use explicit GetProcAddress calls for each Wintun function
- Remove invalid fields from MIB_IPINTERFACE_ROW (PromiscuousMode, DadState, etc.)
- Add #ifndef _WIN32 around IF_NAMESIZE/if_indextoname in etcp_connections.c
- All 22 tests pass on Linux
- Wrap net/if.h include in #ifndef _WIN32 in etcp_connections.c
- Add forward declarations for ROUTE_TABLE and ROUTE_ENTRY in route_lib.h
- All 22 tests pass on Linux
- Wrap POSIX headers (netdb.h, ifaddrs.h, net/if.h) in #ifndef _WIN32 in config_parser.c
- Add Windows stub for get_netif_index() - returns 0 (no interface binding)
- Wrap daemonize() function for Windows - returns 0 (no fork/setsid support)
- Replace setlinebuf() with setvbuf() for Windows compatibility
- Wrap SIGHUP signal handler in #ifndef _WIN32
- Add explicit poll() declaration for Windows in platform_compat.h
- All 22 tests pass on Linux
- Add sa_family_t typedef for Windows in platform_compat.h
- Add forward declaration of struct ll_queue in ll_queue.h to fix warnings
- Replace arpa/inet.h includes with platform_compat.h in:
tun_linux.c, etcp_connections.c, route_lib.c, route_bgp.c,
utun_instance.c, routing.c, utun.c, packet_dump.h, config_parser.c
- All 22 tests pass on Linux
- Replace sys/socket.h with platform_compat.h in config_parser.h
- Add #include <poll.h> for Windows in platform_compat.h
- Fix localtime() type mismatch: cast tv.tv_sec to time_t
- All 22 tests pass on Linux
- Remove duplicate struct pollfd (already in winsock2.h)
- Remove duplicate struct timezone (already in time.h)
- Remove duplicate nanosleep (already in pthread_time.h)
- Add fcntl.h include for _O_BINARY
- Use platform_pipe/fcntl to avoid naming conflicts
- All 22 tests pass on Linux
- Add platform_compat.h with Windows implementations of:
* gettimeofday() using GetSystemTimeAsFileTime
* poll() using select()
* pipe() using _pipe()
* fcntl() using ioctlsocket for O_NONBLOCK
* pollfd structure and POLL* constants
* strcasecmp/strncasecmp macros
- Update debug_config.c and u_async.c/h to use platform_compat.h
- Remove POSIX-specific headers (arpa/inet.h, sys/time.h, etc.)
- All 22 tests pass on Linux
- Fixes build errors on Windows MSYS2
- Add #ifdef _WIN32 to use winsock2.h/ws2tcpip.h instead of sys/socket.h
- Update build.sh to support both Linux and Windows/MSYS2
- Auto-detect platform and configure accordingly (--host=x86_64-w64-mingw32 for Windows)
- All 22 tests pass on Linux
- Split TUN implementation into platform-specific files:
- tun_if.c: Common code (queues, callbacks, statistics)
- tun_linux.c: Linux TUN/TAP implementation (/dev/net/tun + ioctl)
- tun_windows.c: Windows Wintun implementation (wintun.dll + IP Helper)
- Update tun_if.h with platform abstraction layer:
- tun_platform_init/cleanup/read/write/get_poll_fd
- Platform handles: fd (Linux), WINTUN handles (Windows)
- Windows implementation features:
- Dynamic loading of wintun.dll with graceful error handling
- IP Helper API for IP address and MTU configuration
- HANDLE-based uasync integration
- Clear error message if wintun.dll is not found
- Update build system:
- configure.ac: Detect Windows (mingw/msys/cygwin)
- src/Makefile.am: Conditional compilation of tun_linux/tun_windows
- tests/Makefile.am: Link platform-specific TUN objects
- Add wintun.dll and wintun.h to lib/ directory
- All 22 tests pass on Linux
- Ready for MSYS2 UCRT64 Windows build
- Add socket_compat.h/c with platform abstraction for POSIX/Windows
- socket_t typedef: int on POSIX, SOCKET on Windows
- Add socket_platform_init/cleanup for WSAStartup on Windows
- Add socket operations: create_udp, sendto, recvfrom, set_nonblocking
- Add socket options: set_buffers, set_reuseaddr, set_mark (Linux), bind_to_device (Linux)
- Update u_async: add socket_t support with uasync_add_socket_t/remove_socket_t
- Update ETCP: use socket_t and socket_compat functions
- Add DEBUG_CATEGORY_SOCKET for socket debugging
- All 22 tests pass on Linux
- MSYS2 UCRT64 compatible
- Replace artificial timing loop with uasync_poll(ua, -1) for proper timeout handling
- Fix endianness bug: use htonl() for IP address comparison in check_learned_route()
- Remove duplicate init_connections() calls
Test now passes successfully - BGP route exchange working correctly
- Add ROUTE_BGP_CONN_ITEM structure for connection list management
- Modify route_bgp_new_conn() to add connections to senders_list
- Create route_bgp_remove_conn() for cleanup on connection close
- Add route_change_callback typedef and fields to ROUTE_TABLE
- Implement route_bgp_on_route_change() to broadcast updates
- Modify route_table_insert() to call callback on insert/update
- Modify route_table_delete_entry() to call callback on delete
- Add route_bgp_remove_conn() call in etcp_connection_close()
- Fix test: remove duplicate init_connections() calls
Features:
- Connections tracked in senders_list (ll_queue)
- Route changes broadcast to all connections
- Withdraw messages sent on connection close
- No port binding conflicts in tests
All changes working correctly - BGP route exchange functional in both directions
- Add route_bgp.c/h with BGP-like route exchange functionality
- Implement route_bgp_init/destroy for module lifecycle
- Add route_bgp_new_conn to send routing table on connection
- Implement route_bgp_receive_cbk for processing incoming routes
- Add route_table_delete_entry for individual route removal
- Extend ROUTE_ENTRY with endpoint_ip, endpoint_port, destination_node_id
- Add DEBUG_CATEGORY_BGP to debug_config.h
- Integrate BGP initialization into utun_instance_create
- Call route_bgp_new_conn from etcp_connections on link init
- Create integration test test_bgp_route_exchange.c
- Add route_bgp_delete_entry tests to test_route_lib.c
- Update Makefiles to include new module
Route exchange tested and working in both directions (client-server)
Test now verifies that NAT IP:port exactly matches client's local bind:
- Gets expected port from client socket using getsockname()
- Compares nat_port with expected_client_port for exact match
- Validates nat_ip equals 127.0.0.1 (localhost test)
- Fails test if values don't match exactly
This ensures the server correctly returns the client's actual address
in the INIT_RESPONSE handshake without any modification.
Test output:
[TEST] Client socket bound to port 9012 (expected NAT port)
[CLIENT] PASS: NAT address is set: 127.0.0.1:9012
[CLIENT] PASS: nat_changes_count=0, nat_hits_count=0
[CLIENT] PASS: NAT IP and port match exactly (127.0.0.1:9012)
Test now verifies that NAT fields contain CORRECT data, not just non-zero:
- Verifies nat_ip equals 127.0.0.1 (0x7F000001) - expected for localhost test
- Verifies nat_port is in valid ephemeral port range (> 1024 and <= 65535)
- Fails test if values are incorrect (not just warning)
This ensures the server correctly returns the client's external address
in the INIT_RESPONSE handshake packet.
Test output:
[CLIENT] PASS: NAT address is set: 127.0.0.1:9012
[CLIENT] PASS: nat_changes_count=0, nat_hits_count=0
[CLIENT] PASS: NAT IP and port contain valid values (127.0.0.1:9012)