Skip to content

Mac userspace subnet router binding to wrong interface #5719

Closed

Description

@bradfitz

On macOS, subnet routers forwarding connections on with netstack can bind to the wrong device when the machine has multiple NICs.

Situation from debug call:

  • macOS (one of the GUI builds)
  • three network devices (wired ethernet (primary), wifi, USB ethernet dongle with a /30 to a raspberry pi)
  • tailscale up --advertise-routes=192.168.1.0/30

The netstack forwarding code gets the packet and does an outbound TCP dial but netns binds the socket to the primary wired ethernet's NIC instead of the USB ethernet dongle.

We should look at the routing table and pick the right device.

/cc @andrew-d @danderson @crawshaw @maisem @quinnypig

Activity

  1. andrew-d commented on Sep 22, 2022

    @andrew-d
    Member

    I'm pretty sure this is because this code here picks the default route (i.e. "to the internet") to bind to, rather than the route for a specific destination:

    idx, err := interfaces.DefaultRouteInterfaceIndex()

  2. andrew-d commented on Sep 22, 2022

    @andrew-d
    Member

    @bradfitz - Any chance you can get an (appropriately-redacted, if necessary) dump of netstat -nr from the system in question?

  3. bradfitz commented on Sep 22, 2022

    @bradfitz
    MemberAuthor

    The line you link to is for tailscaled, not the GUI version. But similar.

    I don't have the routing table output but it was as described above: a /30 on a separate link that wasn't the default route's.

  4. quinnypig commented on Sep 22, 2022

    @quinnypig

    I do; it's my system in question. Here's a partial dump just because it's wordy as hell, particularly on the ipv6 section; en0 is wired, en1 is wireless (same network), en8 is the other interface with a small network attached, utun5 is Tailscale.

    Internet:
    Destination        Gateway            Flags           Netif Expire
    default            192.168.1.1        UGScg             en0       
    default            192.168.1.1        UGScIg            en1       
    default            link#34            UCSIg           utun5       
    10.98.32/28        link#22            UCS               en8      !
    10.98.32.11/32     link#22            UCS               en8      !
    10.98.32.15        ff:ff:ff:ff:ff:ff  UHLWbI            en8      !
    100.64/10          link#34            UCS             utun5       
    100.93.10.83       link#34            UHWIi           utun5       
    100.99.181.129     link#34            UHWIi           utun5       
    100.100.100.100/32 link#34            UCS             utun5       
    100.100.100.100    link#34            UHWIi           utun5       
    100.126.71.95      100.126.71.95      UH              utun5       
    127                127.0.0.1          UCS               lo0       
    127.0.0.1          127.0.0.1          UH                lo0       
    
  5. quinnypig commented on Sep 27, 2022

    @quinnypig

    Now that I'm not remote I can troubleshoot more accurately; what can I do to help?

  6. DentonGentry commented on Nov 1, 2022

    @DentonGentry
    Contributor

    This may have been fixed by #5940, which went into Tailscale release 1.32.2 for macOS.

    App Store releases go through a gradual rollout process which starts with 1% of the fleet on the first day and gradually increases, your Mac may not have been prompted to update yet. Visiting the App Store page for Tailscale should show the update as available even if it hasn't prompted an update yet.


    On the assumption that this will resolve this issue: barring further comment, we'll expect to close this during the next regular bug scrub.

    (This is the magic phrase that we search for at the start of a bug scrub)

  7. DentonGentry commented on Jan 7, 2023

    @DentonGentry
    Contributor

    Fixed by #5940

  8. fylie commented on Jan 13, 2023

    @fylie

    Reopening since we have another report of this issue.

    The report was on version: TestFlight 1.35.99, commit ID a45c9f9

    Some details from investigating with @mihaip and @andrew-d :
    Based on logs, we can see that en0 is consistently chosen as the default route, which results in dropped packets meant to go to other interfaces. The routing code for macOS just selects the default route, while Linux does something a little different that results in setting the bypass mark and not explicitly binding to an interface.

    To fix this, Mihai thinks that we’d need to loop over all interfaces and if any have explicitly set InterfaceIPs that matches the target address, prefer that over the default.

  9. reopened this on Jan 13, 2023
  10. DentonGentry commented on Feb 18, 2023

    @DentonGentry
    Contributor

    I believe #7065 is available in the current macOS TestFlight.

  11. DentonGentry commented on Jun 2, 2023

    @DentonGentry
    Contributor

    Believed fixed by #7065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions