--- gvpe/src/conf.C 2008/08/10 22:18:58 1.49 +++ gvpe/src/conf.C 2011/03/06 19:40:28 1.55 @@ -1,6 +1,6 @@ /* - conf.c -- configuration code - Copyright (C) 2003-2008 Marc Lehmann + conf.C -- configuration code + Copyright (C) 2003-2008,2011 Marc Lehmann This file is part of GVPE. @@ -59,7 +59,8 @@ struct configuration conf; -u8 best_protocol (u8 protset) +u8 +best_protocol (u8 protset) { if (protset & PROT_IPv4 ) return PROT_IPv4; if (protset & PROT_ICMPv4) return PROT_ICMPv4; @@ -70,7 +71,8 @@ return 0; } -const char *strprotocol (u8 protocol) +const char * +strprotocol (u8 protocol) { if (protocol & PROT_IPv4 ) return "rawip"; if (protocol & PROT_ICMPv4) return "icmp"; @@ -105,25 +107,6 @@ return true; } -void -conf_node::print () -{ - printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", - id, - id >> 8, id & 0xff, - compress ? 'Y' : 'N', - connectmode == C_ONDEMAND ? "ondemand" - : connectmode == C_NEVER ? "never" - : connectmode == C_ALWAYS ? "always" - : connectmode == C_DISABLED ? "disabled" - : "", - nodename, - hostname ? hostname : "", - hostname ? ":" : "", - hostname ? udp_port : 0 - ); -} - conf_node::~conf_node () { #if 0 @@ -142,11 +125,13 @@ #endif } -void configuration::init () +void +configuration::init () { memset (this, 0, sizeof (*this)); mtu = DEFAULT_MTU; + nfmark = 0; rekey = DEFAULT_REKEY; keepalive = DEFAULT_KEEPALIVE; llevel = L_INFO; @@ -168,6 +153,7 @@ #if ENABLE_DNS default_node.dns_port = 0; // default is 0 == client + dns_case_preserving = true; dns_forw_host = strdup ("127.0.0.1"); dns_forw_port = 53; dns_timeout_factor = DEFAULT_DNS_TIMEOUT_FACTOR; @@ -179,22 +165,27 @@ conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); } -void configuration::cleanup() +void +configuration::cleanup () { if (rsa_key) RSA_free (rsa_key); rsa_key = 0; - free (pidfilename); pidfilename = 0; - free (ifname); ifname = 0; + free (pidfilename); pidfilename = 0; + free (ifname); ifname = 0; #if ENABLE_HTTP_PROXY - free (proxy_host); proxy_host = 0; - free (proxy_auth); proxy_auth = 0; + free (proxy_host); proxy_host = 0; + free (proxy_auth); proxy_auth = 0; #endif #if ENABLE_DNS - free (dns_forw_host); dns_forw_host = 0; + free (dns_forw_host); dns_forw_host = 0; #endif + free (script_if_up); script_if_up = 0; + free (script_node_up); script_node_up = 0; + free (script_node_change); script_node_change = 0; + free (script_node_down); script_node_down = 0; } void @@ -209,6 +200,12 @@ init (); } +//static bool +//is_true (const char *name) +//{ + //re +//} + #define parse_bool(target,name,trueval,falseval) do { \ if (!strcmp (val, "yes")) target = trueval; \ else if (!strcmp (val, "no")) target = falseval; \ @@ -247,18 +244,23 @@ if (!val || val[0] == '#') return _("no value given for variable. (ignored)"); - if (!strcmp (var, "on")) + else if (!strcmp (var, "on")) { if (!::thisnode || (val[0] == '!' && strcmp (val + 1, ::thisnode)) || !strcmp (val, ::thisnode)) return parse_line (strtok (NULL, "\n\r")); - else - return 0; + } + + else if (!strcmp (var, "include")) + { + char *fname = conf.config_filename (val); + parse_file (fname); + free (fname); } // truly global - if (!strcmp (var, "loglevel")) + else if (!strcmp (var, "loglevel")) { loglevel l = string_to_loglevel (val); @@ -332,10 +334,14 @@ conf.keepalive = atoi (val); else if (!strcmp (var, "mtu")) conf.mtu = atoi (val); + else if (!strcmp (var, "nfmark")) + conf.nfmark = atoi (val); else if (!strcmp (var, "if-up")) free (conf.script_if_up), conf.script_if_up = strdup (val); else if (!strcmp (var, "node-up")) free (conf.script_node_up), conf.script_node_up = strdup (val); + else if (!strcmp (var, "node-change")) + free (conf.script_node_change), conf.script_node_change = strdup (val); else if (!strcmp (var, "node-down")) free (conf.script_node_down), conf.script_node_down = strdup (val); else if (!strcmp (var, "pid-file")) @@ -376,6 +382,12 @@ conf.dns_max_outstanding = atoi (val); #endif } + else if (!strcmp (var, "dns-case-preserving")) + { +#if ENABLE_DNS + parse_bool (conf.dns_case_preserving, "dns-case-preserving", true, false); +#endif + } else if (!strcmp (var, "http-proxy-host")) { #if ENABLE_HTTP_PROXY @@ -483,12 +495,13 @@ // unknown or misplaced else - return _("unknown configuration directive. (ignored)"); + return _("unknown configuration directive - ignored"); return 0; } -void conf_node::finalise () +void +conf_node::finalise () { if (max_queue < 1) { @@ -503,7 +516,8 @@ } } -void configuration_parser::parse_argv () +void +configuration_parser::parse_argv () { for (int i = 0; i < argc; ++i) { @@ -537,23 +551,12 @@ } } -configuration_parser::configuration_parser (configuration &conf, - bool need_keys, - int argc, - char **argv) -: conf (conf),need_keys (need_keys), argc (argc), argv (argv) +void +configuration_parser::parse_file (const char *fname) { - char *fname; - FILE *f; - - conf.clear (); - - asprintf (&fname, "%s/gvpe.conf", confbase); - f = fopen (fname, "r"); - - if (f) + if (FILE *f = fopen (fname, "r")) { - char line[16384]; + char line [2048]; int lineno = 0; node = &conf.default_node; @@ -576,13 +579,25 @@ slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); exit (EXIT_FAILURE); } +} + +configuration_parser::configuration_parser (configuration &conf, + bool need_keys, + int argc, + char **argv) +: conf (conf),need_keys (need_keys), argc (argc), argv (argv) +{ + char *fname; + + conf.clear (); + asprintf (&fname, "%s/gvpe.conf", confbase); + parse_file (fname); free (fname); fname = conf.config_filename (conf.prikeyfile, "hostkey"); - f = fopen (fname, "r"); - if (f) + if (FILE *f = fopen (fname, "r")) { conf.rsa_key = RSA_new (); @@ -605,6 +620,8 @@ exit (EXIT_FAILURE); } + free (fname); + if (need_keys && ::thisnode && conf.rsa_key && conf.thisnode && conf.thisnode->rsa_key) if (BN_cmp (conf.rsa_key->n, conf.thisnode->rsa_key->n) != 0 @@ -614,13 +631,12 @@ exit (EXIT_FAILURE); } - 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) +char * +configuration::config_filename (const char *name, const char *dflt) { char *fname; @@ -637,6 +653,26 @@ } void +conf_node::print () +{ + printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %02x %s%s%d\n", + id, + id >> 8, id & 0xff, + compress ? 'Y' : 'N', + connectmode == C_ONDEMAND ? "ondemand" + : connectmode == C_NEVER ? "never" + : connectmode == C_ALWAYS ? "always" + : connectmode == C_DISABLED ? "disabled" + : "", + nodename, + protocols, + hostname ? hostname : "", + hostname ? ":" : "", + hostname ? udp_port : 0 + ); +} + +void configuration::print () { printf (_("\nConfiguration\n\n")); @@ -650,8 +686,8 @@ printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); printf ("\n"); - printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", - _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); + printf ("%4s %-17s %s %-8.8s %-10.10s %04s %s\n", + _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Prot"), _("Host:Port")); for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) (*i)->print (); @@ -671,4 +707,3 @@ cleanup (); } -