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.44 by pcg, Thu Aug 7 17:54:26 2008 UTC vs.
Revision 1.53 by root, Tue Feb 8 23:13:48 2011 UTC

57char *thisnode; 57char *thisnode;
58char *identname; 58char *identname;
59 59
60struct configuration conf; 60struct configuration conf;
61 61
62u8
62u8 best_protocol (u8 protset) 63best_protocol (u8 protset)
63{ 64{
64 if (protset & PROT_IPv4 ) return PROT_IPv4; 65 if (protset & PROT_IPv4 ) return PROT_IPv4;
65 if (protset & PROT_ICMPv4) return PROT_ICMPv4; 66 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
66 if (protset & PROT_UDPv4 ) return PROT_UDPv4; 67 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
67 if (protset & PROT_TCPv4 ) return PROT_TCPv4; 68 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
68 if (protset & PROT_DNSv4 ) return PROT_DNSv4; 69 if (protset & PROT_DNSv4 ) return PROT_DNSv4;
69 70
70 return 0; 71 return 0;
71} 72}
72 73
74const char *
73const char *strprotocol (u8 protocol) 75strprotocol (u8 protocol)
74{ 76{
75 if (protocol & PROT_IPv4 ) return "rawip"; 77 if (protocol & PROT_IPv4 ) return "rawip";
76 if (protocol & PROT_ICMPv4) return "icmp"; 78 if (protocol & PROT_ICMPv4) return "icmp";
77 if (protocol & PROT_UDPv4 ) return "udp"; 79 if (protocol & PROT_UDPv4 ) return "udp";
78 if (protocol & PROT_TCPv4 ) return "tcp"; 80 if (protocol & PROT_TCPv4 ) return "tcp";
92 94
93 return false; 95 return false;
94} 96}
95 97
96bool 98bool
97conf_node::can_direct (struct conf_node *other) 99conf_node::may_direct (struct conf_node *other)
98{ 100{
99 if (match_list (allow_direct, other->nodename)) 101 if (match_list (allow_direct, other->nodename))
100 return true; 102 return true;
101 103
102 if (match_list (deny_direct, other->nodename)) 104 if (match_list (deny_direct, other->nodename))
110{ 112{
111 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", 113 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
112 id, 114 id,
113 id >> 8, id & 0xff, 115 id >> 8, id & 0xff,
114 compress ? 'Y' : 'N', 116 compress ? 'Y' : 'N',
115 connectmode == C_ONDEMAND ? "ondemand" : 117 connectmode == C_ONDEMAND ? "ondemand"
116 connectmode == C_NEVER ? "never" : 118 : connectmode == C_NEVER ? "never"
117 connectmode == C_ALWAYS ? "always" : "", 119 : connectmode == C_ALWAYS ? "always"
120 : connectmode == C_DISABLED ? "disabled"
121 : "",
118 nodename, 122 nodename,
119 hostname ? hostname : "", 123 hostname ? hostname : "",
120 hostname ? ":" : "", 124 hostname ? ":" : "",
121 hostname ? udp_port : 0 125 hostname ? udp_port : 0
122 ); 126 );
138 free (dns_hostname); 142 free (dns_hostname);
139#endif 143#endif
140#endif 144#endif
141} 145}
142 146
147void
143void configuration::init () 148configuration::init ()
144{ 149{
145 memset (this, 0, sizeof (*this)); 150 memset (this, 0, sizeof (*this));
146 151
147 mtu = DEFAULT_MTU; 152 mtu = DEFAULT_MTU;
153 nfmark = 0;
148 rekey = DEFAULT_REKEY; 154 rekey = DEFAULT_REKEY;
149 keepalive = DEFAULT_KEEPALIVE; 155 keepalive = DEFAULT_KEEPALIVE;
150 llevel = L_INFO; 156 llevel = L_INFO;
151 ip_proto = IPPROTO_GRE; 157 ip_proto = IPPROTO_GRE;
152#if ENABLE_ICMP 158#if ENABLE_ICMP
175#endif 181#endif
176 182
177 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); 183 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
178} 184}
179 185
186void
180void configuration::cleanup() 187configuration::cleanup ()
181{ 188{
182 if (rsa_key) 189 if (rsa_key)
183 RSA_free (rsa_key); 190 RSA_free (rsa_key);
184 191
185 rsa_key = 0; 192 rsa_key = 0;
186 193
187 free (pidfilename); pidfilename = 0; 194 free (pidfilename); pidfilename = 0;
188 free (ifname); ifname = 0; 195 free (ifname); ifname = 0;
189#if ENABLE_HTTP_PROXY 196#if ENABLE_HTTP_PROXY
190 free (proxy_host); proxy_host = 0; 197 free (proxy_host); proxy_host = 0;
191 free (proxy_auth); proxy_auth = 0; 198 free (proxy_auth); proxy_auth = 0;
192#endif 199#endif
193#if ENABLE_DNS 200#if ENABLE_DNS
194 free (dns_forw_host); dns_forw_host = 0; 201 free (dns_forw_host); dns_forw_host = 0;
195#endif 202#endif
203 free (script_if_up); script_if_up = 0;
204 free (script_node_up); script_node_up = 0;
205 free (script_node_change); script_node_change = 0;
206 free (script_node_down); script_node_down = 0;
196} 207}
197 208
198void 209void
199configuration::clear () 210configuration::clear ()
200{ 211{
328 conf.rekey = atoi (val); 339 conf.rekey = atoi (val);
329 else if (!strcmp (var, "keepalive")) 340 else if (!strcmp (var, "keepalive"))
330 conf.keepalive = atoi (val); 341 conf.keepalive = atoi (val);
331 else if (!strcmp (var, "mtu")) 342 else if (!strcmp (var, "mtu"))
332 conf.mtu = atoi (val); 343 conf.mtu = atoi (val);
344 else if (!strcmp (var, "nfmark"))
345 conf.nfmark = atoi (val);
333 else if (!strcmp (var, "if-up")) 346 else if (!strcmp (var, "if-up"))
334 free (conf.script_if_up), conf.script_if_up = strdup (val); 347 free (conf.script_if_up), conf.script_if_up = strdup (val);
335 else if (!strcmp (var, "node-up")) 348 else if (!strcmp (var, "node-up"))
336 free (conf.script_node_up), conf.script_node_up = strdup (val); 349 free (conf.script_node_up), conf.script_node_up = strdup (val);
350 else if (!strcmp (var, "node-change"))
351 free (conf.script_node_change), conf.script_node_change = strdup (val);
337 else if (!strcmp (var, "node-down")) 352 else if (!strcmp (var, "node-down"))
338 free (conf.script_node_down), conf.script_node_down = strdup (val); 353 free (conf.script_node_down), conf.script_node_down = strdup (val);
339 else if (!strcmp (var, "pid-file")) 354 else if (!strcmp (var, "pid-file"))
340 free (conf.pidfilename), conf.pidfilename = strdup (val); 355 free (conf.pidfilename), conf.pidfilename = strdup (val);
341 else if (!strcmp (var, "dns-forw-host")) 356 else if (!strcmp (var, "dns-forw-host"))
484 return _("unknown configuration directive. (ignored)"); 499 return _("unknown configuration directive. (ignored)");
485 500
486 return 0; 501 return 0;
487} 502}
488 503
504void
505conf_node::finalise ()
506{
507 if (max_queue < 1)
508 {
509 slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename);
510 max_queue = 1;
511 }
512
513 if (routerprio > 1 && (connectmode != C_ALWAYS && connectmode != C_DISABLED))
514 {
515 //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename);
516 connectmode = C_ALWAYS;
517 }
518}
519
520void
489void configuration_parser::parse_argv () 521configuration_parser::parse_argv ()
490{ 522{
491 for (int i = 0; i < argc; ++i) 523 for (int i = 0; i < argc; ++i)
492 { 524 {
493 char *v = argv [i]; 525 char *v = argv [i];
494 526
596 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); 628 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
597 exit (EXIT_FAILURE); 629 exit (EXIT_FAILURE);
598 } 630 }
599 631
600 free (fname); 632 free (fname);
601}
602 633
634 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i)
635 (*i)->finalise ();
636}
637
638char *
603char *configuration::config_filename (const char *name, const char *dflt) 639configuration::config_filename (const char *name, const char *dflt)
604{ 640{
605 char *fname; 641 char *fname;
606 642
607 asprintf (&fname, name ? name : dflt, ::thisnode); 643 asprintf (&fname, name ? name : dflt, ::thisnode);
608 644
649configuration::~configuration () 685configuration::~configuration ()
650{ 686{
651 cleanup (); 687 cleanup ();
652} 688}
653 689
654

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines