--- gvpe/src/conf.C 2003/03/01 15:53:03 1.1 +++ gvpe/src/conf.C 2003/10/14 03:22:09 1.16 @@ -33,6 +33,18 @@ #include #include +#include +#include +#ifdef ENABLE_ICMP +# ifdef HAVE_NETINET_IN_SYSTM_H +# include +# endif +# ifdef HAVE_NETINET_IP_H +# include +# endif +# include +#endif + #include #include #include @@ -51,14 +63,50 @@ struct configuration conf; -configuration::configuration () +u8 best_protocol (u8 protset) { - init (); + if (protset & PROT_IPv4 ) return PROT_IPv4; + if (protset & PROT_ICMPv4) return PROT_ICMPv4; + if (protset & PROT_UDPv4 ) return PROT_UDPv4; + if (protset & PROT_TCPv4 ) return PROT_TCPv4; + + return 0; } -configuration::~configuration () +const char *strprotocol (u8 protocol) { - cleanup (); + if (protocol & PROT_IPv4 ) return "rawip"; + if (protocol & PROT_ICMPv4) return "icmp"; + if (protocol & PROT_UDPv4 ) return "udp"; + if (protocol & PROT_TCPv4 ) return "tcp"; + + return ""; +} + +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" : "", + nodename, + hostname ? hostname : "", + hostname ? ":" : "", + hostname ? udp_port : 0 + ); +} + +conf_node::~conf_node () +{ + if (rsa_key) + RSA_free (rsa_key); + + free (nodename); + free (hostname); } void configuration::init () @@ -67,10 +115,17 @@ rekey = DEFAULT_REKEY; keepalive = DEFAULT_KEEPALIVE; + llevel = L_INFO; + ip_proto = IPPROTO_GRE; +#if ENABLE_ICMP + icmp_type = ICMP_ECHOREPLY; +#endif - 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() @@ -78,10 +133,13 @@ if (rsa_key) RSA_free (rsa_key); - free (ifname); - rsa_key = 0; - ifname = 0; + + free (ifname); ifname = 0; +#if ENABLE_HTTP_PROXY + free (proxy_host); proxy_host = 0; + free (proxy_auth); proxy_auth = 0; +#endif } void @@ -96,6 +154,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; @@ -164,10 +234,17 @@ loglevel l = string_to_loglevel (val); if (l != L_NONE) - set_loglevel (l); + llevel = l; 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); +#if ENABLE_ICMP + //TODO: error message + else if (!strcmp (var, "icmp-type")) + icmp_type = atoi (val); +#endif // per config else if (!strcmp (var, "node")) @@ -220,14 +297,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); @@ -243,6 +313,14 @@ script_node_up = strdup (val); else if (!strcmp (var, "node-down")) script_node_down = strdup (val); +#if ENABLE_HTTP_PROXY + else if (!strcmp (var, "http-proxy-host")) + proxy_host = strdup (val); + else if (!strcmp (var, "http-proxy-port")) + proxy_port = atoi (val); + else if (!strcmp (var, "http-proxy-auth")) + proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); +#endif /* node-specific, non-defaultable */ else if (node != &default_node && !strcmp (var, "hostname")) @@ -252,8 +330,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")) @@ -264,30 +344,48 @@ 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")) + { +#if ENABLE_TCP + u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; +#endif + } + else if (!strcmp (var, "enable-icmp")) + { +#if ENABLE_ICMP + u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; +#endif + } + 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 else - { - slog (L_WARN, - _("unknown or misplaced variable `%s', at '%s' line %d"), - var, fname, lineno); - } + slog (L_WARN, + _("unknown or misplaced variable `%s', at '%s' line %d"), + var, fname, lineno); } fclose (f); @@ -356,7 +454,7 @@ printf (_("keepalive interval: %d\n"), keepalive); printf (_("interface: %s\n"), ifname); printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : ""); - printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); + 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", @@ -368,20 +466,14 @@ printf ("\n"); } -void -conf_node::print () +configuration::configuration () { - 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" : "", - nodename, - hostname ? hostname : "", - hostname ? ":" : "", - hostname ? port : 0 - ); + init (); } +configuration::~configuration () +{ + cleanup (); +} + +