… | |
… | |
32 | #include <sys/stat.h> |
32 | #include <sys/stat.h> |
33 | #include <sys/types.h> |
33 | #include <sys/types.h> |
34 | #include <unistd.h> |
34 | #include <unistd.h> |
35 | |
35 | |
36 | #include <netinet/in.h> |
36 | #include <netinet/in.h> |
|
|
37 | #include <arpa/inet.h> |
|
|
38 | #ifdef ENABLE_ICMP |
|
|
39 | # ifdef HAVE_NETINET_IN_SYSTM_H |
|
|
40 | # include <netinet/in_systm.h> |
|
|
41 | # endif |
|
|
42 | # ifdef HAVE_NETINET_IP_H |
|
|
43 | # include <netinet/ip.h> |
|
|
44 | # endif |
|
|
45 | # include <netinet/ip_icmp.h> |
|
|
46 | #endif |
37 | |
47 | |
38 | #include <openssl/err.h> |
48 | #include <openssl/err.h> |
39 | #include <openssl/pem.h> |
49 | #include <openssl/pem.h> |
40 | #include <openssl/rsa.h> |
50 | #include <openssl/rsa.h> |
41 | #include <openssl/rand.h> |
51 | #include <openssl/rand.h> |
… | |
… | |
53 | |
63 | |
54 | struct configuration conf; |
64 | struct configuration conf; |
55 | |
65 | |
56 | u8 best_protocol (u8 protset) |
66 | u8 best_protocol (u8 protset) |
57 | { |
67 | { |
58 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
68 | if (protset & PROT_IPv4 ) return PROT_IPv4; |
|
|
69 | if (protset & PROT_ICMPv4) return PROT_ICMPv4; |
59 | if (protset & PROT_UDPv4) return PROT_UDPv4; |
70 | if (protset & PROT_UDPv4 ) return PROT_UDPv4; |
60 | if (protset & PROT_TCPv4) return PROT_TCPv4; |
71 | if (protset & PROT_TCPv4 ) return PROT_TCPv4; |
61 | |
72 | |
62 | return 0; |
73 | return 0; |
63 | } |
74 | } |
64 | |
75 | |
65 | const char *strprotocol (u8 protocol) |
76 | const char *strprotocol (u8 protocol) |
66 | { |
77 | { |
67 | if (protocol & PROT_IPv4 ) return "rawip"; |
78 | if (protocol & PROT_IPv4 ) return "rawip"; |
|
|
79 | if (protocol & PROT_ICMPv4) return "icmp"; |
68 | if (protocol & PROT_UDPv4) return "udp"; |
80 | if (protocol & PROT_UDPv4 ) return "udp"; |
69 | if (protocol & PROT_TCPv4) return "tcp"; |
81 | if (protocol & PROT_TCPv4 ) return "tcp"; |
70 | |
82 | |
71 | return "<unknown>"; |
83 | return "<unknown>"; |
72 | } |
84 | } |
73 | |
85 | |
74 | void |
86 | void |
… | |
… | |
103 | |
115 | |
104 | rekey = DEFAULT_REKEY; |
116 | rekey = DEFAULT_REKEY; |
105 | keepalive = DEFAULT_KEEPALIVE; |
117 | keepalive = DEFAULT_KEEPALIVE; |
106 | llevel = L_INFO; |
118 | llevel = L_INFO; |
107 | ip_proto = IPPROTO_GRE; |
119 | ip_proto = IPPROTO_GRE; |
|
|
120 | #if ENABLE_ICMP |
|
|
121 | icmp_type = ICMP_ECHOREPLY; |
|
|
122 | #endif |
108 | |
123 | |
109 | default_node.udp_port = DEFAULT_UDPPORT; |
124 | default_node.udp_port = DEFAULT_UDPPORT; |
110 | default_node.tcp_port = DEFAULT_UDPPORT; |
125 | default_node.tcp_port = DEFAULT_UDPPORT; |
111 | default_node.connectmode = conf_node::C_ALWAYS; |
126 | default_node.connectmode = conf_node::C_ALWAYS; |
112 | default_node.compress = true; |
127 | default_node.compress = true; |
… | |
… | |
223 | else |
238 | else |
224 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
239 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
225 | } |
240 | } |
226 | else if (!strcmp (var, "ip-proto")) |
241 | else if (!strcmp (var, "ip-proto")) |
227 | ip_proto = atoi (val); |
242 | ip_proto = atoi (val); |
|
|
243 | #if ENABLE_ICMP |
|
|
244 | //TODO: error message |
|
|
245 | else if (!strcmp (var, "icmp-type")) |
|
|
246 | icmp_type = atoi (val); |
|
|
247 | #endif |
228 | |
248 | |
229 | // per config |
249 | // per config |
230 | else if (!strcmp (var, "node")) |
250 | else if (!strcmp (var, "node")) |
231 | { |
251 | { |
232 | default_node.id++; |
252 | default_node.id++; |
… | |
… | |
344 | { |
364 | { |
345 | #if ENABLE_TCP |
365 | #if ENABLE_TCP |
346 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
366 | u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; |
347 | #endif |
367 | #endif |
348 | } |
368 | } |
|
|
369 | else if (!strcmp (var, "enable-icmp")) |
|
|
370 | { |
|
|
371 | #if ENABLE_ICMP |
|
|
372 | u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; |
|
|
373 | #endif |
|
|
374 | } |
349 | else if (!strcmp (var, "enable-udp")) |
375 | else if (!strcmp (var, "enable-udp")) |
350 | { |
376 | { |
351 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
377 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
352 | } |
378 | } |
353 | else if (!strcmp (var, "enable-rawip")) |
379 | else if (!strcmp (var, "enable-rawip")) |
… | |
… | |
426 | printf (_("MTU: %d\n"), mtu); |
452 | printf (_("MTU: %d\n"), mtu); |
427 | printf (_("rekeying interval: %d\n"), rekey); |
453 | printf (_("rekeying interval: %d\n"), rekey); |
428 | printf (_("keepalive interval: %d\n"), keepalive); |
454 | printf (_("keepalive interval: %d\n"), keepalive); |
429 | printf (_("interface: %s\n"), ifname); |
455 | printf (_("interface: %s\n"), ifname); |
430 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
456 | printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); |
431 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); |
457 | printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); |
432 | printf ("\n"); |
458 | printf ("\n"); |
433 | |
459 | |
434 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
460 | printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", |
435 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
461 | _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); |
436 | |
462 | |