X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_setup.c;h=cb70926ad0c3dbaa13bac715514098a536f533a8;hp=cb606caad46897e9cb73def798b178e82d5372af;hb=32f5524c4b52a2d3a96bc48ee2437f8b9b4dbe10;hpb=5038964032ef55913b2d4741c67bf191b2208abb diff --git a/src/net_setup.c b/src/net_setup.c index cb606caa..cb70926a 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -204,14 +204,14 @@ bool read_rsa_private_key(void) { /* 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; avl_tree_t *config_tree; config_t *cfg; - subnet_t *s; + subnet_t *s, *s2; node_t *n; bool result; @@ -228,9 +228,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; @@ -243,15 +240,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); @@ -309,6 +312,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"); @@ -339,6 +352,7 @@ bool setup_myself(void) { if(myself->options & OPTION_TCPONLY) myself->options |= OPTION_INDIRECT; + get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets); get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver); strictsubnets |= tunnelserver; @@ -355,8 +369,21 @@ bool setup_myself(void) { return false; } free(mode); - } else - routing_mode = RMODE_ROUTER; + } + + if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) { + if(!strcasecmp(mode, "off")) + forwarding_mode = FMODE_OFF; + else if(!strcasecmp(mode, "internal")) + forwarding_mode = FMODE_INTERNAL; + else if(!strcasecmp(mode, "kernel")) + forwarding_mode = FMODE_KERNEL; + else { + logger(LOG_ERR, "Invalid forwarding mode!"); + return false; + } + free(mode); + } choice = true; get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice);