Browse Source

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.
nodeinfo-routing-update
jeka 2 months ago
parent
commit
3ab19094d0
  1. 1
      .gitignore
  2. 11
      AGENTS.md
  3. 7
      lib/platform_compat.h
  4. 13
      lib/socket_compat.c
  5. 3
      src/secure_channel.c
  6. 42
      src/utun.conf
  7. 5
      tests/test_routing_mesh.c

1
.gitignore vendored

@ -68,3 +68,4 @@ utun.conf
# MSVC temp files # MSVC temp files
cl cl
build_win.log build_win.log
wintun.dll

11
AGENTS.md

@ -194,14 +194,6 @@ sc_decrypt(&ctx, ciphertext, ciphertext_len, plaintext, &plaintext_len);
2. **Undefined references:** Ensure source files are listed in Makefile.am 2. **Undefined references:** Ensure source files are listed in Makefile.am
3. **Link errors:** Check function declarations match definitions 3. **Link errors:** Check function declarations match definitions
### Testing Crypto
```bash
cd tests/
./test_etcp_crypto # Should show all tests passing
cd tests/
./working_crypto_test # Standalone crypto test
```
## 📦 Dependencies ## 📦 Dependencies
### Build Dependencies ### Build Dependencies
@ -233,7 +225,7 @@ Crypto: Fixed CCM nonce size to 13 bytes, all crypto tests passing
1. Add new source file to `src/Makefile.am` under `utun_SOURCES` 1. Add new source file to `src/Makefile.am` under `utun_SOURCES`
2. Add test file to `tests/Makefile.am` under `check_PROGRAMS` 2. Add test file to `tests/Makefile.am` under `check_PROGRAMS`
3. Use existing patterns from similar modules 3. Use existing patterns from similar modules
4. Run `make check` after changes 4. Run `make check` after changes (win: build.bat and run_tests.bat)
5. Commit with descriptive message in appropriate language 5. Commit with descriptive message in appropriate language
--- ---
@ -295,4 +287,5 @@ Crypto: Fixed CCM nonce size to 13 bytes, all crypto tests passing
стоп utun: sudo /home/vnc1/proj/utun3/utun_stop1.sh стоп utun: sudo /home/vnc1/proj/utun3/utun_stop1.sh
логи - utun.log логи - utun.log
*Last updated: 2026-02-13 - c_util fully functional with toc/description/show/edit commands* *Last updated: 2026-02-13 - c_util fully functional with toc/description/show/edit commands*

7
lib/platform_compat.h

@ -45,8 +45,10 @@
#define _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED
#endif #endif
// gettimeofday for Windows - provide our own implementation // gettimeofday for Windows - provide our own implementation if not already defined
static inline int gettimeofday(struct timeval *tv, void *tz) { #ifndef _GETTIMEOFDAY_DEFINED
#define _GETTIMEOFDAY_DEFINED
static inline int utun_gettimeofday(struct timeval *tv, void *tz) {
FILETIME ft; FILETIME ft;
unsigned __int64 tmpres = 0; unsigned __int64 tmpres = 0;
@ -67,6 +69,7 @@
return 0; return 0;
} }
#endif // _GETTIMEOFDAY_DEFINED
// Pipe creation for Windows // Pipe creation for Windows
static inline int platform_pipe(int pipefd[2]) { static inline int platform_pipe(int pipefd[2]) {

13
lib/socket_compat.c

@ -8,7 +8,10 @@
#ifdef _WIN32 #ifdef _WIN32
// ==================== Windows Implementation ==================== // ==================== Windows Implementation ====================
static int wsa_init_count = 0;
int socket_platform_init(void) { int socket_platform_init(void) {
if (wsa_init_count == 0) {
WSADATA wsaData; WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData); int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (result != 0) { if (result != 0) {
@ -16,12 +19,22 @@ int socket_platform_init(void) {
return -1; return -1;
} }
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock 2.2 initialized"); DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock 2.2 initialized");
}
wsa_init_count++;
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock init count: %d", wsa_init_count);
return 0; return 0;
} }
void socket_platform_cleanup(void) { void socket_platform_cleanup(void) {
if (wsa_init_count > 0) {
wsa_init_count--;
if (wsa_init_count == 0) {
WSACleanup(); WSACleanup();
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock cleanup completed"); DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock cleanup completed");
} else {
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "Winsock init count after cleanup: %d", wsa_init_count);
}
}
} }
int socket_set_nonblocking(socket_t sock) { int socket_set_nonblocking(socket_t sock) {

3
src/secure_channel.c

@ -574,6 +574,9 @@ sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key,
curve = uECC_secp256r1(); curve = uECC_secp256r1();
} }
/* Set RNG function for TinyCrypt - must be done before any ECC operations */
uECC_set_rng(sc_rng);
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: public_key len=%zu, private_key len=%zu", DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: public_key len=%zu, private_key len=%zu",
strlen(public_key), strlen(private_key)); strlen(public_key), strlen(private_key));

42
src/utun.conf

@ -1,42 +0,0 @@
[global]
tun_ip=10.0.0.1
mtu=1500 # MTU for all connections (0 = use default 1500)
control_ip=127.0.0.1
control_port=12345
net_debug=0
my_node_id=61be9d4cd3c60c2d
my_private_key=1313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc
my_public_key=
[routing]
route_subnet=10.0.0.0/24
route_subnet=10.22.0.0/16
route_subnet=10.23.0.0/16
my_subnet=10.23.5.0/24
my_subnet=10.23.6.0/24
# мои адреса и каналы
[server: lo0_test]
addr=127.0.0.1:1330
#so_mark=100
#netif=eth0
type=nat # public / nat / private
[server: lan1]
addr=192.168.29.117:1333
so_mark=100
netif=eth0
type=public # public / nat / private
[client: client_test1]
# линки
link=lo0_test:192.168.0.20:1234
#link=wired1_fast:1.2.3.4:1234
link=lan1:192.168.0.20:1234
#link=wireless_bkp:1.2.3.4:1234
keepalive=1
peer_public_key=deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee

5
tests/test_routing_mesh.c

@ -4,7 +4,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h> #include <arpa/inet.h>
#endif
#include "test_utils.h" #include "test_utils.h"
#include "../lib/platform_compat.h" #include "../lib/platform_compat.h"
#include "../src/etcp.h" #include "../src/etcp.h"

Loading…
Cancel
Save