… | |
… | |
93 | if (rsa_key) |
93 | if (rsa_key) |
94 | RSA_free (rsa_key); |
94 | RSA_free (rsa_key); |
95 | |
95 | |
96 | free (nodename); |
96 | free (nodename); |
97 | free (hostname); |
97 | free (hostname); |
|
|
98 | #if ENABLE_DNS |
|
|
99 | free (domain); |
|
|
100 | free (dns_hostname); |
|
|
101 | #endif |
98 | } |
102 | } |
99 | |
103 | |
100 | void configuration::init () |
104 | void configuration::init () |
101 | { |
105 | { |
102 | memset (this, 0, sizeof (*this)); |
106 | memset (this, 0, sizeof (*this)); |
… | |
… | |
112 | |
116 | |
113 | default_node.udp_port = DEFAULT_UDPPORT; |
117 | default_node.udp_port = DEFAULT_UDPPORT; |
114 | default_node.tcp_port = DEFAULT_UDPPORT; // ehrm |
118 | default_node.tcp_port = DEFAULT_UDPPORT; // ehrm |
115 | default_node.connectmode = conf_node::C_ALWAYS; |
119 | default_node.connectmode = conf_node::C_ALWAYS; |
116 | default_node.compress = true; |
120 | default_node.compress = true; |
117 | default_node.protocols = PROT_UDPv4; |
121 | default_node.protocols = 0; |
|
|
122 | default_node.max_retry = DEFAULT_MAX_RETRY; |
|
|
123 | |
|
|
124 | #if ENABLE_DNS |
|
|
125 | default_node.dns_port = 53; |
|
|
126 | dns_forw_port = 53; |
|
|
127 | #endif |
|
|
128 | |
|
|
129 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
118 | } |
130 | } |
119 | |
131 | |
120 | void configuration::cleanup() |
132 | void configuration::cleanup() |
121 | { |
133 | { |
122 | if (rsa_key) |
134 | if (rsa_key) |
123 | RSA_free (rsa_key); |
135 | RSA_free (rsa_key); |
124 | |
136 | |
125 | rsa_key = 0; |
137 | rsa_key = 0; |
126 | |
138 | |
127 | free (pidfilename); pidfilename = 0; |
139 | free (pidfilename); pidfilename = 0; |
128 | free (ifname); ifname = 0; |
140 | free (ifname); ifname = 0; |
129 | #if ENABLE_HTTP_PROXY |
141 | #if ENABLE_HTTP_PROXY |
130 | free (proxy_host); proxy_host = 0; |
142 | free (proxy_host); proxy_host = 0; |
131 | free (proxy_auth); proxy_auth = 0; |
143 | free (proxy_auth); proxy_auth = 0; |
|
|
144 | #endif |
|
|
145 | #if ENABLE_DNS |
|
|
146 | free (dns_forw_host); dns_forw_host = 0; |
132 | #endif |
147 | #endif |
133 | } |
148 | } |
134 | |
149 | |
135 | void |
150 | void |
136 | configuration::clear_config () |
151 | configuration::clear_config () |
… | |
… | |
161 | char *fname; |
176 | char *fname; |
162 | FILE *f; |
177 | FILE *f; |
163 | |
178 | |
164 | clear_config (); |
179 | clear_config (); |
165 | |
180 | |
166 | asprintf (&fname, "%s/vped.conf", confbase); |
181 | asprintf (&fname, "%s/gvpe.conf", confbase); |
167 | f = fopen (fname, "r"); |
182 | f = fopen (fname, "r"); |
168 | |
183 | |
169 | if (f) |
184 | if (f) |
170 | { |
185 | { |
171 | char line[16384]; |
186 | char line[16384]; |
… | |
… | |
304 | free (script_node_up), script_node_up = strdup (val); |
319 | free (script_node_up), script_node_up = strdup (val); |
305 | else if (!strcmp (var, "node-down")) |
320 | else if (!strcmp (var, "node-down")) |
306 | free (script_node_down), script_node_down = strdup (val); |
321 | free (script_node_down), script_node_down = strdup (val); |
307 | else if (!strcmp (var, "pid-file")) |
322 | else if (!strcmp (var, "pid-file")) |
308 | free (pidfilename), pidfilename = strdup (val); |
323 | free (pidfilename), pidfilename = strdup (val); |
|
|
324 | #if ENABLE_DNS |
|
|
325 | else if (!strcmp (var, "dns-forw-host")) |
|
|
326 | free (dns_forw_host), dns_forw_host = strdup (val); |
|
|
327 | else if (!strcmp (var, "dns-forw-port")) |
|
|
328 | dns_forw_port = atoi (val); |
|
|
329 | #endif |
309 | else if (!strcmp (var, "http-proxy-host")) |
330 | else if (!strcmp (var, "http-proxy-host")) |
310 | { |
331 | { |
311 | #if ENABLE_HTTP_PROXY |
332 | #if ENABLE_HTTP_PROXY |
312 | free (proxy_host), proxy_host = strdup (val); |
333 | free (proxy_host), proxy_host = strdup (val); |
313 | #endif |
334 | #endif |
… | |
… | |
332 | /* node-specific, defaultable */ |
353 | /* node-specific, defaultable */ |
333 | else if (!strcmp (var, "udp-port")) |
354 | else if (!strcmp (var, "udp-port")) |
334 | node->udp_port = atoi (val); |
355 | node->udp_port = atoi (val); |
335 | else if (!strcmp (var, "tcp-port")) |
356 | else if (!strcmp (var, "tcp-port")) |
336 | node->tcp_port = atoi (val); |
357 | node->tcp_port = atoi (val); |
|
|
358 | #if ENABLE_DNS |
|
|
359 | else if (!strcmp (var, "dns-hostname")) |
|
|
360 | free (node->dns_hostname), node->dns_hostname = strdup (val); |
337 | else if (!strcmp (var, "dns-port")) |
361 | else if (!strcmp (var, "dns-port")) |
338 | node->dns_port = atoi (val); |
362 | node->dns_port = atoi (val); |
|
|
363 | #endif |
|
|
364 | else if (!strcmp (var, "dns-domain")) |
|
|
365 | { |
|
|
366 | #if ENABLE_DNS |
|
|
367 | free (node->domain), node->domain = strdup (val); |
|
|
368 | #endif |
|
|
369 | } |
339 | else if (!strcmp (var, "router-priority")) |
370 | else if (!strcmp (var, "router-priority")) |
340 | node->routerprio = atoi (val); |
371 | node->routerprio = atoi (val); |
|
|
372 | else if (!strcmp (var, "max-retry")) |
|
|
373 | node->max_retry = atoi (val); |
341 | else if (!strcmp (var, "connect")) |
374 | else if (!strcmp (var, "connect")) |
342 | { |
375 | { |
343 | if (!strcmp (val, "ondemand")) |
376 | if (!strcmp (val, "ondemand")) |
344 | node->connectmode = conf_node::C_ONDEMAND; |
377 | node->connectmode = conf_node::C_ONDEMAND; |
345 | else if (!strcmp (val, "never")) |
378 | else if (!strcmp (val, "never")) |
… | |
… | |
348 | node->connectmode = conf_node::C_ALWAYS; |
381 | node->connectmode = conf_node::C_ALWAYS; |
349 | else if (!strcmp (val, "disabled")) |
382 | else if (!strcmp (val, "disabled")) |
350 | node->connectmode = conf_node::C_DISABLED; |
383 | node->connectmode = conf_node::C_DISABLED; |
351 | else |
384 | else |
352 | slog (L_WARN, |
385 | slog (L_WARN, |
353 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
386 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
354 | var, fname, lineno); |
387 | var, fname, lineno); |
355 | } |
388 | } |
356 | else if (!strcmp (var, "inherit-tos")) |
389 | else if (!strcmp (var, "inherit-tos")) |
357 | { |
390 | { |
358 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
391 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
359 | } |
392 | } |
… | |
… | |
383 | else if (!strcmp (var, "enable-udp")) |
416 | else if (!strcmp (var, "enable-udp")) |
384 | { |
417 | { |
385 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
418 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
386 | } |
419 | } |
387 | else if (!strcmp (var, "enable-rawip")) |
420 | else if (!strcmp (var, "enable-rawip")) |
388 | {; |
421 | { |
389 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
422 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
390 | } |
423 | } |
391 | |
424 | |
392 | // unknown or misplaced |
425 | // unknown or misplaced |
393 | else |
426 | else |
… | |
… | |
483 | printf ("\n"); |
516 | printf ("\n"); |
484 | } |
517 | } |
485 | |
518 | |
486 | configuration::configuration () |
519 | configuration::configuration () |
487 | { |
520 | { |
|
|
521 | asprintf (&confbase, "%s/gvpe", CONFDIR); |
|
|
522 | |
488 | init (); |
523 | init (); |
489 | } |
524 | } |
490 | |
525 | |
491 | configuration::~configuration () |
526 | configuration::~configuration () |
492 | { |
527 | { |