mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-12 07:23:45 +02:00
It almost builds!
This commit is contained in:
parent
cdbb86b830
commit
83f830618f
17 changed files with 110 additions and 206 deletions
|
@ -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<struct sockaddr *>(&in6),&salen);
|
||||
if (s > 0) {
|
||||
gn->node->processWirePacket(&gnt,OSUtils::now(),(int64_t)udpSock,reinterpret_cast<const struct sockaddr_storage *>(&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<struct sockaddr *>(&in6),&salen);
|
||||
if (s > 0) {
|
||||
ZT_Node_processWirePacket(
|
||||
reinterpret_cast<ZT_Node *>(gn->node),
|
||||
nullptr,
|
||||
OSUtils::now(),
|
||||
(int64_t)udpSock,
|
||||
reinterpret_cast<const struct sockaddr_storage *>(&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<struct sockaddr *>(&in4),&salen);
|
||||
if (s > 0) {
|
||||
gn->node->processWirePacket(&gnt,OSUtils::now(),(int64_t)udpSock,reinterpret_cast<const struct sockaddr_storage *>(&in4),buf,(unsigned int)s,&(gn->nextBackgroundTaskDeadline));
|
||||
void *buf = ZT_getBuffer();
|
||||
if (buf) {
|
||||
int s = (int)recvfrom(udpSock,buf,sizeof(buf),0,reinterpret_cast<struct sockaddr *>(&in4),&salen);
|
||||
if (s > 0) {
|
||||
ZT_Node_processWirePacket(
|
||||
reinterpret_cast<ZT_Node *>(gn->node),
|
||||
nullptr,
|
||||
OSUtils::now(),
|
||||
(int64_t)udpSock,
|
||||
reinterpret_cast<const struct sockaddr_storage *>(&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<ZT_GoNode *>(uptr);
|
||||
gn->node->processVirtualNetworkFrame(tptr,OSUtils::now(),nwid,from.toInt(),to.toInt(),etherType,vlanId,data,len,&(gn->nextBackgroundTaskDeadline));
|
||||
ZT_Node_processVirtualNetworkFrame(
|
||||
reinterpret_cast<ZT_Node *>(reinterpret_cast<ZT_GoNode *>(uptr)->node),
|
||||
tptr,
|
||||
OSUtils::now(),
|
||||
nwid,
|
||||
from.toInt(),
|
||||
to.toInt(),
|
||||
etherType,
|
||||
vlanId,
|
||||
data,
|
||||
len,
|
||||
0,
|
||||
&(reinterpret_cast<ZT_GoNode *>(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<EthernetTap *>(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<EthernetTap *>(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<EthernetTap *>(tap)->removeRoute(target,via,metric);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
19
node/OS.hpp
19
node/OS.hpp
|
@ -17,9 +17,9 @@
|
|||
#ifndef ZT_OS_HPP
|
||||
#define ZT_OS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#ifdef _MSC_VER
|
||||
|
@ -40,10 +40,22 @@
|
|||
#include <sys/param.h>
|
||||
#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 <atomic>
|
||||
#ifndef __CPP11__
|
||||
|
@ -58,6 +70,7 @@
|
|||
#define constexpr ZT_INLINE
|
||||
#define noexcept throw()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#ifndef ZT_DEBUG
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "../node/MAC.hpp"
|
||||
#include "../node/InetAddress.hpp"
|
||||
#include "../node/MulticastGroup.hpp"
|
||||
#include "ManagedRoute.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
@ -57,35 +56,6 @@ public:
|
|||
virtual void setFriendlyName(const char *friendlyName) = 0;
|
||||
virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &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<std::mutex> l(_managedRoutes_l);
|
||||
_managedRoutes[std::pair<InetAddress,unsigned int>(target,metric)] = std::shared_ptr<ManagedRoute>(new ManagedRoute(target,via,dnp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZT_INLINE int removeRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_managedRoutes_l);
|
||||
_managedRoutes.erase(std::pair<InetAddress,unsigned int>(target,metric));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZT_INLINE int syncRoutes()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_managedRoutes_l);
|
||||
for(auto r=_managedRoutes.begin();r!=_managedRoutes.end();++r) {
|
||||
r->second->sync();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map< std::pair<InetAddress,unsigned int>,std::shared_ptr<ManagedRoute> > _managedRoutes;
|
||||
std::mutex _managedRoutes_l;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -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<MulticastGroup> &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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MulticastGroup> &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);
|
||||
|
|
|
@ -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<InetAddress, _NDEntry>::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<sockaddr_storage *>(&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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue