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.17 by pcg, Tue Oct 14 15:48:15 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines