From 350cc480493de5859c512b9963a81c332e53d157 Mon Sep 17 00:00:00 2001
From: Moritz Warning <moritzwarning@web.de>
Date: Thu, 4 May 2017 23:25:51 +0200
Subject: [PATCH] zerotier: update to version 1.2.4

Zerotier now needs to have libstd, libminiupnpc and libnatpmp.

Signed-off-by: Moritz Warning <moritzwarning@web.de>
---
 net/zerotier/Config.in                        | 12 +---
 net/zerotier/Makefile                         | 23 +++-----
 ...TIFY_SOURCE-from-being-defined-twice.patch | 28 ---------
 ...external-libminiupnpc-and-libnatpmp.patch} | 59 ++++++++-----------
 .../patches/0002-pin-target-to-linux.patch    | 24 ++++++++
 5 files changed, 59 insertions(+), 87 deletions(-)
 delete mode 100644 net/zerotier/patches/0001-prevent-D_FORTIFY_SOURCE-from-being-defined-twice.patch
 rename net/zerotier/patches/{0002-make-natpmp-miniupnpc-configurable.patch => 0001-use-external-libminiupnpc-and-libnatpmp.patch} (56%)
 create mode 100644 net/zerotier/patches/0002-pin-target-to-linux.patch

diff --git a/net/zerotier/Config.in b/net/zerotier/Config.in
index bf38b0bca..e08ec7570 100644
--- a/net/zerotier/Config.in
+++ b/net/zerotier/Config.in
@@ -6,18 +6,8 @@ config ZEROTIER_ENABLE_DEBUG
 	depends on PACKAGE_zerotier
 	default n
 
-config ZEROTIER_ENABLE_PORTMAPPING
-	bool "Build with MiniUPnPc and NAT-PMP support"
-	depends on PACKAGE_zerotier
-	default n
-
-config ZEROTIER_ENABLE_CLUSTER
-	bool "Build with cluster support"
-	depends on PACKAGE_zerotier
-	default n
-
 config ZEROTIER_ENABLE_SELFTEST
-	bool "Build self test program"
+	bool "Build a self test program"
 	depends on PACKAGE_zerotier
 	default n
 
diff --git a/net/zerotier/Makefile b/net/zerotier/Makefile
index c2443f520..6284f1038 100644
--- a/net/zerotier/Makefile
+++ b/net/zerotier/Makefile
@@ -6,17 +6,17 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=zerotier
-PKG_VERSION:=1.2.2
-PKG_RELEASE:=4
+PKG_VERSION:=1.2.4
+PKG_RELEASE:=1
 
 PKG_LICENSE:=GPL-3.0
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://github.com/zerotier/ZeroTierOne
 PKG_SOURCE_SUBDIR:=ZeroTierOne-$(PKG_VERSION)
-PKG_SOURCE_VERSION:=cfe0d0971f3ce5972d955250dc1ff6ec7a30e3f7
+PKG_SOURCE_VERSION:=fe5257df81c4ec4b5d48f707eb794de0748b7ac0
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
-PKG_MIRROR_MD5SUM:=c8c3219c995a59161832d580a194f6280de7a4eef75cebece6f38400b64f003e
+PKG_MIRROR_HASH:=131436529d26f8eb975a0a8705b489cc22a1139c323755895c1776db579003bc
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_SUBDIR)
 
 PKG_BUILD_PARALLEL:=1
@@ -25,7 +25,7 @@ include $(INCLUDE_DIR)/package.mk
 define Package/zerotier
   SECTION:=net
   CATEGORY:=Network
-  DEPENDS:=+libpthread +kmod-tun +ip +libstdcpp +ZEROTIER_ENABLE_PORTMAPPING:libminiupnpc +ZEROTIER_ENABLE_PORTMAPPING:libnatpmp
+  DEPENDS:=+libpthread +libstdcpp +kmod-tun +ip +libminiupnpc +libnatpmp
   TITLE:=Create flat virtual Ethernet networks of almost unlimited size
   URL:=https://www.zerotier.com
   SUBMENU:=VPN
@@ -40,18 +40,13 @@ define Package/zerotier/config
 	source "$(SOURCE)/Config.in"
 endef
 
-ifeq ($(CONFIG_ZEROTIER_ENABLE_CLUSTER),y)
-MAKE_FLAGS += ZT_ENABLE_CLUSTER=1
-endif
-
-ifeq ($(CONFIG_ZEROTIER_ENABLE_PORTMAPPING),y)
-MAKE_FLAGS += ZT_ENABLE_PORTMAPPING=1
-endif
-
 ifeq ($(CONFIG_ZEROTIER_ENABLE_DEBUG),y)
-TARGET_CXXFLAGS += -DZT_TRACE -ggdb3
+MAKE_FLAGS += ZT_DEBUG=1
 endif
 
+MAKE_FLAGS += \
+	DEFS="" \
+
 define Build/Compile
 	$(call Build/Compile/Default,one)
 ifeq ($(CONFIG_ZEROTIER_ENABLE_SELFTEST),y)
diff --git a/net/zerotier/patches/0001-prevent-D_FORTIFY_SOURCE-from-being-defined-twice.patch b/net/zerotier/patches/0001-prevent-D_FORTIFY_SOURCE-from-being-defined-twice.patch
deleted file mode 100644
index fe9d04acc..000000000
--- a/net/zerotier/patches/0001-prevent-D_FORTIFY_SOURCE-from-being-defined-twice.patch
+++ /dev/null
@@ -1,28 +0,0 @@
-From 4fd495fca8417a8fd4405951d1eee80f345eaf9b Mon Sep 17 00:00:00 2001
-From: Moritz Warning <moritzwarning@web.de>
-Date: Sun, 19 Mar 2017 01:13:14 +0100
-Subject: [PATCH 1/2] prevent D_FORTIFY_SOURCE from being defined twice
-
----
- make-linux.mk | 3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
-
-diff --git a/make-linux.mk b/make-linux.mk
-index 7c77f58f..508d8c42 100644
---- a/make-linux.mk
-+++ b/make-linux.mk
-@@ -8,9 +8,10 @@ ifeq ($(origin CXX),default)
- endif
- 
- INCLUDES?=
--DEFS?=-D_FORTIFY_SOURCE=2
-+DEFS?=
- LDLIBS?=
- DESTDIR?=
-+ZT_ENABLE_PORTMAPPING?=0
- 
- include objects.mk
- 
--- 
-2.12.0
-
diff --git a/net/zerotier/patches/0002-make-natpmp-miniupnpc-configurable.patch b/net/zerotier/patches/0001-use-external-libminiupnpc-and-libnatpmp.patch
similarity index 56%
rename from net/zerotier/patches/0002-make-natpmp-miniupnpc-configurable.patch
rename to net/zerotier/patches/0001-use-external-libminiupnpc-and-libnatpmp.patch
index 1ec8ea8ed..e65d7eca0 100644
--- a/net/zerotier/patches/0002-make-natpmp-miniupnpc-configurable.patch
+++ b/net/zerotier/patches/0001-use-external-libminiupnpc-and-libnatpmp.patch
@@ -1,26 +1,26 @@
-From b8390696d81f66109560d12046bb63b9704e07f3 Mon Sep 17 00:00:00 2001
+From 61b69f74fecf3c34c0fd2003897c92790ca5a9f5 Mon Sep 17 00:00:00 2001
 From: Moritz Warning <moritzwarning@web.de>
-Date: Sun, 19 Mar 2017 01:14:10 +0100
-Subject: [PATCH 2/2] make natpmp/miniupnpc configurable
+Date: Thu, 4 May 2017 22:13:55 +0200
+Subject: [PATCH 1/2] use external libminiupnpc and libnatpmp
 
-also include staging_dir variable in the search paths
 ---
- make-linux.mk | 32 ++++++++++++++++++--------------
- 1 file changed, 18 insertions(+), 14 deletions(-)
+ make-linux.mk | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
 
 diff --git a/make-linux.mk b/make-linux.mk
