Add full integration test using real UTUN instances

- test_etcp_connection_full.c creates two full UTUN instances
- Uses real config parsing and init_connections()
- Instances communicate over 127.0.0.1:9001
- Test validates complete handshake process
This commit is contained in:
Evgeny committed 2026-01-20 19:11:57 +03:00
1 parent 4a2044973c
commit e737f2ae0b
2 files changed
+168 -27

No files matched your search

+17 -27
View File
@@ -203,7 +203,7 @@ struct ETCP_LINK* etcp_link_find_by_addr(struct ETCP_SOCKET* e_sock, struct sock
// ===============================
struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct sockaddr_storage* ip, uint32_t netif_index, int so_mark, uint8_t type) {
if (!instance || !ip) return NULL;
if (!instance) return NULL;
struct ETCP_SOCKET* e_sock = calloc(1, sizeof(struct ETCP_SOCKET));
if (!e_sock) {
@@ -211,12 +211,14 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka
return NULL;
}
// Determine address family from the provided sockaddr_storage
int family = ip->ss_family;
if (family != AF_INET && family != AF_INET6) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "Unsupported address family: %d", family);
free(e_sock);
return NULL;
int family = AF_INET;
if (ip) {
family = ip->ss_family;
if (family != AF_INET && family != AF_INET6) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "Unsupported address family: %d", family);
free(e_sock);
return NULL;
}
}
e_sock->fd = socket(family, SOCK_DGRAM, 0);
@@ -250,28 +252,16 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka
#endif
}
// Copy the address for binding
memcpy(&e_sock->local_addr, ip, sizeof(struct sockaddr_storage));
socklen_t addr_len = (e_sock->local_addr.ss_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
// Bind socket
if (bind(e_sock->fd, (struct sockaddr*)&e_sock->local_addr, addr_len) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "Failed to bind socket: %s", strerror(errno));
close(e_sock->fd);
free(e_sock);
return NULL;
// Store the local address if provided
if (ip) {
memcpy(&e_sock->local_addr, ip, sizeof(struct sockaddr_storage));
}
// Get actual bound address (in case port was 0)
if (getsockname(e_sock->fd, (struct sockaddr*)&e_sock->local_addr, &addr_len) < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "Failed to get socket name: %s", strerror(errno));
close(e_sock->fd);
free(e_sock);
return NULL;
}
// Insert into instance's connections list
e_sock->instance = instance;
e_sock->errorcode = 0;
e_sock->pkt_format_errors = 0;
// Add to instance's socket list
e_sock->next = instance->etcp_sockets;
instance->etcp_sockets = e_sock;