@ -115,6 +115,9 @@ static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) {
if ( link - > remote_addr . ss_family = = AF_INET ) {
if ( link - > remote_addr . ss_family = = AF_INET ) {
struct sockaddr_in * sin = ( struct sockaddr_in * ) & link - > remote_addr ;
struct sockaddr_in * sin = ( struct sockaddr_in * ) & link - > remote_addr ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] INIT sending to %s:%d, link=%p, rst_req=%d " , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) , link , reset ) ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] INIT sending to %s:%d, link=%p, rst_req=%d " , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) , link , reset ) ;
} else if ( link - > remote_addr . ss_family = = AF_INET6 ) {
struct sockaddr_in6 * sin6 = ( struct sockaddr_in6 * ) & link - > remote_addr ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] INIT sending to %s:%d, link=%p, rst_req=%d " , ip_to_str ( & sin6 - > sin6_addr , AF_INET6 ) . str , ntohs ( sin6 - > sin6_port ) , link , reset ) ;
}
}
etcp_encrypt_send ( dgram ) ;
etcp_encrypt_send ( dgram ) ;
@ -518,15 +521,24 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct CFG_S
if ( ip - > ss_family = = AF_INET ) {
if ( ip - > ss_family = = AF_INET ) {
struct sockaddr_in * sin = ( struct sockaddr_in * ) ip ;
struct sockaddr_in * sin = ( struct sockaddr_in * ) ip ;
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " [ETCP] Failed to bind to %s:%d " , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " [ETCP] Failed to bind to %s:%d " , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
} else if ( ip - > ss_family = = AF_INET6 ) {
struct sockaddr_in6 * sin6 = ( struct sockaddr_in6 * ) ip ;
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " [ETCP] Failed to bind to %s:%d " , ip_to_str ( & sin6 - > sin6_addr , AF_INET6 ) . str , ntohs ( sin6 - > sin6_port ) ) ;
}
}
socket_close_wrapper ( e_sock - > fd ) ;
socket_close_wrapper ( e_sock - > fd ) ;
u_free ( e_sock ) ;
u_free ( e_sock ) ;
return NULL ;
return NULL ;
}
}
struct sockaddr_in * sin = ( struct sockaddr_in * ) ip ;
if ( ip - > ss_family = = AF_INET ) {
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] Successfully bound socket to local address, family=%d %s:%d " , ip - > ss_family , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
struct sockaddr_in * sin = ( struct sockaddr_in * ) ip ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " Listen socket initialized: name=%s fd=%d addr=%s:%d " , e_sock - > name , e_sock - > fd , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] Successfully bound socket to local address, family=AF_INET %s:%d " , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " Listen socket initialized: name=%s fd=%d addr=%s:%d " , e_sock - > name , e_sock - > fd , ip_to_str ( & sin - > sin_addr , AF_INET ) . str , ntohs ( sin - > sin_port ) ) ;
} else if ( ip - > ss_family = = AF_INET6 ) {
struct sockaddr_in6 * sin6 = ( struct sockaddr_in6 * ) ip ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " [ETCP] Successfully bound socket to local address, family=AF_INET6 %s:%d " , ip_to_str ( & sin6 - > sin6_addr , AF_INET6 ) . str , ntohs ( sin6 - > sin6_port ) ) ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " Listen socket initialized: name=%s fd=%d addr=%s:%d " , e_sock - > name , e_sock - > fd , ip_to_str ( & sin6 - > sin6_addr , AF_INET6 ) . str , ntohs ( sin6 - > sin6_port ) ) ;
}
}
}
e_sock - > instance = instance ;
e_sock - > instance = instance ;
e_sock - > errorcode = 0 ;
e_sock - > errorcode = 0 ;
@ -1235,7 +1247,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
conn - > peer_node_id = peer_id ;
conn - > peer_node_id = peer_id ;
etcp_update_log_name ( conn ) ;
etcp_update_log_name ( conn ) ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " New connection received on socket %s: log_name=%s peer_id=%lu " , e_sock - > name , conn - > log_name , ( unsigned long ) peer_id ) ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " New connection received on socket %s: log_name=%s peer_id=%lu " , e_sock - > name , conn - > log_name , ( unsigned long ) peer_id ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " New connection from %s peer_id=%ld etcp=%p " , ip_to_str ( & ( ( struct sockaddr_in * ) & addr ) - > sin_addr . s_ addr, addr . ss_family ) . str , peer_id , conn ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " New connection from %s peer_id=%ld etcp=%p " , ip_to_str ( & addr , addr . ss_family ) . str , peer_id , conn ) ;
conn - > next = e_sock - > instance - > connections ;
conn - > next = e_sock - > instance - > connections ;
e_sock - > instance - > connections = conn ;
e_sock - > instance - > connections = conn ;
e_sock - > instance - > connections_count + + ;
e_sock - > instance - > connections_count + + ;
@ -1546,10 +1558,12 @@ int init_sockets(struct UTUN_INSTANCE* instance) {
struct ETCP_SOCKET * e_sock = etcp_socket_add ( instance , server ) ;
struct ETCP_SOCKET * e_sock = etcp_socket_add ( instance , server ) ;
if ( e_sock & & default_ip ! = 0 ) {
if ( e_sock & & default_ip ! = 0 ) {
struct in_addr addr ;
addr . s_addr = default_ip ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " Server %s type %d ip=%s " , server - > name , server - > type , ip_to_str ( & addr , AF_INET ) . str ) ;
e_sock - > local_defaultroute_ip = default_ip ;
e_sock - > local_defaultroute_ip = default_ip ;
if ( server - > ip . ss_family = = AF_INET ) {
struct in_addr addr ;
addr . s_addr = default_ip ;
DEBUG_INFO ( DEBUG_CATEGORY_ETCP , " Server %s type %d ip=%s " , server - > name , server - > type , ip_to_str ( & addr , AF_INET ) . str ) ;
}
}
}
if ( ! e_sock ) {
if ( ! e_sock ) {
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " Failed to create socket for server %s " , server - > name ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " Failed to create socket for server %s " , server - > name ) ;
@ -1669,6 +1683,14 @@ int init_connections(struct UTUN_INSTANCE* instance) {
e_sock = sock ;
e_sock = sock ;
break ;
break ;
}
}
} else if ( sock - > local_addr . ss_family = = AF_INET6 ) {
struct sockaddr_in6 * sock_addr6 = ( struct sockaddr_in6 * ) & sock - > local_addr ;
struct sockaddr_in6 * srv_addr6 = ( struct sockaddr_in6 * ) & local_server - > ip ;
if ( memcmp ( & sock_addr6 - > sin6_addr , & srv_addr6 - > sin6_addr , 16 ) = = 0 & &
sock_addr6 - > sin6_port = = srv_addr6 - > sin6_port ) {
e_sock = sock ;
break ;
}
}
}
}
}
sock = sock - > next ;
sock = sock - > next ;