summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-05-06 10:57:53 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-05-06 10:57:53 -0700
commit0f17077b3d592d5c39374cf44fe5ea1173d7109c (patch)
treef4e99971eaedc50f7c76e85fa9fde55af0d35eb6
parent9da8bf37d783cb1ac9b9c72a8effe2ce7c904ab6 (diff)
downloadinfinitytier-0f17077b3d592d5c39374cf44fe5ea1173d7109c.tar.gz
infinitytier-0f17077b3d592d5c39374cf44fe5ea1173d7109c.zip
Merge gateways and routes in netconf since they are the same thing.
-rw-r--r--include/ZeroTierOne.h25
-rw-r--r--node/NetworkConfig.cpp8
-rw-r--r--node/NetworkConfig.hpp58
-rw-r--r--node/NetworkConfigRequestMetaData.hpp1
4 files changed, 35 insertions, 57 deletions
diff --git a/include/ZeroTierOne.h b/include/ZeroTierOne.h
index 465fd892..6f0517ba 100644
--- a/include/ZeroTierOne.h
+++ b/include/ZeroTierOne.h
@@ -82,9 +82,9 @@ extern "C" {
#define ZT_MAX_NETWORK_SHORT_NAME_LENGTH 127
/**
- * Maximum number of local routes on a network
+ * Maximum number of pushed routes on a network
*/
-#define ZT_MAX_NETWORK_LOCAL_ROUTES 16
+#define ZT_MAX_NETWORK_ROUTES 32
/**
* Maximum number of statically assigned IP addresses per network endpoint using ZT address management (not DHCP)
@@ -92,11 +92,6 @@ extern "C" {
#define ZT_MAX_ZT_ASSIGNED_ADDRESSES 16
/**
- * Maximum number of default routes / gateways on a network (ZT managed)
- */
-#define ZT_MAX_NETWORK_GATEWAYS 8
-
-/**
* Maximum number of "specialists" on a network -- bridges, relays, etc.
*/
#define ZT_MAX_NETWORK_SPECIALISTS 256
@@ -620,6 +615,22 @@ typedef struct
} ZT_VirtualNetworkRule;
/**
+ * A route to be pushed on a virtual network
+ */
+typedef struct
+{
+ /**
+ * Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
+ */
+ struct sockaddr_storage target;
+
+ /**
+ * Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
+ */
+ struct sockaddr_storage via;
+} ZT_VirtualNetworkRoute;
+
+/**
* An Ethernet multicast group
*/
typedef struct
diff --git a/node/NetworkConfig.cpp b/node/NetworkConfig.cpp
index 66c1c3ee..14e555f9 100644
--- a/node/NetworkConfig.cpp
+++ b/node/NetworkConfig.cpp
@@ -100,17 +100,14 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
default: // ignore unrecognized address types or junk/empty fields
continue;
}
- if (addr.isNetwork()) {
- if ((_localRouteCount < ZT_MAX_NETWORK_LOCAL_ROUTES)&&(std::find(&(_localRoutes[0]),&(_localRoutes[_localRouteCount]),addr) == &(_localRoutes[_localRouteCount])))
- _localRoutes[_localRouteCount++] = addr;
- } else {
+ if (!addr.isNetwork()) {
if ((_staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)&&(std::find(&(_staticIps[0]),&(_staticIps[_staticIpCount]),addr) == &(_staticIps[_staticIpCount])))
_staticIps[_staticIpCount++] = addr;
}
}
- std::sort(&(_localRoutes[0]),&(_localRoutes[_localRouteCount]));
std::sort(&(_staticIps[0]),&(_staticIps[_staticIpCount]));
+ /* Old versions don't support gateways anyway, so ignore this in old netconfs
std::vector<std::string> gatewaysSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_GATEWAYS,"").c_str(),",","",""));
for(std::vector<std::string>::const_iterator gwstr(gatewaysSplit.begin());gwstr!=gatewaysSplit.end();++gwstr) {
InetAddress gw(*gwstr);
@@ -118,6 +115,7 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
_gateways[_gatewayCount++] = gw;
}
std::sort(&(_gateways[0]),&(_gateways[_gatewayCount]));
+ */
std::vector<std::string> relaysSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_RELAYS,"").c_str(),",","",""));
for(std::vector<std::string>::const_iterator r(relaysSplit.begin());r!=relaysSplit.end();++r) {
diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp
index 73f1e3f2..00277585 100644
--- a/node/NetworkConfig.hpp
+++ b/node/NetworkConfig.hpp
@@ -279,17 +279,6 @@ public:
inline const CertificateOfMembership &com() const throw() { return _com; }
/**
- * @return Network/netmask routes that are considered local to this virtual LAN interface
- */
- inline std::vector<InetAddress> localRoutes() const
- {
- std::vector<InetAddress> r;
- for(unsigned int i=0;i<_localRouteCount;++i)
- r.push_back(_localRoutes[i]);
- return r;
- }
-
- /**
* @return ZeroTier-managed static IPs assigned to this device on this network
*/
inline std::vector<InetAddress> staticIps() const
@@ -301,17 +290,6 @@ public:
}
/**
- * @return ZeroTier-managed default gateways (for full tunnel) available on this network
- */
- inline std::vector<InetAddress> gateways() const
- {
- std::vector<InetAddress> r;
- for(unsigned int i=0;i<_gatewayCount;++i)
- r.push_back(_gateways[i]);
- return r;
- }
-
- /**
* @return ZeroTier addresses of devices on this network designated as active bridges
*/
inline std::vector<Address> activeBridges() const
@@ -436,18 +414,16 @@ public:
for(unsigned int i=0;i<_specialistCount;++i)
b.append((uint64_t)_specialists[i]);
- b.append((uint16_t)_localRouteCount);
- for(unsigned int i=0;i<_localRouteCount;++i)
- _localRoutes[i].serialize(b);
+ b.append((uint16_t)_routeCount);
+ for(unsigned int i=0;i<_routeCount;++i) {
+ reinterpret_cast<const InetAddress *>(&(_routes[i].target))->serialize(b);
+ reinterpret_cast<const InetAddress *>(&(_routes[i].via))->serialize(b);
+ }
b.append((uint16_t)_staticIpCount);
for(unsigned int i=0;i<_staticIpCount;++i)
_staticIps[i].serialize(b);
- b.append((uint16_t)_gatewayCount);
- for(unsigned int i=0;i<_gatewayCount;++i)
- _gateways[i].serialize(b);
-
b.append((uint16_t)_staticCount);
for(unsigned int i=0;i<_staticCount;++i) {
_static[i].zt.appendTo(b);
@@ -568,11 +544,12 @@ public:
_specialists[i] = b.template at<uint64_t>(p); p += 8;
}
- _localRouteCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
- if (_localRouteCount > ZT_MAX_NETWORK_LOCAL_ROUTES)
- throw std::invalid_argument("overflow (local routes)");
- for(unsigned int i=0;i<_localRouteCount;++i) {
- p += _localRoutes[i].deserialize(b,p);
+ _routeCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
+ if (_routeCount > ZT_MAX_NETWORK_ROUTES)
+ throw std::invalid_argument("overflow (routes)");
+ for(unsigned int i=0;i<_routeCount;++i) {
+ p += reinterpret_cast<InetAddress *>(&(_routes[i].target))->deserialize(b,p);
+ p += reinterpret_cast<InetAddress *>(&(_routes[i].via))->deserialize(b,p);
}
_staticIpCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
@@ -582,13 +559,6 @@ public:
p += _staticIps[i].deserialize(b,p);
}
- _gatewayCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
- if (_gatewayCount > ZT_MAX_NETWORK_GATEWAYS)
- throw std::invalid_argument("overflow (gateways)");
- for(unsigned int i=0;i<_gatewayCount;++i) {
- p += _gateways[i].deserialize(b,p);
- }
-
_staticCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
if (_staticCount > ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)
throw std::invalid_argument("overflow (static addresses)");
@@ -688,9 +658,8 @@ protected: // protected so that a subclass can fill this out in network controll
uint64_t _specialists[ZT_MAX_NETWORK_SPECIALISTS];
// ZeroTier-managed IPs and routing table entries and stuff
- InetAddress _localRoutes[ZT_MAX_NETWORK_LOCAL_ROUTES];
+ ZT_VirtualNetworkRoute _routes[ZT_MAX_NETWORK_ROUTES];
InetAddress _staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
- InetAddress _gateways[ZT_MAX_NETWORK_GATEWAYS];
// ZeroTier to physical static mappings
struct {
@@ -702,9 +671,8 @@ protected: // protected so that a subclass can fill this out in network controll
ZT_VirtualNetworkRule _rules[ZT_MAX_NETWORK_RULES];
unsigned int _specialistCount;
- unsigned int _localRouteCount;
+ unsigned int _routeCount;
unsigned int _staticIpCount;
- unsigned int _gatewayCount;
unsigned int _staticCount;
unsigned int _ruleCount;
diff --git a/node/NetworkConfigRequestMetaData.hpp b/node/NetworkConfigRequestMetaData.hpp
index 757ed20b..5bf8bac4 100644
--- a/node/NetworkConfigRequestMetaData.hpp
+++ b/node/NetworkConfigRequestMetaData.hpp
@@ -53,6 +53,7 @@ protected:
unsigned int _revision;
unsigned int _buildNo;
unsigned int _flags;
+ char _passcode[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
};
} // namespace ZeroTier