diff --git a/docs/manual.rst b/docs/manual.rst index 9ba9acbb4..ffd7e8714 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -776,7 +776,10 @@ unless the following conditions are met: * the IP address is not in a known loopback range * the item the IP address was expanded from was not marked local (``l``) * the IP address is in a globally reachable IP address range OR the routing - table contains a default route with a gateway for the corresponding network + table contains a default route with a gateway for the corresponding network. + This bullet only applies when expanding from an unspecified IP address. When + explicitly specifying a device, we don't need to find a route to treat it as + external. The NAT-PMP/PCP and UPnP port mapper objects are only created for networks that are expected to be externally available (i.e. not "local network"). If there are diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index e075d3c28..a9eb79673 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -292,7 +292,6 @@ namespace aux { listen_interface_t const& iface , listen_socket_flags_t flags , span const ifs - , span const routes , std::vector& eps); // expand [::] to all IPv6 interfaces for BEP 45 compliance diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 1f42815e8..93ab99a94 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1747,7 +1747,6 @@ namespace aux { void interface_to_endpoints(listen_interface_t const& iface , listen_socket_flags_t flags , span const ifs - , span const routes , std::vector& eps) { flags |= iface.local ? listen_socket_t::local_network : listen_socket_flags_t{}; @@ -1779,9 +1778,7 @@ namespace aux { // bother looking for the gateway bool const local = iface.local || ipface.interface_address.is_loopback() - || is_link_local(ipface.interface_address) - || (!is_global(ipface.interface_address) - && !has_default_route(ipface.name, family(ipface.interface_address), routes)); + || is_link_local(ipface.interface_address); eps.emplace_back(ipface.interface_address, iface.port, iface.device , ssl, flags | (local ? listen_socket_t::local_network : listen_socket_flags_t{})); @@ -1851,7 +1848,7 @@ namespace aux { // IP address or a device name. In case it's a device name, we want to // (potentially) end up binding a socket for each IP address associated // with that device. - interface_to_endpoints(iface, flags, ifs, routes, eps); + interface_to_endpoints(iface, flags, ifs, eps); } // if no listen interfaces are specified, create sockets to use diff --git a/test/test_listen_socket.cpp b/test/test_listen_socket.cpp index efc98693f..dcca299e5 100644 --- a/test/test_listen_socket.cpp +++ b/test/test_listen_socket.cpp @@ -391,11 +391,10 @@ TORRENT_TEST(expand_unspecified) namespace { std::vector to_endpoint(listen_interface_t const& iface - , span const ifs - , span const routes) + , span const ifs) { std::vector ret; - interface_to_endpoints(iface, aux::listen_socket_t::accept_incoming, ifs, routes, ret); + interface_to_endpoints(iface, aux::listen_socket_t::accept_incoming, ifs, ret); return ret; } @@ -411,7 +410,7 @@ using ls = aux::listen_socket_t; TORRENT_TEST(interface_to_endpoint) { - TEST_CHECK(to_endpoint(ift("10.0.1.1", 6881), {}, {}) == eps{ep("10.0.1.1", 6881)}); + TEST_CHECK(to_endpoint(ift("10.0.1.1", 6881), {}) == eps{ep("10.0.1.1", 6881)}); std::vector const ifs = { @@ -423,25 +422,19 @@ TORRENT_TEST(interface_to_endpoint) , ifc("2601:646:c600:a3:d250:99ff:fe0c:9b74", "eth1") }; - TEST_CHECK((to_endpoint(ift("eth0", 1234), ifs, {}) + TEST_CHECK((to_endpoint(ift("eth0", 1234), ifs) == eps{ep("185.0.1.2", 1234, "eth0", ls::was_expanded | ls::accept_incoming) , ep("fe80::d250:99ff:fe0c:9b74", 1234, "eth0", ls::was_expanded | ls::accept_incoming | ls::local_network)})); - TEST_CHECK((to_endpoint(ift("eth1", 1234), ifs, {}) - == eps{ep("192.168.2.2", 1234, "eth1", ls::was_expanded | ls::accept_incoming | ls::local_network) + TEST_CHECK((to_endpoint(ift("eth1", 1234), ifs) + == eps{ep("192.168.2.2", 1234, "eth1", ls::was_expanded | ls::accept_incoming) , ep("2601:646:c600:a3:d250:99ff:fe0c:9b74", 1234, "eth1", ls::was_expanded | ls::accept_incoming)})); - std::vector const routes = { - rt("0.0.0.0", "eth1", "3.4.5.6"), - rt("0.0.0.0", "eth0", "1.2.3.4"), - rt("::", "eth0", "1234:5678::1"), - }; - std::vector const ifs2 = { ifc("10.0.1.1", "eth0") }; - TEST_CHECK((to_endpoint(ift("eth0", 1234), ifs2, routes) + TEST_CHECK((to_endpoint(ift("eth0", 1234), ifs2) == eps{ep("10.0.1.1", 1234, "eth0", ls::was_expanded | ls::accept_incoming)})); }