Commit Graph
146 Commits
Author SHA1 Message Date
jeka b20bff32dd config 2026-03-04 01:53:17 +03:00
jeka 783f229711 obf 2026-03-01 17:19:47 +03:00
jeka c420b8f18e пердайт icmp в tun 2026-03-01 02:48:03 +03:00
Evgeny fc9fac2e3a Fix: Remove reference to missing test_control_server.c 2026-02-21 23:29:31 +03:00
Evgeny 8502451ec7 compile fixes 2026-02-21 21:30:39 +03:00
jeka b8ea33160d восстановление морды (частичное) 2026-02-21 21:04:11 +03:00
Evgeny 6ffec2f1e7 Fix: INVALID_SOCKET usage in POSIX code and remove missing test
- control_server.c: Use -1 instead of INVALID_SOCKET on lines 241 and 511
- Makefile.am: Remove test_control_server reference (source file missing)
2026-02-21 18:09:47 +03:00
Evgeny 3749c5037c fix build for linux 2026-02-20 22:39:58 +03:00
jeka d10bddd1f7 Build: incremental build support, Windows uasync fixes, TUN cross-platform refactoring
- build.sh: added --full flag for full rebuild (autoreconf + configure + make)
- build_direct.sh: incremental compilation (skips unchanged files)
- build_full.bat: new Windows batch for full rebuild
- configure.ac: fixed Windows detection using AC_COMPILE_IFELSE
- lib/u_async.c/h: Windows wakeup socket support, uasync_post for thread-safe callbacks
- src/tun_if.c/h: cross-platform TUN refactoring, Windows read thread support
- src/tun_windows.c: Windows TUN implementation improvements
- src/control_server.c: removed premature return statement
- src/routing.c: include ordering fix
- src/utun.c: windows compat includes
- Deleted obsolete net_emulator/Makefile and tinycrypt/Makefile
2026-02-20 21:20:50 +03:00
jeka 734851329f Control: Add monitoring server with ETCP protocol support
- Implement control_server.c/h for monitoring and management
- Add Windows-compatible uasync_poll using select() instead of WSAPoll
- Fix Wintun adapter creation to open existing adapters first
- Add debug category for control server operations
- Update build files to include control server in compilation
- Add test_control_server to test suite
2026-02-19 01:24:42 +03:00
Evgeny 96100663e7 Exclude test_dummynet from make check (temporarily disabled due to long execution time) 2026-02-17 21:31:47 +03:00
jeka 8a3cdaf759 1 2026-02-16 23:42:28 +03:00
jeka 3ab19094d0 Fix: segfault in ETCP tests and add wintun.dll to gitignore
- Fix segfault in ETCP tests by initializing uECC RNG in sc_init_local_keys()
- Fix segfault during cleanup by adding reference counting to socket_platform_cleanup()
- Add wintun.dll to .gitignore
- Update AGENTS.md and platform compatibility headers

