|
|
@ -691,7 +691,7 @@ static int process_mgmt(n2n_sn_t *sss, |
|
|
|
} |
|
|
|
} |
|
|
|
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, |
|
|
|
"-------------------------------------------------------------------------------------------------\n"); |
|
|
|
"---------------------------------------------------------------------------------\n"); |
|
|
|
|
|
|
|
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize, |
|
|
|
"uptime %lu | ", (now - sss->start_time)); |
|
|
@ -1091,7 +1091,6 @@ static int process_udp(n2n_sn_t * sss, |
|
|
|
} |
|
|
|
|
|
|
|
if(!comm && (!sss->lock_communities || (match == 1))) { |
|
|
|
|
|
|
|
comm = (struct sn_community*)calloc(1,sizeof(struct sn_community)); |
|
|
|
|
|
|
|
if(comm) { |
|
|
@ -1277,21 +1276,45 @@ if(comm) { |
|
|
|
size_t encx=0; |
|
|
|
n2n_common_t cmn2; |
|
|
|
n2n_PEER_INFO_t pi; |
|
|
|
struct sn_community_regular_expression *re, *tmp_re; |
|
|
|
struct peer_info *peer, *tmp_peer, *p; |
|
|
|
int8_t allowed_match = -1; |
|
|
|
uint8_t match = 0; |
|
|
|
int match_length = 0; |
|
|
|
|
|
|
|
if(!comm) { |
|
|
|
if(!comm && sss->lock_communities) { |
|
|
|
HASH_ITER(hh, sss->rules, re, tmp_re) { |
|
|
|
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length); |
|
|
|
|
|
|
|
if( (allowed_match != -1) |
|
|
|
&& (match_length == strlen((const char *)cmn.community)) // --- only full match…
|
|
|
|
&& (allowed_match == 0)) { // --- only full matches allowed (re…
|
|
|
|
match = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(match != 1) { |
|
|
|
traceEvent(TRACE_DEBUG, "process_udp QUERY_PEER from unknown community %s", cmn.community); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(!comm && sss->lock_communities && (match == 0)) { |
|
|
|
traceEvent(TRACE_DEBUG, "process_udp QUERY_PEER from not allowed community %s", cmn.community); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
decode_QUERY_PEER( &query, &cmn, udp_buf, &rem, &idx ); |
|
|
|
|
|
|
|
// already checked for valid comm
|
|
|
|
if (comm) { |
|
|
|
if(comm->header_encryption == HEADER_ENCRYPTION_ENABLED) { |
|
|
|
if(!find_edge_time_stamp_and_verify (comm->edges, from_supernode, query.srcMac, stamp, TIME_STAMP_ALLOW_JITTER)) { |
|
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped QUERY_PEER due to time stamp error."); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(memcmp(query.targetMac, null_mac, sizeof(n2n_mac_t)) == 0){ |
|
|
|
traceEvent( TRACE_DEBUG, "Rx PING from %s. Requested data: %d", |
|
|
@ -1309,10 +1332,12 @@ if(comm) { |
|
|
|
|
|
|
|
encode_PEER_INFO( encbuf, &encx, &cmn2, &pi ); |
|
|
|
|
|
|
|
if(comm){ |
|
|
|
if(comm->header_encryption == HEADER_ENCRYPTION_ENABLED) |
|
|
|
packet_header_encrypt (encbuf, encx, comm->header_encryption_ctx, |
|
|
|
comm->header_iv_ctx, |
|
|
|
time_stamp (), pearson_hash_16 (encbuf, encx)); |
|
|
|
} |
|
|
|
|
|
|
|
sendto( sss->sock, encbuf, encx, 0, |
|
|
|
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in) ); |
|
|
@ -1327,7 +1352,6 @@ if(comm) { |
|
|
|
|
|
|
|
struct peer_info *scan; |
|
|
|
HASH_FIND_PEER(comm->edges, query.targetMac, scan); |
|
|
|
|
|
|
|
if (scan) { |
|
|
|
cmn2.ttl = N2N_DEFAULT_TTL; |
|
|
|
cmn2.pc = n2n_peer_info; |
|
|
@ -1354,7 +1378,6 @@ if(comm) { |
|
|
|
traceEvent( TRACE_DEBUG, "Ignoring QUERY_PEER for unknown edge %s", |
|
|
|
macaddr_str( mac_buf, query.targetMac ) ); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|