ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/conf.C
(Generate patch)

Comparing gvpe/src/conf.C (file contents):
Revision 1.3 by pcg, Sun Mar 9 12:40:18 2003 UTC vs.
Revision 1.11 by pcg, Wed Apr 2 21:43:44 2003 UTC

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
49char *identname; 51char *identname;
50char *pidfilename; 52char *pidfilename;
51 53
52struct configuration conf; 54struct configuration conf;
53 55
56u8 best_protocol (u8 protset)
57{
58 if (protset & PROT_IPv4 ) return PROT_IPv4;
59 if (protset & PROT_UDPv4) return PROT_UDPv4;
60 if (protset & PROT_TCPv4) return PROT_TCPv4;
61
62 return 0;
63}
64
65const char *strprotocol (u8 protocol)
66{
67 if (protocol & PROT_IPv4 ) return "rawip";
68 if (protocol & PROT_UDPv4) return "udp";
69 if (protocol & PROT_TCPv4) return "tcp";
70
71 return "<unknown>";
72}
73
54configuration::configuration () 74configuration::configuration ()
55{ 75{
56 init (); 76 init ();
57} 77}
58 78
66 memset (this, 0, sizeof (*this)); 86 memset (this, 0, sizeof (*this));
67 87
68 rekey = DEFAULT_REKEY; 88 rekey = DEFAULT_REKEY;
69 keepalive = DEFAULT_KEEPALIVE; 89 keepalive = DEFAULT_KEEPALIVE;
70 llevel = L_INFO; 90 llevel = L_INFO;
91 ip_proto = IPPROTO_GRE;
71 92
72 default_node.port = DEFAULT_PORT; 93 default_node.udp_port = DEFAULT_UDPPORT;
94 default_node.tcp_port = DEFAULT_UDPPORT;
73 default_node.connectmode = conf_node::C_ALWAYS; 95 default_node.connectmode = conf_node::C_ALWAYS;
74 default_node.compress = true; 96 default_node.compress = true;
97 default_node.protocols = PROT_UDPv4;
75} 98}
76 99
77void configuration::cleanup() 100void configuration::cleanup()
78{ 101{
79 if (rsa_key) 102 if (rsa_key)
94 nodes.clear (); 117 nodes.clear ();
95 118
96 cleanup (); 119 cleanup ();
97 init (); 120 init ();
98} 121}
122
123#define parse_bool(target,name,trueval,falseval) \
124 if (!strcmp (val, "yes")) target = trueval; \
125 else if (!strcmp (val, "no")) target = falseval; \
126 else if (!strcmp (val, "true")) target = trueval; \
127 else if (!strcmp (val, "false")) target = falseval; \
128 else if (!strcmp (val, "on")) target = trueval; \
129 else if (!strcmp (val, "off")) target = falseval; \
130 else \
131 slog (L_WARN, \
132 _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \
133 name, var, fname, lineno);
99 134
100void configuration::read_config (bool need_keys) 135void configuration::read_config (bool need_keys)
101{ 136{
102 char *fname; 137 char *fname;
103 FILE *f; 138 FILE *f;
167 if (l != L_NONE) 202 if (l != L_NONE)
168 llevel = l; 203 llevel = l;
169 else 204 else
170 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); 205 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line);
171 } 206 }
207 else if (!strcmp (var, "ip-proto"))
208 ip_proto = atoi (val);
172 209
173 // per config 210 // per config
174 else if (!strcmp (var, "node")) 211 else if (!strcmp (var, "node"))
175 { 212 {
176 default_node.id++; 213 default_node.id++;
219 } 256 }
220 else if (!strcmp (var, "private-key")) 257 else if (!strcmp (var, "private-key"))
221 prikeyfile = strdup (val); 258 prikeyfile = strdup (val);
222 else if (!strcmp (var, "ifpersist")) 259 else if (!strcmp (var, "ifpersist"))
223 { 260 {
224 if (!strcmp (val, "yes")) 261 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 } 262 }
233 else if (!strcmp (var, "ifname")) 263 else if (!strcmp (var, "ifname"))
234 ifname = strdup (val); 264 ifname = strdup (val);
235 else if (!strcmp (var, "rekey")) 265 else if (!strcmp (var, "rekey"))
236 rekey = atoi (val); 266 rekey = atoi (val);
251 free (node->hostname); 281 free (node->hostname);
252 node->hostname = strdup (val); 282 node->hostname = strdup (val);
253 } 283 }
254 284
255 /* node-specific, defaultable */ 285 /* node-specific, defaultable */
256 else if (!strcmp (var, "port")) 286 else if (!strcmp (var, "udp-port"))
257 node->port = atoi (val); 287 node->udp_port = atoi (val);
288 else if (!strcmp (var, "tcp-port"))
289 node->tcp_port = atoi (val);
258 else if (!strcmp (var, "router-priority")) 290 else if (!strcmp (var, "router-priority"))
259 node->routerprio = atoi (val); 291 node->routerprio = atoi (val);
260 else if (!strcmp (var, "connect")) 292 else if (!strcmp (var, "connect"))
261 { 293 {
262 if (!strcmp (val, "ondemand")) 294 if (!strcmp (val, "ondemand"))
263 node->connectmode = conf_node::C_ONDEMAND; 295 node->connectmode = conf_node::C_ONDEMAND;
264 else if (!strcmp (val, "never")) 296 else if (!strcmp (val, "never"))
265 node->connectmode = conf_node::C_NEVER; 297 node->connectmode = conf_node::C_NEVER;
266 else if (!strcmp (val, "always")) 298 else if (!strcmp (val, "always"))
267 node->connectmode = conf_node::C_ALWAYS; 299 node->connectmode = conf_node::C_ALWAYS;
300 else if (!strcmp (val, "disabled"))
301 node->connectmode = conf_node::C_DISABLED;
268 else 302 else
269 slog (L_WARN, 303 slog (L_WARN,
270 _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), 304 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"),
271 var, fname, lineno); 305 var, fname, lineno);
272 } 306 }
273 else if (!strcmp (var, "inherit-tos")) 307 else if (!strcmp (var, "inherit-tos"))
274 { 308 {
275 if (!strcmp (val, "yes")) 309 parse_bool (node->inherit_tos, "inherit-tos", true, false);
276 node->inherit_tos = true;
277 else if (!strcmp (val, "no"))
278 node->inherit_tos = false;
279 else 310 }
280 slog (L_WARN,
281 _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"),
282 var, fname, lineno);
283 }
284
285 else if (!strcmp (var, "compress")) 311 else if (!strcmp (var, "compress"))
286 { 312 {
287 if (!strcmp (val, "yes")) 313 parse_bool (node->compress, "compress", true, false);
288 node->compress = true;
289 else if (!strcmp (val, "no"))
290 node->compress = false;
291 else 314 }
292 slog (L_WARN, 315 // all these bool options really really cost a lot of executable size!
293 _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), 316 else if (!strcmp (var, "enable-tcp"))
294 var, fname, lineno); 317 {
318#if ENABLE_TCP
319 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
320#endif
321 }
322 else if (!strcmp (var, "enable-udp"))
323 {
324 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
325 }
326 else if (!strcmp (var, "enable-rawip"))
327 {
328 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
295 } 329 }
296 330
297 // unknown or misplaced 331 // unknown or misplaced
298 else 332 else
299 { 333 {
392 connectmode == C_NEVER ? "never" : 426 connectmode == C_NEVER ? "never" :
393 connectmode == C_ALWAYS ? "always" : "", 427 connectmode == C_ALWAYS ? "always" : "",
394 nodename, 428 nodename,
395 hostname ? hostname : "", 429 hostname ? hostname : "",
396 hostname ? ":" : "", 430 hostname ? ":" : "",
397 hostname ? port : 0 431 hostname ? udp_port : 0
398 ); 432 );
399} 433}
400 434

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines