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.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.7 by pcg, Fri Mar 28 16:21:09 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)
59 return PROT_IPv4;
60
61 return PROT_UDPv4;
62}
63
64const char *strprotocol (u8 protocol)
65{
66 if (protocol & PROT_IPv4 ) return "rawip";
67 if (protocol & PROT_UDPv4) return "udp";
68
69 return "<unknown>";
70}
71
54configuration::configuration () 72configuration::configuration ()
55{ 73{
56 init (); 74 init ();
57} 75}
58 76
65{ 83{
66 memset (this, 0, sizeof (*this)); 84 memset (this, 0, sizeof (*this));
67 85
68 rekey = DEFAULT_REKEY; 86 rekey = DEFAULT_REKEY;
69 keepalive = DEFAULT_KEEPALIVE; 87 keepalive = DEFAULT_KEEPALIVE;
88 llevel = L_INFO;
89 ip_proto = IPPROTO_GRE;
70 90
71 default_node.port = DEFAULT_PORT; 91 default_node.udp_port = DEFAULT_UDPPORT;
72 default_node.connectmode = conf_node::C_ALWAYS; 92 default_node.connectmode = conf_node::C_ALWAYS;
73 default_node.compress = true; 93 default_node.compress = true;
94 default_node.protocols = PROT_UDPv4;
74} 95}
75 96
76void configuration::cleanup() 97void configuration::cleanup()
77{ 98{
78 if (rsa_key) 99 if (rsa_key)
93 nodes.clear (); 114 nodes.clear ();
94 115
95 cleanup (); 116 cleanup ();
96 init (); 117 init ();
97} 118}
119
120#define parse_bool(target,name,trueval,falseval) \
121 if (!strcmp (val, "yes")) target = trueval; \
122 else if (!strcmp (val, "no")) target = falseval; \
123 else if (!strcmp (val, "true")) target = trueval; \
124 else if (!strcmp (val, "false")) target = falseval; \
125 else if (!strcmp (val, "on")) target = trueval; \
126 else if (!strcmp (val, "off")) target = falseval; \
127 else \
128 slog (L_WARN, \
129 _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \
130 name, var, fname, lineno);
98 131
99void configuration::read_config (bool need_keys) 132void configuration::read_config (bool need_keys)
100{ 133{
101 char *fname; 134 char *fname;
102 FILE *f; 135 FILE *f;
162 if (!strcmp (var, "loglevel")) 195 if (!strcmp (var, "loglevel"))
163 { 196 {
164 loglevel l = string_to_loglevel (val); 197 loglevel l = string_to_loglevel (val);
165 198
166 if (l != L_NONE) 199 if (l != L_NONE)
167 set_loglevel (l); 200 llevel = l;
168 else 201 else
169 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); 202 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line);
170 } 203 }
204 else if (!strcmp (var, "ip-proto"))
205 ip_proto = atoi (val);
171 206
172 // per config 207 // per config
173 else if (!strcmp (var, "node")) 208 else if (!strcmp (var, "node"))
174 { 209 {
175 default_node.id++; 210 default_node.id++;
218 } 253 }
219 else if (!strcmp (var, "private-key")) 254 else if (!strcmp (var, "private-key"))
220 prikeyfile = strdup (val); 255 prikeyfile = strdup (val);
221 else if (!strcmp (var, "ifpersist")) 256 else if (!strcmp (var, "ifpersist"))
222 { 257 {
223 if (!strcmp (val, "yes")) 258 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 } 259 }
232 else if (!strcmp (var, "ifname")) 260 else if (!strcmp (var, "ifname"))
233 ifname = strdup (val); 261 ifname = strdup (val);
234 else if (!strcmp (var, "rekey")) 262 else if (!strcmp (var, "rekey"))
235 rekey = atoi (val); 263 rekey = atoi (val);
250 free (node->hostname); 278 free (node->hostname);
251 node->hostname = strdup (val); 279 node->hostname = strdup (val);
252 } 280 }
253 281
254 /* node-specific, defaultable */ 282 /* node-specific, defaultable */
255 else if (!strcmp (var, "port")) 283 else if (!strcmp (var, "udp-port"))
256 node->port = atoi (val); 284 node->udp_port = atoi (val);
257 else if (!strcmp (var, "router-priority")) 285 else if (!strcmp (var, "router-priority"))
258 node->routerprio = atoi (val); 286 node->routerprio = atoi (val);
259 else if (!strcmp (var, "connect")) 287 else if (!strcmp (var, "connect"))
260 { 288 {
261 if (!strcmp (val, "ondemand")) 289 if (!strcmp (val, "ondemand"))
262 node->connectmode = conf_node::C_ONDEMAND; 290 node->connectmode = conf_node::C_ONDEMAND;
263 else if (!strcmp (val, "never")) 291 else if (!strcmp (val, "never"))
264 node->connectmode = conf_node::C_NEVER; 292 node->connectmode = conf_node::C_NEVER;
265 else if (!strcmp (val, "always")) 293 else if (!strcmp (val, "always"))
266 node->connectmode = conf_node::C_ALWAYS; 294 node->connectmode = conf_node::C_ALWAYS;
295 else if (!strcmp (val, "disabled"))
296 node->connectmode = conf_node::C_DISABLED;
267 else 297 else
268 slog (L_WARN, 298 slog (L_WARN,
269 _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), 299 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"),
270 var, fname, lineno); 300 var, fname, lineno);
271 } 301 }
302 else if (!strcmp (var, "inherit-tos"))
303 {
304 parse_bool (node->inherit_tos, "inherit-tos", true, false);
305 }
272 else if (!strcmp (var, "compress")) 306 else if (!strcmp (var, "compress"))
273 { 307 {
274 if (!strcmp (val, "yes")) 308 parse_bool (node->compress, "compress", true, false);
275 node->compress = true;
276 else if (!strcmp (val, "no"))
277 node->compress = false;
278 else 309 }
279 slog (L_WARN, 310 // 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"), 311 else if (!strcmp (var, "enable-udp"))
281 var, fname, lineno); 312 {
313 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
314 }
315 else if (!strcmp (var, "enable-rawip"))
316 {
317 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
282 } 318 }
283 319
284 // unknown or misplaced 320 // unknown or misplaced
285 else 321 else
286 { 322 {
379 connectmode == C_NEVER ? "never" : 415 connectmode == C_NEVER ? "never" :
380 connectmode == C_ALWAYS ? "always" : "", 416 connectmode == C_ALWAYS ? "always" : "",
381 nodename, 417 nodename,
382 hostname ? hostname : "", 418 hostname ? hostname : "",
383 hostname ? ":" : "", 419 hostname ? ":" : "",
384 hostname ? port : 0 420 hostname ? udp_port : 0
385 ); 421 );
386} 422}
387 423

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines