ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vpn.C
(Generate patch)

Comparing gvpe/src/vpn.C (file contents):
Revision 1.50 by pcg, Sun Aug 10 02:49:21 2008 UTC vs.
Revision 1.52 by pcg, Sun Aug 10 22:18:58 2008 UTC

122} 122}
123 123
124int 124int
125vpn::setup () 125vpn::setup ()
126{ 126{
127 int success = 0;
128
127 ipv4_tos = -1; 129 ipv4_tos = -1;
128 ipv4_fd = -1; 130 ipv4_fd = -1;
129 131
130 if (THISNODE->protocols & PROT_IPv4 && ::conf.ip_proto) 132 if (THISNODE->protocols & PROT_IPv4 && ::conf.ip_proto)
131 { 133 {
154 slog (L_ERR, _("can't bind ipv4 socket on %s: %s, exiting."), (const char *)si, strerror (errno)); 156 slog (L_ERR, _("can't bind ipv4 socket on %s: %s, exiting."), (const char *)si, strerror (errno));
155 exit (EXIT_FAILURE); 157 exit (EXIT_FAILURE);
156 } 158 }
157 159
158 ipv4_ev_watcher.start (ipv4_fd, EV_READ); 160 ipv4_ev_watcher.start (ipv4_fd, EV_READ);
161 ++success;
159 } 162 }
163 else
164 THISNODE->protocols &= ~PROT_IPv4;
160 165
161 udpv4_tos = -1; 166 udpv4_tos = -1;
162 udpv4_fd = -1; 167 udpv4_fd = -1;
163 168
164 if (THISNODE->protocols & PROT_UDPv4 && THISNODE->udp_port) 169 if (THISNODE->protocols & PROT_UDPv4 && THISNODE->udp_port)
194 slog (L_ERR, _("can't bind udpv4 on %s: %s, exiting."), (const char *)si, strerror (errno)); 199 slog (L_ERR, _("can't bind udpv4 on %s: %s, exiting."), (const char *)si, strerror (errno));
195 exit (EXIT_FAILURE); 200 exit (EXIT_FAILURE);
196 } 201 }
197 202
198 udpv4_ev_watcher.start (udpv4_fd, EV_READ); 203 udpv4_ev_watcher.start (udpv4_fd, EV_READ);
204 ++success;
199 } 205 }
206 else
207 THISNODE->protocols &= ~PROT_UDPv4;
200 208
201 icmpv4_tos = -1; 209 icmpv4_tos = -1;
202 icmpv4_fd = -1; 210 icmpv4_fd = -1;
203 211
204#if ENABLE_ICMP 212#if ENABLE_ICMP
240 slog (L_ERR, _("can't bind icmpv4 on %s: %s, exiting."), (const char *)si, strerror (errno)); 248 slog (L_ERR, _("can't bind icmpv4 on %s: %s, exiting."), (const char *)si, strerror (errno));
241 exit (EXIT_FAILURE); 249 exit (EXIT_FAILURE);
242 } 250 }
243 251
244 icmpv4_ev_watcher.start (icmpv4_fd, EV_READ); 252 icmpv4_ev_watcher.start (icmpv4_fd, EV_READ);
253 ++success;
245 } 254 }
246#endif 255#endif
247 256
248 tcpv4_fd = -1; 257 tcpv4_fd = -1;
249 258
277 slog (L_ERR, _("can't listen tcpv4 on %s: %s, exiting."), (const char *)si, strerror (errno)); 286 slog (L_ERR, _("can't listen tcpv4 on %s: %s, exiting."), (const char *)si, strerror (errno));
278 exit (EXIT_FAILURE); 287 exit (EXIT_FAILURE);
279 } 288 }
280 289
281 tcpv4_ev_watcher.start (tcpv4_fd, EV_READ); 290 tcpv4_ev_watcher.start (tcpv4_fd, EV_READ);
291 ++success;
282 } 292 }
293 else
294 THISNODE->protocols &= ~PROT_TCPv4;
283#endif 295#endif
284 296
285 dnsv4_tos = -1; 297 dnsv4_tos = -1;
286 dnsv4_fd = -1; 298 dnsv4_fd = -1;
287 299
323 slog (L_ERR, _("can't bind dnsv4 on %s: %s, exiting."), (const char *)si, strerror (errno)); 335 slog (L_ERR, _("can't bind dnsv4 on %s: %s, exiting."), (const char *)si, strerror (errno));
324 exit (EXIT_FAILURE); 336 exit (EXIT_FAILURE);
325 } 337 }
326 338
327 dnsv4_ev_watcher.start (dnsv4_fd, EV_READ); 339 dnsv4_ev_watcher.start (dnsv4_fd, EV_READ);
340 ++success;
328 } 341 }
329#endif 342#endif
330 343
331 ///////////////////////////////////////////////////////////////////////////// 344 /////////////////////////////////////////////////////////////////////////////
345
346 if (!success)
347 {
348 slog (L_ERR, _("no protocols enabled, exiting."));
349 exit (EXIT_FAILURE);
350 }
332 351
333 reconnect_all (); 352 reconnect_all ();
334 353
335 ///////////////////////////////////////////////////////////////////////////// 354 /////////////////////////////////////////////////////////////////////////////
336 355
746// from THISNODE to dst 765// from THISNODE to dst
747connection *vpn::find_router_for (const connection *dst) 766connection *vpn::find_router_for (const connection *dst)
748{ 767{
749 connection *router = 0; 768 connection *router = 0;
750 769
751 // first try to find a router with a direct connection 770 // first try to find a router with a direct connection, route there
771 // regardless of any other considerations.
752 { 772 {
753 u32 prio = 1; 773 u32 prio = 1;
754 774
755 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 775 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
756 { 776 {
757 connection *c = *i; 777 connection *c = *i;
758 778
759 if (c->conf->routerprio > prio 779 if (c->conf->routerprio > prio
760 && c->conf != THISNODE 780 && c->conf != THISNODE
761 && c != dst
762 && can_direct (c->conf, dst->conf)) 781 && can_direct (c->conf, dst->conf)
782 && c->ictx && c->octx)
763 { 783 {
764 if (c->ictx && c->octx)
765 {
766 prio = c->conf->routerprio; 784 prio = c->conf->routerprio;
767 router = c; 785 router = c;
768 }
769 else
770 c->establish_connection ();
771 } 786 }
772 } 787 }
773 } 788 }
774 789
775 if (router) 790 if (router)
776 return router; 791 return router;
777 792
778 // second try find the router with the highest priority higher than ours 793 // second try find the router with the highest priority, higher than ours
779 { 794 {
780 u32 prio = 1; 795 u32 prio = THISNODE->routerprio ? THISNODE->routerprio : 1;
781 796
782 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 797 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
783 { 798 {
784 connection *c = *i; 799 connection *c = *i;
785 800
786 if (c->conf->routerprio > prio 801 if (c->conf->routerprio > prio
787 && c->conf->routerprio > THISNODE->routerprio
788 && c != dst 802 && c != dst
789 && c->conf != THISNODE) 803 && c->conf != THISNODE
804 && c->ictx && c->octx)
790 { 805 {
791 if (c->ictx && c->octx)
792 {
793 prio = c->conf->routerprio; 806 prio = c->conf->routerprio;
794 router = c; 807 router = c;
795 }
796 else
797 c->establish_connection ();
798 } 808 }
799 } 809 }
800 } 810 }
811
801 return router; 812 return router;
802} 813}
803 814
804void vpn::connection_established (connection *c) 815void vpn::connection_established (connection *c)
805{ 816{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines