mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
cleanup
This commit is contained in:
commit
62cdb8dc94
3 changed files with 0 additions and 303 deletions
|
@ -1,28 +0,0 @@
|
||||||
# Common makefile -- loads make rules for each platform
|
|
||||||
|
|
||||||
OSTYPE=$(shell uname -s)
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),Darwin)
|
|
||||||
include make-mac.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),Linux)
|
|
||||||
include make-linux.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),FreeBSD)
|
|
||||||
CC=clang
|
|
||||||
CXX=clang++
|
|
||||||
ZT_BUILD_PLATFORM=7
|
|
||||||
include make-bsd.mk
|
|
||||||
endif
|
|
||||||
ifeq ($(OSTYPE),OpenBSD)
|
|
||||||
CC=egcc
|
|
||||||
CXX=eg++
|
|
||||||
ZT_BUILD_PLATFORM=9
|
|
||||||
include make-bsd.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),NetBSD)
|
|
||||||
include make-netbsd.mk
|
|
||||||
endif
|
|
|
@ -1,152 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2019 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
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_MULTICASTGROUP_HPP
|
|
||||||
#define ZT_MULTICASTGROUP_HPP
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "Constants.hpp"
|
|
||||||
#include "MAC.hpp"
|
|
||||||
#include "InetAddress.hpp"
|
|
||||||
#include "Utils.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A multicast group composed of a multicast MAC and a 32-bit ADI field
|
|
||||||
*
|
|
||||||
* ADI stands for additional distinguishing information. ADI is primarily for
|
|
||||||
* adding additional information to broadcast (ff:ff:ff:ff:ff:ff) memberships,
|
|
||||||
* since straight-up broadcast won't scale. Right now it's zero except for
|
|
||||||
* IPv4 ARP, where it holds the IPv4 address itself to make ARP into a
|
|
||||||
* selective multicast query that can scale.
|
|
||||||
*
|
|
||||||
* In the future we might add some kind of plugin architecture that can add
|
|
||||||
* ADI for things like mDNS (multicast DNS) to improve the selectivity of
|
|
||||||
* those protocols.
|
|
||||||
*
|
|
||||||
* MulticastGroup behaves as an immutable value object.
|
|
||||||
*/
|
|
||||||
class MulticastGroup
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline MulticastGroup() :
|
|
||||||
_mac(),
|
|
||||||
_adi(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline MulticastGroup(const MAC &m,uint32_t a) :
|
|
||||||
_mac(m),
|
|
||||||
_adi(a)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derive the multicast group used for address resolution (ARP/NDP) for an IP
|
|
||||||
*
|
|
||||||
* @param ip IP address (port field is ignored)
|
|
||||||
* @return Multicast group for ARP/NDP
|
|
||||||
*/
|
|
||||||
static inline MulticastGroup deriveMulticastGroupForAddressResolution(const InetAddress &ip)
|
|
||||||
{
|
|
||||||
if (ip.isV4()) {
|
|
||||||
// IPv4 wants broadcast MACs, so we shove the V4 address itself into
|
|
||||||
// the Multicast Group ADI field. Making V4 ARP work is basically why
|
|
||||||
// ADI was added, as well as handling other things that want mindless
|
|
||||||
// Ethernet broadcast to all.
|
|
||||||
return MulticastGroup(MAC(0xffffffffffffULL),Utils::ntoh(*((const uint32_t *)ip.rawIpData())));
|
|
||||||
} else if (ip.isV6()) {
|
|
||||||
// IPv6 is better designed in this respect. We can compute the IPv6
|
|
||||||
// multicast address directly from the IP address, and it gives us
|
|
||||||
// 24 bits of uniqueness. Collisions aren't likely to be common enough
|
|
||||||
// to care about.
|
|
||||||
const unsigned char *a = (const unsigned char *)ip.rawIpData();
|
|
||||||
return MulticastGroup(MAC(0x33,0x33,0xff,a[13],a[14],a[15]),0);
|
|
||||||
}
|
|
||||||
return MulticastGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Multicast address
|
|
||||||
*/
|
|
||||||
inline const MAC &mac() const { return _mac; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Additional distinguishing information
|
|
||||||
*/
|
|
||||||
inline uint32_t adi() const { return _adi; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute a 32-bit randomized identifier for this group
|
|
||||||
*
|
|
||||||
* This is a 32-bit fnv1a hash of the MAC and ADI. It's part of the protocol as it's
|
|
||||||
* used to generate unique identifiers for multicast groups for multicast lookup, so
|
|
||||||
* don't change it lightly.
|
|
||||||
*/
|
|
||||||
inline uint32_t id32() const
|
|
||||||
{
|
|
||||||
uint32_t h = 0x811c9dc5;
|
|
||||||
const uint64_t m = _mac.toInt();
|
|
||||||
const uint32_t p = 0x1000193;
|
|
||||||
h ^= (uint32_t)(m >> 40) & 0xff; h *= p;
|
|
||||||
h ^= (uint32_t)(m >> 32) & 0xff; h *= p;
|
|
||||||
h ^= (uint32_t)(m >> 24) & 0xff; h *= p;
|
|
||||||
h ^= (uint32_t)(m >> 16) & 0xff; h *= p;
|
|
||||||
h ^= (uint32_t)(m >> 8) & 0xff; h *= p;
|
|
||||||
h ^= (uint32_t)m & 0xff; h *= p;
|
|
||||||
h ^= _adi >> 24; h *= p;
|
|
||||||
h ^= (_adi >> 16) & 0xff; h *= p;
|
|
||||||
h ^= (_adi >> 8) & 0xff; h *= p;
|
|
||||||
h ^= _adi & 0xff; h *= p;
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned long hashCode() const { return (_mac.hashCode() + (unsigned long)_adi); }
|
|
||||||
|
|
||||||
inline bool operator==(const MulticastGroup &g) const { return ((_mac == g._mac)&&(_adi == g._adi)); }
|
|
||||||
inline bool operator!=(const MulticastGroup &g) const { return ((_mac != g._mac)||(_adi != g._adi)); }
|
|
||||||
inline bool operator<(const MulticastGroup &g) const
|
|
||||||
{
|
|
||||||
if (_mac < g._mac)
|
|
||||||
return true;
|
|
||||||
else if (_mac == g._mac)
|
|
||||||
return (_adi < g._adi);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
inline bool operator>(const MulticastGroup &g) const { return (g < *this); }
|
|
||||||
inline bool operator<=(const MulticastGroup &g) const { return !(g < *this); }
|
|
||||||
inline bool operator>=(const MulticastGroup &g) const { return !(*this < g); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
MAC _mac;
|
|
||||||
uint32_t _adi;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,123 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2019 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
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_MULTICASTSUBSCRIPTIONS_HPP
|
|
||||||
#define ZT_MULTICASTSUBSCRIPTIONS_HPP
|
|
||||||
|
|
||||||
#include "Constants.hpp"
|
|
||||||
#include "MulticastGroup.hpp"
|
|
||||||
#include "Identity.hpp"
|
|
||||||
#include "Buffer.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A compact collection of multicast subscriptions identified by 32-bit hash values
|
|
||||||
*/
|
|
||||||
class MulticastSubscriptions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline MulticastSubscriptions() : _signatureLength(0) {}
|
|
||||||
|
|
||||||
inline void add(const MulticastGroup &mg)
|
|
||||||
{
|
|
||||||
if (_subscriptions.size() < ZT_MAX_MULTICAST_SUBSCRIPTIONS)
|
|
||||||
_subscriptions.push_back(mg.id32());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool sign(const Identity &signer,const int64_t ts)
|
|
||||||
{
|
|
||||||
_ts = ts;
|
|
||||||
std::sort(_subscriptions.begin(),_subscriptions.end());
|
|
||||||
_subscriptions.erase(std::unique(_subscriptions.begin(),_subscriptions.end()),_subscriptions.end());
|
|
||||||
|
|
||||||
_SRec tmp;
|
|
||||||
tmp.ts = Utils::hton((uint64_t)ts);
|
|
||||||
for(unsigned long i=0,j=(unsigned long)_subscriptions.size();i<j;++i)
|
|
||||||
tmp.g[i] = Utils::hton(_subscriptions[i]);
|
|
||||||
|
|
||||||
_signatureLength = signer.sign(&tmp,(unsigned int)((_subscriptions.size() * sizeof(uint32_t)) + sizeof(uint64_t)),_signature,sizeof(_signature));
|
|
||||||
return (_signatureLength > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool verify(const Identity &signer)
|
|
||||||
{
|
|
||||||
if ((_signatureLength == 0)||(_signatureLength > ZT_SIGNATURE_BUFFER_SIZE))
|
|
||||||
return false;
|
|
||||||
_SRec tmp;
|
|
||||||
tmp.ts = Utils::hton((uint64_t)_ts);
|
|
||||||
for(unsigned long i=0,j=(unsigned long)_subscriptions.size();i<j;++i)
|
|
||||||
tmp.g[i] = Utils::hton(_subscriptions[i]);
|
|
||||||
return signer.verify(&tmp,(unsigned int)((_subscriptions.size() * sizeof(uint32_t)) + sizeof(uint64_t)),_signature,_signatureLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int64_t timestamp() const { return _ts; }
|
|
||||||
inline unsigned int count() const { return (unsigned int)_subscriptions.size(); }
|
|
||||||
inline bool contains(const MulticastGroup &mg) const { return std::binary_search(_subscriptions.begin(),_subscriptions.end(),mg.id32()); }
|
|
||||||
|
|
||||||
template<unsigned int C>
|
|
||||||
inline void serialize(Buffer<C> &b) const
|
|
||||||
{
|
|
||||||
b.append((uint64_t)_ts);
|
|
||||||
b.append((uint16_t)_subscriptions.size());
|
|
||||||
for(std::vector<uint32_t>::const_iterator i(_subscriptions.begin());i!=_subscriptions.end();++i)
|
|
||||||
b.append(*i);
|
|
||||||
b.append((uint16_t)_signatureLength);
|
|
||||||
b.append(_signature,_signatureLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<unsigned int C>
|
|
||||||
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
|
||||||
{
|
|
||||||
unsigned int p = startAt;
|
|
||||||
_ts = (int64_t)(b.template at<uint64_t>(p)); p += 8;
|
|
||||||
_subscriptions.resize(b.template at<uint16_t>(p)); p += 2;
|
|
||||||
for(std::vector<uint32_t>::iterator i(_subscriptions.begin());i!=_subscriptions.end();++i) {
|
|
||||||
*i = b.template at<uint32_t>(p);
|
|
||||||
p += 4;
|
|
||||||
}
|
|
||||||
_signatureLength = b.template at<uint16_t>(p); p += 2;
|
|
||||||
if (_signatureLength > ZT_SIGNATURE_BUFFER_SIZE)
|
|
||||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
|
||||||
memcpy(_signature,b.field(p,_signatureLength),_signatureLength); p += _signatureLength;
|
|
||||||
return (p - startAt);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ZT_PACKED_STRUCT(struct _SRec {
|
|
||||||
uint64_t ts;
|
|
||||||
uint32_t g[ZT_MAX_MULTICAST_SUBSCRIPTIONS];
|
|
||||||
});
|
|
||||||
|
|
||||||
int64_t _ts;
|
|
||||||
std::vector<uint32_t> _subscriptions;
|
|
||||||
unsigned int _signatureLength;
|
|
||||||
uint8_t _signature[ZT_SIGNATURE_BUFFER_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Add table
Reference in a new issue