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. 7
      src/edge.c
  2. 12
      src/edge_utils.c
  3. 3
      src/edge_utils_win32.c
  4. 10
      src/example_sn_embed.c
  5. 1
      src/network_traffic_filter.c
  6. 23
      src/sn.c
  7. 2
      src/sn_utils.c

7
src/edge.c

@ -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 */

12
src/edge_utils.c

@ -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);
@ -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]",

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);
}

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;

23
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) {
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';
@ -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
@ -282,6 +283,7 @@ 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);
@ -293,6 +295,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
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();
}
}
}
@ -354,6 +357,7 @@ 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);
sss->federation->community[N2N_COMMUNITY_SIZE - 1] = '\0';
@ -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);
}
@ -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;

2
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) {

Loading…
Cancel
Save