--- gvpe/src/vpn.C 2003/04/08 02:00:54 1.9 +++ gvpe/src/vpn.C 2003/04/13 16:53:36 1.13 @@ -31,9 +31,10 @@ #include #include #include +#include #include #include -#include +#include #include "pidfile.h" @@ -83,6 +84,8 @@ if (ipv4_fd < 0) return -1; + fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); + #ifdef IP_MTU_DISCOVER // this I really consider a linux bug. I am neither connected // nor do I fragment myself. Linux still sets DF and doesn't @@ -113,6 +116,8 @@ if (udpv4_fd < 0) return -1; + fcntl (udpv4_fd, F_SETFL, O_NONBLOCK); + // standard daemon practise... { int oval = 1; @@ -150,6 +155,8 @@ if (icmpv4_fd < 0) return -1; + fcntl (icmpv4_fd, F_SETFL, O_NONBLOCK); + #ifdef ICMP_FILTER { icmp_filter oval; @@ -193,6 +200,8 @@ if (tcpv4_fd < 0) return -1; + fcntl (tcpv4_fd, F_SETFL, O_NONBLOCK); + // standard daemon practise... { int oval = 1; @@ -293,6 +302,7 @@ return ~sum; } +#if ENABLE_ICMP bool vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) { @@ -310,6 +320,7 @@ return true; } +#endif bool vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) @@ -341,8 +352,8 @@ { connection *c = conns[src - 1]; - if (dst == 0 && !THISNODE->routerprio) - slog (L_WARN, _("%s(%s): received broadcast, but we are no router"), + if (dst == 0) + slog (L_WARN, _("%s(%s): received broadcast (protocol violation)"), c->conf->nodename, (const char *)rsi); else if (dst != 0 && dst != THISNODE->id) { @@ -407,6 +418,7 @@ } } +#if ENABLE_ICMP void vpn::icmpv4_ev (io_watcher &w, short revents) { @@ -459,6 +471,7 @@ exit (1); } } +#endif void vpn::udpv4_ev (io_watcher &w, short revents) @@ -540,15 +553,11 @@ } else { - // broadcast, first check router, then self, then english - connection *router = find_router (); - - if (router) - router->inject_data_packet (pkt, true); - else - for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) - if ((*c)->conf != THISNODE) - (*c)->inject_data_packet (pkt); + // broadcast, this is ugly, but due to the security policy + // we have to connect to all hosts... + for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) + if ((*c)->conf != THISNODE) + (*c)->inject_data_packet (pkt); } } @@ -625,7 +634,7 @@ connection *vpn::find_router () { - u32 prio = 0; + u32 prio = 1; connection *router = 0; for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) @@ -633,9 +642,9 @@ connection *c = *i; if (c->conf->routerprio > prio - && c->connectmode == conf_node::C_ALWAYS - && c->conf != THISNODE - && c->ictx && c->octx) + && c->connectmode == conf_node::C_ALWAYS // so we don't drop the connection if in use + && c->ictx && c->octx + && c->conf != THISNODE) // redundant, since ictx==octx==0 always on thisnode { prio = c->conf->routerprio; router = c; @@ -654,7 +663,7 @@ else // no router found, aggressively connect to all routers for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) - if ((*i)->conf->routerprio) + if ((*i)->conf->routerprio && (*i)->conf != THISNODE) (*i)->establish_connection (); }