Skip to content

outgoing_interfaces: silent fallback to default route when bind_device fails #8668

Description

@PoSFFS

When outgoing_interfaces is set and bind_device() fails, session_impl::bind_outgoing_socket() logs the error but does not abort. It continues to call connect() on the now-unbound socket, causing traffic to silently go out on whatever interface the OS routing table prefers.

Impact:
On machines with multiple network interfaces, this is particularly problematic — traffic intended for one network will silently leak onto another with no indication to the user.

Location:
src/session_impl.cpp, bind_outgoing_socket() — bind_device() failure does not prevent connect() from being called.

Requested Solution:
Close the socket and return on bind_device() failure. Do not connect.

if (!device.empty()) {
    bind_device(s, device.c_str(), ec);
    if (ec) {
        s.close();
        return;
    }
}

Suggestion:
Additionally, fire peer_blocked_alert with invalid_local_interface so the caller can diagnose the misconfiguration.

if (m_alerts.should_post<peer_blocked_alert>())
    m_alerts.emplace_alert<peer_blocked_alert>(
        torrent_handle(),
        endpoint,
        peer_blocked_alert::invalid_local_interface);

Reason:
If a user specifies X and X fails, Y should not be used silently. I make this request because i do not want to solve a internal issue with a external program. Even thou my stance is to always use a firewall and a proper routing table.

Thank you for maintaining libtorrent — I have great appreciation for your work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions