diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-11 14:21:59 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-11 14:21:59 -0800 |
| commit | 3f912eb4ada67610eee21d3749ba7d5cfb083359 (patch) | |
| tree | fe8fac739717067998bcdc732f64f1b721f077a5 /node/Network.cpp | |
| parent | f1b45f7df0381dbf6c46208daa86cde336ab644c (diff) | |
| download | infinitytier-3f912eb4ada67610eee21d3749ba7d5cfb083359.tar.gz infinitytier-3f912eb4ada67610eee21d3749ba7d5cfb083359.zip | |
Fix for GitHub issue #37: remember *nix device names.
Diffstat (limited to 'node/Network.cpp')
| -rw-r--r-- | node/Network.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/node/Network.cpp b/node/Network.cpp index db252f73..19190207 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -75,7 +75,7 @@ Network::~Network() } } -SharedPtr<Network> Network::newInstance(const RuntimeEnvironment *renv,uint64_t id) +SharedPtr<Network> Network::newInstance(const RuntimeEnvironment *renv,NodeConfig *nc,uint64_t id) { /* We construct Network via a static method to ensure that it is immediately * wrapped in a SharedPtr<>. Otherwise if there is traffic on the Ethernet @@ -85,6 +85,7 @@ SharedPtr<Network> Network::newInstance(const RuntimeEnvironment *renv,uint64_t SharedPtr<Network> nw(new Network()); nw->_id = id; + nw->_nc = nc; nw->_mac = renv->identity.address().toMAC(); nw->_r = renv; nw->_tap = (EthernetTap *)0; @@ -269,12 +270,31 @@ void Network::_pushMembershipCertificate(const Address &peer,bool force,uint64_t void Network::threadMain() throw() { + // Setup thread -- this exits when tap is constructed. It's here + // because opening the tap can take some time on some platforms. + try { - // Setup thread -- this exits when tap is constructed. It's here - // because opening the tap can take some time on some platforms. - char tag[32]; +#ifdef __WINDOWS__ + // Windows tags interfaces by their network IDs, which are shoved into the + // registry to mark persistent instance of the tap device. + char tag[24]; Utils::snprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)_id); +#else + // Unix tries to get the same device name next time, if possible. + std::string tagstr; + char lcentry[128]; + Utils::snprintf(lcentry,sizeof(lcentry),"_dev_for_%.16llx",(unsigned long long)_id); + tagstr = _nc->getLocalConfig(lcentry); + const char *tag = (tagstr.length() > 0) ? tagstr.c_str() : (const char *)0; +#endif + _tap = new EthernetTap(_r,tag,_mac,ZT_IF_MTU,&_CBhandleTapData,this); + +#ifndef __WINDOWS__ + std::string dn(_tap->deviceName()); + if ((!tag)||(dn != tag)) + _nc->putLocalConfig(lcentry,dn); +#endif } catch (std::exception &exc) { LOG("network %.16llx failed to initialize: %s",_id,exc.what()); _netconfFailure = NETCONF_FAILURE_INIT_FAILED; |
