forked from premiere/premiere-libtorrent
avoid port mapping of local addresses (#2296)
This commit is contained in:
parent
f022285b13
commit
ac914d4415
|
@ -69,10 +69,17 @@ namespace libtorrent {
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
if (a.is_v6())
|
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();
|
address_v6 const a6 = a.to_v6();
|
||||||
return a6.is_loopback()
|
return a6.is_loopback()
|
||||||
|| a6.is_link_local()
|
|| a6.is_link_local()
|
||||||
|
|| a6.is_site_local()
|
||||||
|| a6.is_multicast_link_local()
|
|| a6.is_multicast_link_local()
|
||||||
|
|| a6.is_multicast_site_local()
|
||||||
// fc00::/7, unique local address
|
// fc00::/7, unique local address
|
||||||
|| (a6.to_bytes()[0] & 0xfe) == 0xfc;
|
|| (a6.to_bytes()[0] & 0xfe) == 0xfc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2172,12 +2172,20 @@ namespace {
|
||||||
if (map_handle != -1) m.delete_mapping(map_handle);
|
if (map_handle != -1) m.delete_mapping(map_handle);
|
||||||
map_handle = -1;
|
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
|
// only update this mapping if we actually have a socket listening
|
||||||
if (ep != EndpointType())
|
if (ep != EndpointType())
|
||||||
map_handle = m.add_mapping(protocol, ep.port(), ep);
|
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());
|
return tcp::endpoint(ep.address(), ep.port());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue