diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-14 15:55:03 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-14 15:55:03 -0700 |
commit | e205e5fdfea608e38a2a138aa8738c0885537c04 (patch) | |
tree | aa7595a1dfd2eb92aca85cdc16ba785e613257a3 | |
parent | 347e98dcd2d29772d5b9cf23c307b0a6ce0d8858 (diff) | |
download | infinitytier-e205e5fdfea608e38a2a138aa8738c0885537c04.tar.gz infinitytier-e205e5fdfea608e38a2a138aa8738c0885537c04.zip |
Include tap device name in JSON output for network info.
-rw-r--r-- | service/ControlPlane.cpp | 18 | ||||
-rw-r--r-- | service/ControlPlane.hpp | 4 | ||||
-rw-r--r-- | service/One.cpp | 21 | ||||
-rw-r--r-- | service/One.hpp | 5 |
4 files changed, 38 insertions, 10 deletions
diff --git a/service/ControlPlane.cpp b/service/ControlPlane.cpp index 01e31fbf..146c20d6 100644 --- a/service/ControlPlane.cpp +++ b/service/ControlPlane.cpp @@ -26,6 +26,7 @@ */ #include "ControlPlane.hpp" +#include "One.hpp" #include "../version.h" #include "../include/ZeroTierOne.h" @@ -115,7 +116,7 @@ static std::string _jsonEnumerate(const ZT1_PeerPhysicalPath *pp,unsigned int co buf.push_back(']'); return buf; } -static void _jsonAppend(std::string &buf,const ZT1_VirtualNetworkConfig *nc) +static void _jsonAppend(std::string &buf,const ZT1_VirtualNetworkConfig *nc,const std::string &portDeviceName) { char json[65536]; const char *nstatus = "",*ntype = ""; @@ -145,7 +146,8 @@ static void _jsonAppend(std::string &buf,const ZT1_VirtualNetworkConfig *nc) "\"portError\": %d," "\"netconfRevision\": %lu," "\"multicastSubscriptions\": %s," - "\"assignedAddresses\": %s" + "\"assignedAddresses\": %s," + "\"portDeviceName\": \"%s\"" "}", nc->nwid, (unsigned int)((nc->mac >> 40) & 0xff),(unsigned int)((nc->mac >> 32) & 0xff),(unsigned int)((nc->mac >> 24) & 0xff),(unsigned int)((nc->mac >> 16) & 0xff),(unsigned int)((nc->mac >> 8) & 0xff),(unsigned int)(nc->mac & 0xff), @@ -159,7 +161,8 @@ static void _jsonAppend(std::string &buf,const ZT1_VirtualNetworkConfig *nc) nc->portError, nc->netconfRevision, _jsonEnumerate(nc->multicastSubscriptions,nc->multicastSubscriptionCount).c_str(), - _jsonEnumerate(nc->assignedAddresses,nc->assignedAddressCount).c_str()); + _jsonEnumerate(nc->assignedAddresses,nc->assignedAddressCount).c_str(), + _jsonEscape(portDeviceName).c_str()); buf.append(json); } static void _jsonAppend(std::string &buf,const ZT1_Peer *peer) @@ -193,7 +196,8 @@ static void _jsonAppend(std::string &buf,const ZT1_Peer *peer) buf.append(json); } -ControlPlane::ControlPlane(Node *n) : +ControlPlane::ControlPlane(One *svc,Node *n) : + _svc(svc), _node(n) { } @@ -317,7 +321,7 @@ unsigned int ControlPlane::handleRequest( for(unsigned long i=0;i<nws->networkCount;++i) { if (i > 0) responseBody.push_back(','); - _jsonAppend(responseBody,&(nws->networks[i])); + _jsonAppend(responseBody,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid)); } responseBody.push_back(']'); scode = 200; @@ -327,7 +331,7 @@ unsigned int ControlPlane::handleRequest( for(unsigned long i=0;i<nws->networkCount;++i) { if (nws->networks[i].nwid == wantnw) { responseContentType = "application/json"; - _jsonAppend(responseBody,&(nws->networks[i])); + _jsonAppend(responseBody,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid)); scode = 200; break; } @@ -384,7 +388,7 @@ unsigned int ControlPlane::handleRequest( for(unsigned long i=0;i<nws->networkCount;++i) { if (nws->networks[i].nwid == wantnw) { responseContentType = "application/json"; - _jsonAppend(responseBody,&(nws->networks[i])); + _jsonAppend(responseBody,&(nws->networks[i]),_svc->portDeviceName(nws->networks[i].nwid)); scode = 200; break; } diff --git a/service/ControlPlane.hpp b/service/ControlPlane.hpp index 87a65ead..a181eb5c 100644 --- a/service/ControlPlane.hpp +++ b/service/ControlPlane.hpp @@ -36,6 +36,7 @@ namespace ZeroTier { +class One; class Node; struct InetAddress; @@ -45,7 +46,7 @@ struct InetAddress; class ControlPlane { public: - ControlPlane(Node *n); + ControlPlane(One *svc,Node *n); ~ControlPlane(); /** @@ -70,6 +71,7 @@ public: std::string &responseContentType); private: + One *const _svc; Node *const _node; std::set<std::string> _authTokens; }; diff --git a/service/One.cpp b/service/One.cpp index c4e1b251..031dc375 100644 --- a/service/One.cpp +++ b/service/One.cpp @@ -52,6 +52,11 @@ #include "One.hpp" #include "ControlPlane.hpp" +#ifdef __APPLE__ +#include "../osdep/OSXEthernetTap.hpp" +namespace ZeroTier { typedef OSXEthernetTap EthernetTap; } +#endif + // Sanity limits for HTTP #define ZT_MAX_HTTP_MESSAGE_SIZE (1024 * 1024 * 8) #define ZT_MAX_HTTP_CONNECTIONS 64 @@ -189,9 +194,9 @@ public: if (_master) _node->setNetconfMaster((void *)_master); - _controlPlane = new ControlPlane(_node); + _controlPlane = new ControlPlane(this,_node); - { + { // Remember networks from previous session std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str())); for(std::vector<std::string>::iterator f(networksDotD.begin());f!=networksDotD.end();++f) { std::size_t dot = f->find_last_of('.'); @@ -259,6 +264,15 @@ public: return _fatalErrorMessage; } + virtual std::string portDeviceName(uint64_t nwid) const + { + Mutex::Lock _l(_taps_m); + std::map< uint64_t,EthernetTap * >::const_iterator t(_taps.find(nwid)); + if (t != _taps.end()) + return t->second->deviceName(); + return std::string(); + } + virtual void terminate() { _run_m.lock(); @@ -537,6 +551,9 @@ private: ControlPlane *_controlPlane; uint64_t _nextBackgroundTaskDeadline; + std::map< uint64_t,EthernetTap * > _taps; + Mutex _taps_m; + std::map< PhySocket *,HttpConnection > _httpConnections; // no mutex for this since it's done in the main loop thread only ReasonForTermination _termReason; diff --git a/service/One.hpp b/service/One.hpp index a1e8d2ad..48fbc2ba 100644 --- a/service/One.hpp +++ b/service/One.hpp @@ -112,6 +112,11 @@ public: virtual std::string fatalErrorMessage() const = 0; /** + * @return System device name corresponding with a given ZeroTier network ID + */ + virtual std::string portDeviceName(uint64_t nwid) const = 0; + + /** * Terminate background service (can be called from other threads) */ virtual void terminate() = 0; |