… | |
… | |
31 | #include <netdb.h> |
31 | #include <netdb.h> |
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> |
|
|
37 | |
36 | #include <openssl/err.h> |
38 | #include <openssl/err.h> |
37 | #include <openssl/pem.h> |
39 | #include <openssl/pem.h> |
38 | #include <openssl/rsa.h> |
40 | #include <openssl/rsa.h> |
39 | #include <openssl/rand.h> |
41 | #include <openssl/rand.h> |
40 | |
42 | |
… | |
… | |
65 | { |
67 | { |
66 | memset (this, 0, sizeof (*this)); |
68 | memset (this, 0, sizeof (*this)); |
67 | |
69 | |
68 | rekey = DEFAULT_REKEY; |
70 | rekey = DEFAULT_REKEY; |
69 | keepalive = DEFAULT_KEEPALIVE; |
71 | keepalive = DEFAULT_KEEPALIVE; |
|
|
72 | llevel = L_INFO; |
|
|
73 | ip_proto = IPPROTO_GRE; |
70 | |
74 | |
71 | default_node.port = DEFAULT_PORT; |
75 | default_node.udp_port = DEFAULT_UDPPORT; |
72 | default_node.connectmode = conf_node::C_ALWAYS; |
76 | default_node.connectmode = conf_node::C_ALWAYS; |
73 | default_node.compress = true; |
77 | default_node.compress = true; |
|
|
78 | default_node.protocols = PROT_UDPv4; |
74 | } |
79 | } |
75 | |
80 | |
76 | void configuration::cleanup() |
81 | void configuration::cleanup() |
77 | { |
82 | { |
78 | if (rsa_key) |
83 | if (rsa_key) |
… | |
… | |
93 | nodes.clear (); |
98 | nodes.clear (); |
94 | |
99 | |
95 | cleanup (); |
100 | cleanup (); |
96 | init (); |
101 | init (); |
97 | } |
102 | } |
|
|
103 | |
|
|
104 | #define parse_bool(target,name,trueval,falseval) \ |
|
|
105 | if (!strcmp (val, "yes")) target = trueval; \ |
|
|
106 | else if (!strcmp (val, "no")) target = falseval; \ |
|
|
107 | else if (!strcmp (val, "true")) target = trueval; \ |
|
|
108 | else if (!strcmp (val, "false")) target = falseval; \ |
|
|
109 | else if (!strcmp (val, "on")) target = trueval; \ |
|
|
110 | else if (!strcmp (val, "off")) target = falseval; \ |
|
|
111 | else \ |
|
|
112 | slog (L_WARN, \ |
|
|
113 | _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ |
|
|
114 | name, var, fname, lineno); |
98 | |
115 | |
99 | void configuration::read_config (bool need_keys) |
116 | void configuration::read_config (bool need_keys) |
100 | { |
117 | { |
101 | char *fname; |
118 | char *fname; |
102 | FILE *f; |
119 | FILE *f; |
… | |
… | |
162 | if (!strcmp (var, "loglevel")) |
179 | if (!strcmp (var, "loglevel")) |
163 | { |
180 | { |
164 | loglevel l = string_to_loglevel (val); |
181 | loglevel l = string_to_loglevel (val); |
165 | |
182 | |
166 | if (l != L_NONE) |
183 | if (l != L_NONE) |
167 | set_loglevel (l); |
184 | llevel = l; |
168 | else |
185 | else |
169 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
186 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
170 | } |
187 | } |
|
|
188 | else if (!strcmp (var, "ip-proto")) |
|
|
189 | ip_proto = atoi (val); |
171 | |
190 | |
172 | // per config |
191 | // per config |
173 | else if (!strcmp (var, "node")) |
192 | else if (!strcmp (var, "node")) |
174 | { |
193 | { |
175 | default_node.id++; |
194 | default_node.id++; |
… | |
… | |
218 | } |
237 | } |
219 | else if (!strcmp (var, "private-key")) |
238 | else if (!strcmp (var, "private-key")) |
220 | prikeyfile = strdup (val); |
239 | prikeyfile = strdup (val); |
221 | else if (!strcmp (var, "ifpersist")) |
240 | else if (!strcmp (var, "ifpersist")) |
222 | { |
241 | { |
223 | if (!strcmp (val, "yes")) |
242 | parse_bool (ifpersist, "ifpersist", true, false); |
224 | ifpersist = true; |
|
|
225 | else if (!strcmp (val, "no")) |
|
|
226 | ifpersist = false; |
|
|
227 | else |
|
|
228 | slog (L_WARN, |
|
|
229 | _("illegal value for 'ifpersist', only 'yes' or 'no' allowed, at '%s' line %d"), |
|
|
230 | var, fname, lineno); |
|
|
231 | } |
243 | } |
232 | else if (!strcmp (var, "ifname")) |
244 | else if (!strcmp (var, "ifname")) |
233 | ifname = strdup (val); |
245 | ifname = strdup (val); |
234 | else if (!strcmp (var, "rekey")) |
246 | else if (!strcmp (var, "rekey")) |
235 | rekey = atoi (val); |
247 | rekey = atoi (val); |
… | |
… | |
250 | free (node->hostname); |
262 | free (node->hostname); |
251 | node->hostname = strdup (val); |
263 | node->hostname = strdup (val); |
252 | } |
264 | } |
253 | |
265 | |
254 | /* node-specific, defaultable */ |
266 | /* node-specific, defaultable */ |
255 | else if (!strcmp (var, "port")) |
267 | else if (!strcmp (var, "udp-port")) |
256 | node->port = atoi (val); |
268 | node->udp_port = atoi (val); |
257 | else if (!strcmp (var, "router-priority")) |
269 | else if (!strcmp (var, "router-priority")) |
258 | node->routerprio = atoi (val); |
270 | node->routerprio = atoi (val); |
259 | else if (!strcmp (var, "connect")) |
271 | else if (!strcmp (var, "connect")) |
260 | { |
272 | { |
261 | if (!strcmp (val, "ondemand")) |
273 | if (!strcmp (val, "ondemand")) |
262 | node->connectmode = conf_node::C_ONDEMAND; |
274 | node->connectmode = conf_node::C_ONDEMAND; |
263 | else if (!strcmp (val, "never")) |
275 | else if (!strcmp (val, "never")) |
264 | node->connectmode = conf_node::C_NEVER; |
276 | node->connectmode = conf_node::C_NEVER; |
265 | else if (!strcmp (val, "always")) |
277 | else if (!strcmp (val, "always")) |
266 | node->connectmode = conf_node::C_ALWAYS; |
278 | node->connectmode = conf_node::C_ALWAYS; |
|
|
279 | else if (!strcmp (val, "disabled")) |
|
|
280 | node->connectmode = conf_node::C_DISABLED; |
267 | else |
281 | else |
268 | slog (L_WARN, |
282 | slog (L_WARN, |
269 | _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), |
283 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
270 | var, fname, lineno); |
284 | var, fname, lineno); |
271 | } |
285 | } |
|
|
286 | else if (!strcmp (var, "inherit-tos")) |
|
|
287 | { |
|
|
288 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
|
|
289 | } |
272 | else if (!strcmp (var, "compress")) |
290 | else if (!strcmp (var, "compress")) |
273 | { |
291 | { |
274 | if (!strcmp (val, "yes")) |
292 | parse_bool (node->compress, "compress", true, false); |
275 | node->compress = true; |
|
|
276 | else if (!strcmp (val, "no")) |
|
|
277 | node->compress = false; |
|
|
278 | else |
293 | } |
279 | slog (L_WARN, |
294 | // all these bool options really really cost a lot of executable size! |
280 | _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), |
295 | else if (!strcmp (var, "enable-udp")) |
281 | var, fname, lineno); |
296 | { |
|
|
297 | u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; |
|
|
298 | } |
|
|
299 | else if (!strcmp (var, "enable-rawip")) |
|
|
300 | { |
|
|
301 | u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; |
282 | } |
302 | } |
283 | |
303 | |
284 | // unknown or misplaced |
304 | // unknown or misplaced |
285 | else |
305 | else |
286 | { |
306 | { |
… | |
… | |
379 | connectmode == C_NEVER ? "never" : |
399 | connectmode == C_NEVER ? "never" : |
380 | connectmode == C_ALWAYS ? "always" : "", |
400 | connectmode == C_ALWAYS ? "always" : "", |
381 | nodename, |
401 | nodename, |
382 | hostname ? hostname : "", |
402 | hostname ? hostname : "", |
383 | hostname ? ":" : "", |
403 | hostname ? ":" : "", |
384 | hostname ? port : 0 |
404 | hostname ? udp_port : 0 |
385 | ); |
405 | ); |
386 | } |
406 | } |
387 | |
407 | |