mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Gogog
This commit is contained in:
parent
bb53ee9567
commit
5e35346f17
7 changed files with 19 additions and 76 deletions
|
@ -108,12 +108,12 @@ extern "C" int goPathLookupFunc(ZT_GoNode *,uint64_t,int,int *,uint8_t [16],int
|
||||||
extern "C" void goStateObjectPutFunc(ZT_GoNode *,int,const uint64_t [2],const void *,int);
|
extern "C" void goStateObjectPutFunc(ZT_GoNode *,int,const uint64_t [2],const void *,int);
|
||||||
extern "C" int goStateObjectGetFunc(ZT_GoNode *,int,const uint64_t [2],void *,unsigned int);
|
extern "C" int goStateObjectGetFunc(ZT_GoNode *,int,const uint64_t [2],void *,unsigned int);
|
||||||
extern "C" void goDNSResolverFunc(ZT_GoNode *,const uint8_t *,int,const char *,uintptr_t);
|
extern "C" void goDNSResolverFunc(ZT_GoNode *,const uint8_t *,int,const char *,uintptr_t);
|
||||||
extern "C" int goVirtualNetworkConfigFunc(ZT_GoNode *,ZT_GoTap *,uint64_t,int,const ZT_VirtualNetworkConfig *);
|
extern "C" void goVirtualNetworkConfigFunc(ZT_GoNode *,ZT_GoTap *,uint64_t,int,const ZT_VirtualNetworkConfig *);
|
||||||
extern "C" void goZtEvent(ZT_GoNode *,int,const void *);
|
extern "C" void goZtEvent(ZT_GoNode *,int,const void *);
|
||||||
extern "C" void goHandleTapAddedMulticastGroup(ZT_GoNode *,ZT_GoTap *,uint64_t,uint64_t,uint32_t);
|
extern "C" void goHandleTapAddedMulticastGroup(ZT_GoNode *,ZT_GoTap *,uint64_t,uint64_t,uint32_t);
|
||||||
extern "C" void goHandleTapRemovedMulticastGroup(ZT_GoNode *,ZT_GoTap *,uint64_t,uint64_t,uint32_t);
|
extern "C" void goHandleTapRemovedMulticastGroup(ZT_GoNode *,ZT_GoTap *,uint64_t,uint64_t,uint32_t);
|
||||||
|
|
||||||
static int ZT_GoNode_VirtualNetworkConfigFunction(
|
static void ZT_GoNode_VirtualNetworkConfigFunction(
|
||||||
ZT_Node *node,
|
ZT_Node *node,
|
||||||
void *uptr,
|
void *uptr,
|
||||||
void *tptr,
|
void *tptr,
|
||||||
|
@ -122,7 +122,7 @@ static int ZT_GoNode_VirtualNetworkConfigFunction(
|
||||||
enum ZT_VirtualNetworkConfigOperation op,
|
enum ZT_VirtualNetworkConfigOperation op,
|
||||||
const ZT_VirtualNetworkConfig *cfg)
|
const ZT_VirtualNetworkConfig *cfg)
|
||||||
{
|
{
|
||||||
return goVirtualNetworkConfigFunc(reinterpret_cast<ZT_GoNode *>(uptr),reinterpret_cast<ZT_GoTap *>(*nptr),nwid,op,cfg);
|
goVirtualNetworkConfigFunc(reinterpret_cast<ZT_GoNode *>(uptr),reinterpret_cast<ZT_GoTap *>(*nptr),nwid,op,cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZT_GoNode_VirtualNetworkFrameFunction(
|
static void ZT_GoNode_VirtualNetworkFrameFunction(
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkID is a network's 64-bit unique ID
|
// NetworkID is a network's 64-bit unique ID
|
||||||
|
@ -70,9 +69,6 @@ type NetworkConfig struct {
|
||||||
// Status is a status code indicating this network's authorization status
|
// Status is a status code indicating this network's authorization status
|
||||||
Status int
|
Status int
|
||||||
|
|
||||||
// LastUpdated is the time this network's configuration was last updated from the controller
|
|
||||||
LastUpdated time.Time
|
|
||||||
|
|
||||||
// Type is this network's type
|
// Type is this network's type
|
||||||
Type int
|
Type int
|
||||||
|
|
||||||
|
@ -80,34 +76,19 @@ type NetworkConfig struct {
|
||||||
MTU int
|
MTU int
|
||||||
|
|
||||||
// CanBridge is true if this network is allowed to bridge in other devices with different Ethernet addresses
|
// CanBridge is true if this network is allowed to bridge in other devices with different Ethernet addresses
|
||||||
CanBridge bool
|
Bridge bool
|
||||||
|
|
||||||
// AllowsBroadcast is true if the broadcast (ff:ff:ff:ff:ff:ff) address works (excluding IPv4 ARP which is handled via a special path)
|
// BroadcastEnabled is true if the broadcast (ff:ff:ff:ff:ff:ff) address works (excluding IPv4 ARP which is handled via a special path)
|
||||||
AllowsBroadcast bool
|
BroadcastEnabled bool
|
||||||
|
|
||||||
// IPs are static IPs assigned by the network controller to this device
|
// Network configuration revision number according to network controller
|
||||||
IPs []net.IPNet
|
NetconfRevision uint64
|
||||||
|
|
||||||
|
// AssignedAddresses are static IPs assigned by the network controller to this device
|
||||||
|
AssignedAddresses []net.IPNet
|
||||||
|
|
||||||
// Routes are static routes assigned by the network controller to this device
|
// Routes are static routes assigned by the network controller to this device
|
||||||
Routes []Route
|
Routes []Route
|
||||||
|
|
||||||
// MulticastSubscriptions are this device's current multicast subscriptions
|
|
||||||
MulticastSubscriptions []MulticastGroup
|
|
||||||
|
|
||||||
// Enabled is true if this network's tap device is enabled
|
|
||||||
Enabled bool
|
|
||||||
|
|
||||||
// TapDeviceType is a human-readable description of this network's tap device type
|
|
||||||
TapDeviceType string
|
|
||||||
|
|
||||||
// TapDevicePort is the OS-specific virtual device name (if applicable)
|
|
||||||
TapDevicePort string
|
|
||||||
|
|
||||||
// TapErrorCode is an implementation-specific error code from the tap device (0 for no error)
|
|
||||||
TapErrorCode int
|
|
||||||
|
|
||||||
// TapError is a human-readable description of this tap device's error state or an empty string if there is no error
|
|
||||||
TapError string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network is a currently joined network
|
// Network is a currently joined network
|
||||||
|
@ -125,11 +106,7 @@ func (n *Network) ID() NetworkID { return n.id }
|
||||||
// Config returns a copy of this network's current configuration
|
// Config returns a copy of this network's current configuration
|
||||||
func (n *Network) Config() NetworkConfig {
|
func (n *Network) Config() NetworkConfig {
|
||||||
n.configLock.RLock()
|
n.configLock.RLock()
|
||||||
n.tapLock.RLock()
|
|
||||||
defer n.tapLock.RUnlock()
|
|
||||||
defer n.configLock.RUnlock()
|
defer n.configLock.RUnlock()
|
||||||
n.config.Enabled = n.tap.Enabled()
|
|
||||||
n.config.TapErrorCode, n.config.TapError = n.tap.Error()
|
|
||||||
return n.config
|
return n.config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,7 @@ func goDNSResolverFunc(gn unsafe.Pointer, dnsRecordTypes unsafe.Pointer, numDNSR
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goVirtualNetworkConfigFunc
|
//export goVirtualNetworkConfigFunc
|
||||||
func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.int, conf unsafe.Pointer) C.int {
|
func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.int, conf unsafe.Pointer) {
|
||||||
nodesByUserPtrLock.RLock()
|
nodesByUserPtrLock.RLock()
|
||||||
node := nodesByUserPtr[uintptr(gn)]
|
node := nodesByUserPtr[uintptr(gn)]
|
||||||
nodesByUserPtrLock.RUnlock()
|
nodesByUserPtrLock.RUnlock()
|
||||||
|
|
|
@ -687,17 +687,7 @@ enum ZT_VirtualNetworkStatus
|
||||||
/**
|
/**
|
||||||
* Netconf master exists, but this virtual network does not
|
* Netconf master exists, but this virtual network does not
|
||||||
*/
|
*/
|
||||||
ZT_NETWORK_STATUS_NOT_FOUND = 3,
|
ZT_NETWORK_STATUS_NOT_FOUND = 3
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialization of network failed or other internal error
|
|
||||||
*/
|
|
||||||
ZT_NETWORK_STATUS_PORT_ERROR = 4,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ZeroTier core version too old
|
|
||||||
*/
|
|
||||||
ZT_NETWORK_STATUS_CLIENT_TOO_OLD = 5
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1098,15 +1088,6 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
unsigned int mtu;
|
unsigned int mtu;
|
||||||
|
|
||||||
/**
|
|
||||||
* If nonzero, the network this port belongs to indicates DHCP availability
|
|
||||||
*
|
|
||||||
* This is a suggestion. The underlying implementation is free to ignore it
|
|
||||||
* for security or other reasons. This is simply a netconf parameter that
|
|
||||||
* means 'DHCP is available on this network.'
|
|
||||||
*/
|
|
||||||
int dhcp;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If nonzero, this port is allowed to bridge to other networks
|
* If nonzero, this port is allowed to bridge to other networks
|
||||||
*
|
*
|
||||||
|
@ -1120,11 +1101,6 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
int broadcastEnabled;
|
int broadcastEnabled;
|
||||||
|
|
||||||
/**
|
|
||||||
* If the network is in PORT_ERROR state, this is the (negative) error code most recently reported
|
|
||||||
*/
|
|
||||||
int portError;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revision number as reported by controller or 0 if still waiting for config
|
* Revision number as reported by controller or 0 if still waiting for config
|
||||||
*/
|
*/
|
||||||
|
@ -1409,12 +1385,8 @@ typedef void ZT_Node;
|
||||||
* This should not call multicastSubscribe() or other network-modifying
|
* This should not call multicastSubscribe() or other network-modifying
|
||||||
* methods, as this could cause a deadlock in multithreaded or interrupt
|
* methods, as this could cause a deadlock in multithreaded or interrupt
|
||||||
* driven environments.
|
* driven environments.
|
||||||
*
|
|
||||||
* This must return 0 on success. It can return any OS-dependent error code
|
|
||||||
* on failure, and this results in the network being placed into the
|
|
||||||
* PORT_ERROR state.
|
|
||||||
*/
|
*/
|
||||||
typedef int (*ZT_VirtualNetworkConfigFunction)(
|
typedef void (*ZT_VirtualNetworkConfigFunction)(
|
||||||
ZT_Node *, /* Node */
|
ZT_Node *, /* Node */
|
||||||
void *, /* User ptr */
|
void *, /* User ptr */
|
||||||
void *, /* Thread ptr */
|
void *, /* Thread ptr */
|
||||||
|
|
|
@ -548,8 +548,7 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
|
||||||
_portInitialized(false),
|
_portInitialized(false),
|
||||||
_lastConfigUpdate(0),
|
_lastConfigUpdate(0),
|
||||||
_destroyed(false),
|
_destroyed(false),
|
||||||
_netconfFailure(NETCONF_FAILURE_NONE),
|
_netconfFailure(NETCONF_FAILURE_NONE)
|
||||||
_portError(0)
|
|
||||||
{
|
{
|
||||||
for(int i=0;i<ZT_NETWORK_MAX_INCOMING_UPDATES;++i)
|
for(int i=0;i<ZT_NETWORK_MAX_INCOMING_UPDATES;++i)
|
||||||
_incomingConfigChunks[i].ts = 0;
|
_incomingConfigChunks[i].ts = 0;
|
||||||
|
@ -584,7 +583,7 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
|
||||||
if (!_portInitialized) {
|
if (!_portInitialized) {
|
||||||
ZT_VirtualNetworkConfig ctmp;
|
ZT_VirtualNetworkConfig ctmp;
|
||||||
_externalConfig(&ctmp);
|
_externalConfig(&ctmp);
|
||||||
_portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||||
_portInitialized = true;
|
_portInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -991,7 +990,7 @@ int Network::setConfiguration(void *tPtr,const NetworkConfig &nconf,bool saveToD
|
||||||
_externalConfig(&ctmp);
|
_externalConfig(&ctmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_portError = RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,(oldPortInitialized) ? ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
RR->node->configureVirtualNetworkPort(tPtr,_id,&_uPtr,(oldPortInitialized) ? ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE : ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP,&ctmp);
|
||||||
|
|
||||||
if (saveToDisk) {
|
if (saveToDisk) {
|
||||||
try {
|
try {
|
||||||
|
@ -1311,8 +1310,6 @@ void Network::_requestConfiguration(void *tPtr)
|
||||||
|
|
||||||
ZT_VirtualNetworkStatus Network::_status() const
|
ZT_VirtualNetworkStatus Network::_status() const
|
||||||
{
|
{
|
||||||
if (_portError)
|
|
||||||
return ZT_NETWORK_STATUS_PORT_ERROR;
|
|
||||||
switch(_netconfFailure) {
|
switch(_netconfFailure) {
|
||||||
case NETCONF_FAILURE_ACCESS_DENIED:
|
case NETCONF_FAILURE_ACCESS_DENIED:
|
||||||
return ZT_NETWORK_STATUS_ACCESS_DENIED;
|
return ZT_NETWORK_STATUS_ACCESS_DENIED;
|
||||||
|
@ -1321,7 +1318,7 @@ ZT_VirtualNetworkStatus Network::_status() const
|
||||||
case NETCONF_FAILURE_NONE:
|
case NETCONF_FAILURE_NONE:
|
||||||
return ((_config) ? ZT_NETWORK_STATUS_OK : ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION);
|
return ((_config) ? ZT_NETWORK_STATUS_OK : ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION);
|
||||||
default:
|
default:
|
||||||
return ZT_NETWORK_STATUS_PORT_ERROR;
|
return ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1336,7 +1333,6 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||||
ec->status = _status();
|
ec->status = _status();
|
||||||
ec->type = (_config) ? (_config.isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE;
|
ec->type = (_config) ? (_config.isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE;
|
||||||
ec->mtu = (_config) ? _config.mtu : ZT_DEFAULT_MTU;
|
ec->mtu = (_config) ? _config.mtu : ZT_DEFAULT_MTU;
|
||||||
ec->dhcp = 0;
|
|
||||||
std::vector<Address> ab;
|
std::vector<Address> ab;
|
||||||
for(unsigned int i=0;i<_config.specialistCount;++i) {
|
for(unsigned int i=0;i<_config.specialistCount;++i) {
|
||||||
if ((_config.specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
|
if ((_config.specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
|
||||||
|
@ -1344,7 +1340,6 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||||
}
|
}
|
||||||
ec->bridge = (std::find(ab.begin(),ab.end(),RR->identity.address()) != ab.end()) ? 1 : 0;
|
ec->bridge = (std::find(ab.begin(),ab.end(),RR->identity.address()) != ab.end()) ? 1 : 0;
|
||||||
ec->broadcastEnabled = (_config) ? (_config.enableBroadcast() ? 1 : 0) : 0;
|
ec->broadcastEnabled = (_config) ? (_config.enableBroadcast() ? 1 : 0) : 0;
|
||||||
ec->portError = _portError;
|
|
||||||
ec->netconfRevision = (_config) ? (unsigned long)_config.revision : 0;
|
ec->netconfRevision = (_config) ? (unsigned long)_config.revision : 0;
|
||||||
|
|
||||||
ec->assignedAddressCount = 0;
|
ec->assignedAddressCount = 0;
|
||||||
|
|
|
@ -459,7 +459,6 @@ private:
|
||||||
NETCONF_FAILURE_NOT_FOUND,
|
NETCONF_FAILURE_NOT_FOUND,
|
||||||
NETCONF_FAILURE_INIT_FAILED
|
NETCONF_FAILURE_INIT_FAILED
|
||||||
} _netconfFailure;
|
} _netconfFailure;
|
||||||
int _portError; // return value from port config callback
|
|
||||||
|
|
||||||
Hashtable<Address,Membership> _memberships;
|
Hashtable<Address,Membership> _memberships;
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_ALWAYS_INLINE void postEvent(void *tPtr,ZT_Event ev,const void *md = (const void *)0) { _cb.eventCallback(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,ev,md); }
|
ZT_ALWAYS_INLINE void postEvent(void *tPtr,ZT_Event ev,const void *md = (const void *)0) { _cb.eventCallback(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,ev,md); }
|
||||||
ZT_ALWAYS_INLINE int configureVirtualNetworkPort(void *tPtr,uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { return _cb.virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,nwid,nuptr,op,nc); }
|
ZT_ALWAYS_INLINE void configureVirtualNetworkPort(void *tPtr,uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) { _cb.virtualNetworkConfigFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,nwid,nuptr,op,nc); }
|
||||||
ZT_ALWAYS_INLINE bool online() const { return _online; }
|
ZT_ALWAYS_INLINE bool online() const { return _online; }
|
||||||
ZT_ALWAYS_INLINE int stateObjectGet(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],void *const data,const unsigned int maxlen) { return _cb.stateGetFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,type,id,data,maxlen); }
|
ZT_ALWAYS_INLINE int stateObjectGet(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],void *const data,const unsigned int maxlen) { return _cb.stateGetFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,type,id,data,maxlen); }
|
||||||
ZT_ALWAYS_INLINE void stateObjectPut(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],const void *const data,const unsigned int len) { _cb.statePutFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,type,id,data,(int)len); }
|
ZT_ALWAYS_INLINE void stateObjectPut(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],const void *const data,const unsigned int len) { _cb.statePutFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,type,id,data,(int)len); }
|
||||||
|
|
Loading…
Add table
Reference in a new issue