--- /dev/null
+menu "Configuration"
+ depends on PACKAGE_zerotier
+
+config ZEROTIER_ENABLE_DEBUG
+ bool "Build in debug mode"
+ depends on PACKAGE_zerotier
+ default n
+
+config ZEROTIER_USE_MINIUPNPC
+ bool "Build with MiniUPnPc"
+ depends on PACKAGE_zerotier
+ default n
+
+config ZEROTIER_ENABLE_NETWORK_CONTROLLER
+ bool "Build with network controller"
+ depends on PACKAGE_zerotier
+ default n
+
+config ZEROTIER_ENABLE_SELFTEST
+ bool "Build a self test program"
+ depends on PACKAGE_zerotier
+ default n
+
+endmenu
--- /dev/null
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=zerotier
+PKG_VERSION:=1.1.14
+PKG_RELEASE:=4
+
+PKG_LICENSE:=GPL-3.0
+
+PKG_SOURCE:=$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/zerotier/ZeroTierOne/archive/
+PKG_SOURCE_SUBDIR:=ZeroTierOne-$(PKG_VERSION)
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_SUBDIR)
+PKG_MD5SUM:=5e381f0864797886b3b3bf20beb49bba
+
+PKG_BUILD_DEPENDS:=uclibcxx
+PKG_BUILD_PARALLEL:=1
+include $(INCLUDE_DIR)/package.mk
+
+define Package/zerotier
+ SECTION:=net
+ CATEGORY:=Network
+ DEPENDS:=+libpthread +kmod-tun +ip +ZEROTIER_ENABLE_NETWORK_CONTROLLER:libsqlite3 +ZEROTIER_USE_MINIUPNPC:libminiupnpc +ZEROTIER_USE_MINIUPNPC:libnatpmp
+ TITLE:=Create flat virtual Ethernet networks of almost unlimited size
+ URL:=https://www.zerotier.com
+ SUBMENU:=VPN
+ MAINTAINER:=Moritz Warning <moritzwarning@web.de>
+endef
+
+define Package/zerotier/description
+ ZeroTier creates a global provider-independent virtual private cloud network.
+endef
+
+define Package/zerotier/config
+ source "$(SOURCE)/Config.in"
+endef
+
+ifeq ($(CONFIG_ZEROTIER_ENABLE_NETWORK_CONTROLLER),y)
+MAKE_FLAGS += ZT_ENABLE_NETWORK_CONTROLLER=1
+MAKE_FLAGS += LDLIBS+=" -lsqlite3 "
+endif
+
+ifeq ($(CONFIG_ZEROTIER_USE_MINIUPNPC),y)
+MAKE_FLAGS += ZT_USE_MINIUPNPC=1
+endif
+
+ifeq ($(CONFIG_ZEROTIER_ENABLE_DEBUG),y)
+TARGET_CXXFLAGS += -DZT_TRACE -ggdb3
+endif
+
+MAKE_FLAGS += \
+ DEFS="" \
+ LDFLAGS+=" -L$(STAGING_DIR)/usr/lib/uClibc++ -pthread " \
+ LDLIBS+=" -fno-builtin -nodefaultlibs -Wl,-Bstatic -luClibc++ -Wl,-Bdynamic -lpthread -lm -lc -lsupc++ -lc -lgcc -lgcc_eh -lgcc_s -lssp_nonshared " \
+ CXXFLAGS+=" -fno-builtin -nostdinc++ -I$(STAGING_DIR)/usr/include/uClibc++ -DGCC_HASCLASSVISIBILITY -Wall -fPIE -fvisibility=hidden "
+
+define Build/Compile
+ $(call Build/Compile/Default,one)
+ifeq ($(CONFIG_ZEROTIER_ENABLE_SELFTEST),y)
+ $(call Build/Compile/Default,selftest)
+endif
+endef
+
+define Package/zerotier/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/zerotier-one $(1)/usr/bin/
+ $(LN) zerotier-one $(1)/usr/bin/zerotier-cli
+ $(LN) zerotier-one $(1)/usr/bin//zerotier-idtool
+
+ifeq ($(CONFIG_ZEROTIER_ENABLE_SELFTEST),y)
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/zerotier-selftest $(1)/usr/bin/
+endif
+
+ $(INSTALL_DIR) $(1)/etc/init.d/
+ $(INSTALL_BIN) files/zerotier.init $(1)/etc/init.d/zerotier
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) files/zerotier.config $(1)/etc/config/zerotier
+endef
+
+$(eval $(call BuildPackage,zerotier))
+
--- /dev/null
+
+config zerotier sample_config
+ option enabled 1
+ option interface 'wan' # restart ZT when wan status changed
+ #option port '9993'
+ option secret 'generate' # generate secret on first start
+ list join '8056c2e21c000001' # a public network called Earth
--- /dev/null
+#!/bin/sh /etc/rc.common
+
+START=90
+
+USE_PROCD=1
+
+LIST_SEP="
+"
+ZT_COMMAND=/usr/bin/zerotier-one
+
+section_enabled() {
+ config_get_bool enabled "$1" 'enabled' 0
+ [ $enabled -gt 0 ]
+}
+
+start_instance() {
+ local cfg="$1"
+ local port secret interface
+ local ARGS=""
+
+ section_enabled "$cfg" || return 1
+
+ mkdir -p /var/lib/zerotier-one/networks.d/
+
+ config_get_bool port $cfg 'port'
+ config_get secret $cfg 'secret'
+ config_get interface $cfg 'interface'
+
+ if [ -n "$port" ]; then
+ ARGS="$ARGS -p$port"
+ fi
+
+ if [ "$secret" = "generate" ]; then
+ echo "Generate secret - please wait..."
+ local tmp="/tmp/zt.$cfg.secret"
+ zerotier-idtool generate "$tmp" > /dev/null
+ secret="$(cat $tmp)"
+ rm "$tmp"
+
+ uci set zerotier.$cfg.secret="$secret"
+ uci commit zerotier
+ fi
+
+ if [ -n "$secret" ]; then
+ echo "$secret" > /var/lib/zerotier-one/identity.secret
+ #make sure there is not previous dentity.public
+ rm -f /var/lib/zerotier-one/identity.public
+ fi
+
+ add_join() {
+ #an (empty) config file will cause ZT to join a network
+ touch /var/lib/zerotier-one/networks.d/$1.conf
+ }
+
+ config_list_foreach $cfg 'join' add_join
+
+ procd_open_instance
+ procd_add_reload_interface_trigger "$interface"
+ procd_set_param command $ZT_COMMAND $ARGS
+ procd_set_param nice -10
+ procd_close_instance
+}
+
+service_triggers() {
+ procd_add_reload_trigger zerotier
+}
+
+start_service() {
+ config_load 'zerotier'
+ config_foreach start_instance 'zerotier'
+}
--- /dev/null
+From 830250759cd4c14ca2ae5ddf24f0a0427f258622 Mon Sep 17 00:00:00 2001
+From: Adam Ierymenko <adam.ierymenko@gmail.com>
+Date: Tue, 26 Jul 2016 16:36:20 -0700
+Subject: [PATCH 1/2] Fix for running under MUSL libc (e.g. Alpine Linux)
+
+---
+ osdep/Thread.hpp | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/osdep/Thread.hpp b/osdep/Thread.hpp
+index 7fb38d8..4f90dc0 100644
+--- a/osdep/Thread.hpp
++++ b/osdep/Thread.hpp
+@@ -125,6 +125,10 @@ public:
+ throw()\r
+ {\r
+ memset(&_tid,0,sizeof(_tid));\r
++ pthread_attr_init(&_tattr);\r
++#ifdef __LINUX__\r
++ pthread_attr_setstacksize(&_tattr,8388608); // for MUSL libc and others, has no effect in normal glibc environments\r
++#endif\r
+ _started = false;\r
+ }\r
+ \r
+@@ -157,7 +161,7 @@ public:
+ {\r
+ Thread t;\r
+ t._started = true;\r
+- if (pthread_create(&t._tid,(const pthread_attr_t *)0,&___zt_threadMain<C>,instance))\r
++ if (pthread_create(&t._tid,&t._tattr,&___zt_threadMain<C>,instance))\r
+ throw std::runtime_error("pthread_create() failed, unable to create thread");\r
+ return t;\r
+ }\r
+@@ -184,6 +188,7 @@ public:
+ \r
+ private:\r
+ pthread_t _tid;\r
++ pthread_attr_t _tattr;\r
+ volatile bool _started;\r
+ };\r
+ \r
+--
+2.9.0
+
--- /dev/null
+From 333bbabc6dfad0553fb63d560ab6442a50cc9e52 Mon Sep 17 00:00:00 2001
+From: Moritz Warning <moritzwarning@web.de>
+Date: Fri, 22 Jul 2016 23:27:31 +0200
+Subject: [PATCH 2/2] fix build
+
+---
+ make-linux.mk | 30 +++++++++++++++---------------
+ 1 file changed, 15 insertions(+), 15 deletions(-)
+
+Index: ZeroTierOne-1.1.14/make-linux.mk
+===================================================================
+--- ZeroTierOne-1.1.14.orig/make-linux.mk
++++ ZeroTierOne-1.1.14/make-linux.mk
+@@ -39,19 +39,19 @@ include objects.mk
+
+ # On Linux we auto-detect the presence of some libraries and if present we
+ # link against the system version. This works with our package build images.
+-ifeq ($(wildcard /usr/include/lz4.h),)
++ifeq ($(wildcard $(STAGING_DIR)/usr/include/lz4.h),)
+ OBJS+=ext/lz4/lz4.o
+ else
+ LDLIBS+=-llz4
+ DEFS+=-DZT_USE_SYSTEM_LZ4
+ endif
+-ifeq ($(wildcard /usr/include/http_parser.h),)
++ifeq ($(wildcard $(STAGING_DIR)/usr/include/http_parser.h),)
+ OBJS+=ext/http-parser/http_parser.o
+ else
+ LDLIBS+=-lhttp_parser
+ DEFS+=-DZT_USE_SYSTEM_HTTP_PARSER
+ endif
+-ifeq ($(wildcard /usr/include/json-parser/json.h),)
++ifeq ($(wildcard $(STAGING_DIR)/usr/include/json-parser/json.h),)
+ OBJS+=ext/json-parser/json.o
+ else
+ LDLIBS+=-ljsonparser
--- /dev/null
+From 21f4958bd48cae59b478b1b3445e00fa4fb18991 Mon Sep 17 00:00:00 2001
+From: muebau <muebau@gmail.com>
+Date: Fri, 5 Aug 2016 19:22:45 +0200
+Subject: [PATCH] OpenWRT workaround to avoid seg faults
+
+---
+ service/OneService.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/service/OneService.cpp b/service/OneService.cpp
+index 13820f5..9ba3238 100644
+--- a/service/OneService.cpp
++++ b/service/OneService.cpp
+@@ -862,8 +862,8 @@ public:
+ }
+
+ // Start two background threads to handle expensive ops out of line
+- Thread::start(_node);
+- Thread::start(_node);
++ //Thread::start(_node);
++ //Thread::start(_node);
+
+ _nextBackgroundTaskDeadline = 0;
+ uint64_t clockShouldBe = OSUtils::now();
+--
+2.7.4
+
--- /dev/null
+Index: ZeroTierOne-1.1.14/make-linux.mk
+===================================================================
+--- ZeroTierOne-1.1.14.orig/make-linux.mk
++++ ZeroTierOne-1.1.14/make-linux.mk
+@@ -64,7 +64,7 @@ ifeq ($(ZT_USE_MINIUPNPC),1)
+ DEFS+=-DZT_USE_MINIUPNPC
+
+ # Auto-detect libminiupnpc at least v2.0
+- MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' /usr/include/miniupnpc/miniupnpc.h && echo 1)
++ MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' $(STAGING_DIR)/usr/include/miniupnpc/miniupnpc.h && echo 1)
+ ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
+ DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
+ LDLIBS+=-lminiupnpc
+@@ -74,7 +74,7 @@ ifeq ($(ZT_USE_MINIUPNPC),1)
+ endif
+
+ # Auto-detect libnatpmp
+- ifeq ($(wildcard /usr/include/natpmp.h),)
++ ifeq ($(wildcard $(STAGING_DIR)/usr/include/natpmp.h),)
+ OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
+ else
+ LDLIBS+=-lnatpmp
+Index: ZeroTierOne-1.1.14/osdep/PortMapper.cpp
+===================================================================
+--- ZeroTierOne-1.1.14.orig/osdep/PortMapper.cpp
++++ ZeroTierOne-1.1.14/osdep/PortMapper.cpp
+@@ -180,7 +180,7 @@ public:
+ struct IGDdatas data;
+
+ int upnpError = 0;
+- UPNPDev *devlist = upnpDiscoverAll(5000,(const char *)0,(const char *)0,0,0,2,&upnpError);
++ UPNPDev *devlist = upnpDiscoverAll(5000,(const char *)0,(const char *)0,0,0,&upnpError);
+ if (devlist) {
+
+ #ifdef ZT_PORTMAPPER_TRACE