1 | /* |
1 | /* |
2 | conf.h -- configuration database |
2 | conf.h -- configuration database |
3 | Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de> |
3 | Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> |
4 | |
4 | |
5 | This file is part of GVPE. |
5 | This file is part of GVPE. |
6 | |
6 | |
7 | GVPE is free software; you can redistribute it and/or modify |
7 | GVPE is free software; you can redistribute it and/or modify it |
8 | it under the terms of the GNU General Public License as published by |
8 | under the terms of the GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
9 | Free Software Foundation; either version 3 of the License, or (at your |
10 | (at your option) any later version. |
10 | option) any later version. |
11 | |
11 | |
12 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, but |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
15 | GNU General Public License for more details. |
15 | Public License for more details. |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License along |
18 | along with gvpe; if not, write to the Free Software |
18 | with this program; if not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | |
|
|
20 | Additional permission under GNU GPL version 3 section 7 |
|
|
21 | |
|
|
22 | If you modify this Program, or any covered work, by linking or |
|
|
23 | combining it with the OpenSSL project's OpenSSL library (or a modified |
|
|
24 | version of that library), containing parts covered by the terms of the |
|
|
25 | OpenSSL or SSLeay licenses, the licensors of this Program grant you |
|
|
26 | additional permission to convey the resulting work. Corresponding |
|
|
27 | Source for a non-source form of such a combination shall include the |
|
|
28 | source code for the parts of OpenSSL used as well as that of the |
|
|
29 | covered work. |
20 | */ |
30 | */ |
21 | |
31 | |
22 | #ifndef VPE_CONF_H__ |
32 | #ifndef GVPE_CONF_H__ |
23 | #define VPE_CONF_H__ |
33 | #define GVPE_CONF_H__ |
24 | |
34 | |
25 | #include <vector> |
35 | #include <vector> |
26 | |
36 | |
27 | #include <openssl/rsa.h> |
37 | #include <openssl/rsa.h> |
28 | |
38 | |
29 | #include "slog.h" |
39 | #include "slog.h" |
30 | #include "global.h" |
40 | #include "global.h" |
31 | |
41 | |
32 | #define DEFAULT_REKEY 3600 |
42 | #define DEFAULT_REKEY 3600 |
33 | #define DEFAULT_KEEPALIVE 60 // one keepalive/minute (it's just 8 bytes...) |
43 | #define DEFAULT_KEEPALIVE 60 // one keepalive/minute (it's just 8 bytes...) |
34 | #define DEFAULT_UDPPORT 655 // same as tinc, conflicts would be rare |
44 | #define DEFAULT_UDPPORT 655 // same as tinc, conflicts would be rare |
35 | #define DEFAULT_MTU 1500 // let's ether-net |
45 | #define DEFAULT_MTU 1500 // let's ether-net |
36 | #define DEFAULT_MAX_RETRY 3600 // retry at least this often |
46 | #define DEFAULT_MAX_RETRY 3600 // retry at least this often |
|
|
47 | #define DEFAULT_MAX_TTL 60 // packets expire after this many seconds |
|
|
48 | #define DEFAULT_MAX_QUEUE 512 // never queue more than this many packets |
|
|
49 | |
|
|
50 | #define DEFAULT_DNS_TIMEOUT_FACTOR 8.F // initial retry timeout multiple |
|
|
51 | #define DEFAULT_DNS_SEND_INTERVAL .01F // minimum send interval |
|
|
52 | #define DEFAULT_DNS_OVERLAP_FACTOR .5F // RTT * LATENCY_FACTOR == sending rate |
|
|
53 | #define DEFAULT_DNS_MAX_OUTSTANDING 100 // max. number of outstanding requests |
37 | |
54 | |
38 | enum { |
55 | enum |
|
|
56 | { |
39 | PROT_UDPv4 = 0x01, // udp over ipv4 |
57 | PROT_UDPv4 = 0x01, // udp over ipv4 |
40 | PROT_IPv4 = 0x02, // generic ip protocol |
58 | PROT_IPv4 = 0x02, // generic ip protocol |
41 | PROT_TCPv4 = 0x04, // tcp over ipv4 (server) |
59 | PROT_TCPv4 = 0x04, // tcp over ipv4 (server) |
42 | PROT_ICMPv4 = 0x08, // icmp over ipv4 |
60 | PROT_ICMPv4 = 0x08, // icmp over ipv4 |
43 | PROT_DNSv4 = 0x10, // dns tunnel ipv4 (server) |
61 | PROT_DNSv4 = 0x10, // dns tunnel ipv4 (server) |
… | |
… | |
48 | |
66 | |
49 | // select the "best" protocol of the available ones |
67 | // select the "best" protocol of the available ones |
50 | u8 best_protocol (u8 protset); |
68 | u8 best_protocol (u8 protset); |
51 | const char *strprotocol (u8 protocol); |
69 | const char *strprotocol (u8 protocol); |
52 | |
70 | |
53 | struct conf_node { |
71 | struct conf_node |
|
|
72 | { |
54 | int id; // the id of this node, a 12-bit-number |
73 | int id; // the id of this node, a 12-bit-number |
55 | |
74 | |
56 | RSA *rsa_key; // his public key |
75 | RSA *rsa_key; // his public key |
57 | char *nodename; // nodename, an internal nickname. |
76 | char *nodename; // nodename, an internal nickname. |
58 | char *hostname; // hostname, if known, or NULL. |
77 | char *hostname; // hostname, if known, or NULL. |
|
|
78 | char *if_up_data; |
59 | #if ENABLE_DNS |
79 | #if ENABLE_DNS |
60 | char *domain; // dns tunnel domain |
80 | char *domain; // dns tunnel domain |
61 | #endif |
81 | #endif |
62 | char *dns_hostname; |
82 | char *dns_hostname; |
63 | u16 dns_port; |
83 | u16 dns_port; |
64 | |
84 | |
65 | u8 protocols; // protocols this host can send & receive |
85 | u8 protocols; // protocols this host can send & receive |
66 | u16 udp_port, tcp_port; // the port to bind to |
86 | u16 udp_port, tcp_port; // the port to bind to |
67 | int max_retry; |
87 | int max_retry; |
|
|
88 | double max_ttl; // packets expire after this many seconds |
|
|
89 | int max_queue; // maixmum send queue length |
68 | |
90 | |
69 | enum connectmode { C_ONDEMAND, C_NEVER, C_ALWAYS, C_DISABLED } connectmode; |
91 | enum connectmode { C_ONDEMAND, C_NEVER, C_ALWAYS, C_DISABLED } connectmode; |
70 | bool compress; |
92 | bool compress; |
71 | bool inherit_tos; // inherit TOS in packets send to this destination |
93 | bool inherit_tos; // inherit TOS in packets send to this destination |
72 | |
94 | |
|
|
95 | vector<const char *> allow_direct; |
|
|
96 | vector<const char *> deny_direct; |
|
|
97 | |
73 | u32 routerprio; |
98 | u32 routerprio; |
|
|
99 | |
|
|
100 | u8 connectable_protocols () const |
|
|
101 | { |
|
|
102 | u8 protocols = this->protocols; |
|
|
103 | |
|
|
104 | // mask out endpoints we can't connect to |
|
|
105 | if (!udp_port) protocols &= ~PROT_UDPv4; |
|
|
106 | if (!tcp_port) protocols &= ~PROT_TCPv4; |
|
|
107 | if (!dns_port) protocols &= ~PROT_DNSv4; |
|
|
108 | |
|
|
109 | return protocols; |
|
|
110 | } |
|
|
111 | |
|
|
112 | bool may_direct (struct conf_node *other); |
|
|
113 | void finalise (); |
74 | |
114 | |
75 | void print (); |
115 | void print (); |
76 | |
116 | |
77 | ~conf_node (); |
117 | ~conf_node (); |
78 | }; |
118 | }; |
79 | |
119 | |
80 | struct configuration { |
120 | struct configuration |
|
|
121 | { |
81 | typedef vector<conf_node *> node_vector; |
122 | typedef vector<conf_node *> node_vector; |
82 | node_vector nodes; |
123 | node_vector nodes; |
83 | conf_node default_node; |
124 | conf_node default_node; |
84 | conf_node *thisnode; |
125 | conf_node *thisnode; |
85 | int mtu; // the mtu used for outgoing tunnel packets |
126 | int mtu; // the mtu used for outgoing tunnel packets |
|
|
127 | int nfmark; // the SO_MARK // netfilter mark // fwmark |
86 | double rekey; // rekey interval |
128 | double rekey; // rekey interval |
87 | double keepalive; // keepalive probes interval |
129 | double keepalive; // keepalive probes interval |
88 | char *ifname; // the interface name (tap0 ...) |
130 | char *ifname; // the interface name (tap0 ...) |
89 | bool ifpersist; // should the interface be persistent |
131 | bool ifpersist; // should the interface be persistent |
90 | char *prikeyfile; |
132 | char *prikeyfile; |
… | |
… | |
107 | #endif |
149 | #endif |
108 | |
150 | |
109 | #if ENABLE_DNS |
151 | #if ENABLE_DNS |
110 | char *dns_forw_host; |
152 | char *dns_forw_host; |
111 | u16 dns_forw_port; |
153 | u16 dns_forw_port; |
|
|
154 | float dns_timeout_factor; |
|
|
155 | float dns_send_interval; |
|
|
156 | float dns_overlap_factor; |
|
|
157 | int dns_max_outstanding; |
112 | #endif |
158 | #endif |
113 | |
159 | |
114 | void init (); |
160 | void init (); |
115 | void cleanup (); |
161 | void cleanup (); |
116 | void read_config (bool need_keys); |
|
|
117 | void clear_config (); |
162 | void clear (); |
118 | |
163 | |
119 | // create a filename from string, replacing %s by the nodename |
164 | // create a filename from string, replacing %s by the nodename |
120 | // and using relative paths under confbase. |
165 | // and using relative paths under confbase. |
121 | char *config_filename (const char *name, const char *dflt); |
166 | char *config_filename (const char *name, const char *dflt); |
122 | |
167 | |
… | |
… | |
124 | |
169 | |
125 | configuration (); |
170 | configuration (); |
126 | ~configuration (); |
171 | ~configuration (); |
127 | }; |
172 | }; |
128 | |
173 | |
|
|
174 | struct configuration_parser |
|
|
175 | { |
|
|
176 | configuration &conf; |
|
|
177 | |
|
|
178 | bool need_keys; |
|
|
179 | conf_node *node; |
|
|
180 | |
|
|
181 | int argc; |
|
|
182 | char **argv; |
|
|
183 | |
|
|
184 | configuration_parser (configuration &conf, bool need_keys, int argc, char **argv); |
|
|
185 | |
|
|
186 | const char *parse_line (char *line); |
|
|
187 | void parse_argv (); |
|
|
188 | }; |
|
|
189 | |
129 | extern struct configuration conf; |
190 | extern struct configuration conf; |
130 | |
191 | |
131 | #define THISNODE ::conf.thisnode |
192 | #define THISNODE ::conf.thisnode |
132 | |
193 | |
133 | #endif |
194 | #endif |