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.6 by pcg, Fri Mar 28 16:14:40 2003 UTC vs.
Revision 1.12 by pcg, Mon Apr 7 01:12:56 2003 UTC

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_UDPv4) return PROT_UDPv4;
60 if (protset & PROT_TCPv4) return PROT_TCPv4;
60 61
61configuration::~configuration () 62 return 0;
63}
64
65const char *strprotocol (u8 protocol)
62{ 66{
63 cleanup (); 67 if (protocol & PROT_IPv4 ) return "rawip";
68 if (protocol & PROT_UDPv4) return "udp";
69 if (protocol & PROT_TCPv4) return "tcp";
70
71 return "<unknown>";
72}
73
74void
75conf_node::print ()
76{
77 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
78 id,
79 id >> 8, id & 0xff,
80 compress ? 'Y' : 'N',
81 connectmode == C_ONDEMAND ? "ondemand" :
82 connectmode == C_NEVER ? "never" :
83 connectmode == C_ALWAYS ? "always" : "",
84 nodename,
85 hostname ? hostname : "",
86 hostname ? ":" : "",
87 hostname ? udp_port : 0
88 );
89}
90
91conf_node::~conf_node ()
92{
93 if (rsa_key)
94 RSA_free (rsa_key);
95
96 free (nodename);
97 free (hostname);
64} 98}
65 99
66void configuration::init () 100void configuration::init ()
67{ 101{
68 memset (this, 0, sizeof (*this)); 102 memset (this, 0, sizeof (*this));
71 keepalive = DEFAULT_KEEPALIVE; 105 keepalive = DEFAULT_KEEPALIVE;
72 llevel = L_INFO; 106 llevel = L_INFO;
73 ip_proto = IPPROTO_GRE; 107 ip_proto = IPPROTO_GRE;
74 108
75 default_node.udp_port = DEFAULT_UDPPORT; 109 default_node.udp_port = DEFAULT_UDPPORT;
110 default_node.tcp_port = DEFAULT_UDPPORT;
76 default_node.connectmode = conf_node::C_ALWAYS; 111 default_node.connectmode = conf_node::C_ALWAYS;
77 default_node.compress = true; 112 default_node.compress = true;
78 default_node.protocols = PROT_UDPv4; 113 default_node.protocols = PROT_UDPv4;
79} 114}
80 115
81void configuration::cleanup() 116void configuration::cleanup()
82{ 117{
83 if (rsa_key) 118 if (rsa_key)
84 RSA_free (rsa_key); 119 RSA_free (rsa_key);
85 120
86 free (ifname);
87
88 rsa_key = 0; 121 rsa_key = 0;
89 ifname = 0; 122
123 free (ifname); ifname = 0;
124#if ENABLE_HTTP_PROXY
125 free (proxy_host); proxy_host = 0;
126 free (proxy_auth); proxy_auth = 0;
127#endif
90} 128}
91 129
92void 130void
93configuration::clear_config () 131configuration::clear_config ()
94{ 132{
253 script_if_up = strdup (val); 291 script_if_up = strdup (val);
254 else if (!strcmp (var, "node-up")) 292 else if (!strcmp (var, "node-up"))
255 script_node_up = strdup (val); 293 script_node_up = strdup (val);
256 else if (!strcmp (var, "node-down")) 294 else if (!strcmp (var, "node-down"))
257 script_node_down = strdup (val); 295 script_node_down = strdup (val);
296#if ENABLE_HTTP_PROXY
297 else if (!strcmp (var, "http-proxy-host"))
298 proxy_host = strdup (val);
299 else if (!strcmp (var, "http-proxy-port"))
300 proxy_port = atoi (val);
301 else if (!strcmp (var, "http-proxy-auth"))
302 proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val));
303#endif
258 304
259 /* node-specific, non-defaultable */ 305 /* node-specific, non-defaultable */
260 else if (node != &default_node && !strcmp (var, "hostname")) 306 else if (node != &default_node && !strcmp (var, "hostname"))
261 { 307 {
262 free (node->hostname); 308 free (node->hostname);
264 } 310 }
265 311
266 /* node-specific, defaultable */ 312 /* node-specific, defaultable */
267 else if (!strcmp (var, "udp-port")) 313 else if (!strcmp (var, "udp-port"))
268 node->udp_port = atoi (val); 314 node->udp_port = atoi (val);
315 else if (!strcmp (var, "tcp-port"))
316 node->tcp_port = atoi (val);
269 else if (!strcmp (var, "router-priority")) 317 else if (!strcmp (var, "router-priority"))
270 node->routerprio = atoi (val); 318 node->routerprio = atoi (val);
271 else if (!strcmp (var, "connect")) 319 else if (!strcmp (var, "connect"))
272 { 320 {
273 if (!strcmp (val, "ondemand")) 321 if (!strcmp (val, "ondemand"))
290 else if (!strcmp (var, "compress")) 338 else if (!strcmp (var, "compress"))
291 { 339 {
292 parse_bool (node->compress, "compress", true, false); 340 parse_bool (node->compress, "compress", true, false);
293 } 341 }
294 // all these bool options really really cost a lot of executable size! 342 // all these bool options really really cost a lot of executable size!
343 else if (!strcmp (var, "enable-tcp"))
344 {
345#if ENABLE_TCP
346 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
347#endif
348 }
295 else if (!strcmp (var, "enable-udp")) 349 else if (!strcmp (var, "enable-udp"))
296 { 350 {
297 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 351 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
298 } 352 }
299 else if (!strcmp (var, "enable-rawip")) 353 else if (!strcmp (var, "enable-rawip"))
301 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 355 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
302 } 356 }
303 357
304 // unknown or misplaced 358 // unknown or misplaced
305 else 359 else
306 {
307 slog (L_WARN, 360 slog (L_WARN,
308 _("unknown or misplaced variable `%s', at '%s' line %d"), 361 _("unknown or misplaced variable `%s', at '%s' line %d"),
309 var, fname, lineno); 362 var, fname, lineno);
310 }
311 } 363 }
312 364
313 fclose (f); 365 fclose (f);
314 } 366 }
315 else 367 else
386 (*i)->print (); 438 (*i)->print ();
387 439
388 printf ("\n"); 440 printf ("\n");
389} 441}
390 442
391void 443configuration::configuration ()
392conf_node::print ()
393{ 444{
394 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 445 init ();
395 id,
396 id >> 8, id & 0xff,
397 compress ? 'Y' : 'N',
398 connectmode == C_ONDEMAND ? "ondemand" :
399 connectmode == C_NEVER ? "never" :
400 connectmode == C_ALWAYS ? "always" : "",
401 nodename,
402 hostname ? hostname : "",
403 hostname ? ":" : "",
404 hostname ? udp_port : 0
405 );
406} 446}
407 447
448configuration::~configuration ()
449{
450 cleanup ();
451}
452
453

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines