mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 21:43:08 +00:00
Add a portMappingEnabled flag to local.conf to allow uPnP/NAT-PMP to be disabled.
This commit is contained in:
parent
56e5b34934
commit
89d74cd293
@ -344,6 +344,7 @@ public:
|
|||||||
Mutex _termReason_m;
|
Mutex _termReason_m;
|
||||||
|
|
||||||
// uPnP/NAT-PMP port mapper if enabled
|
// uPnP/NAT-PMP port mapper if enabled
|
||||||
|
bool _portMappingEnabled; // local.conf settings
|
||||||
#ifdef ZT_USE_MINIUPNPC
|
#ifdef ZT_USE_MINIUPNPC
|
||||||
PortMapper *_portMapper;
|
PortMapper *_portMapper;
|
||||||
#endif
|
#endif
|
||||||
@ -379,6 +380,7 @@ public:
|
|||||||
,_nextBackgroundTaskDeadline(0)
|
,_nextBackgroundTaskDeadline(0)
|
||||||
,_tcpFallbackTunnel((TcpConnection *)0)
|
,_tcpFallbackTunnel((TcpConnection *)0)
|
||||||
,_termReason(ONE_STILL_RUNNING)
|
,_termReason(ONE_STILL_RUNNING)
|
||||||
|
,_portMappingEnabled(true)
|
||||||
#ifdef ZT_USE_MINIUPNPC
|
#ifdef ZT_USE_MINIUPNPC
|
||||||
,_portMapper((PortMapper *)0)
|
,_portMapper((PortMapper *)0)
|
||||||
#endif
|
#endif
|
||||||
@ -598,25 +600,27 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ZT_USE_MINIUPNPC
|
#ifdef ZT_USE_MINIUPNPC
|
||||||
// If we're running uPnP/NAT-PMP, bind a *third* port for that. We can't
|
if (_portMappingEnabled) {
|
||||||
// use the other two ports for that because some NATs do really funky
|
// If we're running uPnP/NAT-PMP, bind a *third* port for that. We can't
|
||||||
// stuff with ports that are explicitly mapped that breaks things.
|
// use the other two ports for that because some NATs do really funky
|
||||||
if (_ports[1]) {
|
// stuff with ports that are explicitly mapped that breaks things.
|
||||||
_ports[2] = _ports[1];
|
if (_ports[1]) {
|
||||||
for(int i=0;;++i) {
|
_ports[2] = _ports[1];
|
||||||
if (i > 1000) {
|
for(int i=0;;++i) {
|
||||||
_ports[2] = 0;
|
if (i > 1000) {
|
||||||
break;
|
_ports[2] = 0;
|
||||||
} else if (++_ports[2] >= 65536) {
|
break;
|
||||||
_ports[2] = 20000;
|
} else if (++_ports[2] >= 65536) {
|
||||||
|
_ports[2] = 20000;
|
||||||
|
}
|
||||||
|
if (_trialBind(_ports[2]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_ports[2]) {
|
||||||
|
char uniqueName[64];
|
||||||
|
Utils::snprintf(uniqueName,sizeof(uniqueName),"ZeroTier/%.10llx@%u",_node->address(),_ports[2]);
|
||||||
|
_portMapper = new PortMapper(_ports[2],uniqueName);
|
||||||
}
|
}
|
||||||
if (_trialBind(_ports[2]))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (_ports[2]) {
|
|
||||||
char uniqueName[64];
|
|
||||||
Utils::snprintf(uniqueName,sizeof(uniqueName),"ZeroTier/%.10llx@%u",_node->address(),_ports[2]);
|
|
||||||
_portMapper = new PortMapper(_ports[2],uniqueName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -983,6 +987,8 @@ public:
|
|||||||
_interfacePrefixBlacklist.clear();
|
_interfacePrefixBlacklist.clear();
|
||||||
json &settings = _localConfig["settings"];
|
json &settings = _localConfig["settings"];
|
||||||
if (settings.is_object()) {
|
if (settings.is_object()) {
|
||||||
|
_portMappingEnabled = OSUtils::jsonBool(settings["portMappingEnabled"],true);
|
||||||
|
|
||||||
const std::string rp(OSUtils::jsonString(settings["relayPolicy"],""));
|
const std::string rp(OSUtils::jsonString(settings["relayPolicy"],""));
|
||||||
if ((rp == "always")||(rp == "ALWAYS"))
|
if ((rp == "always")||(rp == "ALWAYS"))
|
||||||
_node->setRelayPolicy(ZT_RELAY_POLICY_ALWAYS);
|
_node->setRelayPolicy(ZT_RELAY_POLICY_ALWAYS);
|
||||||
|
Loading…
Reference in New Issue
Block a user