--- gvpe/src/vpn.C 2003/10/14 15:48:15 1.15 +++ gvpe/src/vpn.C 2003/10/16 02:41:21 1.19 @@ -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 @@ -26,7 +27,6 @@ #include #include -#include #include #include #include @@ -338,6 +338,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 (); @@ -361,7 +380,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. @@ -532,39 +551,30 @@ pkt = tap->recv (); - int dst = mac2id (pkt->dst); - int src = mac2id (pkt->src); - - if (src != THISNODE->id) - { - slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); - exit (1); - } + if (!pkt) + return; - if (dst == THISNODE->id) + if (pkt->len > 14) { - slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); - exit (1); - } + int dst = mac2id (pkt->dst); + int src = mac2id (pkt->src); - if (dst > conns.size ()) - slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); - else - { - if (dst) + if (src != THISNODE->id) { - // unicast - if (dst != THISNODE->id) - conns[dst - 1]->inject_data_packet (pkt); + slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); + exit (1); } - else + + if (dst == THISNODE->id) { - // 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); + slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); + exit (1); } + + if (dst > conns.size ()) + slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); + else + inject_data_packet (pkt, dst); } delete pkt;