diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-07-28 14:32:02 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-07-28 14:32:02 -0700 |
commit | fe6d5b1402307e1be80e6d78b765cf5175288c1f (patch) | |
tree | c568c74a579f363a9bc2f7439d88173b06f00734 /service | |
parent | d2bfdfa6e79e54ba1d5127a75a56f7ec57415cf9 (diff) | |
download | infinitytier-fe6d5b1402307e1be80e6d78b765cf5175288c1f.tar.gz infinitytier-fe6d5b1402307e1be80e6d78b765cf5175288c1f.zip |
UPNP/NAT-PMP support with libminiupnpc (if built with it) -- GitHub issue #64
Diffstat (limited to 'service')
-rw-r--r-- | service/OneService.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/service/OneService.cpp b/service/OneService.cpp index b83cd83f..05fdfb90 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -54,6 +54,7 @@ #include "../osdep/OSUtils.hpp" #include "../osdep/Http.hpp" #include "../osdep/BackgroundResolver.hpp" +#include "../osdep/UPNPClient.hpp" #include "OneService.hpp" #include "ControlPlane.hpp" @@ -415,6 +416,9 @@ public: _tcpFallbackTunnel((TcpConnection *)0), _termReason(ONE_STILL_RUNNING), _port(port), +#ifdef ZT_USE_MINIUPNPC + _upnpClient((int)port), +#endif _run(true) { struct sockaddr_in in4; @@ -511,7 +515,7 @@ public: _lastRestart = clockShouldBe; uint64_t lastTapMulticastGroupCheck = 0; uint64_t lastTcpFallbackResolve = 0; - uint64_t lastLocalInterfaceAddressCheck = 0; + uint64_t lastLocalInterfaceAddressCheck = (OSUtils::now() - ZT1_LOCAL_INTERFACE_CHECK_INTERVAL) + 15000; // do this in 15s to give UPnP time to configure and other things time to settle #ifdef ZT_AUTO_UPDATE uint64_t lastSoftwareUpdateCheck = 0; #endif // ZT_AUTO_UPDATE @@ -576,9 +580,18 @@ public: ztDevices.push_back(t->second->deviceName()); } + _node->clearLocalInterfaceAddresses(); + +#ifdef ZT_USE_MINIUPNPC + std::vector<InetAddress> upnpAddresses(_upnpClient.get()); + for(std::vector<InetAddress>::const_iterator ext(upnpAddresses.begin());ext!=upnpAddresses.end();++ext) { + printf("Adding UPNP address: %s\n",ext->toString().c_str()); + _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*ext)),0,ZT1_LOCAL_INTERFACE_ADDRESS_TRUST_NORMAL); + } +#endif + struct ifaddrs *ifatbl = (struct ifaddrs *)0; if ((getifaddrs(&ifatbl) == 0)&&(ifatbl)) { - _node->clearLocalInterfaceAddresses(); struct ifaddrs *ifa = ifatbl; while (ifa) { if ((ifa->ifa_name)&&(ifa->ifa_addr)) { @@ -1242,6 +1255,10 @@ private: unsigned int _port; +#ifdef ZT_USE_MINIUPNPC + UPNPClient _upnpClient; +#endif + bool _run; Mutex _run_m; }; |