mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-02 19:26:41 +00:00
Merge gateways and routes in netconf since they are the same thing.
This commit is contained in:
parent
9da8bf37d7
commit
0f17077b3d
@ -82,20 +82,15 @@ extern "C" {
|
|||||||
#define ZT_MAX_NETWORK_SHORT_NAME_LENGTH 127
|
#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)
|
* Maximum number of statically assigned IP addresses per network endpoint using ZT address management (not DHCP)
|
||||||
*/
|
*/
|
||||||
#define ZT_MAX_ZT_ASSIGNED_ADDRESSES 16
|
#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.
|
* Maximum number of "specialists" on a network -- bridges, relays, etc.
|
||||||
*/
|
*/
|
||||||
@ -619,6 +614,22 @@ typedef struct
|
|||||||
} v;
|
} v;
|
||||||
} ZT_VirtualNetworkRule;
|
} 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
|
* An Ethernet multicast group
|
||||||
*/
|
*/
|
||||||
|
@ -100,17 +100,14 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
|||||||
default: // ignore unrecognized address types or junk/empty fields
|
default: // ignore unrecognized address types or junk/empty fields
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (addr.isNetwork()) {
|
if (!addr.isNetwork()) {
|
||||||
if ((_localRouteCount < ZT_MAX_NETWORK_LOCAL_ROUTES)&&(std::find(&(_localRoutes[0]),&(_localRoutes[_localRouteCount]),addr) == &(_localRoutes[_localRouteCount])))
|
|
||||||
_localRoutes[_localRouteCount++] = addr;
|
|
||||||
} else {
|
|
||||||
if ((_staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)&&(std::find(&(_staticIps[0]),&(_staticIps[_staticIpCount]),addr) == &(_staticIps[_staticIpCount])))
|
if ((_staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)&&(std::find(&(_staticIps[0]),&(_staticIps[_staticIpCount]),addr) == &(_staticIps[_staticIpCount])))
|
||||||
_staticIps[_staticIpCount++] = addr;
|
_staticIps[_staticIpCount++] = addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::sort(&(_localRoutes[0]),&(_localRoutes[_localRouteCount]));
|
|
||||||
std::sort(&(_staticIps[0]),&(_staticIps[_staticIpCount]));
|
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(),",","",""));
|
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) {
|
for(std::vector<std::string>::const_iterator gwstr(gatewaysSplit.begin());gwstr!=gatewaysSplit.end();++gwstr) {
|
||||||
InetAddress gw(*gwstr);
|
InetAddress gw(*gwstr);
|
||||||
@ -118,6 +115,7 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
|||||||
_gateways[_gatewayCount++] = gw;
|
_gateways[_gatewayCount++] = gw;
|
||||||
}
|
}
|
||||||
std::sort(&(_gateways[0]),&(_gateways[_gatewayCount]));
|
std::sort(&(_gateways[0]),&(_gateways[_gatewayCount]));
|
||||||
|
*/
|
||||||
|
|
||||||
std::vector<std::string> relaysSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_RELAYS,"").c_str(),",","",""));
|
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) {
|
for(std::vector<std::string>::const_iterator r(relaysSplit.begin());r!=relaysSplit.end();++r) {
|
||||||
|
@ -278,17 +278,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline const CertificateOfMembership &com() const throw() { return _com; }
|
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
|
* @return ZeroTier-managed static IPs assigned to this device on this network
|
||||||
*/
|
*/
|
||||||
@ -300,17 +289,6 @@ public:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
* @return ZeroTier addresses of devices on this network designated as active bridges
|
||||||
*/
|
*/
|
||||||
@ -436,18 +414,16 @@ public:
|
|||||||
for(unsigned int i=0;i<_specialistCount;++i)
|
for(unsigned int i=0;i<_specialistCount;++i)
|
||||||
b.append((uint64_t)_specialists[i]);
|
b.append((uint64_t)_specialists[i]);
|
||||||
|
|
||||||
b.append((uint16_t)_localRouteCount);
|
b.append((uint16_t)_routeCount);
|
||||||
for(unsigned int i=0;i<_localRouteCount;++i)
|
for(unsigned int i=0;i<_routeCount;++i) {
|
||||||
_localRoutes[i].serialize(b);
|
reinterpret_cast<const InetAddress *>(&(_routes[i].target))->serialize(b);
|
||||||
|
reinterpret_cast<const InetAddress *>(&(_routes[i].via))->serialize(b);
|
||||||
|
}
|
||||||
|
|
||||||
b.append((uint16_t)_staticIpCount);
|
b.append((uint16_t)_staticIpCount);
|
||||||
for(unsigned int i=0;i<_staticIpCount;++i)
|
for(unsigned int i=0;i<_staticIpCount;++i)
|
||||||
_staticIps[i].serialize(b);
|
_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);
|
b.append((uint16_t)_staticCount);
|
||||||
for(unsigned int i=0;i<_staticCount;++i) {
|
for(unsigned int i=0;i<_staticCount;++i) {
|
||||||
_static[i].zt.appendTo(b);
|
_static[i].zt.appendTo(b);
|
||||||
@ -568,11 +544,12 @@ public:
|
|||||||
_specialists[i] = b.template at<uint64_t>(p); p += 8;
|
_specialists[i] = b.template at<uint64_t>(p); p += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
_localRouteCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
_routeCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||||
if (_localRouteCount > ZT_MAX_NETWORK_LOCAL_ROUTES)
|
if (_routeCount > ZT_MAX_NETWORK_ROUTES)
|
||||||
throw std::invalid_argument("overflow (local routes)");
|
throw std::invalid_argument("overflow (routes)");
|
||||||
for(unsigned int i=0;i<_localRouteCount;++i) {
|
for(unsigned int i=0;i<_routeCount;++i) {
|
||||||
p += _localRoutes[i].deserialize(b,p);
|
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;
|
_staticIpCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||||
@ -582,13 +559,6 @@ public:
|
|||||||
p += _staticIps[i].deserialize(b,p);
|
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;
|
_staticCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||||
if (_staticCount > ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)
|
if (_staticCount > ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)
|
||||||
throw std::invalid_argument("overflow (static 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];
|
uint64_t _specialists[ZT_MAX_NETWORK_SPECIALISTS];
|
||||||
|
|
||||||
// ZeroTier-managed IPs and routing table entries and stuff
|
// 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 _staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
|
||||||
InetAddress _gateways[ZT_MAX_NETWORK_GATEWAYS];
|
|
||||||
|
|
||||||
// ZeroTier to physical static mappings
|
// ZeroTier to physical static mappings
|
||||||
struct {
|
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];
|
ZT_VirtualNetworkRule _rules[ZT_MAX_NETWORK_RULES];
|
||||||
|
|
||||||
unsigned int _specialistCount;
|
unsigned int _specialistCount;
|
||||||
unsigned int _localRouteCount;
|
unsigned int _routeCount;
|
||||||
unsigned int _staticIpCount;
|
unsigned int _staticIpCount;
|
||||||
unsigned int _gatewayCount;
|
|
||||||
unsigned int _staticCount;
|
unsigned int _staticCount;
|
||||||
unsigned int _ruleCount;
|
unsigned int _ruleCount;
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ protected:
|
|||||||
unsigned int _revision;
|
unsigned int _revision;
|
||||||
unsigned int _buildNo;
|
unsigned int _buildNo;
|
||||||
unsigned int _flags;
|
unsigned int _flags;
|
||||||
|
char _passcode[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
Loading…
Reference in New Issue
Block a user