mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
Compilation fixes
This commit is contained in:
parent
8915609f1a
commit
2a46674a9a
188
src/sn_utils.c
188
src/sn_utils.c
|
@ -26,8 +26,7 @@ static int try_forward(n2n_sn_t * sss,
|
||||||
const n2n_mac_t dstMac,
|
const n2n_mac_t dstMac,
|
||||||
uint8_t from_supernode,
|
uint8_t from_supernode,
|
||||||
const uint8_t * pktbuf,
|
const uint8_t * pktbuf,
|
||||||
size_t pktsize,
|
size_t pktsize);
|
||||||
uint8_t from_supernode);
|
|
||||||
|
|
||||||
static ssize_t sendto_sock(n2n_sn_t *sss,
|
static ssize_t sendto_sock(n2n_sn_t *sss,
|
||||||
const n2n_sock_t *sock,
|
const n2n_sock_t *sock,
|
||||||
|
@ -45,8 +44,7 @@ static int try_broadcast(n2n_sn_t * sss,
|
||||||
const n2n_mac_t srcMac,
|
const n2n_mac_t srcMac,
|
||||||
uint8_t from_supernode,
|
uint8_t from_supernode,
|
||||||
const uint8_t * pktbuf,
|
const uint8_t * pktbuf,
|
||||||
size_t pktsize,
|
size_t pktsize);
|
||||||
uint8_t from_supernode);
|
|
||||||
|
|
||||||
static uint16_t reg_lifetime(n2n_sn_t *sss);
|
static uint16_t reg_lifetime(n2n_sn_t *sss);
|
||||||
|
|
||||||
|
@ -86,8 +84,7 @@ static int try_forward(n2n_sn_t * sss,
|
||||||
const n2n_mac_t dstMac,
|
const n2n_mac_t dstMac,
|
||||||
uint8_t from_supernode,
|
uint8_t from_supernode,
|
||||||
const uint8_t * pktbuf,
|
const uint8_t * pktbuf,
|
||||||
size_t pktsize,
|
size_t pktsize)
|
||||||
uint8_t from_supernode)
|
|
||||||
{
|
{
|
||||||
struct peer_info * scan;
|
struct peer_info * scan;
|
||||||
macstr_t mac_buf;
|
macstr_t mac_buf;
|
||||||
|
@ -181,8 +178,7 @@ static int try_broadcast(n2n_sn_t * sss,
|
||||||
const n2n_mac_t srcMac,
|
const n2n_mac_t srcMac,
|
||||||
uint8_t from_supernode,
|
uint8_t from_supernode,
|
||||||
const uint8_t * pktbuf,
|
const uint8_t * pktbuf,
|
||||||
size_t pktsize,
|
size_t pktsize)
|
||||||
uint8_t from_supernode)
|
|
||||||
{
|
{
|
||||||
struct peer_info *scan, *tmp;
|
struct peer_info *scan, *tmp;
|
||||||
macstr_t mac_buf;
|
macstr_t mac_buf;
|
||||||
|
@ -236,15 +232,15 @@ static int try_broadcast(n2n_sn_t * sss,
|
||||||
sock_to_cstr(sockbuf, &(scan->sock)),
|
sock_to_cstr(sockbuf, &(scan->sock)),
|
||||||
macaddr_str(mac_buf, scan->mac_addr),
|
macaddr_str(mac_buf, scan->mac_addr),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
++(sss->stats.broadcast);
|
++(sss->stats.broadcast);
|
||||||
traceEvent(TRACE_DEBUG, "multicast %lu to [%s] %s",
|
traceEvent(TRACE_DEBUG, "multicast %lu to [%s] %s",
|
||||||
pktsize,
|
pktsize,
|
||||||
sock_to_cstr(sockbuf, &(scan->sock)),
|
sock_to_cstr(sockbuf, &(scan->sock)),
|
||||||
macaddr_str(mac_buf, scan->mac_addr));
|
macaddr_str(mac_buf, scan->mac_addr));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -711,9 +707,9 @@ static int process_mgmt(n2n_sn_t *sss,
|
||||||
|
|
||||||
traceEvent(TRACE_DEBUG, "process_mgmt");
|
traceEvent(TRACE_DEBUG, "process_mgmt");
|
||||||
|
|
||||||
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
||||||
" id tun_tap MAC edge hint last_seen\n");
|
" id tun_tap MAC edge hint last_seen\n");
|
||||||
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
||||||
"-------------------------------------------------------------------------------------------------\n");
|
"-------------------------------------------------------------------------------------------------\n");
|
||||||
HASH_ITER(hh, sss->communities, community, tmp) {
|
HASH_ITER(hh, sss->communities, community, tmp) {
|
||||||
num_edges += HASH_COUNT(community->edges);
|
num_edges += HASH_COUNT(community->edges);
|
||||||
|
@ -724,13 +720,13 @@ static int process_mgmt(n2n_sn_t *sss,
|
||||||
|
|
||||||
num = 0;
|
num = 0;
|
||||||
HASH_ITER(hh, community->edges, peer, tmpPeer) {
|
HASH_ITER(hh, community->edges, peer, tmpPeer) {
|
||||||
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
|
||||||
" %-4u %-18s %-17s %-21s %-15s %lu\n",
|
" %-4u %-18s %-17s %-21s %-15s %lu\n",
|
||||||
++num, ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
|
++num, ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
|
||||||
macaddr_str(mac_buf, peer->mac_addr),
|
macaddr_str(mac_buf, peer->mac_addr),
|
||||||
sock_to_cstr(sockbuf, &(peer->sock)),
|
sock_to_cstr(sockbuf, &(peer->sock)),
|
||||||
peer->dev_desc,
|
peer->dev_desc,
|
||||||
now - peer->last_seen);
|
now - peer->last_seen);
|
||||||
|
|
||||||
sendto_mgmt(sss, sender_sock, (const uint8_t *) resbuf, ressize);
|
sendto_mgmt(sss, sender_sock, (const uint8_t *) resbuf, ressize);
|
||||||
ressize = 0;
|
ressize = 0;
|
||||||
|
@ -1001,9 +997,9 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
|
|
||||||
/* Common section to forward the final product. */
|
/* Common section to forward the final product. */
|
||||||
if(unicast)
|
if(unicast)
|
||||||
try_forward(sss, comm, &cmn, pkt.dstMac, from_supernode, rec_buf, encx);
|
try_forward(sss, comm, &cmn, pkt.dstMac, from_supernode, rec_buf, encx);
|
||||||
else
|
else
|
||||||
try_broadcast(sss, comm, &cmn, pkt.srcMac, from_supernode, rec_buf, encx);
|
try_broadcast(sss, comm, &cmn, pkt.srcMac, from_supernode, rec_buf, encx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_TYPE_REGISTER:
|
case MSG_TYPE_REGISTER:
|
||||||
|
@ -1119,15 +1115,15 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!comm && sss->lock_communities) {
|
if(!comm && sss->lock_communities) {
|
||||||
HASH_ITER(hh, sss->rules, re, tmp_re) {
|
HASH_ITER(hh, sss->rules, re, tmp_re) {
|
||||||
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length);
|
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length);
|
||||||
|
|
||||||
if( (allowed_match != -1)
|
if( (allowed_match != -1)
|
||||||
&& (match_length == strlen((const char *)cmn.community)) // --- only full matches allowed (remove, if also partial matches wanted)
|
&& (match_length == strlen((const char *)cmn.community)) // --- only full matches allowed (remove, if also partial matches wanted)
|
||||||
&& (allowed_match == 0)) { // --- only full matches allowed (remove, if also partial matches wanted)
|
&& (allowed_match == 0)) { // --- only full matches allowed (remove, if also partial matches wanted)
|
||||||
match = 1;
|
match = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(match != 1) {
|
if(match != 1) {
|
||||||
traceEvent(TRACE_INFO, "Discarded registration: unallowed community '%s'",
|
traceEvent(TRACE_INFO, "Discarded registration: unallowed community '%s'",
|
||||||
|
@ -1136,25 +1132,25 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!comm && (!sss->lock_communities || (match == 1))) {
|
if(!comm && (!sss->lock_communities || (match == 1))) {
|
||||||
comm = (struct sn_community*)calloc(1,sizeof(struct sn_community));
|
comm = (struct sn_community*)calloc(1,sizeof(struct sn_community));
|
||||||
|
|
||||||
if(comm) {
|
if(comm) {
|
||||||
comm_init(comm,(char *)cmn.community);
|
comm_init(comm,(char *)cmn.community);
|
||||||
/* new communities introduced by REGISTERs could not have had encrypted header... */
|
/* new communities introduced by REGISTERs could not have had encrypted header... */
|
||||||
comm->header_encryption = HEADER_ENCRYPTION_NONE;
|
comm->header_encryption = HEADER_ENCRYPTION_NONE;
|
||||||
comm->header_encryption_ctx = NULL;
|
comm->header_encryption_ctx = NULL;
|
||||||
/* ... and also are purgeable during periodic purge */
|
/* ... and also are purgeable during periodic purge */
|
||||||
comm->purgeable = COMMUNITY_PURGEABLE;
|
comm->purgeable = COMMUNITY_PURGEABLE;
|
||||||
comm->number_enc_packets = 0;
|
comm->number_enc_packets = 0;
|
||||||
HASH_ADD_STR(sss->communities, community, comm);
|
HASH_ADD_STR(sss->communities, community, comm);
|
||||||
|
|
||||||
traceEvent(TRACE_INFO, "New community: %s", comm->community);
|
traceEvent(TRACE_INFO, "New community: %s", comm->community);
|
||||||
assign_one_ip_subnet(sss, comm);
|
assign_one_ip_subnet(sss, comm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comm) {
|
if(comm) {
|
||||||
cmn2.ttl = N2N_DEFAULT_TTL;
|
cmn2.ttl = N2N_DEFAULT_TTL;
|
||||||
cmn2.pc = n2n_register_super_ack;
|
cmn2.pc = n2n_register_super_ack;
|
||||||
cmn2.flags = N2N_FLAGS_SOCKET | N2N_FLAGS_FROM_SUPERNODE;
|
cmn2.flags = N2N_FLAGS_SOCKET | N2N_FLAGS_FROM_SUPERNODE;
|
||||||
|
@ -1233,8 +1229,8 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
|
|
||||||
if (comm->header_encryption == HEADER_ENCRYPTION_ENABLED)
|
if (comm->header_encryption == HEADER_ENCRYPTION_ENABLED)
|
||||||
packet_header_encrypt (ackbuf, encx, comm->header_encryption_ctx,
|
packet_header_encrypt (ackbuf, encx, comm->header_encryption_ctx,
|
||||||
comm->header_iv_ctx,
|
comm->header_iv_ctx,
|
||||||
time_stamp (), pearson_hash_16 (ackbuf, encx));
|
time_stamp (), pearson_hash_16 (ackbuf, encx));
|
||||||
|
|
||||||
sendto(sss->sock, ackbuf, encx, 0,
|
sendto(sss->sock, ackbuf, encx, 0,
|
||||||
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in));
|
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in));
|
||||||
|
@ -1348,8 +1344,8 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length);
|
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length);
|
||||||
|
|
||||||
if( (allowed_match != -1)
|
if( (allowed_match != -1)
|
||||||
&& (match_length == strlen((const char *)cmn.community)) // --- only full match…
|
&& (match_length == strlen((const char *)cmn.community)) // --- only full match…
|
||||||
&& (allowed_match == 0)) { // --- only full matches allowed (re…
|
&& (allowed_match == 0)) { // --- only full matches allowed (re…
|
||||||
match = 1;
|
match = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1416,60 +1412,60 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
|
|
||||||
struct peer_info *scan;
|
struct peer_info *scan;
|
||||||
HASH_FIND_PEER(comm->edges, query.targetMac, scan);
|
HASH_FIND_PEER(comm->edges, query.targetMac, scan);
|
||||||
if (scan) {
|
if (scan) {
|
||||||
cmn2.ttl = N2N_DEFAULT_TTL;
|
cmn2.ttl = N2N_DEFAULT_TTL;
|
||||||
cmn2.pc = n2n_peer_info;
|
cmn2.pc = n2n_peer_info;
|
||||||
cmn2.flags = N2N_FLAGS_FROM_SUPERNODE;
|
cmn2.flags = N2N_FLAGS_FROM_SUPERNODE;
|
||||||
memcpy( cmn2.community, cmn.community, sizeof(n2n_community_t) );
|
memcpy( cmn2.community, cmn.community, sizeof(n2n_community_t) );
|
||||||
|
|
||||||
pi.aflags = 0;
|
pi.aflags = 0;
|
||||||
memcpy( pi.mac, query.targetMac, sizeof(n2n_mac_t) );
|
memcpy( pi.mac, query.targetMac, sizeof(n2n_mac_t) );
|
||||||
pi.sock = scan->sock;
|
pi.sock = scan->sock;
|
||||||
|
|
||||||
encode_PEER_INFO( encbuf, &encx, &cmn2, &pi);
|
encode_PEER_INFO( encbuf, &encx, &cmn2, &pi);
|
||||||
|
|
||||||
if(comm->header_encryption == HEADER_ENCRYPTION_ENABLED)
|
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));
|
||||||
|
|
||||||
|
if(cmn.flags & N2N_FLAGS_SOCKET){
|
||||||
|
sendto_sock(sss, &query.sock, encbuf, encx);
|
||||||
|
} else {
|
||||||
|
sendto( sss->sock, encbuf, encx, 0,
|
||||||
|
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in) );
|
||||||
|
}
|
||||||
|
traceEvent( TRACE_DEBUG, "Tx PEER_INFO to %s",
|
||||||
|
macaddr_str( mac_buf, query.srcMac ) );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if(from_supernode){
|
||||||
|
traceEvent( TRACE_DEBUG, "QUERY_PEER on unknown edge from supernode %s. Dropping the packet.",
|
||||||
|
macaddr_str( mac_buf, query.srcMac ) );
|
||||||
|
} else {
|
||||||
|
traceEvent( TRACE_DEBUG, "QUERY_PEER from unknown edge %s. Forwarding to all other supernodes.",
|
||||||
|
macaddr_str( mac_buf, query.srcMac ) );
|
||||||
|
|
||||||
|
memcpy(&cmn2, &cmn, sizeof(n2n_common_t));
|
||||||
|
|
||||||
|
/* We are going to add socket even if it was not there before */
|
||||||
|
cmn2.flags |= N2N_FLAGS_SOCKET | N2N_FLAGS_FROM_SUPERNODE;
|
||||||
|
query.sock.family = AF_INET;
|
||||||
|
query.sock.port = ntohs(sender_sock->sin_port);
|
||||||
|
memcpy(query.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
||||||
|
|
||||||
|
encode_QUERY_PEER( encbuf, &encx, &cmn2, &query );
|
||||||
|
|
||||||
|
if (comm->header_encryption == HEADER_ENCRYPTION_ENABLED)
|
||||||
packet_header_encrypt (encbuf, encx, comm->header_encryption_ctx,
|
packet_header_encrypt (encbuf, encx, comm->header_encryption_ctx,
|
||||||
comm->header_iv_ctx,
|
comm->header_iv_ctx,
|
||||||
time_stamp (), pearson_hash_16 (encbuf, encx));
|
time_stamp (), pearson_hash_16 (encbuf, encx));
|
||||||
|
|
||||||
if(cmn.flags & N2N_FLAGS_SOCKET){
|
try_broadcast(sss, NULL, &cmn, query.srcMac, from_supernode, encbuf, encx);
|
||||||
sendto_sock(sss, &query.sock, encbuf, encx);
|
|
||||||
} else {
|
|
||||||
sendto( sss->sock, encbuf, encx, 0,
|
|
||||||
(struct sockaddr *)sender_sock, sizeof(struct sockaddr_in) );
|
|
||||||
}
|
|
||||||
traceEvent( TRACE_DEBUG, "Tx PEER_INFO to %s",
|
|
||||||
macaddr_str( mac_buf, query.srcMac ) );
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if(from_supernode){
|
|
||||||
traceEvent( TRACE_DEBUG, "QUERY_PEER on unknown edge from supernode %s. Dropping the packet.",
|
|
||||||
macaddr_str( mac_buf, query.srcMac ) );
|
|
||||||
} else {
|
|
||||||
traceEvent( TRACE_DEBUG, "QUERY_PEER from unknown edge %s. Forwarding to all other supernodes.",
|
|
||||||
macaddr_str( mac_buf, query.srcMac ) );
|
|
||||||
|
|
||||||
memcpy(&cmn2, &cmn, sizeof(n2n_common_t));
|
|
||||||
|
|
||||||
/* We are going to add socket even if it was not there before */
|
|
||||||
cmn2.flags |= N2N_FLAGS_SOCKET | N2N_FLAGS_FROM_SUPERNODE;
|
|
||||||
query.sock.family = AF_INET;
|
|
||||||
query.sock.port = ntohs(sender_sock->sin_port);
|
|
||||||
memcpy(query.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
|
||||||
|
|
||||||
encode_QUERY_PEER( encbuf, &encx, &cmn2, &query );
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
try_broadcast(sss, NULL, &cmn, query.srcMac, from_supernode, encbuf, encx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user