2013-10-18 13:48:02 +00:00
|
|
|
/*
|
2015-02-17 21:11:34 +00:00
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
2017-04-28 03:47:25 +00:00
|
|
|
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
2013-10-18 13:48:02 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2017-04-28 03:47:25 +00:00
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* 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.
|
2013-10-18 13:48:02 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-07 00:49:20 +00:00
|
|
|
#ifndef ZT_NETWORKCONFIG_HPP
|
|
|
|
#define ZT_NETWORKCONFIG_HPP
|
2013-10-18 13:48:02 +00:00
|
|
|
|
2013-10-18 15:01:41 +00:00
|
|
|
#include <stdint.h>
|
2016-04-12 19:11:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2013-10-18 15:01:41 +00:00
|
|
|
|
2014-10-04 20:15:02 +00:00
|
|
|
#include <vector>
|
2013-10-18 13:48:02 +00:00
|
|
|
#include <stdexcept>
|
2016-05-06 20:29:10 +00:00
|
|
|
#include <algorithm>
|
2013-10-18 13:48:02 +00:00
|
|
|
|
2016-04-12 19:11:34 +00:00
|
|
|
#include "../include/ZeroTierOne.h"
|
|
|
|
|
2013-10-18 15:01:41 +00:00
|
|
|
#include "Constants.hpp"
|
2016-04-12 19:11:34 +00:00
|
|
|
#include "Buffer.hpp"
|
2013-10-18 13:48:02 +00:00
|
|
|
#include "InetAddress.hpp"
|
2013-10-18 15:01:41 +00:00
|
|
|
#include "MulticastGroup.hpp"
|
|
|
|
#include "Address.hpp"
|
2013-10-18 16:01:48 +00:00
|
|
|
#include "CertificateOfMembership.hpp"
|
2017-02-23 19:47:36 +00:00
|
|
|
#include "CertificateOfOwnership.hpp"
|
2016-08-04 01:04:08 +00:00
|
|
|
#include "Capability.hpp"
|
|
|
|
#include "Tag.hpp"
|
2016-04-26 15:53:49 +00:00
|
|
|
#include "Dictionary.hpp"
|
2016-08-09 20:14:38 +00:00
|
|
|
#include "Identity.hpp"
|
2017-02-23 19:47:36 +00:00
|
|
|
#include "Utils.hpp"
|
2017-12-04 22:40:10 +00:00
|
|
|
#include "Trace.hpp"
|
2016-04-26 15:53:49 +00:00
|
|
|
|
2016-08-23 20:02:59 +00:00
|
|
|
/**
|
2016-09-07 19:12:52 +00:00
|
|
|
* Default maximum time delta for COMs, tags, and capabilities
|
2016-08-23 20:02:59 +00:00
|
|
|
*
|
|
|
|
* The current value is two hours, providing ample time for a controller to
|
|
|
|
* experience fail-over, etc.
|
|
|
|
*/
|
2016-09-07 19:12:52 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DEFAULT_CREDENTIAL_TIME_MAX_MAX_DELTA 7200000ULL
|
2016-08-23 20:02:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default minimum credential TTL and maxDelta for COM timestamps
|
|
|
|
*
|
|
|
|
* This is just slightly over three minutes and provides three retries for
|
|
|
|
* all currently online members to refresh.
|
|
|
|
*/
|
2016-09-07 19:12:52 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DEFAULT_CREDENTIAL_TIME_MIN_MAX_DELTA 185000ULL
|
2016-08-23 20:02:59 +00:00
|
|
|
|
2016-04-26 15:40:26 +00:00
|
|
|
/**
|
|
|
|
* Flag: allow passive bridging (experimental)
|
|
|
|
*/
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING 0x0000000000000001ULL
|
2016-04-26 15:40:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag: enable broadcast
|
|
|
|
*/
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST 0x0000000000000002ULL
|
2016-04-26 15:40:26 +00:00
|
|
|
|
2016-06-24 05:41:14 +00:00
|
|
|
/**
|
|
|
|
* Flag: enable IPv6 NDP emulation for certain V6 address patterns
|
|
|
|
*/
|
|
|
|
#define ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION 0x0000000000000004ULL
|
|
|
|
|
2016-09-01 19:07:17 +00:00
|
|
|
/**
|
|
|
|
* Flag: result of unrecognized MATCH entries in a rules table: match if set, no-match if clear
|
|
|
|
*/
|
|
|
|
#define ZT_NETWORKCONFIG_FLAG_RULES_RESULT_OF_UNSUPPORTED_MATCH 0x0000000000000008ULL
|
|
|
|
|
2016-09-27 19:22:25 +00:00
|
|
|
/**
|
|
|
|
* Flag: disable frame compression
|
|
|
|
*/
|
|
|
|
#define ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION 0x0000000000000010ULL
|
|
|
|
|
2016-04-27 00:11:25 +00:00
|
|
|
/**
|
|
|
|
* Device is an active bridge
|
|
|
|
*/
|
|
|
|
#define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE 0x0000020000000000ULL
|
|
|
|
|
|
|
|
/**
|
2016-08-23 16:39:38 +00:00
|
|
|
* Anchors are stable devices on this network that can cache multicast info, etc.
|
2016-04-27 00:11:25 +00:00
|
|
|
*/
|
2016-05-06 20:29:10 +00:00
|
|
|
#define ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR 0x0000040000000000ULL
|
2016-04-27 00:11:25 +00:00
|
|
|
|
2016-08-23 18:29:02 +00:00
|
|
|
/**
|
|
|
|
* Device can send CIRCUIT_TESTs for this network
|
|
|
|
*/
|
|
|
|
#define ZT_NETWORKCONFIG_SPECIALIST_TYPE_CIRCUIT_TESTER 0x0000080000000000ULL
|
|
|
|
|
2013-10-18 13:48:02 +00:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
2016-08-09 15:32:42 +00:00
|
|
|
// Dictionary capacity needed for max size network config
|
2017-02-23 19:47:36 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_CAPACITY (1024 + (sizeof(ZT_VirtualNetworkRule) * ZT_MAX_NETWORK_RULES) + (sizeof(Capability) * ZT_MAX_NETWORK_CAPABILITIES) + (sizeof(Tag) * ZT_MAX_NETWORK_TAGS) + (sizeof(CertificateOfOwnership) * ZT_MAX_CERTIFICATES_OF_OWNERSHIP))
|
2016-08-09 15:32:42 +00:00
|
|
|
|
|
|
|
// Dictionary capacity needed for max size network meta-data
|
|
|
|
#define ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY 1024
|
2016-06-21 14:32:58 +00:00
|
|
|
|
2016-06-16 19:28:43 +00:00
|
|
|
// Network config version
|
2016-08-23 16:39:38 +00:00
|
|
|
#define ZT_NETWORKCONFIG_VERSION 7
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2015-07-23 16:50:10 +00:00
|
|
|
// Fields for meta-data sent with network config requests
|
2016-08-09 15:32:42 +00:00
|
|
|
|
|
|
|
// Network config version
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_VERSION "v"
|
2016-08-09 15:32:42 +00:00
|
|
|
// Protocol version (see Packet.hpp)
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_PROTOCOL_VERSION "pv"
|
2016-09-15 20:17:37 +00:00
|
|
|
// Software vendor
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_VENDOR "vend"
|
|
|
|
// Software major version
|
2015-07-23 16:50:10 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION "majv"
|
2016-09-15 20:17:37 +00:00
|
|
|
// Software minor version
|
2015-07-23 16:50:10 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION "minv"
|
2016-09-15 20:17:37 +00:00
|
|
|
// Software revision
|
2015-07-23 16:50:10 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION "revv"
|
2016-08-26 17:38:43 +00:00
|
|
|
// Rules engine revision
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_RULES_ENGINE_REV "revr"
|
2016-08-09 15:32:42 +00:00
|
|
|
// Maximum number of rules per network this node can accept
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_RULES "mr"
|
|
|
|
// Maximum number of capabilities this node can accept
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_CAPABILITIES "mc"
|
|
|
|
// Maximum number of rules per capability this node can accept
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_CAPABILITY_RULES "mcr"
|
|
|
|
// Maximum number of tags this node can accept
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_TAGS "mt"
|
2016-08-17 20:41:45 +00:00
|
|
|
// Network join authorization token (if any)
|
2016-09-15 20:17:37 +00:00
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_AUTH "a"
|
2016-08-23 16:39:38 +00:00
|
|
|
// Network configuration meta-data flags
|
|
|
|
#define ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_FLAGS "f"
|
2016-08-17 20:41:45 +00:00
|
|
|
|
2016-06-16 19:28:43 +00:00
|
|
|
// These dictionary keys are short so they don't take up much room.
|
2016-08-09 15:32:42 +00:00
|
|
|
// By convention we use upper case for binary blobs, but it doesn't really matter.
|
2015-06-13 09:34:31 +00:00
|
|
|
|
2016-06-16 19:28:43 +00:00
|
|
|
// network config version
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_VERSION "v"
|
2015-06-13 09:34:31 +00:00
|
|
|
// network ID
|
2013-10-18 13:48:02 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID "nwid"
|
2015-06-13 09:34:31 +00:00
|
|
|
// integer(hex)
|
2013-10-18 13:48:02 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP "ts"
|
2015-06-13 09:34:31 +00:00
|
|
|
// integer(hex)
|
2015-03-18 23:10:48 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_REVISION "r"
|
2015-06-13 09:34:31 +00:00
|
|
|
// address of member
|
2013-10-18 13:48:02 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO "id"
|
2017-07-07 23:58:05 +00:00
|
|
|
// remote trace target
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_TARGET "tt"
|
2017-12-04 22:40:10 +00:00
|
|
|
// remote trace level
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_LEVEL "tl"
|
2016-06-16 19:28:43 +00:00
|
|
|
// flags(hex)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_FLAGS "f"
|
2015-06-13 09:34:31 +00:00
|
|
|
// integer(hex)
|
2014-09-24 16:01:58 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT "ml"
|
2016-06-16 19:28:43 +00:00
|
|
|
// network type (hex)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_TYPE "t"
|
2015-06-13 09:34:31 +00:00
|
|
|
// text
|
2014-05-08 00:11:50 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_NAME "n"
|
2017-05-05 00:12:02 +00:00
|
|
|
// network MTU
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_MTU "mtu"
|
2016-09-07 19:12:52 +00:00
|
|
|
// credential time max delta in ms
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_CREDENTIAL_TIME_MAX_DELTA "ctmd"
|
2016-06-16 19:28:43 +00:00
|
|
|
// binary serialized certificate of membership
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_COM "C"
|
|
|
|
// specialists (binary array of uint64_t)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_SPECIALISTS "S"
|
|
|
|
// routes (binary blob)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ROUTES "RT"
|
|
|
|
// static IPs (binary blob)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_STATIC_IPS "I"
|
|
|
|
// rules (binary blob)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_RULES "R"
|
2016-08-09 15:32:42 +00:00
|
|
|
// capabilities (binary blobs)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_CAPABILITIES "CAP"
|
|
|
|
// tags (binary blobs)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_TAGS "TAG"
|
2017-02-23 19:47:36 +00:00
|
|
|
// tags (binary blobs)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATES_OF_OWNERSHIP "COO"
|
2016-06-16 19:28:43 +00:00
|
|
|
|
|
|
|
// Legacy fields -- these are obsoleted but are included when older clients query
|
|
|
|
|
|
|
|
// boolean (now a flag)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING_OLD "pb"
|
|
|
|
// boolean (now a flag)
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST_OLD "eb"
|
2015-06-13 09:34:31 +00:00
|
|
|
// IP/bits[,IP/bits,...]
|
2015-06-29 17:21:28 +00:00
|
|
|
// Note that IPs that end in all zeroes are routes with no assignment in them.
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC_OLD "v4s"
|
2015-06-13 09:34:31 +00:00
|
|
|
// IP/bits[,IP/bits,...]
|
2015-06-29 17:21:28 +00:00
|
|
|
// Note that IPs that end in all zeroes are routes with no assignment in them.
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC_OLD "v6s"
|
2015-06-13 09:34:31 +00:00
|
|
|
// 0/1
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_PRIVATE_OLD "p"
|
|
|
|
// integer(hex)[,integer(hex),...]
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES_OLD "et"
|
|
|
|
// string-serialized CertificateOfMembership
|
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP_OLD "com"
|
2015-06-13 09:34:31 +00:00
|
|
|
// node[,node,...]
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES_OLD "ab"
|
2015-06-13 09:34:31 +00:00
|
|
|
// node;IP/port[,node;IP/port]
|
2016-06-16 19:28:43 +00:00
|
|
|
#define ZT_NETWORKCONFIG_DICT_KEY_RELAYS_OLD "rl"
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2016-08-23 16:39:38 +00:00
|
|
|
// End legacy fields
|
|
|
|
|
2013-10-18 13:48:02 +00:00
|
|
|
/**
|
2015-04-15 22:12:09 +00:00
|
|
|
* Network configuration received from network controller nodes
|
2013-10-18 13:48:02 +00:00
|
|
|
*
|
2016-04-12 19:11:34 +00:00
|
|
|
* This is a memcpy()'able structure and is safe (in a crash sense) to modify
|
|
|
|
* without locks.
|
2013-10-18 13:48:02 +00:00
|
|
|
*/
|
|
|
|
class NetworkConfig
|
|
|
|
{
|
2014-10-03 21:49:11 +00:00
|
|
|
public:
|
2016-04-12 19:11:34 +00:00
|
|
|
NetworkConfig()
|
|
|
|
{
|
|
|
|
memset(this,0,sizeof(NetworkConfig));
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkConfig(const NetworkConfig &nc)
|
|
|
|
{
|
|
|
|
memcpy(this,&nc,sizeof(NetworkConfig));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NetworkConfig &operator=(const NetworkConfig &nc)
|
|
|
|
{
|
|
|
|
memcpy(this,&nc,sizeof(NetworkConfig));
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-18 13:48:02 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-16 19:28:43 +00:00
|
|
|
* Write this network config to a dictionary for transport
|
|
|
|
*
|
|
|
|
* @param d Dictionary
|
|
|
|
* @param includeLegacy If true, include legacy fields for old node versions
|
|
|
|
* @return True if dictionary was successfully created, false if e.g. overflow
|
|
|
|
*/
|
2016-06-21 14:32:58 +00:00
|
|
|
bool toDictionary(Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d,bool includeLegacy) const;
|
2016-06-16 19:28:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read this network config from a dictionary
|
|
|
|
*
|
2016-08-09 20:14:38 +00:00
|
|
|
* @param d Dictionary (non-const since it might be modified during parse, should not be used after call)
|
2016-06-16 19:28:43 +00:00
|
|
|
* @return True if dictionary was valid and network config successfully initialized
|
|
|
|
*/
|
2016-08-23 18:52:10 +00:00
|
|
|
bool fromDictionary(const Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d);
|
2016-06-16 19:28:43 +00:00
|
|
|
|
2016-04-26 15:20:03 +00:00
|
|
|
/**
|
|
|
|
* @return True if passive bridging is allowed (experimental)
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool allowPassiveBridging() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0); }
|
2016-04-26 15:20:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if broadcast (ff:ff:ff:ff:ff:ff) address should work on this network
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool enableBroadcast() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); }
|
2016-04-26 15:20:03 +00:00
|
|
|
|
2016-06-24 05:41:14 +00:00
|
|
|
/**
|
|
|
|
* @return True if IPv6 NDP emulation should be allowed for certain "magic" IPv6 address patterns
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool ndpEmulation() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION) != 0); }
|
2016-06-24 05:41:14 +00:00
|
|
|
|
2016-09-27 19:22:25 +00:00
|
|
|
/**
|
|
|
|
* @return True if frames should not be compressed
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool disableCompression() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION) != 0); }
|
2016-09-27 19:22:25 +00:00
|
|
|
|
2016-04-26 15:20:03 +00:00
|
|
|
/**
|
|
|
|
* @return Network type is public (no access control)
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool isPublic() const { return (this->type == ZT_NETWORK_TYPE_PUBLIC); }
|
2016-04-26 15:20:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Network type is private (certificate access control)
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool isPrivate() const { return (this->type == ZT_NETWORK_TYPE_PRIVATE); }
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2016-04-26 15:20:03 +00:00
|
|
|
/**
|
|
|
|
* @return ZeroTier addresses of devices on this network designated as active bridges
|
|
|
|
*/
|
2016-04-12 19:11:34 +00:00
|
|
|
inline std::vector<Address> activeBridges() const
|
|
|
|
{
|
|
|
|
std::vector<Address> r;
|
2016-05-06 23:13:11 +00:00
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
|
|
|
|
r.push_back(Address(specialists[i]));
|
2016-04-27 00:11:25 +00:00
|
|
|
}
|
2016-04-12 19:11:34 +00:00
|
|
|
return r;
|
|
|
|
}
|
2013-10-18 16:01:48 +00:00
|
|
|
|
2016-05-06 20:29:10 +00:00
|
|
|
/**
|
|
|
|
* @return ZeroTier addresses of "anchor" devices on this network
|
|
|
|
*/
|
|
|
|
inline std::vector<Address> anchors() const
|
|
|
|
{
|
|
|
|
std::vector<Address> r;
|
2016-05-06 23:13:11 +00:00
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0)
|
|
|
|
r.push_back(Address(specialists[i]));
|
2016-05-06 20:29:10 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-09-09 16:32:00 +00:00
|
|
|
/**
|
|
|
|
* @param a Address to check
|
|
|
|
* @return True if address is an anchor
|
|
|
|
*/
|
|
|
|
inline bool isAnchor(const Address &a) const
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((a == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-18 16:01:48 +00:00
|
|
|
/**
|
|
|
|
* @param fromPeer Peer attempting to bridge other Ethernet peers onto network
|
|
|
|
* @return True if this network allows bridging
|
|
|
|
*/
|
|
|
|
inline bool permitsBridging(const Address &fromPeer) const
|
|
|
|
{
|
2016-05-06 23:13:11 +00:00
|
|
|
if ((flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0)
|
2016-04-12 19:11:34 +00:00
|
|
|
return true;
|
2016-05-06 23:13:11 +00:00
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((fromPeer == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0))
|
2016-04-27 00:11:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:29:02 +00:00
|
|
|
/**
|
|
|
|
* @param byPeer Address to check
|
|
|
|
* @return True if this peer is allowed to do circuit tests on this network (controller is always true)
|
|
|
|
*/
|
|
|
|
inline bool circuitTestingAllowed(const Address &byPeer) const
|
|
|
|
{
|
|
|
|
if (byPeer.toInt() == ((networkId >> 24) & 0xffffffffffULL))
|
|
|
|
return true;
|
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((byPeer == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_CIRCUIT_TESTER) != 0))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:20:03 +00:00
|
|
|
/**
|
|
|
|
* @return True if this network config is non-NULL
|
|
|
|
*/
|
2017-07-17 21:21:09 +00:00
|
|
|
inline operator bool() const { return (networkId != 0); }
|
2015-01-06 01:47:59 +00:00
|
|
|
|
2016-04-12 19:11:34 +00:00
|
|
|
inline bool operator==(const NetworkConfig &nc) const { return (memcmp(this,&nc,sizeof(NetworkConfig)) == 0); }
|
|
|
|
inline bool operator!=(const NetworkConfig &nc) const { return (!(*this == nc)); }
|
2013-10-18 13:48:02 +00:00
|
|
|
|
2016-08-04 01:04:08 +00:00
|
|
|
/**
|
|
|
|
* Add a specialist or mask flags if already present
|
|
|
|
*
|
|
|
|
* This masks the existing flags if the specialist is already here or adds
|
|
|
|
* it otherwise.
|
|
|
|
*
|
|
|
|
* @param a Address of specialist
|
|
|
|
* @param f Flags (OR of specialist role/type flags)
|
|
|
|
* @return True if successfully masked or added
|
|
|
|
*/
|
|
|
|
inline bool addSpecialist(const Address &a,const uint64_t f)
|
|
|
|
{
|
|
|
|
const uint64_t aint = a.toInt();
|
|
|
|
for(unsigned int i=0;i<specialistCount;++i) {
|
|
|
|
if ((specialists[i] & 0xffffffffffULL) == aint) {
|
|
|
|
specialists[i] |= f;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (specialistCount < ZT_MAX_NETWORK_SPECIALISTS) {
|
|
|
|
specialists[specialistCount++] = f | aint;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-04 16:51:15 +00:00
|
|
|
const Capability *capability(const uint32_t id) const
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i<capabilityCount;++i) {
|
|
|
|
if (capabilities[i].id() == id)
|
|
|
|
return &(capabilities[i]);
|
|
|
|
}
|
|
|
|
return (Capability *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Tag *tag(const uint32_t id) const
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i<tagCount;++i) {
|
|
|
|
if (tags[i].id() == id)
|
|
|
|
return &(tags[i]);
|
|
|
|
}
|
|
|
|
return (Tag *)0;
|
|
|
|
}
|
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Network ID that this configuration applies to
|
|
|
|
*/
|
|
|
|
uint64_t networkId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller-side time of config generation/issue
|
|
|
|
*/
|
2017-10-04 19:01:17 +00:00
|
|
|
int64_t timestamp;
|
2016-05-06 23:13:11 +00:00
|
|
|
|
2016-08-23 01:06:46 +00:00
|
|
|
/**
|
2016-09-07 19:12:52 +00:00
|
|
|
* Max difference between timestamp and tag/capability timestamp
|
2016-08-23 01:06:46 +00:00
|
|
|
*/
|
2017-10-04 19:01:17 +00:00
|
|
|
int64_t credentialTimeMaxDelta;
|
2016-08-23 01:06:46 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Controller-side revision counter for this configuration
|
|
|
|
*/
|
|
|
|
uint64_t revision;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Address of device to which this config is issued
|
|
|
|
*/
|
|
|
|
Address issuedTo;
|
|
|
|
|
2017-07-07 23:58:05 +00:00
|
|
|
/**
|
|
|
|
* If non-NULL, remote traces related to this network are sent here
|
|
|
|
*/
|
|
|
|
Address remoteTraceTarget;
|
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
2016-06-07 17:46:29 +00:00
|
|
|
* Flags (64-bit)
|
2016-05-06 23:13:11 +00:00
|
|
|
*/
|
2016-06-07 17:46:29 +00:00
|
|
|
uint64_t flags;
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2017-12-04 22:40:10 +00:00
|
|
|
/**
|
|
|
|
* Remote trace level
|
|
|
|
*/
|
|
|
|
Trace::Level remoteTraceLevel;
|
|
|
|
|
2017-05-05 00:12:02 +00:00
|
|
|
/**
|
|
|
|
* Network MTU
|
|
|
|
*/
|
|
|
|
unsigned int mtu;
|
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
2016-06-07 17:46:29 +00:00
|
|
|
* Maximum number of recipients per multicast (not including active bridges)
|
2016-05-06 23:13:11 +00:00
|
|
|
*/
|
2016-06-07 17:46:29 +00:00
|
|
|
unsigned int multicastLimit;
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Number of specialists
|
|
|
|
*/
|
|
|
|
unsigned int specialistCount;
|
2016-04-27 00:11:25 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Number of routes
|
|
|
|
*/
|
|
|
|
unsigned int routeCount;
|
2016-04-27 00:11:25 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Number of ZT-managed static IP assignments
|
|
|
|
*/
|
|
|
|
unsigned int staticIpCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of rule table entries
|
|
|
|
*/
|
|
|
|
unsigned int ruleCount;
|
|
|
|
|
2016-08-04 01:04:08 +00:00
|
|
|
/**
|
|
|
|
* Number of capabilities
|
|
|
|
*/
|
|
|
|
unsigned int capabilityCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of tags
|
|
|
|
*/
|
|
|
|
unsigned int tagCount;
|
|
|
|
|
2017-02-23 19:47:36 +00:00
|
|
|
/**
|
|
|
|
* Number of certificates of ownership
|
|
|
|
*/
|
|
|
|
unsigned int certificateOfOwnershipCount;
|
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Specialist devices
|
|
|
|
*
|
|
|
|
* For each entry the least significant 40 bits are the device's ZeroTier
|
|
|
|
* address and the most significant 24 bits are flags indicating its role.
|
|
|
|
*/
|
|
|
|
uint64_t specialists[ZT_MAX_NETWORK_SPECIALISTS];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statically defined "pushed" routes (including default gateways)
|
|
|
|
*/
|
|
|
|
ZT_VirtualNetworkRoute routes[ZT_MAX_NETWORK_ROUTES];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static IP assignments
|
|
|
|
*/
|
|
|
|
InetAddress staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
|
|
|
|
|
|
|
|
/**
|
2016-08-04 01:04:08 +00:00
|
|
|
* Base network rules
|
2016-05-06 23:13:11 +00:00
|
|
|
*/
|
|
|
|
ZT_VirtualNetworkRule rules[ZT_MAX_NETWORK_RULES];
|
|
|
|
|
2016-08-04 01:04:08 +00:00
|
|
|
/**
|
2016-08-09 15:32:42 +00:00
|
|
|
* Capabilities for this node on this network, in ascending order of capability ID
|
2016-08-04 01:04:08 +00:00
|
|
|
*/
|
|
|
|
Capability capabilities[ZT_MAX_NETWORK_CAPABILITIES];
|
|
|
|
|
|
|
|
/**
|
2016-08-09 15:32:42 +00:00
|
|
|
* Tags for this node on this network, in ascending order of tag ID
|
2016-08-04 01:04:08 +00:00
|
|
|
*/
|
|
|
|
Tag tags[ZT_MAX_NETWORK_TAGS];
|
|
|
|
|
2017-02-23 19:47:36 +00:00
|
|
|
/**
|
|
|
|
* Certificates of ownership for this network member
|
|
|
|
*/
|
|
|
|
CertificateOfOwnership certificatesOfOwnership[ZT_MAX_CERTIFICATES_OF_OWNERSHIP];
|
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Network type (currently just public or private)
|
|
|
|
*/
|
|
|
|
ZT_VirtualNetworkType type;
|
2013-10-18 13:48:02 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Network short name or empty string if not defined
|
|
|
|
*/
|
|
|
|
char name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2016-05-06 23:13:11 +00:00
|
|
|
/**
|
|
|
|
* Certficiate of membership (for private networks)
|
|
|
|
*/
|
|
|
|
CertificateOfMembership com;
|
2013-10-18 13:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|