This commit is contained in:
Adam Ierymenko 2020-11-25 23:35:39 -05:00
commit 3f921c01a6
16 changed files with 120 additions and 101 deletions

View File

@ -97,7 +97,7 @@ static json _renderRule(ZT_VirtualNetworkRule &rule)
break; break;
} }
if (r.size() == 0) { if (r.empty()) {
switch(rt) { switch(rt) {
case ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS: case ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS:
r["type"] = "MATCH_SOURCE_ZEROTIER_ADDRESS"; r["type"] = "MATCH_SOURCE_ZEROTIER_ADDRESS";
@ -239,7 +239,7 @@ static json _renderRule(ZT_VirtualNetworkRule &rule)
break; break;
} }
if (r.size() > 0) { if (!r.empty()) {
r["not"] = ((rule.t & 0x80) != 0); r["not"] = ((rule.t & 0x80) != 0);
r["or"] = ((rule.t & 0x40) != 0); r["or"] = ((rule.t & 0x40) != 0);
} }
@ -554,7 +554,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
std::string &responseBody, std::string &responseBody,
std::string &responseContentType) std::string &responseContentType)
{ {
if ((path.size() > 0)&&(path[0] == "network")) { if ((!path.empty())&&(path[0] == "network")) {
if ((path.size() >= 2)&&(path[1].length() == 16)) { if ((path.size() >= 2)&&(path[1].length() == 16)) {
const uint64_t nwid = Utils::hexStrToU64(path[1].c_str()); const uint64_t nwid = Utils::hexStrToU64(path[1].c_str());
@ -1247,11 +1247,11 @@ void EmbeddedNetworkController::_request(
Utils::hex(nwid,nwids); Utils::hex(nwid,nwids);
_db.get(nwid,network,identity.address().toInt(),member,ns); _db.get(nwid,network,identity.address().toInt(),member,ns);
if ((!network.is_object())||(network.size() == 0)) { if ((!network.is_object())||(network.empty())) {
_sender->ncSendError(nwid,requestPacketId,identity.address(),NetworkController::NC_ERROR_OBJECT_NOT_FOUND); _sender->ncSendError(nwid,requestPacketId,identity.address(),NetworkController::NC_ERROR_OBJECT_NOT_FOUND);
return; return;
} }
const bool newMember = ((!member.is_object())||(member.size() == 0)); const bool newMember = ((!member.is_object())||(member.empty()));
DB::initMember(member); DB::initMember(member);
{ {
@ -1459,11 +1459,11 @@ void EmbeddedNetworkController::_request(
std::map< uint64_t,json * >::const_iterator ctmp = capsById.find(capId); std::map< uint64_t,json * >::const_iterator ctmp = capsById.find(capId);
if (ctmp != capsById.end()) { if (ctmp != capsById.end()) {
json *cap = ctmp->second; json *cap = ctmp->second;
if ((cap)&&(cap->is_object())&&(cap->size() > 0)) { if ((cap)&&(cap->is_object())&&(!cap->empty())) {
ZT_VirtualNetworkRule capr[ZT_MAX_CAPABILITY_RULES]; ZT_VirtualNetworkRule capr[ZT_MAX_CAPABILITY_RULES];
unsigned int caprc = 0; unsigned int caprc = 0;
json &caprj = (*cap)["rules"]; json &caprj = (*cap)["rules"];
if ((caprj.is_array())&&(caprj.size() > 0)) { if ((caprj.is_array())&&(!caprj.empty())) {
for(unsigned long j=0;j<caprj.size();++j) { for(unsigned long j=0;j<caprj.size();++j) {
if (caprc >= ZT_MAX_CAPABILITY_RULES) if (caprc >= ZT_MAX_CAPABILITY_RULES)
break; break;

View File

@ -190,10 +190,10 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
if (resp) { if (resp) {
if (resp->status == 200) { if (resp->status == 200) {
nlohmann::json results(OSUtils::jsonParse(resp->body)); nlohmann::json results(OSUtils::jsonParse(resp->body));
if ((results.is_array())&&(results.size() > 0)) { if ((results.is_array())&&(!results.empty())) {
for(std::size_t ri=0;ri<results.size();++ri) { for(std::size_t ri=0;ri<results.size();++ri) {
nlohmann::json &rset = results[ri]; nlohmann::json &rset = results[ri];
if ((rset.is_array())&&(rset.size() > 0)) { if ((rset.is_array())&&(!rset.empty())) {
nlohmann::json &result = rset[0]; nlohmann::json &result = rset[0];
if (result.is_object()) { if (result.is_object()) {
@ -258,10 +258,10 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
if (resp) { if (resp) {
if (resp->status == 200) { if (resp->status == 200) {
nlohmann::json results(OSUtils::jsonParse(resp->body)); nlohmann::json results(OSUtils::jsonParse(resp->body));
if ((results.is_array())&&(results.size() > 0)) { if ((results.is_array())&&(!results.empty())) {
for(std::size_t ri=0;ri<results.size();++ri) { for(std::size_t ri=0;ri<results.size();++ri) {
nlohmann::json &rset = results[ri]; nlohmann::json &rset = results[ri];
if ((rset.is_array())&&(rset.size() > 0)) { if ((rset.is_array())&&(!rset.empty())) {
nlohmann::json &result = rset[0]; nlohmann::json &result = rset[0];
if (result.is_object()) { if (result.is_object()) {

View File

@ -65,7 +65,7 @@ ifeq ($(CC_MACH),armhf)
endif endif
ifeq ($(CC_MACH),armv6) ifeq ($(CC_MACH),armv6)
ZT_ARCHITECTURE=3 ZT_ARCHITECTURE=3
override DEFS+=-DZT_NO_TYPE_PUNNING override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_NO_UNALIGNED_ACCESS
ZT_USE_ARM32_NEON_ASM_SALSA2012=1 ZT_USE_ARM32_NEON_ASM_SALSA2012=1
endif endif
ifeq ($(CC_MACH),armv6zk) ifeq ($(CC_MACH),armv6zk)
@ -80,7 +80,7 @@ ifeq ($(CC_MACH),armv6kz)
endif endif
ifeq ($(CC_MACH),armv7) ifeq ($(CC_MACH),armv7)
ZT_ARCHITECTURE=3 ZT_ARCHITECTURE=3
override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_AES_NO_ACCEL override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_AES_NO_ACCEL -DZT_NO_UNALIGNED_ACCESS
ZT_USE_ARM32_NEON_ASM_SALSA2012=1 ZT_USE_ARM32_NEON_ASM_SALSA2012=1
endif endif
ifeq ($(CC_MACH),arm64) ifeq ($(CC_MACH),arm64)

View File

@ -144,6 +144,9 @@ endif
ifeq ($(CC_MACH),ppc64el) ifeq ($(CC_MACH),ppc64el)
ZT_ARCHITECTURE=8 ZT_ARCHITECTURE=8
endif endif
ifeq ($(CC_MACH),e2k)
ZT_ARCHITECTURE=2
endif
ifeq ($(CC_MACH),i386) ifeq ($(CC_MACH),i386)
ZT_ARCHITECTURE=1 ZT_ARCHITECTURE=1
endif endif
@ -206,6 +209,11 @@ ifeq ($(CC_MACH),armv7hl)
override DEFS+=-DZT_NO_TYPE_PUNNING override DEFS+=-DZT_NO_TYPE_PUNNING
ZT_USE_ARM32_NEON_ASM_CRYPTO=1 ZT_USE_ARM32_NEON_ASM_CRYPTO=1
endif endif
ifeq ($(CC_MACH),armv7ve)
ZT_ARCHITECTURE=3
override DEFS+=-DZT_NO_TYPE_PUNNING
ZT_USE_ARM32_NEON_ASM_CRYPTO=1
endif
ifeq ($(CC_MACH),arm64) ifeq ($(CC_MACH),arm64)
ZT_ARCHITECTURE=4 ZT_ARCHITECTURE=4
override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_ARCH_ARM_HAS_NEON -march=armv8-a+aes+crypto -mtune=generic -mstrict-align override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_ARCH_ARM_HAS_NEON -march=armv8-a+aes+crypto -mtune=generic -mstrict-align

View File

@ -96,7 +96,7 @@ ext/x64-salsa2012-asm/salsa2012.o:
as -arch x86_64 -mmacosx-version-min=10.7 -o ext/x64-salsa2012-asm/salsa2012.o ext/x64-salsa2012-asm/salsa2012.s as -arch x86_64 -mmacosx-version-min=10.7 -o ext/x64-salsa2012-asm/salsa2012.o ext/x64-salsa2012-asm/salsa2012.s
mac-agent: FORCE mac-agent: FORCE
$(CC) -Ofast $(ARCH_FLAGS) -o MacEthernetTapAgent osdep/MacEthernetTapAgent.c $(CC) -Ofast $(ARCH_FLAGS) -mmacosx-version-min=10.7 -o MacEthernetTapAgent osdep/MacEthernetTapAgent.c
$(CODESIGN) -f --options=runtime -s $(CODESIGN_APP_CERT) MacEthernetTapAgent $(CODESIGN) -f --options=runtime -s $(CODESIGN_APP_CERT) MacEthernetTapAgent
osdep/MacDNSHelper.o: osdep/MacDNSHelper.mm osdep/MacDNSHelper.o: osdep/MacDNSHelper.mm

View File

@ -149,15 +149,6 @@ void AES::GMAC::update(const void *const data, unsigned int len) noexcept
} }
} }
if (likely(((uintptr_t)in & 7U) == 0U)) {
while (len >= 16) {
y0 ^= *reinterpret_cast<const uint64_t *>(in);
y1 ^= *reinterpret_cast<const uint64_t *>(in + 8);
in += 16;
s_gfmul(h0, h1, y0, y1);
len -= 16;
}
} else {
while (len >= 16) { while (len >= 16) {
y0 ^= Utils::loadMachineEndian< uint64_t >(in); y0 ^= Utils::loadMachineEndian< uint64_t >(in);
y1 ^= Utils::loadMachineEndian< uint64_t >(in + 8); y1 ^= Utils::loadMachineEndian< uint64_t >(in + 8);
@ -165,7 +156,6 @@ void AES::GMAC::update(const void *const data, unsigned int len) noexcept
s_gfmul(h0, h1, y0, y1); s_gfmul(h0, h1, y0, y1);
len -= 16; len -= 16;
} }
}
_y[0] = y0; _y[0] = y0;
_y[1] = y1; _y[1] = y1;

View File

@ -131,7 +131,7 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
uint8x16_t k14 = _aes.p_k.neon.ek[14]; uint8x16_t k14 = _aes.p_k.neon.ek[14];
unsigned int totalLen = _len; unsigned int totalLen = _len;
if ((totalLen & 15U)) { if ((totalLen & 15U) != 0) {
for (;;) { for (;;) {
if (unlikely(!len)) { if (unlikely(!len)) {
vst1q_u8(reinterpret_cast<uint8_t *>(_ctr), vrev32q_u8(dd)); vst1q_u8(reinterpret_cast<uint8_t *>(_ctr), vrev32q_u8(dd));
@ -140,7 +140,7 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
} }
--len; --len;
out[totalLen++] = *(in++); out[totalLen++] = *(in++);
if (!(totalLen & 15U)) { if ((totalLen & 15U) == 0) {
uint8_t *const otmp = out + (totalLen - 16); uint8_t *const otmp = out + (totalLen - 16);
uint8x16_t d0 = vrev32q_u8(dd); uint8x16_t d0 = vrev32q_u8(dd);
uint8x16_t pt = vld1q_u8(otmp); uint8x16_t pt = vld1q_u8(otmp);
@ -180,7 +180,10 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
uint8x16_t d2 = vrev32q_u8(dd2); uint8x16_t d2 = vrev32q_u8(dd2);
uint8x16_t d3 = vrev32q_u8(dd3); uint8x16_t d3 = vrev32q_u8(dd3);
uint8x16_t pt0 = vld1q_u8(in); uint8x16_t pt0 = vld1q_u8(in);
in += 16; uint8x16_t pt1 = vld1q_u8(in + 16);
uint8x16_t pt2 = vld1q_u8(in + 16);
uint8x16_t pt3 = vld1q_u8(in + 16);
d0 = vaesmcq_u8(vaeseq_u8(d0, k0)); d0 = vaesmcq_u8(vaeseq_u8(d0, k0));
d1 = vaesmcq_u8(vaeseq_u8(d1, k0)); d1 = vaesmcq_u8(vaeseq_u8(d1, k0));
d2 = vaesmcq_u8(vaeseq_u8(d2, k0)); d2 = vaesmcq_u8(vaeseq_u8(d2, k0));
@ -193,8 +196,6 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
d1 = vaesmcq_u8(vaeseq_u8(d1, k2)); d1 = vaesmcq_u8(vaeseq_u8(d1, k2));
d2 = vaesmcq_u8(vaeseq_u8(d2, k2)); d2 = vaesmcq_u8(vaeseq_u8(d2, k2));
d3 = vaesmcq_u8(vaeseq_u8(d3, k2)); d3 = vaesmcq_u8(vaeseq_u8(d3, k2));
uint8x16_t pt1 = vld1q_u8(in);
in += 16;
d0 = vaesmcq_u8(vaeseq_u8(d0, k3)); d0 = vaesmcq_u8(vaeseq_u8(d0, k3));
d1 = vaesmcq_u8(vaeseq_u8(d1, k3)); d1 = vaesmcq_u8(vaeseq_u8(d1, k3));
d2 = vaesmcq_u8(vaeseq_u8(d2, k3)); d2 = vaesmcq_u8(vaeseq_u8(d2, k3));
@ -207,8 +208,6 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
d1 = vaesmcq_u8(vaeseq_u8(d1, k5)); d1 = vaesmcq_u8(vaeseq_u8(d1, k5));
d2 = vaesmcq_u8(vaeseq_u8(d2, k5)); d2 = vaesmcq_u8(vaeseq_u8(d2, k5));
d3 = vaesmcq_u8(vaeseq_u8(d3, k5)); d3 = vaesmcq_u8(vaeseq_u8(d3, k5));
uint8x16_t pt2 = vld1q_u8(in);
in += 16;
d0 = vaesmcq_u8(vaeseq_u8(d0, k6)); d0 = vaesmcq_u8(vaeseq_u8(d0, k6));
d1 = vaesmcq_u8(vaeseq_u8(d1, k6)); d1 = vaesmcq_u8(vaeseq_u8(d1, k6));
d2 = vaesmcq_u8(vaeseq_u8(d2, k6)); d2 = vaesmcq_u8(vaeseq_u8(d2, k6));
@ -221,8 +220,6 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
d1 = vaesmcq_u8(vaeseq_u8(d1, k8)); d1 = vaesmcq_u8(vaeseq_u8(d1, k8));
d2 = vaesmcq_u8(vaeseq_u8(d2, k8)); d2 = vaesmcq_u8(vaeseq_u8(d2, k8));
d3 = vaesmcq_u8(vaeseq_u8(d3, k8)); d3 = vaesmcq_u8(vaeseq_u8(d3, k8));
uint8x16_t pt3 = vld1q_u8(in);
in += 16;
d0 = vaesmcq_u8(vaeseq_u8(d0, k9)); d0 = vaesmcq_u8(vaeseq_u8(d0, k9));
d1 = vaesmcq_u8(vaeseq_u8(d1, k9)); d1 = vaesmcq_u8(vaeseq_u8(d1, k9));
d2 = vaesmcq_u8(vaeseq_u8(d2, k9)); d2 = vaesmcq_u8(vaeseq_u8(d2, k9));
@ -253,7 +250,9 @@ void AES::CTR::p_armCrypt(const uint8_t *in, uint8_t *out, unsigned int len) noe
vst1q_u8(out + 16, d1); vst1q_u8(out + 16, d1);
vst1q_u8(out + 32, d2); vst1q_u8(out + 32, d2);
vst1q_u8(out + 48, d3); vst1q_u8(out + 48, d3);
out += 64; out += 64;
in += 64;
dd = (uint8x16_t)vaddq_u32((uint32x4_t)dd, four); dd = (uint8x16_t)vaddq_u32((uint32x4_t)dd, four);
if (unlikely(len < 64)) if (unlikely(len < 64))

View File

@ -126,7 +126,12 @@
// Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64. // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64.
#if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386))) #if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386)))
#ifndef ZT_NO_TYPE_PUNNING #ifndef ZT_NO_TYPE_PUNNING
#define ZT_NO_TYPE_PUNNING #define ZT_NO_TYPE_PUNNING 1
#endif
#endif
#ifdef ZT_NO_TYPE_PUNNING
#ifndef ZT_NO_UNALIGNED_ACCESS
#define ZT_NO_UNALIGNED_ACCESS 1
#endif #endif
#endif #endif

View File

@ -430,7 +430,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,void *tPtr,const bool
if ((planetWorldId)&&(RR->topology->planetWorldTimestamp() > planetWorldTimestamp)&&(planetWorldId == RR->topology->planetWorldId())) { if ((planetWorldId)&&(RR->topology->planetWorldTimestamp() > planetWorldTimestamp)&&(planetWorldId == RR->topology->planetWorldId())) {
RR->topology->planet().serialize(outp,false); RR->topology->planet().serialize(outp,false);
} }
if (moonIdsAndTimestamps.size() > 0) { if (!moonIdsAndTimestamps.empty()) {
std::vector<World> moons(RR->topology->moons()); std::vector<World> moons(RR->topology->moons());
for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) { for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) {
for(std::vector< std::pair<uint64_t,uint64_t> >::const_iterator i(moonIdsAndTimestamps.begin());i!=moonIdsAndTimestamps.end();++i) { for(std::vector< std::pair<uint64_t,uint64_t> >::const_iterator i(moonIdsAndTimestamps.begin());i!=moonIdsAndTimestamps.end();++i) {

View File

@ -183,7 +183,7 @@ void Peer::received(
if (sinceLastPush >= ((hops == 0) ? ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH : ZT_DIRECT_PATH_PUSH_INTERVAL)) { if (sinceLastPush >= ((hops == 0) ? ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH : ZT_DIRECT_PATH_PUSH_INTERVAL)) {
_lastDirectPathPushSent = now; _lastDirectPathPushSent = now;
std::vector<InetAddress> pathsToPush(RR->node->directPaths()); std::vector<InetAddress> pathsToPush(RR->node->directPaths());
if (pathsToPush.size() > 0) { if (!pathsToPush.empty()) {
std::vector<InetAddress>::const_iterator p(pathsToPush.begin()); std::vector<InetAddress>::const_iterator p(pathsToPush.begin());
while (p != pathsToPush.end()) { while (p != pathsToPush.end()) {
Packet *const outp = new Packet(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS); Packet *const outp = new Packet(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS);

View File

@ -183,7 +183,7 @@ bool Topology::isProhibitedEndpoint(const Address &ztaddr,const InetAddress &ipa
if (std::find(_upstreamAddresses.begin(),_upstreamAddresses.end(),ztaddr) != _upstreamAddresses.end()) { if (std::find(_upstreamAddresses.begin(),_upstreamAddresses.end(),ztaddr) != _upstreamAddresses.end()) {
for(std::vector<World::Root>::const_iterator r(_planet.roots().begin());r!=_planet.roots().end();++r) { for(std::vector<World::Root>::const_iterator r(_planet.roots().begin());r!=_planet.roots().end();++r) {
if (r->identity.address() == ztaddr) { if (r->identity.address() == ztaddr) {
if (r->stableEndpoints.size() == 0) if (r->stableEndpoints.empty())
return false; // no stable endpoints specified, so allow dynamic paths return false; // no stable endpoints specified, so allow dynamic paths
for(std::vector<InetAddress>::const_iterator e(r->stableEndpoints.begin());e!=r->stableEndpoints.end();++e) { for(std::vector<InetAddress>::const_iterator e(r->stableEndpoints.begin());e!=r->stableEndpoints.end();++e) {
if (ipaddr.ipsEqual(*e)) if (ipaddr.ipsEqual(*e))
@ -194,7 +194,7 @@ bool Topology::isProhibitedEndpoint(const Address &ztaddr,const InetAddress &ipa
for(std::vector<World>::const_iterator m(_moons.begin());m!=_moons.end();++m) { for(std::vector<World>::const_iterator m(_moons.begin());m!=_moons.end();++m) {
for(std::vector<World::Root>::const_iterator r(m->roots().begin());r!=m->roots().end();++r) { for(std::vector<World::Root>::const_iterator r(m->roots().begin());r!=m->roots().end();++r) {
if (r->identity.address() == ztaddr) { if (r->identity.address() == ztaddr) {
if (r->stableEndpoints.size() == 0) if (r->stableEndpoints.empty())
return false; // no stable endpoints specified, so allow dynamic paths return false; // no stable endpoints specified, so allow dynamic paths
for(std::vector<InetAddress>::const_iterator e(r->stableEndpoints.begin());e!=r->stableEndpoints.end();++e) { for(std::vector<InetAddress>::const_iterator e(r->stableEndpoints.begin());e!=r->stableEndpoints.end();++e) {
if (ipaddr.ipsEqual(*e)) if (ipaddr.ipsEqual(*e))

View File

@ -1021,7 +1021,7 @@ static int cli(int argc,char **argv)
int addressCountOfType = 0; int addressCountOfType = 0;
for (int k = 0; k<std::min(ZT_MAX_ZT_ASSIGNED_ADDRESSES, (int)assignedAddresses.size());++k) { for (int k = 0; k<std::min(ZT_MAX_ZT_ASSIGNED_ADDRESSES, (int)assignedAddresses.size());++k) {
nlohmann::json &addr = assignedAddresses[k]; nlohmann::json &addr = assignedAddresses[k];
if ((arg2 == "ip4" && addr.get<std::string>().find(".") != std::string::npos) if ((arg2 == "ip4" && addr.get<std::string>().find('.') != std::string::npos)
|| ((arg2.find("ip6") == 0) && addr.get<std::string>().find(":") != std::string::npos) || ((arg2.find("ip6") == 0) && addr.get<std::string>().find(":") != std::string::npos)
|| (arg2 == "ip") || (arg2 == "ip")
) { ) {
@ -1036,19 +1036,19 @@ static int cli(int argc,char **argv)
if (arg2.find("ip6p") == 0) { if (arg2.find("ip6p") == 0) {
if (arg2 == "ip6plane") { if (arg2 == "ip6plane") {
if (addr.get<std::string>().find("fc") == 0) { if (addr.get<std::string>().find("fc") == 0) {
aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find("/"))); aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find('/')));
if (k < addressCountOfType-1) aa.append("\n"); if (k < addressCountOfType-1) aa.append("\n");
} }
} }
if (arg2 == "ip6prefix") { if (arg2 == "ip6prefix") {
if (addr.get<std::string>().find("fc") == 0) { if (addr.get<std::string>().find("fc") == 0) {
aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find("/")).substr(0,24)); aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find('/')).substr(0,24));
if (k < addressCountOfType-1) aa.append("\n"); if (k < addressCountOfType-1) aa.append("\n");
} }
} }
} }
else { else {
aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find("/"))); aa.append(addr.get<std::string>().substr(0,addr.get<std::string>().find('/')));
if (k < addressCountOfType-1) aa.append("\n"); if (k < addressCountOfType-1) aa.append("\n");
} }
} }

View File

@ -136,7 +136,9 @@ public:
PIP_ADAPTER_UNICAST_ADDRESS ua = a->FirstUnicastAddress; PIP_ADAPTER_UNICAST_ADDRESS ua = a->FirstUnicastAddress;
while (ua) { while (ua) {
InetAddress ip(ua->Address.lpSockaddr); InetAddress ip(ua->Address.lpSockaddr);
if (ifChecker.shouldBindInterface("",ip)) { char strBuf[128] = { 0 };
wcstombs(strBuf, a->FriendlyName, sizeof(strBuf));
if (ifChecker.shouldBindInterface(strBuf,ip)) {
switch(ip.ipScope()) { switch(ip.ipScope()) {
default: break; default: break;
case InetAddress::IP_SCOPE_PSEUDOPRIVATE: case InetAddress::IP_SCOPE_PSEUDOPRIVATE:
@ -234,7 +236,7 @@ public:
} }
// Get IPv4 addresses for each device // Get IPv4 addresses for each device
if (ifnames.size() > 0) { if (!ifnames.empty()) {
const int controlfd = (int)socket(AF_INET,SOCK_DGRAM,0); const int controlfd = (int)socket(AF_INET,SOCK_DGRAM,0);
struct ifconf configuration; struct ifconf configuration;
configuration.ifc_len = 0; configuration.ifc_len = 0;
@ -276,7 +278,7 @@ public:
if (controlfd > 0) close(controlfd); if (controlfd > 0) close(controlfd);
} }
const bool gotViaProc = (localIfAddrs.size() > 0); const bool gotViaProc = (!localIfAddrs.empty());
#else #else
const bool gotViaProc = false; const bool gotViaProc = false;
#endif #endif

View File

@ -351,7 +351,7 @@ std::vector<std::string> OSUtils::split(const char *s,const char *const sep,cons
else if ((buf.size() <= 0)&&((quotTmp = strchr(quot,*s)))) else if ((buf.size() <= 0)&&((quotTmp = strchr(quot,*s))))
quoteState = *quotTmp; quoteState = *quotTmp;
else if (strchr(sep,*s)) { else if (strchr(sep,*s)) {
if (buf.size() > 0) { if (!buf.empty()) {
fields.push_back(buf); fields.push_back(buf);
buf.clear(); buf.clear();
} // else skip runs of separators } // else skip runs of separators

View File

@ -1059,7 +1059,7 @@ public:
} }
// Set trusted paths if there are any // Set trusted paths if there are any
if (ppc.size() > 0) { if (!ppc.empty()) {
for(std::map<InetAddress,ZT_PhysicalPathConfiguration>::iterator i(ppc.begin());i!=ppc.end();++i) for(std::map<InetAddress,ZT_PhysicalPathConfiguration>::iterator i(ppc.begin());i!=ppc.end();++i)
_node->setPhysicalPathConfiguration(reinterpret_cast<const struct sockaddr_storage *>(&(i->first)),&(i->second)); _node->setPhysicalPathConfiguration(reinterpret_cast<const struct sockaddr_storage *>(&(i->first)),&(i->second));
} }
@ -1177,7 +1177,7 @@ public:
* URL encoding, and /'s in URL args will screw it up. But the only URL args * URL encoding, and /'s in URL args will screw it up. But the only URL args
* it really uses in ?jsonp=funcionName, and otherwise it just takes simple * it really uses in ?jsonp=funcionName, and otherwise it just takes simple
* paths to simply-named resources. */ * paths to simply-named resources. */
if (ps.size() > 0) { if (!ps.empty()) {
std::size_t qpos = ps[ps.size() - 1].find('?'); std::size_t qpos = ps[ps.size() - 1].find('?');
if (qpos != std::string::npos) { if (qpos != std::string::npos) {
std::string args(ps[ps.size() - 1].substr(qpos + 1)); std::string args(ps[ps.size() - 1].substr(qpos + 1));
@ -1210,12 +1210,12 @@ public:
// Authenticate via Synology's built-in cgi script // Authenticate via Synology's built-in cgi script
if (!isAuth) { if (!isAuth) {
int synotoken_pos = path.find("SynoToken"); int synotoken_pos = path.find("SynoToken");
int argpos = path.find("?"); int argpos = path.find('?');
if(synotoken_pos != std::string::npos && argpos != std::string::npos) { if(synotoken_pos != std::string::npos && argpos != std::string::npos) {
std::string cookie = path.substr(argpos+1, synotoken_pos-(argpos+1)); std::string cookie = path.substr(argpos+1, synotoken_pos-(argpos+1));
std::string synotoken = path.substr(synotoken_pos); std::string synotoken = path.substr(synotoken_pos);
std::string cookie_val = cookie.substr(cookie.find("=")+1); std::string cookie_val = cookie.substr(cookie.find('=')+1);
std::string synotoken_val = synotoken.substr(synotoken.find("=")+1); std::string synotoken_val = synotoken.substr(synotoken.find('=')+1);
// Set necessary env for auth script // Set necessary env for auth script
std::map<std::string,std::string>::const_iterator ah2(headers.find("x-forwarded-for")); std::map<std::string,std::string>::const_iterator ah2(headers.find("x-forwarded-for"));
setenv("HTTP_COOKIE", cookie_val.c_str(), true); setenv("HTTP_COOKIE", cookie_val.c_str(), true);
@ -1920,7 +1920,7 @@ public:
if (!n.settings.allowManaged) if (!n.settings.allowManaged)
return false; return false;
if (n.settings.allowManagedWhitelist.size() > 0) { if (!n.settings.allowManagedWhitelist.empty()) {
bool allowed = false; bool allowed = false;
for (InetAddress addr : n.settings.allowManagedWhitelist) { for (InetAddress addr : n.settings.allowManagedWhitelist) {
if (addr.containsAddress(target) && addr.netmaskBits() <= target.netmaskBits()) { if (addr.containsAddress(target) && addr.netmaskBits() <= target.netmaskBits()) {
@ -2207,7 +2207,7 @@ public:
bool allow; bool allow;
{ {
Mutex::Lock _l(_localConfig_m); Mutex::Lock _l(_localConfig_m);
if (_allowManagementFrom.size() == 0) { if (_allowManagementFrom.empty()) {
allow = (tc->remoteAddr.ipScope() == InetAddress::IP_SCOPE_LOOPBACK); allow = (tc->remoteAddr.ipScope() == InetAddress::IP_SCOPE_LOOPBACK);
} else { } else {
allow = false; allow = false;
@ -2386,7 +2386,7 @@ public:
Dictionary<4096> nc; Dictionary<4096> nc;
nc.load(nlcbuf.c_str()); nc.load(nlcbuf.c_str());
Buffer<1024> allowManaged; Buffer<1024> allowManaged;
if (nc.get("allowManaged", allowManaged) && allowManaged.size() != 0) { if (nc.get("allowManaged", allowManaged) && !allowManaged.size() == 0) {
std::string addresses (allowManaged.begin(), allowManaged.size()); std::string addresses (allowManaged.begin(), allowManaged.size());
if (allowManaged.size() <= 5) { // untidy parsing for backward compatibility if (allowManaged.size() <= 5) { // untidy parsing for backward compatibility
if (allowManaged[0] == '1' || allowManaged[0] == 't' || allowManaged[0] == 'T') { if (allowManaged[0] == '1' || allowManaged[0] == 't' || allowManaged[0] == 'T') {
@ -2943,10 +2943,11 @@ public:
lh = &_v6Hints; lh = &_v6Hints;
else return 0; else return 0;
const std::vector<InetAddress>* l = lh->get(ztaddr); const std::vector<InetAddress>* l = lh->get(ztaddr);
if ((l)&&(l->size() > 0)) { if ((l) && (!l->empty())) {
memcpy(result, &((*l)[(unsigned long)_node->prng() % l->size()]), sizeof(struct sockaddr_storage)); memcpy(result, &((*l)[(unsigned long)_node->prng() % l->size()]), sizeof(struct sockaddr_storage));
return 1; return 1;
} else return 0; }
else return 0;
} }
inline void tapFrameHandler(uint64_t nwid, const MAC& from, const MAC& to, unsigned int etherType, unsigned int vlanId, const void* data, unsigned int len) inline void tapFrameHandler(uint64_t nwid, const MAC& from, const MAC& to, unsigned int etherType, unsigned int vlanId, const void* data, unsigned int len)
@ -2966,10 +2967,12 @@ public:
try { try {
scode = handleControlPlaneHttpRequest(tc->remoteAddr, tc->parser.method, tc->url, tc->headers, tc->readq, data, contentType); scode = handleControlPlaneHttpRequest(tc->remoteAddr, tc->parser.method, tc->url, tc->headers, tc->readq, data, contentType);
} catch (std::exception &exc) { }
catch (std::exception& exc) {
fprintf(stderr, "WARNING: unexpected exception processing control HTTP request: %s" ZT_EOL_S, exc.what()); fprintf(stderr, "WARNING: unexpected exception processing control HTTP request: %s" ZT_EOL_S, exc.what());
scode = 500; scode = 500;
} catch ( ... ) { }
catch (...) {
fprintf(stderr, "WARNING: unexpected exception processing control HTTP request: unknown exception" ZT_EOL_S); fprintf(stderr, "WARNING: unexpected exception processing control HTTP request: unknown exception" ZT_EOL_S);
scode = 500; scode = 500;
} }
@ -3025,6 +3028,18 @@ public:
if ((ifname[0] == 'u') && (ifname[1] == 't') && (ifname[2] == 'u') && (ifname[3] == 'n')) return false; // ... as is utun# if ((ifname[0] == 'u') && (ifname[1] == 't') && (ifname[2] == 'u') && (ifname[3] == 'n')) return false; // ... as is utun#
#endif #endif
#ifdef _WIN32
if ((ifname[0] == 'Z') && (ifname[1] == 'e') && (ifname[2] == 'r') && ifname[3] == 'o' &&
(ifname[4] == 'T') && (ifname[5] == 'i') && (ifname[6] == 'e') && (ifname[7] == 'r')) {
return false;
}
#endif
#ifdef __FreeBSD__
if ((ifname[0] == 'l') && (ifname[1] == 'o')) return false; // loopback
if ((ifname[0] == 'z') && (ifname[1] == 't')) return false; // sanity check: zt#
#endif
{ {
Mutex::Lock _l(_localConfig_m); Mutex::Lock _l(_localConfig_m);
for(std::vector<std::string>::const_iterator p(_interfacePrefixBlacklist.begin());p!=_interfacePrefixBlacklist.end();++p) { for(std::vector<std::string>::const_iterator p(_interfacePrefixBlacklist.begin());p!=_interfacePrefixBlacklist.end();++p) {

View File

@ -161,7 +161,7 @@ void SoftwareUpdater::handleSoftwareUpdateUserMessage(uint64_t origin,const void
if (v == VERB_GET_LATEST) { if (v == VERB_GET_LATEST) {
if (_dist.size() > 0) { if (!_dist.empty()) {
const nlohmann::json *latest = (const nlohmann::json *)0; const nlohmann::json *latest = (const nlohmann::json *)0;
const std::string expectedSigner = OSUtils::jsonString(req[ZT_SOFTWARE_UPDATE_JSON_EXPECT_SIGNED_BY],""); const std::string expectedSigner = OSUtils::jsonString(req[ZT_SOFTWARE_UPDATE_JSON_EXPECT_SIGNED_BY],"");
unsigned int bestVMaj = rvMaj; unsigned int bestVMaj = rvMaj;
@ -241,7 +241,7 @@ void SoftwareUpdater::handleSoftwareUpdateUserMessage(uint64_t origin,const void
} break; } break;
case VERB_GET_DATA: case VERB_GET_DATA:
if ((len >= 21)&&(_dist.size() > 0)) { if ((len >= 21)&&(!_dist.empty())) {
unsigned long idx = (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 17) << 24; unsigned long idx = (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 17) << 24;
idx |= (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 18) << 16; idx |= (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 18) << 16;
idx |= (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 19) << 8; idx |= (unsigned long)*(reinterpret_cast<const uint8_t *>(data) + 19) << 8;