mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-05 21:47:31 +00:00
fix: system:// should ignore dns server setting by tun listener
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/metacubex/mihomo/adapter/inbound"
|
||||
"github.com/metacubex/mihomo/component/dialer"
|
||||
"github.com/metacubex/mihomo/component/iface"
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
LC "github.com/metacubex/mihomo/listener/config"
|
||||
"github.com/metacubex/mihomo/listener/sing"
|
||||
@@ -39,6 +40,8 @@ type Listener struct {
|
||||
networkUpdateMonitor tun.NetworkUpdateMonitor
|
||||
defaultInterfaceMonitor tun.DefaultInterfaceMonitor
|
||||
packageManager tun.PackageManager
|
||||
|
||||
dnsServerIp []string
|
||||
}
|
||||
|
||||
func CalculateInterfaceName(name string) (tunName string) {
|
||||
@@ -147,12 +150,16 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
||||
|
||||
dnsAdds = append(dnsAdds, addrPort)
|
||||
}
|
||||
|
||||
var dnsServerIp []string
|
||||
for _, a := range options.Inet4Address {
|
||||
addrPort := netip.AddrPortFrom(a.Addr().Next(), 53)
|
||||
dnsServerIp = append(dnsServerIp, a.Addr().Next().String())
|
||||
dnsAdds = append(dnsAdds, addrPort)
|
||||
}
|
||||
for _, a := range options.Inet6Address {
|
||||
addrPort := netip.AddrPortFrom(a.Addr().Next(), 53)
|
||||
dnsServerIp = append(dnsServerIp, a.Addr().Next().String())
|
||||
dnsAdds = append(dnsAdds, addrPort)
|
||||
}
|
||||
|
||||
@@ -244,6 +251,10 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
||||
return
|
||||
}
|
||||
|
||||
l.dnsServerIp = dnsServerIp
|
||||
// after tun.New sing-tun has set DNS to TUN interface
|
||||
resolver.AddSystemDnsBlacklist(dnsServerIp...)
|
||||
|
||||
stackOptions := tun.StackOptions{
|
||||
Context: context.TODO(),
|
||||
Tun: tunIf,
|
||||
@@ -336,6 +347,7 @@ func parseRange(uidRanges []ranges.Range[uint32], rangeList []string) ([]ranges.
|
||||
|
||||
func (l *Listener) Close() error {
|
||||
l.closed = true
|
||||
resolver.RemoveSystemDnsBlacklist(l.dnsServerIp...)
|
||||
return common.Close(
|
||||
l.tunStack,
|
||||
l.tunIf,
|
||||
|
||||
Reference in New Issue
Block a user