mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-05 17:13:32 +08:00
fix: when host's ip in fakeip's range, don't send to remote server
This commit is contained in:
parent
7c8d8f56e1
commit
64552fbd00
@ -495,7 +495,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
}
|
}
|
||||||
config.DNS = dnsCfg
|
config.DNS = dnsCfg
|
||||||
|
|
||||||
err = parseTun(rawCfg.Tun, config.General, dnsCfg)
|
err = parseTun(rawCfg.Tun, config.General)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1053,8 +1053,9 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[netip.Addr], rules []C.R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fakeIPRange, err := netip.ParsePrefix(cfg.FakeIPRange)
|
||||||
|
T.SetFakeIPRange(fakeIPRange)
|
||||||
if cfg.EnhancedMode == C.DNSFakeIP {
|
if cfg.EnhancedMode == C.DNSFakeIP {
|
||||||
ipnet, err := netip.ParsePrefix(cfg.FakeIPRange)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1081,7 +1082,7 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[netip.Addr], rules []C.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool, err := fakeip.New(fakeip.Options{
|
pool, err := fakeip.New(fakeip.Options{
|
||||||
IPNet: &ipnet,
|
IPNet: &fakeIPRange,
|
||||||
Size: 1000,
|
Size: 1000,
|
||||||
Host: host,
|
Host: host,
|
||||||
Persistence: rawCfg.Profile.StoreFakeIP,
|
Persistence: rawCfg.Profile.StoreFakeIP,
|
||||||
@ -1124,7 +1125,7 @@ func parseAuthentication(rawRecords []string) []auth.AuthUser {
|
|||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTun(rawTun RawTun, general *General, dnsCfg *DNS) error {
|
func parseTun(rawTun RawTun, general *General) error {
|
||||||
var dnsHijack []netip.AddrPort
|
var dnsHijack []netip.AddrPort
|
||||||
|
|
||||||
for _, d := range rawTun.DNSHijack {
|
for _, d := range rawTun.DNSHijack {
|
||||||
@ -1140,10 +1141,8 @@ func parseTun(rawTun RawTun, general *General, dnsCfg *DNS) error {
|
|||||||
dnsHijack = append(dnsHijack, addrPort)
|
dnsHijack = append(dnsHijack, addrPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunAddressPrefix netip.Prefix
|
tunAddressPrefix := T.FakeIPRange()
|
||||||
if dnsCfg.FakeIPRange != nil {
|
if !tunAddressPrefix.IsValid() {
|
||||||
tunAddressPrefix = *dnsCfg.FakeIPRange.IPNet()
|
|
||||||
} else {
|
|
||||||
tunAddressPrefix = netip.MustParsePrefix("198.18.0.1/16")
|
tunAddressPrefix = netip.MustParsePrefix("198.18.0.1/16")
|
||||||
}
|
}
|
||||||
tunAddressPrefix = netip.PrefixFrom(tunAddressPrefix.Addr(), 30)
|
tunAddressPrefix = netip.PrefixFrom(tunAddressPrefix.Addr(), 30)
|
||||||
|
@ -41,8 +41,18 @@ var (
|
|||||||
udpTimeout = 60 * time.Second
|
udpTimeout = 60 * time.Second
|
||||||
|
|
||||||
alwaysFindProcess = false
|
alwaysFindProcess = false
|
||||||
|
|
||||||
|
fakeIPRange netip.Prefix
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SetFakeIPRange(p netip.Prefix) {
|
||||||
|
fakeIPRange = p
|
||||||
|
}
|
||||||
|
|
||||||
|
func FakeIPRange() netip.Prefix {
|
||||||
|
return fakeIPRange
|
||||||
|
}
|
||||||
|
|
||||||
func SetSniffing(b bool) {
|
func SetSniffing(b bool) {
|
||||||
if sniffer.Dispatcher.Enable() {
|
if sniffer.Dispatcher.Enable() {
|
||||||
configMux.Lock()
|
configMux.Lock()
|
||||||
@ -334,9 +344,11 @@ func handleTCPConn(connCtx C.ConnContext) {
|
|||||||
dialMetadata := metadata
|
dialMetadata := metadata
|
||||||
if len(metadata.Host) > 0 {
|
if len(metadata.Host) > 0 {
|
||||||
if node := resolver.DefaultHosts.Search(metadata.Host); node != nil {
|
if node := resolver.DefaultHosts.Search(metadata.Host); node != nil {
|
||||||
dialMetadata.DstIP = node.Data()
|
if dstIp := node.Data(); !FakeIPRange().Contains(dstIp) {
|
||||||
dialMetadata.DNSMode = C.DNSHosts
|
dialMetadata.DstIP = dstIp
|
||||||
dialMetadata = dialMetadata.Pure()
|
dialMetadata.DNSMode = C.DNSHosts
|
||||||
|
dialMetadata = dialMetadata.Pure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user