summaryrefslogtreecommitdiff
path: root/node/NetworkConfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/NetworkConfig.cpp')
-rw-r--r--node/NetworkConfig.cpp77
1 files changed, 55 insertions, 22 deletions
diff --git a/node/NetworkConfig.cpp b/node/NetworkConfig.cpp
index c78dd995..b3e2c178 100644
--- a/node/NetworkConfig.cpp
+++ b/node/NetworkConfig.cpp
@@ -25,28 +25,59 @@
* LLC. Start here: http://www.zerotier.com/
*/
+#include <stdint.h>
+
#include "NetworkConfig.hpp"
#include "Utils.hpp"
namespace ZeroTier {
// This is fast enough for things like Apple's mDNS spam, so it should serve
-// as a good default for your average network. It's 64 bytes per second, with
-// a starting and max balance of 64k.
-const NetworkConfig::MulticastRate NetworkConfig::DEFAULT_MULTICAST_RATE(32768,32768,64);
+// as a good default for your average network.
+const NetworkConfig::MulticastRate NetworkConfig::DEFAULT_MULTICAST_RATE(40000,60000,80);
+
+SharedPtr<NetworkConfig> NetworkConfig::createTestNetworkConfig(const Address &self)
+{
+ SharedPtr<NetworkConfig> nc(new NetworkConfig());
+
+ memset(nc->_etWhitelist,0,sizeof(nc->_etWhitelist));
+ nc->_etWhitelist[0] |= 1; // allow all
+ nc->_nwid = ZT_TEST_NETWORK_ID;
+ nc->_timestamp = Utils::now();
+ nc->_issuedTo = self;
+ nc->_multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
+ nc->_allowPassiveBridging = false;
+ nc->_private = false;
+ nc->_enableBroadcast = true;
+ nc->_name = "ZT_TEST_NETWORK";
+ nc->_description = "Built-in dummy test network";
+
+ // Make up a V4 IP from 'self' in the 10.0.0.0/8 range -- no
+ // guarantee of uniqueness but collisions are unlikely.
+ uint32_t ip = (uint32_t)((self.toInt() & 0x00ffffff) | 0x0a000000); // 10.x.x.x
+ if ((ip & 0x000000ff) == 0x000000ff) ip ^= 0x00000001; // but not ending in .255
+ if ((ip & 0x000000ff) == 0x00000000) ip ^= 0x00000001; // or .0
+ nc->_staticIps.push_back(InetAddress(Utils::hton(ip),8));
+
+ return nc;
+}
-std::set<unsigned int> NetworkConfig::allowedEtherTypes() const
+std::vector<unsigned int> NetworkConfig::allowedEtherTypes() const
{
- std::set<unsigned int> ets;
- for(unsigned int i=0;i<sizeof(_etWhitelist);++i) {
- if (_etWhitelist[i]) {
- unsigned char b = _etWhitelist[i];
- unsigned int et = i * 8;
- while (b) {
- if ((b & 1))
- ets.insert(et);
- b >>= 1;
- ++et;
+ std::vector<unsigned int> ets;
+ if ((_etWhitelist[0] & 1) != 0) {
+ ets.push_back(0);
+ } else {
+ for(unsigned int i=0;i<sizeof(_etWhitelist);++i) {
+ if (_etWhitelist[i]) {
+ unsigned char b = _etWhitelist[i];
+ unsigned int et = i * 8;
+ while (b) {
+ if ((b & 1))
+ ets.push_back(et);
+ b >>= 1;
+ ++et;
+ }
}
}
}
@@ -85,18 +116,16 @@ void NetworkConfig::_fromDictionary(const Dictionary &d)
_timestamp = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP).c_str());
_issuedTo = Address(d.get(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO));
- _multicastPrefixBits = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_PREFIX_BITS,zero).c_str());
- if (!_multicastPrefixBits)
- _multicastPrefixBits = ZT_DEFAULT_MULTICAST_PREFIX_BITS;
- _multicastDepth = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_DEPTH,zero).c_str());
- if (!_multicastDepth)
- _multicastDepth = ZT_DEFAULT_MULTICAST_DEPTH;
+ _multicastLimit = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,zero).c_str());
+ if (_multicastLimit == 0) _multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
_allowPassiveBridging = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0);
_private = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0);
_enableBroadcast = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0);
_name = d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME);
_description = d.get(ZT_NETWORKCONFIG_DICT_KEY_DESC,std::string());
+ // In dictionary IPs are split into V4 and V6 addresses, but we don't really
+ // need that so merge them here.
std::string ipAddrs(d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC,std::string()));
{
std::string v6s(d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC,std::string()));
@@ -122,17 +151,21 @@ void NetworkConfig::_fromDictionary(const Dictionary &d)
default: // ignore unrecognized address types or junk/empty fields
continue;
}
- _staticIps.insert(addr);
+ _staticIps.push_back(addr);
}
+ std::sort(_staticIps.begin(),_staticIps.end());
+ std::unique(_staticIps.begin(),_staticIps.end());
std::vector<std::string> activeBridgesSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES,"").c_str(),",","",""));
for(std::vector<std::string>::const_iterator a(activeBridgesSplit.begin());a!=activeBridgesSplit.end();++a) {
if (a->length() == ZT_ADDRESS_LENGTH_HEX) { // ignore empty or garbage fields
Address tmp(*a);
if (!tmp.isReserved())
- _activeBridges.insert(tmp);
+ _activeBridges.push_back(tmp);
}
}
+ std::sort(_activeBridges.begin(),_activeBridges.end());
+ std::unique(_activeBridges.begin(),_activeBridges.end());
Dictionary multicastRateEntries(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_RATES,std::string()));
for(Dictionary::const_iterator i(multicastRateEntries.begin());i!=multicastRateEntries.end();++i) {