mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Add DNS TXT resolver (need one for Windows)
This commit is contained in:
parent
01e8fd0b07
commit
846f03504e
3 changed files with 71 additions and 20 deletions
|
@ -8,7 +8,6 @@ else()
|
||||||
cmake_policy(VERSION 3.15)
|
cmake_policy(VERSION 3.15)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
# If building on Windows, set minimum target to Windows 7
|
# If building on Windows, set minimum target to Windows 7
|
||||||
set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
|
set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
|
||||||
|
@ -17,8 +16,8 @@ endif(WIN32)
|
||||||
# ZeroTier One Version Config
|
# ZeroTier One Version Config
|
||||||
|
|
||||||
set(ZEROTIER_ONE_VERSION_MAJOR 1 CACHE INTERNAL "")
|
set(ZEROTIER_ONE_VERSION_MAJOR 1 CACHE INTERNAL "")
|
||||||
set(ZEROTIER_ONE_VERSION_MINOR 4 CACHE INTERNAL "")
|
set(ZEROTIER_ONE_VERSION_MINOR 9 CACHE INTERNAL "")
|
||||||
set(ZEROTIER_ONE_VERSION_REVISION 2 CACHE INTERNAL "")
|
set(ZEROTIER_ONE_VERSION_REVISION 0 CACHE INTERNAL "")
|
||||||
set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "")
|
set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "")
|
||||||
|
|
||||||
# Set a default build type if none was specified
|
# Set a default build type if none was specified
|
||||||
|
@ -42,7 +41,6 @@ option(ZT_DEBUG_TRACE "Debug Trace Messages" OFF)
|
||||||
|
|
||||||
if (BUILD_CENTRAL_CONTROLLER)
|
if (BUILD_CENTRAL_CONTROLLER)
|
||||||
find_package(PostgreSQL REQUIRED)
|
find_package(PostgreSQL REQUIRED)
|
||||||
|
|
||||||
set(ENABLE_SSL_SUPPORT OFF)
|
set(ENABLE_SSL_SUPPORT OFF)
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
set(BUILD_EXAMPLES OFF)
|
set(BUILD_EXAMPLES OFF)
|
||||||
|
@ -62,7 +60,6 @@ project(zerotier-one
|
||||||
DESCRIPTION "ZeroTier One"
|
DESCRIPTION "ZeroTier One"
|
||||||
LANGUAGES CXX C)
|
LANGUAGES CXX C)
|
||||||
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_definitions(-DNOMINMAX)
|
add_definitions(-DNOMINMAX)
|
||||||
else(WIN32)
|
else(WIN32)
|
||||||
|
@ -76,14 +73,13 @@ else(WIN32)
|
||||||
-msse
|
-msse
|
||||||
-msse2
|
-msse2
|
||||||
-msse3
|
-msse3
|
||||||
-msse4.1
|
|
||||||
$<$<CONFIG:Debug>:-g>
|
$<$<CONFIG:Debug>:-g>
|
||||||
$<$<CONFIG:DEBUG>:-O0>
|
$<$<CONFIG:DEBUG>:-O0>
|
||||||
$<$<CONFIG:RELEASE>:-O3>
|
$<$<CONFIG:RELEASE>:-Ofast>
|
||||||
$<$<CONFIG:RELEASE>:-fstack-protector>
|
$<$<CONFIG:RELEASE>:-fstack-protector-strong>
|
||||||
$<$<CONFIG:RELEASE>:-fPIE>
|
$<$<CONFIG:RELEASE>:-fPIE>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-O3>
|
$<$<CONFIG:RELWITHDEBINFO>:-Ofast>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-fstack-protector>
|
$<$<CONFIG:RELWITHDEBINFO>:-fstack-protector-strong>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
||||||
)
|
)
|
||||||
|
@ -97,7 +93,6 @@ else(WIN32)
|
||||||
-msse
|
-msse
|
||||||
-msse2
|
-msse2
|
||||||
-msse3
|
-msse3
|
||||||
-msse4.1
|
|
||||||
$<$<CONFIG:Debug>:-g>
|
$<$<CONFIG:Debug>:-g>
|
||||||
$<$<CONFIG:DEBUG>:-O0>
|
$<$<CONFIG:DEBUG>:-O0>
|
||||||
$<$<CONFIG:RELEASE>:-O3>
|
$<$<CONFIG:RELEASE>:-O3>
|
||||||
|
@ -165,7 +160,7 @@ if(WIN32)
|
||||||
"windows/ZeroTierOne/ZeroTierOneService.h"
|
"windows/ZeroTierOne/ZeroTierOneService.h"
|
||||||
)
|
)
|
||||||
else(WIN32)
|
else(WIN32)
|
||||||
set(libs ${libs} pthread)
|
set(libs ${libs} pthread resolv)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
if(BUILD_CENTRAL_CONTROLLER)
|
if(BUILD_CENTRAL_CONTROLLER)
|
||||||
|
|
|
@ -44,6 +44,14 @@
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#ifndef C_IN
|
||||||
|
#define C_IN ns_c_in
|
||||||
|
#endif
|
||||||
|
#ifndef T_TXT
|
||||||
|
#define T_TXT ns_t_txt
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
@ -54,6 +62,8 @@
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "OSUtils.hpp"
|
#include "OSUtils.hpp"
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
@ -303,6 +313,54 @@ int64_t OSUtils::getFileSize(const char *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> OSUtils::resolveTxt(const char *host)
|
||||||
|
{
|
||||||
|
static std::atomic_bool libresolvInitialized(false);
|
||||||
|
if (!libresolvInitialized.exchange(true))
|
||||||
|
res_init();
|
||||||
|
|
||||||
|
std::vector<std::string> results;
|
||||||
|
|
||||||
|
uint8_t answer[32768];
|
||||||
|
char name[1024];
|
||||||
|
int alen = res_search(host,C_IN,T_TXT,answer,sizeof(answer));
|
||||||
|
if ((alen > 12)&&(alen < sizeof(answer))) {
|
||||||
|
uint8_t *pptr = answer + 12;
|
||||||
|
uint8_t *const end = answer + alen;
|
||||||
|
int explen = dn_expand(answer,end,pptr,name,sizeof(name));
|
||||||
|
if (explen > 0) {
|
||||||
|
pptr += explen;
|
||||||
|
if ((pptr + 2) >= end) return results;
|
||||||
|
unsigned int rtype = ((unsigned int)pptr[0] << 8) | (unsigned int)pptr[1];
|
||||||
|
if (rtype == T_TXT) {
|
||||||
|
pptr += 4;
|
||||||
|
if (pptr >= end) return results;
|
||||||
|
while (pptr < end) {
|
||||||
|
explen = dn_expand(answer,end,pptr,name,sizeof(name));
|
||||||
|
if (explen > 0) {
|
||||||
|
pptr += explen;
|
||||||
|
if ((pptr + 2) >= end) return results;
|
||||||
|
rtype = ((unsigned int)pptr[0] << 8) | (unsigned int)pptr[1];
|
||||||
|
pptr += 10;
|
||||||
|
if (pptr >= end) return results;
|
||||||
|
unsigned int elen = *(pptr++);
|
||||||
|
if (elen) {
|
||||||
|
if ((pptr + elen) > end) return results;
|
||||||
|
if (rtype == T_TXT)
|
||||||
|
results.push_back(std::string((const char *)pptr,elen));
|
||||||
|
pptr += elen;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
bool OSUtils::readFile(const char *path,std::string &buf)
|
bool OSUtils::readFile(const char *path,std::string &buf)
|
||||||
{
|
{
|
||||||
char tmp[16384];
|
char tmp[16384];
|
||||||
|
|
|
@ -199,14 +199,12 @@ public:
|
||||||
static int64_t getFileSize(const char *path);
|
static int64_t getFileSize(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get IP (v4 and/or v6) addresses for a given host
|
* Get full DNS TXT results
|
||||||
*
|
*
|
||||||
* This is a blocking resolver.
|
* @param name DNS FQDN
|
||||||
*
|
* @return TXT record result(s) or empty on error or not found
|
||||||
* @param name Host name
|
|
||||||
* @return IP addresses in InetAddress sort order or empty vector if not found
|
|
||||||
*/
|
*/
|
||||||
static std::vector<InetAddress> resolve(const char *name);
|
static std::vector<std::string> resolveTxt(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Current time in milliseconds since epoch
|
* @return Current time in milliseconds since epoch
|
||||||
|
|
Loading…
Add table
Reference in a new issue