-index 508d8c42..36060857 100644
+index 87d29af..f5b3d8d 100644
 --- a/make-linux.mk
 +++ b/make-linux.mk
-@@ -22,20 +22,24 @@ OBJS+=ext/http-parser/http_parser.o
- # Auto-detect miniupnpc and nat-pmp as well and use system libs if present,
+@@ -22,20 +22,20 @@ OBJS+=ext/http-parser/http_parser.o
  # otherwise build into binary as done on Mac and Windows.
  OBJS+=osdep/PortMapper.o
--DEFS+=-DZT_USE_MINIUPNPC
+ DEFS+=-DZT_USE_MINIUPNPC
 -MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' /usr/include/miniupnpc/miniupnpc.h && echo 1)
 -ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
--	DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
--	LDLIBS+=-lminiupnpc
++#MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' /usr/include/miniupnpc/miniupnpc.h && echo 1)
++#ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
+ 	DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
+ 	LDLIBS+=-lminiupnpc
 -else
 -	DEFS+=-DMINIUPNP_STATICLIB -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DOS_STRING=\"Linux\" -DMINIUPNPC_VERSION_STRING=\"2.0\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
 -	OBJS+=ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o
@@ -28,29 +28,20 @@ index 508d8c42..36060857 100644
 -ifeq ($(wildcard /usr/include/natpmp.h),)
 -	OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
 -else
--	LDLIBS+=-lnatpmp
--	DEFS+=-DZT_USE_SYSTEM_NATPMP
-+
-+ifeq ($(ZT_ENABLE_PORTMAPPING),1)
-+	DEFS+=-DZT_USE_MINIUPNPC
-+	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
-+	else
-+		DEFS+=-DMINIUPNP_STATICLIB -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DOS_STRING=\"Linux\" -DMINIUPNPC_VERSION_STRING=\"2.0\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
-+		OBJS+=ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o
-+	endif
-+
-+	ifeq ($(wildcard $(STAGING_DIR)/usr/include/natpmp.h),)
-+		OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
-+	else
-+		LDLIBS+=-lnatpmp
-+		DEFS+=-DZT_USE_SYSTEM_NATPMP
-+	endif
- endif
++#else
++#	DEFS+=-DMINIUPNP_STATICLIB -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DOS_STRING=\"Linux\" -DMINIUPNPC_VERSION_STRING=\"2.0\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
++#	OBJS+=ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o
++#endif
++#ifeq ($(wildcard /usr/include/natpmp.h),)
++#	OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
++#else
+ 	LDLIBS+=-lnatpmp
+ 	DEFS+=-DZT_USE_SYSTEM_NATPMP
+-endif
++#endif
  
  ifeq ($(ZT_ENABLE_CLUSTER),1)
+ 	DEFS+=-DZT_ENABLE_CLUSTER
 -- 
-2.12.0
+2.1.4
 
diff --git a/net/zerotier/patches/0002-pin-target-to-linux.patch b/net/zerotier/patches/0002-pin-target-to-linux.patch
new file mode 100644
index 000000000..48459dd8f
--- /dev/null
+++ b/net/zerotier/patches/0002-pin-target-to-linux.patch
@@ -0,0 +1,24 @@
+From b8a0598002fd08618d20cd1bbfb03559435241a8 Mon Sep 17 00:00:00 2001
+From: Moritz Warning <moritzwarning@web.de>
+Date: Thu, 4 May 2017 22:35:58 +0200
+Subject: [PATCH 2/2] pin target to linux
+
+---
+ Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Makefile b/Makefile
+index 9511862..d5b0dfc 100644
+--- a/Makefile
++++ b/Makefile
+@@ -1,6 +1,6 @@
+ # Common makefile -- loads make rules for each platform
+ 
+-OSTYPE=$(shell uname -s)
++OSTYPE=Linux
+ 
+ ifeq ($(OSTYPE),Darwin)
+ 	include make-mac.mk
+-- 
+2.1.4
+