Browse Source

Merge of netcon with edge and unification of make processes.

Adam Ierymenko 9 years ago
parent
commit
425d311ce8

+ 1 - 0
.gitignore

@@ -54,6 +54,7 @@ Thumbs.db
 *.rpm
 *.rpm
 *.autosave
 *.autosave
 *.tmp
 *.tmp
+.depend
 node_modules
 node_modules
 cluster-geo/cluster-geo/config.js
 cluster-geo/cluster-geo/config.js
 cluster-geo/cluster-geo/cache.*
 cluster-geo/cluster-geo/cache.*

+ 6 - 6
make-freebsd.mk

@@ -6,21 +6,21 @@ DEFS=
 LIBS=
 LIBS=
 
 
 include objects.mk
 include objects.mk
-OBJS+=osdep/BSDEthernetTap.o 
+OBJS+=osdep/BSDEthernetTap.o
 
 
 # "make official" is a shortcut for this
 # "make official" is a shortcut for this
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
-	DEFS+=-DZT_OFFICIAL_RELEASE 
+	DEFS+=-DZT_OFFICIAL_RELEASE
 endif
 endif
 
 
 # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
 # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
 ifeq ($(ZT_ENABLE_CLUSTER),1)
 ifeq ($(ZT_ENABLE_CLUSTER),1)
-        DEFS+=-DZT_ENABLE_CLUSTER
+	DEFS+=-DZT_ENABLE_CLUSTER
 endif
 endif
 
 
 # "make debug" is a shortcut for this
 # "make debug" is a shortcut for this
 ifeq ($(ZT_DEBUG),1)
 ifeq ($(ZT_DEBUG),1)
-	DEFS+=-DZT_TRACE 
+	DEFS+=-DZT_TRACE
 	CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
 	CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
 	LDFLAGS+=
 	LDFLAGS+=
 	STRIP=echo
 	STRIP=echo
@@ -38,8 +38,8 @@ CXXFLAGS+=$(CFLAGS) -fno-rtti
 
 
 all:	one
 all:	one
 
 
-one:	$(OBJS) one.o
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
+one:	$(OBJS) service/OneService.o one.o
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o $(LIBS)
 	$(STRIP) zerotier-one
 	$(STRIP) zerotier-one
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-cli
 	ln -sf zerotier-one zerotier-cli

+ 15 - 9
make-linux.mk

@@ -28,13 +28,11 @@ endif
 
 
 #UNAME_M=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
 #UNAME_M=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
 
 
-INCLUDES=-Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6
-DEFS=-DZT_ENABLE_NETCON
-#CXXFLAGS+=-Wc++11-compat-deprecated-writable-strings -Wformat
+INCLUDES?=
+DEFS?=
 LDLIBS?=
 LDLIBS?=
 
 
 include objects.mk
 include objects.mk
-OBJS+=osdep/LinuxEthernetTap.o netcon/NetconEthernetTap.o
 
 
 # "make official" is a shortcut for this
 # "make official" is a shortcut for this
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
@@ -91,12 +89,20 @@ endif
 
 
 all:	one
 all:	one
 
 
-one:	$(OBJS) one.o
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LDLIBS)
+one:	$(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o $(LDLIBS)
 	$(STRIP) zerotier-one
 	$(STRIP) zerotier-one
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-cli
 	ln -sf zerotier-one zerotier-cli
 
 
+netcon: one
+	# Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -DZT_SERVICE_NETCON -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -o zerotier-netcon-service one.cpp service/OneService.cpp netcon/NetconEthernetTap.cpp $(OBJS) $(LDLIBS) -ldl
+	# Build netcon/liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
+	cd netcon ; make -f make-liblwip.mk
+	# Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility
+	cd netcon ; gcc -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -DDEBUG_RPC -DCHECKS -D_GNU_SOURCE -DNETCON_INTERCEPT -I. -nostdlib -shared -o ../libzerotierintercept.so Intercept.c
+
 selftest:	$(OBJS) selftest.o
 selftest:	$(OBJS) selftest.o
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
 	$(STRIP) zerotier-selftest
 	$(STRIP) zerotier-selftest
@@ -105,9 +111,9 @@ installer: one FORCE
 	./ext/installfiles/linux/buildinstaller.sh
 	./ext/installfiles/linux/buildinstaller.sh
 
 
 clean:
 clean:
-	rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o $(OBJS) zerotier-one zerotier-idtool zerotier-cli zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm
-	# Remove files from all the funny places we put them for tests
-	find netcon -type f \( -name '*.o' -o -name '*.so' -o -name '*.1.0' -o -name 'zerotier-one' -o -name 'zerotier-cli' \) -delete
+	rm -rf *.so *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o $(OBJS) zerotier-one zerotier-idtool zerotier-cli zerotier-selftest zerotier-netcon-service build-* ZeroTierOneInstaller-* *.deb *.rpm
+	# Remove files from all the funny places we put them for netcon tests
+	find netcon -type f \( -name '*.o' -o -name '*.so' -o -name '.depend' -o -name '*.1.0' -o -name 'zerotier-one' -o -name 'zerotier-cli' \) -delete
 	find netcon/docker-test -name "zerotier-intercept" -type f -delete
 	find netcon/docker-test -name "zerotier-intercept" -type f -delete
 
 
 debug:	FORCE
 debug:	FORCE

+ 2 - 2
make-mac.mk

@@ -71,8 +71,8 @@ CXXFLAGS=$(CFLAGS) -fno-rtti
 
 
 all: one
 all: one
 
 
-one:	$(OBJS) one.o
-	$(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) one.o $(LIBS)
+one:	$(OBJS) service/OneService.o one.o
+	$(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o $(LIBS)
 	$(STRIP) zerotier-one
 	$(STRIP) zerotier-one
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-idtool
 	ln -sf zerotier-one zerotier-cli
 	ln -sf zerotier-one zerotier-cli

+ 0 - 4
netcon/NetconEthernetTap.cpp

@@ -25,8 +25,6 @@
  * LLC. Start here: http://www.zerotier.com/
  * LLC. Start here: http://www.zerotier.com/
  */
  */
 
 
-#ifdef ZT_ENABLE_NETCON
-
 #include <algorithm>
 #include <algorithm>
 #include <utility>
 #include <utility>
 #include <dlfcn.h>
 #include <dlfcn.h>
@@ -1551,5 +1549,3 @@ void NetconEthernetTap::handle_write(TcpConnection *conn)
 }
 }
 
 
 } // namespace ZeroTier
 } // namespace ZeroTier
-
-#endif // ZT_ENABLE_NETCON

+ 0 - 4
netcon/NetconEthernetTap.hpp

@@ -28,8 +28,6 @@
 #ifndef ZT_NETCONETHERNETTAP_HPP
 #ifndef ZT_NETCONETHERNETTAP_HPP
 #define ZT_NETCONETHERNETTAP_HPP
 #define ZT_NETCONETHERNETTAP_HPP
 
 
-#ifdef ZT_ENABLE_NETCON
-
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
@@ -182,6 +180,4 @@ private:
 
 
 } // namespace ZeroTier
 } // namespace ZeroTier
 
 
-#endif // ZT_ENABLE_NETCON
-
 #endif
 #endif

BIN
netcon/docker-test/zerotier-cli


+ 0 - 54
netcon/docker-test/zerotier-intercept

@@ -1,54 +0,0 @@
-#!/bin/sh
-# usage:
-# /usr/bin/intercept program <args>
-
-if [ $# = 0 ] ; then
-   echo "$0: insufficient arguments"
-   exit
-fi
-
-case "$1" in
-	on)
-		if [ -z "$LD_PRELOAD" ]
-			then
-				export LD_PRELOAD="/lib/libzerotierintercept.so.1.0"
-			else
-				echo $LD_PRELOAD | grep -q "/lib/libzerotierintercept\.so.1.0" || \
-				export LD_PRELOAD="/lib/libzerotierintercept.so $LD_PRELOAD"
-		fi
-	;;
-	off)
-		export LD_PRELOAD=`echo -n $LD_PRELOAD | sed 's/\/lib\/libzerotierintercept.so.1.0 \?//'`
-		if [ -z "$LD_PRELOAD" ]
-			then
-				unset LD_PRELOAD
-		fi
-	;;
-	show|sh)
-		echo "LD_PRELOAD=\"$LD_PRELOAD\""
-	;;
-	-h|-?)
-      echo ""
-   ;;
-	*)
-		if [ -z "$LD_PRELOAD" ]
-		then
-			export LD_PRELOAD="/lib/libzerotierintercept.so.1.0"
-		else
-			echo $LD_PRELOAD | grep -q "/lib/libzerotierintercept\.so.1.0" || \
-			export LD_PRELOAD="/lib/libzerotierintercept.so.1.0 $LD_PRELOAD"
-		fi
-
-		if [ $# = 0 ]
-		then
-			${SHELL:-/bin/sh}
-		fi
-
-		if [ $# -gt 0 ]
-		then
-			exec "$@"
-		fi
-	;;
-esac
-
-#EOF

BIN
netcon/docker-test/zerotier-one


+ 0 - 53
netcon/make-intercept.mk

@@ -1,53 +0,0 @@
-#
-# ZeroTier One - Network Virtualization Everywhere
-# Copyright (C) 2011-2015  ZeroTier, Inc.
-#
-# 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/>.
-#
-# --
-#
-# ZeroTier may be used and distributed under the terms of the GPLv3, which
-# are available at: http://www.gnu.org/licenses/gpl-3.0.html
-#
-# If you would like to embed ZeroTier into a commercial application or
-# redistribute it in a modified binary form, please contact ZeroTier Networks
-# LLC. Start here: http://www.zerotier.com/
-#
-
-SHCC=gcc
-
-intercept_CFLAGS = -c -fPIC -g -O2 -Wall -std=c99 -DVERBOSE -DDEBUG_RPC -DCHECKS -D_GNU_SOURCE -DNETCON_INTERCEPT
-#LIB_NAME = intercept
-SHLIB_EXT=dylib
-SHLIB_MAJOR = 1
-SHLIB_MINOR = 8
-COMMON = Common
-OBJS= Intercept.o
-#SHLIB = ${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR}.${SHLIB_MINOR}
-SHLDFLAGS = -g -O2 -Wall -I. -nostdlib -shared
-LIBS = -ldl -lc -lrt -lpthread
-
-lib:
-	${SHCC} $(intercept_CFLAGS) -I. Intercept.c -o Intercept.o
-	${SHCC} $(SHLDFLAGS) Intercept.o -o libzerotierintercept.so.1.0 $(LIBS)
-
-install:
-	cp libzerotierintercept.so.1.0 /lib/libzerotierintercept.so.1.0
-	ln -sf /lib/libzerotierintercept.so.1.0 /lib/libzerotierintercept
-	/usr/bin/install -c zerotier-intercept /usr/bin
-
-uninstall:
-	rm -r /lib/libzerotierintercept.so.1.0
-	rm -r /lib/libzerotierintercept
-	rm -r /usr/bin/zerotier-intercept

+ 1 - 2
objects.mk

@@ -29,5 +29,4 @@ OBJS=\
 	osdep/Http.o \
 	osdep/Http.o \
 	osdep/OSUtils.o \
 	osdep/OSUtils.o \
 	service/ClusterGeoIpService.o \
 	service/ClusterGeoIpService.o \
-	service/ControlPlane.o \
-	service/OneService.o
+	service/ControlPlane.o

+ 2 - 0
one.cpp

@@ -1096,10 +1096,12 @@ int main(int argc,char **argv)
 	}
 	}
 
 
 #ifdef __UNIX_LIKE__
 #ifdef __UNIX_LIKE__
+#ifndef ZT_ONE_NO_ROOT_CHECK
 	if ((!skipRootCheck)&&(getuid() != 0)) {
 	if ((!skipRootCheck)&&(getuid() != 0)) {
 		fprintf(stderr,"%s: must be run as root (uid 0)"ZT_EOL_S,argv[0]);
 		fprintf(stderr,"%s: must be run as root (uid 0)"ZT_EOL_S,argv[0]);
 		return 1;
 		return 1;
 	}
 	}
+#endif // !ZT_ONE_NO_ROOT_CHECK
 	if (runAsDaemon) {
 	if (runAsDaemon) {
 		long p = (long)fork();
 		long p = (long)fork();
 		if (p < 0) {
 		if (p < 0) {

+ 9 - 14
service/OneService.cpp

@@ -92,37 +92,32 @@ class SqliteNetworkController;
 #endif
 #endif
 
 
 // Include the right tap device driver for this platform -- add new platforms here
 // Include the right tap device driver for this platform -- add new platforms here
-#ifdef ZT_ENABLE_NETCON
+#ifdef ZT_SERVICE_NETCON
 
 
+// In network containers builds, use the virtual netcon endpoint instead of a tun/tap port driver
 #include "../netcon/NetconEthernetTap.hpp"
 #include "../netcon/NetconEthernetTap.hpp"
 namespace ZeroTier { typedef NetconEthernetTap EthernetTap; }
 namespace ZeroTier { typedef NetconEthernetTap EthernetTap; }
 
 
-#else
-#ifdef __APPLE__
+#else // not ZT_SERVICE_NETCON so pick a tap driver
 
 
+#ifdef __APPLE__
 #include "../osdep/OSXEthernetTap.hpp"
 #include "../osdep/OSXEthernetTap.hpp"
 namespace ZeroTier { typedef OSXEthernetTap EthernetTap; }
 namespace ZeroTier { typedef OSXEthernetTap EthernetTap; }
-
-#endif
+#endif // __APPLE__
 #ifdef __LINUX__
 #ifdef __LINUX__
-
 #include "../osdep/LinuxEthernetTap.hpp"
 #include "../osdep/LinuxEthernetTap.hpp"
 namespace ZeroTier { typedef LinuxEthernetTap EthernetTap; }
 namespace ZeroTier { typedef LinuxEthernetTap EthernetTap; }
-
-#endif
+#endif // __LINUX__
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
-
 #include "../osdep/WindowsEthernetTap.hpp"
 #include "../osdep/WindowsEthernetTap.hpp"
 namespace ZeroTier { typedef WindowsEthernetTap EthernetTap; }
 namespace ZeroTier { typedef WindowsEthernetTap EthernetTap; }
-
-#endif
+#endif // __WINDOWS__
 #ifdef __FreeBSD__
 #ifdef __FreeBSD__
-
 #include "../osdep/BSDEthernetTap.hpp"
 #include "../osdep/BSDEthernetTap.hpp"
 namespace ZeroTier { typedef BSDEthernetTap EthernetTap; }
 namespace ZeroTier { typedef BSDEthernetTap EthernetTap; }
+#endif // __FreeBSD__
 
 
-#endif
-#endif // ZT_ENABLE_NETCON
+#endif // ZT_SERVICE_NETCON
 
 
 // Sanity limits for HTTP
 // Sanity limits for HTTP
 #define ZT_MAX_HTTP_MESSAGE_SIZE (1024 * 1024 * 64)
 #define ZT_MAX_HTTP_MESSAGE_SIZE (1024 * 1024 * 64)