--- gvpe/src/conf.C 2005/04/26 00:55:55 1.41 +++ gvpe/src/conf.C 2008/08/10 02:49:27 1.48 @@ -1,22 +1,32 @@ /* conf.c -- configuration code - Copyright (C) 2003-2005 Marc Lehmann + Copyright (C) 2003-2008 Marc Lehmann This file is part of GVPE. - GVPE is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with gvpe; if not, write to the Free Software - Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + GVPE is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + + Additional permission under GNU GPL version 3 section 7 + + If you modify this Program, or any covered work, by linking or + combining it with the OpenSSL project's OpenSSL library (or a modified + version of that library), containing parts covered by the terms of the + OpenSSL or SSLeay licenses, the licensors of this Program grant you + additional permission to convey the resulting work. Corresponding + Source for a non-source form of such a combination shall include the + source code for the parts of OpenSSL used as well as that of the + covered work. */ #include "config.h" @@ -71,6 +81,30 @@ return ""; } +static bool +match_list (const vector &list, const char *str) +{ + for (vector::const_iterator i = list.end (); i-- > list.begin (); ) + if ((*i)[0] == '*' && !(*i)[1]) + return true; + else if (!strcmp (*i, str)) + return true; + + return false; +} + +bool +conf_node::may_direct (struct conf_node *other) +{ + if (match_list (allow_direct, other->nodename)) + return true; + + if (match_list (deny_direct, other->nodename)) + return false; + + return true; +} + void conf_node::print () { @@ -78,9 +112,11 @@ id, id >> 8, id & 0xff, compress ? 'Y' : 'N', - connectmode == C_ONDEMAND ? "ondemand" : - connectmode == C_NEVER ? "never" : - connectmode == C_ALWAYS ? "always" : "", + connectmode == C_ONDEMAND ? "ondemand" + : connectmode == C_NEVER ? "never" + : connectmode == C_ALWAYS ? "always" + : connectmode == C_DISABLED ? "disabled" + : "", nodename, hostname ? hostname : "", hostname ? ":" : "", @@ -125,6 +161,8 @@ default_node.compress = true; default_node.protocols = 0; default_node.max_retry = DEFAULT_MAX_RETRY; + default_node.max_ttl = DEFAULT_MAX_TTL; + default_node.max_queue = DEFAULT_MAX_QUEUE; default_node.if_up_data = strdup (""); #if ENABLE_DNS @@ -434,6 +472,14 @@ { u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; } + else if (!strcmp (var, "allow-direct")) + node->allow_direct.push_back (strdup (val)); + else if (!strcmp (var, "deny-direct")) + node->deny_direct.push_back (strdup (val)); + else if (!strcmp (var, "max-ttl")) + node->max_ttl = atof (val); + else if (!strcmp (var, "max-queue")) + node->max_queue = atoi (val); // unknown or misplaced else @@ -442,6 +488,21 @@ return 0; } +void conf_node::finalise () +{ + if (max_queue < 1) + { + slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); + max_queue = 1; + } + + if (routerprio && (connectmode != C_ALWAYS && connectmode != C_DISABLED)) + { + //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); + connectmode = C_ALWAYS; + } +} + void configuration_parser::parse_argv () { for (int i = 0; i < argc; ++i) @@ -554,6 +615,9 @@ } free (fname); + + for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) + (*i)->finalise (); } char *configuration::config_filename (const char *name, const char *dflt)