Browse Source

Mare make-self-contained code cleanup.

Adam Ierymenko 9 years ago
parent
commit
95106e2e30
5 changed files with 42 additions and 120 deletions
  1. 1 1
      make-linux.mk
  2. 41 7
      netcon/NetconEthernetTap.cpp
  3. 0 2
      netcon/NetconEthernetTap.hpp
  4. 0 71
      netcon/NetconUtilities.cpp
  5. 0 39
      netcon/NetconUtilities.hpp

+ 1 - 1
make-linux.mk

@@ -34,7 +34,7 @@ DEFS=-DZT_ENABLE_NETCON
 LDLIBS?=
 
 include objects.mk
-OBJS+=osdep/LinuxEthernetTap.o netcon/NetconEthernetTap.o osdep/Arp.o netcon/NetconUtilities.o
+OBJS+=osdep/LinuxEthernetTap.o netcon/NetconEthernetTap.o
 
 # "make official" is a shortcut for this
 ifeq ($(ZT_OFFICIAL_RELEASE),1)

+ 41 - 7
netcon/NetconEthernetTap.cpp

@@ -40,7 +40,6 @@
 
 #include "Intercept.h"
 #include "LWIPStack.hpp"
-#include "NetconUtilities.hpp"
 
 #include "lwip/tcp_impl.h"
 #include "netif/etharp.h"
@@ -59,6 +58,37 @@
 
 namespace ZeroTier {
 
+// ---------------------------------------------------------------------------
+
+/*
+static void clearscreen(){
+	fprintf(stderr, "\033[2J");
+}
+static void gotoxy(int x,int y) {
+    fprintf(stderr, "%c[%d;%df",0x1B,y,x);
+}
+*/
+
+// Gets the process/path name associated with a pid
+static void get_path_from_pid(char* dest, int pid)
+{
+  char ppath[80];
+  sprintf(ppath, "/proc/%d/exe", pid);
+	if (readlink (ppath, dest, 80) != -1){
+  }
+}
+
+// Gets the process/path name associated with a fd
+/*
+static void get_path_from_fd(char* dest, int pid, int fd)
+{
+	char ppfd[80];
+	sprintf(ppfd, "/proc/%d/fd/%d", pid, fd);
+	if (readlink (ppfd, dest, 80) != -1){
+	}
+}
+*/
+
 static err_t tapif_init(struct netif *netif)
 {
   // Actual init functionality is in addIp() of tap
@@ -137,6 +167,8 @@ public:
   Larg(NetconEthernetTap *_tap, TcpConnection *conn) : tap(_tap), conn(conn) {}
 };
 
+// ---------------------------------------------------------------------------
+
 NetconEthernetTap::NetconEthernetTap(
 	const char *homePath,
 	const MAC &mac,
@@ -157,14 +189,15 @@ NetconEthernetTap::NetconEthernetTap(
 	_enabled(true),
 	_run(true)
 {
+	char sockPath[4096],lwipPath[4096];
 	rpc_counter = -1;
-	char sockPath[4096];
-	Utils::snprintf(sockPath,sizeof(sockPath),"/tmp/.ztnc_%.16llx",(unsigned long long)nwid);
-	_dev = sockPath;
+	Utils::snprintf(sockPath,sizeof(sockPath),"%s%snetcon_service_%.16llx",homePath,ZT_PATH_SEPARATOR_S,(unsigned long long)nwid);
+  _dev = sockPath; // in netcon mode, set device to be just the network ID
 
-	lwipstack = new LWIPStack("ext/bin/lwip/liblwip.so"); // ext/bin/liblwip.so.debug for debug symbols
+	Utils::snprintf(lwipPath,sizeof(lwipPath),"%s%sliblwip.so",homePath,ZT_PATH_SEPARATOR_S);
+	lwipstack = new LWIPStack(lwipPath);
 	if(!lwipstack)
-		throw std::runtime_error("unable to load lwip lib.");
+		throw std::runtime_error("unable to dynamically load a new instance of liblwip.so (searched ZeroTier home path)");
 	lwipstack->lwip_init();
 
 	_unixListenSocket = _phy.unixListen(sockPath,(void *)this);
@@ -290,7 +323,8 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
 	}
 }
 
-std::string NetconEthernetTap::deviceName() const {
+std::string NetconEthernetTap::deviceName() const
+{
 	return _dev;
 }
 

+ 0 - 2
netcon/NetconEthernetTap.hpp

@@ -44,8 +44,6 @@
 #include "../osdep/Thread.hpp"
 #include "../osdep/Phy.hpp"
 
-#include "NetconUtilities.hpp"
-
 #include "netif/etharp.h"
 
 struct tcp_pcb;

+ 0 - 71
netcon/NetconUtilities.cpp

@@ -1,71 +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/
- */
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <sys/socket.h>
-
-#include "lwip/ip.h"
-#include "lwip/ip_addr.h"
-#include "lwip/ip_frag.h"
-
-#ifndef _NETCON_UTILITIES_CPP
-#define _NETCON_UTILITIES_CPP
-
-namespace ZeroTier
-{
-	void clearscreen(){
-		fprintf(stderr, "\033[2J");
-	}
-	void gotoxy(int x,int y) {
-	    fprintf(stderr, "%c[%d;%df",0x1B,y,x);
-	}
-
-	// Gets the process/path name associated with a pid
-	void get_path_from_pid(char* dest, int pid)
-	{
-	  char ppath[80];
-	  sprintf(ppath, "/proc/%d/exe", pid);
-		if (readlink (ppath, dest, 80) != -1){
-	  }
-	}
-
-	// Gets the process/path name associated with a fd
-	void get_path_from_fd(char* dest, int pid, int fd)
-	{
-		char ppfd[80];
-		sprintf(ppfd, "/proc/%d/fd/%d", pid, fd);
-		if (readlink (ppfd, dest, 80) != -1){
-		}
-	}
-}
-
-#endif

+ 0 - 39
netcon/NetconUtilities.hpp

@@ -1,39 +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/
- */
-
-#ifndef _NETCON_UTILITIES_H
-#define _NETCON_UTILITIES_H
-
-namespace ZeroTier
-{
-  void clearscreen();
-  void gotoxy(int x,int y);
-  void get_path_from_pid(char* dest, int pid);
-  void get_path_from_fd(char* dest, int pid, int fd);
-}
-#endif