From 2a6ea387180e76ae934a9d653adb7aa5f9fa479f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 23 Nov 2015 13:02:50 -0800 Subject: [PATCH] More code cleanup, just moving some stuff into NetconEthernetTap that is not used elsewhere. --- netcon/Common.c | 0 netcon/Intercept.c | 0 netcon/Intercept.h | 0 netcon/LWIPStack.hpp | 5 +-- netcon/NetconEthernetTap.cpp | 46 +++++++++++++++++--- netcon/NetconEthernetTap.hpp | 11 ++++- netcon/NetconService.hpp | 82 ------------------------------------ 7 files changed, 50 insertions(+), 94 deletions(-) mode change 100755 => 100644 netcon/Common.c mode change 100755 => 100644 netcon/Intercept.c mode change 100755 => 100644 netcon/Intercept.h delete mode 100644 netcon/NetconService.hpp diff --git a/netcon/Common.c b/netcon/Common.c old mode 100755 new mode 100644 diff --git a/netcon/Intercept.c b/netcon/Intercept.c old mode 100755 new mode 100644 diff --git a/netcon/Intercept.h b/netcon/Intercept.h old mode 100755 new mode 100644 diff --git a/netcon/LWIPStack.hpp b/netcon/LWIPStack.hpp index 7d6211df8..fedbdd5f1 100644 --- a/netcon/LWIPStack.hpp +++ b/netcon/LWIPStack.hpp @@ -25,6 +25,8 @@ * LLC. Start here: http://www.zerotier.com/ */ +#ifndef ZT_LWIPSTACK_H +#define ZT_LWIPSTACK_H #include "lwip/mem.h" #include "lwip/pbuf.h" @@ -36,9 +38,6 @@ #include #include -#ifndef LWIPSTACK_H -#define LWIPSTACK_H - #ifdef D_GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp index 7d76b0b94..b722c6820 100644 --- a/netcon/NetconEthernetTap.cpp +++ b/netcon/NetconEthernetTap.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "NetconEthernetTap.hpp" @@ -37,17 +38,18 @@ #include "../osdep/OSUtils.hpp" #include "../osdep/Phy.hpp" +#include "Intercept.h" +#include "LWIPStack.hpp" +#include "NetconUtilities.hpp" + #include "lwip/tcp_impl.h" #include "netif/etharp.h" +#include "lwip/api.h" #include "lwip/ip.h" #include "lwip/ip_addr.h" #include "lwip/ip_frag.h" #include "lwip/tcp.h" -#include "LWIPStack.hpp" -#include "NetconService.hpp" -#include "Intercept.h" -#include "NetconUtilities.hpp" #include "Common.c" #include "Sendfd.c" @@ -57,8 +59,6 @@ namespace ZeroTier { -namespace { - static err_t tapif_init(struct netif *netif) { // Actual init functionality is in addIp() of tap @@ -103,7 +103,39 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) return ERR_OK; } -} // anonymous namespace +/* + * TCP connection administered by service + */ +class TcpConnection +{ +public: + int perceived_fd; + int their_fd; + bool pending; + bool listening; + int pid; + + unsigned long written; + unsigned long acked; + + PhySocket *rpcSock; + PhySocket *dataSock; + struct tcp_pcb *pcb; + + unsigned char buf[DEFAULT_READ_BUFFER_SIZE]; + int idx; +}; + +/* + * A helper class for passing a reference to _phy to LWIP callbacks as a "state" + */ +class Larg +{ +public: + NetconEthernetTap *tap; + TcpConnection *conn; + Larg(NetconEthernetTap *_tap, TcpConnection *conn) : tap(_tap), conn(conn) {} +}; NetconEthernetTap::NetconEthernetTap( const char *homePath, diff --git a/netcon/NetconEthernetTap.hpp b/netcon/NetconEthernetTap.hpp index 17b9975f9..17d6ce4f1 100644 --- a/netcon/NetconEthernetTap.hpp +++ b/netcon/NetconEthernetTap.hpp @@ -44,15 +44,22 @@ #include "../osdep/Thread.hpp" #include "../osdep/Phy.hpp" -#include "NetconService.hpp" #include "NetconUtilities.hpp" #include "netif/etharp.h" +struct tcp_pcb; +struct socket_st; +struct listen_st; +struct bind_st; +struct connect_st; + namespace ZeroTier { class NetconEthernetTap; - +class TcpConnection; +class Larg; +class LWIPStack; /** * Network Containers instance -- emulates an Ethernet tap device as far as OneService knows diff --git a/netcon/NetconService.hpp b/netcon/NetconService.hpp deleted file mode 100644 index edb5dc81e..000000000 --- a/netcon/NetconService.hpp +++ /dev/null @@ -1,82 +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 . - * - * -- - * - * 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 -#include - -#include "../osdep/Phy.hpp" -#include "NetconEthernetTap.hpp" - -#include "Intercept.h" -#include "LWIPStack.hpp" - -#ifndef _NETCON_SERVICE_HPP -#define _NETCON_SERVICE_HPP - -using namespace std; - -namespace ZeroTier { - - class NetconEthernetTap; - class TcpConnection; - - /* - * TCP connection administered by service - */ - class TcpConnection - { - public: - int perceived_fd; - int their_fd; - bool pending; - bool listening; - int pid; - - unsigned long written; - unsigned long acked; - - PhySocket *rpcSock; - PhySocket *dataSock; - struct tcp_pcb *pcb; - - unsigned char buf[DEFAULT_READ_BUFFER_SIZE]; - int idx; - }; - - /* - * A helper class for passing a reference to _phy to LWIP callbacks as a "state" - */ - class Larg - { - public: - NetconEthernetTap *tap; - TcpConnection *conn; - Larg(NetconEthernetTap *_tap, TcpConnection *conn) : tap(_tap), conn(conn) {} - }; -} // namespace ZeroTier - -#endif