mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 05:28:01 +00:00
Fixes for possible ARM issues, cleanup, fix for spurious meaningless exceptions on NETWORK_CONFIG_REQUEST
This commit is contained in:
parent
0daff26fba
commit
c6a39ed927
@ -54,7 +54,7 @@ ifeq ($(ZT_RULES_ENGINE_DEBUGGING),1)
|
||||
endif
|
||||
|
||||
ifeq ($(ZT_DEBUG),1)
|
||||
DEFS+=-DZT_TRACE
|
||||
# DEFS+=-DZT_TRACE
|
||||
override CFLAGS+=-Wall -g -O -pthread $(INCLUDES) $(DEFS)
|
||||
override CXXFLAGS+=-Wall -g -O -std=c++11 -pthread $(INCLUDES) $(DEFS)
|
||||
override LDFLAGS+=
|
||||
@ -96,6 +96,12 @@ endif
|
||||
ifeq ($(CC_MACH),arm)
|
||||
ZT_ARCHITECTURE=3
|
||||
endif
|
||||
ifeq ($(CC_MACH),armv6)
|
||||
ZT_ARCHITECTURE=3
|
||||
endif
|
||||
ifeq ($(CC_MACH),armv7)
|
||||
ZT_ARCHITECTURE=3
|
||||
endif
|
||||
ifeq ($(CC_MACH),arm64)
|
||||
ZT_ARCHITECTURE=4
|
||||
endif
|
||||
@ -104,6 +110,12 @@ ifeq ($(CC_MACH),aarch64)
|
||||
endif
|
||||
DEFS+=-DZT_BUILD_PLATFORM=1 -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
|
||||
|
||||
# Define some conservative CPU instruction set flags for arm32 since there's a ton of variation out there
|
||||
ifeq ($(ZT_ARCHITECTURE),3)
|
||||
override CFLAGS+=-march=armv6zk -mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp
|
||||
override CXXFLAGS+=-march=armv6zk -mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp
|
||||
endif
|
||||
|
||||
# Define this to build a static binary, which is needed to make this runnable on a few ancient Linux distros
|
||||
ifeq ($(ZT_STATIC),1)
|
||||
override LDFLAGS+=-static
|
||||
|
@ -61,15 +61,23 @@ public:
|
||||
|
||||
Dictionary(const char *s)
|
||||
{
|
||||
Utils::scopy(_d,sizeof(_d),s);
|
||||
if (s) {
|
||||
Utils::scopy(_d,sizeof(_d),s);
|
||||
} else {
|
||||
_d[0] = (char)0;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary(const char *s,unsigned int len)
|
||||
{
|
||||
if (len > (C-1))
|
||||
len = C-1;
|
||||
memcpy(_d,s,len);
|
||||
_d[len] = (char)0;
|
||||
if (s) {
|
||||
if (len > (C-1))
|
||||
len = C-1;
|
||||
memcpy(_d,s,len);
|
||||
_d[len] = (char)0;
|
||||
} else {
|
||||
_d[0] = (char)0;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary(const Dictionary &d)
|
||||
@ -91,7 +99,12 @@ public:
|
||||
*/
|
||||
inline bool load(const char *s)
|
||||
{
|
||||
return Utils::scopy(_d,sizeof(_d),s);
|
||||
if (s) {
|
||||
return Utils::scopy(_d,sizeof(_d),s);
|
||||
} else {
|
||||
_d[0] = (char)0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -836,7 +836,7 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,const S
|
||||
bool trustEstablished = false;
|
||||
|
||||
unsigned int p = ZT_PACKET_IDX_PAYLOAD;
|
||||
while ((p < size())&&((*this)[p])) {
|
||||
while ((p < size())&&((*this)[p] != 0)) {
|
||||
p += com.deserialize(*this,p);
|
||||
if (com) {
|
||||
const SharedPtr<Network> network(RR->node->network(com.networkId()));
|
||||
@ -953,8 +953,8 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
||||
const uint64_t requestPacketId = packetId();
|
||||
|
||||
if (RR->localNetworkController) {
|
||||
const unsigned int metaDataLength = at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN);
|
||||
const char *metaDataBytes = (const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength);
|
||||
const unsigned int metaDataLength = (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN <= size()) ? at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN) : 0;
|
||||
const char *metaDataBytes = (metaDataLength != 0) ? (const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength) : (const char *)0;
|
||||
const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> metaData(metaDataBytes,metaDataLength);
|
||||
RR->localNetworkController->request(nwid,(hopCount > 0) ? InetAddress() : _path->address(),requestPacketId,peer->identity(),metaData);
|
||||
} else {
|
||||
|
@ -1517,6 +1517,10 @@ void Network::_sendUpdatesToMembers(const MulticastGroup *const newMulticastGrou
|
||||
Packet outp(*a,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
|
||||
_config.com.serialize(outp);
|
||||
outp.append((uint8_t)0x00);
|
||||
outp.append((uint16_t)0); // no capabilities
|
||||
outp.append((uint16_t)0); // no tags
|
||||
outp.append((uint16_t)0); // no revocations
|
||||
outp.append((uint16_t)0); // no certificates of ownership
|
||||
RR->sw->send(outp,true);
|
||||
}
|
||||
_announceMulticastGroupsTo(*a,groups);
|
||||
@ -1529,6 +1533,10 @@ void Network::_sendUpdatesToMembers(const MulticastGroup *const newMulticastGrou
|
||||
Packet outp(c,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
|
||||
_config.com.serialize(outp);
|
||||
outp.append((uint8_t)0x00);
|
||||
outp.append((uint16_t)0); // no capabilities
|
||||
outp.append((uint16_t)0); // no tags
|
||||
outp.append((uint16_t)0); // no revocations
|
||||
outp.append((uint16_t)0); // no certificates of ownership
|
||||
RR->sw->send(outp,true);
|
||||
}
|
||||
_announceMulticastGroupsTo(c,groups);
|
||||
|
85
one.cpp
85
one.cpp
@ -72,6 +72,7 @@
|
||||
|
||||
#include "osdep/OSUtils.hpp"
|
||||
#include "osdep/Http.hpp"
|
||||
#include "osdep/Thread.hpp"
|
||||
|
||||
#include "service/OneService.hpp"
|
||||
|
||||
@ -1209,6 +1210,52 @@ static void printHelp(const char *cn,FILE *out)
|
||||
fprintf(out," -q - Query API (zerotier-cli)" ZT_EOL_S);
|
||||
}
|
||||
|
||||
class _OneServiceRunner
|
||||
{
|
||||
public:
|
||||
_OneServiceRunner(const char *pn,const std::string &hd,unsigned int p) : progname(pn),returnValue(0),port(p),homeDir(hd) {}
|
||||
void threadMain()
|
||||
throw()
|
||||
{
|
||||
try {
|
||||
for(;;) {
|
||||
zt1Service = OneService::newInstance(homeDir.c_str(),port);
|
||||
switch(zt1Service->run()) {
|
||||
case OneService::ONE_STILL_RUNNING: // shouldn't happen, run() won't return until done
|
||||
case OneService::ONE_NORMAL_TERMINATION:
|
||||
break;
|
||||
case OneService::ONE_UNRECOVERABLE_ERROR:
|
||||
fprintf(stderr,"%s: fatal error: %s" ZT_EOL_S,progname,zt1Service->fatalErrorMessage().c_str());
|
||||
returnValue = 1;
|
||||
break;
|
||||
case OneService::ONE_IDENTITY_COLLISION: {
|
||||
delete zt1Service;
|
||||
zt1Service = (OneService *)0;
|
||||
std::string oldid;
|
||||
OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str(),oldid);
|
||||
if (oldid.length()) {
|
||||
OSUtils::writeFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret.saved_after_collision").c_str(),oldid);
|
||||
OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str());
|
||||
OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.public").c_str());
|
||||
}
|
||||
} continue; // restart!
|
||||
}
|
||||
break; // terminate loop -- normally we don't keep restarting
|
||||
}
|
||||
|
||||
delete zt1Service;
|
||||
zt1Service = (OneService *)0;
|
||||
} catch ( ... ) {
|
||||
fprintf(stderr,"%s: unexpected exception starting main OneService instance" ZT_EOL_S,progname);
|
||||
returnValue = 1;
|
||||
}
|
||||
}
|
||||
const char *progname;
|
||||
unsigned int returnValue;
|
||||
unsigned int port;
|
||||
const std::string &homeDir;
|
||||
};
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
#else
|
||||
@ -1421,8 +1468,8 @@ int main(int argc,char **argv)
|
||||
} else {
|
||||
// Running from service manager
|
||||
_winPokeAHole();
|
||||
ZeroTierOneService zt1Service;
|
||||
if (CServiceBase::Run(zt1Service) == TRUE) {
|
||||
ZeroTierOneService zt1WindowsService;
|
||||
if (CServiceBase::Run(zt1WindowsService) == TRUE) {
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr,"%s: unable to start service (try -h for help)" ZT_EOL_S,argv[0]);
|
||||
@ -1448,35 +1495,11 @@ int main(int argc,char **argv)
|
||||
}
|
||||
#endif // __UNIX_LIKE__
|
||||
|
||||
unsigned int returnValue = 0;
|
||||
_OneServiceRunner thr(argv[0],homeDir,port);
|
||||
thr.threadMain();
|
||||
//Thread::join(Thread::start(&thr));
|
||||
|
||||
for(;;) {
|
||||
zt1Service = OneService::newInstance(homeDir.c_str(),port);
|
||||
switch(zt1Service->run()) {
|
||||
case OneService::ONE_STILL_RUNNING: // shouldn't happen, run() won't return until done
|
||||
case OneService::ONE_NORMAL_TERMINATION:
|
||||
break;
|
||||
case OneService::ONE_UNRECOVERABLE_ERROR:
|
||||
fprintf(stderr,"%s: fatal error: %s" ZT_EOL_S,argv[0],zt1Service->fatalErrorMessage().c_str());
|
||||
returnValue = 1;
|
||||
break;
|
||||
case OneService::ONE_IDENTITY_COLLISION: {
|
||||
delete zt1Service;
|
||||
zt1Service = (OneService *)0;
|
||||
std::string oldid;
|
||||
OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str(),oldid);
|
||||
if (oldid.length()) {
|
||||
OSUtils::writeFile((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret.saved_after_collision").c_str(),oldid);
|
||||
OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.secret").c_str());
|
||||
OSUtils::rm((homeDir + ZT_PATH_SEPARATOR_S + "identity.public").c_str());
|
||||
}
|
||||
} continue; // restart!
|
||||
}
|
||||
break; // terminate loop -- normally we don't keep restarting
|
||||
}
|
||||
OSUtils::rm(pidPath.c_str());
|
||||
|
||||
delete zt1Service;
|
||||
zt1Service = (OneService *)0;
|
||||
|
||||
return returnValue;
|
||||
return thr.returnValue;
|
||||
}
|
||||
|
@ -488,6 +488,8 @@ public:
|
||||
,_updater((SoftwareUpdater *)0)
|
||||
,_updateAutoApply(false)
|
||||
,_primaryPort(port)
|
||||
,_v4TcpControlSocket((PhySocket *)0)
|
||||
,_v6TcpControlSocket((PhySocket *)0)
|
||||
,_lastDirectReceiveFromGlobal(0)
|
||||
#ifdef ZT_TCP_FALLBACK_RELAY
|
||||
,_lastSendToGlobalV4(0)
|
||||
|
Loading…
Reference in New Issue
Block a user