Windows now builds at least to the point of running zt_core_tests. Go will need a revision to the command in CMake files.

This commit is contained in:
Adam Ierymenko 2020-06-16 21:21:24 -07:00
parent b165b9dd4f
commit a472aafb3e
11 changed files with 76 additions and 52 deletions

4
build.bat Normal file
View file

@ -0,0 +1,4 @@
echo off
mkdir build
cd build
cmake .. -G "MinGW Makefiles"

View file

@ -512,6 +512,9 @@ void AES::GMAC::finish(uint8_t tag[16]) noexcept
#ifdef ZT_AES_AESNI
#if !defined(__WINDOWS__)
#define ZT_AES_VAES512
static
__attribute__((__target__("sse4,avx,avx2,vaes,avx512f,avx512bw")))
void p_aesCtrInnerVAES512(unsigned int &len, const uint64_t c0, uint64_t &c1, const uint8_t *&in, uint8_t *&out, const __m128i *const k) noexcept
@ -562,6 +565,7 @@ void p_aesCtrInnerVAES512(unsigned int &len, const uint64_t c0, uint64_t &c1, co
} while (len >= 64);
}
#define ZT_AES_VAES256
static
__attribute__((__target__("sse4,avx,avx2,vaes")))
void p_aesCtrInnerVAES256(unsigned int &len, uint64_t &c0, uint64_t &c1, const uint8_t *&in, uint8_t *&out, const __m128i *const k) noexcept
@ -630,6 +634,8 @@ void p_aesCtrInnerVAES256(unsigned int &len, uint64_t &c0, uint64_t &c1, const u
} while (len >= 64);
}
#endif
static void p_aesCtrInner128(unsigned int &len, uint64_t &c0, uint64_t &c1, const uint8_t *&in, uint8_t *&out, const __m128i *const k) noexcept
{
const __m128i k0 = k[0];
@ -787,6 +793,7 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
_len = totalLen + len;
if (likely(len >= 64)) {
#if defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
if (Utils::CPUID.vaes) {
if ((!Utils::CPUID.avx512f) || ((len < 1024))) {
p_aesCtrInnerVAES256(len, c0, c1, in, out, k);
@ -794,8 +801,11 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
p_aesCtrInnerVAES512(len, c0, c1, in, out, k);
}
} else {
#endif
p_aesCtrInner128(len, c0, c1, in, out, k);
#if defined(ZT_AES_VAES512) && defined(ZT_AES_VAES256)
}
#endif
}
while (len >= 16) {

View file

@ -17,7 +17,9 @@
#include "zerotier.h"
#include "OS.hpp"
#if __has_include("version.h")
#include "version.h"
#endif
/**
* Version bit packed into four 16-bit fields in a 64-bit unsigned integer.

View file

@ -11,8 +11,7 @@
*/
/****/
#include <cstring>
#include <cstdint>
#define _WIN32_WINNT 0x06010000
#include "Constants.hpp"
#include "InetAddress.hpp"

View file

@ -37,7 +37,10 @@
#undef __UNIX_LIKE__
#undef __BSD__
#include <WinSock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#include <shlwapi.h>
#include <Shlobj.h>
#include <sys/param.h>
#endif

View file

@ -57,13 +57,8 @@ static int64_t now()
{
#ifdef __WINDOWS__
FILETIME ft;
SYSTEMTIME st;
ULARGE_INTEGER tmp;
GetSystemTime(&st);
SystemTimeToFileTime(&st,&ft);
tmp.LowPart = ft.dwLowDateTime;
tmp.HighPart = ft.dwHighDateTime;
return (int64_t)( ((tmp.QuadPart - 116444736000000000LL) / 10000L) + st.wMilliseconds );
GetSystemTimeAsFileTime(&ft);
return (((LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32)) / 10000LL) - 116444736000000000LL;
#else
timeval tv; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
gettimeofday(&tv,nullptr);

View file

@ -27,6 +27,7 @@
#include <time.h>
#ifdef __WINDOWS__
#include <intrin.h>
#include <wincrypt.h>
#endif

View file

@ -16,11 +16,9 @@
#include "../core/Containers.hpp"
#include "OSUtils.hpp"
#ifdef __WINDOWS__
#include <WinSock2.h>
#include <Windows.h>
#include <Shlwapi.h>
#else
#include <sys/stat.h>
#ifndef __WINDOWS__
#include <dirent.h>
#include <fcntl.h>
#endif
@ -339,13 +337,15 @@ ZeroTier::String OSUtils::platformDefaultHomePath()
#ifdef __WINDOWS__
// Look up app data folder on Windows, e.g. C:\ProgramData\...
char buf[16384];
if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
return (ZeroTier::String(buf) + "\\ZeroTier");
else return ZeroTier::String("C:\\ZeroTier");
if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf))) {
ZeroTier::String tmp(buf);
tmp.append("\\ZeroTier");
return tmp;
} else {
return ZeroTier::String("C:\\ZeroTier");
}
#else
return (ZeroTier::String(ZT_PATH_SEPARATOR_S) + "ZeroTier"); // UNKNOWN PLATFORM
#endif
#endif // __UNIX_LIKE__ or not...

View file

@ -21,7 +21,7 @@
#include <time.h>
#ifndef __WINDOWS__
#include <sys/time.h> // NOLINT(modernize-deprecated-headers)
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
@ -154,13 +154,8 @@ public:
{
#ifdef __WINDOWS__
FILETIME ft;
SYSTEMTIME st;
ULARGE_INTEGER tmp;
GetSystemTime(&st);
SystemTimeToFileTime(&st,&ft);
tmp.LowPart = ft.dwLowDateTime;
tmp.HighPart = ft.dwHighDateTime;
return (int64_t)( ((tmp.QuadPart - 116444736000000000LL) / 10000L) + st.wMilliseconds );
GetSystemTimeAsFileTime(&ft);
return (((LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32)) / 10000LL) - 116444736000000000LL;
#else
#ifdef __LINUX__
timespec ts;

View file

@ -11,6 +11,8 @@
*/
/****/
#define _WIN32_WINNT 0x06010000
#include "../core/Constants.hpp"
#ifdef __WINDOWS__
@ -30,7 +32,8 @@
#include <IPHlpApi.h>
#include <nldef.h>
#include <netioapi.h>
#include <atlbase.h>
#include <ipmib.h>
//#include <atlbase.h>
#include <netlistmgr.h>
#include <nldef.h>
#include <SetupAPI.h>
@ -46,7 +49,7 @@
#include "WindowsEthernetTap.hpp"
#include "OSUtils.hpp"
#include "..\windows\TapDriver6\tap-windows.h"
#include "../installsupport/windows/tap-windows-ndis6/src/tap-windows-ndis6/tap-windows.h"
#include <netcon.h>
@ -790,10 +793,10 @@ void WindowsEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherTyp
_injectPending.emplace();
_injectPending.back().len = len + 14;
char *const d = _injectPending.back().data;
to.copyTo(d,6);
from.copyTo(d + 6,6);
d[12] = (char)((etherType >> 8) & 0xff);
d[13] = (char)(etherType & 0xff);
to.copyTo((uint8_t *)d);
from.copyTo((uint8_t *)(d + 6));
d[12] = (char)((etherType >> 8U) & 0xffU);
d[13] = (char)(etherType & 0xffU);
memcpy(d + 14,data,len);
ReleaseSemaphore(_injectSemaphore,1,NULL);
@ -893,7 +896,7 @@ void WindowsEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,
MAC mac;
DWORD i = 0;
while ((i + 6) <= bytesReturned) {
mac.setTo(mcastbuf + i,6);
mac.setTo((uint8_t *)(mcastbuf + i));
i += 6;
if ((mac.isMulticast())&&(!mac.isBroadcast())) {
// exclude the nulls that may be returned or any other junk Windows puts in there
@ -1049,7 +1052,7 @@ void WindowsEthernetTap::threadMain()
nr.NextHop.si_family = AF_INET;
nr.NextHop.Ipv4.sin_addr.s_addr = fakeIp;
nr.Metric = 9999; // do not use as real default route
nr.Protocol = MIB_IPPROTO_NETMGMT;
nr.Protocol = (NL_ROUTE_PROTOCOL)MIB_IPPROTO_NETMGMT;
DWORD result = CreateIpForwardEntry2(&nr);
if (result != NO_ERROR)
Sleep(250);
@ -1128,11 +1131,11 @@ void WindowsEthernetTap::threadMain()
DWORD bytesRead = 0;
if (GetOverlappedResult(_tap,&tapOvlRead,&bytesRead,FALSE)) {
if ((bytesRead > 14)&&(_enabled)) {
MAC to(tapReadBuf,6);
MAC from(tapReadBuf + 6,6);
unsigned int etherType = ((((unsigned int)tapReadBuf[12]) & 0xff) << 8) | (((unsigned int)tapReadBuf[13]) & 0xff);
MAC to((uint8_t *)tapReadBuf);
MAC from((uint8_t *)(tapReadBuf + 6));
unsigned int etherType = ((((unsigned int)tapReadBuf[12]) & 0xffU) << 8U) | (((unsigned int)tapReadBuf[13]) & 0xffU);
try {
_handler(_arg,(void *)0,_nwid,from,to,etherType,0,tapReadBuf + 14,bytesRead - 14);
_handler(_arg,nullptr,_nwid,from,to,etherType,0,tapReadBuf + 14,bytesRead - 14);
} catch ( ... ) {} // handlers should not throw
}
}

View file

@ -11,6 +11,8 @@
*/
/****/
#define _WIN32_WINNT 0x06010000
#include "GoGlue.h"
#include "../core/Constants.hpp"
@ -198,19 +200,19 @@ static ZT_INLINE void doUdpSend(ZT_SOCKET sock, const struct sockaddr_storage *a
#else
int tmp = (int)ipTTL;
#endif
setsockopt(sock, IPPROTO_IP, IP_TTL, &tmp, sizeof(tmp));
sendto(sock, data, len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in));
setsockopt(sock, IPPROTO_IP, IP_TTL, reinterpret_cast<const char *>(&tmp), sizeof(tmp));
sendto(sock, reinterpret_cast<const char *>(data), len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in));
tmp = 255;
setsockopt(sock, IPPROTO_IP, IP_TTL, &tmp, sizeof(tmp));
setsockopt(sock, IPPROTO_IP, IP_TTL, reinterpret_cast<const char *>(&tmp), sizeof(tmp));
} else {
sendto(sock, data, len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in));
sendto(sock, reinterpret_cast<const char *>(data), len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in));
}
break;
case AF_INET6:
// The ipTTL option isn't currently used with IPv6. It's only used
// with IPv4 "firewall opener" / "NAT buster" preamble packets as part
// of IPv4 NAT traversal.
sendto(sock, data, len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in6));
sendto(sock, reinterpret_cast<const char *>(data), len, MSG_DONTWAIT, (const sockaddr *)addr, sizeof(struct sockaddr_in6));
break;
}
}
@ -368,8 +370,13 @@ extern "C" void ZT_GoNode_delete(ZT_GoNode *gn)
gn->threads_l.lock();
for (auto t = gn->threads.begin(); t != gn->threads.end(); ++t) {
t->second.run = false;
#ifdef __WINDOWS__
shutdown(t->first, SD_BOTH);
closesocket(t->first);
#else
shutdown(t->first, SHUT_RDWR);
close(t->first);
#endif
t->second.thr.join();
}
gn->threads_l.unlock();
@ -412,23 +419,23 @@ static void setCommonUdpSocketSettings(ZT_SOCKET udpSock, const char *dev)
#ifdef SO_REUSEPORT
fl = SETSOCKOPT_FLAG_TRUE;
setsockopt(udpSock, SOL_SOCKET, SO_REUSEPORT, (void *)&fl, sizeof(fl));
setsockopt(udpSock, SOL_SOCKET, SO_REUSEPORT, &fl, sizeof(fl));
#endif
#ifndef __LINUX__ // linux wants just SO_REUSEPORT
fl = SETSOCKOPT_FLAG_TRUE;
setsockopt(udpSock, SOL_SOCKET, SO_REUSEADDR, (void *)&fl, sizeof(fl));
setsockopt(udpSock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char *>(&fl), sizeof(fl));
#endif
fl = SETSOCKOPT_FLAG_TRUE;
setsockopt(udpSock, SOL_SOCKET, SO_BROADCAST, (void *)&fl, sizeof(fl));
setsockopt(udpSock, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char *>(&fl), sizeof(fl));
#ifdef IP_DONTFRAG
fl = SETSOCKOPT_FLAG_FALSE;
setsockopt(udpSock,IPPROTO_IP,IP_DONTFRAG,(void *)&fl,sizeof(fl));
setsockopt(udpSock,IPPROTO_IP,IP_DONTFRAG,&fl,sizeof(fl));
#endif
#ifdef IP_MTU_DISCOVER
fl = SETSOCKOPT_FLAG_FALSE;
setsockopt(udpSock,IPPROTO_IP,IP_MTU_DISCOVER,(void *)&fl,sizeof(fl));
setsockopt(udpSock,IPPROTO_IP,IP_MTU_DISCOVER,&fl,sizeof(fl));
#endif
#ifdef SO_BINDTODEVICE
@ -462,7 +469,7 @@ extern "C" int ZT_GoNode_phyStartListen(ZT_GoNode *gn, const char *dev, const ch
setsockopt(udpSock, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&fl, sizeof(fl));
#ifdef IPV6_DONTFRAG
fl = SETSOCKOPT_FLAG_FALSE;
setsockopt(udpSock,IPPROTO_IPV6,IPV6_DONTFRAG,&fl,sizeof(fl));
setsockopt(udpSock, IPPROTO_IPV6, IPV6_DONTFRAG, reinterpret_cast<const char *>(&fl), sizeof(fl));
#endif
if (bind(udpSock, reinterpret_cast<const struct sockaddr *>(&in6), sizeof(in6)) != 0)
@ -483,7 +490,7 @@ extern "C" int ZT_GoNode_phyStartListen(ZT_GoNode *gn, const char *dev, const ch
salen = sizeof(in6);
void *buf = ZT_getBuffer();
if (buf) {
int s = (int)recvfrom(udpSock, buf, 16384, 0, reinterpret_cast<struct sockaddr *>(&in6), &salen);
int s = (int)recvfrom(udpSock, reinterpret_cast<char *>(buf), 16384, 0, reinterpret_cast<struct sockaddr *>(&in6), &salen);
if (s > 0) {
ZT_Node_processWirePacket(
reinterpret_cast<ZT_Node *>(gn->node),
@ -538,7 +545,7 @@ extern "C" int ZT_GoNode_phyStartListen(ZT_GoNode *gn, const char *dev, const ch
salen = sizeof(in4);
void *buf = ZT_getBuffer();
if (buf) {
int s = (int)recvfrom(udpSock, buf, sizeof(buf), 0, reinterpret_cast<struct sockaddr *>(&in4), &salen);
int s = (int)recvfrom(udpSock, reinterpret_cast<char *>(buf), sizeof(buf), 0, reinterpret_cast<struct sockaddr *>(&in4), &salen);
if (s > 0) {
ZT_Node_processWirePacket(
reinterpret_cast<ZT_Node *>(gn->node),
@ -570,8 +577,13 @@ extern "C" int ZT_GoNode_phyStopListen(ZT_GoNode *gn, const char *dev, const cha
for (auto t = gn->threads.begin(); t != gn->threads.end();) {
if ((t->second.ip == ip) && (t->second.port == port)) {
t->second.run = false;
#ifdef __WINDOWS__
shutdown(t->first, SD_BOTH);
closesocket(t->first);
#else
shutdown(t->first, SHUT_RDWR);
close(t->first);
#endif
t->second.thr.join();
gn->threads.erase(t++);
} else ++t;