X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Fnet_setup.c;h=6e51b2e243107114577aa320473e17912eaf0085;hp=0718a8c5725acd0576b32110e7600f28e57e0ea4;hb=95a6974de173e0cb78611c6704ed09631d510dae;hpb=7203d5fb07be2d3ae006c2b65d0be1e6533e1273 diff --git a/src/net_setup.c b/src/net_setup.c index 0718a8c..6e51b2e 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -1,7 +1,7 @@ /* net_setup.c -- Setup. Copyright (C) 1998-2005 Ivo Timmermans, - 2000-2009 Guus Sliepen + 2000-2010 Guus Sliepen 2006 Scott Lamb This program is free software; you can redistribute it and/or modify @@ -201,6 +201,65 @@ bool read_rsa_private_key(void) { return true; } +/* + Read Subnets from all host config files +*/ +static 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; + node_t *n; + bool result; + + xasprintf(&dname, "%s/hosts", confbase); + dir = opendir(dname); + if(!dir) { + logger(LOG_ERR, "Could not open %s: %s", dname, strerror(errno)); + free(dname); + return; + } + + while((ent = readdir(dir))) { + if(!check_id(ent->d_name)) + continue; + + n = lookup_node(ent->d_name); + if(n) + continue; + + #ifdef _DIRENT_HAVE_D_TYPE + //if(ent->d_type != DT_REG) + // continue; + #endif + + xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name); + init_configuration(&config_tree); + result = read_config_file(config_tree, fname); + free(fname); + if(!result) + continue; + + 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); + } + + exit_configuration(&config_tree); + } + + closedir(dir); +} + /* Configure node_t myself and set up the local sockets (listen only) */ @@ -246,7 +305,8 @@ bool setup_myself(void) { if(!read_rsa_private_key()) return false; - if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport)) + if(!get_config_string(lookup_config(config_tree, "Port"), &myport) + && !get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport)) myport = xstrdup("655"); /* Read in all the subnets specified in the host configuration file */ @@ -279,7 +339,9 @@ bool setup_myself(void) { if(myself->options & OPTION_TCPONLY) myself->options |= OPTION_INDIRECT; + get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets); get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver); + strictsubnets |= tunnelserver; if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) { if(!strcasecmp(mode, "router")) @@ -293,16 +355,34 @@ bool setup_myself(void) { return false; } free(mode); - } else - routing_mode = RMODE_ROUTER; + } - // Enable PMTUDiscovery by default if we are in router mode. + if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) { + if(!strcasecmp(mode, "off")) + routing_mode = FMODE_OFF; + else if(!strcasecmp(mode, "internal")) + routing_mode = FMODE_INTERNAL; + else if(!strcasecmp(mode, "kernel")) + routing_mode = FMODE_KERNEL; + else { + logger(LOG_ERR, "Invalid forwarding mode!"); + return false; + } + free(mode); + } - choice = routing_mode == RMODE_ROUTER; + choice = true; get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice); - if(choice) + get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice); + if(choice) myself->options |= OPTION_PMTU_DISCOVERY; + choice = true; + get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice); + get_config_bool(lookup_config(myself->connection->config_tree, "ClampMSS"), &choice); + if(choice) + myself->options |= OPTION_CLAMP_MSS; + get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance); #if !defined(SOL_IP) || !defined(IP_TOS) @@ -420,6 +500,9 @@ bool setup_myself(void) { graph(); + if(strictsubnets) + load_all_subnets(); + /* Open device */ if(!setup_device())