… | |
… | |
53 | |
53 | |
54 | struct configuration conf; |
54 | struct configuration conf; |
55 | |
55 | |
56 | u8 best_protocol (u8 protset) |
56 | u8 best_protocol (u8 protset) |
57 | { |
57 | { |
58 | if (protset & PROT_IPv4) |
58 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
59 | return PROT_IPv4; |
59 | if (protset & PROT_UDPv4) return PROT_UDPv4; |
|
|
60 | if (protset & PROT_TCPv4) return PROT_TCPv4; |
60 | |
61 | |
61 | return PROT_UDPv4; |
62 | return 0; |
62 | } |
63 | } |
63 | |
64 | |
64 | const char *strprotocol (u8 protocol) |
65 | const char *strprotocol (u8 protocol) |
65 | { |
66 | { |
66 | if (protocol & PROT_IPv4 ) return "rawip"; |
67 | if (protocol & PROT_IPv4 ) return "rawip"; |
67 | if (protocol & PROT_UDPv4) return "udp"; |
68 | if (protocol & PROT_UDPv4) return "udp"; |
|
|
69 | if (protocol & PROT_TCPv4) return "tcp"; |
68 | |
70 | |
69 | return "<unknown>"; |
71 | return "<unknown>"; |
70 | } |
72 | } |
71 | |
73 | |
72 | configuration::configuration () |
74 | void |
|
|
75 | conf_node::print () |
73 | { |
76 | { |
74 | init (); |
77 | printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", |
|
|
78 | id, |
|
|
79 | id >> 8, id & 0xff, |
|
|
80 | compress ? 'Y' : 'N', |
|
|
81 | connectmode == C_ONDEMAND ? "ondemand" : |
|
|
82 | connectmode == C_NEVER ? "never" : |
|
|
83 | connectmode == C_ALWAYS ? "always" : "", |
|
|
84 | nodename, |
|
|
85 | hostname ? hostname : "", |
|
|
86 | hostname ? ":" : "", |
|
|
87 | hostname ? udp_port : 0 |
|
|
88 | ); |
75 | } |
89 | } |
76 | |
90 | |
77 | configuration::~configuration () |
91 | conf_node::~conf_node () |
78 | { |
92 | { |
79 | cleanup (); |
93 | if (rsa_key) |
|
|
94 | RSA_free (rsa_key); |
|
|
95 | |
|
|
96 | free (nodename); |
|
|
97 | free (hostname); |
80 | } |
98 | } |
81 | |
99 | |
82 | void configuration::init () |
100 | void configuration::init () |
83 | { |
101 | { |
84 | memset (this, 0, sizeof (*this)); |
102 | memset (this, 0, sizeof (*this)); |
… | |
… | |
87 | keepalive = DEFAULT_KEEPALIVE; |
105 | keepalive = DEFAULT_KEEPALIVE; |
88 | llevel = L_INFO; |
106 | llevel = L_INFO; |
89 | ip_proto = IPPROTO_GRE; |
107 | ip_proto = IPPROTO_GRE; |
90 | |
108 | |
91 | default_node.udp_port = DEFAULT_UDPPORT; |
109 | default_node.udp_port = DEFAULT_UDPPORT; |
|
|
110 | default_node.tcp_port = DEFAULT_UDPPORT; |
92 | default_node.connectmode = conf_node::C_ALWAYS; |
111 | default_node.connectmode = conf_node::C_ALWAYS; |
93 | default_node.compress = true; |
112 | default_node.compress = true; |
94 | default_node.protocols = PROT_UDPv4; |
113 | default_node.protocols = PROT_UDPv4; |
95 | } |
114 | } |
96 | |
115 | |
97 | void configuration::cleanup() |
116 | void configuration::cleanup() |
98 | { |
117 | { |
99 | if (rsa_key) |
118 | if (rsa_key) |
100 | RSA_free (rsa_key); |
119 | RSA_free (rsa_key); |
101 | |
120 | |
102 | free (ifname); |
|
|
103 | |
|
|
104 | rsa_key = 0; |
121 | rsa_key = 0; |
105 | ifname = 0; |
122 | |
|
|
123 | free (ifname); ifname = 0; |
|
|
124 | #if ENABLE_HTTP_PROXY |
|
|
125 | free (proxy_host); proxy_host = 0; |
|
|
126 | free (proxy_auth); proxy_auth = 0; |
|
|
127 | #endif |
106 | } |
128 | } |
107 | |
129 | |
108 | void |
130 | void |
109 | configuration::clear_config () |
131 | configuration::clear_config () |
110 | { |
132 | { |
… | |
… | |
269 | script_if_up = strdup (val); |
291 | script_if_up = strdup (val); |
270 | else if (!strcmp (var, "node-up")) |
292 | else if (!strcmp (var, "node-up")) |
271 | script_node_up = strdup (val); |
293 | script_node_up = strdup (val); |
272 | else if (!strcmp (var, "node-down")) |
294 | else if (!strcmp (var, "node-down")) |
273 | script_node_down = strdup (val); |
295 | script_node_down = strdup (val); |
|
|
296 | #if ENABLE_HTTP_PROXY |
|
|
297 | else if (!strcmp (var, "http-proxy-host")) |
|
|
298 | proxy_host = strdup (val); |
|
|
299 | else if (!strcmp (var, "http-proxy-port")) |
|
|
300 | proxy_port = atoi (val); |
|
|
301 | else if (!strcmp (var, "http-proxy-auth")) |
|
|
302 | proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); |
|
|
303 | #endif |
274 | |
304 | |
275 | /* node-specific, non-defaultable */ |
305 | /* node-specific, non-defaultable */ |
276 | else if (node != &default_node && !strcmp (var, "hostname")) |
306 | else if (node != &default_node && !strcmp (var, "hostname")) |
277 | { |
307 | { |
278 | free (node->hostname); |
308 | free (node->hostname); |
… | |
… | |
280 | } |
310 | } |
281 | |
311 | |
282 | /* node-specific, defaultable */ |
312 | /* node-specific, defaultable */ |
283 | else if (!strcmp (var, "udp-port")) |
313 | else if (!strcmp (var, "udp-port")) |
284 | node->udp_port = atoi (val); |
314 | node->udp_port = atoi (val); |
|
|
315 | else if (!strcmp (var, "tcp-port")) |
|
|
316 | node->tcp_port = atoi (val); |
285 | else if (!strcmp (var, "router-priority")) |
317 | else if (!strcmp (var, "router-priority")) |
286 | node->routerprio = atoi (val); |
318 | node->routerprio = atoi (val); |
287 | else if (!strcmp (var, "connect")) |
319 | else if (!strcmp (var, "connect")) |
288 | { |
320 | { |
289 | if (!strcmp (val, "ondemand")) |
321 | if (!strcmp (val, "ondemand")) |
… | |
… | |
306 | else if (!strcmp (var, "compress")) |
338 | else if (!strcmp (var, "compress")) |
307 | { |
339 | { |
308 | parse_bool (node->compress, "compress", true, false); |
340 | parse_bool (node->compress, "compress", true, false); |
309 | } |
341 | } |
310 | // all these bool options really really cost a lot of executable size! |
342 | // all these bool options really really cost a lot of executable size! |
|
|
343 | else if (!strcmp (var, "enable-tcp")) |
|
|
344 | { |
|
|
345 | #if ENABLE_TCP |
|
|
346 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
|
|
347 | #endif |
|
|
348 | } |
311 | else if (!strcmp (var, "enable-udp")) |
349 | else if (!strcmp (var, "enable-udp")) |
312 | { |
350 | { |
313 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
351 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
314 | } |
352 | } |
315 | else if (!strcmp (var, "enable-rawip")) |
353 | else if (!strcmp (var, "enable-rawip")) |
… | |
… | |
317 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
355 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
318 | } |
356 | } |
319 | |
357 | |
320 | // unknown or misplaced |
358 | // unknown or misplaced |
321 | else |
359 | else |
322 | { |
|
|
323 | slog (L_WARN, |
360 | slog (L_WARN, |
324 | _("unknown or misplaced variable `%s', at '%s' line %d"), |
361 | _("unknown or misplaced variable `%s', at '%s' line %d"), |
325 | var, fname, lineno); |
362 | var, fname, lineno); |
326 | } |
|
|
327 | } |
363 | } |
328 | |
364 | |
329 | fclose (f); |
365 | fclose (f); |
330 | } |
366 | } |
331 | else |
367 | else |
… | |
… | |
402 | (*i)->print (); |
438 | (*i)->print (); |
403 | |
439 | |
404 | printf ("\n"); |
440 | printf ("\n"); |
405 | } |
441 | } |
406 | |
442 | |
407 | void |
443 | configuration::configuration () |
408 | conf_node::print () |
|
|
409 | { |
444 | { |
410 | printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", |
445 | init (); |
411 | id, |
|
|
412 | id >> 8, id & 0xff, |
|
|
413 | compress ? 'Y' : 'N', |
|
|
414 | connectmode == C_ONDEMAND ? "ondemand" : |
|
|
415 | connectmode == C_NEVER ? "never" : |
|
|
416 | connectmode == C_ALWAYS ? "always" : "", |
|
|
417 | nodename, |
|
|
418 | hostname ? hostname : "", |
|
|
419 | hostname ? ":" : "", |
|
|
420 | hostname ? udp_port : 0 |
|
|
421 | ); |
|
|
422 | } |
446 | } |
423 | |
447 | |
|
|
448 | configuration::~configuration () |
|
|
449 | { |
|
|
450 | cleanup (); |
|
|
451 | } |
|
|
452 | |
|
|
453 | |