… | |
… | |
37 | #include <openssl/pem.h> |
37 | #include <openssl/pem.h> |
38 | #include <openssl/rsa.h> |
38 | #include <openssl/rsa.h> |
39 | #include <openssl/rand.h> |
39 | #include <openssl/rand.h> |
40 | #include <openssl/bn.h> |
40 | #include <openssl/bn.h> |
41 | |
41 | |
42 | #include "gettext.h" |
|
|
43 | |
|
|
44 | #include "conf.h" |
42 | #include "conf.h" |
45 | #include "slog.h" |
43 | #include "slog.h" |
46 | #include "util.h" |
44 | #include "util.h" |
47 | |
45 | |
48 | char *confbase; |
46 | char *confbase; |
… | |
… | |
123 | default_node.protocols = 0; |
121 | default_node.protocols = 0; |
124 | default_node.max_retry = DEFAULT_MAX_RETRY; |
122 | default_node.max_retry = DEFAULT_MAX_RETRY; |
125 | |
123 | |
126 | #if ENABLE_DNS |
124 | #if ENABLE_DNS |
127 | default_node.dns_port = 0; // default is 0 == client |
125 | default_node.dns_port = 0; // default is 0 == client |
|
|
126 | dns_forw_host = strdup ("127.0.0.1"); |
128 | dns_forw_port = 53; |
127 | dns_forw_port = 53; |
129 | #endif |
128 | #endif |
130 | |
129 | |
131 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
130 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
132 | } |
131 | } |
… | |
… | |
159 | |
158 | |
160 | cleanup (); |
159 | cleanup (); |
161 | init (); |
160 | init (); |
162 | } |
161 | } |
163 | |
162 | |
164 | #define parse_bool(target,name,trueval,falseval) \ |
163 | #define parse_bool(target,name,trueval,falseval) do { \ |
165 | if (!strcmp (val, "yes")) target = trueval; \ |
164 | if (!strcmp (val, "yes")) target = trueval; \ |
166 | else if (!strcmp (val, "no")) target = falseval; \ |
165 | else if (!strcmp (val, "no")) target = falseval; \ |
167 | else if (!strcmp (val, "true")) target = trueval; \ |
166 | else if (!strcmp (val, "true")) target = trueval; \ |
168 | else if (!strcmp (val, "false")) target = falseval; \ |
167 | else if (!strcmp (val, "false")) target = falseval; \ |
169 | else if (!strcmp (val, "on")) target = trueval; \ |
168 | else if (!strcmp (val, "on")) target = trueval; \ |
170 | else if (!strcmp (val, "off")) target = falseval; \ |
169 | else if (!strcmp (val, "off")) target = falseval; \ |
171 | else \ |
170 | else \ |
172 | slog (L_WARN, \ |
171 | slog (L_WARN, \ |
173 | _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ |
172 | _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ |
174 | name, var, fname, lineno); |
173 | name, var, fname, lineno); \ |
|
|
174 | } while (0) |
175 | |
175 | |
176 | void configuration::read_config (bool need_keys) |
176 | void configuration::read_config (bool need_keys) |
177 | { |
177 | { |
178 | char *fname; |
178 | char *fname; |
179 | FILE *f; |
179 | FILE *f; |
… | |
… | |
218 | val = strtok (NULL, "\t\n\r ="); |
218 | val = strtok (NULL, "\t\n\r ="); |
219 | |
219 | |
220 | if (!val || val[0] == '#') |
220 | if (!val || val[0] == '#') |
221 | { |
221 | { |
222 | slog (L_WARN, |
222 | slog (L_WARN, |
223 | _("no value for variable `%s', at '%s' line %d"), |
223 | _("no value for variable `%s', at '%s' line %d, skipping."), |
224 | var, fname, lineno); |
224 | var, fname, lineno); |
225 | break; |
225 | continue; |
226 | } |
226 | } |
227 | |
227 | |
228 | if (!strcmp (var, "on")) |
228 | if (!strcmp (var, "on")) |
229 | { |
229 | { |
230 | if (!::thisnode |
230 | if (!::thisnode |
… | |
… | |
302 | thisnode = node; |
302 | thisnode = node; |
303 | } |
303 | } |
304 | else if (!strcmp (var, "private-key")) |
304 | else if (!strcmp (var, "private-key")) |
305 | free (prikeyfile), prikeyfile = strdup (val); |
305 | free (prikeyfile), prikeyfile = strdup (val); |
306 | else if (!strcmp (var, "ifpersist")) |
306 | else if (!strcmp (var, "ifpersist")) |
307 | { |
|
|
308 | parse_bool (ifpersist, "ifpersist", true, false); |
307 | parse_bool (ifpersist, "ifpersist", true, false); |
309 | } |
|
|
310 | else if (!strcmp (var, "ifname")) |
308 | else if (!strcmp (var, "ifname")) |
311 | free (ifname), ifname = strdup (val); |
309 | free (ifname), ifname = strdup (val); |
312 | else if (!strcmp (var, "rekey")) |
310 | else if (!strcmp (var, "rekey")) |
313 | rekey = atoi (val); |
311 | rekey = atoi (val); |
314 | else if (!strcmp (var, "keepalive")) |
312 | else if (!strcmp (var, "keepalive")) |
… | |
… | |
321 | free (script_node_up), script_node_up = strdup (val); |
319 | free (script_node_up), script_node_up = strdup (val); |
322 | else if (!strcmp (var, "node-down")) |
320 | else if (!strcmp (var, "node-down")) |
323 | free (script_node_down), script_node_down = strdup (val); |
321 | free (script_node_down), script_node_down = strdup (val); |
324 | else if (!strcmp (var, "pid-file")) |
322 | else if (!strcmp (var, "pid-file")) |
325 | free (pidfilename), pidfilename = strdup (val); |
323 | free (pidfilename), pidfilename = strdup (val); |
326 | #if ENABLE_DNS |
|
|
327 | else if (!strcmp (var, "dns-forw-host")) |
324 | else if (!strcmp (var, "dns-forw-host")) |
|
|
325 | { |
|
|
326 | #if ENABLE_DNS |
328 | free (dns_forw_host), dns_forw_host = strdup (val); |
327 | free (dns_forw_host), dns_forw_host = strdup (val); |
|
|
328 | #endif |
|
|
329 | } |
329 | else if (!strcmp (var, "dns-forw-port")) |
330 | else if (!strcmp (var, "dns-forw-port")) |
|
|
331 | { |
|
|
332 | #if ENABLE_DNS |
330 | dns_forw_port = atoi (val); |
333 | dns_forw_port = atoi (val); |
331 | #endif |
334 | #endif |
|
|
335 | } |
332 | else if (!strcmp (var, "http-proxy-host")) |
336 | else if (!strcmp (var, "http-proxy-host")) |
333 | { |
337 | { |
334 | #if ENABLE_HTTP_PROXY |
338 | #if ENABLE_HTTP_PROXY |
335 | free (proxy_host), proxy_host = strdup (val); |
339 | free (proxy_host), proxy_host = strdup (val); |
336 | #endif |
340 | #endif |
… | |
… | |
355 | /* node-specific, defaultable */ |
359 | /* node-specific, defaultable */ |
356 | else if (!strcmp (var, "udp-port")) |
360 | else if (!strcmp (var, "udp-port")) |
357 | node->udp_port = atoi (val); |
361 | node->udp_port = atoi (val); |
358 | else if (!strcmp (var, "tcp-port")) |
362 | else if (!strcmp (var, "tcp-port")) |
359 | node->tcp_port = atoi (val); |
363 | node->tcp_port = atoi (val); |
360 | #if ENABLE_DNS |
|
|
361 | else if (!strcmp (var, "dns-hostname")) |
364 | else if (!strcmp (var, "dns-hostname")) |
|
|
365 | { |
|
|
366 | #if ENABLE_DNS |
362 | free (node->dns_hostname), node->dns_hostname = strdup (val); |
367 | free (node->dns_hostname), node->dns_hostname = strdup (val); |
|
|
368 | #endif |
|
|
369 | } |
363 | else if (!strcmp (var, "dns-port")) |
370 | else if (!strcmp (var, "dns-port")) |
|
|
371 | { |
|
|
372 | #if ENABLE_DNS |
364 | node->dns_port = atoi (val); |
373 | node->dns_port = atoi (val); |
365 | #endif |
374 | #endif |
|
|
375 | } |
366 | else if (!strcmp (var, "dns-domain")) |
376 | else if (!strcmp (var, "dns-domain")) |
367 | { |
377 | { |
368 | #if ENABLE_DNS |
378 | #if ENABLE_DNS |
369 | free (node->domain), node->domain = strdup (val); |
379 | free (node->domain), node->domain = strdup (val); |
370 | #endif |
380 | #endif |
… | |
… | |
383 | node->connectmode = conf_node::C_ALWAYS; |
393 | node->connectmode = conf_node::C_ALWAYS; |
384 | else if (!strcmp (val, "disabled")) |
394 | else if (!strcmp (val, "disabled")) |
385 | node->connectmode = conf_node::C_DISABLED; |
395 | node->connectmode = conf_node::C_DISABLED; |
386 | else |
396 | else |
387 | slog (L_WARN, |
397 | slog (L_WARN, |
388 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
398 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d, ignoring."), |
389 | var, fname, lineno); |
399 | var, fname, lineno); |
390 | } |
400 | } |
391 | else if (!strcmp (var, "inherit-tos")) |
401 | else if (!strcmp (var, "inherit-tos")) |
392 | { |
|
|
393 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
402 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
394 | } |
|
|
395 | else if (!strcmp (var, "compress")) |
403 | else if (!strcmp (var, "compress")) |
396 | { |
|
|
397 | parse_bool (node->compress, "compress", true, false); |
404 | parse_bool (node->compress, "compress", true, false); |
398 | } |
|
|
399 | // all these bool options really really cost a lot of executable size! |
405 | // all these bool options really really cost a lot of executable size! |
400 | else if (!strcmp (var, "enable-tcp")) |
406 | else if (!strcmp (var, "enable-tcp")) |
401 | { |
407 | { |
402 | #if ENABLE_TCP |
408 | #if ENABLE_TCP |
403 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
409 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
… | |
… | |
425 | } |
431 | } |
426 | |
432 | |
427 | // unknown or misplaced |
433 | // unknown or misplaced |
428 | else |
434 | else |
429 | slog (L_WARN, |
435 | slog (L_WARN, |
430 | _("unknown or misplaced variable `%s', at '%s' line %d"), |
436 | _("unknown or misplaced variable `%s', at '%s' line %d, skipping."), |
431 | var, fname, lineno); |
437 | var, fname, lineno); |
432 | } |
438 | } |
433 | |
439 | |
434 | fclose (f); |
440 | fclose (f); |
435 | } |
441 | } |