Fix: missing fake-ip record should return error
This commit is contained in:
parent
8c3e2a7559
commit
d3bb4c65a8
4 changed files with 30 additions and 2 deletions
|
@ -17,6 +17,7 @@ type Pool struct {
|
|||
offset uint32
|
||||
mux sync.Mutex
|
||||
host *trie.DomainTrie
|
||||
ipnet *net.IPNet
|
||||
cache *cache.LruCache
|
||||
}
|
||||
|
||||
|
@ -89,6 +90,11 @@ func (p *Pool) Gateway() net.IP {
|
|||
return uintToIP(p.gateway)
|
||||
}
|
||||
|
||||
// IPNet return raw ipnet
|
||||
func (p *Pool) IPNet() *net.IPNet {
|
||||
return p.ipnet
|
||||
}
|
||||
|
||||
// PatchFrom clone cache from old pool
|
||||
func (p *Pool) PatchFrom(o *Pool) {
|
||||
o.cache.CloneTo(p.cache)
|
||||
|
@ -141,6 +147,7 @@ func New(ipnet *net.IPNet, size int, host *trie.DomainTrie) (*Pool, error) {
|
|||
max: max,
|
||||
gateway: min - 1,
|
||||
host: host,
|
||||
ipnet: ipnet,
|
||||
cache: cache.NewLRUCache(cache.WithSize(size * 2)),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ type Enhancer interface {
|
|||
FakeIPEnabled() bool
|
||||
MappingEnabled() bool
|
||||
IsFakeIP(net.IP) bool
|
||||
IsExistFakeIP(net.IP) bool
|
||||
FindHostByIP(net.IP) (string, bool)
|
||||
}
|
||||
|
||||
|
@ -37,6 +38,14 @@ func IsFakeIP(ip net.IP) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func IsExistFakeIP(ip net.IP) bool {
|
||||
if mapper := DefaultHostMapper; mapper != nil {
|
||||
return mapper.IsExistFakeIP(ip)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func FindHostByIP(ip net.IP) (string, bool) {
|
||||
if mapper := DefaultHostMapper; mapper != nil {
|
||||
return mapper.FindHostByIP(ip)
|
||||
|
|
|
@ -21,7 +21,7 @@ func (h *ResolverEnhancer) MappingEnabled() bool {
|
|||
return h.mode == FAKEIP || h.mode == MAPPING
|
||||
}
|
||||
|
||||
func (h *ResolverEnhancer) IsFakeIP(ip net.IP) bool {
|
||||
func (h *ResolverEnhancer) IsExistFakeIP(ip net.IP) bool {
|
||||
if !h.FakeIPEnabled() {
|
||||
return false
|
||||
}
|
||||
|
@ -33,6 +33,18 @@ func (h *ResolverEnhancer) IsFakeIP(ip net.IP) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (h *ResolverEnhancer) IsFakeIP(ip net.IP) bool {
|
||||
if !h.FakeIPEnabled() {
|
||||
return false
|
||||
}
|
||||
|
||||
if pool := h.fakePool; pool != nil {
|
||||
return pool.IPNet().Contains(ip) && !pool.Gateway().Equal(ip)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (h *ResolverEnhancer) FindHostByIP(ip net.IP) (string, bool) {
|
||||
if pool := h.fakePool; pool != nil {
|
||||
if host, existed := pool.LookBack(ip); existed {
|
||||
|
|
|
@ -170,7 +170,7 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
|
|||
|
||||
// make a fAddr if requset ip is fakeip
|
||||
var fAddr net.Addr
|
||||
if resolver.IsFakeIP(metadata.DstIP) {
|
||||
if resolver.IsExistFakeIP(metadata.DstIP) {
|
||||
fAddr = metadata.UDPAddr()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue