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.16 by pcg, Tue Oct 14 03:22: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#include <arpa/inet.h>
38#ifdef ENABLE_ICMP
39# ifdef HAVE_NETINET_IN_SYSTM_H
40# include <netinet/in_systm.h>
41# endif
42# ifdef HAVE_NETINET_IP_H
43# include <netinet/ip.h>
44# endif
45# include <netinet/ip_icmp.h>
46#endif
47
36#include <openssl/err.h> 48#include <openssl/err.h>
37#include <openssl/pem.h> 49#include <openssl/pem.h>
38#include <openssl/rsa.h> 50#include <openssl/rsa.h>
39#include <openssl/rand.h> 51#include <openssl/rand.h>
40 52
49char *identname; 61char *identname;
50char *pidfilename; 62char *pidfilename;
51 63
52struct configuration conf; 64struct configuration conf;
53 65
54configuration::configuration () 66u8 best_protocol (u8 protset)
55{ 67{
56 init (); 68 if (protset & PROT_IPv4 ) return PROT_IPv4;
57} 69 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
70 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
71 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
58 72
59configuration::~configuration () 73 return 0;
74}
75
76const char *strprotocol (u8 protocol)
60{ 77{
61 cleanup (); 78 if (protocol & PROT_IPv4 ) return "rawip";
79 if (protocol & PROT_ICMPv4) return "icmp";
80 if (protocol & PROT_UDPv4 ) return "udp";
81 if (protocol & PROT_TCPv4 ) return "tcp";
82
83 return "<unknown>";
84}
85
86void
87conf_node::print ()
88{
89 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
90 id,
91 id >> 8, id & 0xff,
92 compress ? 'Y' : 'N',
93 connectmode == C_ONDEMAND ? "ondemand" :
94 connectmode == C_NEVER ? "never" :
95 connectmode == C_ALWAYS ? "always" : "",
96 nodename,
97 hostname ? hostname : "",
98 hostname ? ":" : "",
99 hostname ? udp_port : 0
100 );
101}
102
103conf_node::~conf_node ()
104{
105 if (rsa_key)
106 RSA_free (rsa_key);
107
108 free (nodename);
109 free (hostname);
62} 110}
63 111
64void configuration::init () 112void configuration::init ()
65{ 113{
66 memset (this, 0, sizeof (*this)); 114 memset (this, 0, sizeof (*this));
67 115
68 rekey = DEFAULT_REKEY; 116 rekey = DEFAULT_REKEY;
69 keepalive = DEFAULT_KEEPALIVE; 117 keepalive = DEFAULT_KEEPALIVE;
118 llevel = L_INFO;
119 ip_proto = IPPROTO_GRE;
120#if ENABLE_ICMP
121 icmp_type = ICMP_ECHOREPLY;
122#endif
70 123
71 default_node.port = DEFAULT_PORT; 124 default_node.udp_port = DEFAULT_UDPPORT;
125 default_node.tcp_port = DEFAULT_UDPPORT;
72 default_node.connectmode = conf_node::C_ALWAYS; 126 default_node.connectmode = conf_node::C_ALWAYS;
73 default_node.compress = true; 127 default_node.compress = true;
128 default_node.protocols = PROT_UDPv4;
74} 129}
75 130
76void configuration::cleanup() 131void configuration::cleanup()
77{ 132{
78 if (rsa_key) 133 if (rsa_key)
79 RSA_free (rsa_key); 134 RSA_free (rsa_key);
80 135
81 free (ifname);
82
83 rsa_key = 0; 136 rsa_key = 0;
84 ifname = 0; 137
138 free (ifname); ifname = 0;
139#if ENABLE_HTTP_PROXY
140 free (proxy_host); proxy_host = 0;
141 free (proxy_auth); proxy_auth = 0;
142#endif
85} 143}
86 144
87void 145void
88configuration::clear_config () 146configuration::clear_config ()
89{ 147{
93 nodes.clear (); 151 nodes.clear ();
94 152
95 cleanup (); 153 cleanup ();
96 init (); 154 init ();
97} 155}
156
157#define parse_bool(target,name,trueval,falseval) \
158 if (!strcmp (val, "yes")) target = trueval; \
159 else if (!strcmp (val, "no")) target = falseval; \
160 else if (!strcmp (val, "true")) target = trueval; \
161 else if (!strcmp (val, "false")) target = falseval; \
162 else if (!strcmp (val, "on")) target = trueval; \
163 else if (!strcmp (val, "off")) target = falseval; \
164 else \
165 slog (L_WARN, \
166 _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \
167 name, var, fname, lineno);
98 168
99void configuration::read_config (bool need_keys) 169void configuration::read_config (bool need_keys)
100{ 170{
101 char *fname; 171 char *fname;
102 FILE *f; 172 FILE *f;
162 if (!strcmp (var, "loglevel")) 232 if (!strcmp (var, "loglevel"))
163 { 233 {
164 loglevel l = string_to_loglevel (val); 234 loglevel l = string_to_loglevel (val);
165 235
166 if (l != L_NONE) 236 if (l != L_NONE)
167 set_loglevel (l); 237 llevel = l;
168 else 238 else
169 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); 239 slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line);
170 } 240 }
241 else if (!strcmp (var, "ip-proto"))
242 ip_proto = atoi (val);
243#if ENABLE_ICMP
244 //TODO: error message
245 else if (!strcmp (var, "icmp-type"))
246 icmp_type = atoi (val);
247#endif
171 248
172 // per config 249 // per config
173 else if (!strcmp (var, "node")) 250 else if (!strcmp (var, "node"))
174 { 251 {
175 default_node.id++; 252 default_node.id++;
218 } 295 }
219 else if (!strcmp (var, "private-key")) 296 else if (!strcmp (var, "private-key"))
220 prikeyfile = strdup (val); 297 prikeyfile = strdup (val);
221 else if (!strcmp (var, "ifpersist")) 298 else if (!strcmp (var, "ifpersist"))
222 { 299 {
223 if (!strcmp (val, "yes")) 300 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 } 301 }
232 else if (!strcmp (var, "ifname")) 302 else if (!strcmp (var, "ifname"))
233 ifname = strdup (val); 303 ifname = strdup (val);
234 else if (!strcmp (var, "rekey")) 304 else if (!strcmp (var, "rekey"))
235 rekey = atoi (val); 305 rekey = atoi (val);
241 script_if_up = strdup (val); 311 script_if_up = strdup (val);
242 else if (!strcmp (var, "node-up")) 312 else if (!strcmp (var, "node-up"))
243 script_node_up = strdup (val); 313 script_node_up = strdup (val);
244 else if (!strcmp (var, "node-down")) 314 else if (!strcmp (var, "node-down"))
245 script_node_down = strdup (val); 315 script_node_down = strdup (val);
316#if ENABLE_HTTP_PROXY
317 else if (!strcmp (var, "http-proxy-host"))
318 proxy_host = strdup (val);
319 else if (!strcmp (var, "http-proxy-port"))
320 proxy_port = atoi (val);
321 else if (!strcmp (var, "http-proxy-auth"))
322 proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val));
323#endif
246 324
247 /* node-specific, non-defaultable */ 325 /* node-specific, non-defaultable */
248 else if (node != &default_node && !strcmp (var, "hostname")) 326 else if (node != &default_node && !strcmp (var, "hostname"))
249 { 327 {
250 free (node->hostname); 328 free (node->hostname);
251 node->hostname = strdup (val); 329 node->hostname = strdup (val);
252 } 330 }
253 331
254 /* node-specific, defaultable */ 332 /* node-specific, defaultable */
255 else if (!strcmp (var, "port")) 333 else if (!strcmp (var, "udp-port"))
256 node->port = atoi (val); 334 node->udp_port = atoi (val);
335 else if (!strcmp (var, "tcp-port"))
336 node->tcp_port = atoi (val);
257 else if (!strcmp (var, "router-priority")) 337 else if (!strcmp (var, "router-priority"))
258 node->routerprio = atoi (val); 338 node->routerprio = atoi (val);
259 else if (!strcmp (var, "connect")) 339 else if (!strcmp (var, "connect"))
260 { 340 {
261 if (!strcmp (val, "ondemand")) 341 if (!strcmp (val, "ondemand"))
262 node->connectmode = conf_node::C_ONDEMAND; 342 node->connectmode = conf_node::C_ONDEMAND;
263 else if (!strcmp (val, "never")) 343 else if (!strcmp (val, "never"))
264 node->connectmode = conf_node::C_NEVER; 344 node->connectmode = conf_node::C_NEVER;
265 else if (!strcmp (val, "always")) 345 else if (!strcmp (val, "always"))
266 node->connectmode = conf_node::C_ALWAYS; 346 node->connectmode = conf_node::C_ALWAYS;
347 else if (!strcmp (val, "disabled"))
348 node->connectmode = conf_node::C_DISABLED;
267 else 349 else
268 slog (L_WARN, 350 slog (L_WARN,
269 _("illegal value for 'connectmode', use one of 'ondemand', 'never' or 'always', at '%s' line %d"), 351 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"),
270 var, fname, lineno); 352 var, fname, lineno);
271 } 353 }
354 else if (!strcmp (var, "inherit-tos"))
355 {
356 parse_bool (node->inherit_tos, "inherit-tos", true, false);
357 }
272 else if (!strcmp (var, "compress")) 358 else if (!strcmp (var, "compress"))
273 { 359 {
274 if (!strcmp (val, "yes")) 360 parse_bool (node->compress, "compress", true, false);
275 node->compress = true;
276 else if (!strcmp (val, "no"))
277 node->compress = false;
278 else 361 }
279 slog (L_WARN, 362 // 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"), 363 else if (!strcmp (var, "enable-tcp"))
281 var, fname, lineno); 364 {
365#if ENABLE_TCP
366 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
367#endif
368 }
369 else if (!strcmp (var, "enable-icmp"))
370 {
371#if ENABLE_ICMP
372 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
373#endif
374 }
375 else if (!strcmp (var, "enable-udp"))
376 {
377 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
378 }
379 else if (!strcmp (var, "enable-rawip"))
380 {
381 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
282 } 382 }
283 383
284 // unknown or misplaced 384 // unknown or misplaced
285 else 385 else
286 {
287 slog (L_WARN, 386 slog (L_WARN,
288 _("unknown or misplaced variable `%s', at '%s' line %d"), 387 _("unknown or misplaced variable `%s', at '%s' line %d"),
289 var, fname, lineno); 388 var, fname, lineno);
290 }
291 } 389 }
292 390
293 fclose (f); 391 fclose (f);
294 } 392 }
295 else 393 else
354 printf (_("MTU: %d\n"), mtu); 452 printf (_("MTU: %d\n"), mtu);
355 printf (_("rekeying interval: %d\n"), rekey); 453 printf (_("rekeying interval: %d\n"), rekey);
356 printf (_("keepalive interval: %d\n"), keepalive); 454 printf (_("keepalive interval: %d\n"), keepalive);
357 printf (_("interface: %s\n"), ifname); 455 printf (_("interface: %s\n"), ifname);
358 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); 456 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>");
359 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) : -1); 457 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1);
360 printf ("\n"); 458 printf ("\n");
361 459
362 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", 460 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n",
363 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); 461 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port"));
364 462
366 (*i)->print (); 464 (*i)->print ();
367 465
368 printf ("\n"); 466 printf ("\n");
369} 467}
370 468
371void 469configuration::configuration ()
372conf_node::print ()
373{ 470{
374 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 471 init ();
375 id,
376 id >> 8, id & 0xff,
377 compress ? 'Y' : 'N',
378 connectmode == C_ONDEMAND ? "ondemand" :
379 connectmode == C_NEVER ? "never" :
380 connectmode == C_ALWAYS ? "always" : "",
381 nodename,
382 hostname ? hostname : "",
383 hostname ? ":" : "",
384 hostname ? port : 0
385 );
386} 472}
387 473
474configuration::~configuration ()
475{
476 cleanup ();
477}
478
479

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines