ignores UPnP routers that are not configured as routers on the local machine

This commit is contained in:
Arvid Norberg 2008-05-13 04:59:56 +00:00
parent 3ea8c933d3
commit 0de312c80c
2 changed files with 33 additions and 14 deletions

View File

@ -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;

View File

@ -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<ip_interface> const& net = enum_net_interfaces(m_io_service, ec);
for (std::vector<ip_interface>::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<ip_route> 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<ip_interface> 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<ip_interface>::const_iterator i = net.begin()
, end(net.end()); i != end; ++i)
"ignored because it's not a router on our network ";
for (std::vector<ip_route>::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;
}