|
|
@ -116,7 +116,7 @@ const char* transop_str (enum n2n_transform tr) { |
|
|
|
case N2N_TRANSFORM_ID_TWOFISH: return("Twofish"); |
|
|
|
case N2N_TRANSFORM_ID_AES: return("AES"); |
|
|
|
case N2N_TRANSFORM_ID_CHACHA20:return("ChaCha20"); |
|
|
|
case N2N_TRANSFORM_ID_SPECK :return("Speck"); |
|
|
|
case N2N_TRANSFORM_ID_SPECK: return("Speck"); |
|
|
|
default: return("invalid"); |
|
|
|
}; |
|
|
|
} |
|
|
@ -275,8 +275,9 @@ n2n_edge_t* edge_init (const n2n_edge_conf_t *conf, int *rv) { |
|
|
|
|
|
|
|
eee->conf.auth.scheme = n2n_auth_simple_id; |
|
|
|
|
|
|
|
for (idx = 0; idx < N2N_AUTH_TOKEN_SIZE; ++idx) |
|
|
|
for(idx = 0; idx < N2N_AUTH_TOKEN_SIZE; ++idx) { |
|
|
|
eee->conf.auth.token[idx] = n2n_rand() % 0xff; |
|
|
|
} |
|
|
|
|
|
|
|
eee->conf.auth.toksize = sizeof(eee->conf.auth.token); |
|
|
|
|
|
|
@ -443,6 +444,7 @@ static void register_with_new_peer (n2n_edge_t *eee, |
|
|
|
const n2n_ip_subnet_t *dev_addr, |
|
|
|
const n2n_desc_t *dev_desc, |
|
|
|
const n2n_sock_t *peer) { |
|
|
|
|
|
|
|
/* REVISIT: purge of pending_peers not yet done. */ |
|
|
|
struct peer_info *scan; |
|
|
|
macstr_t mac_buf; |
|
|
@ -467,7 +469,6 @@ static void register_with_new_peer (n2n_edge_t *eee, |
|
|
|
|
|
|
|
traceEvent(TRACE_DEBUG, "Pending peers list size=%u", |
|
|
|
HASH_COUNT(eee->pending_peers)); |
|
|
|
|
|
|
|
/* trace Sending REGISTER */ |
|
|
|
if(from_supernode) { |
|
|
|
/* UDP NAT hole punching through supernode. Send to peer first(punch local UDP hole)
|
|
|
@ -825,8 +826,9 @@ static void send_register_super (n2n_edge_t *eee) { |
|
|
|
cmn.flags = 0; |
|
|
|
memcpy(cmn.community, eee->conf.community_name, N2N_COMMUNITY_SIZE); |
|
|
|
|
|
|
|
for(idx = 0; idx < N2N_COOKIE_SIZE; ++idx) |
|
|
|
for(idx = 0; idx < N2N_COOKIE_SIZE; ++idx) { |
|
|
|
eee->curr_sn->last_cookie[idx] = n2n_rand() % 0xff; |
|
|
|
} |
|
|
|
|
|
|
|
memcpy(reg.cookie, eee->curr_sn->last_cookie, N2N_COOKIE_SIZE); |
|
|
|
reg.dev_addr.net_addr = ntohl(eee->device.ip_addr); |
|
|
@ -974,9 +976,9 @@ static void send_register (n2n_edge_t * eee, |
|
|
|
sock_to_cstr(sockbuf, remote_peer)); |
|
|
|
|
|
|
|
if(eee->conf.header_encryption == HEADER_ENCRYPTION_ENABLED) |
|
|
|
packet_header_encrypt (pktbuf, idx, eee->conf.header_encryption_ctx, |
|
|
|
packet_header_encrypt(pktbuf, idx, eee->conf.header_encryption_ctx, |
|
|
|
eee->conf.header_iv_ctx, |
|
|
|
time_stamp (), pearson_hash_16 (pktbuf, idx)); |
|
|
|
time_stamp(), pearson_hash_16(pktbuf, idx)); |
|
|
|
|
|
|
|
/* sent = */ sendto_sock(eee->udp_sock, pktbuf, idx, remote_peer); |
|
|
|
} |
|
|
@ -1019,9 +1021,9 @@ static void send_register_ack (n2n_edge_t * eee, |
|
|
|
sock_to_cstr(sockbuf, remote_peer)); |
|
|
|
|
|
|
|
if(eee->conf.header_encryption == HEADER_ENCRYPTION_ENABLED) |
|
|
|
packet_header_encrypt (pktbuf, idx, eee->conf.header_encryption_ctx, |
|
|
|
packet_header_encrypt(pktbuf, idx, eee->conf.header_encryption_ctx, |
|
|
|
eee->conf.header_iv_ctx, |
|
|
|
time_stamp (), pearson_hash_16 (pktbuf, idx)); |
|
|
|
time_stamp(), pearson_hash_16(pktbuf, idx)); |
|
|
|
|
|
|
|
/* sent = */ sendto_sock(eee->udp_sock, pktbuf, idx, remote_peer); |
|
|
|
} |
|
|
@ -1111,9 +1113,9 @@ void update_supernode_reg (n2n_edge_t * eee, time_t nowTime) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
} else { |
|
|
|
--(eee->sup_attempts); |
|
|
|
} |
|
|
|
|
|
|
|
if(supernode2sock(&(eee->supernode), eee->curr_sn->ip_addr) == 0) { |
|
|
|
traceEvent(TRACE_INFO, "Registering with supernode [%s][number of supernodes %d][attempts left %u]", |
|
|
@ -1169,7 +1171,7 @@ static int handle_PACKET (n2n_edge_t * eee, |
|
|
|
++(eee->stats.rx_sup_broadcast); |
|
|
|
|
|
|
|
++(eee->stats.rx_sup); |
|
|
|
eee->last_sup=now; |
|
|
|
eee->last_sup = now; |
|
|
|
} else { |
|
|
|
++(eee->stats.rx_p2p); |
|
|
|
eee->last_p2p=now; |
|
|
@ -1487,7 +1489,7 @@ static void readFromMgmtSocket (n2n_edge_t *eee, int *keep_running) { |
|
|
|
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), |
|
|
|
" %-4u %-15s %-17s %-21s %-14s %lu\n", |
|
|
|
++num, |
|
|
|
(peer->purgeable == SN_UNPURGEABLE)?"-l ":" ", |
|
|
|
(peer->purgeable == SN_UNPURGEABLE) ? "-l " : " ", |
|
|
|
macaddr_str(mac_buf, peer->mac_addr), |
|
|
|
sock_to_cstr(sockbuf, &(peer->sock)), |
|
|
|
sn_selection_criterion_str(sel_buf, peer), |
|
|
@ -1749,7 +1751,7 @@ void edge_send_packet2net (n2n_edge_t * eee, |
|
|
|
pkt.compression = N2N_COMPRESSION_ID_ZSTD; |
|
|
|
} |
|
|
|
} else { |
|
|
|
traceEvent (TRACE_ERROR, "payload compression failed with zstd error '%s'.", |
|
|
|
traceEvent(TRACE_ERROR, "payload compression failed with zstd error '%s'.", |
|
|
|
ZSTD_getErrorName(compression_len)); |
|
|
|
free(compression_buffer); |
|
|
|
// continue with unset without pkt.compression --> will send uncompressed
|
|
|
@ -1761,10 +1763,10 @@ void edge_send_packet2net (n2n_edge_t * eee, |
|
|
|
} |
|
|
|
|
|
|
|
if(pkt.compression != N2N_COMPRESSION_ID_NONE) { |
|
|
|
traceEvent (TRACE_DEBUG, "payload compression [%s]: compressed %u bytes to %u bytes\n", |
|
|
|
traceEvent(TRACE_DEBUG, "payload compression [%s]: compressed %u bytes to %u bytes\n", |
|
|
|
compression_str(pkt.compression), len, compression_len); |
|
|
|
|
|
|
|
memcpy (tap_pkt, compression_buffer, compression_len); |
|
|
|
memcpy(tap_pkt, compression_buffer, compression_len); |
|
|
|
len = compression_len; |
|
|
|
} |
|
|
|
|
|
|
@ -1779,16 +1781,16 @@ void edge_send_packet2net (n2n_edge_t * eee, |
|
|
|
uint16_t headerIdx = idx; |
|
|
|
|
|
|
|
idx += eee->transop.fwd(&eee->transop, |
|
|
|
pktbuf+idx, N2N_PKT_BUF_SIZE-idx, |
|
|
|
pktbuf + idx, N2N_PKT_BUF_SIZE - idx, |
|
|
|
tap_pkt, len, pkt.dstMac); |
|
|
|
|
|
|
|
traceEvent(TRACE_DEBUG, "Encode %u B PACKET [%u B data, %u B overhead] transform %u", |
|
|
|
(u_int)idx, (u_int)len, (u_int)(idx-len), tx_transop_idx); |
|
|
|
(u_int)idx, (u_int)len, (u_int)(idx - len), tx_transop_idx); |
|
|
|
|
|
|
|
if(eee->conf.header_encryption == HEADER_ENCRYPTION_ENABLED) |
|
|
|
packet_header_encrypt (pktbuf, headerIdx, eee->conf.header_encryption_ctx, |
|
|
|
packet_header_encrypt(pktbuf, headerIdx, eee->conf.header_encryption_ctx, |
|
|
|
eee->conf.header_iv_ctx, |
|
|
|
time_stamp (), pearson_hash_16 (pktbuf, idx)); |
|
|
|
time_stamp(), pearson_hash_16(pktbuf, idx)); |
|
|
|
|
|
|
|
#ifdef MTU_ASSERT_VALUE |
|
|
|
{ |
|
|
@ -2129,8 +2131,8 @@ void readFromIPSocket (n2n_edge_t * eee, int in_sock) { |
|
|
|
sn->ip_addr = calloc(1,N2N_EDGE_SN_HOST_SIZE); |
|
|
|
if(sn->ip_addr != NULL) { |
|
|
|
inet_ntop(payload->sock.family, |
|
|
|
(payload->sock.family == AF_INET)?(void*)&(payload->sock.addr.v4):(void*)&(payload->sock.addr.v6), |
|
|
|
sn->ip_addr, N2N_EDGE_SN_HOST_SIZE-1); |
|
|
|
(payload->sock.family == AF_INET) ? (void*)&(payload->sock.addr.v4) : (void*)&(payload->sock.addr.v6), |
|
|
|
sn->ip_addr, N2N_EDGE_SN_HOST_SIZE - 1); |
|
|
|
sprintf (sn->ip_addr, "%s:%u", sn->ip_addr, (uint16_t)(payload->sock.port)); |
|
|
|
} |
|
|
|
sn_selection_criterion_default(&(sn->selection_criterion)); |
|
|
@ -2226,7 +2228,7 @@ void readFromIPSocket (n2n_edge_t * eee, int in_sock) { |
|
|
|
if(!is_valid_peer_sock(&pi.sock)) { |
|
|
|
traceEvent(TRACE_DEBUG, "Skip invalid PEER_INFO %s [%s]", |
|
|
|
sock_to_cstr(sockbuf1, &pi.sock), |
|
|
|
macaddr_str(mac_buf1, pi.mac) ); |
|
|
|
macaddr_str(mac_buf1, pi.mac)); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
@ -2252,7 +2254,7 @@ void readFromIPSocket (n2n_edge_t * eee, int in_sock) { |
|
|
|
|
|
|
|
} else { |
|
|
|
traceEvent(TRACE_INFO, "Rx PEER_INFO unknown peer %s", |
|
|
|
macaddr_str(mac_buf1, pi.mac) ); |
|
|
|
macaddr_str(mac_buf1, pi.mac)); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|