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

libtorrent https://github.com/arvidn/libtorrent/commit/9ac4e6eed88c1ea1e6cdb6865889320164ad0b85 listening on bound interface but not making outgoing connections through it #4482

Closed
rwasef1830 opened this issue Mar 30, 2020 · 9 comments

Comments

@rwasef1830
Copy link

Hey @arvidn
I just compiled qBittorrent https://github.com/qbittorrent/qBittorrent/tree/v4_2_x with libtorrent 9ac4e6e and even though I selected an interface and one of its addresses to bind, libtorrent does not use it when making outgoing connections.

It is listening on the correct interface and address but making actual outgoing connections to peers over the primary interface IP (not the explicitly selected one) (seen using lsof -i tcp -i udp -n -L | grep qbitt) in the shell.

@arvidn
Copy link
Owner

arvidn commented Mar 30, 2020

thanks for testing! Is this a regression with that patch specifically? I should review it to make sure there aren't any success paths where bind() isn't called.

@rwasef1830
Copy link
Author

@arvidn

OK, there's 2 strange behaviors that are affected by the patch. But overall the patch makes it more broken.

  1. With the patch:
  • Bind interface + Bind address ---> No effect for outgoing (only honored by listen socket)
  • Bind any interface + Bind address ---> No effect for outgoing (only honored by listen socket)
  1. Without that patch:
  • Bind interface + Bind address ---> Outgoing connection uses correct IP (seen by lsof), listen socket listening on correct address.
  • Bind any interface + Bind address --> No effect for outgoing (only honored by listen socket)

I think there is a missing or broken code path for outgoing connections. If only bind address is specified, outgoing connections should use it. If more than 1 interface has the same bind address, then outgoing connections should be distributed over all interfaces having it.

In both cases, the patch breaks outgoing connections. I'm not actually sure why there is a separate bind interface and bind address setting... It makes things very confusing.

@arvidn
Copy link
Owner

arvidn commented Mar 30, 2020

if SO_BINDTODEVICE succeeds, the bind() call will be using 0.0.0.0. Is that a problem? Presumably binding to the device will still be in affect.

@rwasef1830
Copy link
Author

rwasef1830 commented Mar 30, 2020

I don't quite follow...
What I can say is 9ac4e6e causes outgoing connections to not honor any bind settings at all.

Without that commit, outgoing connections have the correct source IP only if both the interface and address to bind are selected in qBittorrent.

If only the address to bind is selected in qBittorrent, outgoing connections still have the wrong source IP with or without that commit.

Note: I am testing on a seedbox, where I have a single outgoing physical interface that has multiple IP addresses assigned to it.

@arvidn
Copy link
Owner

arvidn commented Mar 30, 2020 via email

@arvidn
Copy link
Owner

arvidn commented Mar 30, 2020 via email

@arvidn
Copy link
Owner

arvidn commented Apr 2, 2020

I cannot reproduce this issue. Can you help me? your lsof command is helpful in verifying the local endpoint of sockets. This is Ubuntu 19.10.

I'm testing with this command line:

./client_test -f client-test.log -s . --alert_mask=error,connect,tracker --outgoing_interfaces=tun0 --listen_interfaces=tun0:8888 ubuntu-19.10-desktop-amd64.iso.torrent

and the peer list shows the local endpoint (correctly) as 10.51.10.6, which is my VPN IP address.

The lsof command:

lsof -i tcp -i udp -n -L | grep client_t

Shows the outgoing connections to be bound to the VPN IP as well:

client_te 68960 arvid    8u  IPv4 906643      0t0  TCP 10.51.10.6:8888 (LISTEN)
client_te 68960 arvid   10u  IPv4 906644      0t0  UDP 10.51.10.6:8888
client_te 68960 arvid   11u  IPv6 906646      0t0  TCP [fe80::4830:521c:fb5d:8f6b]:8888 (LISTEN)
client_te 68960 arvid   12u  IPv6 906647      0t0  UDP [fe80::4830:521c:fb5d:8f6b]:8888
client_te 68960 arvid   13u  IPv4 906679      0t0  UDP 10.51.10.6:54214
client_te 68960 arvid   14u  IPv4 906680      0t0  UDP 10.51.10.6:1900
client_te 68960 arvid   15u  IPv4 906681      0t0  UDP 10.51.10.6:36445
client_te 68960 arvid   16u  IPv4 906682      0t0  UDP *:6771
client_te 68960 arvid   17u  IPv6 906683      0t0  UDP *:6771
client_te 68960 arvid   19u  IPv4 900924      0t0  TCP 10.51.10.6:47067->68.204.189.151:51413 (ESTABLISHED)
client_te 68960 arvid   23u  IPv4 900960      0t0  TCP 10.51.10.6:54813->91.12.53.117:51413 (SYN_SENT)

@rwasef1830
Copy link
Author

With this command:

~/bin/client_test -f client-test.log -s . --alert_mask=error,connect,tracker --listen_interfaces=5.79.67.9:61888 ../ubuntu-18.04.4-server-amd64.iso.torrent

I get correct listen IP but wrong outgoing connection IP.

With this command

~/bin/client_test -f client-test.log -s . --alert_mask=error,connect,tracker --outgoing_interfaces=5.79.67.9  --listen_interfaces=5.79.67.9:61888 ../ubuntu-18.04.4-server-amd64.iso.torrent

I get correct listen IP and correct outgoing connection IP.

My server has a single interface eth4 but with many IPs assigned, one of which is 5.79.67.9

-- Ok so I guess the problem is actually in qBittorrent not setting libtorrent outgoing_interfaces properly. I will check there.

@arvidn
Copy link
Owner

arvidn commented Apr 5, 2020

thanks for testing! It's still possible there's an issue in libtorrent, but it's hard to say before we know more about what settings qbt set

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

2 participants