diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 3b4d4a2e3..7c69ffd5a 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -252,7 +252,7 @@ private: bool m_disabled; bool m_closing; - bool m_ignore_outside_network; + bool m_ignore_non_routers; connection_queue& m_cc; diff --git a/src/upnp.cpp b/src/upnp.cpp index 142763e24..6c127a840 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -54,12 +54,6 @@ POSSIBILITY OF SUCH DAMAGE. using boost::bind; using namespace libtorrent; -namespace libtorrent -{ - bool is_local(address const& a); - address guess_local_address(io_service&); -} - upnp::upnp(io_service& ios, connection_queue& cc , address const& listen_interface, std::string const& user_agent , portmap_callback_t const& cb, bool ignore_nonrouters) @@ -73,7 +67,7 @@ upnp::upnp(io_service& ios, connection_queue& cc , m_refresh_timer(ios) , m_disabled(false) , m_closing(false) - , m_ignore_outside_network(ignore_nonrouters) + , m_ignore_non_routers(ignore_nonrouters) , m_cc(cc) { #ifdef TORRENT_UPNP_LOGGING @@ -307,7 +301,33 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer */ error_code ec; - if (m_ignore_outside_network && !in_local_network(m_io_service, from.address(), ec)) + if (!in_local_network(m_io_service, from.address(), ec)) + { +#ifdef TORRENT_UPNP_LOGGING + if (ec) + { + m_log << time_now_string() << " <== (" << from << ") error: " + << ec.message() << std::endl; + } + else + { + m_log << time_now_string() << " <== (" << from << ") UPnP device " + "ignored because it's not on our local network "; + std::vector const& net = enum_net_interfaces(m_io_service, ec); + for (std::vector::const_iterator i = net.begin() + , end(net.end()); i != end; ++i) + { + m_log << "(" << i->interface_address << ", " << i->netmask << ") "; + } + m_log << std::endl; + } +#endif + return; + } + + std::vector routes = enum_routes(m_io_service, ec); + if (m_ignore_non_routers && std::find_if(routes.begin(), routes.end() + , bind(&ip_route::gateway, _1) == from.address()) == routes.end()) { // this upnp device is filtered because it's not in the // list of configured routers @@ -319,13 +339,12 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer } else { - std::vector const& net = enum_net_interfaces(m_io_service, ec); m_log << time_now_string() << " <== (" << from << ") UPnP device " - "ignored because it's not on our network "; - for (std::vector::const_iterator i = net.begin() - , end(net.end()); i != end; ++i) + "ignored because it's not a router on our network "; + for (std::vector::const_iterator i = routes.begin() + , end(routes.end()); i != end; ++i) { - m_log << "(" << i->interface_address << ", " << i->netmask << ") "; + m_log << "(" << i->gateway << ", " << i->netmask << ") "; } m_log << std::endl; }