--- gvpe/src/conf.C 2003/03/06 18:43:07 1.2 +++ gvpe/src/conf.C 2003/04/02 05:14:59 1.9 @@ -33,6 +33,8 @@ #include #include +#include + #include #include #include @@ -51,6 +53,23 @@ struct configuration conf; +u8 best_protocol (u8 protset) +{ + if (protset & PROT_IPv4 ) return PROT_IPv4; + if (protset & PROT_UDPv4) return PROT_UDPv4; + if (protset & PROT_TCPv4) return PROT_TCPv4; + + return 0; +} + +const char *strprotocol (u8 protocol) +{ + if (protocol & PROT_IPv4 ) return "rawip"; + if (protocol & PROT_UDPv4) return "udp"; + + return ""; +} + configuration::configuration () { init (); @@ -68,10 +87,13 @@ rekey = DEFAULT_REKEY; keepalive = DEFAULT_KEEPALIVE; llevel = L_INFO; + ip_proto = IPPROTO_GRE; - default_node.port = DEFAULT_PORT; + default_node.udp_port = DEFAULT_UDPPORT; + default_node.tcp_port = DEFAULT_UDPPORT; default_node.connectmode = conf_node::C_ALWAYS; default_node.compress = true; + default_node.protocols = PROT_UDPv4; } void configuration::cleanup() @@ -97,6 +119,18 @@ init (); } +#define parse_bool(target,name,trueval,falseval) \ + if (!strcmp (val, "yes")) target = trueval; \ + else if (!strcmp (val, "no")) target = falseval; \ + else if (!strcmp (val, "true")) target = trueval; \ + else if (!strcmp (val, "false")) target = falseval; \ + else if (!strcmp (val, "on")) target = trueval; \ + else if (!strcmp (val, "off")) target = falseval; \ + else \ + slog (L_WARN, \ + _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ + name, var, fname, lineno); + void configuration::read_config (bool need_keys) { char *fname; @@ -169,6 +203,8 @@ else slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); } + else if (!strcmp (var, "ip-proto")) + ip_proto = atoi (val); // per config else if (!strcmp (var, "node")) @@ -221,14 +257,7 @@ prikeyfile = strdup (val); else if (!strcmp (var, "ifpersist")) { - if (!strcmp (val, "yes")) - ifpersist = true; - else if (!strcmp (val, "no")) - ifpersist = false; - else - slog (L_WARN, - _("illegal value for 'ifpersist', only 'yes' or 'no' allowed, at '%s' line %d"), - var, fname, lineno); + parse_bool (ifpersist, "ifpersist", true, false); } else if (!strcmp (var, "ifname")) ifname = strdup (val); @@ -253,8 +282,10 @@ } /* node-specific, defaultable */ - else if (!strcmp (var, "port")) - node->port = atoi (val); + else if (!strcmp (var, "udp-port")) + node->udp_port = atoi (val); + else if (!strcmp (var, "tcp-port")) + node->tcp_port = atoi (val); else if (!strcmp (var, "router-priority")) node->routerprio = atoi (val); else if (!strcmp (var, "connect")) @@ -265,21 +296,33 @@ node->connectmode = conf_node::C_NEVER; else if (!strcmp (val, "always")) node->connectmode = conf_node::C_ALWAYS; + else if (!strcmp (val, "disabled")) + node->connectmode = conf_node::C_DISABLED; else slog (L_WARN, - _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), + _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), var, fname, lineno); } + else if (!strcmp (var, "inherit-tos")) + { + parse_bool (node->inherit_tos, "inherit-tos", true, false); + } else if (!strcmp (var, "compress")) { - if (!strcmp (val, "yes")) - node->compress = true; - else if (!strcmp (val, "no")) - node->compress = false; - else - slog (L_WARN, - _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), - var, fname, lineno); + parse_bool (node->compress, "compress", true, false); + } + // all these bool options really really cost a lot of executable size! + else if (!strcmp (var, "enable-tcp")) + { + u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; + } + else if (!strcmp (var, "enable-udp")) + { + u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; + } + else if (!strcmp (var, "enable-rawip")) + { + u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; } // unknown or misplaced @@ -382,7 +425,7 @@ nodename, hostname ? hostname : "", hostname ? ":" : "", - hostname ? port : 0 + hostname ? udp_port : 0 ); }