--- gvpe/src/vpn.C 2003/04/13 00:35:46 1.11 +++ gvpe/src/vpn.C 2003/10/14 19:59:16 1.16 @@ -26,15 +26,14 @@ #include #include -#include #include #include #include #include #include -#include -#include -#include +#include + +#include "netcompat.h" #include "pidfile.h" @@ -86,7 +85,7 @@ fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); -#ifdef IP_MTU_DISCOVER +#if defined(SOL_IP) && defined(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 // fragment for me sometimes. @@ -124,7 +123,7 @@ setsockopt (udpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); } -#ifdef IP_MTU_DISCOVER +#if defined(SOL_IP) && defined(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 // fragment for me sometimes. @@ -168,7 +167,7 @@ } #endif -#ifdef IP_MTU_DISCOVER +#if defined(SOL_IP) && defined(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 // fragment for me sometimes. @@ -273,7 +272,9 @@ bool vpn::send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) { +#if defined(SOL_IP) && defined(IP_TOS) setsockopt (ipv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); +#endif sendto (ipv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); return true; @@ -302,14 +303,17 @@ return ~sum; } +#if ENABLE_ICMP bool vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) { +#if defined(SOL_IP) && defined(IP_TOS) setsockopt (icmpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); +#endif pkt->unshift_hdr (4); - icmphdr *hdr = (icmphdr *)&((*pkt)[0]); + icmp_header *hdr = (icmp_header *)&((*pkt)[0]); hdr->type = ::conf.icmp_type; hdr->code = 255; hdr->checksum = 0; @@ -319,11 +323,14 @@ return true; } +#endif bool vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) { +#if defined(SOL_IP) && defined(IP_TOS) setsockopt (udpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); +#endif sendto (udpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); return true; @@ -350,8 +357,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) { @@ -416,6 +423,7 @@ } } +#if ENABLE_ICMP void vpn::icmpv4_ev (io_watcher &w, short revents) { @@ -434,7 +442,7 @@ { pkt->len = len; - icmphdr *hdr = (icmphdr *)&((*pkt)[IP_OVERHEAD]); + icmp_header *hdr = (icmp_header *)&((*pkt)[IP_OVERHEAD]); if (hdr->type == ::conf.icmp_type && hdr->code == 255) @@ -468,6 +476,7 @@ exit (1); } } +#endif void vpn::udpv4_ev (io_watcher &w, short revents) @@ -527,13 +536,13 @@ if (src != THISNODE->id) { - slog (L_ERR, _("FATAL: tap packet not originating on current node received, terminating.")); + slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); exit (1); } if (dst == THISNODE->id) { - slog (L_ERR, _("FATAL: tap packet destined for current node received, terminating.")); + slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); exit (1); } @@ -549,15 +558,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); } } @@ -634,7 +639,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) @@ -644,9 +649,7 @@ if (c->conf->routerprio > prio && 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 - && (!THISNODE->routerprio - || c->conf->routerprio <= THISNODE->routerprio)) + && c->conf != THISNODE) // redundant, since ictx==octx==0 always on thisnode { prio = c->conf->routerprio; router = c; @@ -665,7 +668,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 (); }