Files

89 lines
2.2 KiB
C++
Raw Permalink Normal View History

2025-08-06 12:10:18 -04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
2014-09-25 22:08:52 -07:00
*
2025-08-06 12:10:18 -04:00
* (c) ZeroTier, Inc.
* https://www.zerotier.com/
2014-09-25 22:08:52 -07:00
*/
#include "OutboundMulticast.hpp"
2025-07-03 11:26:23 -04:00
#include "Constants.hpp"
#include "Network.hpp"
2015-04-08 15:42:23 -07:00
#include "Node.hpp"
2025-07-03 11:26:23 -04:00
#include "RuntimeEnvironment.hpp"
#include "Switch.hpp"
#include "Topology.hpp"
2014-09-25 22:08:52 -07:00
namespace ZeroTier {
void OutboundMulticast::init(
2025-07-03 11:26:23 -04:00
const RuntimeEnvironment* RR,
uint64_t timestamp,
uint64_t nwid,
bool disableCompression,
unsigned int limit,
unsigned int gatherLimit,
2025-07-03 11:26:23 -04:00
const MAC& src,
const MulticastGroup& dest,
unsigned int etherType,
2025-07-03 11:26:23 -04:00
const void* payload,
unsigned int len)
2014-09-25 22:08:52 -07:00
{
2016-08-05 15:02:01 -07:00
uint8_t flags = 0;
2014-09-25 22:08:52 -07:00
_timestamp = timestamp;
_nwid = nwid;
2016-08-05 15:02:01 -07:00
if (src) {
_macSrc = src;
2016-08-05 15:02:01 -07:00
flags |= 0x04;
2025-07-03 11:26:23 -04:00
}
else {
_macSrc.fromAddress(RR->identity.address(), nwid);
2016-08-05 15:02:01 -07:00
}
_macDest = dest.mac();
_limit = limit;
_frameLen = (len < ZT_MAX_MTU) ? len : ZT_MAX_MTU;
_etherType = etherType;
2023-05-01 14:48:16 -04:00
if (gatherLimit) {
flags |= 0x02;
}
_packet.setSource(RR->identity.address());
_packet.setVerb(Packet::VERB_MULTICAST_FRAME);
_packet.append((uint64_t)nwid);
_packet.append(flags);
2023-05-01 14:48:16 -04:00
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);
2025-07-03 11:26:23 -04:00
_packet.append(payload, _frameLen);
if (! disableCompression) {
_packet.compress();
2023-05-01 14:48:16 -04:00
}
2025-07-03 11:26:23 -04:00
memcpy(_frameData, payload, _frameLen);
2014-09-25 22:08:52 -07:00
}
2025-07-03 11:26:23 -04:00
void OutboundMulticast::sendOnly(const RuntimeEnvironment* RR, void* tPtr, const Address& toAddr)
2014-09-25 22:08:52 -07:00
{
const SharedPtr<Network> nw(RR->node->network(_nwid));
2025-07-03 11:26:23 -04:00
uint8_t QoSBucket = 255; // Dummy value
if ((nw) && (nw->filterOutgoingPacket(tPtr, true, RR->identity.address(), toAddr, _macSrc, _macDest, _frameData, _frameLen, _etherType, 0, QoSBucket))) {
nw->pushCredentialsIfNeeded(tPtr, toAddr, RR->node->now());
_packet.newInitializationVector();
_packet.setDestination(toAddr);
RR->node->expectReplyTo(_packet.packetId());
2019-06-17 15:50:05 -07:00
_tmp = _packet;
RR->sw->send(tPtr, _tmp, true, _nwid, ZT_QOS_NO_FLOW);
}
2014-09-25 22:08:52 -07:00
}
2025-07-03 11:26:23 -04:00
} // namespace ZeroTier