1 | /* |
1 | /* |
2 | conf.c -- configuration code |
2 | conf.c -- configuration code |
3 | Copyright (C) 1998 Robert van der Meulen |
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | 1998-2002 Ivo Timmermans <ivo@o2w.nl> |
|
|
5 | 2000-2002 Guus Sliepen <guus@sliepen.eu.org> |
|
|
6 | 2000 Cris van Pelt <tribbel@arise.dhs.org> |
|
|
7 | 2003 Marc Lehmann <pcg@goof.com> |
|
|
8 | |
4 | |
9 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
11 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
12 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
31 | #include <netdb.h> |
27 | #include <netdb.h> |
32 | #include <sys/stat.h> |
28 | #include <sys/stat.h> |
33 | #include <sys/types.h> |
29 | #include <sys/types.h> |
34 | #include <unistd.h> |
30 | #include <unistd.h> |
35 | |
31 | |
36 | #include <netinet/in.h> |
32 | #include "netcompat.h" |
37 | |
33 | |
38 | #include <openssl/err.h> |
34 | #include <openssl/err.h> |
39 | #include <openssl/pem.h> |
35 | #include <openssl/pem.h> |
40 | #include <openssl/rsa.h> |
36 | #include <openssl/rsa.h> |
41 | #include <openssl/rand.h> |
37 | #include <openssl/rand.h> |
… | |
… | |
53 | |
49 | |
54 | struct configuration conf; |
50 | struct configuration conf; |
55 | |
51 | |
56 | u8 best_protocol (u8 protset) |
52 | u8 best_protocol (u8 protset) |
57 | { |
53 | { |
58 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
54 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
|
|
55 | if (protset & PROT_ICMPv4) return PROT_ICMPv4; |
59 | if (protset & PROT_UDPv4) return PROT_UDPv4; |
56 | if (protset & PROT_UDPv4 ) return PROT_UDPv4; |
60 | if (protset & PROT_TCPv4) return PROT_TCPv4; |
57 | if (protset & PROT_TCPv4 ) return PROT_TCPv4; |
61 | |
58 | |
62 | return 0; |
59 | return 0; |
63 | } |
60 | } |
64 | |
61 | |
65 | const char *strprotocol (u8 protocol) |
62 | const char *strprotocol (u8 protocol) |
66 | { |
63 | { |
67 | if (protocol & PROT_IPv4 ) return "rawip"; |
64 | if (protocol & PROT_IPv4 ) return "rawip"; |
|
|
65 | if (protocol & PROT_ICMPv4) return "icmp"; |
68 | if (protocol & PROT_UDPv4) return "udp"; |
66 | if (protocol & PROT_UDPv4 ) return "udp"; |
69 | if (protocol & PROT_TCPv4) return "tcp"; |
67 | if (protocol & PROT_TCPv4 ) return "tcp"; |
70 | |
68 | |
71 | return "<unknown>"; |
69 | return "<unknown>"; |
72 | } |
70 | } |
73 | |
71 | |
74 | void |
72 | void |
… | |
… | |
99 | |
97 | |
100 | void configuration::init () |
98 | void configuration::init () |
101 | { |
99 | { |
102 | memset (this, 0, sizeof (*this)); |
100 | memset (this, 0, sizeof (*this)); |
103 | |
101 | |
|
|
102 | mtu = DEFAULT_MTU; |
104 | rekey = DEFAULT_REKEY; |
103 | rekey = DEFAULT_REKEY; |
105 | keepalive = DEFAULT_KEEPALIVE; |
104 | keepalive = DEFAULT_KEEPALIVE; |
106 | llevel = L_INFO; |
105 | llevel = L_INFO; |
107 | ip_proto = IPPROTO_GRE; |
106 | ip_proto = IPPROTO_GRE; |
|
|
107 | #if ENABLE_ICMP |
|
|
108 | icmp_type = ICMP_ECHOREPLY; |
|
|
109 | #endif |
108 | |
110 | |
109 | default_node.udp_port = DEFAULT_UDPPORT; |
111 | default_node.udp_port = DEFAULT_UDPPORT; |
110 | default_node.tcp_port = DEFAULT_UDPPORT; |
112 | default_node.tcp_port = DEFAULT_UDPPORT; |
111 | default_node.connectmode = conf_node::C_ALWAYS; |
113 | default_node.connectmode = conf_node::C_ALWAYS; |
112 | default_node.compress = true; |
114 | default_node.compress = true; |
… | |
… | |
223 | else |
225 | else |
224 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
226 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
225 | } |
227 | } |
226 | else if (!strcmp (var, "ip-proto")) |
228 | else if (!strcmp (var, "ip-proto")) |
227 | ip_proto = atoi (val); |
229 | ip_proto = atoi (val); |
|
|
230 | else if (!strcmp (var, "icmp-type")) |
|
|
231 | { |
|
|
232 | #if ENABLE_ICMP |
|
|
233 | icmp_type = atoi (val); |
|
|
234 | #endif |
|
|
235 | } |
228 | |
236 | |
229 | // per config |
237 | // per config |
230 | else if (!strcmp (var, "node")) |
238 | else if (!strcmp (var, "node")) |
231 | { |
239 | { |
232 | default_node.id++; |
240 | default_node.id++; |
… | |
… | |
291 | script_if_up = strdup (val); |
299 | script_if_up = strdup (val); |
292 | else if (!strcmp (var, "node-up")) |
300 | else if (!strcmp (var, "node-up")) |
293 | script_node_up = strdup (val); |
301 | script_node_up = strdup (val); |
294 | else if (!strcmp (var, "node-down")) |
302 | else if (!strcmp (var, "node-down")) |
295 | script_node_down = strdup (val); |
303 | script_node_down = strdup (val); |
|
|
304 | else if (!strcmp (var, "http-proxy-host")) |
|
|
305 | { |
296 | #if ENABLE_HTTP_PROXY |
306 | #if ENABLE_HTTP_PROXY |
297 | else if (!strcmp (var, "http-proxy-host")) |
|
|
298 | proxy_host = strdup (val); |
307 | proxy_host = strdup (val); |
|
|
308 | #endif |
|
|
309 | } |
299 | else if (!strcmp (var, "http-proxy-port")) |
310 | else if (!strcmp (var, "http-proxy-port")) |
|
|
311 | { |
|
|
312 | #if ENABLE_HTTP_PROXY |
300 | proxy_port = atoi (val); |
313 | proxy_port = atoi (val); |
|
|
314 | #endif |
|
|
315 | } |
301 | else if (!strcmp (var, "http-proxy-auth")) |
316 | else if (!strcmp (var, "http-proxy-auth")) |
|
|
317 | { |
|
|
318 | #if ENABLE_HTTP_PROXY |
302 | proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); |
319 | proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); |
303 | #endif |
320 | #endif |
|
|
321 | } |
304 | |
322 | |
305 | /* node-specific, non-defaultable */ |
323 | /* node-specific, non-defaultable */ |
306 | else if (node != &default_node && !strcmp (var, "hostname")) |
324 | else if (node != &default_node && !strcmp (var, "hostname")) |
307 | { |
325 | { |
308 | free (node->hostname); |
326 | free (node->hostname); |
… | |
… | |
344 | { |
362 | { |
345 | #if ENABLE_TCP |
363 | #if ENABLE_TCP |
346 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
364 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
347 | #endif |
365 | #endif |
348 | } |
366 | } |
|
|
367 | else if (!strcmp (var, "enable-icmp")) |
|
|
368 | { |
|
|
369 | #if ENABLE_ICMP |
|
|
370 | u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; |
|
|
371 | #endif |
|
|
372 | } |
349 | else if (!strcmp (var, "enable-udp")) |
373 | else if (!strcmp (var, "enable-udp")) |
350 | { |
374 | { |
351 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
375 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
352 | } |
376 | } |
353 | else if (!strcmp (var, "enable-rawip")) |
377 | else if (!strcmp (var, "enable-rawip")) |
… | |
… | |
426 | printf (_("MTU: %d\n"), mtu); |
450 | printf (_("MTU: %d\n"), mtu); |
427 | printf (_("rekeying interval: %d\n"), rekey); |
451 | printf (_("rekeying interval: %d\n"), rekey); |
428 | printf (_("keepalive interval: %d\n"), keepalive); |
452 | printf (_("keepalive interval: %d\n"), keepalive); |
429 | printf (_("interface: %s\n"), ifname); |
453 | printf (_("interface: %s\n"), ifname); |
430 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
454 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
431 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); |
455 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); |
432 | printf ("\n"); |
456 | printf ("\n"); |
433 | |
457 | |
434 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
458 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
435 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
459 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
436 | |
460 | |