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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines