ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/conf.C
(Generate patch)

Comparing gvpe/src/conf.C (file contents):
Revision 1.7 by pcg, Fri Mar 28 16:21:09 2003 UTC vs.
Revision 1.15 by pcg, Sun Apr 13 00:35:46 2003 UTC

32#include <sys/stat.h> 32#include <sys/stat.h>
33#include <sys/types.h> 33#include <sys/types.h>
34#include <unistd.h> 34#include <unistd.h>
35 35
36#include <netinet/in.h> 36#include <netinet/in.h>
37#include <netinet/ip_icmp.h>
37 38
38#include <openssl/err.h> 39#include <openssl/err.h>
39#include <openssl/pem.h> 40#include <openssl/pem.h>
40#include <openssl/rsa.h> 41#include <openssl/rsa.h>
41#include <openssl/rand.h> 42#include <openssl/rand.h>
53 54
54struct configuration conf; 55struct configuration conf;
55 56
56u8 best_protocol (u8 protset) 57u8 best_protocol (u8 protset)
57{ 58{
58 if (protset & PROT_IPv4) 59 if (protset & PROT_IPv4 ) return PROT_IPv4;
59 return PROT_IPv4; 60 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
61 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
62 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
60 63
61 return PROT_UDPv4; 64 return 0;
62} 65}
63 66
64const char *strprotocol (u8 protocol) 67const char *strprotocol (u8 protocol)
65{ 68{
66 if (protocol & PROT_IPv4 ) return "rawip"; 69 if (protocol & PROT_IPv4 ) return "rawip";
70 if (protocol & PROT_ICMPv4) return "icmp";
67 if (protocol & PROT_UDPv4) return "udp"; 71 if (protocol & PROT_UDPv4 ) return "udp";
72 if (protocol & PROT_TCPv4 ) return "tcp";
68 73
69 return "<unknown>"; 74 return "<unknown>";
70} 75}
71 76
72configuration::configuration () 77void
78conf_node::print ()
73{ 79{
74 init (); 80 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
81 id,
82 id >> 8, id & 0xff,
83 compress ? 'Y' : 'N',
84 connectmode == C_ONDEMAND ? "ondemand" :
85 connectmode == C_NEVER ? "never" :
86 connectmode == C_ALWAYS ? "always" : "",
87 nodename,
88 hostname ? hostname : "",
89 hostname ? ":" : "",
90 hostname ? udp_port : 0
91 );
75} 92}
76 93
77configuration::~configuration () 94conf_node::~conf_node ()
78{ 95{
79 cleanup (); 96 if (rsa_key)
97 RSA_free (rsa_key);
98
99 free (nodename);
100 free (hostname);
80} 101}
81 102
82void configuration::init () 103void configuration::init ()
83{ 104{
84 memset (this, 0, sizeof (*this)); 105 memset (this, 0, sizeof (*this));
85 106
86 rekey = DEFAULT_REKEY; 107 rekey = DEFAULT_REKEY;
87 keepalive = DEFAULT_KEEPALIVE; 108 keepalive = DEFAULT_KEEPALIVE;
88 llevel = L_INFO; 109 llevel = L_INFO;
89 ip_proto = IPPROTO_GRE; 110 ip_proto = IPPROTO_GRE;
111 icmp_type = ICMP_ECHOREPLY;
90 112
91 default_node.udp_port = DEFAULT_UDPPORT; 113 default_node.udp_port = DEFAULT_UDPPORT;
114 default_node.tcp_port = DEFAULT_UDPPORT;
92 default_node.connectmode = conf_node::C_ALWAYS; 115 default_node.connectmode = conf_node::C_ALWAYS;
93 default_node.compress = true; 116 default_node.compress = true;
94 default_node.protocols = PROT_UDPv4; 117 default_node.protocols = PROT_UDPv4;
95} 118}
96 119
97void configuration::cleanup() 120void configuration::cleanup()
98{ 121{
99 if (rsa_key) 122 if (rsa_key)
100 RSA_free (rsa_key); 123 RSA_free (rsa_key);
101 124
102 free (ifname);
103
104 rsa_key = 0; 125 rsa_key = 0;
105 ifname = 0; 126
127 free (ifname); ifname = 0;
128#if ENABLE_HTTP_PROXY
129 free (proxy_host); proxy_host = 0;
130 free (proxy_auth); proxy_auth = 0;
131#endif
106} 132}
107 133
108void 134void
109configuration::clear_config () 135configuration::clear_config ()
110{ 136{
201 else 227 else
202 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); 228 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line);
203 } 229 }
204 else if (!strcmp (var, "ip-proto")) 230 else if (!strcmp (var, "ip-proto"))
205 ip_proto = atoi (val); 231 ip_proto = atoi (val);
232 else if (!strcmp (var, "icmp-type"))
233 icmp_type = atoi (val);
206 234
207 // per config 235 // per config
208 else if (!strcmp (var, "node")) 236 else if (!strcmp (var, "node"))
209 { 237 {
210 default_node.id++; 238 default_node.id++;
269 script_if_up = strdup (val); 297 script_if_up = strdup (val);
270 else if (!strcmp (var, "node-up")) 298 else if (!strcmp (var, "node-up"))
271 script_node_up = strdup (val); 299 script_node_up = strdup (val);
272 else if (!strcmp (var, "node-down")) 300 else if (!strcmp (var, "node-down"))
273 script_node_down = strdup (val); 301 script_node_down = strdup (val);
302#if ENABLE_HTTP_PROXY
303 else if (!strcmp (var, "http-proxy-host"))
304 proxy_host = strdup (val);
305 else if (!strcmp (var, "http-proxy-port"))
306 proxy_port = atoi (val);
307 else if (!strcmp (var, "http-proxy-auth"))
308 proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val));
309#endif
274 310
275 /* node-specific, non-defaultable */ 311 /* node-specific, non-defaultable */
276 else if (node != &default_node && !strcmp (var, "hostname")) 312 else if (node != &default_node && !strcmp (var, "hostname"))
277 { 313 {
278 free (node->hostname); 314 free (node->hostname);
280 } 316 }
281 317
282 /* node-specific, defaultable */ 318 /* node-specific, defaultable */
283 else if (!strcmp (var, "udp-port")) 319 else if (!strcmp (var, "udp-port"))
284 node->udp_port = atoi (val); 320 node->udp_port = atoi (val);
321 else if (!strcmp (var, "tcp-port"))
322 node->tcp_port = atoi (val);
285 else if (!strcmp (var, "router-priority")) 323 else if (!strcmp (var, "router-priority"))
286 node->routerprio = atoi (val); 324 node->routerprio = atoi (val);
287 else if (!strcmp (var, "connect")) 325 else if (!strcmp (var, "connect"))
288 { 326 {
289 if (!strcmp (val, "ondemand")) 327 if (!strcmp (val, "ondemand"))
306 else if (!strcmp (var, "compress")) 344 else if (!strcmp (var, "compress"))
307 { 345 {
308 parse_bool (node->compress, "compress", true, false); 346 parse_bool (node->compress, "compress", true, false);
309 } 347 }
310 // all these bool options really really cost a lot of executable size! 348 // all these bool options really really cost a lot of executable size!
349 else if (!strcmp (var, "enable-tcp"))
350 {
351#if ENABLE_TCP
352 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
353#endif
354 }
355 else if (!strcmp (var, "enable-icmp"))
356 {
357#if ENABLE_ICMP
358 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
359#endif
360 }
311 else if (!strcmp (var, "enable-udp")) 361 else if (!strcmp (var, "enable-udp"))
312 { 362 {
313 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 363 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
314 } 364 }
315 else if (!strcmp (var, "enable-rawip")) 365 else if (!strcmp (var, "enable-rawip"))
317 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 367 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
318 } 368 }
319 369
320 // unknown or misplaced 370 // unknown or misplaced
321 else 371 else
322 {
323 slog (L_WARN, 372 slog (L_WARN,
324 _("unknown or misplaced variable `%s', at '%s' line %d"), 373 _("unknown or misplaced variable `%s', at '%s' line %d"),
325 var, fname, lineno); 374 var, fname, lineno);
326 }
327 } 375 }
328 376
329 fclose (f); 377 fclose (f);
330 } 378 }
331 else 379 else
390 printf (_("MTU: %d\n"), mtu); 438 printf (_("MTU: %d\n"), mtu);
391 printf (_("rekeying interval: %d\n"), rekey); 439 printf (_("rekeying interval: %d\n"), rekey);
392 printf (_("keepalive interval: %d\n"), keepalive); 440 printf (_("keepalive interval: %d\n"), keepalive);
393 printf (_("interface: %s\n"), ifname); 441 printf (_("interface: %s\n"), ifname);
394 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); 442 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>");
395 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); 443 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1);
396 printf ("\n"); 444 printf ("\n");
397 445
398 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", 446 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n",
399 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); 447 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port"));
400 448
402 (*i)->print (); 450 (*i)->print ();
403 451
404 printf ("\n"); 452 printf ("\n");
405} 453}
406 454
407void 455configuration::configuration ()
408conf_node::print ()
409{ 456{
410 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 457 init ();
411 id,
412 id >> 8, id & 0xff,
413 compress ? 'Y' : 'N',
414 connectmode == C_ONDEMAND ? "ondemand" :
415 connectmode == C_NEVER ? "never" :
416 connectmode == C_ALWAYS ? "always" : "",
417 nodename,
418 hostname ? hostname : "",
419 hostname ? ":" : "",
420 hostname ? udp_port : 0
421 );
422} 458}
423 459
460configuration::~configuration ()
461{
462 cleanup ();
463}
464
465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines