Merge gateways and routes in netconf since they are the same thing.

This commit is contained in:
Adam Ierymenko 2016-05-06 10:57:53 -07:00
parent 9da8bf37d7
commit 0f17077b3d
4 changed files with 35 additions and 57 deletions

View File

@ -82,20 +82,15 @@ 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)
*/
#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.
*/
@ -619,6 +614,22 @@ typedef struct
} v;
} 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
*/

View File

@ -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) {

View File

@ -278,17 +278,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
*/
@ -300,17 +289,6 @@ public:
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
*/
@ -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;

View File

@ -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