X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_setup.c;h=74c57c5dd07cfadbcaaa3a9ebc94034da3716aaf;hb=717ea66d7ba0c23f27d86b3d5c6992b751135455;hp=462ff10339ce3b9a761caa5f812a2ed4781f0f5e;hpb=d917c8cb6b69475d568ccbe82389b9f2b3eb5e80;p=tinc diff --git a/src/net_setup.c b/src/net_setup.c index 462ff103..74c57c5d 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -50,6 +50,7 @@ char *proxyport; char *proxyuser; char *proxypass; proxytype_t proxytype; +int autoconnect; char *scriptinterpreter; char *scriptextension; @@ -347,6 +348,36 @@ void load_all_subnets(void) { closedir(dir); } +void load_all_nodes(void) { + DIR *dir; + struct dirent *ent; + char *dname; + + xasprintf(&dname, "%s" SLASH "hosts", confbase); + dir = opendir(dname); + if(!dir) { + logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno)); + free(dname); + return; + } + + while((ent = readdir(dir))) { + if(!check_id(ent->d_name)) + continue; + + node_t *n = lookup_node(ent->d_name); + if(n) + continue; + + n = new_node(); + n->name = xstrdup(ent->d_name); + node_add(n); + } + + closedir(dir); +} + + char *get_name(void) { char *name = NULL; @@ -359,12 +390,12 @@ char *get_name(void) { char *envname = getenv(name + 1); if(!envname) { if(strcmp(name + 1, "HOST")) { - fprintf(stderr, "Invalid Name: environment variable %s does not exist\n", name + 1); + logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1); return false; } envname = alloca(32); if(gethostname(envname, 32)) { - fprintf(stderr, "Could not get hostname: %s\n", strerror(errno)); + logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno)); return false; } envname[31] = 0; @@ -570,6 +601,8 @@ bool setup_myself_reloadable(void) { if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime)) keylifetime = 3600; + get_config_int(lookup_config(config_tree, "AutoConnect"), &autoconnect); + return true; } @@ -668,6 +701,7 @@ static bool setup_myself(void) { return false; } replaywin = (unsigned)replaywin_int; + sptps_replaywin = replaywin; } /* Generate packet encryption key */ @@ -729,6 +763,8 @@ static bool setup_myself(void) { if(strictsubnets) load_all_subnets(); + else if(autoconnect) + load_all_nodes(); /* Open device */