summaryrefslogtreecommitdiff
path: root/node/OutboundMulticast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/OutboundMulticast.cpp')
-rw-r--r--node/OutboundMulticast.cpp107
1 files changed, 46 insertions, 61 deletions
diff --git a/node/OutboundMulticast.cpp b/node/OutboundMulticast.cpp
index eea1132c..d7a7b4d8 100644
--- a/node/OutboundMulticast.cpp
+++ b/node/OutboundMulticast.cpp
@@ -1,6 +1,6 @@
/*
* ZeroTier One - Network Virtualization Everywhere
- * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
+ * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
*
* 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
@@ -14,6 +14,14 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * --
+ *
+ * You can be released from the requirements of the license by purchasing
+ * a commercial license. Buying such a license is mandatory as soon as you
+ * develop commercial closed-source software that incorporates or links
+ * directly against ZeroTier software without disclosing the source code
+ * of your own application.
*/
#include "Constants.hpp"
@@ -21,8 +29,9 @@
#include "OutboundMulticast.hpp"
#include "Switch.hpp"
#include "Network.hpp"
-#include "CertificateOfMembership.hpp"
#include "Node.hpp"
+#include "Peer.hpp"
+#include "Topology.hpp"
namespace ZeroTier {
@@ -30,7 +39,7 @@ void OutboundMulticast::init(
const RuntimeEnvironment *RR,
uint64_t timestamp,
uint64_t nwid,
- const CertificateOfMembership *com,
+ bool disableCompression,
unsigned int limit,
unsigned int gatherLimit,
const MAC &src,
@@ -39,75 +48,51 @@ void OutboundMulticast::init(
const void *payload,
unsigned int len)
{
+ uint8_t flags = 0;
+
_timestamp = timestamp;
_nwid = nwid;
+ if (src) {
+ _macSrc = src;
+ flags |= 0x04;
+ } else {
+ _macSrc.fromAddress(RR->identity.address(),nwid);
+ }
+ _macDest = dest.mac();
_limit = limit;
+ _frameLen = (len < ZT_MAX_MTU) ? len : ZT_MAX_MTU;
+ _etherType = etherType;
- uint8_t flags = 0;
if (gatherLimit) flags |= 0x02;
- if (src) flags |= 0x04;
-
- /*
- TRACE(">>MC %.16llx INIT %.16llx/%s limit %u gatherLimit %u from %s to %s length %u com==%d",
- (unsigned long long)this,
- nwid,
- dest.toString().c_str(),
- limit,
- gatherLimit,
- (src) ? src.toString().c_str() : MAC(RR->identity.address(),nwid).toString().c_str(),
- dest.toString().c_str(),
- len,
- (com) ? 1 : 0);
- */
-
- _packetNoCom.setSource(RR->identity.address());
- _packetNoCom.setVerb(Packet::VERB_MULTICAST_FRAME);
- _packetNoCom.append((uint64_t)nwid);
- _packetNoCom.append(flags);
- if (gatherLimit) _packetNoCom.append((uint32_t)gatherLimit);
- if (src) src.appendTo(_packetNoCom);
- dest.mac().appendTo(_packetNoCom);
- _packetNoCom.append((uint32_t)dest.adi());
- _packetNoCom.append((uint16_t)etherType);
- _packetNoCom.append(payload,len);
- _packetNoCom.compress();
- if (com) {
- _haveCom = true;
- flags |= 0x01;
+ _packet.setSource(RR->identity.address());
+ _packet.setVerb(Packet::VERB_MULTICAST_FRAME);
+ _packet.append((uint64_t)nwid);
+ _packet.append(flags);
+ if (gatherLimit) _packet.append((uint32_t)gatherLimit);
+ if (src) src.appendTo(_packet);
+ dest.mac().appendTo(_packet);
+ _packet.append((uint32_t)dest.adi());
+ _packet.append((uint16_t)etherType);
+ _packet.append(payload,_frameLen);
+ if (!disableCompression)
+ _packet.compress();
- _packetWithCom.setSource(RR->identity.address());
- _packetWithCom.setVerb(Packet::VERB_MULTICAST_FRAME);
- _packetWithCom.append((uint64_t)nwid);
- _packetWithCom.append(flags);
- com->serialize(_packetWithCom);
- if (gatherLimit) _packetWithCom.append((uint32_t)gatherLimit);
- if (src) src.appendTo(_packetWithCom);
- dest.mac().appendTo(_packetWithCom);
- _packetWithCom.append((uint32_t)dest.adi());
- _packetWithCom.append((uint16_t)etherType);
- _packetWithCom.append(payload,len);
- _packetWithCom.compress();
- } else _haveCom = false;
+ ZT_FAST_MEMCPY(_frameData,payload,_frameLen);
}
-void OutboundMulticast::sendOnly(const RuntimeEnvironment *RR,const Address &toAddr)
+void OutboundMulticast::sendOnly(const RuntimeEnvironment *RR,void *tPtr,const Address &toAddr)
{
- if (_haveCom) {
- SharedPtr<Peer> peer(RR->topology->getPeer(toAddr));
- if ( (!peer) || (peer->needsOurNetworkMembershipCertificate(_nwid,RR->node->now(),true)) ) {
- //TRACE(">>MC %.16llx -> %s (with COM)",(unsigned long long)this,toAddr.toString().c_str());
- _packetWithCom.newInitializationVector();
- _packetWithCom.setDestination(toAddr);
- RR->sw->send(_packetWithCom,true,_nwid);
- return;
- }
- }
+ const SharedPtr<Network> nw(RR->node->network(_nwid));
+ const Address toAddr2(toAddr);
+ if ((nw)&&(nw->filterOutgoingPacket(tPtr,true,RR->identity.address(),toAddr2,_macSrc,_macDest,_frameData,_frameLen,_etherType,0))) {
+ _packet.newInitializationVector();
+ _packet.setDestination(toAddr2);
+ RR->node->expectReplyTo(_packet.packetId());
- //TRACE(">>MC %.16llx -> %s (without COM)",(unsigned long long)this,toAddr.toString().c_str());
- _packetNoCom.newInitializationVector();
- _packetNoCom.setDestination(toAddr);
- RR->sw->send(_packetNoCom,true,_nwid);
+ Packet tmp(_packet); // make a copy of packet so as not to garble the original -- GitHub issue #461
+ RR->sw->send(tPtr,tmp,true);
+ }
}
} // namespace ZeroTier