mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
change space indention
This commit is contained in:
parent
102ff18aaa
commit
067f675faa
|
@ -211,6 +211,7 @@ static void help() {
|
||||||
/* *************************************************** */
|
/* *************************************************** */
|
||||||
|
|
||||||
static void setPayloadCompression (n2n_edge_conf_t *conf, int compression) {
|
static void setPayloadCompression (n2n_edge_conf_t *conf, int compression) {
|
||||||
|
|
||||||
/* even though 'compression' and 'conf->compression' share the same encoding scheme,
|
/* even though 'compression' and 'conf->compression' share the same encoding scheme,
|
||||||
* a switch-statement under conditional compilation is used to sort out the
|
* a switch-statement under conditional compilation is used to sort out the
|
||||||
* unsupported optarguments */
|
* 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) {
|
static void setPayloadEncryption (n2n_edge_conf_t *conf, int cipher) {
|
||||||
|
|
||||||
/* even though 'cipher' and 'conf->transop_id' share the same encoding scheme,
|
/* even though 'cipher' and 'conf->transop_id' share the same encoding scheme,
|
||||||
* a switch-statement under conditional compilation is used to sort out the
|
* a switch-statement under conditional compilation is used to sort out the
|
||||||
* unsupported ciphers */
|
* 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) {
|
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 : ""); */
|
/* traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, optargument ? optargument : ""); */
|
||||||
|
|
||||||
switch(optkey) {
|
switch(optkey) {
|
||||||
|
@ -536,6 +539,7 @@ static const struct option long_options[] =
|
||||||
|
|
||||||
/* read command line options */
|
/* read command line options */
|
||||||
static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
|
static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
|
||||||
|
|
||||||
u_char c;
|
u_char c;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv,
|
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) {
|
static char *trim (char *s) {
|
||||||
|
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
while(isspace(s[0]) || (s[0] == '"') || (s[0] == '\'')) s++;
|
while(isspace(s[0]) || (s[0] == '"') || (s[0] == '\'')) s++;
|
||||||
|
@ -573,6 +578,7 @@ static char *trim (char *s) {
|
||||||
|
|
||||||
/* parse the configuration file */
|
/* parse the configuration file */
|
||||||
static int loadFromFile (const char *path, n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
|
static int loadFromFile (const char *path, n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
|
||||||
|
|
||||||
char buffer[4096], *line, *key, *value;
|
char buffer[4096], *line, *key, *value;
|
||||||
u_int line_len, opt_name_len;
|
u_int line_len, opt_name_len;
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
@ -733,6 +739,7 @@ BOOL WINAPI term_handler(DWORD sig)
|
||||||
|
|
||||||
/** Entry point to program from kernel. */
|
/** Entry point to program from kernel. */
|
||||||
int main (int argc, char* argv[]) {
|
int main (int argc, char* argv[]) {
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
tuntap_dev tuntap; /* a tuntap device */
|
tuntap_dev tuntap; /* a tuntap device */
|
||||||
n2n_edge_t *eee; /* single instance for this program */
|
n2n_edge_t *eee; /* single instance for this program */
|
||||||
|
|
|
@ -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;
|
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.token[idx] = n2n_rand() % 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
eee->conf.auth.toksize = sizeof(eee->conf.auth.token);
|
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_ip_subnet_t *dev_addr,
|
||||||
const n2n_desc_t *dev_desc,
|
const n2n_desc_t *dev_desc,
|
||||||
const n2n_sock_t *peer) {
|
const n2n_sock_t *peer) {
|
||||||
|
|
||||||
/* REVISIT: purge of pending_peers not yet done. */
|
/* REVISIT: purge of pending_peers not yet done. */
|
||||||
struct peer_info *scan;
|
struct peer_info *scan;
|
||||||
macstr_t mac_buf;
|
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",
|
traceEvent(TRACE_DEBUG, "Pending peers list size=%u",
|
||||||
HASH_COUNT(eee->pending_peers));
|
HASH_COUNT(eee->pending_peers));
|
||||||
|
|
||||||
/* trace Sending REGISTER */
|
/* trace Sending REGISTER */
|
||||||
if(from_supernode) {
|
if(from_supernode) {
|
||||||
/* UDP NAT hole punching through supernode. Send to peer first(punch local UDP hole)
|
/* 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;
|
cmn.flags = 0;
|
||||||
memcpy(cmn.community, eee->conf.community_name, N2N_COMMUNITY_SIZE);
|
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;
|
eee->curr_sn->last_cookie[idx] = n2n_rand() % 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(reg.cookie, eee->curr_sn->last_cookie, N2N_COOKIE_SIZE);
|
memcpy(reg.cookie, eee->curr_sn->last_cookie, N2N_COOKIE_SIZE);
|
||||||
reg.dev_addr.net_addr = ntohl(eee->device.ip_addr);
|
reg.dev_addr.net_addr = ntohl(eee->device.ip_addr);
|
||||||
|
@ -1111,9 +1113,9 @@ void update_supernode_reg (n2n_edge_t * eee, time_t nowTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
--(eee->sup_attempts);
|
--(eee->sup_attempts);
|
||||||
|
}
|
||||||
|
|
||||||
if(supernode2sock(&(eee->supernode), eee->curr_sn->ip_addr) == 0) {
|
if(supernode2sock(&(eee->supernode), eee->curr_sn->ip_addr) == 0) {
|
||||||
traceEvent(TRACE_INFO, "Registering with supernode [%s][number of supernodes %d][attempts left %u]",
|
traceEvent(TRACE_INFO, "Registering with supernode [%s][number of supernodes %d][attempts left %u]",
|
||||||
|
|
|
@ -26,8 +26,9 @@ static DWORD* tunReadThread (LPVOID lpArg) {
|
||||||
|
|
||||||
struct tunread_arg *arg = (struct tunread_arg*)lpArg;
|
struct tunread_arg *arg = (struct tunread_arg*)lpArg;
|
||||||
|
|
||||||
while(*arg->keep_running)
|
while(*arg->keep_running) {
|
||||||
edge_read_from_tap(arg->eee);
|
edge_read_from_tap(arg->eee);
|
||||||
|
}
|
||||||
|
|
||||||
return((DWORD*)NULL);
|
return((DWORD*)NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
static int keep_running;
|
static int keep_running;
|
||||||
|
|
||||||
int main()
|
int main () {
|
||||||
{
|
|
||||||
n2n_sn_t sss_node;
|
n2n_sn_t sss_node;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -30,14 +30,12 @@ int main()
|
||||||
sss_node.lport = 1234; // Main UDP listen port
|
sss_node.lport = 1234; // Main UDP listen port
|
||||||
|
|
||||||
sss_node.sock = open_socket(sss_node.lport, 1);
|
sss_node.sock = open_socket(sss_node.lport, 1);
|
||||||
if (-1 == sss_node.sock)
|
if(-1 == sss_node.sock) {
|
||||||
{
|
|
||||||
exit(-2);
|
exit(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
sss_node.mgmt_sock = open_socket(5645, 0); // Main UDP management port
|
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);
|
exit(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,6 @@ uint8_t march_rule_and_cache_key (filter_rule_key_t *rule_key, packet_address_pr
|
||||||
/* for [-Wmissing-declarations] */
|
/* 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* 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;
|
filter_rule_t *item = 0, *tmp = 0, *marched_rule = 0;
|
||||||
|
|
20
src/sn.c
20
src/sn.c
|
@ -67,11 +67,11 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) {
|
||||||
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
|
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
|
||||||
int len = strlen(line);
|
int len = strlen(line);
|
||||||
|
|
||||||
if(((len < 2) || line[0]) == '#') {
|
if((len < 2) || line[0] == '#') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
len--;
|
|
||||||
|
|
||||||
|
len--;
|
||||||
while(len > 0) {
|
while(len > 0) {
|
||||||
if((line[len] == '\n') || (line[len] == '\r')) {
|
if((line[len] == '\n') || (line[len] == '\r')) {
|
||||||
line[len] = '\0';
|
line[len] = '\0';
|
||||||
|
@ -229,7 +229,6 @@ static void help () {
|
||||||
/* *************************************************** */
|
/* *************************************************** */
|
||||||
|
|
||||||
static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
|
static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||||
|
|
||||||
//traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, _optarg ? _optarg : "");
|
//traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, _optarg ? _optarg : "");
|
||||||
|
|
||||||
switch(optkey) {
|
switch(optkey) {
|
||||||
|
@ -282,6 +281,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sss->federation != NULL) {
|
if(sss->federation != NULL) {
|
||||||
|
|
||||||
skip_add = SN_ADD;
|
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);
|
anchor_sn = add_sn_to_list_by_mac_or_sock(&(sss->federation->edges), socket, (n2n_mac_t*) null_mac, &skip_add);
|
||||||
|
|
||||||
|
@ -293,6 +293,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||||
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,6 +355,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case 'F': { /* federation name */
|
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';
|
sss->federation->community[N2N_COMMUNITY_SIZE - 1] = '\0';
|
||||||
|
|
||||||
|
@ -464,6 +466,7 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
|
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) {
|
||||||
|
|
||||||
line = trim(line);
|
line = trim(line);
|
||||||
value = NULL;
|
value = NULL;
|
||||||
|
|
||||||
|
@ -499,12 +502,8 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) {
|
||||||
}
|
}
|
||||||
} else if(line[0] == '-') { /* short opt */
|
} else if(line[0] == '-') { /* short opt */
|
||||||
key = &line[1], line_len--;
|
key = &line[1], line_len--;
|
||||||
if(line_len > 1) {
|
if(line_len > 1) key[1] = '\0';
|
||||||
key[1] = '\0';
|
if(line_len > 2) value = trim(&key[2]);
|
||||||
}
|
|
||||||
if(line_len > 2) {
|
|
||||||
value = trim(&key[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// traceEvent(TRACE_NORMAL, "key: %c value: %s", key[0], value);
|
// traceEvent(TRACE_NORMAL, "key: %c value: %s", key[0], value);
|
||||||
setOption(key[0], value, sss);
|
setOption(key[0], value, sss);
|
||||||
|
@ -528,7 +527,9 @@ static int add_federation_to_communities (n2n_sn_t *sss) {
|
||||||
|
|
||||||
if(sss->federation != NULL) {
|
if(sss->federation != NULL) {
|
||||||
HASH_ADD_STR(sss->communities, community, sss->federation);
|
HASH_ADD_STR(sss->communities, community, sss->federation);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -659,6 +660,7 @@ int main (int argc, char * const argv[]) {
|
||||||
} else {
|
} else {
|
||||||
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
|
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if(((pw = getpwnam ("n2n")) != NULL) || ((pw = getpwnam ("nobody")) != NULL)) {
|
if(((pw = getpwnam ("n2n")) != NULL) || ((pw = getpwnam ("nobody")) != NULL)) {
|
||||||
sss_node.userid = sss_node.userid == 0 ? pw->pw_uid : 0;
|
sss_node.userid = sss_node.userid == 0 ? pw->pw_uid : 0;
|
||||||
|
|
|
@ -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)),
|
udp_size, intoa(ntohl(sender_sock->sin_addr.s_addr), buf, sizeof(buf)),
|
||||||
ntohs(sender_sock->sin_port));
|
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
|
* 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 */
|
* changes to wire.c:encode/decode_common need to go together with this code */
|
||||||
if(udp_size < 20) {
|
if(udp_size < 20) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user