1 | /* |
1 | /* |
2 | conf.c -- configuration code |
2 | conf.c -- configuration code |
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de> |
4 | |
4 | |
|
|
5 | This file is part of GVPE. |
|
|
6 | |
5 | This program is free software; you can redistribute it and/or modify |
7 | GVPE is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
9 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
10 | (at your option) any later version. |
9 | |
11 | |
10 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
14 | |
16 | |
15 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
20 | */ |
19 | |
21 | |
20 | #include "config.h" |
22 | #include "config.h" |
21 | |
23 | |
… | |
… | |
93 | if (rsa_key) |
95 | if (rsa_key) |
94 | RSA_free (rsa_key); |
96 | RSA_free (rsa_key); |
95 | |
97 | |
96 | free (nodename); |
98 | free (nodename); |
97 | free (hostname); |
99 | free (hostname); |
|
|
100 | #if ENABLE_DNS |
|
|
101 | free (domain); |
|
|
102 | free (dns_hostname); |
|
|
103 | #endif |
98 | } |
104 | } |
99 | |
105 | |
100 | void configuration::init () |
106 | void configuration::init () |
101 | { |
107 | { |
102 | memset (this, 0, sizeof (*this)); |
108 | memset (this, 0, sizeof (*this)); |
… | |
… | |
112 | |
118 | |
113 | default_node.udp_port = DEFAULT_UDPPORT; |
119 | default_node.udp_port = DEFAULT_UDPPORT; |
114 | default_node.tcp_port = DEFAULT_UDPPORT; // ehrm |
120 | default_node.tcp_port = DEFAULT_UDPPORT; // ehrm |
115 | default_node.connectmode = conf_node::C_ALWAYS; |
121 | default_node.connectmode = conf_node::C_ALWAYS; |
116 | default_node.compress = true; |
122 | default_node.compress = true; |
117 | default_node.protocols = PROT_UDPv4; |
123 | default_node.protocols = 0; |
|
|
124 | default_node.max_retry = DEFAULT_MAX_RETRY; |
|
|
125 | |
|
|
126 | #if ENABLE_DNS |
|
|
127 | default_node.dns_port = 0; // default is 0 == client |
|
|
128 | dns_forw_port = 53; |
|
|
129 | #endif |
|
|
130 | |
|
|
131 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
118 | } |
132 | } |
119 | |
133 | |
120 | void configuration::cleanup() |
134 | void configuration::cleanup() |
121 | { |
135 | { |
122 | if (rsa_key) |
136 | if (rsa_key) |
123 | RSA_free (rsa_key); |
137 | RSA_free (rsa_key); |
124 | |
138 | |
125 | rsa_key = 0; |
139 | rsa_key = 0; |
126 | |
140 | |
127 | free (pidfilename); pidfilename = 0; |
141 | free (pidfilename); pidfilename = 0; |
128 | free (ifname); ifname = 0; |
142 | free (ifname); ifname = 0; |
129 | #if ENABLE_HTTP_PROXY |
143 | #if ENABLE_HTTP_PROXY |
130 | free (proxy_host); proxy_host = 0; |
144 | free (proxy_host); proxy_host = 0; |
131 | free (proxy_auth); proxy_auth = 0; |
145 | free (proxy_auth); proxy_auth = 0; |
|
|
146 | #endif |
|
|
147 | #if ENABLE_DNS |
|
|
148 | free (dns_forw_host); dns_forw_host = 0; |
132 | #endif |
149 | #endif |
133 | } |
150 | } |
134 | |
151 | |
135 | void |
152 | void |
136 | configuration::clear_config () |
153 | configuration::clear_config () |
… | |
… | |
161 | char *fname; |
178 | char *fname; |
162 | FILE *f; |
179 | FILE *f; |
163 | |
180 | |
164 | clear_config (); |
181 | clear_config (); |
165 | |
182 | |
166 | asprintf (&fname, "%s/vped.conf", confbase); |
183 | asprintf (&fname, "%s/gvpe.conf", confbase); |
167 | f = fopen (fname, "r"); |
184 | f = fopen (fname, "r"); |
168 | |
185 | |
169 | if (f) |
186 | if (f) |
170 | { |
187 | { |
171 | char line[16384]; |
188 | char line[16384]; |
… | |
… | |
304 | free (script_node_up), script_node_up = strdup (val); |
321 | free (script_node_up), script_node_up = strdup (val); |
305 | else if (!strcmp (var, "node-down")) |
322 | else if (!strcmp (var, "node-down")) |
306 | free (script_node_down), script_node_down = strdup (val); |
323 | free (script_node_down), script_node_down = strdup (val); |
307 | else if (!strcmp (var, "pid-file")) |
324 | else if (!strcmp (var, "pid-file")) |
308 | free (pidfilename), pidfilename = strdup (val); |
325 | free (pidfilename), pidfilename = strdup (val); |
|
|
326 | #if ENABLE_DNS |
|
|
327 | else if (!strcmp (var, "dns-forw-host")) |
|
|
328 | free (dns_forw_host), dns_forw_host = strdup (val); |
|
|
329 | else if (!strcmp (var, "dns-forw-port")) |
|
|
330 | dns_forw_port = atoi (val); |
|
|
331 | #endif |
309 | else if (!strcmp (var, "http-proxy-host")) |
332 | else if (!strcmp (var, "http-proxy-host")) |
310 | { |
333 | { |
311 | #if ENABLE_HTTP_PROXY |
334 | #if ENABLE_HTTP_PROXY |
312 | free (proxy_host), proxy_host = strdup (val); |
335 | free (proxy_host), proxy_host = strdup (val); |
313 | #endif |
336 | #endif |
… | |
… | |
332 | /* node-specific, defaultable */ |
355 | /* node-specific, defaultable */ |
333 | else if (!strcmp (var, "udp-port")) |
356 | else if (!strcmp (var, "udp-port")) |
334 | node->udp_port = atoi (val); |
357 | node->udp_port = atoi (val); |
335 | else if (!strcmp (var, "tcp-port")) |
358 | else if (!strcmp (var, "tcp-port")) |
336 | node->tcp_port = atoi (val); |
359 | node->tcp_port = atoi (val); |
|
|
360 | #if ENABLE_DNS |
|
|
361 | else if (!strcmp (var, "dns-hostname")) |
|
|
362 | free (node->dns_hostname), node->dns_hostname = strdup (val); |
337 | else if (!strcmp (var, "dns-port")) |
363 | else if (!strcmp (var, "dns-port")) |
338 | node->dns_port = atoi (val); |
364 | node->dns_port = atoi (val); |
|
|
365 | #endif |
|
|
366 | else if (!strcmp (var, "dns-domain")) |
|
|
367 | { |
|
|
368 | #if ENABLE_DNS |
|
|
369 | free (node->domain), node->domain = strdup (val); |
|
|
370 | #endif |
|
|
371 | } |
339 | else if (!strcmp (var, "router-priority")) |
372 | else if (!strcmp (var, "router-priority")) |
340 | node->routerprio = atoi (val); |
373 | node->routerprio = atoi (val); |
|
|
374 | else if (!strcmp (var, "max-retry")) |
|
|
375 | node->max_retry = atoi (val); |
341 | else if (!strcmp (var, "connect")) |
376 | else if (!strcmp (var, "connect")) |
342 | { |
377 | { |
343 | if (!strcmp (val, "ondemand")) |
378 | if (!strcmp (val, "ondemand")) |
344 | node->connectmode = conf_node::C_ONDEMAND; |
379 | node->connectmode = conf_node::C_ONDEMAND; |
345 | else if (!strcmp (val, "never")) |
380 | else if (!strcmp (val, "never")) |
… | |
… | |
348 | node->connectmode = conf_node::C_ALWAYS; |
383 | node->connectmode = conf_node::C_ALWAYS; |
349 | else if (!strcmp (val, "disabled")) |
384 | else if (!strcmp (val, "disabled")) |
350 | node->connectmode = conf_node::C_DISABLED; |
385 | node->connectmode = conf_node::C_DISABLED; |
351 | else |
386 | else |
352 | slog (L_WARN, |
387 | slog (L_WARN, |
353 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
388 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
354 | var, fname, lineno); |
389 | var, fname, lineno); |
355 | } |
390 | } |
356 | else if (!strcmp (var, "inherit-tos")) |
391 | else if (!strcmp (var, "inherit-tos")) |
357 | { |
392 | { |
358 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
393 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
359 | } |
394 | } |
… | |
… | |
383 | else if (!strcmp (var, "enable-udp")) |
418 | else if (!strcmp (var, "enable-udp")) |
384 | { |
419 | { |
385 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
420 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
386 | } |
421 | } |
387 | else if (!strcmp (var, "enable-rawip")) |
422 | else if (!strcmp (var, "enable-rawip")) |
388 | {; |
423 | { |
389 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
424 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
390 | } |
425 | } |
391 | |
426 | |
392 | // unknown or misplaced |
427 | // unknown or misplaced |
393 | else |
428 | else |
… | |
… | |
483 | printf ("\n"); |
518 | printf ("\n"); |
484 | } |
519 | } |
485 | |
520 | |
486 | configuration::configuration () |
521 | configuration::configuration () |
487 | { |
522 | { |
|
|
523 | asprintf (&confbase, "%s/gvpe", CONFDIR); |
|
|
524 | |
488 | init (); |
525 | init (); |
489 | } |
526 | } |
490 | |
527 | |
491 | configuration::~configuration () |
528 | configuration::~configuration () |
492 | { |
529 | { |