… | |
… | |
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"; |
… | |
… | |
103 | return false; |
105 | return false; |
104 | |
106 | |
105 | return true; |
107 | return true; |
106 | } |
108 | } |
107 | |
109 | |
108 | void |
|
|
109 | conf_node::print () |
|
|
110 | { |
|
|
111 | printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", |
|
|
112 | id, |
|
|
113 | id >> 8, id & 0xff, |
|
|
114 | compress ? 'Y' : 'N', |
|
|
115 | connectmode == C_ONDEMAND ? "ondemand" |
|
|
116 | : connectmode == C_NEVER ? "never" |
|
|
117 | : connectmode == C_ALWAYS ? "always" |
|
|
118 | : connectmode == C_DISABLED ? "disabled" |
|
|
119 | : "", |
|
|
120 | nodename, |
|
|
121 | hostname ? hostname : "", |
|
|
122 | hostname ? ":" : "", |
|
|
123 | hostname ? udp_port : 0 |
|
|
124 | ); |
|
|
125 | } |
|
|
126 | |
|
|
127 | conf_node::~conf_node () |
110 | conf_node::~conf_node () |
128 | { |
111 | { |
129 | #if 0 |
112 | #if 0 |
130 | // does not work, because string pointers etc. are shared |
113 | // does not work, because string pointers etc. are shared |
131 | // is not called, however |
114 | // is not called, however |
… | |
… | |
140 | free (dns_hostname); |
123 | free (dns_hostname); |
141 | #endif |
124 | #endif |
142 | #endif |
125 | #endif |
143 | } |
126 | } |
144 | |
127 | |
|
|
128 | void |
145 | void configuration::init () |
129 | configuration::init () |
146 | { |
130 | { |
147 | memset (this, 0, sizeof (*this)); |
131 | memset (this, 0, sizeof (*this)); |
148 | |
132 | |
149 | mtu = DEFAULT_MTU; |
133 | mtu = DEFAULT_MTU; |
|
|
134 | nfmark = 0; |
150 | rekey = DEFAULT_REKEY; |
135 | rekey = DEFAULT_REKEY; |
151 | keepalive = DEFAULT_KEEPALIVE; |
136 | keepalive = DEFAULT_KEEPALIVE; |
152 | llevel = L_INFO; |
137 | llevel = L_INFO; |
153 | ip_proto = IPPROTO_GRE; |
138 | ip_proto = IPPROTO_GRE; |
154 | #if ENABLE_ICMP |
139 | #if ENABLE_ICMP |
… | |
… | |
177 | #endif |
162 | #endif |
178 | |
163 | |
179 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
164 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
180 | } |
165 | } |
181 | |
166 | |
|
|
167 | void |
182 | void configuration::cleanup() |
168 | configuration::cleanup () |
183 | { |
169 | { |
184 | if (rsa_key) |
170 | if (rsa_key) |
185 | RSA_free (rsa_key); |
171 | RSA_free (rsa_key); |
186 | |
172 | |
187 | rsa_key = 0; |
173 | rsa_key = 0; |
188 | |
174 | |
189 | free (pidfilename); pidfilename = 0; |
175 | free (pidfilename); pidfilename = 0; |
190 | free (ifname); ifname = 0; |
176 | free (ifname); ifname = 0; |
191 | #if ENABLE_HTTP_PROXY |
177 | #if ENABLE_HTTP_PROXY |
192 | free (proxy_host); proxy_host = 0; |
178 | free (proxy_host); proxy_host = 0; |
193 | free (proxy_auth); proxy_auth = 0; |
179 | free (proxy_auth); proxy_auth = 0; |
194 | #endif |
180 | #endif |
195 | #if ENABLE_DNS |
181 | #if ENABLE_DNS |
196 | free (dns_forw_host); dns_forw_host = 0; |
182 | free (dns_forw_host); dns_forw_host = 0; |
197 | #endif |
183 | #endif |
|
|
184 | free (script_if_up); script_if_up = 0; |
|
|
185 | free (script_node_up); script_node_up = 0; |
|
|
186 | free (script_node_change); script_node_change = 0; |
|
|
187 | free (script_node_down); script_node_down = 0; |
198 | } |
188 | } |
199 | |
189 | |
200 | void |
190 | void |
201 | configuration::clear () |
191 | configuration::clear () |
202 | { |
192 | { |
… | |
… | |
330 | conf.rekey = atoi (val); |
320 | conf.rekey = atoi (val); |
331 | else if (!strcmp (var, "keepalive")) |
321 | else if (!strcmp (var, "keepalive")) |
332 | conf.keepalive = atoi (val); |
322 | conf.keepalive = atoi (val); |
333 | else if (!strcmp (var, "mtu")) |
323 | else if (!strcmp (var, "mtu")) |
334 | conf.mtu = atoi (val); |
324 | conf.mtu = atoi (val); |
|
|
325 | else if (!strcmp (var, "nfmark")) |
|
|
326 | conf.nfmark = atoi (val); |
335 | else if (!strcmp (var, "if-up")) |
327 | else if (!strcmp (var, "if-up")) |
336 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
328 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
337 | else if (!strcmp (var, "node-up")) |
329 | else if (!strcmp (var, "node-up")) |
338 | free (conf.script_node_up), conf.script_node_up = strdup (val); |
330 | free (conf.script_node_up), conf.script_node_up = strdup (val); |
|
|
331 | else if (!strcmp (var, "node-change")) |
|
|
332 | free (conf.script_node_change), conf.script_node_change = strdup (val); |
339 | else if (!strcmp (var, "node-down")) |
333 | else if (!strcmp (var, "node-down")) |
340 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
334 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
341 | else if (!strcmp (var, "pid-file")) |
335 | else if (!strcmp (var, "pid-file")) |
342 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
336 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
343 | else if (!strcmp (var, "dns-forw-host")) |
337 | else if (!strcmp (var, "dns-forw-host")) |
… | |
… | |
486 | return _("unknown configuration directive. (ignored)"); |
480 | return _("unknown configuration directive. (ignored)"); |
487 | |
481 | |
488 | return 0; |
482 | return 0; |
489 | } |
483 | } |
490 | |
484 | |
|
|
485 | void |
491 | void conf_node::finalise () |
486 | conf_node::finalise () |
492 | { |
487 | { |
493 | if (max_queue < 1) |
488 | if (max_queue < 1) |
494 | { |
489 | { |
495 | slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); |
490 | slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); |
496 | max_queue = 1; |
491 | max_queue = 1; |
… | |
… | |
501 | //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); |
496 | //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; |
497 | connectmode = C_ALWAYS; |
503 | } |
498 | } |
504 | } |
499 | } |
505 | |
500 | |
|
|
501 | void |
506 | void configuration_parser::parse_argv () |
502 | configuration_parser::parse_argv () |
507 | { |
503 | { |
508 | for (int i = 0; i < argc; ++i) |
504 | for (int i = 0; i < argc; ++i) |
509 | { |
505 | { |
510 | char *v = argv [i]; |
506 | char *v = argv [i]; |
511 | |
507 | |
… | |
… | |
618 | |
614 | |
619 | for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) |
615 | for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) |
620 | (*i)->finalise (); |
616 | (*i)->finalise (); |
621 | } |
617 | } |
622 | |
618 | |
|
|
619 | char * |
623 | char *configuration::config_filename (const char *name, const char *dflt) |
620 | configuration::config_filename (const char *name, const char *dflt) |
624 | { |
621 | { |
625 | char *fname; |
622 | char *fname; |
626 | |
623 | |
627 | asprintf (&fname, name ? name : dflt, ::thisnode); |
624 | asprintf (&fname, name ? name : dflt, ::thisnode); |
628 | |
625 | |
… | |
… | |
632 | asprintf (&fname, "%s/%s", confbase, rname); |
629 | asprintf (&fname, "%s/%s", confbase, rname); |
633 | free (rname); |
630 | free (rname); |
634 | } |
631 | } |
635 | |
632 | |
636 | return fname; |
633 | return fname; |
|
|
634 | } |
|
|
635 | |
|
|
636 | void |
|
|
637 | conf_node::print () |
|
|
638 | { |
|
|
639 | printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %02x %s%s%d\n", |
|
|
640 | id, |
|
|
641 | id >> 8, id & 0xff, |
|
|
642 | compress ? 'Y' : 'N', |
|
|
643 | connectmode == C_ONDEMAND ? "ondemand" |
|
|
644 | : connectmode == C_NEVER ? "never" |
|
|
645 | : connectmode == C_ALWAYS ? "always" |
|
|
646 | : connectmode == C_DISABLED ? "disabled" |
|
|
647 | : "", |
|
|
648 | nodename, |
|
|
649 | protocols, |
|
|
650 | hostname ? hostname : "", |
|
|
651 | hostname ? ":" : "", |
|
|
652 | hostname ? udp_port : 0 |
|
|
653 | ); |
637 | } |
654 | } |
638 | |
655 | |
639 | void |
656 | void |
640 | configuration::print () |
657 | configuration::print () |
641 | { |
658 | { |
… | |
… | |
648 | printf (_("interface: %s\n"), ifname); |
665 | printf (_("interface: %s\n"), ifname); |
649 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
666 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
650 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); |
667 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); |
651 | printf ("\n"); |
668 | printf ("\n"); |
652 | |
669 | |
653 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
670 | printf ("%4s %-17s %s %-8.8s %-10.10s %04s %s\n", |
654 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
671 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Prot"), _("Host:Port")); |
655 | |
672 | |
656 | for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) |
673 | for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) |
657 | (*i)->print (); |
674 | (*i)->print (); |
658 | |
675 | |
659 | printf ("\n"); |
676 | printf ("\n"); |
… | |
… | |
669 | configuration::~configuration () |
686 | configuration::~configuration () |
670 | { |
687 | { |
671 | cleanup (); |
688 | cleanup (); |
672 | } |
689 | } |
673 | |
690 | |
674 | |
|
|