expanding a device does not look for a default route

This commit is contained in:
arvidn 2020-02-28 18:17:21 +01:00 committed by Arvid Norberg
parent 1e4083b3fb
commit 14d5c99a18
4 changed files with 13 additions and 21 deletions

View File

@ -776,7 +776,10 @@ unless the following conditions are met:
* the IP address is not in a known loopback range * the IP address is not in a known loopback range
* the item the IP address was expanded from was not marked local (``l``) * 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 * 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 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 are expected to be externally available (i.e. not "local network"). If there are

View File

@ -292,7 +292,6 @@ namespace aux {
listen_interface_t const& iface listen_interface_t const& iface
, listen_socket_flags_t flags , listen_socket_flags_t flags
, span<ip_interface const> const ifs , span<ip_interface const> const ifs
, span<ip_route const> const routes
, std::vector<listen_endpoint_t>& eps); , std::vector<listen_endpoint_t>& eps);
// expand [::] to all IPv6 interfaces for BEP 45 compliance // expand [::] to all IPv6 interfaces for BEP 45 compliance

View File

@ -1747,7 +1747,6 @@ namespace aux {
void interface_to_endpoints(listen_interface_t const& iface void interface_to_endpoints(listen_interface_t const& iface
, listen_socket_flags_t flags , listen_socket_flags_t flags
, span<ip_interface const> const ifs , span<ip_interface const> const ifs
, span<ip_route const> const routes
, std::vector<listen_endpoint_t>& eps) , std::vector<listen_endpoint_t>& eps)
{ {
flags |= iface.local ? listen_socket_t::local_network : listen_socket_flags_t{}; flags |= iface.local ? listen_socket_t::local_network : listen_socket_flags_t{};
@ -1779,9 +1778,7 @@ namespace aux {
// bother looking for the gateway // bother looking for the gateway
bool const local = iface.local bool const local = iface.local
|| ipface.interface_address.is_loopback() || ipface.interface_address.is_loopback()
|| is_link_local(ipface.interface_address) || is_link_local(ipface.interface_address);
|| (!is_global(ipface.interface_address)
&& !has_default_route(ipface.name, family(ipface.interface_address), routes));
eps.emplace_back(ipface.interface_address, iface.port, iface.device eps.emplace_back(ipface.interface_address, iface.port, iface.device
, ssl, flags | (local ? listen_socket_t::local_network : listen_socket_flags_t{})); , 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 // 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 // (potentially) end up binding a socket for each IP address associated
// with that device. // 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 // if no listen interfaces are specified, create sockets to use

View File

@ -391,11 +391,10 @@ TORRENT_TEST(expand_unspecified)
namespace { namespace {
std::vector<aux::listen_endpoint_t> to_endpoint(listen_interface_t const& iface std::vector<aux::listen_endpoint_t> to_endpoint(listen_interface_t const& iface
, span<ip_interface const> const ifs , span<ip_interface const> const ifs)
, span<ip_route const> const routes)
{ {
std::vector<aux::listen_endpoint_t> ret; std::vector<aux::listen_endpoint_t> 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; return ret;
} }
@ -411,7 +410,7 @@ using ls = aux::listen_socket_t;
TORRENT_TEST(interface_to_endpoint) 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<ip_interface> const ifs = { std::vector<ip_interface> const ifs = {
@ -423,25 +422,19 @@ TORRENT_TEST(interface_to_endpoint)
, ifc("2601:646:c600:a3:d250:99ff:fe0c:9b74", "eth1") , 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) == 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)})); , 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, {}) 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) == 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)})); , ep("2601:646:c600:a3:d250:99ff:fe0c:9b74", 1234, "eth1", ls::was_expanded | ls::accept_incoming)}));
std::vector<ip_route> 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<ip_interface> const ifs2 = { std::vector<ip_interface> const ifs2 = {
ifc("10.0.1.1", "eth0") 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)})); == eps{ep("10.0.1.1", 1234, "eth0", ls::was_expanded | ls::accept_incoming)}));
} }