Browse Source

Change space indention (#556)

* readability code clean-up

* readability code clean-up

* change space indention

* change space indention

* Update sn_utils.c
pull/572/head
Francesco Carli 4 years ago
committed by GitHub
parent
commit
244b1bef95
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/edge.c
  2. 48
      src/edge_utils.c
  3. 3
      src/edge_utils_win32.c
  4. 10
      src/example_sn_embed.c
  5. 10
      src/n2n.c
  6. 16
      src/n2n_regex.c
  7. 1
      src/network_traffic_filter.c
  8. 47
      src/sn.c
  9. 14
      src/sn_utils.c
  10. 8
      src/wire.c

11
src/edge.c

@ -112,7 +112,7 @@ static int scan_address (char * ip_addr, size_t addr_size,
/* *************************************************** */
static void help() {
static void help () {
print_n2n_version();
printf("edge <config file> (see edge.conf)\n"
@ -211,6 +211,7 @@ static void help() {
/* *************************************************** */
static void setPayloadCompression (n2n_edge_conf_t *conf, int compression) {
/* even though 'compression' and 'conf->compression' share the same encoding scheme,
* a switch-statement under conditional compilation is used to sort out the
* unsupported optarguments */
@ -238,6 +239,7 @@ static void setPayloadCompression (n2n_edge_conf_t *conf, int compression) {
/* *************************************************** */
static void setPayloadEncryption (n2n_edge_conf_t *conf, int cipher) {
/* even though 'cipher' and 'conf->transop_id' share the same encoding scheme,
* a switch-statement under conditional compilation is used to sort out the
* unsupported ciphers */
@ -278,6 +280,7 @@ static void setPayloadEncryption (n2n_edge_conf_t *conf, int cipher) {
/* *************************************************** */
static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *ec, n2n_edge_conf_t *conf) {
/* traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, optargument ? optargument : ""); */
switch(optkey) {
@ -536,6 +539,7 @@ static const struct option long_options[] =
/* read command line options */
static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
u_char c;
while ((c = getopt_long(argc, argv,
@ -555,6 +559,7 @@ static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tunta
/* *************************************************** */
static char *trim (char *s) {
char *end;
while(isspace(s[0]) || (s[0] == '"') || (s[0] == '\'')) s++;
@ -573,6 +578,7 @@ static char *trim (char *s) {
/* parse the configuration file */
static int loadFromFile (const char *path, n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
char buffer[4096], *line, *key, *value;
u_int line_len, opt_name_len;
FILE *fd;
@ -733,6 +739,7 @@ BOOL WINAPI term_handler(DWORD sig)
/** Entry point to program from kernel. */
int main (int argc, char* argv[]) {
int rc;
tuntap_dev tuntap; /* a tuntap device */
n2n_edge_t *eee; /* single instance for this program */
@ -860,7 +867,7 @@ int main (int argc, char* argv[]) {
traceEvent(TRACE_NORMAL, "Local tap IP: %s, Mask: %s",
eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask);
memcpy(&eee->device, &tuntap, sizeof(tuntap));
// hexdump((unsigned char*)&tuntap,sizeof(tuntap_dev));
//hexdump((unsigned char*)&tuntap,sizeof(tuntap_dev));
#ifndef WIN32
if(eee->tuntap_priv_conf.daemon) {

48
src/edge_utils.c

@ -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;

3
src/edge_utils_win32.c

@ -26,8 +26,9 @@ static DWORD* tunReadThread (LPVOID lpArg) {
struct tunread_arg *arg = (struct tunread_arg*)lpArg;
while(*arg->keep_running)
while(*arg->keep_running) {
edge_read_from_tap(arg->eee);
}
return((DWORD*)NULL);
}

10
src/example_sn_embed.c

@ -20,8 +20,8 @@
static int keep_running;
int main()
{
int main () {
n2n_sn_t sss_node;
int rc;
@ -30,14 +30,12 @@ int main()
sss_node.lport = 1234; // Main UDP listen port
sss_node.sock = open_socket(sss_node.lport, 1);
if (-1 == sss_node.sock)
{
if(-1 == sss_node.sock) {
exit(-2);
}
sss_node.mgmt_sock = open_socket(5645, 0); // Main UDP management port
if (-1 == sss_node.mgmt_sock)
{
if(-1 == sss_node.mgmt_sock) {
exit(-2);
}

10
src/n2n.c

@ -232,7 +232,7 @@ uint8_t mask2bitlen (uint32_t mask) {
uint8_t i, bitlen = 0;
for (i = 0; i < 32; ++i) {
if ((mask << i) & 0x80000000) {
if((mask << i) & 0x80000000) {
++bitlen;
} else {
break;
@ -399,8 +399,8 @@ void hexdump (const uint8_t *buf, size_t len) {
}
printf("-----------------------------------------------\n");
for (i = 0; i < len; i++) {
if ((i > 0) && ((i % 16) == 0)) {
for(i = 0; i < len; i++) {
if((i > 0) && ((i % 16) == 0)) {
printf("\n");
}
printf("%02X ", buf[i] & 0xFF);
@ -611,8 +611,8 @@ uint64_t time_stamp (void) {
fraction never exceeds 1,000,000,) encode the value tv_usec. The remaining lowest 12 bits
are kept random for use in IV */
micro_seconds = n2n_rand();
micro_seconds = ( (((uint64_t)(tod.tv_sec) << 32) + (tod.tv_usec << 12))
| (micro_seconds >> 52) );
micro_seconds = ((((uint64_t)(tod.tv_sec) << 32) + (tod.tv_usec << 12))
| (micro_seconds >> 52));
// more exact but more costly due to the multiplication:
// micro_seconds = (tod.tv_sec * 1000000 + tod.tv_usec) << 12) | ...

16
src/n2n_regex.c

@ -140,22 +140,22 @@ re_t re_compile (const char* pattern) {
int i = 0; /* index into pattern */
int j = 0; /* index into re_compiled */
while(pattern[i] != '\0' && (j+1 < MAX_REGEXP_OBJECTS)) {
while(pattern[i] != '\0' && (j + 1 < MAX_REGEXP_OBJECTS)) {
c = pattern[i];
switch(c) {
/* Meta-characters: */
// case '^': { re_compiled[j].type = BEGIN; } break; <-- disabled (always full matches)
// case '$': { re_compiled[j].type = END; } break; <-- disabled (always full matches)
// case '^': { re_compiled[j].type = BEGIN; } break; <-- disabled (always full matches)
// case '$': { re_compiled[j].type = END; } break; <-- disabled (always full matches)
case '.': { re_compiled[j].type = DOT; } break;
case '*': { re_compiled[j].type = STAR; } break;
case '+': { re_compiled[j].type = PLUS; } break;
case '?': { re_compiled[j].type = QUESTIONMARK; } break;
/* case '|': { re_compiled[j].type = BRANCH; } break; <-- not working properly */
/* case '|': { re_compiled[j].type = BRANCH; } break; <-- not working properly */
/* Escaped character-classes (\s \w ...): */
case '\\': {
if(pattern[i+1] != '\0') {
if(pattern[i + 1] != '\0') {
/* Skip the escape-char '\\' */
i += 1;
/* ... and check the next */
@ -176,13 +176,13 @@ re_t re_compile (const char* pattern) {
}
}
/* '\\' as last char in pattern -> invalid regular expression. */
/*
/*
else
{
re_compiled[j].type = CHAR_TYPE;
re_compiled[j].ch = pattern[i];
}
*/
*/
} break;
/* Character class: */
@ -199,7 +199,7 @@ re_t re_compile (const char* pattern) {
}
/* Copy characters inside [..] to buffer */
while( (pattern[++i] != ']')
while((pattern[++i] != ']')
&& (pattern[i] != '\0')) /* Missing ] */
{
if(pattern[i] == '\\') {

1
src/network_traffic_filter.c

@ -265,7 +265,6 @@ uint8_t march_rule_and_cache_key (filter_rule_key_t *rule_key, packet_address_pr
/* for [-Wmissing-declarations] */
filter_rule_t* get_filter_rule (filter_rule_t **rules, packet_address_proto_info_t *pkt_addr_info);
filter_rule_t* get_filter_rule (filter_rule_t **rules, packet_address_proto_info_t *pkt_addr_info) {
filter_rule_t *item = 0, *tmp = 0, *marched_rule = 0;

47
src/sn.c

@ -54,7 +54,7 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
}
HASH_DEL(sss->communities, s);
if(NULL != s->header_encryption_ctx) {
free (s->header_encryption_ctx);
free(s->header_encryption_ctx);
}
free(s);
}
@ -67,11 +67,11 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
int len = strlen(line);
if(((len < 2) || line[0]) == '#') {
if((len < 2) || line[0] == '#') {
continue;
}
len--;
len--;
while(len > 0) {
if((line[len] == '\n') || (line[len] == '\r')) {
line[len] = '\0';
@ -88,7 +88,7 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
// if it contains typical characters...
if(NULL != strpbrk(cmn_str, ".*+?[]\\")) {
// ...it is treated as regular expression
re = (struct sn_community_regular_expression*)calloc(1, sizeof(struct sn_community_regular_expression));
re = (struct sn_community_regular_expression*)calloc(1,sizeof(struct sn_community_regular_expression));
if(re) {
re->rule = re_compile(cmn_str);
HASH_ADD_PTR(sss->rules, rule, re);
@ -99,7 +99,7 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
}
}
s = (struct sn_community*)calloc(1, sizeof(struct sn_community));
s = (struct sn_community*)calloc(1,sizeof(struct sn_community));
if(s != NULL) {
comm_init(s,cmn_str);
@ -125,7 +125,7 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
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);
has_net = 0;
@ -186,6 +186,7 @@ static void help () {
printf("-p <local port> ");
printf("-c <path> ");
printf("-l <supernode:port> ");
#if defined(N2N_HAVE_DAEMON)
printf("[-f] ");
#endif
@ -207,7 +208,7 @@ static void help () {
#if defined(N2N_HAVE_DAEMON)
printf("-f | Run in foreground.\n");
#endif /* #if defined(N2N_HAVE_DAEMON) */
printf("-F <fed_name> | Name of the supernodes federation (otherwise use '%s' by default)\n",(char *)FEDERATION_NAME);
printf("-F <fed_name> | Name of the supernodes federation (otherwise use '%s' by default)\n", (char *)FEDERATION_NAME);
#if 0
printf("-m <mac_addr> | Fix MAC address for the supernode (otherwise it may be random)\n"
" | eg. -m 01:02:03:04:05:06\n");
@ -282,17 +283,19 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
}
if(sss->federation != NULL) {
skip_add = SN_ADD;
anchor_sn = add_sn_to_list_by_mac_or_sock(&(sss->federation->edges), socket, (n2n_mac_t*) null_mac, &skip_add);
if(anchor_sn != NULL) {
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);
strncpy(anchor_sn->ip_addr, _optarg, N2N_EDGE_SN_HOST_SIZE - 1);
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();
}
}
}
@ -319,7 +322,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
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) ) {
|| ((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);
@ -354,7 +357,8 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
#endif
case 'F': { /* federation name */
snprintf(sss->federation->community, N2N_COMMUNITY_SIZE - 1, "*%s", _optarg);
snprintf(sss->federation->community, N2N_COMMUNITY_SIZE - 1 ,"*%s", _optarg);
sss->federation->community[N2N_COMMUNITY_SIZE - 1] = '\0';
break;
@ -384,7 +388,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
break;
default:
traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char)optkey);
traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char) optkey);
return (-1);
}
@ -464,6 +468,7 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) {
}
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
line = trim(line);
value = NULL;
@ -499,12 +504,8 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) {
}
} else if(line[0] == '-') { /* short opt */
key = &line[1], line_len--;
if(line_len > 1) {
key[1] = '\0';
}
if(line_len > 2) {
value = trim(&key[2]);
}
if(line_len > 1) key[1] = '\0';
if(line_len > 2) value = trim(&key[2]);
// traceEvent(TRACE_NORMAL, "key: %c value: %s", key[0], value);
setOption(key[0], value, sss);
@ -528,7 +529,9 @@ static int add_federation_to_communities (n2n_sn_t *sss) {
if(sss->federation != NULL) {
HASH_ADD_STR(sss->communities, community, sss->federation);
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);
}
@ -558,11 +561,11 @@ static void dump_registrations (int signo) {
++num, macaddr_str(buf, list->mac_addr),
list->sock.addr.v4[0], list->sock.addr.v4[1], list->sock.addr.v4[2], list->sock.addr.v4[3],
list->sock.port,
now-list->last_seen);
now - list->last_seen);
} else {
traceEvent(TRACE_NORMAL, "[id: %u][MAC: %s][edge: IPv6:%u][last seen: %u sec ago]",
++num, macaddr_str(buf, list->mac_addr), list->sock.port,
now-list->last_seen);
now - list->last_seen);
}
}
}
@ -579,7 +582,7 @@ static int keep_running;
#ifdef WIN32
BOOL WINAPI term_handler (DWORD sig)
#else
static void term_handler (int sig)
static void term_handler(int sig)
#endif
{
static int called = 0;
@ -605,6 +608,7 @@ BOOL WINAPI term_handler (DWORD sig)
int main (int argc, char * const argv[]) {
int rc;
#ifndef WIN32
struct passwd *pw = NULL;
#endif
@ -620,6 +624,7 @@ int main (int argc, char * const argv[]) {
} else if(argc > 1) {
rc = loadFromCLI(argc, argv, &sss_node);
} else
#ifdef WIN32
/* Load from current directory */
rc = loadFromFile("supernode.conf", &sss_node);
@ -631,6 +636,7 @@ int main (int argc, char * const argv[]) {
help();
}
#if defined(N2N_HAVE_DAEMON)
if(sss_node.daemon) {
setUseSyslog(1); /* traceEvent output now goes to syslog. */
@ -659,6 +665,7 @@ int main (int argc, char * const argv[]) {
} else {
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
}
#ifndef WIN32
if(((pw = getpwnam ("n2n")) != NULL) || ((pw = getpwnam ("nobody")) != NULL)) {
sss_node.userid = sss_node.userid == 0 ? pw->pw_uid : 0;

14
src/sn_utils.c

@ -879,7 +879,7 @@ static int process_udp (n2n_sn_t * sss,
udp_size, intoa(ntohl(sender_sock->sin_addr.s_addr), buf, sizeof(buf)),
ntohs(sender_sock->sin_port));
/* check if header is unenrypted. the following check is around 99.99962 percent reliable.
/* check if header is unencrypted. the following check is around 99.99962 percent reliable.
* it heavily relies on the structure of packet's common part
* changes to wire.c:encode/decode_common need to go together with this code */
if(udp_size < 20) {
@ -888,8 +888,8 @@ static int process_udp (n2n_sn_t * sss,
}
if((udp_buf[19] == (uint8_t)0x00) // null terminated community name
&& (udp_buf[00] == N2N_PKT_VERSION) // correct packet version
&& ((be16toh (*(uint16_t*)&(udp_buf[02])) & N2N_FLAGS_TYPE_MASK ) <= MSG_TYPE_MAX_TYPE ) // message type
&& ( be16toh (*(uint16_t*)&(udp_buf[02])) < N2N_FLAGS_OPTIONS) // flags
&& ((be16toh(*(uint16_t*)&(udp_buf[02])) & N2N_FLAGS_TYPE_MASK) <= MSG_TYPE_MAX_TYPE) // message type
&& ( be16toh(*(uint16_t*)&(udp_buf[02])) < N2N_FLAGS_OPTIONS) // flags
) {
/* most probably unencrypted */
/* make sure, no downgrading happens here and no unencrypted packets can be
@ -968,7 +968,7 @@ static int process_udp (n2n_sn_t * sss,
}
msg_type = cmn.pc; /* packet code */
from_supernode= cmn.flags & N2N_FLAGS_FROM_SUPERNODE;
from_supernode = cmn.flags & N2N_FLAGS_FROM_SUPERNODE;
if(cmn.ttl < 1) {
traceEvent(TRACE_WARNING, "Expired TTL");
@ -995,12 +995,12 @@ static int process_udp (n2n_sn_t * sss,
return -1;
}
sss->stats.last_fwd=now;
sss->stats.last_fwd = now;
decode_PACKET(&pkt, &cmn, udp_buf, &rem, &idx);
// already checked for valid comm
if(comm->header_encryption == HEADER_ENCRYPTION_ENABLED) {
if(!find_edge_time_stamp_and_verify (comm->edges, from_supernode, pkt.srcMac, stamp, TIME_STAMP_ALLOW_JITTER)) {
if(!find_edge_time_stamp_and_verify(comm->edges, from_supernode, pkt.srcMac, stamp, TIME_STAMP_ALLOW_JITTER)) {
traceEvent(TRACE_DEBUG, "process_udp dropped PACKET due to time stamp error.");
return -1;
}
@ -1077,7 +1077,7 @@ static int process_udp (n2n_sn_t * sss,
return -1;
}
sss->stats.last_fwd=now;
sss->stats.last_fwd = now;
decode_REGISTER(&reg, &cmn, udp_buf, &rem, &idx);
// already checked for valid comm

8
src/wire.c

@ -217,13 +217,13 @@ int decode_common (n2n_common_t * out,
decode_uint8(&dummy, base, rem, idx);
if (N2N_PKT_VERSION != dummy) {
if(N2N_PKT_VERSION != dummy) {
return -1;
}
decode_uint8(&(out->ttl), base, rem, idx);
decode_uint16(&(out->flags), base, rem, idx);
out->pc = ( out->flags & N2N_FLAGS_TYPE_MASK );
out->pc = (out->flags & N2N_FLAGS_TYPE_MASK);
out->flags &= N2N_FLAGS_BITS_MASK;
decode_buf(out->community, N2N_COMMUNITY_SIZE, base, rem, idx);
@ -288,7 +288,7 @@ int decode_sock (n2n_sock_t * sock,
decode_buf(sock->addr.v4, IPV4_SIZE, base, rem, idx);
}
return (idx-idx0);
return (idx - idx0);
}
@ -511,7 +511,7 @@ 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);
retval += decode_buf(tmpbuf, (reg->num_sn*REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE), base, rem, idx);
retval += decode_buf(tmpbuf, (reg->num_sn * REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE), base, rem, idx);
return retval;
}

Loading…
Cancel
Save