… | |
… | |
44 | #include "util.h" |
44 | #include "util.h" |
45 | |
45 | |
46 | char *confbase; |
46 | char *confbase; |
47 | char *thisnode; |
47 | char *thisnode; |
48 | char *identname; |
48 | char *identname; |
49 | char *pidfilename; |
|
|
50 | |
49 | |
51 | struct configuration conf; |
50 | struct configuration conf; |
52 | |
51 | |
53 | u8 best_protocol (u8 protset) |
52 | u8 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 | |
63 | const char *strprotocol (u8 protocol) |
63 | const 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 | |
73 | void |
74 | void |
… | |
… | |
92 | if (rsa_key) |
93 | if (rsa_key) |
93 | RSA_free (rsa_key); |
94 | RSA_free (rsa_key); |
94 | |
95 | |
95 | free (nodename); |
96 | free (nodename); |
96 | free (hostname); |
97 | free (hostname); |
|
|
98 | free (domain); |
97 | } |
99 | } |
98 | |
100 | |
99 | void configuration::init () |
101 | void configuration::init () |
100 | { |
102 | { |
101 | memset (this, 0, sizeof (*this)); |
103 | memset (this, 0, sizeof (*this)); |
… | |
… | |
108 | #if ENABLE_ICMP |
110 | #if ENABLE_ICMP |
109 | icmp_type = ICMP_ECHOREPLY; |
111 | icmp_type = ICMP_ECHOREPLY; |
110 | #endif |
112 | #endif |
111 | |
113 | |
112 | default_node.udp_port = DEFAULT_UDPPORT; |
114 | default_node.udp_port = DEFAULT_UDPPORT; |
113 | default_node.tcp_port = DEFAULT_UDPPORT; |
115 | default_node.tcp_port = DEFAULT_UDPPORT; // ehrm |
114 | default_node.connectmode = conf_node::C_ALWAYS; |
116 | default_node.connectmode = conf_node::C_ALWAYS; |
115 | default_node.compress = true; |
117 | default_node.compress = true; |
116 | default_node.protocols = PROT_UDPv4; |
118 | default_node.protocols = 0; |
|
|
119 | default_node.max_retry = DEFAULT_MAX_RETRY; |
|
|
120 | |
|
|
121 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
117 | } |
122 | } |
118 | |
123 | |
119 | void configuration::cleanup() |
124 | void configuration::cleanup() |
120 | { |
125 | { |
121 | if (rsa_key) |
126 | if (rsa_key) |
122 | RSA_free (rsa_key); |
127 | RSA_free (rsa_key); |
123 | |
128 | |
124 | rsa_key = 0; |
129 | rsa_key = 0; |
125 | |
130 | |
|
|
131 | free (pidfilename); pidfilename = 0; |
126 | free (ifname); ifname = 0; |
132 | free (ifname); ifname = 0; |
127 | #if ENABLE_HTTP_PROXY |
133 | #if ENABLE_HTTP_PROXY |
128 | free (proxy_host); proxy_host = 0; |
134 | free (proxy_host); proxy_host = 0; |
129 | free (proxy_auth); proxy_auth = 0; |
135 | free (proxy_auth); proxy_auth = 0; |
|
|
136 | #endif |
|
|
137 | #if ENABLE_DNS |
|
|
138 | free (dns_forw_host); dns_forw_host = 0; |
130 | #endif |
139 | #endif |
131 | } |
140 | } |
132 | |
141 | |
133 | void |
142 | void |
134 | configuration::clear_config () |
143 | configuration::clear_config () |
… | |
… | |
159 | char *fname; |
168 | char *fname; |
160 | FILE *f; |
169 | FILE *f; |
161 | |
170 | |
162 | clear_config (); |
171 | clear_config (); |
163 | |
172 | |
164 | asprintf (&fname, "%s/vped.conf", confbase); |
173 | asprintf (&fname, "%s/gvpe.conf", confbase); |
165 | f = fopen (fname, "r"); |
174 | f = fopen (fname, "r"); |
166 | |
175 | |
167 | if (f) |
176 | if (f) |
168 | { |
177 | { |
169 | char line[16384]; |
178 | char line[16384]; |
… | |
… | |
281 | |
290 | |
282 | if (::thisnode && !strcmp (node->nodename, ::thisnode)) |
291 | if (::thisnode && !strcmp (node->nodename, ::thisnode)) |
283 | thisnode = node; |
292 | thisnode = node; |
284 | } |
293 | } |
285 | else if (!strcmp (var, "private-key")) |
294 | else if (!strcmp (var, "private-key")) |
286 | prikeyfile = strdup (val); |
295 | free (prikeyfile), prikeyfile = strdup (val); |
287 | else if (!strcmp (var, "ifpersist")) |
296 | else if (!strcmp (var, "ifpersist")) |
288 | { |
297 | { |
289 | parse_bool (ifpersist, "ifpersist", true, false); |
298 | parse_bool (ifpersist, "ifpersist", true, false); |
290 | } |
299 | } |
291 | else if (!strcmp (var, "ifname")) |
300 | else if (!strcmp (var, "ifname")) |
292 | ifname = strdup (val); |
301 | free (ifname), ifname = strdup (val); |
293 | else if (!strcmp (var, "rekey")) |
302 | else if (!strcmp (var, "rekey")) |
294 | rekey = atoi (val); |
303 | rekey = atoi (val); |
295 | else if (!strcmp (var, "keepalive")) |
304 | else if (!strcmp (var, "keepalive")) |
296 | keepalive = atoi (val); |
305 | keepalive = atoi (val); |
297 | else if (!strcmp (var, "mtu")) |
306 | else if (!strcmp (var, "mtu")) |
298 | mtu = atoi (val); |
307 | mtu = atoi (val); |
299 | else if (!strcmp (var, "if-up")) |
308 | else if (!strcmp (var, "if-up")) |
300 | script_if_up = strdup (val); |
309 | free (script_if_up), script_if_up = strdup (val); |
301 | else if (!strcmp (var, "node-up")) |
310 | else if (!strcmp (var, "node-up")) |
302 | script_node_up = strdup (val); |
311 | free (script_node_up), script_node_up = strdup (val); |
303 | else if (!strcmp (var, "node-down")) |
312 | else if (!strcmp (var, "node-down")) |
304 | script_node_down = strdup (val); |
313 | free (script_node_down), script_node_down = strdup (val); |
|
|
314 | else if (!strcmp (var, "pid-file")) |
|
|
315 | free (pidfilename), pidfilename = strdup (val); |
|
|
316 | else if (!strcmp (var, "dns-forw-host")) |
|
|
317 | { |
|
|
318 | #if ENABLE_DNS |
|
|
319 | free (dns_forw_host), dns_forw_host = strdup (val); |
|
|
320 | #endif |
|
|
321 | } |
|
|
322 | else if (!strcmp (var, "dns-forw-port")) |
|
|
323 | { |
|
|
324 | #if ENABLE_DNS |
|
|
325 | dns_forw_port = atoi (val); |
|
|
326 | #endif |
|
|
327 | } |
305 | else if (!strcmp (var, "http-proxy-host")) |
328 | else if (!strcmp (var, "http-proxy-host")) |
306 | { |
329 | { |
307 | #if ENABLE_HTTP_PROXY |
330 | #if ENABLE_HTTP_PROXY |
308 | proxy_host = strdup (val); |
331 | free (proxy_host), proxy_host = strdup (val); |
309 | #endif |
332 | #endif |
310 | } |
333 | } |
311 | else if (!strcmp (var, "http-proxy-port")) |
334 | else if (!strcmp (var, "http-proxy-port")) |
312 | { |
335 | { |
313 | #if ENABLE_HTTP_PROXY |
336 | #if ENABLE_HTTP_PROXY |
… | |
… | |
321 | #endif |
344 | #endif |
322 | } |
345 | } |
323 | |
346 | |
324 | /* node-specific, non-defaultable */ |
347 | /* node-specific, non-defaultable */ |
325 | else if (node != &default_node && !strcmp (var, "hostname")) |
348 | else if (node != &default_node && !strcmp (var, "hostname")) |
326 | { |
|
|
327 | free (node->hostname); |
|
|
328 | node->hostname = strdup (val); |
349 | free (node->hostname), node->hostname = strdup (val); |
329 | } |
|
|
330 | |
350 | |
331 | /* node-specific, defaultable */ |
351 | /* node-specific, defaultable */ |
332 | else if (!strcmp (var, "udp-port")) |
352 | else if (!strcmp (var, "udp-port")) |
333 | node->udp_port = atoi (val); |
353 | node->udp_port = atoi (val); |
334 | else if (!strcmp (var, "tcp-port")) |
354 | else if (!strcmp (var, "tcp-port")) |
335 | node->tcp_port = atoi (val); |
355 | node->tcp_port = atoi (val); |
|
|
356 | else if (!strcmp (var, "dns-port")) |
|
|
357 | { |
|
|
358 | #if ENABLE_DNS |
|
|
359 | node->dns_port = atoi (val); |
|
|
360 | #endif |
|
|
361 | } |
|
|
362 | else if (!strcmp (var, "dns-domain")) |
|
|
363 | { |
|
|
364 | #if ENABLE_DNS |
|
|
365 | free (node->domain), node->domain = strdup (val); |
|
|
366 | #endif |
|
|
367 | } |
336 | else if (!strcmp (var, "router-priority")) |
368 | else if (!strcmp (var, "router-priority")) |
337 | node->routerprio = atoi (val); |
369 | node->routerprio = atoi (val); |
|
|
370 | else if (!strcmp (var, "max-retry")) |
|
|
371 | node->max_retry = atoi (val); |
338 | else if (!strcmp (var, "connect")) |
372 | else if (!strcmp (var, "connect")) |
339 | { |
373 | { |
340 | if (!strcmp (val, "ondemand")) |
374 | if (!strcmp (val, "ondemand")) |
341 | node->connectmode = conf_node::C_ONDEMAND; |
375 | node->connectmode = conf_node::C_ONDEMAND; |
342 | else if (!strcmp (val, "never")) |
376 | else if (!strcmp (val, "never")) |
… | |
… | |
345 | node->connectmode = conf_node::C_ALWAYS; |
379 | node->connectmode = conf_node::C_ALWAYS; |
346 | else if (!strcmp (val, "disabled")) |
380 | else if (!strcmp (val, "disabled")) |
347 | node->connectmode = conf_node::C_DISABLED; |
381 | node->connectmode = conf_node::C_DISABLED; |
348 | else |
382 | else |
349 | slog (L_WARN, |
383 | slog (L_WARN, |
350 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
384 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
351 | var, fname, lineno); |
385 | var, fname, lineno); |
352 | } |
386 | } |
353 | else if (!strcmp (var, "inherit-tos")) |
387 | else if (!strcmp (var, "inherit-tos")) |
354 | { |
388 | { |
355 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
389 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
356 | } |
390 | } |
… | |
… | |
367 | } |
401 | } |
368 | else if (!strcmp (var, "enable-icmp")) |
402 | else if (!strcmp (var, "enable-icmp")) |
369 | { |
403 | { |
370 | #if ENABLE_ICMP |
404 | #if ENABLE_ICMP |
371 | u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; |
405 | u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; |
|
|
406 | #endif |
|
|
407 | } |
|
|
408 | else if (!strcmp (var, "enable-dns")) |
|
|
409 | { |
|
|
410 | #if ENABLE_DNS |
|
|
411 | u8 v; parse_bool (v, "enable-dns" , PROT_DNSv4, 0); node->protocols = (node->protocols & ~PROT_DNSv4) | v; |
372 | #endif |
412 | #endif |
373 | } |
413 | } |
374 | else if (!strcmp (var, "enable-udp")) |
414 | else if (!strcmp (var, "enable-udp")) |
375 | { |
415 | { |
376 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
416 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
… | |
… | |
474 | printf ("\n"); |
514 | printf ("\n"); |
475 | } |
515 | } |
476 | |
516 | |
477 | configuration::configuration () |
517 | configuration::configuration () |
478 | { |
518 | { |
|
|
519 | asprintf (&confbase, "%s/gvpe", CONFDIR); |
|
|
520 | |
479 | init (); |
521 | init (); |
480 | } |
522 | } |
481 | |
523 | |
482 | configuration::~configuration () |
524 | configuration::~configuration () |
483 | { |
525 | { |