… | |
… | |
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"; |
… | |
… | |
92 | |
94 | |
93 | return false; |
95 | return false; |
94 | } |
96 | } |
95 | |
97 | |
96 | bool |
98 | bool |
97 | conf_node::can_direct (struct conf_node *other) |
99 | conf_node::may_direct (struct conf_node *other) |
98 | { |
100 | { |
99 | if (match_list (allow_direct, other->nodename)) |
101 | if (match_list (allow_direct, other->nodename)) |
100 | return true; |
102 | return true; |
101 | |
103 | |
102 | if (match_list (deny_direct, other->nodename)) |
104 | if (match_list (deny_direct, other->nodename)) |
103 | return false; |
105 | return false; |
104 | |
106 | |
105 | return true; |
107 | return true; |
106 | } |
|
|
107 | |
|
|
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 | nodename, |
|
|
119 | hostname ? hostname : "", |
|
|
120 | hostname ? ":" : "", |
|
|
121 | hostname ? udp_port : 0 |
|
|
122 | ); |
|
|
123 | } |
108 | } |
124 | |
109 | |
125 | conf_node::~conf_node () |
110 | conf_node::~conf_node () |
126 | { |
111 | { |
127 | #if 0 |
112 | #if 0 |
… | |
… | |
138 | free (dns_hostname); |
123 | free (dns_hostname); |
139 | #endif |
124 | #endif |
140 | #endif |
125 | #endif |
141 | } |
126 | } |
142 | |
127 | |
|
|
128 | void |
143 | void configuration::init () |
129 | configuration::init () |
144 | { |
130 | { |
145 | memset (this, 0, sizeof (*this)); |
131 | memset (this, 0, sizeof (*this)); |
146 | |
132 | |
147 | mtu = DEFAULT_MTU; |
133 | mtu = DEFAULT_MTU; |
|
|
134 | nfmark = 0; |
148 | rekey = DEFAULT_REKEY; |
135 | rekey = DEFAULT_REKEY; |
149 | keepalive = DEFAULT_KEEPALIVE; |
136 | keepalive = DEFAULT_KEEPALIVE; |
150 | llevel = L_INFO; |
137 | llevel = L_INFO; |
151 | ip_proto = IPPROTO_GRE; |
138 | ip_proto = IPPROTO_GRE; |
152 | #if ENABLE_ICMP |
139 | #if ENABLE_ICMP |
… | |
… | |
175 | #endif |
162 | #endif |
176 | |
163 | |
177 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
164 | conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); |
178 | } |
165 | } |
179 | |
166 | |
|
|
167 | void |
180 | void configuration::cleanup() |
168 | configuration::cleanup () |
181 | { |
169 | { |
182 | if (rsa_key) |
170 | if (rsa_key) |
183 | RSA_free (rsa_key); |
171 | RSA_free (rsa_key); |
184 | |
172 | |
185 | rsa_key = 0; |
173 | rsa_key = 0; |
186 | |
174 | |
187 | free (pidfilename); pidfilename = 0; |
175 | free (pidfilename); pidfilename = 0; |
188 | free (ifname); ifname = 0; |
176 | free (ifname); ifname = 0; |
189 | #if ENABLE_HTTP_PROXY |
177 | #if ENABLE_HTTP_PROXY |
190 | free (proxy_host); proxy_host = 0; |
178 | free (proxy_host); proxy_host = 0; |
191 | free (proxy_auth); proxy_auth = 0; |
179 | free (proxy_auth); proxy_auth = 0; |
192 | #endif |
180 | #endif |
193 | #if ENABLE_DNS |
181 | #if ENABLE_DNS |
194 | free (dns_forw_host); dns_forw_host = 0; |
182 | free (dns_forw_host); dns_forw_host = 0; |
195 | #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; |
196 | } |
188 | } |
197 | |
189 | |
198 | void |
190 | void |
199 | configuration::clear () |
191 | configuration::clear () |
200 | { |
192 | { |
… | |
… | |
328 | conf.rekey = atoi (val); |
320 | conf.rekey = atoi (val); |
329 | else if (!strcmp (var, "keepalive")) |
321 | else if (!strcmp (var, "keepalive")) |
330 | conf.keepalive = atoi (val); |
322 | conf.keepalive = atoi (val); |
331 | else if (!strcmp (var, "mtu")) |
323 | else if (!strcmp (var, "mtu")) |
332 | conf.mtu = atoi (val); |
324 | conf.mtu = atoi (val); |
|
|
325 | else if (!strcmp (var, "nfmark")) |
|
|
326 | conf.nfmark = atoi (val); |
333 | else if (!strcmp (var, "if-up")) |
327 | else if (!strcmp (var, "if-up")) |
334 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
328 | free (conf.script_if_up), conf.script_if_up = strdup (val); |
335 | else if (!strcmp (var, "node-up")) |
329 | else if (!strcmp (var, "node-up")) |
336 | 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); |
337 | else if (!strcmp (var, "node-down")) |
333 | else if (!strcmp (var, "node-down")) |
338 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
334 | free (conf.script_node_down), conf.script_node_down = strdup (val); |
339 | else if (!strcmp (var, "pid-file")) |
335 | else if (!strcmp (var, "pid-file")) |
340 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
336 | free (conf.pidfilename), conf.pidfilename = strdup (val); |
341 | else if (!strcmp (var, "dns-forw-host")) |
337 | else if (!strcmp (var, "dns-forw-host")) |
… | |
… | |
484 | return _("unknown configuration directive. (ignored)"); |
480 | return _("unknown configuration directive. (ignored)"); |
485 | |
481 | |
486 | return 0; |
482 | return 0; |
487 | } |
483 | } |
488 | |
484 | |
|
|
485 | void |
|
|
486 | conf_node::finalise () |
|
|
487 | { |
|
|
488 | if (max_queue < 1) |
|
|
489 | { |
|
|
490 | slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); |
|
|
491 | max_queue = 1; |
|
|
492 | } |
|
|
493 | |
|
|
494 | if (routerprio > 1 && (connectmode != C_ALWAYS && connectmode != C_DISABLED)) |
|
|
495 | { |
|
|
496 | //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); |
|
|
497 | connectmode = C_ALWAYS; |
|
|
498 | } |
|
|
499 | } |
|
|
500 | |
|
|
501 | void |
489 | void configuration_parser::parse_argv () |
502 | configuration_parser::parse_argv () |
490 | { |
503 | { |
491 | for (int i = 0; i < argc; ++i) |
504 | for (int i = 0; i < argc; ++i) |
492 | { |
505 | { |
493 | char *v = argv [i]; |
506 | char *v = argv [i]; |
494 | |
507 | |
… | |
… | |
596 | slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); |
609 | slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); |
597 | exit (EXIT_FAILURE); |
610 | exit (EXIT_FAILURE); |
598 | } |
611 | } |
599 | |
612 | |
600 | free (fname); |
613 | free (fname); |
601 | } |
|
|
602 | |
614 | |
|
|
615 | for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) |
|
|
616 | (*i)->finalise (); |
|
|
617 | } |
|
|
618 | |
|
|
619 | char * |
603 | char *configuration::config_filename (const char *name, const char *dflt) |
620 | configuration::config_filename (const char *name, const char *dflt) |
604 | { |
621 | { |
605 | char *fname; |
622 | char *fname; |
606 | |
623 | |
607 | asprintf (&fname, name ? name : dflt, ::thisnode); |
624 | asprintf (&fname, name ? name : dflt, ::thisnode); |
608 | |
625 | |
… | |
… | |
612 | asprintf (&fname, "%s/%s", confbase, rname); |
629 | asprintf (&fname, "%s/%s", confbase, rname); |
613 | free (rname); |
630 | free (rname); |
614 | } |
631 | } |
615 | |
632 | |
616 | 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 | ); |
617 | } |
654 | } |
618 | |
655 | |
619 | void |
656 | void |
620 | configuration::print () |
657 | configuration::print () |
621 | { |
658 | { |
… | |
… | |
628 | printf (_("interface: %s\n"), ifname); |
665 | printf (_("interface: %s\n"), ifname); |
629 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
666 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
630 | 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); |
631 | printf ("\n"); |
668 | printf ("\n"); |
632 | |
669 | |
633 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
670 | printf ("%4s %-17s %s %-8.8s %-10.10s %04s %s\n", |
634 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
671 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Prot"), _("Host:Port")); |
635 | |
672 | |
636 | for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) |
673 | for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) |
637 | (*i)->print (); |
674 | (*i)->print (); |
638 | |
675 | |
639 | printf ("\n"); |
676 | printf ("\n"); |
… | |
… | |
649 | configuration::~configuration () |
686 | configuration::~configuration () |
650 | { |
687 | { |
651 | cleanup (); |
688 | cleanup (); |
652 | } |
689 | } |
653 | |
690 | |
654 | |
|
|