X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_setup.c;h=198da3df93419e7760d58d98a11c8dca14b17923;hb=ee427cac0d04c60d09cc235c04664eab8b0c6527;hp=597c3cb754575ab16f5b69d82164eb0377bc210b;hpb=ffa1dc73dcd62a856325641972a13d398aa8121c;p=tinc diff --git a/src/net_setup.c b/src/net_setup.c index 597c3cb7..198da3df 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -157,14 +157,14 @@ void regenerate_key() { /* Read Subnets from all host config files */ -static void load_all_subnets(void) { +void load_all_subnets(void) { DIR *dir; struct dirent *ent; char *dname; char *fname; splay_tree_t *config_tree; config_t *cfg; - subnet_t *s; + subnet_t *s, *s2; node_t *n; bool result; @@ -181,9 +181,6 @@ static void load_all_subnets(void) { continue; n = lookup_node(ent->d_name); - if(n) - continue; - #ifdef _DIRENT_HAVE_D_TYPE //if(ent->d_type != DT_REG) // continue; @@ -196,15 +193,21 @@ static void load_all_subnets(void) { if(!result) continue; - n = new_node(); - n->name = xstrdup(ent->d_name); - node_add(n); + if(!n) { + n = new_node(); + n->name = xstrdup(ent->d_name); + node_add(n); + } for(cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) { if(!get_config_subnet(cfg, &s)) continue; - subnet_add(n, s); + if((s2 = lookup_subnet(n, s))) { + s2->expires = -1; + } else { + subnet_add(n, s); + } } exit_configuration(&config_tree); @@ -262,6 +265,16 @@ bool setup_myself(void) { && !get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport)) myport = xstrdup("655"); + if(!atoi(myport)) { + struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM); + sockaddr_t sa; + if(!ai || !ai->ai_addr) + return false; + free(myport); + memcpy(&sa, ai->ai_addr, ai->ai_addrlen); + sockaddr2str(&sa, NULL, &myport); + } + /* Read in all the subnets specified in the host configuration file */ cfg = lookup_config(myself->connection->config_tree, "Subnet"); @@ -452,7 +465,7 @@ bool setup_myself(void) { execute_script("tinc-up", envp); - for(i = 0; i < 5; i++) + for(i = 0; i < 4; i++) free(envp[i]); /* Run subnet-up scripts for our own subnets */ @@ -498,7 +511,7 @@ bool setup_myself(void) { EV_READ|EV_PERSIST, handle_new_meta_connection, NULL); if(event_add(&listen_socket[listen_sockets].ev_tcp, NULL) < 0) { - logger(LOG_EMERG, "event_add failed: %s", strerror(errno)); + logger(LOG_ERR, "event_add failed: %s", strerror(errno)); abort(); } @@ -507,7 +520,7 @@ bool setup_myself(void) { EV_READ|EV_PERSIST, handle_incoming_vpn_data, NULL); if(event_add(&listen_socket[listen_sockets].ev_udp, NULL) < 0) { - logger(LOG_EMERG, "event_add failed: %s", strerror(errno)); + logger(LOG_ERR, "event_add failed: %s", strerror(errno)); abort(); }