… | |
… | |
57 | char *thisnode; |
57 | char *thisnode; |
58 | char *identname; |
58 | char *identname; |
59 | |
59 | |
60 | struct configuration conf; |
60 | struct configuration conf; |
61 | |
61 | |
|
|
62 | u8 |
62 | u8 best_protocol (u8 protset) |
63 | best_protocol (u8 protset) |
63 | { |
64 | { |
64 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
65 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
65 | if (protset & PROT_ICMPv4) return PROT_ICMPv4; |
66 | if (protset & PROT_ICMPv4) return PROT_ICMPv4; |
66 | if (protset & PROT_UDPv4 ) return PROT_UDPv4; |
67 | if (protset & PROT_UDPv4 ) return PROT_UDPv4; |
67 | if (protset & PROT_TCPv4 ) return PROT_TCPv4; |
68 | if (protset & PROT_TCPv4 ) return PROT_TCPv4; |
68 | if (protset & PROT_DNSv4 ) return PROT_DNSv4; |
69 | if (protset & PROT_DNSv4 ) return PROT_DNSv4; |
69 | |
70 | |
70 | return 0; |
71 | return 0; |
71 | } |
72 | } |
72 | |
73 | |
|
|
74 | const char * |
73 | const char *strprotocol (u8 protocol) |
75 | strprotocol (u8 protocol) |
74 | { |
76 | { |
75 | if (protocol & PROT_IPv4 ) return "rawip"; |
77 | if (protocol & PROT_IPv4 ) return "rawip"; |
76 | if (protocol & PROT_ICMPv4) return "icmp"; |
78 | if (protocol & PROT_ICMPv4) return "icmp"; |
77 | if (protocol & PROT_UDPv4 ) return "udp"; |
79 | if (protocol & PROT_UDPv4 ) return "udp"; |
78 | if (protocol & PROT_TCPv4 ) return "tcp"; |
80 | if (protocol & PROT_TCPv4 ) return "tcp"; |
… | |
… | |
140 | free (dns_hostname); |
142 | free (dns_hostname); |
141 | #endif |
143 | #endif |
142 | #endif |
144 | #endif |
143 | } |
145 | } |
144 | |
146 | |
|
|
147 | void |
145 | void configuration::init () |
148 | configuration::init () |
146 | { |
149 | { |
147 | memset (this, 0, sizeof (*this)); |
150 | memset (this, 0, sizeof (*this)); |
148 | |
151 | |
149 | mtu = DEFAULT_MTU; |
152 | mtu = DEFAULT_MTU; |
|
|
153 | nfmark = 0; |
150 | rekey = DEFAULT_REKEY; |
154 | rekey = DEFAULT_REKEY; |
151 | keepalive = DEFAULT_KEEPALIVE; |
155 | keepalive = DEFAULT_KEEPALIVE; |
152 | llevel = L_INFO; |
156 | llevel = L_INFO; |
153 | ip_proto = IPPROTO_GRE; |
157 | ip_proto = IPPROTO_GRE; |
154 | #if ENABLE_ICMP |
158 | #if ENABLE_ICMP |
… | |
… | |
177 | #endif |
181 | #endif |
178 | |
182 | |
179 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
183 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
180 | } |
184 | } |
181 | |
185 | |
|
|
186 | void |
182 | void configuration::cleanup() |
187 | configuration::cleanup () |
183 | { |
188 | { |
184 | if (rsa_key) |
189 | if (rsa_key) |
185 | RSA_free (rsa_key); |
190 | RSA_free (rsa_key); |
186 | |
191 | |
187 | rsa_key = 0; |
192 | rsa_key = 0; |
188 | |
193 | |
189 | free (pidfilename); pidfilename = 0; |
194 | free (pidfilename); pidfilename = 0; |
190 | free (ifname); ifname = 0; |
195 | free (ifname); ifname = 0; |
191 | #if ENABLE_HTTP_PROXY |
196 | #if ENABLE_HTTP_PROXY |
192 | free (proxy_host); proxy_host = 0; |
197 | free (proxy_host); proxy_host = 0; |
193 | free (proxy_auth); proxy_auth = 0; |
198 | free (proxy_auth); proxy_auth = 0; |
194 | #endif |
199 | #endif |
195 | #if ENABLE_DNS |
200 | #if ENABLE_DNS |
196 | free (dns_forw_host); dns_forw_host = 0; |
201 | free (dns_forw_host); dns_forw_host = 0; |
197 | #endif |
202 | #endif |
|
|
203 | free (script_if_up); script_if_up = 0; |
|
|
204 | free (script_node_up); script_node_up = 0; |
|
|
205 | free (script_node_change); script_node_change = 0; |
|
|
206 | free (script_node_down); script_node_down = 0; |
198 | } |
207 | } |
199 | |
208 | |
200 | void |
209 | void |
201 | configuration::clear () |
210 | configuration::clear () |
202 | { |
211 | { |
… | |
… | |
330 | conf.rekey = atoi (val); |
339 | conf.rekey = atoi (val); |
331 | else if (!strcmp (var, "keepalive")) |
340 | else if (!strcmp (var, "keepalive")) |
332 | conf.keepalive = atoi (val); |
341 | conf.keepalive = atoi (val); |
333 | else if (!strcmp (var, "mtu")) |
342 | else if (!strcmp (var, "mtu")) |
334 | conf.mtu = atoi (val); |
343 | conf.mtu = atoi (val); |
|
|
344 | else if (!strcmp (var, "nfmark")) |
|
|
345 | conf.nfmark = atoi (val); |
335 | else if (!strcmp (var, "if-up")) |
346 | else if (!strcmp (var, "if-up")) |
336 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
347 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
337 | else if (!strcmp (var, "node-up")) |
348 | else if (!strcmp (var, "node-up")) |
338 | free (conf.script_node_up), conf.script_node_up = strdup (val); |
349 | free (conf.script_node_up), conf.script_node_up = strdup (val); |
|
|
350 | else if (!strcmp (var, "node-change")) |
|
|
351 | free (conf.script_node_change), conf.script_node_change = strdup (val); |
339 | else if (!strcmp (var, "node-down")) |
352 | else if (!strcmp (var, "node-down")) |
340 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
353 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
341 | else if (!strcmp (var, "pid-file")) |
354 | else if (!strcmp (var, "pid-file")) |
342 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
355 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
343 | else if (!strcmp (var, "dns-forw-host")) |
356 | else if (!strcmp (var, "dns-forw-host")) |
… | |
… | |
486 | return _("unknown configuration directive. (ignored)"); |
499 | return _("unknown configuration directive. (ignored)"); |
487 | |
500 | |
488 | return 0; |
501 | return 0; |
489 | } |
502 | } |
490 | |
503 | |
|
|
504 | void |
491 | void conf_node::finalise () |
505 | conf_node::finalise () |
492 | { |
506 | { |
493 | if (max_queue < 1) |
507 | if (max_queue < 1) |
494 | { |
508 | { |
495 | slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); |
509 | slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); |
496 | max_queue = 1; |
510 | max_queue = 1; |
497 | } |
511 | } |
498 | |
512 | |
499 | if (routerprio && (connectmode != C_ALWAYS && connectmode != C_DISABLED)) |
513 | if (routerprio > 1 && (connectmode != C_ALWAYS && connectmode != C_DISABLED)) |
500 | { |
514 | { |
501 | //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); |
515 | //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); |
502 | connectmode = C_ALWAYS; |
516 | connectmode = C_ALWAYS; |
503 | } |
517 | } |
504 | } |
518 | } |
505 | |
519 | |
|
|
520 | void |
506 | void configuration_parser::parse_argv () |
521 | configuration_parser::parse_argv () |
507 | { |
522 | { |
508 | for (int i = 0; i < argc; ++i) |
523 | for (int i = 0; i < argc; ++i) |
509 | { |
524 | { |
510 | char *v = argv [i]; |
525 | char *v = argv [i]; |
511 | |
526 | |
… | |
… | |
618 | |
633 | |
619 | for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) |
634 | for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) |
620 | (*i)->finalise (); |
635 | (*i)->finalise (); |
621 | } |
636 | } |
622 | |
637 | |
|
|
638 | char * |
623 | char *configuration::config_filename (const char *name, const char *dflt) |
639 | configuration::config_filename (const char *name, const char *dflt) |
624 | { |
640 | { |
625 | char *fname; |
641 | char *fname; |
626 | |
642 | |
627 | asprintf (&fname, name ? name : dflt, ::thisnode); |
643 | asprintf (&fname, name ? name : dflt, ::thisnode); |
628 | |
644 | |
… | |
… | |
669 | configuration::~configuration () |
685 | configuration::~configuration () |
670 | { |
686 | { |
671 | cleanup (); |
687 | cleanup (); |
672 | } |
688 | } |
673 | |
689 | |
674 | |
|
|