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.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.can_send = PROT_UDPv4; 113 default_node.protocols = PROT_UDPv4;
79 default_node.can_recv = PROT_IPv4;
80} 114}
81 115
82void configuration::cleanup() 116void configuration::cleanup()
83{ 117{
84 if (rsa_key) 118 if (rsa_key)
85 RSA_free (rsa_key); 119 RSA_free (rsa_key);
86 120
87 free (ifname);
88
89 rsa_key = 0; 121 rsa_key = 0;
90 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
91} 128}
92 129
93void 130void
94configuration::clear_config () 131configuration::clear_config ()
95{ 132{
254 script_if_up = strdup (val); 291 script_if_up = strdup (val);
255 else if (!strcmp (var, "node-up")) 292 else if (!strcmp (var, "node-up"))
256 script_node_up = strdup (val); 293 script_node_up = strdup (val);
257 else if (!strcmp (var, "node-down")) 294 else if (!strcmp (var, "node-down"))
258 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
259 304
260 /* node-specific, non-defaultable */ 305 /* node-specific, non-defaultable */
261 else if (node != &default_node && !strcmp (var, "hostname")) 306 else if (node != &default_node && !strcmp (var, "hostname"))
262 { 307 {
263 free (node->hostname); 308 free (node->hostname);
265 } 310 }
266 311
267 /* node-specific, defaultable */ 312 /* node-specific, defaultable */
268 else if (!strcmp (var, "udp-port")) 313 else if (!strcmp (var, "udp-port"))
269 node->udp_port = atoi (val); 314 node->udp_port = atoi (val);
315 else if (!strcmp (var, "tcp-port"))
316 node->tcp_port = atoi (val);
270 else if (!strcmp (var, "router-priority")) 317 else if (!strcmp (var, "router-priority"))
271 node->routerprio = atoi (val); 318 node->routerprio = atoi (val);
272 else if (!strcmp (var, "connect")) 319 else if (!strcmp (var, "connect"))
273 { 320 {
274 if (!strcmp (val, "ondemand")) 321 if (!strcmp (val, "ondemand"))
291 else if (!strcmp (var, "compress")) 338 else if (!strcmp (var, "compress"))
292 { 339 {
293 parse_bool (node->compress, "compress", true, false); 340 parse_bool (node->compress, "compress", true, false);
294 } 341 }
295 // 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!
296 else if (!strcmp (var, "can-send-udp")) 343 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 } 344 {
300 else if (!strcmp (var, "can-recv-udp")) 345#if ENABLE_TCP
346 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
347#endif
301 { 348 }
302 u8 v; parse_bool (v, "can-recv-udp", PROT_UDPv4, 0); node->can_recv = (node->can_recv & ~PROT_UDPv4) | v; 349 else if (!strcmp (var, "enable-udp"))
303 } 350 {
304 else if (!strcmp (var, "can-send-rawip")) 351 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
305 { 352 }
306 u8 v; parse_bool (v, "can-send-rawip", PROT_IPv4, 0); node->can_send = (node->can_send & ~PROT_IPv4) | v; 353 else if (!strcmp (var, "enable-rawip"))
307 } 354 {
308 else if (!strcmp (var, "can-recv-rawip"))
309 {
310 u8 v; parse_bool (v, "can-recv-rawip", PROT_IPv4, 0); node->can_recv = (node->can_recv & ~PROT_IPv4) | v; 355 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
311 } 356 }
312 357
313 // unknown or misplaced 358 // unknown or misplaced
314 else 359 else
315 {
316 slog (L_WARN, 360 slog (L_WARN,
317 _("unknown or misplaced variable `%s', at '%s' line %d"), 361 _("unknown or misplaced variable `%s', at '%s' line %d"),
318 var, fname, lineno); 362 var, fname, lineno);
319 }
320 } 363 }
321 364
322 fclose (f); 365 fclose (f);
323 } 366 }
324 else 367 else
395 (*i)->print (); 438 (*i)->print ();
396 439
397 printf ("\n"); 440 printf ("\n");
398} 441}
399 442
400void 443configuration::configuration ()
401conf_node::print ()
402{ 444{
403 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 445 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} 446}
416 447
448configuration::~configuration ()
449{
450 cleanup ();
451}
452
453

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines