Introduction of sequential-API build variant, better thread safety (lwIP only)

This commit is contained in:
Joseph Henry
2017-09-27 02:29:04 -07:00
parent e4620e4c85
commit 5f1e9fe795
176 changed files with 16494 additions and 20406 deletions

View File

@@ -24,16 +24,28 @@
* of your own application.
*/
/**
* @file
*
* Debug macros
*/
#ifndef LIBZT_DEBUG_HPP
#define LIBZT_DEBUG_HPP
#include <pthread.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include "Platform.h"
#define ZT_MSG_ERROR true // Errors
#define ZT_MSG_INFO true // Information which is generally useful to any developer
#define ZT_MSG_TEST true // For use in selftest
#define ZT_MSG_TRANSFER true // RX/TX specific statements
#define ZT_MSG_EXTRA false // If nothing in your world makes sense
#define ZT_MSG_EXTRA true // If nothing in your world makes sense
#define ZT_COLOR true
@@ -74,7 +86,7 @@ extern unsigned int gettid(); // defined in libzt.cpp
#ifdef __linux__
#define ZT_THREAD_ID syscall(SYS_gettid)
#elif __APPLE__
#define ZT_THREAD_ID (long)gettid()
#define ZT_THREAD_ID (long)0//(long)gettid()
#endif
#if defined(__JNI_LIB__)
@@ -87,10 +99,10 @@ extern unsigned int gettid(); // defined in libzt.cpp
// Network stack debugging
#if defined(__ANDROID__)
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"STACK[%ld]: %17s:%5d:%20s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL "STACK[%ld]: %17s:%5d:%25s: " fmt \
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL "STACK[%ld]: %17s:%5d:%25s: " fmt \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
@@ -99,10 +111,10 @@ extern unsigned int gettid(); // defined in libzt.cpp
//
#if ZT_MSG_TEST == true
#if defined(__ANDROID__)
#define DEBUG_TEST(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
#define DEBUG_TEST(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TEST : %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt \
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt \
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -112,10 +124,10 @@ extern unsigned int gettid(); // defined in libzt.cpp
//
#if ZT_MSG_ERROR == true
#if defined(__ANDROID__)
#define DEBUG_ERROR(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
#define DEBUG_ERROR(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ERROR: %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED \
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED \
"ERROR[%ld]: %17s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -125,10 +137,10 @@ extern unsigned int gettid(); // defined in libzt.cpp
//
#if ZT_MSG_INFO == true
#if defined(__ANDROID__)
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"INFO : %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
"INFO [%ld]: %17s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -141,7 +153,7 @@ extern unsigned int gettid(); // defined in libzt.cpp
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TRANS: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt \
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt \
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -154,7 +166,7 @@ extern unsigned int gettid(); // defined in libzt.cpp
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"EXTRA: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
"EXTRA[%ld]: %17s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#endif
#else
@@ -170,3 +182,5 @@ extern unsigned int gettid(); // defined in libzt.cpp
#define DEBUG_TRANS(fmt, args...)
#define DEBUG_EXTRA(fmt, args...)
#endif
#endif // LIBZT_DEBUG_HPP

347
include/Defs.h Normal file
View File

@@ -0,0 +1,347 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* Application-facing, partially-POSIX-compliant socket API
*/
#ifndef LIBZT_DEFINES_H
#define LIBZT_DEFINES_H
#define ZT_MAX_MTU 10000
/**
* How fast service states are re-checked (in milliseconds)
*/
#define ZTO_WRAPPER_CHECK_INTERVAL 50
/**
*
*/
#define ZTO_ID_LEN 16
typedef uint32_t socklen_t;
/****************************************************************************/
/* For SOCK_RAW support, it will initially be modeled after linux's API, so */
/* below are the various things we need to define in order to make this API */
/* work on other platforms. Mayber later down the road we will customize */
/* this for each different platform. Maybe. */
/****************************************************************************/
#if !defined(__linux__)
#define SIOCGIFINDEX 101
#define SIOCGIFHWADDR 102
// Normally defined in linux/if_packet.h, defined here so we can offer a linux-like
// raw socket API on non-linux platforms
struct sockaddr_ll {
unsigned short sll_family; /* Always AF_PACKET */
unsigned short sll_protocol; /* Physical layer protocol */
int sll_ifindex; /* Interface number */
unsigned short sll_hatype; /* ARP hardware type */
unsigned char sll_pkttype; /* Packet type */
unsigned char sll_halen; /* Length of address */
unsigned char sll_addr[8]; /* Physical layer address */
};
#endif
// Provide missing optnames for setsockopt() implementations
#ifdef _WIN32
#ifdef _WIN64
#else
#endif
#elif __APPLE__
#define IP_BIND_ADDRESS_NO_PORT 201
#define IP_FREEBIND 202
#define IP_MTU 203
#define IP_MTU_DISCOVER 204
#define IP_MULTICAST_ALL 205
#define IP_NODEFRAG 206
#define IP_RECVORIGDSTADDR 207
#define IP_ROUTER_ALERT 208
#define IP_TRANSPARENT 209
#define TCP_INFO 210
#define SO_STYLE 100
#define TCP_CORK 101
#define TCP_DEFER_ACCEPT 102
#define TCP_KEEPIDLE 103
#define TCP_LINGER2 104
#define TCP_QUICKACK 105
#define TCP_SYNCNT 106
#define TCP_WINDOW_CLAMP 107
#define UDP_CORK 108
#elif __linux__
#define SO_STYLE 100
#define UDP_CORK 101
#define IP_BIND_ADDRESS_NO_PORT 201
#define IP_NODEFRAG 206
#elif __unix__
#elif defined(_POSIX_VERSION)
#else
# error "Unknown platform"
#endif
/****************************************************************************/
/* Legend */
/****************************************************************************/
/*
NSLWIP network_stack_lwip
NSPICO network_stack_pico
NSRXBF network_stack_pico guarded frame buffer RX
ZTVIRT zt_virtual_wire
APPFDS app_fd
VSRXBF app_fd TX buf
VSTXBF app_fd RX buf
*/
/****************************************************************************/
/* lwIP */
/****************************************************************************/
// For LWIP configuration see: include/lwipopts.h
#if defined(STACK_LWIP)
typedef signed char err_t;
/*
Specifies the polling interval and the callback function that should
be called to poll the application. The interval is specified in
number of TCP coarse grained timer shots, which typically occurs
twice a second. An interval of 10 means that the application would
be polled every 5 seconds.
*/
#define LWIP_APPLICATION_POLL_FREQ 2
/**
*
*/
#define LWIP_TCP_TIMER_INTERVAL 25
/**
* How often we check VirtualSocket statuses (in ms)
*/
#define LWIP_STATUS_TMR_INTERVAL 500
// #define LWIP_CHKSUM <your_checksum_routine>, See: RFC1071 for inspiration
#endif
/****************************************************************************/
/* picoTCP */
/****************************************************************************/
#if defined(STACK_PICO)
#endif
/****************************************************************************/
/* Defines */
/****************************************************************************/
/**
*
*/
#define ZT_MAX_SOCKETS 1024
/**
*
*/
#define ZT_SDK_MTU ZT_MAX_MTU
/**
*
*/
#define ZT_LEN_SZ 4
/**
*
*/
#define ZT_ADDR_SZ 128
/**
*
*/
#define ZT_SOCKET_MSG_BUF_SZ ZT_SDK_MTU + ZT_LEN_SZ + ZT_ADDR_SZ
/**
*
*/
#define ZT_PHY_POLL_INTERVAL 5 // ms
/**
*
*/
#define ZT_ACCEPT_RECHECK_DELAY 100 // ms (for blocking zts_accept() calls)
/**
*
*/
#define ZT_CONNECT_RECHECK_DELAY 100 // ms (for blocking zts_connect() calls)
/**
*
*/
#define ZT_API_CHECK_INTERVAL 100 // ms
/**
*
*/
#define MAX_PICO_FRAME_RX_BUF_SZ ZT_MAX_MTU * 128
/**
*
*/
#define ZT_TCP_TX_BUF_SZ 1024 * 1024 * 128
/**
*
*/
#define ZT_TCP_RX_BUF_SZ 1024 * 1024 * 128
/**
*
*/
#define ZT_UDP_TX_BUF_SZ ZT_MAX_MTU
/**
*
*/
#define ZT_UDP_RX_BUF_SZ ZT_MAX_MTU * 10
// Send and Receive buffer sizes for the network stack
// By default picoTCP sets them to 16834, this is good for embedded-scale
// stuff but you might want to consider higher values for desktop and mobile
// applications.
/**
*
*/
#define ZT_STACK_TCP_SOCKET_TX_SZ ZT_TCP_TX_BUF_SZ
/**
*
*/
#define ZT_STACK_TCP_SOCKET_RX_SZ ZT_TCP_RX_BUF_SZ
// Maximum size we're allowed to read or write from a stack socket
// This is put in place because picoTCP seems to fail at higher values.
// If you use another stack you can probably bump this up a bit.
/**
*
*/
#define ZT_STACK_SOCKET_WR_MAX 4096
/**
*
*/
#define ZT_STACK_SOCKET_RD_MAX 4096*4
/**
*
*/
#define ZT_CORE_VERSION_MAJOR 1
#define ZT_CORE_VERSION_MINOR 2
#define ZT_CORE_VERSION_REVISION 5
/**
*
*/
#define ZT_LIB_VERSION_MAJOR 1
#define ZT_LIB_VERSION_MINOR 1
#define ZT_LIB_VERSION_REVISION 4
/**
*
*/
#define ZT_ID_LEN 16
/**
*
*/
#define ZT_VER_STR_LEN 6
/**
*
*/
#define ZT_HOME_PATH_MAX_LEN 128
/**
*
*/
#define ZT_MAC_ADDRSTRLEN 18
/**
*
*/
#define ZT_ERR_OK 0
/**
*
*/
#define ZT_ERR_GENERAL_FAILURE -88
// Since extra time is required to send a mesage via a socket through the
// stack and ZT service, calling a zts_close() immediately after a "successful"
// zts_write() might cause data loss, for this reason, sockets will SO_LINGER for
// a short period of time by default as a precaution.
/**
*
*/
#define ZT_SOCK_BEHAVIOR_LINGER true
/**
*
*/
#define ZT_SOCK_BEHAVIOR_LINGER_TIME 3 // s
/**
* Wait time for socket closure if data is still present in the write queue
*/
#define ZT_SDK_CLTIME 60
// After closing a pico_socket, other threads might still try to use the
// VirtualSocket object for remaining data I/O, as a safety measure we will wait to
// delete this VirtualSocket object until the socket has been closed for some arbitrary
// amount of time and it is safe to assume any clients interacting with this
// socket have read some sort of error code from the API.
/**
* Interval for performing cleanup tasks on Tap/Stack objects (in seconds)
*/
#define ZT_HOUSEKEEPING_INTERVAL 10
/**
* Whether or not we want libzt to exit on internal failure
*/
#define ZT_EXIT_ON_GENERAL_FAIL false
#endif // LIBZT_DEFINES_H

62
include/Platform.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* Platform-specific implementations of common functions
*/
#ifndef LIBZT_PLATFORM_H
#define LIBZT_PLATFORM_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void handle_general_failure();
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
inline unsigned int gettid();
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,4 +1 @@
libzt API
======
This is the C++ API for libzt. It provides a platform-agnostic interface to the ZeroTier network virtualization service. All other [language bindings](../examples) are written in terms of this.
For applications, see [libzt.h](libzt.h) for POSIX-like socket API.

90
include/Utilities.h Normal file
View File

@@ -0,0 +1,90 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* Misc utilities
*/
#ifndef LIBZT_UTILITIES_H
#define LIBZT_UTILITIES_H
#include "InetAddress.hpp"
/**
* @brief Returns masked address for subnet comparisons
*
* @usage For internal use only.
*
* @param
*
* @return
*/
bool ipv6_in_subnet(ZeroTier::InetAddress *subnet, ZeroTier::InetAddress *addr);
/**
* @brief Convert protocol numbers to human-readable strings
*
* @usage For internal use only.
*
* @param
*
* @return
*/
char *beautify_eth_proto_nums(int proto);
/**
* @brief Convert a struct sockaddr to a ZeroTier::InetAddress
*
* @usage For internal use only.
*
* @param
*
* @return
*/
void sockaddr2inet(int socket_family, const struct sockaddr *addr, ZeroTier::InetAddress *inet);
/**
* @brief Convert a raw MAC address byte array into a human-readable string
*
* @usage For internal use only.
*
* @param
*
* @return
*/
void mac2str(char *macbuf, int len, unsigned char* addr);
#if defined(STACK_LWIP) && defined(LIBZT_IPV6)
#define IP6_ADDR2(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = ZeroTier::Utils::hton((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \
(ipaddr)->addr[1] = ZeroTier::Utils::hton(((c & 0xffff) << 16) | (d & 0xffff)); \
(ipaddr)->addr[2] = ZeroTier::Utils::hton(((e & 0xffff) << 16) | (f & 0xffff)); \
(ipaddr)->addr[3] = ZeroTier::Utils::hton(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
#endif
#endif // UTILITIES_HPP

View File

@@ -0,0 +1,48 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
*
*/
/*
#ifndef LIBZT_VIRTUALBINDINGPAIR_H
#define LIBZT_VIRTUALBINDINGPAIR_H
#ifdef __cplusplus
extern "C" {
#endif
struct VirtualBindingPair;
#ifdef __cplusplus
}
#endif
#endif
*/

51
include/VirtualSocket.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* Platform-agnostic implementation of a socket-like object
*/
#ifndef LIBZT_VIRTUALSOCKET_H
#define LIBZT_VIRTUALSOCKET_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* An abstraction of a socket that operates between the application-exposed platform-sockets
* and the network stack's representation of a protocol control structure. This object is used by
* the POSIX socket emulation layer and stack drivers.
*/
class VirtualSocket;
#ifdef __cplusplus
}
#endif
#endif

346
include/ZT1Service.h Normal file
View File

@@ -0,0 +1,346 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* ZeroTier One service control wrapper header file
*/
#include "ZeroTierOne.h"
#include "Defs.h"
#include <vector>
#ifndef ZT1SERVICE_H
#define ZT1SERVICE_H
#ifdef __cplusplus
extern "C" {
#endif
namespace ZeroTier
{
extern std::vector<void*> vtaps;
class picoTCP;
extern ZeroTier::picoTCP *picostack;
class lwIP;
extern ZeroTier::lwIP *lwipstack;
class VirtualTap;
class VirtualSocket;
struct InetAddress;
}
/**
* @brief Returns a vector of network routes { target, via, metric, etc... }
*
* @usage
* @param nwid
* @return
*/
std::vector<ZT_VirtualNetworkRoute> *zts_get_network_routes(char *nwid);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
int zts_get_device_id_from_file(const char *filepath, char *devID);
/**
* @brief Starts a ZeroTier service in the background
*
* @usage For internal use only.
* @param
* @return
*/
void *zts_start_service(void *thread_id);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void disableTaps();
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void zts_get_ipv4_address(const char *nwid, char *addrstr, const int addrlen);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void zts_get_ipv6_address(const char *nwid, char *addrstr, const int addrlen);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
int zts_has_ipv4_address(const char *nwid);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
int zts_has_ipv6_address(const char *nwid);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
int zts_has_address(const char *nwid);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_get_6plane_addr(char *addr, const char *nwid, const char *devID);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_get_rfc4193_addr(char *addr, const char *nwid, const char *devID);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_join(const char * nwid);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void zts_join_soft(const char * filepath, const char * nwid);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_leave(const char * nwid);
/**
* @brief
*
* @usage For internal use only.
* @param
* @return
*/
void zts_leave_soft(const char * filepath, const char * nwid);
/**
* @brief
*
* @usage
* @param
* @return
*/
int zts_running();
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_start(const char *path);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_simple_start(const char *path, const char *nwid);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_stop();
/**
* @brief
*
* @usage
* @param
* @return
*/void zts_get_homepath(char *homePath, int len);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_core_version(char *ver);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_lib_version(char *ver);
/**
* @brief
*
* @usage
* @param
* @return
*/
int zts_get_device_id(char *devID);
/**
* @brief
*
* @usage
* @param
* @return
*/
unsigned long zts_get_peer_count();
/**
* @brief
*
* @usage
* @param
* @return
*/
int zts_get_peer_address(char *peer, const char *devID);
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_enable_http_control_plane();
/**
* @brief
*
* @usage
* @param
* @return
*/
void zts_disable_http_control_plane();
/**
* @brief Whether we can add a new socket or not. Depends on stack in use
*
* @usage
* @param socket_type
* @return
*/
bool can_provision_new_socket(int socket_type);
/**
* @brief Returns the number of sockets either already provisioned or waiting to be
* Some network stacks may have a limit on the number of sockets that they can
* safely handle due to timer construction, this is a way to check that we
* haven't passed that limit. Someday if multiple stacks are used simultaneously
* the logic for this function should change accordingly.
*
* @usage
* @param
* @return
*/
int zts_num_active_virt_sockets();
/**
* @brief Returns maximum number of sockets allowed by network stack
*
* @usage
* @param socket_type
* @return
*/
int zts_maxsockets(int socket_type);
/**
* @brief
*
* @usage
* @param
* @return
*/
int pico_ntimers();
#endif // ZT1SERVICE_H
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

73
include/lwIP.hpp Normal file
View File

@@ -0,0 +1,73 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial closed-source software that incorporates or links
* directly against ZeroTier software without disclosing the source code
* of your own application.
*/
/**
* @file
*
* lwIP network stack driver
*/
#ifndef ZT_LWIP_HPP
#define ZT_LWIP_HPP
#include "MAC.hpp"
#include "InetAddress.hpp"
#include "Defs.h"
/**
* @brief Initialize network stack semaphores, threads, and timers.
*
* @param
* @return
*/
void lwip_driver_init();
/**
* @brief Set up an interface in the network stack for the VirtualTap.
*
* @param
* @return
*/
void lwip_init_interface(void *tapref, const ZeroTier::MAC &mac, const ZeroTier::InetAddress &ip);
/**
* @brief Called from the stack, outbound ethernet frames from the network stack enter the ZeroTier virtual wire here.
*
* @param
* @return
*/
err_t lwip_eth_tx(struct netif *netif, struct pbuf *p);
/**
* @brief Packets from the ZeroTier virtual wire enter the stack here.
*
* @param
* @return
*/
void lwip_eth_rx(ZeroTier::VirtualTap *tap, const ZeroTier::MAC &from, const ZeroTier::MAC &to, unsigned int etherType,
const void *data, unsigned int len);
#endif

View File

@@ -1,9 +1,3 @@
/**
* @file
*
* lwIP Options Configuration
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
@@ -35,9 +29,48 @@
* Author: Adam Dunkels <adam@sics.se>
*
*/
/**
* @file
*
* lwIP Options Configuration
*/
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
/*
* Provides its own errno
*/
#define LWIP_PROVIDE_ERRNO 0
/*
* Provides core locking machinery
*/
#define LWIP_TCPIP_CORE_LOCKING 1
/*
* Provides a macro to spoof the names of the lwip socket functions
*/
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
/*
*
*/
#define LWIP_TIMERS 1
/*
*
*/
//#define LWIP_COMPAT_MUTEX 1
//#define LWIP_COMPAT_MUTEX_ALLOWED 1
/*
* Provides network/host byte transformation macros
*/
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1
/*
* Include user defined options first. Anything not defined in these files
* will be set to standard values. Override anything you dont like!
@@ -56,6 +89,9 @@
// --- DEBUG ---
#define LWIP_DEBUG 1
/* flag for LWIP_DEBUGF indicating a tracing message
* (to follow program flow)
*/
@@ -124,8 +160,6 @@
#define DNS_DEBUG LWIP_DBG_OFF
#define LWIP_UDP 1
#define LWIP_TCP 1
#define LWIP_ETHERNET 1
#define LWIP_CHKSUM_ALGORITHM 2
@@ -187,7 +221,7 @@ happening sooner than they should.
* critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT 0
#define SYS_LIGHTWEIGHT_PROT 1
/**
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
@@ -195,10 +229,10 @@ happening sooner than they should.
*/
/* set to 1 so we have no thread behaviour */
#define NO_SYS 1
#define NO_SYS 0
/* set to 1 so we can use our own timers */
#define NO_SYS_NO_TIMERS 1
#define NO_SYS_NO_TIMERS 0
/*------------------------------------------------------------------------------
@@ -218,7 +252,7 @@ happening sooner than they should.
* 4 byte alignment -> #define MEM_ALIGNMENT 4
* 2 byte alignment -> #define MEM_ALIGNMENT 2
*/
#define MEM_ALIGNMENT 1
#define MEM_ALIGNMENT 4
/**
* MEM_SIZE: the size of the heap memory. If the application will send
@@ -526,7 +560,7 @@ happening sooner than they should.
/**
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
*/
#define LWIP_NETCONN 0
#define LWIP_NETCONN 1//(NO_SYS==0)
/*------------------------------------------------------------------------------
@@ -535,7 +569,8 @@ happening sooner than they should.
/**
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
#define LWIP_SOCKET 0
#define LWIP_SOCKET 1//(NO_SYS==0)
/*------------------------------------------------------------------------------