All 19 tests now pass successfully.
2026-02-16 23:36:50 +03:00
Evgeny a5818d9cc4 Backup before fixing test_routing_mesh segfault 2026-02-16 22:02:57 +03:00
Evgeny 15a9521559 ETCP: реализация keepalive пакетов для каждого линка
- Добавлены поля keepalive_timer и pkt_sent_since_keepalive в struct ETCP_LINK
- Реализована отправка пустых keepalive пакетов (только timestamp) по таймеру
- Keepalive пропускается если был отправлен другой пакет с момента последнего тика
- Таймер запускается после инициализации линка (keepalive_interval из конфига)
- Исправлен тест test_bgp_route_exchange: убран лишний htonl() при проверке маршрутов
2026-02-16 19:17:47 +03:00
Evgeny 4cd22b1513 feat: переименован allowed_subnet в route_subnet, добавлено управление системными маршрутами
- Переименовано поле allowed_subnets -> route_subnets в конфигурации
- Обновлен парсинг конфига: allowed_subnet -> route_subnet
- Создан новый модуль tun_route для управления системными маршрутами
- Linux: реализация через netlink sockets с fallback на ip route
- Windows: реализация через IP Helper API
- BSD: реализация через routing sockets с fallback на route
- При запуске: автоматическое добавление маршрутов route_subnet на TUN интерфейс
- При завершении: автоматическое удаление всех маршрутов через tun_route_flush
- Обновлены Makefile.am для сборки новых файлов
2026-02-16 17:07:52 +03:00
jeka a0b02b9812 Fix port conflicts in test_pkt_normalizer_etcp - use unique ports 9041/9042 2026-02-16 10:35:26 +03:00
jeka 78dfdde400 Fix Windows test failures: proper WSAPoll error handling and FD_SETSIZE check 2026-02-16 10:33:43 +03:00
Evgeny 1cc475e9b0 Rewrite test_routing_mesh to use programmatic config creation
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.
2026-02-15 23:56:18 +03:00
Evgeny f7e1234d3d Mesh test с файлами конфигов - все еще ошибки расшифровки 2026-02-15 21:36:18 +03:00
Evgeny bee1e41b07 Добавлен тестовый режим для TUN интерфейса и тест роутинга mesh
- Добавлена опция tun_test_mode в конфиг для работы без реального TUN устройства
- Добавлены функции для работы с очередями TUN в тестовом режиме
- Добавлен API для программного создания instance из структуры конфига
- Создан тест test_routing_mesh.c с 3-instance mesh топологией
- Ключи генерируются автоматически и распределяются между instance
2026-02-15 20:37:10 +03:00
Evgeny 602d9174a4 Remove test binaries from git tracking (now ignored) 2026-02-15 18:57:23 +03:00
Evgeny ca16d175e6 Backup: before code simplification refactoring 2026-02-15 18:37:23 +03:00
jeka 806226c049 Remove test logs from git and add to .gitignore
- Remove tests/logs/ directory from git tracking
- Add tests/logs/ to .gitignore
2026-02-15 18:05:14 +03:00
jeka 10d6b28090 Update test logs after u_async fixes 2026-02-15 17:56:50 +03:00
jeka 53c7330a7f Backup before fixing u_async socket registration bug 2026-02-15 17:25:34 +03:00
Evgeny 28ff3a4776 Fix test_u_async_comprehensive: add Windows socketpair replacement using UDP sockets 2026-02-15 14:31:31 +03:00
Evgeny 20a3eaf73c Fix remaining test files: replace POSIX headers with platform_compat.h 2026-02-15 13:25:05 +03:00
Evgeny c75ac9d23b Fix test_u_async_comprehensive.c: replace POSIX headers with platform_compat.h 2026-02-15 13:18:34 +03:00
Evgeny 4403c46788 Fix Windows build: skip gettimeofday on MSYS2, force recompile ecc_platform_specific 2026-02-15 12:26:32 +03:00
Evgeny 560e121d4c Fix tests Makefile.am: WIN_LIBS must be defined before COMMON_LIBS 2026-02-15 04:41:25 +03:00
Evgeny ada25ec4cc Add -ladvapi32 for Windows CryptGenRandom support 2026-02-15 04:36:47 +03:00
Evgeny f5faa7c834 Fix Windows build: add default_CSPRNG and improve build.sh error handling
- 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
2026-02-15 04:34:05 +03:00
Evgeny 27f2edca40 Fix remaining Windows test build issues
- 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
2026-02-15 04:24:46 +03:00
Evgeny 4d486c7017 Fix test files for Windows cross-platform compatibility
- 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
2026-02-15 04:09:24 +03:00
Evgeny 8af2904033 Fix Windows build: net/if.h and route_lib.h forward declarations
- 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
2026-02-15 03:30:42 +03:00
Evgeny c83fdeeaad Fix Windows build: add sa_family_t typedef, replace arpa/inet.h, fix ll_queue warnings
- 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
2026-02-15 03:06:02 +03:00
Evgeny 15b670e563 Add cross-platform TUN support with Wintun for Windows
- 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
2026-02-15 01:40:17 +03:00
Evgeny 1f3a99086a Fix test_bgp_route_exchange: use proper byte order and uasync timers
- 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
2026-02-14 22:30:32 +03:00
Evgeny 43114d727c BGP: Complete route exchange with connection tracking and broadcast
- 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
2026-02-14 21:48:27 +03:00
Evgeny 68668821e4 BGP: Implement route exchange module between uTun instances
- 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)
2026-02-14 20:37:14 +03:00
Evgeny 4fcdfc15f9 Add exact IP:port match validation to NAT test
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)
2026-02-14 11:19:47 +03:00
Evgeny 507f2da831 Improve NAT IP:port test validation to check specific values
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)
2026-02-14 11:14:52 +03:00
Evgeny a843b998ed Add NAT IP:port validation to test_etcp_two_instances
- Added check that NAT fields are populated after connection establishment
- Verifies nat_ip is non-zero and contains correct IP (127.0.0.1)
- Verifies nat_port is non-zero and contains correct port
- Checks nat_changes_count=0 (first initialization)
- Checks nat_hits_count=0 (no repeated matches yet)

