From 802b0b2449b73a862636e87e190d433c43a52079 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 15 May 2026 14:38:24 +0800 Subject: [PATCH] fix: netlink permission denied on android for tailscale --- adapter/outbound/tailscale.go | 5 +++++ component/iface/anet/interface_android.go | 6 +++++- component/iface/iface.go | 9 ++------- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/adapter/outbound/tailscale.go b/adapter/outbound/tailscale.go index bcb4dd31..c0d5922e 100644 --- a/adapter/outbound/tailscale.go +++ b/adapter/outbound/tailscale.go @@ -72,8 +72,13 @@ func init() { return nil, err } for _, iff := range ifaces { + addrs, err := anet.InterfaceAddrsByInterface(&iff) + if err != nil { + continue + } nif = append(nif, netmon.Interface{ Interface: &iff, + AltAddrs: addrs, }) } return diff --git a/component/iface/anet/interface_android.go b/component/iface/anet/interface_android.go index 904b8cdd..af612eae 100644 --- a/component/iface/anet/interface_android.go +++ b/component/iface/anet/interface_android.go @@ -97,11 +97,15 @@ func InterfaceByName(name string) (*net.Interface, error) { // InterfaceAddrsByInterface returns a list of the system's unicast // interface addresses by specific interface. func InterfaceAddrsByInterface(ifi *net.Interface) ([]net.Addr, error) { + ifat, err := ifi.Addrs() + if err == nil { + return ifat, nil + } if ifi == nil { return nil, &net.OpError{Op: "route", Net: "ip+net", Source: nil, Addr: nil, Err: errInvalidInterface} } - ifat, err := interfaceAddrTable(ifi) + ifat, err = interfaceAddrTable(ifi) if err != nil { err = &net.OpError{Op: "route", Net: "ip+net", Source: nil, Addr: nil, Err: err} } diff --git a/component/iface/iface.go b/component/iface/iface.go index 5c4c1c07..bbdabfea 100644 --- a/component/iface/iface.go +++ b/component/iface/iface.go @@ -4,7 +4,6 @@ import ( "errors" "net" "net/netip" - "runtime" "time" "github.com/metacubex/mihomo/common/singledo" @@ -37,11 +36,7 @@ var caches = singledo.NewSingle[*ifaceCache](time.Second * 20) func getCache() (*ifaceCache, error) { value, err, _ := caches.Do(func() (*ifaceCache, error) { - netInterfaces := net.Interfaces - if runtime.GOOS == "android" { - netInterfaces = anet.Interfaces - } - ifaces, err := netInterfaces() + ifaces, err := anet.Interfaces() if err != nil { return nil, err } @@ -52,7 +47,7 @@ func getCache() (*ifaceCache, error) { } for _, iface := range ifaces { - addrs, err := iface.Addrs() + addrs, err := anet.InterfaceAddrsByInterface(&iface) if err != nil { continue } diff --git a/go.mod b/go.mod index c817ea5c..c22792b8 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/metacubex/sing-wireguard v0.0.0-20260507084707-690d479ec947 github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141 github.com/metacubex/ssh v0.1.0 - github.com/metacubex/tailscale v0.0.0-20260514010142-10fd27a2338f + github.com/metacubex/tailscale v0.0.0-20260515062623-8d044ba43b3a github.com/metacubex/tfo-go v0.0.0-20251130171125-413e892ac443 github.com/metacubex/tls v0.1.5 github.com/metacubex/utls v1.8.4 diff --git a/go.sum b/go.sum index f4c1b321..9190e5ac 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,8 @@ github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141 h1:DK2l6m2Fc85H2Bhi github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141/go.mod h1:/yI4OiGOSn0SURhZdJF3CbtPg3nwK700bG8TZLMBvAg= github.com/metacubex/ssh v0.1.0 h1:iGfr99qk/eMHzUnQ/0bTxXT8+8SWqLSHBWDHoAhngzw= github.com/metacubex/ssh v0.1.0/go.mod h1:NUtl0d+/f2cG9ECEpMM8iCVOpmggQlC13oLeDUONDlU= -github.com/metacubex/tailscale v0.0.0-20260514010142-10fd27a2338f h1:nJvp3tZr4Leqh92u8mgj/aT9wUXPrGXhUQ2iXd8KxPI= -github.com/metacubex/tailscale v0.0.0-20260514010142-10fd27a2338f/go.mod h1:2G1V82OGXgxT7m7046GA80I9SlcvczljCK0C7NQ3c10= +github.com/metacubex/tailscale v0.0.0-20260515062623-8d044ba43b3a h1:NBZsWmEjoEpXkkfg6mPi0jbXimpkd17aKQThM4ZIFJ8= +github.com/metacubex/tailscale v0.0.0-20260515062623-8d044ba43b3a/go.mod h1:2G1V82OGXgxT7m7046GA80I9SlcvczljCK0C7NQ3c10= github.com/metacubex/tailscale-wireguard-go v0.0.0-20260513233728-8bc7ee255d04 h1:zk+mDDSBl5lv80WWtaFUbpj8XLb7AhjCUbn2pB37N0U= github.com/metacubex/tailscale-wireguard-go v0.0.0-20260513233728-8bc7ee255d04/go.mod h1:pKUKBy7IcQ5r0i66gWENHgxKvBn8tlgAGx0DZMq8h5M= github.com/metacubex/tfo-go v0.0.0-20251130171125-413e892ac443 h1:H6TnfM12tOoTizYE/qBHH3nEuibIelmHI+BVSxVJr8o=