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.20 by pcg, Thu Oct 16 21:57:54 2003 UTC

1/* 1/*
2 conf.c -- configuration code 2 conf.c -- configuration code
3 Copyright (C) 1998 Robert van der Meulen 3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com>
4 1998-2002 Ivo Timmermans <ivo@o2w.nl>
5 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
6 2000 Cris van Pelt <tribbel@arise.dhs.org>
7 2003 Marc Lehmann <pcg@goof.com>
8 4
9 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 8 (at your option) any later version.
31#include <netdb.h> 27#include <netdb.h>
32#include <sys/stat.h> 28#include <sys/stat.h>
33#include <sys/types.h> 29#include <sys/types.h>
34#include <unistd.h> 30#include <unistd.h>
35 31
36#include <netinet/in.h> 32#include "netcompat.h"
37 33
38#include <openssl/err.h> 34#include <openssl/err.h>
39#include <openssl/pem.h> 35#include <openssl/pem.h>
40#include <openssl/rsa.h> 36#include <openssl/rsa.h>
41#include <openssl/rand.h> 37#include <openssl/rand.h>
53 49
54struct configuration conf; 50struct configuration conf;
55 51
56u8 best_protocol (u8 protset) 52u8 best_protocol (u8 protset)
57{ 53{
58 if (protset & PROT_IPv4) 54 if (protset & PROT_IPv4 ) return PROT_IPv4;
59 return PROT_IPv4; 55 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
56 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
57 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
60 58
61 return PROT_UDPv4; 59 return 0;
62} 60}
63 61
64const char *strprotocol (u8 protocol) 62const char *strprotocol (u8 protocol)
65{ 63{
66 if (protocol & PROT_IPv4 ) return "rawip"; 64 if (protocol & PROT_IPv4 ) return "rawip";
65 if (protocol & PROT_ICMPv4) return "icmp";
67 if (protocol & PROT_UDPv4) return "udp"; 66 if (protocol & PROT_UDPv4 ) return "udp";
67 if (protocol & PROT_TCPv4 ) return "tcp";
68 68
69 return "<unknown>"; 69 return "<unknown>";
70} 70}
71 71
72configuration::configuration () 72void
73conf_node::print ()
73{ 74{
74 init (); 75 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
76 id,
77 id >> 8, id & 0xff,
78 compress ? 'Y' : 'N',
79 connectmode == C_ONDEMAND ? "ondemand" :
80 connectmode == C_NEVER ? "never" :
81 connectmode == C_ALWAYS ? "always" : "",
82 nodename,
83 hostname ? hostname : "",
84 hostname ? ":" : "",
85 hostname ? udp_port : 0
86 );
75} 87}
76 88
77configuration::~configuration () 89conf_node::~conf_node ()
78{ 90{
79 cleanup (); 91 if (rsa_key)
92 RSA_free (rsa_key);
93
94 free (nodename);
95 free (hostname);
80} 96}
81 97
82void configuration::init () 98void configuration::init ()
83{ 99{
84 memset (this, 0, sizeof (*this)); 100 memset (this, 0, sizeof (*this));
85 101
102 mtu = DEFAULT_MTU;
86 rekey = DEFAULT_REKEY; 103 rekey = DEFAULT_REKEY;
87 keepalive = DEFAULT_KEEPALIVE; 104 keepalive = DEFAULT_KEEPALIVE;
88 llevel = L_INFO; 105 llevel = L_INFO;
89 ip_proto = IPPROTO_GRE; 106 ip_proto = IPPROTO_GRE;
107#if ENABLE_ICMP
108 icmp_type = ICMP_ECHOREPLY;
109#endif
90 110
91 default_node.udp_port = DEFAULT_UDPPORT; 111 default_node.udp_port = DEFAULT_UDPPORT;
112 default_node.tcp_port = DEFAULT_UDPPORT;
92 default_node.connectmode = conf_node::C_ALWAYS; 113 default_node.connectmode = conf_node::C_ALWAYS;
93 default_node.compress = true; 114 default_node.compress = true;
94 default_node.protocols = PROT_UDPv4; 115 default_node.protocols = PROT_UDPv4;
95} 116}
96 117
97void configuration::cleanup() 118void configuration::cleanup()
98{ 119{
99 if (rsa_key) 120 if (rsa_key)
100 RSA_free (rsa_key); 121 RSA_free (rsa_key);
101 122
102 free (ifname);
103
104 rsa_key = 0; 123 rsa_key = 0;
105 ifname = 0; 124
125 free (ifname); ifname = 0;
126#if ENABLE_HTTP_PROXY
127 free (proxy_host); proxy_host = 0;
128 free (proxy_auth); proxy_auth = 0;
129#endif
106} 130}
107 131
108void 132void
109configuration::clear_config () 133configuration::clear_config ()
110{ 134{
201 else 225 else
202 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); 226 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line);
203 } 227 }
204 else if (!strcmp (var, "ip-proto")) 228 else if (!strcmp (var, "ip-proto"))
205 ip_proto = atoi (val); 229 ip_proto = atoi (val);
230 else if (!strcmp (var, "icmp-type"))
231 {
232#if ENABLE_ICMP
233 icmp_type = atoi (val);
234#endif
235 }
206 236
207 // per config 237 // per config
208 else if (!strcmp (var, "node")) 238 else if (!strcmp (var, "node"))
209 { 239 {
210 default_node.id++; 240 default_node.id++;
269 script_if_up = strdup (val); 299 script_if_up = strdup (val);
270 else if (!strcmp (var, "node-up")) 300 else if (!strcmp (var, "node-up"))
271 script_node_up = strdup (val); 301 script_node_up = strdup (val);
272 else if (!strcmp (var, "node-down")) 302 else if (!strcmp (var, "node-down"))
273 script_node_down = strdup (val); 303 script_node_down = strdup (val);
304 else if (!strcmp (var, "http-proxy-host"))
305 {
306#if ENABLE_HTTP_PROXY
307 proxy_host = strdup (val);
308#endif
309 }
310 else if (!strcmp (var, "http-proxy-port"))
311 {
312#if ENABLE_HTTP_PROXY
313 proxy_port = atoi (val);
314#endif
315 }
316 else if (!strcmp (var, "http-proxy-auth"))
317 {
318#if ENABLE_HTTP_PROXY
319 proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val));
320#endif
321 }
274 322
275 /* node-specific, non-defaultable */ 323 /* node-specific, non-defaultable */
276 else if (node != &default_node && !strcmp (var, "hostname")) 324 else if (node != &default_node && !strcmp (var, "hostname"))
277 { 325 {
278 free (node->hostname); 326 free (node->hostname);
280 } 328 }
281 329
282 /* node-specific, defaultable */ 330 /* node-specific, defaultable */
283 else if (!strcmp (var, "udp-port")) 331 else if (!strcmp (var, "udp-port"))
284 node->udp_port = atoi (val); 332 node->udp_port = atoi (val);
333 else if (!strcmp (var, "tcp-port"))
334 node->tcp_port = atoi (val);
285 else if (!strcmp (var, "router-priority")) 335 else if (!strcmp (var, "router-priority"))
286 node->routerprio = atoi (val); 336 node->routerprio = atoi (val);
287 else if (!strcmp (var, "connect")) 337 else if (!strcmp (var, "connect"))
288 { 338 {
289 if (!strcmp (val, "ondemand")) 339 if (!strcmp (val, "ondemand"))
306 else if (!strcmp (var, "compress")) 356 else if (!strcmp (var, "compress"))
307 { 357 {
308 parse_bool (node->compress, "compress", true, false); 358 parse_bool (node->compress, "compress", true, false);
309 } 359 }
310 // all these bool options really really cost a lot of executable size! 360 // all these bool options really really cost a lot of executable size!
361 else if (!strcmp (var, "enable-tcp"))
362 {
363#if ENABLE_TCP
364 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
365#endif
366 }
367 else if (!strcmp (var, "enable-icmp"))
368 {
369#if ENABLE_ICMP
370 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
371#endif
372 }
311 else if (!strcmp (var, "enable-udp")) 373 else if (!strcmp (var, "enable-udp"))
312 { 374 {
313 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 375 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
314 } 376 }
315 else if (!strcmp (var, "enable-rawip")) 377 else if (!strcmp (var, "enable-rawip"))
317 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 379 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
318 } 380 }
319 381
320 // unknown or misplaced 382 // unknown or misplaced
321 else 383 else
322 {
323 slog (L_WARN, 384 slog (L_WARN,
324 _("unknown or misplaced variable `%s', at '%s' line %d"), 385 _("unknown or misplaced variable `%s', at '%s' line %d"),
325 var, fname, lineno); 386 var, fname, lineno);
326 }
327 } 387 }
328 388
329 fclose (f); 389 fclose (f);
330 } 390 }
331 else 391 else
390 printf (_("MTU: %d\n"), mtu); 450 printf (_("MTU: %d\n"), mtu);
391 printf (_("rekeying interval: %d\n"), rekey); 451 printf (_("rekeying interval: %d\n"), rekey);
392 printf (_("keepalive interval: %d\n"), keepalive); 452 printf (_("keepalive interval: %d\n"), keepalive);
393 printf (_("interface: %s\n"), ifname); 453 printf (_("interface: %s\n"), ifname);
394 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); 454 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>");
395 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); 455 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1);
396 printf ("\n"); 456 printf ("\n");
397 457
398 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", 458 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n",
399 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); 459 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port"));
400 460
402 (*i)->print (); 462 (*i)->print ();
403 463
404 printf ("\n"); 464 printf ("\n");
405} 465}
406 466
407void 467configuration::configuration ()
408conf_node::print ()
409{ 468{
410 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 469 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} 470}
423 471
472configuration::~configuration ()
473{
474 cleanup ();
475}
476
477

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines