Updated build script, minor shuffling of code to prevent naming conflicts
This commit is contained in:
229
CMakeLists.txt
229
CMakeLists.txt
@@ -1,48 +1,59 @@
|
||||
#
|
||||
# ZeroTier SDK - Network Virtualization Everywhere
|
||||
# Copyright (C) 2011-2019 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.
|
||||
#
|
||||
|
||||
cmake_minimum_required (VERSION 3.0)
|
||||
project (zt)
|
||||
|
||||
set (CMAKE_VERBOSE_MAKEFILE OFF)
|
||||
|
||||
# Library and executable output paths
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
message( FATAL_ERROR "Must specify CMAKE_BUILD_TYPE, CMake will exit." )
|
||||
# -----------------------------------------------------------------------------
|
||||
# | PLATFORM/FEATURE AND IDE DETECTION |
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
set (BUILDING_ANDROID TRUE)
|
||||
endif ()
|
||||
if (WIN32)
|
||||
set (BUILDING_WIN32 TRUE)
|
||||
endif ()
|
||||
if ("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
|
||||
set (BUILDING_WIN64 TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set (BUILDING_DARWIN TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set (BUILDING_LINUX TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_GENERATOR} STREQUAL "Xcode")
|
||||
set (IN_XCODE TRUE)
|
||||
set(XCODE_EMIT_EFFECTIVE_PLATFORM_NAME ON)
|
||||
#set_target_properties (${STATIC_LIB_NAME}
|
||||
# PROPERTIES XCODE_ATTRIBUTE_MY_BUILD_ONLY_ACTIVE_ARCH YES)
|
||||
#set_target_properties (${STATIC_LIB_NAME}
|
||||
# PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "${MY_BUILD_ONLY_ACTIVE_ARCH})
|
||||
endif ()
|
||||
if (BUILDING_WIN32 OR BUILDING_WIN64 OR MSVC)
|
||||
set (BUILDING_WIN TRUE)
|
||||
endif ()
|
||||
if (NOT BUILDING_ANDROID AND NOT IN_XCODE)
|
||||
set(SHOULD_BUILD_TESTS TRUE)
|
||||
endif ()
|
||||
if (BUILDING_WIN32 OR BUILDING_WIN64 OR MSVC)
|
||||
set (BUILDING_WIN TRUE)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set (CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin/debug)
|
||||
# -----------------------------------------------------------------------------
|
||||
# | BUILD TYPES |
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "debug")
|
||||
set (CMAKE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
endif()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set (CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin/release)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "release")
|
||||
set (CMAKE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
endif()
|
||||
|
||||
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
set (INTERMEDIATE_LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/intermediate)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -66,46 +77,19 @@ else ()
|
||||
set (DYNAMIC_LIB_OUTPUT_NAME ${PROJECT_NAME})
|
||||
endif ()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | PLATFORM/FEATURE AND IDE DETECTION |
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
set (BUILDING_ANDROID TRUE)
|
||||
endif ()
|
||||
if (WIN32)
|
||||
set (BUILDING_WIN32 TRUE)
|
||||
endif ()
|
||||
if ("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
|
||||
set (BUILDING_WIN64 TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set (BUILDING_DARWIN TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set (BUILDING_LINUX TRUE)
|
||||
endif ()
|
||||
if (${CMAKE_GENERATOR} STREQUAL "Xcode")
|
||||
set (IN_XCODE TRUE)
|
||||
set(XCODE_EMIT_EFFECTIVE_PLATFORM_NAME ON)
|
||||
#set_target_properties (${STATIC_LIB_NAME} PROPERTIES XCODE_ATTRIBUTE_MY_BUILD_ONLY_ACTIVE_ARCH YES)
|
||||
#set_target_properties (${STATIC_LIB_NAME} PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "${MY_BUILD_ONLY_ACTIVE_ARCH})
|
||||
endif ()
|
||||
if (BUILDING_WIN32 OR BUILDING_WIN64 OR MSVC)
|
||||
set (BUILDING_WIN TRUE)
|
||||
endif ()
|
||||
if (NOT BUILDING_ANDROID AND NOT IN_XCODE AND NOT BUILD_TESTS EQUAL 0)
|
||||
set(SHOULD_BUILD_TESTS TRUE)
|
||||
endif ()
|
||||
if (BUILDING_WIN32 OR BUILDING_WIN64 OR MSVC)
|
||||
set (BUILDING_WIN TRUE)
|
||||
endif ()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | FLAGS |
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
set (SILENCE "-Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-missing-field-initializers")
|
||||
set (SILENCE "-Wno-unused-parameter \
|
||||
-Wno-format \
|
||||
-Wno-tautological-constant-out-of-range-compare \
|
||||
-Wno-macro-redefined -Wno-parentheses-equality \
|
||||
-Wno-sign-compare \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-unused-variable \
|
||||
-Wno-missing-field-initializers")
|
||||
|
||||
set (LIBZT_FLAGS "-D_USING_LWIP_DEFINITIONS_=1 -DZT_SDK")
|
||||
set (ZTCORE_FLAGS "-DZT_USE_MINIUPNPC=1 -DZT_SOFTWARE_UPDATE_DEFAULT=0")
|
||||
|
||||
@@ -113,24 +97,29 @@ if (BUILDING_WIN)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNOMINMAX")
|
||||
else ()
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBZT_FLAGS} -fstack-protector")
|
||||
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${LIBZT_FLAGS} -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")
|
||||
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${LIBZT_FLAGS} -fstack-protector")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SILENCE} ${LIBZT_FLAGS} -O3 -Wall -Wextra -std=c++11")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SILENCE} ${LIBZT_FLAGS} -std=c++11 -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SILENCE} ${LIBZT_FLAGS} -O3 -std=c++11")
|
||||
set (CMAKE_C_FLAGS
|
||||
"${SILENCE} ${CMAKE_C_FLAGS} ${LIBZT_FLAGS} -fstack-protector")
|
||||
set (CMAKE_C_FLAGS_DEBUG
|
||||
"${CMAKE_C_FLAGS_DEBUG} ${LIBZT_FLAGS} -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")
|
||||
set (CMAKE_C_FLAGS_RELEASE
|
||||
"${SILENCE} ${CMAKE_C_FLAGS_RELEASE} ${LIBZT_FLAGS} -fstack-protector")
|
||||
set (CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} ${SILENCE} ${LIBZT_FLAGS} -O3 -Wall -Wextra -std=c++11")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} ${LIBZT_FLAGS} -std=c++11 -DLWIP_DEBUG=1 -DLIBZT_DEBUG=1")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE
|
||||
"${CMAKE_CXX_FLAGS_RELEASE} ${SILENCE} ${LIBZT_FLAGS} -O3 -std=c++11")
|
||||
endif ()
|
||||
|
||||
if (BUILDING_LINUX AND NOT BUILDING_ANDROID)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpthread")
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | JNI |
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if (NOT IN_XCODE)
|
||||
MESSAGE (STATUS "Looking for JNI")
|
||||
|
||||
if (BUILDING_WIN)
|
||||
@@ -170,6 +159,8 @@ if ((BUILDING_ANDROID OR JNI) AND JNI_FOUND)
|
||||
add_definitions (-DSDK_JNI=1)
|
||||
endif ()
|
||||
|
||||
endif () # NOT IN_XCODE
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | SOURCE FILE GLOBS |
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -223,6 +214,11 @@ file (GLOB lwipSrcGlob
|
||||
${LWIP_SRC_DIR}/core/ipv6/*.c)
|
||||
list(REMOVE_ITEM lwipSrcGlob ${LWIP_SRC_DIR}/netif/slipif.c)
|
||||
|
||||
# header globs for xcode frameworks
|
||||
file (GLOB frameworkPrivateHeaderGlob include/ZeroTier.h include/ZeroTierConstants.h)
|
||||
file (GLOB frameworkPublicHeaderGlob include/Xcode-Bridging-Header.h)
|
||||
file (GLOB frameworkHeaderGlob ${frameworkPublicHeaderGlob} ${frameworkPrivateHeaderGlob})
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | INCLUDES |
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -239,6 +235,33 @@ include_directories (${LWIP_SRC_DIR}/include)
|
||||
include_directories (${LWIP_PORT_DIR}/include)
|
||||
include_directories (${PROJ_DIR}/ext/concurrentqueue)
|
||||
|
||||
# TODO: Should separate this into its own ios.cmake file
|
||||
|
||||
if (IOS_FRAMEWORK)
|
||||
set(DEVROOT
|
||||
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer")
|
||||
if (IOS_ARM64)
|
||||
set (CMAKE_OSX_ARCHITECTURES arm64)
|
||||
set (SDKVER "11.4")
|
||||
endif ()
|
||||
if (IOS_ARMV7)
|
||||
# armv7 armv7s
|
||||
set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)")
|
||||
set (SDKVER "10.0")
|
||||
endif ()
|
||||
|
||||
set(SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk")
|
||||
if(EXISTS ${SDKROOT})
|
||||
set(CMAKE_OSX_SYSROOT "${SDKROOT}")
|
||||
else()
|
||||
message("Warning, iOS Base SDK path not found: " ${SDKROOT})
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (MACOS_FRAMEWORK)
|
||||
include_directories ("/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/")
|
||||
endif ()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# | OBJECT LIBRARIES (INTERMEDIATE) |
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -309,26 +332,50 @@ set_target_properties (lwip PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY ${INTERMEDIATE_LIBRARY_OUTPUT_PATH})
|
||||
|
||||
# libzt.a
|
||||
add_library (zt STATIC $<TARGET_OBJECTS:libzt_obj>
|
||||
add_library (${STATIC_LIB_NAME} STATIC $<TARGET_OBJECTS:libzt_obj>
|
||||
$<TARGET_OBJECTS:zto_obj>
|
||||
$<TARGET_OBJECTS:libnatpmp_obj>
|
||||
$<TARGET_OBJECTS:miniupnpc_obj>
|
||||
$<TARGET_OBJECTS:lwip_obj>)
|
||||
set_target_properties (zt PROPERTIES
|
||||
$<TARGET_OBJECTS:lwip_obj> ${libztSrcGlob})
|
||||
set_target_properties (${STATIC_LIB_NAME} PROPERTIES
|
||||
OUTPUT_NAME zt
|
||||
LIBRARY_OUTPUT_DIRECTORY ${INTERMEDIATE_LIBRARY_OUTPUT_PATH})
|
||||
|
||||
# libzt.so/dylib/dll
|
||||
add_library (zt-shared SHARED ${libztSrcGlob})
|
||||
add_library (${DYNAMIC_LIB_NAME} SHARED ${libztSrcGlob})
|
||||
message (STATUS ${libztSrcGlob})
|
||||
target_link_libraries (zt-shared lwip_pic zto_pic)
|
||||
set_target_properties (zt-shared PROPERTIES COMPILE_FLAGS "${SILENCE} -std=c++11 -DZT_SDK")
|
||||
set_target_properties (zt-shared PROPERTIES OUTPUT_NAME ${DYNAMIC_LIB_OUTPUT_NAME}
|
||||
target_link_libraries (${DYNAMIC_LIB_NAME} lwip_pic zto_pic)
|
||||
set_target_properties (${DYNAMIC_LIB_NAME} PROPERTIES COMPILE_FLAGS "${SILENCE} -std=c++11 -DZT_SDK")
|
||||
set_target_properties (${DYNAMIC_LIB_NAME} PROPERTIES OUTPUT_NAME ${DYNAMIC_LIB_OUTPUT_NAME}
|
||||
WINDOWS_EXPORT_ALL_SYMBOLS true)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
if (BUILDING_ANDROID)
|
||||
target_link_libraries (zt-shared android log)
|
||||
target_link_libraries (${DYNAMIC_LIB_NAME} android log)
|
||||
endif ()
|
||||
|
||||
# xcode framework
|
||||
if (IN_XCODE)
|
||||
include_directories (${frameworkHeaderGlob})
|
||||
|
||||
add_library(${XCODE_FRAMEWORK_NAME} STATIC
|
||||
$<TARGET_OBJECTS:libzt_obj>
|
||||
$<TARGET_OBJECTS:zto_obj>
|
||||
$<TARGET_OBJECTS:libnatpmp_obj>
|
||||
$<TARGET_OBJECTS:miniupnpc_obj>
|
||||
$<TARGET_OBJECTS:lwip_obj>
|
||||
${libztSrcGlob}
|
||||
${frameworkHeaderGlob})
|
||||
|
||||
set_target_properties(${XCODE_FRAMEWORK_NAME} PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION A
|
||||
DEFINES_MODULE TRUE
|
||||
MACOSX_FRAMEWORK_IDENTIFIER com.cmake.${XCODE_FRAMEWORK_NAME}
|
||||
MODULE_MAP "~/op/zt/libzt/libzt_experimental/ports/module.modulemap"
|
||||
PUBLIC_HEADER "${frameworkHeaderGlob}"
|
||||
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
|
||||
)
|
||||
endif ()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -338,20 +385,20 @@ endif ()
|
||||
if (SHOULD_BUILD_TESTS)
|
||||
# Minimal functional example
|
||||
#add_executable (example ${PROJ_DIR}/test/example.cpp)
|
||||
#target_link_libraries(example zt)
|
||||
#target_link_libraries(example ${STATIC_LIB_NAME})
|
||||
|
||||
# API test
|
||||
#add_executable (apitest ${PROJ_DIR}/test/apitest.cpp)
|
||||
#target_link_libraries(apitest zt)
|
||||
#target_link_libraries(apitest ${STATIC_LIB_NAME})
|
||||
|
||||
# Selftest
|
||||
#add_executable (selftest ${PROJ_DIR}/test/selftest.cpp)
|
||||
#target_link_libraries(selftest zt)
|
||||
#target_link_libraries(selftest ${STATIC_LIB_NAME})
|
||||
#set_target_properties (selftest PROPERTIES COMPILE_FLAGS "-D__SELFTEST__")
|
||||
|
||||
# client/server performance test
|
||||
#add_executable (client ${PROJ_DIR}/test/client.cpp)
|
||||
#target_link_libraries(client zt)
|
||||
#target_link_libraries(client ${STATIC_LIB_NAME})
|
||||
#add_executable (server ${PROJ_DIR}/test/server.cpp)
|
||||
#target_link_libraries(server zt)
|
||||
#target_link_libraries(server ${STATIC_LIB_NAME})
|
||||
endif ()
|
||||
94
Makefile
94
Makefile
@@ -1,29 +1,3 @@
|
||||
#
|
||||
# ZeroTier SDK - Network Virtualization Everywhere
|
||||
# Copyright (C) 2011-2019 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.
|
||||
#
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
DIST_BUILD_SCRIPT := ports\dist.bat
|
||||
CLEAN_SCRIPT := ports\clean.bat
|
||||
@@ -33,8 +7,6 @@ CLEAN_SCRIPT := ./ports/clean.sh
|
||||
PACKAGE_SCRIPT := ./ports/package.sh
|
||||
endif
|
||||
|
||||
CONCURRENT_BUILD_JOBS=#-j 2
|
||||
|
||||
# Patch submodules
|
||||
patch:
|
||||
-git -C ext/lwip apply ../lwip.patch
|
||||
@@ -43,28 +15,56 @@ patch:
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm -rf bin staging generated dist
|
||||
-rm -rf tmp lib bin products
|
||||
-find ports -name ".externalNativeBuild" -exec rm -r "{}" \;
|
||||
-rm -f *.o *.s *.exp *.lib *.core core
|
||||
find . -type f \( -name '*.o' -o -name '*.o.d' -o -name \
|
||||
'*.out' -o -name '*.log' -o -name '*.dSYM' -o -name '*.class' \) -delete
|
||||
|
||||
all: debug release
|
||||
# Use CMake generators to build projects from CMakeLists.txt
|
||||
projects:
|
||||
$(DIST_BUILD_SCRIPT) generate_projects
|
||||
|
||||
release:
|
||||
-mkdir generated
|
||||
cmake -H. -Bgenerated/release -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build generated/release $(CONCURRENT_BUILD_JOBS)
|
||||
# Android
|
||||
android_debug:
|
||||
$(DIST_BUILD_SCRIPT) android "debug"
|
||||
android_release:
|
||||
$(DIST_BUILD_SCRIPT) android "release"
|
||||
android_clean:
|
||||
$(DIST_BUILD_SCRIPT) android "clean"
|
||||
android: android_debug android_release
|
||||
|
||||
# macOS
|
||||
macos_debug:
|
||||
$(DIST_BUILD_SCRIPT) macos "debug"
|
||||
macos_release:
|
||||
$(DIST_BUILD_SCRIPT) macos "release"
|
||||
macos: macos_debug macos_release
|
||||
|
||||
debug:
|
||||
-mkdir generated
|
||||
cmake -H. -Bgenerated/debug -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build generated/debug $(CONCURRENT_BUILD_JOBS)
|
||||
# iOS
|
||||
ios_debug:
|
||||
$(DIST_BUILD_SCRIPT) ios "debug"
|
||||
ios_release:
|
||||
$(DIST_BUILD_SCRIPT) ios "release"
|
||||
ios: ios_debug ios_release
|
||||
|
||||
# dist:
|
||||
# Build and package everything
|
||||
# This command shall be run twice:
|
||||
# (1) Generates projects
|
||||
# <perform any required modifications>
|
||||
# (2) Build products and package everything
|
||||
.PHONY: dist
|
||||
dist: patch
|
||||
$(DIST_BUILD_SCRIPT)
|
||||
# Host
|
||||
host_release:
|
||||
$(DIST_BUILD_SCRIPT) host "release"
|
||||
host_debug:
|
||||
$(DIST_BUILD_SCRIPT) host "debug"
|
||||
host_clean:
|
||||
$(DIST_BUILD_SCRIPT) host "clean"
|
||||
host_jar_debug:
|
||||
$(DIST_BUILD_SCRIPT) host_jar "debug"
|
||||
host_jar_release:
|
||||
$(DIST_BUILD_SCRIPT) host_jar "release"
|
||||
host_jar: host_jar_debug host_jar_release
|
||||
host: host_debug host_release host_jar
|
||||
|
||||
# all
|
||||
all: host macos ios android
|
||||
|
||||
# dist
|
||||
dist:
|
||||
$(DIST_BUILD_SCRIPT) dist
|
||||
@@ -1,12 +1,3 @@
|
||||
This license file applies to everything in this repository except that which
|
||||
is explicitly annotated as being written by other authors, i.e. the Boost
|
||||
queue (included in the benchmarks for comparison), Intel's TBB library (ditto),
|
||||
the CDSChecker tool (used for verification), the Relacy model checker (ditto),
|
||||
and Jeff Preshing's semaphore implementation (used in the blocking queue) which
|
||||
has a zlib license (embedded in blockingconcurrentqueue.h).
|
||||
|
||||
---
|
||||
|
||||
Simplified BSD License:
|
||||
|
||||
Copyright (c) 2013-2016, Cameron Desrochers.
|
||||
@@ -30,32 +21,3 @@ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTE
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
---
|
||||
|
||||
I have also chosen to dual-license under the Boost Software License as an alternative to
|
||||
the Simplified BSD license above:
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#define LIBZT_BRIDGING_HEADER_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include "libzt.h"
|
||||
#include "ZeroTier.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Service Controls //
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
#ifndef LIBZT_H
|
||||
#define LIBZT_H
|
||||
|
||||
#include "lwipopts.h"
|
||||
#include "ZeroTierConstants.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef ADD_EXPORTS
|
||||
@@ -47,17 +49,23 @@
|
||||
#define ZTCALL
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__ANDROID__)
|
||||
typedef unsigned int socklen_t;
|
||||
//#include <sys/socket.h>
|
||||
#else
|
||||
typedef int socklen_t;
|
||||
//#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include "TargetConditionals.h"
|
||||
//#if TARGET_OS_IPHONE
|
||||
//#ifndef sockaddr_storage
|
||||
#include <sys/socket.h>
|
||||
//#endif
|
||||
//#endif
|
||||
// TARGET_OS_MAC
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <WinSock2.h>
|
||||
#include <stdint.h>
|
||||
@@ -65,18 +73,12 @@ typedef int socklen_t;
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifdef _USING_LWIP_DEFINITIONS_
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <BaseTsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
|
||||
namespace ZeroTier {
|
||||
//namespace ZeroTier {
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -84,213 +86,6 @@ extern "C" {
|
||||
|
||||
// Custom errno to prevent conflicts with platform's own errno
|
||||
extern int zts_errno;
|
||||
typedef int zts_err_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The system port upon which ZT traffic is sent and received
|
||||
*/
|
||||
#define ZTS_DEFAULT_PORT 9994
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API error codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Everything is ok
|
||||
#define ZTS_ERR_OK 0
|
||||
// A argument provided by the user application is invalid (e.g. out of range, NULL, etc)
|
||||
#define ZTS_ERR_INVALID_ARG -1
|
||||
// The service isn't initialized or is for some reason currently unavailable. Try again.
|
||||
#define ZTS_ERR_SERVICE -2
|
||||
// For some reason this API operation is not permitted or doesn't make sense at this time.
|
||||
#define ZTS_ERR_INVALID_OP -3
|
||||
// The call succeeded, but no object or relevant result was available
|
||||
#define ZTS_ERR_NO_RESULT -4
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API event codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ZTS_EVENT_NONE -1
|
||||
#define ZTS_EVENT_NODE_UP 0
|
||||
// Standard node events
|
||||
#define ZTS_EVENT_NODE_OFFLINE 1
|
||||
#define ZTS_EVENT_NODE_ONLINE 2
|
||||
#define ZTS_EVENT_NODE_DOWN 3
|
||||
#define ZTS_EVENT_NODE_IDENTITY_COLLISION 4
|
||||
#define ZTS_EVENT_NODE_UNRECOVERABLE_ERROR 16
|
||||
#define ZTS_EVENT_NODE_NORMAL_TERMINATION 17
|
||||
// Network events
|
||||
#define ZTS_EVENT_NETWORK_NOT_FOUND 32
|
||||
#define ZTS_EVENT_NETWORK_CLIENT_TOO_OLD 33
|
||||
#define ZTS_EVENT_NETWORK_REQUESTING_CONFIG 34
|
||||
#define ZTS_EVENT_NETWORK_OK 35
|
||||
#define ZTS_EVENT_NETWORK_ACCESS_DENIED 36
|
||||
#define ZTS_EVENT_NETWORK_READY_IP4 37
|
||||
#define ZTS_EVENT_NETWORK_READY_IP6 38
|
||||
#define ZTS_EVENT_NETWORK_READY_IP4_IP6 39
|
||||
#define ZTS_EVENT_NETWORK_DOWN 40
|
||||
// Network Stack events
|
||||
#define ZTS_EVENT_STACK_UP 48
|
||||
#define ZTS_EVENT_STACK_DOWN 49
|
||||
// lwIP netif events
|
||||
#define ZTS_EVENT_NETIF_UP 64
|
||||
#define ZTS_EVENT_NETIF_DOWN 65
|
||||
#define ZTS_EVENT_NETIF_REMOVED 66
|
||||
#define ZTS_EVENT_NETIF_LINK_UP 67
|
||||
#define ZTS_EVENT_NETIF_LINK_DOWN 68
|
||||
// Peer events
|
||||
#define ZTS_EVENT_PEER_P2P 96
|
||||
#define ZTS_EVENT_PEER_RELAY 97
|
||||
#define ZTS_EVENT_PEER_UNREACHABLE 98
|
||||
// Path events
|
||||
#define ZTS_EVENT_PATH_DISCOVERED 112
|
||||
#define ZTS_EVENT_PATH_ALIVE 113
|
||||
#define ZTS_EVENT_PATH_DEAD 114
|
||||
// Route events
|
||||
#define ZTS_EVENT_ROUTE_ADDED 128
|
||||
#define ZTS_EVENT_ROUTE_REMOVED 129
|
||||
// Address events
|
||||
#define ZTS_EVENT_ADDR_ADDED_IP4 144
|
||||
#define ZTS_EVENT_ADDR_REMOVED_IP4 145
|
||||
#define ZTS_EVENT_ADDR_ADDED_IP6 146
|
||||
#define ZTS_EVENT_ADDR_REMOVED_IP6 147
|
||||
|
||||
// Macros for legacy behaviour
|
||||
#define NODE_EVENT_TYPE(code) code >= ZTS_EVENT_NODE_UP && code <= ZTS_EVENT_NODE_NORMAL_TERMINATION
|
||||
#define NETWORK_EVENT_TYPE(code) code >= ZTS_EVENT_NETWORK_NOT_FOUND && code <= ZTS_EVENT_NETWORK_DOWN
|
||||
#define STACK_EVENT_TYPE(code) code >= ZTS_EVENT_STACK_UP && code <= ZTS_EVENT_STACK_DOWN
|
||||
#define NETIF_EVENT_TYPE(code) code >= ZTS_EVENT_NETIF_UP && code <= ZTS_EVENT_NETIF_LINK_DOWN
|
||||
#define PEER_EVENT_TYPE(code) code >= ZTS_EVENT_PEER_P2P && code <= ZTS_EVENT_PEER_UNREACHABLE
|
||||
#define PATH_EVENT_TYPE(code) code >= ZTS_EVENT_PATH_DISCOVERED && code <= ZTS_EVENT_PATH_DEAD
|
||||
#define ROUTE_EVENT_TYPE(code) code >= ZTS_EVENT_ROUTE_ADDED && code <= ZTS_EVENT_ROUTE_REMOVED
|
||||
#define ADDR_EVENT_TYPE(code) code >= ZTS_EVENT_ADDR_ADDED_IP4 && code <= ZTS_EVENT_ADDR_REMOVED_IP6
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Common definitions and structures for interacting with the ZT socket API //
|
||||
// This is a subset of lwip/sockets.h, lwip/arch.h, and lwip/inet.h //
|
||||
// //
|
||||
// These re-definitions exist here so that the user application's usage //
|
||||
// of the API is internally consistent with the underlying network stack. //
|
||||
// They have an attached prefix so that they can co-exist with the native //
|
||||
// platform's own definitions and structures. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Socket protocol types
|
||||
#define ZTS_SOCK_STREAM 0x0001
|
||||
#define ZTS_SOCK_DGRAM 0x0002
|
||||
#define ZTS_SOCK_RAW 0x0003
|
||||
// Socket family types
|
||||
#define ZTS_AF_UNSPEC 0x0000
|
||||
#define ZTS_AF_INET 0x0002
|
||||
#define ZTS_AF_INET6 0x000a
|
||||
#define ZTS_PF_INET ZTS_AF_INET
|
||||
#define ZTS_PF_INET6 ZTS_AF_INET6
|
||||
#define ZTS_PF_UNSPEC ZTS_AF_UNSPEC
|
||||
// Protocol command types
|
||||
#define ZTS_IPPROTO_IP 0x0000
|
||||
#define ZTS_IPPROTO_ICMP 0x0001
|
||||
#define ZTS_IPPROTO_TCP 0x0006
|
||||
#define ZTS_IPPROTO_UDP 0x0011
|
||||
#define ZTS_IPPROTO_IPV6 0x0029
|
||||
#define ZTS_IPPROTO_ICMPV6 0x003a
|
||||
#define ZTS_IPPROTO_UDPLITE 0x0088
|
||||
#define ZTS_IPPROTO_RAW 0x00ff
|
||||
// send() and recv() flags
|
||||
#define ZTS_MSG_PEEK 0x0001
|
||||
#define ZTS_MSG_WAITALL 0x0002 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_OOB 0x0004 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_DONTWAIT 0x0008
|
||||
#define ZTS_MSG_MORE 0x0010
|
||||
// fnctl() commands
|
||||
#define ZTS_F_GETFL 0x0003
|
||||
#define ZTS_F_SETFL 0x0004
|
||||
// fnctl() flags
|
||||
#define ZTS_O_NONBLOCK 0x0001
|
||||
#define ZTS_O_NDELAY 0x0001
|
||||
// Shutdown commands
|
||||
#define ZTS_SHUT_RD 0x0000
|
||||
#define ZTS_SHUT_WR 0x0001
|
||||
#define ZTS_SHUT_RDWR 0x0002
|
||||
// Socket level option number
|
||||
#define ZTS_SOL_SOCKET 0x0fff
|
||||
// Socket options
|
||||
#define ZTS_SO_DEBUG 0x0001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_ACCEPTCONN 0x0002
|
||||
#define ZTS_SO_REUSEADDR 0x0004
|
||||
#define ZTS_SO_KEEPALIVE 0x0008
|
||||
#define ZTS_SO_DONTROUTE 0x0010 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_BROADCAST 0x0020
|
||||
#define ZTS_SO_USELOOPBACK 0x0040 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_LINGER 0x0080
|
||||
#define ZTS_SO_DONTLINGER ((int)(~ZTS_SO_LINGER))
|
||||
#define ZTS_SO_OOBINLINE 0x0100 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_REUSEPORT 0x0200 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDBUF 0x1001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVBUF 0x1002
|
||||
#define ZTS_SO_SNDLOWAT 0x1003 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVLOWAT 0x1004 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDTIMEO 0x1005
|
||||
#define ZTS_SO_RCVTIMEO 0x1006
|
||||
#define ZTS_SO_ERROR 0x1007
|
||||
#define ZTS_SO_TYPE 0x1008
|
||||
#define ZTS_SO_CONTIMEO 0x1009
|
||||
#define ZTS_SO_NO_CHECK 0x100a
|
||||
// IPPROTO_IP options
|
||||
#define ZTS_IP_TOS 0x0001
|
||||
#define ZTS_IP_TTL 0x0002
|
||||
// IPPROTO_TCP options
|
||||
#define ZTS_TCP_NODELAY 0x0001
|
||||
#define ZTS_TCP_KEEPALIVE 0x0002
|
||||
#define ZTS_TCP_KEEPIDLE 0x0003
|
||||
#define ZTS_TCP_KEEPINTVL 0x0004
|
||||
#define ZTS_TCP_KEEPCNT 0x0005
|
||||
// IPPROTO_IPV6 options
|
||||
#define ZTS_IPV6_CHECKSUM 0x0007 // RFC3542
|
||||
#define ZTS_IPV6_V6ONLY 0x001b // RFC3493
|
||||
// Macro's for defining ioctl() command values
|
||||
#define ZTS_IOCPARM_MASK 0x7fU
|
||||
#define ZTS_IOC_VOID 0x20000000UL
|
||||
#define ZTS_IOC_OUT 0x40000000UL
|
||||
#define ZTS_IOC_IN 0x80000000UL
|
||||
#define ZTS_IOC_INOUT (ZTS_IOC_IN | ZTS_IOC_OUT)
|
||||
#define ZTS_IO(x,y) (ZTS_IOC_VOID | ((x)<<8)|(y))
|
||||
#define ZTS_IOR(x,y,t) (ZTS_IOC_OUT | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y))
|
||||
#define ZTS_IOW(x,y,t) (ZTS_IOC_IN | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y))
|
||||
// ioctl() commands
|
||||
#define ZTS_FIONREAD ZTS_IOR('f', 127, unsigned long)
|
||||
#define ZTS_FIONBIO ZTS_IOW('f', 126, unsigned long)
|
||||
|
||||
/* FD_SET used for lwip_select */
|
||||
|
||||
#ifndef ZTS_FD_SET
|
||||
#undef ZTS_FD_SETSIZE
|
||||
// Make FD_SETSIZE match NUM_SOCKETS in socket.c
|
||||
#define ZTS_FD_SETSIZE MEMP_NUM_NETCONN
|
||||
#define ZTS_FDSETSAFESET(n, code) do { \
|
||||
if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
|
||||
code; }} while(0)
|
||||
#define ZTS_FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
|
||||
(code) : 0)
|
||||
#define ZTS_FD_SET(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_CLR(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_ISSET(n,p) ZTS_FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
|
||||
|
||||
#elif LWIP_SOCKET_OFFSET
|
||||
#error LWIP_SOCKET_OFFSET does not work with external FD_SET!
|
||||
#elif ZTS_FD_SETSIZE < MEMP_NUM_NETCONN
|
||||
#error "external ZTS_FD_SETSIZE too small for number of sockets"
|
||||
#endif // FD_SET
|
||||
|
||||
#if defined(_USING_LWIP_DEFINITIONS_)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8_t;
|
||||
typedef int8_t s8_t;
|
||||
@@ -309,7 +104,7 @@ struct zts_in_addr {
|
||||
};
|
||||
|
||||
struct zts_in6_addr {
|
||||
union {
|
||||
union un {
|
||||
u32_t u32_addr[4];
|
||||
u8_t u8_addr[16];
|
||||
} un;
|
||||
@@ -384,33 +179,6 @@ typedef struct fd_set
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _USING_LWIP_DEFINITIONS_
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 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. Maybe 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
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Subset of: ZeroTierOne.h //
|
||||
// We redefine a few ZT structures here so that we don't need to drag the //
|
||||
@@ -499,16 +267,6 @@ struct zts_node_details
|
||||
*/
|
||||
struct zts_callback_msg
|
||||
{
|
||||
zts_callback_msg():
|
||||
eventCode(-1),
|
||||
node(NULL),
|
||||
network(NULL),
|
||||
netif(NULL),
|
||||
route(NULL),
|
||||
path(NULL),
|
||||
peer(NULL),
|
||||
addr(NULL) {}
|
||||
|
||||
/**
|
||||
* Event identifier
|
||||
*/
|
||||
@@ -712,7 +470,7 @@ struct zts_peer_details
|
||||
/**
|
||||
* Known network paths to peer
|
||||
*/
|
||||
zts_physical_path paths[ZT_MAX_PEER_NETWORK_PATHS];
|
||||
struct zts_physical_path paths[ZT_MAX_PEER_NETWORK_PATHS];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -720,7 +478,7 @@ struct zts_peer_details
|
||||
*/
|
||||
struct zts_peer_list
|
||||
{
|
||||
zts_peer_details *peers;
|
||||
struct zts_peer_details *peers;
|
||||
unsigned long peerCount;
|
||||
};
|
||||
|
||||
@@ -745,7 +503,7 @@ extern "C" {
|
||||
* @param userCallbackFunc User-specified callback for ZeroTier events
|
||||
* @return 0 if successful; or 1 if failed
|
||||
*/
|
||||
ZT_SOCKET_API int ZTCALL zts_start(const char *path, void (*userCallbackFunc)(struct zts_callback_msg*), int port = ZTS_DEFAULT_PORT);
|
||||
ZT_SOCKET_API int ZTCALL zts_start(const char *path, void (*userCallbackFunc)(struct zts_callback_msg*), int port);
|
||||
|
||||
/**
|
||||
* @brief Stops the ZeroTier service, brings down all virtual interfaces in order to stop all traffic processing.
|
||||
@@ -781,7 +539,7 @@ ZT_SOCKET_API int ZTCALL zts_core_running();
|
||||
* @usage Call this after zts_start(), zts_startjoin() and/or zts_join()
|
||||
* @return Number of networks joined by this node
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_get_num_joined_networks();
|
||||
ZT_SOCKET_API int ZTCALL zts_get_num_joined_networks();
|
||||
|
||||
/**
|
||||
* @brief Populates a structure with details for a given network
|
||||
@@ -791,7 +549,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_get_num_joined_networks();
|
||||
* @param nd Pointer to a zts_network_details structure to populate
|
||||
* @return ZTS_ERR_SERVICE if failed, 0 if otherwise
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_get_network_details(uint64_t nwid, struct zts_network_details *nd);
|
||||
ZT_SOCKET_API int ZTCALL zts_get_network_details(uint64_t nwid, struct zts_network_details *nd);
|
||||
|
||||
/**
|
||||
* @brief Populates an array of structures with details for any given number of networks
|
||||
@@ -802,7 +560,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_get_network_details(uint64_t nwid, struct zts
|
||||
* to reflect number of structures that were actually populated
|
||||
* @return ZTS_ERR_SERVICE if failed, 0 if otherwise
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_get_all_network_details(struct zts_network_details *nds, int *num);
|
||||
ZT_SOCKET_API int ZTCALL zts_get_all_network_details(struct zts_network_details *nds, int *num);
|
||||
|
||||
/**
|
||||
* @brief Join a network
|
||||
@@ -811,7 +569,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_get_all_network_details(struct zts_network_de
|
||||
* @param nwid A 16-digit hexidecimal virtual network ID
|
||||
* @return 0 if successful, -1 for any failure
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_join(const uint64_t nwid);
|
||||
ZT_SOCKET_API int ZTCALL zts_join(const uint64_t nwid);
|
||||
|
||||
/**
|
||||
* @brief Leave a network
|
||||
@@ -820,7 +578,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_join(const uint64_t nwid);
|
||||
* @param nwid A 16-digit hexidecimal virtual network ID
|
||||
* @return 0 if successful, -1 for any failure
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_leave(const uint64_t nwid);
|
||||
ZT_SOCKET_API int ZTCALL zts_leave(const uint64_t nwid);
|
||||
|
||||
|
||||
/**
|
||||
@@ -829,7 +587,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_leave(const uint64_t nwid);
|
||||
* @usage Call this from application thread. Only after zts_start() has succeeded
|
||||
* @return 0 if successful, -1 for any failure
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_leave_all();
|
||||
ZT_SOCKET_API int ZTCALL zts_leave_all();
|
||||
|
||||
/**
|
||||
* @brief Orbits a given moon (user-defined root server)
|
||||
@@ -839,7 +597,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_leave_all();
|
||||
* @param moonSeed A 16-digit hexidecimal seed ID
|
||||
* @return ZTS_ERR_OK if successful, ZTS_ERR_SERVICE, ZTS_ERR_INVALID_ARG, ZTS_ERR_INVALID_OP if otherwise
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_orbit(uint64_t moonWorldId, uint64_t moonSeed);
|
||||
ZT_SOCKET_API int ZTCALL zts_orbit(uint64_t moonWorldId, uint64_t moonSeed);
|
||||
|
||||
/**
|
||||
* @brief De-orbits a given moon (user-defined root server)
|
||||
@@ -848,7 +606,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_orbit(uint64_t moonWorldId, uint64_t moonSeed
|
||||
* @param moonWorldId A 16-digit hexidecimal world ID
|
||||
* @return ZTS_ERR_OK if successful, ZTS_ERR_SERVICE, ZTS_ERR_INVALID_ARG, ZTS_ERR_INVALID_OP if otherwise
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_deorbit(uint64_t moonWorldId);
|
||||
ZT_SOCKET_API int ZTCALL zts_deorbit(uint64_t moonWorldId);
|
||||
|
||||
/**
|
||||
* @brief Copies the configuration path used by ZeroTier into the provided buffer
|
||||
@@ -858,7 +616,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_deorbit(uint64_t moonWorldId);
|
||||
* @param len Length of destination buffer
|
||||
* @return 0 if no error, -1 if invalid argument was supplied
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_get_path(char *homePath, size_t *len);
|
||||
ZT_SOCKET_API int ZTCALL zts_get_path(char *homePath, size_t *len);
|
||||
|
||||
/**
|
||||
* @brief Returns the node ID of this instance
|
||||
@@ -940,7 +698,7 @@ ZT_SOCKET_API void ZTCALL zts_get_rfc4193_addr(
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_peer_count();
|
||||
ZT_SOCKET_API int zts_get_peer_count();
|
||||
|
||||
/**
|
||||
* @brief Return details of all peers
|
||||
@@ -951,7 +709,7 @@ ZT_SOCKET_API zts_err_t zts_get_peer_count();
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_peers(struct zts_peer_details *pds, int *num);
|
||||
ZT_SOCKET_API int zts_get_peers(struct zts_peer_details *pds, int *num);
|
||||
|
||||
/**
|
||||
* @brief Return details of a given peer.
|
||||
@@ -961,7 +719,7 @@ ZT_SOCKET_API zts_err_t zts_get_peers(struct zts_peer_details *pds, int *num);
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_peer(struct zts_peer_details *pds, uint64_t peerId);
|
||||
ZT_SOCKET_API int zts_get_peer(struct zts_peer_details *pds, uint64_t peerId);
|
||||
|
||||
/**
|
||||
* @brief Starts a ZeroTier service in the background
|
||||
@@ -995,7 +753,7 @@ int _zts_can_perform_service_operation();
|
||||
* @usage Can be called at any time
|
||||
* @return ZTS_EVENT_NODE_ONLINE, ZTS_EVENT_NODE_OFFLINE, or standard ZTS_ errors
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_node_status();
|
||||
ZT_SOCKET_API int zts_get_node_status();
|
||||
|
||||
/**
|
||||
* @brief Queries a the status of a network
|
||||
@@ -1003,7 +761,7 @@ ZT_SOCKET_API zts_err_t zts_get_node_status();
|
||||
* @usage Can be called at any time
|
||||
* @return ZTS_NETWORK_ values, or standard ZTS_ errors
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_network_status(uint64_t nwid);
|
||||
ZT_SOCKET_API int zts_get_network_status(uint64_t nwid);
|
||||
|
||||
/**
|
||||
* @brief Determines whether a peer is reachable via a P2P connection
|
||||
@@ -1013,7 +771,7 @@ ZT_SOCKET_API zts_err_t zts_get_network_status(uint64_t nwid);
|
||||
* @param peerId The ID of the peer to check
|
||||
* @return ZTS_PEER_ values, or standard ZTS_ errors
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t zts_get_peer_status(uint64_t peerId);
|
||||
ZT_SOCKET_API int zts_get_peer_status(uint64_t peerId);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Socket API //
|
||||
@@ -1033,7 +791,7 @@ ZT_SOCKET_API zts_err_t zts_get_peer_status(uint64_t peerId);
|
||||
* @param protocol Protocols supported on this socket
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_socket(int socket_family, int socket_type, int protocol);
|
||||
ZT_SOCKET_API int ZTCALL zts_socket(int socket_family, int socket_type, int protocol);
|
||||
|
||||
/**
|
||||
* @brief Connect a socket to a remote host
|
||||
@@ -1044,7 +802,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_socket(int socket_family, int socket_type, in
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
ZT_SOCKET_API int ZTCALL zts_connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* @brief Bind a socket to a virtual interface
|
||||
@@ -1055,7 +813,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_connect(int fd, const struct sockaddr *addr,
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
ZT_SOCKET_API int ZTCALL zts_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* @brief Listen for incoming connections
|
||||
@@ -1065,7 +823,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_bind(int fd, const struct sockaddr *addr, soc
|
||||
* @param backlog Number of backlogged connection allowed
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_listen(int fd, int backlog);
|
||||
ZT_SOCKET_API int ZTCALL zts_listen(int fd, int backlog);
|
||||
|
||||
/**
|
||||
* @brief Accept an incoming connection
|
||||
@@ -1076,7 +834,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_listen(int fd, int backlog);
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
ZT_SOCKET_API int ZTCALL zts_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Accept an incoming connection
|
||||
@@ -1089,7 +847,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_accept(int fd, struct sockaddr *addr, socklen
|
||||
* @return
|
||||
*/
|
||||
#if defined(__linux__)
|
||||
zts_err_t zts_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
|
||||
int zts_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -1103,7 +861,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_accept(int fd, struct sockaddr *addr, socklen
|
||||
* @param optlen Length of option value
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_setsockopt(
|
||||
ZT_SOCKET_API int ZTCALL zts_setsockopt(
|
||||
int fd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
/**
|
||||
@@ -1117,7 +875,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_setsockopt(
|
||||
* @param optlen Length of value
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_getsockopt(
|
||||
ZT_SOCKET_API int ZTCALL zts_getsockopt(
|
||||
int fd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
|
||||
/**
|
||||
@@ -1129,7 +887,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_getsockopt(
|
||||
* @param addrlen Length of name
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
ZT_SOCKET_API int ZTCALL zts_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Get the peer name for the remote end of a connected socket
|
||||
@@ -1140,7 +898,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_getsockname(int fd, struct sockaddr *addr, so
|
||||
* @param addrlen Length of name
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
ZT_SOCKET_API int ZTCALL zts_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Gets current hostname
|
||||
@@ -1150,7 +908,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_getpeername(int fd, struct sockaddr *addr, so
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_gethostname(char *name, size_t len);
|
||||
ZT_SOCKET_API int ZTCALL zts_gethostname(char *name, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Sets current hostname
|
||||
@@ -1160,7 +918,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_gethostname(char *name, size_t len);
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_sethostname(const char *name, size_t len);
|
||||
ZT_SOCKET_API int ZTCALL zts_sethostname(const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Return a pointer to an object with the following structure describing an internet host referenced by name
|
||||
@@ -1178,7 +936,7 @@ ZT_SOCKET_API struct hostent *zts_gethostbyname(const char *name);
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_close(int fd);
|
||||
ZT_SOCKET_API int ZTCALL zts_close(int fd);
|
||||
|
||||
/**
|
||||
* @brief Waits for one of a set of file descriptors to become ready to perform I/O.
|
||||
@@ -1207,7 +965,7 @@ int zts_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_select(
|
||||
ZT_SOCKET_API int ZTCALL zts_select(
|
||||
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
|
||||
/**
|
||||
@@ -1223,7 +981,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_select(
|
||||
#define F_SETFL 0
|
||||
#define O_NONBLOCK 0
|
||||
#endif
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_fcntl(int fd, int cmd, int flags);
|
||||
ZT_SOCKET_API int ZTCALL zts_fcntl(int fd, int cmd, int flags);
|
||||
|
||||
/**
|
||||
* @brief Control a device
|
||||
@@ -1234,7 +992,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_fcntl(int fd, int cmd, int flags);
|
||||
* @param argp
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_ioctl(int fd, unsigned long request, void *argp);
|
||||
ZT_SOCKET_API int ZTCALL zts_ioctl(int fd, unsigned long request, void *argp);
|
||||
|
||||
/**
|
||||
* @brief Send data to remote host
|
||||
@@ -1321,7 +1079,7 @@ ZT_SOCKET_API ssize_t ZTCALL zts_recvmsg(int fd, struct msghdr *msg,int flags);
|
||||
* @param len Length of data buffer to receive data
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_read(int fd, void *buf, size_t len);
|
||||
ZT_SOCKET_API int ZTCALL zts_read(int fd, void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Write bytes from buffer to socket
|
||||
@@ -1332,7 +1090,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_read(int fd, void *buf, size_t len);
|
||||
* @param len Length of buffer to write
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_write(int fd, const void *buf, size_t len);
|
||||
ZT_SOCKET_API int ZTCALL zts_write(int fd, const void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Shut down some aspect of a socket (read, write, or both)
|
||||
@@ -1342,7 +1100,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_write(int fd, const void *buf, size_t len);
|
||||
* @param how Which aspects of the socket should be shut down
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_shutdown(int fd, int how);
|
||||
ZT_SOCKET_API int ZTCALL zts_shutdown(int fd, int how);
|
||||
|
||||
/**
|
||||
* @brief Adds a DNS nameserver for the network stack to use
|
||||
@@ -1351,7 +1109,7 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_shutdown(int fd, int how);
|
||||
* @param addr Address for DNS nameserver
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_add_dns_nameserver(struct sockaddr *addr);
|
||||
ZT_SOCKET_API int ZTCALL zts_add_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
/**
|
||||
* @brief Removes a DNS nameserver
|
||||
@@ -1360,12 +1118,12 @@ ZT_SOCKET_API zts_err_t ZTCALL zts_add_dns_nameserver(struct sockaddr *addr);
|
||||
* @param addr Address for DNS nameserver
|
||||
* @return
|
||||
*/
|
||||
ZT_SOCKET_API zts_err_t ZTCALL zts_del_dns_nameserver(struct sockaddr *addr);
|
||||
ZT_SOCKET_API int ZTCALL zts_del_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
} // namespace ZeroTier
|
||||
//} // namespace ZeroTier
|
||||
|
||||
#endif // _H
|
||||
229
include/ZeroTierConstants.h
Normal file
229
include/ZeroTierConstants.h
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2019 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
|
||||
*
|
||||
* Common constants used throughout the SDK
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API error codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Everything is ok
|
||||
#define ZTS_ERR_OK 0
|
||||
// A argument provided by the user application is invalid (e.g. out of range, NULL, etc)
|
||||
#define ZTS_ERR_INVALID_ARG -1
|
||||
// The service isn't initialized or is for some reason currently unavailable. Try again.
|
||||
#define ZTS_ERR_SERVICE -2
|
||||
// For some reason this API operation is not permitted or doesn't make sense at this time.
|
||||
#define ZTS_ERR_INVALID_OP -3
|
||||
// The call succeeded, but no object or relevant result was available
|
||||
#define ZTS_ERR_NO_RESULT -4
|
||||
|
||||
/**
|
||||
* The system port upon which ZT traffic is sent and received
|
||||
*/
|
||||
#define ZTS_DEFAULT_PORT 9994
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API event codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ZTS_EVENT_NONE -1
|
||||
#define ZTS_EVENT_NODE_UP 0
|
||||
// Standard node events
|
||||
#define ZTS_EVENT_NODE_OFFLINE 1
|
||||
#define ZTS_EVENT_NODE_ONLINE 2
|
||||
#define ZTS_EVENT_NODE_DOWN 3
|
||||
#define ZTS_EVENT_NODE_IDENTITY_COLLISION 4
|
||||
#define ZTS_EVENT_NODE_UNRECOVERABLE_ERROR 16
|
||||
#define ZTS_EVENT_NODE_NORMAL_TERMINATION 17
|
||||
// Network events
|
||||
#define ZTS_EVENT_NETWORK_NOT_FOUND 32
|
||||
#define ZTS_EVENT_NETWORK_CLIENT_TOO_OLD 33
|
||||
#define ZTS_EVENT_NETWORK_REQUESTING_CONFIG 34
|
||||
#define ZTS_EVENT_NETWORK_OK 35
|
||||
#define ZTS_EVENT_NETWORK_ACCESS_DENIED 36
|
||||
#define ZTS_EVENT_NETWORK_READY_IP4 37
|
||||
#define ZTS_EVENT_NETWORK_READY_IP6 38
|
||||
#define ZTS_EVENT_NETWORK_READY_IP4_IP6 39
|
||||
#define ZTS_EVENT_NETWORK_DOWN 40
|
||||
// Network Stack events
|
||||
#define ZTS_EVENT_STACK_UP 48
|
||||
#define ZTS_EVENT_STACK_DOWN 49
|
||||
// lwIP netif events
|
||||
#define ZTS_EVENT_NETIF_UP 64
|
||||
#define ZTS_EVENT_NETIF_DOWN 65
|
||||
#define ZTS_EVENT_NETIF_REMOVED 66
|
||||
#define ZTS_EVENT_NETIF_LINK_UP 67
|
||||
#define ZTS_EVENT_NETIF_LINK_DOWN 68
|
||||
// Peer events
|
||||
#define ZTS_EVENT_PEER_P2P 96
|
||||
#define ZTS_EVENT_PEER_RELAY 97
|
||||
#define ZTS_EVENT_PEER_UNREACHABLE 98
|
||||
// Path events
|
||||
#define ZTS_EVENT_PATH_DISCOVERED 112
|
||||
#define ZTS_EVENT_PATH_ALIVE 113
|
||||
#define ZTS_EVENT_PATH_DEAD 114
|
||||
// Route events
|
||||
#define ZTS_EVENT_ROUTE_ADDED 128
|
||||
#define ZTS_EVENT_ROUTE_REMOVED 129
|
||||
// Address events
|
||||
#define ZTS_EVENT_ADDR_ADDED_IP4 144
|
||||
#define ZTS_EVENT_ADDR_REMOVED_IP4 145
|
||||
#define ZTS_EVENT_ADDR_ADDED_IP6 146
|
||||
#define ZTS_EVENT_ADDR_REMOVED_IP6 147
|
||||
|
||||
// Macros for legacy behaviour
|
||||
#define NODE_EVENT_TYPE(code) code >= ZTS_EVENT_NODE_UP && code <= ZTS_EVENT_NODE_NORMAL_TERMINATION
|
||||
#define NETWORK_EVENT_TYPE(code) code >= ZTS_EVENT_NETWORK_NOT_FOUND && code <= ZTS_EVENT_NETWORK_DOWN
|
||||
#define STACK_EVENT_TYPE(code) code >= ZTS_EVENT_STACK_UP && code <= ZTS_EVENT_STACK_DOWN
|
||||
#define NETIF_EVENT_TYPE(code) code >= ZTS_EVENT_NETIF_UP && code <= ZTS_EVENT_NETIF_LINK_DOWN
|
||||
#define PEER_EVENT_TYPE(code) code >= ZTS_EVENT_PEER_P2P && code <= ZTS_EVENT_PEER_UNREACHABLE
|
||||
#define PATH_EVENT_TYPE(code) code >= ZTS_EVENT_PATH_DISCOVERED && code <= ZTS_EVENT_PATH_DEAD
|
||||
#define ROUTE_EVENT_TYPE(code) code >= ZTS_EVENT_ROUTE_ADDED && code <= ZTS_EVENT_ROUTE_REMOVED
|
||||
#define ADDR_EVENT_TYPE(code) code >= ZTS_EVENT_ADDR_ADDED_IP4 && code <= ZTS_EVENT_ADDR_REMOVED_IP6
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Common definitions and structures for interacting with the ZT socket API //
|
||||
// This is a subset of lwip/sockets.h, lwip/arch.h, and lwip/inet.h //
|
||||
// //
|
||||
// These re-definitions exist here so that the user application's usage //
|
||||
// of the API is internally consistent with the underlying network stack. //
|
||||
// They have an attached prefix so that they can co-exist with the native //
|
||||
// platform's own definitions and structures. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Socket protocol types
|
||||
#define ZTS_SOCK_STREAM 0x0001
|
||||
#define ZTS_SOCK_DGRAM 0x0002
|
||||
#define ZTS_SOCK_RAW 0x0003
|
||||
// Socket family types
|
||||
#define ZTS_AF_UNSPEC 0x0000
|
||||
#define ZTS_AF_INET 0x0002
|
||||
#define ZTS_AF_INET6 0x000a
|
||||
#define ZTS_PF_INET ZTS_AF_INET
|
||||
#define ZTS_PF_INET6 ZTS_AF_INET6
|
||||
#define ZTS_PF_UNSPEC ZTS_AF_UNSPEC
|
||||
// Protocol command types
|
||||
#define ZTS_IPPROTO_IP 0x0000
|
||||
#define ZTS_IPPROTO_ICMP 0x0001
|
||||
#define ZTS_IPPROTO_TCP 0x0006
|
||||
#define ZTS_IPPROTO_UDP 0x0011
|
||||
#define ZTS_IPPROTO_IPV6 0x0029
|
||||
#define ZTS_IPPROTO_ICMPV6 0x003a
|
||||
#define ZTS_IPPROTO_UDPLITE 0x0088
|
||||
#define ZTS_IPPROTO_RAW 0x00ff
|
||||
// send() and recv() flags
|
||||
#define ZTS_MSG_PEEK 0x0001
|
||||
#define ZTS_MSG_WAITALL 0x0002 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_OOB 0x0004 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_DONTWAIT 0x0008
|
||||
#define ZTS_MSG_MORE 0x0010
|
||||
// fnctl() commands
|
||||
#define ZTS_F_GETFL 0x0003
|
||||
#define ZTS_F_SETFL 0x0004
|
||||
// fnctl() flags
|
||||
#define ZTS_O_NONBLOCK 0x0001
|
||||
#define ZTS_O_NDELAY 0x0001
|
||||
// Shutdown commands
|
||||
#define ZTS_SHUT_RD 0x0000
|
||||
#define ZTS_SHUT_WR 0x0001
|
||||
#define ZTS_SHUT_RDWR 0x0002
|
||||
// Socket level option number
|
||||
#define ZTS_SOL_SOCKET 0x0fff
|
||||
// Socket options
|
||||
#define ZTS_SO_DEBUG 0x0001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_ACCEPTCONN 0x0002
|
||||
#define ZTS_SO_REUSEADDR 0x0004
|
||||
#define ZTS_SO_KEEPALIVE 0x0008
|
||||
#define ZTS_SO_DONTROUTE 0x0010 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_BROADCAST 0x0020
|
||||
#define ZTS_SO_USELOOPBACK 0x0040 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_LINGER 0x0080
|
||||
#define ZTS_SO_DONTLINGER ((int)(~ZTS_SO_LINGER))
|
||||
#define ZTS_SO_OOBINLINE 0x0100 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_REUSEPORT 0x0200 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDBUF 0x1001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVBUF 0x1002
|
||||
#define ZTS_SO_SNDLOWAT 0x1003 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVLOWAT 0x1004 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDTIMEO 0x1005
|
||||
#define ZTS_SO_RCVTIMEO 0x1006
|
||||
#define ZTS_SO_ERROR 0x1007
|
||||
#define ZTS_SO_TYPE 0x1008
|
||||
#define ZTS_SO_CONTIMEO 0x1009
|
||||
#define ZTS_SO_NO_CHECK 0x100a
|
||||
// IPPROTO_IP options
|
||||
#define ZTS_IP_TOS 0x0001
|
||||
#define ZTS_IP_TTL 0x0002
|
||||
// IPPROTO_TCP options
|
||||
#define ZTS_TCP_NODELAY 0x0001
|
||||
#define ZTS_TCP_KEEPALIVE 0x0002
|
||||
#define ZTS_TCP_KEEPIDLE 0x0003
|
||||
#define ZTS_TCP_KEEPINTVL 0x0004
|
||||
#define ZTS_TCP_KEEPCNT 0x0005
|
||||
// IPPROTO_IPV6 options
|
||||
#define ZTS_IPV6_CHECKSUM 0x0007 // RFC3542
|
||||
#define ZTS_IPV6_V6ONLY 0x001b // RFC3493
|
||||
// Macro's for defining ioctl() command values
|
||||
#define ZTS_IOCPARM_MASK 0x7fU
|
||||
#define ZTS_IOC_VOID 0x20000000UL
|
||||
#define ZTS_IOC_OUT 0x40000000UL
|
||||
#define ZTS_IOC_IN 0x80000000UL
|
||||
#define ZTS_IOC_INOUT (ZTS_IOC_IN | ZTS_IOC_OUT)
|
||||
#define ZTS_IO(x,y) (ZTS_IOC_VOID | ((x)<<8)|(y))
|
||||
#define ZTS_IOR(x,y,t) (ZTS_IOC_OUT | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y))
|
||||
#define ZTS_IOW(x,y,t) (ZTS_IOC_IN | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y))
|
||||
// ioctl() commands
|
||||
#define ZTS_FIONREAD ZTS_IOR('f', 127, unsigned long)
|
||||
#define ZTS_FIONBIO ZTS_IOW('f', 126, unsigned long)
|
||||
|
||||
/* FD_SET used for lwip_select */
|
||||
|
||||
#ifndef ZTS_FD_SET
|
||||
#undef ZTS_FD_SETSIZE
|
||||
// Make FD_SETSIZE match NUM_SOCKETS in socket.c
|
||||
#define ZTS_FD_SETSIZE MEMP_NUM_NETCONN
|
||||
#define ZTS_FDSETSAFESET(n, code) do { \
|
||||
if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
|
||||
code; }} while(0)
|
||||
#define ZTS_FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
|
||||
(code) : 0)
|
||||
#define ZTS_FD_SET(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_CLR(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_ISSET(n,p) ZTS_FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
||||
#define ZTS_FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
|
||||
|
||||
#elif LWIP_SOCKET_OFFSET
|
||||
#error LWIP_SOCKET_OFFSET does not work with external FD_SET!
|
||||
#elif ZTS_FD_SETSIZE < MEMP_NUM_NETCONN
|
||||
#error "external ZTS_FD_SETSIZE too small for number of sockets"
|
||||
#endif // FD_SET
|
||||
|
||||
//#if defined(_USING_LWIP_DEFINITIONS_)
|
||||
37
include/net/ROUTE_H-LICENSE
Normal file
37
include/net/ROUTE_H-LICENSE
Normal file
@@ -0,0 +1,37 @@
|
||||
License for: include/net/route.h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)route.h 8.3 (Berkeley) 4/19/94
|
||||
* $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $
|
||||
*/
|
||||
29
include/net/ROUTE_H-LICENSE.APSL
Normal file
29
include/net/ROUTE_H-LICENSE.APSL
Normal file
@@ -0,0 +1,29 @@
|
||||
License for: include/net/route.h
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. The rights granted to you under the License
|
||||
* may not be used to create, or enable the creation or redistribution of,
|
||||
* unlawful or unlicensed copies of an Apple operating system, or to
|
||||
* circumvent, violate, or enable the circumvention or violation of, any
|
||||
* terms of an Apple operating system software license agreement.
|
||||
*
|
||||
* Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
|
||||
*/
|
||||
257
include/net/route.h
Normal file
257
include/net/route.h
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2017 Apple Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. The rights granted to you under the License
|
||||
* may not be used to create, or enable the creation or redistribution of,
|
||||
* unlawful or unlicensed copies of an Apple operating system, or to
|
||||
* circumvent, violate, or enable the circumvention or violation of, any
|
||||
* terms of an Apple operating system software license agreement.
|
||||
*
|
||||
* Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)route.h 8.3 (Berkeley) 4/19/94
|
||||
* $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NET_ROUTE_H_
|
||||
#define _NET_ROUTE_H_
|
||||
#include <sys/appleapiopts.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/*
|
||||
* These numbers are used by reliable protocols for determining
|
||||
* retransmission behavior and are included in the routing structure.
|
||||
*/
|
||||
struct rt_metrics {
|
||||
u_int32_t rmx_locks; /* Kernel leaves these values alone */
|
||||
u_int32_t rmx_mtu; /* MTU for this path */
|
||||
u_int32_t rmx_hopcount; /* max hops expected */
|
||||
int32_t rmx_expire; /* lifetime for route, e.g. redirect */
|
||||
u_int32_t rmx_recvpipe; /* inbound delay-bandwidth product */
|
||||
u_int32_t rmx_sendpipe; /* outbound delay-bandwidth product */
|
||||
u_int32_t rmx_ssthresh; /* outbound gateway buffer limit */
|
||||
u_int32_t rmx_rtt; /* estimated round trip time */
|
||||
u_int32_t rmx_rttvar; /* estimated rtt variance */
|
||||
u_int32_t rmx_pksent; /* packets sent using this route */
|
||||
u_int32_t rmx_state; /* route state */
|
||||
u_int32_t rmx_filler[3]; /* will be used for T/TCP later */
|
||||
};
|
||||
|
||||
/*
|
||||
* rmx_rtt and rmx_rttvar are stored as microseconds;
|
||||
*/
|
||||
#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
|
||||
|
||||
|
||||
|
||||
#define RTF_UP 0x1 /* route usable */
|
||||
#define RTF_GATEWAY 0x2 /* destination is a gateway */
|
||||
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||
#define RTF_REJECT 0x8 /* host or net unreachable */
|
||||
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
|
||||
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
|
||||
#define RTF_DONE 0x40 /* message confirmed */
|
||||
#define RTF_DELCLONE 0x80 /* delete cloned route */
|
||||
#define RTF_CLONING 0x100 /* generate new routes on use */
|
||||
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
|
||||
#define RTF_LLINFO 0x400 /* DEPRECATED - exists ONLY for backward
|
||||
compatibility */
|
||||
#define RTF_LLDATA 0x400 /* used by apps to add/del L2 entries */
|
||||
#define RTF_STATIC 0x800 /* manually added */
|
||||
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
|
||||
#define RTF_NOIFREF 0x2000 /* not eligible for RTF_IFREF */
|
||||
#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
|
||||
#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
|
||||
|
||||
#define RTF_PRCLONING 0x10000 /* protocol requires cloning */
|
||||
#define RTF_WASCLONED 0x20000 /* route generated through cloning */
|
||||
#define RTF_PROTO3 0x40000 /* protocol specific routing flag */
|
||||
/* 0x80000 unused */
|
||||
#define RTF_PINNED 0x100000 /* future use */
|
||||
#define RTF_LOCAL 0x200000 /* route represents a local address */
|
||||
#define RTF_BROADCAST 0x400000 /* route represents a bcast address */
|
||||
#define RTF_MULTICAST 0x800000 /* route represents a mcast address */
|
||||
#define RTF_IFSCOPE 0x1000000 /* has valid interface scope */
|
||||
#define RTF_CONDEMNED 0x2000000 /* defunct; no longer modifiable */
|
||||
#define RTF_IFREF 0x4000000 /* route holds a ref to interface */
|
||||
#define RTF_PROXY 0x8000000 /* proxying, no interface scope */
|
||||
#define RTF_ROUTER 0x10000000 /* host is a router */
|
||||
#define RTF_DEAD 0x20000000 /* Route entry is being freed */
|
||||
/* 0x40000000 and up unassigned */
|
||||
|
||||
#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */
|
||||
#define RTF_BITS \
|
||||
"\020\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE" \
|
||||
"\10DELCLONE\11CLONING\12XRESOLVE\13LLINFO\14STATIC\15BLACKHOLE" \
|
||||
"\16NOIFREF\17PROTO2\20PROTO1\21PRCLONING\22WASCLONED\23PROTO3" \
|
||||
"\25PINNED\26LOCAL\27BROADCAST\30MULTICAST\31IFSCOPE\32CONDEMNED" \
|
||||
"\33IFREF\34PROXY\35ROUTER"
|
||||
|
||||
#define IS_DIRECT_HOSTROUTE(rt) \
|
||||
(((rt)->rt_flags & (RTF_HOST | RTF_GATEWAY)) == RTF_HOST)
|
||||
/*
|
||||
* Routing statistics.
|
||||
*/
|
||||
struct rtstat {
|
||||
short rts_badredirect; /* bogus redirect calls */
|
||||
short rts_dynamic; /* routes created by redirects */
|
||||
short rts_newgateway; /* routes modified by redirects */
|
||||
short rts_unreach; /* lookups which failed */
|
||||
short rts_wildcard; /* lookups satisfied by a wildcard */
|
||||
short rts_badrtgwroute; /* route to gateway is not direct */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structures for routing messages.
|
||||
*/
|
||||
struct rt_msghdr {
|
||||
u_short rtm_msglen; /* to skip over non-understood messages */
|
||||
u_char rtm_version; /* future binary compatibility */
|
||||
u_char rtm_type; /* message type */
|
||||
u_short rtm_index; /* index for associated ifp */
|
||||
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
|
||||
int rtm_addrs; /* bitmask identifying sockaddrs in msg */
|
||||
pid_t rtm_pid; /* identify sender */
|
||||
int rtm_seq; /* for sender to identify action */
|
||||
int rtm_errno; /* why failed */
|
||||
int rtm_use; /* from rtentry */
|
||||
u_int32_t rtm_inits; /* which metrics we are initializing */
|
||||
struct rt_metrics rtm_rmx; /* metrics themselves */
|
||||
};
|
||||
|
||||
struct rt_msghdr2 {
|
||||
u_short rtm_msglen; /* to skip over non-understood messages */
|
||||
u_char rtm_version; /* future binary compatibility */
|
||||
u_char rtm_type; /* message type */
|
||||
u_short rtm_index; /* index for associated ifp */
|
||||
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
|
||||
int rtm_addrs; /* bitmask identifying sockaddrs in msg */
|
||||
int32_t rtm_refcnt; /* reference count */
|
||||
int rtm_parentflags; /* flags of the parent route */
|
||||
int rtm_reserved; /* reserved field set to 0 */
|
||||
int rtm_use; /* from rtentry */
|
||||
u_int32_t rtm_inits; /* which metrics we are initializing */
|
||||
struct rt_metrics rtm_rmx; /* metrics themselves */
|
||||
};
|
||||
|
||||
|
||||
#define RTM_VERSION 5 /* Up the ante and ignore older versions */
|
||||
|
||||
/*
|
||||
* Message types.
|
||||
*/
|
||||
#define RTM_ADD 0x1 /* Add Route */
|
||||
#define RTM_DELETE 0x2 /* Delete Route */
|
||||
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
|
||||
#define RTM_GET 0x4 /* Report Metrics */
|
||||
#define RTM_LOSING 0x5 /* RTM_LOSING is no longer generated by xnu
|
||||
and is deprecated */
|
||||
#define RTM_REDIRECT 0x6 /* Told to use different route */
|
||||
#define RTM_MISS 0x7 /* Lookup failed on this address */
|
||||
#define RTM_LOCK 0x8 /* fix specified metrics */
|
||||
#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
|
||||
#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
|
||||
#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
|
||||
#define RTM_NEWADDR 0xc /* address being added to iface */
|
||||
#define RTM_DELADDR 0xd /* address being removed from iface */
|
||||
#define RTM_IFINFO 0xe /* iface going up/down etc. */
|
||||
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
|
||||
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
|
||||
#define RTM_IFINFO2 0x12 /* */
|
||||
#define RTM_NEWMADDR2 0x13 /* */
|
||||
#define RTM_GET2 0x14 /* */
|
||||
|
||||
/*
|
||||
* Bitmask values for rtm_inits and rmx_locks.
|
||||
*/
|
||||
#define RTV_MTU 0x1 /* init or lock _mtu */
|
||||
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
|
||||
#define RTV_EXPIRE 0x4 /* init or lock _expire */
|
||||
#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
|
||||
#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
|
||||
#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
|
||||
#define RTV_RTT 0x40 /* init or lock _rtt */
|
||||
#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
|
||||
|
||||
/*
|
||||
* Bitmask values for rtm_addrs.
|
||||
*/
|
||||
#define RTA_DST 0x1 /* destination sockaddr present */
|
||||
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
|
||||
#define RTA_NETMASK 0x4 /* netmask sockaddr present */
|
||||
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
|
||||
#define RTA_IFP 0x10 /* interface name sockaddr present */
|
||||
#define RTA_IFA 0x20 /* interface addr sockaddr present */
|
||||
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
|
||||
#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
|
||||
/*
|
||||
* Index offsets for sockaddr array for alternate internal encoding.
|
||||
*/
|
||||
#define RTAX_DST 0 /* destination sockaddr present */
|
||||
#define RTAX_GATEWAY 1 /* gateway sockaddr present */
|
||||
#define RTAX_NETMASK 2 /* netmask sockaddr present */
|
||||
#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
|
||||
#define RTAX_IFP 4 /* interface name sockaddr present */
|
||||
#define RTAX_IFA 5 /* interface addr sockaddr present */
|
||||
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
|
||||
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
#define RTAX_MAX 8 /* size of array to allocate */
|
||||
|
||||
struct rt_addrinfo {
|
||||
int rti_addrs;
|
||||
struct sockaddr *rti_info[RTAX_MAX];
|
||||
};
|
||||
|
||||
|
||||
#endif /* _NET_ROUTE_H_ */
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -rf bin build products tmp
|
||||
rm -f *.o *.s *.exp *.lib .depend* *.core core
|
||||
rm -rf .depend
|
||||
find . -type f \( -name '*.o' -o -name '*.o.d' -o -name \
|
||||
'*.out' -o -name '*.log' -o -name '*.dSYM' -o -name '*.class' \) -delete
|
||||
386
ports/dist.sh
386
ports/dist.sh
@@ -1,184 +1,258 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Call this script from the root project directory via `make dist`
|
||||
# - submodules will be recursively initialized and updated
|
||||
# - patches will be applied to submodules if needed
|
||||
# - this script will call CMake to generate library-building packages if necessary
|
||||
# - once projects have been generated, this script will use their tooling to build the libraries/packages
|
||||
# - when all products have been built and moved to `tmp`, they will be compressed and moved to `products`
|
||||
# This script works in conjunction with the Makefile and CMakeLists.txt. It is
|
||||
# intented to be called from the Makefile, it generates projects and builds
|
||||
# targets as specified in CMakeLists.txt. This script is also responsible for
|
||||
# packaging all of the resultant builds, licenses, and documentation.
|
||||
|
||||
BUILD_CONCURRENCY=
|
||||
#"-j 2"
|
||||
OSNAME=$(uname | tr '[A-Z]' '[a-z]')
|
||||
BUILD_CONCURRENCY=4
|
||||
PROJROOT=$(pwd)
|
||||
BUILD_PRODUCTS_DIR=$(pwd)/bin
|
||||
LIB_PRODUCTS_DIR=$BUILD_PRODUCTS_DIR/lib
|
||||
FINISHED_PRODUCTS_DIR=$(pwd)/products
|
||||
STAGING_DIR=$(pwd)/staging
|
||||
# Windows (previously built)
|
||||
WIN_PREBUILT_DIR=$PROJROOT/staging/win
|
||||
WIN_RELEASE_PRODUCTS_DIR=$WIN_PREBUILT_DIR/release
|
||||
WIN_DEBUG_PRODUCTS_DIR=$WIN_PREBUILT_DIR/debug
|
||||
WIN32_RELEASE_PRODUCTS_DIR=$WIN_RELEASE_PRODUCTS_DIR/win32
|
||||
WIN64_RELEASE_PRODUCTS_DIR=$WIN_RELEASE_PRODUCTS_DIR/win64
|
||||
WIN32_DEBUG_PRODUCTS_DIR=$WIN_DEBUG_PRODUCTS_DIR/win32
|
||||
WIN64_DEBUG_PRODUCTS_DIR=$WIN_DEBUG_PRODUCTS_DIR/win64
|
||||
# Linux
|
||||
LINUX_PROD_DIR=$PROJROOT/staging/linux
|
||||
# macOS
|
||||
MACOS_PROD_DIR=$PROJROOT/staging/macos
|
||||
MACOS_RELEASE_PROD_DIR=$MACOS_PROD_DIR/release
|
||||
MACOS_DEBUG_PROD_DIR=$MACOS_PROD_DIR/debug
|
||||
# iOS
|
||||
IOS_PROD_DIR=$PROJROOT/staging/ios
|
||||
# Android
|
||||
ANDROID_PROJ_DIR=$(pwd)/"ports/android"
|
||||
ANDROID_ARCHIVE_FILENAME="zt.aar"
|
||||
# Xcode
|
||||
XCODE_IOS_PROJ_DIR=$(pwd)/"ports/xcode_ios"
|
||||
XCODE_MACOS_PROJ_DIR=$(pwd)/"ports/xcode_macos"
|
||||
BUILD_TMP=$(pwd)/tmp
|
||||
ANDROID_PROJ_DIR=$(pwd)/ports/android
|
||||
XCODE_IOS_ARM64_PROJ_DIR=$(pwd)/ports/xcode_ios-arm64
|
||||
#XCODE_IOS_ARMV7_PROJ_DIR=$(pwd)/ports/xcode_ios-armv7
|
||||
XCODE_MACOS_PROJ_DIR=$(pwd)/ports/xcode_macos
|
||||
|
||||
mkdir $FINISHED_PRODUCTS_DIR
|
||||
mkdir $STAGING_DIR
|
||||
|
||||
# Check that projects exist, generate them and exit if they don't exist
|
||||
generate_projects_if_necessary()
|
||||
# Generates projects if needed
|
||||
generate_projects()
|
||||
{
|
||||
if [[ ! $OSNAME = *"darwin"* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
if [[ $OSNAME = *"darwin"* ]]; then
|
||||
# iOS
|
||||
if [ ! -d "$XCODE_IOS_PROJ_DIR" ]; then
|
||||
echo "BUILDING: iOS project"
|
||||
should_exit=1
|
||||
mkdir -p $XCODE_IOS_PROJ_DIR
|
||||
cd $XCODE_IOS_PROJ_DIR
|
||||
cmake -G Xcode ../../
|
||||
# Bug in CMake requires us to manually replace architecture strings in project file
|
||||
sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' $PROJNAME.xcodeproj/project.pbxproj
|
||||
# iOS (SDK 11+, 64-bit only, arm64)
|
||||
if [ ! -d "$XCODE_IOS_ARM64_PROJ_DIR" ]; then
|
||||
mkdir -p $XCODE_IOS_ARM64_PROJ_DIR
|
||||
cd $XCODE_IOS_ARM64_PROJ_DIR
|
||||
cmake -G Xcode ../../ -DIOS_FRAMEWORK=1 -DIOS_ARM64=1
|
||||
# Manually replace arch strings in project file
|
||||
sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj
|
||||
cd -
|
||||
fi
|
||||
# iOS (SDK <11, 32-bit only, armv7, armv7s)
|
||||
#if [ ! -d "$XCODE_IOS_ARMV7_PROJ_DIR" ]; then
|
||||
# mkdir -p $XCODE_IOS_ARMV7_PROJ_DIR
|
||||
# cd $XCODE_IOS_ARMV7_PROJ_DIR
|
||||
# cmake -G Xcode ../../ -DIOS_FRAMEWORK=1 -DIOS_ARMV7=1
|
||||
# Manually replace arch strings in project file
|
||||
# sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj
|
||||
# cd -
|
||||
#fi
|
||||
# macOS
|
||||
if [ ! -d "$XCODE_MACOS_PROJ_DIR" ]; then
|
||||
echo "BUILDING: macOS project"
|
||||
should_exit=1
|
||||
mkdir -p $XCODE_MACOS_PROJ_DIR
|
||||
cd $XCODE_MACOS_PROJ_DIR
|
||||
cmake -G Xcode ../../
|
||||
cmake -G Xcode ../../ -DMACOS_FRAMEWORK=1
|
||||
cd -
|
||||
fi
|
||||
# android?
|
||||
if [[ $should_exit = 1 ]]; then
|
||||
echo "Generated projects. Perform necessary modifications and then re-run this script"
|
||||
echo "Please place previously built windows binaries in $WIN_PREBUILT_DIR before running again."
|
||||
exit 0
|
||||
else
|
||||
echo "Projects detected, going to build stage next"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
build_all_products()
|
||||
ios()
|
||||
{
|
||||
CONFIG=$1
|
||||
if [[ ! $OSNAME = *"darwin"* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
generate_projects # if needed
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
|
||||
|
||||
# Targets to build on and for darwin
|
||||
if [[ $OSNAME = *"darwin"* ]]; then
|
||||
# Xcode Frameworks --- Builds targets from a CMake-generated Xcode project
|
||||
if false; then
|
||||
if [[ $2 != *"JNI"* ]]; then
|
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR/$UPPERCASE_CONFIG
|
||||
# (iOS)
|
||||
echo "BUILDING: iOS"
|
||||
cd $XCODE_IOS_PROJ_DIR
|
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos"
|
||||
xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos"
|
||||
# 64-bit
|
||||
cd $XCODE_IOS_ARM64_PROJ_DIR
|
||||
# Framework
|
||||
xcodebuild -arch arm64 -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos"
|
||||
cd -
|
||||
CURR_ARCH="arm64" # spoof this architecture since HOSTTYPE is likely x86_64
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/ios-$CURR_ARCH
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
mv $CURR_BUILD_PRODUCTS_DIR/*.framework $CURR_TMP_PRODUCT_DIR
|
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR
|
||||
OUTPUT_DIR=$(pwd)/lib/$1/ios-arm64
|
||||
mkdir -p $OUTPUT_DIR
|
||||
rm -rf $OUTPUT_DIR/zt.framework # Remove prior to move to prevent error
|
||||
mv $XCODE_IOS_ARM64_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/* $OUTPUT_DIR
|
||||
|
||||
# (macOS)
|
||||
echo "BUILDING: macOS"
|
||||
cd $XCODE_MACOS_PROJ_DIR
|
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
xcodebuild -target zt-shared -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
cd -
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/macos-$(uname -m)
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
mv $CURR_BUILD_PRODUCTS_DIR/*.framework $CURR_TMP_PRODUCT_DIR
|
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR
|
||||
fi
|
||||
fi
|
||||
# Android Archive (AAR) --- Executes a Gradle task
|
||||
if true; then
|
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DSDK_JNI=1"
|
||||
CURR_ARCH="armeabi-v7a" # spoof this architecture since HOSTTYPE is likely x86_64
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/android-$CURR_ARCH
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
echo "BUILDING: AAR"
|
||||
cd $ANDROID_PROJ_DIR
|
||||
./gradlew assemble$UPPERCASE_CONFIG # e.g. assembleRelease
|
||||
mv $ANDROID_PROJ_DIR/app/build/outputs/aar/app-$CONFIG.aar $CURR_TMP_PRODUCT_DIR/$ANDROID_ARCHIVE_FILENAME
|
||||
cd -
|
||||
fi
|
||||
# Java Archive (JAR)
|
||||
if false; then
|
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR
|
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DJNI=1"
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/macos-$(uname -m)
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
echo "BUILDING: JAR"
|
||||
rm -rf $LIB_PRODUCTS_DIR # clean-lite
|
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DJNI=1 -DBUILD_TESTS=0"
|
||||
cmake --build build
|
||||
cd $PROJROOT/ports/java
|
||||
cp $CURR_BUILD_PRODUCTS_DIR/libzt.dylib .
|
||||
javac com/zerotier/libzt/*.java
|
||||
jar cf zt.jar libzt.dylib com/zerotier/libzt/*.class
|
||||
rm libzt.dylib
|
||||
mv zt.jar $CURR_TMP_PRODUCT_DIR
|
||||
cd -
|
||||
fi
|
||||
fi
|
||||
# Linux targets
|
||||
if [[ $OSNAME = *"linux"* ]]; then
|
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR
|
||||
# Ordinary libraries
|
||||
if true; then
|
||||
rm -rf $LIB_PRODUCTS_DIR
|
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DBUILD_TESTS=0"
|
||||
cmake --build build
|
||||
# -j $BUILD_CONCURRENCY
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/linux-$(uname -m)
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR
|
||||
fi
|
||||
# Java JAR file
|
||||
if true; then
|
||||
rm -rf $LIB_PRODUCTS_DIR
|
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DJNI=1 -DBUILD_TESTS=0"
|
||||
cmake --build build
|
||||
# -j $BUILD_CONCURRENCY
|
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/linux-$(uname -m)
|
||||
mkdir -p $CURR_TMP_PRODUCT_DIR
|
||||
cd $PROJROOT/ports/java
|
||||
cp $CURR_BUILD_PRODUCTS_DIR/libzt.so .
|
||||
javac com/zerotier/libzt/*.java
|
||||
jar cf zt.jar libzt.dylib com/zerotier/libzt/*.class
|
||||
rm libzt.dylib
|
||||
mv zt.jar $CURR_TMP_PRODUCT_DIR
|
||||
cd -
|
||||
fi
|
||||
fi
|
||||
# 32-bit
|
||||
#cd $XCODE_IOS_ARMV7_PROJ_DIR
|
||||
# Framework
|
||||
#xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos10.0"
|
||||
# Manually replace arch strings in project file
|
||||
#sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj
|
||||
#cd -
|
||||
#OUTPUT_DIR=$(pwd)/lib/$1/ios-armv7
|
||||
#mkdir -p $OUTPUT_DIR
|
||||
#rm -rf $OUTPUT_DIR/*
|
||||
#mv $XCODE_IOS_ARMV7_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/* $OUTPUT_DIR
|
||||
}
|
||||
|
||||
main()
|
||||
macos()
|
||||
{
|
||||
#generate_projects_if_necessary
|
||||
build_all_products "release"
|
||||
build_all_products "debug"
|
||||
if [[ ! $OSNAME = *"darwin"* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
generate_projects # if needed
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
|
||||
cd $XCODE_MACOS_PROJ_DIR
|
||||
# Framework
|
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
# NOTE: We build the static and dynamic editions in host()
|
||||
# Static library (libzt.a)
|
||||
#xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
# Dynamic library (libzt.dylib)
|
||||
#xcodebuild -target zt-shared -configuration "$UPPERCASE_CONFIG" -sdk "macosx"
|
||||
cd -
|
||||
OUTPUT_DIR=$(pwd)/lib/$1/macos-$(uname -m)
|
||||
mkdir -p $OUTPUT_DIR
|
||||
rm -rf $OUTPUT_DIR/zt.framework # Remove prior to move to prevent error
|
||||
mv $XCODE_MACOS_PROJ_DIR/$UPPERCASE_CONFIG/* $OUTPUT_DIR
|
||||
}
|
||||
|
||||
main "$@"
|
||||
host_jar()
|
||||
{
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
NORMALIZED_OSNAME=$OSNAME
|
||||
if [[ $OSNAME = *"darwin"* ]]; then
|
||||
DYNAMIC_LIB_NAME="libzt.dylib"
|
||||
NORMALIZED_OSNAME="macos"
|
||||
fi
|
||||
if [[ $OSNAME = *"linux"* ]]; then
|
||||
DYNAMIC_LIB_NAME="libzt.so"
|
||||
fi
|
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m)
|
||||
mkdir -p $LIB_OUTPUT_DIR
|
||||
# Build dynamic library
|
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-jni-$1
|
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
|
||||
cmake -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$UPPERCASE_CONFIG "-DJNI=1"
|
||||
cmake --build $BUILD_DIR $BUILD_CONCURRENCY
|
||||
# Copy dynamic library from previous build step
|
||||
# And, remove any lib that may exist prior. We don't want accidental successes
|
||||
cd $(pwd)/ports/java
|
||||
rm $DYNAMIC_LIB_NAME
|
||||
mv $BUILD_DIR/lib/$DYNAMIC_LIB_NAME .
|
||||
# Begin constructing JAR
|
||||
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
|
||||
javac com/zerotier/libzt/*.java
|
||||
jar cf zt.jar $DYNAMIC_LIB_NAME com/zerotier/libzt/*.class
|
||||
rm $DYNAMIC_LIB_NAME
|
||||
cd -
|
||||
# Move completed JAR
|
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m)
|
||||
mkdir -p $LIB_OUTPUT_DIR
|
||||
mv $(pwd)/ports/java/zt.jar $LIB_OUTPUT_DIR
|
||||
}
|
||||
|
||||
host()
|
||||
{
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
NORMALIZED_OSNAME=$OSNAME
|
||||
if [[ $OSNAME = *"darwin"* ]]; then
|
||||
NORMALIZED_OSNAME="macos"
|
||||
fi
|
||||
# CMake build files
|
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-$1
|
||||
mkdir -p $BUILD_DIR
|
||||
# Where to place results
|
||||
BIN_OUTPUT_DIR=$(pwd)/bin/$1/${NORMALIZED_OSNAME}-$(uname -m)
|
||||
mkdir -p $BIN_OUTPUT_DIR
|
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m)
|
||||
mkdir -p $LIB_OUTPUT_DIR
|
||||
# Build
|
||||
cmake -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$1
|
||||
cmake --build $BUILD_DIR $BUILD_CONCURRENCY
|
||||
# Move and clean up
|
||||
mv $BUILD_DIR/bin/* $BIN_OUTPUT_DIR
|
||||
mv $BUILD_DIR/lib/* $LIB_OUTPUT_DIR
|
||||
cleanup
|
||||
}
|
||||
|
||||
android()
|
||||
{
|
||||
# NOTE: There's no reason this won't build on linux, it's just that
|
||||
# for our purposes we limit this to execution on macOS
|
||||
if [[ ! $OSNAME = *"darwin"* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
ARCH="armeabi-v7a"
|
||||
# CMake build files
|
||||
BUILD_DIR=$(pwd)/tmp/android-$ARCH-$1
|
||||
mkdir -p $BUILD_DIR
|
||||
# If clean requested, remove temp build dir
|
||||
if [[ $1 = *"clean"* ]]; then
|
||||
rm -rf $BUILD_DIR
|
||||
exit 0
|
||||
fi
|
||||
# Where to place results
|
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/android-$ARCH
|
||||
mkdir -p $LIB_OUTPUT_DIR
|
||||
# Build
|
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
|
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DSDK_JNI=1"
|
||||
cd $ANDROID_PROJ_DIR
|
||||
./gradlew assemble$UPPERCASE_CONFIG # assembleRelease / assembleDebug
|
||||
mv $ANDROID_PROJ_DIR/app/build/outputs/aar/app-$1.aar \
|
||||
$LIB_OUTPUT_DIR/libzt-$1.aar
|
||||
cd -
|
||||
}
|
||||
|
||||
cleanup()
|
||||
{
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
find $(pwd)/lib -type f -name 'liblwip_pic.a' -exec rm {} +
|
||||
find $(pwd)/lib -type f -name 'liblwip.a' -exec rm {} +
|
||||
find $(pwd)/lib -type f -name 'libminiupnpc.a' -exec rm {} +
|
||||
find $(pwd)/lib -type f -name 'libnatpmp.a' -exec rm {} +
|
||||
find $(pwd)/lib -type f -name 'libzto_pic.a' -exec rm {} +
|
||||
find $(pwd)/lib -type f -name 'libzerotiercore.a' -exec rm {} +
|
||||
}
|
||||
|
||||
package_everything()
|
||||
{
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
LIBZT_VERSION=$(git describe)
|
||||
ZT_CORE_VERSION="1.2.12"
|
||||
PROD_NAME=$LIBZT_VERSION-$1
|
||||
PROD_DIR=$(pwd)/products/$PROD_NAME/
|
||||
# Make products directory
|
||||
LICENSE_DIR=$PROD_DIR/licenses
|
||||
mkdir -p $LICENSE_DIR
|
||||
# Licenses
|
||||
cp $(pwd)/ext/lwip/COPYING $LICENSE_DIR/LWIP-LICENSE.BSD
|
||||
cp $(pwd)/ext/concurrentqueue/LICENSE.md $LICENSE_DIR/CONCURRENTQUEUE-LICENSE.BSD
|
||||
cp $(pwd)/LICENSE.GPL-3 $LICENSE_DIR/ZEROTIER-LICENSE.GPL-3
|
||||
cp $(pwd)/include/net/ROUTE_H-LICENSE.APSL $LICENSE_DIR/ROUTE_H-LICENSE.APSL
|
||||
cp $(pwd)/include/net/ROUTE_H-LICENSE $LICENSE_DIR/ROUTE_H-LICENSE
|
||||
|
||||
# Documentation
|
||||
#mkdir -p $PROD_DIR/doc
|
||||
#cp $(pwd)/README.md $PROD_DIR/doc
|
||||
# Header(s)
|
||||
mkdir -p $PROD_DIR/include
|
||||
cp $(pwd)/include/*.h $PROD_DIR/include
|
||||
# Libraries
|
||||
mkdir -p $PROD_DIR/lib
|
||||
cp -r $(pwd)/lib/$1/* $PROD_DIR/lib
|
||||
# Clean
|
||||
find $PROD_DIR -type f \( -name '*.DS_Store' -o -name 'thumbs.db' \) -delete
|
||||
# Emit a README file
|
||||
# echo $'* libzt version: '${LIBZT_VERSION}$'\n* Core ZeroTier version:
|
||||
#'${ZT_CORE_VERSION}$'\n* Date: '$(date)$'\n
|
||||
#- ZeroTier Manual: https://www.zerotier.com/manual.shtml
|
||||
#- libzt Manual: https://www.zerotier.com/manual.shtml#5
|
||||
#- libzt Repo: https://github.com/zerotier/libzt
|
||||
#- Other Downloads: https://www.zerotier.com/download.shtml
|
||||
#- For more assistance, visit https://my.zerotier.com and ask your
|
||||
#question in our Community section' > $PROD_DIR/README.FIRST
|
||||
# Tar everything
|
||||
PROD_FILENAME=$(pwd)/products/$PROD_NAME.tar.gz
|
||||
tar --exclude=$PROD_FILENAME -zcvf $PROD_FILENAME $PROD_DIR
|
||||
md5 $PROD_FILENAME
|
||||
}
|
||||
|
||||
dist()
|
||||
{
|
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")"
|
||||
package_everything "debug"
|
||||
package_everything "release"
|
||||
}
|
||||
|
||||
"$@"
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PROJNAME="zt"
|
||||
LIBNAME="lib"$PROJNAME
|
||||
LIBZT_VERSION="1.2.0"
|
||||
LIBZT_REVISION="1"
|
||||
ZT_CORE_VERSION="1.2.12"
|
||||
FILENAME_PREFIX=${LIBNAME}
|
||||
|
||||
STAGING_DIR=$(pwd)/staging
|
||||
STAGING_DEBUG_DIR=$(pwd)/staging/debug
|
||||
STAGING_RELEASE_DIR=$(pwd)/staging/release
|
||||
FINISHED_PRODUCTS_DIR=$(pwd)/products
|
||||
|
||||
# Clean before zipping
|
||||
find . -type f \( -name '*.DS_Store' -o -name 'thumbs.db' \) -delete
|
||||
|
||||
# Emit a README file
|
||||
echo $'* libzt version: '${LIBZT_VERSION}$'r'${LIBZT_REVISION}$'\n* Core ZeroTier version: '${ZT_CORE_VERSION}$'\n* Date: '$(date)$'\n\nZeroTier Manual: https://www.zerotier.com/manual.shtml\n
|
||||
Other Downloads: https://www.zerotier.com/download.shtml
|
||||
\nlibzt Repo: https://github.com/zerotier/libzt\n\nFor more assistance, visit https://my.zerotier.com and ask your question in our Community section' > ${STAGING_DIR}/README.md
|
||||
|
||||
cp ${STAGING_DIR}/README.md ${STAGING_DIR}/debug/README.md
|
||||
cp ${STAGING_DIR}/README.md ${STAGING_DIR}/release/README.md
|
||||
|
||||
# Package everything together
|
||||
# (debug)
|
||||
PRODUCT_FILENAME=${FILENAME_PREFIX}-debug.tar.gz
|
||||
echo "Making: " ${FINISHED_PRODUCTS_DIR}/${PRODUCT_FILENAME}
|
||||
cd ${STAGING_DEBUG_DIR}
|
||||
tar --exclude=${PRODUCT_FILENAME} -zcvf ${PRODUCT_FILENAME} .
|
||||
md5 $PRODUCT_FILENAME
|
||||
mv *.tar.gz ${FINISHED_PRODUCTS_DIR}
|
||||
cd -
|
||||
|
||||
# (release)
|
||||
PRODUCT_FILENAME=${FILENAME_PREFIX}-release.tar.gz
|
||||
echo "Making: " ${FINISHED_PRODUCTS_DIR}/${PRODUCT_FILENAME}
|
||||
cd ${STAGING_RELEASE_DIR}
|
||||
tar --exclude=${PRODUCT_FILENAME} -zcvf ${PRODUCT_FILENAME} .
|
||||
md5 $PRODUCT_FILENAME
|
||||
mv *.tar.gz ${FINISHED_PRODUCTS_DIR}
|
||||
cd -
|
||||
@@ -30,18 +30,19 @@
|
||||
* ZeroTier service controls
|
||||
*/
|
||||
|
||||
#include <queue>
|
||||
#if defined(__linux__)
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include "Service.hpp"
|
||||
#include "Node.hpp"
|
||||
#include "ZeroTierOne.h"
|
||||
|
||||
#include "OSUtils.hpp"
|
||||
|
||||
#include "Service.hpp"
|
||||
#include "VirtualTap.hpp"
|
||||
#include "Debug.hpp"
|
||||
#include "concurrentqueue.h"
|
||||
|
||||
#include "libzt.h"
|
||||
#include "ZeroTier.h"
|
||||
#include "lwipDriver.hpp"
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -124,6 +125,15 @@ moodycamel::ConcurrentQueue<struct zts_callback_msg*> _callbackMsgQueue;
|
||||
void postEvent(int eventCode, void *arg)
|
||||
{
|
||||
struct zts_callback_msg *msg = new zts_callback_msg();
|
||||
|
||||
msg->node = NULL;
|
||||
msg->network = NULL;
|
||||
msg->netif = NULL;
|
||||
msg->route = NULL;
|
||||
msg->path = NULL;
|
||||
msg->peer = NULL;
|
||||
msg->addr = NULL;
|
||||
|
||||
msg->eventCode = eventCode;
|
||||
|
||||
if (NODE_EVENT_TYPE(eventCode)) {
|
||||
@@ -171,7 +181,11 @@ only for legacy reasons. */
|
||||
#if 1
|
||||
if(_userCallbackMethodRef) {
|
||||
JNIEnv *env;
|
||||
#if defined(__ANDROID__)
|
||||
jint rs = jvm->AttachCurrentThread(&env, NULL);
|
||||
#else
|
||||
jint rs = jvm->AttachCurrentThread((void **)&env, NULL);
|
||||
#endif
|
||||
assert (rs == JNI_OK);
|
||||
uint64_t arg = 0;
|
||||
uint64_t id = 0;
|
||||
@@ -275,15 +289,11 @@ void _api_sleep(int interval_ms)
|
||||
|
||||
int _change_nice(int increment)
|
||||
{
|
||||
#if !defined(__ANDROID__)
|
||||
if (increment == 0) {
|
||||
return 0;
|
||||
}
|
||||
int priority = getpriority(PRIO_PROCESS, 0);
|
||||
return setpriority( PRIO_PROCESS, 0, priority+increment);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
return setpriority(PRIO_PROCESS, 0, priority+increment);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -312,7 +322,11 @@ void *_zts_run_callbacks(void *thread_id)
|
||||
}
|
||||
_api_sleep(ZTS_CALLBACK_PROCESSING_INTERVAL);
|
||||
}
|
||||
#if SDK_JNI
|
||||
JNIEnv *env;
|
||||
jint rs = jvm->DetachCurrentThread();
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -420,7 +434,7 @@ JNIEXPORT void JNICALL Java_com_zerotier_libzt_ZeroTier_init(JNIEnv *env, jobjec
|
||||
}
|
||||
#endif
|
||||
|
||||
zts_err_t zts_join(const uint64_t nwid)
|
||||
int zts_join(const uint64_t nwid)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
if (!__zts_can_perform_service_operation()) {
|
||||
@@ -439,7 +453,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_join(
|
||||
}
|
||||
#endif
|
||||
|
||||
zts_err_t zts_leave(const uint64_t nwid)
|
||||
int zts_leave(const uint64_t nwid)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
if (!__zts_can_perform_service_operation()) {
|
||||
@@ -458,7 +472,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_leave(
|
||||
}
|
||||
#endif
|
||||
|
||||
zts_err_t zts_leave_all()
|
||||
int zts_leave_all()
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
if (!__zts_can_perform_service_operation()) {
|
||||
@@ -472,7 +486,7 @@ zts_err_t zts_leave_all()
|
||||
#ifdef SDK_JNI
|
||||
#endif
|
||||
|
||||
zts_err_t zts_orbit(uint64_t moonWorldId, uint64_t moonSeed)
|
||||
int zts_orbit(uint64_t moonWorldId, uint64_t moonSeed)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
void *tptr = NULL;
|
||||
@@ -486,7 +500,7 @@ zts_err_t zts_orbit(uint64_t moonWorldId, uint64_t moonSeed)
|
||||
#ifdef SDK_JNI
|
||||
#endif
|
||||
|
||||
zts_err_t zts_deorbit(uint64_t moonWorldId)
|
||||
int zts_deorbit(uint64_t moonWorldId)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
void *tptr = NULL;
|
||||
@@ -500,7 +514,7 @@ zts_err_t zts_deorbit(uint64_t moonWorldId)
|
||||
#ifdef SDK_JNI
|
||||
#endif
|
||||
|
||||
zts_err_t zts_start(const char *path, void (*callback)(struct zts_callback_msg*), int port)
|
||||
int zts_start(const char *path, void (*callback)(struct zts_callback_msg*), int port)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
lwip_driver_init();
|
||||
@@ -580,17 +594,17 @@ JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_start(
|
||||
JNIEnv *env, jobject thisObj, jstring path, jobject callback, jint port)
|
||||
{
|
||||
if (!path) {
|
||||
return;
|
||||
return ZTS_ERR_INVALID_ARG;
|
||||
}
|
||||
jclass eventListenerClass = env->GetObjectClass(callback);
|
||||
if(eventListenerClass == NULL) {
|
||||
DEBUG_ERROR("Couldn't find class for ZeroTierEventListener instance");
|
||||
return;
|
||||
return ZTS_ERR_INVALID_ARG;
|
||||
}
|
||||
jmethodID eventListenerCallbackMethod = env->GetMethodID(eventListenerClass, "onZeroTierEvent", "(JI)V");
|
||||
if(eventListenerCallbackMethod == NULL) {
|
||||
DEBUG_ERROR("Couldn't find onZeroTierEvent method");
|
||||
return;
|
||||
return ZTS_ERR_INVALID_ARG;
|
||||
}
|
||||
objRef = env->NewGlobalRef(callback); // Reference used for later calls
|
||||
_userCallbackMethodRef = eventListenerCallbackMethod;
|
||||
@@ -601,7 +615,7 @@ JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_start(
|
||||
}
|
||||
#endif
|
||||
|
||||
zts_err_t zts_stop()
|
||||
int zts_stop()
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
bool didStop = false;
|
||||
@@ -624,10 +638,10 @@ JNIEXPORT void JNICALL Java_com_zerotier_libzt_ZeroTier_stop(
|
||||
}
|
||||
#endif
|
||||
|
||||
zts_err_t zts_free()
|
||||
int zts_free()
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
zts_err_t retval = 0;
|
||||
int retval = 0;
|
||||
if (_freeHasBeenCalled) {
|
||||
return ZTS_ERR_INVALID_OP;
|
||||
}
|
||||
@@ -743,10 +757,10 @@ int zts_get_peer(struct zts_peer_details *pd, uint64_t peerId)
|
||||
// Networks //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
zts_err_t zts_get_num_joined_networks()
|
||||
int zts_get_num_joined_networks()
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (!__zts_can_perform_service_operation()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
@@ -807,11 +821,11 @@ void _get_all_network_details(struct zts_network_details *nds, int *num)
|
||||
*/
|
||||
}
|
||||
|
||||
zts_err_t zts_get_network_details(uint64_t nwid, struct zts_network_details *nd)
|
||||
int zts_get_network_details(uint64_t nwid, struct zts_network_details *nd)
|
||||
{
|
||||
/*
|
||||
_service_lock.lock();
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (!nd || nwid == 0) {
|
||||
retval = ZTS_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -829,11 +843,11 @@ zts_err_t zts_get_network_details(uint64_t nwid, struct zts_network_details *nd)
|
||||
#ifdef SDK_JNI
|
||||
#endif
|
||||
|
||||
zts_err_t zts_get_all_network_details(struct zts_network_details *nds, int *num)
|
||||
int zts_get_all_network_details(struct zts_network_details *nds, int *num)
|
||||
{
|
||||
/*
|
||||
_service_lock.lock();
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (!nds || !num) {
|
||||
retval = ZTS_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -903,7 +917,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_get_1network_1status(
|
||||
int zts_get_peer_status(uint64_t peerId)
|
||||
{
|
||||
Mutex::Lock _l(_service_lock);
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (!__zts_can_perform_service_operation()) {
|
||||
return ZTS_ERR_SERVICE;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#include "Debug.hpp"
|
||||
#include "concurrentqueue.h"
|
||||
|
||||
#include "libzt.h"
|
||||
#include "ZeroTier.h"
|
||||
#include "lwipDriver.hpp"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
@@ -86,7 +86,6 @@
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "libzt.h"
|
||||
#include "Controls.hpp"
|
||||
|
||||
// Use the virtual netcon endpoint instead of a tun/tap port driver
|
||||
|
||||
120
src/Sockets.cpp
120
src/Sockets.cpp
@@ -35,7 +35,7 @@
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/def.h"
|
||||
|
||||
#include "libzt.h"
|
||||
#include "ZeroTierConstants.h"
|
||||
#include "Options.h"
|
||||
#include "Debug.hpp"
|
||||
#include "Controls.hpp"
|
||||
@@ -53,7 +53,7 @@
|
||||
namespace ZeroTier {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Socket API //
|
||||
// ZeroTier Socket API //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern bool _run_service;
|
||||
@@ -63,6 +63,8 @@ extern bool _run_lwip_tcpip;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int zts_errno;
|
||||
|
||||
#ifdef SDK_JNI
|
||||
void ss2zta(JNIEnv *env, struct sockaddr_storage *ss, jobject addr);
|
||||
void zta2ss(JNIEnv *env, struct sockaddr_storage *ss, jobject addr);
|
||||
@@ -70,20 +72,6 @@ void ztfdset2fdset(JNIEnv *env, int nfds, jobject src_ztfd_set, fd_set *dest_fd_
|
||||
void fdset2ztfdset(JNIEnv *env, int nfds, fd_set *src_fd_set, jobject dest_ztfd_set);
|
||||
#endif
|
||||
|
||||
// Copied from lwip/src/include/sockets.h and renamed to prevent a name collision
|
||||
// with system definitions
|
||||
struct lwip_sockaddr {
|
||||
u8_t sa_len;
|
||||
sa_family_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// ZeroTier Socket API //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern int zts_errno;
|
||||
|
||||
int zts_socket(int socket_family, int socket_type, int protocol)
|
||||
{
|
||||
return (!_run_service || !_run_lwip_tcpip) ? ZTS_ERR_SERVICE : lwip_socket(socket_family, socket_type, protocol);
|
||||
@@ -92,7 +80,7 @@ int zts_socket(int socket_family, int socket_type, int protocol)
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_socket(
|
||||
JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol)
|
||||
{
|
||||
zts_err_t retval = zts_socket(family, type, protocol);
|
||||
int retval = zts_socket(family, type, protocol);
|
||||
return retval > -1 ? retval : -(zts_errno); // Encode lwip errno in return value for JNI functions only
|
||||
}
|
||||
#endif
|
||||
@@ -114,7 +102,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_connect(
|
||||
struct sockaddr_storage ss;
|
||||
zta2ss(env, &ss, addr);
|
||||
socklen_t addrlen = ss.ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
|
||||
zts_err_t retval = zts_connect(fd, (struct sockaddr *)&ss, addrlen);
|
||||
int retval = zts_connect(fd, (struct sockaddr *)&ss, addrlen);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -136,7 +124,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_bind(
|
||||
struct sockaddr_storage ss;
|
||||
zta2ss(env, &ss, addr);
|
||||
socklen_t addrlen = ss.ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
|
||||
zts_err_t retval = zts_bind(fd, (struct sockaddr*)&ss, addrlen);
|
||||
int retval = zts_bind(fd, (struct sockaddr*)&ss, addrlen);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -149,7 +137,7 @@ int zts_listen(int fd, int backlog)
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_listen(
|
||||
JNIEnv *env, jobject thisObj, jint fd, int backlog)
|
||||
{
|
||||
zts_err_t retval = zts_listen(fd, backlog);
|
||||
int retval = zts_listen(fd, backlog);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -164,7 +152,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_accept(
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_storage);
|
||||
zts_err_t retval =zts_accept(fd, (struct sockaddr *)&ss, &addrlen);
|
||||
int retval =zts_accept(fd, (struct sockaddr *)&ss, &addrlen);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -183,7 +171,7 @@ int zts_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_storage);
|
||||
zts_err_t retval = zts_accept4(fd, (struct sockaddr *)&ss, &addrlen, flags);
|
||||
int retval = zts_accept4(fd, (struct sockaddr *)&ss, &addrlen, flags);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -204,29 +192,29 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_setsockopt(
|
||||
}
|
||||
int optval_int = -1;
|
||||
|
||||
if (optname == ZTS_SO_BROADCAST
|
||||
|| optname == ZTS_SO_KEEPALIVE
|
||||
|| optname == ZTS_SO_REUSEADDR
|
||||
|| optname == ZTS_SO_REUSEPORT
|
||||
|| optname == ZTS_TCP_NODELAY)
|
||||
if (optname == SO_BROADCAST
|
||||
|| optname == SO_KEEPALIVE
|
||||
|| optname == SO_REUSEADDR
|
||||
|| optname == SO_REUSEPORT
|
||||
|| optname == TCP_NODELAY)
|
||||
{
|
||||
jfieldID fid = (*env).GetFieldID(c, "booleanValue", "Z");
|
||||
optval_int = (int)(*env).GetBooleanField(optval, fid);
|
||||
}
|
||||
if (optname == ZTS_IP_TTL
|
||||
|| optname == ZTS_SO_RCVTIMEO
|
||||
|| optname == ZTS_IP_TOS
|
||||
|| optname == ZTS_SO_LINGER
|
||||
|| optname == ZTS_SO_RCVBUF
|
||||
|| optname == ZTS_SO_SNDBUF)
|
||||
if (optname == IP_TTL
|
||||
|| optname == SO_RCVTIMEO
|
||||
|| optname == IP_TOS
|
||||
|| optname == SO_LINGER
|
||||
|| optname == SO_RCVBUF
|
||||
|| optname == SO_SNDBUF)
|
||||
{
|
||||
jfieldID fid = (*env).GetFieldID(c, "integerValue", "I");
|
||||
optval_int = (*env).GetIntField(optval, fid);
|
||||
}
|
||||
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
|
||||
if (optname == ZTS_SO_RCVTIMEO) {
|
||||
if (optname == SO_RCVTIMEO) {
|
||||
struct timeval tv;
|
||||
// Convert milliseconds from setSoTimeout() call to seconds and microseconds
|
||||
tv.tv_usec = optval_int * 1000;
|
||||
@@ -253,11 +241,11 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_getsockopt(
|
||||
return ZTS_ERR_INVALID_OP;
|
||||
}
|
||||
int optval_int = 0;
|
||||
int optlen; // Intentionally not used
|
||||
socklen_t optlen; // Intentionally not used
|
||||
|
||||
zts_err_t retval;
|
||||
int retval;
|
||||
|
||||
if (optname == ZTS_SO_RCVTIMEO) {
|
||||
if (optname == SO_RCVTIMEO) {
|
||||
struct timeval tv;
|
||||
optlen = sizeof(tv);
|
||||
retval = zts_getsockopt(fd, level, optname, &tv, &optlen);
|
||||
@@ -268,23 +256,23 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_getsockopt(
|
||||
retval = zts_getsockopt(fd, level, optname, &optval_int, &optlen);
|
||||
}
|
||||
|
||||
if (optname == ZTS_SO_BROADCAST
|
||||
|| optname == ZTS_SO_KEEPALIVE
|
||||
|| optname == ZTS_SO_REUSEADDR
|
||||
|| optname == ZTS_SO_REUSEPORT
|
||||
|| optname == ZTS_TCP_NODELAY)
|
||||
if (optname == SO_BROADCAST
|
||||
|| optname == SO_KEEPALIVE
|
||||
|| optname == SO_REUSEADDR
|
||||
|| optname == SO_REUSEPORT
|
||||
|| optname == TCP_NODELAY)
|
||||
{
|
||||
jfieldID fid = (*env).GetFieldID(c, "isBoolean", "Z");
|
||||
(*env).SetBooleanField(optval, fid, true);
|
||||
fid = (*env).GetFieldID(c, "booleanValue", "Z");
|
||||
(*env).SetBooleanField(optval, fid, (bool)optval_int);
|
||||
}
|
||||
if (optname == ZTS_IP_TTL
|
||||
|| optname == ZTS_SO_RCVTIMEO
|
||||
|| optname == ZTS_IP_TOS
|
||||
|| optname == ZTS_SO_LINGER
|
||||
|| optname == ZTS_SO_RCVBUF
|
||||
|| optname == ZTS_SO_SNDBUF)
|
||||
if (optname == IP_TTL
|
||||
|| optname == SO_RCVTIMEO
|
||||
|| optname == IP_TOS
|
||||
|| optname == SO_LINGER
|
||||
|| optname == SO_RCVBUF
|
||||
|| optname == SO_SNDBUF)
|
||||
{
|
||||
jfieldID fid = (*env).GetFieldID(c, "isInteger", "Z");
|
||||
(*env).SetBooleanField(optval, fid, true);
|
||||
@@ -311,7 +299,7 @@ JNIEXPORT jboolean JNICALL Java_com_zerotier_libzt_ZeroTier_getsockname(JNIEnv *
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_storage);
|
||||
zts_err_t retval =zts_getsockname(fd, (struct sockaddr *)&ss, &addrlen);
|
||||
int retval =zts_getsockname(fd, (struct sockaddr *)&ss, &addrlen);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -332,7 +320,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_getpeername(JNIEnv *env,
|
||||
jint fd, jobject addr)
|
||||
{
|
||||
struct sockaddr_storage ss;
|
||||
zts_err_t retval = zts_getpeername(fd, (struct sockaddr *)&ss, (socklen_t *)sizeof(struct sockaddr_storage));
|
||||
int retval = zts_getpeername(fd, (struct sockaddr *)&ss, (socklen_t *)sizeof(struct sockaddr_storage));
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -417,7 +405,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_select(JNIEnv *env, jobj
|
||||
e = &_exceptfds;
|
||||
ztfdset2fdset(env, nfds, exceptfds, &_exceptfds);
|
||||
}
|
||||
zts_err_t retval = zts_select(nfds, r, w, e, &_timeout);
|
||||
int retval = zts_select(nfds, r, w, e, &_timeout);
|
||||
if (readfds) {
|
||||
fdset2ztfdset(env, nfds, &_readfds, readfds);
|
||||
}
|
||||
@@ -451,7 +439,7 @@ int zts_fcntl(int fd, int cmd, int flags)
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_fcntl(
|
||||
JNIEnv *env, jobject thisObj, jint fd, jint cmd, jint flags)
|
||||
{
|
||||
zts_err_t retval = zts_fcntl(fd, cmd, flags);
|
||||
int retval = zts_fcntl(fd, cmd, flags);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
@@ -467,9 +455,9 @@ int zts_ioctl(int fd, unsigned long request, void *argp)
|
||||
JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_ioctl(
|
||||
JNIEnv *env, jobject thisObj, jint fd, jlong request, jobject argp)
|
||||
{
|
||||
zts_err_t retval = ZTS_ERR_OK;
|
||||
int retval = ZTS_ERR_OK;
|
||||
if (request == FIONREAD) {
|
||||
DEBUG_ERROR("FIONREAD");
|
||||
// DEBUG_ERROR("FIONREAD");
|
||||
int bytesRemaining = 0;
|
||||
retval = zts_ioctl(fd, request, &bytesRemaining);
|
||||
// set value in general object
|
||||
@@ -483,7 +471,7 @@ JNIEXPORT int JNICALL Java_com_zerotier_libzt_ZeroTier_ioctl(
|
||||
if (request == FIONBIO) {
|
||||
// TODO: double check
|
||||
int meaninglessVariable = 0;
|
||||
DEBUG_ERROR("FIONBIO");
|
||||
// DEBUG_ERROR("FIONBIO");
|
||||
retval = zts_ioctl(fd, request, &meaninglessVariable);
|
||||
}
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
@@ -502,7 +490,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_send(
|
||||
JNIEnv *env, jobject thisObj, jint fd, jbyteArray buf, int flags)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_send(fd, data, env->GetArrayLength(buf), flags);
|
||||
int retval = zts_send(fd, data, env->GetArrayLength(buf), flags);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -527,7 +515,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_sendto(
|
||||
struct sockaddr_storage ss;
|
||||
zta2ss(env, &ss, addr);
|
||||
socklen_t addrlen = ss.ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
|
||||
zts_err_t retval = zts_sendto(fd, data, env->GetArrayLength(buf), flags, (struct sockaddr *)&ss, addrlen);
|
||||
int retval = zts_sendto(fd, data, env->GetArrayLength(buf), flags, (struct sockaddr *)&ss, addrlen);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -552,7 +540,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_recv(JNIEnv *env, jobjec
|
||||
jint fd, jbyteArray buf, jint flags)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_recv(fd, data, env->GetArrayLength(buf), flags);
|
||||
int retval = zts_recv(fd, data, env->GetArrayLength(buf), flags);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -573,7 +561,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_recvfrom(
|
||||
socklen_t addrlen = sizeof(struct sockaddr_storage);
|
||||
struct sockaddr_storage ss;
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_recvfrom(fd, data, env->GetArrayLength(buf), flags, (struct sockaddr *)&ss, &addrlen);
|
||||
int retval = zts_recvfrom(fd, data, env->GetArrayLength(buf), flags, (struct sockaddr *)&ss, &addrlen);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
ss2zta(env, &ss, addr);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
@@ -607,7 +595,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read(JNIEnv *env, jobjec
|
||||
jint fd, jbyteArray buf)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_read(fd, data, env->GetArrayLength(buf));
|
||||
int retval = zts_read(fd, data, env->GetArrayLength(buf));
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -615,7 +603,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1offset(JNIEnv *env
|
||||
jint fd, jbyteArray buf, jint offset, jint len)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_read_offset(fd, data, offset, len);
|
||||
int retval = zts_read_offset(fd, data, offset, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -623,7 +611,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_read_1length(JNIEnv *env
|
||||
jint fd, jbyteArray buf, jint len)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_read(fd, data, len);
|
||||
int retval = zts_read(fd, data, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -641,7 +629,7 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write__IB(JNIEnv *env, j
|
||||
jint fd, jbyteArray buf)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(buf, NULL);
|
||||
zts_err_t retval = zts_write(fd, data, env->GetArrayLength(buf));
|
||||
int retval = zts_write(fd, data, env->GetArrayLength(buf));
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
@@ -649,14 +637,14 @@ JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write_1offset(JNIEnv *en
|
||||
jint fd, jbyteArray buf, jint offset, jint len)
|
||||
{
|
||||
void *data = env->GetPrimitiveArrayCritical(&(buf[offset]), NULL); // PENDING: check?
|
||||
zts_err_t retval = zts_write(fd, data, len);
|
||||
int retval = zts_write(fd, data, len);
|
||||
env->ReleasePrimitiveArrayCritical(buf, data, 0);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_zerotier_libzt_ZeroTier_write_1byte(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jbyte buf)
|
||||
{
|
||||
zts_err_t retval = zts_write(fd, &buf, 1);
|
||||
int retval = zts_write(fd, &buf, 1);
|
||||
return retval > -1 ? retval : -(zts_errno);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "Service.hpp"
|
||||
#include "Mutex.hpp"
|
||||
#include "lwipDriver.hpp"
|
||||
#include "libzt.h"
|
||||
#include "ZeroTier.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include "Synchapi.h"
|
||||
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
|
||||
/*
|
||||
* Timestamp of last run of housekeeping
|
||||
* SEE: ZT_HOUSEKEEPING_INTERVAL in libzt.h
|
||||
* SEE: ZT_HOUSEKEEPING_INTERVAL in ZeroTier.h
|
||||
*/
|
||||
uint64_t last_housekeeping_ts = 0;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
#include "VirtualTap.hpp"
|
||||
#include "lwipDriver.hpp"
|
||||
#include "libzt.h"
|
||||
#include "ZeroTier.h"
|
||||
#include "Controls.hpp"
|
||||
|
||||
extern void postEvent(uint64_t eventCode, void *arg);
|
||||
|
||||
Reference in New Issue
Block a user