Fix outbound link-local connections on mobile (#1300)

This commit is contained in:
Andrei Tregubov
2026-01-18 23:12:31 +04:00
committed by GitHub
parent 20155a2081
commit 9184cd23e5

View File

@@ -69,6 +69,13 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error)
dialer.Control = l.getControl(sintf) dialer.Control = l.getControl(sintf)
ief, err := net.InterfaceByName(sintf) ief, err := net.InterfaceByName(sintf)
if err != nil { if err != nil {
// On mobile platforms (Android/iOS), InterfaceByName may fail due to
// permission restrictions (SELinux on Android), but for link-local
// addresses with zone identifiers, the zone is sufficient for routing
// and we can proceed without source binding
if dst.IP.IsLinkLocalUnicast() && dst.Zone != "" {
return dialer, nil
}
return nil, fmt.Errorf("interface %q not found", sintf) return nil, fmt.Errorf("interface %q not found", sintf)
} }
if ief.Flags&net.FlagUp == 0 { if ief.Flags&net.FlagUp == 0 {
@@ -76,6 +83,10 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error)
} }
addrs, err := ief.Addrs() addrs, err := ief.Addrs()
if err != nil { if err != nil {
// Same mobile platform handling for address lookup failures
if dst.IP.IsLinkLocalUnicast() && dst.Zone != "" {
return dialer, nil
}
return nil, fmt.Errorf("interface %q addresses not available: %w", sintf, err) return nil, fmt.Errorf("interface %q addresses not available: %w", sintf, err)
} }
for addrindex, addr := range addrs { for addrindex, addr := range addrs {
@@ -104,6 +115,10 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error)
} }
} }
if dialer.LocalAddr == nil { if dialer.LocalAddr == nil {
// Proceed without source binding if link-local
if dst.IP.IsLinkLocalUnicast() && dst.Zone != "" {
return dialer, nil
}
return nil, fmt.Errorf("no suitable source address found on interface %q", sintf) return nil, fmt.Errorf("no suitable source address found on interface %q", sintf)
} }
} }