fix: rand ip error and clash remove loopback ip

This commit is contained in:
gVisor bot 2023-03-12 18:44:30 +08:00
parent 4f23cda7c8
commit 020ed8bc96
2 changed files with 3 additions and 3 deletions

View file

@ -2,12 +2,12 @@ package resolver
import ( import (
"errors" "errors"
"math/rand"
"net/netip" "net/netip"
"strings" "strings"
"github.com/Dreamacro/clash/common/utils" "github.com/Dreamacro/clash/common/utils"
"github.com/Dreamacro/clash/component/trie" "github.com/Dreamacro/clash/component/trie"
"github.com/zhangyunhao116/fastrand"
) )
type Hosts struct { type Hosts struct {
@ -109,5 +109,5 @@ func (hv HostValue) RandIP() (netip.Addr, error) {
if hv.IsDomain { if hv.IsDomain {
return netip.Addr{}, errors.New("value type is error") 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
} }

View file

@ -845,7 +845,7 @@ func parseHosts(cfg *RawConfig) (*trie.DomainTrie[resolver.HostValue], error) {
} else { } else {
ips := make([]netip.Addr, 0) ips := make([]netip.Addr, 0)
for _, addr := range addrs { 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 { if ip, err := netip.ParseAddr(ipnet.IP.String()); err == nil {
ips = append(ips, ip) ips = append(ips, ip)
} }