2019-02-06 22:00:39 -08:00
|
|
|
/*
|
2021-01-30 13:53:49 -08:00
|
|
|
* Copyright (c)2013-2021 ZeroTier, Inc.
|
2019-02-06 22:00:39 -08:00
|
|
|
*
|
2020-04-13 23:38:06 -07:00
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
2019-02-06 22:00:39 -08:00
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
* Change Date: 2026-01-01
|
2019-02-06 22:00:39 -08:00
|
|
|
*
|
2020-04-13 23:38:06 -07:00
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
2019-02-06 22:00:39 -08:00
|
|
|
*/
|
2020-04-13 23:38:06 -07:00
|
|
|
/****/
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
* ZeroTier Node Service
|
2020-05-01 19:15:38 -07:00
|
|
|
*/
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
#ifndef ZTS_NODE_SERVICE_HPP
|
|
|
|
|
#define ZTS_NODE_SERVICE_HPP
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-30 15:36:46 -07:00
|
|
|
#define ZTS_UNUSED_ARG(x) (void)x
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
#include "Binder.hpp"
|
2020-05-01 19:15:38 -07:00
|
|
|
#include "Mutex.hpp"
|
2021-04-17 23:46:21 -07:00
|
|
|
#include "Node.hpp"
|
2021-04-29 14:03:15 -07:00
|
|
|
#include "Phy.hpp"
|
2021-04-22 11:20:04 -07:00
|
|
|
#include "PortMapper.hpp"
|
2020-05-01 19:15:38 -07:00
|
|
|
#include "ZeroTierSockets.h"
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#define ZTS_SERVICE_THREAD_NAME "ZTServiceThread"
|
|
|
|
|
#define ZTS_EVENT_CALLBACK_THREAD_NAME "ZTEventCallbackThread"
|
2021-04-22 11:20:04 -07:00
|
|
|
// Interface metric for ZeroTier taps -- this ensures that if we are on WiFi and
|
|
|
|
|
// also bridged via ZeroTier to the same LAN traffic will (if the OS is sane)
|
|
|
|
|
// prefer WiFi.
|
2021-04-17 23:46:21 -07:00
|
|
|
#define ZT_IF_METRIC 5000
|
2020-05-01 19:15:38 -07:00
|
|
|
// How often to check for new multicast subscriptions on a tap device
|
2021-04-17 23:46:21 -07:00
|
|
|
#define ZT_TAP_CHECK_MULTICAST_INTERVAL 5000
|
2020-05-01 19:15:38 -07:00
|
|
|
// How often to check for local interface addresses
|
|
|
|
|
#define ZT_LOCAL_INTERFACE_CHECK_INTERVAL 60000
|
|
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2021-12-29 16:23:32 -05:00
|
|
|
#include <windows.h>
|
2019-02-06 22:00:39 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
2021-04-30 15:36:46 -07:00
|
|
|
struct InetAddress;
|
2021-04-29 14:03:15 -07:00
|
|
|
class VirtualTap;
|
|
|
|
|
class MAC;
|
|
|
|
|
class Events;
|
|
|
|
|
|
2019-02-06 22:00:39 -08:00
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
* ZeroTier node service
|
2019-02-06 22:00:39 -08:00
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
class NodeService {
|
|
|
|
|
public:
|
2021-04-26 22:07:55 -07:00
|
|
|
/**
|
|
|
|
|
* Returned by node main if/when it terminates
|
|
|
|
|
*/
|
|
|
|
|
enum ReasonForTermination {
|
|
|
|
|
/**
|
|
|
|
|
* Instance is still running
|
|
|
|
|
*/
|
|
|
|
|
ONE_STILL_RUNNING = 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normal shutdown
|
|
|
|
|
*/
|
|
|
|
|
ONE_NORMAL_TERMINATION = 1,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A serious unrecoverable error has occurred
|
|
|
|
|
*/
|
|
|
|
|
ONE_UNRECOVERABLE_ERROR = 2,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Your identity has collided with another
|
|
|
|
|
*/
|
|
|
|
|
ONE_IDENTITY_COLLISION = 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Local settings for each network
|
|
|
|
|
*/
|
|
|
|
|
struct NetworkSettings {
|
|
|
|
|
/**
|
|
|
|
|
* Allow this network to configure IP addresses and routes?
|
|
|
|
|
*/
|
|
|
|
|
bool allowManaged;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whitelist of addresses that can be configured by this network.
|
|
|
|
|
* If empty and allowManaged is true, allow all
|
|
|
|
|
* private/pseudoprivate addresses.
|
|
|
|
|
*/
|
|
|
|
|
std::vector<InetAddress> allowManagedWhitelist;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allow configuration of IPs and routes within global (Internet) IP
|
|
|
|
|
* space?
|
|
|
|
|
*/
|
|
|
|
|
bool allowGlobal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allow overriding of system default routes for "full tunnel"
|
|
|
|
|
* operation?
|
|
|
|
|
*/
|
|
|
|
|
bool allowDefault;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Phy<NodeService*> _phy;
|
|
|
|
|
Node* _node;
|
2021-05-11 14:31:01 -07:00
|
|
|
|
|
|
|
|
uint64_t _nodeId;
|
2021-05-13 14:17:08 -07:00
|
|
|
unsigned int _primaryPort;
|
|
|
|
|
unsigned int _secondaryPort;
|
|
|
|
|
unsigned int _tertiaryPort;
|
|
|
|
|
|
|
|
|
|
unsigned int _randomPortRangeStart;
|
|
|
|
|
unsigned int _randomPortRangeEnd;
|
|
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
volatile unsigned int _udpPortPickerCounter;
|
|
|
|
|
|
|
|
|
|
std::map<uint64_t, unsigned int> peerCache;
|
|
|
|
|
|
|
|
|
|
// Local configuration and memo-ized information from it
|
|
|
|
|
Hashtable<uint64_t, std::vector<InetAddress> > _v4Hints;
|
|
|
|
|
Hashtable<uint64_t, std::vector<InetAddress> > _v6Hints;
|
|
|
|
|
Hashtable<uint64_t, std::vector<InetAddress> > _v4Blacklists;
|
|
|
|
|
Hashtable<uint64_t, std::vector<InetAddress> > _v6Blacklists;
|
|
|
|
|
std::vector<InetAddress> _globalV4Blacklist;
|
|
|
|
|
std::vector<InetAddress> _globalV6Blacklist;
|
|
|
|
|
std::vector<InetAddress> _allowManagementFrom;
|
|
|
|
|
std::vector<std::string> _interfacePrefixBlacklist;
|
|
|
|
|
Mutex _localConfig_m;
|
|
|
|
|
|
|
|
|
|
std::vector<InetAddress> explicitBind;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* To attempt to handle NAT/gateway craziness we use three local UDP
|
|
|
|
|
* ports:
|
|
|
|
|
*
|
|
|
|
|
* [0] is the normal/default port, usually 9993
|
|
|
|
|
* [1] is a port derived from our ZeroTier address
|
|
|
|
|
* [2] is a port computed from the normal/default for use with
|
|
|
|
|
* uPnP/NAT-PMP mappings
|
|
|
|
|
*
|
|
|
|
|
* [2] exists because on some gateways trying to do regular NAT-t
|
|
|
|
|
* interferes destructively with uPnP port mapping behavior in very
|
|
|
|
|
* weird buggy ways. It's only used if uPnP/NAT-PMP is enabled in this
|
|
|
|
|
* build.
|
|
|
|
|
*/
|
|
|
|
|
unsigned int _ports[3] = { 0 };
|
|
|
|
|
Binder _binder;
|
|
|
|
|
|
|
|
|
|
// Time we last received a packet from a global address
|
|
|
|
|
uint64_t _lastDirectReceiveFromGlobal;
|
|
|
|
|
|
|
|
|
|
// Last potential sleep/wake event
|
|
|
|
|
uint64_t _lastRestart;
|
|
|
|
|
|
|
|
|
|
// Deadline for the next background task service function
|
|
|
|
|
volatile int64_t _nextBackgroundTaskDeadline;
|
|
|
|
|
|
|
|
|
|
// Configured networks
|
|
|
|
|
struct NetworkState {
|
|
|
|
|
NetworkState() : tap((VirtualTap*)0)
|
|
|
|
|
{
|
|
|
|
|
// Real defaults are in network 'up' code in network event
|
|
|
|
|
// handler
|
|
|
|
|
settings.allowManaged = true;
|
|
|
|
|
settings.allowGlobal = false;
|
|
|
|
|
settings.allowDefault = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VirtualTap* tap;
|
|
|
|
|
ZT_VirtualNetworkConfig config; // memcpy() of raw config from core
|
|
|
|
|
std::vector<InetAddress> managedIps;
|
|
|
|
|
NetworkSettings settings;
|
|
|
|
|
};
|
|
|
|
|
std::map<uint64_t, NetworkState> _nets;
|
|
|
|
|
|
|
|
|
|
/** Lock to control access to network configuration data */
|
|
|
|
|
Mutex _nets_m;
|
|
|
|
|
/** Lock to control access to storage data */
|
|
|
|
|
Mutex _store_m;
|
|
|
|
|
/** Lock to control access to service run state */
|
|
|
|
|
Mutex _run_m;
|
|
|
|
|
// Set to false to force service to stop
|
|
|
|
|
volatile bool _run;
|
|
|
|
|
/** Lock to control access to termination reason */
|
|
|
|
|
Mutex _termReason_m;
|
|
|
|
|
// Termination status information
|
|
|
|
|
ReasonForTermination _termReason;
|
|
|
|
|
|
|
|
|
|
std::string _fatalErrorMessage;
|
|
|
|
|
|
|
|
|
|
// uPnP/NAT-PMP port mapper if enabled
|
2021-05-13 14:17:08 -07:00
|
|
|
bool _allowPortMapping;
|
2021-04-22 11:20:04 -07:00
|
|
|
#ifdef ZT_USE_MINIUPNPC
|
2021-04-26 22:07:55 -07:00
|
|
|
PortMapper* _portMapper;
|
2021-04-22 11:20:04 -07:00
|
|
|
#endif
|
2021-05-13 14:17:08 -07:00
|
|
|
bool _allowSecondaryPort;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
uint8_t _allowNetworkCaching;
|
|
|
|
|
uint8_t _allowPeerCaching;
|
|
|
|
|
uint8_t _allowIdentityCaching;
|
2021-05-13 14:17:08 -07:00
|
|
|
uint8_t _allowRootSetCaching;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
char _publicIdStr[ZT_IDENTITY_STRING_BUFFER_LENGTH] = { 0 };
|
|
|
|
|
char _secretIdStr[ZT_IDENTITY_STRING_BUFFER_LENGTH] = { 0 };
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
bool _userDefinedWorld;
|
2021-04-29 14:03:15 -07:00
|
|
|
char _rootsData[ZTS_STORE_DATA_LEN] = { 0 };
|
|
|
|
|
int _rootsDataLen = 0;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Whether the node has successfully come online */
|
|
|
|
|
bool _nodeIsOnline;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Whether we allow the NodeService to generate events for the user */
|
|
|
|
|
bool _eventsEnabled;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Storage path defined by the user */
|
|
|
|
|
std::string _homePath;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** System to ingest events from this class and emit them to the user */
|
|
|
|
|
Events* _events;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
NodeService();
|
|
|
|
|
~NodeService();
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Main service loop */
|
|
|
|
|
ReasonForTermination run();
|
2020-05-30 18:29:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
ReasonForTermination reasonForTermination() const;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
std::string fatalErrorMessage() const;
|
2019-02-06 22:00:39 -08:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Stop the node and service */
|
|
|
|
|
void terminate();
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Apply or update managed IPs for a configured network */
|
|
|
|
|
void syncManagedStuff(NetworkState& n);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void phyOnDatagram(
|
|
|
|
|
PhySocket* sock,
|
|
|
|
|
void** uptr,
|
|
|
|
|
const struct sockaddr* localAddr,
|
|
|
|
|
const struct sockaddr* from,
|
|
|
|
|
void* data,
|
|
|
|
|
unsigned long len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int nodeVirtualNetworkConfigFunction(
|
|
|
|
|
uint64_t net_id,
|
|
|
|
|
void** nuptr,
|
|
|
|
|
enum ZT_VirtualNetworkConfigOperation op,
|
|
|
|
|
const ZT_VirtualNetworkConfig* nwc);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void nodeEventCallback(enum ZT_Event event, const void* metaData);
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
zts_net_info_t* prepare_network_details_msg(const NetworkState& n);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-05-11 14:31:01 -07:00
|
|
|
void generateSyntheticEvents();
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-05-11 14:31:01 -07:00
|
|
|
void sendEventToUser(unsigned int zt_event_code, const void* obj, unsigned int len = 0);
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Join a network */
|
|
|
|
|
int join(uint64_t net_id);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Leave a network */
|
|
|
|
|
int leave(uint64_t net_id);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return whether the network is ready for transport services */
|
|
|
|
|
bool networkIsReady(uint64_t net_id) const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Lock the service so we can perform queries */
|
|
|
|
|
void obtainLock() const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Unlock the service */
|
|
|
|
|
void releaseLock() const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return number of assigned addresses on the network. Service must be locked. */
|
|
|
|
|
int addressCount(uint64_t net_id) const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return number of managed routes on the network. Service must be locked. */
|
|
|
|
|
int routeCount(uint64_t net_id) const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return number of multicast subscriptions on the network. Service must be locked. */
|
|
|
|
|
int multicastSubCount(uint64_t net_id) const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return number of known physical paths to the peer. Service must be locked. */
|
|
|
|
|
int pathCount(uint64_t peer_id) const;
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int getAddrAtIdx(uint64_t net_id, unsigned int idx, char* dst, unsigned int len);
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int getRouteAtIdx(
|
|
|
|
|
uint64_t net_id,
|
|
|
|
|
unsigned int idx,
|
|
|
|
|
char* target,
|
|
|
|
|
char* via,
|
|
|
|
|
unsigned int len,
|
|
|
|
|
uint16_t* flags,
|
|
|
|
|
uint16_t* metric);
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int getMulticastSubAtIdx(uint64_t net_id, unsigned int idx, uint64_t* mac, uint32_t* adi);
|
2021-04-26 21:55:01 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int getPathAtIdx(uint64_t peer_id, unsigned int idx, char* path, unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Orbit a moon */
|
2021-04-30 15:36:46 -07:00
|
|
|
int orbit(uint64_t moonWorldId, uint64_t moonSeed);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** De-orbit a moon */
|
2021-04-30 15:36:46 -07:00
|
|
|
int deorbit(uint64_t moonWorldId);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return the integer-form of the node's identity */
|
|
|
|
|
uint64_t getNodeId();
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Gets the node's identity */
|
|
|
|
|
int getIdentity(char* keypair, unsigned int* len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Set the node's identity */
|
|
|
|
|
int setIdentity(const char* keypair, unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void nodeStatePutFunction(enum ZT_StateObjectType type, const uint64_t id[2], const void* data, unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int nodeStateGetFunction(enum ZT_StateObjectType type, const uint64_t id[2], void* data, unsigned int maxlen);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int nodeWirePacketSendFunction(
|
|
|
|
|
const int64_t localSocket,
|
|
|
|
|
const struct sockaddr_storage* addr,
|
|
|
|
|
const void* data,
|
|
|
|
|
unsigned int len,
|
|
|
|
|
unsigned int ttl);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void nodeVirtualNetworkFrameFunction(
|
|
|
|
|
uint64_t net_id,
|
|
|
|
|
void** nuptr,
|
|
|
|
|
uint64_t sourceMac,
|
|
|
|
|
uint64_t destMac,
|
|
|
|
|
unsigned int etherType,
|
|
|
|
|
unsigned int vlanId,
|
|
|
|
|
const void* data,
|
|
|
|
|
unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int nodePathCheckFunction(uint64_t ztaddr, const int64_t localSocket, const struct sockaddr_storage* remoteAddr);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int nodePathLookupFunction(uint64_t ztaddr, unsigned int family, struct sockaddr_storage* result);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void tapFrameHandler(
|
|
|
|
|
uint64_t net_id,
|
|
|
|
|
const MAC& from,
|
|
|
|
|
const MAC& to,
|
|
|
|
|
unsigned int etherType,
|
|
|
|
|
unsigned int vlanId,
|
|
|
|
|
const void* data,
|
|
|
|
|
unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int shouldBindInterface(const char* ifname, const InetAddress& ifaddr);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-12-07 11:46:07 -08:00
|
|
|
unsigned int _getRandomPort(unsigned int minPort, unsigned int maxPort);
|
|
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
int _trialBind(unsigned int port);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return whether the NodeService is running */
|
|
|
|
|
int isRunning() const;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Return whether the node is online */
|
|
|
|
|
int nodeIsOnline() const;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Instruct the NodeService on where to look for identity files and caches */
|
|
|
|
|
int setHomePath(const char* homePath);
|
|
|
|
|
|
2021-05-13 14:17:08 -07:00
|
|
|
/** Set the primary port */
|
2021-04-26 22:07:55 -07:00
|
|
|
int setPrimaryPort(unsigned short primaryPort);
|
|
|
|
|
|
2021-05-13 14:17:08 -07:00
|
|
|
/** Set random range to select backup ports from */
|
|
|
|
|
int setRandomPortRange(unsigned short startPort, unsigned short endPort);
|
|
|
|
|
|
|
|
|
|
/** Get the primary port */
|
2021-04-26 22:07:55 -07:00
|
|
|
unsigned short getPrimaryPort() const;
|
|
|
|
|
|
2021-05-13 14:17:08 -07:00
|
|
|
/** Allow or disallow port-mapping */
|
|
|
|
|
int allowPortMapping(unsigned int allowed);
|
|
|
|
|
|
|
|
|
|
/** Allow or disallow backup port */
|
|
|
|
|
int allowSecondaryPort(unsigned int allowed);
|
|
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
/** Set the event system instance used to convey messages to the user */
|
|
|
|
|
int setUserEventSystem(Events* events);
|
|
|
|
|
|
|
|
|
|
void enableEvents();
|
|
|
|
|
|
2021-04-29 14:03:15 -07:00
|
|
|
/** Set the roots definition */
|
2021-05-13 14:17:08 -07:00
|
|
|
int setRoots(const void* data, unsigned int len);
|
2021-04-26 22:07:55 -07:00
|
|
|
|
|
|
|
|
/** Add Interface prefix to blacklist (prevents ZeroTier from using that interface) */
|
|
|
|
|
int addInterfacePrefixToBlacklist(const char* prefix, unsigned int len);
|
|
|
|
|
|
|
|
|
|
/** Return the MAC Address of the node in the given network */
|
|
|
|
|
uint64_t getMACAddress(uint64_t net_id) const;
|
|
|
|
|
|
|
|
|
|
/** Get the string format name of a network */
|
|
|
|
|
int getNetworkName(uint64_t net_id, char* dst, unsigned int len) const;
|
|
|
|
|
|
|
|
|
|
/** Allow ZeroTier to cache peer hints to storage */
|
|
|
|
|
int allowPeerCaching(unsigned int allowed);
|
|
|
|
|
|
|
|
|
|
/** Allow ZeroTier to cache network info to storage */
|
|
|
|
|
int allowNetworkCaching(unsigned int allowed);
|
|
|
|
|
|
|
|
|
|
/** Allow ZeroTier to write identities to storage */
|
|
|
|
|
int allowIdentityCaching(unsigned int allowed);
|
|
|
|
|
|
2021-04-29 14:03:15 -07:00
|
|
|
/** Allow ZeroTier to cache root definitions to storage */
|
2021-05-13 14:17:08 -07:00
|
|
|
int allowRootSetCaching(unsigned int allowed);
|
2021-04-26 22:07:55 -07:00
|
|
|
|
|
|
|
|
/** Return whether broadcast is enabled on the given network */
|
|
|
|
|
int getNetworkBroadcast(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
/** Return the MTU of the given network */
|
|
|
|
|
int getNetworkMTU(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
/** Return whether the network is public or private */
|
|
|
|
|
int getNetworkType(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
/** Return the status of the network join */
|
|
|
|
|
int getNetworkStatus(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
/** Get the first address assigned by the network */
|
|
|
|
|
int getFirstAssignedAddr(uint64_t net_id, unsigned int family, struct zts_sockaddr_storage* addr);
|
|
|
|
|
|
|
|
|
|
/** Get an array of assigned addresses for the given network */
|
|
|
|
|
int getAllAssignedAddr(uint64_t net_id, struct zts_sockaddr_storage* addr, unsigned int* count);
|
|
|
|
|
|
|
|
|
|
/** Return whether a managed route of the given family has been assigned by the network */
|
|
|
|
|
int networkHasRoute(uint64_t net_id, unsigned int family);
|
|
|
|
|
|
|
|
|
|
/** Return whether an address of the given family has been assigned by the network */
|
|
|
|
|
int addrIsAssigned(uint64_t net_id, unsigned int family);
|
|
|
|
|
|
|
|
|
|
void phyOnTcpConnect(PhySocket* sock, void** uptr, bool success)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
|
|
|
|
ZTS_UNUSED_ARG(success);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnTcpAccept(PhySocket* sockL, PhySocket* sockN, void** uptrL, void** uptrN, const struct sockaddr* from)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sockL);
|
|
|
|
|
ZTS_UNUSED_ARG(sockN);
|
|
|
|
|
ZTS_UNUSED_ARG(uptrL);
|
|
|
|
|
ZTS_UNUSED_ARG(uptrN);
|
|
|
|
|
ZTS_UNUSED_ARG(from);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnTcpClose(PhySocket* sock, void** uptr)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnTcpData(PhySocket* sock, void** uptr, void* data, unsigned long len)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
|
|
|
|
ZTS_UNUSED_ARG(data);
|
|
|
|
|
ZTS_UNUSED_ARG(len);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnTcpWritable(PhySocket* sock, void** uptr)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnFileDescriptorActivity(PhySocket* sock, void** uptr, bool readable, bool writable)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
|
|
|
|
ZTS_UNUSED_ARG(readable);
|
|
|
|
|
ZTS_UNUSED_ARG(writable);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnUnixAccept(PhySocket* sockL, PhySocket* sockN, void** uptrL, void** uptrN)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sockL);
|
|
|
|
|
ZTS_UNUSED_ARG(sockN);
|
|
|
|
|
ZTS_UNUSED_ARG(uptrL);
|
|
|
|
|
ZTS_UNUSED_ARG(uptrN);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnUnixClose(PhySocket* sock, void** uptr)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
|
|
|
|
void phyOnUnixData(PhySocket* sock, void** uptr, void* data, unsigned long len)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
|
|
|
|
ZTS_UNUSED_ARG(data);
|
|
|
|
|
ZTS_UNUSED_ARG(len);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
2021-04-30 15:36:46 -07:00
|
|
|
|
2021-04-26 22:07:55 -07:00
|
|
|
void phyOnUnixWritable(PhySocket* sock, void** uptr)
|
|
|
|
|
{
|
2021-04-30 15:36:46 -07:00
|
|
|
ZTS_UNUSED_ARG(sock);
|
|
|
|
|
ZTS_UNUSED_ARG(uptr);
|
2021-04-26 22:07:55 -07:00
|
|
|
}
|
2019-02-06 22:00:39 -08:00
|
|
|
};
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
} // namespace ZeroTier
|
2019-02-06 22:00:39 -08:00
|
|
|
|
|
|
|
|
#endif
|