Removed cruft from project
This commit is contained in:
473
attic/Makefile
473
attic/Makefile
@@ -1,473 +0,0 @@
|
||||
#
|
||||
# ZeroTier SDK - Network Virtualization Everywhere
|
||||
# Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# --
|
||||
#
|
||||
# You can be released from the requirements of the license by purchasing
|
||||
# a commercial license. Buying such a license is mandatory as soon as you
|
||||
# develop commercial closed-source software that incorporates or links
|
||||
# directly against ZeroTier software without disclosing the source code
|
||||
# of your own application.
|
||||
#
|
||||
|
||||
# Automagically pick clang or gcc, with preference for clang
|
||||
# This is only done if we have not overridden these with an environment or CLI variable
|
||||
ifeq ($(origin CC),default)
|
||||
CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
|
||||
endif
|
||||
ifeq ($(origin CXX),default)
|
||||
CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
|
||||
endif
|
||||
|
||||
OSTYPE=$(shell uname -s | tr '[A-Z]' '[a-z]')
|
||||
BUILDPATH=build/$(OSTYPE)
|
||||
LIBPATH=lib
|
||||
LWIPCONTRIBDIR=ext/lwip-contrib
|
||||
|
||||
# default
|
||||
CFLAGS+=-Wall
|
||||
|
||||
# Windows
|
||||
ifeq ($(OSTYPE),mingw32_nt-6.2)
|
||||
ARTOOL=ar
|
||||
ARFLAGS=rcs
|
||||
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
CFLAGS=
|
||||
CXXFLAGS+=-fpermissive -Wno-unknown-pragmas -Wno-pointer-arith -Wno-deprecated-declarations -Wno-conversion-null
|
||||
WINDEFS=-lws2_32 -lshlwapi -liphlpapi -static -static-libgcc -static-libstdc++
|
||||
LWIPARCHINCLUDE=$(LWIPCONTRIBDIR)/ports/win32/include
|
||||
STATIC_LIB=libzt.a
|
||||
SHARED_LIB=libzt.dll
|
||||
endif
|
||||
# Darwin
|
||||
ifeq ($(OSTYPE),darwin)
|
||||
CFLAGS+=-fvisibility=hidden -fstack-protector
|
||||
ARTOOL=libtool
|
||||
ARFLAGS=-static
|
||||
LWIPARCHINCLUDE=$(LWIPCONTRIBDIR)/ports/unix/include
|
||||
STATIC_LIB=libzt.a
|
||||
SHARED_LIB=libzt.dylib
|
||||
endif
|
||||
# Linux
|
||||
ifeq ($(OSTYPE),linux)
|
||||
CFLAGS+=-fvisibility=hidden -fstack-protector
|
||||
ARTOOL=ar
|
||||
ARFLAGS=rcs
|
||||
LWIPARCHINCLUDE=$(LWIPCONTRIBDIR)/ports/unix/include
|
||||
STATIC_LIB=libzt.a
|
||||
SHARED_LIB=libzt.so
|
||||
endif
|
||||
# FreeBSD
|
||||
ifeq ($(OSTYPE),freebsd)
|
||||
CFLAGS+=-fvisibility=hidden -fstack-protector
|
||||
ARTOOL=ar
|
||||
ARFLAGS=rcs
|
||||
LWIPARCHINCLUDE=$(LWIPCONTRIBDIR)/ports/unix/include
|
||||
STATIC_LIB=libzt.a
|
||||
SHARED_LIB=libzt.so
|
||||
endif
|
||||
# OpenBSD
|
||||
ifeq ($(OSTYPE),openbsd)
|
||||
CFLAGS+=-fvisibility=hidden -fstack-protector
|
||||
ARTOOL=ar
|
||||
ARFLAGS=rcs
|
||||
LWIPARCHINCLUDE=$(LWIPCONTRIBDIR)/ports/unix/include
|
||||
STATIC_LIB=libzt.a
|
||||
SHARED_LIB=libzt.so
|
||||
endif
|
||||
|
||||
##############################################################################
|
||||
## Objects and includes ##
|
||||
##############################################################################
|
||||
|
||||
include zto/objects.mk
|
||||
|
||||
ZTO_OBJS=\
|
||||
zto/node/C25519.o \
|
||||
zto/node/Capability.o \
|
||||
zto/node/CertificateOfMembership.o \
|
||||
zto/node/CertificateOfOwnership.o \
|
||||
zto/node/Identity.o \
|
||||
zto/node/IncomingPacket.o \
|
||||
zto/node/InetAddress.o \
|
||||
zto/node/Membership.o \
|
||||
zto/node/Multicaster.o \
|
||||
zto/node/Network.o \
|
||||
zto/node/NetworkConfig.o \
|
||||
zto/node/Node.o \
|
||||
zto/node/OutboundMulticast.o \
|
||||
zto/node/Packet.o \
|
||||
zto/node/Path.o \
|
||||
zto/node/Peer.o \
|
||||
zto/node/Poly1305.o \
|
||||
zto/node/Revocation.o \
|
||||
zto/node/Salsa20.o \
|
||||
zto/node/SelfAwareness.o \
|
||||
zto/node/SHA512.o \
|
||||
zto/node/Switch.o \
|
||||
zto/node/Tag.o \
|
||||
zto/node/Topology.o \
|
||||
zto/node/Trace.o \
|
||||
zto/node/Utils.o \
|
||||
zto/controller/EmbeddedNetworkController.o \
|
||||
zto/controller/DB.o \
|
||||
zto/controller/FileDB.o \
|
||||
zto/osdep/ManagedRoute.o \
|
||||
zto/osdep/Http.o \
|
||||
zto/osdep/OSUtils.o \
|
||||
zto/service/SoftwareUpdater.o \
|
||||
zto/service/OneService.o \
|
||||
zto/ext/http-parser/http_parser.o
|
||||
|
||||
ZT_INCLUDES+=-Iext \
|
||||
-Izto/osdep \
|
||||
-Izto/node \
|
||||
-Izto/service \
|
||||
-Izto/include \
|
||||
|
||||
LIBZT_INCLUDES+=-Iinclude \
|
||||
-I../include \
|
||||
-Isrc
|
||||
|
||||
##############################################################################
|
||||
## General Build Configuration ##
|
||||
##############################################################################
|
||||
|
||||
# ZT_ Configuration options for ZeroTier core
|
||||
# LIBZT_ Configuration options for libzt
|
||||
# NS_ Configuration options for userspace network stack
|
||||
|
||||
STRIP=strip
|
||||
# Determine if PIC is needed for the intended build target
|
||||
ifeq ($(MAKECMDGOALS),static_lib)
|
||||
CFLAGS?=
|
||||
#-fPIE
|
||||
endif
|
||||
ifeq ($(MAKECMDGOALS),shared_lib)
|
||||
CFLAGS?=
|
||||
#-fPIC
|
||||
endif
|
||||
# ZeroTier core debug and tracing
|
||||
ifeq ($(ZT_DEBUG),1)
|
||||
CFLAGS?=-g
|
||||
ZT_DEFS?=-DZT_TRACE=1
|
||||
STRIP=echo
|
||||
else
|
||||
CFLAGS?=-Ofast
|
||||
endif
|
||||
# For consistency. ZT_DEBUG=1 will also turn this on
|
||||
ifeq ($(ZT_TRACE),1)
|
||||
ZT_DEFS?=-DZT_TRACE
|
||||
endif
|
||||
# Don't optimize, add debug symbols
|
||||
ifeq ($(LIBZT_DEBUG),1)
|
||||
CFLAGS?=-g
|
||||
STRIP=echo
|
||||
else
|
||||
CFLAGS?=-Ofast
|
||||
endif
|
||||
# Turns on file/function/line debug output logging
|
||||
ifeq ($(LIBZT_TRACE),1)
|
||||
LIBZT_DEFS?=-DLIBZT_TRACE
|
||||
endif
|
||||
# Experimental stack drivers which interface via raw API's
|
||||
ifeq ($(LIBZT_RAW),1)
|
||||
LIBZT_DEFS?=-DLIBZT_RAW=1
|
||||
endif
|
||||
# Debug the userspace stack
|
||||
ifeq ($(NS_DEBUG),1)
|
||||
CFLAGS?=-g
|
||||
STRIP=echo
|
||||
endif
|
||||
|
||||
# Build with address sanitization library for advanced debugging (clang)
|
||||
# TODO: Add GCC version as well
|
||||
ifeq ($(LIBZT_SANITIZE),1)
|
||||
SANFLAGS+=-x c++ -g -fsanitize=address -DASAN_OPTIONS=symbolize=1 \
|
||||
-DASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer)
|
||||
endif
|
||||
|
||||
# JNI (Java Native Interface)
|
||||
ifeq ($(OSTYPE),darwin)
|
||||
JNI_INCLUDES+=-I$(shell /usr/libexec/java_home)/include
|
||||
JNI_INCLUDES+=-I$(shell /usr/libexec/java_home)/include/$(OSTYPE)
|
||||
endif
|
||||
ifeq ($(OSTYPE),linux)
|
||||
JNI_INCLUDES+=-I$(shell dirname $(shell dirname $(shell readlink -f $(shell which javac))))/include
|
||||
JNI_INCLUDES+=-I$(shell dirname $(shell dirname $(shell readlink -f $(shell which javac))))/include/$(OSTYPE)
|
||||
endif
|
||||
|
||||
CXXFLAGS+=$(CFLAGS) -Wno-format -fno-rtti -std=c++11
|
||||
ZT_DEFS+=-DZT_SDK -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
|
||||
LIBZT_FILES:=src/VirtualTap.cpp src/libzt.cpp src/Utilities.cpp
|
||||
|
||||
##############################################################################
|
||||
## Stack Configuration ##
|
||||
##############################################################################
|
||||
|
||||
#ifeq ($(NO_STACK),1)
|
||||
#STACK_DRIVER_DEFS+=-DNO_STACK
|
||||
#endif
|
||||
|
||||
ifeq ($(NS_DEBUG),1)
|
||||
STACK_DEFS+=LWIP_DEBUG=1
|
||||
endif
|
||||
|
||||
# picoTCP
|
||||
STACK_INCLUDES+=-Iext/picotcp/include -Iext/picotcp/build/include
|
||||
STACK_DRIVER_FILES:=src/picoTCP.cpp
|
||||
|
||||
# lwIP
|
||||
LWIPDIR=ext/lwip/src
|
||||
STACK_INCLUDES+=-I$(LWIPARCHINCLUDE) -Iext/lwip/src/include/lwip \
|
||||
-I$(LWIPDIR)/include \
|
||||
-I$(LWIPARCH)/include \
|
||||
-I$(LWIPDIR)/include/ipv4 \
|
||||
-I$(LWIPDIR) \
|
||||
-Iext
|
||||
STACK_DRIVER_FILES:=src/lwIP.cpp
|
||||
|
||||
##############################################################################
|
||||
## Targets ##
|
||||
##############################################################################
|
||||
|
||||
%.o : %.cpp
|
||||
@mkdir -p $(BUILDPATH) obj
|
||||
$(CXX) $(CXXFLAGS) $(STACK_DRIVER_DEFS) $(ZT_DEFS) \
|
||||
$(ZT_INCLUDES) $(LIBZT_INCLUDES) -c $^ -o obj/$(@F)
|
||||
|
||||
%.o : %.c
|
||||
@mkdir -p $(BUILDPATH) obj
|
||||
$(CC) $(CFLAGS) -c $^ -o obj/$(@F)
|
||||
|
||||
core:
|
||||
cd zto; make core
|
||||
mv zto/libzerotiercore.a $(BUILDPATH)
|
||||
|
||||
picotcp:
|
||||
cd ext/picotcp; make lib ARCH=shared IPV4=1 IPV6=1
|
||||
|
||||
lwip:
|
||||
echo $(STACK_DEFS)
|
||||
make -f make-liblwip.mk liblwip.a LIBZT_IPV4=1 IPV4=1
|
||||
|
||||
lwip_driver:
|
||||
$(CXX) $(CXXFLAGS) -c src/lwIP.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(STACK_INCLUDES) $(LIBZT_DEFS) $(LIBZT_INCLUDES) -DZT_DRIVER_MODULE
|
||||
|
||||
picotcp_driver:
|
||||
$(CXX) $(CXXFLAGS) -c src/picoTCP.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(STACK_INCLUDES) $(LIBZT_DEFS) $(LIBZT_INCLUDES) -DZT_DRIVER_MODULE
|
||||
|
||||
libzt_socket_layer:
|
||||
$(CXX) $(CXXFLAGS) -c src/VirtualSocket.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(LIBZT_INCLUDES) $(LIBZT_DEFS)
|
||||
$(CXX) $(CXXFLAGS) -c src/VirtualSocketLayer.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(STACK_INCLUDES) $(LIBZT_INCLUDES) $(LIBZT_DEFS)
|
||||
$(CXX) $(CXXFLAGS) -c src/VirtualTap.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(LIBZT_DEFS) $(LIBZT_INCLUDES)
|
||||
$(CXX) $(CXXFLAGS) -c src/ZT1Service.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(LIBZT_INCLUDES) $(LIBZT_DEFS)
|
||||
$(CXX) $(CXXFLAGS) -c src/libzt.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(STACK_INCLUDES) $(LIBZT_DEFS) $(LIBZT_INCLUDES)
|
||||
$(CXX) $(CXXFLAGS) -c src/RingBuffer.cpp $(LIBZT_INCLUDES)
|
||||
|
||||
jni_socket_wrapper:
|
||||
$(CXX) $(CXXFLAGS) -DSDK_JNI -c src/libztJNI.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(STACK_INCLUDES) $(JNI_INCLUDES) $(LIBZT_DEFS) $(LIBZT_INCLUDES)
|
||||
|
||||
utilities:
|
||||
$(CXX) $(CXXFLAGS) -c src/SysUtils.cpp \
|
||||
$(LIBZT_INCLUDES)
|
||||
$(CXX) $(CXXFLAGS) -c src/Utilities.cpp \
|
||||
$(ZT_DEFS) $(ZT_INCLUDES) $(LIBZT_INCLUDES) $(STACK_INCLUDES)
|
||||
|
||||
remove_objs:
|
||||
rm -rf *.o
|
||||
|
||||
prereqs: remove_objs lwip lwip_driver libzt_socket_layer jni_socket_wrapper utilities
|
||||
|
||||
static_lib: prereqs $(ZTO_OBJS)
|
||||
mv *.o obj
|
||||
mkdir -p lib
|
||||
$(ARTOOL) $(ARFLAGS) obj/*.o -o $(LIBPATH)/$(STATIC_LIB)
|
||||
|
||||
shared_lib: prereqs $(ZTO_OBJS)
|
||||
mv *.o obj
|
||||
mkdir -p lib
|
||||
$(CXX) $(CXXFLAGS) obj/*.o $(SOLIBTYPE) -o $(LIBPATH)/$(SHARED_LIB) -lpthread
|
||||
|
||||
dynamic_lib: prereqs $(ZTO_OBJS)
|
||||
|
||||
ifdef JNI
|
||||
ZT_DEFS+=-DSDK_JNI
|
||||
SOLIBTYPE=-shared
|
||||
else
|
||||
SOLIBTYPE=-shared
|
||||
# user dynamiclib for macOS
|
||||
endif
|
||||
ifdef STATIC
|
||||
CFLAGS+=
|
||||
#-fPIE
|
||||
lib: static_lib
|
||||
endif
|
||||
ifdef SHARED
|
||||
CFLAGS+=
|
||||
#-fPIC
|
||||
lib: shared_lib
|
||||
endif
|
||||
|
||||
# windows DLL
|
||||
win_dll: lwip lwip_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
||||
# First we use mingw to build our DLL
|
||||
@mkdir -p $(BUILDPATH) obj
|
||||
mv *.o obj
|
||||
windres -i res/libztdll.rc -o obj/libztdllres.o
|
||||
$(CXX) $(CXXFLAGS) -shared -o $(BUILDPATH)/libzt.dll obj/*.o -Wl,--output-def,$(BUILDPATH)/libzt.def,--out-implib,$(BUILDPATH)/libzt.a $(WINDEFS)
|
||||
$(STRIP) $(BUILDPATH)/libzt.dll
|
||||
# Then do the following to generate the MSVC DLL from the def file (which was generated from the MinGW DLL):
|
||||
# lib /machine:x64 /def:libzt.def
|
||||
# or just execute: makelib
|
||||
|
||||
# ordinary shared library
|
||||
#shared_lib: lwip lwip_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
||||
# @mkdir -p $(BUILDPATH) obj
|
||||
# mv *.o obj
|
||||
# $(CXX) $(CXXFLAGS) -shared -o $(BUILDPATH)/libzt.so obj/*.o
|
||||
|
||||
# dynamic library for use with Java JNI, scala, etc
|
||||
#shared_jni_lib: lwip lwip_driver libzt_socket_layer jni_socket_wrapper utilities $(ZTO_OBJS)
|
||||
# @mkdir -p $(BUILDPATH) obj
|
||||
# mv *.o obj
|
||||
#$(CXX) $(CXXFLAGS) -shared -o $(BUILDPATH)/libzt.so obj/*.o
|
||||
# $(CXX) $(CXXFLAGS) -dynamiclib obj/*.o -o $(BUILDPATH)/libzt.dylib -lpthread
|
||||
|
||||
# static library for use with Java JNI, scala, etc
|
||||
#static_jni_lib: lwip lwip_driver libzt_socket_layer jni_socket_wrapper utilities $(ZTO_OBJS)
|
||||
# @mkdir -p $(BUILDPATH) obj
|
||||
# mv *.o obj
|
||||
# $(ARTOOL) $(ARFLAGS) -o $(BUILDPATH)/$(STATIC_LIB) obj/*.o
|
||||
|
||||
# static library
|
||||
#static_lib: lwip lwip_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
||||
# @mkdir -p $(BUILDPATH) obj
|
||||
# mv *.o obj
|
||||
# mv ext/picotcp/build/lib/*.o obj
|
||||
# mv ext/picotcp/build/modules/*.o obj
|
||||
# $(ARTOOL) $(ARFLAGS) -o $(BUILDPATH)/$(STATIC_LIB) obj/*.o
|
||||
|
||||
##############################################################################
|
||||
## iOS/macOS App Frameworks ##
|
||||
##############################################################################
|
||||
|
||||
ios_app_framework:
|
||||
cd examples/apple/ZeroTierSDK_Apple; xcodebuild -configuration Release \
|
||||
-scheme ZeroTierSDK_iOS build SYMROOT="../../../$(BUILDPATH)/ios_app_framework"
|
||||
cd examples/apple/ZeroTierSDK_Apple; xcodebuild -configuration Debug \
|
||||
-scheme ZeroTierSDK_iOS build SYMROOT="../../../$(BUILDPATH)/ios_app_framework"
|
||||
|
||||
macos_app_framework:
|
||||
cd examples/apple/ZeroTierSDK_Apple; xcodebuild -configuration Release \
|
||||
-scheme ZeroTierSDK_OSX build SYMROOT="../../../$(BUILDPATH)/macos_app_framework"
|
||||
cd examples/apple/ZeroTierSDK_Apple; xcodebuild -configuration Debug \
|
||||
-scheme ZeroTierSDK_OSX build SYMROOT="../../../$(BUILDPATH)/macos_app_framework"
|
||||
|
||||
##############################################################################
|
||||
## Python module ##
|
||||
##############################################################################
|
||||
|
||||
python_module:
|
||||
swig -cpperraswarn -python -c++ -o examples/python/libzt.cc examples/python/swig_libzt.i
|
||||
python examples/python/setup.py build_ext --inplace --swig-opts="-modern -I../../zto/include"
|
||||
|
||||
##############################################################################
|
||||
## Unit Tests ##
|
||||
##############################################################################
|
||||
|
||||
tests: selftest nativetest ztproxy ipv4simple ipv6simple ipv6adhoc
|
||||
# intercept
|
||||
|
||||
ZT_UTILS:=zto/node/Utils.cpp -Izto/node
|
||||
|
||||
sample:
|
||||
$(CXX) $(CXXFLAGS) -D__SELFTEST__ $(STACK_DRIVER_DEFS) $(LIBZT_DEFS) \
|
||||
$(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/sample.cpp -o \
|
||||
$(BUILDPATH)/sample -L$(LIBPATH) -lzt
|
||||
selftest:
|
||||
$(CXX) $(CXXFLAGS) -D__SELFTEST__ $(STACK_DRIVER_DEFS) $(LIBZT_DEFS) \
|
||||
$(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/selftest.cpp -o \
|
||||
$(BUILDPATH)/selftest -L$(LIBPATH) -lzt -lpthread
|
||||
nativetest:
|
||||
$(CXX) $(CXXFLAGS) -D__NATIVETEST__ $(STACK_DRIVER_DEFS) $(SANFLAGS) \
|
||||
$(LIBZT_INCLUDES) $(ZT_INCLUDES) test/selftest.cpp -o $(BUILDPATH)/nativetest
|
||||
ztproxy:
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) $(ZT_INCLUDES) \
|
||||
examples/apps/ztproxy/ztproxy.cpp -o $(BUILDPATH)/ztproxy $< -L$(LIBPATH) -lzt -lpthread $(WINDEFS)
|
||||
intercept:
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(STACK_DRIVER_DEFS) $(LIBZT_INCLUDES) \
|
||||
$(ZT_INCLUDES) examples/intercept/intercept.cpp -D_GNU_SOURCE \
|
||||
-shared -o $(BUILDPATH)/intercept.so $< -ldl
|
||||
ipv4simple:
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv4simple/client.cpp -o $(BUILDPATH)/ipv4client -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv4simple/server.cpp -o $(BUILDPATH)/ipv4server -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
ipv6simple:
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv6simple/client.cpp -o $(BUILDPATH)/ipv6client -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv6simple/server.cpp -o $(BUILDPATH)/ipv6server -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
ipv6adhoc:
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv6adhoc/client.cpp -o $(BUILDPATH)/ipv6adhocclient -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) \
|
||||
examples/bindings/cpp/ipv6adhoc/server.cpp -o $(BUILDPATH)/ipv6adhocserver -L$(LIBPATH) -lpthread -lzt $(WINDEFS)
|
||||
dlltest:
|
||||
$(CXX) $(CXXFLAGS)
|
||||
|
||||
##############################################################################
|
||||
## Installation and Uninstallation ##
|
||||
##############################################################################
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/lib
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/include
|
||||
cp $(BUILDPATH)/$(STATIC_LIB) $(DESTDIR)$(PREFIX)/lib/
|
||||
cp include/libzt.h $(DESTDIR)$(PREFIX)/include/
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/*.a
|
||||
rm -f $(DESTDIR)$(PREFIX)/include/*.h
|
||||
|
||||
##############################################################################
|
||||
## Misc ##
|
||||
##############################################################################
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm f $(LIBPATH)/*
|
||||
-rm -rf $(BUILDPATH)/*
|
||||
-rm f obj/*
|
||||
-rm f *.o *.s *.exp *.lib .depend* *.core core
|
||||
-rm -rf .depend
|
||||
-find . -type f \( -name '*.a' -o -name '*.o' -o -name '*.so' -o -name \
|
||||
'*.o.d' -o -name '*.out' -o -name '*.log' -o -name '*.dSYM' \) -delete
|
||||
|
||||
54
attic/VirtualBindingPair.h
Normal file
54
attic/VirtualBindingPair.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LIBZT_VIRTUALBINDINGPAIR_H
|
||||
#define LIBZT_VIRTUALBINDINGPAIR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A helper object for passing VirtualTap(s) and VirtualSocket(s) through the stack
|
||||
*/
|
||||
struct VirtualBindingPair
|
||||
{
|
||||
VirtualTap *tap;
|
||||
VirtualSocket *vs;
|
||||
VirtualBindingPair(VirtualTap *_tap, VirtualSocket *_vs) : tap(_tap), vs(_vs) {}
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _H
|
||||
105
attic/VirtualSocket.cpp
Normal file
105
attic/VirtualSocket.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Platform- and stack-agnostic implementation of a socket-like object
|
||||
*/
|
||||
|
||||
#include "libztDefs.h"
|
||||
|
||||
#ifdef ZT_VIRTUAL_SOCKET
|
||||
|
||||
#include <ctime>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "Phy.hpp"
|
||||
|
||||
#include "libzt.h"
|
||||
#include "libztDebug.h"
|
||||
#include "VirtualSocket.h"
|
||||
#include "VirtualTap.h"
|
||||
#include "RingBuffer.h"
|
||||
|
||||
class VirtualTap;
|
||||
|
||||
void VirtualSocket::apply_state(int state) {
|
||||
// states may be set by application or by stack callbacks, thus this must be guarded
|
||||
_op_m.lock();
|
||||
_state &= state;
|
||||
_op_m.unlock();
|
||||
}
|
||||
|
||||
void VirtualSocket::set_state(int state) {
|
||||
_op_m.lock();
|
||||
_state = state;
|
||||
_op_m.unlock();
|
||||
}
|
||||
|
||||
int VirtualSocket::get_state() {
|
||||
return _state;
|
||||
}
|
||||
|
||||
VirtualSocket::VirtualSocket() {
|
||||
DEBUG_EXTRA("this=%p",this);
|
||||
memset(&local_addr, 0, sizeof(sockaddr_storage));
|
||||
memset(&peer_addr, 0, sizeof(sockaddr_storage));
|
||||
|
||||
// ringbuffer used for incoming and outgoing traffic between app, stack, stack drivers, and ZT
|
||||
TXbuf = new RingBuffer(ZT_TCP_TX_BUF_SZ);
|
||||
RXbuf = new RingBuffer(ZT_TCP_RX_BUF_SZ);
|
||||
|
||||
// socketpair, I/O channel between app and stack drivers
|
||||
ZT_PHY_SOCKFD_TYPE fdpair[2];
|
||||
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fdpair) < 0) {
|
||||
if (errno < 0) {
|
||||
DEBUG_ERROR("unable to create socketpair, errno=%d", errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
sdk_fd = fdpair[0];
|
||||
app_fd = fdpair[1];
|
||||
|
||||
// set to non-blocking since these are used as the primary I/O channel
|
||||
if (fcntl(sdk_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
DEBUG_ERROR("error while setting virtual socket to NONBLOCKING. exiting", errno);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
VirtualSocket::~VirtualSocket() {
|
||||
DEBUG_EXTRA("this=%p",this);
|
||||
close(app_fd);
|
||||
close(sdk_fd);
|
||||
delete TXbuf;
|
||||
delete RXbuf;
|
||||
TXbuf = RXbuf = NULL;
|
||||
//picosock->priv = NULL;
|
||||
pcb = NULL;
|
||||
}
|
||||
|
||||
#endif // ZT_VIRTUAL_SOCKET
|
||||
159
attic/VirtualSocket.h
Normal file
159
attic/VirtualSocket.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Platform- and stack-agnostic implementation of a socket-like object
|
||||
*/
|
||||
|
||||
#ifndef LIBZT_VIRTUALSOCKET_H
|
||||
#define LIBZT_VIRTUALSOCKET_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "RingBuffer.h"
|
||||
#include "libztDefs.h"
|
||||
#include "VirtualTap.h"
|
||||
#include "Mutex.hpp"
|
||||
|
||||
#define VS_STATE_INACTIVE 0x000000u // Default value for newly created VirtualSocket
|
||||
#define VS_STATE_ACTIVE 0x000001u // VirtualSocket is RX'ing or TX'ing without issue
|
||||
#define VS_STATE_SHOULD_SHUTDOWN 0x000002u // Application, stack driver, or stack marked this VirtualSocket for death
|
||||
#define VS_STATE_SHUTDOWN 0x000004u // VirtualSocket and underlying protocol control structures will not RX/TX
|
||||
#define VS_STATE_CLOSED 0x000008u // VirtualSocket and underlying protocol control structures are closed
|
||||
#define VS_STATE_UNHANDLED_CONNECTED 0x000010u // stack callback has received a connection but we haven't dealt with it
|
||||
#define VS_STATE_CONNECTED 0x000020u // stack driver has akwnowledged new connection
|
||||
#define VS_STATE_LISTENING 0x000040u // virtual socket is listening for incoming connections
|
||||
|
||||
#define VS_OPT_TCP_NODELAY 0x000000u // Nagle's algorithm
|
||||
#define VS_OPT_SO_LINGER 0x000001u // VirtualSocket waits for data transmission before closure
|
||||
/*
|
||||
#define VS_RESERVED 0x000002u //
|
||||
#define VS_RESERVED 0x000004u //
|
||||
#define VS_RESERVED 0x000008u //
|
||||
#define VS_RESERVED 0x000010u //
|
||||
#define VS_RESERVED 0x000020u //
|
||||
#define VS_RESERVED 0x000040u //
|
||||
*/
|
||||
#define VS_OPT_FD_NONBLOCKING 0x000080u // Whether the VirtualSocket exhibits non-blocking behaviour
|
||||
/*
|
||||
#define VS_RESERVED 0x000100u //
|
||||
#define VS_RESERVED 0x000200u //
|
||||
#define VS_RESERVED 0x000400u //
|
||||
#define VS_RESERVED 0x000800u //
|
||||
#define VS_RESERVED 0x001000u //
|
||||
#define VS_RESERVED 0x002000u //
|
||||
#define VS_RESERVED 0x004000u //
|
||||
#define VS_RESERVED 0x008000u //
|
||||
#define VS_RESERVED 0x010000u //
|
||||
#define VS_RESERVED 0x020000u //
|
||||
#define VS_RESERVED 0x040000u //
|
||||
#define VS_RESERVED 0x080000u //
|
||||
#define VS_RESERVED 0x100000u //
|
||||
#define VS_RESERVED 0x200000u //
|
||||
#define VS_RESERVED 0x400000u //
|
||||
#define VS_RESERVED 0x800000u //
|
||||
*/
|
||||
|
||||
#define vs_is_nonblocking(vs) (((vs)->optflags & VS_OPT_FD_NONBLOCKING) != 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* An abstraction of a socket that operates between the application-exposed platform-sockets
|
||||
* and the network stack's representation of a protocol control structure. This object is used by
|
||||
* the POSIX socket emulation layer and stack drivers.
|
||||
*/
|
||||
class VirtualSocket
|
||||
{
|
||||
private:
|
||||
int _state = VS_STATE_INACTIVE;
|
||||
public:
|
||||
RingBuffer *TXbuf, *RXbuf;
|
||||
ZeroTier::Mutex _tx_m, _rx_m, _op_m;
|
||||
ZeroTier::PhySocket *sock = NULL;
|
||||
|
||||
void *pcb = NULL; // Protocol Control Block
|
||||
|
||||
#if defined(STACK_LWIP)
|
||||
int32_t optflags = 0;
|
||||
int linger;
|
||||
/*
|
||||
- TCP_WRITE_FLAG_COPY: indicates whether the new memory should be allocated
|
||||
for the data to be copied into. If this flag is not given, no new memory
|
||||
should be allocated and the data should only be referenced by pointer. This
|
||||
also means that the memory behind dataptr must not change until the data is
|
||||
ACKed by the remote host
|
||||
- TCP_WRITE_FLAG_MORE: indicates that more data follows. If this is omitted,
|
||||
the PSH flag is set in the last segment created by this call to tcp_write.
|
||||
If this flag is given, the PSH flag is not set.
|
||||
*/
|
||||
// copy as default, processed via pointer reference if set to 0. See notes in lwip_cb_sent() and lwip_Write()
|
||||
int8_t copymode = 1; // TCP_WRITE_FLAG_COPY;
|
||||
#endif
|
||||
struct sockaddr_storage local_addr; // address we've bound to locally
|
||||
struct sockaddr_storage peer_addr; // address of connection call to remote host
|
||||
int socket_family = 0;
|
||||
int socket_type = 0;
|
||||
int protocol = 0;
|
||||
int app_fd = 0; // used by app for I/O
|
||||
int sdk_fd = 0; // used by lib for I/O
|
||||
std::queue<VirtualSocket*> _AcceptedConnections;
|
||||
VirtualTap *tap = NULL;
|
||||
|
||||
/**
|
||||
* Sets the VirtualSocket's state value
|
||||
*/
|
||||
void apply_state(int state);
|
||||
|
||||
/**
|
||||
* Sets the VirtualSocket's state value
|
||||
*/
|
||||
void set_state(int state);
|
||||
/**
|
||||
* Gets the VirtualSocket's state value
|
||||
*/
|
||||
int get_state();
|
||||
|
||||
/**
|
||||
* default ctor
|
||||
*/
|
||||
VirtualSocket();
|
||||
|
||||
/**
|
||||
* dtor
|
||||
*/
|
||||
~VirtualSocket();
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _H
|
||||
1250
attic/VirtualSocketLayer.cpp
Normal file
1250
attic/VirtualSocketLayer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
443
attic/VirtualSocketLayer.h
Normal file
443
attic/VirtualSocketLayer.h
Normal file
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2018 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
|
||||
*
|
||||
* VirtualSocket management layer
|
||||
*/
|
||||
|
||||
#include "libztDefs.h"
|
||||
|
||||
namespace ZeroTier {
|
||||
class Mutex;
|
||||
struct InetAddress;
|
||||
}
|
||||
|
||||
class VirtualSocket;
|
||||
class VirtualTap;
|
||||
|
||||
extern ZeroTier::Mutex _multiplexer_lock;
|
||||
|
||||
VirtualSocket *get_virt_socket(int fd);
|
||||
int del_virt_socket(int fd);
|
||||
int add_unassigned_virt_socket(int fd, VirtualSocket *vs);
|
||||
int del_unassigned_virt_socket(int fd);
|
||||
int add_assigned_virt_socket(void *tap, VirtualSocket *vs, int fd);
|
||||
int del_assigned_virt_socket(void *tap, VirtualSocket *vs, int fd);
|
||||
//void *get_assigned_virtual_pair(int fd);
|
||||
|
||||
/**
|
||||
* @brief Stops all VirtualTap interfaces and associated I/O loops
|
||||
*
|
||||
* @usage For internal use only.
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void disableTaps();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a socket
|
||||
*
|
||||
* This function will return an integer which can be used in much the same way as a
|
||||
* typical file descriptor, however it is only valid for use with libzt library calls
|
||||
* as this is merely a facade which is associated with the internal socket representation
|
||||
* of both the network stacks and drivers.
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param socket_family Address family (AF_INET, AF_INET6)
|
||||
* @param socket_type Type of socket (SOCK_STREAM, SOCK_DGRAM, SOCK_RAW)
|
||||
* @param protocol Protocols supported on this socket
|
||||
* @return
|
||||
*/
|
||||
int virt_socket(int socket_family, int socket_type, int protocol);
|
||||
|
||||
/**
|
||||
* @brief Connect a socket to a remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Remote host address to connect to
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
int virt_connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* @brief Bind a socket to a virtual interface
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Local interface address to bind to
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
int virt_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* @brief Listen for incoming connections
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param backlog Number of backlogged connection allowed
|
||||
* @return
|
||||
*/
|
||||
int virt_listen(int fd, int backlog);
|
||||
|
||||
/**
|
||||
* @brief Accept an incoming connection
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Address of remote host for accepted connection
|
||||
* @param addrlen Length of address
|
||||
* @return
|
||||
*/
|
||||
int virt_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Accept an incoming connection
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Address of remote host for accepted connection
|
||||
* @param addrlen Length of address
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
#if defined(__linux__)
|
||||
int virt_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set socket options
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param level Protocol level to which option name should apply
|
||||
* @param optname Option name to set
|
||||
* @param optval Source of option value to set
|
||||
* @param optlen Length of option value
|
||||
* @return
|
||||
*/
|
||||
int virt_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
/**
|
||||
* @brief Get socket options
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param level Protocol level to which option name should apply
|
||||
* @param optname Option name to get
|
||||
* @param optval Where option value will be stored
|
||||
* @param optlen Length of value
|
||||
* @return
|
||||
*/
|
||||
int virt_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
|
||||
/**
|
||||
* @brief Get socket name
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Name associated with this socket
|
||||
* @param addrlen Length of name
|
||||
* @return
|
||||
*/
|
||||
int virt_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Get the peer name for the remote end of a connected socket
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param addr Name associated with remote end of this socket
|
||||
* @param addrlen Length of name
|
||||
* @return
|
||||
*/
|
||||
int virt_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Gets current hostname
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param name
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
int virt_gethostname(char *name, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Sets current hostname
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param name
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
int virt_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
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param name
|
||||
* @return Returns pointer to hostent structure otherwise NULL if failure
|
||||
*/
|
||||
struct hostent *virt_gethostbyname(const char *name);
|
||||
|
||||
/**
|
||||
* @brief Close a socket
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @return
|
||||
*/
|
||||
int virt_close(int fd);
|
||||
|
||||
/**
|
||||
* @brief Waits for one of a set of file descriptors to become ready to perform I/O.
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fds
|
||||
* @param nfds
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
#ifdef __linux__
|
||||
int virt_poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
#endif
|
||||
*/
|
||||
/**
|
||||
* @brief Monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready"
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param nfds
|
||||
* @param readfds
|
||||
* @param writefds
|
||||
* @param exceptfds
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
int virt_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
|
||||
/**
|
||||
* @brief Issue file control commands on a socket
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param cmd
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
int virt_fcntl(int fd, int cmd, int flags);
|
||||
|
||||
/**
|
||||
* @brief Control a device
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param request
|
||||
* @param argp
|
||||
* @return
|
||||
*/
|
||||
int virt_ioctl(int fd, unsigned long request, void *argp);
|
||||
|
||||
/**
|
||||
* @brief Send data to remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of data to write
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_send(int fd, const void *buf, size_t len, int flags);
|
||||
|
||||
/**
|
||||
* @brief Send data to remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of data to write
|
||||
* @param flags
|
||||
* @param addr Destination address
|
||||
* @param addrlen Length of destination address
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* @brief Send message to remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param msg
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_sendmsg(int fd, const struct msghdr *msg, int flags);
|
||||
|
||||
/**
|
||||
* @brief Receive data from remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of data buffer
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_recv(int fd, void *buf, size_t len, int flags);
|
||||
|
||||
/**
|
||||
* @brief Receive data from remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of data buffer
|
||||
* @param flags
|
||||
* @param addr
|
||||
* @param addrlen
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
/**
|
||||
* @brief Receive a message from remote host
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param msg
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
ssize_t virt_recvmsg(int fd, struct msghdr *msg,int flags);
|
||||
|
||||
/**
|
||||
* @brief Read bytes from socket onto buffer
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of data buffer to receive data
|
||||
* @return
|
||||
*/
|
||||
int virt_read(int fd, void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Write bytes from buffer to socket
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param buf Pointer to data buffer
|
||||
* @param len Length of buffer to write
|
||||
* @return
|
||||
*/
|
||||
int virt_write(int fd, const void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Shut down some aspect of a socket (read, write, or both)
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param fd File descriptor (only valid for use with libzt calls)
|
||||
* @param how Which aspects of the socket should be shut down
|
||||
* @return
|
||||
*/
|
||||
int virt_shutdown(int fd, int how);
|
||||
|
||||
/**
|
||||
* @brief Adds a DNS nameserver for the network stack to use
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param addr Address for DNS nameserver
|
||||
* @return
|
||||
*/
|
||||
int virt_add_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
/**
|
||||
* @brief Removes a DNS nameserver
|
||||
*
|
||||
* @usage Call this after virt_start() has succeeded
|
||||
* @param addr Address for DNS nameserver
|
||||
* @return
|
||||
*/
|
||||
int virt_del_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
/**
|
||||
* @brief Returns whether one can add a new socket or not. This depends on network stack in use.
|
||||
*
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @param socket_type
|
||||
* @return
|
||||
*/
|
||||
bool virt_can_provision_new_socket(int socket_type);
|
||||
|
||||
/**
|
||||
* @brief Returns the number of VirtualSockets either already provisioned or waiting to be
|
||||
* Some network stacks may have a limit on the number of sockets that they can
|
||||
* safely handle due to timer construction, this is a way to check that we
|
||||
* haven't passed that limit. Someday if multiple stacks are used simultaneously
|
||||
* the logic for this function should change accordingly.
|
||||
*
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @return
|
||||
*/
|
||||
int virt_num_active_sockets();
|
||||
|
||||
/**
|
||||
* @brief Return the maximum number of sockets allowable by platform/stack configuration
|
||||
*
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @param socket_type
|
||||
* @return
|
||||
*/
|
||||
int virt_maxsockets(int socket_type);
|
||||
|
||||
/**
|
||||
* @brief Return the number of currently active picoTCP timers
|
||||
*
|
||||
* @usage Call this after zts_start() has succeeded
|
||||
* @return
|
||||
*/
|
||||
//int pico_ntimers();
|
||||
|
||||
/**
|
||||
* @brief Convert a struct sockaddr to a ZeroTier::InetAddress
|
||||
*
|
||||
* @usage For internal use only.
|
||||
* @param socket_family
|
||||
* @param addr
|
||||
* @param inet
|
||||
* @return
|
||||
*/
|
||||
void sockaddr2inet(int socket_family, const struct sockaddr *addr, ZeroTier::InetAddress *inet);
|
||||
|
||||
1979
attic/picoTCP.cpp
Normal file
1979
attic/picoTCP.cpp
Normal file
File diff suppressed because it is too large
Load Diff
222
attic/picoTCP.h
Normal file
222
attic/picoTCP.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2018 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.
|
||||
*/
|
||||
|
||||
#ifndef ZT_PICOTCP_HPP
|
||||
#define ZT_PICOTCP_HPP
|
||||
/*
|
||||
#include "pico_eth.h"
|
||||
#include "pico_stack.h"
|
||||
#include "pico_ipv4.h"
|
||||
#include "pico_icmp4.h"
|
||||
#include "pico_dev_tap.h"
|
||||
#include "pico_protocol.h"
|
||||
#include "pico_socket.h"
|
||||
#include "pico_device.h"
|
||||
#include "pico_ipv6.h"
|
||||
*/
|
||||
|
||||
struct pico_socket;
|
||||
class VirtualSocket;
|
||||
class VirtualTap;
|
||||
|
||||
#include "VirtualTap.h"
|
||||
|
||||
/****************************************************************************/
|
||||
/* PicoTCP API Signatures (See libzt.h for the application-facing API) */
|
||||
/****************************************************************************/
|
||||
|
||||
#define PICO_IPV4_TO_STRING_SIG char *ipbuf, const uint32_t ip
|
||||
#define PICO_TAP_CREATE_SIG char *name
|
||||
#define PICO_IPV4_LINK_ADD_SIG struct pico_device *dev, struct pico_ip4 address, struct pico_ip4 netmask
|
||||
#define PICO_DEVICE_INIT_SIG struct pico_device *dev, const char *name, uint8_t *mac
|
||||
#define PICO_STACK_RECV_SIG struct pico_device *dev, uint8_t *buffer, uint32_t len
|
||||
#define PICO_ICMP4_PING_SIG char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp4_stats *)
|
||||
#define PICO_TIMER_ADD_SIG pico_time expire, void (*timer)(pico_time, void *), void *arg
|
||||
#define PICO_STRING_TO_IPV4_SIG const char *ipstr, uint32_t *ip
|
||||
#define PICO_STRING_TO_IPV6_SIG const char *ipstr, uint8_t *ip
|
||||
#define PICO_SOCKET_SETOPTION_SIG struct pico_socket *s, int option, void *value
|
||||
#define PICO_SOCKET_SEND_SIG struct pico_socket *s, const void *buf, int len
|
||||
#define PICO_SOCKET_SENDTO_SIG struct pico_socket *s, const void *buf, int len, void *dst, uint16_t remote_port
|
||||
#define PICO_SOCKET_RECV_SIG struct pico_socket *s, void *buf, int len
|
||||
#define PICO_SOCKET_RECVFROM_SIG struct pico_socket *s, void *buf, int len, void *orig, uint16_t *remote_port
|
||||
#define PICO_SOCKET_OPEN_SIG uint16_t net, uint16_t proto, void (*wakeup)(uint16_t ev, struct pico_socket *s)
|
||||
#define PICO_SOCKET_BIND_SIG struct pico_socket *s, void *local_addr, uint16_t *port
|
||||
#define PICO_SOCKET_CONNECT_SIG struct pico_socket *s, const void *srv_addr, uint16_t remote_port
|
||||
#define PICO_SOCKET_LISTEN_SIG struct pico_socket *s, const int backlog
|
||||
#define PICO_SOCKET_READ_SIG struct pico_socket *s, void *buf, int len
|
||||
#define PICO_SOCKET_WRITE_SIG struct pico_socket *s, const void *buf, int len
|
||||
#define PICO_SOCKET_CLOSE_SIG struct pico_socket *s
|
||||
#define PICO_SOCKET_SHUTDOWN_SIG struct pico_socket *s, int mode
|
||||
#define PICO_SOCKET_ACCEPT_SIG struct pico_socket *s, void *orig, uint16_t *port
|
||||
#define PICO_IPV6_LINK_ADD_SIG struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask
|
||||
#define PICO_IPV4_ROUTE_ADD_SIG struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link
|
||||
#define PICO_IPV4_ROUTE_DEL_SIG struct pico_ip4 address, struct pico_ip4 netmask, int metric
|
||||
#define PICO_IPV6_ROUTE_ADD_SIG struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link
|
||||
#define PICO_IPV6_ROUTE_DEL_SIG struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link
|
||||
#define PICO_DNS_CLIENT_NAMESERVER_SIG pico_ip4*, unsigned char
|
||||
|
||||
/**
|
||||
* Send raw frames from the stack to the ZeroTier virtual wire
|
||||
*/
|
||||
int rd_pico_eth_tx(struct pico_device *dev, void *buf, int len);
|
||||
|
||||
/**
|
||||
* Read raw frames from RX frame buffer into the stack
|
||||
*/
|
||||
int rd_pico_eth_poll(struct pico_device *dev, int loop_score);
|
||||
|
||||
/**
|
||||
* Set up an interface in the network stack for the VirtualTap
|
||||
*/
|
||||
bool pico_init_interface(VirtualTap *tap);
|
||||
|
||||
/**
|
||||
* Register an address with the stack
|
||||
*/
|
||||
bool pico_register_address(VirtualTap *tap, const InetAddress &ip);
|
||||
|
||||
/**
|
||||
* Adds a route to the picoTCP device
|
||||
*/
|
||||
bool rd_pico_route_add(VirtualTap *tap, const InetAddress &addr, const InetAddress &nm, const InetAddress &gw, int metric);
|
||||
|
||||
/**
|
||||
* Deletes a route from the picoTCP device
|
||||
*/
|
||||
bool rd_pico_route_del(VirtualTap *tap, const InetAddress &addr, const InetAddress &nm, int metric);
|
||||
|
||||
/**
|
||||
* Registers a DNS nameserver with the network stack
|
||||
*/
|
||||
int rd_pico_add_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
/**
|
||||
* Un-registers a DNS nameserver from the network stack
|
||||
*/
|
||||
int rd_pico_del_dns_nameserver(struct sockaddr *addr);
|
||||
|
||||
/**
|
||||
* Main stack loop
|
||||
*/
|
||||
void rd_pico_loop(VirtualTap *tap);
|
||||
|
||||
/**
|
||||
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
||||
*/
|
||||
void rd_pico_cb_tcp_read(VirtualTap *tap, struct pico_socket *s);
|
||||
|
||||
/**
|
||||
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
||||
*/
|
||||
void rd_pico_cb_udp_read(VirtualTap *tap, struct pico_socket *s);
|
||||
|
||||
/**
|
||||
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
||||
*/
|
||||
void rd_pico_cb_tcp_write(VirtualTap *tap, struct pico_socket *s);
|
||||
|
||||
/**
|
||||
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
||||
*/
|
||||
void rd_pico_cb_socket_ev(uint16_t ev, struct pico_socket *s);
|
||||
|
||||
/**
|
||||
* Packets from the ZeroTier virtual wire enter the stack here
|
||||
*/
|
||||
void rd_pico_eth_rx(VirtualTap *tap, const ZeroTier::MAC &from, const ZeroTier::MAC &to,
|
||||
unsigned int etherType, const void *data, unsigned int len);
|
||||
|
||||
/**
|
||||
* Creates a stack-specific "socket" or "VirtualSocket object"
|
||||
*/
|
||||
int rd_pico_socket(struct pico_socket **p, int socket_family, int socket_type, int protocol);
|
||||
|
||||
/**
|
||||
* Connect to remote host via userspace network stack interface - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_connect(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* Bind to a userspace network stack interface - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_bind(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* Listen for incoming VirtualSockets - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_listen(VirtualSocket *vs, int backlog);
|
||||
|
||||
/**
|
||||
* Accept an incoming VirtualSocket - Called from VirtualTap
|
||||
*/
|
||||
VirtualSocket* rd_pico_accept(VirtualSocket *vs);
|
||||
|
||||
/**
|
||||
* Read from RX buffer to application - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_read(VirtualTap *tap, ZeroTier::PhySocket *sock, VirtualSocket *vs, bool stack_invoked);
|
||||
|
||||
/**
|
||||
* Write to userspace network stack - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_write(VirtualSocket *vs, void *data, ssize_t len);
|
||||
|
||||
/**
|
||||
* Close a VirtualSocket - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_close(VirtualSocket *vs);
|
||||
|
||||
/**
|
||||
* Shuts down some aspect of a VirtualSocket - Called from VirtualTap
|
||||
*/
|
||||
int rd_pico_shutdown(VirtualSocket *vs, int how);
|
||||
|
||||
/**
|
||||
* Sets a property of a socket
|
||||
*/
|
||||
int rd_pico_setsockopt(VirtualSocket *vs, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
/**
|
||||
* Gets a property of a socket
|
||||
*/
|
||||
int rd_pico_getsockopt(VirtualSocket *vs, int level, int optname, void *optval, socklen_t *optlen);
|
||||
|
||||
/**
|
||||
* Converts a pico_err to its most closely-related errno, and sets errno
|
||||
*/
|
||||
int map_pico_err_to_errno(int err);
|
||||
|
||||
/**
|
||||
* Converts picoTCP error codes to pretty string
|
||||
*/
|
||||
char *beautify_pico_error(int err);
|
||||
|
||||
/**
|
||||
* Converts picoTCP socket states into pretty string
|
||||
*/
|
||||
char *beautify_pico_state(int state);
|
||||
|
||||
#endif // _H
|
||||
Reference in New Issue
Block a user