Test output shows:
  [CLIENT] PASS: NAT address is set: 127.0.0.1:9012
  [CLIENT] PASS: nat_changes_count=0, nat_hits_count=0
2026-02-14 11:11:45 +03:00
Evgeny 8334b97521 Backup before adding NAT IP:port tracking to ETCP handshake 2026-02-14 11:02:20 +03:00
Evgeny 801770f117 Backup before routing refactor: etcp_bind id=0 + etcp_send routing 2026-02-14 01:58:59 +03:00
Evgeny d694c92b1f Refactor etcp_api: per-instance bindings with struct ETCP_BINDINGS
Changed from global bindings to per-instance bindings:

1. Added struct ETCP_BINDINGS in etcp_api.h:
   - Contains array of callbacks[ETCP_MAX_BINDINGS]
   - NULL means not bound

2. Updated UTUN_INSTANCE (utun_instance.h):
   - Added field: struct ETCP_BINDINGS api_bindings
   - Initialized to NULL by calloc in utun_instance_create

3. Updated API functions (etcp_api.h/c):
   - etcp_bind(inst, id, callback) - per-instance binding
   - etcp_unbind(inst, id) - per-instance unbinding
   - Removed etcp_api_init/etcp_api_deinit (not needed)
   - etcp_int_recv now uses conn->instance->api_bindings.callbacks[id]

4. Updated test_etcp_api.c:
   - Separate callbacks for server and client
   - Register via etcp_bind(server_instance, ...) and etcp_bind(client_instance, ...)
   - Removed global etcp_api_init/etcp_api_deinit calls

Test passes: All 100 packets transmitted in each direction.
2026-02-14 01:39:55 +03:00
Evgeny 1a7356e923 Clean up test_etcp_api: set WARN level, remove obsolete comments 2026-02-14 01:07:44 +03:00
Evgeny 7a1f160094 Fix test_etcp_api: use single callback with connection check
etcp_bind uses global table - multiple binds with same ID overwrite.
Fixed by using single recv_callback that checks conn pointer:
- conn == server_conn: forward direction (client->server)
- conn == client_conn: backward direction (server->client)

Test now passes: All 100 packets transmitted in each direction.
2026-02-14 01:07:11 +03:00
Evgeny 6e93c087ca Add test_etcp_api.c - test for ETCP API (etcp_send, etcp_bind)
Based on test_pkt_normalizer_etcp.c but uses high-level API:
- etcp_send() for sending packets via ETCP normalizer
- etcp_bind() for registering receive callbacks
- etcp_api_init()/etcp_api_deinit() for API lifecycle

NOTE: Test has current limitation - pkt_normalizer packer aggregates
packets into ~1536 byte chunks, exceeding ETCP max payload of 1480 bytes.
This causes encrypt_send to fail. The test demonstrates correct API usage
pattern but requires packer fix for full functionality.
2026-02-13 23:37:13 +03:00