From 7d230139a06dbf02d4846f6e27e16ddd1598b893 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 12 Mar 2023 18:44:30 +0800 Subject: [PATCH] fix: rand ip error and `clash` remove loopback ip --- component/resolver/host.go | 4 ++-- config/config.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/component/resolver/host.go b/component/resolver/host.go index 49168e2b..3b7e9a37 100644 --- a/component/resolver/host.go +++ b/component/resolver/host.go @@ -2,12 +2,12 @@ package resolver import ( "errors" - "math/rand" "net/netip" "strings" "github.com/Dreamacro/clash/common/utils" "github.com/Dreamacro/clash/component/trie" + "github.com/zhangyunhao116/fastrand" ) type Hosts struct { @@ -109,5 +109,5 @@ func (hv HostValue) RandIP() (netip.Addr, error) { if hv.IsDomain { return netip.Addr{}, errors.New("value type is error") } - return hv.IPs[rand.Intn(len(hv.IPs)-1)], nil + return hv.IPs[fastrand.Intn(len(hv.IPs))], nil } diff --git a/config/config.go b/config/config.go index c8c00664..dfcb772e 100644 --- a/config/config.go +++ b/config/config.go @@ -845,7 +845,7 @@ func parseHosts(cfg *RawConfig) (*trie.DomainTrie[resolver.HostValue], error) { } else { ips := make([]netip.Addr, 0) for _, addr := range addrs { - if ipnet, ok := addr.(*net.IPNet); ok { + if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ip, err := netip.ParseAddr(ipnet.IP.String()); err == nil { ips = append(ips, ip) }