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.5 by pcg, Fri Mar 28 04:05:10 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>
51char *identname; 52char *identname;
52char *pidfilename; 53char *pidfilename;
53 54
54struct configuration conf; 55struct configuration conf;
55 56
56configuration::configuration () 57u8 best_protocol (u8 protset)
57{ 58{
58 init (); 59 if (protset & PROT_IPv4 ) return PROT_IPv4;
59} 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
61configuration::~configuration () 64 return 0;
65}
66
67const char *strprotocol (u8 protocol)
62{ 68{
63 cleanup (); 69 if (protocol & PROT_IPv4 ) return "rawip";
70 if (protocol & PROT_ICMPv4) return "icmp";
71 if (protocol & PROT_UDPv4 ) return "udp";
72 if (protocol & PROT_TCPv4 ) return "tcp";
73
74 return "<unknown>";
75}
76
77void
78conf_node::print ()
79{
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 );
92}
93
94conf_node::~conf_node ()
95{
96 if (rsa_key)
97 RSA_free (rsa_key);
98
99 free (nodename);
100 free (hostname);
64} 101}
65 102
66void configuration::init () 103void configuration::init ()
67{ 104{
68 memset (this, 0, sizeof (*this)); 105 memset (this, 0, sizeof (*this));
69 106
70 rekey = DEFAULT_REKEY; 107 rekey = DEFAULT_REKEY;
71 keepalive = DEFAULT_KEEPALIVE; 108 keepalive = DEFAULT_KEEPALIVE;
72 llevel = L_INFO; 109 llevel = L_INFO;
73 ip_proto = IPPROTO_GRE; 110 ip_proto = IPPROTO_GRE;
111 icmp_type = ICMP_ECHOREPLY;
74 112
75 default_node.udp_port = DEFAULT_UDPPORT; 113 default_node.udp_port = DEFAULT_UDPPORT;
114 default_node.tcp_port = DEFAULT_UDPPORT;
76 default_node.connectmode = conf_node::C_ALWAYS; 115 default_node.connectmode = conf_node::C_ALWAYS;
77 default_node.compress = true; 116 default_node.compress = true;
78 default_node.can_send = PROT_UDPv4; 117 default_node.protocols = PROT_UDPv4;
79 default_node.can_recv = PROT_IPv4;
80} 118}
81 119
82void configuration::cleanup() 120void configuration::cleanup()
83{ 121{
84 if (rsa_key) 122 if (rsa_key)
85 RSA_free (rsa_key); 123 RSA_free (rsa_key);
86 124
87 free (ifname);
88
89 rsa_key = 0; 125 rsa_key = 0;
90 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
91} 132}
92 133
93void 134void
94configuration::clear_config () 135configuration::clear_config ()
95{ 136{
186 else 227 else
187 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);
188 } 229 }
189 else if (!strcmp (var, "ip-proto")) 230 else if (!strcmp (var, "ip-proto"))
190 ip_proto = atoi (val); 231 ip_proto = atoi (val);
232 else if (!strcmp (var, "icmp-type"))
233 icmp_type = atoi (val);
191 234
192 // per config 235 // per config
193 else if (!strcmp (var, "node")) 236 else if (!strcmp (var, "node"))
194 { 237 {
195 default_node.id++; 238 default_node.id++;
254 script_if_up = strdup (val); 297 script_if_up = strdup (val);
255 else if (!strcmp (var, "node-up")) 298 else if (!strcmp (var, "node-up"))
256 script_node_up = strdup (val); 299 script_node_up = strdup (val);
257 else if (!strcmp (var, "node-down")) 300 else if (!strcmp (var, "node-down"))
258 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
259 310
260 /* node-specific, non-defaultable */ 311 /* node-specific, non-defaultable */
261 else if (node != &default_node && !strcmp (var, "hostname")) 312 else if (node != &default_node && !strcmp (var, "hostname"))
262 { 313 {
263 free (node->hostname); 314 free (node->hostname);
265 } 316 }
266 317
267 /* node-specific, defaultable */ 318 /* node-specific, defaultable */
268 else if (!strcmp (var, "udp-port")) 319 else if (!strcmp (var, "udp-port"))
269 node->udp_port = atoi (val); 320 node->udp_port = atoi (val);
321 else if (!strcmp (var, "tcp-port"))
322 node->tcp_port = atoi (val);
270 else if (!strcmp (var, "router-priority")) 323 else if (!strcmp (var, "router-priority"))
271 node->routerprio = atoi (val); 324 node->routerprio = atoi (val);
272 else if (!strcmp (var, "connect")) 325 else if (!strcmp (var, "connect"))
273 { 326 {
274 if (!strcmp (val, "ondemand")) 327 if (!strcmp (val, "ondemand"))
291 else if (!strcmp (var, "compress")) 344 else if (!strcmp (var, "compress"))
292 { 345 {
293 parse_bool (node->compress, "compress", true, false); 346 parse_bool (node->compress, "compress", true, false);
294 } 347 }
295 // 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!
296 else if (!strcmp (var, "can-send-udp")) 349 else if (!strcmp (var, "enable-tcp"))
297 {
298 u8 v; parse_bool (v, "can-send-udp", PROT_UDPv4, 0); node->can_send = (node->can_send & ~PROT_UDPv4) | v;
299 } 350 {
300 else if (!strcmp (var, "can-recv-udp")) 351#if ENABLE_TCP
352 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
353#endif
301 { 354 }
302 u8 v; parse_bool (v, "can-recv-udp", PROT_UDPv4, 0); node->can_recv = (node->can_recv & ~PROT_UDPv4) | v; 355 else if (!strcmp (var, "enable-icmp"))
303 } 356 {
304 else if (!strcmp (var, "can-send-rawip")) 357#if ENABLE_ICMP
358 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
359#endif
305 { 360 }
306 u8 v; parse_bool (v, "can-send-rawip", PROT_IPv4, 0); node->can_send = (node->can_send & ~PROT_IPv4) | v; 361 else if (!strcmp (var, "enable-udp"))
307 } 362 {
308 else if (!strcmp (var, "can-recv-rawip")) 363 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
309 { 364 }
365 else if (!strcmp (var, "enable-rawip"))
366 {
310 u8 v; parse_bool (v, "can-recv-rawip", PROT_IPv4, 0); node->can_recv = (node->can_recv & ~PROT_IPv4) | v; 367 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
311 } 368 }
312 369
313 // unknown or misplaced 370 // unknown or misplaced
314 else 371 else
315 {
316 slog (L_WARN, 372 slog (L_WARN,
317 _("unknown or misplaced variable `%s', at '%s' line %d"), 373 _("unknown or misplaced variable `%s', at '%s' line %d"),
318 var, fname, lineno); 374 var, fname, lineno);
319 }
320 } 375 }
321 376
322 fclose (f); 377 fclose (f);
323 } 378 }
324 else 379 else
383 printf (_("MTU: %d\n"), mtu); 438 printf (_("MTU: %d\n"), mtu);
384 printf (_("rekeying interval: %d\n"), rekey); 439 printf (_("rekeying interval: %d\n"), rekey);
385 printf (_("keepalive interval: %d\n"), keepalive); 440 printf (_("keepalive interval: %d\n"), keepalive);
386 printf (_("interface: %s\n"), ifname); 441 printf (_("interface: %s\n"), ifname);
387 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); 442 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>");
388 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);
389 printf ("\n"); 444 printf ("\n");
390 445
391 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", 446 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n",
392 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); 447 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port"));
393 448
395 (*i)->print (); 450 (*i)->print ();
396 451
397 printf ("\n"); 452 printf ("\n");
398} 453}
399 454
400void 455configuration::configuration ()
401conf_node::print ()
402{ 456{
403 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 457 init ();
404 id,
405 id >> 8, id & 0xff,
406 compress ? 'Y' : 'N',
407 connectmode == C_ONDEMAND ? "ondemand" :
408 connectmode == C_NEVER ? "never" :
409 connectmode == C_ALWAYS ? "always" : "",
410 nodename,
411 hostname ? hostname : "",
412 hostname ? ":" : "",
413 hostname ? udp_port : 0
414 );
415} 458}
416 459
460configuration::~configuration ()
461{
462 cleanup ();
463}
464
465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines