avoid port mapping of local addresses (#2296)

This commit is contained in:
Alden Torres 2017-09-01 13:28:27 -04:00 committed by Arvid Norberg
parent f022285b13
commit ac914d4415
2 changed files with 16 additions and 1 deletions

View File

@ -69,10 +69,17 @@ namespace libtorrent {
#if TORRENT_USE_IPV6
if (a.is_v6())
{
// NOTE: site local is deprecated but by
// https://www.ietf.org/rfc/rfc3879.txt:
// routers SHOULD be configured to prevent
// routing of this prefix by default.
address_v6 const a6 = a.to_v6();
return a6.is_loopback()
|| a6.is_link_local()
|| a6.is_site_local()
|| a6.is_multicast_link_local()
|| a6.is_multicast_site_local()
// fc00::/7, unique local address
|| (a6.to_bytes()[0] & 0xfe) == 0xfc;
}

View File

@ -2172,12 +2172,20 @@ namespace {
if (map_handle != -1) m.delete_mapping(map_handle);
map_handle = -1;
#if TORRENT_USE_IPV6
address const addr = ep.address();
// with IPv4 the interface might be behind NAT so we can't skip them
// based on the scope of the local address
if (addr.is_v6() && is_local(addr))
return;
#endif
// only update this mapping if we actually have a socket listening
if (ep != EndpointType())
map_handle = m.add_mapping(protocol, ep.port(), ep);
}
tcp::endpoint to_tcp(udp::endpoint const ep)
tcp::endpoint to_tcp(udp::endpoint const& ep)
{
return tcp::endpoint(ep.address(), ep.port());
}