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.5 by pcg, Fri Mar 28 04:05:10 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
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.can_send = PROT_UDPv4;
79 default_node.can_recv = PROT_IPv4;
74} 80}
75 81
76void configuration::cleanup() 82void configuration::cleanup()
77{ 83{
78 if (rsa_key) 84 if (rsa_key)
93 nodes.clear (); 99 nodes.clear ();
94 100
95 cleanup (); 101 cleanup ();
96 init (); 102 init ();
97} 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);
98 116
99void configuration::read_config (bool need_keys) 117void configuration::read_config (bool need_keys)
100{ 118{
101 char *fname; 119 char *fname;
102 FILE *f; 120 FILE *f;
162 if (!strcmp (var, "loglevel")) 180 if (!strcmp (var, "loglevel"))
163 { 181 {
164 loglevel l = string_to_loglevel (val); 182 loglevel l = string_to_loglevel (val);
165 183
166 if (l != L_NONE) 184 if (l != L_NONE)
167 set_loglevel (l); 185 llevel = l;
168 else 186 else
169 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);
170 } 188 }
189 else if (!strcmp (var, "ip-proto"))
190 ip_proto = atoi (val);
171 191
172 // per config 192 // per config
173 else if (!strcmp (var, "node")) 193 else if (!strcmp (var, "node"))
174 { 194 {
175 default_node.id++; 195 default_node.id++;
218 } 238 }
219 else if (!strcmp (var, "private-key")) 239 else if (!strcmp (var, "private-key"))
220 prikeyfile = strdup (val); 240 prikeyfile = strdup (val);
221 else if (!strcmp (var, "ifpersist")) 241 else if (!strcmp (var, "ifpersist"))
222 { 242 {
223 if (!strcmp (val, "yes")) 243 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 } 244 }
232 else if (!strcmp (var, "ifname")) 245 else if (!strcmp (var, "ifname"))
233 ifname = strdup (val); 246 ifname = strdup (val);
234 else if (!strcmp (var, "rekey")) 247 else if (!strcmp (var, "rekey"))
235 rekey = atoi (val); 248 rekey = atoi (val);
250 free (node->hostname); 263 free (node->hostname);
251 node->hostname = strdup (val); 264 node->hostname = strdup (val);
252 } 265 }
253 266
254 /* node-specific, defaultable */ 267 /* node-specific, defaultable */
255 else if (!strcmp (var, "port")) 268 else if (!strcmp (var, "udp-port"))
256 node->port = atoi (val); 269 node->udp_port = atoi (val);
257 else if (!strcmp (var, "router-priority")) 270 else if (!strcmp (var, "router-priority"))
258 node->routerprio = atoi (val); 271 node->routerprio = atoi (val);
259 else if (!strcmp (var, "connect")) 272 else if (!strcmp (var, "connect"))
260 { 273 {
261 if (!strcmp (val, "ondemand")) 274 if (!strcmp (val, "ondemand"))
262 node->connectmode = conf_node::C_ONDEMAND; 275 node->connectmode = conf_node::C_ONDEMAND;
263 else if (!strcmp (val, "never")) 276 else if (!strcmp (val, "never"))
264 node->connectmode = conf_node::C_NEVER; 277 node->connectmode = conf_node::C_NEVER;
265 else if (!strcmp (val, "always")) 278 else if (!strcmp (val, "always"))
266 node->connectmode = conf_node::C_ALWAYS; 279 node->connectmode = conf_node::C_ALWAYS;
280 else if (!strcmp (val, "disabled"))
281 node->connectmode = conf_node::C_DISABLED;
267 else 282 else
268 slog (L_WARN, 283 slog (L_WARN,
269 _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), 284 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"),
270 var, fname, lineno); 285 var, fname, lineno);
271 } 286 }
287 else if (!strcmp (var, "inherit-tos"))
288 {
289 parse_bool (node->inherit_tos, "inherit-tos", true, false);
290 }
272 else if (!strcmp (var, "compress")) 291 else if (!strcmp (var, "compress"))
273 { 292 {
274 if (!strcmp (val, "yes")) 293 parse_bool (node->compress, "compress", true, false);
275 node->compress = true; 294 }
295 // all these bool options really really cost a lot of executable size!
276 else if (!strcmp (val, "no")) 296 else if (!strcmp (var, "can-send-udp"))
277 node->compress = false;
278 else 297 {
279 slog (L_WARN, 298 u8 v; parse_bool (v, "can-send-udp", PROT_UDPv4, 0); node->can_send = (node->can_send & ~PROT_UDPv4) | v;
280 _("illegal value for 'compress', only 'yes' or 'no' allowed, at '%s' line %d"), 299 }
281 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;
282 } 311 }
283 312
284 // unknown or misplaced 313 // unknown or misplaced
285 else 314 else
286 { 315 {
379 connectmode == C_NEVER ? "never" : 408 connectmode == C_NEVER ? "never" :
380 connectmode == C_ALWAYS ? "always" : "", 409 connectmode == C_ALWAYS ? "always" : "",
381 nodename, 410 nodename,
382 hostname ? hostname : "", 411 hostname ? hostname : "",
383 hostname ? ":" : "", 412 hostname ? ":" : "",
384 hostname ? port : 0 413 hostname ? udp_port : 0
385 ); 414 );
386} 415}
387 416

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines