diff --git a/common/settings/proxy_darwin.go b/common/settings/proxy_darwin.go index ce8e9cd7..7cc66f43 100644 --- a/common/settings/proxy_darwin.go +++ b/common/settings/proxy_darwin.go @@ -20,7 +20,7 @@ type systemProxy struct { isMixed bool } -func (p *systemProxy) update() error { +func (p *systemProxy) update(event int) error { newInterfaceName := p.monitor.DefaultInterfaceName(netip.IPv4Unspecified()) if p.interfaceName == newInterfaceName { return nil @@ -88,7 +88,7 @@ func SetSystemProxy(router adapter.Router, port uint16, isMixed bool) (func() er port: port, isMixed: isMixed, } - err := proxy.update() + err := proxy.update(tun.EventInterfaceUpdate) if err != nil { return nil, err } diff --git a/inbound/tun.go b/inbound/tun.go index 09426511..1522e284 100644 --- a/inbound/tun.go +++ b/inbound/tun.go @@ -86,6 +86,7 @@ func NewTun(ctx context.Context, router adapter.Router, logger log.ContextLogger IncludeAndroidUser: options.IncludeAndroidUser, IncludePackage: options.IncludePackage, ExcludePackage: options.ExcludePackage, + InterfaceMonitor: router.InterfaceMonitor(), }, endpointIndependentNat: options.EndpointIndependentNat, udpTimeout: udpTimeout, diff --git a/option/route.go b/option/route.go index 86f31d23..74f67d02 100644 --- a/option/route.go +++ b/option/route.go @@ -16,6 +16,7 @@ type RouteOptions struct { Final string `json:"final,omitempty"` FindProcess bool `json:"find_process,omitempty"` AutoDetectInterface bool `json:"auto_detect_interface,omitempty"` + OverrideAndroidVPN bool `json:"override_android_vpn,omitempty"` DefaultInterface string `json:"default_interface,omitempty"` DefaultMark int `json:"default_mark,omitempty"` } diff --git a/route/router.go b/route/router.go index b3957f5a..9b8a076b 100644 --- a/route/router.go +++ b/route/router.go @@ -244,7 +244,7 @@ func NewRouter(ctx context.Context, logger log.ContextLogger, dnsLogger log.Cont needInterfaceMonitor := options.AutoDetectInterface || C.IsDarwin && common.Any(inbounds, func(inbound option.Inbound) bool { - return inbound.HTTPOptions.SetSystemProxy || inbound.MixedOptions.SetSystemProxy + return inbound.HTTPOptions.SetSystemProxy || inbound.MixedOptions.SetSystemProxy || C.IsAndroid && inbound.TunOptions.AutoRoute }) if router.interfaceBindManager != nil || needInterfaceMonitor { @@ -258,12 +258,24 @@ func NewRouter(ctx context.Context, logger log.ContextLogger, dnsLogger log.Cont } if router.networkMonitor != nil && needInterfaceMonitor { - interfaceMonitor, err := tun.NewDefaultInterfaceMonitor(router.networkMonitor) + interfaceMonitor, err := tun.NewDefaultInterfaceMonitor(router.networkMonitor, tun.DefaultInterfaceMonitorOptions{ + OverrideAndroidVPN: options.OverrideAndroidVPN, + }) if err != nil { return nil, E.New("auto_detect_interface unsupported on current platform") } - interfaceMonitor.RegisterCallback(func() error { - router.logger.Info("updated default interface ", router.interfaceMonitor.DefaultInterfaceName(netip.IPv4Unspecified()), ", index ", router.interfaceMonitor.DefaultInterfaceIndex(netip.IPv4Unspecified())) + interfaceMonitor.RegisterCallback(func(event int) error { + if C.IsAndroid { + var vpnStatus string + if router.interfaceMonitor.AndroidVPNEnabled() { + vpnStatus = "enabled" + } else { + vpnStatus = "disabled" + } + router.logger.Info("updated default interface ", router.interfaceMonitor.DefaultInterfaceName(netip.IPv4Unspecified()), ", index ", router.interfaceMonitor.DefaultInterfaceIndex(netip.IPv4Unspecified()), ", vpn ", vpnStatus) + } else { + router.logger.Info("updated default interface ", router.interfaceMonitor.DefaultInterfaceName(netip.IPv4Unspecified()), ", index ", router.interfaceMonitor.DefaultInterfaceIndex(netip.IPv4Unspecified())) + } return nil }) router.interfaceMonitor = interfaceMonitor @@ -667,12 +679,12 @@ func (r *Router) match(ctx context.Context, metadata *adapter.InboundContext, de } processInfo, err := process.FindProcessInfo(r.processSearcher, ctx, metadata.Network, metadata.Source.AddrPort(), originDestination) if err != nil { - r.logger.DebugContext(ctx, "failed to search process: ", err) + r.logger.InfoContext(ctx, "failed to search process: ", err) } else { if processInfo.ProcessPath != "" { - r.logger.DebugContext(ctx, "found process path: ", processInfo.ProcessPath) + r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath) } else if processInfo.PackageName != "" { - r.logger.DebugContext(ctx, "found package name: ", processInfo.PackageName) + r.logger.InfoContext(ctx, "found package name: ", processInfo.PackageName) } else if processInfo.UserId != -1 { if /*needUserName &&*/ true { osUser, _ := user.LookupId(F.ToString(processInfo.UserId)) @@ -681,9 +693,9 @@ func (r *Router) match(ctx context.Context, metadata *adapter.InboundContext, de } } if processInfo.User != "" { - r.logger.DebugContext(ctx, "found user: ", processInfo.User) + r.logger.InfoContext(ctx, "found user: ", processInfo.User) } else { - r.logger.DebugContext(ctx, "found user id: ", processInfo.UserId) + r.logger.InfoContext(ctx, "found user id: ", processInfo.UserId) } } metadata.ProcessInfo = processInfo