|
|
|
@ -28,6 +28,9 @@ |
|
|
|
#include "../lib/debug_config.h" |
|
|
|
#include "../lib/debug_config.h" |
|
|
|
#include "etcp_loadbalancer.h" |
|
|
|
#include "etcp_loadbalancer.h" |
|
|
|
#include "etcp_keepalive.h" |
|
|
|
#include "etcp_keepalive.h" |
|
|
|
|
|
|
|
#ifdef UTUN_HAVE_STANDBY |
|
|
|
|
|
|
|
#include "standby.h" |
|
|
|
|
|
|
|
#endif |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <time.h> |
|
|
|
#include <time.h> |
|
|
|
#include "../lib/mem.h" |
|
|
|
#include "../lib/mem.h" |
|
|
|
@ -2107,6 +2110,9 @@ static void etcp_process_packet(struct ETCP_SOCKET* e_sock, uint8_t* data, |
|
|
|
salt[0], salt[1], salt[2], salt[3], salt[4], salt[5], salt[6], salt[7], |
|
|
|
salt[0], salt[1], salt[2], salt[3], salt[4], salt[5], salt[6], salt[7], |
|
|
|
encrypted_pubkey[0], encrypted_pubkey[1], encrypted_pubkey[2], encrypted_pubkey[3]); |
|
|
|
encrypted_pubkey[0], encrypted_pubkey[1], encrypted_pubkey[2], encrypted_pubkey[3]); |
|
|
|
if (sc_decrypt(&sc, data, recv_len - SC_PUBKEY_ENC_SIZE, (uint8_t*)&pkt->timestamp, &pkt_len)) { |
|
|
|
if (sc_decrypt(&sc, data, recv_len - SC_PUBKEY_ENC_SIZE, (uint8_t*)&pkt->timestamp, &pkt_len)) { |
|
|
|
|
|
|
|
#ifdef UTUN_HAVE_STANDBY |
|
|
|
|
|
|
|
{ char who[64]; snprintf(who, sizeof(who), "addr=%s", sockaddr_storage_to_str(&addr).str); standby_log_rx("udp undecryptable", who); } |
|
|
|
|
|
|
|
#endif |
|
|
|
if (link) { |
|
|
|
if (link) { |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, |
|
|
|
"packet undecryptable (normal+init fail) from=%s — existing link log=%s state=%d sess=%d", |
|
|
|
"packet undecryptable (normal+init fail) from=%s — existing link log=%s state=%d sess=%d", |
|
|
|
@ -2140,6 +2146,9 @@ static void etcp_process_packet(struct ETCP_SOCKET* e_sock, uint8_t* data, |
|
|
|
uint8_t code = pkt->data[0]; |
|
|
|
uint8_t code = pkt->data[0]; |
|
|
|
uint64_t peer_id = be64toh(*(uint64_t*)(pkt->data + 2)); |
|
|
|
uint64_t peer_id = be64toh(*(uint64_t*)(pkt->data + 2)); |
|
|
|
if (code == ETCP_PING) { |
|
|
|
if (code == ETCP_PING) { |
|
|
|
|
|
|
|
#ifdef UTUN_HAVE_STANDBY |
|
|
|
|
|
|
|
{ char who[64]; snprintf(who, sizeof(who), "addr=%s", sockaddr_storage_to_str(&addr).str); standby_log_rx("udp ping", who); } |
|
|
|
|
|
|
|
#endif |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "X25519 decrypted: PING from peer=0x%016llx src=%s", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "X25519 decrypted: PING from peer=0x%016llx src=%s", |
|
|
|
(unsigned long long)peer_id, sockaddr_storage_to_str(&addr).str); |
|
|
|
(unsigned long long)peer_id, sockaddr_storage_to_str(&addr).str); |
|
|
|
int ret = handle_ping(e_sock, pkt, &addr, decrypted_pubkey, pkt_len); |
|
|
|
int ret = handle_ping(e_sock, pkt, &addr, decrypted_pubkey, pkt_len); |
|
|
|
@ -2147,6 +2156,9 @@ static void etcp_process_packet(struct ETCP_SOCKET* e_sock, uint8_t* data, |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (code == ETCP_PONG) { |
|
|
|
if (code == ETCP_PONG) { |
|
|
|
|
|
|
|
#ifdef UTUN_HAVE_STANDBY |
|
|
|
|
|
|
|
{ char who[64]; snprintf(who, sizeof(who), "addr=%s", sockaddr_storage_to_str(&addr).str); standby_log_rx("udp pong", who); } |
|
|
|
|
|
|
|
#endif |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "X25519 decrypted: PONG from peer=0x%016llx src=%s", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "X25519 decrypted: PONG from peer=0x%016llx src=%s", |
|
|
|
(unsigned long long)peer_id, sockaddr_storage_to_str(&addr).str); |
|
|
|
(unsigned long long)peer_id, sockaddr_storage_to_str(&addr).str); |
|
|
|
int ret = handle_pong(e_sock, pkt, &addr, pkt_len); |
|
|
|
int ret = handle_pong(e_sock, pkt, &addr, pkt_len); |
|
|
|
@ -2483,6 +2495,17 @@ int etcp_packet_decrypted(struct ETCP_SOCKET* e_sock, struct ETCP_DGRAM* pkt, |
|
|
|
|
|
|
|
|
|
|
|
uint8_t pkt_code = pkt->data[0]; |
|
|
|
uint8_t pkt_code = pkt->data[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef UTUN_HAVE_STANDBY |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char who[256]; |
|
|
|
|
|
|
|
snprintf(who, sizeof(who), "%s addr=%s", link->etcp->log_name, |
|
|
|
|
|
|
|
sockaddr_storage_to_str(&link->remote_addr).str); |
|
|
|
|
|
|
|
int is_ka = (pkt_code == ETCP_KEEPALIVE || pkt_code == ETCP_KEEPALIVE_REQ || pkt_code == ETCP_KEEPALIVE_RESP); |
|
|
|
|
|
|
|
standby_log_rx(is_ka ? (link->is_tcp ? "tcp keepalive" : "udp keepalive") |
|
|
|
|
|
|
|
: (link->is_tcp ? "tcp data" : "udp data"), who); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (etcp_keepalive_on_recv(e_sock, pkt, link, pkt_len)) { |
|
|
|
if (etcp_keepalive_on_recv(e_sock, pkt, link, pkt_len)) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|