summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
Diffstat (limited to 'node')
-rw-r--r--node/EthernetTap.cpp33
-rw-r--r--node/EthernetTap.hpp28
-rw-r--r--node/Network.cpp1
-rw-r--r--node/Network.hpp9
4 files changed, 71 insertions, 0 deletions
diff --git a/node/EthernetTap.cpp b/node/EthernetTap.cpp
index ee866b6d..9088343c 100644
--- a/node/EthernetTap.cpp
+++ b/node/EthernetTap.cpp
@@ -739,6 +739,8 @@ EthernetTap::EthernetTap(
_r(renv),
_handler(handler),
_arg(arg),
+ _dhcp(false),
+ _dhcp6(false),
_tap(INVALID_HANDLE_VALUE),
_injectSemaphore(INVALID_HANDLE_VALUE),
_run(true)
@@ -901,6 +903,9 @@ EthernetTap::EthernetTap(
throw std::runtime_error("unable to convert instance ID GUID to native GUID (invalid NetCfgInstanceId in registry?)");
}
+ setDhcpEnabled(false);
+ setDhcp6Enabled(false);
+
// Disable and enable interface to ensure registry settings take effect
{
STARTUPINFOA startupInfo;
@@ -989,6 +994,34 @@ void EthernetTap::whack()
{
}
+bool EthernetTap::setDhcpEnabled(bool dhcp)
+{
+ HKEY tcpIpInterfaces;
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces",0,KEY_READ|KEY_WRITE,&tcpIpInterfaces) == ERROR_SUCCESS) {
+ _dhcp = dhcp;
+ DWORD enable = (dhcp ? 1 : 0);
+ RegSetKeyValueA(tcpIpInterfaces,_myDeviceInstanceId.c_str(),"EnableDHCP",REG_DWORD,&enable,sizeof(enable));
+ RegCloseKey(tcpIpInterfaces);
+ } else _dhcp = false;
+
+ return _dhcp;
+}
+
+bool EthernetTap::setDhcp6Enabled(bool dhcp)
+{
+ // TODO
+ return _dhcp6;
+}
+
+void EthernetTap::setDisplayName(const char *dn)
+{
+ HKEY ifp;
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,(std::string("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\") + _myDeviceInstanceId).c_str(),0,KEY_READ|KEY_WRITE,&ifp) == ERROR_SUCCESS) {
+ RegSetKeyValueA(ifp,"Connection","Name",REG_SZ,(LPCVOID)dn,strlen(dn)+1);
+ RegCloseKey(ifp);
+ }
+}
+
bool EthernetTap::addIP(const InetAddress &ip)
{
Mutex::Lock _l(_ips_m);
diff --git a/node/EthernetTap.hpp b/node/EthernetTap.hpp
index 87a7de55..3db41392 100644
--- a/node/EthernetTap.hpp
+++ b/node/EthernetTap.hpp
@@ -100,6 +100,31 @@ public:
void whack();
/**
+ * Set whether or not DHCP is enabled (disabled by default)
+ *
+ * @param dhcp DHCP status
+ * @return New state of DHCP (may be false even on 'true' if DHCP enable failed)
+ */
+ bool setDhcpEnabled(bool dhcp);
+
+ /**
+ * Set whether or not DHCP6 is enabled (disabled by default)
+ *
+ * @param dhcp DHCP6 status
+ * @return New state of DHCP6 (may be false even on 'true' if DHCP enable failed)
+ */
+ bool setDhcp6Enabled(bool dhcp);
+
+ /**
+ * Set the user display name for this connection
+ *
+ * This does nothing on platforms that don't have this concept.
+ *
+ * @param dn User display name
+ */
+ void setDisplayName(const char *dn);
+
+ /**
* @return MAC address of this interface
*/
inline const MAC &mac() const throw() { return _mac; }
@@ -205,6 +230,9 @@ private:
void (*_handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &);
void *_arg;
+ bool _dhcp;
+ bool _dhcp6;
+
Thread _thread;
#ifdef __UNIX_LIKE__
diff --git a/node/Network.cpp b/node/Network.cpp
index 496e58fe..730e86d2 100644
--- a/node/Network.cpp
+++ b/node/Network.cpp
@@ -175,6 +175,7 @@ void Network::setConfiguration(const Network::Config &conf)
_lastConfigUpdate = Utils::now();
_tap->setIps(conf.staticAddresses());
+ _tap->setDisplayName((std::string("ZeroTier One [") + conf.name() + "]").c_str());
std::string confPath(_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d" + ZT_PATH_SEPARATOR_S + toString() + ".conf");
if (!Utils::writeFile(confPath.c_str(),conf.toString())) {
diff --git a/node/Network.hpp b/node/Network.hpp
index f263cd5d..f692c168 100644
--- a/node/Network.hpp
+++ b/node/Network.hpp
@@ -233,6 +233,15 @@ public:
#endif
}
+ inline std::string name() const
+ {
+ if (contains("name"))
+ return get("name");
+ char buf[32];
+ sprintf(buf,"%.16llx",(unsigned long long)networkId());
+ return std::string(buf);
+ }
+
inline Address peerAddress() const
throw(std::invalid_argument)
{