diff --git a/osdep/ManagedRoute.cpp b/attic/ManagedRoute.cpp similarity index 100% rename from osdep/ManagedRoute.cpp rename to attic/ManagedRoute.cpp diff --git a/osdep/ManagedRoute.hpp b/attic/ManagedRoute.hpp similarity index 100% rename from osdep/ManagedRoute.hpp rename to attic/ManagedRoute.hpp diff --git a/go/native/GoGlue.cpp b/go/native/GoGlue.cpp index a157d84a2..faaf7421f 100644 --- a/go/native/GoGlue.cpp +++ b/go/native/GoGlue.cpp @@ -344,8 +344,6 @@ extern "C" ZT_GoNode *ZT_GoNode_new(const char *workingPath,uintptr_t userPtr) goHandleTapAddedMulticastGroup(gn,(ZT_GoTap *)t->second.get(),t->first,g->mac().toInt(),g->adi()); for(auto g=removed.begin();g!=removed.end();++g) goHandleTapRemovedMulticastGroup(gn,(ZT_GoTap *)t->second.get(),t->first,g->mac().toInt(),g->adi()); - - t->second->syncRoutes(); } } } @@ -477,17 +475,26 @@ extern "C" int ZT_GoNode_phyStartListen(ZT_GoNode *gn,const char *dev,const char gnt.thr = std::thread([udpSock,gn,&gnt] { struct sockaddr_in6 in6; socklen_t salen; - char buf[16384]; while (gnt.run) { salen = sizeof(in6); - int s = (int)recvfrom(udpSock,buf,sizeof(buf),0,reinterpret_cast(&in6),&salen); - if (s > 0) { - gn->node->processWirePacket(&gnt,OSUtils::now(),(int64_t)udpSock,reinterpret_cast(&in6),buf,(unsigned int)s,&(gn->nextBackgroundTaskDeadline)); - } else { - // If something goes bad with this socket such as its interface vanishing, it - // will eventually be closed by higher level (Go) code. Until then prevent the - // system from consuming too much CPU. - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + void *buf = ZT_getBuffer(); + if (buf) { + int s = (int)recvfrom(udpSock,buf,16384,0,reinterpret_cast(&in6),&salen); + if (s > 0) { + ZT_Node_processWirePacket( + reinterpret_cast(gn->node), + nullptr, + OSUtils::now(), + (int64_t)udpSock, + reinterpret_cast(&in6), + buf, + (unsigned int)s, + 1, + &(gn->nextBackgroundTaskDeadline)); + } else { + ZT_freeBuffer(buf); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } } } }); @@ -523,12 +530,26 @@ extern "C" int ZT_GoNode_phyStartListen(ZT_GoNode *gn,const char *dev,const char gnt.thr = std::thread([udpSock,gn,&gnt] { struct sockaddr_in in4; socklen_t salen; - char buf[16384]; while (gnt.run) { salen = sizeof(in4); - int s = (int)recvfrom(udpSock,buf,sizeof(buf),0,reinterpret_cast(&in4),&salen); - if (s > 0) { - gn->node->processWirePacket(&gnt,OSUtils::now(),(int64_t)udpSock,reinterpret_cast(&in4),buf,(unsigned int)s,&(gn->nextBackgroundTaskDeadline)); + void *buf = ZT_getBuffer(); + if (buf) { + int s = (int)recvfrom(udpSock,buf,sizeof(buf),0,reinterpret_cast(&in4),&salen); + if (s > 0) { + ZT_Node_processWirePacket( + reinterpret_cast(gn->node), + nullptr, + OSUtils::now(), + (int64_t)udpSock, + reinterpret_cast(&in4), + buf, + (unsigned int)s, + 1, + &(gn->nextBackgroundTaskDeadline)); + } else { + ZT_freeBuffer(buf); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } } } }); @@ -557,8 +578,19 @@ extern "C" int ZT_GoNode_phyStopListen(ZT_GoNode *gn,const char *dev,const char static void tapFrameHandler(void *uptr,void *tptr,uint64_t nwid,const MAC &from,const MAC &to,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len) { - ZT_GoNode *const gn = reinterpret_cast(uptr); - gn->node->processVirtualNetworkFrame(tptr,OSUtils::now(),nwid,from.toInt(),to.toInt(),etherType,vlanId,data,len,&(gn->nextBackgroundTaskDeadline)); + ZT_Node_processVirtualNetworkFrame( + reinterpret_cast(reinterpret_cast(uptr)->node), + tptr, + OSUtils::now(), + nwid, + from.toInt(), + to.toInt(), + etherType, + vlanId, + data, + len, + 0, + &(reinterpret_cast(uptr)->nextBackgroundTaskDeadline)); } extern "C" ZT_GoTap *ZT_GoNode_join(ZT_GoNode *gn,uint64_t nwid) @@ -662,47 +694,3 @@ extern "C" void ZT_GoTap_setMtu(ZT_GoTap *tap,unsigned int mtu) { reinterpret_cast(tap)->setMtu(mtu); } - -extern "C" int ZT_GoTap_addRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric) -{ - InetAddress target,via; - switch(targetAf) { - case AF_INET: - target.set(targetIp,4,(unsigned int)targetNetmaskBits); - break; - case AF_INET6: - target.set(targetIp,16,(unsigned int)targetNetmaskBits); - break; - } - switch(viaAf) { - case AF_INET: - via.set(viaIp,4,0); - break; - case AF_INET6: - via.set(viaIp,16,0); - break; - } - return reinterpret_cast(tap)->addRoute(target,via,metric); -} - -extern "C" int ZT_GoTap_removeRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric) -{ - InetAddress target,via; - switch(targetAf) { - case AF_INET: - target.set(targetIp,4,(unsigned int)targetNetmaskBits); - break; - case AF_INET6: - target.set(targetIp,16,(unsigned int)targetNetmaskBits); - break; - } - switch(viaAf) { - case AF_INET: - via.set(viaIp,4,0); - break; - case AF_INET6: - via.set(viaIp,16,0); - break; - } - return reinterpret_cast(tap)->removeRoute(target,via,metric); -} diff --git a/go/native/GoGlue.h b/go/native/GoGlue.h index 3c75dab67..39ea65879 100644 --- a/go/native/GoGlue.h +++ b/go/native/GoGlue.h @@ -80,10 +80,6 @@ void ZT_GoTap_setFriendlyName(ZT_GoTap *tap,const char *friendlyName); void ZT_GoTap_setMtu(ZT_GoTap *tap,unsigned int mtu); -int ZT_GoTap_addRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric); - -int ZT_GoTap_removeRoute(ZT_GoTap *tap,int targetAf,const void *targetIp,int targetNetmaskBits,int viaAf,const void *viaIp,unsigned int metric); - /* Core self-tests that output results to stdout and return non-zero on failure. */ int ZT_TestCrypto(); int ZT_TestIdentity(); diff --git a/go/pkg/zerotier/nativetap.go b/go/pkg/zerotier/nativetap.go index 2d4b789fc..c7c12cf48 100644 --- a/go/pkg/zerotier/nativetap.go +++ b/go/pkg/zerotier/nativetap.go @@ -158,66 +158,6 @@ func (t *nativeTap) AddMulticastGroupChangeHandler(handler func(bool, *Multicast t.multicastGroupHandlersLock.Unlock() } -// AddRoute adds or updates a managed route on this tap's interface -func (t *nativeTap) AddRoute(r *Route) error { - rc := 0 - if r != nil { - var via []byte - if r.Via != nil { - via = *r.Via - } - if len(r.Target.IP) == 4 { - mask, _ := r.Target.Mask.Size() - if len(via) == 4 { - rc = int(C.ZT_GoTap_addRoute(t.tap, syscall.AF_INET, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), syscall.AF_INET, unsafe.Pointer(&via[0]), C.uint(r.Metric))) - } else { - rc = int(C.ZT_GoTap_addRoute(t.tap, syscall.AF_INET, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), 0, nil, C.uint(r.Metric))) - } - } else if len(r.Target.IP) == 16 { - mask, _ := r.Target.Mask.Size() - if len(via) == 16 { - rc = int(C.ZT_GoTap_addRoute(t.tap, syscall.AF_INET6, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), syscall.AF_INET6, unsafe.Pointer(&via[0]), C.uint(r.Metric))) - } else { - rc = int(C.ZT_GoTap_addRoute(t.tap, syscall.AF_INET6, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), 0, nil, C.uint(r.Metric))) - } - } - } - if rc != 0 { - return fmt.Errorf("tap device error adding route: %d", rc) - } - return nil -} - -// RemoveRoute removes a managed route on this tap's interface -func (t *nativeTap) RemoveRoute(r *Route) error { - rc := 0 - if r != nil { - var via []byte - if r.Via != nil { - via = *r.Via - } - if len(r.Target.IP) == 4 { - mask, _ := r.Target.Mask.Size() - if len(via) == 4 { - rc = int(C.ZT_GoTap_removeRoute(t.tap, syscall.AF_INET, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), syscall.AF_INET, unsafe.Pointer(&(via[0])), C.uint(r.Metric))) - } else { - rc = int(C.ZT_GoTap_removeRoute(t.tap, syscall.AF_INET, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), 0, nil, C.uint(r.Metric))) - } - } else if len(r.Target.IP) == 16 { - mask, _ := r.Target.Mask.Size() - if len(via) == 16 { - rc = int(C.ZT_GoTap_removeRoute(t.tap, syscall.AF_INET6, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), syscall.AF_INET6, unsafe.Pointer(&via[0]), C.uint(r.Metric))) - } else { - rc = int(C.ZT_GoTap_removeRoute(t.tap, syscall.AF_INET6, unsafe.Pointer(&r.Target.IP[0]), C.int(mask), 0, nil, C.uint(r.Metric))) - } - } - } - if rc != 0 { - return fmt.Errorf("tap device error removing route: %d", rc) - } - return nil -} - func handleTapMulticastGroupChange(gn unsafe.Pointer, nwid, mac C.uint64_t, adi C.uint32_t, added bool) { go func() { nodesByUserPtrLock.RLock() diff --git a/go/pkg/zerotier/network.go b/go/pkg/zerotier/network.go index 589bb5074..a182f6f47 100644 --- a/go/pkg/zerotier/network.go +++ b/go/pkg/zerotier/network.go @@ -341,7 +341,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) { wantManagedRoutes[k] = true if _, have := haveManagedRoutes[k]; !have { n.node.infoLog.Printf("%.16x adding managed route %s", uint64(n.id), r.String()) - _ = n.tap.AddRoute(&r) + //TODO _ = n.tap.AddRoute(&r) } } } @@ -349,7 +349,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) { for k, r := range haveManagedRoutes { if _, want := wantManagedRoutes[k]; !want { n.node.infoLog.Printf("%.16x removing managed route %s", uint64(n.id), r.String()) - _ = n.tap.RemoveRoute(r) + //TODO _ = n.tap.RemoveRoute(r) } } diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index 396b9ad4d..7fe87ca71 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -56,18 +56,6 @@ const ( NetworkTypePrivate int = C.ZT_NETWORK_TYPE_PRIVATE NetworkTypePublic int = C.ZT_NETWORK_TYPE_PUBLIC - // CoreVersionMajor is the major version of the ZeroTier core - CoreVersionMajor int = C.ZEROTIER_ONE_VERSION_MAJOR - - // CoreVersionMinor is the minor version of the ZeroTier core - CoreVersionMinor int = C.ZEROTIER_ONE_VERSION_MINOR - - // CoreVersionRevision is the revision of the ZeroTier core - CoreVersionRevision int = C.ZEROTIER_ONE_VERSION_REVISION - - // CoreVersionBuild is the build version of the ZeroTier core - CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD - networkConfigOpUp int = C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP networkConfigOpUpdate int = C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE @@ -82,8 +70,22 @@ var ( nodesByUserPtr = make(map[uintptr]*Node) nodesByUserPtrCtr = uintptr(0) nodesByUserPtrLock sync.RWMutex + + CoreVersionMajor int + CoreVersionMinor int + CoreVersionRevision int + CoreVersionBuild int ) +func init() { + var vMaj,vMin,vRev,vBuild C.int + C.ZT_version(&vMaj,&vMin,&vRev,&vBuild) + CoreVersionMajor = int(vMaj) + CoreVersionMinor = int(vMin) + CoreVersionRevision = int(vRev) + CoreVersionBuild = int(vBuild) +} + // Node is an instance of a virtual port on the global switch. type Node struct { // networks contains networks we have joined, and networksByMAC by their local MAC address diff --git a/go/pkg/zerotier/tap.go b/go/pkg/zerotier/tap.go index a72bd8190..29c119d98 100644 --- a/go/pkg/zerotier/tap.go +++ b/go/pkg/zerotier/tap.go @@ -46,10 +46,4 @@ type Tap interface { // AddMulticastGroupChangeHandler registers a function to be called on multicast group subscribe or unsubscribe (first argument) AddMulticastGroupChangeHandler(func(bool, *MulticastGroup)) - - // AddRoute adds a route to this tap device via the system or other routing table - AddRoute(r *Route) error - - // RemoveRoute removes a route from this tap device - RemoveRoute(r *Route) error } diff --git a/include/ZeroTierCore.h b/include/ZeroTierCore.h index 03a8783ca..70942a0fe 100644 --- a/include/ZeroTierCore.h +++ b/include/ZeroTierCore.h @@ -2203,8 +2203,9 @@ ZT_SDK_API void ZT_Identity_delete(ZT_Identity *id); * @param major Result: major version * @param minor Result: minor version * @param revision Result: revision + * @param build Result: build number */ -ZT_SDK_API void ZT_version(int *major,int *minor,int *revision); +ZT_SDK_API void ZT_version(int *major,int *minor,int *revision,int *build); #ifdef __cplusplus } diff --git a/node/Node.cpp b/node/Node.cpp index 000b15abf..f11869496 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -1073,7 +1073,7 @@ enum ZT_ResultCode ZT_Node_setPhysicalPathConfiguration(ZT_Node *node,const stru } } -void ZT_version(int *major,int *minor,int *revision) +void ZT_version(int *major,int *minor,int *revision,int *build) { if (major) *major = ZEROTIER_VERSION_MAJOR; @@ -1081,6 +1081,8 @@ void ZT_version(int *major,int *minor,int *revision) *minor = ZEROTIER_VERSION_MINOR; if (revision) *revision = ZEROTIER_VERSION_REVISION; + if (build) + *build = ZEROTIER_VERSION_BUILD; } } // extern "C" diff --git a/node/OS.hpp b/node/OS.hpp index 97cff81c8..13d50068f 100644 --- a/node/OS.hpp +++ b/node/OS.hpp @@ -17,9 +17,9 @@ #ifndef ZT_OS_HPP #define ZT_OS_HPP -#include -#include -#include +#include +#include +#include #if defined(_WIN32) || defined(_WIN64) #ifdef _MSC_VER @@ -40,10 +40,22 @@ #include #endif +#ifdef SOCKET +#define ZT_SOCKET SOCKET +#else +#define ZT_SOCKET int +#endif +#ifdef INVALID_SOCKET +#define ZT_INVALID_SOCKET INVALID_SOCKET +#else +#define ZT_INVALID_SOCKET (-1) +#endif + #if !defined(__GNUC__) && (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(__INTEL_COMPILER) || defined(__clang__)) #define __GNUC__ 3 #endif +#ifdef __cplusplus #if __cplusplus > 199711L #include #ifndef __CPP11__ @@ -58,6 +70,7 @@ #define constexpr ZT_INLINE #define noexcept throw() #endif +#endif #ifdef __GNUC__ #ifndef ZT_DEBUG diff --git a/osdep/CMakeLists.txt b/osdep/CMakeLists.txt index 8cf6c864e..a0e6c9d81 100644 --- a/osdep/CMakeLists.txt +++ b/osdep/CMakeLists.txt @@ -4,7 +4,6 @@ project(zt_osdep) set(src Arp.cpp EthernetTap.cpp - ManagedRoute.cpp NeighborDiscovery.cpp OSUtils.cpp ) @@ -13,7 +12,6 @@ set(headers Arp.hpp BlockingQueue.hpp EthernetTap.hpp - ManagedRoute.hpp OSUtils.hpp Thread.hpp ) diff --git a/osdep/EthernetTap.hpp b/osdep/EthernetTap.hpp index e7e6d6b08..bd47c67ee 100644 --- a/osdep/EthernetTap.hpp +++ b/osdep/EthernetTap.hpp @@ -18,7 +18,6 @@ #include "../node/MAC.hpp" #include "../node/InetAddress.hpp" #include "../node/MulticastGroup.hpp" -#include "ManagedRoute.hpp" #include #include @@ -57,35 +56,6 @@ public: virtual void setFriendlyName(const char *friendlyName) = 0; virtual void scanMulticastGroups(std::vector &added,std::vector &removed) = 0; virtual void setMtu(unsigned int mtu) = 0; - - ZT_INLINE int addRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) - { - const std::string dn(this->routingDeviceName()); - const char *const dnp = (dn.length() > 0) ? dn.c_str() : (const char *)0; - std::lock_guard l(_managedRoutes_l); - _managedRoutes[std::pair(target,metric)] = std::shared_ptr(new ManagedRoute(target,via,dnp)); - return 0; - } - - ZT_INLINE int removeRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) - { - std::lock_guard l(_managedRoutes_l); - _managedRoutes.erase(std::pair(target,metric)); - return 0; - } - - ZT_INLINE int syncRoutes() - { - std::lock_guard l(_managedRoutes_l); - for(auto r=_managedRoutes.begin();r!=_managedRoutes.end();++r) { - r->second->sync(); - } - return 0; - } - -private: - std::map< std::pair,std::shared_ptr > _managedRoutes; - std::mutex _managedRoutes_l; }; } // namespace ZeroTier diff --git a/osdep/MacEthernetTap.cpp b/osdep/MacEthernetTap.cpp index 1a6539eda..2913faea7 100644 --- a/osdep/MacEthernetTap.cpp +++ b/osdep/MacEthernetTap.cpp @@ -227,7 +227,7 @@ bool MacEthernetTap::addIp(const InetAddress &ip) std::string cmd; cmd.push_back((char)ZT_MACETHERNETTAPAGENT_STDIN_CMD_IFCONFIG); - cmd.append((ip.ss_family == AF_INET6) ? "inet6" : "inet"); + cmd.append((ip.family() == AF_INET6) ? "inet6" : "inet"); cmd.push_back(0); cmd.append(ip.toString(tmp)); cmd.push_back(0); @@ -252,7 +252,7 @@ bool MacEthernetTap::removeIp(const InetAddress &ip) std::string cmd; cmd.push_back((char)ZT_MACETHERNETTAPAGENT_STDIN_CMD_IFCONFIG); - cmd.append((ip.ss_family == AF_INET6) ? "inet6" : "inet"); + cmd.append((ip.family() == AF_INET6) ? "inet6" : "inet"); cmd.push_back(0); cmd.append(ip.toString(tmp)); cmd.push_back(0); @@ -307,8 +307,8 @@ void MacEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,co uint16_t l; if ((_agentStdin > 0)&&(len <= _mtu)&&(_enabled)) { hdr[0] = ZT_MACETHERNETTAPAGENT_STDIN_CMD_PACKET; - to.copyTo(hdr + 1,6); - from.copyTo(hdr + 7,6); + to.copyTo(hdr + 1); + from.copyTo(hdr + 7); hdr[13] = (unsigned char)((etherType >> 8) & 0xff); hdr[14] = (unsigned char)(etherType & 0xff); l = (uint16_t)(len + 15); @@ -339,7 +339,7 @@ void MacEthernetTap::scanMulticastGroups(std::vector &added,std: struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name; struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr; if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen))) - newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0)); + newGroups.push_back(MulticastGroup(MAC((uint8_t *)(la->sdl_data + la->sdl_nlen)),0)); } p = p->ifma_next; } @@ -423,8 +423,8 @@ void MacEthernetTap::threadMain() char *msg = agentReadBuf + 2; if ((len > 14)&&(_enabled)) { - to.setTo(msg,6); - from.setTo(msg + 6,6); + to.setTo((uint8_t *)msg); + from.setTo((uint8_t *)(msg + 6)); _handler(_arg,(void *)0,_nwid,from,to,ntohs(((const uint16_t *)msg)[6]),0,(const void *)(msg + 14),(unsigned int)len - 14); } diff --git a/osdep/MacKextEthernetTap.cpp b/osdep/MacKextEthernetTap.cpp index 27414eb1a..0b63b7c26 100644 --- a/osdep/MacKextEthernetTap.cpp +++ b/osdep/MacKextEthernetTap.cpp @@ -487,7 +487,7 @@ bool MacKextEthernetTap::addIp(const InetAddress &ip) long cpid = (long)vfork(); if (cpid == 0) { char tmp[128]; - ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.ss_family == AF_INET6) ? "inet6" : "inet",ip.toString(tmp),"alias",(const char *)0); + ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.family() == AF_INET6) ? "inet6" : "inet",ip.toString(tmp),"alias",(const char *)0); ::_exit(-1); } else if (cpid > 0) { int exitcode = -1; @@ -508,7 +508,7 @@ bool MacKextEthernetTap::removeIp(const InetAddress &ip) long cpid = (long)vfork(); if (cpid == 0) { char tmp[128]; - execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.ss_family == AF_INET6) ? "inet6" : "inet",ip.toIpString(tmp),"-alias",(const char *)0); + execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),(ip.family() == AF_INET6) ? "inet6" : "inet",ip.toIpString(tmp),"-alias",(const char *)0); _exit(-1); } else if (cpid > 0) { int exitcode = -1; @@ -562,8 +562,8 @@ void MacKextEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherTyp { char putBuf[ZT_MAX_MTU + 64]; if ((_fd > 0)&&(len <= _mtu)&&(_enabled)) { - to.copyTo(putBuf,6); - from.copyTo(putBuf + 6,6); + to.copyTo((uint8_t *)putBuf); + from.copyTo((uint8_t *)(putBuf + 6)); *((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType); memcpy(putBuf + 14,data,len); len += 14; @@ -592,7 +592,7 @@ void MacKextEthernetTap::scanMulticastGroups(std::vector &added, struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name; struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr; if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen))) - newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0)); + newGroups.push_back(MulticastGroup(MAC((uint8_t *)(la->sdl_data + la->sdl_nlen)),0)); } p = p->ifma_next; } @@ -673,8 +673,8 @@ void MacKextEthernetTap::threadMain() r = _mtu + 14; if (_enabled) { - to.setTo(getBuf,6); - from.setTo(getBuf + 6,6); + to.setTo((uint8_t *)getBuf); + from.setTo((uint8_t *)(getBuf + 6)); unsigned int etherType = ntohs(((const uint16_t *)getBuf)[6]); // TODO: VLAN support _handler(_arg,(void *)0,_nwid,from,to,etherType,0,(const void *)(getBuf + 14),r - 14); diff --git a/osdep/NeighborDiscovery.cpp b/osdep/NeighborDiscovery.cpp index c09933d67..2adda8c93 100644 --- a/osdep/NeighborDiscovery.cpp +++ b/osdep/NeighborDiscovery.cpp @@ -124,7 +124,7 @@ struct _neighbor_advertisement { memset(target, 0, sizeof(target)); } - void calculateChecksum(const sockaddr_storage &sourceIp, const sockaddr_storage &destIp) { + void calculateChecksum(const sockaddr_storage &sourceIp, const InetAddress &destIp) { _pseudo_header ph; memset(&ph, 0, sizeof(_pseudo_header)); const sockaddr_in6 *src = (const sockaddr_in6*)&sourceIp; @@ -180,7 +180,7 @@ sockaddr_storage NeighborDiscovery::processIncomingND(const uint8_t *nd, unsigne // assert(sizeof(_neighbor_advertisement) == 32); const uint64_t now = OSUtils::now(); - sockaddr_storage ip = {0}; + InetAddress ip; if (len >= sizeof(_neighbor_solicitation) && nd[0] == 0x87) { // respond to Neighbor Solicitation request for local address @@ -190,12 +190,12 @@ sockaddr_storage NeighborDiscovery::processIncomingND(const uint8_t *nd, unsigne _NDEntry *targetEntry = _cache.get(targetAddress); if (targetEntry && targetEntry->local) { _neighbor_advertisement adv; - targetEntry->mac.copyTo(adv.option.mac, 6); + targetEntry->mac.copyTo(adv.option.mac); memcpy(adv.target, solicitation.target, 16); adv.calculateChecksum(localIp, targetAddress); memcpy(response, &adv, sizeof(_neighbor_advertisement)); responseLen = sizeof(_neighbor_advertisement); - responseDest.setTo(solicitation.option.mac, 6); + responseDest.setTo(solicitation.option.mac); } } else if (len >= sizeof(_neighbor_advertisement) && nd[0] == 0x88) { _neighbor_advertisement adv; @@ -204,7 +204,7 @@ sockaddr_storage NeighborDiscovery::processIncomingND(const uint8_t *nd, unsigne _NDEntry *queryEntry = _cache.get(responseAddress); if(queryEntry && !queryEntry->local && (now - queryEntry->lastQuerySent <= ZT_ND_QUERY_MAX_TTL)) { queryEntry->lastResponseReceived = now; - queryEntry->mac.setTo(adv.option.mac, 6); + queryEntry->mac.setTo(adv.option.mac); ip = responseAddress; } } @@ -212,8 +212,8 @@ sockaddr_storage NeighborDiscovery::processIncomingND(const uint8_t *nd, unsigne if ((now - _lastCleaned) >= ZT_ND_EXPIRE) { _lastCleaned = now; Hashtable::Iterator i(_cache); - InetAddress *k = NULL; - _NDEntry *v = NULL; + InetAddress *k = nullptr; + _NDEntry *v = nullptr; while (i.next(k, v)) { if(!v->local && (now - v->lastResponseReceived) >= ZT_ND_EXPIRE) { _cache.erase(*k); @@ -221,7 +221,7 @@ sockaddr_storage NeighborDiscovery::processIncomingND(const uint8_t *nd, unsigne } } - return ip; + return *reinterpret_cast(&ip); } MAC NeighborDiscovery::query(const MAC &localMac, const sockaddr_storage &localIp, const sockaddr_storage &targetIp, uint8_t *query, unsigned int &queryLen, MAC &queryDest) @@ -241,7 +241,7 @@ MAC NeighborDiscovery::query(const MAC &localMac, const sockaddr_storage &localI _neighbor_solicitation ns; memcpy(ns.target, targetAddress.rawIpData(), 16); - localMac.copyTo(ns.option.mac, 6); + localMac.copyTo(ns.option.mac); ns.calculateChecksum(localIp, targetIp); if (e.mac) { queryDest = e.mac; diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index dc8c03ecc..1390bc68a 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -352,7 +352,7 @@ uint64_t OSUtils::jsonInt(const nlohmann::json &jv,const uint64_t dfl) return (uint64_t)jv; } else if (jv.is_string()) { std::string s = jv; - return Utils::strToU64(s.c_str()); + return (uint64_t)strtoull(s.c_str(),nullptr,10); } else if (jv.is_boolean()) { return ((bool)jv ? 1ULL : 0ULL); }