mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
Partial fixes for addressing compilation issues introduced by https://github.com/ntop/n2n/pull/460
This commit is contained in:
parent
c9eedd68f0
commit
f6e4047ce0
|
@ -82,6 +82,9 @@ enum federation{IS_NO_FEDERATION = 0,IS_FEDERATION = 1};
|
||||||
#define COMMUNITY_UNPURGEABLE 0
|
#define COMMUNITY_UNPURGEABLE 0
|
||||||
#define COMMUNITY_PURGEABLE 1
|
#define COMMUNITY_PURGEABLE 1
|
||||||
|
|
||||||
|
#define SN_UNPURGEABLE 0 /* FIX fcarli3 */
|
||||||
|
#define SN_PURGEABLE 1 /* FIX fcarli3 */
|
||||||
|
|
||||||
/* Header encryption indicators */
|
/* Header encryption indicators */
|
||||||
#define HEADER_ENCRYPTION_UNKNOWN 0
|
#define HEADER_ENCRYPTION_UNKNOWN 0
|
||||||
#define HEADER_ENCRYPTION_NONE 1
|
#define HEADER_ENCRYPTION_NONE 1
|
||||||
|
|
|
@ -11,4 +11,3 @@ dh_link
|
||||||
dh_gencontrol
|
dh_gencontrol
|
||||||
dh_md5sums
|
dh_md5sums
|
||||||
dh_builddeb
|
dh_builddeb
|
||||||
dh_builddeb
|
|
||||||
|
|
|
@ -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
|
if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
|
||||||
. /usr/share/debconf/confmodule
|
. /usr/share/debconf/confmodule
|
||||||
db_purge
|
db_purge
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
misc:Depends=debconf (>= 0.5) | debconf-2.0
|
misc:Depends=debconf (>= 0.5) | debconf-2.0
|
||||||
|
misc:Pre-Depends=
|
||||||
|
|
991
src/edge_utils.c
991
src/edge_utils.c
File diff suppressed because it is too large
Load Diff
51
src/sn.c
51
src/sn.c
|
@ -113,20 +113,20 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
|
||||||
if(has_net) {
|
if(has_net) {
|
||||||
if(sscanf(net_str, "%15[^/]/%hhu", ip_str, &bitlen) != 2) {
|
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.",
|
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;
|
has_net = 0;
|
||||||
}
|
}
|
||||||
net = inet_addr(ip_str);
|
net = inet_addr(ip_str);
|
||||||
mask = bitlen2mask(bitlen);
|
mask = bitlen2mask(bitlen);
|
||||||
if((net == (in_addr_t)(-1)) || (net == INADDR_NONE) || (net == INADDR_ANY)
|
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.",
|
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;
|
has_net = 0;
|
||||||
}
|
}
|
||||||
if ((bitlen > 30) || (bitlen == 0)) {
|
if ((bitlen > 30) || (bitlen == 0)) {
|
||||||
traceEvent(TRACE_WARNING, "Bad prefix '%hhu' in '%s' for community '%s', ignoring.",
|
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;
|
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_addr = ntohl(net);
|
||||||
s->auto_ip_net.net_bitlen = bitlen;
|
s->auto_ip_net.net_bitlen = bitlen;
|
||||||
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
|
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
|
||||||
inet_ntoa(*(struct in_addr *) &net),
|
inet_ntoa(*(struct in_addr *) &net),
|
||||||
s->auto_ip_net.net_bitlen,
|
s->auto_ip_net.net_bitlen,
|
||||||
s->community);
|
s->community);
|
||||||
} else {
|
} else {
|
||||||
assign_one_ip_subnet(sss, s);
|
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 */
|
case 'l': { /* supernode:port */
|
||||||
n2n_sock_t *socket;
|
n2n_sock_t *socket;
|
||||||
struct peer_info *anchor_sn;
|
struct peer_info *anchor_sn;
|
||||||
size_t length;
|
size_t length;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sss->federation != NULL) {
|
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);
|
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);
|
anchor_sn->ip_addr = calloc(1,N2N_EDGE_SN_HOST_SIZE);
|
||||||
if(anchor_sn->ip_addr){
|
if(anchor_sn->ip_addr){
|
||||||
strncpy(anchor_sn->ip_addr,_optarg,N2N_EDGE_SN_HOST_SIZE-1);
|
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){
|
if(rv != 0){
|
||||||
traceEvent(TRACE_WARNING, "Invalid socket");
|
traceEvent(TRACE_WARNING, "Invalid socket");
|
||||||
break;
|
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));
|
memcpy(&(anchor_sn->mac_addr),null_mac,sizeof(n2n_mac_t));
|
||||||
anchor_sn->purgeable = SN_UNPURGEABLE;
|
anchor_sn->purgeable = SN_UNPURGEABLE;
|
||||||
anchor_sn->last_valid_time_stamp = initial_time_stamp();
|
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);
|
net_max = inet_addr(ip_max_str);
|
||||||
mask = bitlen2mask(bitlen);
|
mask = bitlen2mask(bitlen);
|
||||||
if ((net_min == (in_addr_t)(-1)) || (net_min == INADDR_NONE) || (net_min == INADDR_ANY)
|
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)
|
|| (net_max == (in_addr_t)(-1)) || (net_max == INADDR_NONE) || (net_max == INADDR_ANY)
|
||||||
|| (ntohl(net_min) > ntohl(net_max))
|
|| (ntohl(net_min) > ntohl(net_max))
|
||||||
|| ((ntohl(net_min) & ~mask) != 0) || ((ntohl(net_max) & ~mask) != 0) ) {
|
|| ((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'",
|
traceEvent(TRACE_WARNING, "Bad network range '%s...%s/%u' in '%s', defaulting to '%s...%s/%d'",
|
||||||
ip_min_str, ip_max_str, bitlen, _optarg,
|
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);
|
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[] = {
|
static const struct option long_options[] = {
|
||||||
{"communities", required_argument, NULL, 'c'},
|
{"communities", required_argument, NULL, 'c'},
|
||||||
{"foreground", no_argument, NULL, 'f'},
|
{"foreground", no_argument, NULL, 'f'},
|
||||||
{"local-port", required_argument, NULL, 'p'},
|
{"local-port", required_argument, NULL, 'p'},
|
||||||
{"mgmt-port", required_argument, NULL, 't'},
|
{"mgmt-port", required_argument, NULL, 't'},
|
||||||
{"autoip", required_argument, NULL, 'a'},
|
{"autoip", required_argument, NULL, 'a'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* *************************************************** */
|
/* *************************************************** */
|
||||||
|
@ -484,7 +489,7 @@ static int add_federation_to_communities(n2n_sn_t *sss){
|
||||||
num_communities = HASH_COUNT(sss->communities);
|
num_communities = HASH_COUNT(sss->communities);
|
||||||
|
|
||||||
traceEvent(TRACE_INFO, "Added federation '%s' to the list of communities [total: %u]",
|
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;
|
return 0;
|
||||||
|
|
287
src/sn_utils.c
287
src/sn_utils.c
|
@ -205,13 +205,13 @@ static int try_broadcast(n2n_sn_t * sss,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialise some fields of the community structure **/
|
/** 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);
|
strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1);
|
||||||
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
|
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
|
||||||
comm->is_federation = IS_NO_FEDERATION;
|
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 = 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_addr = ntohl(sss->max_auto_ip_net.net_addr);
|
||||||
sss->max_auto_ip_net.net_bitlen = N2N_SN_AUTO_IP_NET_BIT_DEFAULT;
|
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 */
|
/* Initialize the federation */
|
||||||
if(sss->federation){
|
if(sss->federation) {
|
||||||
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1);
|
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1);
|
||||||
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0';
|
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0';
|
||||||
/* enable the flag for federation */
|
/* enable the flag for federation */
|
||||||
sss->federation->is_federation = IS_FEDERATION;
|
sss->federation->is_federation = IS_FEDERATION;
|
||||||
sss->federation->purgeable = COMMUNITY_UNPURGEABLE;
|
sss->federation->purgeable = COMMUNITY_UNPURGEABLE;
|
||||||
/* header encryption enabled by default */
|
/* header encryption enabled by default */
|
||||||
sss->federation->header_encryption = HEADER_ENCRYPTION_ENABLED;
|
sss->federation->header_encryption = HEADER_ENCRYPTION_ENABLED;
|
||||||
/*setup the encryption key */
|
/*setup the encryption key */
|
||||||
packet_header_setup_key(sss->federation->community, &(sss->federation->header_encryption_ctx), &(sss->federation->header_iv_ctx));
|
packet_header_setup_key(sss->federation->community, &(sss->federation->header_encryption_ctx), &(sss->federation->header_iv_ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
n2n_srand (n2n_seed());
|
n2n_srand (n2n_seed());
|
||||||
|
|
||||||
/* Random MAC address */
|
/* Random MAC address */
|
||||||
for(i=0; i<6; i++){
|
for(i=0; i<6; i++) {
|
||||||
sss->mac_addr[i] = n2n_rand();
|
sss->mac_addr[i] = n2n_rand();
|
||||||
}
|
}
|
||||||
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */
|
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 == comm) continue;
|
||||||
if(cmn->is_federation == IS_FEDERATION) continue;
|
if(cmn->is_federation == IS_FEDERATION) continue;
|
||||||
if( (net_id <= (cmn->auto_ip_net.net_addr + ~bitlen2mask(cmn->auto_ip_net.net_bitlen)))
|
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) ) {
|
&&(net_id + ~mask >= cmn->auto_ip_net.net_addr) ) {
|
||||||
success = 0;
|
success = 0;
|
||||||
break;
|
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;
|
comm->auto_ip_net.net_bitlen = sss->min_auto_ip_net.net_bitlen;
|
||||||
net = htonl(comm->auto_ip_net.net_addr);
|
net = htonl(comm->auto_ip_net.net_addr);
|
||||||
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
|
traceEvent(TRACE_INFO, "Assigned sub-network %s/%u to community '%s'.",
|
||||||
inet_ntoa(*(struct in_addr *) &net),
|
inet_ntoa(*(struct in_addr *) &net),
|
||||||
comm->auto_ip_net.net_bitlen,
|
comm->auto_ip_net.net_bitlen,
|
||||||
comm->community);
|
comm->community);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
comm->auto_ip_net.net_addr = 0;
|
comm->auto_ip_net.net_addr = 0;
|
||||||
comm->auto_ip_net.net_bitlen = 0;
|
comm->auto_ip_net.net_bitlen = 0;
|
||||||
traceEvent(TRACE_WARNING, "No assignable sub-network left for community '%s'.",
|
traceEvent(TRACE_WARNING, "No assignable sub-network left for community '%s'.",
|
||||||
comm->community);
|
comm->community);
|
||||||
return -1;
|
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) );
|
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;
|
time_t time;
|
||||||
struct peer_info *peer, *tmp;
|
struct peer_info *peer, *tmp;
|
||||||
|
|
||||||
if(comm != NULL){
|
if(comm != NULL) {
|
||||||
HASH_ITER(hh,comm->edges,peer,tmp){
|
HASH_ITER(hh,comm->edges,peer,tmp) {
|
||||||
time = now - peer->last_seen;
|
time = now - peer->last_seen;
|
||||||
if(time <= ALLOWED_TIME) continue;
|
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;
|
|
||||||
|
|
||||||
memset(&cmn, 0, sizeof(cmn));
|
if((time < PURGE_FEDERATION_NODE_INTERVAL)
|
||||||
memset(®, 0, sizeof(reg));
|
|| (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;
|
memset(&cmn, 0, sizeof(cmn));
|
||||||
cmn.pc = n2n_register_super;
|
memset(®, 0, sizeof(reg));
|
||||||
cmn.flags = 0;
|
|
||||||
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
|
|
||||||
|
|
||||||
for (idx = 0; idx < N2N_COOKIE_SIZE; ++idx) /* aggiungi sn_idx */
|
cmn.ttl = N2N_DEFAULT_TTL;
|
||||||
cookie[idx] = n2n_rand() % 0xff;
|
cmn.pc = n2n_register_super;
|
||||||
|
cmn.flags = 0;
|
||||||
|
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
|
||||||
|
|
||||||
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
|
for (idx = 0; idx < N2N_COOKIE_SIZE; ++idx) /* aggiungi sn_idx */
|
||||||
reg.dev_addr.net_addr = ntohl(peer->dev_addr.net_addr);
|
cookie[idx] = n2n_rand() % 0xff;
|
||||||
reg.dev_addr.net_bitlen = mask2bitlen(ntohl(peer->dev_addr.net_bitlen));
|
|
||||||
reg.auth.scheme = 0; /* No auth yet */
|
|
||||||
|
|
||||||
idx = 0;
|
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
|
||||||
encode_mac(reg.edgeMac, &idx, peer->mac_addr);
|
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;
|
idx = 0;
|
||||||
encode_REGISTER_SUPER(pktbuf, &idx, &cmn, ®);
|
encode_mac(reg.edgeMac, &idx, peer->mac_addr);
|
||||||
|
|
||||||
traceEvent(TRACE_DEBUG, "send REGISTER_SUPER to %s",
|
idx = 0;
|
||||||
sock_to_cstr(sockbuf, &(peer->sock)));
|
encode_REGISTER_SUPER(pktbuf, &idx, &cmn, ®);
|
||||||
|
|
||||||
packet_header_encrypt(pktbuf, idx, comm->header_encryption_ctx,
|
traceEvent(TRACE_DEBUG, "send REGISTER_SUPER to %s",
|
||||||
comm->header_iv_ctx,
|
sock_to_cstr(sockbuf, &(peer->sock)));
|
||||||
time_stamp(), pearson_hash_16(pktbuf, idx));
|
|
||||||
|
|
||||||
/* 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 */
|
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
|
/** 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
|
* 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* 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;
|
struct peer_info *scan, *tmp, *peer;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
if(sss->federation != NULL){
|
if(sss->federation != NULL) {
|
||||||
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0){ /* not zero MAC */
|
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0) { /* not zero MAC */
|
||||||
HASH_FIND_PEER(sss->federation->edges, mac, peer);
|
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 */
|
if(peer == NULL) { /* zero MAC, search by socket */
|
||||||
HASH_ITER(hh,sss->federation->edges,scan,tmp){
|
HASH_ITER(hh,sss->federation->edges,scan,tmp) {
|
||||||
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))){
|
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))) {
|
||||||
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t));
|
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t));
|
||||||
peer = scan;
|
peer = scan;
|
||||||
break;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
reg.sock.port = ntohs(sender_sock->sin_port);
|
||||||
memcpy(reg.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
memcpy(reg.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
||||||
|
|
||||||
/* Re-encode the header. */
|
/* Re-encode the header. */
|
||||||
encode_REGISTER(encbuf, &encx, &cmn2, ®);
|
encode_REGISTER(encbuf, &encx, &cmn2, ®);
|
||||||
|
|
||||||
rec_buf = encbuf;
|
rec_buf = encbuf;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1052,7 +1055,7 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
n2n_REGISTER_SUPER_ACK_t ack;
|
n2n_REGISTER_SUPER_ACK_t ack;
|
||||||
n2n_common_t cmn2;
|
n2n_common_t cmn2;
|
||||||
uint8_t ackbuf[N2N_SN_PKTBUF_SIZE];
|
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;
|
size_t encx=0;
|
||||||
struct sn_community *fed;
|
struct sn_community *fed;
|
||||||
struct sn_community_regular_expression *re, *tmp_re;
|
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_sock_t *tmp_sock;
|
||||||
n2n_mac_t *tmp_mac;
|
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");
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER: from_supernode value doesn't correspond to the internal federation marking");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1119,7 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
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;
|
||||||
|
@ -1151,34 +1154,34 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
ack.sock.port = ntohs(sender_sock->sin_port);
|
ack.sock.port = ntohs(sender_sock->sin_port);
|
||||||
memcpy(ack.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
memcpy(ack.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE);
|
||||||
|
|
||||||
/* Add sender's data to federation (or update it) */
|
/* Add sender's data to federation (or update it) */
|
||||||
if(comm->is_federation == IS_FEDERATION){
|
if(comm->is_federation == IS_FEDERATION) {
|
||||||
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac));
|
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac));
|
||||||
if(p) p->last_seen = now;
|
if(p) p->last_seen = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_sock = (void*)tmpbuf;
|
tmp_sock = (void*)tmpbuf;
|
||||||
tmp_mac = (void*)tmpbuf + sizeof(n2n_sock_t);
|
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 */
|
/* Assembling supernode list for REGISTER_SUPER_ACK payload */
|
||||||
HASH_ITER(hh, sss->federation->edges, peer, tmp_peer) {
|
HASH_ITER(hh, sss->federation->edges, peer, tmp_peer) {
|
||||||
if((now - peer->last_seen) >= ALLOWED_TIME) continue; /* skip long-time-not-seen supernodes */
|
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 */
|
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->sock), sizeof(n2n_sock_t));
|
||||||
memcpy((void*)tmpbuf, (void*)&(peer->mac_addr), sizeof(n2n_mac_t));
|
memcpy((void*)tmpbuf, (void*)&(peer->mac_addr), sizeof(n2n_mac_t));
|
||||||
tmp_sock += ENTRY_SIZE;
|
tmp_sock += ENTRY_SIZE;
|
||||||
tmp_mac += ENTRY_SIZE;
|
tmp_mac += ENTRY_SIZE;
|
||||||
}
|
}
|
||||||
ack.num_sn = num;
|
ack.num_sn = num;
|
||||||
|
|
||||||
|
|
||||||
traceEvent(TRACE_DEBUG, "Rx REGISTER_SUPER for %s [%s]",
|
traceEvent(TRACE_DEBUG, "Rx REGISTER_SUPER for %s [%s]",
|
||||||
macaddr_str(mac_buf, reg.edgeMac),
|
macaddr_str(mac_buf, reg.edgeMac),
|
||||||
sock_to_cstr(sockbuf, &(ack.sock)));
|
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, ®, comm, &(ack.sock), now);
|
update_edge(sss, ®, comm, &(ack.sock), now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1213,9 +1216,9 @@ static int process_udp(n2n_sn_t * sss,
|
||||||
macstr_t mac_buf1;
|
macstr_t mac_buf1;
|
||||||
n2n_sock_t sender;
|
n2n_sock_t sender;
|
||||||
n2n_sock_t *orig_sender;
|
n2n_sock_t *orig_sender;
|
||||||
n2n_sock_t *tmp_sock;
|
n2n_sock_t *tmp_sock;
|
||||||
n2n_mac_t *tmp_mac;
|
n2n_mac_t *tmp_mac;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sender.family = AF_INET;
|
sender.family = AF_INET;
|
||||||
sender.port = ntohs(sender_sock->sin_port);
|
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));
|
memset(&ack, 0, sizeof(n2n_REGISTER_SUPER_ACK_t));
|
||||||
|
|
||||||
if(!comm) {
|
if(!comm) {
|
||||||
traceEvent(TRACE_DEBUG, "process_udp REGISTER_SUPER_ACK with unknown community %s", cmn.community);
|
traceEvent(TRACE_DEBUG, "process_udp REGISTER_SUPER_ACK with unknown community %s", cmn.community);
|
||||||
return -1;
|
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.");
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK: from_supernode value doesn't correspond to the internal federation marking.");
|
||||||
return -1;
|
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)",
|
traceEvent(TRACE_INFO, "Rx REGISTER_SUPER_ACK myMAC=%s [%s] (external %s)",
|
||||||
macaddr_str(mac_buf1, ack.edgeMac),
|
macaddr_str(mac_buf1, ack.edgeMac),
|
||||||
sock_to_cstr(sockbuf1, &sender),
|
sock_to_cstr(sockbuf1, &sender),
|
||||||
sock_to_cstr(sockbuf2, orig_sender));
|
sock_to_cstr(sockbuf2, orig_sender));
|
||||||
|
|
||||||
if(comm->is_federation == IS_FEDERATION) {
|
if(comm->is_federation == IS_FEDERATION) {
|
||||||
HASH_FIND_PEER(sss->federation->edges, ack.edgeMac, scan);
|
HASH_FIND_PEER(sss->federation->edges, ack.edgeMac, scan);
|
||||||
if(scan != NULL){
|
if(scan != NULL) {
|
||||||
scan->last_seen = now;
|
scan->last_seen = now;
|
||||||
} else {
|
} else {
|
||||||
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode.");
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn);
|
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn);
|
||||||
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t);
|
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t);
|
||||||
|
|
||||||
for(i=0; i<ack.num_sn; i++){
|
for(i=0; i<ack.num_sn; i++) {
|
||||||
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac);
|
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac);
|
||||||
|
|
||||||
if(tmp){
|
if(tmp) {
|
||||||
tmp->last_seen = now - TEST_TIME;
|
tmp->last_seen = now - TEST_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_sock += ENTRY_SIZE;
|
tmp_sock += ENTRY_SIZE;
|
||||||
tmp_mac += ENTRY_SIZE;
|
tmp_mac += ENTRY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_TYPE_QUERY_PEER: {
|
case MSG_TYPE_QUERY_PEER: {
|
||||||
n2n_QUERY_PEER_t query;
|
n2n_QUERY_PEER_t query;
|
||||||
uint8_t encbuf[N2N_SN_PKTBUF_SIZE];
|
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 (rc > 0)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(sss->sock, &socket_mask))
|
if (FD_ISSET(sss->sock, &socket_mask))
|
||||||
{
|
{
|
||||||
struct sockaddr_in sender_sock;
|
struct sockaddr_in sender_sock;
|
||||||
socklen_t i;
|
socklen_t i;
|
||||||
|
@ -1434,7 +1437,7 @@ int run_sn_loop(n2n_sn_t *sss, int *keep_running)
|
||||||
traceEvent(TRACE_DEBUG, "timeout");
|
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);
|
purge_expired_communities(sss, &last_purge_edges, now);
|
||||||
sort_communities (sss, &last_sort_communities, now);
|
sort_communities (sss, &last_sort_communities, now);
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
|
@ -405,11 +405,14 @@ int encode_REGISTER_SUPER_ACK(uint8_t *base,
|
||||||
retval += encode_uint16(base, idx, reg->lifetime);
|
retval += encode_uint16(base, idx, reg->lifetime);
|
||||||
retval += encode_sock(base, idx, &(reg->sock));
|
retval += encode_sock(base, idx, &(reg->sock));
|
||||||
retval += encode_uint8(base, idx, reg->num_sn);
|
retval += encode_uint8(base, idx, reg->num_sn);
|
||||||
|
|
||||||
|
#if 0 /* FIX fcarli3 */
|
||||||
if (reg->num_sn > 0) {
|
if (reg->num_sn > 0) {
|
||||||
/* We only support 0 or 1 at this stage */
|
/* We only support 0 or 1 at this stage */
|
||||||
retval += encode_sock(base, idx, &(reg->sn_bak));
|
retval += encode_sock(base, idx, &(reg->sn_bak));
|
||||||
retval += encode_mac(base, idx, reg->mac_addr);
|
retval += encode_mac(base, idx, reg->mac_addr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -434,11 +437,14 @@ int decode_REGISTER_SUPER_ACK(n2n_REGISTER_SUPER_ACK_t *reg,
|
||||||
|
|
||||||
/* Following the edge socket are an array of backup supernodes. */
|
/* Following the edge socket are an array of backup supernodes. */
|
||||||
retval += decode_uint8(&(reg->num_sn), base, rem, idx);
|
retval += decode_uint8(&(reg->num_sn), base, rem, idx);
|
||||||
|
|
||||||
|
#if 0 /* FIX fcarli3 */
|
||||||
if (reg->num_sn > 0) {
|
if (reg->num_sn > 0) {
|
||||||
/* We only support 0 or 1 at this stage */
|
/* We only support 0 or 1 at this stage */
|
||||||
retval += decode_sock(&(reg->sn_bak), base, rem, idx);
|
retval += decode_sock(&(reg->sn_bak), base, rem, idx);
|
||||||
retval += decode_mac(reg->mac_addr, base, rem, idx);
|
retval += decode_mac(reg->mac_addr, base, rem, idx);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user