Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP filter seems not to be applied for DHT traffic #7789

Open
HanabishiRecca opened this issue Nov 11, 2024 · 1 comment
Open

IP filter seems not to be applied for DHT traffic #7789

HanabishiRecca opened this issue Nov 11, 2024 · 1 comment

Comments

@HanabishiRecca
Copy link
Contributor

HanabishiRecca commented Nov 11, 2024

I noticed that libtorrent still tries to contact filtered IPs. It sends UDP packets as part of an outgoing connection, which appears to be DHT traffic.
Fun fact that it does alert about IP being filtered, but still sends the packets regardless. And amount of outgoing UDP packets on my firewall matches with amount of alerts.

Seeking through the code, I see that at least here a DHT node is added before the filter:

libtorrent/src/torrent.cpp

Lines 11185 to 11199 in bb08bdb

#ifndef TORRENT_DISABLE_DHT
if (source != peer_info::resume_data)
{
// try to send a DHT ping to this peer
// as well, to figure out if it supports
// DHT (uTorrent and BitComet don't
// advertise support)
session().add_dht_node({adr.address(), adr.port()});
}
#endif
if (m_apply_ip_filter
&& m_ip_filter
&& m_ip_filter->access(adr.address()) & ip_filter::blocked)
{

And I don't see any filters in the DHT tracker logic at all, so it appears to be talking with blocked IPs freely. That should not happen in my opinion.
It's hard to track the logic though, so maybe I misunderstood something. @arvidn, could you clarify on that?

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Nov 12, 2024

Some testing confirms that moving the add_dht_node part below all filters at least prevents such outgoing connections.

--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -11182,17 +11182,6 @@ namespace {
 
 		TORRENT_ASSERT(info_hash().has_v2() || !(flags & pex_lt_v2));
 
-#ifndef TORRENT_DISABLE_DHT
-		if (source != peer_info::resume_data)
-		{
-			// try to send a DHT ping to this peer
-			// as well, to figure out if it supports
-			// DHT (uTorrent and BitComet don't
-			// advertise support)
-			session().add_dht_node({adr.address(), adr.port()});
-		}
-#endif
-
 		if (m_apply_ip_filter
 			&& m_ip_filter
 			&& m_ip_filter->access(adr.address()) & ip_filter::blocked)
@@ -11241,6 +11230,17 @@ namespace {
 			return nullptr;
 		}
 
+#ifndef TORRENT_DISABLE_DHT
+		if (source != peer_info::resume_data)
+		{
+			// try to send a DHT ping to this peer
+			// as well, to figure out if it supports
+			// DHT (uTorrent and BitComet don't
+			// advertise support)
+			session().add_dht_node({adr.address(), adr.port()});
+		}
+#endif
+
 		if (!torrent_file().info_hashes().has_v1())
 			flags |= pex_lt_v2;
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant