2017-04-06 19:16:01 -07:00
|
|
|
/*
|
2017-05-04 15:53:38 -07:00
|
|
|
* ZeroTier SDK - Network Virtualization Everywhere
|
2017-05-04 15:35:50 -07:00
|
|
|
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
2017-04-06 19:16:01 -07:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
2017-05-04 15:35:50 -07:00
|
|
|
*
|
|
|
|
|
* --
|
|
|
|
|
*
|
|
|
|
|
* You can be released from the requirements of the license by purchasing
|
|
|
|
|
* a commercial license. Buying such a license is mandatory as soon as you
|
|
|
|
|
* develop commercial closed-source software that incorporates or links
|
|
|
|
|
* directly against ZeroTier software without disclosing the source code
|
|
|
|
|
* of your own application.
|
2017-04-06 19:16:01 -07:00
|
|
|
*/
|
|
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
2017-04-06 19:16:01 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "SocketTap.hpp"
|
2017-06-14 16:53:59 -07:00
|
|
|
#include "libzt.h"
|
2017-07-25 23:40:24 -07:00
|
|
|
|
|
|
|
|
#if defined(STACK_PICO)
|
2017-07-26 02:13:13 -07:00
|
|
|
#include "picoTCP.hpp"
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
2017-07-26 02:13:13 -07:00
|
|
|
#include "lwIP.hpp"
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-04-06 19:16:01 -07:00
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
#include <netinet/ether.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-04-06 19:16:01 -07:00
|
|
|
#include "Utils.hpp"
|
|
|
|
|
#include "OSUtils.hpp"
|
|
|
|
|
#include "Constants.hpp"
|
|
|
|
|
#include "Phy.hpp"
|
|
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
class SocketTap;
|
|
|
|
|
|
|
|
|
|
extern std::vector<void*> vtaps;
|
|
|
|
|
|
2017-04-06 19:16:01 -07:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
int SocketTap::devno = 0;
|
|
|
|
|
|
2017-04-20 13:39:46 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
|
/* SocketTap Service */
|
|
|
|
|
/* - For each joined network a SocketTap will be created to administer I/O */
|
|
|
|
|
/* calls to the stack and the ZT virtual wire */
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
|
|
SocketTap::SocketTap(
|
|
|
|
|
const char *homePath,
|
|
|
|
|
const MAC &mac,
|
|
|
|
|
unsigned int mtu,
|
|
|
|
|
unsigned int metric,
|
|
|
|
|
uint64_t nwid,
|
|
|
|
|
const char *friendlyName,
|
|
|
|
|
void (*handler)(void *,void*,uint64_t,const MAC &,const MAC &,
|
|
|
|
|
unsigned int,unsigned int,const void *,unsigned int),
|
|
|
|
|
void *arg) :
|
2017-08-02 14:54:29 -07:00
|
|
|
_handler(handler),
|
2017-04-20 13:39:46 -07:00
|
|
|
_homePath(homePath),
|
|
|
|
|
_arg(arg),
|
|
|
|
|
_enabled(true),
|
|
|
|
|
_run(true),
|
|
|
|
|
_mac(mac),
|
|
|
|
|
_mtu(mtu),
|
|
|
|
|
_nwid(nwid),
|
|
|
|
|
_unixListenSocket((PhySocket *)0),
|
|
|
|
|
_phy(this,false,true)
|
|
|
|
|
{
|
2017-08-02 14:39:21 -07:00
|
|
|
vtaps.push_back((void*)this);
|
|
|
|
|
|
|
|
|
|
// set interface name
|
|
|
|
|
char tmp3[17];
|
|
|
|
|
ifindex = devno;
|
|
|
|
|
sprintf(tmp3, "libzt%d", devno++);
|
|
|
|
|
_dev = tmp3;
|
|
|
|
|
DEBUG_INFO("set device name to: %s", _dev.c_str());
|
|
|
|
|
|
2017-05-05 16:46:07 -07:00
|
|
|
_thread = Thread::start(this);
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
|
|
|
|
SocketTap::~SocketTap()
|
|
|
|
|
{
|
|
|
|
|
_run = false;
|
|
|
|
|
_phy.whack();
|
|
|
|
|
Thread::join(_thread);
|
|
|
|
|
_phy.close(_unixListenSocket,false);
|
|
|
|
|
for(int i=0; i<_Connections.size(); i++) delete _Connections[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SocketTap::setEnabled(bool en)
|
|
|
|
|
{
|
|
|
|
|
_enabled = en;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SocketTap::enabled() const
|
|
|
|
|
{
|
|
|
|
|
return _enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 16:46:07 -07:00
|
|
|
bool SocketTap::registerIpWithStack(const InetAddress &ip)
|
2017-04-20 13:39:46 -07:00
|
|
|
{
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
|
|
|
|
if(picostack){
|
|
|
|
|
picostack->pico_init_interface(this, ip);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
|
|
|
|
if(lwipstack){
|
|
|
|
|
lwipstack->lwip_init_interface(this, ip);
|
2017-05-02 09:35:27 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-05-02 09:35:27 -07:00
|
|
|
return false;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 16:46:07 -07:00
|
|
|
bool SocketTap::addIp(const InetAddress &ip)
|
|
|
|
|
{
|
2017-07-26 02:13:13 -07:00
|
|
|
#if defined(NO_STACK)
|
|
|
|
|
DEBUG_INFO("addIp (%s)", ip.toString().c_str());
|
|
|
|
|
_ips.push_back(ip);
|
|
|
|
|
std::sort(_ips.begin(),_ips.end());
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
2017-05-05 16:46:07 -07:00
|
|
|
if(registerIpWithStack(ip))
|
|
|
|
|
{
|
|
|
|
|
// only start the stack if we successfully registered and initialized a device to
|
|
|
|
|
// the given address
|
2017-07-26 02:13:13 -07:00
|
|
|
_ips.push_back(ip);
|
|
|
|
|
std::sort(_ips.begin(),_ips.end());
|
2017-05-05 16:46:07 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 13:39:46 -07:00
|
|
|
bool SocketTap::removeIp(const InetAddress &ip)
|
|
|
|
|
{
|
|
|
|
|
Mutex::Lock _l(_ips_m);
|
|
|
|
|
std::vector<InetAddress>::iterator i(std::find(_ips.begin(),_ips.end(),ip));
|
|
|
|
|
if (i == _ips.end())
|
|
|
|
|
return false;
|
|
|
|
|
_ips.erase(i);
|
|
|
|
|
if (ip.isV4()) {
|
|
|
|
|
// FIXME: De-register from network stacks
|
|
|
|
|
}
|
|
|
|
|
if (ip.isV6()) {
|
|
|
|
|
// FIXME: De-register from network stacks
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
|
|
|
|
std::vector<InetAddress> SocketTap::ips() const
|
|
|
|
|
{
|
|
|
|
|
Mutex::Lock _l(_ips_m);
|
|
|
|
|
return _ips;
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
|
|
|
|
void SocketTap::put(const MAC &from,const MAC &to,unsigned int etherType,
|
|
|
|
|
const void *data,unsigned int len)
|
|
|
|
|
{
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-08-02 14:54:29 -07:00
|
|
|
if(picostack)
|
|
|
|
|
picostack->pico_rx(this,from,to,etherType,data,len);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
2017-08-02 14:54:29 -07:00
|
|
|
if(lwipstack)
|
|
|
|
|
lwipstack->lwip_rx(this,from,to,etherType,data,len);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
|
|
|
|
std::string SocketTap::deviceName() const
|
|
|
|
|
{
|
|
|
|
|
return _dev;
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
2017-07-26 02:13:13 -07:00
|
|
|
void SocketTap::setFriendlyName(const char *friendlyName)
|
|
|
|
|
{
|
2017-08-02 14:39:21 -07:00
|
|
|
DEBUG_INFO("%s", friendlyName);
|
2017-07-26 02:13:13 -07:00
|
|
|
// Someday
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
|
|
|
|
void SocketTap::scanMulticastGroups(std::vector<MulticastGroup> &added,
|
|
|
|
|
std::vector<MulticastGroup> &removed)
|
|
|
|
|
{
|
|
|
|
|
std::vector<MulticastGroup> newGroups;
|
|
|
|
|
Mutex::Lock _l(_multicastGroups_m);
|
|
|
|
|
// TODO: get multicast subscriptions from network stack
|
|
|
|
|
std::vector<InetAddress> allIps(ips());
|
|
|
|
|
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
|
|
|
|
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
|
|
|
|
|
|
|
|
|
std::sort(newGroups.begin(),newGroups.end());
|
|
|
|
|
std::unique(newGroups.begin(),newGroups.end());
|
|
|
|
|
|
|
|
|
|
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
|
|
|
|
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
|
|
|
|
added.push_back(*m);
|
|
|
|
|
}
|
|
|
|
|
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
|
|
|
|
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
|
|
|
|
removed.push_back(*m);
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
_multicastGroups.swap(newGroups);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 13:17:39 -07:00
|
|
|
void SocketTap::setMtu(unsigned int mtu)
|
|
|
|
|
{
|
|
|
|
|
if (_mtu != mtu) {
|
|
|
|
|
_mtu = mtu;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 13:39:46 -07:00
|
|
|
void SocketTap::threadMain()
|
|
|
|
|
throw()
|
|
|
|
|
{
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
|
|
|
|
picostack->pico_loop(this);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
|
|
|
|
if(lwipstack)
|
|
|
|
|
lwipstack->lwip_loop(this);
|
|
|
|
|
#endif
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SocketTap::phyOnUnixClose(PhySocket *sock,void **uptr)
|
|
|
|
|
{
|
2017-05-02 09:35:27 -07:00
|
|
|
if(sock) {
|
|
|
|
|
Connection *conn = (Connection*)uptr;
|
|
|
|
|
if(conn)
|
|
|
|
|
Close(conn);
|
|
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SocketTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len)
|
|
|
|
|
{
|
2017-07-26 02:13:13 -07:00
|
|
|
DEBUG_ATTN("sock->fd=%d", _phy.getDescriptor(sock));
|
2017-04-20 13:39:46 -07:00
|
|
|
Connection *conn = (Connection*)*uptr;
|
|
|
|
|
if(!conn)
|
|
|
|
|
return;
|
2017-08-02 14:54:29 -07:00
|
|
|
if(len){
|
2017-07-12 11:44:31 -07:00
|
|
|
|
2017-08-02 14:54:29 -07:00
|
|
|
Write(conn, data, len);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SocketTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool stack_invoked)
|
|
|
|
|
{
|
2017-05-02 09:35:27 -07:00
|
|
|
if(sock)
|
|
|
|
|
Read(sock,uptr,stack_invoked);
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
/* SDK Socket API */
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int SocketTap::Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen) {
|
|
|
|
|
Mutex::Lock _l(_tcpconns_m);
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
|
|
|
|
return picostack->pico_Connect(conn, fd, addr, addrlen);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
|
|
|
|
if(lwipstack)
|
|
|
|
|
return lwipstack->lwip_Connect(conn, fd, addr, addrlen);
|
|
|
|
|
#endif
|
2017-05-02 09:35:27 -07:00
|
|
|
return ZT_ERR_GENERAL_FAILURE;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SocketTap::Bind(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen) {
|
|
|
|
|
Mutex::Lock _l(_tcpconns_m);
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
|
|
|
|
return picostack->pico_Bind(conn, fd, addr, addrlen);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
#if defined(STACK_LWIP)
|
|
|
|
|
if(lwipstack)
|
|
|
|
|
return lwipstack->lwip_Bind(this, conn, fd, addr, addrlen);
|
|
|
|
|
#endif
|
2017-05-02 09:35:27 -07:00
|
|
|
return ZT_ERR_GENERAL_FAILURE;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-04-21 14:56:42 -07:00
|
|
|
int SocketTap::Listen(Connection *conn, int fd, int backlog) {
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-04-20 13:39:46 -07:00
|
|
|
Mutex::Lock _l(_tcpconns_m);
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
|
|
|
|
return picostack->pico_Listen(conn, fd, backlog);
|
|
|
|
|
return ZT_ERR_GENERAL_FAILURE;
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
return ZT_ERR_GENERAL_FAILURE;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-02 09:35:27 -07:00
|
|
|
Connection* SocketTap::Accept(Connection *conn) {
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-04-20 13:39:46 -07:00
|
|
|
Mutex::Lock _l(_tcpconns_m);
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
|
|
|
|
return picostack->pico_Accept(conn);
|
|
|
|
|
return NULL;
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
|
|
|
|
return NULL;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
int SocketTap::Read(PhySocket *sock,void **uptr,bool stack_invoked) {
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
2017-08-02 14:39:21 -07:00
|
|
|
return picostack->pico_Read(this, sock, (Connection*)uptr, stack_invoked);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-08-02 14:39:21 -07:00
|
|
|
return -1;
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
int SocketTap::Write(Connection *conn, void *data, ssize_t len) {
|
|
|
|
|
if(conn->socket_type == SOCK_RAW) { // we don't want to use a stack, just VL2
|
2017-08-02 14:54:29 -07:00
|
|
|
struct ether_header *eh = (struct ether_header *) data;
|
|
|
|
|
MAC src_mac;
|
|
|
|
|
MAC dest_mac;
|
|
|
|
|
src_mac.setTo(eh->ether_shost, 6);
|
|
|
|
|
dest_mac.setTo(eh->ether_dhost, 6);
|
|
|
|
|
_handler(_arg,NULL,_nwid,src_mac,dest_mac, Utils::ntoh((uint16_t)eh->ether_type),0, ((char*)data) + sizeof(struct ether_header),len - sizeof(struct ether_header));
|
|
|
|
|
return len;
|
2017-08-02 14:39:21 -07:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(picostack)
|
2017-08-02 14:39:21 -07:00
|
|
|
return picostack->pico_Write(conn, data, len);
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-08-02 14:39:21 -07:00
|
|
|
return -1;
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
2017-08-02 14:39:21 -07:00
|
|
|
int SocketTap::Close(Connection *conn) {
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-05-02 09:35:27 -07:00
|
|
|
if(!conn) {
|
|
|
|
|
DEBUG_ERROR("invalid connection");
|
2017-08-02 14:39:21 -07:00
|
|
|
return -1;
|
2017-05-02 09:35:27 -07:00
|
|
|
}
|
2017-05-05 16:46:07 -07:00
|
|
|
picostack->pico_Close(conn);
|
2017-04-20 13:39:46 -07:00
|
|
|
if(!conn->sock) {
|
2017-06-11 20:24:11 -07:00
|
|
|
// DEBUG_EXTRA("invalid PhySocket");
|
2017-08-02 14:39:21 -07:00
|
|
|
return -1;
|
2017-04-20 13:39:46 -07:00
|
|
|
}
|
2017-05-02 09:35:27 -07:00
|
|
|
// Here we assume _tcpconns_m is already locked by caller
|
|
|
|
|
// FIXME: is this assumption still valid
|
2017-07-12 11:44:31 -07:00
|
|
|
if(conn->state==ZT_SOCK_STATE_LISTENING)
|
|
|
|
|
{
|
|
|
|
|
// since we never wrapped this socket
|
|
|
|
|
DEBUG_INFO("in LISTENING state, no need to close in PhyIO");
|
2017-08-02 14:39:21 -07:00
|
|
|
return -1;
|
2017-07-12 11:44:31 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(conn->sock)
|
|
|
|
|
_phy.close(conn->sock, false);
|
|
|
|
|
}
|
2017-05-02 09:35:27 -07:00
|
|
|
close(_phy.getDescriptor(conn->sock));
|
2017-04-20 13:39:46 -07:00
|
|
|
for(size_t i=0;i<_Connections.size();++i) {
|
|
|
|
|
if(_Connections[i] == conn){
|
2017-06-05 14:26:06 -07:00
|
|
|
// FIXME: double free issue exists here (potentially)
|
|
|
|
|
// _Connections.erase(_Connections.begin() + i);
|
|
|
|
|
//delete conn;
|
2017-04-20 13:39:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-08-02 14:39:21 -07:00
|
|
|
return 0; // TODO
|
2017-04-06 19:16:01 -07:00
|
|
|
}
|
2017-04-20 13:39:46 -07:00
|
|
|
|
2017-06-05 14:26:06 -07:00
|
|
|
void SocketTap::Housekeeping()
|
|
|
|
|
{
|
2017-07-25 23:40:24 -07:00
|
|
|
#if defined(STACK_PICO)
|
2017-06-05 14:26:06 -07:00
|
|
|
Mutex::Lock _l(_tcpconns_m);
|
|
|
|
|
std::time_t current_ts = std::time(nullptr);
|
|
|
|
|
if(current_ts > last_housekeeping_ts + ZT_HOUSEKEEPING_INTERVAL) {
|
|
|
|
|
// Clean up old Connection objects
|
|
|
|
|
for(size_t i=0;i<_Connections.size();++i) {
|
|
|
|
|
if(_Connections[i]->closure_ts != -1 && (current_ts > _Connections[i]->closure_ts + ZT_CONNECTION_DELETE_WAIT_TIME)) {
|
|
|
|
|
// DEBUG_ERROR("deleting %p object, _Connections.size() = %d", _Connections[i], _Connections.size());
|
|
|
|
|
delete _Connections[i];
|
|
|
|
|
_Connections.erase(_Connections.begin() + i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
last_housekeeping_ts = std::time(nullptr);
|
|
|
|
|
}
|
2017-07-25 23:40:24 -07:00
|
|
|
#endif
|
2017-06-05 14:26:06 -07:00
|
|
|
}
|
|
|
|
|
|
2017-04-20 13:39:46 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
|
/* Not used in this implementation */
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void SocketTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *local_address,
|
|
|
|
|
const struct sockaddr *from,void *data,unsigned long len) {}
|
|
|
|
|
void SocketTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success) {}
|
|
|
|
|
void SocketTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,
|
|
|
|
|
const struct sockaddr *from) {}
|
|
|
|
|
void SocketTap::phyOnTcpClose(PhySocket *sock,void **uptr) {}
|
|
|
|
|
void SocketTap::phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len) {}
|
2017-05-04 15:33:33 -07:00
|
|
|
void SocketTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {}
|
2017-04-06 19:16:01 -07:00
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|