summaryrefslogtreecommitdiff
path: root/attic
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-08 18:47:06 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-08 18:47:06 -0700
commitd76133046518e71025000ec6322f5b8f1c98529f (patch)
tree1fba494c7f77ae0e9ed786c739356252592a69cf /attic
parentccc73b920ecab667aa6ddb7d47e17c12f4b0ab8c (diff)
downloadinfinitytier-d76133046518e71025000ec6322f5b8f1c98529f.tar.gz
infinitytier-d76133046518e71025000ec6322f5b8f1c98529f.zip
No more tap factories.
Diffstat (limited to 'attic')
-rw-r--r--attic/BSDEthernetTapFactory.cpp78
-rw-r--r--attic/BSDEthernetTapFactory.hpp63
-rw-r--r--attic/LinuxEthernetTapFactory.cpp74
-rw-r--r--attic/LinuxEthernetTapFactory.hpp63
-rw-r--r--attic/OSXEthernetTapFactory.cpp122
-rw-r--r--attic/OSXEthernetTapFactory.hpp76
-rw-r--r--attic/WindowsEthernetTapFactory.cpp162
-rw-r--r--attic/WindowsEthernetTapFactory.hpp90
8 files changed, 728 insertions, 0 deletions
diff --git a/attic/BSDEthernetTapFactory.cpp b/attic/BSDEthernetTapFactory.cpp
new file mode 100644
index 00000000..79ae73f7
--- /dev/null
+++ b/attic/BSDEthernetTapFactory.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "BSDEthernetTapFactory.hpp"
+#include "BSDEthernetTap.hpp"
+
+namespace ZeroTier {
+
+BSDEthernetTapFactory::BSDEthernetTapFactory()
+{
+}
+
+BSDEthernetTapFactory::~BSDEthernetTapFactory()
+{
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d)
+ delete *d;
+}
+
+EthernetTap *BSDEthernetTapFactory::open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg)
+{
+ Mutex::Lock _l(_devices_m);
+ EthernetTap *t = new BSDEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
+ _devices.push_back(t);
+ return t;
+}
+
+void BSDEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
+{
+ {
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
+ if (*d == tap) {
+ _devices.erase(d);
+ break;
+ }
+ }
+ }
+ delete tap;
+}
+
+} // namespace ZeroTier
diff --git a/attic/BSDEthernetTapFactory.hpp b/attic/BSDEthernetTapFactory.hpp
new file mode 100644
index 00000000..5c681fb4
--- /dev/null
+++ b/attic/BSDEthernetTapFactory.hpp
@@ -0,0 +1,63 @@
+/*
+ * 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 ZT_BSDETHERNETTAPFACTORY_HPP
+#define ZT_BSDETHERNETTAPFACTORY_HPP
+
+#include <vector>
+#include <string>
+
+#include "EthernetTapFactory.hpp"
+#include "../node/Mutex.hpp"
+
+namespace ZeroTier {
+
+class BSDEthernetTapFactory : public EthernetTapFactory
+{
+public:
+ BSDEthernetTapFactory();
+ virtual ~BSDEthernetTapFactory();
+
+ virtual EthernetTap *open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg);
+ virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
+
+private:
+ std::vector<EthernetTap *> _devices;
+ Mutex _devices_m;
+};
+
+} // namespace ZeroTier
+
+#endif
diff --git a/attic/LinuxEthernetTapFactory.cpp b/attic/LinuxEthernetTapFactory.cpp
new file mode 100644
index 00000000..014c6514
--- /dev/null
+++ b/attic/LinuxEthernetTapFactory.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "LinuxEthernetTapFactory.hpp"
+#include "LinuxEthernetTap.hpp"
+
+namespace ZeroTier {
+
+LinuxEthernetTapFactory::LinuxEthernetTapFactory()
+{
+}
+
+LinuxEthernetTapFactory::~LinuxEthernetTapFactory()
+{
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d)
+ delete *d;
+}
+
+EthernetTap *LinuxEthernetTapFactory::open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg)
+{
+ Mutex::Lock _l(_devices_m);
+ EthernetTap *t = new LinuxEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
+ _devices.push_back(t);
+ return t;
+}
+
+void LinuxEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
+{
+ {
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
+ if (*d == tap) {
+ _devices.erase(d);
+ break;
+ }
+ }
+ }
+ delete tap;
+}
+
+} // namespace ZeroTier
diff --git a/attic/LinuxEthernetTapFactory.hpp b/attic/LinuxEthernetTapFactory.hpp
new file mode 100644
index 00000000..e61863ed
--- /dev/null
+++ b/attic/LinuxEthernetTapFactory.hpp
@@ -0,0 +1,63 @@
+/*
+ * 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 ZT_LINUXETHERNETTAPFACTORY_HPP
+#define ZT_LINUXETHERNETTAPFACTORY_HPP
+
+#include <vector>
+#include <string>
+
+#include "../node/EthernetTapFactory.hpp"
+#include "../node/Mutex.hpp"
+
+namespace ZeroTier {
+
+class LinuxEthernetTapFactory : public EthernetTapFactory
+{
+public:
+ LinuxEthernetTapFactory();
+ virtual ~LinuxEthernetTapFactory();
+
+ virtual EthernetTap *open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg);
+ virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
+
+private:
+ std::vector<EthernetTap *> _devices;
+ Mutex _devices_m;
+};
+
+} // namespace ZeroTier
+
+#endif
diff --git a/attic/OSXEthernetTapFactory.cpp b/attic/OSXEthernetTapFactory.cpp
new file mode 100644
index 00000000..4cad8daa
--- /dev/null
+++ b/attic/OSXEthernetTapFactory.cpp
@@ -0,0 +1,122 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include "OSXEthernetTapFactory.hpp"
+#include "OSXEthernetTap.hpp"
+
+#include "../node/Utils.hpp"
+
+namespace ZeroTier {
+
+OSXEthernetTapFactory::OSXEthernetTapFactory(const char *pathToTapKext,const char *tapKextName) :
+ _pathToTapKext((pathToTapKext) ? pathToTapKext : ""),
+ _tapKextName((tapKextName) ? tapKextName : "")
+{
+ struct stat stattmp;
+
+ if ((_pathToTapKext.length())&&(_tapKextName.length())) {
+ if (stat("/dev/zt0",&stattmp)) {
+ long kextpid = (long)vfork();
+ if (kextpid == 0) {
+ ::chdir(_pathToTapKext.c_str());
+ Utils::redirectUnixOutputs("/dev/null",(const char *)0);
+ ::execl("/sbin/kextload","/sbin/kextload","-q","-repository",_pathToTapKext.c_str(),_tapKextName.c_str(),(const char *)0);
+ ::_exit(-1);
+ } else if (kextpid > 0) {
+ int exitcode = -1;
+ ::waitpid(kextpid,&exitcode,0);
+ } else throw std::runtime_error("unable to create subprocess with fork()");
+ }
+ }
+
+ if (stat("/dev/zt0",&stattmp)) {
+ ::usleep(500); // give tap device driver time to start up and try again
+ if (stat("/dev/zt0",&stattmp))
+ throw std::runtime_error("/dev/zt# tap devices do not exist and unable to load kernel extension");
+ }
+}
+
+OSXEthernetTapFactory::~OSXEthernetTapFactory()
+{
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d)
+ delete *d;
+
+ if ((_pathToTapKext.length())&&(_tapKextName.length())) {
+ // Attempt to unload kext. If anything else is using a /dev/zt# node, this
+ // fails and the kext stays in the kernel.
+ char tmp[16384];
+ sprintf(tmp,"%s/%s",_pathToTapKext.c_str(),_tapKextName.c_str());
+ long kextpid = (long)vfork();
+ if (kextpid == 0) {
+ Utils::redirectUnixOutputs("/dev/null",(const char *)0);
+ ::execl("/sbin/kextunload","/sbin/kextunload",tmp,(const char *)0);
+ ::_exit(-1);
+ } else if (kextpid > 0) {
+ int exitcode = -1;
+ ::waitpid(kextpid,&exitcode,0);
+ }
+ }
+}
+
+EthernetTap *OSXEthernetTapFactory::open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg)
+{
+ Mutex::Lock _l(_devices_m);
+ EthernetTap *t = new OSXEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
+ _devices.push_back(t);
+ return t;
+}
+
+void OSXEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
+{
+ {
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
+ if (*d == tap) {
+ _devices.erase(d);
+ break;
+ }
+ }
+ }
+ delete tap;
+}
+
+} // namespace ZeroTier
diff --git a/attic/OSXEthernetTapFactory.hpp b/attic/OSXEthernetTapFactory.hpp
new file mode 100644
index 00000000..2f2ee527
--- /dev/null
+++ b/attic/OSXEthernetTapFactory.hpp
@@ -0,0 +1,76 @@
+/*
+ * 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 ZT_OSXETHERNETTAPFACTORY_HPP
+#define ZT_OSXETHERNETTAPFACTORY_HPP
+
+#include <vector>
+#include <string>
+
+#include "../node/EthernetTapFactory.hpp"
+#include "../node/Mutex.hpp"
+
+namespace ZeroTier {
+
+class OSXEthernetTapFactory : public EthernetTapFactory
+{
+public:
+ /**
+ * Create OSX ethernet tap factory
+ *
+ * If kext paths are specified, an attempt will be made to load the kext
+ * on launch if not present and unload it on shutdown.
+ *
+ * @param pathToTapKext Full path to the location of the tap kext
+ * @param tapKextName Name of tap kext as found within tap kext path (usually "tap.kext")
+ * @throws std::runtime_error Tap not available and unable to load kext
+ */
+ OSXEthernetTapFactory(const char *pathToTapKext,const char *tapKextName);
+
+ virtual ~OSXEthernetTapFactory();
+
+ virtual EthernetTap *open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg);
+ virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
+
+private:
+ std::vector<EthernetTap *> _devices;
+ Mutex _devices_m;
+ std::string _pathToTapKext;
+ std::string _tapKextName;
+};
+
+} // namespace ZeroTier
+
+#endif
diff --git a/attic/WindowsEthernetTapFactory.cpp b/attic/WindowsEthernetTapFactory.cpp
new file mode 100644
index 00000000..996460a1
--- /dev/null
+++ b/attic/WindowsEthernetTapFactory.cpp
@@ -0,0 +1,162 @@
+/*
+ * 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 "WindowsEthernetTapFactory.hpp"
+#include "WindowsEthernetTap.hpp"
+
+namespace ZeroTier {
+
+WindowsEthernetTapFactory::Env::Env()
+{
+#ifdef _WIN64
+ is64Bit = TRUE;
+ devcon = "\\devcon_x64.exe";
+ tapDriver = "\\tap-windows\\x64\\zttap200.inf";
+#else
+ is64Bit = FALSE;
+ IsWow64Process(GetCurrentProcess(),&is64Bit);
+ devcon = ((is64Bit == TRUE) ? "\\devcon_x64.exe" : "\\devcon_x86.exe");
+ tapDriver = ((is64Bit == TRUE) ? "\\tap-windows\\x64\\zttap200.inf" : "\\tap-windows\\x86\\zttap200.inf");
+#endif
+}
+const WindowsEthernetTapFactory::Env WindowsEthernetTapFactory::WINENV;
+
+WindowsEthernetTapFactory::WindowsEthernetTapFactory(const char *pathToHelpers) :
+ _pathToHelpers(pathToHelpers)
+{
+}
+
+WindowsEthernetTapFactory::~WindowsEthernetTapFactory()
+{
+ Mutex::Lock _l(_devices_m);
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d)
+ delete *d;
+}
+
+EthernetTap *WindowsEthernetTapFactory::open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg)
+{
+ Mutex::Lock _l(_devices_m);
+ EthernetTap *t = new WindowsEthernetTap(_pathToHelpers.c_str(),mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg);
+ _devices.push_back(t);
+ return t;
+}
+
+void WindowsEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices)
+{
+ if (!tap)
+ return;
+
+ std::string instanceId(((WindowsEthernetTap *)tap)->instanceId());
+ Mutex::Lock _l(_devices_m);
+
+ for(std::vector<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
+ if (*d == tap) {
+ _devices.erase(d);
+ break;
+ }
+ }
+
+ delete tap;
+
+ if (destroyPersistentDevices)
+ _deletePersistentTapDevice(_pathToHelpers.c_str(),instanceId.c_str());
+}
+
+void WindowsEthernetTapFactory::destroyAllPersistentTapDevices(const char *pathToHelpers)
+{
+ char subkeyName[4096];
+ char subkeyClass[4096];
+ char data[4096];
+
+ std::set<std::string> instanceIdPathsToRemove;
+ {
+ HKEY nwAdapters;
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_READ|KEY_WRITE,&nwAdapters) != ERROR_SUCCESS)
+ return;
+
+ for(DWORD subkeyIndex=0;;++subkeyIndex) {
+ DWORD type;
+ DWORD dataLen;
+ DWORD subkeyNameLen = sizeof(subkeyName);
+ DWORD subkeyClassLen = sizeof(subkeyClass);
+ FILETIME lastWriteTime;
+ if (RegEnumKeyExA(nwAdapters,subkeyIndex,subkeyName,&subkeyNameLen,(DWORD *)0,subkeyClass,&subkeyClassLen,&lastWriteTime) == ERROR_SUCCESS) {
+ type = 0;
+ dataLen = sizeof(data);
+ if (RegGetValueA(nwAdapters,subkeyName,"ComponentId",RRF_RT_ANY,&type,(PVOID)data,&dataLen) == ERROR_SUCCESS) {
+ data[dataLen] = '\0';
+ if (!strnicmp(data,"zttap",5)) {
+ std::string instanceIdPath;
+ type = 0;
+ dataLen = sizeof(data);
+ if (RegGetValueA(nwAdapters,subkeyName,"DeviceInstanceID",RRF_RT_ANY,&type,(PVOID)data,&dataLen) == ERROR_SUCCESS)
+ instanceIdPath.assign(data,dataLen);
+ if (instanceIdPath.length() != 0)
+ instanceIdPathsToRemove.insert(instanceIdPath);
+ }
+ }
+ } else break; // end of list or failure
+ }
+
+ RegCloseKey(nwAdapters);
+ }
+
+ for(std::set<std::string>::iterator iidp(instanceIdPathsToRemove.begin());iidp!=instanceIdPathsToRemove.end();++iidp)
+ _deletePersistentTapDevice(pathToHelpers,iidp->c_str());
+}
+
+void WindowsEthernetTapFactory::_deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId)
+{
+ HANDLE devconLog = CreateFileA((std::string(pathToHelpers) + "\\devcon.log").c_str(),GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+ STARTUPINFOA startupInfo;
+ startupInfo.cb = sizeof(startupInfo);
+ if (devconLog != INVALID_HANDLE_VALUE) {
+ SetFilePointer(devconLog,0,0,FILE_END);
+ startupInfo.hStdOutput = devconLog;
+ startupInfo.hStdError = devconLog;
+ }
+ PROCESS_INFORMATION processInfo;
+ memset(&startupInfo,0,sizeof(STARTUPINFOA));
+ memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
+ if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + pathToHelpers + WINENV.devcon + "\" remove @" + instanceId).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
+ WaitForSingleObject(processInfo.hProcess,INFINITE);
+ CloseHandle(processInfo.hProcess);
+ CloseHandle(processInfo.hThread);
+ }
+ if (devconLog != INVALID_HANDLE_VALUE)
+ CloseHandle(devconLog);
+}
+
+} // namespace ZeroTier
diff --git a/attic/WindowsEthernetTapFactory.hpp b/attic/WindowsEthernetTapFactory.hpp
new file mode 100644
index 00000000..47e146e3
--- /dev/null
+++ b/attic/WindowsEthernetTapFactory.hpp
@@ -0,0 +1,90 @@
+/*
+ * 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 ZT_WINDOWSETHERNETTAPFACTORY_HPP
+#define ZT_WINDOWSETHERNETTAPFACTORY_HPP
+
+#include <vector>
+#include <string>
+
+#include "../node/EthernetTapFactory.hpp"
+#include "../node/Mutex.hpp"
+
+namespace ZeroTier {
+
+class WindowsEthernetTapFactory : public EthernetTapFactory
+{
+public:
+ class Env
+ {
+ public:
+ Env();
+ BOOL is64Bit; // true if WIN64 or WoW64 (32-bit binary on 64-bit architecture)
+ const char *devcon; // name of devcon binary in pathToHelpers to use
+ const char *tapDriver; // relative path to driver under pathToHelpers to use
+ };
+
+ /**
+ * Constants related to Windows environment, computed on program start
+ */
+ static const Env WINENV;
+
+ /**
+ * @param pathToHelpers Path to devcon32.exe, devcon64.exe, and other required helper binaries (ZeroTier running directory)
+ */
+ WindowsEthernetTapFactory(const char *pathToHelpers);
+ virtual ~WindowsEthernetTapFactory();
+
+ virtual EthernetTap *open(
+ const MAC &mac,
+ unsigned int mtu,
+ unsigned int metric,
+ uint64_t nwid,
+ const char *desiredDevice,
+ const char *friendlyName,
+ void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
+ void *arg);
+ virtual void close(EthernetTap *tap,bool destroyPersistentDevices);
+
+ /**
+ * Uninstalls all persistent tap devices in the system belonging to ZeroTier
+ *
+ * This is for uninstallation. Do not call this while tap devices are active.
+ */
+ static void destroyAllPersistentTapDevices(const char *pathToHelpers);
+
+private:
+ static void _deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId);
+
+ std::string _pathToHelpers;
+ std::vector<EthernetTap *> _devices;
+ Mutex _devices_m;
+};
+
+} // namespace ZeroTier
+
+#endif