Commit Graph
25 Commits
Author SHA1 Message Date
Evgeny f0f8edbcb6 Fix: Restore original callback in pkt_normalizer.c
Restored queue_set_callback(etcp->output_queue, pn_unpacker_cb, pn)
which was incorrectly replaced in the previous commit.

The etcp_recv callback should be set up separately by the API user,
not by replacing the internal pkt_normalizer callback.

Test Results: All 19 tests PASS
2026-02-13 19:21:42 +03:00
Evgeny ffaf7a25b8 Add etcp_api.c/h - ETCP packet send/receive API
Implemented:
- etcp_send(conn, entry) - отправляет пакет в очередь normalizer
- etcp_bind(id, callback) - подписка на пакеты с определенным ID
- etcp_unbind(id) - отписка от пакетов
- etcp_recv(queue, arg) - коллбэк для маршрутизации пакетов по ID
- etcp_api_init/deinit - инициализация API

Integration:
- pn_init() теперь устанавливает etcp_recv как callback для pn->output
- Добавлены etcp_api.c/h в src/Makefile.am
- Добавлен etcp_api.o в тестовые зависимости

API использует первый байт кодограммы (cmd) как ID для маршрутизации.
ID=0 используется как default handler если нет специфичного binding.
2026-02-13 19:15:16 +03:00
Evgeny 5dfb67a4e3 Fix: Update tests/Makefile.am for correct object dependencies
- Changed object file references from 'name.o' to 'utun-name.o' to match automake naming
- Added explicit rules for building TinyCrypt objects
- Added tinycrypt-objects target for building crypto dependencies
- Fixed test_etcp_simple_traffic.c: replaced etcp_send with etcp_int_send
- Fixed test_etcp_100_packets.c: replaced etcp_send with etcp_int_send

Test Results: All 19 tests PASS
2026-02-13 18:30:59 +03:00
Evgeny ce15d6b883 Backup before route_lib.c refactoring 2026-02-13 18:12:26 +03:00
Evgeny 277ab872bf Fix: routing initialization timing and test callbacks
- Fixed race condition: routing_add_conn called before etcp->normalizer was assigned

- Moved routing_add_conn from pn_init to etcp_connection_create after normalizer init

- Added routing.h include to etcp.c

- Fixed tests: disable routing callback on output_queue to keep packets for test verification

All 19 tests now pass.
2026-02-07 23:41:07 +03:00
Evgeny 355824792d Fix test_etcp_simple_traffic for new tun_if API 2026-02-07 02:30:53 +03:00
Evgeny 5a7107b855 Simplify tun_if: unified init, write, close API with queue-based reads
- New struct tun_if with internal queue for incoming packets
- Single tun_init() does everything: create TUN, set MTU=1500, up, register in uasync
- tun_write() for outgoing packets
- tun_close() cleans up everything including queue
- Removed: tun_create, tun_set_ip, tun_set_up, tun_set_mtu, tun_read, tun_get_config
- Removed: utun_instance_register/unregister_sockets (now internal)
- Updated utun_instance to use new tun_if* pointer
- Updated test_etcp_two_instances for new API
2026-02-07 02:28:58 +03:00
Evgeny 2e48f9a111 Refactor: TUN ioctl helpers, routing documentation; prepare for tun_if simplification 2026-02-07 02:19:33 +03:00
Evgeny 07d4616aea Refactor: Updated SHA256 implementation and secure channel improvements 2026-02-06 21:47:41 +03:00
Evgeny 3281e4878e Backup before fixing test_etcp_simple_traffic 2026-02-06 01:34:03 +03:00
Evgeny beafb9b198 Fix: Remove usleep from event loops and fix segfault in tests
- Removed usleep(5000) from all test event loops
- Changed to use single shared uasync for server and client instances
- Removed uasync_destroy from utun_instance_destroy to prevent double-free
- Added explicit uasync_destroy calls in all tests and main program
- Fixed segfault in test_pkt_normalizer_etcp and test_etcp_100_packets
- Added DEBUG_TRACE to all functions in etcp.c and etcp_connections.c

