--- gvpe/src/vpn.C 2003/10/15 06:06:41 1.17 +++ gvpe/src/vpn.C 2003/10/16 14:12:00 1.20 @@ -1,5 +1,6 @@ /* vpn.C -- handle the protocol, encryption, handshaking etc. + Copyright (C) 2003 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,6 +42,8 @@ #include "util.h" #include "vpn.h" +vpn network; // THE vpn (bad design...) + ///////////////////////////////////////////////////////////////////////////// const char *vpn::script_if_up () @@ -337,6 +340,25 @@ } void +vpn::inject_data_packet (tap_packet *pkt, int dst) +{ + if (dst) + { + // unicast + if (dst != THISNODE->id) + conns[dst - 1]->inject_data_packet (pkt); + } + else + { + // 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, true); + } +} + +void vpn::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) { unsigned int src = pkt->src (); @@ -360,7 +382,7 @@ 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) + else if (dst != THISNODE->id) { if (THISNODE->routerprio) // the tos setting gets lost here. who cares. @@ -554,22 +576,7 @@ if (dst > conns.size ()) slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); else - { - if (dst) - { - // unicast - if (dst != THISNODE->id) - conns[dst - 1]->inject_data_packet (pkt); - } - else - { - // 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); - } - } + inject_data_packet (pkt, dst); } delete pkt;