Skip to content

Commit

Permalink
fix: rand ip error and clash remove loopback ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyxim committed Mar 12, 2023
1 parent 0a6c848 commit 7d23013
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions component/resolver/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7d23013

Please sign in to comment.