Tests now run without artificial delays and complete successfully.
2026-02-05 20:51:07 +03:00
Evgeny 8a3f01fbf8 Add epoll support, fix ETCP timestamp bug, optimize uasync with cached pollfds 2026-02-05 04:11:10 +03:00
Evgeny 528c1ddd00 WIP: Current normalizer changes before error handling fix 2026-02-04 23:24:25 +03:00
Evgeny 5840e77e1e Fix test_pkt_normalizer_etcp: fixed packet normalizer and test verification logic
- Fixed pkt_normalizer.c to send packets immediately instead of buffering
- Added queue_resume_callback() call in etcp.c after adding to output_queue
- Updated test to use simple checksum verification instead of pattern-based
- Added strict sequence order checking in test
- Reduced MAX_TEST_PACKET_SIZE to 1400 to fit in normalizer fragment
- Reduced TOTAL_PACKETS to 10 and TEST_TIMEOUT_MS to 5s for faster testing
2026-02-03 23:54:15 +03:00
Evgeny 98c43e6fb6 Backup before fixing dgram_pool initialization 2026-02-03 17:56:31 +03:00
Evgeny a0c4727b8b Fix: Added explicit type casts for ll_queue type conversions
- Fixed all incompatible pointer type warnings in src/etcp.c
- Fixed warnings in src/pkt_normalizer.c
- Fixed warnings in tests/test_etcp_simple_traffic.c
- Fixed warnings in tests/test_etcp_100_packets.c
- Fixed warnings in tests/test_ll_queue.c
- Fixed DEBUG_CATEGORY_ALL overflow warning in debug_config.h
- Fixed DEBUG_CATEGORY_LL_QUEUE redefinition warning in test_ll_queue.c
- Fixed write() unused result warning in test_u_async_comprehensive.c
2026-02-02 10:30:16 +03:00
Evgeny e9ebab4037 ref 2026-02-02 00:46:12 +03:00
Evgeny 9a5db10939 Refactor: Code cleanup and improvements across multiple modules
- Refactored ll_queue.c/h with improved error handling
- Cleaned up pkt_normalizer.c memory management
- Updated etcp.c with better logging
- Fixed test files compilation warnings
- General code quality improvements
2026-02-01 23:47:55 +03:00
Evgeny 985ed5c4b1 Fix ETCP test: server connection registration and packet handling
- etcp_connections.c: Add incoming server connections to instance->connections list
- test_etcp_simple_traffic.c: Fix ETCP_FRAGMENT handling in check_packet_received()
- test_etcp_simple_traffic.c: Fix packet size check (ETCP adds headers to payload)
- Reduced debug verbosity in ll_queue.c and debug_config.c
2026-01-28 20:49:14 +03:00
Evgeny a34035f41f ETCP: Fix protocol parsing and crypto nonce handling
- Fixed ACK section parsing (elm_cnt and till offset)
- Fixed payload section to include seq number in packet
- Fixed assembly trigger condition (last_delivered_id+1==seq)
- Crypto: Added nonce transmission in encrypted packets
- Crypto: Fixed nonce generation with usec timestamp
- Reduced debug verbosity in connection handling
- Added unknown section type handling
2026-01-28 19:56:38 +03:00
Evgeny 41626a02c3 Fix ll_queue callback signature and add debug utilities
Changes:
- ll_queue callback now receives only queue pointer and arg (no data)
- Added log_dump and addr_to_string utility functions
- Removed temporary backup files
- Updated AGENTS.md with additional guidelines
- Fixed compiler warnings in etcp.c and pkt_normalizer.c
2026-01-27 22:43:18 +03:00
Evgeny 3ddfb79338 Backup before replacing all printf with DEBUG_ macros in tests 2026-01-26 17:52:50 +03:00
Evgeny 1bafe6a681 Backup before fixing etcp_connections list addition 2026-01-26 17:40:51 +03:00
Evgeny d74f76a5a0 Fix: Resolved double free in timeout_heap_pop() and test_etcp_simple_traffic bind conflict
- Fixed incorrect init_connections() call in test_etcp_simple_traffic.c (was calling server_instance instead of client_instance)
- Fixed double free in timeout_heap_pop() when handling deleted elements
- Enhanced NULL pointer safety in uasync_print_resources() by removing complex heap manipulation
- Added debug logging to timeout_heap_pop() for better error tracking

Test results: test_etcp_simple_traffic now passes without double free errors
2026-01-25 10:47:02 +03:00
Evgeny 64489fa194 Add comprehensive ETCP traffic flow debugging tests
Implemented multiple levels of ETCP traffic debugging tests:

1. test_etcp_minimal.c - Basic packet analysis and section parsing:
   - Single section payload packets
   - Multi-section packets (TIMESTAMP, ACK, PAYLOAD)
   - Connection establishment packets (INIT_REQUEST, INIT_RESPONSE)
   - Detailed section-by-section analysis with timing

2. test_etcp_simple_traffic.c - TUN-less traffic simulation:
   - Direct packet injection and analysis
   - Connection state simulation
   - Traffic generation and processing
   - Comprehensive packet capture and analysis

3. test_etcp_traffic_flow.c - Full instance simulation:
   - Two-instance setup with traffic analysis
   - Packet capture hooks in ETCP pipeline
   - Traffic analyzer with detailed metrics
   - Connection establishment debugging

Key debugging features added:
- Section-by-section packet parsing and validation
- Packet ID tracking and sequence analysis
- ACK processing with timestamp correlation
- Connection handshake simulation
- Retransmission request handling
- Multi-section packet composition analysis
- Traffic flow metrics and timing analysis

All tests use comprehensive DEBUG_* output for detailed traffic flow tracing:
- Packet type identification
- Section length validation
- Payload content analysis
- Connection state tracking
- Timing and sequence verification

This enables thorough debugging of ETCP protocol traffic flow, packet processing,
and connection establishment without requiring TUN devices or network setup.
2026-01-23 01:41:39 +03:00