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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines