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.51 by pcg, Sat Jul 18 05:59:16 2009 UTC vs.
Revision 1.54 by root, Tue Feb 15 13:31:23 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";
103 return false; 105 return false;
104 106
105 return true; 107 return true;
106} 108}
107 109
108void
109conf_node::print ()
110{
111 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n",
112 id,
113 id >> 8, id & 0xff,
114 compress ? 'Y' : 'N',
115 connectmode == C_ONDEMAND ? "ondemand"
116 : connectmode == C_NEVER ? "never"
117 : connectmode == C_ALWAYS ? "always"
118 : connectmode == C_DISABLED ? "disabled"
119 : "",
120 nodename,
121 hostname ? hostname : "",
122 hostname ? ":" : "",
123 hostname ? udp_port : 0
124 );
125}
126
127conf_node::~conf_node () 110conf_node::~conf_node ()
128{ 111{
129#if 0 112#if 0
130 // does not work, because string pointers etc. are shared 113 // does not work, because string pointers etc. are shared
131 // is not called, however 114 // is not called, however
140 free (dns_hostname); 123 free (dns_hostname);
141#endif 124#endif
142#endif 125#endif
143} 126}
144 127
128void
145void configuration::init () 129configuration::init ()
146{ 130{
147 memset (this, 0, sizeof (*this)); 131 memset (this, 0, sizeof (*this));
148 132
149 mtu = DEFAULT_MTU; 133 mtu = DEFAULT_MTU;
150 nfmark = 0; 134 nfmark = 0;
178#endif 162#endif
179 163
180 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); 164 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
181} 165}
182 166
167void
183void configuration::cleanup() 168configuration::cleanup ()
184{ 169{
185 if (rsa_key) 170 if (rsa_key)
186 RSA_free (rsa_key); 171 RSA_free (rsa_key);
187 172
188 rsa_key = 0; 173 rsa_key = 0;
189 174
190 free (pidfilename); pidfilename = 0; 175 free (pidfilename); pidfilename = 0;
191 free (ifname); ifname = 0; 176 free (ifname); ifname = 0;
192#if ENABLE_HTTP_PROXY 177#if ENABLE_HTTP_PROXY
193 free (proxy_host); proxy_host = 0; 178 free (proxy_host); proxy_host = 0;
194 free (proxy_auth); proxy_auth = 0; 179 free (proxy_auth); proxy_auth = 0;
195#endif 180#endif
196#if ENABLE_DNS 181#if ENABLE_DNS
197 free (dns_forw_host); dns_forw_host = 0; 182 free (dns_forw_host); dns_forw_host = 0;
198#endif 183#endif
199 free (script_if_up); script_if_up = 0; 184 free (script_if_up); script_if_up = 0;
200 free (script_node_up); script_node_up = 0; 185 free (script_node_up); script_node_up = 0;
201 free (script_node_change); script_node_change = 0; 186 free (script_node_change); script_node_change = 0;
495 return _("unknown configuration directive. (ignored)"); 480 return _("unknown configuration directive. (ignored)");
496 481
497 return 0; 482 return 0;
498} 483}
499 484
485void
500void conf_node::finalise () 486conf_node::finalise ()
501{ 487{
502 if (max_queue < 1) 488 if (max_queue < 1)
503 { 489 {
504 slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename); 490 slog (L_WARN, _("%s: max-queue value invalid, setting it to 1."), nodename);
505 max_queue = 1; 491 max_queue = 1;
510 //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename); 496 //slog (L_WARN, _("%s: has non-zero router-priority but either 'never' or 'ondemand' as connectmode, setting it to 'always'."), nodename);
511 connectmode = C_ALWAYS; 497 connectmode = C_ALWAYS;
512 } 498 }
513} 499}
514 500
501void
515void configuration_parser::parse_argv () 502configuration_parser::parse_argv ()
516{ 503{
517 for (int i = 0; i < argc; ++i) 504 for (int i = 0; i < argc; ++i)
518 { 505 {
519 char *v = argv [i]; 506 char *v = argv [i];
520 507
627 614
628 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) 615 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i)
629 (*i)->finalise (); 616 (*i)->finalise ();
630} 617}
631 618
619char *
632char *configuration::config_filename (const char *name, const char *dflt) 620configuration::config_filename (const char *name, const char *dflt)
633{ 621{
634 char *fname; 622 char *fname;
635 623
636 asprintf (&fname, name ? name : dflt, ::thisnode); 624 asprintf (&fname, name ? name : dflt, ::thisnode);
637 625
641 asprintf (&fname, "%s/%s", confbase, rname); 629 asprintf (&fname, "%s/%s", confbase, rname);
642 free (rname); 630 free (rname);
643 } 631 }
644 632
645 return fname; 633 return fname;
634}
635
636void
637conf_node::print ()
638{
639 printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %02x %s%s%d\n",
640 id,
641 id >> 8, id & 0xff,
642 compress ? 'Y' : 'N',
643 connectmode == C_ONDEMAND ? "ondemand"
644 : connectmode == C_NEVER ? "never"
645 : connectmode == C_ALWAYS ? "always"
646 : connectmode == C_DISABLED ? "disabled"
647 : "",
648 nodename,
649 protocols,
650 hostname ? hostname : "",
651 hostname ? ":" : "",
652 hostname ? udp_port : 0
653 );
646} 654}
647 655
648void 656void
649configuration::print () 657configuration::print ()
650{ 658{
657 printf (_("interface: %s\n"), ifname); 665 printf (_("interface: %s\n"), ifname);
658 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>"); 666 printf (_("primary rsa key: %s\n"), prikeyfile ? prikeyfile : "<default>");
659 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); 667 printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1);
660 printf ("\n"); 668 printf ("\n");
661 669
662 printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", 670 printf ("%4s %-17s %s %-8.8s %-10.10s %04s %s\n",
663 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); 671 _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Prot"), _("Host:Port"));
664 672
665 for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) 673 for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i)
666 (*i)->print (); 674 (*i)->print ();
667 675
668 printf ("\n"); 676 printf ("\n");
678configuration::~configuration () 686configuration::~configuration ()
679{ 687{
680 cleanup (); 688 cleanup ();
681} 689}
682 690
683

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines