Partial fixes for addressing compilation issues introduced by https://github.com/ntop/n2n/pull/460

This commit is contained in:
Luca Deri 2020-10-11 11:57:48 +02:00
parent c9eedd68f0
commit f6e4047ce0
8 changed files with 682 additions and 664 deletions

View File

@ -82,6 +82,9 @@ enum federation{IS_NO_FEDERATION = 0,IS_FEDERATION = 1};
#define COMMUNITY_UNPURGEABLE 0
#define COMMUNITY_PURGEABLE 1
#define SN_UNPURGEABLE 0 /* FIX fcarli3 */
#define SN_PURGEABLE 1 /* FIX fcarli3 */
/* Header encryption indicators */
#define HEADER_ENCRYPTION_UNKNOWN 0
#define HEADER_ENCRYPTION_NONE 1

View File

@ -11,4 +11,3 @@ dh_link
dh_gencontrol
dh_md5sums
dh_builddeb
dh_builddeb

View File

@ -1,4 +1,4 @@
# Automatically added by dh_installdebconf
# Automatically added by dh_installdebconf/11.1.6ubuntu2
if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
db_purge

View File

@ -1 +1,2 @@
misc:Depends=debconf (>= 0.5) | debconf-2.0
misc:Pre-Depends=

File diff suppressed because it is too large Load Diff

View File

@ -113,20 +113,20 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
if(has_net) {
if(sscanf(net_str, "%15[^/]/%hhu", ip_str, &bitlen) != 2) {
traceEvent(TRACE_WARNING, "Bad net/bit format '%s' for community '%c', ignoring. See comments inside community.list file.",
net_str, cmn_str);
net_str, cmn_str);
has_net = 0;
}
net = inet_addr(ip_str);
mask = bitlen2mask(bitlen);
if((net == (in_addr_t)(-1)) || (net == INADDR_NONE) || (net == INADDR_ANY)
|| ((ntohl(net) & ~mask) != 0) ) {
|| ((ntohl(net) & ~mask) != 0) ) {
traceEvent(TRACE_WARNING, "Bad network '%s/%u' in '%s' for community '%s', ignoring.",
ip_str, bitlen, net_str, cmn_str);
ip_str, bitlen, net_str, cmn_str);
has_net = 0;
}
if ((bitlen > 30) || (bitlen == 0)) {
traceEvent(TRACE_WARNING, "Bad prefix '%hhu' in '%s' for community '%s', ignoring.",
bitlen, net_str, cmn_str);
bitlen, net_str, cmn_str);
has_net = 0;
}
}
@ -134,9 +134,9 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
s->auto_ip_net.net_addr = ntohl(net);
s->auto_ip_net.net_bitlen = bitlen;
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
inet_ntoa(*(struct in_addr *) &net),
s->auto_ip_net.net_bitlen,
s->community);
inet_ntoa(*(struct in_addr *) &net),
s->auto_ip_net.net_bitlen,
s->community);
} else {
assign_one_ip_subnet(sss, s);
}
@ -232,7 +232,7 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
case 'l': { /* supernode:port */
n2n_sock_t *socket;
struct peer_info *anchor_sn;
struct peer_info *anchor_sn;
size_t length;
int rv;
@ -243,7 +243,7 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
}
if(sss->federation != NULL) {
socket = (n2n_sock_t *)calloc(1,sizeof(n2n_sock_t));
socket = (n2n_sock_t *)calloc(1,sizeof(n2n_sock_t));
anchor_sn = add_sn_to_federation_by_mac_or_sock(sss,socket, (n2n_mac_t*) null_mac);
@ -251,14 +251,19 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
anchor_sn->ip_addr = calloc(1,N2N_EDGE_SN_HOST_SIZE);
if(anchor_sn->ip_addr){
strncpy(anchor_sn->ip_addr,_optarg,N2N_EDGE_SN_HOST_SIZE-1);
rv = supernode2sock(socket,_optarg);
#if 1
rv = -1;
#else
rv = supernode2sock(socket,_optarg); /* FIX fcarli3 */
#endif
if(rv != 0){
traceEvent(TRACE_WARNING, "Invalid socket");
break;
}
memcpy(&(anchor_sn->sock), socket, sizeof(n2n_sock_t));
memcpy(&(anchor_sn->sock), socket, sizeof(n2n_sock_t));
memcpy(&(anchor_sn->mac_addr),null_mac,sizeof(n2n_mac_t));
anchor_sn->purgeable = SN_UNPURGEABLE;
anchor_sn->last_valid_time_stamp = initial_time_stamp();
@ -285,9 +290,9 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
net_max = inet_addr(ip_max_str);
mask = bitlen2mask(bitlen);
if ((net_min == (in_addr_t)(-1)) || (net_min == INADDR_NONE) || (net_min == INADDR_ANY)
|| (net_max == (in_addr_t)(-1)) || (net_max == INADDR_NONE) || (net_max == INADDR_ANY)
|| (ntohl(net_min) > ntohl(net_max))
|| ((ntohl(net_min) & ~mask) != 0) || ((ntohl(net_max) & ~mask) != 0) ) {
|| (net_max == (in_addr_t)(-1)) || (net_max == INADDR_NONE) || (net_max == INADDR_ANY)
|| (ntohl(net_min) > ntohl(net_max))
|| ((ntohl(net_min) & ~mask) != 0) || ((ntohl(net_max) & ~mask) != 0) ) {
traceEvent(TRACE_WARNING, "Bad network range '%s...%s/%u' in '%s', defaulting to '%s...%s/%d'",
ip_min_str, ip_max_str, bitlen, _optarg,
N2N_SN_MIN_AUTO_IP_NET_DEFAULT, N2N_SN_MAX_AUTO_IP_NET_DEFAULT, N2N_SN_AUTO_IP_NET_BIT_DEFAULT);
@ -364,14 +369,14 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
/* *********************************************** */
static const struct option long_options[] = {
{"communities", required_argument, NULL, 'c'},
{"foreground", no_argument, NULL, 'f'},
{"local-port", required_argument, NULL, 'p'},
{"mgmt-port", required_argument, NULL, 't'},
{"autoip", required_argument, NULL, 'a'},
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
{"communities", required_argument, NULL, 'c'},
{"foreground", no_argument, NULL, 'f'},
{"local-port", required_argument, NULL, 'p'},
{"mgmt-port", required_argument, NULL, 't'},
{"autoip", required_argument, NULL, 'a'},
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
/* *************************************************** */
@ -484,7 +489,7 @@ static int add_federation_to_communities(n2n_sn_t *sss){
num_communities = HASH_COUNT(sss->communities);
traceEvent(TRACE_INFO, "Added federation '%s' to the list of communities [total: %u]",
(char*)sss->federation->community, num_communities);
(char*)sss->federation->community, num_communities);
}
return 0;

View File

@ -205,13 +205,13 @@ static int try_broadcast(n2n_sn_t * sss,
}
/** Initialise some fields of the community structure **/
int comm_init(struct sn_community *comm, char *cmn){
int comm_init(struct sn_community *comm, char *cmn) {
strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1);
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
comm->is_federation = IS_NO_FEDERATION;
strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1);
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
comm->is_federation = IS_NO_FEDERATION;
return 0; /* OK */
return 0; /* OK */
}
@ -238,25 +238,25 @@ int sn_init(n2n_sn_t *sss) {
sss->max_auto_ip_net.net_addr = inet_addr(N2N_SN_MAX_AUTO_IP_NET_DEFAULT);
sss->max_auto_ip_net.net_addr = ntohl(sss->max_auto_ip_net.net_addr);
sss->max_auto_ip_net.net_bitlen = N2N_SN_AUTO_IP_NET_BIT_DEFAULT;
sss->federation = (struct sn_community *)calloc(1,sizeof(struct sn_community));
sss->federation = (struct sn_community *)calloc(1,sizeof(struct sn_community));
/* Initialize the federation */
if(sss->federation){
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1);
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0';
/* enable the flag for federation */
/* Initialize the federation */
if(sss->federation) {
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1);
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0';
/* enable the flag for federation */
sss->federation->is_federation = IS_FEDERATION;
sss->federation->purgeable = COMMUNITY_UNPURGEABLE;
/* header encryption enabled by default */
sss->federation->header_encryption = HEADER_ENCRYPTION_ENABLED;
/*setup the encryption key */
packet_header_setup_key(sss->federation->community, &(sss->federation->header_encryption_ctx), &(sss->federation->header_iv_ctx));
}
}
n2n_srand (n2n_seed());
/* Random MAC address */
for(i=0; i<6; i++){
for(i=0; i<6; i++) {
sss->mac_addr[i] = n2n_rand();
}
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */
@ -423,9 +423,9 @@ int subnet_available(n2n_sn_t *sss,
if (cmn == comm) continue;
if(cmn->is_federation == IS_FEDERATION) continue;
if( (net_id <= (cmn->auto_ip_net.net_addr + ~bitlen2mask(cmn->auto_ip_net.net_bitlen)))
&&(net_id + ~mask >= cmn->auto_ip_net.net_addr) ) {
success = 0;
break;
&&(net_id + ~mask >= cmn->auto_ip_net.net_addr) ) {
success = 0;
break;
}
}
@ -471,15 +471,15 @@ int assign_one_ip_subnet(n2n_sn_t *sss,
comm->auto_ip_net.net_bitlen = sss->min_auto_ip_net.net_bitlen;
net = htonl(comm->auto_ip_net.net_addr);
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
inet_ntoa(*(struct in_addr *) &net),
comm->auto_ip_net.net_bitlen,
comm->community);
inet_ntoa(*(struct in_addr *) &net),
comm->auto_ip_net.net_bitlen,
comm->community);
return 0;
} else {
comm->auto_ip_net.net_addr = 0;
comm->auto_ip_net.net_bitlen = 0;
traceEvent(TRACE_WARNING, "No assignable sub-network left for community '%s'.",
comm->community);
comm->community);
return -1;
}
}
@ -510,58 +510,61 @@ static int find_edge_time_stamp_and_verify (struct peer_info * edges,
return ( time_stamp_verify_and_update (stamp, previous_stamp, allow_jitter) );
}
static int re_register_and_purge_supernodes(n2n_sn_t *sss, struct sn_community *comm, time_t now){
static int re_register_and_purge_supernodes(n2n_sn_t *sss, struct sn_community *comm, time_t now) {
time_t time;
struct peer_info *peer, *tmp;
if(comm != NULL){
HASH_ITER(hh,comm->edges,peer,tmp){
time = now - peer->last_seen;
if(time <= ALLOWED_TIME) continue;
if((time < PURGE_FEDERATION_NODE_INTERVAL) || (peer->purgeable == SN_UNPURGEABLE)){ /* re-regitser (send REGISTER_SUPER) */
uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0};
size_t idx;
/* ssize_t sent; */
n2n_common_t cmn;
n2n_cookie_t cookie;
n2n_REGISTER_SUPER_t reg;
n2n_sock_str_t sockbuf;
if(comm != NULL) {
HASH_ITER(hh,comm->edges,peer,tmp) {
time = now - peer->last_seen;
if(time <= ALLOWED_TIME) continue;
memset(&cmn, 0, sizeof(cmn));
memset(&reg, 0, sizeof(reg));
if((time < PURGE_FEDERATION_NODE_INTERVAL)
|| (peer->purgeable == SN_UNPURGEABLE) /* FIX fcarli3 */
) {
/* re-regitser (send REGISTER_SUPER) */
uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0};
size_t idx;
/* ssize_t sent; */
n2n_common_t cmn;
n2n_cookie_t cookie;
n2n_REGISTER_SUPER_t reg;
n2n_sock_str_t sockbuf;
cmn.ttl = N2N_DEFAULT_TTL;
cmn.pc = n2n_register_super;
cmn.flags = 0;
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
memset(&cmn, 0, sizeof(cmn));
memset(&reg, 0, sizeof(reg));
for (idx = 0; idx < N2N_COOKIE_SIZE; ++idx) /* aggiungi sn_idx */
cookie[idx] = n2n_rand() % 0xff;
cmn.ttl = N2N_DEFAULT_TTL;
cmn.pc = n2n_register_super;
cmn.flags = 0;
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
reg.dev_addr.net_addr = ntohl(peer->dev_addr.net_addr);
reg.dev_addr.net_bitlen = mask2bitlen(ntohl(peer->dev_addr.net_bitlen));
reg.auth.scheme = 0; /* No auth yet */
for (idx = 0; idx < N2N_COOKIE_SIZE; ++idx) /* aggiungi sn_idx */
cookie[idx] = n2n_rand() % 0xff;
idx = 0;
encode_mac(reg.edgeMac, &idx, peer->mac_addr);
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
reg.dev_addr.net_addr = ntohl(peer->dev_addr.net_addr);
reg.dev_addr.net_bitlen = mask2bitlen(ntohl(peer->dev_addr.net_bitlen));
reg.auth.scheme = 0; /* No auth yet */
idx = 0;
encode_REGISTER_SUPER(pktbuf, &idx, &cmn, &reg);
idx = 0;
encode_mac(reg.edgeMac, &idx, peer->mac_addr);
traceEvent(TRACE_DEBUG, "send REGISTER_SUPER to %s",
sock_to_cstr(sockbuf, &(peer->sock)));
idx = 0;
encode_REGISTER_SUPER(pktbuf, &idx, &cmn, &reg);
packet_header_encrypt(pktbuf, idx, comm->header_encryption_ctx,
comm->header_iv_ctx,
time_stamp(), pearson_hash_16(pktbuf, idx));
traceEvent(TRACE_DEBUG, "send REGISTER_SUPER to %s",
sock_to_cstr(sockbuf, &(peer->sock)));
/* sent = */ sendto_sock(sss, &(peer->sock), pktbuf, N2N_PKT_BUF_SIZE);
packet_header_encrypt(pktbuf, idx, comm->header_encryption_ctx,
comm->header_iv_ctx,
time_stamp(), pearson_hash_16(pktbuf, idx));
/* sent = */ sendto_sock(sss, &(peer->sock), pktbuf, N2N_PKT_BUF_SIZE);
}
if(time >= PURGE_FEDERATION_NODE_INTERVAL) purge_expired_registrations(&(comm->edges),&time,PURGE_FEDERATION_NODE_INTERVAL);/* purge not-seen-long-time supernodes*/
}
}
if(time >= PURGE_FEDERATION_NODE_INTERVAL) purge_expired_registrations(&(comm->edges),&time,PURGE_FEDERATION_NODE_INTERVAL);/* purge not-seen-long-time supernodes*/
}
}
return 0; /* OK */
}
@ -731,40 +734,40 @@ static int sendto_mgmt(n2n_sn_t *sss,
/** Search for a node in the federation list. If it has to add a new node, it creates a new peer_info and initializes it
* Evaluate first the MAC parameter and if it's zero-MAC, then it can skip HASH_FIND_PEER by MAC and search by socket
*/
struct peer_info* add_sn_to_federation_by_mac_or_sock(n2n_sn_t *sss,n2n_sock_t *sock, n2n_mac_t *mac){
struct peer_info *scan, *tmp, *peer;
int found = 0;
* Evaluate first the MAC parameter and if it's zero-MAC, then it can skip HASH_FIND_PEER by MAC and search by socket
*/
struct peer_info* add_sn_to_federation_by_mac_or_sock(n2n_sn_t *sss,n2n_sock_t *sock, n2n_mac_t *mac) {
struct peer_info *scan, *tmp, *peer;
int found = 0;
if(sss->federation != NULL){
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0){ /* not zero MAC */
HASH_FIND_PEER(sss->federation->edges, mac, peer);
if(sss->federation != NULL) {
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0) { /* not zero MAC */
HASH_FIND_PEER(sss->federation->edges, mac, peer);
//REVISIT: make this dependent from last_seen and update socket
}
//REVISIT: make this dependent from last_seen and update socket
}
if(peer == NULL){ /* zero MAC, search by socket */
HASH_ITER(hh,sss->federation->edges,scan,tmp){
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))){
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t));
peer = scan;
break;
}
}
if(peer == NULL){
peer = (struct peer_info*)calloc(1,sizeof(struct peer_info));
if(peer){
memcpy(&(peer->sock),sock,sizeof(n2n_sock_t));
memcpy(&(peer->mac_addr),mac, sizeof(n2n_mac_t));
HASH_ADD_PEER(sss->federation->edges,peer);
}
}
}
if(peer == NULL) { /* zero MAC, search by socket */
HASH_ITER(hh,sss->federation->edges,scan,tmp) {
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))) {
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t));
peer = scan;
break;
}
}
return peer;
if(peer == NULL) {
peer = (struct peer_info*)calloc(1,sizeof(struct peer_info));
if(peer) {
memcpy(&(peer->sock),sock,sizeof(n2n_sock_t));
memcpy(&(peer->mac_addr),mac, sizeof(n2n_mac_t));
HASH_ADD_PEER(sss->federation->edges,peer);
}
}
}
}
return peer;
}
@ -1021,8 +1024,8 @@ static int process_udp(n2n_sn_t * sss,
reg.sock.port = ntohs(sender_sock->sin_port);
memcpy(reg.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
/* Re-encode the header. */
encode_REGISTER(encbuf, &encx, &cmn2, &reg);
/* Re-encode the header. */
encode_REGISTER(encbuf, &encx, &cmn2, &reg);
rec_buf = encbuf;
} else {
@ -1052,7 +1055,7 @@ static int process_udp(n2n_sn_t * sss,
n2n_REGISTER_SUPER_ACK_t ack;
n2n_common_t cmn2;
uint8_t ackbuf[N2N_SN_PKTBUF_SIZE];
uint8_t tmpbuf[MAX_AVAILABLE_SPACE_FOR_ENTRIES];
uint8_t tmpbuf[MAX_AVAILABLE_SPACE_FOR_ENTRIES];
size_t encx=0;
struct sn_community *fed;
struct sn_community_regular_expression *re, *tmp_re;
@ -1065,7 +1068,7 @@ static int process_udp(n2n_sn_t * sss,
n2n_sock_t *tmp_sock;
n2n_mac_t *tmp_mac;
if(from_supernode != comm->is_federation){
if(from_supernode != comm->is_federation) {
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER: from_supernode value doesn't correspond to the internal federation marking");
return -1;
}
@ -1116,7 +1119,7 @@ static int process_udp(n2n_sn_t * sss,
comm = (struct sn_community*)calloc(1,sizeof(struct sn_community));
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... */
comm->header_encryption = HEADER_ENCRYPTION_NONE;
comm->header_encryption_ctx = NULL;
@ -1151,34 +1154,34 @@ static int process_udp(n2n_sn_t * sss,
ack.sock.port = ntohs(sender_sock->sin_port);
memcpy(ack.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
/* Add sender's data to federation (or update it) */
if(comm->is_federation == IS_FEDERATION){
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac));
/* Add sender's data to federation (or update it) */
if(comm->is_federation == IS_FEDERATION) {
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac));
if(p) p->last_seen = now;
}
tmp_sock = (void*)tmpbuf;
tmp_mac = (void*)tmpbuf + sizeof(n2n_sock_t);
tmp_sock = (void*)tmpbuf;
tmp_mac = (void*)tmpbuf + sizeof(n2n_sock_t);
// REVISIT: consider adding last_seen
// REVISIT: consider adding last_seen
/* Assembling supernode list for REGISTER_SUPER_ACK payload */
HASH_ITER(hh, sss->federation->edges, peer, tmp_peer) {
if((now - peer->last_seen) >= ALLOWED_TIME) continue; /* skip long-time-not-seen supernodes */
if(((++num)*ENTRY_SIZE) > MAX_AVAILABLE_SPACE_FOR_ENTRIES) break; /* no more space available in REGISTER_SUPER_ACK payload */
memcpy((void*)tmpbuf, (void*)&(peer->sock), sizeof(n2n_sock_t));
memcpy((void*)tmpbuf, (void*)&(peer->mac_addr), sizeof(n2n_mac_t));
tmp_sock += ENTRY_SIZE;
tmp_mac += ENTRY_SIZE;
}
ack.num_sn = num;
/* Assembling supernode list for REGISTER_SUPER_ACK payload */
HASH_ITER(hh, sss->federation->edges, peer, tmp_peer) {
if((now - peer->last_seen) >= ALLOWED_TIME) continue; /* skip long-time-not-seen supernodes */
if(((++num)*ENTRY_SIZE) > MAX_AVAILABLE_SPACE_FOR_ENTRIES) break; /* no more space available in REGISTER_SUPER_ACK payload */
memcpy((void*)tmpbuf, (void*)&(peer->sock), sizeof(n2n_sock_t));
memcpy((void*)tmpbuf, (void*)&(peer->mac_addr), sizeof(n2n_mac_t));
tmp_sock += ENTRY_SIZE;
tmp_mac += ENTRY_SIZE;
}
ack.num_sn = num;
traceEvent(TRACE_DEBUG, "Rx REGISTER_SUPER for %s [%s]",
macaddr_str(mac_buf, reg.edgeMac),
sock_to_cstr(sockbuf, &(ack.sock)));
if(memcmp(reg.edgeMac, &null_mac, N2N_MAC_SIZE) != 0){
if(memcmp(reg.edgeMac, &null_mac, N2N_MAC_SIZE) != 0) {
update_edge(sss, &reg, comm, &(ack.sock), now);
}
@ -1213,9 +1216,9 @@ static int process_udp(n2n_sn_t * sss,
macstr_t mac_buf1;
n2n_sock_t sender;
n2n_sock_t *orig_sender;
n2n_sock_t *tmp_sock;
n2n_mac_t *tmp_mac;
int i;
n2n_sock_t *tmp_sock;
n2n_mac_t *tmp_mac;
int i;
sender.family = AF_INET;
sender.port = ntohs(sender_sock->sin_port);
@ -1224,12 +1227,12 @@ static int process_udp(n2n_sn_t * sss,
memset(&ack, 0, sizeof(n2n_REGISTER_SUPER_ACK_t));
if(!comm) {
traceEvent(TRACE_DEBUG, "process_udp REGISTER_SUPER_ACK with unknown community %s", cmn.community);
return -1;
}
if(!comm) {
traceEvent(TRACE_DEBUG, "process_udp REGISTER_SUPER_ACK with unknown community %s", cmn.community);
return -1;
}
if(from_supernode != comm->is_federation){
if(from_supernode != comm->is_federation) {
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK: from_supernode value doesn't correspond to the internal federation marking.");
return -1;
}
@ -1247,36 +1250,36 @@ static int process_udp(n2n_sn_t * sss,
}
traceEvent(TRACE_INFO, "Rx REGISTER_SUPER_ACK myMAC=%s [%s] (external %s)",
macaddr_str(mac_buf1, ack.edgeMac),
sock_to_cstr(sockbuf1, &sender),
sock_to_cstr(sockbuf2, orig_sender));
macaddr_str(mac_buf1, ack.edgeMac),
sock_to_cstr(sockbuf1, &sender),
sock_to_cstr(sockbuf2, orig_sender));
if(comm->is_federation == IS_FEDERATION) {
HASH_FIND_PEER(sss->federation->edges, ack.edgeMac, scan);
if(scan != NULL){
scan->last_seen = now;
} else {
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode.");
break;
}
}
if(scan != NULL) {
scan->last_seen = now;
} else {
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode.");
break;
}
}
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn);
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t);
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn);
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t);
for(i=0; i<ack.num_sn; i++){
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac);
for(i=0; i<ack.num_sn; i++) {
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac);
if(tmp){
tmp->last_seen = now - TEST_TIME;
}
if(tmp) {
tmp->last_seen = now - TEST_TIME;
}
tmp_sock += ENTRY_SIZE;
tmp_mac += ENTRY_SIZE;
}
tmp_sock += ENTRY_SIZE;
tmp_mac += ENTRY_SIZE;
}
break;
}
break;
}
case MSG_TYPE_QUERY_PEER: {
n2n_QUERY_PEER_t query;
uint8_t encbuf[N2N_SN_PKTBUF_SIZE];
@ -1376,7 +1379,7 @@ int run_sn_loop(n2n_sn_t *sss, int *keep_running)
if (rc > 0)
{
if (FD_ISSET(sss->sock, &socket_mask))
if (FD_ISSET(sss->sock, &socket_mask))
{
struct sockaddr_in sender_sock;
socklen_t i;
@ -1434,7 +1437,7 @@ int run_sn_loop(n2n_sn_t *sss, int *keep_running)
traceEvent(TRACE_DEBUG, "timeout");
}
re_register_and_purge_supernodes(sss, sss->federation, now);
re_register_and_purge_supernodes(sss, sss->federation, now);
purge_expired_communities(sss, &last_purge_edges, now);
sort_communities (sss, &last_sort_communities, now);
} /* while */

View File

@ -405,12 +405,15 @@ int encode_REGISTER_SUPER_ACK(uint8_t *base,
retval += encode_uint16(base, idx, reg->lifetime);
retval += encode_sock(base, idx, &(reg->sock));
retval += encode_uint8(base, idx, reg->num_sn);
#if 0 /* FIX fcarli3 */
if (reg->num_sn > 0) {
/* We only support 0 or 1 at this stage */
retval += encode_sock(base, idx, &(reg->sn_bak));
retval += encode_mac(base, idx, reg->mac_addr);
}
#endif
return retval;
}
@ -434,12 +437,15 @@ int decode_REGISTER_SUPER_ACK(n2n_REGISTER_SUPER_ACK_t *reg,
/* Following the edge socket are an array of backup supernodes. */
retval += decode_uint8(&(reg->num_sn), base, rem, idx);
#if 0 /* FIX fcarli3 */
if (reg->num_sn > 0) {
/* We only support 0 or 1 at this stage */
retval += decode_sock(&(reg->sn_bak), base, rem, idx);
retval += decode_mac(reg->mac_addr, base, rem, idx);
}
#endif
return retval;
}