mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2026-05-21 21:36:30 +03:00
Fix outbound link-local connections on mobile (#1300)
This commit is contained in:
@@ -69,6 +69,13 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error)
|
||||
dialer.Control = l.getControl(sintf)
|
||||
ief, err := net.InterfaceByName(sintf)
|
||||
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)
|
||||
}
|
||||
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()
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user