summaryrefslogtreecommitdiff
path: root/service/OneService.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'service/OneService.cpp')
-rw-r--r--service/OneService.cpp21
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;
};