--- gvpe/src/vpn.C 2008/08/10 02:49:21 1.50 +++ gvpe/src/vpn.C 2008/08/10 22:18:58 1.52 @@ -124,6 +124,8 @@ int vpn::setup () { + int success = 0; + ipv4_tos = -1; ipv4_fd = -1; @@ -156,7 +158,10 @@ } ipv4_ev_watcher.start (ipv4_fd, EV_READ); + ++success; } + else + THISNODE->protocols &= ~PROT_IPv4; udpv4_tos = -1; udpv4_fd = -1; @@ -196,7 +201,10 @@ } udpv4_ev_watcher.start (udpv4_fd, EV_READ); + ++success; } + else + THISNODE->protocols &= ~PROT_UDPv4; icmpv4_tos = -1; icmpv4_fd = -1; @@ -242,6 +250,7 @@ } icmpv4_ev_watcher.start (icmpv4_fd, EV_READ); + ++success; } #endif @@ -279,7 +288,10 @@ } tcpv4_ev_watcher.start (tcpv4_fd, EV_READ); + ++success; } + else + THISNODE->protocols &= ~PROT_TCPv4; #endif dnsv4_tos = -1; @@ -325,11 +337,18 @@ } dnsv4_ev_watcher.start (dnsv4_fd, EV_READ); + ++success; } #endif ///////////////////////////////////////////////////////////////////////////// + if (!success) + { + slog (L_ERR, _("no protocols enabled, exiting.")); + exit (EXIT_FAILURE); + } + reconnect_all (); ///////////////////////////////////////////////////////////////////////////// @@ -748,7 +767,8 @@ { connection *router = 0; - // first try to find a router with a direct connection + // first try to find a router with a direct connection, route there + // regardless of any other considerations. { u32 prio = 1; @@ -758,16 +778,11 @@ if (c->conf->routerprio > prio && c->conf != THISNODE - && c != dst - && can_direct (c->conf, dst->conf)) + && can_direct (c->conf, dst->conf) + && c->ictx && c->octx) { - if (c->ictx && c->octx) - { - prio = c->conf->routerprio; - router = c; - } - else - c->establish_connection (); + prio = c->conf->routerprio; + router = c; } } } @@ -775,29 +790,25 @@ if (router) return router; - // second try find the router with the highest priority higher than ours + // second try find the router with the highest priority, higher than ours { - u32 prio = 1; + u32 prio = THISNODE->routerprio ? THISNODE->routerprio : 1; for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) { connection *c = *i; if (c->conf->routerprio > prio - && c->conf->routerprio > THISNODE->routerprio && c != dst - && c->conf != THISNODE) + && c->conf != THISNODE + && c->ictx && c->octx) { - if (c->ictx && c->octx) - { - prio = c->conf->routerprio; - router = c; - } - else - c->establish_connection (); + prio = c->conf->routerprio; + router = c; } } } + return router; }