… | |
… | |
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 | |
… | |
… | |
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; |
70 | llevel = L_INFO; |
72 | llevel = L_INFO; |
|
|
73 | ip_proto = IPPROTO_GRE; |
71 | |
74 | |
72 | default_node.port = DEFAULT_PORT; |
75 | default_node.udp_port = DEFAULT_UDPPORT; |
73 | default_node.connectmode = conf_node::C_ALWAYS; |
76 | default_node.connectmode = conf_node::C_ALWAYS; |
74 | default_node.compress = true; |
77 | default_node.compress = true; |
|
|
78 | default_node.can_send = PROT_UDPv4; |
|
|
79 | default_node.can_recv = PROT_IPv4; |
75 | } |
80 | } |
76 | |
81 | |
77 | void configuration::cleanup() |
82 | void configuration::cleanup() |
78 | { |
83 | { |
79 | if (rsa_key) |
84 | if (rsa_key) |
… | |
… | |
94 | nodes.clear (); |
99 | nodes.clear (); |
95 | |
100 | |
96 | cleanup (); |
101 | cleanup (); |
97 | init (); |
102 | init (); |
98 | } |
103 | } |
|
|
104 | |
|
|
105 | #define parse_bool(target,name,trueval,falseval) \ |
|
|
106 | if (!strcmp (val, "yes")) target = trueval; \ |
|
|
107 | else if (!strcmp (val, "no")) target = falseval; \ |
|
|
108 | else if (!strcmp (val, "true")) target = trueval; \ |
|
|
109 | else if (!strcmp (val, "false")) target = falseval; \ |
|
|
110 | else if (!strcmp (val, "on")) target = trueval; \ |
|
|
111 | else if (!strcmp (val, "off")) target = falseval; \ |
|
|
112 | else \ |
|
|
113 | slog (L_WARN, \ |
|
|
114 | _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ |
|
|
115 | name, var, fname, lineno); |
99 | |
116 | |
100 | void configuration::read_config (bool need_keys) |
117 | void configuration::read_config (bool need_keys) |
101 | { |
118 | { |
102 | char *fname; |
119 | char *fname; |
103 | FILE *f; |
120 | FILE *f; |
… | |
… | |
167 | if (l != L_NONE) |
184 | if (l != L_NONE) |
168 | llevel = l; |
185 | llevel = l; |
169 | else |
186 | else |
170 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
187 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
171 | } |
188 | } |
|
|
189 | else if (!strcmp (var, "ip-proto")) |
|
|
190 | ip_proto = atoi (val); |
172 | |
191 | |
173 | // per config |
192 | // per config |
174 | else if (!strcmp (var, "node")) |
193 | else if (!strcmp (var, "node")) |
175 | { |
194 | { |
176 | default_node.id++; |
195 | default_node.id++; |
… | |
… | |
219 | } |
238 | } |
220 | else if (!strcmp (var, "private-key")) |
239 | else if (!strcmp (var, "private-key")) |
221 | prikeyfile = strdup (val); |
240 | prikeyfile = strdup (val); |
222 | else if (!strcmp (var, "ifpersist")) |
241 | else if (!strcmp (var, "ifpersist")) |
223 | { |
242 | { |
224 | if (!strcmp (val, "yes")) |
243 | parse_bool (ifpersist, "ifpersist", true, false); |
225 | ifpersist = true; |
|
|
226 | else if (!strcmp (val, "no")) |
|
|
227 | ifpersist = false; |
|
|
228 | else |
|
|
229 | slog (L_WARN, |
|
|
230 | _("illegal value for 'ifpersist', only 'yes' or 'no' allowed, at '%s' line %d"), |
|
|
231 | var, fname, lineno); |
|
|
232 | } |
244 | } |
233 | else if (!strcmp (var, "ifname")) |
245 | else if (!strcmp (var, "ifname")) |
234 | ifname = strdup (val); |
246 | ifname = strdup (val); |
235 | else if (!strcmp (var, "rekey")) |
247 | else if (!strcmp (var, "rekey")) |
236 | rekey = atoi (val); |
248 | rekey = atoi (val); |
… | |
… | |
252 | node->hostname = strdup (val); |
264 | node->hostname = strdup (val); |
253 | } |
265 | } |
254 | |
266 | |
255 | /* node-specific, defaultable */ |
267 | /* node-specific, defaultable */ |
256 | else if (!strcmp (var, "udp-port")) |
268 | else if (!strcmp (var, "udp-port")) |
257 | node->port = atoi (val); |
269 | node->udp_port = atoi (val); |
258 | else if (!strcmp (var, "port")) //deprecated |
|
|
259 | node->port = atoi (val); |
|
|
260 | else if (!strcmp (var, "router-priority")) |
270 | else if (!strcmp (var, "router-priority")) |
261 | node->routerprio = atoi (val); |
271 | node->routerprio = atoi (val); |
262 | else if (!strcmp (var, "connect")) |
272 | else if (!strcmp (var, "connect")) |
263 | { |
273 | { |
264 | if (!strcmp (val, "ondemand")) |
274 | if (!strcmp (val, "ondemand")) |
… | |
… | |
274 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
284 | _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), |
275 | var, fname, lineno); |
285 | var, fname, lineno); |
276 | } |
286 | } |
277 | else if (!strcmp (var, "inherit-tos")) |
287 | else if (!strcmp (var, "inherit-tos")) |
278 | { |
288 | { |
279 | if (!strcmp (val, "yes")) |
289 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
280 | node->inherit_tos = true; |
|
|
281 | else if (!strcmp (val, "no")) |
|
|
282 | node->inherit_tos = false; |
|
|
283 | else |
290 | } |
284 | slog (L_WARN, |
|
|
285 | _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), |
|
|
286 | var, fname, lineno); |
|
|
287 | } |
|
|
288 | |
|
|
289 | else if (!strcmp (var, "compress")) |
291 | else if (!strcmp (var, "compress")) |
290 | { |
292 | { |
291 | if (!strcmp (val, "yes")) |
293 | parse_bool (node->compress, "compress", true, false); |
292 | node->compress = true; |
294 | } |
|
|
295 | // all these bool options really really cost a lot of executable size! |
293 | else if (!strcmp (val, "no")) |
296 | else if (!strcmp (var, "can-send-udp")) |
294 | node->compress = false; |
|
|
295 | else |
297 | { |
296 | slog (L_WARN, |
298 | u8 v; parse_bool (v, "can-send-udp", PROT_UDPv4, 0); node->can_send = (node->can_send & ~PROT_UDPv4) | v; |
297 | _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), |
299 | } |
298 | var, fname, lineno); |
300 | else if (!strcmp (var, "can-recv-udp")) |
|
|
301 | { |
|
|
302 | u8 v; parse_bool (v, "can-recv-udp", PROT_UDPv4, 0); node->can_recv = (node->can_recv & ~PROT_UDPv4) | v; |
|
|
303 | } |
|
|
304 | else if (!strcmp (var, "can-send-rawip")) |
|
|
305 | { |
|
|
306 | u8 v; parse_bool (v, "can-send-rawip", PROT_IPv4, 0); node->can_send = (node->can_send & ~PROT_IPv4) | v; |
|
|
307 | } |
|
|
308 | else if (!strcmp (var, "can-recv-rawip")) |
|
|
309 | { |
|
|
310 | u8 v; parse_bool (v, "can-recv-rawip", PROT_IPv4, 0); node->can_recv = (node->can_recv & ~PROT_IPv4) | v; |
299 | } |
311 | } |
300 | |
312 | |
301 | // unknown or misplaced |
313 | // unknown or misplaced |
302 | else |
314 | else |
303 | { |
315 | { |
… | |
… | |
396 | connectmode == C_NEVER ? "never" : |
408 | connectmode == C_NEVER ? "never" : |
397 | connectmode == C_ALWAYS ? "always" : "", |
409 | connectmode == C_ALWAYS ? "always" : "", |
398 | nodename, |
410 | nodename, |
399 | hostname ? hostname : "", |
411 | hostname ? hostname : "", |
400 | hostname ? ":" : "", |
412 | hostname ? ":" : "", |
401 | hostname ? port : 0 |
413 | hostname ? udp_port : 0 |
402 | ); |
414 | ); |
403 | } |
415 | } |
404 | |
416 | |