mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-30 22:14:22 +00:00
OpenBSD fixes, workaround for apparent libstdc++ bug.
This commit is contained in:
parent
7b231b38b0
commit
d79f792e6f
6
Makefile
6
Makefile
@ -13,10 +13,12 @@ endif
|
|||||||
ifeq ($(OSTYPE),FreeBSD)
|
ifeq ($(OSTYPE),FreeBSD)
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
include make-freebsd.mk
|
ZT_BUILD_PLATFORM=7
|
||||||
|
include make-bsd.mk
|
||||||
endif
|
endif
|
||||||
ifeq ($(OSTYPE),OpenBSD)
|
ifeq ($(OSTYPE),OpenBSD)
|
||||||
CC=egcc
|
CC=egcc
|
||||||
CXX=eg++
|
CXX=eg++
|
||||||
include make-freebsd.mk
|
ZT_BUILD_PLATFORM=9
|
||||||
|
include make-bsd.mk
|
||||||
endif
|
endif
|
||||||
|
@ -50,7 +50,7 @@ endif
|
|||||||
ifeq ($(CC_MACH),aarch64)
|
ifeq ($(CC_MACH),aarch64)
|
||||||
ZT_ARCHITECTURE=4
|
ZT_ARCHITECTURE=4
|
||||||
endif
|
endif
|
||||||
DEFS+=-DZT_BUILD_PLATFORM=7 -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
|
DEFS+=-DZT_BUILD_PLATFORM=$(ZT_BUILD_PLATFORM) -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
|
||||||
|
|
||||||
CXXFLAGS+=$(CFLAGS) -fno-rtti -std=c++11
|
CXXFLAGS+=$(CFLAGS) -fno-rtti -std=c++11
|
||||||
|
|
60
one.cpp
60
one.cpp
@ -289,7 +289,7 @@ static int cli(int argc,char **argv)
|
|||||||
|
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
try {
|
try {
|
||||||
j = nlohmann::json::parse(responseBody);
|
j = OSUtils::jsonParse(responseBody);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
||||||
return 1;
|
return 1;
|
||||||
@ -299,14 +299,16 @@ static int cli(int argc,char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scode == 200) {
|
if (scode == 200) {
|
||||||
std::ostringstream out;
|
|
||||||
if (json) {
|
if (json) {
|
||||||
out << j.dump(2) << ZT_EOL_S;
|
printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str());
|
||||||
} else {
|
} else {
|
||||||
if (j.is_object())
|
if (j.is_object()) {
|
||||||
out << "200 info " << j["address"].get<std::string>() << " " << j["version"].get<std::string>() << " " << ((j["tcpFallbackActive"]) ? "TUNNELED" : ((j["online"]) ? "ONLINE" : "OFFLINE")) << ZT_EOL_S;
|
printf("200 info %s %s %s" ZT_EOL_S,
|
||||||
|
OSUtils::jsonString(j["address"],"-").c_str(),
|
||||||
|
OSUtils::jsonString(j["version"],"-").c_str(),
|
||||||
|
((j["tcpFallbackActive"]) ? "TUNNELED" : ((j["online"]) ? "ONLINE" : "OFFLINE")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("%s",out.str().c_str());
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
||||||
@ -317,7 +319,7 @@ static int cli(int argc,char **argv)
|
|||||||
|
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
try {
|
try {
|
||||||
j = nlohmann::json::parse(responseBody);
|
j = OSUtils::jsonParse(responseBody);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
||||||
return 1;
|
return 1;
|
||||||
@ -327,19 +329,18 @@ static int cli(int argc,char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scode == 200) {
|
if (scode == 200) {
|
||||||
std::ostringstream out;
|
|
||||||
if (json) {
|
if (json) {
|
||||||
out << j.dump(2) << ZT_EOL_S;
|
printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str());
|
||||||
} else {
|
} else {
|
||||||
out << "200 listpeers <ztaddr> <path> <latency> <version> <role>" << ZT_EOL_S;
|
printf("200 listpeers <ztaddr> <path> <latency> <version> <role>" ZT_EOL_S);
|
||||||
if (j.is_array()) {
|
if (j.is_array()) {
|
||||||
for(unsigned long k=0;k<j.size();++k) {
|
for(unsigned long k=0;k<j.size();++k) {
|
||||||
auto &p = j[k];
|
nlohmann::json &p = j[k];
|
||||||
std::string bestPath;
|
std::string bestPath;
|
||||||
auto paths = p["paths"];
|
nlohmann::json &paths = p["paths"];
|
||||||
if (paths.is_array()) {
|
if (paths.is_array()) {
|
||||||
for(unsigned long i=0;i<paths.size();++i) {
|
for(unsigned long i=0;i<paths.size();++i) {
|
||||||
auto &path = paths[i];
|
nlohmann::json &path = paths[i];
|
||||||
if (path["preferred"]) {
|
if (path["preferred"]) {
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
std::string addr = path["address"];
|
std::string addr = path["address"];
|
||||||
@ -361,11 +362,15 @@ static int cli(int argc,char **argv)
|
|||||||
ver[0] = '-';
|
ver[0] = '-';
|
||||||
ver[1] = (char)0;
|
ver[1] = (char)0;
|
||||||
}
|
}
|
||||||
out << "200 listpeers " << p["address"].get<std::string>() << " " << bestPath << " " << p["latency"] << " " << ver << " " << p["role"].get<std::string>() << ZT_EOL_S;
|
printf("200 listpeers %s %s %d %s %s" ZT_EOL_S,
|
||||||
|
OSUtils::jsonString(p["address"],"-").c_str(),
|
||||||
|
bestPath.c_str(),
|
||||||
|
(int)OSUtils::jsonInt(p["latency"],0),
|
||||||
|
ver,
|
||||||
|
OSUtils::jsonString(p["role"],"-").c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%s",out.str().c_str());
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
||||||
@ -376,7 +381,7 @@ static int cli(int argc,char **argv)
|
|||||||
|
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
try {
|
try {
|
||||||
j = nlohmann::json::parse(responseBody);
|
j = OSUtils::jsonParse(responseBody);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what());
|
||||||
return 1;
|
return 1;
|
||||||
@ -386,20 +391,19 @@ static int cli(int argc,char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scode == 200) {
|
if (scode == 200) {
|
||||||
std::ostringstream out;
|
|
||||||
if (json) {
|
if (json) {
|
||||||
out << j.dump(2) << ZT_EOL_S;
|
printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str());
|
||||||
} else {
|
} else {
|
||||||
out << "200 listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips>" << ZT_EOL_S;
|
printf("200 listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips>" ZT_EOL_S);
|
||||||
if (j.is_array()) {
|
if (j.is_array()) {
|
||||||
for(unsigned long i=0;i<j.size();++i) {
|
for(unsigned long i=0;i<j.size();++i) {
|
||||||
auto &n = j[i];
|
nlohmann::json &n = j[i];
|
||||||
if (n.is_object()) {
|
if (n.is_object()) {
|
||||||
std::string aa;
|
std::string aa;
|
||||||
auto &assignedAddresses = n["assignedAddresses"];
|
nlohmann::json &assignedAddresses = n["assignedAddresses"];
|
||||||
if (assignedAddresses.is_array()) {
|
if (assignedAddresses.is_array()) {
|
||||||
for(unsigned long j=0;j<assignedAddresses.size();++j) {
|
for(unsigned long j=0;j<assignedAddresses.size();++j) {
|
||||||
auto &addr = assignedAddresses[j];
|
nlohmann::json &addr = assignedAddresses[j];
|
||||||
if (addr.is_string()) {
|
if (addr.is_string()) {
|
||||||
if (aa.length() > 0) aa.push_back(',');
|
if (aa.length() > 0) aa.push_back(',');
|
||||||
aa.append(addr.get<std::string>());
|
aa.append(addr.get<std::string>());
|
||||||
@ -407,14 +411,18 @@ static int cli(int argc,char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aa.length() == 0) aa = "-";
|
if (aa.length() == 0) aa = "-";
|
||||||
std::string name = n["name"];
|
printf("200 listnetworks %s %s %s %s %s %s %s" ZT_EOL_S,
|
||||||
if (name.length() == 0) name = "-";
|
OSUtils::jsonString(n["nwid"],"-").c_str(),
|
||||||
out << "200 listnetworks " << n["nwid"].get<std::string>() << " " << name << " " << n["mac"].get<std::string>() << " " << n["status"].get<std::string>() << " " << n["type"].get<std::string>() << " " << n["portDeviceName"].get<std::string>() << " " << aa << ZT_EOL_S;
|
OSUtils::jsonString(n["name"],"-").c_str(),
|
||||||
|
OSUtils::jsonString(n["mac"],"-").c_str(),
|
||||||
|
OSUtils::jsonString(n["status"],"-").c_str(),
|
||||||
|
OSUtils::jsonString(n["type"],"-").c_str(),
|
||||||
|
OSUtils::jsonString(n["portDeviceName"],"-").c_str(),
|
||||||
|
aa.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%s",out.str().c_str());
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
|
||||||
|
@ -83,7 +83,6 @@ BSDEthernetTap::BSDEthernetTap(
|
|||||||
{
|
{
|
||||||
static Mutex globalTapCreateLock;
|
static Mutex globalTapCreateLock;
|
||||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],tmpdevname[32];
|
char devpath[64],ethaddr[64],mtustr[32],metstr[32],tmpdevname[32];
|
||||||
struct stat stattmp;
|
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
Mutex::Lock _gl(globalTapCreateLock);
|
||||||
|
|
||||||
@ -122,6 +121,7 @@ BSDEthernetTap::BSDEthernetTap(
|
|||||||
::waitpid(cpid,&exitcode,0);
|
::waitpid(cpid,&exitcode,0);
|
||||||
} else throw std::runtime_error("fork() failed");
|
} else throw std::runtime_error("fork() failed");
|
||||||
|
|
||||||
|
struct stat stattmp;
|
||||||
if (!stat(devpath,&stattmp)) {
|
if (!stat(devpath,&stattmp)) {
|
||||||
cpid = (long)vfork();
|
cpid = (long)vfork();
|
||||||
if (cpid == 0) {
|
if (cpid == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user