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.23 by pcg, Thu Jan 29 19:30:08 2004 UTC vs.
Revision 1.27 by pcg, Fri Jun 11 15:56:31 2004 UTC

44#include "util.h" 44#include "util.h"
45 45
46char *confbase; 46char *confbase;
47char *thisnode; 47char *thisnode;
48char *identname; 48char *identname;
49char *pidfilename;
50 49
51struct configuration conf; 50struct configuration conf;
52 51
53u8 best_protocol (u8 protset) 52u8 best_protocol (u8 protset)
54{ 53{
55 if (protset & PROT_IPv4 ) return PROT_IPv4; 54 if (protset & PROT_IPv4 ) return PROT_IPv4;
56 if (protset & PROT_ICMPv4) return PROT_ICMPv4; 55 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
57 if (protset & PROT_UDPv4 ) return PROT_UDPv4; 56 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
58 if (protset & PROT_TCPv4 ) return PROT_TCPv4; 57 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
58 if (protset & PROT_DNSv4 ) return PROT_DNSv4;
59 59
60 return 0; 60 return 0;
61} 61}
62 62
63const char *strprotocol (u8 protocol) 63const char *strprotocol (u8 protocol)
64{ 64{
65 if (protocol & PROT_IPv4 ) return "rawip"; 65 if (protocol & PROT_IPv4 ) return "rawip";
66 if (protocol & PROT_ICMPv4) return "icmp"; 66 if (protocol & PROT_ICMPv4) return "icmp";
67 if (protocol & PROT_UDPv4 ) return "udp"; 67 if (protocol & PROT_UDPv4 ) return "udp";
68 if (protocol & PROT_TCPv4 ) return "tcp"; 68 if (protocol & PROT_TCPv4 ) return "tcp";
69 if (protocol & PROT_DNSv4 ) return "dns";
69 70
70 return "<unknown>"; 71 return "<unknown>";
71} 72}
72 73
73void 74void
108#if ENABLE_ICMP 109#if ENABLE_ICMP
109 icmp_type = ICMP_ECHOREPLY; 110 icmp_type = ICMP_ECHOREPLY;
110#endif 111#endif
111 112
112 default_node.udp_port = DEFAULT_UDPPORT; 113 default_node.udp_port = DEFAULT_UDPPORT;
113 default_node.tcp_port = DEFAULT_UDPPORT; 114 default_node.tcp_port = DEFAULT_UDPPORT; // ehrm
114 default_node.connectmode = conf_node::C_ALWAYS; 115 default_node.connectmode = conf_node::C_ALWAYS;
115 default_node.compress = true; 116 default_node.compress = true;
116 default_node.protocols = PROT_UDPv4; 117 default_node.protocols = PROT_UDPv4;
118 default_node.max_retry = DEFAULT_MAX_RETRY;
119
120 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
117} 121}
118 122
119void configuration::cleanup() 123void configuration::cleanup()
120{ 124{
121 if (rsa_key) 125 if (rsa_key)
122 RSA_free (rsa_key); 126 RSA_free (rsa_key);
123 127
124 rsa_key = 0; 128 rsa_key = 0;
125 129
130 free (pidfilename); pidfilename = 0;
126 free (ifname); ifname = 0; 131 free (ifname); ifname = 0;
127#if ENABLE_HTTP_PROXY 132#if ENABLE_HTTP_PROXY
128 free (proxy_host); proxy_host = 0; 133 free (proxy_host); proxy_host = 0;
129 free (proxy_auth); proxy_auth = 0; 134 free (proxy_auth); proxy_auth = 0;
130#endif 135#endif
131} 136}
132 137
133void 138void
134configuration::clear_config () 139configuration::clear_config ()
159 char *fname; 164 char *fname;
160 FILE *f; 165 FILE *f;
161 166
162 clear_config (); 167 clear_config ();
163 168
164 asprintf (&fname, "%s/vped.conf", confbase); 169 asprintf (&fname, "%s/gvpe.conf", confbase);
165 f = fopen (fname, "r"); 170 f = fopen (fname, "r");
166 171
167 if (f) 172 if (f)
168 { 173 {
169 char line[16384]; 174 char line[16384];
281 286
282 if (::thisnode && !strcmp (node->nodename, ::thisnode)) 287 if (::thisnode && !strcmp (node->nodename, ::thisnode))
283 thisnode = node; 288 thisnode = node;
284 } 289 }
285 else if (!strcmp (var, "private-key")) 290 else if (!strcmp (var, "private-key"))
286 prikeyfile = strdup (val); 291 free (prikeyfile), prikeyfile = strdup (val);
287 else if (!strcmp (var, "ifpersist")) 292 else if (!strcmp (var, "ifpersist"))
288 { 293 {
289 parse_bool (ifpersist, "ifpersist", true, false); 294 parse_bool (ifpersist, "ifpersist", true, false);
290 } 295 }
291 else if (!strcmp (var, "ifname")) 296 else if (!strcmp (var, "ifname"))
292 ifname = strdup (val); 297 free (ifname), ifname = strdup (val);
293 else if (!strcmp (var, "rekey")) 298 else if (!strcmp (var, "rekey"))
294 rekey = atoi (val); 299 rekey = atoi (val);
295 else if (!strcmp (var, "keepalive")) 300 else if (!strcmp (var, "keepalive"))
296 keepalive = atoi (val); 301 keepalive = atoi (val);
297 else if (!strcmp (var, "mtu")) 302 else if (!strcmp (var, "mtu"))
298 mtu = atoi (val); 303 mtu = atoi (val);
299 else if (!strcmp (var, "if-up")) 304 else if (!strcmp (var, "if-up"))
300 script_if_up = strdup (val); 305 free (script_if_up), script_if_up = strdup (val);
301 else if (!strcmp (var, "node-up")) 306 else if (!strcmp (var, "node-up"))
302 script_node_up = strdup (val); 307 free (script_node_up), script_node_up = strdup (val);
303 else if (!strcmp (var, "node-down")) 308 else if (!strcmp (var, "node-down"))
304 script_node_down = strdup (val); 309 free (script_node_down), script_node_down = strdup (val);
310 else if (!strcmp (var, "pid-file"))
311 free (pidfilename), pidfilename = strdup (val);
305 else if (!strcmp (var, "http-proxy-host")) 312 else if (!strcmp (var, "http-proxy-host"))
306 { 313 {
307#if ENABLE_HTTP_PROXY 314#if ENABLE_HTTP_PROXY
308 proxy_host = strdup (val); 315 free (proxy_host), proxy_host = strdup (val);
309#endif 316#endif
310 } 317 }
311 else if (!strcmp (var, "http-proxy-port")) 318 else if (!strcmp (var, "http-proxy-port"))
312 { 319 {
313#if ENABLE_HTTP_PROXY 320#if ENABLE_HTTP_PROXY
321#endif 328#endif
322 } 329 }
323 330
324 /* node-specific, non-defaultable */ 331 /* node-specific, non-defaultable */
325 else if (node != &default_node && !strcmp (var, "hostname")) 332 else if (node != &default_node && !strcmp (var, "hostname"))
326 {
327 free (node->hostname);
328 node->hostname = strdup (val); 333 free (node->hostname), node->hostname = strdup (val);
329 }
330 334
331 /* node-specific, defaultable */ 335 /* node-specific, defaultable */
332 else if (!strcmp (var, "udp-port")) 336 else if (!strcmp (var, "udp-port"))
333 node->udp_port = atoi (val); 337 node->udp_port = atoi (val);
334 else if (!strcmp (var, "tcp-port")) 338 else if (!strcmp (var, "tcp-port"))
335 node->tcp_port = atoi (val); 339 node->tcp_port = atoi (val);
340 else if (!strcmp (var, "dns-port"))
341 node->dns_port = atoi (val);
336 else if (!strcmp (var, "router-priority")) 342 else if (!strcmp (var, "router-priority"))
337 node->routerprio = atoi (val); 343 node->routerprio = atoi (val);
344 else if (!strcmp (var, "max-retry"))
345 node->max_retry = atoi (val);
338 else if (!strcmp (var, "connect")) 346 else if (!strcmp (var, "connect"))
339 { 347 {
340 if (!strcmp (val, "ondemand")) 348 if (!strcmp (val, "ondemand"))
341 node->connectmode = conf_node::C_ONDEMAND; 349 node->connectmode = conf_node::C_ONDEMAND;
342 else if (!strcmp (val, "never")) 350 else if (!strcmp (val, "never"))
345 node->connectmode = conf_node::C_ALWAYS; 353 node->connectmode = conf_node::C_ALWAYS;
346 else if (!strcmp (val, "disabled")) 354 else if (!strcmp (val, "disabled"))
347 node->connectmode = conf_node::C_DISABLED; 355 node->connectmode = conf_node::C_DISABLED;
348 else 356 else
349 slog (L_WARN, 357 slog (L_WARN,
350 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), 358 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"),
351 var, fname, lineno); 359 var, fname, lineno);
352 } 360 }
353 else if (!strcmp (var, "inherit-tos")) 361 else if (!strcmp (var, "inherit-tos"))
354 { 362 {
355 parse_bool (node->inherit_tos, "inherit-tos", true, false); 363 parse_bool (node->inherit_tos, "inherit-tos", true, false);
356 } 364 }
369 { 377 {
370#if ENABLE_ICMP 378#if ENABLE_ICMP
371 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; 379 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
372#endif 380#endif
373 } 381 }
382 else if (!strcmp (var, "enable-dns"))
383 {
384#if ENABLE_DNS
385 u8 v; parse_bool (v, "enable-dns" , PROT_DNSv4, 0); node->protocols = (node->protocols & ~PROT_DNSv4) | v;
386#endif
387 }
374 else if (!strcmp (var, "enable-udp")) 388 else if (!strcmp (var, "enable-udp"))
375 { 389 {
376 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 390 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
377 } 391 }
378 else if (!strcmp (var, "enable-rawip")) 392 else if (!strcmp (var, "enable-rawip"))
379 { 393 {;
380 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 394 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
381 } 395 }
382 396
383 // unknown or misplaced 397 // unknown or misplaced
384 else 398 else
474 printf ("\n"); 488 printf ("\n");
475} 489}
476 490
477configuration::configuration () 491configuration::configuration ()
478{ 492{
493 asprintf (&confbase, "%s/gvpe", CONFDIR);
494
479 init (); 495 init ();
480} 496}
481 497
482configuration::~configuration () 498configuration::~configuration ()
483{ 499{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines