Merge branch 'dns' into dev
This commit is contained in:
commit
8d0a3563e4
27 changed files with 822 additions and 21 deletions
56
node/DNS.hpp
Normal file
56
node/DNS.hpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c)2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2023-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
#ifndef ZT_DNS_HPP
|
||||
#define ZT_DNS_HPP
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Buffer.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
#include "../include/ZeroTierOne.h"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
* DNS data serealization methods
|
||||
*/
|
||||
class DNS {
|
||||
public:
|
||||
template<unsigned int C>
|
||||
static inline void serializeDNS(Buffer<C> &b, const ZT_VirtualNetworkDNS *dns)
|
||||
{
|
||||
b.append(dns->domain, 128);
|
||||
for(unsigned int j = 0; j < ZT_MAX_DNS_SERVERS; ++j) {
|
||||
InetAddress tmp(dns->server_addr[j]);
|
||||
tmp.serialize(b);
|
||||
}
|
||||
}
|
||||
|
||||
template<unsigned int C>
|
||||
static inline void deserializeDNS(const Buffer<C> &b, unsigned int &p, ZT_VirtualNetworkDNS *dns)
|
||||
{
|
||||
char *d = (char*)b.data()+p;
|
||||
memset(dns, 0, sizeof(ZT_VirtualNetworkDNS));
|
||||
memcpy(dns->domain, d, 128);
|
||||
p += 128;
|
||||
for (unsigned int j = 0; j < ZT_MAX_DNS_SERVERS; ++j) {
|
||||
p += reinterpret_cast<InetAddress *>(&(dns->server_addr[j]))->deserialize(b, p);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ZT_DNS_HPP
|
|
@ -586,6 +586,7 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
|
|||
|
||||
if (!_portInitialized) {
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
memset(&ctmp, 0, sizeof(ZT_VirtualNetworkConfig));
|
||||
_externalConfig(&ctmp);
|
||||
_portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||
_portInitialized = true;
|
||||
|
@ -1426,6 +1427,8 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
|||
ec->multicastSubscriptions[i].mac = _myMulticastGroups[i].mac().toInt();
|
||||
ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi();
|
||||
}
|
||||
|
||||
memcpy(&ec->dns, &_config.dns, sizeof(ZT_VirtualNetworkDNS));
|
||||
}
|
||||
|
||||
void Network::_sendUpdatesToMembers(void *tPtr,const MulticastGroup *const newMulticastGroup)
|
||||
|
|
|
@ -176,6 +176,12 @@ bool NetworkConfig::toDictionary(Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d,b
|
|||
}
|
||||
}
|
||||
|
||||
tmp->clear();
|
||||
DNS::serializeDNS(*tmp, &dns);
|
||||
if (tmp->size()) {
|
||||
if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_DNS,*tmp)) return false;
|
||||
}
|
||||
|
||||
delete tmp;
|
||||
} catch ( ... ) {
|
||||
delete tmp;
|
||||
|
@ -354,6 +360,11 @@ bool NetworkConfig::fromDictionary(const Dictionary<ZT_NETWORKCONFIG_DICT_CAPACI
|
|||
unsigned int p = 0;
|
||||
Capability::deserializeRules(*tmp,p,this->rules,this->ruleCount,ZT_MAX_NETWORK_RULES);
|
||||
}
|
||||
|
||||
if (d.get(ZT_NETWORKCONFIG_DICT_KEY_DNS, *tmp)) {
|
||||
unsigned int p = 0;
|
||||
DNS::deserializeDNS(*tmp, p, &dns);
|
||||
}
|
||||
}
|
||||
|
||||
//printf("~~~\n%s\n~~~\n",d.data());
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "Constants.hpp"
|
||||
#include "Buffer.hpp"
|
||||
#include "DNS.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
#include "MulticastGroup.hpp"
|
||||
#include "Address.hpp"
|
||||
|
@ -175,6 +176,8 @@ namespace ZeroTier {
|
|||
#define ZT_NETWORKCONFIG_DICT_KEY_TAGS "TAG"
|
||||
// tags (binary blobs)
|
||||
#define ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATES_OF_OWNERSHIP "COO"
|
||||
// dns (binary blobs)
|
||||
#define ZT_NETWORKCONFIG_DICT_KEY_DNS "DNS"
|
||||
|
||||
// Legacy fields -- these are obsoleted but are included when older clients query
|
||||
|
||||
|
@ -229,13 +232,15 @@ public:
|
|||
capabilities(),
|
||||
tags(),
|
||||
certificatesOfOwnership(),
|
||||
type(ZT_NETWORK_TYPE_PRIVATE)
|
||||
type(ZT_NETWORK_TYPE_PRIVATE),
|
||||
dnsCount(0)
|
||||
{
|
||||
name[0] = 0;
|
||||
memset(specialists, 0, sizeof(uint64_t)*ZT_MAX_NETWORK_SPECIALISTS);
|
||||
memset(routes, 0, sizeof(ZT_VirtualNetworkRoute)*ZT_MAX_NETWORK_ROUTES);
|
||||
memset(staticIps, 0, sizeof(InetAddress)*ZT_MAX_ZT_ASSIGNED_ADDRESSES);
|
||||
memset(rules, 0, sizeof(ZT_VirtualNetworkRule)*ZT_MAX_NETWORK_RULES);
|
||||
memset(&dns, 0, sizeof(ZT_VirtualNetworkDNS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -589,6 +594,16 @@ public:
|
|||
* Certificate of membership (for private networks)
|
||||
*/
|
||||
CertificateOfMembership com;
|
||||
|
||||
/**
|
||||
* Number of ZT-pushed DNS configurations
|
||||
*/
|
||||
unsigned int dnsCount;
|
||||
|
||||
/**
|
||||
* ZT pushed DNS configuration
|
||||
*/
|
||||
ZT_VirtualNetworkDNS dns;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue